]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/wireless/iwlwifi/iwl4965-base.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / iwlwifi / iwl4965-base.c
index 8de301d1da8e1226f9f2fccd2ba8b8e05e78589f..d7e2358a213a1a32d5b7dadd084ae34daeed200a 100644 (file)
 #include <asm/div64.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"
+#include "iwl-sta.h"
 
 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
                                  struct iwl4965_tx_queue *txq);
@@ -59,14 +61,6 @@ static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
  *
  ******************************************************************************/
 
-/* module parameters */
-struct iwl_mod_params iwl4965_mod_params = {
-       .num_of_queues = IWL_MAX_NUM_QUEUES,
-       .enable_qos = 1,
-       .amsdu_size_8K = 1,
-       /* the rest are 0 by default */
-};
-
 /*
  * module name, copyright, version, etc.
  * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
@@ -305,7 +299,7 @@ int iwl4965_tx_queue_init(struct iwl_priv *priv,
         * For normal Tx queues (all other queues), no super-size command
         * space is needed.
         */
-       len = sizeof(struct iwl4965_cmd) * slots_num;
+       len = sizeof(struct iwl_cmd) * slots_num;
        if (txq_id == IWL_CMD_QUEUE_NUM)
                len +=  IWL_MAX_SCAN_SIZE;
        txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
@@ -356,7 +350,7 @@ void iwl4965_tx_queue_free(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
             q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
                iwl4965_hw_txq_free_tfd(priv, txq);
 
-       len = sizeof(struct iwl4965_cmd) * q->n_window;
+       len = sizeof(struct iwl_cmd) * q->n_window;
        if (q->id == IWL_CMD_QUEUE_NUM)
                len += IWL_MAX_SCAN_SIZE;
 
@@ -404,9 +398,9 @@ static u8 iwl4965_remove_station(struct iwl_priv *priv, const u8 *addr, int is_a
        if (is_ap)
                index = IWL_AP_ID;
        else if (is_broadcast_ether_addr(addr))
-               index = priv->hw_setting.bcast_sta_id;
+               index = priv->hw_params.bcast_sta_id;
        else
-               for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
+               for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
                        if (priv->stations[i].used &&
                            !compare_ether_addr(priv->stations[i].sta.sta.addr,
                                                addr)) {
@@ -446,9 +440,9 @@ u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr,
        if (is_ap)
                index = IWL_AP_ID;
        else if (is_broadcast_ether_addr(addr))
-               index = priv->hw_setting.bcast_sta_id;
+               index = priv->hw_params.bcast_sta_id;
        else
-               for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) {
+               for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
                        if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
                                                addr)) {
                                index = i;
@@ -489,7 +483,7 @@ u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr,
 
 #ifdef CONFIG_IWL4965_HT
        /* BCAST station and IBSS stations do not work in HT mode */
-       if (index != priv->hw_setting.bcast_sta_id &&
+       if (index != priv->hw_params.bcast_sta_id &&
            priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
                iwl4965_set_ht_add_station(priv, index,
                                 (struct ieee80211_ht_info *) ht_data);
@@ -503,103 +497,10 @@ u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr,
 
 }
 
-/*************** DRIVER STATUS FUNCTIONS   *****/
-
-static inline int iwl4965_is_ready(struct iwl_priv *priv)
-{
-       /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
-        * set but EXIT_PENDING is not */
-       return test_bit(STATUS_READY, &priv->status) &&
-              test_bit(STATUS_GEO_CONFIGURED, &priv->status) &&
-              !test_bit(STATUS_EXIT_PENDING, &priv->status);
-}
-
-static inline int iwl4965_is_alive(struct iwl_priv *priv)
-{
-       return test_bit(STATUS_ALIVE, &priv->status);
-}
-
-static inline int iwl4965_is_init(struct iwl_priv *priv)
-{
-       return test_bit(STATUS_INIT, &priv->status);
-}
-
-static inline int iwl4965_is_rfkill(struct iwl_priv *priv)
-{
-       return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
-              test_bit(STATUS_RF_KILL_SW, &priv->status);
-}
-
-static inline int iwl4965_is_ready_rf(struct iwl_priv *priv)
-{
-
-       if (iwl4965_is_rfkill(priv))
-               return 0;
 
-       return iwl4965_is_ready(priv);
-}
 
 /*************** HOST COMMAND QUEUE FUNCTIONS   *****/
 
-#define IWL_CMD(x) case x : return #x
-
-static const char *get_cmd_string(u8 cmd)
-{
-       switch (cmd) {
-               IWL_CMD(REPLY_ALIVE);
-               IWL_CMD(REPLY_ERROR);
-               IWL_CMD(REPLY_RXON);
-               IWL_CMD(REPLY_RXON_ASSOC);
-               IWL_CMD(REPLY_QOS_PARAM);
-               IWL_CMD(REPLY_RXON_TIMING);
-               IWL_CMD(REPLY_ADD_STA);
-               IWL_CMD(REPLY_REMOVE_STA);
-               IWL_CMD(REPLY_REMOVE_ALL_STA);
-               IWL_CMD(REPLY_TX);
-               IWL_CMD(REPLY_RATE_SCALE);
-               IWL_CMD(REPLY_LEDS_CMD);
-               IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
-               IWL_CMD(RADAR_NOTIFICATION);
-               IWL_CMD(REPLY_QUIET_CMD);
-               IWL_CMD(REPLY_CHANNEL_SWITCH);
-               IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
-               IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
-               IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
-               IWL_CMD(POWER_TABLE_CMD);
-               IWL_CMD(PM_SLEEP_NOTIFICATION);
-               IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
-               IWL_CMD(REPLY_SCAN_CMD);
-               IWL_CMD(REPLY_SCAN_ABORT_CMD);
-               IWL_CMD(SCAN_START_NOTIFICATION);
-               IWL_CMD(SCAN_RESULTS_NOTIFICATION);
-               IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
-               IWL_CMD(BEACON_NOTIFICATION);
-               IWL_CMD(REPLY_TX_BEACON);
-               IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
-               IWL_CMD(QUIET_NOTIFICATION);
-               IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
-               IWL_CMD(MEASURE_ABORT_NOTIFICATION);
-               IWL_CMD(REPLY_BT_CONFIG);
-               IWL_CMD(REPLY_STATISTICS_CMD);
-               IWL_CMD(STATISTICS_NOTIFICATION);
-               IWL_CMD(REPLY_CARD_STATE_CMD);
-               IWL_CMD(CARD_STATE_NOTIFICATION);
-               IWL_CMD(MISSED_BEACONS_NOTIFICATION);
-               IWL_CMD(REPLY_CT_KILL_CONFIG_CMD);
-               IWL_CMD(SENSITIVITY_CMD);
-               IWL_CMD(REPLY_PHY_CALIBRATION_CMD);
-               IWL_CMD(REPLY_RX_PHY_CMD);
-               IWL_CMD(REPLY_RX_MPDU_CMD);
-               IWL_CMD(REPLY_4965_RX);
-               IWL_CMD(REPLY_COMPRESSED_BA);
-       default:
-               return "UNKNOWN";
-
-       }
-}
-
-#define HOST_COMPLETE_TIMEOUT (HZ / 2)
-
 /**
  * iwl4965_enqueue_hcmd - enqueue a uCode command
  * @priv: device private data point
@@ -609,13 +510,13 @@ static const char *get_cmd_string(u8 cmd)
  * failed. On success, it turns the index (> 0) of command in the
  * command queue.
  */
-static int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
+int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
 {
        struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
        struct iwl4965_queue *q = &txq->q;
        struct iwl4965_tfd_frame *tfd;
        u32 *control_flags;
-       struct iwl4965_cmd *out_cmd;
+       struct iwl_cmd *out_cmd;
        u32 idx;
        u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
        dma_addr_t phys_addr;
@@ -628,7 +529,7 @@ static int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl4965_host_cmd *
        BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
               !(cmd->meta.flags & CMD_SIZE_HUGE));
 
-       if (iwl4965_is_rfkill(priv)) {
+       if (iwl_is_rfkill(priv)) {
                IWL_DEBUG_INFO("Not sending command - RF KILL");
                return -EIO;
        }
@@ -662,7 +563,7 @@ static int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl4965_host_cmd *
                out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
 
        phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
-                       offsetof(struct iwl4965_cmd, hdr);
+                       offsetof(struct iwl_cmd, hdr);
        iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
 
        IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
@@ -674,128 +575,16 @@ static int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl4965_host_cmd *
        txq->need_update = 1;
 
        /* Set up entry in queue's byte count circular buffer */
-       ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0);
+       priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, 0);
 
        /* Increment and update queue's write index */
        q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
-       iwl4965_tx_queue_update_write_ptr(priv, txq);
+       ret = iwl4965_tx_queue_update_write_ptr(priv, txq);
 
        spin_unlock_irqrestore(&priv->hcmd_lock, flags);
        return ret ? ret : idx;
 }
 
-static int iwl4965_send_cmd_async(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
-{
-       int ret;
-
-       BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
-
-       /* An asynchronous command can not expect an SKB to be set. */
-       BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
-
-       /* An asynchronous command MUST have a callback. */
-       BUG_ON(!cmd->meta.u.callback);
-
-       if (test_bit(STATUS_EXIT_PENDING, &priv->status))
-               return -EBUSY;
-
-       ret = iwl4965_enqueue_hcmd(priv, cmd);
-       if (ret < 0) {
-               IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
-                         get_cmd_string(cmd->id), ret);
-               return ret;
-       }
-       return 0;
-}
-
-static int iwl4965_send_cmd_sync(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
-{
-       int cmd_idx;
-       int ret;
-       static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */
-
-       BUG_ON(cmd->meta.flags & CMD_ASYNC);
-
-        /* A synchronous command can not have a callback set. */
-       BUG_ON(cmd->meta.u.callback != NULL);
-
-       if (atomic_xchg(&entry, 1)) {
-               IWL_ERROR("Error sending %s: Already sending a host command\n",
-                         get_cmd_string(cmd->id));
-               return -EBUSY;
-       }
-
-       set_bit(STATUS_HCMD_ACTIVE, &priv->status);
-
-       if (cmd->meta.flags & CMD_WANT_SKB)
-               cmd->meta.source = &cmd->meta;
-
-       cmd_idx = iwl4965_enqueue_hcmd(priv, cmd);
-       if (cmd_idx < 0) {
-               ret = cmd_idx;
-               IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
-                         get_cmd_string(cmd->id), ret);
-               goto out;
-       }
-
-       ret = wait_event_interruptible_timeout(priv->wait_command_queue,
-                       !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
-                       HOST_COMPLETE_TIMEOUT);
-       if (!ret) {
-               if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
-                       IWL_ERROR("Error sending %s: time out after %dms.\n",
-                                 get_cmd_string(cmd->id),
-                                 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
-
-                       clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
-                       ret = -ETIMEDOUT;
-                       goto cancel;
-               }
-       }
-
-       if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
-               IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
-                              get_cmd_string(cmd->id));
-               ret = -ECANCELED;
-               goto fail;
-       }
-       if (test_bit(STATUS_FW_ERROR, &priv->status)) {
-               IWL_DEBUG_INFO("Command %s failed: FW Error\n",
-                              get_cmd_string(cmd->id));
-               ret = -EIO;
-               goto fail;
-       }
-       if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
-               IWL_ERROR("Error: Response NULL in '%s'\n",
-                         get_cmd_string(cmd->id));
-               ret = -EIO;
-               goto out;
-       }
-
-       ret = 0;
-       goto out;
-
-cancel:
-       if (cmd->meta.flags & CMD_WANT_SKB) {
-               struct iwl4965_cmd *qcmd;
-
-               /* Cancel the CMD_WANT_SKB flag for the cmd in the
-                * TX cmd queue. Otherwise in case the cmd comes
-                * in later, it will possibly set an invalid
-                * address (cmd->meta.source). */
-               qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
-               qcmd->meta.flags &= ~CMD_WANT_SKB;
-       }
-fail:
-       if (cmd->meta.u.skb) {
-               dev_kfree_skb_any(cmd->meta.u.skb);
-               cmd->meta.u.skb = NULL;
-       }
-out:
-       atomic_set(&entry, 0);
-       return ret;
-}
-
 static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
 {
        struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
@@ -807,41 +596,6 @@ static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
 
 }
 
