iwlwifi: parametrize eeprom versions
[cascardo/linux.git] / drivers / net / wireless / iwlwifi / iwl-5000.c
index 5155b8a..f3316d4 100644 (file)
@@ -46,6 +46,8 @@
 
 #define IWL5000_UCODE_API  "-1"
 
+#define IWL5000_MODULE_FIRMWARE "iwlwifi-5000" IWL5000_UCODE_API ".ucode"
+
 static const u16 iwl5000_default_queue_to_tx_fifo[] = {
        IWL_TX_FIFO_AC3,
        IWL_TX_FIFO_AC2,
@@ -291,30 +293,17 @@ static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
        return (address & ADDRESS_MSK) + (offset << 1);
 }
 
-static int iwl5000_eeprom_check_version(struct iwl_priv *priv)
+static u16 iwl5000_eeprom_calib_version(struct iwl_priv *priv)
 {
-       u16 eeprom_ver;
        struct iwl_eeprom_calib_hdr {
                u8 version;
                u8 pa_type;
                u16 voltage;
        } *hdr;
 
-       eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
-
        hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
                                                        EEPROM_5000_CALIB_ALL);
-
-       if (eeprom_ver < EEPROM_5000_EEPROM_VERSION ||
-           hdr->version < EEPROM_5000_TX_POWER_VERSION)
-               goto err;
-
-       return 0;
-err:
-       IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
-                 eeprom_ver, EEPROM_5000_EEPROM_VERSION,
-                 hdr->version, EEPROM_5000_TX_POWER_VERSION);
-       return -EINVAL;
+       return hdr->version;
 
 }
 
@@ -390,8 +379,8 @@ static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
 static void iwl5000_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
                        __le32 *tx_flags)
 {
-       if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) ||
-           (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT))
+       if ((info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
+           (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT))
                *tx_flags |= TX_CMD_FLG_RTS_CTS_MSK;
        else
                *tx_flags &= ~TX_CMD_FLG_RTS_CTS_MSK;
@@ -429,20 +418,19 @@ static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
 /*
  *  Calibration
  */
-static int iwl5000_send_Xtal_calib(struct iwl_priv *priv)
+static int iwl5000_set_Xtal_calib(struct iwl_priv *priv)
 {
+       u8 data[sizeof(struct iwl5000_calib_hdr) +
+               sizeof(struct iwl_cal_xtal_freq)];
+       struct iwl5000_calib_cmd *cmd = (struct iwl5000_calib_cmd *)data;
+       struct iwl_cal_xtal_freq *xtal = (struct iwl_cal_xtal_freq *)cmd->data;
        u16 *xtal_calib = (u16 *)iwl_eeprom_query_addr(priv, EEPROM_5000_XTAL);
 
-       struct iwl5000_calibration cal_cmd = {
-               .op_code = IWL5000_PHY_CALIBRATE_CRYSTAL_FRQ_CMD,
-               .data = {
-                       (u8)xtal_calib[0],
-                       (u8)xtal_calib[1],
-               }
-       };
-
-       return iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
-                               sizeof(cal_cmd), &cal_cmd);
+       cmd->hdr.op_code = IWL5000_PHY_CALIBRATE_CRYSTAL_FRQ_CMD;
+       xtal->cap_pin1 = (u8)xtal_calib[0];
+       xtal->cap_pin2 = (u8)xtal_calib[1];
+       return iwl_calib_set(&priv->calib_results[IWL5000_CALIB_XTAL],
+                            data, sizeof(data));
 }
 
 static int iwl5000_send_calib_cfg(struct iwl_priv *priv)
