iwl-debugfs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 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. * Tomas Winkler <tomas.winkler@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. goto err; \
  55. } while (0)
  56. #define DEBUGFS_REMOVE(name) do { \
  57. debugfs_remove(name); \
  58. name = NULL; \
  59. } while (0);
  60. /* file operation */
  61. #define DEBUGFS_READ_FUNC(name) \
  62. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  63. char __user *user_buf, \
  64. size_t count, loff_t *ppos);
  65. #define DEBUGFS_WRITE_FUNC(name) \
  66. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  67. const char __user *user_buf, \
  68. size_t count, loff_t *ppos);
  69. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  70. {
  71. file->private_data = inode->i_private;
  72. return 0;
  73. }
  74. #define DEBUGFS_READ_FILE_OPS(name) \
  75. DEBUGFS_READ_FUNC(name); \
  76. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  77. .read = iwl_dbgfs_##name##_read, \
  78. .open = iwl_dbgfs_open_file_generic, \
  79. };
  80. #define DEBUGFS_WRITE_FILE_OPS(name) \
  81. DEBUGFS_WRITE_FUNC(name); \
  82. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  83. .write = iwl_dbgfs_##name##_write, \
  84. .open = iwl_dbgfs_open_file_generic, \
  85. };
  86. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  87. DEBUGFS_READ_FUNC(name); \
  88. DEBUGFS_WRITE_FUNC(name); \
  89. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  90. .write = iwl_dbgfs_##name##_write, \
  91. .read = iwl_dbgfs_##name##_read, \
  92. .open = iwl_dbgfs_open_file_generic, \
  93. };
  94. static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
  95. char __user *user_buf,
  96. size_t count, loff_t *ppos) {
  97. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  98. char buf[256];
  99. int pos = 0;
  100. const size_t bufsz = sizeof(buf);
  101. pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
  102. priv->tx_stats[0].cnt);
  103. pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
  104. priv->tx_stats[1].cnt);
  105. pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
  106. priv->tx_stats[2].cnt);
  107. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  108. }
  109. static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
  110. char __user *user_buf,
  111. size_t count, loff_t *ppos) {
  112. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  113. char buf[256];
  114. int pos = 0;
  115. const size_t bufsz = sizeof(buf);
  116. pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
  117. priv->rx_stats[0].cnt);
  118. pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
  119. priv->rx_stats[1].cnt);
  120. pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
  121. priv->rx_stats[2].cnt);
  122. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  123. }
  124. #define BYTE1_MASK 0x000000ff;
  125. #define BYTE2_MASK 0x0000ffff;
  126. #define BYTE3_MASK 0x00ffffff;
  127. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  128. char __user *user_buf,
  129. size_t count, loff_t *ppos)
  130. {
  131. u32 val;
  132. char buf[1024];
  133. ssize_t ret;
  134. int i;
  135. int pos = 0;
  136. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  137. const size_t bufsz = sizeof(buf);
  138. printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n",
  139. priv->dbgfs->sram_offset, priv->dbgfs->sram_len);
  140. iwl_grab_nic_access(priv);
  141. for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
  142. val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
  143. priv->dbgfs->sram_len - i);
  144. if (i < 4) {
  145. switch (i) {
  146. case 1:
  147. val &= BYTE1_MASK;
  148. break;
  149. case 2:
  150. val &= BYTE2_MASK;
  151. break;
  152. case 3:
  153. val &= BYTE3_MASK;
  154. break;
  155. }
  156. }
  157. pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
  158. }
  159. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  160. iwl_release_nic_access(priv);
  161. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  162. return ret;
  163. }
  164. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  165. const char __user *user_buf,
  166. size_t count, loff_t *ppos)
  167. {
  168. struct iwl_priv *priv = file->private_data;
  169. char buf[64];
  170. int buf_size;
  171. u32 offset, len;
  172. memset(buf, 0, sizeof(buf));
  173. buf_size = min(count, sizeof(buf) - 1);
  174. if (copy_from_user(buf, user_buf, buf_size))
  175. return -EFAULT;
  176. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  177. priv->dbgfs->sram_offset = offset;
  178. priv->dbgfs->sram_len = len;
  179. } else {
  180. priv->dbgfs->sram_offset = 0;
  181. priv->dbgfs->sram_len = 0;
  182. }
  183. return count;
  184. }
  185. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  186. size_t count, loff_t *ppos)
  187. {
  188. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  189. struct iwl_station_entry *station;
  190. int max_sta = priv->hw_params.max_stations;
  191. char *buf;
  192. int i, j, pos = 0;
  193. ssize_t ret;
  194. /* Add 30 for initial string */
  195. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  196. DECLARE_MAC_BUF(mac);
  197. buf = kmalloc(bufsz, GFP_KERNEL);
  198. if (!buf)
  199. return -ENOMEM;
  200. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  201. priv->num_stations);
  202. for (i = 0; i < max_sta; i++) {
  203. station = &priv->stations[i];
  204. if (station->used) {
  205. pos += scnprintf(buf + pos, bufsz - pos,
  206. "station %d:\ngeneral data:\n", i+1);
  207. print_mac(mac, station->sta.sta.addr);
  208. pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
  209. station->sta.sta.sta_id);
  210. pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
  211. station->sta.mode);
  212. pos += scnprintf(buf + pos, bufsz - pos,
  213. "flags: 0x%x\n",
  214. station->sta.station_flags_msk);
  215. pos += scnprintf(buf + pos, bufsz - pos,
  216. "ps_status: %u\n", station->ps_status);
  217. pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
  218. pos += scnprintf(buf + pos, bufsz - pos,
  219. "seq_num\t\ttxq_id");
  220. pos += scnprintf(buf + pos, bufsz - pos,
  221. "\tframe_count\twait_for_ba\t");
  222. pos += scnprintf(buf + pos, bufsz - pos,
  223. "start_idx\tbitmap0\t");
  224. pos += scnprintf(buf + pos, bufsz - pos,
  225. "bitmap1\trate_n_flags");
  226. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  227. for (j = 0; j < MAX_TID_COUNT; j++) {
  228. pos += scnprintf(buf + pos, bufsz - pos,
  229. "[%d]:\t\t%u", j,
  230. station->tid[j].seq_number);
  231. pos += scnprintf(buf + pos, bufsz - pos,
  232. "\t%u\t\t%u\t\t%u\t\t",
  233. station->tid[j].agg.txq_id,
  234. station->tid[j].agg.frame_count,
  235. station->tid[j].agg.wait_for_ba);
  236. pos += scnprintf(buf + pos, bufsz - pos,
  237. "%u\t%llu\t%u",
  238. station->tid[j].agg.start_idx,
  239. (unsigned long long)station->tid[j].agg.bitmap,
  240. station->tid[j].agg.rate_n_flags);
  241. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  242. }
  243. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  244. }
  245. }
  246. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  247. kfree(buf);
  248. return ret;
  249. }
  250. static ssize_t iwl_dbgfs_eeprom_read(struct file *file,
  251. char __user *user_buf,
  252. size_t count,
  253. loff_t *ppos)
  254. {
  255. ssize_t ret;
  256. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  257. int pos = 0, ofs = 0, buf_size = 0;
  258. const u8 *ptr;
  259. char *buf;
  260. size_t eeprom_len = priv->cfg->eeprom_size;
  261. buf_size = 4 * eeprom_len + 256;
  262. if (eeprom_len % 16) {
  263. IWL_ERROR("EEPROM size is not multiple of 16.\n");
  264. return -ENODATA;
  265. }
  266. /* 4 characters for byte 0xYY */
  267. buf = kzalloc(buf_size, GFP_KERNEL);
  268. if (!buf) {
  269. IWL_ERROR("Can not allocate Buffer\n");
  270. return -ENOMEM;
  271. }
  272. ptr = priv->eeprom;
  273. for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
  274. pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
  275. hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
  276. buf_size - pos, 0);
  277. pos += strlen(buf);
  278. if (buf_size - pos > 0)
  279. buf[pos++] = '\n';
  280. }
  281. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  282. kfree(buf);
  283. return ret;
  284. }
  285. static ssize_t iwl_dbgfs_log_event_write(struct file *file,
  286. const char __user *user_buf,
  287. size_t count, loff_t *ppos)
  288. {
  289. struct iwl_priv *priv = file->private_data;
  290. u32 event_log_flag;
  291. char buf[8];
  292. int buf_size;
  293. memset(buf, 0, sizeof(buf));
  294. buf_size = min(count, sizeof(buf) - 1);
  295. if (copy_from_user(buf, user_buf, buf_size))
  296. return -EFAULT;
  297. if (sscanf(buf, "%d", &event_log_flag) != 1)
  298. return -EFAULT;
  299. if (event_log_flag == 1)
  300. iwl_dump_nic_event_log(priv);
  301. return count;
  302. }
  303. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  304. DEBUGFS_WRITE_FILE_OPS(log_event);
  305. DEBUGFS_READ_FILE_OPS(eeprom);
  306. DEBUGFS_READ_FILE_OPS(stations);
  307. DEBUGFS_READ_FILE_OPS(rx_statistics);
  308. DEBUGFS_READ_FILE_OPS(tx_statistics);
  309. /*
  310. * Create the debugfs files and directories
  311. *
  312. */
  313. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  314. {
  315. struct iwl_debugfs *dbgfs;
  316. struct dentry *phyd = priv->hw->wiphy->debugfsdir;
  317. int ret = 0;
  318. dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
  319. if (!dbgfs) {
  320. ret = -ENOMEM;
  321. goto err;
  322. }
  323. priv->dbgfs = dbgfs;
  324. dbgfs->name = name;
  325. dbgfs->dir_drv = debugfs_create_dir(name, phyd);
  326. if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
  327. ret = -ENOENT;
  328. goto err;
  329. }
  330. DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
  331. DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
  332. DEBUGFS_ADD_FILE(eeprom, data);
  333. DEBUGFS_ADD_FILE(sram, data);
  334. DEBUGFS_ADD_FILE(log_event, data);
  335. DEBUGFS_ADD_FILE(stations, data);
  336. DEBUGFS_ADD_FILE(rx_statistics, data);
  337. DEBUGFS_ADD_FILE(tx_statistics, data);
  338. DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
  339. DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
  340. &priv->disable_chain_noise_cal);
  341. DEBUGFS_ADD_BOOL(disable_tx_power, rf, &priv->disable_tx_power_cal);
  342. return 0;
  343. err:
  344. IWL_ERROR("Can't open the debugfs directory\n");
  345. iwl_dbgfs_unregister(priv);
  346. return ret;
  347. }
  348. EXPORT_SYMBOL(iwl_dbgfs_register);
  349. /**
  350. * Remove the debugfs files and directories
  351. *
  352. */
  353. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  354. {
  355. if (!priv->dbgfs)
  356. return;
  357. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_eeprom);
  358. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
  359. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
  360. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
  361. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
  362. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
  363. DEBUGFS_REMOVE(priv->dbgfs->dir_data);
  364. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
  365. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
  366. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
  367. DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
  368. DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
  369. kfree(priv->dbgfs);
  370. priv->dbgfs = NULL;
  371. }
  372. EXPORT_SYMBOL(iwl_dbgfs_unregister);