iwlwifi: introduce statistics lock
authorJohannes Berg <johannes.berg@intel.com>
Mon, 5 Mar 2012 19:24:26 +0000 (11:24 -0800)
committerJohn W. Linville <linville@tuxdriver.com>
Tue, 6 Mar 2012 20:16:09 +0000 (15:16 -0500)
The statistics are currently only half-heartedly
locked against concurrent reading & modification
so introduce a lock to really protect them.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Wey-Yi Guy <wey-yi.w.guy@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/iwlwifi/iwl-agn-calib.c
drivers/net/wireless/iwlwifi/iwl-agn-lib.c
drivers/net/wireless/iwlwifi/iwl-agn-rx.c
drivers/net/wireless/iwlwifi/iwl-agn.c
drivers/net/wireless/iwlwifi/iwl-debugfs.c
drivers/net/wireless/iwlwifi/iwl-dev.h

index 988ee454a9446773a94feea6fb6642c3e187feb6..12acc81ed4194bb7e31739ba2991733f5a675749 100644 (file)
@@ -655,7 +655,6 @@ void iwl_sensitivity_calibration(struct iwl_priv *priv)
        struct iwl_sensitivity_data *data = NULL;
        struct statistics_rx_non_phy *rx_info;
        struct statistics_rx_phy *ofdm, *cck;
-       unsigned long flags;
        struct statistics_general_data statis;
 
        if (priv->disable_sens_cal)
@@ -668,13 +667,13 @@ void iwl_sensitivity_calibration(struct iwl_priv *priv)
                return;
        }
 
-       spin_lock_irqsave(&priv->shrd->lock, flags);
+       spin_lock_bh(&priv->statistics.lock);
        rx_info = &priv->statistics.rx_non_phy;
        ofdm = &priv->statistics.rx_ofdm;
        cck = &priv->statistics.rx_cck;
        if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) {
                IWL_DEBUG_CALIB(priv, "<< invalid data.\n");
-               spin_unlock_irqrestore(&priv->shrd->lock, flags);
+               spin_unlock_bh(&priv->statistics.lock);
                return;
        }
 
@@ -698,7 +697,7 @@ void iwl_sensitivity_calibration(struct iwl_priv *priv)
        statis.beacon_energy_c =
                        le32_to_cpu(rx_info->beacon_energy_c);
 
-       spin_unlock_irqrestore(&priv->shrd->lock, flags);
+       spin_unlock_bh(&priv->statistics.lock);
 
        IWL_DEBUG_CALIB(priv, "rx_enable_time = %u usecs\n", rx_enable_time);
 
@@ -958,7 +957,6 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv)
        u16 stat_chnum = INITIALIZATION_VALUE;
        u8 rxon_band24;
        u8 stat_band24;
-       unsigned long flags;
        struct statistics_rx_non_phy *rx_info;
 
        /*
@@ -983,13 +981,13 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv)
                return;
        }
 
-       spin_lock_irqsave(&priv->shrd->lock, flags);
+       spin_lock_bh(&priv->statistics.lock);
 
        rx_info = &priv->statistics.rx_non_phy;
 
        if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) {
                IWL_DEBUG_CALIB(priv, " << Interference data unavailable\n");
-               spin_unlock_irqrestore(&priv->shrd->lock, flags);
+               spin_unlock_bh(&priv->statistics.lock);
                return;
        }
 
@@ -1004,7 +1002,7 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv)
        if ((rxon_chnum != stat_chnum) || (rxon_band24 != stat_band24)) {
                IWL_DEBUG_CALIB(priv, "Stats not from chan=%d, band24=%d\n",
                                rxon_chnum, rxon_band24);
-               spin_unlock_irqrestore(&priv->shrd->lock, flags);
+               spin_unlock_bh(&priv->statistics.lock);
                return;
        }
 
@@ -1023,7 +1021,7 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv)
        chain_sig_b = le32_to_cpu(rx_info->beacon_rssi_b) & IN_BAND_FILTER;
        chain_sig_c = le32_to_cpu(rx_info->beacon_rssi_c) & IN_BAND_FILTER;
 
-       spin_unlock_irqrestore(&priv->shrd->lock, flags);
+       spin_unlock_bh(&priv->statistics.lock);
 
        data->beacon_count++;
 
index 5be0d3695d036a2b34b63ebce29572c1ed4c0aaf..0f8dd0f96fa693cdfaf97dbcc884c4561b0bbad2 100644 (file)
@@ -88,6 +88,8 @@ int iwlagn_send_tx_power(struct iwl_priv *priv)
 
 void iwlagn_temperature(struct iwl_priv *priv)
 {
+       lockdep_assert_held(&priv->statistics.lock);
+
        /* store temperature from correct statistics (in Celsius) */
        priv->temperature = le32_to_cpu(priv->statistics.common.temperature);
        iwl_tt_handler(priv);