@@ -535,7 +523,7 @@ static int iwl5000_load_section(struct iwl_priv *priv,
 
        iwl_write_direct32(priv,
                FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL),
-               (iwl_get_dma_hi_address(phy_addr)
+               (iwl_get_dma_hi_addr(phy_addr)
                        << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt);
 
        iwl_write_direct32(priv,
@@ -682,7 +670,7 @@ static void iwl5000_tx_queue_set_status(struct iwl_priv *priv,
                                        int tx_fifo_id, int scd_retry)
 {
        int txq_id = txq->q.id;
-       int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
+       int active = test_bit(txq_id, &priv->txq_ctx_active_msk) ? 1 : 0;
 
        iwl_write_prph(priv, IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
                        (active << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
@@ -784,10 +772,8 @@ static int iwl5000_alive_notify(struct iwl_priv *priv)
 
        iwl5000_send_wimax_coex(priv);
 
-       iwl5000_send_Xtal_calib(priv);
-
-       if (priv->ucode_type == UCODE_RT)
-               iwl_send_calib_results(priv);
+       iwl5000_set_Xtal_calib(priv);
+       iwl_send_calib_results(priv);
 
        return 0;
 }
@@ -802,7 +788,6 @@ static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
        }
 
        priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
-       priv->hw_params.first_ampdu_q = IWL50_FIRST_AMPDU_QUEUE;
        priv->hw_params.max_stations = IWL5000_STATION_COUNT;
        priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
        priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
@@ -814,10 +799,14 @@ static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
 
        switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
        case CSR_HW_REV_TYPE_5100:
+               priv->hw_params.tx_chains_num = 1;
+               priv->hw_params.rx_chains_num = 2;
+               priv->hw_params.valid_tx_ant = ANT_B;
+               priv->hw_params.valid_rx_ant = ANT_AB;
+               break;
        case CSR_HW_REV_TYPE_5150:
                priv->hw_params.tx_chains_num = 1;
                priv->hw_params.rx_chains_num = 2;
-               /* FIXME: move to ANT_A, ANT_B, ANT_C enum */
                priv->hw_params.valid_tx_ant = ANT_A;
                priv->hw_params.valid_rx_ant = ANT_AB;
                break;
@@ -844,6 +833,23 @@ static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
                break;
        }
 
+       /* Set initial calibration set */
+       switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
+       case CSR_HW_REV_TYPE_5100:
+       case CSR_HW_REV_TYPE_5300:
+       case CSR_HW_REV_TYPE_5350:
+               priv->hw_params.calib_init_cfg =
+                       BIT(IWL5000_CALIB_XTAL)         |
+                       BIT(IWL5000_CALIB_LO)           |
+                       BIT(IWL5000_CALIB_TX_IQ)        |
+                       BIT(IWL5000_CALIB_TX_IQ_PERD);
+               break;
+       case CSR_HW_REV_TYPE_5150:
+               priv->hw_params.calib_init_cfg = 0;
+               break;
+       }
+
+
        return 0;
 }
 
@@ -1136,10 +1142,10 @@ static int iwl5000_tx_status_reply_tx(struct iwl_priv *priv,
                                   agg->frame_count, agg->start_idx, idx);
 
                info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
-               info->status.retry_count = tx_resp->failure_frame;
+               info->status.rates[0].count = tx_resp->failure_frame + 1;
                info->flags &= ~IEEE80211_TX_CTL_AMPDU;
                info->flags |= iwl_is_tx_success(status)?
-                       IEEE80211_TX_STAT_ACK : 0;
+                                       IEEE80211_TX_STAT_ACK : 0;
                iwl_hwrate_to_tx_control(priv, rate_n_flags, info);
 
                /* FIXME: code repetition end */
@@ -1225,9 +1231,9 @@ static void iwl5000_rx_reply_tx(struct iwl_priv *priv,
        struct ieee80211_tx_info *info;
        struct iwl5000_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
        u32  status = le16_to_cpu(tx_resp->status.status);
-       int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
-       struct ieee80211_hdr *hdr;
-       u8 *qc = NULL;
+       int tid;
+       int sta_id;
+       int freed;
 
        if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
                IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
@@ -1240,25 +1246,13 @@ static void iwl5000_rx_reply_tx(struct iwl_priv *priv,
        info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
        memset(&info->status, 0, sizeof(info->status));
 
-       hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
-       if (ieee80211_is_data_qos(hdr->frame_control)) {
-               qc = ieee80211_get_qos_ctl(hdr);
-               tid = qc[0] & 0xf;
-       }
-
-       sta_id = iwl_get_ra_sta_id(priv, hdr);
-       if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
-               IWL_ERROR("Station not known\n");
-               return;
-       }
+       tid = (tx_resp->ra_tid & IWL50_TX_RES_TID_MSK) >> IWL50_TX_RES_TID_POS;
+       sta_id = (tx_resp->ra_tid & IWL50_TX_RES_RA_MSK) >> IWL50_TX_RES_RA_POS;
 
        if (txq->sched_retry) {
                const u32 scd_ssn = iwl5000_get_scd_ssn(tx_resp);
                struct iwl_ht_agg *agg = NULL;
 
-               if (!qc)
-                       return;
-
                agg = &priv->stations[sta_id].tid[tid].agg;
 
                iwl5000_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
@@ -1268,53 +1262,53 @@ static void iwl5000_rx_reply_tx(struct iwl_priv *priv,
                        info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
 
                if (txq->q.read_ptr != (scd_ssn & 0xff)) {
-                       int freed, ampdu_q;
                        index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
-                       IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
-                                          "%d index %d\n", scd_ssn , index);
+                       IWL_DEBUG_TX_REPLY("Retry scheduler reclaim "
+                                       "scd_ssn=%d idx=%d txq=%d swq=%d\n",
+                                       scd_ssn , index, txq_id, txq->swq_id);
+
                        freed = iwl_tx_queue_reclaim(priv, txq_id, index);
                        priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
 
-                       if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
-                           txq_id >= 0 && priv->mac80211_registered &&
-                           agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
-                               /* calculate mac80211 ampdu sw queue to wake */
-                               ampdu_q = txq_id - IWL50_FIRST_AMPDU_QUEUE +
-                                         priv->hw->queues;
+                       if (priv->mac80211_registered &&
+                           (iwl_queue_space(&txq->q) > txq->q.low_mark) &&
+                           (agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)) {
                                if (agg->state == IWL_AGG_OFF)
                                        ieee80211_wake_queue(priv->hw, txq_id);
                                else
-                                       ieee80211_wake_queue(priv->hw, ampdu_q);
+                                       ieee80211_wake_queue(priv->hw,
+                                                            txq->swq_id);
                        }
-                       iwl_txq_check_empty(priv, sta_id, tid, txq_id);
                }
        } else {
-               info->status.retry_count = tx_resp->failure_frame;
-               info->flags =
-                       iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
+               BUG_ON(txq_id != txq->swq_id);
+
+               info->status.rates[0].count = tx_resp->failure_frame + 1;
+               info->flags |= iwl_is_tx_success(status) ?
+                                       IEEE80211_TX_STAT_ACK : 0;
                iwl_hwrate_to_tx_control(priv,
                                        le32_to_cpu(tx_resp->rate_n_flags),
                                        info);
 
-               IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags "
-                            "0x%x retries %d\n", txq_id,
-                               iwl_get_tx_fail_reason(status),
-                               status, le32_to_cpu(tx_resp->rate_n_flags),
-                               tx_resp->failure_frame);
+               IWL_DEBUG_TX_REPLY("TXQ %d status %s (0x%08x) rate_n_flags "
+                                  "0x%x retries %d\n",
+                                  txq_id,
+                                  iwl_get_tx_fail_reason(status), status,
+                                  le32_to_cpu(tx_resp->rate_n_flags),
+                                  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)
+               freed = iwl_tx_queue_reclaim(priv, txq_id, index);
+               if (ieee80211_is_data_qos(tx_resp->frame_ctrl))
                        priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
-                   if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
-                       (txq_id >= 0) && priv->mac80211_registered)
+
+               if (priv->mac80211_registered &&
+                   (iwl_queue_space(&txq->q) > txq->q.low_mark))
                        ieee80211_wake_queue(priv->hw, txq_id);
-                   if (tid != MAX_TID_COUNT)
-                       iwl_txq_check_empty(priv, sta_id, tid, txq_id);
-               }
        }
 
