]> err.no Git - linux-2.6/blobdiff - drivers/net/wireless/iwlwifi/iwl4965-base.c
iwlwifi: Re-ordering probe flow (4965)
[linux-2.6] / drivers / net / wireless / iwlwifi / iwl4965-base.c
index 20d012d4f37e34660b09dcc0d9df666b07322417..a2ee34e40b20085c1d77c39466ae09def619a93f 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved.
+ * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
  *
  * Portions of this file are derived from the ipw3945 project, as well
  * as portions of the ieee80211 subsystem header files.
 
 #include <asm/div64.h>
 
+#include "iwl-eeprom.h"
+#include "iwl-core.h"
 #include "iwl-4965.h"
 #include "iwl-helpers.h"
 
-#ifdef CONFIG_IWL4965_DEBUG
-u32 iwl4965_debug_level;
-#endif
-
-static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv,
+static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
                                  struct iwl4965_tx_queue *txq);
 
 /******************************************************************************
@@ -78,7 +76,7 @@ int iwl4965_param_amsdu_size_8K;   /* def: enable 8K amsdu size */
 
 #define DRV_DESCRIPTION        "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
 
-#ifdef CONFIG_IWL4965_DEBUG
+#ifdef CONFIG_IWLWIFI_DEBUG
 #define VD "d"
 #else
 #define VD
@@ -90,15 +88,8 @@ int iwl4965_param_amsdu_size_8K;   /* def: enable 8K amsdu size */
 #define VS
 #endif
 
-#define IWLWIFI_VERSION "1.2.26k" VD VS
-#define DRV_COPYRIGHT  "Copyright(c) 2003-2007 Intel Corporation"
-#define DRV_VERSION     IWLWIFI_VERSION
+#define DRV_VERSION     IWLWIFI_VERSION VD VS
 
-/* Change firmware file name, using "-" and incrementing number,
- *   *only* when uCode interface or architecture changes so that it
- *   is not compatible with earlier drivers.
- * This number will also appear in << 8 position of 1st dword of uCode file */
-#define IWL4965_UCODE_API "-1"
 
 MODULE_DESCRIPTION(DRV_DESCRIPTION);
 MODULE_VERSION(DRV_VERSION);
@@ -116,7 +107,7 @@ __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
 }
 
 static const struct ieee80211_supported_band *iwl4965_get_hw_mode(
-               struct iwl4965_priv *priv, enum ieee80211_band band)
+               struct iwl_priv *priv, enum ieee80211_band band)
 {
        return priv->hw->wiphy->bands[band];
 }
@@ -161,17 +152,6 @@ static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
        return escaped;
 }
 