-int iwl4965_send_cmd(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
-{
-       if (cmd->meta.flags & CMD_ASYNC)
-               return iwl4965_send_cmd_async(priv, cmd);
-
-       return iwl4965_send_cmd_sync(priv, cmd);
-}
-
-int iwl4965_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, const void *data)
-{
-       struct iwl4965_host_cmd cmd = {
-               .id = id,
-               .len = len,
-               .data = data,
-       };
-
-       return iwl4965_send_cmd_sync(priv, &cmd);
-}
-
-static int __must_check iwl4965_send_cmd_u32(struct iwl_priv *priv, u8 id, u32 val)
-{
-       struct iwl4965_host_cmd cmd = {
-               .id = id,
-               .len = sizeof(val),
-               .data = &val,
-       };
-
-       return iwl4965_send_cmd_sync(priv, &cmd);
-}
-
-int iwl4965_send_statistics_request(struct iwl_priv *priv)
-{
-       return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
-}
-
 /**
  * iwl4965_rxon_add_station - add station into station table.
  *
@@ -995,60 +749,6 @@ static int iwl4965_full_rxon_required(struct iwl_priv *priv)
        return 0;
 }
 
-static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
-{
-       int rc = 0;
-       struct iwl4965_rx_packet *res = NULL;
-       struct iwl4965_rxon_assoc_cmd rxon_assoc;
-       struct iwl4965_host_cmd cmd = {
-               .id = REPLY_RXON_ASSOC,
-               .len = sizeof(rxon_assoc),
-               .meta.flags = CMD_WANT_SKB,
-               .data = &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;
-
-       rc = iwl4965_send_cmd_sync(priv, &cmd);
-       if (rc)
-               return rc;
-
-       res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
-       if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
-               IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
-               rc = -EIO;
-       }
-
-       priv->alloc_rxb_skb--;
-       dev_kfree_skb_any(cmd.meta.u.skb);
-
-       return rc;
-}
-
 /**
  * iwl4965_commit_rxon - commit staging_rxon to hardware
  *
@@ -1064,7 +764,7 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
        DECLARE_MAC_BUF(mac);
        int rc = 0;
 
-       if (!iwl4965_is_alive(priv))
+       if (!iwl_is_alive(priv))
                return -1;
 
        /* always get timestamp with Rx frame */
@@ -1080,7 +780,7 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
         * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
         * and other flags for the current radio configuration. */
        if (!iwl4965_full_rxon_required(priv)) {
-               rc = iwl4965_send_rxon_assoc(priv);
+               rc = iwl_send_rxon_assoc(priv);
                if (rc) {
                        IWL_ERROR("Error setting RXON_ASSOC "
                                  "configuration (%d).\n", rc);
@@ -1107,12 +807,12 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
         * an RXON_ASSOC and the new config wants the associated mask enabled,
         * we must clear the associated from the active configuration
         * before we apply the new config */
-       if (iwl4965_is_associated(priv) &&
+       if (iwl_is_associated(priv) &&
            (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
                IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
                active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
 
-               rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
+               rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
                                      sizeof(struct iwl4965_rxon_cmd),
                                      &priv->active_rxon);
 
@@ -1135,9 +835,9 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
                       le16_to_cpu(priv->staging_rxon.channel),
                       print_mac(mac, priv->staging_rxon.bssid_addr));
 
-       iwl4965_set_rxon_hwcrypto(priv, priv->cfg->mod_params->hw_crypto);
+       iwl4965_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto);
        /* Apply the new configuration */
-       rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
+       rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
                              sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon);
        if (rc) {
                IWL_ERROR("Error setting new configuration (%d).\n", rc);
@@ -1173,7 +873,7 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
 
        /* If we have set the ASSOC_MSK and we are in BSS mode then
         * add the IWL_AP_ID to the station rate table */
-       if (iwl4965_is_associated(priv) &&
+       if (iwl_is_associated(priv) &&
            (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
                if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
                    == IWL_INVALID_STATION) {
@@ -1181,6 +881,9 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
                        return -EIO;
                }
                priv->assoc_station_added = 1;
+               if (priv->default_wep_key &&
+                   iwl_send_static_wepkey_cmd(priv, 0))
+                       IWL_ERROR("Could not send WEP static key.\n");
        }
 
        return 0;
@@ -1196,7 +899,7 @@ static int iwl4965_send_bt_config(struct iwl_priv *priv)
                .kill_cts_mask = 0,
        };
 
-       return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG,
+       return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
                                sizeof(struct iwl4965_bt_cmd), &bt_cmd);
 }
 
@@ -1204,7 +907,7 @@ static int iwl4965_send_scan_abort(struct iwl_priv *priv)
 {
        int rc = 0;
        struct iwl4965_rx_packet *res;
-       struct iwl4965_host_cmd cmd = {
+       struct iwl_host_cmd cmd = {
                .id = REPLY_SCAN_ABORT_CMD,
                .meta.flags = CMD_WANT_SKB,
        };
@@ -1217,7 +920,7 @@ static int iwl4965_send_scan_abort(struct iwl_priv *priv)
                return 0;
        }
 
-       rc = iwl4965_send_cmd_sync(priv, &cmd);
+       rc = iwl_send_cmd_sync(priv, &cmd);
        if (rc) {
                clear_bit(STATUS_SCAN_ABORTING, &priv->status);
                return rc;
@@ -1242,7 +945,7 @@ static int iwl4965_send_scan_abort(struct iwl_priv *priv)
 }
 
 static int iwl4965_card_state_sync_callback(struct iwl_priv *priv,
-                                       struct iwl4965_cmd *cmd,
+                                       struct iwl_cmd *cmd,
                                        struct sk_buff *skb)
 {
        return 1;
@@ -1260,7 +963,7 @@ static int iwl4965_card_state_sync_callback(struct iwl_priv *priv,
  */
 static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
 {
-       struct iwl4965_host_cmd cmd = {
+       struct iwl_host_cmd cmd = {
                .id = REPLY_CARD_STATE_CMD,
                .len = sizeof(u32),
                .data = &flags,
@@ -1270,11 +973,11 @@ static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_fla
        if (meta_flag & CMD_ASYNC)
                cmd.meta.u.callback = iwl4965_card_state_sync_callback;
 
-       return iwl4965_send_cmd(priv, &cmd);
+       return iwl_send_cmd(priv, &cmd);
 }
 
 static int iwl4965_add_sta_sync_callback(struct iwl_priv *priv,
-                                    struct iwl4965_cmd *cmd, struct sk_buff *skb)
+                                    struct iwl_cmd *cmd, struct sk_buff *skb)
 {
        struct iwl4965_rx_packet *res = NULL;
 
@@ -1306,7 +1009,7 @@ int iwl4965_send_add_station(struct iwl_priv *priv,
 {
        struct iwl4965_rx_packet *res = NULL;
        int rc = 0;
-       struct iwl4965_host_cmd cmd = {
+       struct iwl_host_cmd cmd = {
                .id = REPLY_ADD_STA,
                .len = sizeof(struct iwl4965_addsta_cmd),
                .meta.flags = flags,
@@ -1318,7 +1021,7 @@ int iwl4965_send_add_station(struct iwl_priv *priv,
        else
                cmd.meta.flags |= CMD_WANT_SKB;
 
-       rc = iwl4965_send_cmd(priv, &cmd);
+       rc = iwl_send_cmd(priv, &cmd);
 
        if (rc || (flags & CMD_ASYNC))
                return rc;
@@ -1348,111 +1051,6 @@ int iwl4965_send_add_station(struct iwl_priv *priv,
        return rc;
 }
 
-static int iwl4965_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
-                                  struct ieee80211_key_conf *keyconf,
-                                  u8 sta_id)
-{
-       unsigned long flags;
-       __le16 key_flags = 0;
-
-       key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
-       key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
-
-       if (sta_id == priv->hw_setting.bcast_sta_id)
-               key_flags |= STA_KEY_MULTICAST_MSK;
-
-       keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
-       keyconf->hw_key_idx = keyconf->keyidx;
-
-       key_flags &= ~STA_KEY_FLG_INVALID;
-
-       spin_lock_irqsave(&priv->sta_lock, flags);
-       priv->stations[sta_id].keyinfo.alg = keyconf->alg;
-       priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
-
-       memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
-              keyconf->keylen);
-
-       memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
-              keyconf->keylen);
-
-       priv->stations[sta_id].sta.key.key_offset
-                       = (sta_id % STA_KEY_MAX_NUM);/*FIXME*/
-       priv->stations[sta_id].sta.key.key_flags = key_flags;
-       priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
-       priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
-
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
-
-       IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
-       return iwl4965_send_add_station(priv,
-                               &priv->stations[sta_id].sta, CMD_ASYNC);
-}
-
-static int iwl4965_set_tkip_dynamic_key_info(struct iwl_priv *priv,
-                                  struct ieee80211_key_conf *keyconf,
-                                  u8 sta_id)
-{
-       return -EOPNOTSUPP;
-}
-
-static int iwl4965_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&priv->sta_lock, flags);
-       memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key));
-       memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo));
-       priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
-       priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
-       priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
-
-       IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
-       iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
-       return 0;
-}
-
-static int iwl4965_set_dynamic_key(struct iwl_priv *priv,
-                               struct ieee80211_key_conf *key, u8 sta_id)
-{
-       int ret;
-
-       switch (key->alg) {
-       case ALG_CCMP:
-               ret = iwl4965_set_ccmp_dynamic_key_info(priv, key, sta_id);
-               break;
-       case ALG_TKIP:
-               ret = iwl4965_set_tkip_dynamic_key_info(priv, key, sta_id);
-               break;
-       case ALG_WEP:
-               ret = -EOPNOTSUPP;
-               break;
-       default:
-               IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, key->alg);
-               ret = -EINVAL;
-       }
-
-       return ret;
-}
-
-static int iwl4965_remove_static_key(struct iwl_priv *priv)
-{
-       int ret = -EOPNOTSUPP;
-
-       return ret;
-}
-
-static int iwl4965_set_static_key(struct iwl_priv *priv,
-                               struct ieee80211_key_conf *key)
-{
-       if (key->alg == ALG_WEP)
-               return -EOPNOTSUPP;
-
-       IWL_ERROR("Static key invalid: alg %d\n", key->alg);
-       return -EINVAL;
-}
-
 static void iwl4965_clear_free_frames(struct iwl_priv *priv)
 {
        struct list_head *element;
@@ -1505,7 +1103,7 @@ unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
                                const u8 *dest, int left)
 {
 
-       if (!iwl4965_is_associated(priv) || !priv->ibss_beacon ||
+       if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
            ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
             (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
                return 0;
@@ -1559,7 +1157,7 @@ static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
 
        frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
 
-       rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
+       rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
                              &frame->u.cmd[0]);
 
        iwl4965_free_frame(priv, frame);
@@ -1573,13 +1171,13 @@ static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
  *
  ******************************************************************************/
 
-static void iwl4965_unset_hw_setting(struct iwl_priv *priv)
+static void iwl4965_unset_hw_params(struct iwl_priv *priv)
 {
-       if (priv->hw_setting.shared_virt)
+       if (priv->shared_virt)
                pci_free_consistent(priv->pci_dev,
                                    sizeof(struct iwl4965_shared),
-                                   priv->hw_setting.shared_virt,
-                                   priv->hw_setting.shared_phys);
+                                   priv->shared_virt,
+                                   priv->shared_phys);
 }
 
 /**
@@ -1736,7 +1334,7 @@ static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
                                       struct iwl4965_qosparam_cmd *qos)
 {
 
-       return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM,
+       return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
                                sizeof(struct iwl4965_qosparam_cmd), qos);
 }
 
@@ -1768,7 +1366,7 @@ static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
 
        spin_unlock_irqrestore(&priv->lock, flags);
 
-       if (force || iwl4965_is_associated(priv)) {
+       if (force || iwl_is_associated(priv)) {
                IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
                                priv->qos_data.qos_active,
                                priv->qos_data.def_qos_parm.qos_flags);
@@ -1946,7 +1544,7 @@ static int iwl4965_send_power_mode(struct iwl_priv *priv, u32 mode)
 
        iwl4965_update_power_cmd(priv, &cmd, final_mode);
 
-       rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
+       rc = iwl_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
 
        if (final_mode == IWL_POWER_MODE_CAM)
                clear_bit(STATUS_POWER_PMI, &priv->status);
@@ -1979,6 +1577,8 @@ int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *heade
                        return !compare_ether_addr(header->addr2, priv->bssid);
                /* packets to our adapter go through */
                return !compare_ether_addr(header->addr1, priv->mac_addr);
+       default:
+               break;
        }
 
        return 1;
@@ -2105,13 +1705,13 @@ static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
        conf = ieee80211_get_hw_conf(priv->hw);
 
        spin_lock_irqsave(&priv->lock, flags);
-       priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1);
-       priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0);
+       priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
+       priv->rxon_timing.timestamp.dw[0] =
+                               cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
 
        priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
 
-       tsf = priv->timestamp1;
-       tsf = ((tsf << 32) | priv->timestamp0);
+       tsf = priv->timestamp;
 
        beacon_int = priv->beacon_int;
        spin_unlock_irqrestore(&priv->lock, flags);
@@ -2157,7 +1757,7 @@ static int iwl4965_scan_initiate(struct iwl_priv *priv)
                return 0;
        }
 
-       if (!iwl4965_is_ready_rf(priv)) {
+       if (!iwl_is_ready_rf(priv)) {
                IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
                return -EIO;
        }
@@ -2194,7 +1794,7 @@ static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv,
                      | RXON_FLG_CCK_MSK);
                priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
        } else {
-               /* Copied from iwl4965_bg_post_associate() */
+               /* Copied from iwl4965_post_associate() */
                if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
                        priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
                else
@@ -2240,6 +1840,9 @@ static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
                priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
                    RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
                break;
+       default:
+               IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
+               break;
        }
 
 #if 0
@@ -2251,7 +1854,7 @@ static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
                priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
 #endif
 
