Merge branch 'core/xen' into x86/xen
[safe/jmp/linux-2.6] / drivers / net / wireless / iwlwifi / iwl-4965.c
index 84414da..23fed32 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/version.h>
 #include <linux/init.h>
 #include <linux/pci.h>
 #include <linux/dma-mapping.h>
 #include "iwl-calib.h"
 #include "iwl-sta.h"
 
+static int iwl4965_send_tx_power(struct iwl_priv *priv);
+static int iwl4965_hw_get_temperature(const struct iwl_priv *priv);
+
+/* 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 "-2"
+
+
 /* module parameters */
 static struct iwl_mod_params iwl4965_mod_params = {
        .num_of_queues = IWL49_NUM_QUEUES,
+       .num_of_ampdu_queues = IWL49_NUM_AMPDU_QUEUES,
        .enable_qos = 1,
        .amsdu_size_8K = 1,
        .restart_fw = 1,
@@ -281,7 +291,7 @@ static void iwl4965_init_alive_start(struct iwl_priv *priv)
        }
 
        /* Calculate temperature */
-       priv->temperature = iwl4965_get_temperature(priv);
+       priv->temperature = iwl4965_hw_get_temperature(priv);
 
        /* Send pointers to protocol/runtime uCode image ... init code will
         * load and launch runtime uCode, which will send us another "Alive"
@@ -305,60 +315,6 @@ static int is_fat_channel(__le32 rxon_flags)
                (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
 }
 
-int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
-{
-       int idx = 0;
-
-       /* 4965 HT rate format */
-       if (rate_n_flags & RATE_MCS_HT_MSK) {
-               idx = (rate_n_flags & 0xff);
-
-               if (idx >= IWL_RATE_MIMO2_6M_PLCP)
-                       idx = idx - IWL_RATE_MIMO2_6M_PLCP;
-
-               idx += IWL_FIRST_OFDM_RATE;
-               /* skip 9M not supported in ht*/
-               if (idx >= IWL_RATE_9M_INDEX)
-                       idx += 1;
-               if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
-                       return idx;
-
-       /* 4965 legacy rate format, search for match in table */
-       } else {
-               for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
-                       if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
-                               return idx;
-       }
-
-       return -1;
-}
-
-/**
- * translate ucode response to mac80211 tx status control values
- */
-void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
-                                 struct ieee80211_tx_info *control)
-{
-       int rate_index;
-
-       control->antenna_sel_tx =
-               ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
-       if (rate_n_flags & RATE_MCS_HT_MSK)
-               control->flags |= IEEE80211_TX_CTL_OFDM_HT;
-       if (rate_n_flags & RATE_MCS_GF_MSK)
-               control->flags |= IEEE80211_TX_CTL_GREEN_FIELD;
-       if (rate_n_flags & RATE_MCS_FAT_MSK)
-               control->flags |= IEEE80211_TX_CTL_40_MHZ_WIDTH;
-       if (rate_n_flags & RATE_MCS_DUP_MSK)
-               control->flags |= IEEE80211_TX_CTL_DUP_DATA;
-       if (rate_n_flags & RATE_MCS_SGI_MSK)
-               control->flags |= IEEE80211_TX_CTL_SHORT_GI;
-       rate_index = iwl4965_hwrate_to_plcp_idx(rate_n_flags);
-       if (control->band == IEEE80211_BAND_5GHZ)
-               rate_index -= IWL_FIRST_OFDM_RATE;
-       control->tx_rate_idx = rate_index;
-}
-
 /*
  * EEPROM handlers
  */
@@ -384,39 +340,6 @@ err:
        return -EINVAL;
 
 }
-int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
-{
-       int ret;
-       unsigned long flags;
-
-       spin_lock_irqsave(&priv->lock, flags);
-       ret = iwl_grab_nic_access(priv);
-       if (ret) {
-               spin_unlock_irqrestore(&priv->lock, flags);
-               return ret;
-       }
-
-       if (src == IWL_PWR_SRC_VAUX) {
-               u32 val;
-               ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE,
-                                           &val);
-
-               if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) {
-                       iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
-                                              APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
-                                              ~APMG_PS_CTRL_MSK_PWR_SRC);
-               }
-       } else {
-               iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
-                                      APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
-                                      ~APMG_PS_CTRL_MSK_PWR_SRC);
-       }
-
-       iwl_release_nic_access(priv);
-       spin_unlock_irqrestore(&priv->lock, flags);
-
-       return ret;
-}
 
 /*
  * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
@@ -551,8 +474,8 @@ static void iwl4965_apm_stop(struct iwl_priv *priv)
        iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
 
        udelay(10);
-
-       iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
+       /* clear "init complete"  move adapter D0A* --> D0U state */
+       iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
        spin_unlock_irqrestore(&priv->lock, flags);
 }
 
@@ -606,54 +529,6 @@ out:
        return ret;
 }
 
-#define REG_RECALIB_PERIOD (60)
-
-/**
- * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
- *
- * This callback is provided in order to send a statistics request.
- *
- * This timer function is continually reset to execute within
- * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
- * was received.  We need to ensure we receive the statistics in order
- * to update the temperature used for calibrating the TXPOWER.
- */
-static void iwl4965_bg_statistics_periodic(unsigned long data)
-{
-       struct iwl_priv *priv = (struct iwl_priv *)data;
-
-       if (test_bit(STATUS_EXIT_PENDING, &priv->status))
-               return;
-
-       iwl_send_statistics_request(priv, CMD_ASYNC);
-}
-
-void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
-{
-       struct iwl4965_ct_kill_config cmd;
-       unsigned long flags;
-       int ret = 0;
-
-       spin_lock_irqsave(&priv->lock, flags);
-       iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
-                   CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
-       spin_unlock_irqrestore(&priv->lock, flags);
-
-       cmd.critical_temperature_R =
-               cpu_to_le32(priv->hw_params.ct_kill_threshold);
-
-       ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
-                              sizeof(cmd), &cmd);
-       if (ret)
-               IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
-       else
-               IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded, "
-                       "critical temperature is %d\n",
-                       cmd.critical_temperature_R);
-}
-
-#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
-
 /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
  * Called after every association, but this runs only once!
  *  ... once chain noise is calibrated the first time, it's good forever.  */
@@ -741,29 +616,17 @@ static void iwl4965_gain_computation(struct iwl_priv *priv,
        data->beacon_count = 0;
 }
 
-static void iwl4965_bg_sensitivity_work(struct work_struct *work)
+static void iwl4965_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
+                       __le32 *tx_flags)
 {
-       struct iwl_priv *priv = container_of(work, struct iwl_priv,
-                       sensitivity_work);
-
-       mutex_lock(&priv->mutex);
-
-       if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
-           test_bit(STATUS_SCANNING, &priv->status)) {
-               mutex_unlock(&priv->mutex);
-               return;
+       if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) {
+               *tx_flags |= TX_CMD_FLG_RTS_MSK;
+               *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
+       } else if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) {
+               *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
+               *tx_flags |= TX_CMD_FLG_CTS_MSK;
        }
-
-       if (priv->start_calib) {
-               iwl_chain_noise_calibration(priv, &priv->statistics);
-
-               iwl_sensitivity_calibration(priv, &priv->statistics);
-       }
-
-       mutex_unlock(&priv->mutex);
-       return;
 }
