iwlwifi: move host command sending functions to core module
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl4965-base.c
index 396940e701e55a35efc4d6ee49c755467afd60ac..8fe09e893279c118b0fb84f40b574f59d242a969 100644 (file)
@@ -60,14 +60,12 @@ static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
  ******************************************************************************/
 
 /* module parameters */
-static int iwl4965_param_disable_hw_scan; /* def: 0 = use 4965's h/w scan */
-static int iwl4965_param_debug;    /* def: 0 = minimal debug log messages */
-static int iwl4965_param_disable;  /* def: enable radio */
-static int iwl4965_param_antenna;  /* def: 0 = both antennas (use diversity) */
-int iwl4965_param_hwcrypto;        /* def: using software encryption */
-static int iwl4965_param_qos_enable = 1; /* def: 1 = use quality of service */
-int iwl4965_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 16 Tx queues */
-int iwl4965_param_amsdu_size_8K;   /* def: enable 8K amsdu size */
+struct iwl_mod_params iwl4965_mod_params = {
+       .num_of_queues = IWL_MAX_NUM_QUEUES,
+       .enable_qos = 1,
+       .amsdu_size_8K = 1,
+       /* the rest are 0 by default */
+};
 
 /*
  * module name, copyright, version, etc.
@@ -307,7 +305,7 @@ int iwl4965_tx_queue_init(struct iwl_priv *priv,
         * For normal Tx queues (all other queues), no super-size command
         * space is needed.
         */
-       len = sizeof(struct iwl4965_cmd) * slots_num;
+       len = sizeof(struct iwl_cmd) * slots_num;
        if (txq_id == IWL_CMD_QUEUE_NUM)
                len +=  IWL_MAX_SCAN_SIZE;
        txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
@@ -358,7 +356,7 @@ void iwl4965_tx_queue_free(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
             q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
                iwl4965_hw_txq_free_tfd(priv, txq);
 
-       len = sizeof(struct iwl4965_cmd) * q->n_window;
+       len = sizeof(struct iwl_cmd) * q->n_window;
        if (q->id == IWL_CMD_QUEUE_NUM)
                len += IWL_MAX_SCAN_SIZE;
 
@@ -432,23 +430,6 @@ out:
 }
 #endif
 
-/**
- * iwl4965_clear_stations_table - Clear the driver's station table
- *
- * NOTE:  This does not clear or otherwise alter the device's station table.
- */
-static void iwl4965_clear_stations_table(struct iwl_priv *priv)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&priv->sta_lock, flags);
-
-       priv->num_stations = 0;
-       memset(priv->stations, 0, sizeof(priv->stations));
-
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
-}
-
 /**
  * iwl4965_add_station_flags - Add station to tables in driver and device
  */
@@ -560,65 +541,6 @@ static inline int iwl4965_is_ready_rf(struct iwl_priv *priv)
 
 /*************** HOST COMMAND QUEUE FUNCTIONS   *****/
 
-#define IWL_CMD(x) case x : return #x
-
-static const char *get_cmd_string(u8 cmd)
-{
-       switch (cmd) {
-               IWL_CMD(REPLY_ALIVE);
-               IWL_CMD(REPLY_ERROR);
-               IWL_CMD(REPLY_RXON);
-               IWL_CMD(REPLY_RXON_ASSOC);
-               IWL_CMD(REPLY_QOS_PARAM);
-               IWL_CMD(REPLY_RXON_TIMING);
-               IWL_CMD(REPLY_ADD_STA);
-               IWL_CMD(REPLY_REMOVE_STA);
-               IWL_CMD(REPLY_REMOVE_ALL_STA);
-               IWL_CMD(REPLY_TX);
-               IWL_CMD(REPLY_RATE_SCALE);
-               IWL_CMD(REPLY_LEDS_CMD);
-               IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
-               IWL_CMD(RADAR_NOTIFICATION);
-               IWL_CMD(REPLY_QUIET_CMD);
-               IWL_CMD(REPLY_CHANNEL_SWITCH);
-               IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
-               IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
-               IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
-               IWL_CMD(POWER_TABLE_CMD);
-               IWL_CMD(PM_SLEEP_NOTIFICATION);
-               IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
-               IWL_CMD(REPLY_SCAN_CMD);
-               IWL_CMD(REPLY_SCAN_ABORT_CMD);
-               IWL_CMD(SCAN_START_NOTIFICATION);
-               IWL_CMD(SCAN_RESULTS_NOTIFICATION);
-               IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
-               IWL_CMD(BEACON_NOTIFICATION);
-               IWL_CMD(REPLY_TX_BEACON);
-               IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
-               IWL_CMD(QUIET_NOTIFICATION);
-               IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
-               IWL_CMD(MEASURE_ABORT_NOTIFICATION);
-               IWL_CMD(REPLY_BT_CONFIG);
-               IWL_CMD(REPLY_STATISTICS_CMD);
-               IWL_CMD(STATISTICS_NOTIFICATION);
-               IWL_CMD(REPLY_CARD_STATE_CMD);
-               IWL_CMD(CARD_STATE_NOTIFICATION);
-               IWL_CMD(MISSED_BEACONS_NOTIFICATION);
-               IWL_CMD(REPLY_CT_KILL_CONFIG_CMD);
-               IWL_CMD(SENSITIVITY_CMD);
-               IWL_CMD(REPLY_PHY_CALIBRATION_CMD);
-               IWL_CMD(REPLY_RX_PHY_CMD);
-               IWL_CMD(REPLY_RX_MPDU_CMD);
-               IWL_CMD(REPLY_4965_RX);
-               IWL_CMD(REPLY_COMPRESSED_BA);
-       default:
-               return "UNKNOWN";
-
-       }
-}
-
-#define HOST_COMPLETE_TIMEOUT (HZ / 2)
-
 /**
  * iwl4965_enqueue_hcmd - enqueue a uCode command
  * @priv: device private data point
@@ -628,13 +550,13 @@ static const char *get_cmd_string(u8 cmd)
  * failed. On success, it turns the index (> 0) of command in the
  * command queue.
  */
-static int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
+int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
 {
        struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
        struct iwl4965_queue *q = &txq->q;
        struct iwl4965_tfd_frame *tfd;
        u32 *control_flags;
-       struct iwl4965_cmd *out_cmd;
+       struct iwl_cmd *out_cmd;
        u32 idx;
        u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
        dma_addr_t phys_addr;
@@ -681,7 +603,7 @@ static int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl4965_host_cmd *
                out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
 
        phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
-                       offsetof(struct iwl4965_cmd, hdr);
+                       offsetof(struct iwl_cmd, hdr);
        iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
 
        IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
@@ -703,151 +625,22 @@ static int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl4965_host_cmd *
        return ret ? ret : idx;
 }
 