-       ch_info = iwl4965_get_channel_info(priv, priv->band,
+       ch_info = iwl_get_channel_info(priv, priv->band,
                                       le16_to_cpu(priv->staging_rxon.channel));
 
        if (!ch_info)
@@ -2289,7 +1892,7 @@ static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
        if (mode == IEEE80211_IF_TYPE_IBSS) {
                const struct iwl_channel_info *ch_info;
 
-               ch_info = iwl4965_get_channel_info(priv,
+               ch_info = iwl_get_channel_info(priv,
                        priv->band,
                        le16_to_cpu(priv->staging_rxon.channel));
 
@@ -2308,7 +1911,7 @@ static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
        iwlcore_clear_stations_table(priv);
 
        /* dont commit rxon if rf-kill is on*/
-       if (!iwl4965_is_ready_rf(priv))
+       if (!iwl_is_ready_rf(priv))
                return -EAGAIN;
 
        cancel_delayed_work(&priv->scan_check);
@@ -2325,11 +1928,15 @@ static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
 
 static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
                                      struct ieee80211_tx_control *ctl,
-                                     struct iwl4965_cmd *cmd,
+                                     struct iwl_cmd *cmd,
                                      struct sk_buff *skb_frag,
                                      int sta_id)
 {
        struct iwl4965_hw_key *keyinfo = &priv->stations[sta_id].keyinfo;
+       struct iwl_wep_key *wepkey;
+       int keyidx = 0;
+
+       BUG_ON(ctl->key_idx > 3);
 
        switch (keyinfo->alg) {
        case ALG_CCMP:
@@ -2341,28 +1948,36 @@ static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
                break;
 
        case ALG_TKIP:
-#if 0
                cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
-
-               if (last_frag)
-                       memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
-                              8);
-               else
-                       memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
-#endif
+               ieee80211_get_tkip_key(keyinfo->conf, skb_frag,
+                       IEEE80211_TKIP_P2_KEY, cmd->cmd.tx.key);
+               IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
                break;
 
        case ALG_WEP:
-               cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
-                       (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
-
-               if (keyinfo->keylen == 13)
-                       cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
+               wepkey = &priv->wep_keys[ctl->key_idx];
+               cmd->cmd.tx.sec_ctl = 0;
+               if (priv->default_wep_key) {
+                       /* the WEP key was sent as static */
+                       keyidx = ctl->key_idx;
+                       memcpy(&cmd->cmd.tx.key[3], wepkey->key,
+                                                       wepkey->key_size);
+                       if (wepkey->key_size == WEP_KEY_LEN_128)
+                               cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
+               } else {
+                       /* the WEP key was sent as dynamic */
+                       keyidx = keyinfo->keyidx;
+                       memcpy(&cmd->cmd.tx.key[3], keyinfo->key,
+                                                       keyinfo->keylen);
+                       if (keyinfo->keylen == WEP_KEY_LEN_128)
+                               cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
+               }
 
-               memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
+               cmd->cmd.tx.sec_ctl |= (TX_CMD_SEC_WEP |
+                       (keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT);
 
                IWL_DEBUG_TX("Configuring packet for WEP encryption "
-                            "with key %d\n", ctl->key_idx);
+                            "with key %d\n", keyidx);
                break;
 
        default:
@@ -2375,7 +1990,7 @@ static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
  * handle build REPLY_TX command notification.
  */
 static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv,
-                                 struct iwl4965_cmd *cmd,
+                                 struct iwl_cmd *cmd,
                                  struct ieee80211_tx_control *ctrl,
                                  struct ieee80211_hdr *hdr,
                                  int is_unicast, u8 std_id)
@@ -2430,8 +2045,9 @@ static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv,
                        cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
                else
                        cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
-       } else
+       } else {
                cmd->cmd.tx.timeout.pm_frame_timeout = 0;
+       }
 
        cmd->cmd.tx.driver_txop = 0;
        cmd->cmd.tx.tx_flags = tx_flags;
@@ -2459,7 +2075,7 @@ static int iwl4965_get_sta_id(struct iwl_priv *priv,
        /* If this frame is broadcast or management, use broadcast station id */
        if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
            is_multicast_ether_addr(hdr->addr1))
-               return priv->hw_setting.bcast_sta_id;
+               return priv->hw_params.bcast_sta_id;
 
        switch (priv->iw_mode) {
 
@@ -2473,7 +2089,7 @@ static int iwl4965_get_sta_id(struct iwl_priv *priv,
                sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
                if (sta_id != IWL_INVALID_STATION)
                        return sta_id;
-               return priv->hw_setting.bcast_sta_id;
+               return priv->hw_params.bcast_sta_id;
 
        /* If this frame is going out to an IBSS network, find the station,
         * or create a new station table entry */
@@ -2493,11 +2109,11 @@ static int iwl4965_get_sta_id(struct iwl_priv *priv,
                               "Defaulting to broadcast...\n",
                               print_mac(mac, hdr->addr1));
                iwl_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
-               return priv->hw_setting.bcast_sta_id;
+               return priv->hw_params.bcast_sta_id;
 
        default:
                IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
-               return priv->hw_setting.bcast_sta_id;
+               return priv->hw_params.bcast_sta_id;
        }
 }
 
@@ -2516,7 +2132,7 @@ static int iwl4965_tx_skb(struct iwl_priv *priv,
        dma_addr_t phys_addr;
        dma_addr_t txcmd_phys;
        dma_addr_t scratch_phys;
-       struct iwl4965_cmd *out_cmd = NULL;
+       struct iwl_cmd *out_cmd = NULL;
        u16 len, idx, len_org;
        u8 id, hdr_len, unicast;
        u8 sta_id;
@@ -2528,7 +2144,7 @@ static int iwl4965_tx_skb(struct iwl_priv *priv,
        int rc;
 
        spin_lock_irqsave(&priv->lock, flags);
-       if (iwl4965_is_rfkill(priv)) {
+       if (iwl_is_rfkill(priv)) {
                IWL_DEBUG_DROP("Dropping - RF KILL\n");
                goto drop_unlock;
        }
@@ -2559,10 +2175,10 @@ static int iwl4965_tx_skb(struct iwl_priv *priv,
 
        /* drop all data frame if we are not associated */
        if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
-          (!iwl4965_is_associated(priv) ||
+          (!iwl_is_associated(priv) ||
            ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) ||
            !priv->assoc_station_added)) {
-               IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n");
+               IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n");
                goto drop_unlock;
        }
 
@@ -2644,8 +2260,8 @@ static int iwl4965_tx_skb(struct iwl_priv *priv,
         * of the MAC header (device reads on dword boundaries).
         * We'll tell device about this padding later.
         */
-       len = priv->hw_setting.tx_cmd_len +
-               sizeof(struct iwl4965_cmd_header) + hdr_len;
+       len = priv->hw_params.tx_cmd_len +
+               sizeof(struct iwl_cmd_header) + hdr_len;
 
        len_org = len;
        len = (len + 3) & ~3;
@@ -2657,8 +2273,8 @@ static int iwl4965_tx_skb(struct iwl_priv *priv,
 
        /* Physical address of this Tx command's header (not MAC header!),
         * within command buffer array. */
-       txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx +
-                    offsetof(struct iwl4965_cmd, hdr);
+       txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx +
+                    offsetof(struct iwl_cmd, hdr);
 
        /* Add buffer containing Tx command and MAC(!) header to TFD's
         * first entry */
@@ -2692,7 +2308,7 @@ static int iwl4965_tx_skb(struct iwl_priv *priv,
 
        iwl_update_tx_stats(priv, fc, len);
 
-       scratch_phys = txcmd_phys + sizeof(struct iwl4965_cmd_header) +
+       scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) +
                offsetof(struct iwl4965_tx_cmd, scratch);
        out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys);
        out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys);
@@ -2715,7 +2331,7 @@ static int iwl4965_tx_skb(struct iwl_priv *priv,
                           ieee80211_get_hdrlen(fc));
 
        /* Set up entry for this TFD in Tx byte-count array */
-       iwl4965_tx_queue_update_wr_ptr(priv, txq, len);
+       priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, len);
 
        /* Tell device the write index *just past* this latest filled TFD */
        q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
@@ -2792,7 +2408,7 @@ static void iwl4965_set_rate(struct iwl_priv *priv)
                   (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
 }
 
-static void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
+void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
 {
        unsigned long flags;
 
@@ -2807,17 +2423,26 @@ static void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
                /* FIXME: This is a workaround for AP */
                if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
                        spin_lock_irqsave(&priv->lock, flags);
-                       iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
+                       iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
                                    CSR_UCODE_SW_BIT_RFKILL);
                        spin_unlock_irqrestore(&priv->lock, flags);
-                       iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
+                       /* call the host command only if no hw rf-kill set */
+                       if (!test_bit(STATUS_RF_KILL_HW, &priv->status) &&
+                           iwl_is_ready(priv))
+                               iwl4965_send_card_state(priv,
+                                                       CARD_STATE_CMD_DISABLE,
+                                                       0);
                        set_bit(STATUS_RF_KILL_SW, &priv->status);
+
+                       /* make sure mac80211 stop sending Tx frame */
+                       if (priv->mac80211_registered)
+                               ieee80211_stop_queues(priv->hw);
                }
                return;
        }
 
        spin_lock_irqsave(&priv->lock, flags);
-       iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
+       iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
 
        clear_bit(STATUS_RF_KILL_SW, &priv->status);
        spin_unlock_irqrestore(&priv->lock, flags);
@@ -2826,9 +2451,9 @@ static void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
        msleep(10);
 
        spin_lock_irqsave(&priv->lock, flags);
-       iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
-       if (!iwl4965_grab_nic_access(priv))
-               iwl4965_release_nic_access(priv);
+       iwl_read32(priv, CSR_UCODE_DRV_GP1);
+       if (!iwl_grab_nic_access(priv))
+               iwl_release_nic_access(priv);
        spin_unlock_irqrestore(&priv->lock, flags);
 
        if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
@@ -3005,7 +2630,7 @@ static int iwl4965_get_measurement(struct iwl_priv *priv,
 {
        struct iwl4965_spectrum_cmd spectrum;
        struct iwl4965_rx_packet *res;
-       struct iwl4965_host_cmd cmd = {
+       struct iwl_host_cmd cmd = {
                .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
                .data = (void *)&spectrum,
                .meta.flags = CMD_WANT_SKB,
@@ -3015,7 +2640,7 @@ static int iwl4965_get_measurement(struct iwl_priv *priv,
        int spectrum_resp_status;
        int duration = le16_to_cpu(params->duration);
 
-       if (iwl4965_is_associated(priv))
+       if (iwl_is_associated(priv))
                add_time =
                    iwl4965_usecs_to_beacons(
                        le64_to_cpu(params->start_time) - priv->last_tsf,
@@ -3030,7 +2655,7 @@ static int iwl4965_get_measurement(struct iwl_priv *priv,
        cmd.len = sizeof(spectrum);
        spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
 
-       if (iwl4965_is_associated(priv))
+       if (iwl_is_associated(priv))
                spectrum.start_time =
                    iwl4965_add_beacon_time(priv->last_beacon_time,
                                add_time,
@@ -3045,7 +2670,7 @@ static int iwl4965_get_measurement(struct iwl_priv *priv,
                spectrum.flags |= RXON_FLG_BAND_24G_MSK |
                    RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
 
-       rc = iwl4965_send_cmd_sync(priv, &cmd);
+       rc = iwl_send_cmd_sync(priv, &cmd);
        if (rc)
                return rc;
 
@@ -3296,7 +2921,7 @@ static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
                agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
                IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
                                   agg->frame_count, agg->start_idx,
-                                  agg->bitmap);
+                                  (unsigned long long)agg->bitmap);
 
                if (bitmap)
                        agg->wait_for_ba = 1;
@@ -3705,35 +3330,35 @@ static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
        if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
                     RF_CARD_DISABLED)) {
 
-               iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
+               iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
                            CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
 
-               if (!iwl4965_grab_nic_access(priv)) {
-                       iwl4965_write_direct32(
+               if (!iwl_grab_nic_access(priv)) {
+                       iwl_write_direct32(
                                priv, HBUS_TARG_MBX_C,
                                HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
 
-                       iwl4965_release_nic_access(priv);
+                       iwl_release_nic_access(priv);
                }
 
                if (!(flags & RXON_CARD_DISABLED)) {
-                       iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
+                       iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
                                    CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
-                       if (!iwl4965_grab_nic_access(priv)) {
-                               iwl4965_write_direct32(
+                       if (!iwl_grab_nic_access(priv)) {
+                               iwl_write_direct32(
                                        priv, HBUS_TARG_MBX_C,
                                        HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
 
-                               iwl4965_release_nic_access(priv);
+                               iwl_release_nic_access(priv);
                        }
                }
 
                if (flags & RF_CARD_DISABLED) {
-                       iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
+                       iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
                                    CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
-                       iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
-                       if (!iwl4965_grab_nic_access(priv))
-                               iwl4965_release_nic_access(priv);
+                       iwl_read32(priv, CSR_UCODE_DRV_GP1);
+                       if (!iwl_grab_nic_access(priv))
+                               iwl_release_nic_access(priv);
                }
        }
 
@@ -3820,7 +3445,7 @@ static void iwl4965_tx_cmd_complete(struct iwl_priv *priv,
        int index = SEQ_TO_INDEX(sequence);
        int huge = sequence & SEQ_HUGE_FRAME;
        int cmd_index;
-       struct iwl4965_cmd *cmd;
+       struct iwl_cmd *cmd;
 
        /* If a Tx command is being handled and it isn't in the actual
         * command queue then there a command routing bug has been introduced
@@ -3947,27 +3572,27 @@ int iwl4965_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl4965_rx_q
 
        /* If power-saving is in use, make sure device is awake */
        if (test_bit(STATUS_POWER_PMI, &priv->status)) {
-               reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
+               reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
 
                if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
-                       iwl4965_set_bit(priv, CSR_GP_CNTRL,
+                       iwl_set_bit(priv, CSR_GP_CNTRL,
                                    CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
                        goto exit_unlock;
                }
 
-               rc = iwl4965_grab_nic_access(priv);
+               rc = iwl_grab_nic_access(priv);
                if (rc)
                        goto exit_unlock;
 
                /* Device expects a multiple of 8 */
-               iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
+               iwl_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
                                     q->write & ~0x7);
-               iwl4965_release_nic_access(priv);
+               iwl_release_nic_access(priv);
 
        /* Else device is assumed to be awake */
        } else
                /* Device expects a multiple of 8 */
-               iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
+               iwl_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
 
 
        q->need_update = 0;
@@ -4063,7 +3688,7 @@ static void iwl4965_rx_allocate(struct iwl_priv *priv)
 
                /* Alloc a new receive buffer */
                rxb->skb =
-                   alloc_skb(priv->hw_setting.rx_buf_size,
+                   alloc_skb(priv->hw_params.rx_buf_size,
                                __GFP_NOWARN | GFP_ATOMIC);
                if (!rxb->skb) {
                        if (net_ratelimit())
@@ -4080,7 +3705,7 @@ static void iwl4965_rx_allocate(struct iwl_priv *priv)
                /* Get physical address of RB/SKB */
                rxb->dma_addr =
                    pci_map_single(priv->pci_dev, rxb->skb->data,
-                          priv->hw_setting.rx_buf_size, PCI_DMA_FROMDEVICE);
+                          priv->hw_params.rx_buf_size, PCI_DMA_FROMDEVICE);
                list_add_tail(&rxb->list, &rxq->rx_free);
                rxq->free_count++;
        }
@@ -4123,7 +3748,7 @@ static void iwl4965_rx_queue_free(struct iwl_priv *priv, struct iwl4965_rx_queue
                if (rxq->pool[i].skb != NULL) {
                        pci_unmap_single(priv->pci_dev,
                                         rxq->pool[i].dma_addr,
-                                        priv->hw_setting.rx_buf_size,
+                                        priv->hw_params.rx_buf_size,
                                         PCI_DMA_FROMDEVICE);
                        dev_kfree_skb(rxq->pool[i].skb);
                }
@@ -4175,7 +3800,7 @@ void iwl4965_rx_queue_reset(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
                if (rxq->pool[i].skb != NULL) {
                        pci_unmap_single(priv->pci_dev,
                                         rxq->pool[i].dma_addr,
-                                        priv->hw_setting.rx_buf_size,
+                                        priv->hw_params.rx_buf_size,
                                         PCI_DMA_FROMDEVICE);
                        priv->alloc_rxb_skb--;
                        dev_kfree_skb(rxq->pool[i].skb);
@@ -4310,7 +3935,7 @@ static void iwl4965_rx_handle(struct iwl_priv *priv)
                rxq->queue[i] = NULL;
 
                pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
-                                           priv->hw_setting.rx_buf_size,
+                                           priv->hw_params.rx_buf_size,
                                            PCI_DMA_FROMDEVICE);
                pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
 
@@ -4322,7 +3947,7 @@ static void iwl4965_rx_handle(struct iwl_priv *priv)
                 *   but apparently a few don't get set; catch them here. */
                reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
                        (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
-                       (pkt->hdr.cmd != REPLY_4965_RX) &&
+                       (pkt->hdr.cmd != REPLY_RX) &&
                        (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
                        (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
                        (pkt->hdr.cmd != REPLY_TX);
@@ -4345,7 +3970,7 @@ static void iwl4965_rx_handle(struct iwl_priv *priv)
 
                if (reclaim) {
                        /* Invoke any callbacks, transfer the skb to caller, and
-                        * fire off the (possibly) blocking iwl4965_send_cmd()
+                        * fire off the (possibly) blocking iwl_send_cmd()
                         * as we reclaim the driver command queue */
                        if (rxb && rxb->skb)
                                iwl4965_tx_cmd_complete(priv, rxb);
@@ -4363,7 +3988,7 @@ static void iwl4965_rx_handle(struct iwl_priv *priv)
                }
 
                pci_unmap_single(priv->pci_dev, rxb->dma_addr,
-                                priv->hw_setting.rx_buf_size,
+                                priv->hw_params.rx_buf_size,
                                 PCI_DMA_FROMDEVICE);
                spin_lock_irqsave(&rxq->lock, flags);
                list_add_tail(&rxb->list, &priv->rxq.rx_used);
@@ -4404,27 +4029,27 @@ static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
                /* wake up nic if it's powered down ...
                 * uCode will wake up, and interrupt us again, so next
                 * time we'll skip this part. */
-               reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
+               reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
 
                if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
                        IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
-                       iwl4965_set_bit(priv, CSR_GP_CNTRL,
+                       iwl_set_bit(priv, CSR_GP_CNTRL,
                                    CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
                        return rc;
                }
 
                /* restore this queue's parameters in nic hardware. */
-               rc = iwl4965_grab_nic_access(priv);
+               rc = iwl_grab_nic_access(priv);
                if (rc)
                        return rc;
-               iwl4965_write_direct32(priv, HBUS_TARG_WRPTR,
+               iwl_write_direct32(priv, HBUS_TARG_WRPTR,
                                     txq->q.write_ptr | (txq_id << 8));
-               iwl4965_release_nic_access(priv);
+               iwl_release_nic_access(priv);
 
        /* else not in power-save mode, uCode will never sleep when we're
         * trying to tx (during RFKILL, we're not trying to tx). */
        } else
-               iwl4965_write32(priv, HBUS_TARG_WRPTR,
+               iwl_write32(priv, HBUS_TARG_WRPTR,
                            txq->q.write_ptr | (txq_id << 8));
 
        txq->need_update = 0;
@@ -4459,7 +4084,15 @@ static void iwl4965_enable_interrupts(struct iwl_priv *priv)
 {
        IWL_DEBUG_ISR("Enabling interrupts\n");
        set_bit(STATUS_INT_ENABLED, &priv->status);
-       iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
+       iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
+}
+
+/* call this function to flush any scheduled tasklet */
+static inline void iwl_synchronize_irq(struct iwl_priv *priv)
+{
+       /* wait to make sure we flush pedding tasklet*/
+       synchronize_irq(priv->pci_dev->irq);
+       tasklet_kill(&priv->irq_tasklet);
 }
 
 static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
@@ -4467,12 +4100,12 @@ static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
        clear_bit(STATUS_INT_ENABLED, &priv->status);
 
        /* disable interrupts from uCode/NIC to host */
-       iwl4965_write32(priv, CSR_INT_MASK, 0x00000000);
+       iwl_write32(priv, CSR_INT_MASK, 0x00000000);
 
        /* acknowledge/clear/reset any interrupts still pending
         * from uCode or flow handler (Rx/Tx DMA) */
-       iwl4965_write32(priv, CSR_INT, 0xffffffff);
-       iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
+       iwl_write32(priv, CSR_INT, 0xffffffff);
+       iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
        IWL_DEBUG_ISR("Disabled interrupts\n");
 }
 
@@ -4508,33 +4141,33 @@ static void iwl4965_dump_nic_error_log(struct iwl_priv *priv)
 
        base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
 
-       if (!iwl4965_hw_valid_rtc_data_addr(base)) {
+       if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
                IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
                return;
        }
 
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (rc) {
                IWL_WARNING("Can not read from adapter at this time.\n");
                return;
        }
 
-       count = iwl4965_read_targ_mem(priv, base);
+       count = iwl_read_targ_mem(priv, base);
 
        if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
                IWL_ERROR("Start IWL Error Log Dump:\n");
                IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count);
        }
 
-       desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32));
-       blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32));
-       blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32));
-       ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32));
-       ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32));
-       data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32));
-       data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32));
-       line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32));
-       time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32));
+       desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
+       blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
+       blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
+       ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
+       ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
+       data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
+       data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
+       line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
+       time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
 
        IWL_ERROR("Desc               Time       "
                  "data1      data2      line\n");