+       if (ieee80211_is_data_qos(tx_resp->frame_ctrl))
+               iwl_txq_check_empty(priv, sta_id, tid, txq_id);
+
        if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
                IWL_ERROR("TODO:  Implement Tx ABORT REQUIRED!!!\n");
 }
@@ -1503,7 +1497,7 @@ static struct iwl_lib_ops iwl5000_lib = {
                .verify_signature  = iwlcore_eeprom_verify_signature,
                .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
                .release_semaphore = iwlcore_eeprom_release_semaphore,
-               .check_version  = iwl5000_eeprom_check_version,
+               .calib_version  = iwl5000_eeprom_calib_version,
                .query_addr = iwl5000_eeprom_query_addr,
        },
 };
@@ -1526,50 +1520,60 @@ static struct iwl_mod_params iwl50_mod_params = {
 
 struct iwl_cfg iwl5300_agn_cfg = {
        .name = "5300AGN",
-       .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
+       .fw_name = IWL5000_MODULE_FIRMWARE,
        .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
        .ops = &iwl5000_ops,
        .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
+       .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
+       .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
        .mod_params = &iwl50_mod_params,
 };
 
 struct iwl_cfg iwl5100_bg_cfg = {
        .name = "5100BG",
-       .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
+       .fw_name = IWL5000_MODULE_FIRMWARE,
        .sku = IWL_SKU_G,
        .ops = &iwl5000_ops,
        .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
+       .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
+       .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
        .mod_params = &iwl50_mod_params,
 };
 
 struct iwl_cfg iwl5100_abg_cfg = {
        .name = "5100ABG",
-       .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
+       .fw_name = IWL5000_MODULE_FIRMWARE,
        .sku = IWL_SKU_A|IWL_SKU_G,
        .ops = &iwl5000_ops,
        .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
+       .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
+       .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
        .mod_params = &iwl50_mod_params,
 };
 
 struct iwl_cfg iwl5100_agn_cfg = {
        .name = "5100AGN",
-       .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
+       .fw_name = IWL5000_MODULE_FIRMWARE,
        .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
        .ops = &iwl5000_ops,
        .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
+       .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
+       .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
        .mod_params = &iwl50_mod_params,
 };
 
 struct iwl_cfg iwl5350_agn_cfg = {
        .name = "5350AGN",
-       .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
+       .fw_name = IWL5000_MODULE_FIRMWARE,
        .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
        .ops = &iwl5000_ops,
        .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
+       .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
+       .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
        .mod_params = &iwl50_mod_params,
 };
 
-MODULE_FIRMWARE("iwlwifi-5000" IWL5000_UCODE_API ".ucode");
+MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE);
 
 module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
 MODULE_PARM_DESC(disable50,