index 30bb5bbb0cd724055c4bb68748c06a83deba135b..bc21586aed633ca8a8a41a2246a73ad1aca96a22 100644 (file)
@@ -266,6 +266,8 @@ static bool iwlagn_good_ack_health(struct iwl_priv *priv,
        if (priv->agg_tids_count)
                return true;
 
+       lockdep_assert_held(&priv->statistics.lock);
+
        old = &priv->statistics.tx;
 
        actual_delta = le32_to_cpu(cur->actual_ack_cnt) -
@@ -509,6 +511,8 @@ static int iwlagn_rx_statistics(struct iwl_priv *priv,
        IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n",
                     len);
 
+       spin_lock(&priv->statistics.lock);
+
        if (len == sizeof(struct iwl_bt_notif_statistics)) {
                struct iwl_bt_notif_statistics *stats;
                stats = &pkt->u.stats_bt;
@@ -542,6 +546,7 @@ static int iwlagn_rx_statistics(struct iwl_priv *priv,
                WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n",
                          len, sizeof(struct iwl_bt_notif_statistics),
                          sizeof(struct iwl_notif_statistics));
+               spin_unlock(&priv->statistics.lock);
                return 0;
        }
 
@@ -585,6 +590,9 @@ static int iwlagn_rx_statistics(struct iwl_priv *priv,
        }
        if (cfg(priv)->lib->temperature && change)
                cfg(priv)->lib->temperature(priv);
+
+       spin_unlock(&priv->statistics.lock);
+
        return 0;
 }
 
index 0090fab3aacbfd1ece262703fc1bd52329ab66ae..47c788607024e829177240a012d02ff391621ae5 100644 (file)
@@ -1233,6 +1233,7 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans)
         */
        spin_lock_init(&trans(priv)->reg_lock);
        spin_lock_init(&priv->shrd->lock);
+       spin_lock_init(&priv->statistics.lock);
 
        /***********************
         * 3. Read REV register
index ad74138e1c7011a233bcdcc204242fa24917077f..628af563e4e15796373e93c668d1097cc62367f7 100644 (file)
@@ -920,6 +920,8 @@ static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
        int p = 0;
        u32 flag;
 
+       lockdep_assert_held(&priv->statistics.lock);
+
        flag = le32_to_cpu(priv->statistics.flag);
 
        p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
@@ -967,6 +969,7 @@ static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
         * the last statistics notification from uCode
         * might not reflect the current uCode activity
         */
+       spin_lock_bh(&priv->statistics.lock);
        ofdm = &priv->statistics.rx_ofdm;
        cck = &priv->statistics.rx_cck;
        general = &priv->statistics.rx_non_phy;
@@ -1363,6 +1366,8 @@ static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
                         accum_ht->unsupport_mcs,
                         delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
 
+       spin_unlock_bh(&priv->statistics.lock);
+
        ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
        kfree(buf);
        return ret;
@@ -1392,6 +1397,8 @@ static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
         * the last statistics notification from uCode
         * might not reflect the current uCode activity
         */
+       spin_lock_bh(&priv->statistics.lock);
+
        tx = &priv->statistics.tx;
        accum_tx = &priv->accum_stats.tx;
        delta_tx = &priv->delta_stats.tx;
@@ -1554,6 +1561,9 @@ static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
                                        fmt_hex, "antenna C:",
                                        tx->tx_power.ant_c);
        }
+
+       spin_unlock_bh(&priv->statistics.lock);
+
        ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
        kfree(buf);
        return ret;
@@ -1586,6 +1596,9 @@ static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
         * the last statistics notification from uCode
         * might not reflect the current uCode activity
         */
+
+       spin_lock_bh(&priv->statistics.lock);
+
        general = &priv->statistics.common;
        dbg = &priv->statistics.common.dbg;
        div = &priv->statistics.common.div;
@@ -1670,6 +1683,9 @@ static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
                         accum_general->num_of_sos_states,
                         delta_general->num_of_sos_states,
                         max_general->num_of_sos_states);
+
+       spin_unlock_bh(&priv->statistics.lock);
+
        ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
        kfree(buf);
        return ret;
@@ -1713,6 +1729,9 @@ static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
         * the last statistics notification from uCode
         * might not reflect the current uCode activity
         */
+
+       spin_lock_bh(&priv->statistics.lock);
+
        bt = &priv->statistics.bt_activity;
        accum_bt = &priv->accum_stats.bt_activity;
 
@@ -1758,6 +1777,8 @@ static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
                         le32_to_cpu(priv->statistics.num_bt_kills),
                         priv->statistics.accum_num_bt_kills);
 
+       spin_unlock_bh(&priv->statistics.lock);
+
        ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
        kfree(buf);
        return ret;
index dc57522594a6d69dc789eba40e59a1cf2a4a87f8..daf233026b5eaf1588173ba3db2802b8d1979688 100644 (file)
@@ -851,6 +851,7 @@ struct iwl_priv {
                struct statistics_bt_activity bt_activity;
                __le32 num_bt_kills, accum_num_bt_kills;
 #endif
+               spinlock_t lock;
        } statistics;
 #ifdef CONFIG_IWLWIFI_DEBUGFS
        struct {