-#endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
 
 static void iwl4965_bg_txpower_work(struct work_struct *work)
 {
@@ -783,7 +646,7 @@ static void iwl4965_bg_txpower_work(struct work_struct *work)
        /* Regardless of if we are assocaited, we must reconfigure the
         * TX power since frames can be sent on non-radar channels while
         * not associated */
-       iwl4965_hw_reg_send_txpower(priv);
+       iwl4965_send_tx_power(priv);
 
        /* Update last_temperature to keep is_calib_needed from running
         * when it isn't needed... */
@@ -843,7 +706,7 @@ static const u16 default_queue_to_tx_fifo[] = {
        IWL_TX_FIFO_HCCA_2
 };
 
-int iwl4965_alive_notify(struct iwl_priv *priv)
+static int iwl4965_alive_notify(struct iwl_priv *priv)
 {
        u32 a;
        int i = 0;
@@ -920,7 +783,6 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
        return ret;
 }
 
-#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
 static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
        .min_nrg_cck = 97,
        .max_nrg_cck = 0,
@@ -943,14 +805,13 @@ static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
        .nrg_th_cck = 100,
        .nrg_th_ofdm = 100,
 };
-#endif
 
 /**
  * iwl4965_hw_set_hw_params
  *
  * Called when initializing driver
  */
-int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
+static int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
 {
 
        if ((priv->cfg->mod_params->num_of_queues > IWL49_NUM_QUEUES) ||
@@ -961,17 +822,9 @@ int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
        }
 
        priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
-       priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
-       priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
-       priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
-       if (priv->cfg->mod_params->amsdu_size_8K)
-               priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
-       else
-               priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
-       priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
+       priv->hw_params.first_ampdu_q = IWL49_FIRST_AMPDU_QUEUE;
        priv->hw_params.max_stations = IWL4965_STATION_COUNT;
        priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
-
        priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE;
        priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE;
        priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
@@ -983,30 +836,11 @@ int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
        priv->hw_params.valid_rx_ant = ANT_A | ANT_B;
        priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
 
-#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
        priv->hw_params.sens = &iwl4965_sensitivity;
-#endif
 
        return 0;
 }
 
-/* set card power command */
-static int iwl4965_set_power(struct iwl_priv *priv,
-                     void *cmd)
-{
-       int ret = 0;
-
-       ret = iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD,
-                                   sizeof(struct iwl4965_powertable_cmd),
-                                   cmd, NULL);
-       return ret;
-}
-int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
-{
-       IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n");
-       return -EINVAL;
-}
-
 static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res)
 {
        s32 sign = 1;
@@ -1056,20 +890,6 @@ static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
        return comp;
 }
 
-static const struct iwl_channel_info *
-iwl4965_get_channel_txpower_info(struct iwl_priv *priv,
-                                enum ieee80211_band band, u16 channel)
-{
-       const struct iwl_channel_info *ch_info;
-
-       ch_info = iwl_get_channel_info(priv, band, channel);
-
-       if (!is_channel_valid(ch_info))
-               return NULL;
-
-       return ch_info;
-}
-
 static s32 iwl4965_get_tx_atten_grp(u16 channel)
 {
        if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH &&
@@ -1146,7 +966,7 @@ static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
 
        s = iwl4965_get_sub_band(priv, channel);
        if (s >= EEPROM_TX_POWER_BANDS) {
-               IWL_ERROR("Tx Power can not find channel %d ", channel);
+               IWL_ERROR("Tx Power can not find channel %d\n", channel);
                return -1;
        }
 
@@ -1493,30 +1313,17 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
        s32 factory_actual_pwr[2];
        s32 power_index;
 
-       /* Sanity check requested level (dBm) */
-       if (priv->user_txpower_limit < IWL_TX_POWER_TARGET_POWER_MIN) {
-               IWL_WARNING("Requested user TXPOWER %d below limit.\n",
-                           priv->user_txpower_limit);
-               return -EINVAL;
-       }
-       if (priv->user_txpower_limit > IWL_TX_POWER_TARGET_POWER_MAX) {
-               IWL_WARNING("Requested user TXPOWER %d above limit.\n",
-                           priv->user_txpower_limit);
-               return -EINVAL;
-       }
-
        /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units
         *   are used for indexing into txpower table) */
-       user_target_power = 2 * priv->user_txpower_limit;
+       user_target_power = 2 * priv->tx_power_user_lmt;
 
        /* Get current (RXON) channel, band, width */
-       ch_info =
-               iwl4965_get_channel_txpower_info(priv, priv->band, channel);
-
        IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band,
                          is_fat);
 
-       if (!ch_info)
+       ch_info = iwl_get_channel_info(priv, priv->band, channel);
+
+       if (!is_channel_valid(ch_info))
                return -EINVAL;
 
        /* get txatten group, used to select 1) thermal txpower adjustment
@@ -1707,22 +1514,22 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
                                          c, atten_value, power_index,
                                        tx_power.s.radio_tx_gain[c],
                                        tx_power.s.dsp_predis_atten[c]);
-               }/* for each chain */
+               } /* for each chain */
 
                tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
 
-       }/* for each rate */
+       } /* for each rate */
 
        return 0;
 }
 
 /**
- * iwl4965_hw_reg_send_txpower - Configure the TXPOWER level user limit
+ * iwl4965_send_tx_power - Configure the TXPOWER level user limit
  *
  * Uses the active RXON for channel, band, and characteristics (fat, high)
- * The power limit is taken from priv->user_txpower_limit.
+ * The power limit is taken from priv->tx_power_user_lmt.
  */
-int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv)
+static int iwl4965_send_tx_power(struct iwl_priv *priv)
 {
        struct iwl4965_txpowertable_cmd cmd = { 0 };
        int ret;
@@ -1848,43 +1655,6 @@ static int iwl4965_shared_mem_rx_idx(struct iwl_priv *priv)
        return le32_to_cpu(s->rb_closed) & 0xFFF;
 }
 
-int iwl4965_hw_get_temperature(struct iwl_priv *priv)
-{
-       return priv->temperature;
-}
-
-unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
-                         struct iwl_frame *frame, u8 rate)
-{
-       struct iwl4965_tx_beacon_cmd *tx_beacon_cmd;
-       unsigned int frame_size;
-
-       tx_beacon_cmd = &frame->u.beacon;
-       memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
-
-       tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
-       tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
-
-       frame_size = iwl4965_fill_beacon_frame(priv,
-                               tx_beacon_cmd->frame,
-                               iwl_bcast_addr,
-                               sizeof(frame->u) - sizeof(*tx_beacon_cmd));
-
-       BUG_ON(frame_size > MAX_MPDU_SIZE);
-       tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
-
-       if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
-               tx_beacon_cmd->tx.rate_n_flags =
-                       iwl4965_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
-       else
-               tx_beacon_cmd->tx.rate_n_flags =
-                       iwl4965_hw_set_rate_n_flags(rate, 0);
-
-       tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
-                               TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK);
-       return (sizeof(*tx_beacon_cmd) + frame_size);
-}
-
 static int iwl4965_alloc_shared_mem(struct iwl_priv *priv)
 {
        priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
@@ -1950,12 +1720,12 @@ static s32 sign_extend(u32 oper, int index)
 }
 
 /**
- * iwl4965_get_temperature - return the calibrated temperature (in Kelvin)
+ * iwl4965_hw_get_temperature - return the calibrated temperature (in Kelvin)
  * @statistics: Provides the temperature reading from the uCode
  *
  * A return of <0 indicates bogus data in the statistics
  */
