iwl-debugfs.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2009 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *****************************************************************************/
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/debugfs.h>
  31. #include <linux/ieee80211.h>
  32. #include <net/mac80211.h>
  33. #include "iwl-dev.h"
  34. #include "iwl-debug.h"
  35. #include "iwl-core.h"
  36. #include "iwl-io.h"
  37. /* create and remove of files */
  38. #define DEBUGFS_ADD_DIR(name, parent) do { \
  39. dbgfs->dir_##name = debugfs_create_dir(#name, parent); \
  40. if (!(dbgfs->dir_##name)) \
  41. goto err; \
  42. } while (0)
  43. #define DEBUGFS_ADD_FILE(name, parent) do { \
  44. dbgfs->dbgfs_##parent##_files.file_##name = \
  45. debugfs_create_file(#name, 0644, dbgfs->dir_##parent, priv, \
  46. &iwl_dbgfs_##name##_ops); \
  47. if (!(dbgfs->dbgfs_##parent##_files.file_##name)) \
  48. goto err; \
  49. } while (0)
  50. #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
  51. dbgfs->dbgfs_##parent##_files.file_##name = \
  52. debugfs_create_bool(#name, 0644, dbgfs->dir_##parent, ptr); \
  53. if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
  54. || !dbgfs->dbgfs_##parent##_files.file_##name) \
  55. goto err; \
  56. } while (0)
  57. #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
  58. dbgfs->dbgfs_##parent##_files.file_##name = \
  59. debugfs_create_x32(#name, 0444, dbgfs->dir_##parent, ptr); \
  60. if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
  61. || !dbgfs->dbgfs_##parent##_files.file_##name) \
  62. goto err; \
  63. } while (0)
  64. #define DEBUGFS_REMOVE(name) do { \
  65. debugfs_remove(name); \
  66. name = NULL; \
  67. } while (0);
  68. /* file operation */
  69. #define DEBUGFS_READ_FUNC(name) \
  70. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  71. char __user *user_buf, \
  72. size_t count, loff_t *ppos);
  73. #define DEBUGFS_WRITE_FUNC(name) \
  74. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  75. const char __user *user_buf, \
  76. size_t count, loff_t *ppos);
  77. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  78. {
  79. file->private_data = inode->i_private;
  80. return 0;
  81. }
  82. #define DEBUGFS_READ_FILE_OPS(name) \
  83. DEBUGFS_READ_FUNC(name); \
  84. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  85. .read = iwl_dbgfs_##name##_read, \
  86. .open = iwl_dbgfs_open_file_generic, \
  87. };
  88. #define DEBUGFS_WRITE_FILE_OPS(name) \
  89. DEBUGFS_WRITE_FUNC(name); \
  90. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  91. .write = iwl_dbgfs_##name##_write, \
  92. .open = iwl_dbgfs_open_file_generic, \
  93. };
  94. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  95. DEBUGFS_READ_FUNC(name); \
  96. DEBUGFS_WRITE_FUNC(name); \
  97. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  98. .write = iwl_dbgfs_##name##_write, \
  99. .read = iwl_dbgfs_##name##_read, \
  100. .open = iwl_dbgfs_open_file_generic, \
  101. };
  102. static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
  103. char __user *user_buf,
  104. size_t count, loff_t *ppos) {
  105. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  106. char buf[256];
  107. int pos = 0;
  108. const size_t bufsz = sizeof(buf);
  109. pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
  110. priv->tx_stats[0].cnt);
  111. pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
  112. priv->tx_stats[1].cnt);
  113. pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
  114. priv->tx_stats[2].cnt);
  115. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  116. }
  117. static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
  118. char __user *user_buf,
  119. size_t count, loff_t *ppos) {
  120. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  121. char buf[256];
  122. int pos = 0;
  123. const size_t bufsz = sizeof(buf);
  124. pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
  125. priv->rx_stats[0].cnt);
  126. pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
  127. priv->rx_stats[1].cnt);
  128. pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
  129. priv->rx_stats[2].cnt);
  130. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  131. }
  132. #define BYTE1_MASK 0x000000ff;
  133. #define BYTE2_MASK 0x0000ffff;
  134. #define BYTE3_MASK 0x00ffffff;
  135. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  136. char __user *user_buf,
  137. size_t count, loff_t *ppos)
  138. {
  139. u32 val;
  140. char buf[1024];
  141. ssize_t ret;
  142. int i;
  143. int pos = 0;
  144. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  145. const size_t bufsz = sizeof(buf);
  146. for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
  147. val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
  148. priv->dbgfs->sram_len - i);
  149. if (i < 4) {
  150. switch (i) {
  151. case 1:
  152. val &= BYTE1_MASK;
  153. break;
  154. case 2:
  155. val &= BYTE2_MASK;
  156. break;
  157. case 3:
  158. val &= BYTE3_MASK;
  159. break;
  160. }
  161. }
  162. pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
  163. }
  164. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  165. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  166. return ret;
  167. }
  168. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  169. const char __user *user_buf,
  170. size_t count, loff_t *ppos)
  171. {
  172. struct iwl_priv *priv = file->private_data;
  173. char buf[64];
  174. int buf_size;
  175. u32 offset, len;
  176. memset(buf, 0, sizeof(buf));
  177. buf_size = min(count, sizeof(buf) - 1);
  178. if (copy_from_user(buf, user_buf, buf_size))
  179. return -EFAULT;
  180. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  181. priv->dbgfs->sram_offset = offset;
  182. priv->dbgfs->sram_len = len;
  183. } else {
  184. priv->dbgfs->sram_offset = 0;
  185. priv->dbgfs->sram_len = 0;
  186. }
  187. return count;
  188. }
  189. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  190. size_t count, loff_t *ppos)
  191. {
  192. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  193. struct iwl_station_entry *station;
  194. int max_sta = priv->hw_params.max_stations;
  195. char *buf;
  196. int i, j, pos = 0;
  197. ssize_t ret;
  198. /* Add 30 for initial string */
  199. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  200. buf = kmalloc(bufsz, GFP_KERNEL);
  201. if (!buf)
  202. return -ENOMEM;
  203. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  204. priv->num_stations);
  205. for (i = 0; i < max_sta; i++) {
  206. station = &priv->stations[i];
  207. if (station->used) {
  208. pos += scnprintf(buf + pos, bufsz - pos,
  209. "station %d:\ngeneral data:\n", i+1);
  210. pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
  211. station->sta.sta.sta_id);
  212. pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
  213. station->sta.mode);
  214. pos += scnprintf(buf + pos, bufsz - pos,
  215. "flags: 0x%x\n",
  216. station->sta.station_flags_msk);
  217. pos += scnprintf(buf + pos, bufsz - pos,
  218. "ps_status: %u\n", station->ps_status);
  219. pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
  220. pos += scnprintf(buf + pos, bufsz - pos,
  221. "seq_num\t\ttxq_id");
  222. pos += scnprintf(buf + pos, bufsz - pos,
  223. "\tframe_count\twait_for_ba\t");
  224. pos += scnprintf(buf + pos, bufsz - pos,
  225. "start_idx\tbitmap0\t");
  226. pos += scnprintf(buf + pos, bufsz - pos,
  227. "bitmap1\trate_n_flags");
  228. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  229. for (j = 0; j < MAX_TID_COUNT; j++) {
  230. pos += scnprintf(buf + pos, bufsz - pos,
  231. "[%d]:\t\t%u", j,
  232. station->tid[j].seq_number);
  233. pos += scnprintf(buf + pos, bufsz - pos,
  234. "\t%u\t\t%u\t\t%u\t\t",
  235. station->tid[j].agg.txq_id,
  236. station->tid[j].agg.frame_count,
  237. station->tid[j].agg.wait_for_ba);
  238. pos += scnprintf(buf + pos, bufsz - pos,
  239. "%u\t%llu\t%u",
  240. station->tid[j].agg.start_idx,
  241. (unsigned long long)station->tid[j].agg.bitmap,
  242. station->tid[j].agg.rate_n_flags);
  243. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  244. }
  245. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  246. }
  247. }
  248. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  249. kfree(buf);
  250. return ret;
  251. }
  252. static ssize_t iwl_dbgfs_nvm_read(struct file *file,
  253. char __user *user_buf,
  254. size_t count,
  255. loff_t *ppos)
  256. {
  257. ssize_t ret;
  258. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  259. int pos = 0, ofs = 0, buf_size = 0;
  260. const u8 *ptr;
  261. char *buf;
  262. size_t eeprom_len = priv->cfg->eeprom_size;
  263. buf_size = 4 * eeprom_len + 256;
  264. if (eeprom_len % 16) {
  265. IWL_ERR(priv, "NVM size is not multiple of 16.\n");
  266. return -ENODATA;
  267. }
  268. /* 4 characters for byte 0xYY */
  269. buf = kzalloc(buf_size, GFP_KERNEL);
  270. if (!buf) {
  271. IWL_ERR(priv, "Can not allocate Buffer\n");
  272. return -ENOMEM;
  273. }
  274. ptr = priv->eeprom;
  275. if (!ptr) {
  276. IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
  277. return -ENOMEM;
  278. }
  279. pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s\n",
  280. (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
  281. ? "OTP" : "EEPROM");
  282. for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
  283. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  284. hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
  285. buf_size - pos, 0);
  286. pos += strlen(buf);
  287. if (buf_size - pos > 0)
  288. buf[pos++] = '\n';
  289. }
  290. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  291. kfree(buf);
  292. return ret;
  293. }
  294. static ssize_t iwl_dbgfs_log_event_write(struct file *file,
  295. const char __user *user_buf,
  296. size_t count, loff_t *ppos)
  297. {
  298. struct iwl_priv *priv = file->private_data;
  299. u32 event_log_flag;
  300. char buf[8];
  301. int buf_size;
  302. memset(buf, 0, sizeof(buf));
  303. buf_size = min(count, sizeof(buf) - 1);
  304. if (copy_from_user(buf, user_buf, buf_size))
  305. return -EFAULT;
  306. if (sscanf(buf, "%d", &event_log_flag) != 1)
  307. return -EFAULT;
  308. if (event_log_flag == 1)
  309. iwl_dump_nic_event_log(priv);
  310. return count;
  311. }
  312. static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
  313. size_t count, loff_t *ppos)
  314. {
  315. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  316. struct ieee80211_channel *channels = NULL;
  317. const struct ieee80211_supported_band *supp_band = NULL;
  318. int pos = 0, i, bufsz = PAGE_SIZE;
  319. char *buf;
  320. ssize_t ret;
  321. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
  322. return -EAGAIN;
  323. buf = kzalloc(bufsz, GFP_KERNEL);
  324. if (!buf) {
  325. IWL_ERR(priv, "Can not allocate Buffer\n");
  326. return -ENOMEM;
  327. }
  328. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  329. if (supp_band) {
  330. channels = supp_band->channels;
  331. pos += scnprintf(buf + pos, bufsz - pos,
  332. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  333. supp_band->n_channels);
  334. for (i = 0; i < supp_band->n_channels; i++)
  335. pos += scnprintf(buf + pos, bufsz - pos,
  336. "%d: %ddBm: BSS%s%s, %s.\n",
  337. ieee80211_frequency_to_channel(
  338. channels[i].center_freq),
  339. channels[i].max_power,
  340. channels[i].flags & IEEE80211_CHAN_RADAR ?
  341. " (IEEE 802.11h required)" : "",
  342. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  343. || (channels[i].flags &
  344. IEEE80211_CHAN_RADAR)) ? "" :
  345. ", IBSS",
  346. channels[i].flags &
  347. IEEE80211_CHAN_PASSIVE_SCAN ?
  348. "passive only" : "active/passive");
  349. }
  350. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  351. if (supp_band) {
  352. channels = supp_band->channels;
  353. pos += scnprintf(buf + pos, bufsz - pos,
  354. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  355. supp_band->n_channels);
  356. for (i = 0; i < supp_band->n_channels; i++)
  357. pos += scnprintf(buf + pos, bufsz - pos,
  358. "%d: %ddBm: BSS%s%s, %s.\n",
  359. ieee80211_frequency_to_channel(
  360. channels[i].center_freq),
  361. channels[i].max_power,
  362. channels[i].flags & IEEE80211_CHAN_RADAR ?
  363. " (IEEE 802.11h required)" : "",
  364. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  365. || (channels[i].flags &
  366. IEEE80211_CHAN_RADAR)) ? "" :
  367. ", IBSS",
  368. channels[i].flags &
  369. IEEE80211_CHAN_PASSIVE_SCAN ?
  370. "passive only" : "active/passive");
  371. }
  372. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  373. kfree(buf);
  374. return ret;
  375. }
  376. static ssize_t iwl_dbgfs_status_read(struct file *file,
  377. char __user *user_buf,
  378. size_t count, loff_t *ppos) {
  379. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  380. char buf[512];
  381. int pos = 0;
  382. const size_t bufsz = sizeof(buf);
  383. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
  384. test_bit(STATUS_HCMD_ACTIVE, &priv->status));
  385. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
  386. test_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status));
  387. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
  388. test_bit(STATUS_INT_ENABLED, &priv->status));
  389. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
  390. test_bit(STATUS_RF_KILL_HW, &priv->status));
  391. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
  392. test_bit(STATUS_INIT, &priv->status));
  393. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
  394. test_bit(STATUS_ALIVE, &priv->status));
  395. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
  396. test_bit(STATUS_READY, &priv->status));
  397. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
  398. test_bit(STATUS_TEMPERATURE, &priv->status));
  399. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
  400. test_bit(STATUS_GEO_CONFIGURED, &priv->status));
  401. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
  402. test_bit(STATUS_EXIT_PENDING, &priv->status));
  403. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
  404. test_bit(STATUS_STATISTICS, &priv->status));
  405. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
  406. test_bit(STATUS_SCANNING, &priv->status));
  407. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
  408. test_bit(STATUS_SCAN_ABORTING, &priv->status));
  409. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
  410. test_bit(STATUS_SCAN_HW, &priv->status));
  411. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
  412. test_bit(STATUS_POWER_PMI, &priv->status));
  413. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
  414. test_bit(STATUS_FW_ERROR, &priv->status));
  415. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_MODE_PENDING:\t %d\n",
  416. test_bit(STATUS_MODE_PENDING, &priv->status));
  417. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  418. }
  419. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  420. char __user *user_buf,
  421. size_t count, loff_t *ppos) {
  422. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  423. int pos = 0;
  424. int cnt = 0;
  425. char *buf;
  426. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  427. ssize_t ret;
  428. buf = kzalloc(bufsz, GFP_KERNEL);
  429. if (!buf) {
  430. IWL_ERR(priv, "Can not allocate Buffer\n");
  431. return -ENOMEM;
  432. }
  433. pos += scnprintf(buf + pos, bufsz - pos,
  434. "Interrupt Statistics Report:\n");
  435. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  436. priv->isr_stats.hw);
  437. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  438. priv->isr_stats.sw);
  439. if (priv->isr_stats.sw > 0) {
  440. pos += scnprintf(buf + pos, bufsz - pos,
  441. "\tLast Restarting Code: 0x%X\n",
  442. priv->isr_stats.sw_err);
  443. }
  444. #ifdef CONFIG_IWLWIFI_DEBUG
  445. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  446. priv->isr_stats.sch);
  447. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  448. priv->isr_stats.alive);
  449. #endif
  450. pos += scnprintf(buf + pos, bufsz - pos,
  451. "HW RF KILL switch toggled:\t %u\n",
  452. priv->isr_stats.rfkill);
  453. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  454. priv->isr_stats.ctkill);
  455. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  456. priv->isr_stats.wakeup);
  457. pos += scnprintf(buf + pos, bufsz - pos,
  458. "Rx command responses:\t\t %u\n",
  459. priv->isr_stats.rx);
  460. for (cnt = 0; cnt < REPLY_MAX; cnt++) {
  461. if (priv->isr_stats.rx_handlers[cnt] > 0)
  462. pos += scnprintf(buf + pos, bufsz - pos,
  463. "\tRx handler[%36s]:\t\t %u\n",
  464. get_cmd_string(cnt),
  465. priv->isr_stats.rx_handlers[cnt]);
  466. }
  467. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  468. priv->isr_stats.tx);
  469. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  470. priv->isr_stats.unhandled);
  471. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  472. kfree(buf);
  473. return ret;
  474. }
  475. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  476. const char __user *user_buf,
  477. size_t count, loff_t *ppos)
  478. {
  479. struct iwl_priv *priv = file->private_data;
  480. char buf[8];
  481. int buf_size;
  482. u32 reset_flag;
  483. memset(buf, 0, sizeof(buf));
  484. buf_size = min(count, sizeof(buf) - 1);
  485. if (copy_from_user(buf, user_buf, buf_size))
  486. return -EFAULT;
  487. if (sscanf(buf, "%x", &reset_flag) != 1)
  488. return -EFAULT;
  489. if (reset_flag == 0)
  490. iwl_clear_isr_stats(priv);
  491. return count;
  492. }
  493. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  494. DEBUGFS_WRITE_FILE_OPS(log_event);
  495. DEBUGFS_READ_FILE_OPS(nvm);
  496. DEBUGFS_READ_FILE_OPS(stations);
  497. DEBUGFS_READ_FILE_OPS(rx_statistics);
  498. DEBUGFS_READ_FILE_OPS(tx_statistics);
  499. DEBUGFS_READ_FILE_OPS(channels);
  500. DEBUGFS_READ_FILE_OPS(status);
  501. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  502. /*
  503. * Create the debugfs files and directories
  504. *
  505. */
  506. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  507. {
  508. struct iwl_debugfs *dbgfs;
  509. struct dentry *phyd = priv->hw->wiphy->debugfsdir;
  510. int ret = 0;
  511. dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
  512. if (!dbgfs) {
  513. ret = -ENOMEM;
  514. goto err;
  515. }
  516. priv->dbgfs = dbgfs;
  517. dbgfs->name = name;
  518. dbgfs->dir_drv = debugfs_create_dir(name, phyd);
  519. if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
  520. ret = -ENOENT;
  521. goto err;
  522. }
  523. DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
  524. DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
  525. DEBUGFS_ADD_FILE(nvm, data);
  526. DEBUGFS_ADD_FILE(sram, data);
  527. DEBUGFS_ADD_FILE(log_event, data);
  528. DEBUGFS_ADD_FILE(stations, data);
  529. DEBUGFS_ADD_FILE(rx_statistics, data);
  530. DEBUGFS_ADD_FILE(tx_statistics, data);
  531. DEBUGFS_ADD_FILE(channels, data);
  532. DEBUGFS_ADD_FILE(status, data);
  533. DEBUGFS_ADD_FILE(interrupt, data);
  534. DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
  535. DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
  536. &priv->disable_chain_noise_cal);
  537. DEBUGFS_ADD_BOOL(disable_tx_power, rf, &priv->disable_tx_power_cal);
  538. return 0;
  539. err:
  540. IWL_ERR(priv, "Can't open the debugfs directory\n");
  541. iwl_dbgfs_unregister(priv);
  542. return ret;
  543. }
  544. EXPORT_SYMBOL(iwl_dbgfs_register);
  545. /**
  546. * Remove the debugfs files and directories
  547. *
  548. */
  549. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  550. {
  551. if (!priv->dbgfs)
  552. return;
  553. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_nvm);
  554. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
  555. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
  556. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
  557. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
  558. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
  559. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
  560. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status);
  561. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_interrupt);
  562. DEBUGFS_REMOVE(priv->dbgfs->dir_data);
  563. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
  564. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
  565. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
  566. DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
  567. DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
  568. kfree(priv->dbgfs);
  569. priv->dbgfs = NULL;
  570. }
  571. EXPORT_SYMBOL(iwl_dbgfs_unregister);