iwl-debugfs.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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, S_IWUSR | S_IRUSR, \
  46. dbgfs->dir_##parent, priv, \
  47. &iwl_dbgfs_##name##_ops); \
  48. if (!(dbgfs->dbgfs_##parent##_files.file_##name)) \
  49. goto err; \
  50. } while (0)
  51. #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
  52. dbgfs->dbgfs_##parent##_files.file_##name = \
  53. debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
  54. dbgfs->dir_##parent, ptr); \
  55. if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
  56. || !dbgfs->dbgfs_##parent##_files.file_##name) \
  57. goto err; \
  58. } while (0)
  59. #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
  60. dbgfs->dbgfs_##parent##_files.file_##name = \
  61. debugfs_create_x32(#name, S_IRUSR, dbgfs->dir_##parent, ptr); \
  62. if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
  63. || !dbgfs->dbgfs_##parent##_files.file_##name) \
  64. goto err; \
  65. } while (0)
  66. #define DEBUGFS_REMOVE(name) do { \
  67. debugfs_remove(name); \
  68. name = NULL; \
  69. } while (0);
  70. /* file operation */
  71. #define DEBUGFS_READ_FUNC(name) \
  72. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  73. char __user *user_buf, \
  74. size_t count, loff_t *ppos);
  75. #define DEBUGFS_WRITE_FUNC(name) \
  76. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  77. const char __user *user_buf, \
  78. size_t count, loff_t *ppos);
  79. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  80. {
  81. file->private_data = inode->i_private;
  82. return 0;
  83. }
  84. #define DEBUGFS_READ_FILE_OPS(name) \
  85. DEBUGFS_READ_FUNC(name); \
  86. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  87. .read = iwl_dbgfs_##name##_read, \
  88. .open = iwl_dbgfs_open_file_generic, \
  89. };
  90. #define DEBUGFS_WRITE_FILE_OPS(name) \
  91. DEBUGFS_WRITE_FUNC(name); \
  92. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  93. .write = iwl_dbgfs_##name##_write, \
  94. .open = iwl_dbgfs_open_file_generic, \
  95. };
  96. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  97. DEBUGFS_READ_FUNC(name); \
  98. DEBUGFS_WRITE_FUNC(name); \
  99. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  100. .write = iwl_dbgfs_##name##_write, \
  101. .read = iwl_dbgfs_##name##_read, \
  102. .open = iwl_dbgfs_open_file_generic, \
  103. };
  104. static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
  105. char __user *user_buf,
  106. size_t count, loff_t *ppos) {
  107. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  108. char buf[256];
  109. int pos = 0;
  110. const size_t bufsz = sizeof(buf);
  111. pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
  112. priv->tx_stats[0].cnt);
  113. pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
  114. priv->tx_stats[1].cnt);
  115. pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
  116. priv->tx_stats[2].cnt);
  117. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  118. }
  119. static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
  120. char __user *user_buf,
  121. size_t count, loff_t *ppos) {
  122. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  123. char buf[256];
  124. int pos = 0;
  125. const size_t bufsz = sizeof(buf);
  126. pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
  127. priv->rx_stats[0].cnt);
  128. pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
  129. priv->rx_stats[1].cnt);
  130. pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
  131. priv->rx_stats[2].cnt);
  132. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  133. }
  134. #define BYTE1_MASK 0x000000ff;
  135. #define BYTE2_MASK 0x0000ffff;
  136. #define BYTE3_MASK 0x00ffffff;
  137. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  138. char __user *user_buf,
  139. size_t count, loff_t *ppos)
  140. {
  141. u32 val;
  142. char buf[1024];
  143. ssize_t ret;
  144. int i;
  145. int pos = 0;
  146. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  147. const size_t bufsz = sizeof(buf);
  148. for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
  149. val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
  150. priv->dbgfs->sram_len - i);
  151. if (i < 4) {
  152. switch (i) {
  153. case 1:
  154. val &= BYTE1_MASK;
  155. break;
  156. case 2:
  157. val &= BYTE2_MASK;
  158. break;
  159. case 3:
  160. val &= BYTE3_MASK;
  161. break;
  162. }
  163. }
  164. pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
  165. }
  166. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  167. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  168. return ret;
  169. }
  170. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  171. const char __user *user_buf,
  172. size_t count, loff_t *ppos)
  173. {
  174. struct iwl_priv *priv = file->private_data;
  175. char buf[64];
  176. int buf_size;
  177. u32 offset, len;
  178. memset(buf, 0, sizeof(buf));
  179. buf_size = min(count, sizeof(buf) - 1);
  180. if (copy_from_user(buf, user_buf, buf_size))
  181. return -EFAULT;
  182. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  183. priv->dbgfs->sram_offset = offset;
  184. priv->dbgfs->sram_len = len;
  185. } else {
  186. priv->dbgfs->sram_offset = 0;
  187. priv->dbgfs->sram_len = 0;
  188. }
  189. return count;
  190. }
  191. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  192. size_t count, loff_t *ppos)
  193. {
  194. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  195. struct iwl_station_entry *station;
  196. int max_sta = priv->hw_params.max_stations;
  197. char *buf;
  198. int i, j, pos = 0;
  199. ssize_t ret;
  200. /* Add 30 for initial string */
  201. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  202. buf = kmalloc(bufsz, GFP_KERNEL);
  203. if (!buf)
  204. return -ENOMEM;
  205. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  206. priv->num_stations);
  207. for (i = 0; i < max_sta; i++) {
  208. station = &priv->stations[i];
  209. if (station->used) {
  210. pos += scnprintf(buf + pos, bufsz - pos,
  211. "station %d:\ngeneral data:\n", i+1);
  212. pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
  213. station->sta.sta.sta_id);
  214. pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
  215. station->sta.mode);
  216. pos += scnprintf(buf + pos, bufsz - pos,
  217. "flags: 0x%x\n",
  218. station->sta.station_flags_msk);
  219. pos += scnprintf(buf + pos, bufsz - pos,
  220. "ps_status: %u\n", station->ps_status);
  221. pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
  222. pos += scnprintf(buf + pos, bufsz - pos,
  223. "seq_num\t\ttxq_id");
  224. pos += scnprintf(buf + pos, bufsz - pos,
  225. "\tframe_count\twait_for_ba\t");
  226. pos += scnprintf(buf + pos, bufsz - pos,
  227. "start_idx\tbitmap0\t");
  228. pos += scnprintf(buf + pos, bufsz - pos,
  229. "bitmap1\trate_n_flags");
  230. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  231. for (j = 0; j < MAX_TID_COUNT; j++) {
  232. pos += scnprintf(buf + pos, bufsz - pos,
  233. "[%d]:\t\t%u", j,
  234. station->tid[j].seq_number);
  235. pos += scnprintf(buf + pos, bufsz - pos,
  236. "\t%u\t\t%u\t\t%u\t\t",
  237. station->tid[j].agg.txq_id,
  238. station->tid[j].agg.frame_count,
  239. station->tid[j].agg.wait_for_ba);
  240. pos += scnprintf(buf + pos, bufsz - pos,
  241. "%u\t%llu\t%u",
  242. station->tid[j].agg.start_idx,
  243. (unsigned long long)station->tid[j].agg.bitmap,
  244. station->tid[j].agg.rate_n_flags);
  245. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  246. }
  247. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  248. }
  249. }
  250. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  251. kfree(buf);
  252. return ret;
  253. }
  254. static ssize_t iwl_dbgfs_nvm_read(struct file *file,
  255. char __user *user_buf,
  256. size_t count,
  257. loff_t *ppos)
  258. {
  259. ssize_t ret;
  260. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  261. int pos = 0, ofs = 0, buf_size = 0;
  262. const u8 *ptr;
  263. char *buf;
  264. size_t eeprom_len = priv->cfg->eeprom_size;
  265. buf_size = 4 * eeprom_len + 256;
  266. if (eeprom_len % 16) {
  267. IWL_ERR(priv, "NVM size is not multiple of 16.\n");
  268. return -ENODATA;
  269. }
  270. /* 4 characters for byte 0xYY */
  271. buf = kzalloc(buf_size, GFP_KERNEL);
  272. if (!buf) {
  273. IWL_ERR(priv, "Can not allocate Buffer\n");
  274. return -ENOMEM;
  275. }
  276. ptr = priv->eeprom;
  277. if (!ptr) {
  278. IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
  279. return -ENOMEM;
  280. }
  281. pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s\n",
  282. (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
  283. ? "OTP" : "EEPROM");
  284. for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
  285. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  286. hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
  287. buf_size - pos, 0);
  288. pos += strlen(buf);
  289. if (buf_size - pos > 0)
  290. buf[pos++] = '\n';
  291. }
  292. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  293. kfree(buf);
  294. return ret;
  295. }
  296. static ssize_t iwl_dbgfs_log_event_write(struct file *file,
  297. const char __user *user_buf,
  298. size_t count, loff_t *ppos)
  299. {
  300. struct iwl_priv *priv = file->private_data;
  301. u32 event_log_flag;
  302. char buf[8];
  303. int buf_size;
  304. memset(buf, 0, sizeof(buf));
  305. buf_size = min(count, sizeof(buf) - 1);
  306. if (copy_from_user(buf, user_buf, buf_size))
  307. return -EFAULT;
  308. if (sscanf(buf, "%d", &event_log_flag) != 1)
  309. return -EFAULT;
  310. if (event_log_flag == 1)
  311. iwl_dump_nic_event_log(priv);
  312. return count;
  313. }
  314. static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
  315. size_t count, loff_t *ppos)
  316. {
  317. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  318. struct ieee80211_channel *channels = NULL;
  319. const struct ieee80211_supported_band *supp_band = NULL;
  320. int pos = 0, i, bufsz = PAGE_SIZE;
  321. char *buf;
  322. ssize_t ret;
  323. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
  324. return -EAGAIN;
  325. buf = kzalloc(bufsz, GFP_KERNEL);
  326. if (!buf) {
  327. IWL_ERR(priv, "Can not allocate Buffer\n");
  328. return -ENOMEM;
  329. }
  330. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  331. if (supp_band) {
  332. channels = supp_band->channels;
  333. pos += scnprintf(buf + pos, bufsz - pos,
  334. "Displaying %d channels in 2.4GHz band 802.11bg):\n",
  335. supp_band->n_channels);
  336. for (i = 0; i < supp_band->n_channels; i++)
  337. pos += scnprintf(buf + pos, bufsz - pos,
  338. "%d: %ddBm: BSS%s%s, %s.\n",
  339. ieee80211_frequency_to_channel(
  340. channels[i].center_freq),
  341. channels[i].max_power,
  342. channels[i].flags & IEEE80211_CHAN_RADAR ?
  343. " (IEEE 802.11h required)" : "",
  344. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  345. || (channels[i].flags &
  346. IEEE80211_CHAN_RADAR)) ? "" :
  347. ", IBSS",
  348. channels[i].flags &
  349. IEEE80211_CHAN_PASSIVE_SCAN ?
  350. "passive only" : "active/passive");
  351. }
  352. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  353. if (supp_band) {
  354. channels = supp_band->channels;
  355. pos += scnprintf(buf + pos, bufsz - pos,
  356. "Displaying %d channels in 5.2GHz band (802.11a)\n",
  357. supp_band->n_channels);
  358. for (i = 0; i < supp_band->n_channels; i++)
  359. pos += scnprintf(buf + pos, bufsz - pos,
  360. "%d: %ddBm: BSS%s%s, %s.\n",
  361. ieee80211_frequency_to_channel(
  362. channels[i].center_freq),
  363. channels[i].max_power,
  364. channels[i].flags & IEEE80211_CHAN_RADAR ?
  365. " (IEEE 802.11h required)" : "",
  366. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  367. || (channels[i].flags &
  368. IEEE80211_CHAN_RADAR)) ? "" :
  369. ", IBSS",
  370. channels[i].flags &
  371. IEEE80211_CHAN_PASSIVE_SCAN ?
  372. "passive only" : "active/passive");
  373. }
  374. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  375. kfree(buf);
  376. return ret;
  377. }
  378. static ssize_t iwl_dbgfs_status_read(struct file *file,
  379. char __user *user_buf,
  380. size_t count, loff_t *ppos) {
  381. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  382. char buf[512];
  383. int pos = 0;
  384. const size_t bufsz = sizeof(buf);
  385. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
  386. test_bit(STATUS_HCMD_ACTIVE, &priv->status));
  387. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
  388. test_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status));
  389. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
  390. test_bit(STATUS_INT_ENABLED, &priv->status));
  391. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
  392. test_bit(STATUS_RF_KILL_HW, &priv->status));
  393. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
  394. test_bit(STATUS_INIT, &priv->status));
  395. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
  396. test_bit(STATUS_ALIVE, &priv->status));
  397. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
  398. test_bit(STATUS_READY, &priv->status));
  399. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
  400. test_bit(STATUS_TEMPERATURE, &priv->status));
  401. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
  402. test_bit(STATUS_GEO_CONFIGURED, &priv->status));
  403. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
  404. test_bit(STATUS_EXIT_PENDING, &priv->status));
  405. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
  406. test_bit(STATUS_STATISTICS, &priv->status));
  407. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
  408. test_bit(STATUS_SCANNING, &priv->status));
  409. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
  410. test_bit(STATUS_SCAN_ABORTING, &priv->status));
  411. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
  412. test_bit(STATUS_SCAN_HW, &priv->status));
  413. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
  414. test_bit(STATUS_POWER_PMI, &priv->status));
  415. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
  416. test_bit(STATUS_FW_ERROR, &priv->status));
  417. pos += scnprintf(buf + pos, bufsz - pos, "STATUS_MODE_PENDING:\t %d\n",
  418. test_bit(STATUS_MODE_PENDING, &priv->status));
  419. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  420. }
  421. static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
  422. char __user *user_buf,
  423. size_t count, loff_t *ppos) {
  424. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  425. int pos = 0;
  426. int cnt = 0;
  427. char *buf;
  428. int bufsz = 24 * 64; /* 24 items * 64 char per item */
  429. ssize_t ret;
  430. buf = kzalloc(bufsz, GFP_KERNEL);
  431. if (!buf) {
  432. IWL_ERR(priv, "Can not allocate Buffer\n");
  433. return -ENOMEM;
  434. }
  435. pos += scnprintf(buf + pos, bufsz - pos,
  436. "Interrupt Statistics Report:\n");
  437. pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
  438. priv->isr_stats.hw);
  439. pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
  440. priv->isr_stats.sw);
  441. if (priv->isr_stats.sw > 0) {
  442. pos += scnprintf(buf + pos, bufsz - pos,
  443. "\tLast Restarting Code: 0x%X\n",
  444. priv->isr_stats.sw_err);
  445. }
  446. #ifdef CONFIG_IWLWIFI_DEBUG
  447. pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
  448. priv->isr_stats.sch);
  449. pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
  450. priv->isr_stats.alive);
  451. #endif
  452. pos += scnprintf(buf + pos, bufsz - pos,
  453. "HW RF KILL switch toggled:\t %u\n",
  454. priv->isr_stats.rfkill);
  455. pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
  456. priv->isr_stats.ctkill);
  457. pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
  458. priv->isr_stats.wakeup);
  459. pos += scnprintf(buf + pos, bufsz - pos,
  460. "Rx command responses:\t\t %u\n",
  461. priv->isr_stats.rx);
  462. for (cnt = 0; cnt < REPLY_MAX; cnt++) {
  463. if (priv->isr_stats.rx_handlers[cnt] > 0)
  464. pos += scnprintf(buf + pos, bufsz - pos,
  465. "\tRx handler[%36s]:\t\t %u\n",
  466. get_cmd_string(cnt),
  467. priv->isr_stats.rx_handlers[cnt]);
  468. }
  469. pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
  470. priv->isr_stats.tx);
  471. pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
  472. priv->isr_stats.unhandled);
  473. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  474. kfree(buf);
  475. return ret;
  476. }
  477. static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
  478. const char __user *user_buf,
  479. size_t count, loff_t *ppos)
  480. {
  481. struct iwl_priv *priv = file->private_data;
  482. char buf[8];
  483. int buf_size;
  484. u32 reset_flag;
  485. memset(buf, 0, sizeof(buf));
  486. buf_size = min(count, sizeof(buf) - 1);
  487. if (copy_from_user(buf, user_buf, buf_size))
  488. return -EFAULT;
  489. if (sscanf(buf, "%x", &reset_flag) != 1)
  490. return -EFAULT;
  491. if (reset_flag == 0)
  492. iwl_clear_isr_stats(priv);
  493. return count;
  494. }
  495. static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
  496. size_t count, loff_t *ppos)
  497. {
  498. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  499. int pos = 0, i;
  500. char buf[256];
  501. const size_t bufsz = sizeof(buf);
  502. ssize_t ret;
  503. for (i = 0; i < AC_NUM; i++) {
  504. pos += scnprintf(buf + pos, bufsz - pos,
  505. "\tcw_min\tcw_max\taifsn\ttxop\n");
  506. pos += scnprintf(buf + pos, bufsz - pos,
  507. "AC[%d]\t%u\t%u\t%u\t%u\n", i,
  508. priv->qos_data.def_qos_parm.ac[i].cw_min,
  509. priv->qos_data.def_qos_parm.ac[i].cw_max,
  510. priv->qos_data.def_qos_parm.ac[i].aifsn,
  511. priv->qos_data.def_qos_parm.ac[i].edca_txop);
  512. }
  513. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  514. return ret;
  515. }
  516. #ifdef CONFIG_IWLWIFI_LEDS
  517. static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf,
  518. size_t count, loff_t *ppos)
  519. {
  520. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  521. int pos = 0;
  522. char buf[256];
  523. const size_t bufsz = sizeof(buf);
  524. ssize_t ret;
  525. pos += scnprintf(buf + pos, bufsz - pos,
  526. "allow blinking: %s\n",
  527. (priv->allow_blinking) ? "True" : "False");
  528. if (priv->allow_blinking) {
  529. pos += scnprintf(buf + pos, bufsz - pos,
  530. "Led blinking rate: %u\n",
  531. priv->last_blink_rate);
  532. pos += scnprintf(buf + pos, bufsz - pos,
  533. "Last blink time: %lu\n",
  534. priv->last_blink_time);
  535. }
  536. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  537. return ret;
  538. }
  539. #endif
  540. static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
  541. char __user *user_buf,
  542. size_t count, loff_t *ppos)
  543. {
  544. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  545. struct iwl_tt_mgmt *tt = &priv->power_data.tt;
  546. struct iwl_tt_restriction *restriction;
  547. char buf[100];
  548. int pos = 0;
  549. const size_t bufsz = sizeof(buf);
  550. ssize_t ret;
  551. pos += scnprintf(buf + pos, bufsz - pos,
  552. "Thermal Throttling Mode: %s\n",
  553. (priv->power_data.adv_tt)
  554. ? "Advance" : "Legacy");
  555. pos += scnprintf(buf + pos, bufsz - pos,
  556. "Thermal Throttling State: %d\n",
  557. tt->state);
  558. if (priv->power_data.adv_tt) {
  559. restriction = tt->restriction + tt->state;
  560. pos += scnprintf(buf + pos, bufsz - pos,
  561. "Tx mode: %d\n",
  562. restriction->tx_stream);
  563. pos += scnprintf(buf + pos, bufsz - pos,
  564. "Rx mode: %d\n",
  565. restriction->rx_stream);
  566. pos += scnprintf(buf + pos, bufsz - pos,
  567. "HT mode: %d\n",
  568. restriction->is_ht);
  569. }
  570. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  571. return ret;
  572. }
  573. static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
  574. const char __user *user_buf,
  575. size_t count, loff_t *ppos)
  576. {
  577. struct iwl_priv *priv = file->private_data;
  578. char buf[8];
  579. int buf_size;
  580. int ht40;
  581. memset(buf, 0, sizeof(buf));
  582. buf_size = min(count, sizeof(buf) - 1);
  583. if (copy_from_user(buf, user_buf, buf_size))
  584. return -EFAULT;
  585. if (sscanf(buf, "%d", &ht40) != 1)
  586. return -EFAULT;
  587. if (!iwl_is_associated(priv))
  588. priv->disable_ht40 = ht40 ? true : false;
  589. else {
  590. IWL_ERR(priv, "Sta associated with AP - "
  591. "Change to 40MHz channel support is not allowed\n");
  592. return -EINVAL;
  593. }
  594. return count;
  595. }
  596. static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
  597. char __user *user_buf,
  598. size_t count, loff_t *ppos)
  599. {
  600. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  601. char buf[100];
  602. int pos = 0;
  603. const size_t bufsz = sizeof(buf);
  604. ssize_t ret;
  605. pos += scnprintf(buf + pos, bufsz - pos,
  606. "11n 40MHz Mode: %s\n",
  607. priv->disable_ht40 ? "Disabled" : "Enabled");
  608. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  609. return ret;
  610. }
  611. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  612. DEBUGFS_WRITE_FILE_OPS(log_event);
  613. DEBUGFS_READ_FILE_OPS(nvm);
  614. DEBUGFS_READ_FILE_OPS(stations);
  615. DEBUGFS_READ_FILE_OPS(rx_statistics);
  616. DEBUGFS_READ_FILE_OPS(tx_statistics);
  617. DEBUGFS_READ_FILE_OPS(channels);
  618. DEBUGFS_READ_FILE_OPS(status);
  619. DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
  620. DEBUGFS_READ_FILE_OPS(qos);
  621. #ifdef CONFIG_IWLWIFI_LEDS
  622. DEBUGFS_READ_FILE_OPS(led);
  623. #endif
  624. DEBUGFS_READ_FILE_OPS(thermal_throttling);
  625. DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
  626. /*
  627. * Create the debugfs files and directories
  628. *
  629. */
  630. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  631. {
  632. struct iwl_debugfs *dbgfs;
  633. struct dentry *phyd = priv->hw->wiphy->debugfsdir;
  634. int ret = 0;
  635. dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
  636. if (!dbgfs) {
  637. ret = -ENOMEM;
  638. goto err;
  639. }
  640. priv->dbgfs = dbgfs;
  641. dbgfs->name = name;
  642. dbgfs->dir_drv = debugfs_create_dir(name, phyd);
  643. if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
  644. ret = -ENOENT;
  645. goto err;
  646. }
  647. DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
  648. DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
  649. DEBUGFS_ADD_FILE(nvm, data);
  650. DEBUGFS_ADD_FILE(sram, data);
  651. DEBUGFS_ADD_FILE(log_event, data);
  652. DEBUGFS_ADD_FILE(stations, data);
  653. DEBUGFS_ADD_FILE(rx_statistics, data);
  654. DEBUGFS_ADD_FILE(tx_statistics, data);
  655. DEBUGFS_ADD_FILE(channels, data);
  656. DEBUGFS_ADD_FILE(status, data);
  657. DEBUGFS_ADD_FILE(interrupt, data);
  658. DEBUGFS_ADD_FILE(qos, data);
  659. #ifdef CONFIG_IWLWIFI_LEDS
  660. DEBUGFS_ADD_FILE(led, data);
  661. #endif
  662. DEBUGFS_ADD_FILE(thermal_throttling, data);
  663. DEBUGFS_ADD_FILE(disable_ht40, data);
  664. DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
  665. DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
  666. &priv->disable_chain_noise_cal);
  667. if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
  668. ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
  669. DEBUGFS_ADD_BOOL(disable_tx_power, rf,
  670. &priv->disable_tx_power_cal);
  671. return 0;
  672. err:
  673. IWL_ERR(priv, "Can't open the debugfs directory\n");
  674. iwl_dbgfs_unregister(priv);
  675. return ret;
  676. }
  677. EXPORT_SYMBOL(iwl_dbgfs_register);
  678. /**
  679. * Remove the debugfs files and directories
  680. *
  681. */
  682. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  683. {
  684. if (!priv->dbgfs)
  685. return;
  686. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_nvm);
  687. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
  688. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
  689. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
  690. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
  691. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
  692. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
  693. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status);
  694. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_interrupt);
  695. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_qos);
  696. #ifdef CONFIG_IWLWIFI_LEDS
  697. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_led);
  698. #endif
  699. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_thermal_throttling);
  700. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_disable_ht40);
  701. DEBUGFS_REMOVE(priv->dbgfs->dir_data);
  702. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
  703. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
  704. if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
  705. ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
  706. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
  707. DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
  708. DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
  709. kfree(priv->dbgfs);
  710. priv->dbgfs = NULL;
  711. }
  712. EXPORT_SYMBOL(iwl_dbgfs_unregister);