-int iwl4965_get_temperature(const struct iwl_priv *priv)
+static int iwl4965_hw_get_temperature(const struct iwl_priv *priv)
 {
        s32 temperature;
        s32 vt;
@@ -1990,8 +1760,7 @@ int iwl4965_get_temperature(const struct iwl_priv *priv)
                vt = sign_extend(
                        le32_to_cpu(priv->statistics.general.temperature), 23);
 
-       IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n",
-                      R1, R2, R3, vt);
+       IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt);
 
        if (R3 == R1) {
                IWL_ERROR("Calibration conflict R1 == R3\n");
@@ -2002,11 +1771,10 @@ int iwl4965_get_temperature(const struct iwl_priv *priv)
         * Add offset to center the adjustment around 0 degrees Centigrade. */
        temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
        temperature /= (R3 - R1);
-       temperature = (temperature * 97) / 100 +
-           TEMPERATURE_CALIB_KELVIN_OFFSET;
+       temperature = (temperature * 97) / 100 + TEMPERATURE_CALIB_KELVIN_OFFSET;
 
-       IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
-           KELVIN_TO_CELSIUS(temperature));
+       IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n",
+                       temperature, KELVIN_TO_CELSIUS(temperature));
 
        return temperature;
 }
@@ -2053,90 +1821,11 @@ static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
        return 1;
 }
 
-/* Calculate noise level, based on measurements during network silence just
- *   before arriving beacon.  This measurement can be done only if we know
- *   exactly when to expect beacons, therefore only when we're associated. */
-static void iwl4965_rx_calc_noise(struct iwl_priv *priv)
+static void iwl4965_temperature_calib(struct iwl_priv *priv)
 {
-       struct statistics_rx_non_phy *rx_info
-                               = &(priv->statistics.rx.general);
-       int num_active_rx = 0;
-       int total_silence = 0;
-       int bcn_silence_a =
-               le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
-       int bcn_silence_b =
-               le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
-       int bcn_silence_c =
-               le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
-
-       if (bcn_silence_a) {
-               total_silence += bcn_silence_a;
-               num_active_rx++;
-       }
-       if (bcn_silence_b) {
-               total_silence += bcn_silence_b;
-               num_active_rx++;
-       }
-       if (bcn_silence_c) {
-               total_silence += bcn_silence_c;
-               num_active_rx++;
-       }
-
-       /* Average among active antennas */
-       if (num_active_rx)
-               priv->last_rx_noise = (total_silence / num_active_rx) - 107;
-       else
-               priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
-
-       IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
-                       bcn_silence_a, bcn_silence_b, bcn_silence_c,
-                       priv->last_rx_noise);
-}
-
-void iwl4965_hw_rx_statistics(struct iwl_priv *priv,
-                             struct iwl_rx_mem_buffer *rxb)
-{
-       struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
-       int change;
        s32 temp;
 
-       IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n",
-                    (int)sizeof(priv->statistics), pkt->len);
-
-       change = ((priv->statistics.general.temperature !=
-                  pkt->u.stats.general.temperature) ||
-                 ((priv->statistics.flag &
-                   STATISTICS_REPLY_FLG_FAT_MODE_MSK) !=
-                  (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)));
-
-       memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
-
-       set_bit(STATUS_STATISTICS, &priv->status);
-
-       /* Reschedule the statistics timer to occur in
-        * REG_RECALIB_PERIOD seconds to ensure we get a
-        * thermal update even if the uCode doesn't give
-        * us one */
-       mod_timer(&priv->statistics_periodic, jiffies +
-                 msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
-
-       if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
-           (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
-               iwl4965_rx_calc_noise(priv);
-#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
-               queue_work(priv->workqueue, &priv->sensitivity_work);
-#endif
-       }
-
-       iwl_leds_background(priv);
-
-       /* If the hardware hasn't reported a change in
-        * temperature then don't bother computing a
-        * calibrated temperature value */
-       if (!change)
-               return;
-
-       temp = iwl4965_get_temperature(priv);
+       temp = iwl4965_hw_get_temperature(priv);
        if (temp < 0)
                return;
 
@@ -2155,780 +1844,12 @@ void iwl4965_hw_rx_statistics(struct iwl_priv *priv,
        priv->temperature = temp;
        set_bit(STATUS_TEMPERATURE, &priv->status);
 
-       if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
-                    iwl4965_is_temp_calib_needed(priv))
+       if (!priv->disable_tx_power_cal &&
+            unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
+            iwl4965_is_temp_calib_needed(priv))
                queue_work(priv->workqueue, &priv->txpower_work);
 }
 