@@ -4544,7 +4177,7 @@ static void iwl4965_dump_nic_error_log(struct iwl_priv *priv)
        IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
                  ilink1, ilink2);
 
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
 }
 
 #define EVENT_START_OFFSET  (4 * sizeof(u32))
@@ -4552,7 +4185,7 @@ static void iwl4965_dump_nic_error_log(struct iwl_priv *priv)
 /**
  * iwl4965_print_event_log - Dump error event log to syslog
  *
- * NOTE: Must be called with iwl4965_grab_nic_access() already obtained!
+ * NOTE: Must be called with iwl_grab_nic_access() already obtained!
  */
 static void iwl4965_print_event_log(struct iwl_priv *priv, u32 start_idx,
                                u32 num_events, u32 mode)
@@ -4578,14 +4211,14 @@ static void iwl4965_print_event_log(struct iwl_priv *priv, u32 start_idx,
        /* "time" is actually "data" for mode 0 (no timestamp).
         * place event id # at far right for easier visual parsing. */
        for (i = 0; i < num_events; i++) {
-               ev = iwl4965_read_targ_mem(priv, ptr);
+               ev = iwl_read_targ_mem(priv, ptr);
                ptr += sizeof(u32);
-               time = iwl4965_read_targ_mem(priv, ptr);
+               time = iwl_read_targ_mem(priv, ptr);
                ptr += sizeof(u32);
                if (mode == 0)
                        IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
                else {
-                       data = iwl4965_read_targ_mem(priv, ptr);
+                       data = iwl_read_targ_mem(priv, ptr);
                        ptr += sizeof(u32);
                        IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
                }
@@ -4603,29 +4236,29 @@ static void iwl4965_dump_nic_event_log(struct iwl_priv *priv)
        u32 size;       /* # entries that we'll print */
 
        base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
-       if (!iwl4965_hw_valid_rtc_data_addr(base)) {
+       if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
                IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
                return;
        }
 
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (rc) {
                IWL_WARNING("Can not read from adapter at this time.\n");
                return;
        }
 
        /* event log header */
-       capacity = iwl4965_read_targ_mem(priv, base);
-       mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32)));
-       num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32)));
-       next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32)));
+       capacity = iwl_read_targ_mem(priv, base);
+       mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
+       num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
+       next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
 
        size = num_wraps ? capacity : next_entry;
 
        /* bail out if nothing in log */
        if (size == 0) {
                IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
-               iwl4965_release_nic_access(priv);
+               iwl_release_nic_access(priv);
                return;
        }
 
@@ -4641,7 +4274,7 @@ static void iwl4965_dump_nic_event_log(struct iwl_priv *priv)
        /* (then/else) start at top of log */
        iwl4965_print_event_log(priv, 0, next_entry, mode);
 
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
 }
 
 /**
@@ -4673,7 +4306,7 @@ static void iwl4965_irq_handle_error(struct iwl_priv *priv)
                IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
                          "Restarting adapter due to uCode error.\n");
 
-               if (iwl4965_is_associated(priv)) {
+               if (iwl_is_associated(priv)) {
                        memcpy(&priv->recovery_rxon, &priv->active_rxon,
                               sizeof(priv->recovery_rxon));
                        priv->error_recovering = 1;
@@ -4713,19 +4346,19 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
        /* Ack/clear/reset pending uCode interrupts.
         * Note:  Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
         *  and will clear only when CSR_FH_INT_STATUS gets cleared. */
-       inta = iwl4965_read32(priv, CSR_INT);
-       iwl4965_write32(priv, CSR_INT, inta);
+       inta = iwl_read32(priv, CSR_INT);
+       iwl_write32(priv, CSR_INT, inta);
 
        /* Ack/clear/reset pending flow-handler (DMA) interrupts.
         * Any new interrupts that happen after this, either while we're
         * in this tasklet, or later, will show up in next ISR/tasklet. */
-       inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
-       iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh);
+       inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
+       iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
 
 #ifdef CONFIG_IWLWIFI_DEBUG
        if (iwl_debug_level & IWL_DL_ISR) {
                /* just for debug */
-               inta_mask = iwl4965_read32(priv, CSR_INT_MASK);
+               inta_mask = iwl_read32(priv, CSR_INT_MASK);
                IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
                              inta, inta_mask, inta_fh);
        }
