0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/ieee80211.h>
0011 #include <linux/export.h>
0012 #include <net/mac80211.h>
0013
0014 #include "common.h"
0015
0016 static void
0017 il_clear_traffic_stats(struct il_priv *il)
0018 {
0019 memset(&il->tx_stats, 0, sizeof(struct traffic_stats));
0020 memset(&il->rx_stats, 0, sizeof(struct traffic_stats));
0021 }
0022
0023
0024
0025
0026
0027 void
0028 il_update_stats(struct il_priv *il, bool is_tx, __le16 fc, u16 len)
0029 {
0030 struct traffic_stats *stats;
0031
0032 if (is_tx)
0033 stats = &il->tx_stats;
0034 else
0035 stats = &il->rx_stats;
0036
0037 if (ieee80211_is_mgmt(fc)) {
0038 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
0039 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
0040 stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
0041 break;
0042 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
0043 stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
0044 break;
0045 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
0046 stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
0047 break;
0048 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
0049 stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
0050 break;
0051 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
0052 stats->mgmt[MANAGEMENT_PROBE_REQ]++;
0053 break;
0054 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
0055 stats->mgmt[MANAGEMENT_PROBE_RESP]++;
0056 break;
0057 case cpu_to_le16(IEEE80211_STYPE_BEACON):
0058 stats->mgmt[MANAGEMENT_BEACON]++;
0059 break;
0060 case cpu_to_le16(IEEE80211_STYPE_ATIM):
0061 stats->mgmt[MANAGEMENT_ATIM]++;
0062 break;
0063 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
0064 stats->mgmt[MANAGEMENT_DISASSOC]++;
0065 break;
0066 case cpu_to_le16(IEEE80211_STYPE_AUTH):
0067 stats->mgmt[MANAGEMENT_AUTH]++;
0068 break;
0069 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
0070 stats->mgmt[MANAGEMENT_DEAUTH]++;
0071 break;
0072 case cpu_to_le16(IEEE80211_STYPE_ACTION):
0073 stats->mgmt[MANAGEMENT_ACTION]++;
0074 break;
0075 }
0076 } else if (ieee80211_is_ctl(fc)) {
0077 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
0078 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
0079 stats->ctrl[CONTROL_BACK_REQ]++;
0080 break;
0081 case cpu_to_le16(IEEE80211_STYPE_BACK):
0082 stats->ctrl[CONTROL_BACK]++;
0083 break;
0084 case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
0085 stats->ctrl[CONTROL_PSPOLL]++;
0086 break;
0087 case cpu_to_le16(IEEE80211_STYPE_RTS):
0088 stats->ctrl[CONTROL_RTS]++;
0089 break;
0090 case cpu_to_le16(IEEE80211_STYPE_CTS):
0091 stats->ctrl[CONTROL_CTS]++;
0092 break;
0093 case cpu_to_le16(IEEE80211_STYPE_ACK):
0094 stats->ctrl[CONTROL_ACK]++;
0095 break;
0096 case cpu_to_le16(IEEE80211_STYPE_CFEND):
0097 stats->ctrl[CONTROL_CFEND]++;
0098 break;
0099 case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
0100 stats->ctrl[CONTROL_CFENDACK]++;
0101 break;
0102 }
0103 } else {
0104
0105 stats->data_cnt++;
0106 stats->data_bytes += len;
0107 }
0108 }
0109 EXPORT_SYMBOL(il_update_stats);
0110
0111
0112 #define DEBUGFS_ADD_FILE(name, parent, mode) do { \
0113 debugfs_create_file(#name, mode, parent, il, \
0114 &il_dbgfs_##name##_ops); \
0115 } while (0)
0116
0117 #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
0118 debugfs_create_bool(#name, 0600, parent, ptr); \
0119 } while (0)
0120
0121
0122 #define DEBUGFS_READ_FUNC(name) \
0123 static ssize_t il_dbgfs_##name##_read(struct file *file, \
0124 char __user *user_buf, \
0125 size_t count, loff_t *ppos);
0126
0127 #define DEBUGFS_WRITE_FUNC(name) \
0128 static ssize_t il_dbgfs_##name##_write(struct file *file, \
0129 const char __user *user_buf, \
0130 size_t count, loff_t *ppos);
0131
0132
0133 #define DEBUGFS_READ_FILE_OPS(name) \
0134 DEBUGFS_READ_FUNC(name); \
0135 static const struct file_operations il_dbgfs_##name##_ops = { \
0136 .read = il_dbgfs_##name##_read, \
0137 .open = simple_open, \
0138 .llseek = generic_file_llseek, \
0139 };
0140
0141 #define DEBUGFS_WRITE_FILE_OPS(name) \
0142 DEBUGFS_WRITE_FUNC(name); \
0143 static const struct file_operations il_dbgfs_##name##_ops = { \
0144 .write = il_dbgfs_##name##_write, \
0145 .open = simple_open, \
0146 .llseek = generic_file_llseek, \
0147 };
0148
0149 #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
0150 DEBUGFS_READ_FUNC(name); \
0151 DEBUGFS_WRITE_FUNC(name); \
0152 static const struct file_operations il_dbgfs_##name##_ops = { \
0153 .write = il_dbgfs_##name##_write, \
0154 .read = il_dbgfs_##name##_read, \
0155 .open = simple_open, \
0156 .llseek = generic_file_llseek, \
0157 };
0158
0159 static const char *
0160 il_get_mgmt_string(int cmd)
0161 {
0162 switch (cmd) {
0163 IL_CMD(MANAGEMENT_ASSOC_REQ);
0164 IL_CMD(MANAGEMENT_ASSOC_RESP);
0165 IL_CMD(MANAGEMENT_REASSOC_REQ);
0166 IL_CMD(MANAGEMENT_REASSOC_RESP);
0167 IL_CMD(MANAGEMENT_PROBE_REQ);
0168 IL_CMD(MANAGEMENT_PROBE_RESP);
0169 IL_CMD(MANAGEMENT_BEACON);
0170 IL_CMD(MANAGEMENT_ATIM);
0171 IL_CMD(MANAGEMENT_DISASSOC);
0172 IL_CMD(MANAGEMENT_AUTH);
0173 IL_CMD(MANAGEMENT_DEAUTH);
0174 IL_CMD(MANAGEMENT_ACTION);
0175 default:
0176 return "UNKNOWN";
0177
0178 }
0179 }
0180
0181 static const char *
0182 il_get_ctrl_string(int cmd)
0183 {
0184 switch (cmd) {
0185 IL_CMD(CONTROL_BACK_REQ);
0186 IL_CMD(CONTROL_BACK);
0187 IL_CMD(CONTROL_PSPOLL);
0188 IL_CMD(CONTROL_RTS);
0189 IL_CMD(CONTROL_CTS);
0190 IL_CMD(CONTROL_ACK);
0191 IL_CMD(CONTROL_CFEND);
0192 IL_CMD(CONTROL_CFENDACK);
0193 default:
0194 return "UNKNOWN";
0195
0196 }
0197 }
0198
0199 static ssize_t
0200 il_dbgfs_tx_stats_read(struct file *file, char __user *user_buf, size_t count,
0201 loff_t *ppos)
0202 {
0203
0204 struct il_priv *il = file->private_data;
0205 char *buf;
0206 int pos = 0;
0207
0208 int cnt;
0209 ssize_t ret;
0210 const size_t bufsz =
0211 100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
0212 buf = kzalloc(bufsz, GFP_KERNEL);
0213 if (!buf)
0214 return -ENOMEM;
0215 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
0216 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
0217 pos +=
0218 scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
0219 il_get_mgmt_string(cnt), il->tx_stats.mgmt[cnt]);
0220 }
0221 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
0222 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
0223 pos +=
0224 scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
0225 il_get_ctrl_string(cnt), il->tx_stats.ctrl[cnt]);
0226 }
0227 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
0228 pos +=
0229 scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
0230 il->tx_stats.data_cnt);
0231 pos +=
0232 scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
0233 il->tx_stats.data_bytes);
0234 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
0235 kfree(buf);
0236 return ret;
0237 }
0238
0239 static ssize_t
0240 il_dbgfs_clear_traffic_stats_write(struct file *file,
0241 const char __user *user_buf, size_t count,
0242 loff_t *ppos)
0243 {
0244 struct il_priv *il = file->private_data;
0245 u32 clear_flag;
0246 char buf[8];
0247 int buf_size;
0248
0249 memset(buf, 0, sizeof(buf));
0250 buf_size = min(count, sizeof(buf) - 1);
0251 if (copy_from_user(buf, user_buf, buf_size))
0252 return -EFAULT;
0253 if (sscanf(buf, "%x", &clear_flag) != 1)
0254 return -EFAULT;
0255 il_clear_traffic_stats(il);
0256
0257 return count;
0258 }
0259
0260 static ssize_t
0261 il_dbgfs_rx_stats_read(struct file *file, char __user *user_buf, size_t count,
0262 loff_t *ppos)
0263 {
0264
0265 struct il_priv *il = file->private_data;
0266 char *buf;
0267 int pos = 0;
0268 int cnt;
0269 ssize_t ret;
0270 const size_t bufsz =
0271 100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
0272 buf = kzalloc(bufsz, GFP_KERNEL);
0273 if (!buf)
0274 return -ENOMEM;
0275
0276 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
0277 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
0278 pos +=
0279 scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
0280 il_get_mgmt_string(cnt), il->rx_stats.mgmt[cnt]);
0281 }
0282 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
0283 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
0284 pos +=
0285 scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
0286 il_get_ctrl_string(cnt), il->rx_stats.ctrl[cnt]);
0287 }
0288 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
0289 pos +=
0290 scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
0291 il->rx_stats.data_cnt);
0292 pos +=
0293 scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
0294 il->rx_stats.data_bytes);
0295
0296 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
0297 kfree(buf);
0298 return ret;
0299 }
0300
0301 #define BYTE1_MASK 0x000000ff;
0302 #define BYTE2_MASK 0x0000ffff;
0303 #define BYTE3_MASK 0x00ffffff;
0304 static ssize_t
0305 il_dbgfs_sram_read(struct file *file, char __user *user_buf, size_t count,
0306 loff_t *ppos)
0307 {
0308 u32 val;
0309 char *buf;
0310 ssize_t ret;
0311 int i;
0312 int pos = 0;
0313 struct il_priv *il = file->private_data;
0314 size_t bufsz;
0315
0316
0317 if (!il->dbgfs_sram_offset && !il->dbgfs_sram_len) {
0318 il->dbgfs_sram_offset = 0x800000;
0319 if (il->ucode_type == UCODE_INIT)
0320 il->dbgfs_sram_len = il->ucode_init_data.len;
0321 else
0322 il->dbgfs_sram_len = il->ucode_data.len;
0323 }
0324 bufsz = 30 + il->dbgfs_sram_len * sizeof(char) * 10;
0325 buf = kmalloc(bufsz, GFP_KERNEL);
0326 if (!buf)
0327 return -ENOMEM;
0328 pos +=
0329 scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
0330 il->dbgfs_sram_len);
0331 pos +=
0332 scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
0333 il->dbgfs_sram_offset);
0334 for (i = il->dbgfs_sram_len; i > 0; i -= 4) {
0335 val =
0336 il_read_targ_mem(il,
0337 il->dbgfs_sram_offset +
0338 il->dbgfs_sram_len - i);
0339 if (i < 4) {
0340 switch (i) {
0341 case 1:
0342 val &= BYTE1_MASK;
0343 break;
0344 case 2:
0345 val &= BYTE2_MASK;
0346 break;
0347 case 3:
0348 val &= BYTE3_MASK;
0349 break;
0350 }
0351 }
0352 if (!(i % 16))
0353 pos += scnprintf(buf + pos, bufsz - pos, "\n");
0354 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
0355 }
0356 pos += scnprintf(buf + pos, bufsz - pos, "\n");
0357
0358 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
0359 kfree(buf);
0360 return ret;
0361 }
0362
0363 static ssize_t
0364 il_dbgfs_sram_write(struct file *file, const char __user *user_buf,
0365 size_t count, loff_t *ppos)
0366 {
0367 struct il_priv *il = file->private_data;
0368 char buf[64];
0369 int buf_size;
0370 u32 offset, len;
0371
0372 memset(buf, 0, sizeof(buf));
0373 buf_size = min(count, sizeof(buf) - 1);
0374 if (copy_from_user(buf, user_buf, buf_size))
0375 return -EFAULT;
0376
0377 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
0378 il->dbgfs_sram_offset = offset;
0379 il->dbgfs_sram_len = len;
0380 } else {
0381 il->dbgfs_sram_offset = 0;
0382 il->dbgfs_sram_len = 0;
0383 }
0384
0385 return count;
0386 }
0387
0388 static ssize_t
0389 il_dbgfs_stations_read(struct file *file, char __user *user_buf, size_t count,
0390 loff_t *ppos)
0391 {
0392 struct il_priv *il = file->private_data;
0393 struct il_station_entry *station;
0394 int max_sta = il->hw_params.max_stations;
0395 char *buf;
0396 int i, j, pos = 0;
0397 ssize_t ret;
0398
0399 const size_t bufsz = 30 + sizeof(char) * 500 * (il->num_stations);
0400
0401 buf = kmalloc(bufsz, GFP_KERNEL);
0402 if (!buf)
0403 return -ENOMEM;
0404
0405 pos +=
0406 scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
0407 il->num_stations);
0408
0409 for (i = 0; i < max_sta; i++) {
0410 station = &il->stations[i];
0411 if (!station->used)
0412 continue;
0413 pos +=
0414 scnprintf(buf + pos, bufsz - pos,
0415 "station %d - addr: %pM, flags: %#x\n", i,
0416 station->sta.sta.addr,
0417 station->sta.station_flags_msk);
0418 pos +=
0419 scnprintf(buf + pos, bufsz - pos,
0420 "TID\tseq_num\ttxq_id\tframes\ttfds\t");
0421 pos +=
0422 scnprintf(buf + pos, bufsz - pos,
0423 "start_idx\tbitmap\t\t\trate_n_flags\n");
0424
0425 for (j = 0; j < MAX_TID_COUNT; j++) {
0426 pos +=
0427 scnprintf(buf + pos, bufsz - pos,
0428 "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
0429 j, station->tid[j].seq_number,
0430 station->tid[j].agg.txq_id,
0431 station->tid[j].agg.frame_count,
0432 station->tid[j].tfds_in_queue,
0433 station->tid[j].agg.start_idx,
0434 station->tid[j].agg.bitmap,
0435 station->tid[j].agg.rate_n_flags);
0436
0437 if (station->tid[j].agg.wait_for_ba)
0438 pos +=
0439 scnprintf(buf + pos, bufsz - pos,
0440 " - waitforba");
0441 pos += scnprintf(buf + pos, bufsz - pos, "\n");
0442 }
0443
0444 pos += scnprintf(buf + pos, bufsz - pos, "\n");
0445 }
0446
0447 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
0448 kfree(buf);
0449 return ret;
0450 }
0451
0452 static ssize_t
0453 il_dbgfs_nvm_read(struct file *file, char __user *user_buf, size_t count,
0454 loff_t *ppos)
0455 {
0456 ssize_t ret;
0457 struct il_priv *il = file->private_data;
0458 int pos = 0, ofs = 0, buf_size = 0;
0459 const u8 *ptr;
0460 char *buf;
0461 u16 eeprom_ver;
0462 size_t eeprom_len = il->cfg->eeprom_size;
0463 buf_size = 4 * eeprom_len + 256;
0464
0465 if (eeprom_len % 16) {
0466 IL_ERR("NVM size is not multiple of 16.\n");
0467 return -ENODATA;
0468 }
0469
0470 ptr = il->eeprom;
0471 if (!ptr) {
0472 IL_ERR("Invalid EEPROM memory\n");
0473 return -ENOMEM;
0474 }
0475
0476
0477 buf = kzalloc(buf_size, GFP_KERNEL);
0478 if (!buf) {
0479 IL_ERR("Can not allocate Buffer\n");
0480 return -ENOMEM;
0481 }
0482 eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION);
0483 pos +=
0484 scnprintf(buf + pos, buf_size - pos, "EEPROM " "version: 0x%x\n",
0485 eeprom_ver);
0486 for (ofs = 0; ofs < eeprom_len; ofs += 16) {
0487 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x %16ph\n",
0488 ofs, ptr + ofs);
0489 }
0490
0491 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
0492 kfree(buf);
0493 return ret;
0494 }
0495
0496 static ssize_t
0497 il_dbgfs_channels_read(struct file *file, char __user *user_buf, size_t count,
0498 loff_t *ppos)
0499 {
0500 struct il_priv *il = file->private_data;
0501 struct ieee80211_channel *channels = NULL;
0502 const struct ieee80211_supported_band *supp_band = NULL;
0503 int pos = 0, i, bufsz = PAGE_SIZE;
0504 char *buf;
0505 ssize_t ret;
0506
0507 if (!test_bit(S_GEO_CONFIGURED, &il->status))
0508 return -EAGAIN;
0509
0510 buf = kzalloc(bufsz, GFP_KERNEL);
0511 if (!buf) {
0512 IL_ERR("Can not allocate Buffer\n");
0513 return -ENOMEM;
0514 }
0515
0516 supp_band = il_get_hw_mode(il, NL80211_BAND_2GHZ);
0517 if (supp_band) {
0518 channels = supp_band->channels;
0519
0520 pos +=
0521 scnprintf(buf + pos, bufsz - pos,
0522 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
0523 supp_band->n_channels);
0524
0525 for (i = 0; i < supp_band->n_channels; i++)
0526 pos +=
0527 scnprintf(buf + pos, bufsz - pos,
0528 "%d: %ddBm: BSS%s%s, %s.\n",
0529 channels[i].hw_value,
0530 channels[i].max_power,
0531 channels[i].
0532 flags & IEEE80211_CHAN_RADAR ?
0533 " (IEEE 802.11h required)" : "",
0534 ((channels[i].
0535 flags & IEEE80211_CHAN_NO_IR) ||
0536 (channels[i].
0537 flags & IEEE80211_CHAN_RADAR)) ? "" :
0538 ", IBSS",
0539 channels[i].
0540 flags & IEEE80211_CHAN_NO_IR ?
0541 "passive only" : "active/passive");
0542 }
0543 supp_band = il_get_hw_mode(il, NL80211_BAND_5GHZ);
0544 if (supp_band) {
0545 channels = supp_band->channels;
0546
0547 pos +=
0548 scnprintf(buf + pos, bufsz - pos,
0549 "Displaying %d channels in 5.2GHz band (802.11a)\n",
0550 supp_band->n_channels);
0551
0552 for (i = 0; i < supp_band->n_channels; i++)
0553 pos +=
0554 scnprintf(buf + pos, bufsz - pos,
0555 "%d: %ddBm: BSS%s%s, %s.\n",
0556 channels[i].hw_value,
0557 channels[i].max_power,
0558 channels[i].
0559 flags & IEEE80211_CHAN_RADAR ?
0560 " (IEEE 802.11h required)" : "",
0561 ((channels[i].
0562 flags & IEEE80211_CHAN_NO_IR) ||
0563 (channels[i].
0564 flags & IEEE80211_CHAN_RADAR)) ? "" :
0565 ", IBSS",
0566 channels[i].
0567 flags & IEEE80211_CHAN_NO_IR ?
0568 "passive only" : "active/passive");
0569 }
0570 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
0571 kfree(buf);
0572 return ret;
0573 }
0574
0575 static ssize_t
0576 il_dbgfs_status_read(struct file *file, char __user *user_buf, size_t count,
0577 loff_t *ppos)
0578 {
0579
0580 struct il_priv *il = file->private_data;
0581 char buf[512];
0582 int pos = 0;
0583 const size_t bufsz = sizeof(buf);
0584
0585 pos +=
0586 scnprintf(buf + pos, bufsz - pos, "S_HCMD_ACTIVE:\t %d\n",
0587 test_bit(S_HCMD_ACTIVE, &il->status));
0588 pos +=
0589 scnprintf(buf + pos, bufsz - pos, "S_INT_ENABLED:\t %d\n",
0590 test_bit(S_INT_ENABLED, &il->status));
0591 pos +=
0592 scnprintf(buf + pos, bufsz - pos, "S_RFKILL:\t %d\n",
0593 test_bit(S_RFKILL, &il->status));
0594 pos +=
0595 scnprintf(buf + pos, bufsz - pos, "S_CT_KILL:\t\t %d\n",
0596 test_bit(S_CT_KILL, &il->status));
0597 pos +=
0598 scnprintf(buf + pos, bufsz - pos, "S_INIT:\t\t %d\n",
0599 test_bit(S_INIT, &il->status));
0600 pos +=
0601 scnprintf(buf + pos, bufsz - pos, "S_ALIVE:\t\t %d\n",
0602 test_bit(S_ALIVE, &il->status));
0603 pos +=
0604 scnprintf(buf + pos, bufsz - pos, "S_READY:\t\t %d\n",
0605 test_bit(S_READY, &il->status));
0606 pos +=
0607 scnprintf(buf + pos, bufsz - pos, "S_TEMPERATURE:\t %d\n",
0608 test_bit(S_TEMPERATURE, &il->status));
0609 pos +=
0610 scnprintf(buf + pos, bufsz - pos, "S_GEO_CONFIGURED:\t %d\n",
0611 test_bit(S_GEO_CONFIGURED, &il->status));
0612 pos +=
0613 scnprintf(buf + pos, bufsz - pos, "S_EXIT_PENDING:\t %d\n",
0614 test_bit(S_EXIT_PENDING, &il->status));
0615 pos +=
0616 scnprintf(buf + pos, bufsz - pos, "S_STATS:\t %d\n",
0617 test_bit(S_STATS, &il->status));
0618 pos +=
0619 scnprintf(buf + pos, bufsz - pos, "S_SCANNING:\t %d\n",
0620 test_bit(S_SCANNING, &il->status));
0621 pos +=
0622 scnprintf(buf + pos, bufsz - pos, "S_SCAN_ABORTING:\t %d\n",
0623 test_bit(S_SCAN_ABORTING, &il->status));
0624 pos +=
0625 scnprintf(buf + pos, bufsz - pos, "S_SCAN_HW:\t\t %d\n",
0626 test_bit(S_SCAN_HW, &il->status));
0627 pos +=
0628 scnprintf(buf + pos, bufsz - pos, "S_POWER_PMI:\t %d\n",
0629 test_bit(S_POWER_PMI, &il->status));
0630 pos +=
0631 scnprintf(buf + pos, bufsz - pos, "S_FW_ERROR:\t %d\n",
0632 test_bit(S_FW_ERROR, &il->status));
0633 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
0634 }
0635
0636 static ssize_t
0637 il_dbgfs_interrupt_read(struct file *file, char __user *user_buf, size_t count,
0638 loff_t *ppos)
0639 {
0640
0641 struct il_priv *il = file->private_data;
0642 int pos = 0;
0643 int cnt = 0;
0644 char *buf;
0645 int bufsz = 24 * 64;
0646 ssize_t ret;
0647
0648 buf = kzalloc(bufsz, GFP_KERNEL);
0649 if (!buf) {
0650 IL_ERR("Can not allocate Buffer\n");
0651 return -ENOMEM;
0652 }
0653
0654 pos +=
0655 scnprintf(buf + pos, bufsz - pos, "Interrupt Statistics Report:\n");
0656
0657 pos +=
0658 scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
0659 il->isr_stats.hw);
0660 pos +=
0661 scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
0662 il->isr_stats.sw);
0663 if (il->isr_stats.sw || il->isr_stats.hw) {
0664 pos +=
0665 scnprintf(buf + pos, bufsz - pos,
0666 "\tLast Restarting Code: 0x%X\n",
0667 il->isr_stats.err_code);
0668 }
0669 #ifdef CONFIG_IWLEGACY_DEBUG
0670 pos +=
0671 scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
0672 il->isr_stats.sch);
0673 pos +=
0674 scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
0675 il->isr_stats.alive);
0676 #endif
0677 pos +=
0678 scnprintf(buf + pos, bufsz - pos,
0679 "HW RF KILL switch toggled:\t %u\n",
0680 il->isr_stats.rfkill);
0681
0682 pos +=
0683 scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
0684 il->isr_stats.ctkill);
0685
0686 pos +=
0687 scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
0688 il->isr_stats.wakeup);
0689
0690 pos +=
0691 scnprintf(buf + pos, bufsz - pos, "Rx command responses:\t\t %u\n",
0692 il->isr_stats.rx);
0693 for (cnt = 0; cnt < IL_CN_MAX; cnt++) {
0694 if (il->isr_stats.handlers[cnt] > 0)
0695 pos +=
0696 scnprintf(buf + pos, bufsz - pos,
0697 "\tRx handler[%36s]:\t\t %u\n",
0698 il_get_cmd_string(cnt),
0699 il->isr_stats.handlers[cnt]);
0700 }
0701
0702 pos +=
0703 scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
0704 il->isr_stats.tx);
0705
0706 pos +=
0707 scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
0708 il->isr_stats.unhandled);
0709
0710 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
0711 kfree(buf);
0712 return ret;
0713 }
0714
0715 static ssize_t
0716 il_dbgfs_interrupt_write(struct file *file, const char __user *user_buf,
0717 size_t count, loff_t *ppos)
0718 {
0719 struct il_priv *il = file->private_data;
0720 char buf[8];
0721 int buf_size;
0722 u32 reset_flag;
0723
0724 memset(buf, 0, sizeof(buf));
0725 buf_size = min(count, sizeof(buf) - 1);
0726 if (copy_from_user(buf, user_buf, buf_size))
0727 return -EFAULT;
0728 if (sscanf(buf, "%x", &reset_flag) != 1)
0729 return -EFAULT;
0730 if (reset_flag == 0)
0731 il_clear_isr_stats(il);
0732
0733 return count;
0734 }
0735
0736 static ssize_t
0737 il_dbgfs_qos_read(struct file *file, char __user *user_buf, size_t count,
0738 loff_t *ppos)
0739 {
0740 struct il_priv *il = file->private_data;
0741 int pos = 0, i;
0742 char buf[256];
0743 const size_t bufsz = sizeof(buf);
0744
0745 for (i = 0; i < AC_NUM; i++) {
0746 pos +=
0747 scnprintf(buf + pos, bufsz - pos,
0748 "\tcw_min\tcw_max\taifsn\ttxop\n");
0749 pos +=
0750 scnprintf(buf + pos, bufsz - pos,
0751 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
0752 il->qos_data.def_qos_parm.ac[i].cw_min,
0753 il->qos_data.def_qos_parm.ac[i].cw_max,
0754 il->qos_data.def_qos_parm.ac[i].aifsn,
0755 il->qos_data.def_qos_parm.ac[i].edca_txop);
0756 }
0757
0758 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
0759 }
0760
0761 static ssize_t
0762 il_dbgfs_disable_ht40_write(struct file *file, const char __user *user_buf,
0763 size_t count, loff_t *ppos)
0764 {
0765 struct il_priv *il = file->private_data;
0766 char buf[8];
0767 int buf_size;
0768 int ht40;
0769
0770 memset(buf, 0, sizeof(buf));
0771 buf_size = min(count, sizeof(buf) - 1);
0772 if (copy_from_user(buf, user_buf, buf_size))
0773 return -EFAULT;
0774 if (sscanf(buf, "%d", &ht40) != 1)
0775 return -EFAULT;
0776 if (!il_is_any_associated(il))
0777 il->disable_ht40 = ht40 ? true : false;
0778 else {
0779 IL_ERR("Sta associated with AP - "
0780 "Change to 40MHz channel support is not allowed\n");
0781 return -EINVAL;
0782 }
0783
0784 return count;
0785 }
0786
0787 static ssize_t
0788 il_dbgfs_disable_ht40_read(struct file *file, char __user *user_buf,
0789 size_t count, loff_t *ppos)
0790 {
0791 struct il_priv *il = file->private_data;
0792 char buf[100];
0793 int pos = 0;
0794 const size_t bufsz = sizeof(buf);
0795
0796 pos +=
0797 scnprintf(buf + pos, bufsz - pos, "11n 40MHz Mode: %s\n",
0798 il->disable_ht40 ? "Disabled" : "Enabled");
0799 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
0800 }
0801
0802 DEBUGFS_READ_WRITE_FILE_OPS(sram);
0803 DEBUGFS_READ_FILE_OPS(nvm);
0804 DEBUGFS_READ_FILE_OPS(stations);
0805 DEBUGFS_READ_FILE_OPS(channels);
0806 DEBUGFS_READ_FILE_OPS(status);
0807 DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
0808 DEBUGFS_READ_FILE_OPS(qos);
0809 DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
0810
0811 static ssize_t
0812 il_dbgfs_tx_queue_read(struct file *file, char __user *user_buf, size_t count,
0813 loff_t *ppos)
0814 {
0815
0816 struct il_priv *il = file->private_data;
0817 struct il_tx_queue *txq;
0818 struct il_queue *q;
0819 char *buf;
0820 int pos = 0;
0821 int cnt;
0822 int ret;
0823 const size_t bufsz =
0824 sizeof(char) * 64 * il->cfg->num_of_queues;
0825
0826 if (!il->txq) {
0827 IL_ERR("txq not ready\n");
0828 return -EAGAIN;
0829 }
0830 buf = kzalloc(bufsz, GFP_KERNEL);
0831 if (!buf)
0832 return -ENOMEM;
0833
0834 for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
0835 txq = &il->txq[cnt];
0836 q = &txq->q;
0837 pos +=
0838 scnprintf(buf + pos, bufsz - pos,
0839 "hwq %.2d: read=%u write=%u stop=%d"
0840 " swq_id=%#.2x (ac %d/hwq %d)\n", cnt,
0841 q->read_ptr, q->write_ptr,
0842 !!test_bit(cnt, il->queue_stopped),
0843 txq->swq_id, txq->swq_id & 3,
0844 (txq->swq_id >> 2) & 0x1f);
0845 if (cnt >= 4)
0846 continue;
0847
0848 pos +=
0849 scnprintf(buf + pos, bufsz - pos,
0850 " stop-count: %d\n",
0851 atomic_read(&il->queue_stop_count[cnt]));
0852 }
0853 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
0854 kfree(buf);
0855 return ret;
0856 }
0857
0858 static ssize_t
0859 il_dbgfs_rx_queue_read(struct file *file, char __user *user_buf, size_t count,
0860 loff_t *ppos)
0861 {
0862
0863 struct il_priv *il = file->private_data;
0864 struct il_rx_queue *rxq = &il->rxq;
0865 char buf[256];
0866 int pos = 0;
0867 const size_t bufsz = sizeof(buf);
0868
0869 pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n", rxq->read);
0870 pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n", rxq->write);
0871 pos +=
0872 scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
0873 rxq->free_count);
0874 if (rxq->rb_stts) {
0875 pos +=
0876 scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
0877 le16_to_cpu(rxq->rb_stts->
0878 closed_rb_num) & 0x0FFF);
0879 } else {
0880 pos +=
0881 scnprintf(buf + pos, bufsz - pos,
0882 "closed_rb_num: Not Allocated\n");
0883 }
0884 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
0885 }
0886
0887 static ssize_t
0888 il_dbgfs_ucode_rx_stats_read(struct file *file, char __user *user_buf,
0889 size_t count, loff_t *ppos)
0890 {
0891 struct il_priv *il = file->private_data;
0892
0893 return il->debugfs_ops->rx_stats_read(file, user_buf, count, ppos);
0894 }
0895
0896 static ssize_t
0897 il_dbgfs_ucode_tx_stats_read(struct file *file, char __user *user_buf,
0898 size_t count, loff_t *ppos)
0899 {
0900 struct il_priv *il = file->private_data;
0901
0902 return il->debugfs_ops->tx_stats_read(file, user_buf, count, ppos);
0903 }
0904
0905 static ssize_t
0906 il_dbgfs_ucode_general_stats_read(struct file *file, char __user *user_buf,
0907 size_t count, loff_t *ppos)
0908 {
0909 struct il_priv *il = file->private_data;
0910
0911 return il->debugfs_ops->general_stats_read(file, user_buf, count, ppos);
0912 }
0913
0914 static ssize_t
0915 il_dbgfs_sensitivity_read(struct file *file, char __user *user_buf,
0916 size_t count, loff_t *ppos)
0917 {
0918
0919 struct il_priv *il = file->private_data;
0920 int pos = 0;
0921 int cnt = 0;
0922 char *buf;
0923 int bufsz = sizeof(struct il_sensitivity_data) * 4 + 100;
0924 ssize_t ret;
0925 struct il_sensitivity_data *data;
0926
0927 data = &il->sensitivity_data;
0928 buf = kzalloc(bufsz, GFP_KERNEL);
0929 if (!buf) {
0930 IL_ERR("Can not allocate Buffer\n");
0931 return -ENOMEM;
0932 }
0933
0934 pos +=
0935 scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
0936 data->auto_corr_ofdm);
0937 pos +=
0938 scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_mrc:\t\t %u\n",
0939 data->auto_corr_ofdm_mrc);
0940 pos +=
0941 scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
0942 data->auto_corr_ofdm_x1);
0943 pos +=
0944 scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_mrc_x1:\t\t %u\n",
0945 data->auto_corr_ofdm_mrc_x1);
0946 pos +=
0947 scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
0948 data->auto_corr_cck);
0949 pos +=
0950 scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
0951 data->auto_corr_cck_mrc);
0952 pos +=
0953 scnprintf(buf + pos, bufsz - pos,
0954 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
0955 data->last_bad_plcp_cnt_ofdm);
0956 pos +=
0957 scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
0958 data->last_fa_cnt_ofdm);
0959 pos +=
0960 scnprintf(buf + pos, bufsz - pos, "last_bad_plcp_cnt_cck:\t\t %u\n",
0961 data->last_bad_plcp_cnt_cck);
0962 pos +=
0963 scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
0964 data->last_fa_cnt_cck);
0965 pos +=
0966 scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
0967 data->nrg_curr_state);
0968 pos +=
0969 scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
0970 data->nrg_prev_state);
0971 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
0972 for (cnt = 0; cnt < 10; cnt++) {
0973 pos +=
0974 scnprintf(buf + pos, bufsz - pos, " %u",
0975 data->nrg_value[cnt]);
0976 }
0977 pos += scnprintf(buf + pos, bufsz - pos, "\n");
0978 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
0979 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
0980 pos +=
0981 scnprintf(buf + pos, bufsz - pos, " %u",
0982 data->nrg_silence_rssi[cnt]);
0983 }
0984 pos += scnprintf(buf + pos, bufsz - pos, "\n");
0985 pos +=
0986 scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
0987 data->nrg_silence_ref);
0988 pos +=
0989 scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
0990 data->nrg_energy_idx);
0991 pos +=
0992 scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
0993 data->nrg_silence_idx);
0994 pos +=
0995 scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
0996 data->nrg_th_cck);
0997 pos +=
0998 scnprintf(buf + pos, bufsz - pos,
0999 "nrg_auto_corr_silence_diff:\t %u\n",
1000 data->nrg_auto_corr_silence_diff);
1001 pos +=
1002 scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1003 data->num_in_cck_no_fa);
1004 pos +=
1005 scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1006 data->nrg_th_ofdm);
1007
1008 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1009 kfree(buf);
1010 return ret;
1011 }
1012
1013 static ssize_t
1014 il_dbgfs_chain_noise_read(struct file *file, char __user *user_buf,
1015 size_t count, loff_t *ppos)
1016 {
1017
1018 struct il_priv *il = file->private_data;
1019 int pos = 0;
1020 int cnt = 0;
1021 char *buf;
1022 int bufsz = sizeof(struct il_chain_noise_data) * 4 + 100;
1023 ssize_t ret;
1024 struct il_chain_noise_data *data;
1025
1026 data = &il->chain_noise_data;
1027 buf = kzalloc(bufsz, GFP_KERNEL);
1028 if (!buf) {
1029 IL_ERR("Can not allocate Buffer\n");
1030 return -ENOMEM;
1031 }
1032
1033 pos +=
1034 scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1035 data->active_chains);
1036 pos +=
1037 scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1038 data->chain_noise_a);
1039 pos +=
1040 scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1041 data->chain_noise_b);
1042 pos +=
1043 scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1044 data->chain_noise_c);
1045 pos +=
1046 scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1047 data->chain_signal_a);
1048 pos +=
1049 scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1050 data->chain_signal_b);
1051 pos +=
1052 scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1053 data->chain_signal_c);
1054 pos +=
1055 scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1056 data->beacon_count);
1057
1058 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1059 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1060 pos +=
1061 scnprintf(buf + pos, bufsz - pos, " %u",
1062 data->disconn_array[cnt]);
1063 }
1064 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1065 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1066 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1067 pos +=
1068 scnprintf(buf + pos, bufsz - pos, " %u",
1069 data->delta_gain_code[cnt]);
1070 }
1071 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1072 pos +=
1073 scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1074 data->radio_write);
1075 pos +=
1076 scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1077 data->state);
1078
1079 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1080 kfree(buf);
1081 return ret;
1082 }
1083
1084 static ssize_t
1085 il_dbgfs_power_save_status_read(struct file *file, char __user *user_buf,
1086 size_t count, loff_t *ppos)
1087 {
1088 struct il_priv *il = file->private_data;
1089 char buf[60];
1090 int pos = 0;
1091 const size_t bufsz = sizeof(buf);
1092 u32 pwrsave_status;
1093
1094 pwrsave_status =
1095 _il_rd(il, CSR_GP_CNTRL) & CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1096
1097 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1098 pos +=
1099 scnprintf(buf + pos, bufsz - pos, "%s\n",
1100 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1101 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1102 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1103 "error");
1104
1105 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1106 }
1107
1108 static ssize_t
1109 il_dbgfs_clear_ucode_stats_write(struct file *file,
1110 const char __user *user_buf, size_t count,
1111 loff_t *ppos)
1112 {
1113 struct il_priv *il = file->private_data;
1114 char buf[8];
1115 int buf_size;
1116 int clear;
1117
1118 memset(buf, 0, sizeof(buf));
1119 buf_size = min(count, sizeof(buf) - 1);
1120 if (copy_from_user(buf, user_buf, buf_size))
1121 return -EFAULT;
1122 if (sscanf(buf, "%d", &clear) != 1)
1123 return -EFAULT;
1124
1125
1126 mutex_lock(&il->mutex);
1127 il_send_stats_request(il, CMD_SYNC, true);
1128 mutex_unlock(&il->mutex);
1129
1130 return count;
1131 }
1132
1133 static ssize_t
1134 il_dbgfs_rxon_flags_read(struct file *file, char __user *user_buf,
1135 size_t count, loff_t *ppos)
1136 {
1137
1138 struct il_priv *il = file->private_data;
1139 int len = 0;
1140 char buf[20];
1141
1142 len = sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.flags));
1143 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1144 }
1145
1146 static ssize_t
1147 il_dbgfs_rxon_filter_flags_read(struct file *file, char __user *user_buf,
1148 size_t count, loff_t *ppos)
1149 {
1150
1151 struct il_priv *il = file->private_data;
1152 int len = 0;
1153 char buf[20];
1154
1155 len =
1156 sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.filter_flags));
1157 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1158 }
1159
1160 static ssize_t
1161 il_dbgfs_fh_reg_read(struct file *file, char __user *user_buf, size_t count,
1162 loff_t *ppos)
1163 {
1164 struct il_priv *il = file->private_data;
1165 char *buf;
1166 int pos = 0;
1167 ssize_t ret = -EFAULT;
1168
1169 if (il->ops->dump_fh) {
1170 ret = pos = il->ops->dump_fh(il, &buf, true);
1171 if (buf) {
1172 ret =
1173 simple_read_from_buffer(user_buf, count, ppos, buf,
1174 pos);
1175 kfree(buf);
1176 }
1177 }
1178
1179 return ret;
1180 }
1181
1182 static ssize_t
1183 il_dbgfs_missed_beacon_read(struct file *file, char __user *user_buf,
1184 size_t count, loff_t *ppos)
1185 {
1186
1187 struct il_priv *il = file->private_data;
1188 int pos = 0;
1189 char buf[12];
1190 const size_t bufsz = sizeof(buf);
1191
1192 pos +=
1193 scnprintf(buf + pos, bufsz - pos, "%d\n",
1194 il->missed_beacon_threshold);
1195
1196 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1197 }
1198
1199 static ssize_t
1200 il_dbgfs_missed_beacon_write(struct file *file, const char __user *user_buf,
1201 size_t count, loff_t *ppos)
1202 {
1203 struct il_priv *il = file->private_data;
1204 char buf[8];
1205 int buf_size;
1206 int missed;
1207
1208 memset(buf, 0, sizeof(buf));
1209 buf_size = min(count, sizeof(buf) - 1);
1210 if (copy_from_user(buf, user_buf, buf_size))
1211 return -EFAULT;
1212 if (sscanf(buf, "%d", &missed) != 1)
1213 return -EINVAL;
1214
1215 if (missed < IL_MISSED_BEACON_THRESHOLD_MIN ||
1216 missed > IL_MISSED_BEACON_THRESHOLD_MAX)
1217 il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF;
1218 else
1219 il->missed_beacon_threshold = missed;
1220
1221 return count;
1222 }
1223
1224 static ssize_t
1225 il_dbgfs_force_reset_read(struct file *file, char __user *user_buf,
1226 size_t count, loff_t *ppos)
1227 {
1228
1229 struct il_priv *il = file->private_data;
1230 int pos = 0;
1231 char buf[300];
1232 const size_t bufsz = sizeof(buf);
1233 struct il_force_reset *force_reset;
1234
1235 force_reset = &il->force_reset;
1236
1237 pos +=
1238 scnprintf(buf + pos, bufsz - pos, "\tnumber of reset request: %d\n",
1239 force_reset->reset_request_count);
1240 pos +=
1241 scnprintf(buf + pos, bufsz - pos,
1242 "\tnumber of reset request success: %d\n",
1243 force_reset->reset_success_count);
1244 pos +=
1245 scnprintf(buf + pos, bufsz - pos,
1246 "\tnumber of reset request reject: %d\n",
1247 force_reset->reset_reject_count);
1248 pos +=
1249 scnprintf(buf + pos, bufsz - pos, "\treset duration: %lu\n",
1250 force_reset->reset_duration);
1251
1252 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1253 }
1254
1255 static ssize_t
1256 il_dbgfs_force_reset_write(struct file *file, const char __user *user_buf,
1257 size_t count, loff_t *ppos)
1258 {
1259
1260 int ret;
1261 struct il_priv *il = file->private_data;
1262
1263 ret = il_force_reset(il, true);
1264
1265 return ret ? ret : count;
1266 }
1267
1268 static ssize_t
1269 il_dbgfs_wd_timeout_write(struct file *file, const char __user *user_buf,
1270 size_t count, loff_t *ppos)
1271 {
1272
1273 struct il_priv *il = file->private_data;
1274 char buf[8];
1275 int buf_size;
1276 int timeout;
1277
1278 memset(buf, 0, sizeof(buf));
1279 buf_size = min(count, sizeof(buf) - 1);
1280 if (copy_from_user(buf, user_buf, buf_size))
1281 return -EFAULT;
1282 if (sscanf(buf, "%d", &timeout) != 1)
1283 return -EINVAL;
1284 if (timeout < 0 || timeout > IL_MAX_WD_TIMEOUT)
1285 timeout = IL_DEF_WD_TIMEOUT;
1286
1287 il->cfg->wd_timeout = timeout;
1288 il_setup_watchdog(il);
1289 return count;
1290 }
1291
1292 DEBUGFS_READ_FILE_OPS(rx_stats);
1293 DEBUGFS_READ_FILE_OPS(tx_stats);
1294 DEBUGFS_READ_FILE_OPS(rx_queue);
1295 DEBUGFS_READ_FILE_OPS(tx_queue);
1296 DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
1297 DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
1298 DEBUGFS_READ_FILE_OPS(ucode_general_stats);
1299 DEBUGFS_READ_FILE_OPS(sensitivity);
1300 DEBUGFS_READ_FILE_OPS(chain_noise);
1301 DEBUGFS_READ_FILE_OPS(power_save_status);
1302 DEBUGFS_WRITE_FILE_OPS(clear_ucode_stats);
1303 DEBUGFS_WRITE_FILE_OPS(clear_traffic_stats);
1304 DEBUGFS_READ_FILE_OPS(fh_reg);
1305 DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
1306 DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
1307 DEBUGFS_READ_FILE_OPS(rxon_flags);
1308 DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
1309 DEBUGFS_WRITE_FILE_OPS(wd_timeout);
1310
1311
1312
1313
1314
1315 void
1316 il_dbgfs_register(struct il_priv *il, const char *name)
1317 {
1318 struct dentry *phyd = il->hw->wiphy->debugfsdir;
1319 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
1320
1321 dir_drv = debugfs_create_dir(name, phyd);
1322 il->debugfs_dir = dir_drv;
1323
1324 dir_data = debugfs_create_dir("data", dir_drv);
1325 dir_rf = debugfs_create_dir("rf", dir_drv);
1326 dir_debug = debugfs_create_dir("debug", dir_drv);
1327
1328 DEBUGFS_ADD_FILE(nvm, dir_data, 0400);
1329 DEBUGFS_ADD_FILE(sram, dir_data, 0600);
1330 DEBUGFS_ADD_FILE(stations, dir_data, 0400);
1331 DEBUGFS_ADD_FILE(channels, dir_data, 0400);
1332 DEBUGFS_ADD_FILE(status, dir_data, 0400);
1333 DEBUGFS_ADD_FILE(interrupt, dir_data, 0600);
1334 DEBUGFS_ADD_FILE(qos, dir_data, 0400);
1335 DEBUGFS_ADD_FILE(disable_ht40, dir_data, 0600);
1336 DEBUGFS_ADD_FILE(rx_stats, dir_debug, 0400);
1337 DEBUGFS_ADD_FILE(tx_stats, dir_debug, 0400);
1338 DEBUGFS_ADD_FILE(rx_queue, dir_debug, 0400);
1339 DEBUGFS_ADD_FILE(tx_queue, dir_debug, 0400);
1340 DEBUGFS_ADD_FILE(power_save_status, dir_debug, 0400);
1341 DEBUGFS_ADD_FILE(clear_ucode_stats, dir_debug, 0200);
1342 DEBUGFS_ADD_FILE(clear_traffic_stats, dir_debug, 0200);
1343 DEBUGFS_ADD_FILE(fh_reg, dir_debug, 0400);
1344 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, 0200);
1345 DEBUGFS_ADD_FILE(force_reset, dir_debug, 0600);
1346 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, 0400);
1347 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, 0400);
1348 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, 0400);
1349
1350 if (il->cfg->sensitivity_calib_by_driver)
1351 DEBUGFS_ADD_FILE(sensitivity, dir_debug, 0400);
1352 if (il->cfg->chain_noise_calib_by_driver)
1353 DEBUGFS_ADD_FILE(chain_noise, dir_debug, 0400);
1354 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, 0200);
1355 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, 0200);
1356 DEBUGFS_ADD_FILE(wd_timeout, dir_debug, 0200);
1357 if (il->cfg->sensitivity_calib_by_driver)
1358 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
1359 &il->disable_sens_cal);
1360 if (il->cfg->chain_noise_calib_by_driver)
1361 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
1362 &il->disable_chain_noise_cal);
1363 DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf, &il->disable_tx_power_cal);
1364 }
1365 EXPORT_SYMBOL(il_dbgfs_register);
1366
1367
1368
1369
1370 void
1371 il_dbgfs_unregister(struct il_priv *il)
1372 {
1373 if (!il->debugfs_dir)
1374 return;
1375
1376 debugfs_remove_recursive(il->debugfs_dir);
1377 il->debugfs_dir = NULL;
1378 }
1379 EXPORT_SYMBOL(il_dbgfs_unregister);