-static void iwl4965_add_radiotap(struct iwl_priv *priv,
-                                struct sk_buff *skb,
-                                struct iwl4965_rx_phy_res *rx_start,
-                                struct ieee80211_rx_status *stats,
-                                u32 ampdu_status)
-{
-       s8 signal = stats->signal;
-       s8 noise = 0;
-       int rate = stats->rate_idx;
-       u64 tsf = stats->mactime;
-       __le16 antenna;
-       __le16 phy_flags_hw = rx_start->phy_flags;
-       struct iwl4965_rt_rx_hdr {
-               struct ieee80211_radiotap_header rt_hdr;
-               __le64 rt_tsf;          /* TSF */
-               u8 rt_flags;            /* radiotap packet flags */
-               u8 rt_rate;             /* rate in 500kb/s */
-               __le16 rt_channelMHz;   /* channel in MHz */
-               __le16 rt_chbitmask;    /* channel bitfield */
-               s8 rt_dbmsignal;        /* signal in dBm, kluged to signed */
-               s8 rt_dbmnoise;
-               u8 rt_antenna;          /* antenna number */
-       } __attribute__ ((packed)) *iwl4965_rt;
-
-       /* TODO: We won't have enough headroom for HT frames. Fix it later. */
-       if (skb_headroom(skb) < sizeof(*iwl4965_rt)) {
-               if (net_ratelimit())
-                       printk(KERN_ERR "not enough headroom [%d] for "
-                              "radiotap head [%zd]\n",
-                              skb_headroom(skb), sizeof(*iwl4965_rt));
-               return;
-       }
-
-       /* put radiotap header in front of 802.11 header and data */
-       iwl4965_rt = (void *)skb_push(skb, sizeof(*iwl4965_rt));
-
-       /* initialise radiotap header */
-       iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
-       iwl4965_rt->rt_hdr.it_pad = 0;
-
-       /* total header + data */
-       put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt)),
-                     &iwl4965_rt->rt_hdr.it_len);
-
-       /* Indicate all the fields we add to the radiotap header */
-       put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
-                                 (1 << IEEE80211_RADIOTAP_FLAGS) |
-                                 (1 << IEEE80211_RADIOTAP_RATE) |
-                                 (1 << IEEE80211_RADIOTAP_CHANNEL) |
-                                 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
-                                 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
-                                 (1 << IEEE80211_RADIOTAP_ANTENNA)),
-                     &iwl4965_rt->rt_hdr.it_present);
-
-       /* Zero the flags, we'll add to them as we go */
-       iwl4965_rt->rt_flags = 0;
-
-       put_unaligned(cpu_to_le64(tsf), &iwl4965_rt->rt_tsf);
-
-       iwl4965_rt->rt_dbmsignal = signal;
-       iwl4965_rt->rt_dbmnoise = noise;
-
-       /* Convert the channel frequency and set the flags */
-       put_unaligned(cpu_to_le16(stats->freq), &iwl4965_rt->rt_channelMHz);
-       if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
-               put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
-                                         IEEE80211_CHAN_5GHZ),
-                             &iwl4965_rt->rt_chbitmask);
-       else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
-               put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK |
-                                         IEEE80211_CHAN_2GHZ),
-                             &iwl4965_rt->rt_chbitmask);
-       else    /* 802.11g */
-               put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
-                                         IEEE80211_CHAN_2GHZ),
-                             &iwl4965_rt->rt_chbitmask);
-
-       if (rate == -1)
-               iwl4965_rt->rt_rate = 0;
-       else
-               iwl4965_rt->rt_rate = iwl_rates[rate].ieee;
-
-       /*
-        * "antenna number"
-        *
-        * It seems that the antenna field in the phy flags value
-        * is actually a bitfield. This is undefined by radiotap,
-        * it wants an actual antenna number but I always get "7"
-        * for most legacy frames I receive indicating that the
-        * same frame was received on all three RX chains.
-        *
-        * I think this field should be removed in favour of a
-        * new 802.11n radiotap field "RX chains" that is defined
-        * as a bitmask.
-        */
-       antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK;
-       iwl4965_rt->rt_antenna = le16_to_cpu(antenna) >> 4;
-
-       /* set the preamble flag if appropriate */
-       if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
-               iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
-
-       stats->flag |= RX_FLAG_RADIOTAP;
-}
-
-static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len)
-{
-       /* 0 - mgmt, 1 - cnt, 2 - data */
-       int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
-       priv->rx_stats[idx].cnt++;
-       priv->rx_stats[idx].bytes += len;
-}
-
-/*
- * returns non-zero if packet should be dropped
- */
-static int iwl4965_set_decrypted_flag(struct iwl_priv *priv,
-                                     struct ieee80211_hdr *hdr,
-                                     u32 decrypt_res,
-                                     struct ieee80211_rx_status *stats)
-{
-       u16 fc = le16_to_cpu(hdr->frame_control);
-
-       if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
-               return 0;
-
-       if (!(fc & IEEE80211_FCTL_PROTECTED))
-               return 0;
-
-       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;
-
-       case RX_RES_STATUS_SEC_TYPE_WEP:
-               if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
-                   RX_RES_STATUS_BAD_ICV_MIC) {
-                       /* bad ICV, the packet is destroyed since the
-                        * decryption is inplace, drop it */
-                       IWL_DEBUG_RX("Packet destroyed\n");
-                       return -1;
-               }
-       case RX_RES_STATUS_SEC_TYPE_CCMP:
-               if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
-                   RX_RES_STATUS_DECRYPT_OK) {
-                       IWL_DEBUG_RX("hw decrypt successfully!!!\n");
-                       stats->flag |= RX_FLAG_DECRYPTED;
-               }
-               break;
-
-       default:
-               break;
-       }
-       return 0;
-}
-
-static u32 iwl4965_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
-{
-       u32 decrypt_out = 0;
-
-       if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
-                                       RX_RES_STATUS_STATION_FOUND)
-               decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
-                               RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
-
-       decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
-
-       /* packet was not encrypted */
-       if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
-                                       RX_RES_STATUS_SEC_TYPE_NONE)
-               return decrypt_out;
-
-       /* packet was encrypted with unknown alg */
-       if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
-                                       RX_RES_STATUS_SEC_TYPE_ERR)
-               return decrypt_out;
-
-       /* decryption was not done in HW */
-       if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
-                                       RX_MPDU_RES_STATUS_DEC_DONE_MSK)
-               return decrypt_out;
-
-       switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
-
-       case RX_RES_STATUS_SEC_TYPE_CCMP:
-               /* alg is CCM: check MIC only */
-               if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
-                       /* Bad MIC */
-                       decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
-               else
-                       decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
-
-               break;
-
-       case RX_RES_STATUS_SEC_TYPE_TKIP:
-               if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
-                       /* Bad TTAK */
-                       decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
-                       break;
-               }
-               /* fall through if TTAK OK */
-       default:
-               if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
-                       decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
-               else
-                       decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
-               break;
-       };
-
-       IWL_DEBUG_RX("decrypt_in:0x%x  decrypt_out = 0x%x\n",
-                                       decrypt_in, decrypt_out);
-
-       return decrypt_out;
-}
-
-static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
-                                      int include_phy,
-                                      struct iwl_rx_mem_buffer *rxb,
-                                      struct ieee80211_rx_status *stats)
-{
-       struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
-       struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
-           (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL;
-       struct ieee80211_hdr *hdr;
-       u16 len;
-       __le32 *rx_end;
-       unsigned int skblen;
-       u32 ampdu_status;
-       u32 ampdu_status_legacy;
-
-       if (!include_phy && priv->last_phy_res[0])
-               rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
-
-       if (!rx_start) {
-               IWL_ERROR("MPDU frame without a PHY data\n");
-               return;
-       }
-       if (include_phy) {
-               hdr = (struct ieee80211_hdr *)((u8 *) & rx_start[1] +
-                                              rx_start->cfg_phy_cnt);
-
-               len = le16_to_cpu(rx_start->byte_count);
-
-               rx_end = (__le32 *) ((u8 *) & pkt->u.raw[0] +
-                                 sizeof(struct iwl4965_rx_phy_res) +
-                                 rx_start->cfg_phy_cnt + len);
-
-       } else {
-               struct iwl4965_rx_mpdu_res_start *amsdu =
-                   (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
-
-               hdr = (struct ieee80211_hdr *)(pkt->u.raw +
-                              sizeof(struct iwl4965_rx_mpdu_res_start));
-               len =  le16_to_cpu(amsdu->byte_count);
-               rx_start->byte_count = amsdu->byte_count;
-               rx_end = (__le32 *) (((u8 *) hdr) + len);
-       }
-       /* In monitor mode allow 802.11 ACk frames (10 bytes) */
-       if (len > priv->hw_params.max_pkt_size ||
-           len < ((priv->iw_mode == IEEE80211_IF_TYPE_MNTR) ? 10 : 16)) {
-               IWL_WARNING("byte count out of range [16,4K] : %d\n", len);
-               return;
-       }
-
-       ampdu_status = le32_to_cpu(*rx_end);
-       skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32);
-
-       if (!include_phy) {
-               /* New status scheme, need to translate */
-               ampdu_status_legacy = ampdu_status;
-               ampdu_status = iwl4965_translate_rx_status(priv, ampdu_status);
-       }
-
-       /* start from MAC */
-       skb_reserve(rxb->skb, (void *)hdr - (void *)pkt);
-       skb_put(rxb->skb, len); /* end where data ends */
-
-       /* We only process data packets if the interface is open */
-       if (unlikely(!priv->is_open)) {
-               IWL_DEBUG_DROP_LIMIT
-                   ("Dropping packet while interface is not open.\n");
-               return;
-       }
-
-       stats->flag = 0;
-       hdr = (struct ieee80211_hdr *)rxb->skb->data;
-
-       /*  in case of HW accelerated crypto and bad decryption, drop */
-       if (!priv->hw_params.sw_crypto &&
-           iwl4965_set_decrypted_flag(priv, hdr, ampdu_status, stats))
-               return;
-
-       if (priv->add_radiotap)
-               iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status);
-
-       iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len);
-       ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
-       priv->alloc_rxb_skb--;
-       rxb->skb = NULL;
-}
-
-/* Calc max signal level (dBm) among 3 possible receivers */
-static int iwl4965_calc_rssi(struct iwl_priv *priv,
-                            struct iwl4965_rx_phy_res *rx_resp)
-{
-       /* data from PHY/DSP regarding signal strength, etc.,
-        *   contents are always there, not configurable by host.  */
-       struct iwl4965_rx_non_cfg_phy *ncphy =
-           (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy;
-       u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL_AGC_DB_MASK)
-                       >> IWL_AGC_DB_POS;
-
-       u32 valid_antennae =
-           (le16_to_cpu(rx_resp->phy_flags) & RX_PHY_FLAGS_ANTENNAE_MASK)
-                       >> RX_PHY_FLAGS_ANTENNAE_OFFSET;
-       u8 max_rssi = 0;
-       u32 i;
-
-       /* Find max rssi among 3 possible receivers.
-        * These values are measured by the digital signal processor (DSP).
-        * They should stay fairly constant even as the signal strength varies,
-        *   if the radio's automatic gain control (AGC) is working right.
-        * AGC value (see below) will provide the "interesting" info. */
-       for (i = 0; i < 3; i++)
-               if (valid_antennae & (1 << i))
-                       max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
-
-       IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
-               ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
-               max_rssi, agc);
-
-       /* dBm = max_rssi dB - agc dB - constant.
-        * Higher AGC (higher radio gain) means lower signal. */
-       return (max_rssi - agc - IWL_RSSI_OFFSET);
-}
-
-static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&priv->sta_lock, flags);
-       priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
-       priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
-       priv->stations[sta_id].sta.sta.modify_mask = 0;
-       priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
-
-       iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
-}
-
-static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
-{
-       /* FIXME: need locking over ps_status ??? */
-       u8 sta_id = iwl_find_station(priv, addr);
-
-       if (sta_id != IWL_INVALID_STATION) {
-               u8 sta_awake = priv->stations[sta_id].
-                               ps_status == STA_PS_STATUS_WAKE;
-
-               if (sta_awake && ps_bit)
-                       priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
-               else if (!sta_awake && !ps_bit) {
-                       iwl4965_sta_modify_ps_wake(priv, sta_id);
-                       priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
-               }
-       }
-}
-#ifdef CONFIG_IWLWIFI_DEBUG
-
-/**
- * iwl4965_dbg_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.
- */
-static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
-                     struct iwl_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);
-
-       if (likely(!(priv->debug_level & IWL_DL_RX)))
-               return;
-
-       /* 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;
-               int rate_idx;
-               u32 bitrate;
-
-               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_idx = iwl4965_hwrate_to_plcp_idx(rate_sym);
-               if (unlikely(rate_idx == -1))
-                       bitrate = 0;
-               else
-                       bitrate = iwl_rates[rate_idx].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, bitrate);
-               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)
-               iwl_print_hex_dump(priv, IWL_DL_RX, data, length);
-}
-#else
-static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
-                                           struct iwl_rx_packet *pkt,
-                                           struct ieee80211_hdr *header,
-                                           int group100)
-{
-}
-#endif
-
-
-
-/* Called for REPLY_RX (legacy ABG frames), or
- * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
-void iwl4965_rx_reply_rx(struct iwl_priv *priv,
-                               struct iwl_rx_mem_buffer *rxb)
-{
-       struct ieee80211_hdr *header;
-       struct ieee80211_rx_status rx_status;
-       struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
-       /* Use phy data (Rx signal strength, etc.) contained within
-        *   this rx packet for legacy frames,
-        *   or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
-       int include_phy = (pkt->hdr.cmd == REPLY_RX);
-       struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
-               (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) :
-               (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
-       __le32 *rx_end;
-       unsigned int len = 0;
-       u16 fc;
-       u8 network_packet;
-
-       rx_status.mactime = le64_to_cpu(rx_start->timestamp);
-       rx_status.freq =
-               ieee80211_channel_to_frequency(le16_to_cpu(rx_start->channel));
-       rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
-                               IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
-       rx_status.rate_idx =
-               iwl4965_hwrate_to_plcp_idx(le32_to_cpu(rx_start->rate_n_flags));
-       if (rx_status.band == IEEE80211_BAND_5GHZ)
-               rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
-
-       rx_status.antenna = 0;
-       rx_status.flag = 0;
-
-       if ((unlikely(rx_start->cfg_phy_cnt > 20))) {
-               IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n",
-                               rx_start->cfg_phy_cnt);
-               return;
-       }
-
-       if (!include_phy) {
-               if (priv->last_phy_res[0])
-                       rx_start = (struct iwl4965_rx_phy_res *)
-                               &priv->last_phy_res[1];
-               else
-                       rx_start = NULL;
-       }
-
-       if (!rx_start) {
-               IWL_ERROR("MPDU frame without a PHY data\n");
-               return;
-       }
-
-       if (include_phy) {
-               header = (struct ieee80211_hdr *)((u8 *) & rx_start[1]
-                                                 + rx_start->cfg_phy_cnt);
-
-               len = le16_to_cpu(rx_start->byte_count);
-               rx_end = (__le32 *)(pkt->u.raw + rx_start->cfg_phy_cnt +
-                                 sizeof(struct iwl4965_rx_phy_res) + len);
-       } else {
-               struct iwl4965_rx_mpdu_res_start *amsdu =
-                       (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
-
-               header = (void *)(pkt->u.raw +
-                       sizeof(struct iwl4965_rx_mpdu_res_start));
-               len = le16_to_cpu(amsdu->byte_count);
-               rx_end = (__le32 *) (pkt->u.raw +
-                       sizeof(struct iwl4965_rx_mpdu_res_start) + len);
-       }
-
-       if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) ||
-           !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
-               IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n",
-                               le32_to_cpu(*rx_end));
-               return;
-       }
-
-       priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
-
-       /* Find max signal strength (dBm) among 3 antenna/receiver chains */
-       rx_status.signal = iwl4965_calc_rssi(priv, rx_start);
-
-       /* Meaningful noise values are available only from beacon statistics,
-        *   which are gathered only when associated, and indicate noise
-        *   only for the associated network channel ...
-        * Ignore these noise values while scanning (other channels) */
-       if (iwl_is_associated(priv) &&
-           !test_bit(STATUS_SCANNING, &priv->status)) {
-               rx_status.noise = priv->last_rx_noise;
-               rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal,
-                                                        rx_status.noise);
-       } else {
-               rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
-               rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal, 0);
-       }
-
-       /* Reset beacon noise level if not associated. */
-       if (!iwl_is_associated(priv))
-               priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
-
-       /* Set "1" to report good data frames in groups of 100 */
-       /* FIXME: need to optimze the call: */
-       iwl4965_dbg_report_frame(priv, pkt, header, 1);
-
-       IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n",
-                             rx_status.signal, rx_status.noise, rx_status.signal,
-                             (unsigned long long)rx_status.mactime);
-
-
-       if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
-               iwl4965_handle_data_packet(priv, 1, include_phy,
-                                                rxb, &rx_status);
-               return;
-       }
-
-       network_packet = iwl4965_is_network_packet(priv, header);
-       if (network_packet) {
-               priv->last_rx_rssi = rx_status.signal;
-               priv->last_beacon_time =  priv->ucode_beacon_time;
-               priv->last_tsf = le64_to_cpu(rx_start->timestamp);
-       }
-
-       fc = le16_to_cpu(header->frame_control);
-       switch (fc & IEEE80211_FCTL_FTYPE) {
-       case IEEE80211_FTYPE_MGMT:
-               if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
-                       iwl4965_update_ps_mode(priv, fc  & IEEE80211_FCTL_PM,
-                                               header->addr2);
-               iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &rx_status);
-               break;
-
-       case IEEE80211_FTYPE_CTL:
-               switch (fc & IEEE80211_FCTL_STYPE) {
-               case IEEE80211_STYPE_BACK_REQ:
-                       IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n");
-                       iwl4965_handle_data_packet(priv, 0, include_phy,
-                                               rxb, &rx_status);
-                       break;
-               default:
-                       break;
-               }
-               break;
-
-       case IEEE80211_FTYPE_DATA: {
-               DECLARE_MAC_BUF(mac1);
-               DECLARE_MAC_BUF(mac2);
-               DECLARE_MAC_BUF(mac3);
-
-               if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
-                       iwl4965_update_ps_mode(priv, fc  & IEEE80211_FCTL_PM,
-                                               header->addr2);
-
-               if (unlikely(!network_packet))
-                       IWL_DEBUG_DROP("Dropping (non network): "
-                                      "%s, %s, %s\n",
-                                      print_mac(mac1, header->addr1),
-                                      print_mac(mac2, header->addr2),
-                                      print_mac(mac3, header->addr3));
-               else if (unlikely(iwl4965_is_duplicate_packet(priv, header)))
-                       IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n",
-                                      print_mac(mac1, header->addr1),
-                                      print_mac(mac2, header->addr2),
-                                      print_mac(mac3, header->addr3));
-               else
-                       iwl4965_handle_data_packet(priv, 1, include_phy, rxb,
-                                                  &rx_status);
-               break;
-       }
-       default:
-               break;
-
-       }
-}
-
-/**
- * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack
- *
- * Go through block-ack's bitmap of ACK'd frames, update driver's record of
- * ACK vs. not.  This gets sent to mac80211, then to rate scaling algo.
- */
-static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
-                                                struct iwl_ht_agg *agg,
-                                                struct iwl4965_compressed_ba_resp*
-                                                ba_resp)
-
-{
-       int i, sh, ack;
-       u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
-       u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
-       u64 bitmap;
-       int successes = 0;
-       struct ieee80211_tx_info *info;
-
-       if (unlikely(!agg->wait_for_ba))  {
-               IWL_ERROR("Received BA when not expected\n");
-               return -EINVAL;
-       }
-
-       /* Mark that the expected block-ack response arrived */
-       agg->wait_for_ba = 0;
-       IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
-
-       /* Calculate shift to align block-ack bits with our Tx window bits */
-       sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl>>4);
-       if (sh < 0) /* tbw something is wrong with indices */
-               sh += 0x100;
-
-       /* don't use 64-bit values for now */
-       bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
-
-       if (agg->frame_count > (64 - sh)) {
-               IWL_DEBUG_TX_REPLY("more frames than bitmap size");
-               return -1;
-       }
-
-       /* check for success or failure according to the
-        * transmitted bitmap and block-ack bitmap */
-       bitmap &= agg->bitmap;
-
-       /* For each frame attempted in aggregation,
-        * update driver's record of tx frame's status. */
-       for (i = 0; i < agg->frame_count ; i++) {
-               ack = bitmap & (1 << i);
-               successes += !!ack;
-               IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
-                       ack? "ACK":"NACK", i, (agg->start_idx + i) & 0xff,
-                       agg->start_idx + i);
-       }
-
-       info = IEEE80211_SKB_CB(priv->txq[scd_flow].txb[agg->start_idx].skb[0]);
-       memset(&info->status, 0, sizeof(info->status));
-       info->flags = IEEE80211_TX_STAT_ACK;
-       info->flags |= IEEE80211_TX_STAT_AMPDU;
-       info->status.ampdu_ack_map = successes;
-       info->status.ampdu_ack_len = agg->frame_count;
-       iwl4965_hwrate_to_tx_control(priv, agg->rate_n_flags, info);
-
-       IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
-
-       return 0;
-}
-
 /**
  * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
  */
