iwlwifi: fix debugfs buffer handling
[linux-2.6.git] / drivers / net / wireless / iwlwifi / iwl-debugfs.c
index d4109cb..8c374bf 100644 (file)
@@ -38,7 +38,7 @@
 #include "iwl-debug.h"
 #include "iwl-core.h"
 #include "iwl-io.h"
-
+#include "iwl-calib.h"
 
 /* create and remove of files */
 #define DEBUGFS_ADD_DIR(name, parent) do {                              \
@@ -410,7 +410,7 @@ static ssize_t iwl_dbgfs_nvm_read(struct file *file,
                pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
                hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
                                   buf_size - pos, 0);
-               pos += strlen(buf);
+               pos += strlen(buf + pos);
                if (buf_size - pos > 0)
                        buf[pos++] = '\n';
        }
@@ -704,7 +704,7 @@ static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
                                size_t count, loff_t *ppos)
 {
        struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
-       struct iwl_tt_mgmt *tt = &priv->power_data.tt;
+       struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
        struct iwl_tt_restriction *restriction;
        char buf[100];
        int pos = 0;
@@ -713,12 +713,11 @@ static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
 
        pos += scnprintf(buf + pos, bufsz - pos,
                        "Thermal Throttling Mode: %s\n",
-                       (priv->power_data.adv_tt)
-                       ? "Advance" : "Legacy");
+                       tt->advanced_tt ? "Advance" : "Legacy");
        pos += scnprintf(buf + pos, bufsz - pos,
                        "Thermal Throttling State: %d\n",
                        tt->state);
-       if (priv->power_data.adv_tt) {
+       if (tt->advanced_tt) {
                restriction = tt->restriction + tt->state;
                pos += scnprintf(buf + pos, bufsz - pos,
                                "Tx mode: %d\n",
@@ -777,6 +776,83 @@ static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
        return ret;
 }
 
+static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
+                                                   const char __user *user_buf,
+                                                   size_t count, loff_t *ppos)
+{
+       struct iwl_priv *priv = file->private_data;
+       char buf[8];
+       int buf_size;
+       int value;
+
+       memset(buf, 0, sizeof(buf));
+       buf_size = min(count, sizeof(buf) -  1);
+       if (copy_from_user(buf, user_buf, buf_size))
+               return -EFAULT;
+
+       if (sscanf(buf, "%d", &value) != 1)
+               return -EINVAL;
+
+       /*
+        * Our users expect 0 to be "CAM", but 0 isn't actually
+        * valid here. However, let's not confuse them and present
+        * IWL_POWER_INDEX_1 as "1", not "0".
+        */
+       if (value > 0)
+               value -= 1;
+
+       if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
+               return -EINVAL;
+
+       priv->power_data.debug_sleep_level_override = value;
+
+       iwl_power_update_mode(priv, false);
+
+       return count;
+}
+
+static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
+                                                  char __user *user_buf,
+                                                  size_t count, loff_t *ppos)
+{
+       struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
+       char buf[10];
+       int pos, value;
+       const size_t bufsz = sizeof(buf);
+
+       /* see the write function */
+       value = priv->power_data.debug_sleep_level_override;
+       if (value >= 0)
+               value += 1;
+
+       pos = scnprintf(buf, bufsz, "%d\n", value);
+       return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
+}
+
+static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
+                                                   char __user *user_buf,
+                                                   size_t count, loff_t *ppos)
+{
+       struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
+       char buf[200];
+       int pos = 0, i;
+       const size_t bufsz = sizeof(buf);
+       struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
+
+       pos += scnprintf(buf + pos, bufsz - pos,
+                        "flags: %#.2x\n", le16_to_cpu(cmd->flags));
+       pos += scnprintf(buf + pos, bufsz - pos,
+                        "RX/TX timeout: %d/%d usec\n",
+                        le32_to_cpu(cmd->rx_data_timeout),
+                        le32_to_cpu(cmd->tx_data_timeout));
+       for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
+               pos += scnprintf(buf + pos, bufsz - pos,
+                                "sleep_interval[%d]: %d\n", i,
+                                le32_to_cpu(cmd->sleep_interval[i]));
+
+       return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
+}
+
 DEBUGFS_READ_WRITE_FILE_OPS(sram);
 DEBUGFS_WRITE_FILE_OPS(log_event);
 DEBUGFS_READ_FILE_OPS(nvm);
