Merge branch 'topic/hda' into for-linus
[safe/jmp/linux-2.6] / drivers / net / wireless / iwlwifi / iwl-3945.c
index 1377c81..45cfa1c 100644 (file)
@@ -19,7 +19,7 @@
  * file called LICENSE.
  *
  * Contact Information:
- * James P. Ketrenos <ipw2100-admin@linux.intel.com>
+ *  Intel Linux Wireless <ilw@linux.intel.com>
  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  *
  *****************************************************************************/
@@ -200,7 +200,7 @@ static int iwl3945_hwrate_to_plcp_idx(u8 plcp)
  * priv->eeprom  is used to determine if antenna AUX/MAIN are reversed
  * priv->antenna specifies the antenna diversity mode:
  *
- * IWL_ANTENNA_DIVERISTY - NIC selects best antenna by itself
+ * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
  * IWL_ANTENNA_MAIN      - Force MAIN antenna
  * IWL_ANTENNA_AUX       - Force AUX antenna
  */
@@ -261,6 +261,37 @@ static inline const char *iwl3945_get_tx_fail_reason(u32 status)
 }
 #endif
 
+/*
+ * get ieee prev rate from rate scale table.
+ * for A and B mode we need to overright prev
+ * value
+ */
+int iwl3945_rs_next_rate(struct iwl3945_priv *priv, int rate)
+{
+       int next_rate = iwl3945_get_prev_ieee_rate(rate);
+
+       switch (priv->band) {
+       case IEEE80211_BAND_5GHZ:
+               if (rate == IWL_RATE_12M_INDEX)
+                       next_rate = IWL_RATE_9M_INDEX;
+               else if (rate == IWL_RATE_6M_INDEX)
+                       next_rate = IWL_RATE_6M_INDEX;
+               break;
+       case IEEE80211_BAND_2GHZ:
+               if (!(priv->sta_supp_rates & IWL_OFDM_RATES_MASK) &&
+                   iwl3945_is_associated(priv)) {
+                       if (rate == IWL_RATE_11M_INDEX)
+                               next_rate = IWL_RATE_5M_INDEX;
+               }
+               break;
+
+       default:
+               break;
+       }
+
+       return next_rate;
+}
+
 
 /**
  * iwl3945_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
@@ -308,6 +339,7 @@ static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
        struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
        u32  status = le32_to_cpu(tx_resp->status);
        int rate_idx;
+       int fail;
 
        if ((index >= txq->q.n_bd) || (iwl3945_x2_queue_used(&txq->q, index) == 0)) {
                IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
@@ -318,9 +350,18 @@ static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
        }
 
        info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
-       memset(&info->status, 0, sizeof(info->status));
+       ieee80211_tx_info_clear_status(info);
+
+       /* Fill the MRR chain with some info about on-chip retransmissions */
+       rate_idx = iwl3945_hwrate_to_plcp_idx(tx_resp->rate);
+       if (info->band == IEEE80211_BAND_5GHZ)
+               rate_idx -= IWL_FIRST_OFDM_RATE;
+
+       fail = tx_resp->failure_frame;
+
+       info->status.rates[0].idx = rate_idx;
+       info->status.rates[0].count = fail + 1; /* add final attempt */
 
-       info->status.retry_count = tx_resp->failure_frame;
        /* tx_status->rts_retry_count = tx_resp->failure_rts; */
        info->flags |= ((status & TX_STATUS_MSK) == TX_STATUS_SUCCESS) ?
                                IEEE80211_TX_STAT_ACK : 0;
@@ -329,10 +370,6 @@ static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
                        txq_id, iwl3945_get_tx_fail_reason(status), status,
                        tx_resp->rate, tx_resp->failure_frame);
 
-       rate_idx = iwl3945_hwrate_to_plcp_idx(tx_resp->rate);
-       if (info->band == IEEE80211_BAND_5GHZ)
-               rate_idx -= IWL_FIRST_OFDM_RATE;
-       info->tx_rate_idx = rate_idx;
        IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
        iwl3945_tx_queue_reclaim(priv, txq_id, index);
 