@@ -2944,7 +1865,7 @@ static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
 }
 
 /**
- * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID
+ * txq_id must be greater than IWL49_FIRST_AMPDU_QUEUE
  * priv->lock must be held by the caller
  */
 static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
@@ -2952,9 +1873,11 @@ static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
 {
        int ret = 0;
 
-       if (IWL_BACK_QUEUE_FIRST_ID > txq_id) {
-               IWL_WARNING("queue number too small: %d, must be > %d\n",
-                               txq_id, IWL_BACK_QUEUE_FIRST_ID);
+       if ((IWL49_FIRST_AMPDU_QUEUE > txq_id) ||
+           (IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES <= txq_id)) {
+               IWL_WARNING("queue number out of range: %d, must be %d to %d\n",
+                       txq_id, IWL49_FIRST_AMPDU_QUEUE,
+                       IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES - 1);
                return -EINVAL;
        }
 
@@ -2980,82 +1903,6 @@ static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
        return 0;
 }
 
-
-/**
- * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
- *
- * Handles block-acknowledge notification from device, which reports success
- * of frames sent via aggregation.
- */
-static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
-                                          struct iwl_rx_mem_buffer *rxb)
-{
-       struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
-       struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
-       int index;
-       struct iwl_tx_queue *txq = NULL;
-       struct iwl_ht_agg *agg;
-       DECLARE_MAC_BUF(mac);
-
-       /* "flow" corresponds to Tx queue */
-       u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
-
-       /* "ssn" is start of block-ack Tx window, corresponds to index
-        * (in Tx queue's circular buffer) of first TFD/frame in window */
-       u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
-
-       if (scd_flow >= priv->hw_params.max_txq_num) {
-               IWL_ERROR("BUG_ON scd_flow is bigger than number of queues");
-               return;
-       }
-
-       txq = &priv->txq[scd_flow];
-       agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg;
-
-       /* Find index just before block-ack window */
-       index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
-
-       /* TODO: Need to get this copy more safely - now good for debug */
-
-       IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, "
-                          "sta_id = %d\n",
-                          agg->wait_for_ba,
-                          print_mac(mac, (u8*) &ba_resp->sta_addr_lo32),
-                          ba_resp->sta_id);
-       IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
-                          "%d, scd_ssn = %d\n",
-                          ba_resp->tid,
-                          ba_resp->seq_ctl,
-                          (unsigned long long)le64_to_cpu(ba_resp->bitmap),
-                          ba_resp->scd_flow,
-                          ba_resp->scd_ssn);
-       IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n",
-                          agg->start_idx,
-                          (unsigned long long)agg->bitmap);
-
-       /* Update driver's record of ACK vs. not for each frame in window */
-       iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp);
-
-       /* Release all TFDs before the SSN, i.e. all TFDs in front of
-        * block-ack window (we assume that they've been successfully
-        * transmitted ... if not, it's too late anyway). */
-       if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
-               /* calculate mac80211 ampdu sw queue to wake */
-               int ampdu_q =
-                  scd_flow - IWL_BACK_QUEUE_FIRST_ID + priv->hw->queues;
-               int freed = iwl_tx_queue_reclaim(priv, scd_flow, index);
-               priv->stations[ba_resp->sta_id].
-                       tid[ba_resp->tid].tfds_in_queue -= freed;
-               if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
-                       priv->mac80211_registered &&
-                       agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
-                       ieee80211_wake_queue(priv->hw, ampdu_q);
-
-               iwl_txq_check_empty(priv, ba_resp->sta_id,
-                                   ba_resp->tid, scd_flow);
-       }
-}
-
 /**
  * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
  */