-static int iwl4965_send_cmd_async(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
-{
-       int ret;
-
-       BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
-
-       /* An asynchronous command can not expect an SKB to be set. */
-       BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
-
-       /* An asynchronous command MUST have a callback. */
-       BUG_ON(!cmd->meta.u.callback);
-
-       if (test_bit(STATUS_EXIT_PENDING, &priv->status))
-               return -EBUSY;
-
-       ret = iwl4965_enqueue_hcmd(priv, cmd);
-       if (ret < 0) {
-               IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
-                         get_cmd_string(cmd->id), ret);
-               return ret;
-       }
-       return 0;
-}
-
-static int iwl4965_send_cmd_sync(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
-{
-       int cmd_idx;
-       int ret;
-       static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */
-
-       BUG_ON(cmd->meta.flags & CMD_ASYNC);
-
-        /* A synchronous command can not have a callback set. */
-       BUG_ON(cmd->meta.u.callback != NULL);
-
-       if (atomic_xchg(&entry, 1)) {
-               IWL_ERROR("Error sending %s: Already sending a host command\n",
-                         get_cmd_string(cmd->id));
-               return -EBUSY;
-       }
-
-       set_bit(STATUS_HCMD_ACTIVE, &priv->status);
-
-       if (cmd->meta.flags & CMD_WANT_SKB)
-               cmd->meta.source = &cmd->meta;
-
-       cmd_idx = iwl4965_enqueue_hcmd(priv, cmd);
-       if (cmd_idx < 0) {
-               ret = cmd_idx;
-               IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
-                         get_cmd_string(cmd->id), ret);
-               goto out;
-       }
-
-       ret = wait_event_interruptible_timeout(priv->wait_command_queue,
-                       !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
-                       HOST_COMPLETE_TIMEOUT);
-       if (!ret) {
-               if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
-                       IWL_ERROR("Error sending %s: time out after %dms.\n",
-                                 get_cmd_string(cmd->id),
-                                 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
-
-                       clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
-                       ret = -ETIMEDOUT;
-                       goto cancel;
-               }
-       }
-
-       if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
-               IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
-                              get_cmd_string(cmd->id));
-               ret = -ECANCELED;
-               goto fail;
-       }
-       if (test_bit(STATUS_FW_ERROR, &priv->status)) {
-               IWL_DEBUG_INFO("Command %s failed: FW Error\n",
-                              get_cmd_string(cmd->id));
-               ret = -EIO;
-               goto fail;
-       }
-       if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
-               IWL_ERROR("Error: Response NULL in '%s'\n",
-                         get_cmd_string(cmd->id));
-               ret = -EIO;
-               goto out;
-       }
-
-       ret = 0;
-       goto out;
-
-cancel:
-       if (cmd->meta.flags & CMD_WANT_SKB) {
-               struct iwl4965_cmd *qcmd;
-
-               /* Cancel the CMD_WANT_SKB flag for the cmd in the
-                * TX cmd queue. Otherwise in case the cmd comes
-                * in later, it will possibly set an invalid
-                * address (cmd->meta.source). */
-               qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
-               qcmd->meta.flags &= ~CMD_WANT_SKB;
-       }
-fail:
-       if (cmd->meta.u.skb) {
-               dev_kfree_skb_any(cmd->meta.u.skb);
-               cmd->meta.u.skb = NULL;
-       }
-out:
-       atomic_set(&entry, 0);
-       return ret;
-}
-
-int iwl4965_send_cmd(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
+static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
 {
-       if (cmd->meta.flags & CMD_ASYNC)
-               return iwl4965_send_cmd_async(priv, cmd);
-
-       return iwl4965_send_cmd_sync(priv, cmd);
-}
-
-int iwl4965_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, const void *data)
-{
-       struct iwl4965_host_cmd cmd = {
-               .id = id,
-               .len = len,
-               .data = data,
-       };
-
-       return iwl4965_send_cmd_sync(priv, &cmd);
-}
+       struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
 
-static int __must_check iwl4965_send_cmd_u32(struct iwl_priv *priv, u8 id, u32 val)
-{
-       struct iwl4965_host_cmd cmd = {
-               .id = id,
-               .len = sizeof(val),
-               .data = &val,
-       };
+       if (hw_decrypt)
+               rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
+       else
+               rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
 
-       return iwl4965_send_cmd_sync(priv, &cmd);
 }
 
 int iwl4965_send_statistics_request(struct iwl_priv *priv)
 {
-       return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
+       u32 flags = 0;
+       return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
+                                     sizeof(flags), &flags);
 }
 
 /**
@@ -882,43 +675,6 @@ static int iwl4965_rxon_add_station(struct iwl_priv *priv,
        return sta_id;
 }
 
-/**
- * iwl4965_set_rxon_channel - Set the phymode and channel values in staging RXON
- * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
- * @channel: Any channel valid for the requested phymode
-
- * In addition to setting the staging RXON, priv->phymode is also set.
- *
- * 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 iwl_priv *priv,
-                                   enum ieee80211_band band,
-                                u16 channel)
-{
-       if (!iwl4965_get_channel_info(priv, band, channel)) {
-               IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
-                              channel, band);
-               return -EINVAL;
-       }
-
-       if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
-           (priv->band == band))
-               return 0;
-
-       priv->staging_rxon.channel = cpu_to_le16(channel);
-       if (band == IEEE80211_BAND_5GHZ)
-               priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
-       else
-               priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
-
-       priv->band = band;
-
-       IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
-
-       return 0;
-}
-
 /**
  * iwl4965_check_rxon_cmd - validate RXON structure is valid
  *
@@ -1045,7 +801,7 @@ static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
        int rc = 0;
        struct iwl4965_rx_packet *res = NULL;
        struct iwl4965_rxon_assoc_cmd rxon_assoc;
-       struct iwl4965_host_cmd cmd = {
+       struct iwl_host_cmd cmd = {
                .id = REPLY_RXON_ASSOC,
                .len = sizeof(rxon_assoc),
                .meta.flags = CMD_WANT_SKB,
@@ -1078,7 +834,7 @@ static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
            priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
        rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
 
-       rc = iwl4965_send_cmd_sync(priv, &cmd);
+       rc = iwl_send_cmd_sync(priv, &cmd);
        if (rc)
                return rc;
 
@@ -1157,7 +913,7 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
                IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
                active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
 
-               rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
+               rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
                                      sizeof(struct iwl4965_rxon_cmd),
                                      &priv->active_rxon);
 
@@ -1180,15 +936,16 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
                       le16_to_cpu(priv->staging_rxon.channel),
                       print_mac(mac, priv->staging_rxon.bssid_addr));
 
+       iwl4965_set_rxon_hwcrypto(priv, priv->cfg->mod_params->hw_crypto);
        /* Apply the new configuration */
-       rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
+       rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
                              sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon);
        if (rc) {
                IWL_ERROR("Error setting new configuration (%d).\n", rc);
                return rc;
        }
 
-       iwl4965_clear_stations_table(priv);
+       iwlcore_clear_stations_table(priv);
 
 #ifdef CONFIG_IWL4965_SENSITIVITY
        if (!priv->error_recovering)
@@ -1240,7 +997,7 @@ static int iwl4965_send_bt_config(struct iwl_priv *priv)
                .kill_cts_mask = 0,
        };
 
-       return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG,
+       return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
                                sizeof(struct iwl4965_bt_cmd), &bt_cmd);
 }
 