@@ -520,10 +557,10 @@ static int iwl3945_is_network_packet(struct iwl3945_priv *priv,
        /* Filter incoming packets to determine if they are targeted toward
         * this network, discarding packets coming from ourselves */
        switch (priv->iw_mode) {
-       case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source    | BSSID */
+       case NL80211_IFTYPE_ADHOC: /* Header: Dest. | Source    | BSSID */
                /* packets to our IBSS update information */
                return !compare_ether_addr(header->addr3, priv->bssid);
-       case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
+       case NL80211_IFTYPE_STATION: /* Header: Dest. | AP{BSSID} | Source */
                /* packets to our IBSS update information */
                return !compare_ether_addr(header->addr2, priv->bssid);
        default:
@@ -681,19 +718,7 @@ static void iwl3945_rx_reply_rx(struct iwl3945_priv *priv,
                priv->last_rx_noise = rx_status.noise;
        }
 
-       if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
-               iwl3945_pass_packet_to_mac80211(priv, rxb, &rx_status);
-               return;
-       }
-
-       switch (le16_to_cpu(header->frame_control) & IEEE80211_FCTL_FTYPE) {
-       case IEEE80211_FTYPE_MGMT:
-       case IEEE80211_FTYPE_DATA:
-               /* fall through */
-       default:
-               iwl3945_pass_packet_to_mac80211(priv, rxb, &rx_status);
-               break;
-       }
+       iwl3945_pass_packet_to_mac80211(priv, rxb, &rx_status);
 }
 
 int iwl3945_hw_txq_attach_buf_to_tfd(struct iwl3945_priv *priv, void *ptr,
@@ -768,13 +793,19 @@ int iwl3945_hw_txq_free_tfd(struct iwl3945_priv *priv, struct iwl3945_tx_queue *
 
 u8 iwl3945_hw_find_station(struct iwl3945_priv *priv, const u8 *addr)
 {
-       int i;
+       int i, start = IWL_AP_ID;
        int ret = IWL_INVALID_STATION;
        unsigned long flags;
-       DECLARE_MAC_BUF(mac);
+
+       if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) ||
+           (priv->iw_mode == NL80211_IFTYPE_AP))
+               start = IWL_STA_ID;
+
+       if (is_broadcast_ether_addr(addr))
+               return priv->hw_setting.bcast_sta_id;
 
        spin_lock_irqsave(&priv->sta_lock, flags);
-       for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
+       for (i = start; i < priv->hw_setting.max_stations; i++)
                if ((priv->stations[i].used) &&
                    (!compare_ether_addr
                     (priv->stations[i].sta.sta.addr, addr))) {
@@ -782,8 +813,8 @@ u8 iwl3945_hw_find_station(struct iwl3945_priv *priv, const u8 *addr)
                        goto out;
                }
 
-       IWL_DEBUG_INFO("can not find STA %s (total %d)\n",
-                      print_mac(mac, addr), priv->num_stations);
+       IWL_DEBUG_INFO("can not find STA %pM (total %d)\n",
+                      addr, priv->num_stations);
  out:
        spin_unlock_irqrestore(&priv->sta_lock, flags);
        return ret;
@@ -819,7 +850,7 @@ void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv,
 
        priv->stations[sta_id].current_rate.rate_n_flags = rate;
 
-       if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
+       if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
            (sta_id != priv->hw_setting.bcast_sta_id) &&
                (sta_id != IWL_MULTICAST_ID))
                priv->stations[IWL_STA_ID].current_rate.rate_n_flags = rate;
@@ -1072,9 +1103,8 @@ int iwl3945_hw_nic_init(struct iwl3945_priv *priv)
                    CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
 
        iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