@@ -3087,7 +1934,7 @@ static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
 /**
  * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
  *
- * NOTE:  txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID,
+ * NOTE:  txq_id must be greater than IWL49_FIRST_AMPDU_QUEUE,
  *        i.e. it must be one of the higher queues used for aggregation
  */
 static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id,
@@ -3097,9 +1944,13 @@ static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id,
        int ret;
        u16 ra_tid;
 
-       if (IWL_BACK_QUEUE_FIRST_ID > txq_id)
-               IWL_WARNING("queue number too small: %d, must be > %d\n",
-                       txq_id, IWL_BACK_QUEUE_FIRST_ID);
+       if ((IWL49_FIRST_AMPDU_QUEUE > txq_id) ||
+           (IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES <= txq_id)) {
+               IWL_WARNING("queue number out of range: %d, must be %d to %d\n",
+                       txq_id, IWL49_FIRST_AMPDU_QUEUE,
+                       IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES - 1);
+               return -EINVAL;
+       }
 
        ra_tid = BUILD_RAxTID(sta_id, tid);
 
@@ -3150,79 +2001,6 @@ static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id,
        return 0;
 }
 
-static int iwl4965_rx_agg_start(struct iwl_priv *priv,
-                               const u8 *addr, int tid, u16 ssn)
-{
-       unsigned long flags;
-       int sta_id;
-
-       sta_id = iwl_find_station(priv, addr);
-       if (sta_id == IWL_INVALID_STATION)
-               return -ENXIO;
-
-       spin_lock_irqsave(&priv->sta_lock, flags);
-       priv->stations[sta_id].sta.station_flags_msk = 0;
-       priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
-       priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
-       priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
-       priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
-
-       return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
-                                       CMD_ASYNC);
-}
-
-static int iwl4965_rx_agg_stop(struct iwl_priv *priv,
-                              const u8 *addr, int tid)
-{
-       unsigned long flags;
-       int sta_id;
-
-       sta_id = iwl_find_station(priv, addr);
-       if (sta_id == IWL_INVALID_STATION)
-               return -ENXIO;
-
-       spin_lock_irqsave(&priv->sta_lock, flags);
-       priv->stations[sta_id].sta.station_flags_msk = 0;
-       priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
-       priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
-       priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
-
-       return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
-                                       CMD_ASYNC);
-}
-
-int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
-                            enum ieee80211_ampdu_mlme_action action,
-                            const u8 *addr, u16 tid, u16 *ssn)
-{
-       struct iwl_priv *priv = hw->priv;
-       DECLARE_MAC_BUF(mac);
-
-       IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n",
-                    print_mac(mac, addr), tid);
-
-       switch (action) {
-       case IEEE80211_AMPDU_RX_START:
-               IWL_DEBUG_HT("start Rx\n");
-               return iwl4965_rx_agg_start(priv, addr, tid, *ssn);
-       case IEEE80211_AMPDU_RX_STOP:
-               IWL_DEBUG_HT("stop Rx\n");
-               return iwl4965_rx_agg_stop(priv, addr, tid);
-       case IEEE80211_AMPDU_TX_START:
-               IWL_DEBUG_HT("start Tx\n");
-               return iwl_tx_agg_start(priv, addr, tid, ssn);
-       case IEEE80211_AMPDU_TX_STOP:
-               IWL_DEBUG_HT("stop Tx\n");
-               return iwl_tx_agg_stop(priv, addr, tid);
-       default:
-               IWL_DEBUG_HT("unknown\n");
-               return -EINVAL;
-               break;
-       }
-       return 0;
-}
 
 static u16 iwl4965_get_hcmd_size(u8 cmd_id, u16 len)
 {
@@ -3254,10 +2032,7 @@ static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
 
 static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
 {
-       __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
-                               tx_resp->frame_count);
-       return le32_to_cpu(*scd_ssn) & MAX_SN;
-
+       return le32_to_cpup(&tx_resp->u.status + tx_resp->frame_count) & MAX_SN;
 }
 
 /**
@@ -3265,32 +2040,29 @@ static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
  */
 static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
                                      struct iwl_ht_agg *agg,