@@ -1248,7 +1005,7 @@ static int iwl4965_send_scan_abort(struct iwl_priv *priv)
 {
        int rc = 0;
        struct iwl4965_rx_packet *res;
-       struct iwl4965_host_cmd cmd = {
+       struct iwl_host_cmd cmd = {
                .id = REPLY_SCAN_ABORT_CMD,
                .meta.flags = CMD_WANT_SKB,
        };
@@ -1261,7 +1018,7 @@ static int iwl4965_send_scan_abort(struct iwl_priv *priv)
                return 0;
        }
 
-       rc = iwl4965_send_cmd_sync(priv, &cmd);
+       rc = iwl_send_cmd_sync(priv, &cmd);
        if (rc) {
                clear_bit(STATUS_SCAN_ABORTING, &priv->status);
                return rc;
@@ -1286,7 +1043,7 @@ static int iwl4965_send_scan_abort(struct iwl_priv *priv)
 }
 
 static int iwl4965_card_state_sync_callback(struct iwl_priv *priv,
-                                       struct iwl4965_cmd *cmd,
+                                       struct iwl_cmd *cmd,
                                        struct sk_buff *skb)
 {
        return 1;
@@ -1304,7 +1061,7 @@ static int iwl4965_card_state_sync_callback(struct iwl_priv *priv,
  */
 static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
 {
-       struct iwl4965_host_cmd cmd = {
+       struct iwl_host_cmd cmd = {
                .id = REPLY_CARD_STATE_CMD,
                .len = sizeof(u32),
                .data = &flags,
@@ -1314,11 +1071,11 @@ static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_fla
        if (meta_flag & CMD_ASYNC)
                cmd.meta.u.callback = iwl4965_card_state_sync_callback;
 
-       return iwl4965_send_cmd(priv, &cmd);
+       return iwl_send_cmd(priv, &cmd);
 }
 
 static int iwl4965_add_sta_sync_callback(struct iwl_priv *priv,
-                                    struct iwl4965_cmd *cmd, struct sk_buff *skb)
+                                    struct iwl_cmd *cmd, struct sk_buff *skb)
 {
        struct iwl4965_rx_packet *res = NULL;
 
@@ -1350,7 +1107,7 @@ int iwl4965_send_add_station(struct iwl_priv *priv,
 {
        struct iwl4965_rx_packet *res = NULL;
        int rc = 0;
-       struct iwl4965_host_cmd cmd = {
+       struct iwl_host_cmd cmd = {
                .id = REPLY_ADD_STA,
                .len = sizeof(struct iwl4965_addsta_cmd),
                .meta.flags = flags,
@@ -1362,7 +1119,7 @@ int iwl4965_send_add_station(struct iwl_priv *priv,
        else
                cmd.meta.flags |= CMD_WANT_SKB;
 
-       rc = iwl4965_send_cmd(priv, &cmd);
+       rc = iwl_send_cmd(priv, &cmd);
 
        if (rc || (flags & CMD_ASYNC))
                return rc;
@@ -1392,33 +1149,36 @@ int iwl4965_send_add_station(struct iwl_priv *priv,
        return rc;
 }
 
-static int iwl4965_update_sta_key_info(struct iwl_priv *priv,
+static int iwl4965_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
                                   struct ieee80211_key_conf *keyconf,
                                   u8 sta_id)
 {
        unsigned long flags;
        __le16 key_flags = 0;
 
-       switch (keyconf->alg) {
-       case ALG_CCMP:
-               key_flags |= STA_KEY_FLG_CCMP;
-               key_flags |= cpu_to_le16(
-                               keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
-               key_flags &= ~STA_KEY_FLG_INVALID;
-               break;
-       case ALG_TKIP:
-       case ALG_WEP:
-       default:
-               return -EINVAL;
-       }
+       key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
+       key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
+
+       if (sta_id == priv->hw_setting.bcast_sta_id)
+               key_flags |= STA_KEY_MULTICAST_MSK;
+
+       keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
+       keyconf->hw_key_idx = keyconf->keyidx;
+
+       key_flags &= ~STA_KEY_FLG_INVALID;
+
        spin_lock_irqsave(&priv->sta_lock, flags);
        priv->stations[sta_id].keyinfo.alg = keyconf->alg;
        priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
+
        memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
               keyconf->keylen);
 
        memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
               keyconf->keylen);
+
+       priv->stations[sta_id].sta.key.key_offset
+                       = (sta_id % STA_KEY_MAX_NUM);/*FIXME*/
        priv->stations[sta_id].sta.key.key_flags = key_flags;
        priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
        priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
@@ -1426,8 +1186,35 @@ static int iwl4965_update_sta_key_info(struct iwl_priv *priv,
        spin_unlock_irqrestore(&priv->sta_lock, flags);
 
        IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
-       iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
-       return 0;
+       return iwl4965_send_add_station(priv,
+                               &priv->stations[sta_id].sta, CMD_ASYNC);
+}
+
+static int iwl4965_set_tkip_dynamic_key_info(struct iwl_priv *priv,
+                                  struct ieee80211_key_conf *keyconf,
+                                  u8 sta_id)
+{
+       unsigned long flags;
+       int ret = 0;
+
+       keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
+       keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
+       keyconf->hw_key_idx = keyconf->keyidx;
+
+       spin_lock_irqsave(&priv->sta_lock, flags);
+
+       priv->stations[sta_id].keyinfo.alg = keyconf->alg;
+       priv->stations[sta_id].keyinfo.conf = keyconf;
+       priv->stations[sta_id].keyinfo.keylen = 16;
+
+       /* This copy is acutally not needed: we get the key with each TX */
+       memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
+
+       memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
+
+       spin_unlock_irqrestore(&priv->sta_lock, flags);
+
+       return ret;
 }
 
 static int iwl4965_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
@@ -1447,6 +1234,46 @@ static int iwl4965_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
        return 0;
 }
 
+static int iwl4965_set_dynamic_key(struct iwl_priv *priv,
+                               struct ieee80211_key_conf *key, u8 sta_id)
+{
+       int ret;
+
+       switch (key->alg) {
+       case ALG_CCMP:
+               ret = iwl4965_set_ccmp_dynamic_key_info(priv, key, sta_id);
+               break;
+       case ALG_TKIP:
+               ret = iwl4965_set_tkip_dynamic_key_info(priv, key, sta_id);
+               break;
+       case ALG_WEP:
+               ret = -EOPNOTSUPP;
+               break;
+       default:
+               IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, key->alg);
+               ret = -EINVAL;
+       }
+
+       return ret;
+}
+
+static int iwl4965_remove_static_key(struct iwl_priv *priv)
+{
+       int ret = -EOPNOTSUPP;
+
+       return ret;
+}
+
+static int iwl4965_set_static_key(struct iwl_priv *priv,
+                               struct ieee80211_key_conf *key)
+{
+       if (key->alg == ALG_WEP)
+               return -EOPNOTSUPP;
+
+       IWL_ERROR("Static key invalid: alg %d\n", key->alg);
+       return -EINVAL;
+}
+
 static void iwl4965_clear_free_frames(struct iwl_priv *priv)
 {
        struct list_head *element;
@@ -1553,7 +1380,7 @@ static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
 
        frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
 
-       rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
+       rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
                              &frame->u.cmd[0]);
 
        iwl4965_free_frame(priv, frame);
@@ -1730,97 +1557,10 @@ static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
                                       struct iwl4965_qosparam_cmd *qos)
 {
 
-       return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM,
+       return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
                                sizeof(struct iwl4965_qosparam_cmd), qos);
 }
 
-static void iwl4965_reset_qos(struct iwl_priv *priv)
-{
-       u16 cw_min = 15;
-       u16 cw_max = 1023;
-       u8 aifs = 2;
-       u8 is_legacy = 0;
-       unsigned long flags;
-       int i;
-
-       spin_lock_irqsave(&priv->lock, flags);
-       priv->qos_data.qos_active = 0;
-
-       if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
-               if (priv->qos_data.qos_enable)
-                       priv->qos_data.qos_active = 1;
-               if (!(priv->active_rate & 0xfff0)) {
-                       cw_min = 31;
-                       is_legacy = 1;
-               }
-       } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
-               if (priv->qos_data.qos_enable)
-                       priv->qos_data.qos_active = 1;
-       } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
-               cw_min = 31;
-               is_legacy = 1;
-       }
-
-       if (priv->qos_data.qos_active)
-               aifs = 3;
-
-       priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
-       priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
-       priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
-       priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
-       priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
-
-       if (priv->qos_data.qos_active) {
-               i = 1;
-               priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
-               priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
-               priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
-               priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
-               priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
-
-               i = 2;
-               priv->qos_data.def_qos_parm.ac[i].cw_min =
-                       cpu_to_le16((cw_min + 1) / 2 - 1);
-               priv->qos_data.def_qos_parm.ac[i].cw_max =
-                       cpu_to_le16(cw_max);
-               priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
-               if (is_legacy)
-                       priv->qos_data.def_qos_parm.ac[i].edca_txop =
-                               cpu_to_le16(6016);
-               else
-                       priv->qos_data.def_qos_parm.ac[i].edca_txop =
-                               cpu_to_le16(3008);
-               priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
-
-               i = 3;
-               priv->qos_data.def_qos_parm.ac[i].cw_min =
-                       cpu_to_le16((cw_min + 1) / 4 - 1);
-               priv->qos_data.def_qos_parm.ac[i].cw_max =
-                       cpu_to_le16((cw_max + 1) / 2 - 1);
-               priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
-               priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
-               if (is_legacy)
-                       priv->qos_data.def_qos_parm.ac[i].edca_txop =
-                               cpu_to_le16(3264);
-               else
-                       priv->qos_data.def_qos_parm.ac[i].edca_txop =
-                               cpu_to_le16(1504);
-       } else {
-               for (i = 1; i < 4; i++) {
-                       priv->qos_data.def_qos_parm.ac[i].cw_min =
-                               cpu_to_le16(cw_min);
-                       priv->qos_data.def_qos_parm.ac[i].cw_max =
-                               cpu_to_le16(cw_max);
-                       priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
-                       priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
-                       priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
-               }
-       }
-       IWL_DEBUG_QOS("set QoS to default \n");
-
-       spin_unlock_irqrestore(&priv->lock, flags);
-}
-
 static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
 {
        unsigned long flags;
@@ -2027,7 +1767,7 @@ static int iwl4965_send_power_mode(struct iwl_priv *priv, u32 mode)
 
        iwl4965_update_power_cmd(priv, &cmd, final_mode);
 
-       rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
+       rc = iwl_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
 
        if (final_mode == IWL_POWER_MODE_CAM)
                clear_bit(STATUS_POWER_PMI, &priv->status);
@@ -2265,17 +2005,6 @@ static int iwl4965_scan_initiate(struct iwl_priv *priv)
        return 0;
 }
 
-static int iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
-{
-       struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
-
-       if (hw_decrypt)
-               rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
-       else
-               rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
-
-       return 0;
-}
 
 static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv,
                                          enum ieee80211_band band)
@@ -2306,7 +2035,7 @@ static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv,
  */
 static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
 {
-       const struct iwl4965_channel_info *ch_info;
+       const struct iwl_channel_info *ch_info;
 
        memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
 
@@ -2343,7 +2072,7 @@ static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
                priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
 #endif
 
-       ch_info = iwl4965_get_channel_info(priv, priv->band,
+       ch_info = iwl_get_channel_info(priv, priv->band,
                                       le16_to_cpu(priv->staging_rxon.channel));
 
        if (!ch_info)
@@ -2379,9 +2108,9 @@ static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
 static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
 {
        if (mode == IEEE80211_IF_TYPE_IBSS) {
-               const struct iwl4965_channel_info *ch_info;
+               const struct iwl_channel_info *ch_info;
 
-               ch_info = iwl4965_get_channel_info(priv,
+               ch_info = iwl_get_channel_info(priv,
                        priv->band,
                        le16_to_cpu(priv->staging_rxon.channel));
 
@@ -2397,7 +2126,7 @@ static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
        iwl4965_connection_init_rx_config(priv);
        memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
 
-       iwl4965_clear_stations_table(priv);
+       iwlcore_clear_stations_table(priv);
 
        /* dont commit rxon if rf-kill is on*/
        if (!iwl4965_is_ready_rf(priv))
@@ -2417,11 +2146,11 @@ static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
 
 static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
                                      struct ieee80211_tx_control *ctl,
-                                     struct iwl4965_cmd *cmd,
+                                     struct iwl_cmd *cmd,
                                      struct sk_buff *skb_frag,
-                                     int last_frag)
+                                     int sta_id)
 {
-       struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo;
+       struct iwl4965_hw_key *keyinfo = &priv->stations[sta_id].keyinfo;
 
        switch (keyinfo->alg) {
        case ALG_CCMP:
@@ -2433,15 +2162,10 @@ static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
                break;
 
        case ALG_TKIP:
-#if 0
                cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
-
-               if (last_frag)
-                       memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
-                              8);
-               else
-                       memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
-#endif
+               ieee80211_get_tkip_key(keyinfo->conf, skb_frag,
+                       IEEE80211_TKIP_P2_KEY, cmd->cmd.tx.key);
+               IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
                break;
 
        case ALG_WEP:
@@ -2467,7 +2191,7 @@ static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
  * handle build REPLY_TX command notification.
  */
 static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv,
-                                 struct iwl4965_cmd *cmd,
+                                 struct iwl_cmd *cmd,
                                  struct ieee80211_tx_control *ctrl,
                                  struct ieee80211_hdr *hdr,
                                  int is_unicast, u8 std_id)
@@ -2608,7 +2332,7 @@ static int iwl4965_tx_skb(struct iwl_priv *priv,
        dma_addr_t phys_addr;
        dma_addr_t txcmd_phys;
        dma_addr_t scratch_phys;
-       struct iwl4965_cmd *out_cmd = NULL;
+       struct iwl_cmd *out_cmd = NULL;
        u16 len, idx, len_org;
        u8 id, hdr_len, unicast;
        u8 sta_id;
@@ -2737,7 +2461,7 @@ static int iwl4965_tx_skb(struct iwl_priv *priv,
         * We'll tell device about this padding later.
         */
        len = priv->hw_setting.tx_cmd_len +
-               sizeof(struct iwl4965_cmd_header) + hdr_len;
+               sizeof(struct iwl_cmd_header) + hdr_len;
 
        len_org = len;
        len = (len + 3) & ~3;
@@ -2749,15 +2473,15 @@ static int iwl4965_tx_skb(struct iwl_priv *priv,
 
        /* Physical address of this Tx command's header (not MAC header!),
         * within command buffer array. */
-       txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx +
-                    offsetof(struct iwl4965_cmd, hdr);
+       txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx +
+                    offsetof(struct iwl_cmd, hdr);
 
        /* Add buffer containing Tx command and MAC(!) header to TFD's
         * first entry */
        iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
 
        if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
-               iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0);
+               iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, sta_id);
 
        /* Set up TFD's 2nd entry to point directly to remainder of skb,
         * if any (802.11 null frames have no payload). */
@@ -2784,7 +2508,7 @@ static int iwl4965_tx_skb(struct iwl_priv *priv,
 
        iwl_update_tx_stats(priv, fc, len);
 
-       scratch_phys = txcmd_phys + sizeof(struct iwl4965_cmd_header) +
+       scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) +
                offsetof(struct iwl4965_tx_cmd, scratch);
        out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys);
        out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys);
@@ -2948,6 +2672,12 @@ void iwl4965_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
        IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
        switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
        case RX_RES_STATUS_SEC_TYPE_TKIP:
+               /* The uCode has got a bad phase 1 Key, pushes the packet.
+                * Decryption will be done in SW. */
+               if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
+                   RX_RES_STATUS_BAD_KEY_TTAK)
+                       break;
+
                if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
                    RX_RES_STATUS_BAD_ICV_MIC)
                        stats->flag |= RX_FLAG_MMIC_ERROR;
@@ -3091,7 +2821,7 @@ static int iwl4965_get_measurement(struct iwl_priv *priv,
 {
        struct iwl4965_spectrum_cmd spectrum;
        struct iwl4965_rx_packet *res;
-       struct iwl4965_host_cmd cmd = {
+       struct iwl_host_cmd cmd = {
                .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
                .data = (void *)&spectrum,
                .meta.flags = CMD_WANT_SKB,
@@ -3131,7 +2861,7 @@ static int iwl4965_get_measurement(struct iwl_priv *priv,
                spectrum.flags |= RXON_FLG_BAND_24G_MSK |
                    RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
 
-       rc = iwl4965_send_cmd_sync(priv, &cmd);
+       rc = iwl_send_cmd_sync(priv, &cmd);
        if (rc)
                return rc;
 
@@ -3906,7 +3636,7 @@ static void iwl4965_tx_cmd_complete(struct iwl_priv *priv,
        int index = SEQ_TO_INDEX(sequence);
        int huge = sequence & SEQ_HUGE_FRAME;
        int cmd_index;
-       struct iwl4965_cmd *cmd;
+       struct iwl_cmd *cmd;
 
        /* If a Tx command is being handled and it isn't in the actual
         * command queue then there a command routing bug has been introduced
@@ -4408,7 +4138,7 @@ static void iwl4965_rx_handle(struct iwl_priv *priv)
                 *   but apparently a few don't get set; catch them here. */
                reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
                        (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
-                       (pkt->hdr.cmd != REPLY_4965_RX) &&
+                       (pkt->hdr.cmd != REPLY_RX) &&
                        (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
                        (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
                        (pkt->hdr.cmd != REPLY_TX);
@@ -4431,7 +4161,7 @@ static void iwl4965_rx_handle(struct iwl_priv *priv)
 
                if (reclaim) {
                        /* Invoke any callbacks, transfer the skb to caller, and
-                        * fire off the (possibly) blocking iwl4965_send_cmd()
+                        * fire off the (possibly) blocking iwl_send_cmd()
                         * as we reclaim the driver command queue */
                        if (rxb && rxb->skb)
                                iwl4965_tx_cmd_complete(priv, rxb);
@@ -5001,308 +4731,6 @@ static irqreturn_t iwl4965_isr(int irq, void *data)
        return IRQ_NONE;
 }
 
-/************************** EEPROM BANDS ****************************
- *
- * The iwl4965_eeprom_band definitions below provide the mapping from the
- * EEPROM contents to the specific channel number supported for each
- * band.
- *
- * 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.
- *
- * During init, we copy the eeprom information and channel map
- * information into priv->channel_info_24/52 and priv->channel_map_24/52
- *
- * channel_map_24/52 provides the index in the channel_info array for a
- * given channel.  We have to have two separate maps as there is channel
- * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
- * band_2
- *
- * A value of 0xff stored in the channel_map indicates that the channel
- * is not supported by the hardware at all.
- *
- * A value of 0xfe in the channel_map indicates that the channel is not
- * valid for Tx with the current hardware.  This means that
- * while the system can tune and receive on a given channel, it may not
- * be able to associate or transmit any frames on that
- * channel.  There is no corresponding channel information for that
- * entry.
- *
- *********************************************************************/
-
-/* 2.4 GHz */
-static const u8 iwl4965_eeprom_band_1[14] = {
-       1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
-};
-
-/* 5.2 GHz bands */
-static const u8 iwl4965_eeprom_band_2[] = {    /* 4915-5080MHz */
-       183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
-};
-
-static const u8 iwl4965_eeprom_band_3[] = {    /* 5170-5320MHz */
-       34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
-};
-
-static const u8 iwl4965_eeprom_band_4[] = {    /* 5500-5700MHz */
-       100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
-};
-
-static const u8 iwl4965_eeprom_band_5[] = {    /* 5725-5825MHz */
-       145, 149, 153, 157, 161, 165
-};
-
-static u8 iwl4965_eeprom_band_6[] = {       /* 2.4 FAT channel */
-       1, 2, 3, 4, 5, 6, 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 iwl_priv *priv,
-                                   int band,
-                                   int *eeprom_ch_count,
-                                   const struct iwl4965_eeprom_channel
-                                   **eeprom_ch_info,
-                                   const u8 **eeprom_ch_index)
-{
-       switch (band) {
-       case 1:         /* 2.4GHz band */
-               *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_1);
-               *eeprom_ch_info = priv->eeprom.band_1_channels;
-               *eeprom_ch_index = iwl4965_eeprom_band_1;
-               break;
-       case 2:         /* 4.9GHz band */
-               *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_2);
-               *eeprom_ch_info = priv->eeprom.band_2_channels;
-               *eeprom_ch_index = iwl4965_eeprom_band_2;
-               break;
-       case 3:         /* 5.2GHz band */
-               *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_3);
-               *eeprom_ch_info = priv->eeprom.band_3_channels;
-               *eeprom_ch_index = iwl4965_eeprom_band_3;
-               break;
-       case 4:         /* 5.5GHz band */
-               *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_4);
-               *eeprom_ch_info = priv->eeprom.band_4_channels;
-               *eeprom_ch_index = iwl4965_eeprom_band_4;
-               break;
-       case 5:         /* 5.7GHz band */
-               *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_5);
-               *eeprom_ch_info = priv->eeprom.band_5_channels;
-               *eeprom_ch_index = iwl4965_eeprom_band_5;
-               break;
-       case 6:         /* 2.4GHz FAT channels */
-               *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_6);
-               *eeprom_ch_info = priv->eeprom.band_24_channels;
-               *eeprom_ch_index = iwl4965_eeprom_band_6;
-               break;
-       case 7:         /* 5 GHz FAT channels */
-               *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_7);
-               *eeprom_ch_info = priv->eeprom.band_52_channels;
-               *eeprom_ch_index = iwl4965_eeprom_band_7;
-               break;
-       default:
-               BUG();
-               return;
-       }
-}
-
-/**
- * iwl4965_get_channel_info - Find driver's private channel info
- *
- * Based on band and channel number.
- */
-const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl_priv *priv,
-                                                   enum ieee80211_band band, u16 channel)
-{
-       int i;
-
-       switch (band) {
-       case IEEE80211_BAND_5GHZ:
-               for (i = 14; i < priv->channel_count; i++) {
-                       if (priv->channel_info[i].channel == channel)
-                               return &priv->channel_info[i];
-               }
-               break;
-       case IEEE80211_BAND_2GHZ:
-               if (channel >= 1 && channel <= 14)
-                       return &priv->channel_info[channel - 1];
-               break;
-       default:
-               BUG();
-       }
-
-       return NULL;
-}
-
-#define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
-                           ? # x " " : "")
-
-/**
- * iwl4965_init_channel_map - Set up driver's info for all possible channels
- */
-static int iwl4965_init_channel_map(struct iwl_priv *priv)
-{
-       int eeprom_ch_count = 0;
-       const u8 *eeprom_ch_index = NULL;
-       const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL;
-       int band, ch;
-       struct iwl4965_channel_info *ch_info;
-
-       if (priv->channel_count) {
-               IWL_DEBUG_INFO("Channel map already initialized.\n");
-               return 0;
-       }
-
-       if (priv->eeprom.version < 0x2f) {
-               IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
-                           priv->eeprom.version);
-               return -EINVAL;
-       }
-
-       IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
-
-       priv->channel_count =
-           ARRAY_SIZE(iwl4965_eeprom_band_1) +
-           ARRAY_SIZE(iwl4965_eeprom_band_2) +
-           ARRAY_SIZE(iwl4965_eeprom_band_3) +
-           ARRAY_SIZE(iwl4965_eeprom_band_4) +
-           ARRAY_SIZE(iwl4965_eeprom_band_5);
-
-       IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
-
-       priv->channel_info = kzalloc(sizeof(struct iwl4965_channel_info) *
-                                    priv->channel_count, GFP_KERNEL);
-       if (!priv->channel_info) {
-               IWL_ERROR("Could not allocate channel_info\n");
-               priv->channel_count = 0;
-               return -ENOMEM;
-       }
-
-       ch_info = priv->channel_info;
-
-       /* Loop through the 5 EEPROM bands adding them in order to the
-        * channel map we maintain (that contains additional information than
-        * what just in the EEPROM) */
-       for (band = 1; band <= 5; band++) {
-
-               iwl4965_init_band_reference(priv, band, &eeprom_ch_count,
-                                       &eeprom_ch_info, &eeprom_ch_index);
-
-               /* Loop through each band adding each of the channels */
-               for (ch = 0; ch < eeprom_ch_count; ch++) {
-                       ch_info->channel = eeprom_ch_index[ch];
-                       ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
-                           IEEE80211_BAND_5GHZ;
-
-                       /* permanently store EEPROM's channel regulatory flags
-                        *   and max power in channel info database. */
-                       ch_info->eeprom = eeprom_ch_info[ch];
-
-                       /* Copy the run-time flags so they are there even on
-                        * invalid channels */
-                       ch_info->flags = eeprom_ch_info[ch].flags;
-
-                       if (!(is_channel_valid(ch_info))) {
-                               IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
-                                              "No traffic\n",
-                                              ch_info->channel,
-                                              ch_info->flags,
-                                              is_channel_a_band(ch_info) ?
-                                              "5.2" : "2.4");
-                               ch_info++;
-                               continue;
-                       }
-
-                       /* Initialize regulatory-based run-time data */
-                       ch_info->max_power_avg = ch_info->curr_txpow =
-                           eeprom_ch_info[ch].max_power_avg;
-                       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%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),
-                                      CHECK_AND_PRINT(WIDE),
-                                      CHECK_AND_PRINT(NARROW),
-                                      CHECK_AND_PRINT(DFS),
-                                      eeprom_ch_info[ch].flags,
-                                      eeprom_ch_info[ch].max_power_avg,
-                                      ((eeprom_ch_info[ch].
-                                        flags & EEPROM_CHANNEL_IBSS)
-                                       && !(eeprom_ch_info[ch].
-                                            flags & EEPROM_CHANNEL_RADAR))
-                                      ? "" : "not ");
-
-                       /* Set the user_txpower_limit to the highest power
-                        * supported by any channel */
-                       if (eeprom_ch_info[ch].max_power_avg >
-                           priv->user_txpower_limit)
-                               priv->user_txpower_limit =
-                                   eeprom_ch_info[ch].max_power_avg;
-
-                       ch_info++;
-               }
-       }
-
-       /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */
-       for (band = 6; band <= 7; band++) {
-               enum ieee80211_band ieeeband;
-               u8 fat_extension_chan;
-
-               iwl4965_init_band_reference(priv, band, &eeprom_ch_count,
-                                       &eeprom_ch_info, &eeprom_ch_index);
-
-               /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
-               ieeeband = (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
-
-               /* Loop through each band adding each of the channels */
-               for (ch = 0; ch < eeprom_ch_count; ch++) {
-
-                       if ((band == 6) &&
-                           ((eeprom_ch_index[ch] == 5) ||
-                           (eeprom_ch_index[ch] == 6) ||
-                           (eeprom_ch_index[ch] == 7)))
-                              fat_extension_chan = HT_IE_EXT_CHANNEL_MAX;
-                       else
-                               fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE;
-
-                       /* Set up driver's info for lower half */
-                       iwl4965_set_fat_chan_info(priv, ieeeband,
-                                                 eeprom_ch_index[ch],
-                                                 &(eeprom_ch_info[ch]),
-                                                 fat_extension_chan);
-
-                       /* Set up driver's info for upper half */
-                       iwl4965_set_fat_chan_info(priv, ieeeband,
-                                                 (eeprom_ch_index[ch] + 4),
-                                                 &(eeprom_ch_info[ch]),
-                                                 HT_IE_EXT_CHANNEL_BELOW);
-               }
-       }
-
-       return 0;
-}
-
-/*
- * iwl4965_free_channel_map - undo allocations in iwl4965_init_channel_map
- */
-static void iwl4965_free_channel_map(struct iwl_priv *priv)
-{
-       kfree(priv->channel_info);
-       priv->channel_count = 0;
-}
-
 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
  * sending probe req.  This should be set long enough to hear probe responses
  * from more than one AP.  */