-static void iwl4965_print_hex_dump(int level, void *p, u32 len)
-{
-#ifdef CONFIG_IWL4965_DEBUG
-       if (!(iwl4965_debug_level & level))
-               return;
-
-       print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
-                       p, len, 1);
-#endif
-}
-
 /*************** DMA-QUEUE-GENERAL-FUNCTIONS  *****
  * DMA services
  *
@@ -215,25 +195,6 @@ int iwl4965_queue_space(const struct iwl4965_queue *q)
        return s;
 }
 
-/**
- * iwl4965_queue_inc_wrap - increment queue index, wrap back to beginning
- * @index -- current index
- * @n_bd -- total number of entries in queue (must be power of 2)
- */
-static inline int iwl4965_queue_inc_wrap(int index, int n_bd)
-{
-       return ++index & (n_bd - 1);
-}
-
-/**
- * iwl4965_queue_dec_wrap - decrement queue index, wrap back to end
- * @index -- current index
- * @n_bd -- total number of entries in queue (must be power of 2)
- */
-static inline int iwl4965_queue_dec_wrap(int index, int n_bd)
-{
-       return --index & (n_bd - 1);
-}
 
 static inline int x2_queue_used(const struct iwl4965_queue *q, int i)
 {
@@ -255,15 +216,15 @@ static inline u8 get_cmd_index(struct iwl4965_queue *q, u32 index, int is_huge)
 /**
  * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes
  */
-static int iwl4965_queue_init(struct iwl4965_priv *priv, struct iwl4965_queue *q,
+static int iwl4965_queue_init(struct iwl_priv *priv, struct iwl4965_queue *q,
                          int count, int slots_num, u32 id)
 {
        q->n_bd = count;
        q->n_window = slots_num;
        q->id = id;
 
-       /* count must be power-of-two size, otherwise iwl4965_queue_inc_wrap
-        * and iwl4965_queue_dec_wrap are broken. */
+       /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
+        * and iwl_queue_dec_wrap are broken. */
        BUG_ON(!is_power_of_2(count));
 
        /* slots_num must be power-of-two size, otherwise
@@ -286,7 +247,7 @@ static int iwl4965_queue_init(struct iwl4965_priv *priv, struct iwl4965_queue *q
 /**
  * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
  */
-static int iwl4965_tx_queue_alloc(struct iwl4965_priv *priv,
+static int iwl4965_tx_queue_alloc(struct iwl_priv *priv,
                              struct iwl4965_tx_queue *txq, u32 id)
 {
        struct pci_dev *dev = priv->pci_dev;
@@ -331,7 +292,7 @@ static int iwl4965_tx_queue_alloc(struct iwl4965_priv *priv,
 /**
  * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue
  */
-int iwl4965_tx_queue_init(struct iwl4965_priv *priv,
+int iwl4965_tx_queue_init(struct iwl_priv *priv,
                      struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id)
 {
        struct pci_dev *dev = priv->pci_dev;
@@ -363,7 +324,7 @@ int iwl4965_tx_queue_init(struct iwl4965_priv *priv,
        txq->need_update = 0;
 
        /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
-        * iwl4965_queue_inc_wrap and iwl4965_queue_dec_wrap are broken. */
+        * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
        BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
 
        /* Initialize queue's high/low-water marks, and head/tail indexes */
@@ -383,7 +344,7 @@ int iwl4965_tx_queue_init(struct iwl4965_priv *priv,
  * Free all buffers.
  * 0-fill, but do not free "txq" descriptor structure.
  */
-void iwl4965_tx_queue_free(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq)
+void iwl4965_tx_queue_free(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
 {
        struct iwl4965_queue *q = &txq->q;
        struct pci_dev *dev = priv->pci_dev;
@@ -394,7 +355,7 @@ void iwl4965_tx_queue_free(struct iwl4965_priv *priv, struct iwl4965_tx_queue *t
 
        /* first, empty all BD's */
        for (; q->write_ptr != q->read_ptr;
-            q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd))
+            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;
@@ -434,7 +395,7 @@ const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  *
  * NOTE:  This does not remove station from device's station table.
  */
-static u8 iwl4965_remove_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap)
+static u8 iwl4965_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
 {
        int index = IWL_INVALID_STATION;
        int i;
@@ -476,7 +437,7 @@ out:
  *
  * NOTE:  This does not clear or otherwise alter the device's station table.
  */
-static void iwl4965_clear_stations_table(struct iwl4965_priv *priv)
+static void iwl4965_clear_stations_table(struct iwl_priv *priv)
 {
        unsigned long flags;
 
@@ -491,7 +452,7 @@ static void iwl4965_clear_stations_table(struct iwl4965_priv *priv)
 /**
  * iwl4965_add_station_flags - Add station to tables in driver and device
  */
-u8 iwl4965_add_station_flags(struct iwl4965_priv *priv, const u8 *addr,
+u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr,
                                int is_ap, u8 flags, void *ht_data)
 {
        int i;
@@ -563,7 +524,7 @@ u8 iwl4965_add_station_flags(struct iwl4965_priv *priv, const u8 *addr,
 
 /*************** DRIVER STATUS FUNCTIONS   *****/
 
-static inline int iwl4965_is_ready(struct iwl4965_priv *priv)
+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 */
@@ -572,23 +533,23 @@ static inline int iwl4965_is_ready(struct iwl4965_priv *priv)
               !test_bit(STATUS_EXIT_PENDING, &priv->status);
 }
 
-static inline int iwl4965_is_alive(struct iwl4965_priv *priv)
+static inline int iwl4965_is_alive(struct iwl_priv *priv)
 {
        return test_bit(STATUS_ALIVE, &priv->status);
 }
 
-static inline int iwl4965_is_init(struct iwl4965_priv *priv)
+static inline int iwl4965_is_init(struct iwl_priv *priv)
 {
        return test_bit(STATUS_INIT, &priv->status);
 }
 
-static inline int iwl4965_is_rfkill(struct iwl4965_priv *priv)
+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 iwl4965_priv *priv)
+static inline int iwl4965_is_ready_rf(struct iwl_priv *priv)
 {
 
        if (iwl4965_is_rfkill(priv))
@@ -667,7 +628,7 @@ 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 iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
+static int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
 {
        struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
        struct iwl4965_queue *q = &txq->q;
@@ -735,14 +696,14 @@ static int iwl4965_enqueue_hcmd(struct iwl4965_priv *priv, struct iwl4965_host_c
        ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0);
 
        /* Increment and update queue's write index */
-       q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd);
+       q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
        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 iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
+static int iwl4965_send_cmd_async(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
 {
        int ret;
 
@@ -766,7 +727,7 @@ static int iwl4965_send_cmd_async(struct iwl4965_priv *priv, struct iwl4965_host
        return 0;
 }
 
-static int iwl4965_send_cmd_sync(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
+static int iwl4965_send_cmd_sync(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
 {
        int cmd_idx;
        int ret;
@@ -854,7 +815,7 @@ out:
        return ret;
 }
 
-int iwl4965_send_cmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
+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);
@@ -862,7 +823,7 @@ int iwl4965_send_cmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
        return iwl4965_send_cmd_sync(priv, cmd);
 }
 
-int iwl4965_send_cmd_pdu(struct iwl4965_priv *priv, u8 id, u16 len, const void *data)
+int iwl4965_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, const void *data)
 {
        struct iwl4965_host_cmd cmd = {
                .id = id,
@@ -873,7 +834,7 @@ int iwl4965_send_cmd_pdu(struct iwl4965_priv *priv, u8 id, u16 len, const void *
        return iwl4965_send_cmd_sync(priv, &cmd);
 }
 
-static int __must_check iwl4965_send_cmd_u32(struct iwl4965_priv *priv, u8 id, u32 val)
+static int __must_check iwl4965_send_cmd_u32(struct iwl_priv *priv, u8 id, u32 val)
 {
        struct iwl4965_host_cmd cmd = {
                .id = id,
@@ -884,7 +845,7 @@ static int __must_check iwl4965_send_cmd_u32(struct iwl4965_priv *priv, u8 id, u
        return iwl4965_send_cmd_sync(priv, &cmd);
 }
 
-int iwl4965_send_statistics_request(struct iwl4965_priv *priv)
+int iwl4965_send_statistics_request(struct iwl_priv *priv)
 {
        return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
 }
@@ -895,7 +856,7 @@ int iwl4965_send_statistics_request(struct iwl4965_priv *priv)
  * there is only one AP station with id= IWL_AP_ID
  * NOTE: mutex must be held before calling this fnction
  */
-static int iwl4965_rxon_add_station(struct iwl4965_priv *priv,
+static int iwl4965_rxon_add_station(struct iwl_priv *priv,
                                const u8 *addr, int is_ap)
 {
        u8 sta_id;
@@ -931,7 +892,7 @@ static int iwl4965_rxon_add_station(struct iwl4965_priv *priv,
  * NOTE:  Does not commit to the hardware; it sets appropriate bit fields
  * in the staging RXON flag structure based on the phymode
  */
-static int iwl4965_set_rxon_channel(struct iwl4965_priv *priv,
+static int iwl4965_set_rxon_channel(struct iwl_priv *priv,
                                    enum ieee80211_band band,
                                 u16 channel)
 {
@@ -1039,7 +1000,7 @@ static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon)
  * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  */
-static int iwl4965_full_rxon_required(struct iwl4965_priv *priv)
+static int iwl4965_full_rxon_required(struct iwl_priv *priv)
 {
 
        /* These items are only settable from the full RXON command */
@@ -1079,7 +1040,7 @@ static int iwl4965_full_rxon_required(struct iwl4965_priv *priv)
        return 0;
 }
 
-static int iwl4965_send_rxon_assoc(struct iwl4965_priv *priv)
+static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
 {
        int rc = 0;
        struct iwl4965_rx_packet *res = NULL;
@@ -1141,7 +1102,7 @@ static int iwl4965_send_rxon_assoc(struct iwl4965_priv *priv)
  * function correctly transitions out of the RXON_ASSOC_MSK state if
  * a HW tune is required based on the RXON structure changes.
  */
-static int iwl4965_commit_rxon(struct iwl4965_priv *priv)
+static int iwl4965_commit_rxon(struct iwl_priv *priv)
 {
        /* cast away the const for active_rxon in this function */
        struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
@@ -1269,7 +1230,7 @@ static int iwl4965_commit_rxon(struct iwl4965_priv *priv)
        return 0;
 }
 
-static int iwl4965_send_bt_config(struct iwl4965_priv *priv)
+static int iwl4965_send_bt_config(struct iwl_priv *priv)
 {
        struct iwl4965_bt_cmd bt_cmd = {
                .flags = 3,
@@ -1283,7 +1244,7 @@ static int iwl4965_send_bt_config(struct iwl4965_priv *priv)
                                sizeof(struct iwl4965_bt_cmd), &bt_cmd);
 }
 
-static int iwl4965_send_scan_abort(struct iwl4965_priv *priv)
+static int iwl4965_send_scan_abort(struct iwl_priv *priv)
 {
        int rc = 0;
        struct iwl4965_rx_packet *res;
@@ -1324,7 +1285,7 @@ static int iwl4965_send_scan_abort(struct iwl4965_priv *priv)
        return rc;
 }
 
-static int iwl4965_card_state_sync_callback(struct iwl4965_priv *priv,
+static int iwl4965_card_state_sync_callback(struct iwl_priv *priv,
                                        struct iwl4965_cmd *cmd,
                                        struct sk_buff *skb)
 {
@@ -1341,7 +1302,7 @@ static int iwl4965_card_state_sync_callback(struct iwl4965_priv *priv,
  * When in the 'halt' state, the card is shut down and must be fully
  * restarted to come back on.
  */
-static int iwl4965_send_card_state(struct iwl4965_priv *priv, u32 flags, u8 meta_flag)
+static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
 {
        struct iwl4965_host_cmd cmd = {
                .id = REPLY_CARD_STATE_CMD,
@@ -1356,7 +1317,7 @@ static int iwl4965_send_card_state(struct iwl4965_priv *priv, u32 flags, u8 meta
        return iwl4965_send_cmd(priv, &cmd);
 }
 
-static int iwl4965_add_sta_sync_callback(struct iwl4965_priv *priv,
+static int iwl4965_add_sta_sync_callback(struct iwl_priv *priv,
                                     struct iwl4965_cmd *cmd, struct sk_buff *skb)
 {
        struct iwl4965_rx_packet *res = NULL;
@@ -1384,7 +1345,7 @@ static int iwl4965_add_sta_sync_callback(struct iwl4965_priv *priv,
        return 1;
 }
 
-int iwl4965_send_add_station(struct iwl4965_priv *priv,
+int iwl4965_send_add_station(struct iwl_priv *priv,
                         struct iwl4965_addsta_cmd *sta, u8 flags)
 {
        struct iwl4965_rx_packet *res = NULL;
@@ -1431,7 +1392,7 @@ int iwl4965_send_add_station(struct iwl4965_priv *priv,
        return rc;
 }
 
-static int iwl4965_update_sta_key_info(struct iwl4965_priv *priv,
+static int iwl4965_update_sta_key_info(struct iwl_priv *priv,
                                   struct ieee80211_key_conf *keyconf,
                                   u8 sta_id)
 {
@@ -1469,7 +1430,7 @@ static int iwl4965_update_sta_key_info(struct iwl4965_priv *priv,
        return 0;
 }
 
-static int iwl4965_clear_sta_key_info(struct iwl4965_priv *priv, u8 sta_id)
+static int iwl4965_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
 {
        unsigned long flags;
 
@@ -1486,7 +1447,7 @@ static int iwl4965_clear_sta_key_info(struct iwl4965_priv *priv, u8 sta_id)
        return 0;
 }
 
-static void iwl4965_clear_free_frames(struct iwl4965_priv *priv)
+static void iwl4965_clear_free_frames(struct iwl_priv *priv)
 {
        struct list_head *element;
 
@@ -1507,7 +1468,7 @@ static void iwl4965_clear_free_frames(struct iwl4965_priv *priv)
        }
 }
 
-static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl4965_priv *priv)
+static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl_priv *priv)
 {
        struct iwl4965_frame *frame;
        struct list_head *element;
@@ -1527,13 +1488,13 @@ static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl4965_priv *priv)
        return list_entry(element, struct iwl4965_frame, list);
 }
 
-static void iwl4965_free_frame(struct iwl4965_priv *priv, struct iwl4965_frame *frame)
+static void iwl4965_free_frame(struct iwl_priv *priv, struct iwl4965_frame *frame)
 {
        memset(frame, 0, sizeof(*frame));
        list_add(&frame->list, &priv->free_frames);
 }
 
-unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv *priv,
+unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
                                struct ieee80211_hdr *hdr,
                                const u8 *dest, int left)
 {
@@ -1551,34 +1512,6 @@ unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv *priv,
        return priv->ibss_beacon->len;
 }
 
-int iwl4965_rate_index_from_plcp(int plcp)
-{
-       int i = 0;
-
-       /* 4965 HT rate format */
-       if (plcp & RATE_MCS_HT_MSK) {
-               i = (plcp & 0xff);
-
-               if (i >= IWL_RATE_MIMO_6M_PLCP)
-                       i = i - IWL_RATE_MIMO_6M_PLCP;
-
-               i += IWL_FIRST_OFDM_RATE;
-               /* skip 9M not supported in ht*/
-               if (i >= IWL_RATE_9M_INDEX)
-                       i += 1;
-               if ((i >= IWL_FIRST_OFDM_RATE) &&
-                   (i <= IWL_LAST_OFDM_RATE))
-                       return i;
-
-       /* 4965 legacy rate format, search for match in table */
-       } else {
-               for (i = 0; i < ARRAY_SIZE(iwl4965_rates); i++)
-                       if (iwl4965_rates[i].plcp == (plcp &0xFF))
-                               return i;
-       }
-       return -1;
-}
-
 static u8 iwl4965_rate_get_lowest_plcp(int rate_mask)
 {
        u8 i;
@@ -1592,7 +1525,7 @@ static u8 iwl4965_rate_get_lowest_plcp(int rate_mask)
        return IWL_RATE_INVALID;
 }
 
-static int iwl4965_send_beacon_cmd(struct iwl4965_priv *priv)
+static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
 {
        struct iwl4965_frame *frame;
        unsigned int frame_size;
@@ -1628,234 +1561,13 @@ static int iwl4965_send_beacon_cmd(struct iwl4965_priv *priv)
        return rc;
 }
 
-/******************************************************************************
- *
- * EEPROM related functions
- *
- ******************************************************************************/
-
-static void get_eeprom_mac(struct iwl4965_priv *priv, u8 *mac)
-{
-       memcpy(mac, priv->eeprom.mac_address, 6);
-}
-
-static inline void iwl4965_eeprom_release_semaphore(struct iwl4965_priv *priv)
-{
-       iwl4965_clear_bit(priv, CSR_HW_IF_CONFIG_REG,
-               CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
-}
-
-/**
- * iwl4965_eeprom_init - read EEPROM contents
- *
- * Load the EEPROM contents from adapter into priv->eeprom
- *
- * NOTE:  This routine uses the non-debug IO access functions.
- */
-int iwl4965_eeprom_init(struct iwl4965_priv *priv)
-{
-       u16 *e = (u16 *)&priv->eeprom;
-       u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP);
-       u32 r;
-       int sz = sizeof(priv->eeprom);
-       int rc;
-       int i;
-       u16 addr;
-
-       /* The EEPROM structure has several padding buffers within it
-        * and when adding new EEPROM maps is subject to programmer errors
-        * which may be very difficult to identify without explicitly
-        * checking the resulting size of the eeprom map. */
-       BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
-
-       if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
-               IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
-               return -ENOENT;
-       }
-
-       /* Make sure driver (instead of uCode) is allowed to read EEPROM */
-       rc = iwl4965_eeprom_acquire_semaphore(priv);
-       if (rc < 0) {
-               IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
-               return -ENOENT;
-       }
-
-       /* eeprom is an array of 16bit values */
-       for (addr = 0; addr < sz; addr += sizeof(u16)) {
-               _iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1);
-               _iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
-
-               for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
-                                       i += IWL_EEPROM_ACCESS_DELAY) {
-                       r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG);
-                       if (r & CSR_EEPROM_REG_READ_VALID_MSK)
-                               break;
-                       udelay(IWL_EEPROM_ACCESS_DELAY);
-               }
-
-               if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
-                       IWL_ERROR("Time out reading EEPROM[%d]", addr);
-                       rc = -ETIMEDOUT;
-                       goto done;
-               }
-               e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
-       }
-       rc = 0;
-
-done:
-       iwl4965_eeprom_release_semaphore(priv);
-       return rc;
-}
-
 /******************************************************************************
  *
  * Misc. internal state and helper functions
  *
  ******************************************************************************/
-#ifdef CONFIG_IWL4965_DEBUG
-
-/**
- * iwl4965_report_frame - dump frame to syslog during debug sessions
- *
- * You may hack this function to show different aspects of received frames,
- * including selective frame dumps.
- * group100 parameter selects whether to show 1 out of 100 good frames.
- *
- * TODO:  This was originally written for 3945, need to audit for
- *        proper operation with 4965.
- */
-void iwl4965_report_frame(struct iwl4965_priv *priv,
-                     struct iwl4965_rx_packet *pkt,
-                     struct ieee80211_hdr *header, int group100)
-{
-       u32 to_us;
-       u32 print_summary = 0;
-       u32 print_dump = 0;     /* set to 1 to dump all frames' contents */
-       u32 hundred = 0;
-       u32 dataframe = 0;
-       u16 fc;
-       u16 seq_ctl;
-       u16 channel;
-       u16 phy_flags;
-       int rate_sym;
-       u16 length;
-       u16 status;
-       u16 bcn_tmr;
-       u32 tsf_low;
-       u64 tsf;
-       u8 rssi;
-       u8 agc;
-       u16 sig_avg;
-       u16 noise_diff;
-       struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
-       struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
-       struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
-       u8 *data = IWL_RX_DATA(pkt);
-
-       /* MAC header */
-       fc = le16_to_cpu(header->frame_control);
-       seq_ctl = le16_to_cpu(header->seq_ctrl);
-
-       /* metadata */
-       channel = le16_to_cpu(rx_hdr->channel);
-       phy_flags = le16_to_cpu(rx_hdr->phy_flags);
-       rate_sym = rx_hdr->rate;
-       length = le16_to_cpu(rx_hdr->len);
-
-       /* end-of-frame status and timestamp */
-       status = le32_to_cpu(rx_end->status);
-       bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
-       tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
-       tsf = le64_to_cpu(rx_end->timestamp);
-
-       /* signal statistics */
-       rssi = rx_stats->rssi;
-       agc = rx_stats->agc;
-       sig_avg = le16_to_cpu(rx_stats->sig_avg);
-       noise_diff = le16_to_cpu(rx_stats->noise_diff);
-
-       to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
-
-       /* if data frame is to us and all is good,
-        *   (optionally) print summary for only 1 out of every 100 */
-       if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
-           (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
-               dataframe = 1;
-               if (!group100)
-                       print_summary = 1;      /* print each frame */
-               else if (priv->framecnt_to_us < 100) {
-                       priv->framecnt_to_us++;
-                       print_summary = 0;
-               } else {
-                       priv->framecnt_to_us = 0;
-                       print_summary = 1;
-                       hundred = 1;
-               }
-       } else {
-               /* print summary for all other frames */
-               print_summary = 1;
-       }
-
-       if (print_summary) {
-               char *title;
-               u32 rate;
-
-               if (hundred)
-                       title = "100Frames";
-               else if (fc & IEEE80211_FCTL_RETRY)
-                       title = "Retry";
-               else if (ieee80211_is_assoc_response(fc))
-                       title = "AscRsp";
-               else if (ieee80211_is_reassoc_response(fc))
-                       title = "RasRsp";
-               else if (ieee80211_is_probe_response(fc)) {
-                       title = "PrbRsp";
-                       print_dump = 1; /* dump frame contents */
-               } else if (ieee80211_is_beacon(fc)) {
-                       title = "Beacon";
-                       print_dump = 1; /* dump frame contents */
-               } else if (ieee80211_is_atim(fc))
-                       title = "ATIM";
-               else if (ieee80211_is_auth(fc))
-                       title = "Auth";
-               else if (ieee80211_is_deauth(fc))
-                       title = "DeAuth";
-               else if (ieee80211_is_disassoc(fc))
-                       title = "DisAssoc";
-               else
-                       title = "Frame";
 
-               rate = iwl4965_rate_index_from_plcp(rate_sym);
-               if (rate == -1)
-                       rate = 0;
-               else
-                       rate = iwl4965_rates[rate].ieee / 2;
-
-               /* print frame summary.
-                * MAC addresses show just the last byte (for brevity),
-                *    but you can hack it to show more, if you'd like to. */
-               if (dataframe)
-                       IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
-                                    "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
-                                    title, fc, header->addr1[5],
-                                    length, rssi, channel, rate);
-               else {
-                       /* src/dst addresses assume managed mode */
-                       IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
-                                    "src=0x%02x, rssi=%u, tim=%lu usec, "
-                                    "phy=0x%02x, chnl=%d\n",
-                                    title, fc, header->addr1[5],
-                                    header->addr3[5], rssi,
-                                    tsf_low - priv->scan_start_tsf,
-                                    phy_flags, channel);
-               }
-       }
-       if (print_dump)
-               iwl4965_print_hex_dump(IWL_DL_RX, data, length);
-}
-#endif
-
-static void iwl4965_unset_hw_setting(struct iwl4965_priv *priv)
+static void iwl4965_unset_hw_setting(struct iwl_priv *priv)
 {
        if (priv->hw_setting.shared_virt)
                pci_free_consistent(priv->pci_dev,
@@ -1896,7 +1608,7 @@ static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
 /**
  * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
  */
-static u16 iwl4965_fill_probe_req(struct iwl4965_priv *priv,
+static u16 iwl4965_fill_probe_req(struct iwl_priv *priv,
                                  enum ieee80211_band band,
                                  struct ieee80211_mgmt *frame,
                                  int left, int is_direct)
@@ -2014,7 +1726,7 @@ static u16 iwl4965_fill_probe_req(struct iwl4965_priv *priv,
 /*
  * QoS  support
 */
-static int iwl4965_send_qos_params_command(struct iwl4965_priv *priv,
+static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
                                       struct iwl4965_qosparam_cmd *qos)
 {
 
@@ -2022,7 +1734,7 @@ static int iwl4965_send_qos_params_command(struct iwl4965_priv *priv,
                                sizeof(struct iwl4965_qosparam_cmd), qos);
 }
 
-static void iwl4965_reset_qos(struct iwl4965_priv *priv)
+static void iwl4965_reset_qos(struct iwl_priv *priv)
 {
        u16 cw_min = 15;
        u16 cw_max = 1023;
@@ -2109,7 +1821,7 @@ static void iwl4965_reset_qos(struct iwl4965_priv *priv)
        spin_unlock_irqrestore(&priv->lock, flags);
 }
 
-static void iwl4965_activate_qos(struct iwl4965_priv *priv, u8 force)
+static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
 {
        unsigned long flags;
 
@@ -2187,7 +1899,7 @@ static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = {
                 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
 };
 
-int iwl4965_power_init_handle(struct iwl4965_priv *priv)
+int iwl4965_power_init_handle(struct iwl_priv *priv)
 {
        int rc = 0, i;
        struct iwl4965_power_mgr *pow_data;
@@ -2226,7 +1938,7 @@ int iwl4965_power_init_handle(struct iwl4965_priv *priv)
        return rc;
 }
 
-static int iwl4965_update_power_cmd(struct iwl4965_priv *priv,
+static int iwl4965_update_power_cmd(struct iwl_priv *priv,
                                struct iwl4965_powertable_cmd *cmd, u32 mode)
 {
        int rc = 0, i;
@@ -2290,7 +2002,7 @@ static int iwl4965_update_power_cmd(struct iwl4965_priv *priv,
        return rc;
 }
 
-static int iwl4965_send_power_mode(struct iwl4965_priv *priv, u32 mode)
+static int iwl4965_send_power_mode(struct iwl_priv *priv, u32 mode)
 {
        u32 uninitialized_var(final_mode);
        int rc;
@@ -2325,7 +2037,7 @@ static int iwl4965_send_power_mode(struct iwl4965_priv *priv, u32 mode)
        return rc;
 }
 
-int iwl4965_is_network_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header)
+int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
 {
        /* Filter incoming packets to determine if they are targeted toward
         * this network, discarding packets coming from ourselves */
@@ -2386,7 +2098,7 @@ static const char *iwl4965_get_tx_fail_reason(u32 status)
  *
  * NOTE: priv->mutex is not required before calling this function
  */
-static int iwl4965_scan_cancel(struct iwl4965_priv *priv)
+static int iwl4965_scan_cancel(struct iwl_priv *priv)
 {
        if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
                clear_bit(STATUS_SCANNING, &priv->status);
@@ -2414,7 +2126,7 @@ static int iwl4965_scan_cancel(struct iwl4965_priv *priv)
  *
  * NOTE: priv->mutex must be held before calling this function
  */
-static int iwl4965_scan_cancel_timeout(struct iwl4965_priv *priv, unsigned long ms)
+static int iwl4965_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
 {
        unsigned long now = jiffies;
        int ret;
@@ -2433,7 +2145,7 @@ static int iwl4965_scan_cancel_timeout(struct iwl4965_priv *priv, unsigned long
        return ret;
 }
 
-static void iwl4965_sequence_reset(struct iwl4965_priv *priv)
+static void iwl4965_sequence_reset(struct iwl_priv *priv)
 {
        /* Reset ieee stats */
 
@@ -2463,7 +2175,7 @@ static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
        return cpu_to_le16(new_val);
 }
 
-static void iwl4965_setup_rxon_timing(struct iwl4965_priv *priv)
+static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
 {
        u64 interval_tm_unit;
        u64 tsf, result;
@@ -2519,7 +2231,7 @@ static void iwl4965_setup_rxon_timing(struct iwl4965_priv *priv)
                le16_to_cpu(priv->rxon_timing.atim_window));
 }
 
-static int iwl4965_scan_initiate(struct iwl4965_priv *priv)
+static int iwl4965_scan_initiate(struct iwl_priv *priv)
 {
        if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
                IWL_ERROR("APs don't scan.\n");
@@ -2553,7 +2265,7 @@ static int iwl4965_scan_initiate(struct iwl4965_priv *priv)
        return 0;
 }
 
-static int iwl4965_set_rxon_hwcrypto(struct iwl4965_priv *priv, int hw_decrypt)
+static int iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
 {
        struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
 
@@ -2565,7 +2277,7 @@ static int iwl4965_set_rxon_hwcrypto(struct iwl4965_priv *priv, int hw_decrypt)
        return 0;
 }
 
-static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv,
+static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv,
                                          enum ieee80211_band band)
 {
        if (band == IEEE80211_BAND_5GHZ) {
@@ -2592,7 +2304,7 @@ static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv,
 /*
  * initialize rxon structure with default values from eeprom
  */
-static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv)
+static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
 {
        const struct iwl4965_channel_info *ch_info;
 
@@ -2664,7 +2376,7 @@ static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv)
        iwl4965_set_rxon_chain(priv);
 }
 
-static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode)
+static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
 {
        if (mode == IEEE80211_IF_TYPE_IBSS) {
                const struct iwl4965_channel_info *ch_info;
@@ -2703,7 +2415,7 @@ static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode)
        return 0;
 }
 
-static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv,
+static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
                                      struct ieee80211_tx_control *ctl,
                                      struct iwl4965_cmd *cmd,
                                      struct sk_buff *skb_frag,
@@ -2715,6 +2427,8 @@ static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv,
        case ALG_CCMP:
                cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
                memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
+               if (ctl->flags & IEEE80211_TXCTL_AMPDU)
+                       cmd->cmd.tx.tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
                IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
                break;
 
@@ -2752,7 +2466,7 @@ static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv,
 /*
  * handle build REPLY_TX command notification.
  */
-static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv *priv,
+static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv,
                                  struct iwl4965_cmd *cmd,
                                  struct ieee80211_tx_control *ctrl,
                                  struct ieee80211_hdr *hdr,
@@ -2815,13 +2529,19 @@ static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv *priv,
        cmd->cmd.tx.tx_flags = tx_flags;
        cmd->cmd.tx.next_frame_len = 0;
 }
-
+static void iwl_update_tx_stats(struct iwl_priv *priv, u16 fc, u16 len)
+{
+       /* 0 - mgmt, 1 - cnt, 2 - data */
+       int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
+       priv->tx_stats[idx].cnt++;
+       priv->tx_stats[idx].bytes += len;
+}
 /**
  * iwl4965_get_sta_id - Find station's index within station table
  *
  * If new IBSS station, create new entry in station table
  */
-static int iwl4965_get_sta_id(struct iwl4965_priv *priv,
+static int iwl4965_get_sta_id(struct iwl_priv *priv,
                                struct ieee80211_hdr *hdr)
 {
        int sta_id;
@@ -2864,7 +2584,7 @@ static int iwl4965_get_sta_id(struct iwl4965_priv *priv,
                IWL_DEBUG_DROP("Station %s not in station map. "
                               "Defaulting to broadcast...\n",
                               print_mac(mac, hdr->addr1));
-               iwl4965_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
+               iwl_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
                return priv->hw_setting.bcast_sta_id;
 
        default:
@@ -2876,7 +2596,7 @@ static int iwl4965_get_sta_id(struct iwl4965_priv *priv,
 /*
  * start REPLY_TX command process
  */
-static int iwl4965_tx_skb(struct iwl4965_priv *priv,
+static int iwl4965_tx_skb(struct iwl_priv *priv,
                      struct sk_buff *skb, struct ieee80211_tx_control *ctl)
 {
        struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
@@ -2920,7 +2640,7 @@ static int iwl4965_tx_skb(struct iwl4965_priv *priv,
 
        fc = le16_to_cpu(hdr->frame_control);
 
-#ifdef CONFIG_IWL4965_DEBUG
+#ifdef CONFIG_IWLWIFI_DEBUG
        if (ieee80211_is_auth(fc))
                IWL_DEBUG_TX("Sending AUTH frame\n");
        else if (ieee80211_is_assoc_request(fc))
@@ -3062,6 +2782,8 @@ static int iwl4965_tx_skb(struct iwl4965_priv *priv,
        /* set is_hcca to 0; it probably will never be implemented */
        iwl4965_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
 
+       iwl_update_tx_stats(priv, fc, len);
+
        scratch_phys = txcmd_phys + sizeof(struct iwl4965_cmd_header) +
                offsetof(struct iwl4965_tx_cmd, scratch);
        out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys);
@@ -3078,17 +2800,17 @@ static int iwl4965_tx_skb(struct iwl4965_priv *priv,
                txq->need_update = 0;
        }
 
-       iwl4965_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
+       iwl_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
                           sizeof(out_cmd->cmd.tx));
 
-       iwl4965_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
+       iwl_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
                           ieee80211_get_hdrlen(fc));
 
        /* Set up entry for this TFD in Tx byte-count array */
        iwl4965_tx_queue_update_wr_ptr(priv, txq, len);
 
        /* Tell device the write index *just past* this latest filled TFD */
-       q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd);
+       q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
        rc = iwl4965_tx_queue_update_write_ptr(priv, txq);
        spin_unlock_irqrestore(&priv->lock, flags);
 
@@ -3115,7 +2837,7 @@ drop:
        return -1;
 }
 
-static void iwl4965_set_rate(struct iwl4965_priv *priv)
+static void iwl4965_set_rate(struct iwl_priv *priv)
 {
        const struct ieee80211_supported_band *hw = NULL;
        struct ieee80211_rate *rate;
@@ -3162,7 +2884,7 @@ static void iwl4965_set_rate(struct iwl4965_priv *priv)
                   (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
 }
 
-static void iwl4965_radio_kill_sw(struct iwl4965_priv *priv, int disable_radio)
+static void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
 {
        unsigned long flags;
 
@@ -3211,7 +2933,7 @@ static void iwl4965_radio_kill_sw(struct iwl4965_priv *priv, int disable_radio)
        return;
 }
 
-void iwl4965_set_decrypted_flag(struct iwl4965_priv *priv, struct sk_buff *skb,
+void iwl4965_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
                            u32 decrypt_res, struct ieee80211_rx_status *stats)
 {
        u16 fc =
@@ -3246,7 +2968,7 @@ void iwl4965_set_decrypted_flag(struct iwl4965_priv *priv, struct sk_buff *skb,
 
 #define IWL_PACKET_RETRY_TIME HZ
 
-int iwl4965_is_duplicate_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header)
+int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
 {
        u16 sc = le16_to_cpu(header->seq_ctrl);
        u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
@@ -3363,7 +3085,7 @@ static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
        return cpu_to_le32(res);
 }
 
-static int iwl4965_get_measurement(struct iwl4965_priv *priv,
+static int iwl4965_get_measurement(struct iwl_priv *priv,
                               struct ieee80211_measurement_params *params,
                               u8 type)
 {
@@ -3443,7 +3165,7 @@ static int iwl4965_get_measurement(struct iwl4965_priv *priv,
 }
 #endif
 
-static void iwl4965_txstatus_to_ieee(struct iwl4965_priv *priv,
+static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv,
                                 struct iwl4965_tx_info *tx_sta)
 {
 
@@ -3469,7 +3191,7 @@ static void iwl4965_txstatus_to_ieee(struct iwl4965_priv *priv,
  * need to be reclaimed. As result, some free space forms.  If there is
  * enough free space (> low mark), wake the stack that feeds us.
  */
-int iwl4965_tx_queue_reclaim(struct iwl4965_priv *priv, int txq_id, int index)
+int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
 {
        struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
        struct iwl4965_queue *q = &txq->q;
@@ -3482,9 +3204,9 @@ int iwl4965_tx_queue_reclaim(struct iwl4965_priv *priv, int txq_id, int index)
                return 0;
        }
 
-       for (index = iwl4965_queue_inc_wrap(index, q->n_bd);
+       for (index = iwl_queue_inc_wrap(index, q->n_bd);
                q->read_ptr != index;
-               q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd)) {
+               q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
                if (txq_id != IWL_CMD_QUEUE_NUM) {
                        iwl4965_txstatus_to_ieee(priv,
                                        &(txq->txb[txq->q.read_ptr]));
@@ -3520,7 +3242,7 @@ static int iwl4965_is_tx_success(u32 status)
  ******************************************************************************/
 #ifdef CONFIG_IWL4965_HT
 
-static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv *priv,
+static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv,
                                    struct ieee80211_hdr *hdr)
 {
        if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
@@ -3532,7 +3254,7 @@ static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv *priv,
 }
 
 static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr(
-       struct iwl4965_priv *priv, int txq_id, int idx)
+       struct iwl_priv *priv, int txq_id, int idx)
 {
        if (priv->txq[txq_id].txb[idx].skb[0])
                return (struct ieee80211_hdr *)priv->txq[txq_id].
@@ -3551,7 +3273,7 @@ static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
 /**
  * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
  */
-static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv,
+static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
                                      struct iwl4965_ht_agg *agg,
                                      struct iwl4965_tx_resp_agg *tx_resp,
                                      u16 start_idx)
@@ -3591,9 +3313,9 @@ static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv,
                tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU;
                tx_status->flags = iwl4965_is_tx_success(status)?
                        IEEE80211_TX_STATUS_ACK : 0;
-               /* FIXME Wrong Rate
-               tx_status->control.tx_rate =
-                               iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags); */
+               iwl4965_hwrate_to_tx_control(priv,
+                                            le32_to_cpu(tx_resp->rate_n_flags),
+                                            &tx_status->control);
                /* FIXME: code repetition end */
 
                IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
@@ -3672,7 +3394,7 @@ static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv,
 /**
  * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
  */
-static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv,
+static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
                            struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
@@ -3729,7 +3451,7 @@ static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv,
 
                if (txq->q.read_ptr != (scd_ssn & 0xff)) {
                        int freed;
-                       index = iwl4965_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
+                       index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
                        IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
                                           "%d index %d\n", scd_ssn , index);
                        freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
@@ -3750,9 +3472,10 @@ static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv,
        tx_status->queue_number = status;
        tx_status->queue_length = tx_resp->bt_kill_count;
        tx_status->queue_length |= tx_resp->failure_rts;
-
        tx_status->flags =
            iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
+       iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
+                                    &tx_status->control);
 
        IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
                     "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status),
@@ -3782,7 +3505,7 @@ static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv,
 }
 
 
-static void iwl4965_rx_reply_alive(struct iwl4965_priv *priv,
+static void iwl4965_rx_reply_alive(struct iwl_priv *priv,
                               struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
@@ -3818,7 +3541,7 @@ static void iwl4965_rx_reply_alive(struct iwl4965_priv *priv,
                IWL_WARNING("uCode did not respond OK.\n");
 }
 
-static void iwl4965_rx_reply_add_sta(struct iwl4965_priv *priv,
+static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv,
                                 struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
@@ -3827,7 +3550,7 @@ static void iwl4965_rx_reply_add_sta(struct iwl4965_priv *priv,
        return;
 }
 
-static void iwl4965_rx_reply_error(struct iwl4965_priv *priv,
+static void iwl4965_rx_reply_error(struct iwl_priv *priv,
                               struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
@@ -3843,7 +3566,7 @@ static void iwl4965_rx_reply_error(struct iwl4965_priv *priv,
 
 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
 
-static void iwl4965_rx_csa(struct iwl4965_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
+static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
        struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon;
@@ -3854,7 +3577,7 @@ static void iwl4965_rx_csa(struct iwl4965_priv *priv, struct iwl4965_rx_mem_buff
        priv->staging_rxon.channel = csa->channel;
 }
 
-static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv *priv,
+static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
                                          struct iwl4965_rx_mem_buffer *rxb)
 {
 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
@@ -3872,10 +3595,10 @@ static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv *priv,
 #endif
 }
 
-static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv *priv,
+static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
                                  struct iwl4965_rx_mem_buffer *rxb)
 {
-#ifdef CONFIG_IWL4965_DEBUG
+#ifdef CONFIG_IWLWIFI_DEBUG
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
        struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
        IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
@@ -3883,20 +3606,20 @@ static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv *priv,
 #endif
 }
 
-static void iwl4965_rx_pm_debug_statistics_notif(struct iwl4965_priv *priv,
+static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
                                             struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
        IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
                        "notification for %s:\n",
                        le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
-       iwl4965_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
+       iwl_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
 }
 
 static void iwl4965_bg_beacon_update(struct work_struct *work)
 {
-       struct iwl4965_priv *priv =
-               container_of(work, struct iwl4965_priv, beacon_update);
+       struct iwl_priv *priv =
+               container_of(work, struct iwl_priv, beacon_update);
        struct sk_buff *beacon;
 
        /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
@@ -3918,10 +3641,10 @@ static void iwl4965_bg_beacon_update(struct work_struct *work)
        iwl4965_send_beacon_cmd(priv);
 }
 
-static void iwl4965_rx_beacon_notif(struct iwl4965_priv *priv,
+static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
                                struct iwl4965_rx_mem_buffer *rxb)
 {
-#ifdef CONFIG_IWL4965_DEBUG
+#ifdef CONFIG_IWLWIFI_DEBUG
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
        struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
        u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
@@ -3941,10 +3664,10 @@ static void iwl4965_rx_beacon_notif(struct iwl4965_priv *priv,
 }
 
 /* Service response to REPLY_SCAN_CMD (0x80) */
-static void iwl4965_rx_reply_scan(struct iwl4965_priv *priv,
+static void iwl4965_rx_reply_scan(struct iwl_priv *priv,
                              struct iwl4965_rx_mem_buffer *rxb)
 {
-#ifdef CONFIG_IWL4965_DEBUG
+#ifdef CONFIG_IWLWIFI_DEBUG
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
        struct iwl4965_scanreq_notification *notif =
            (struct iwl4965_scanreq_notification *)pkt->u.raw;
@@ -3954,7 +3677,7 @@ static void iwl4965_rx_reply_scan(struct iwl4965_priv *priv,
 }
 
 /* Service SCAN_START_NOTIFICATION (0x82) */
-static void iwl4965_rx_scan_start_notif(struct iwl4965_priv *priv,
+static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv,
                                    struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
@@ -3971,7 +3694,7 @@ static void iwl4965_rx_scan_start_notif(struct iwl4965_priv *priv,
 }
 
 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
-static void iwl4965_rx_scan_results_notif(struct iwl4965_priv *priv,
+static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv,
                                      struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
@@ -3996,7 +3719,7 @@ static void iwl4965_rx_scan_results_notif(struct iwl4965_priv *priv,
 }
 
 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
-static void iwl4965_rx_scan_complete_notif(struct iwl4965_priv *priv,
+static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv,
                                       struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
@@ -4054,7 +3777,7 @@ reschedule:
 
 /* Handle notification from uCode that card's power state is changing
  * due to software, hardware, or critical temperature RFKILL */
-static void iwl4965_rx_card_state_notif(struct iwl4965_priv *priv,
+static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
                                    struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
@@ -4132,7 +3855,7 @@ static void iwl4965_rx_card_state_notif(struct iwl4965_priv *priv,
  * This function chains into the hardware specific files for them to setup
  * any hardware specific handlers as well.
  */
-static void iwl4965_setup_rx_handlers(struct iwl4965_priv *priv)
+static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
 {
        priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive;
        priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta;
@@ -4174,7 +3897,7 @@ static void iwl4965_setup_rx_handlers(struct iwl4965_priv *priv)
  * will be executed.  The attached skb (if present) will only be freed
  * if the callback returns 1
  */
-static void iwl4965_tx_cmd_complete(struct iwl4965_priv *priv,
+static void iwl4965_tx_cmd_complete(struct iwl_priv *priv,
                                struct iwl4965_rx_mem_buffer *rxb)
 {
        struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
@@ -4297,7 +4020,7 @@ static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q)
 /**
  * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
  */
-int iwl4965_rx_queue_update_write_ptr(struct iwl4965_priv *priv, struct iwl4965_rx_queue *q)
+int iwl4965_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl4965_rx_queue *q)
 {
        u32 reg = 0;
        int rc = 0;
@@ -4343,7 +4066,7 @@ int iwl4965_rx_queue_update_write_ptr(struct iwl4965_priv *priv, struct iwl4965_
 /**
  * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  */
-static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv *priv,
+static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl_priv *priv,
                                          dma_addr_t dma_addr)
 {
        return cpu_to_le32((u32)(dma_addr >> 8));
@@ -4361,7 +4084,7 @@ static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv *priv,
  * also updates the memory address in the firmware to reference the new
  * target buffer.
  */
-static int iwl4965_rx_queue_restock(struct iwl4965_priv *priv)
+static int iwl4965_rx_queue_restock(struct iwl_priv *priv)
 {
        struct iwl4965_rx_queue *rxq = &priv->rxq;
        struct list_head *element;
@@ -4413,7 +4136,7 @@ static int iwl4965_rx_queue_restock(struct iwl4965_priv *priv)
  * Also restock the Rx queue via iwl4965_rx_queue_restock.
  * This is called as a scheduled work item (except for during initialization)
  */
-static void iwl4965_rx_allocate(struct iwl4965_priv *priv)
+static void iwl4965_rx_allocate(struct iwl_priv *priv)
 {
        struct iwl4965_rx_queue *rxq = &priv->rxq;
        struct list_head *element;
@@ -4455,7 +4178,7 @@ static void iwl4965_rx_allocate(struct iwl4965_priv *priv)
 */
 static void __iwl4965_rx_replenish(void *data)
 {
-       struct iwl4965_priv *priv = data;
+       struct iwl_priv *priv = data;
 
        iwl4965_rx_allocate(priv);
        iwl4965_rx_queue_restock(priv);
@@ -4464,7 +4187,7 @@ static void __iwl4965_rx_replenish(void *data)
 
 void iwl4965_rx_replenish(void *data)
 {
-       struct iwl4965_priv *priv = data;
+       struct iwl_priv *priv = data;
        unsigned long flags;
 
        iwl4965_rx_allocate(priv);
@@ -4479,7 +4202,7 @@ void iwl4965_rx_replenish(void *data)
  * This free routine walks the list of POOL entries and if SKB is set to
  * non NULL it is unmapped and freed
  */
-static void iwl4965_rx_queue_free(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq)
+static void iwl4965_rx_queue_free(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
 {
        int i;
        for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
@@ -4497,7 +4220,7 @@ static void iwl4965_rx_queue_free(struct iwl4965_priv *priv, struct iwl4965_rx_q
        rxq->bd = NULL;
 }
 
-int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv)
+int iwl4965_rx_queue_alloc(struct iwl_priv *priv)
 {
        struct iwl4965_rx_queue *rxq = &priv->rxq;
        struct pci_dev *dev = priv->pci_dev;
@@ -4524,7 +4247,7 @@ int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv)
        return 0;
 }
 
-void iwl4965_rx_queue_reset(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq)
+void iwl4965_rx_queue_reset(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
 {
        unsigned long flags;
        int i;
@@ -4639,7 +4362,7 @@ int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
  * the appropriate handlers, including command responses,
  * frame-received notifications, and other notifications.
  */
-static void iwl4965_rx_handle(struct iwl4965_priv *priv)
+static void iwl4965_rx_handle(struct iwl_priv *priv)
 {
        struct iwl4965_rx_mem_buffer *rxb;
        struct iwl4965_rx_packet *pkt;
@@ -4752,7 +4475,7 @@ static void iwl4965_rx_handle(struct iwl4965_priv *priv)
 /**
  * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
  */
-static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv,
+static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
                                  struct iwl4965_tx_queue *txq)
 {
        u32 reg = 0;
@@ -4795,13 +4518,13 @@ static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv,
        return rc;
 }
 
-#ifdef CONFIG_IWL4965_DEBUG
+#ifdef CONFIG_IWLWIFI_DEBUG
 static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon)
 {
        DECLARE_MAC_BUF(mac);
 
        IWL_DEBUG_RADIO("RX CONFIG:\n");
-       iwl4965_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
+       iwl_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
        IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
        IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
        IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
@@ -4818,14 +4541,14 @@ static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon)
 }
 #endif
 
-static void iwl4965_enable_interrupts(struct iwl4965_priv *priv)
+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);
 }
 
-static inline void iwl4965_disable_interrupts(struct iwl4965_priv *priv)
+static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
 {
        clear_bit(STATUS_INT_ENABLED, &priv->status);
 
@@ -4862,7 +4585,7 @@ static const char *desc_lookup(int i)
 #define ERROR_START_OFFSET  (1 * sizeof(u32))
 #define ERROR_ELEM_SIZE     (7 * sizeof(u32))
 
-static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv)
+static void iwl4965_dump_nic_error_log(struct iwl_priv *priv)
 {
        u32 data2, line;
        u32 desc, time, count, base, data1;
@@ -4886,8 +4609,7 @@ static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv)
 
        if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
                IWL_ERROR("Start IWL Error Log Dump:\n");
-               IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n",
-                         priv->status, priv->config, count);
+               IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count);
        }
 
        desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32));
@@ -4918,7 +4640,7 @@ static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv)
  *
  * NOTE: Must be called with iwl4965_grab_nic_access() already obtained!
  */
-static void iwl4965_print_event_log(struct iwl4965_priv *priv, u32 start_idx,
+static void iwl4965_print_event_log(struct iwl_priv *priv, u32 start_idx,
                                u32 num_events, u32 mode)
 {
        u32 i;
@@ -4956,7 +4678,7 @@ static void iwl4965_print_event_log(struct iwl4965_priv *priv, u32 start_idx,
        }
 }
 
-static void iwl4965_dump_nic_event_log(struct iwl4965_priv *priv)
+static void iwl4965_dump_nic_event_log(struct iwl_priv *priv)
 {
        int rc;
        u32 base;       /* SRAM byte address of event log header */
@@ -5011,7 +4733,7 @@ static void iwl4965_dump_nic_event_log(struct iwl4965_priv *priv)
 /**
  * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
  */
-static void iwl4965_irq_handle_error(struct iwl4965_priv *priv)
+static void iwl4965_irq_handle_error(struct iwl_priv *priv)
 {
        /* Set the FW error flag -- cleared on iwl4965_down */
        set_bit(STATUS_FW_ERROR, &priv->status);
@@ -5019,8 +4741,8 @@ static void iwl4965_irq_handle_error(struct iwl4965_priv *priv)
        /* Cancel currently queued command. */
        clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
 
-#ifdef CONFIG_IWL4965_DEBUG
-       if (iwl4965_debug_level & IWL_DL_FW_ERRORS) {
+#ifdef CONFIG_IWLWIFI_DEBUG
+       if (iwl_debug_level & IWL_DL_FW_ERRORS) {
                iwl4965_dump_nic_error_log(priv);
                iwl4965_dump_nic_event_log(priv);
                iwl4965_print_rx_config_cmd(&priv->staging_rxon);
@@ -5046,7 +4768,7 @@ static void iwl4965_irq_handle_error(struct iwl4965_priv *priv)
        }
 }
 
-static void iwl4965_error_recovery(struct iwl4965_priv *priv)
+static void iwl4965_error_recovery(struct iwl_priv *priv)
 {
        unsigned long flags;
 
@@ -5063,12 +4785,12 @@ static void iwl4965_error_recovery(struct iwl4965_priv *priv)
        spin_unlock_irqrestore(&priv->lock, flags);
 }
 
-static void iwl4965_irq_tasklet(struct iwl4965_priv *priv)
+static void iwl4965_irq_tasklet(struct iwl_priv *priv)
 {
        u32 inta, handled = 0;
        u32 inta_fh;
        unsigned long flags;
-#ifdef CONFIG_IWL4965_DEBUG
+#ifdef CONFIG_IWLWIFI_DEBUG
        u32 inta_mask;
 #endif
 
@@ -5086,8 +4808,8 @@ static void iwl4965_irq_tasklet(struct iwl4965_priv *priv)
        inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
        iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh);
 
-#ifdef CONFIG_IWL4965_DEBUG
-       if (iwl4965_debug_level & IWL_DL_ISR) {
+#ifdef CONFIG_IWLWIFI_DEBUG
+       if (iwl_debug_level & IWL_DL_ISR) {
                /* just for debug */
                inta_mask = iwl4965_read32(priv, CSR_INT_MASK);
                IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
@@ -5099,9 +4821,9 @@ static void iwl4965_irq_tasklet(struct iwl4965_priv *priv)
         * atomic, make sure that inta covers all the interrupts that
         * we've discovered, even if FH interrupt came in just after
         * reading CSR_INT. */
-       if (inta_fh & CSR_FH_INT_RX_MASK)
+       if (inta_fh & CSR49_FH_INT_RX_MASK)
                inta |= CSR_INT_BIT_FH_RX;
-       if (inta_fh & CSR_FH_INT_TX_MASK)
+       if (inta_fh & CSR49_FH_INT_TX_MASK)
                inta |= CSR_INT_BIT_FH_TX;
 
        /* Now service all interrupt bits discovered above. */
@@ -5120,8 +4842,8 @@ static void iwl4965_irq_tasklet(struct iwl4965_priv *priv)
                return;
        }
 
-#ifdef CONFIG_IWL4965_DEBUG
-       if (iwl4965_debug_level & (IWL_DL_ISR)) {
+#ifdef CONFIG_IWLWIFI_DEBUG
+       if (iwl_debug_level & (IWL_DL_ISR)) {
                /* NIC fires this, but we don't use it, redundant with WAKEUP */
                if (inta & CSR_INT_BIT_SCD)
                        IWL_DEBUG_ISR("Scheduler finished to transmit "
@@ -5211,8 +4933,8 @@ static void iwl4965_irq_tasklet(struct iwl4965_priv *priv)
        /* Re-enable all interrupts */
        iwl4965_enable_interrupts(priv);
 
-#ifdef CONFIG_IWL4965_DEBUG
-       if (iwl4965_debug_level & (IWL_DL_ISR)) {
+#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);
@@ -5225,7 +4947,7 @@ static void iwl4965_irq_tasklet(struct iwl4965_priv *priv)
 
 static irqreturn_t iwl4965_isr(int irq, void *data)
 {
-       struct iwl4965_priv *priv = data;
+       struct iwl_priv *priv = data;
        u32 inta, inta_mask;
        u32 inta_fh;
        if (!priv)
@@ -5285,7 +5007,7 @@ static irqreturn_t iwl4965_isr(int irq, void *data)
  * EEPROM contents to the specific channel number supported for each
  * band.
  *
- * For example, iwl4965_priv->eeprom.band_3_channels[4] from the band_3
+ * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3
  * definition below maps to physical channel 42 in the 5.2GHz spectrum.
  * The specific geography and calibration information for that channel
  * is contained in the eeprom map itself.
@@ -5340,7 +5062,7 @@ static u8 iwl4965_eeprom_band_7[] = {       /* 5.2 FAT channel */
        36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
 };
 
-static void iwl4965_init_band_reference(const struct iwl4965_priv *priv,
+static void iwl4965_init_band_reference(const struct iwl_priv *priv,
                                    int band,
                                    int *eeprom_ch_count,
                                    const struct iwl4965_eeprom_channel
@@ -5394,7 +5116,7 @@ static void iwl4965_init_band_reference(const struct iwl4965_priv *priv,
  *
  * Based on band and channel number.
  */
-const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl4965_priv *priv,
+const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl_priv *priv,
                                                    enum ieee80211_band band, u16 channel)
 {
        int i;
@@ -5423,7 +5145,7 @@ const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl4965
 /**
  * iwl4965_init_channel_map - Set up driver's info for all possible channels
  */
-static int iwl4965_init_channel_map(struct iwl4965_priv *priv)
+static int iwl4965_init_channel_map(struct iwl_priv *priv)
 {
        int eeprom_ch_count = 0;
        const u8 *eeprom_ch_index = NULL;
@@ -5502,11 +5224,12 @@ static int iwl4965_init_channel_map(struct iwl4965_priv *priv)
                        ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
                        ch_info->min_power = 0;
 
-                       IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
+                       IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x"
                                       " %ddBm): Ad-Hoc %ssupported\n",
                                       ch_info->channel,
                                       is_channel_a_band(ch_info) ?
                                       "5.2" : "2.4",
+                                      CHECK_AND_PRINT(VALID),
                                       CHECK_AND_PRINT(IBSS),
                                       CHECK_AND_PRINT(ACTIVE),
                                       CHECK_AND_PRINT(RADAR),
@@ -5574,7 +5297,7 @@ static int iwl4965_init_channel_map(struct iwl4965_priv *priv)
 /*
  * iwl4965_free_channel_map - undo allocations in iwl4965_init_channel_map
  */
-static void iwl4965_free_channel_map(struct iwl4965_priv *priv)
+static void iwl4965_free_channel_map(struct iwl_priv *priv)
 {
        kfree(priv->channel_info);
        priv->channel_count = 0;
@@ -5603,7 +5326,7 @@ static void iwl4965_free_channel_map(struct iwl4965_priv *priv)
 #define IWL_PASSIVE_DWELL_BASE      (100)
 #define IWL_CHANNEL_TUNE_TIME       5
 
-static inline u16 iwl4965_get_active_dwell_time(struct iwl4965_priv *priv,
+static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv,
                                                enum ieee80211_band band)
 {
        if (band == IEEE80211_BAND_5GHZ)
@@ -5612,7 +5335,7 @@ static inline u16 iwl4965_get_active_dwell_time(struct iwl4965_priv *priv,
                return IWL_ACTIVE_DWELL_TIME_24;
 }
 
-static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv,
+static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv,
                                          enum ieee80211_band band)
 {
        u16 active = iwl4965_get_active_dwell_time(priv, band);
@@ -5636,7 +5359,7 @@ static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv,
        return passive;
 }
 
-static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv,
+static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
                                         enum ieee80211_band band,
                                     u8 is_active, u8 direct_mask,
                                     struct iwl4965_scan_channel *scan_ch)
@@ -5723,7 +5446,7 @@ static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv,
        return added;
 }
 
-static void iwl4965_init_hw_rates(struct iwl4965_priv *priv,
+static void iwl4965_init_hw_rates(struct iwl_priv *priv,
                              struct ieee80211_rate *rates)
 {
        int i;
@@ -5737,8 +5460,9 @@ static void iwl4965_init_hw_rates(struct iwl4965_priv *priv,
                        /*
                         * If CCK != 1M then set short preamble rate flag.
                         */
-                       rates[i].flags |= (iwl4965_rates[i].plcp == 10) ?
-                               0 : IEEE80211_RATE_SHORT_PREAMBLE;
+                       rates[i].flags |=
+                               (iwl4965_rates[i].plcp == IWL_RATE_1M_PLCP) ?
+                                       0 : IEEE80211_RATE_SHORT_PREAMBLE;
                }
        }
 }
@@ -5746,10 +5470,10 @@ static void iwl4965_init_hw_rates(struct iwl4965_priv *priv,
 /**
  * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
  */
-static int iwl4965_init_geos(struct iwl4965_priv *priv)
+static int iwl4965_init_geos(struct iwl_priv *priv)
 {
        struct iwl4965_channel_info *ch;
-       struct ieee80211_supported_band *band;
+       struct ieee80211_supported_band *sband;
        struct ieee80211_channel *channels;
        struct ieee80211_channel *geo_ch;
        struct ieee80211_rate *rates;
@@ -5767,7 +5491,7 @@ static int iwl4965_init_geos(struct iwl4965_priv *priv)
        if (!channels)
                return -ENOMEM;
 
-       rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)),
+       rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
                        GFP_KERNEL);
        if (!rates) {
                kfree(channels);
@@ -5775,42 +5499,42 @@ static int iwl4965_init_geos(struct iwl4965_priv *priv)
        }
 
        /* 5.2GHz channels start after the 2.4GHz channels */
-       band = &priv->bands[IEEE80211_BAND_5GHZ];
-       band->channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)];
-       band->bitrates = &rates[4];
-       band->n_bitrates = 8;   /* just OFDM */
+       sband = &priv->bands[IEEE80211_BAND_5GHZ];
+       sband->channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)];
+       /* just OFDM */
+       sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
+       sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
 
-       iwl4965_init_ht_hw_capab(&band->ht_info, IEEE80211_BAND_5GHZ);
+       iwl4965_init_ht_hw_capab(&sband->ht_info, IEEE80211_BAND_5GHZ);
 
-       band = &priv->bands[IEEE80211_BAND_2GHZ];
-       band->channels = channels;
-       band->bitrates = rates;
-       band->n_bitrates = 12;  /* OFDM & CCK */
+       sband = &priv->bands[IEEE80211_BAND_2GHZ];
+       sband->channels = channels;
+       /* OFDM & CCK */
+       sband->bitrates = rates;
+       sband->n_bitrates = IWL_RATE_COUNT;
 
-       iwl4965_init_ht_hw_capab(&band->ht_info, IEEE80211_BAND_2GHZ);
+       iwl4965_init_ht_hw_capab(&sband->ht_info, IEEE80211_BAND_2GHZ);
 
        priv->ieee_channels = channels;
        priv->ieee_rates = rates;
 
        iwl4965_init_hw_rates(priv, rates);
 
-       for (i = 0, geo_ch = channels; i < priv->channel_count; i++) {
+       for (i = 0 i < priv->channel_count; i++) {
                ch = &priv->channel_info[i];
 
-               if (!is_channel_valid(ch)) {
-                       IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- "
-                                   "skipping.\n",
-                                   ch->channel, is_channel_a_band(ch) ?
-                                   "5.2" : "2.4");
+               /* FIXME: might be removed if scan is OK */
+               if (!is_channel_valid(ch))
                        continue;
-               }
 
-               if (is_channel_a_band(ch)) {
-                       geo_ch = &priv->bands[IEEE80211_BAND_5GHZ].channels[priv->bands[IEEE80211_BAND_5GHZ].n_channels++];
-               else
-                       geo_ch = &priv->bands[IEEE80211_BAND_2GHZ].channels[priv->bands[IEEE80211_BAND_2GHZ].n_channels++];
+               if (is_channel_a_band(ch))
+                       sband =  &priv->bands[IEEE80211_BAND_5GHZ];
+               else
+                       sband =  &priv->bands[IEEE80211_BAND_2GHZ];
 
-               geo_ch->center_freq = ieee80211chan2mhz(ch->channel);
+               geo_ch = &sband->channels[sband->n_channels++];
+
+               geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel);
                geo_ch->max_power = ch->max_power_avg;
                geo_ch->max_antenna_gain = 0xff;
                geo_ch->hw_value = ch->channel;
@@ -5828,16 +5552,28 @@ static int iwl4965_init_geos(struct iwl4965_priv *priv)
                        if (ch->max_power_avg > priv->max_channel_txpower_limit)
                                priv->max_channel_txpower_limit =
                                    ch->max_power_avg;
-               } else
+               } else {
                        geo_ch->flags |= IEEE80211_CHAN_DISABLED;
+               }
+
+               /* Save flags for reg domain usage */
+               geo_ch->orig_flags = geo_ch->flags;
+
+               IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
+                               ch->channel, geo_ch->center_freq,
+                               is_channel_a_band(ch) ?  "5.2" : "2.4",
+                               geo_ch->flags & IEEE80211_CHAN_DISABLED ?
+                               "restricted" : "valid",
+                                geo_ch->flags);
        }
 
-       if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && priv->is_abg) {
+       if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
+            priv->cfg->sku & IWL_SKU_A) {
                printk(KERN_INFO DRV_NAME
                       ": Incorrectly detected BG card as ABG.  Please send "
                       "your PCI ID 0x%04X:0x%04X to maintainer.\n",
                       priv->pci_dev->device, priv->pci_dev->subsystem_device);
-               priv->is_abg = 0;
+               priv->cfg->sku &= ~IWL_SKU_A;
        }
 
        printk(KERN_INFO DRV_NAME
@@ -5856,7 +5592,7 @@ static int iwl4965_init_geos(struct iwl4965_priv *priv)
 /*
  * iwl4965_free_geos - undo allocations in iwl4965_init_geos
  */
-static void iwl4965_free_geos(struct iwl4965_priv *priv)
+static void iwl4965_free_geos(struct iwl_priv *priv)
 {
        kfree(priv->ieee_channels);
        kfree(priv->ieee_rates);
@@ -5869,7 +5605,7 @@ static void iwl4965_free_geos(struct iwl4965_priv *priv)
  *
  ******************************************************************************/
 
-static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv *priv)
+static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
 {
        iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
        iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
@@ -5883,7 +5619,7 @@ static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv *priv)
  * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
  *     looking at all data.
  */
-static int iwl4965_verify_inst_full(struct iwl4965_priv *priv, __le32 *image,
+static int iwl4965_verify_inst_full(struct iwl_priv *priv, __le32 *image,
                                 u32 len)
 {
        u32 val;
@@ -5931,7 +5667,7 @@ static int iwl4965_verify_inst_full(struct iwl4965_priv *priv, __le32 *image,
  *   using sample data 100 bytes apart.  If these sample points are good,
  *   it's a pretty good bet that everything between them is good, too.
  */
-static int iwl4965_verify_inst_sparse(struct iwl4965_priv *priv, __le32 *image, u32 len)
+static int iwl4965_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
 {
        u32 val;
        int rc = 0;
@@ -5974,7 +5710,7 @@ static int iwl4965_verify_inst_sparse(struct iwl4965_priv *priv, __le32 *image,
  * iwl4965_verify_ucode - determine which instruction image is in SRAM,
  *    and verify its contents
  */
-static int iwl4965_verify_ucode(struct iwl4965_priv *priv)
+static int iwl4965_verify_ucode(struct iwl_priv *priv)
 {
        __le32 *image;
        u32 len;
@@ -6021,7 +5757,7 @@ static int iwl4965_verify_ucode(struct iwl4965_priv *priv)
 
 
 /* check contents of special bootstrap uCode SRAM */
-static int iwl4965_verify_bsm(struct iwl4965_priv *priv)
+static int iwl4965_verify_bsm(struct iwl_priv *priv)
 {
        __le32 *image = priv->ucode_boot.v_addr;
        u32 len = priv->ucode_boot.len;
@@ -6083,7 +5819,7 @@ static int iwl4965_verify_bsm(struct iwl4965_priv *priv)
  * the runtime uCode instructions and the backup data cache into SRAM,
  * and re-launches the runtime uCode from where it left off.
  */
-static int iwl4965_load_bsm(struct iwl4965_priv *priv)
+static int iwl4965_load_bsm(struct iwl_priv *priv)
 {
        __le32 *image = priv->ucode_boot.v_addr;
        u32 len = priv->ucode_boot.len;
@@ -6169,7 +5905,7 @@ static int iwl4965_load_bsm(struct iwl4965_priv *priv)
        return 0;
 }
 
-static void iwl4965_nic_start(struct iwl4965_priv *priv)
+static void iwl4965_nic_start(struct iwl_priv *priv)
 {
        /* Remove all resets to allow NIC to operate */
        iwl4965_write32(priv, CSR_RESET, 0);
@@ -6181,12 +5917,12 @@ static void iwl4965_nic_start(struct iwl4965_priv *priv)
  *
  * Copy into buffers for card to fetch via bus-mastering
  */
-static int iwl4965_read_ucode(struct iwl4965_priv *priv)
+static int iwl4965_read_ucode(struct iwl_priv *priv)
 {
        struct iwl4965_ucode *ucode;
        int ret;
        const struct firmware *ucode_raw;
-       const char *name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode";
+       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;
@@ -6382,7 +6118,7 @@ static int iwl4965_read_ucode(struct iwl4965_priv *priv)
  * We need to replace them to load runtime uCode inst and data,
  * and to save runtime data when powering down.
  */
-static int iwl4965_set_ucode_ptrs(struct iwl4965_priv *priv)
+static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
 {
        dma_addr_t pinst;
        dma_addr_t pdata;
@@ -6431,7 +6167,7 @@ static int iwl4965_set_ucode_ptrs(struct iwl4965_priv *priv)
  *
  * Tell "initialize" uCode to go ahead and load the runtime uCode.
 */
-static void iwl4965_init_alive_start(struct iwl4965_priv *priv)
+static void iwl4965_init_alive_start(struct iwl_priv *priv)
 {
        /* Check alive response for "valid" sign from uCode */
        if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
@@ -6476,7 +6212,7 @@ static void iwl4965_init_alive_start(struct iwl4965_priv *priv)
  *                   from protocol/runtime uCode (initialization uCode's
  *                   Alive gets handled by iwl4965_init_alive_start()).
  */
-static void iwl4965_alive_start(struct iwl4965_priv *priv)
+static void iwl4965_alive_start(struct iwl_priv *priv)
 {
        int rc = 0;
 
@@ -6561,9 +6297,9 @@ static void iwl4965_alive_start(struct iwl4965_priv *priv)
        queue_work(priv->workqueue, &priv->restart);
 }
 
-static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv);
+static void iwl4965_cancel_deferred_work(struct iwl_priv *priv);
 
-static void __iwl4965_down(struct iwl4965_priv *priv)
+static void __iwl4965_down(struct iwl_priv *priv)
 {
        unsigned long flags;
        int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
@@ -6655,7 +6391,7 @@ static void __iwl4965_down(struct iwl4965_priv *priv)
        iwl4965_clear_free_frames(priv);
 }
 
-static void iwl4965_down(struct iwl4965_priv *priv)
+static void iwl4965_down(struct iwl_priv *priv)
 {
        mutex_lock(&priv->mutex);
        __iwl4965_down(priv);
@@ -6666,7 +6402,7 @@ static void iwl4965_down(struct iwl4965_priv *priv)
 
 #define MAX_HW_RESTARTS 5
 
-static int __iwl4965_up(struct iwl4965_priv *priv)
+static int __iwl4965_up(struct iwl_priv *priv)
 {
        int rc, i;
 
@@ -6769,8 +6505,8 @@ static int __iwl4965_up(struct iwl4965_priv *priv)
 
 static void iwl4965_bg_init_alive_start(struct work_struct *data)
 {
-       struct iwl4965_priv *priv =
-           container_of(data, struct iwl4965_priv, init_alive_start.work);
+       struct iwl_priv *priv =
+           container_of(data, struct iwl_priv, init_alive_start.work);
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
@@ -6782,8 +6518,8 @@ static void iwl4965_bg_init_alive_start(struct work_struct *data)
 
 static void iwl4965_bg_alive_start(struct work_struct *data)
 {
-       struct iwl4965_priv *priv =
-           container_of(data, struct iwl4965_priv, alive_start.work);
+       struct iwl_priv *priv =
+           container_of(data, struct iwl_priv, alive_start.work);
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
@@ -6795,7 +6531,7 @@ static void iwl4965_bg_alive_start(struct work_struct *data)
 
 static void iwl4965_bg_rf_kill(struct work_struct *work)
 {
-       struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, rf_kill);
+       struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
 
        wake_up_interruptible(&priv->wait_command_queue);
 
@@ -6827,8 +6563,8 @@ static void iwl4965_bg_rf_kill(struct work_struct *work)
 
 static void iwl4965_bg_scan_check(struct work_struct *data)
 {
-       struct iwl4965_priv *priv =
-           container_of(data, struct iwl4965_priv, scan_check.work);
+       struct iwl_priv *priv =
+           container_of(data, struct iwl_priv, scan_check.work);
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
@@ -6848,8 +6584,8 @@ static void iwl4965_bg_scan_check(struct work_struct *data)
 
 static void iwl4965_bg_request_scan(struct work_struct *data)
 {
-       struct iwl4965_priv *priv =
-           container_of(data, struct iwl4965_priv, request_scan);
+       struct iwl_priv *priv =
+           container_of(data, struct iwl_priv, request_scan);
        struct iwl4965_host_cmd cmd = {
                .id = REPLY_SCAN_CMD,
                .len = sizeof(struct iwl4965_scan_cmd),
@@ -7018,18 +6754,23 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
        if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
                scan->filter_flags = RXON_FILTER_PROMISC_MSK;
 
-       if (direct_mask)
+       if (direct_mask) {
                IWL_DEBUG_SCAN
                    ("Initiating direct scan for %s.\n",
                     iwl4965_escape_essid(priv->essid, priv->essid_len));
-       else
+               scan->channel_count =
+                       iwl4965_get_channels_for_scan(
+                               priv, band, 1, /* active */
+                               direct_mask,
+                               (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
+       } else {
                IWL_DEBUG_SCAN("Initiating indirect scan.\n");
-
-       scan->channel_count =
-               iwl4965_get_channels_for_scan(
-                       priv, band, 1, /* active */
-                       direct_mask,
-                       (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
+               scan->channel_count =
+                       iwl4965_get_channels_for_scan(
+                               priv, band, 0, /* passive */
+                               direct_mask,
+                               (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
+       }
 
        cmd.len += le16_to_cpu(scan->tx_cmd.len) +
            scan->channel_count * sizeof(struct iwl4965_scan_channel);
@@ -7055,7 +6796,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
 
 static void iwl4965_bg_up(struct work_struct *data)
 {
-       struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, up);
+       struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
@@ -7067,7 +6808,7 @@ static void iwl4965_bg_up(struct work_struct *data)
 
 static void iwl4965_bg_restart(struct work_struct *data)
 {
-       struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, restart);
+       struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
@@ -7078,8 +6819,8 @@ static void iwl4965_bg_restart(struct work_struct *data)
 
 static void iwl4965_bg_rx_replenish(struct work_struct *data)
 {
-       struct iwl4965_priv *priv =
-           container_of(data, struct iwl4965_priv, rx_replenish);
+       struct iwl_priv *priv =
+           container_of(data, struct iwl_priv, rx_replenish);
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
@@ -7093,7 +6834,7 @@ static void iwl4965_bg_rx_replenish(struct work_struct *data)
 
 static void iwl4965_bg_post_associate(struct work_struct *data)
 {
-       struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv,
+       struct iwl_priv *priv = container_of(data, struct iwl_priv,
                                             post_associate.work);
 
        int rc = 0;
@@ -7207,7 +6948,7 @@ static void iwl4965_bg_post_associate(struct work_struct *data)
 
 static void iwl4965_bg_abort_scan(struct work_struct *work)
 {
-       struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, abort_scan);
+       struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
 
        if (!iwl4965_is_ready(priv))
                return;
@@ -7224,8 +6965,8 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
 
 static void iwl4965_bg_scan_completed(struct work_struct *work)
 {
-       struct iwl4965_priv *priv =
-           container_of(work, struct iwl4965_priv, scan_completed);
+       struct iwl_priv *priv =
+           container_of(work, struct iwl_priv, scan_completed);
 
        IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
 
@@ -7254,7 +6995,7 @@ static void iwl4965_bg_scan_completed(struct work_struct *work)
 
 static int iwl4965_mac_start(struct ieee80211_hw *hw)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        int ret;
 
        IWL_DEBUG_MAC80211("enter\n");
@@ -7331,7 +7072,7 @@ out_disable_msi:
 
 static void iwl4965_mac_stop(struct ieee80211_hw *hw)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
 
        IWL_DEBUG_MAC80211("enter\n");
 
@@ -7366,7 +7107,7 @@ static void iwl4965_mac_stop(struct ieee80211_hw *hw)
 static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
                      struct ieee80211_tx_control *ctl)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
 
        IWL_DEBUG_MAC80211("enter\n");
 
@@ -7388,7 +7129,7 @@ static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
 static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
                                 struct ieee80211_if_init_conf *conf)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        unsigned long flags;
        DECLARE_MAC_BUF(mac);
 
@@ -7429,7 +7170,7 @@ static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
  */
 static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        const struct iwl4965_channel_info *ch_info;
        unsigned long flags;
        int ret = 0;
@@ -7524,7 +7265,7 @@ out:
        return ret;
 }
 
-static void iwl4965_config_ap(struct iwl4965_priv *priv)
+static void iwl4965_config_ap(struct iwl_priv *priv)
 {
        int rc = 0;
 
@@ -7588,7 +7329,7 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
                                        struct ieee80211_vif *vif,
                                    struct ieee80211_if_conf *conf)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        DECLARE_MAC_BUF(mac);
        unsigned long flags;
        int rc;
@@ -7596,6 +7337,12 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
        if (conf == NULL)
                return -EIO;
 
+       if (priv->vif != vif) {
+               IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
+               mutex_unlock(&priv->mutex);
+               return 0;
+       }
+
        if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
            (!conf->beacon || !conf->ssid_len)) {
                IWL_DEBUG_MAC80211
@@ -7618,17 +7365,6 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
        if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
            !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
  */
-       if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
-               IWL_DEBUG_MAC80211("leave - scanning\n");
-               mutex_unlock(&priv->mutex);
-               return 0;
-       }
-
-       if (priv->vif != vif) {
-               IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
-               mutex_unlock(&priv->mutex);
-               return 0;
-       }
 
        if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
                if (!conf->bssid) {
@@ -7711,7 +7447,7 @@ static void iwl4965_configure_filter(struct ieee80211_hw *hw,
 static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
                                     struct ieee80211_if_init_conf *conf)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
 
        IWL_DEBUG_MAC80211("enter\n");
 
@@ -7740,7 +7476,7 @@ static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
                                     struct ieee80211_bss_conf *bss_conf,
                                     u32 changes)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
 
        if (changes & BSS_CHANGED_ERP_PREAMBLE) {
                if (bss_conf->use_short_preamble)
@@ -7771,7 +7507,7 @@ static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
 {
        int rc = 0;
        unsigned long flags;
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
 
        IWL_DEBUG_MAC80211("enter\n");
 
@@ -7828,7 +7564,7 @@ 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)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        DECLARE_MAC_BUF(mac);
        int rc = 0;
        u8 sta_id;
@@ -7887,7 +7623,7 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue,
                           const struct ieee80211_tx_queue_params *params)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        unsigned long flags;
        int q;
 
@@ -7938,7 +7674,7 @@ static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue,
 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
                                struct ieee80211_tx_queue_stats *stats)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        int i, avail;
        struct iwl4965_tx_queue *txq;
        struct iwl4965_queue *q;
@@ -7989,7 +7725,7 @@ static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
 
 static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        unsigned long flags;
 
        mutex_lock(&priv->mutex);
@@ -8061,7 +7797,7 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
 static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
                                 struct ieee80211_tx_control *control)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
        unsigned long flags;
 
        mutex_lock(&priv->mutex);
@@ -8103,7 +7839,7 @@ static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *sk
 #ifdef CONFIG_IWL4965_HT
 
 static void iwl4965_ht_info_fill(struct ieee80211_conf *conf,
-                                struct iwl4965_priv *priv)
+                                struct iwl_priv *priv)
 {
        struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
        struct ieee80211_ht_info *ht_conf = &conf->ht_conf;
@@ -8127,15 +7863,21 @@ static void iwl4965_ht_info_fill(struct ieee80211_conf *conf,
        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->extension_chan_offset =
-               ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
        iwl_conf->tx_chan_width =
                !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
        iwl_conf->ht_protection =
@@ -8151,7 +7893,7 @@ static void iwl4965_ht_info_fill(struct ieee80211_conf *conf,
 static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw,
                               struct ieee80211_conf *conf)
 {
-       struct iwl4965_priv *priv = hw->priv;
+       struct iwl_priv *priv = hw->priv;
 
        IWL_DEBUG_MAC80211("enter: \n");
 
@@ -8182,7 +7924,7 @@ static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw,
  *
  *****************************************************************************/
 
-#ifdef CONFIG_IWL4965_DEBUG
+#ifdef CONFIG_IWLWIFI_DEBUG
 
 /*
  * The following adds a new attribute to the sysfs representation
@@ -8194,7 +7936,7 @@ static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw,
 
 static ssize_t show_debug_level(struct device_driver *d, char *buf)
 {
-       return sprintf(buf, "0x%08X\n", iwl4965_debug_level);
+       return sprintf(buf, "0x%08X\n", iwl_debug_level);
 }
 static ssize_t store_debug_level(struct device_driver *d,
                                 const char *buf, size_t count)
@@ -8207,7 +7949,7 @@ static ssize_t store_debug_level(struct device_driver *d,
                printk(KERN_INFO DRV_NAME
                       ": %s is not in hex or decimal form.\n", buf);
        else
-               iwl4965_debug_level = val;
+               iwl_debug_level = val;
 
        return strnlen(buf, count);
 }
@@ -8215,7 +7957,7 @@ static ssize_t store_debug_level(struct device_driver *d,
 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
                   show_debug_level, store_debug_level);
 
-#endif /* CONFIG_IWL4965_DEBUG */
+#endif /* CONFIG_IWLWIFI_DEBUG */
 
 static ssize_t show_rf_kill(struct device *d,
                            struct device_attribute *attr, char *buf)
@@ -8226,7 +7968,7 @@ static ssize_t show_rf_kill(struct device *d,
         * 2 - HW based RF kill active
         * 3 - Both HW and SW based RF kill active
         */
-       struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
+       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);
 
@@ -8237,7 +7979,7 @@ static ssize_t store_rf_kill(struct device *d,
                             struct device_attribute *attr,
                             const char *buf, size_t count)
 {
-       struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
+       struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
 
        mutex_lock(&priv->mutex);
        iwl4965_radio_kill_sw(priv, buf[0] == '1');
@@ -8251,7 +7993,7 @@ 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 iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
+       struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
 
        if (!iwl4965_is_alive(priv))
                return -EAGAIN;
@@ -8265,7 +8007,7 @@ static ssize_t show_rs_window(struct device *d,
                              struct device_attribute *attr,
                              char *buf)
 {
-       struct iwl4965_priv *priv = d->driver_data;
+       struct iwl_priv *priv = d->driver_data;
        return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
 }
 static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
@@ -8273,7 +8015,7 @@ static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
 static ssize_t show_tx_power(struct device *d,
                             struct device_attribute *attr, char *buf)
 {
-       struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
+       struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
        return sprintf(buf, "%d\n", priv->user_txpower_limit);
 }
 
@@ -8281,7 +8023,7 @@ static ssize_t store_tx_power(struct device *d,
                              struct device_attribute *attr,
                              const char *buf, size_t count)
 {
-       struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
+       struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
        char *p = (char *)buf;
        u32 val;
 
@@ -8300,7 +8042,7 @@ static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
 static ssize_t show_flags(struct device *d,
                          struct device_attribute *attr, char *buf)
 {
-       struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
+       struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
 
        return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
 }
@@ -8309,7 +8051,7 @@ static ssize_t store_flags(struct device *d,
                           struct device_attribute *attr,
                           const char *buf, size_t count)
 {
-       struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
+       struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
        u32 flags = simple_strtoul(buf, NULL, 0);
 
        mutex_lock(&priv->mutex);
@@ -8334,7 +8076,7 @@ static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
 static ssize_t show_filter_flags(struct device *d,
                                 struct device_attribute *attr, char *buf)
 {
-       struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
+       struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
 
        return sprintf(buf, "0x%04X\n",
                le32_to_cpu(priv->active_rxon.filter_flags));
@@ -8344,7 +8086,7 @@ static ssize_t store_filter_flags(struct device *d,
                                  struct device_attribute *attr,
                                  const char *buf, size_t count)
 {
-       struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
+       struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
        u32 filter_flags = simple_strtoul(buf, NULL, 0);
 
        mutex_lock(&priv->mutex);
@@ -8373,7 +8115,7 @@ static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
 static ssize_t show_measurement(struct device *d,
                                struct device_attribute *attr, char *buf)
 {
-       struct iwl4965_priv *priv = dev_get_drvdata(d);
+       struct iwl_priv *priv = dev_get_drvdata(d);
        struct iwl4965_spectrum_notification measure_report;
        u32 size = sizeof(measure_report), len = 0, ofs = 0;
        u8 *data = (u8 *) & measure_report;
@@ -8406,7 +8148,7 @@ static ssize_t store_measurement(struct device *d,
                                 struct device_attribute *attr,
                                 const char *buf, size_t count)
 {
-       struct iwl4965_priv *priv = dev_get_drvdata(d);
+       struct iwl_priv *priv = dev_get_drvdata(d);
        struct ieee80211_measurement_params params = {
                .channel = le16_to_cpu(priv->active_rxon.channel),
                .start_time = cpu_to_le64(priv->last_tsf),
@@ -8445,7 +8187,7 @@ static ssize_t store_retry_rate(struct device *d,
                                struct device_attribute *attr,
                                const char *buf, size_t count)
 {
-       struct iwl4965_priv *priv = dev_get_drvdata(d);
+       struct iwl_priv *priv = dev_get_drvdata(d);
 
        priv->retry_rate = simple_strtoul(buf, NULL, 0);
        if (priv->retry_rate <= 0)
@@ -8457,7 +8199,7 @@ static ssize_t store_retry_rate(struct device *d,
 static ssize_t show_retry_rate(struct device *d,
                               struct device_attribute *attr, char *buf)
 {
-       struct iwl4965_priv *priv = dev_get_drvdata(d);
+       struct iwl_priv *priv = dev_get_drvdata(d);
        return sprintf(buf, "%d", priv->retry_rate);
 }
 
@@ -8468,7 +8210,7 @@ static ssize_t store_power_level(struct device *d,
                                 struct device_attribute *attr,
                                 const char *buf, size_t count)
 {
-       struct iwl4965_priv *priv = dev_get_drvdata(d);
+       struct iwl_priv *priv = dev_get_drvdata(d);
        int rc;
        int mode;
 
@@ -8522,7 +8264,7 @@ static const s32 period_duration[] = {
 static ssize_t show_power_level(struct device *d,
                                struct device_attribute *attr, char *buf)
 {
-       struct iwl4965_priv *priv = dev_get_drvdata(d);
+       struct iwl_priv *priv = dev_get_drvdata(d);
        int level = IWL_POWER_LEVEL(priv->power_mode);
        char *p = buf;
 
@@ -8566,7 +8308,7 @@ static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
 static ssize_t show_statistics(struct device *d,
                               struct device_attribute *attr, char *buf)
 {
-       struct iwl4965_priv *priv = dev_get_drvdata(d);
+       struct iwl_priv *priv = dev_get_drvdata(d);
        u32 size = sizeof(struct iwl4965_notif_statistics);
        u32 len = 0, ofs = 0;
        u8 *data = (u8 *) & priv->statistics;
@@ -8604,7 +8346,7 @@ static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
 static ssize_t show_antenna(struct device *d,
                            struct device_attribute *attr, char *buf)
 {
-       struct iwl4965_priv *priv = dev_get_drvdata(d);
+       struct iwl_priv *priv = dev_get_drvdata(d);
 
        if (!iwl4965_is_alive(priv))
                return -EAGAIN;
@@ -8617,7 +8359,7 @@ static ssize_t store_antenna(struct device *d,
                             const char *buf, size_t count)
 {
        int ant;
-       struct iwl4965_priv *priv = dev_get_drvdata(d);
+       struct iwl_priv *priv = dev_get_drvdata(d);
 
        if (count == 0)
                return 0;
@@ -8642,7 +8384,7 @@ static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
 static ssize_t show_status(struct device *d,
                           struct device_attribute *attr, char *buf)
 {
-       struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
+       struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
        if (!iwl4965_is_alive(priv))
                return -EAGAIN;
        return sprintf(buf, "0x%08x\n", (int)priv->status);
@@ -8657,7 +8399,7 @@ static ssize_t dump_error_log(struct device *d,
        char *p = (char *)buf;
 
        if (p[0] == '1')
-               iwl4965_dump_nic_error_log((struct iwl4965_priv *)d->driver_data);
+               iwl4965_dump_nic_error_log((struct iwl_priv *)d->driver_data);
 
        return strnlen(buf, count);
 }
@@ -8671,7 +8413,7 @@ static ssize_t dump_event_log(struct device *d,
        char *p = (char *)buf;
 
        if (p[0] == '1')
-               iwl4965_dump_nic_event_log((struct iwl4965_priv *)d->driver_data);
+               iwl4965_dump_nic_event_log((struct iwl_priv *)d->driver_data);
 
        return strnlen(buf, count);
 }
@@ -8684,7 +8426,7 @@ static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
  *
  *****************************************************************************/
 
-static void iwl4965_setup_deferred_work(struct iwl4965_priv *priv)
+static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
 {
        priv->workqueue = create_workqueue(DRV_NAME);
 
@@ -8709,7 +8451,7 @@ static void iwl4965_setup_deferred_work(struct iwl4965_priv *priv)
                     iwl4965_irq_tasklet, (unsigned long)priv);
 }
 
-static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv)
+static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
 {
        iwl4965_hw_cancel_deferred_work(priv);
 
@@ -8774,11 +8516,16 @@ static struct ieee80211_ops iwl4965_hw_ops = {
 static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
        int err = 0;
-       struct iwl4965_priv *priv;
+       struct iwl_priv *priv;
        struct ieee80211_hw *hw;
+       struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
        int i;
        DECLARE_MAC_BUF(mac);
 
+       /************************
+        * 1. Allocating HW data
+        ************************/
+
        /* Disabling hardware scan means that mac80211 will perform scans
         * "the hard way", rather than using device's scan. */
        if (iwl4965_param_disable_hw_scan) {
@@ -8786,17 +8533,9 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
                iwl4965_hw_ops.hw_scan = NULL;
        }
 
-       if ((iwl4965_param_queues_num > IWL_MAX_NUM_QUEUES) ||
-           (iwl4965_param_queues_num < IWL_MIN_NUM_QUEUES)) {
-               IWL_ERROR("invalid queues_num, should be between %d and %d\n",
-                         IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES);
-               err = -EINVAL;
-               goto out;
-       }
-
        /* mac80211 allocates memory for this device instance, including
         *   space for this driver's private structure */
-       hw = ieee80211_alloc_hw(sizeof(struct iwl4965_priv), &iwl4965_hw_ops);
+       hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwl4965_hw_ops);
        if (hw == NULL) {
                IWL_ERROR("Can not allocate network device\n");
                err = -ENOMEM;
@@ -8804,21 +8543,101 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        }
        SET_IEEE80211_DEV(hw, &pdev->dev);
 
-       hw->rate_control_algorithm = "iwl-4965-rs";
-
        IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
        priv = hw->priv;
        priv->hw = hw;
+       priv->cfg = cfg;
 
        priv->pci_dev = pdev;
-       priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna;
-#ifdef CONFIG_IWL4965_DEBUG
-       iwl4965_debug_level = iwl4965_param_debug;
+
+#ifdef CONFIG_IWLWIFI_DEBUG
+       iwl_debug_level = iwl4965_param_debug;
        atomic_set(&priv->restrict_refcnt, 0);
 #endif
-       priv->retry_rate = 1;
 
-       priv->ibss_beacon = NULL;
+       /**************************
+        * 2. Initializing PCI bus
+        **************************/
+       if (pci_enable_device(pdev)) {
+               err = -ENODEV;
+               goto out_ieee80211_free_hw;
+       }
+
+       pci_set_master(pdev);
+
+       err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
+       if (!err)
+               err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
+               if (err) {
+                       printk(KERN_WARNING DRV_NAME
+                               ": No suitable DMA available.\n");
+                       goto out_pci_disable_device;
+       }
+
+       err = pci_request_regions(pdev, DRV_NAME);
+       if (err)
+               goto out_pci_disable_device;
+
+       pci_set_drvdata(pdev, priv);
+
+       /* We disable the RETRY_TIMEOUT register (0x41) to keep
+        * PCI Tx retries from interfering with C3 CPU state */
+       pci_write_config_byte(pdev, 0x41, 0x00);
+
+       /***********************
+        * 3. Read REV register
+        ***********************/
+       priv->hw_base = pci_iomap(pdev, 0, 0);
+       if (!priv->hw_base) {
+               err = -ENODEV;
+               goto out_pci_release_regions;
+       }
+
+       IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
+               (unsigned long long) pci_resource_len(pdev, 0));
+       IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
+
+       printk(KERN_INFO DRV_NAME
+               ": Detected Intel Wireless WiFi Link %s\n", priv->cfg->name);
+
+       /*****************
+        * 4. Read EEPROM
+        *****************/
+       /* nic init */
+       iwl4965_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,
+               CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
+               CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
+       if (err < 0) {
+               IWL_DEBUG_INFO("Failed to init the card\n");
+               goto out_iounmap;
+       }
+       /* Read the EEPROM */
+       err = iwl_eeprom_init(priv);
+       if (err) {
+               IWL_ERROR("Unable to init EEPROM\n");
+               goto out_iounmap;
+       }
+       /* MAC Address location in EEPROM same for 3945/4965 */
+       iwl_eeprom_get_mac(priv, priv->mac_addr);
+       IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
+       SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
+
+       /************************
+        * 5. Setup HW constants
+        ************************/
+       /* Device-specific setup */
+       if (iwl4965_hw_set_hw_setting(priv)) {
+               IWL_ERROR("failed to set hw settings\n");
+               goto out_iounmap;
+       }
+
+       /*******************
+        * 6. Setup hw/priv
+        *******************/
 
        /* Tell mac80211 and its clients (e.g. Wireless Extensions)
         *   the range of signal quality values that we'll provide.
@@ -8839,6 +8658,11 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        hw->queues = 16;
 #endif /* CONFIG_IWL4965_HT */
 
+       hw->rate_control_algorithm = "iwl-4965-rs";
+       priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna;
+       priv->retry_rate = 1;
+       priv->ibss_beacon = NULL;
+
        spin_lock_init(&priv->lock);
        spin_lock_init(&priv->power_data.lock);
        spin_lock_init(&priv->sta_lock);
@@ -8851,12 +8675,6 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        INIT_LIST_HEAD(&priv->free_frames);
 
        mutex_init(&priv->mutex);
-       if (pci_enable_device(pdev)) {
-               err = -ENODEV;
-               goto out_ieee80211_free_hw;
-       }
-
-       pci_set_master(pdev);
 
        /* Clear the driver's (not device's) station table */
        iwl4965_clear_stations_table(priv);
@@ -8866,44 +8684,8 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        priv->ieee_rates = NULL;
        priv->band = IEEE80211_BAND_2GHZ;
 
-       err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
-       if (!err)
-               err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
-       if (err) {
-               printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
-               goto out_pci_disable_device;
-       }
-
-       pci_set_drvdata(pdev, priv);
-       err = pci_request_regions(pdev, DRV_NAME);
-       if (err)
-               goto out_pci_disable_device;
-
-       /* We disable the RETRY_TIMEOUT register (0x41) to keep
-        * PCI Tx retries from interfering with C3 CPU state */
-       pci_write_config_byte(pdev, 0x41, 0x00);
-
-       priv->hw_base = pci_iomap(pdev, 0, 0);
-       if (!priv->hw_base) {
-               err = -ENODEV;
-               goto out_pci_release_regions;
-       }
-
-       IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
-                       (unsigned long long) pci_resource_len(pdev, 0));
-       IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
-
-       /* Initialize module parameter values here */
-
-       /* Disable radio (SW RF KILL) via parameter when loading driver */
-       if (iwl4965_param_disable) {
-               set_bit(STATUS_RF_KILL_SW, &priv->status);
-               IWL_DEBUG_INFO("Radio disabled.\n");
-       }
-
        priv->iw_mode = IEEE80211_IF_TYPE_STA;
 
-       priv->ps_mode = 0;
        priv->use_ant_b_for_management_frame = 1; /* start with ant B */
        priv->valid_antenna = 0x7;      /* assume all 3 connected */
        priv->ps_mode = IWL_MIMO_PS_NONE;
@@ -8911,67 +8693,22 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        /* Choose which receivers/antennas to use */
        iwl4965_set_rxon_chain(priv);
 
-       printk(KERN_INFO DRV_NAME
-              ": Detected Intel Wireless WiFi Link 4965AGN\n");
-
-       /* Device-specific setup */
-       if (iwl4965_hw_set_hw_setting(priv)) {
-               IWL_ERROR("failed to set hw settings\n");
-               goto out_iounmap;
-       }
-
-       if (iwl4965_param_qos_enable)
-               priv->qos_data.qos_enable = 1;
-
        iwl4965_reset_qos(priv);
 
        priv->qos_data.qos_active = 0;
        priv->qos_data.qos_cap.val = 0;
 
        iwl4965_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
-       iwl4965_setup_deferred_work(priv);
-       iwl4965_setup_rx_handlers(priv);
 
        priv->rates_mask = IWL_RATES_MASK;
        /* If power management is turned on, default to AC mode */
        priv->power_mode = IWL_POWER_AC;
        priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
 
-       iwl4965_disable_interrupts(priv);
-
-       err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
-       if (err) {
-               IWL_ERROR("failed to create sysfs device attributes\n");
-               goto out_release_irq;
-       }
-
-       /* nic init */
-       iwl4965_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,
-                          CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
-                          CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
-        if (err < 0) {
-                IWL_DEBUG_INFO("Failed to init the card\n");
-               goto out_remove_sysfs;
-        }
-       /* Read the EEPROM */
-       err = iwl4965_eeprom_init(priv);
-       if (err) {
-               IWL_ERROR("Unable to init EEPROM\n");
-               goto out_remove_sysfs;
-       }
-       /* MAC Address location in EEPROM same for 3945/4965 */
-       get_eeprom_mac(priv, priv->mac_addr);
-       IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
-       SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
-
        err = iwl4965_init_channel_map(priv);
        if (err) {
                IWL_ERROR("initializing regulatory failed: %d\n", err);
-               goto out_remove_sysfs;
+               goto out_unset_hw_settings;
        }
 
        err = iwl4965_init_geos(priv);
@@ -8989,30 +8726,63 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
 
        priv->hw->conf.beacon_int = 100;
        priv->mac80211_registered = 1;
+
+       /**********************************
+        * 7. Initialize module parameters
+        **********************************/
+
+       /* Disable radio (SW RF KILL) via parameter when loading driver */
+       if (iwl4965_param_disable) {
+               set_bit(STATUS_RF_KILL_SW, &priv->status);
+               IWL_DEBUG_INFO("Radio disabled.\n");
+       }
+
+       if (iwl4965_param_qos_enable)
+               priv->qos_data.qos_enable = 1;
+
+       /********************
+        * 8. Setup services
+        ********************/
+       iwl4965_disable_interrupts(priv);
+
+       err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
+       if (err) {
+               IWL_ERROR("failed to create sysfs device attributes\n");
+               goto out_free_geos;
+       }
+
+       err = iwl_dbgfs_register(priv, DRV_NAME);
+       if (err) {
+               IWL_ERROR("failed to create debugfs files\n");
+               goto out_remove_sysfs;
+       }
+
+       iwl4965_setup_deferred_work(priv);
+       iwl4965_setup_rx_handlers(priv);
+
+       /********************
+        * 9. Conclude
+        ********************/
        pci_save_state(pdev);
        pci_disable_device(pdev);
 
        return 0;
 
+ out_remove_sysfs:
+       sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  out_free_geos:
        iwl4965_free_geos(priv);
  out_free_channel_map:
        iwl4965_free_channel_map(priv);
- out_remove_sysfs:
-       sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
-
- out_release_irq:
-       destroy_workqueue(priv->workqueue);
-       priv->workqueue = NULL;
+ out_unset_hw_settings:
        iwl4965_unset_hw_setting(priv);
-
  out_iounmap:
        pci_iounmap(pdev, priv->hw_base);
  out_pci_release_regions:
        pci_release_regions(pdev);
+       pci_set_drvdata(pdev, NULL);
  out_pci_disable_device:
        pci_disable_device(pdev);
-       pci_set_drvdata(pdev, NULL);
  out_ieee80211_free_hw:
        ieee80211_free_hw(priv->hw);
  out:
@@ -9021,7 +8791,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
 
 static void iwl4965_pci_remove(struct pci_dev *pdev)
 {
-       struct iwl4965_priv *priv = pci_get_drvdata(pdev);
+       struct iwl_priv *priv = pci_get_drvdata(pdev);
        struct list_head *p, *q;
        int i;
 
@@ -9042,6 +8812,7 @@ static void iwl4965_pci_remove(struct pci_dev *pdev)
                }
        }
 
+       iwl_dbgfs_unregister(priv);
        sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
 
        iwl4965_dealloc_ucode_pci(priv);
@@ -9085,7 +8856,7 @@ static void iwl4965_pci_remove(struct pci_dev *pdev)
 
 static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
 {
-       struct iwl4965_priv *priv = pci_get_drvdata(pdev);
+       struct iwl_priv *priv = pci_get_drvdata(pdev);
 
        if (priv->is_open) {
                set_bit(STATUS_IN_SUSPEND, &priv->status);
@@ -9100,7 +8871,7 @@ static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
 
 static int iwl4965_pci_resume(struct pci_dev *pdev)
 {
-       struct iwl4965_priv *priv = pci_get_drvdata(pdev);
+       struct iwl_priv *priv = pci_get_drvdata(pdev);
 
        pci_set_power_state(pdev, PCI_D0);
 
@@ -9141,7 +8912,7 @@ static int __init iwl4965_init(void)
                IWL_ERROR("Unable to initialize PCI module\n");
                return ret;
        }
-#ifdef CONFIG_IWL4965_DEBUG
+#ifdef CONFIG_IWLWIFI_DEBUG
        ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level);
        if (ret) {
                IWL_ERROR("Unable to create driver sysfs file\n");
@@ -9155,7 +8926,7 @@ static int __init iwl4965_init(void)
 
 static void __exit iwl4965_exit(void)
 {
-#ifdef CONFIG_IWL4965_DEBUG
+#ifdef CONFIG_IWLWIFI_DEBUG
        driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level);
 #endif
        pci_unregister_driver(&iwl4965_driver);