-                                     struct iwl4965_tx_resp_agg *tx_resp,
-                                     u16 start_idx)
+                                     struct iwl4965_tx_resp *tx_resp,
+                                     int txq_id, u16 start_idx)
 {
        u16 status;
-       struct agg_tx_status *frame_status = &tx_resp->status;
+       struct agg_tx_status *frame_status = tx_resp->u.agg_status;
        struct ieee80211_tx_info *info = NULL;
        struct ieee80211_hdr *hdr = NULL;
-       int i, sh;
-       int txq_id, idx;
+       u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
+       int i, sh, idx;
        u16 seq;
-
        if (agg->wait_for_ba)
                IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
 
        agg->frame_count = tx_resp->frame_count;
        agg->start_idx = start_idx;
-       agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
+       agg->rate_n_flags = rate_n_flags;
        agg->bitmap = 0;
 
        /* # frames attempted by Tx command */
        if (agg->frame_count == 1) {
                /* Only one frame was attempted; no block-ack will arrive */
                status = le16_to_cpu(frame_status[0].status);
-               seq  = le16_to_cpu(frame_status[0].sequence);
-               idx = SEQ_TO_INDEX(seq);
-               txq_id = SEQ_TO_QUEUE(seq);
+               idx = start_idx;
 
                /* FIXME: code repetition */
                IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
@@ -3301,15 +2073,12 @@ static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
                info->flags &= ~IEEE80211_TX_CTL_AMPDU;
                info->flags |= iwl_is_tx_success(status)?
                        IEEE80211_TX_STAT_ACK : 0;
-               iwl4965_hwrate_to_tx_control(priv,
-                                            le32_to_cpu(tx_resp->rate_n_flags),
-                                            info);
+               iwl_hwrate_to_tx_control(priv, rate_n_flags, info);
                /* FIXME: code repetition end */
 
                IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
                                    status & 0xff, tx_resp->failure_frame);
-               IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
-                       iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
+               IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags);
 
                agg->wait_for_ba = 0;
        } else {
@@ -3360,14 +2129,13 @@ static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
                                bitmap = bitmap << sh;
                                sh = 0;
                        }
-                       bitmap |= (1 << sh);
-                       IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
-                                          start, (u32)(bitmap & 0xFFFFFFFF));
+                       bitmap |= 1ULL << sh;
+                       IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%llx\n",
+                                          start, (unsigned long long)bitmap);
                }
 
                agg->bitmap = bitmap;
                agg->start_idx = start;
-               agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
                IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
                                   agg->frame_count, agg->start_idx,
                                   (unsigned long long)agg->bitmap);
@@ -3391,9 +2159,9 @@ static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
        struct iwl_tx_queue *txq = &priv->txq[txq_id];
        struct ieee80211_tx_info *info;
        struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
-       u32  status = le32_to_cpu(tx_resp->status);
+       u32  status = le32_to_cpu(tx_resp->u.status);
        int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