@@ -5366,7 +4794,7 @@ static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
 {
        const struct ieee80211_channel *channels = NULL;
        const struct ieee80211_supported_band *sband;
-       const struct iwl4965_channel_info *ch_info;
+       const struct iwl_channel_info *ch_info;
        u16 passive_dwell = 0;
        u16 active_dwell = 0;
        int added, i;
@@ -5394,7 +4822,7 @@ static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
 
                scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq);
 
-               ch_info = iwl4965_get_channel_info(priv, band,
+               ch_info = iwl_get_channel_info(priv, band,
                                         scan_ch->channel);
                if (!is_channel_valid(ch_info)) {
                        IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
@@ -5470,9 +4898,9 @@ static void iwl4965_init_hw_rates(struct iwl_priv *priv,
 /**
  * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
  */
-static int iwl4965_init_geos(struct iwl_priv *priv)
+int iwl4965_init_geos(struct iwl_priv *priv)
 {
-       struct iwl4965_channel_info *ch;
+       struct iwl_channel_info *ch;
        struct ieee80211_supported_band *sband;
        struct ieee80211_channel *channels;
        struct ieee80211_channel *geo_ch;
@@ -5500,7 +4928,7 @@ static int iwl4965_init_geos(struct iwl_priv *priv)
 
        /* 5.2GHz channels start after the 2.4GHz channels */
        sband = &priv->bands[IEEE80211_BAND_5GHZ];
-       sband->channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)];
+       sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
        /* just OFDM */
        sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
        sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
@@ -5592,7 +5020,7 @@ static int iwl4965_init_geos(struct iwl_priv *priv)
 /*
  * iwl4965_free_geos - undo allocations in iwl4965_init_geos
  */
-static void iwl4965_free_geos(struct iwl_priv *priv)
+void iwl4965_free_geos(struct iwl_priv *priv)
 {
        kfree(priv->ieee_channels);
        kfree(priv->ieee_rates);
@@ -6235,7 +5663,7 @@ static void iwl4965_alive_start(struct iwl_priv *priv)
                goto restart;
        }
 
-       iwl4965_clear_stations_table(priv);
+       iwlcore_clear_stations_table(priv);
 
        rc = iwl4965_alive_notify(priv);
        if (rc) {
@@ -6312,7 +5740,7 @@ static void __iwl4965_down(struct iwl_priv *priv)
        if (!exit_pending)
                set_bit(STATUS_EXIT_PENDING, &priv->status);
 
-       iwl4965_clear_stations_table(priv);
+       iwlcore_clear_stations_table(priv);
 
        /* Unblock any waiting calls */
        wake_up_interruptible_all(&priv->wait_command_queue);
@@ -6467,7 +5895,7 @@ static int __iwl4965_up(struct iwl_priv *priv)
 
        for (i = 0; i < MAX_HW_RESTARTS; i++) {
 
-               iwl4965_clear_stations_table(priv);
+               iwlcore_clear_stations_table(priv);
 
                /* load bootstrap state machine,
                 * load bootstrap program into processor's memory,
@@ -6586,17 +6014,17 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
 {
        struct iwl_priv *priv =
            container_of(data, struct iwl_priv, request_scan);
-       struct iwl4965_host_cmd cmd = {
+       struct iwl_host_cmd cmd = {
                .id = REPLY_SCAN_CMD,
                .len = sizeof(struct iwl4965_scan_cmd),
                .meta.flags = CMD_SIZE_HUGE,
        };
-       int rc = 0;
        struct iwl4965_scan_cmd *scan;
        struct ieee80211_conf *conf = NULL;
        u16 cmd_len;
        enum ieee80211_band band;
        u8 direct_mask;
+       int ret = 0;
 
        conf = ieee80211_get_hw_conf(priv->hw);
 
@@ -6617,7 +6045,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
        if (test_bit(STATUS_SCAN_HW, &priv->status)) {
                IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
                               "Ignoring second request.\n");
-               rc = -EIO;
+               ret = -EIO;
                goto done;
        }
 
@@ -6650,7 +6078,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
                priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
                                     IWL_MAX_SCAN_SIZE, GFP_KERNEL);
                if (!priv->scan) {
-                       rc = -ENOMEM;
+                       ret = -ENOMEM;
                        goto done;
                }
        }
@@ -6702,8 +6130,9 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
                scan->direct_scan[0].len = priv->essid_len;
                memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
                direct_mask = 1;
-       } else
+       } else {
                direct_mask = 0;
+       }
 
        scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
        scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
@@ -6778,8 +6207,8 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
        scan->len = cpu_to_le16(cmd.len);
 
        set_bit(STATUS_SCAN_HW, &priv->status);
-       rc = iwl4965_send_cmd_sync(priv, &cmd);
-       if (rc)
+       ret = iwl_send_cmd_sync(priv, &cmd);
+       if (ret)
                goto done;
 
        queue_delayed_work(priv->workqueue, &priv->scan_check,
@@ -6836,9 +6265,8 @@ static void iwl4965_bg_post_associate(struct work_struct *data)
 {
        struct iwl_priv *priv = container_of(data, struct iwl_priv,
                                             post_associate.work);
-
-       int rc = 0;
        struct ieee80211_conf *conf = NULL;
+       int ret = 0;
        DECLARE_MAC_BUF(mac);
 
        if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
@@ -6869,9 +6297,9 @@ static void iwl4965_bg_post_associate(struct work_struct *data)
 
        memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
        iwl4965_setup_rxon_timing(priv);
-       rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
+       ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
                              sizeof(priv->rxon_timing), &priv->rxon_timing);
-       if (rc)
+       if (ret)
                IWL_WARNING("REPLY_RXON_TIMING failed - "
                            "Attempting to continue.\n");
 
@@ -6913,7 +6341,7 @@ static void iwl4965_bg_post_associate(struct work_struct *data)
        case IEEE80211_IF_TYPE_IBSS:
 
                /* clear out the station table */
-               iwl4965_clear_stations_table(priv);
+               iwlcore_clear_stations_table(priv);
 
                iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
                iwl4965_rxon_add_station(priv, priv->bssid, 0);
@@ -7171,7 +6599,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 iwl_priv *priv = hw->priv;
-       const struct iwl4965_channel_info *ch_info;
+       const struct iwl_channel_info *ch_info;
        unsigned long flags;
        int ret = 0;
 
@@ -7186,7 +6614,7 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
                goto out;
        }
 
-       if (unlikely(!iwl4965_param_disable_hw_scan &&
+       if (unlikely(!iwl4965_mod_params.disable_hw_scan &&
                     test_bit(STATUS_SCANNING, &priv->status))) {
                IWL_DEBUG_MAC80211("leave - scanning\n");
                set_bit(STATUS_CONF_PENDING, &priv->status);
@@ -7196,7 +6624,7 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
 
        spin_lock_irqsave(&priv->lock, flags);
 
-       ch_info = iwl4965_get_channel_info(priv, conf->channel->band,
+       ch_info = iwl_get_channel_info(priv, conf->channel->band,
                        ieee80211_frequency_to_channel(conf->channel->center_freq));
        if (!is_channel_valid(ch_info)) {
                IWL_DEBUG_MAC80211("leave - invalid channel\n");
@@ -7217,7 +6645,7 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
                priv->staging_rxon.flags = 0;
 #endif /* CONFIG_IWL4965_HT */
 
-       iwl4965_set_rxon_channel(priv, conf->channel->band,
+       iwlcore_set_rxon_channel(priv, conf->channel->band,
                ieee80211_frequency_to_channel(conf->channel->center_freq));
 
        iwl4965_set_flags_for_phymode(priv, conf->channel->band);
@@ -7267,7 +6695,7 @@ out:
 
 static void iwl4965_config_ap(struct iwl_priv *priv)
 {
-       int rc = 0;
+       int ret = 0;
 
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
@@ -7282,9 +6710,9 @@ static void iwl4965_config_ap(struct iwl_priv *priv)
                /* RXON Timing */
                memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
                iwl4965_setup_rxon_timing(priv);
-               rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
+               ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
                                sizeof(priv->rxon_timing), &priv->rxon_timing);
-               if (rc)
+               if (ret)
                        IWL_WARNING("REPLY_RXON_TIMING failed - "
                                        "Attempting to continue.\n");
 
@@ -7560,18 +6988,69 @@ out_unlock:
        return rc;
 }
 
+static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
+                       struct ieee80211_key_conf *keyconf, const u8 *addr,
+                       u32 iv32, u16 *phase1key)
+{
+       struct iwl_priv *priv = hw->priv;
+       u8 sta_id = IWL_INVALID_STATION;
+       unsigned long flags;
+       __le16 key_flags = 0;
+       int i;
+       DECLARE_MAC_BUF(mac);
+
+       IWL_DEBUG_MAC80211("enter\n");
+
+       sta_id = iwl4965_hw_find_station(priv, addr);
+       if (sta_id == IWL_INVALID_STATION) {
+               IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
+                                  print_mac(mac, addr));
+               return;
+       }
+
+       iwl4965_scan_cancel_timeout(priv, 100);
+
+       key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
+       key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
+       key_flags &= ~STA_KEY_FLG_INVALID;
+
+       if (sta_id == priv->hw_setting.bcast_sta_id)
+               key_flags |= STA_KEY_MULTICAST_MSK;
+
+       spin_lock_irqsave(&priv->sta_lock, flags);
+
+       priv->stations[sta_id].sta.key.key_offset =
+                                       (sta_id % STA_KEY_MAX_NUM);/* FIXME */
+       priv->stations[sta_id].sta.key.key_flags = key_flags;
+       priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
+
+       for (i = 0; i < 5; i++)
+               priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
+                       cpu_to_le16(phase1key[i]);
+
+       priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
+       priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
+
+       iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
+
+       spin_unlock_irqrestore(&priv->sta_lock, flags);
+
+       IWL_DEBUG_MAC80211("leave\n");
+}
+
 static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
                           const u8 *local_addr, const u8 *addr,
                           struct ieee80211_key_conf *key)
 {
        struct iwl_priv *priv = hw->priv;
        DECLARE_MAC_BUF(mac);
-       int rc = 0;
-       u8 sta_id;
+       int ret = 0;
+       u8 sta_id = IWL_INVALID_STATION;
+       u8 static_key;
 
        IWL_DEBUG_MAC80211("enter\n");
 
-       if (!iwl4965_param_hwcrypto) {
+       if (!iwl4965_mod_params.hw_crypto) {
                IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
                return -EOPNOTSUPP;
        }
@@ -7580,44 +7059,45 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
                /* only support pairwise keys */
                return -EOPNOTSUPP;
 
-       sta_id = iwl4965_hw_find_station(priv, addr);
-       if (sta_id == IWL_INVALID_STATION) {
-               IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
-                                  print_mac(mac, addr));
-               return -EINVAL;
-       }
+       /* FIXME: need to differenciate between static and dynamic key
+        * in the level of mac80211 */
+       static_key = !iwl4965_is_associated(priv);
 
-       mutex_lock(&priv->mutex);
+       if (!static_key) {
+               sta_id = iwl4965_hw_find_station(priv, addr);
+               if (sta_id == IWL_INVALID_STATION) {
+                       IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
+                                          print_mac(mac, addr));
+                       return -EINVAL;
+               }
+       }
 
        iwl4965_scan_cancel_timeout(priv, 100);
 
        switch (cmd) {
-       case  SET_KEY:
-               rc = iwl4965_update_sta_key_info(priv, key, sta_id);
-               if (!rc) {
-                       iwl4965_set_rxon_hwcrypto(priv, 1);
-                       iwl4965_commit_rxon(priv);
-                       key->hw_key_idx = sta_id;
-                       IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
-                       key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
-               }
+       case SET_KEY:
+               if (static_key)
+                       ret = iwl4965_set_static_key(priv, key);
+               else
+                       ret = iwl4965_set_dynamic_key(priv, key, sta_id);
+
+               IWL_DEBUG_MAC80211("enable hwcrypto key\n");
                break;
        case DISABLE_KEY:
-               rc = iwl4965_clear_sta_key_info(priv, sta_id);
-               if (!rc) {
-                       iwl4965_set_rxon_hwcrypto(priv, 0);
-                       iwl4965_commit_rxon(priv);
-                       IWL_DEBUG_MAC80211("disable hwcrypto key\n");
-               }
+               if (static_key)
+                       ret = iwl4965_remove_static_key(priv);
+               else
+                       ret = iwl4965_clear_sta_key_info(priv, sta_id);
+
+               IWL_DEBUG_MAC80211("disable hwcrypto key\n");
                break;
        default:
-               rc = -EINVAL;
+               ret = -EINVAL;
        }
 
        IWL_DEBUG_MAC80211("leave\n");
-       mutex_unlock(&priv->mutex);
 
-       return rc;
+       return ret;
 }
 
 static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue,
@@ -7738,7 +7218,7 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
        spin_unlock_irqrestore(&priv->lock, flags);
 #endif /* CONFIG_IWL4965_HT */
 
-       iwl4965_reset_qos(priv);
+       iwlcore_reset_qos(priv);
 
        cancel_delayed_work(&priv->post_associate);
 
@@ -7827,7 +7307,7 @@ static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *sk
        IWL_DEBUG_MAC80211("leave\n");
        spin_unlock_irqrestore(&priv->lock, flags);
 
-       iwl4965_reset_qos(priv);
+       iwlcore_reset_qos(priv);
 
        queue_work(priv->workqueue, &priv->post_associate.work);
 
@@ -8499,6 +7979,7 @@ static struct ieee80211_ops iwl4965_hw_ops = {
        .config_interface = iwl4965_mac_config_interface,
        .configure_filter = iwl4965_configure_filter,
        .set_key = iwl4965_mac_set_key,
+       .update_tkip_key = iwl4965_mac_update_tkip_key,
        .get_stats = iwl4965_mac_get_stats,
        .get_tx_stats = iwl4965_mac_get_tx_stats,
        .conf_tx = iwl4965_mac_conf_tx,
@@ -8519,82 +8000,41 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        struct iwl_priv *priv;
        struct ieee80211_hw *hw;
        struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
-       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) {
+       if (iwl4965_mod_params.disable_hw_scan) {
                IWL_DEBUG_INFO("Disabling hw_scan\n");
                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 iwl_priv), &iwl4965_hw_ops);
-       if (hw == NULL) {
-               IWL_ERROR("Can not allocate network device\n");
+       hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
+       if (!hw) {
                err = -ENOMEM;
                goto out;
        }
-       SET_IEEE80211_DEV(hw, &pdev->dev);
+       priv = hw->priv;
+       /* At this point both hw and priv are allocated. */
 
-       hw->rate_control_algorithm = "iwl-4965-rs";
+       SET_IEEE80211_DEV(hw, &pdev->dev);
 
        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_IWLWIFI_DEBUG
-       iwl_debug_level = iwl4965_param_debug;
+       iwl_debug_level = iwl4965_mod_params.debug;
        atomic_set(&priv->restrict_refcnt, 0);
 #endif
-       priv->retry_rate = 1;
-
-       priv->ibss_beacon = NULL;
-
-       /* Tell mac80211 and its clients (e.g. Wireless Extensions)
-        *   the range of signal quality values that we'll provide.
-        * Negative values for level/noise indicate that we'll provide dBm.
-        * For WE, at least, non-0 values here *enable* display of values
-        *   in app (iwconfig). */
-       hw->max_rssi = -20;     /* signal level, negative indicates dBm */
-       hw->max_noise = -20;    /* noise level, negative indicates dBm */
-       hw->max_signal = 100;   /* link quality indication (%) */
-
-       /* Tell mac80211 our Tx characteristics */
-       hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
 
-       /* Default value; 4 EDCA QOS priorities */
-       hw->queues = 4;
-#ifdef CONFIG_IWL4965_HT
-       /* Enhanced value; more queues, to support 11n aggregation */
-       hw->queues = 16;
-#endif /* CONFIG_IWL4965_HT */
-
-       spin_lock_init(&priv->lock);
-       spin_lock_init(&priv->power_data.lock);
-       spin_lock_init(&priv->sta_lock);
-       spin_lock_init(&priv->hcmd_lock);
-       spin_lock_init(&priv->lq_mngr.lock);
-
-       for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
-               INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
-
-       INIT_LIST_HEAD(&priv->free_frames);
-
-       mutex_init(&priv->mutex);
+       /**************************
+        * 2. Initializing PCI bus
+        **************************/
        if (pci_enable_device(pdev)) {
                err = -ENODEV;
                goto out_ieee80211_free_hw;
@@ -8602,31 +8042,28 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
 
        pci_set_master(pdev);
 
-       /* Clear the driver's (not device's) station table */
-       iwl4965_clear_stations_table(priv);
-
-       priv->data_retry_limit = -1;
-       priv->ieee_channels = NULL;
-       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;
+               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;
 
+       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;
@@ -8634,60 +8071,78 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
        }
 
        IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
-                       (unsigned long long) pci_resource_len(pdev, 0));
+               (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;
-
-       /* Choose which receivers/antennas to use */
-       iwl4965_set_rxon_chain(priv);
-
-
        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;
        }
 
-       if (iwl4965_param_qos_enable)
-               priv->qos_data.qos_enable = 1;
+       /*******************
+        * 6. Setup hw/priv
+        *******************/
 
-       iwl4965_reset_qos(priv);
+       err = iwl_setup(priv);
+       if (err)
+               goto out_unset_hw_settings;
+       /* At this point both hw and priv are initialized. */
 
-       priv->qos_data.qos_active = 0;
-       priv->qos_data.qos_cap.val = 0;
+       /**********************************
+        * 7. Initialize module parameters
+        **********************************/
 
-       iwl4965_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
-       iwl4965_setup_deferred_work(priv);
-       iwl4965_setup_rx_handlers(priv);
+       /* Disable radio (SW RF KILL) via parameter when loading driver */
+       if (iwl4965_mod_params.disable) {
+               set_bit(STATUS_RF_KILL_SW, &priv->status);
+               IWL_DEBUG_INFO("Radio disabled.\n");
+       }
 
-       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;
+       if (iwl4965_mod_params.enable_qos)
+               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_release_irq;
+               goto out_unset_hw_settings;
        }
 
        err = iwl_dbgfs_register(priv, DRV_NAME);
@@ -8695,76 +8150,29 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
                IWL_ERROR("failed to create debugfs files\n");
                goto out_remove_sysfs;
        }
-       /* 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_dbgfs;
-        }
-       /* Read the EEPROM */
-       err = iwl_eeprom_init(priv);
-       if (err) {
-               IWL_ERROR("Unable to init EEPROM\n");
-               goto out_remove_dbgfs;
-       }
-       /* 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);
-
-       err = iwl4965_init_channel_map(priv);
-       if (err) {
-               IWL_ERROR("initializing regulatory failed: %d\n", err);
-               goto out_remove_dbgfs;
-       }
-
-       err = iwl4965_init_geos(priv);
-       if (err) {
-               IWL_ERROR("initializing geos failed: %d\n", err);
-               goto out_free_channel_map;
-       }
 
-       iwl4965_rate_control_register(priv->hw);
-       err = ieee80211_register_hw(priv->hw);
-       if (err) {
-               IWL_ERROR("Failed to register network device (error %d)\n", err);
-               goto out_free_geos;
-       }
+       iwl4965_setup_deferred_work(priv);
+       iwl4965_setup_rx_handlers(priv);
 
-       priv->hw->conf.beacon_int = 100;
-       priv->mac80211_registered = 1;
+       /********************
+        * 9. Conclude
+        ********************/
        pci_save_state(pdev);
        pci_disable_device(pdev);
 
        return 0;
 
- out_free_geos:
-       iwl4965_free_geos(priv);
- out_free_channel_map:
-       iwl4965_free_channel_map(priv);
- out_remove_dbgfs:
-       iwl_dbgfs_unregister(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:
@@ -8804,7 +8212,7 @@ static void iwl4965_pci_remove(struct pci_dev *pdev)
        iwl4965_hw_txq_ctx_free(priv);
 
        iwl4965_unset_hw_setting(priv);
-       iwl4965_clear_stations_table(priv);
+       iwlcore_clear_stations_table(priv);
 
        if (priv->mac80211_registered) {
                ieee80211_unregister_hw(priv->hw);
@@ -8825,7 +8233,7 @@ static void iwl4965_pci_remove(struct pci_dev *pdev)
        pci_disable_device(pdev);
        pci_set_drvdata(pdev, NULL);
 
-       iwl4965_free_channel_map(priv);
+       iwl_free_channel_map(priv);
        iwl4965_free_geos(priv);
 
        if (priv->ibss_beacon)
@@ -8914,25 +8322,26 @@ static void __exit iwl4965_exit(void)
        pci_unregister_driver(&iwl4965_driver);
 }
 
-module_param_named(antenna, iwl4965_param_antenna, int, 0444);
+module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
 MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
-module_param_named(disable, iwl4965_param_disable, int, 0444);
+module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
-module_param_named(hwcrypto, iwl4965_param_hwcrypto, int, 0444);
+module_param_named(hwcrypto, iwl4965_mod_params.hw_crypto, int, 0444);
 MODULE_PARM_DESC(hwcrypto,
                 "using hardware crypto engine (default 0 [software])\n");
-module_param_named(debug, iwl4965_param_debug, int, 0444);
+module_param_named(debug, iwl4965_mod_params.debug, int, 0444);
 MODULE_PARM_DESC(debug, "debug output mask");
-module_param_named(disable_hw_scan, iwl4965_param_disable_hw_scan, int, 0444);
+module_param_named(
+       disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444);
 MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
 
-module_param_named(queues_num, iwl4965_param_queues_num, int, 0444);
+module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
 MODULE_PARM_DESC(queues_num, "number of hw queues.");
 
 /* QoS */
-module_param_named(qos_enable, iwl4965_param_qos_enable, int, 0444);
+module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
 MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
-module_param_named(amsdu_size_8K, iwl4965_param_amsdu_size_8K, int, 0444);
+module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
 MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
 
 module_exit(iwl4965_exit);
This page took 0.051048 seconds and 5 git commands to generate.