@@ -4774,7 +4407,7 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
        /* HW RF KILL switch toggled */
        if (inta & CSR_INT_BIT_RF_KILL) {
                int hw_rf_kill = 0;
-               if (!(iwl4965_read32(priv, CSR_GP_CNTRL) &
+               if (!(iwl_read32(priv, CSR_GP_CNTRL) &
                                CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
                        hw_rf_kill = 1;
 
@@ -4845,13 +4478,15 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
        }
 
        /* Re-enable all interrupts */
-       iwl4965_enable_interrupts(priv);
+       /* only Re-enable if diabled by irq */
+       if (test_bit(STATUS_INT_ENABLED, &priv->status))
+               iwl4965_enable_interrupts(priv);
 
 #ifdef CONFIG_IWLWIFI_DEBUG
        if (iwl_debug_level & (IWL_DL_ISR)) {
-               inta = iwl4965_read32(priv, CSR_INT);
-               inta_mask = iwl4965_read32(priv, CSR_INT_MASK);
-               inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
+               inta = iwl_read32(priv, CSR_INT);
+               inta_mask = iwl_read32(priv, CSR_INT_MASK);
+               inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
                IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
                        "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
        }
@@ -4873,12 +4508,12 @@ static irqreturn_t iwl4965_isr(int irq, void *data)
         *    back-to-back ISRs and sporadic interrupts from our NIC.
         * If we have something to service, the tasklet will re-enable ints.
         * If we *don't* have something, we'll re-enable before leaving here. */
-       inta_mask = iwl4965_read32(priv, CSR_INT_MASK);  /* just for debug */
-       iwl4965_write32(priv, CSR_INT_MASK, 0x00000000);
+       inta_mask = iwl_read32(priv, CSR_INT_MASK);  /* just for debug */
+       iwl_write32(priv, CSR_INT_MASK, 0x00000000);
 
        /* Discover which interrupts are active/pending */
-       inta = iwl4965_read32(priv, CSR_INT);
-       inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
+       inta = iwl_read32(priv, CSR_INT);
+       inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
 
        /* Ignore interrupt if there's nothing in NIC to service.
         * This may be due to IRQ shared with another device,
@@ -4910,7 +4545,9 @@ static irqreturn_t iwl4965_isr(int irq, void *data)
 
  none:
        /* re-enable interrupts here since we don't have anything to service. */
-       iwl4965_enable_interrupts(priv);
+       /* only Re-enable if diabled by irq */
+       if (test_bit(STATUS_INT_ENABLED, &priv->status))
+               iwl4965_enable_interrupts(priv);
        spin_unlock(&priv->lock);
        return IRQ_NONE;
 }
@@ -4955,7 +4592,7 @@ static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv,
            IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
            IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
 
-       if (iwl4965_is_associated(priv)) {
+       if (iwl_is_associated(priv)) {
                /* If we're associated, we clamp the maximum passive
                 * dwell time to be 98% of the beacon interval (minus
                 * 2 * channel tune time) */
@@ -4993,9 +4630,12 @@ static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
        passive_dwell = iwl4965_get_passive_dwell_time(priv, band);
 
        for (i = 0, added = 0; i < sband->n_channels; i++) {
+               if (channels[i].flags & IEEE80211_CHAN_DISABLED)
+                       continue;
+
                if (ieee80211_frequency_to_channel(channels[i].center_freq) ==
                    le16_to_cpu(priv->active_rxon.channel)) {
-                       if (iwl4965_is_associated(priv)) {
+                       if (iwl_is_associated(priv)) {
                                IWL_DEBUG_SCAN
                                    ("Skipping current channel %d\n",
                                     le16_to_cpu(priv->active_rxon.channel));
@@ -5006,7 +4646,7 @@ static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
 
                scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq);
 
-               ch_info = iwl4965_get_channel_info(priv, band,
+               ch_info = iwl_get_channel_info(priv, band,
                                         scan_ch->channel);
                if (!is_channel_valid(ch_info)) {
                        IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
@@ -5117,7 +4757,7 @@ int iwl4965_init_geos(struct iwl_priv *priv)
        sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
        sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
 
-       iwl4965_init_ht_hw_capab(&sband->ht_info, IEEE80211_BAND_5GHZ);
+       iwl4965_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_5GHZ);
 
        sband = &priv->bands[IEEE80211_BAND_2GHZ];
        sband->channels = channels;
@@ -5125,7 +4765,7 @@ int iwl4965_init_geos(struct iwl_priv *priv)
        sband->bitrates = rates;
        sband->n_bitrates = IWL_RATE_COUNT;
 
-       iwl4965_init_ht_hw_capab(&sband->ht_info, IEEE80211_BAND_2GHZ);
+       iwl4965_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_2GHZ);
 
        priv->ieee_channels = channels;
        priv->ieee_rates = rates;
@@ -5193,8 +4833,12 @@ int iwl4965_init_geos(struct iwl_priv *priv)
               priv->bands[IEEE80211_BAND_2GHZ].n_channels,
               priv->bands[IEEE80211_BAND_5GHZ].n_channels);
 
-       priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->bands[IEEE80211_BAND_2GHZ];
-       priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->bands[IEEE80211_BAND_5GHZ];
+       if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
+               priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
+                       &priv->bands[IEEE80211_BAND_2GHZ];
+       if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
+               priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
+                       &priv->bands[IEEE80211_BAND_5GHZ];
 
        set_bit(STATUS_GEO_CONFIGURED, &priv->status);
 
@@ -5241,18 +4885,18 @@ static int iwl4965_verify_inst_full(struct iwl_priv *priv, __le32 *image,
 
        IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
 
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (rc)
                return rc;
 
-       iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
+       iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
 
        errcnt = 0;
        for (; len > 0; len -= sizeof(u32), image++) {
                /* read data comes through single port, auto-incr addr */
                /* NOTE: Use the debugless read so we don't flood kernel log
                 * if IWL_DL_IO is set */
-               val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
+               val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
                if (val != le32_to_cpu(*image)) {
                        IWL_ERROR("uCode INST section is invalid at "
                                  "offset 0x%x, is 0x%x, s/b 0x%x\n",
@@ -5264,7 +4908,7 @@ static int iwl4965_verify_inst_full(struct iwl_priv *priv, __le32 *image,
                }
        }
 
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
 
        if (!errcnt)
                IWL_DEBUG_INFO
@@ -5288,7 +4932,7 @@ static int iwl4965_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32
 
        IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
 
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (rc)
                return rc;
 
@@ -5296,9 +4940,9 @@ static int iwl4965_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32
                /* read data comes through single port, auto-incr addr */
                /* NOTE: Use the debugless read so we don't flood kernel log
                 * if IWL_DL_IO is set */
-               iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR,
+               iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
                        i + RTC_INST_LOWER_BOUND);
-               val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
+               val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
                if (val != le32_to_cpu(*image)) {
 #if 0 /* Enable this if you want to see details */
                        IWL_ERROR("uCode INST section is invalid at "
@@ -5312,7 +4956,7 @@ static int iwl4965_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32
                }
        }
 
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
 
        return rc;
 }
@@ -5367,185 +5011,35 @@ static int iwl4965_verify_ucode(struct iwl_priv *priv)
        return rc;
 }
 
-
-/* check contents of special bootstrap uCode SRAM */
-static int iwl4965_verify_bsm(struct iwl_priv *priv)
+static void iwl4965_nic_start(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 = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG);
-       for (reg = BSM_SRAM_LOWER_BOUND;
-            reg < BSM_SRAM_LOWER_BOUND + len;
-            reg += sizeof(u32), image ++) {
-               val = iwl4965_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;
+       /* Remove all resets to allow NIC to operate */
+       iwl_write32(priv, CSR_RESET, 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.
+ * iwl4965_read_ucode - Read uCode images from disk file.
  *
- * 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.
+ * Copy into buffers for card to fetch via bus-mastering
  */
-static int iwl4965_load_bsm(struct iwl_priv *priv)
+static int iwl4965_read_ucode(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 rc;
-       int i;
-       u32 done;
-       u32 reg_offset;
-
-       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;
-
-       rc = iwl4965_grab_nic_access(priv);
-       if (rc)
-               return rc;
-
-       iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
-       iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
-       iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
-       iwl4965_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++)
-               _iwl4965_write_prph(priv, reg_offset,
-                                         le32_to_cpu(*image));
+       struct iwl4965_ucode *ucode;
+       int ret;
+       const struct firmware *ucode_raw;
+       const char *name = priv->cfg->fw_name;
+       u8 *src;
+       size_t len;
+       u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
 
-       rc = iwl4965_verify_bsm(priv);
-       if (rc) {
-               iwl4965_release_nic_access(priv);
-               return rc;
-       }
-
-       /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
-       iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
-       iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG,
-                                RTC_INST_LOWER_BOUND);
-       iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
-
-       /* Load bootstrap code into instruction SRAM now,
-        *   to prepare to load "initialize" uCode */
-       iwl4965_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 = iwl4965_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) */
-       iwl4965_write_prph(priv, BSM_WR_CTRL_REG,
-               BSM_WR_CTRL_REG_BIT_START_EN);
-
-       iwl4965_release_nic_access(priv);
-
-       return 0;
-}
-
-static void iwl4965_nic_start(struct iwl_priv *priv)
-{
-       /* Remove all resets to allow NIC to operate */
-       iwl4965_write32(priv, CSR_RESET, 0);
-}
-
-
-/**
- * iwl4965_read_ucode - Read uCode images from disk file.
- *
- * Copy into buffers for card to fetch via bus-mastering
- */
-static int iwl4965_read_ucode(struct iwl_priv *priv)
-{
-       struct iwl4965_ucode *ucode;
-       int ret;
-       const struct firmware *ucode_raw;
-       const char *name = priv->cfg->fw_name;
-       u8 *src;
-       size_t len;
-       u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
-
-       /* Ask kernel firmware_class module to get the boot firmware off disk.
-        * request_firmware() is synchronous, file is in memory on return. */
-       ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
-       if (ret < 0) {
-               IWL_ERROR("%s firmware file req failed: Reason %d\n",
-                                       name, ret);
-               goto error;
+       /* Ask kernel firmware_class module to get the boot firmware off disk.
+        * request_firmware() is synchronous, file is in memory on return. */
+       ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
+       if (ret < 0) {
+               IWL_ERROR("%s firmware file req failed: Reason %d\n",
+                                       name, ret);
+               goto error;
        }
 
        IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
@@ -5742,24 +5236,24 @@ static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
        pdata = priv->ucode_data_backup.p_addr >> 4;
 
        spin_lock_irqsave(&priv->lock, flags);
-       rc = iwl4965_grab_nic_access(priv);
+       rc = iwl_grab_nic_access(priv);
        if (rc) {
                spin_unlock_irqrestore(&priv->lock, flags);
                return rc;
        }
 
        /* Tell bootstrap uCode where to find image to load */
-       iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
-       iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
-       iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
+       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);
 
        /* Inst bytecount must be last to set up, bit 31 signals uCode
         *   that all new ptr/size info is in place */
-       iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
+       iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
                                 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
 
-       iwl4965_release_nic_access(priv);
+       iwl_release_nic_access(priv);
 
        spin_unlock_irqrestore(&priv->lock, flags);
 
@@ -5826,7 +5320,7 @@ static void iwl4965_init_alive_start(struct iwl_priv *priv)
  */
 static void iwl4965_alive_start(struct iwl_priv *priv)
 {
-       int rc = 0;
+       int ret = 0;
 
        IWL_DEBUG_INFO("Runtime Alive received.\n");
 
@@ -5849,10 +5343,10 @@ static void iwl4965_alive_start(struct iwl_priv *priv)
 
        iwlcore_clear_stations_table(priv);
 
-       rc = iwl4965_alive_notify(priv);
-       if (rc) {
+       ret = priv->cfg->ops->lib->alive_notify(priv);
+       if (ret) {
                IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
-                           rc);
+                           ret);
                goto restart;
        }
 
@@ -5862,7 +5356,7 @@ static void iwl4965_alive_start(struct iwl_priv *priv)
        /* Clear out the uCode error bit if it is set */
        clear_bit(STATUS_FW_ERROR, &priv->status);
 
-       if (iwl4965_is_rfkill(priv))
+       if (iwl_is_rfkill(priv))
                return;
 
        ieee80211_start_queues(priv->hw);
@@ -5872,7 +5366,7 @@ static void iwl4965_alive_start(struct iwl_priv *priv)
 
        iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
 
-       if (iwl4965_is_associated(priv)) {
+       if (iwl_is_associated(priv)) {
                struct iwl4965_rxon_cmd *active_rxon =
                                (struct iwl4965_rxon_cmd *)(&priv->active_rxon);
 
@@ -5893,16 +5387,20 @@ static void iwl4965_alive_start(struct iwl_priv *priv)
 
        /* At this point, the NIC is initialized and operational */
        priv->notif_missed_beacons = 0;
-       set_bit(STATUS_READY, &priv->status);
 
        iwl4965_rf_kill_ct_config(priv);
 
+       iwl_leds_register(priv);
+
        IWL_DEBUG_INFO("ALIVE processing complete.\n");
+       set_bit(STATUS_READY, &priv->status);
        wake_up_interruptible(&priv->wait_command_queue);
 
        if (priv->error_recovering)
                iwl4965_error_recovery(priv);
 
+       iwlcore_low_level_notify(priv, IWLCORE_START_EVT);
+       ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
        return;
 
  restart:
@@ -5924,6 +5422,10 @@ static void __iwl4965_down(struct iwl_priv *priv)
        if (!exit_pending)
                set_bit(STATUS_EXIT_PENDING, &priv->status);
 
+       iwl_leds_unregister(priv);
+
+       iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT);
+
        iwlcore_clear_stations_table(priv);
 
        /* Unblock any waiting calls */
@@ -5935,17 +5437,20 @@ static void __iwl4965_down(struct iwl_priv *priv)
                clear_bit(STATUS_EXIT_PENDING, &priv->status);
 
        /* stop and reset the on-board processor */
-       iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
+       iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
 
        /* tell the device to stop sending interrupts */
+       spin_lock_irqsave(&priv->lock, flags);
        iwl4965_disable_interrupts(priv);
+       spin_unlock_irqrestore(&priv->lock, flags);
+       iwl_synchronize_irq(priv);
 
        if (priv->mac80211_registered)
                ieee80211_stop_queues(priv->hw);
 
        /* If we have not previously called iwl4965_init() then
         * clear all bits but the RF Kill and SUSPEND bits and return */
-       if (!iwl4965_is_init(priv)) {
+       if (!iwl_is_init(priv)) {
                priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
                                        STATUS_RF_KILL_HW |
                               test_bit(STATUS_RF_KILL_SW, &priv->status) <<
@@ -5971,7 +5476,7 @@ static void __iwl4965_down(struct iwl_priv *priv)
                                STATUS_FW_ERROR;
 
        spin_lock_irqsave(&priv->lock, flags);
-       iwl4965_clear_bit(priv, CSR_GP_CNTRL,
+       iwl_clear_bit(priv, CSR_GP_CNTRL,
                         CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
        spin_unlock_irqrestore(&priv->lock, flags);
 
@@ -5979,17 +5484,17 @@ static void __iwl4965_down(struct iwl_priv *priv)
        iwl4965_hw_rxq_stop(priv);
 
        spin_lock_irqsave(&priv->lock, flags);
-       if (!iwl4965_grab_nic_access(priv)) {
-               iwl4965_write_prph(priv, APMG_CLK_DIS_REG,
+       if (!iwl_grab_nic_access(priv)) {
+               iwl_write_prph(priv, APMG_CLK_DIS_REG,
                                         APMG_CLK_VAL_DMA_CLK_RQT);
-               iwl4965_release_nic_access(priv);
+               iwl_release_nic_access(priv);
        }
        spin_unlock_irqrestore(&priv->lock, flags);
 
        udelay(5);
 
        iwl4965_hw_nic_stop_master(priv);
-       iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
+       iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
        iwl4965_hw_nic_reset(priv);
 
  exit:
@@ -6016,7 +5521,8 @@ static void iwl4965_down(struct iwl_priv *priv)
 
 static int __iwl4965_up(struct iwl_priv *priv)
 {
-       int rc, i;
+       int i;
+       int ret;
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
                IWL_WARNING("Exit pending; will not bring the NIC up\n");
@@ -6026,6 +5532,7 @@ static int __iwl4965_up(struct iwl_priv *priv)
        if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
                IWL_WARNING("Radio disabled by SW RF kill (module "
                            "parameter)\n");
+               iwl_rfkill_set_hw_state(priv);
                return -ENODEV;
        }
 
@@ -6035,37 +5542,39 @@ static int __iwl4965_up(struct iwl_priv *priv)
        }
 
        /* If platform's RF_KILL switch is NOT set to KILL */
-       if (iwl4965_read32(priv, CSR_GP_CNTRL) &
+       if (iwl_read32(priv, CSR_GP_CNTRL) &
                                CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
                clear_bit(STATUS_RF_KILL_HW, &priv->status);
        else {
                set_bit(STATUS_RF_KILL_HW, &priv->status);
                if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
+                       iwl_rfkill_set_hw_state(priv);
                        IWL_WARNING("Radio disabled by HW RF Kill switch\n");
                        return -ENODEV;
                }
        }
 
-       iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
+       iwl_rfkill_set_hw_state(priv);
+       iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
 
-       rc = iwl4965_hw_nic_init(priv);
-       if (rc) {
-               IWL_ERROR("Unable to int nic\n");
-               return rc;
+       ret = priv->cfg->ops->lib->hw_nic_init(priv);
+       if (ret) {
+               IWL_ERROR("Unable to init nic\n");
+               return ret;
        }
 
        /* make sure rfkill handshake bits are cleared */
-       iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
-       iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
+       iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
+       iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
                    CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
 
        /* clear (again), then enable host interrupts */
-       iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
+       iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
        iwl4965_enable_interrupts(priv);
 
        /* really make sure rfkill handshake bits are cleared */
-       iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
-       iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
+       iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
+       iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
 
        /* Copy original ucode data image from disk into backup cache.
         * This will be used to initialize the on-board processor's
@@ -6084,10 +5593,10 @@ static int __iwl4965_up(struct iwl_priv *priv)
                /* load bootstrap state machine,
                 * load bootstrap program into processor's memory,
                 * prepare to load the "initialize" uCode */
-               rc = iwl4965_load_bsm(priv);
+               ret = priv->cfg->ops->lib->load_ucode(priv);
 
-               if (rc) {
-                       IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc);
+               if (ret) {
+                       IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
                        continue;
                }
 
@@ -6152,13 +5661,16 @@ static void iwl4965_bg_rf_kill(struct work_struct *work)
 
        mutex_lock(&priv->mutex);
 
-       if (!iwl4965_is_rfkill(priv)) {
+       if (!iwl_is_rfkill(priv)) {
                IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
                          "HW and/or SW RF Kill no longer active, restarting "
                          "device\n");
                if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
                        queue_work(priv->workqueue, &priv->restart);
        } else {
+               /* make sure mac80211 stop sending Tx frame */
+               if (priv->mac80211_registered)
+                       ieee80211_stop_queues(priv->hw);
 
                if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
                        IWL_DEBUG_RF_KILL("Can not turn radio back on - "
@@ -6168,6 +5680,8 @@ static void iwl4965_bg_rf_kill(struct work_struct *work)
                                    "Kill switch must be turned off for "
                                    "wireless networking to work.\n");
        }
+       iwl_rfkill_set_hw_state(priv);
+
        mutex_unlock(&priv->mutex);
 }
 
@@ -6198,23 +5712,23 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
 {
        struct iwl_priv *priv =
            container_of(data, struct iwl_priv, request_scan);
-       struct iwl4965_host_cmd cmd = {
+       struct iwl_host_cmd cmd = {
                .id = REPLY_SCAN_CMD,
                .len = sizeof(struct iwl4965_scan_cmd),
                .meta.flags = CMD_SIZE_HUGE,
        };
-       int rc = 0;
        struct iwl4965_scan_cmd *scan;
        struct ieee80211_conf *conf = NULL;
        u16 cmd_len;
        enum ieee80211_band band;
        u8 direct_mask;
+       int ret = 0;
 
        conf = ieee80211_get_hw_conf(priv->hw);
 
        mutex_lock(&priv->mutex);
 
-       if (!iwl4965_is_ready(priv)) {
+       if (!iwl_is_ready(priv)) {
                IWL_WARNING("request scan called when driver not ready.\n");
                goto done;
        }
@@ -6229,7 +5743,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
        if (test_bit(STATUS_SCAN_HW, &priv->status)) {
                IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
                               "Ignoring second request.\n");
-               rc = -EIO;
+               ret = -EIO;
                goto done;
        }
 
@@ -6243,7 +5757,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
                goto done;
        }
 
-       if (iwl4965_is_rfkill(priv)) {
+       if (iwl_is_rfkill(priv)) {
                IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
                goto done;
        }
@@ -6262,7 +5776,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
                priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
                                     IWL_MAX_SCAN_SIZE, GFP_KERNEL);
                if (!priv->scan) {
-                       rc = -ENOMEM;
+                       ret = -ENOMEM;
                        goto done;
                }
        }
@@ -6272,7 +5786,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
        scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
        scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
 
-       if (iwl4965_is_associated(priv)) {
+       if (iwl_is_associated(priv)) {
                u16 interval = 0;
                u32 extra;
                u32 suspend_time = 100;
@@ -6309,16 +5823,17 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
                memcpy(scan->direct_scan[0].ssid,
                       priv->direct_ssid, priv->direct_ssid_len);
                direct_mask = 1;
-       } else if (!iwl4965_is_associated(priv) && priv->essid_len) {
+       } else if (!iwl_is_associated(priv) && priv->essid_len) {
                scan->direct_scan[0].id = WLAN_EID_SSID;
                scan->direct_scan[0].len = priv->essid_len;
                memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
                direct_mask = 1;
-       } else
+       } else {
                direct_mask = 0;
+       }
 
        scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
-       scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
+       scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
        scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
 
 
@@ -6390,8 +5905,8 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
        scan->len = cpu_to_le16(cmd.len);
 
        set_bit(STATUS_SCAN_HW, &priv->status);
-       rc = iwl4965_send_cmd_sync(priv, &cmd);
-       if (rc)
+       ret = iwl_send_cmd_sync(priv, &cmd);
+       if (ret)
                goto done;
 
        queue_delayed_work(priv->workqueue, &priv->scan_check,
@@ -6444,13 +5959,10 @@ static void iwl4965_bg_rx_replenish(struct work_struct *data)
 
 #define IWL_DELAY_NEXT_SCAN (HZ*2)
 
-static void iwl4965_bg_post_associate(struct work_struct *data)
+static void iwl4965_post_associate(struct iwl_priv *priv)
 {
-       struct iwl_priv *priv = container_of(data, struct iwl_priv,
-                                            post_associate.work);
-
-       int rc = 0;
        struct ieee80211_conf *conf = NULL;
+       int ret = 0;
        DECLARE_MAC_BUF(mac);
 
        if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
@@ -6466,12 +5978,10 @@ static void iwl4965_bg_post_associate(struct work_struct *data)
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
 
-       mutex_lock(&priv->mutex);
 
-       if (!priv->vif || !priv->is_open) {
-               mutex_unlock(&priv->mutex);
+       if (!priv->vif || !priv->is_open)
                return;
-       }
+
        iwl4965_scan_cancel_timeout(priv, 200);
 
        conf = ieee80211_get_hw_conf(priv->hw);
@@ -6481,9 +5991,9 @@ static void iwl4965_bg_post_associate(struct work_struct *data)
 
        memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
        iwl4965_setup_rxon_timing(priv);
-       rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
+       ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
                              sizeof(priv->rxon_timing), &priv->rxon_timing);
-       if (rc)
+       if (ret)
                IWL_WARNING("REPLY_RXON_TIMING failed - "
                            "Attempting to continue.\n");
 
@@ -6555,14 +6065,25 @@ static void iwl4965_bg_post_associate(struct work_struct *data)
 
        /* we have just associated, don't start scan too early */
        priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
+}
+
+
+static void iwl4965_bg_post_associate(struct work_struct *data)
+{
+       struct iwl_priv *priv = container_of(data, struct iwl_priv,
+                                            post_associate.work);
+
+       mutex_lock(&priv->mutex);
+       iwl4965_post_associate(priv);
        mutex_unlock(&priv->mutex);
+
 }
 
 static void iwl4965_bg_abort_scan(struct work_struct *work)
 {
        struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
 
-       if (!iwl4965_is_ready(priv))
+       if (!iwl_is_ready(priv))
                return;
 
        mutex_lock(&priv->mutex);
@@ -6695,7 +6216,7 @@ static void iwl4965_mac_stop(struct ieee80211_hw *hw)
 
        priv->is_open = 0;
 
-       if (iwl4965_is_ready_rf(priv)) {
+       if (iwl_is_ready_rf(priv)) {
                /* stop mac, cancel any scan request and clear
                 * RXON_FILTER_ASSOC_MSK BIT
                 */
@@ -6764,7 +6285,7 @@ static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
                memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
        }
 
-       if (iwl4965_is_ready(priv))
+       if (iwl_is_ready(priv))
                iwl4965_set_mode(priv, conf->type);
 
        mutex_unlock(&priv->mutex);
@@ -6792,13 +6313,13 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
 
        priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
 
-       if (!iwl4965_is_ready(priv)) {
+       if (!iwl_is_ready(priv)) {
                IWL_DEBUG_MAC80211("leave - not ready\n");
                ret = -EIO;
                goto out;
        }
 
-       if (unlikely(!iwl4965_mod_params.disable_hw_scan &&
+       if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
                     test_bit(STATUS_SCANNING, &priv->status))) {
                IWL_DEBUG_MAC80211("leave - scanning\n");
                set_bit(STATUS_CONF_PENDING, &priv->status);
@@ -6808,7 +6329,7 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
 
        spin_lock_irqsave(&priv->lock, flags);
 
-       ch_info = iwl4965_get_channel_info(priv, conf->channel->band,
+       ch_info = iwl_get_channel_info(priv, conf->channel->band,
                        ieee80211_frequency_to_channel(conf->channel->center_freq));
        if (!is_channel_valid(ch_info)) {
                IWL_DEBUG_MAC80211("leave - invalid channel\n");
@@ -6848,14 +6369,15 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
        }
 #endif
 
-       iwl4965_radio_kill_sw(priv, !conf->radio_enabled);
+       if (priv->cfg->ops->lib->radio_kill_sw)
+               priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled);
 
        if (!conf->radio_enabled) {
                IWL_DEBUG_MAC80211("leave - radio disabled\n");
                goto out;
        }
 
-       if (iwl4965_is_rfkill(priv)) {
+       if (iwl_is_rfkill(priv)) {
                IWL_DEBUG_MAC80211("leave - RF kill\n");
                ret = -EIO;
                goto out;
@@ -6879,7 +6401,7 @@ out:
 
 static void iwl4965_config_ap(struct iwl_priv *priv)
 {
-       int rc = 0;
+       int ret = 0;
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
@@ -6894,9 +6416,9 @@ static void iwl4965_config_ap(struct iwl_priv *priv)
                /* RXON Timing */
                memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
                iwl4965_setup_rxon_timing(priv);
-               rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
+               ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
                                sizeof(priv->rxon_timing), &priv->rxon_timing);
-               if (rc)
+               if (ret)
                        IWL_WARNING("REPLY_RXON_TIMING failed - "
                                        "Attempting to continue.\n");
 
@@ -6962,7 +6484,7 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
                return 0;
        }
 
-       if (!iwl4965_is_alive(priv))
+       if (!iwl_is_alive(priv))
                return -EAGAIN;
 
        mutex_lock(&priv->mutex);
@@ -6991,7 +6513,7 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
                priv->ibss_beacon = conf->beacon;
        }
 
-       if (iwl4965_is_rfkill(priv))
+       if (iwl_is_rfkill(priv))
                goto done;
 
        if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
@@ -7065,7 +6587,7 @@ static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
 
        mutex_lock(&priv->mutex);
 
-       if (iwl4965_is_ready_rf(priv)) {
+       if (iwl_is_ready_rf(priv)) {
                iwl4965_scan_cancel_timeout(priv, 100);
                cancel_delayed_work(&priv->post_associate);
                priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
@@ -7083,6 +6605,65 @@ static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
 
 }
 
+
+#ifdef CONFIG_IWL4965_HT
+static void iwl4965_ht_conf(struct iwl_priv *priv,
+                           struct ieee80211_bss_conf *bss_conf)
+{
+       struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
+       struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
+       struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
+
+       IWL_DEBUG_MAC80211("enter: \n");
+
+       iwl_conf->is_ht = bss_conf->assoc_ht;
+
+       if (!iwl_conf->is_ht)
+               return;
+
+       priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
+
+       if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
+               iwl_conf->sgf |= 0x1;
+       if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
+               iwl_conf->sgf |= 0x2;
+
+       iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
+       iwl_conf->max_amsdu_size =
+               !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
+
+       iwl_conf->supported_chan_width =
+               !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
+       iwl_conf->extension_chan_offset =
+               ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
+       /* If no above or below channel supplied disable FAT channel */
+       if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE &&
+           iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW)
+               iwl_conf->supported_chan_width = 0;
+
+       iwl_conf->tx_mimo_ps_mode =
+               (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
+       memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
+
+       iwl_conf->control_channel = ht_bss_conf->primary_channel;
+       iwl_conf->tx_chan_width =
+               !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
+       iwl_conf->ht_protection =
+               ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
+       iwl_conf->non_GF_STA_present =
+               !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
+
+       IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
+       IWL_DEBUG_MAC80211("leave\n");
+}
+#else
+static inline void iwl4965_ht_conf(struct iwl_priv *priv,
+                                  struct ieee80211_bss_conf *bss_conf)
+{
+}
+#endif
+
+#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
 static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
                                     struct ieee80211_vif *vif,
                                     struct ieee80211_bss_conf *bss_conf,
@@ -7090,7 +6671,11 @@ static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
 {
        struct iwl_priv *priv = hw->priv;
 
+       IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
+
        if (changes & BSS_CHANGED_ERP_PREAMBLE) {
+               IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
+                                  bss_conf->use_short_preamble);
                if (bss_conf->use_short_preamble)
                        priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
                else
@@ -7098,21 +6683,44 @@ static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
        }
 
        if (changes & BSS_CHANGED_ERP_CTS_PROT) {
+               IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
                if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
                        priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
                else
                        priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
        }
 
+       if (changes & BSS_CHANGED_HT) {
+               IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
+               iwl4965_ht_conf(priv, bss_conf);
+               iwl4965_set_rxon_chain(priv);
+       }
+
        if (changes & BSS_CHANGED_ASSOC) {
-               /*
-                * TODO:
-                * do stuff instead of sniffing assoc resp
-                */
+               IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
+               /* This should never happen as this function should
+                * never be called from interrupt context. */
+               if (WARN_ON_ONCE(in_interrupt()))
+                       return;
+               if (bss_conf->assoc) {
+                       priv->assoc_id = bss_conf->aid;
+                       priv->beacon_int = bss_conf->beacon_int;
+                       priv->timestamp = bss_conf->timestamp;
+                       priv->assoc_capability = bss_conf->assoc_capability;
+                       priv->next_scan_jiffies = jiffies +
+                                       IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
+                       mutex_lock(&priv->mutex);
+                       iwl4965_post_associate(priv);
+                       mutex_unlock(&priv->mutex);
+               } else {
+                       priv->assoc_id = 0;
+                       IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
+               }
+       } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
+                       IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
+                       iwl_send_rxon_assoc(priv);
        }
 
-       if (iwl4965_is_associated(priv))
-               iwl4965_send_rxon_assoc(priv);
 }
 
 static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
@@ -7126,7 +6734,7 @@ static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
        mutex_lock(&priv->mutex);
        spin_lock_irqsave(&priv->lock, flags);
 
-       if (!iwl4965_is_ready_rf(priv)) {
+       if (!iwl_is_ready_rf(priv)) {
                rc = -EIO;
                IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
                goto out_unlock;
@@ -7172,6 +6780,54 @@ out_unlock:
        return rc;
 }
 
+static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
+                       struct ieee80211_key_conf *keyconf, const u8 *addr,
+                       u32 iv32, u16 *phase1key)
+{
+       struct iwl_priv *priv = hw->priv;
+       u8 sta_id = IWL_INVALID_STATION;
+       unsigned long flags;
+       __le16 key_flags = 0;
+       int i;
+       DECLARE_MAC_BUF(mac);
+
+       IWL_DEBUG_MAC80211("enter\n");
+
+       sta_id = iwl4965_hw_find_station(priv, addr);
+       if (sta_id == IWL_INVALID_STATION) {
+               IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
+                                  print_mac(mac, addr));
+               return;
+       }
+
+       iwl4965_scan_cancel_timeout(priv, 100);
+
+       key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
+       key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
+       key_flags &= ~STA_KEY_FLG_INVALID;
+
+       if (sta_id == priv->hw_params.bcast_sta_id)
+               key_flags |= STA_KEY_MULTICAST_MSK;
+
+       spin_lock_irqsave(&priv->sta_lock, flags);
+
+       priv->stations[sta_id].sta.key.key_flags = key_flags;
+       priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
+
+       for (i = 0; i < 5; i++)
+               priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
+                       cpu_to_le16(phase1key[i]);
+
+       priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
+       priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
+
+       iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
+
+       spin_unlock_irqrestore(&priv->sta_lock, flags);
+
+       IWL_DEBUG_MAC80211("leave\n");
+}
+
 static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
                           const u8 *local_addr, const u8 *addr,
                           struct ieee80211_key_conf *key)
@@ -7180,11 +6836,11 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
        DECLARE_MAC_BUF(mac);
        int ret = 0;
        u8 sta_id = IWL_INVALID_STATION;
-       u8 static_key;
+       u8 is_default_wep_key = 0;
 
        IWL_DEBUG_MAC80211("enter\n");
 
-       if (!iwl4965_mod_params.hw_crypto) {
+       if (priv->cfg->mod_params->sw_crypto) {
                IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
                return -EOPNOTSUPP;
        }
@@ -7193,35 +6849,44 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
                /* only support pairwise keys */
                return -EOPNOTSUPP;
 
-       /* FIXME: need to differenciate between static and dynamic key
-        * in the level of mac80211 */
-       static_key = !iwl4965_is_associated(priv);
+       sta_id = iwl4965_hw_find_station(priv, addr);
+       if (sta_id == IWL_INVALID_STATION) {
+               IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
+                                  print_mac(mac, addr));
+               return -EINVAL;
 
-       if (!static_key) {
-               sta_id = iwl4965_hw_find_station(priv, addr);
-               if (sta_id == IWL_INVALID_STATION) {
-                       IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
-                                          print_mac(mac, addr));
-                       return -EINVAL;
-               }
        }
 
+       mutex_lock(&priv->mutex);
        iwl4965_scan_cancel_timeout(priv, 100);
+       mutex_unlock(&priv->mutex);
+
+       /* If we are getting WEP group key and we didn't receive any key mapping
+        * so far, we are in legacy wep mode (group key only), otherwise we are
+        * in 1X mode.
+        * In legacy wep mode, we use another host command to the uCode */
+       if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
+               priv->iw_mode != IEEE80211_IF_TYPE_AP) {
+               if (cmd == SET_KEY)
+                       is_default_wep_key = !priv->key_mapping_key;
+               else
+                       is_default_wep_key = priv->default_wep_key;
+       }
 
        switch (cmd) {
        case SET_KEY:
-               if (static_key)
-                       ret = iwl4965_set_static_key(priv, key);
+               if (is_default_wep_key)
+                       ret = iwl_set_default_wep_key(priv, key);
                else
-                       ret = iwl4965_set_dynamic_key(priv, key, sta_id);
+                       ret = iwl_set_dynamic_key(priv, key, sta_id);
 
                IWL_DEBUG_MAC80211("enable hwcrypto key\n");
                break;
        case DISABLE_KEY:
-               if (static_key)
-                       ret = iwl4965_remove_static_key(priv);
+               if (is_default_wep_key)
+                       ret = iwl_remove_default_wep_key(priv, key);
                else
-                       ret = iwl4965_clear_sta_key_info(priv, sta_id);
+                       ret = iwl_remove_dynamic_key(priv, sta_id);
 
                IWL_DEBUG_MAC80211("disable hwcrypto key\n");
                break;
@@ -7243,7 +6908,7 @@ static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue,
 
        IWL_DEBUG_MAC80211("enter\n");
 
-       if (!iwl4965_is_ready_rf(priv)) {
+       if (!iwl_is_ready_rf(priv)) {
                IWL_DEBUG_MAC80211("leave - RF not ready\n");
                return -EIO;
        }
@@ -7276,7 +6941,7 @@ static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue,
        mutex_lock(&priv->mutex);
        if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
                iwl4965_activate_qos(priv, 1);
-       else if (priv->assoc_id && iwl4965_is_associated(priv))
+       else if (priv->assoc_id && iwl_is_associated(priv))
                iwl4965_activate_qos(priv, 0);
 
        mutex_unlock(&priv->mutex);
@@ -7296,7 +6961,7 @@ static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
 
        IWL_DEBUG_MAC80211("enter\n");
 
-       if (!iwl4965_is_ready_rf(priv)) {
+       if (!iwl_is_ready_rf(priv)) {
                IWL_DEBUG_MAC80211("leave - RF not ready\n");
                return -EIO;
        }
@@ -7359,7 +7024,6 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
        spin_lock_irqsave(&priv->lock, flags);
        priv->assoc_id = 0;
        priv->assoc_capability = 0;
-       priv->call_post_assoc_from_beacon = 0;
        priv->assoc_station_added = 0;
 
        /* new association get rid of ibss beacon skb */
@@ -7369,14 +7033,13 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
        priv->ibss_beacon = NULL;
 
        priv->beacon_int = priv->hw->conf.beacon_int;
-       priv->timestamp1 = 0;
-       priv->timestamp0 = 0;
+       priv->timestamp = 0;
        if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
                priv->beacon_int = 0;
 
        spin_unlock_irqrestore(&priv->lock, flags);
 
-       if (!iwl4965_is_ready_rf(priv)) {
+       if (!iwl_is_ready_rf(priv)) {
                IWL_DEBUG_MAC80211("leave - not ready\n");
                mutex_unlock(&priv->mutex);
                return;
@@ -7417,7 +7080,7 @@ static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *sk
        mutex_lock(&priv->mutex);
        IWL_DEBUG_MAC80211("enter\n");
 
-       if (!iwl4965_is_ready_rf(priv)) {
+       if (!iwl_is_ready_rf(priv)) {
                IWL_DEBUG_MAC80211("leave - RF not ready\n");
                mutex_unlock(&priv->mutex);
                return -EIO;
@@ -7450,88 +7113,6 @@ static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *sk
        return 0;
 }
 
-#ifdef CONFIG_IWL4965_HT
-
-static void iwl4965_ht_info_fill(struct ieee80211_conf *conf,
-                                struct iwl_priv *priv)
-{
-       struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
-       struct ieee80211_ht_info *ht_conf = &conf->ht_conf;
-       struct ieee80211_ht_bss_info *ht_bss_conf = &conf->ht_bss_conf;
-
-       IWL_DEBUG_MAC80211("enter: \n");
-
-       if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) {
-               iwl_conf->is_ht = 0;
-               return;
-       }
-
-       iwl_conf->is_ht = 1;
-       priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
-
-       if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
-               iwl_conf->sgf |= 0x1;
-       if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
-               iwl_conf->sgf |= 0x2;
-
-       iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
-       iwl_conf->max_amsdu_size =
-               !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
-
-       iwl_conf->supported_chan_width =
-               !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
-       iwl_conf->extension_chan_offset =
-               ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
-       /* If no above or below channel supplied disable FAT channel */
-       if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE &&
-           iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW)
-               iwl_conf->supported_chan_width = 0;
-
-       iwl_conf->tx_mimo_ps_mode =
-               (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
-       memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
-
-       iwl_conf->control_channel = ht_bss_conf->primary_channel;
-       iwl_conf->tx_chan_width =
-               !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
-       iwl_conf->ht_protection =
-               ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
-       iwl_conf->non_GF_STA_present =
-               !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
-
-       IWL_DEBUG_MAC80211("control channel %d\n",
-               iwl_conf->control_channel);
-       IWL_DEBUG_MAC80211("leave\n");
-}
-
-static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw,
-                              struct ieee80211_conf *conf)
-{
-       struct iwl_priv *priv = hw->priv;
-
-       IWL_DEBUG_MAC80211("enter: \n");
-
-       iwl4965_ht_info_fill(conf, priv);
-       iwl4965_set_rxon_chain(priv);
-
-       if (priv && priv->assoc_id &&
-           (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
-               unsigned long flags;
-
-               spin_lock_irqsave(&priv->lock, flags);
-               if (priv->beacon_int)
-                       queue_work(priv->workqueue, &priv->post_associate.work);
-               else
-                       priv->call_post_assoc_from_beacon = 1;
-               spin_unlock_irqrestore(&priv->lock, flags);
-       }
-
-       IWL_DEBUG_MAC80211("leave:\n");
-       return 0;
-}
-
-#endif /*CONFIG_IWL4965_HT*/
-
 /*****************************************************************************
  *
  * sysfs attributes
@@ -7573,43 +7154,13 @@ static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
 
 #endif /* CONFIG_IWLWIFI_DEBUG */
 
-static ssize_t show_rf_kill(struct device *d,
-                           struct device_attribute *attr, char *buf)
-{
-       /*
-        * 0 - RF kill not enabled
-        * 1 - SW based RF kill active (sysfs)
-        * 2 - HW based RF kill active
-        * 3 - Both HW and SW based RF kill active
-        */
-       struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
-       int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) |
-                 (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0);
-
-       return sprintf(buf, "%i\n", val);
-}
-
-static ssize_t store_rf_kill(struct device *d,
-                            struct device_attribute *attr,
-                            const char *buf, size_t count)
-{
-       struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
-
-       mutex_lock(&priv->mutex);
-       iwl4965_radio_kill_sw(priv, buf[0] == '1');
-       mutex_unlock(&priv->mutex);
-
-       return count;
-}
-
-static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
 
 static ssize_t show_temperature(struct device *d,
                                struct device_attribute *attr, char *buf)
 {
        struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
 
-       if (!iwl4965_is_alive(priv))
+       if (!iwl_is_alive(priv))
                return -EAGAIN;
 
        return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv));
@@ -7831,7 +7382,7 @@ static ssize_t store_power_level(struct device *d,
        mode = simple_strtoul(buf, NULL, 0);
        mutex_lock(&priv->mutex);
 
-       if (!iwl4965_is_ready(priv)) {
+       if (!iwl_is_ready(priv)) {
                rc = -EAGAIN;
                goto out;
        }
@@ -7928,11 +7479,11 @@ static ssize_t show_statistics(struct device *d,
        u8 *data = (u8 *) & priv->statistics;
        int rc = 0;
 
-       if (!iwl4965_is_alive(priv))
+       if (!iwl_is_alive(priv))
                return -EAGAIN;
 
        mutex_lock(&priv->mutex);
-       rc = iwl4965_send_statistics_request(priv);
+       rc = iwl_send_statistics_request(priv, 0);
        mutex_unlock(&priv->mutex);
 
        if (rc) {
@@ -7962,7 +7513,7 @@ static ssize_t show_antenna(struct device *d,
 {
        struct iwl_priv *priv = dev_get_drvdata(d);
 
-       if (!iwl4965_is_alive(priv))
+       if (!iwl_is_alive(priv))
                return -EAGAIN;
 
        return sprintf(buf, "%d\n", priv->antenna);
@@ -7999,7 +7550,7 @@ static ssize_t show_status(struct device *d,
                           struct device_attribute *attr, char *buf)
 {
        struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
-       if (!iwl4965_is_alive(priv))
+       if (!iwl_is_alive(priv))
                return -EAGAIN;
        return sprintf(buf, "0x%08x\n", (int)priv->status);
 }
@@ -8088,7 +7639,6 @@ static struct attribute *iwl4965_sysfs_entries[] = {
 #endif
        &dev_attr_power_level.attr,
        &dev_attr_retry_rate.attr,
-       &dev_attr_rf_kill.attr,
        &dev_attr_rs_window.attr,
        &dev_attr_statistics.attr,
        &dev_attr_status.attr,
@@ -8113,6 +7663,7 @@ static struct ieee80211_ops iwl4965_hw_ops = {
        .config_interface = iwl4965_mac_config_interface,
        .configure_filter = iwl4965_configure_filter,
        .set_key = iwl4965_mac_set_key,
+       .update_tkip_key = iwl4965_mac_update_tkip_key,
        .get_stats = iwl4965_mac_get_stats,
        .get_tx_stats = iwl4965_mac_get_tx_stats,
        .conf_tx = iwl4965_mac_conf_tx,
@@ -8121,7 +7672,6 @@ static struct ieee80211_ops iwl4965_hw_ops = {
        .beacon_update = iwl4965_mac_beacon_update,
        .bss_info_changed = iwl4965_bss_info_changed,
 #ifdef CONFIG_IWL4965_HT
-       .conf_ht = iwl4965_mac_conf_ht,
        .ampdu_action = iwl4965_mac_ampdu_action,
 #endif  /* CONFIG_IWL4965_HT */
        .hw_scan = iwl4965_mac_hw_scan
@@ -8133,6 +7683,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        struct iwl_priv *priv;
        struct ieee80211_hw *hw;
        struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
+       unsigned long flags;
        DECLARE_MAC_BUF(mac);
 
        /************************
@@ -8141,7 +7692,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
 
        /* Disabling hardware scan means that mac80211 will perform scans
         * "the hard way", rather than using device's scan. */
-       if (iwl4965_mod_params.disable_hw_scan) {
+       if (cfg->mod_params->disable_hw_scan) {
                IWL_DEBUG_INFO("Disabling hw_scan\n");
                iwl4965_hw_ops.hw_scan = NULL;
        }
@@ -8161,7 +7712,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        priv->pci_dev = pdev;
 
 #ifdef CONFIG_IWLWIFI_DEBUG
-       iwl_debug_level = iwl4965_mod_params.debug;
+       iwl_debug_level = priv->cfg->mod_params->debug;
        atomic_set(&priv->restrict_refcnt, 0);
 #endif
 
@@ -8214,11 +7765,11 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
         * 4. Read EEPROM
         *****************/
        /* nic init */
-       iwl4965_set_bit(priv, CSR_GIO_CHICKEN_BITS,
+       iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
                CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
 
-       iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
-       err = iwl4965_poll_bit(priv, CSR_GP_CNTRL,
+       iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
+       err = 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 (err < 0) {
@@ -8240,8 +7791,8 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
         * 5. Setup HW constants
         ************************/
        /* Device-specific setup */
-       if (iwl4965_hw_set_hw_setting(priv)) {
-               IWL_ERROR("failed to set hw settings\n");
+       if (priv->cfg->ops->lib->set_hw_params(priv)) {
+               IWL_ERROR("failed to set hw parameters\n");
                goto out_iounmap;
        }
 
@@ -8251,7 +7802,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
 
        err = iwl_setup(priv);
        if (err)
-               goto out_unset_hw_settings;
+               goto out_unset_hw_params;
        /* At this point both hw and priv are initialized. */
 
        /**********************************
@@ -8259,23 +7810,25 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
         **********************************/
 
        /* Disable radio (SW RF KILL) via parameter when loading driver */
-       if (iwl4965_mod_params.disable) {
+       if (priv->cfg->mod_params->disable) {
                set_bit(STATUS_RF_KILL_SW, &priv->status);
                IWL_DEBUG_INFO("Radio disabled.\n");
        }
 
-       if (iwl4965_mod_params.enable_qos)
+       if (priv->cfg->mod_params->enable_qos)
                priv->qos_data.qos_enable = 1;
 
        /********************
         * 8. Setup services
         ********************/
+       spin_lock_irqsave(&priv->lock, flags);
        iwl4965_disable_interrupts(priv);
+       spin_unlock_irqrestore(&priv->lock, flags);
 
        err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
        if (err) {
                IWL_ERROR("failed to create sysfs device attributes\n");
-               goto out_unset_hw_settings;
+               goto out_unset_hw_params;
        }
 
        err = iwl_dbgfs_register(priv, DRV_NAME);
@@ -8293,12 +7846,14 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        pci_save_state(pdev);
        pci_disable_device(pdev);
 
+       /* notify iwlcore to init */
+       iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT);
        return 0;
 
  out_remove_sysfs:
        sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
- out_unset_hw_settings:
-       iwl4965_unset_hw_setting(priv);
+ out_unset_hw_params:
+       iwl4965_unset_hw_params(priv);
  out_iounmap:
        pci_iounmap(pdev, priv->hw_base);
  out_pci_release_regions:
@@ -8312,21 +7867,36 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        return err;
 }
 
-static void iwl4965_pci_remove(struct pci_dev *pdev)
+static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
 {
        struct iwl_priv *priv = pci_get_drvdata(pdev);
        struct list_head *p, *q;
        int i;
+       unsigned long flags;
 
        if (!priv)
                return;
 
        IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
 
+       if (priv->mac80211_registered) {
+               ieee80211_unregister_hw(priv->hw);
+               priv->mac80211_registered = 0;
+       }
+
        set_bit(STATUS_EXIT_PENDING, &priv->status);
 
        iwl4965_down(priv);
 
+       /* make sure we flush any pending irq or
+        * tasklet for the driver
+        */
+       spin_lock_irqsave(&priv->lock, flags);
+       iwl4965_disable_interrupts(priv);
+       spin_unlock_irqrestore(&priv->lock, flags);
+
+       iwl_synchronize_irq(priv);
+
        /* Free MAC hash list for ADHOC */
        for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
                list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
@@ -8335,6 +7905,7 @@ static void iwl4965_pci_remove(struct pci_dev *pdev)
                }
        }
 
+       iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT);
        iwl_dbgfs_unregister(priv);
        sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
 
@@ -8344,13 +7915,9 @@ static void iwl4965_pci_remove(struct pci_dev *pdev)
                iwl4965_rx_queue_free(priv, &priv->rxq);
        iwl4965_hw_txq_ctx_free(priv);
 
-       iwl4965_unset_hw_setting(priv);
+       iwl4965_unset_hw_params(priv);
        iwlcore_clear_stations_table(priv);
 
-       if (priv->mac80211_registered) {
-               ieee80211_unregister_hw(priv->hw);
-               iwl4965_rate_control_unregister(priv->hw);
-       }
 
        /*netif_stop_queue(dev); */
        flush_workqueue(priv->workqueue);
@@ -8413,9 +7980,17 @@ static int iwl4965_pci_resume(struct pci_dev *pdev)
  *
  *****************************************************************************/
 
-static struct pci_driver iwl4965_driver = {
+/* Hardware specific file defines the PCI IDs table for that hardware module */
+static struct pci_device_id iwl_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, iwl_hw_card_ids);
+
+static struct pci_driver iwl_driver = {
        .name = DRV_NAME,
-       .id_table = iwl4965_hw_card_ids,
+       .id_table = iwl_hw_card_ids,
        .probe = iwl4965_pci_probe,
        .remove = __devexit_p(iwl4965_pci_remove),
 #ifdef CONFIG_PM
@@ -8430,52 +8005,45 @@ static int __init iwl4965_init(void)
        int ret;
        printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
        printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
-       ret = pci_register_driver(&iwl4965_driver);
+
+       ret = iwl4965_rate_control_register();
        if (ret) {
-               IWL_ERROR("Unable to initialize PCI module\n");
+               IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
                return ret;
        }
+
+       ret = pci_register_driver(&iwl_driver);
+       if (ret) {
+               IWL_ERROR("Unable to initialize PCI module\n");
+               goto error_register;
+       }
 #ifdef CONFIG_IWLWIFI_DEBUG
-       ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level);
+       ret = driver_create_file(&iwl_driver.driver, &driver_attr_debug_level);
        if (ret) {
                IWL_ERROR("Unable to create driver sysfs file\n");
-               pci_unregister_driver(&iwl4965_driver);
-               return ret;
+               goto error_debug;
        }
 #endif
 
        return ret;
+
+#ifdef CONFIG_IWLWIFI_DEBUG
+error_debug:
+       pci_unregister_driver(&iwl_driver);
+#endif
+error_register:
+       iwl4965_rate_control_unregister();
+       return ret;
 }
 
 static void __exit iwl4965_exit(void)
 {
 #ifdef CONFIG_IWLWIFI_DEBUG
-       driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level);
+       driver_remove_file(&iwl_driver.driver, &driver_attr_debug_level);
 #endif
-       pci_unregister_driver(&iwl4965_driver);
-}
-
-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(debug, iwl4965_mod_params.debug, int, 0444);
-MODULE_PARM_DESC(debug, "debug output mask");
-module_param_named(
-       disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444);
-MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
-
-module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
-MODULE_PARM_DESC(queues_num, "number of hw queues.");
-
-/* QoS */
-module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
-MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
-module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
-MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
+       pci_unregister_driver(&iwl_driver);
+       iwl4965_rate_control_unregister();
+}
 
 module_exit(iwl4965_exit);
 module_init(iwl4965_init);