-       u16 fc;
+       __le16 fc;
        struct ieee80211_hdr *hdr;
        u8 *qc = NULL;
 
@@ -3409,9 +2177,9 @@ static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
        memset(&info->status, 0, sizeof(info->status));
 
        hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
-       fc = le16_to_cpu(hdr->frame_control);
-       if (ieee80211_is_qos_data(fc)) {
-               qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
+       fc = hdr->frame_control;
+       if (ieee80211_is_data_qos(fc)) {
+               qc = ieee80211_get_qos_ctl(hdr);
                tid = qc[0] & 0xf;
        }
 
@@ -3430,12 +2198,11 @@ static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
 
                agg = &priv->stations[sta_id].tid[tid].agg;
 
-               iwl4965_tx_status_reply_tx(priv, agg,
-                               (struct iwl4965_tx_resp_agg *)tx_resp, index);
+               iwl4965_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
 
-               if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status)) {
-                       /* TODO: send BAR */
-               }
+               /* check if BAR is needed */
+               if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status))
+                       info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
 
                if (txq->q.read_ptr != (scd_ssn & 0xff)) {
                        int freed, ampdu_q;
@@ -3449,7 +2216,7 @@ static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
                            txq_id >= 0 && priv->mac80211_registered &&
                            agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
                                /* calculate mac80211 ampdu sw queue to wake */
-                               ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID +
+                               ampdu_q = txq_id - IWL49_FIRST_AMPDU_QUEUE +
                                          priv->hw->queues;
                                if (agg->state == IWL_AGG_OFF)
                                        ieee80211_wake_queue(priv->hw, txq_id);
@@ -3462,7 +2229,7 @@ static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
                info->status.retry_count = tx_resp->failure_frame;
                info->flags |=
                        iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
-               iwl4965_hwrate_to_tx_control(priv,
+               iwl_hwrate_to_tx_control(priv,
                                        le32_to_cpu(tx_resp->rate_n_flags),
                                        info);
 
@@ -3473,6 +2240,7 @@ static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
                                tx_resp->failure_frame);
 
                IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
+
                if (index != -1) {
                    int freed = iwl_tx_queue_reclaim(priv, txq_id, index);
                    if (tid != MAX_TID_COUNT)
@@ -3489,34 +2257,58 @@ static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
                IWL_ERROR("TODO:  Implement Tx ABORT REQUIRED!!!\n");
 }
 
+static int iwl4965_calc_rssi(struct iwl_priv *priv,
+                            struct iwl_rx_phy_res *rx_resp)
+{
+       /* data from PHY/DSP regarding signal strength, etc.,
+        *   contents are always there, not configurable by host.  */
+       struct iwl4965_rx_non_cfg_phy *ncphy =
+           (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
+       u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL49_AGC_DB_MASK)
+                       >> IWL49_AGC_DB_POS;
+
+       u32 valid_antennae =
+           (le16_to_cpu(rx_resp->phy_flags) & IWL49_RX_PHY_FLAGS_ANTENNAE_MASK)
+                       >> IWL49_RX_PHY_FLAGS_ANTENNAE_OFFSET;
+       u8 max_rssi = 0;
+       u32 i;
+
+       /* Find max rssi among 3 possible receivers.
+        * These values are measured by the digital signal processor (DSP).
+        * They should stay fairly constant even as the signal strength varies,
+        *   if the radio's automatic gain control (AGC) is working right.
+        * AGC value (see below) will provide the "interesting" info. */
+       for (i = 0; i < 3; i++)
+               if (valid_antennae & (1 << i))
+                       max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
+
+       IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
+               ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
+               max_rssi, agc);
+
+       /* dBm = max_rssi dB - agc dB - constant.
+        * Higher AGC (higher radio gain) means lower signal. */
+       return max_rssi - agc - IWL_RSSI_OFFSET;
+}
+
 
 /* Set up 4965-specific Rx frame reply handlers */
 static void iwl4965_rx_handler_setup(struct iwl_priv *priv)
 {
        /* Legacy Rx frames */
-       priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
+       priv->rx_handlers[REPLY_RX] = iwl_rx_reply_rx;
        /* Tx response */
        priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
-       /* block ack */
-       priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba;
 }
 
-void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv)
+static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
 {
        INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
-#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
-       INIT_WORK(&priv->sensitivity_work, iwl4965_bg_sensitivity_work);
-#endif
-       init_timer(&priv->statistics_periodic);
-       priv->statistics_periodic.data = (unsigned long)priv;
-       priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
 }
 
-void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv)
+static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
 {
-       del_timer_sync(&priv->statistics_periodic);
-
-       cancel_delayed_work(&priv->init_alive_start);
+       cancel_work_sync(&priv->txpower_work);
 }
 
 
@@ -3527,10 +2319,10 @@ static struct iwl_hcmd_ops iwl4965_hcmd = {
 static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
        .get_hcmd_size = iwl4965_get_hcmd_size,
        .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
-#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
        .chain_noise_reset = iwl4965_chain_noise_reset,
        .gain_computation = iwl4965_gain_computation,
-#endif
+       .rts_tx_cmd_flag = iwl4965_rts_tx_cmd_flag,
+       .calc_rssi = iwl4965_calc_rssi,
 };
 
 static struct iwl_lib_ops iwl4965_lib = {
@@ -3543,6 +2335,8 @@ static struct iwl_lib_ops iwl4965_lib = {
        .txq_agg_enable = iwl4965_txq_agg_enable,
        .txq_agg_disable = iwl4965_txq_agg_disable,
        .rx_handler_setup = iwl4965_rx_handler_setup,
+       .setup_deferred_work = iwl4965_setup_deferred_work,
+       .cancel_deferred_work = iwl4965_cancel_deferred_work,
        .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
        .alive_notify = iwl4965_alive_notify,
        .init_alive_start = iwl4965_init_alive_start,
@@ -3570,9 +2364,9 @@ static struct iwl_lib_ops iwl4965_lib = {
                .check_version = iwl4965_eeprom_check_version,
                .query_addr = iwlcore_eeprom_query_addr,
        },
-       .radio_kill_sw = iwl4965_radio_kill_sw,
-       .set_power = iwl4965_set_power,
+       .send_tx_power  = iwl4965_send_tx_power,
        .update_chain_flags = iwl4965_update_chain_flags,
+       .temperature = iwl4965_temperature_calib,
 };
 
 static struct iwl_ops iwl4965_ops = {
@@ -3590,12 +2384,15 @@ struct iwl_cfg iwl4965_agn_cfg = {
        .mod_params = &iwl4965_mod_params,
 };
 
+/* Module firmware */
+MODULE_FIRMWARE("iwlwifi-4965" IWL4965_UCODE_API ".ucode");
+
 module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
 MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
 module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
 module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
-MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])\n");
+MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
 module_param_named(debug, iwl4965_mod_params.debug, int, 0444);
 MODULE_PARM_DESC(debug, "debug output mask");
 module_param_named(
@@ -3604,11 +2401,14 @@ MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
 
 module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
 MODULE_PARM_DESC(queues_num, "number of hw queues.");
-
 /* QoS */
 module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
 MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
+/* 11n */
+module_param_named(11n_disable, iwl4965_mod_params.disable_11n, int, 0444);
+MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
 module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
 MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
+
 module_param_named(fw_restart4965, iwl4965_mod_params.restart_fw, int, 0444);
 MODULE_PARM_DESC(fw_restart4965, "restart firmware in case of error");