-       rc = iwl3945_poll_bit(priv, CSR_GP_CNTRL,
-                         CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
-                         CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
+       rc = iwl3945_poll_direct_bit(priv, CSR_GP_CNTRL,
+                       CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
        if (rc < 0) {
                spin_unlock_irqrestore(&priv->lock, flags);
                IWL_DEBUG_INFO("Failed to init the card\n");
@@ -1255,8 +1285,7 @@ int iwl3945_hw_nic_stop_master(struct iwl3945_priv *priv)
                IWL_DEBUG_INFO("Card in power save, master is already "
                               "stopped\n");
        else {
-               rc = iwl3945_poll_bit(priv, CSR_RESET,
-                                 CSR_RESET_REG_FLAG_MASTER_DISABLED,
+               rc = iwl3945_poll_direct_bit(priv, CSR_RESET,
                                  CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
                if (rc < 0) {
                        spin_unlock_irqrestore(&priv->lock, flags);
@@ -1281,9 +1310,8 @@ int iwl3945_hw_nic_reset(struct iwl3945_priv *priv)
 
        iwl3945_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
 
-       rc = iwl3945_poll_bit(priv, CSR_GP_CNTRL,
-                         CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
-                         CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
+       iwl3945_poll_direct_bit(priv, CSR_GP_CNTRL,
+                        CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
 
        rc = iwl3945_grab_nic_access(priv);
        if (!rc) {
@@ -1842,7 +1870,7 @@ static int iwl3945_hw_reg_comp_txpower_temp(struct iwl3945_priv *priv)
                ref_temp = (s16)priv->eeprom.groups[ch_info->group_index].
                    temperature;
 
-               /* get power index adjustment based on curr and factory
+               /* get power index adjustment based on current and factory
                 * temps */
                delta_index = iwl3945_hw_reg_adjust_power_by_temp(temperature,
                                                              ref_temp);
@@ -2191,7 +2219,7 @@ int iwl3945_txpower_set_from_eeprom(struct iwl3945_priv *priv)
                /* set tx power value for all OFDM rates */
                for (rate_index = 0; rate_index < IWL_OFDM_RATES;
                     rate_index++) {
-                       s32 power_idx;
+                       s32 uninitialized_var(power_idx);
                        int rc;
 
                        /* use channel group's clip-power table,
@@ -2280,7 +2308,8 @@ int iwl3945_hw_rxq_stop(struct iwl3945_priv *priv)
        }
 
        iwl3945_write_direct32(priv, FH_RCSR_CONFIG(0), 0);
-       rc = iwl3945_poll_direct_bit(priv, FH_RSSR_STATUS, (1 << 24), 1000);
+       rc = iwl3945_poll_direct_bit(priv, FH_RSSR_STATUS,
+                       FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
        if (rc < 0)
                IWL_ERROR("Can't stop Rx DMA.\n");
 
@@ -2349,7 +2378,8 @@ int iwl3945_init_hw_rate_table(struct iwl3945_priv *priv)
                        iwl3945_hw_set_rate_n_flags(iwl3945_rates[i].plcp, 0);
                table[index].try_cnt = priv->retry_rate;
                prev_index = iwl3945_get_prev_ieee_rate(i);
-               table[index].next_rate_index = iwl3945_rates[prev_index].table_rs_index;
+               table[index].next_rate_index =
+                               iwl3945_rates[prev_index].table_rs_index;
        }
 
        switch (priv->band) {
@@ -2357,11 +2387,14 @@ int iwl3945_init_hw_rate_table(struct iwl3945_priv *priv)
                IWL_DEBUG_RATE("Select A mode rate scale\n");
                /* If one of the following CCK rates is used,
                 * have it fall back to the 6M OFDM rate */
-               for (i = IWL_RATE_1M_INDEX_TABLE; i <= IWL_RATE_11M_INDEX_TABLE; i++)
-                       table[i].next_rate_index = iwl3945_rates[IWL_FIRST_OFDM_RATE].table_rs_index;
+               for (i = IWL_RATE_1M_INDEX_TABLE;
+                       i <= IWL_RATE_11M_INDEX_TABLE; i++)
+                       table[i].next_rate_index =
+                         iwl3945_rates[IWL_FIRST_OFDM_RATE].table_rs_index;
 
                /* Don't fall back to CCK rates */
-               table[IWL_RATE_12M_INDEX_TABLE].next_rate_index = IWL_RATE_9M_INDEX_TABLE;
+               table[IWL_RATE_12M_INDEX_TABLE].next_rate_index =
+                                               IWL_RATE_9M_INDEX_TABLE;
 
                /* Don't drop out of OFDM rates */
                table[IWL_RATE_6M_INDEX_TABLE].next_rate_index =
@@ -2372,11 +2405,20 @@ int iwl3945_init_hw_rate_table(struct iwl3945_priv *priv)
                IWL_DEBUG_RATE("Select B/G mode rate scale\n");
                /* If an OFDM rate is used, have it fall back to the
                 * 1M CCK rates */
-               for (i = IWL_RATE_6M_INDEX_TABLE; i <= IWL_RATE_54M_INDEX_TABLE; i++)
-                       table[i].next_rate_index = iwl3945_rates[IWL_FIRST_CCK_RATE].table_rs_index;
 
-               /* CCK shouldn't fall back to OFDM... */
-               table[IWL_RATE_11M_INDEX_TABLE].next_rate_index = IWL_RATE_5M_INDEX_TABLE;
+               if (!(priv->sta_supp_rates & IWL_OFDM_RATES_MASK) &&
+                   iwl3945_is_associated(priv)) {
+
+                       index = IWL_FIRST_CCK_RATE;
+                       for (i = IWL_RATE_6M_INDEX_TABLE;
+                            i <= IWL_RATE_54M_INDEX_TABLE; i++)
+                               table[i].next_rate_index =
+                                       iwl3945_rates[index].table_rs_index;
+
+                       index = IWL_RATE_11M_INDEX_TABLE;
+                       /* CCK shouldn't fall back to OFDM... */
+                       table[index].next_rate_index = IWL_RATE_5M_INDEX_TABLE;
+               }
                break;
 
        default:
@@ -2440,7 +2482,6 @@ unsigned int iwl3945_hw_get_beacon_cmd(struct iwl3945_priv *priv,
 
        frame_size = iwl3945_fill_beacon_frame(priv,
                                tx_beacon_cmd->frame,
-                               iwl3945_broadcast_addr,
                                sizeof(frame->u) - sizeof(*tx_beacon_cmd));
 
        BUG_ON(frame_size > MAX_MPDU_SIZE);
@@ -2479,13 +2520,17 @@ void iwl3945_hw_cancel_deferred_work(struct iwl3945_priv *priv)
 
 static struct iwl_3945_cfg iwl3945_bg_cfg = {
        .name = "3945BG",
-       .fw_name = "iwlwifi-3945" IWL3945_UCODE_API ".ucode",
+       .fw_name_pre = IWL3945_FW_PRE,
+       .ucode_api_max = IWL3945_UCODE_API_MAX,
+       .ucode_api_min = IWL3945_UCODE_API_MIN,
        .sku = IWL_SKU_G,
 };
 
 static struct iwl_3945_cfg iwl3945_abg_cfg = {
        .name = "3945ABG",
-       .fw_name = "iwlwifi-3945" IWL3945_UCODE_API ".ucode",
+       .fw_name_pre = IWL3945_FW_PRE,
+       .ucode_api_max = IWL3945_UCODE_API_MAX,
+       .ucode_api_min = IWL3945_UCODE_API_MIN,
        .sku = IWL_SKU_A|IWL_SKU_G,
 };