@@ -790,6 +866,8 @@ DEBUGFS_READ_FILE_OPS(led);
 #endif
 DEBUGFS_READ_FILE_OPS(thermal_throttling);
 DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
+DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
+DEBUGFS_READ_FILE_OPS(current_sleep_command);
 
 static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
                                         char __user *user_buf,
@@ -831,7 +909,7 @@ static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
                                                "0x%.4x ", ofs);
                                hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
                                                   buf + pos, bufsz - pos, 0);
-                               pos += strlen(buf);
+                               pos += strlen(buf + pos);
                                if (bufsz - pos > 0)
                                        buf[pos++] = '\n';
                        }
@@ -854,7 +932,7 @@ static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
                                                "0x%.4x ", ofs);
                                hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
                                                   buf + pos, bufsz - pos, 0);
-                               pos += strlen(buf);
+                               pos += strlen(buf + pos);
                                if (bufsz - pos > 0)
                                        buf[pos++] = '\n';
                        }
@@ -950,11 +1028,603 @@ static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
        return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
 }
 
+#define UCODE_STATISTICS_CLEAR_MSK             (0x1 << 0)
+#define UCODE_STATISTICS_FREQUENCY_MSK         (0x1 << 1)
+#define UCODE_STATISTICS_NARROW_BAND_MSK       (0x1 << 2)
+
+static int iwl_dbgfs_statistics_flag(struct iwl_priv *priv, char *buf,
+                                    int bufsz)
+{
+       int p = 0;
+
+       p += scnprintf(buf + p, bufsz - p,
+               "Statistics Flag(0x%X):\n",
+               le32_to_cpu(priv->statistics.flag));
+       if (le32_to_cpu(priv->statistics.flag) & UCODE_STATISTICS_CLEAR_MSK)
+               p += scnprintf(buf + p, bufsz - p,
+               "\tStatistics have been cleared\n");
+       p += scnprintf(buf + p, bufsz - p,
+               "\tOperational Frequency: %s\n",
+               (le32_to_cpu(priv->statistics.flag) &
+               UCODE_STATISTICS_FREQUENCY_MSK)
+                ? "2.4 GHz" : "5.2 GHz");
+       p += scnprintf(buf + p, bufsz - p,
+               "\tTGj Narrow Band: %s\n",
+               (le32_to_cpu(priv->statistics.flag) &
+               UCODE_STATISTICS_NARROW_BAND_MSK)
+                ? "enabled" : "disabled");
+       return p;
+}
+
+
+static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
+                                       char __user *user_buf,
+                                       size_t count, loff_t *ppos)
+{
+       struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
+       int pos = 0;
+       char *buf;
+       int bufsz = sizeof(struct statistics_rx_phy) * 20 +
+               sizeof(struct statistics_rx_non_phy) * 20 +
+               sizeof(struct statistics_rx_ht_phy) * 20 + 400;
+       ssize_t ret;
+       struct statistics_rx_phy *ofdm;
+       struct statistics_rx_phy *cck;
+       struct statistics_rx_non_phy *general;
+       struct statistics_rx_ht_phy *ht;
+
+       if (!iwl_is_alive(priv))
+               return -EAGAIN;
+
+       /* make request to uCode to retrieve statistics information */
+       mutex_lock(&priv->mutex);
+       ret = iwl_send_statistics_request(priv, 0);
+       mutex_unlock(&priv->mutex);
+
+       if (ret) {
+               IWL_ERR(priv,
+                       "Error sending statistics request: %zd\n", ret);
+               return -EAGAIN;
+       }
+       buf = kzalloc(bufsz, GFP_KERNEL);
+       if (!buf) {
+               IWL_ERR(priv, "Can not allocate Buffer\n");
+               return -ENOMEM;
+       }
+
+       /* the statistic information display here is based on
+        * the last statistics notification from uCode
+        * might not reflect the current uCode activity
+        */
+       ofdm = &priv->statistics.rx.ofdm;
+       cck = &priv->statistics.rx.cck;
+       general = &priv->statistics.rx.general;
+       ht = &priv->statistics.rx.ofdm_ht;
+       pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
+       pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM:\n");
+       pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt: %u\n",
+                        le32_to_cpu(ofdm->ina_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt: %u\n",
+                        le32_to_cpu(ofdm->fina_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "plcp_err: %u\n",
+                        le32_to_cpu(ofdm->plcp_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "crc32_err: %u\n",
+                        le32_to_cpu(ofdm->crc32_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "overrun_err: %u\n",
+                        le32_to_cpu(ofdm->overrun_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "early_overrun_err: %u\n",
+                        le32_to_cpu(ofdm->early_overrun_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "crc32_good: %u\n",
+                        le32_to_cpu(ofdm->crc32_good));
+       pos += scnprintf(buf + pos, bufsz - pos, "false_alarm_cnt: %u\n",
+                        le32_to_cpu(ofdm->false_alarm_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "fina_sync_err_cnt: %u\n",
+                        le32_to_cpu(ofdm->fina_sync_err_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "sfd_timeout: %u\n",
+                        le32_to_cpu(ofdm->sfd_timeout));
+       pos += scnprintf(buf + pos, bufsz - pos, "fina_timeout: %u\n",
+                        le32_to_cpu(ofdm->fina_timeout));
+       pos += scnprintf(buf + pos, bufsz - pos, "unresponded_rts: %u\n",
+                        le32_to_cpu(ofdm->unresponded_rts));
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "rxe_frame_limit_overrun: %u\n",
+                       le32_to_cpu(ofdm->rxe_frame_limit_overrun));
+       pos += scnprintf(buf + pos, bufsz - pos, "sent_ack_cnt: %u\n",
+                        le32_to_cpu(ofdm->sent_ack_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "sent_cts_cnt: %u\n",
+                        le32_to_cpu(ofdm->sent_cts_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "sent_ba_rsp_cnt: %u\n",
+                        le32_to_cpu(ofdm->sent_ba_rsp_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "dsp_self_kill: %u\n",
+                        le32_to_cpu(ofdm->dsp_self_kill));
+       pos += scnprintf(buf + pos, bufsz - pos, "mh_format_err: %u\n",
+                        le32_to_cpu(ofdm->mh_format_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "re_acq_main_rssi_sum: %u\n",
+                        le32_to_cpu(ofdm->re_acq_main_rssi_sum));
+
+       pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - CCK:\n");
+       pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt: %u\n",
+                        le32_to_cpu(cck->ina_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt: %u\n",
+                        le32_to_cpu(cck->fina_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "plcp_err: %u\n",
+                        le32_to_cpu(cck->plcp_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "crc32_err: %u\n",
+                        le32_to_cpu(cck->crc32_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "overrun_err: %u\n",
+                        le32_to_cpu(cck->overrun_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "early_overrun_err: %u\n",
+                        le32_to_cpu(cck->early_overrun_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "crc32_good: %u\n",
+                        le32_to_cpu(cck->crc32_good));
+       pos += scnprintf(buf + pos, bufsz - pos, "false_alarm_cnt: %u\n",
+                        le32_to_cpu(cck->false_alarm_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "fina_sync_err_cnt: %u\n",
+                        le32_to_cpu(cck->fina_sync_err_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "sfd_timeout: %u\n",
+                        le32_to_cpu(cck->sfd_timeout));
+       pos += scnprintf(buf + pos, bufsz - pos, "fina_timeout: %u\n",
+                        le32_to_cpu(cck->fina_timeout));
+       pos += scnprintf(buf + pos, bufsz - pos, "unresponded_rts: %u\n",
+                        le32_to_cpu(cck->unresponded_rts));
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "rxe_frame_limit_overrun: %u\n",
+                       le32_to_cpu(cck->rxe_frame_limit_overrun));
+       pos += scnprintf(buf + pos, bufsz - pos, "sent_ack_cnt: %u\n",
+                        le32_to_cpu(cck->sent_ack_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "sent_cts_cnt: %u\n",
+                        le32_to_cpu(cck->sent_cts_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "sent_ba_rsp_cnt: %u\n",
+                        le32_to_cpu(cck->sent_ba_rsp_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "dsp_self_kill: %u\n",
+                        le32_to_cpu(cck->dsp_self_kill));
+       pos += scnprintf(buf + pos, bufsz - pos, "mh_format_err: %u\n",
+                        le32_to_cpu(cck->mh_format_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "re_acq_main_rssi_sum: %u\n",
+                        le32_to_cpu(cck->re_acq_main_rssi_sum));
+
+       pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - GENERAL:\n");
+       pos += scnprintf(buf + pos, bufsz - pos, "bogus_cts: %u\n",
+                        le32_to_cpu(general->bogus_cts));
+       pos += scnprintf(buf + pos, bufsz - pos, "bogus_ack: %u\n",
+                        le32_to_cpu(general->bogus_ack));
+       pos += scnprintf(buf + pos, bufsz - pos, "non_bssid_frames: %u\n",
+                        le32_to_cpu(general->non_bssid_frames));
+       pos += scnprintf(buf + pos, bufsz - pos, "filtered_frames: %u\n",
+                        le32_to_cpu(general->filtered_frames));
+       pos += scnprintf(buf + pos, bufsz - pos, "non_channel_beacons: %u\n",
+                        le32_to_cpu(general->non_channel_beacons));
+       pos += scnprintf(buf + pos, bufsz - pos, "channel_beacons: %u\n",
+                        le32_to_cpu(general->channel_beacons));
+       pos += scnprintf(buf + pos, bufsz - pos, "num_missed_bcon: %u\n",
+                        le32_to_cpu(general->num_missed_bcon));
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "adc_rx_saturation_time: %u\n",
+                       le32_to_cpu(general->adc_rx_saturation_time));
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "ina_detection_search_time: %u\n",
+                       le32_to_cpu(general->ina_detection_search_time));
+       pos += scnprintf(buf + pos, bufsz - pos, "beacon_silence_rssi_a: %u\n",
+                        le32_to_cpu(general->beacon_silence_rssi_a));
+       pos += scnprintf(buf + pos, bufsz - pos, "beacon_silence_rssi_b: %u\n",
+                        le32_to_cpu(general->beacon_silence_rssi_b));
+       pos += scnprintf(buf + pos, bufsz - pos, "beacon_silence_rssi_c: %u\n",
+                        le32_to_cpu(general->beacon_silence_rssi_c));
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "interference_data_flag: %u\n",
+                       le32_to_cpu(general->interference_data_flag));
+       pos += scnprintf(buf + pos, bufsz - pos, "channel_load: %u\n",
+                        le32_to_cpu(general->channel_load));
+       pos += scnprintf(buf + pos, bufsz - pos, "dsp_false_alarms: %u\n",
+                        le32_to_cpu(general->dsp_false_alarms));
+       pos += scnprintf(buf + pos, bufsz - pos, "beacon_rssi_a: %u\n",
+                        le32_to_cpu(general->beacon_rssi_a));
+       pos += scnprintf(buf + pos, bufsz - pos, "beacon_rssi_b: %u\n",
+                        le32_to_cpu(general->beacon_rssi_b));
+       pos += scnprintf(buf + pos, bufsz - pos, "beacon_rssi_c: %u\n",
+                        le32_to_cpu(general->beacon_rssi_c));
+       pos += scnprintf(buf + pos, bufsz - pos, "beacon_energy_a: %u\n",
+                        le32_to_cpu(general->beacon_energy_a));
+       pos += scnprintf(buf + pos, bufsz - pos, "beacon_energy_b: %u\n",
+                        le32_to_cpu(general->beacon_energy_b));
+       pos += scnprintf(buf + pos, bufsz - pos, "beacon_energy_c: %u\n",
+                        le32_to_cpu(general->beacon_energy_c));
+
+       pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM_HT:\n");
+       pos += scnprintf(buf + pos, bufsz - pos, "plcp_err: %u\n",
+                        le32_to_cpu(ht->plcp_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "overrun_err: %u\n",
+                        le32_to_cpu(ht->overrun_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "early_overrun_err: %u\n",
+                        le32_to_cpu(ht->early_overrun_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "crc32_good: %u\n",
+                        le32_to_cpu(ht->crc32_good));
+       pos += scnprintf(buf + pos, bufsz - pos, "crc32_err: %u\n",
+                        le32_to_cpu(ht->crc32_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "mh_format_err: %u\n",
+                        le32_to_cpu(ht->mh_format_err));
+       pos += scnprintf(buf + pos, bufsz - pos, "agg_crc32_good: %u\n",
+                        le32_to_cpu(ht->agg_crc32_good));
+       pos += scnprintf(buf + pos, bufsz - pos, "agg_mpdu_cnt: %u\n",
+                        le32_to_cpu(ht->agg_mpdu_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "agg_cnt: %u\n",
+                        le32_to_cpu(ht->agg_cnt));
+
+       ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
+       kfree(buf);
+       return ret;
+}
+
+static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
+                                       char __user *user_buf,
+                                       size_t count, loff_t *ppos)
+{
+       struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
+       int pos = 0;
+       char *buf;
+       int bufsz = (sizeof(struct statistics_tx) * 24) + 250;
+       ssize_t ret;
+       struct statistics_tx *tx;
+
+       if (!iwl_is_alive(priv))
+               return -EAGAIN;
+
+       /* make request to uCode to retrieve statistics information */
+       mutex_lock(&priv->mutex);
+       ret = iwl_send_statistics_request(priv, 0);
+       mutex_unlock(&priv->mutex);
+
+       if (ret) {
+               IWL_ERR(priv,
+                       "Error sending statistics request: %zd\n", ret);
+               return -EAGAIN;
+       }
+       buf = kzalloc(bufsz, GFP_KERNEL);
+       if (!buf) {
+               IWL_ERR(priv, "Can not allocate Buffer\n");
+               return -ENOMEM;
+       }
+
+       /* the statistic information display here is based on
+        * the last statistics notification from uCode
+        * might not reflect the current uCode activity
+        */
+       tx = &priv->statistics.tx;
+       pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
+       pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Tx:\n");
+       pos += scnprintf(buf + pos, bufsz - pos, "preamble: %u\n",
+                        le32_to_cpu(tx->preamble_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "rx_detected_cnt: %u\n",
+                        le32_to_cpu(tx->rx_detected_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "bt_prio_defer_cnt: %u\n",
+                        le32_to_cpu(tx->bt_prio_defer_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "bt_prio_kill_cnt: %u\n",
+                        le32_to_cpu(tx->bt_prio_kill_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "few_bytes_cnt: %u\n",
+                        le32_to_cpu(tx->few_bytes_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "cts_timeout: %u\n",
+                        le32_to_cpu(tx->cts_timeout));
+       pos += scnprintf(buf + pos, bufsz - pos, "ack_timeout: %u\n",
+                        le32_to_cpu(tx->ack_timeout));
+       pos += scnprintf(buf + pos, bufsz - pos, "expected_ack_cnt: %u\n",
+                        le32_to_cpu(tx->expected_ack_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "actual_ack_cnt: %u\n",
+                        le32_to_cpu(tx->actual_ack_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "dump_msdu_cnt: %u\n",
+                        le32_to_cpu(tx->dump_msdu_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "burst_abort_next_frame_mismatch_cnt: %u\n",
+                       le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "burst_abort_missing_next_frame_cnt: %u\n",
+                       le32_to_cpu(tx->burst_abort_missing_next_frame_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "cts_timeout_collision: %u\n",
+                        le32_to_cpu(tx->cts_timeout_collision));
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "ack_or_ba_timeout_collision: %u\n",
+                       le32_to_cpu(tx->ack_or_ba_timeout_collision));
+       pos += scnprintf(buf + pos, bufsz - pos, "agg ba_timeout: %u\n",
+                        le32_to_cpu(tx->agg.ba_timeout));
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "agg ba_reschedule_frames: %u\n",
+                       le32_to_cpu(tx->agg.ba_reschedule_frames));
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "agg scd_query_agg_frame_cnt: %u\n",
+                       le32_to_cpu(tx->agg.scd_query_agg_frame_cnt));
+       pos += scnprintf(buf + pos, bufsz - pos, "agg scd_query_no_agg: %u\n",
+                        le32_to_cpu(tx->agg.scd_query_no_agg));
+       pos += scnprintf(buf + pos, bufsz - pos, "agg scd_query_agg: %u\n",
+                        le32_to_cpu(tx->agg.scd_query_agg));
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "agg scd_query_mismatch: %u\n",
+                       le32_to_cpu(tx->agg.scd_query_mismatch));
+       pos += scnprintf(buf + pos, bufsz - pos, "agg frame_not_ready: %u\n",
+                        le32_to_cpu(tx->agg.frame_not_ready));
+       pos += scnprintf(buf + pos, bufsz - pos, "agg underrun: %u\n",
+                        le32_to_cpu(tx->agg.underrun));
+       pos += scnprintf(buf + pos, bufsz - pos, "agg bt_prio_kill: %u\n",
+                        le32_to_cpu(tx->agg.bt_prio_kill));
+       pos += scnprintf(buf + pos, bufsz - pos, "agg rx_ba_rsp_cnt: %u\n",
+                        le32_to_cpu(tx->agg.rx_ba_rsp_cnt));
+
+       ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
+       kfree(buf);
+       return ret;
+}
+
+static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
+                                       char __user *user_buf,
+                                       size_t count, loff_t *ppos)
+{
+       struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
+       int pos = 0;
+       char *buf;
+       int bufsz = sizeof(struct statistics_general) * 4 + 250;
+       ssize_t ret;
+       struct statistics_general *general;
+       struct statistics_dbg *dbg;
+       struct statistics_div *div;
+
+       if (!iwl_is_alive(priv))
+               return -EAGAIN;
+
+       /* make request to uCode to retrieve statistics information */
+       mutex_lock(&priv->mutex);
+       ret = iwl_send_statistics_request(priv, 0);
+       mutex_unlock(&priv->mutex);
+
+       if (ret) {
+               IWL_ERR(priv,
+                       "Error sending statistics request: %zd\n", ret);
+               return -EAGAIN;
+       }
+       buf = kzalloc(bufsz, GFP_KERNEL);
+       if (!buf) {
+               IWL_ERR(priv, "Can not allocate Buffer\n");
+               return -ENOMEM;
+       }
+
+       /* the statistic information display here is based on
+        * the last statistics notification from uCode
+        * might not reflect the current uCode activity
+        */
+       general = &priv->statistics.general;
+       dbg = &priv->statistics.general.dbg;
+       div = &priv->statistics.general.div;
+       pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
+       pos += scnprintf(buf + pos, bufsz - pos, "Statistics_General:\n");
+       pos += scnprintf(buf + pos, bufsz - pos, "temperature: %u\n",
+                        le32_to_cpu(general->temperature));
+       pos += scnprintf(buf + pos, bufsz - pos, "temperature_m: %u\n",
+                        le32_to_cpu(general->temperature_m));
+       pos += scnprintf(buf + pos, bufsz - pos, "burst_check: %u\n",
+                        le32_to_cpu(dbg->burst_check));
+       pos += scnprintf(buf + pos, bufsz - pos, "burst_count: %u\n",
+                        le32_to_cpu(dbg->burst_count));
+       pos += scnprintf(buf + pos, bufsz - pos, "sleep_time: %u\n",
+                        le32_to_cpu(general->sleep_time));
+       pos += scnprintf(buf + pos, bufsz - pos, "slots_out: %u\n",
+                        le32_to_cpu(general->slots_out));
+       pos += scnprintf(buf + pos, bufsz - pos, "slots_idle: %u\n",
+                        le32_to_cpu(general->slots_idle));
+       pos += scnprintf(buf + pos, bufsz - pos, "ttl_timestamp: %u\n",
+                        le32_to_cpu(general->ttl_timestamp));
+       pos += scnprintf(buf + pos, bufsz - pos, "tx_on_a: %u\n",
+                        le32_to_cpu(div->tx_on_a));
+       pos += scnprintf(buf + pos, bufsz - pos, "tx_on_b: %u\n",
+                        le32_to_cpu(div->tx_on_b));
+       pos += scnprintf(buf + pos, bufsz - pos, "exec_time: %u\n",
+                        le32_to_cpu(div->exec_time));
+       pos += scnprintf(buf + pos, bufsz - pos, "probe_time: %u\n",
+                        le32_to_cpu(div->probe_time));
+       pos += scnprintf(buf + pos, bufsz - pos, "rx_enable_counter: %u\n",
+                        le32_to_cpu(general->rx_enable_counter));
+       ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
+       kfree(buf);
+       return ret;
+}
+
+static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
+                                       char __user *user_buf,
+                                       size_t count, loff_t *ppos) {
+
+       struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
+       int pos = 0;
+       int cnt = 0;
+       char *buf;
+       int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
+       ssize_t ret;
+       struct iwl_sensitivity_data *data;
+
+       data = &priv->sensitivity_data;
+       buf = kzalloc(bufsz, GFP_KERNEL);
+       if (!buf) {
+               IWL_ERR(priv, "Can not allocate Buffer\n");
+               return -ENOMEM;
+       }
+
+       pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
+                       data->auto_corr_ofdm);
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "auto_corr_ofdm_mrc:\t\t %u\n",
+                       data->auto_corr_ofdm_mrc);
+       pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
+                       data->auto_corr_ofdm_x1);
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "auto_corr_ofdm_mrc_x1:\t\t %u\n",
+                       data->auto_corr_ofdm_mrc_x1);
+       pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
+                       data->auto_corr_cck);
+       pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
+                       data->auto_corr_cck_mrc);
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "last_bad_plcp_cnt_ofdm:\t\t %u\n",
+                       data->last_bad_plcp_cnt_ofdm);
+       pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
+                       data->last_fa_cnt_ofdm);
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "last_bad_plcp_cnt_cck:\t\t %u\n",
+                       data->last_bad_plcp_cnt_cck);
+       pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
+                       data->last_fa_cnt_cck);
+       pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
+                       data->nrg_curr_state);
+       pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
+                       data->nrg_prev_state);
+       pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
+       for (cnt = 0; cnt < 10; cnt++) {
+               pos += scnprintf(buf + pos, bufsz - pos, " %u",
+                               data->nrg_value[cnt]);
+       }
+       pos += scnprintf(buf + pos, bufsz - pos, "\n");
+       pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
+       for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
+               pos += scnprintf(buf + pos, bufsz - pos, " %u",
+                               data->nrg_silence_rssi[cnt]);
+       }
+       pos += scnprintf(buf + pos, bufsz - pos, "\n");
+       pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
+                       data->nrg_silence_ref);
+       pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
+                       data->nrg_energy_idx);
+       pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
+                       data->nrg_silence_idx);
+       pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
+                       data->nrg_th_cck);
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "nrg_auto_corr_silence_diff:\t %u\n",
+                       data->nrg_auto_corr_silence_diff);
+       pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
+                       data->num_in_cck_no_fa);
+       pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
+                       data->nrg_th_ofdm);
+
+       ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
+       kfree(buf);
+       return ret;
+}
+
+
+static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
+                                       char __user *user_buf,
+                                       size_t count, loff_t *ppos) {
+
+       struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
+       int pos = 0;
+       int cnt = 0;
+       char *buf;
+       int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
+       ssize_t ret;
+       struct iwl_chain_noise_data *data;
+
+       data = &priv->chain_noise_data;
+       buf = kzalloc(bufsz, GFP_KERNEL);
+       if (!buf) {
+               IWL_ERR(priv, "Can not allocate Buffer\n");
+               return -ENOMEM;
+       }
+
+       pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
+                       data->active_chains);
+       pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
+                       data->chain_noise_a);
+       pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
+                       data->chain_noise_b);
+       pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
+                       data->chain_noise_c);
+       pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
+                       data->chain_signal_a);
+       pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
+                       data->chain_signal_b);
+       pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
+                       data->chain_signal_c);
+       pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
+                       data->beacon_count);
+
+       pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
+       for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
+               pos += scnprintf(buf + pos, bufsz - pos, " %u",
+                               data->disconn_array[cnt]);
+       }
+       pos += scnprintf(buf + pos, bufsz - pos, "\n");
+       pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
+       for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
+               pos += scnprintf(buf + pos, bufsz - pos, " %u",
+                               data->delta_gain_code[cnt]);
+       }
+       pos += scnprintf(buf + pos, bufsz - pos, "\n");
+       pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
+                       data->radio_write);
+       pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
+                       data->state);
+
+       ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
+       kfree(buf);
+       return ret;
+}
+
+static ssize_t iwl_dbgfs_tx_power_read(struct file *file,
+                                       char __user *user_buf,
+                                       size_t count, loff_t *ppos) {
+
+       struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
+       char buf[128];
+       int pos = 0;
+       ssize_t ret;
+       const size_t bufsz = sizeof(buf);
+       struct statistics_tx *tx;
+
+       if (!iwl_is_alive(priv))
+               pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
+       else {
+               /* make request to uCode to retrieve statistics information */
+               mutex_lock(&priv->mutex);
+               ret = iwl_send_statistics_request(priv, 0);
+               mutex_unlock(&priv->mutex);
+
+               if (ret) {
+                       IWL_ERR(priv, "Error sending statistics request: %zd\n",
+                               ret);
+                       return -EAGAIN;
+               }
+               tx = &priv->statistics.tx;
+               if (tx->tx_power.ant_a ||
+                   tx->tx_power.ant_b ||
+                   tx->tx_power.ant_c) {
+                       pos += scnprintf(buf + pos, bufsz - pos,
+                               "tx power: (1/2 dB step)\n");
+                       if ((priv->cfg->valid_tx_ant & ANT_A) &&
+                           tx->tx_power.ant_a)
+                               pos += scnprintf(buf + pos, bufsz - pos,
+                                               "\tantenna A: 0x%X\n",
+                                               tx->tx_power.ant_a);
+                       if ((priv->cfg->valid_tx_ant & ANT_B) &&
+                           tx->tx_power.ant_b)
+                               pos += scnprintf(buf + pos, bufsz - pos,
+                                               "\tantenna B: 0x%X\n",
+                                               tx->tx_power.ant_b);
+                       if ((priv->cfg->valid_tx_ant & ANT_C) &&
+                           tx->tx_power.ant_c)
+                               pos += scnprintf(buf + pos, bufsz - pos,
+                                               "\tantenna C: 0x%X\n",
+                                               tx->tx_power.ant_c);
+               } else
+                       pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
+       }
+       return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
+}
+
 DEBUGFS_READ_WRITE_FILE_OPS(rx_statistics);
 DEBUGFS_READ_WRITE_FILE_OPS(tx_statistics);
 DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
 DEBUGFS_READ_FILE_OPS(rx_queue);
 DEBUGFS_READ_FILE_OPS(tx_queue);
+DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
+DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
+DEBUGFS_READ_FILE_OPS(ucode_general_stats);
+DEBUGFS_READ_FILE_OPS(sensitivity);
+DEBUGFS_READ_FILE_OPS(chain_noise);
+DEBUGFS_READ_FILE_OPS(tx_power);
 
 /*
  * Create the debugfs files and directories
@@ -994,6 +1664,8 @@ int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
 #ifdef CONFIG_IWLWIFI_LEDS
        DEBUGFS_ADD_FILE(led, data);
 #endif
+       DEBUGFS_ADD_FILE(sleep_level_override, data);
+       DEBUGFS_ADD_FILE(current_sleep_command, data);
        DEBUGFS_ADD_FILE(thermal_throttling, data);
        DEBUGFS_ADD_FILE(disable_ht40, data);
        DEBUGFS_ADD_FILE(rx_statistics, debug);
@@ -1001,6 +1673,14 @@ int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
        DEBUGFS_ADD_FILE(traffic_log, debug);
        DEBUGFS_ADD_FILE(rx_queue, debug);
        DEBUGFS_ADD_FILE(tx_queue, debug);
+       DEBUGFS_ADD_FILE(tx_power, debug);
+       if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
+               DEBUGFS_ADD_FILE(ucode_rx_stats, debug);
+               DEBUGFS_ADD_FILE(ucode_tx_stats, debug);
+               DEBUGFS_ADD_FILE(ucode_general_stats, debug);
+               DEBUGFS_ADD_FILE(sensitivity, debug);
+               DEBUGFS_ADD_FILE(chain_noise, debug);
+       }
        DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
        DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
                         &priv->disable_chain_noise_cal);
@@ -1026,6 +1706,8 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv)
        if (!priv->dbgfs)
                return;
 
+       DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sleep_level_override);
+       DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_current_sleep_command);
        DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_nvm);
        DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
        DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
@@ -1045,6 +1727,19 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv)
        DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_traffic_log);
        DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_queue);
        DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_queue);
+       DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_power);
+       if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
+               DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
+                       file_ucode_rx_stats);
+               DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
+                       file_ucode_tx_stats);
+               DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
+                       file_ucode_general_stats);
+               DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
+                       file_sensitivity);
+               DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
+                       file_chain_noise);
+       }
        DEBUGFS_REMOVE(priv->dbgfs->dir_debug);
        DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
        DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);