iwl-debugfs.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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-4965.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_REMOVE(name) do { \
  51. debugfs_remove(name); \
  52. name = NULL; \
  53. } while (0);
  54. /* file operation */
  55. #define DEBUGFS_READ_FUNC(name) \
  56. static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
  57. char __user *user_buf, \
  58. size_t count, loff_t *ppos);
  59. #define DEBUGFS_WRITE_FUNC(name) \
  60. static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
  61. const char __user *user_buf, \
  62. size_t count, loff_t *ppos);
  63. static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
  64. {
  65. file->private_data = inode->i_private;
  66. return 0;
  67. }
  68. #define DEBUGFS_READ_FILE_OPS(name) \
  69. DEBUGFS_READ_FUNC(name); \
  70. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  71. .read = iwl_dbgfs_##name##_read, \
  72. .open = iwl_dbgfs_open_file_generic, \
  73. };
  74. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  75. DEBUGFS_READ_FUNC(name); \
  76. DEBUGFS_WRITE_FUNC(name); \
  77. static const struct file_operations iwl_dbgfs_##name##_ops = { \
  78. .write = iwl_dbgfs_##name##_write, \
  79. .read = iwl_dbgfs_##name##_read, \
  80. .open = iwl_dbgfs_open_file_generic, \
  81. };
  82. static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
  83. char __user *user_buf,
  84. size_t count, loff_t *ppos) {
  85. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  86. char buf[256];
  87. int pos = 0;
  88. const size_t bufsz = sizeof(buf);
  89. pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
  90. priv->tx_stats[0].cnt);
  91. pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
  92. priv->tx_stats[1].cnt);
  93. pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
  94. priv->tx_stats[2].cnt);
  95. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  96. }
  97. static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
  98. char __user *user_buf,
  99. size_t count, loff_t *ppos) {
  100. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  101. char buf[256];
  102. int pos = 0;
  103. const size_t bufsz = sizeof(buf);
  104. pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
  105. priv->rx_stats[0].cnt);
  106. pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
  107. priv->rx_stats[1].cnt);
  108. pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
  109. priv->rx_stats[2].cnt);
  110. return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  111. }
  112. #define BYTE1_MASK 0x000000ff;
  113. #define BYTE2_MASK 0x0000ffff;
  114. #define BYTE3_MASK 0x00ffffff;
  115. static ssize_t iwl_dbgfs_sram_read(struct file *file,
  116. char __user *user_buf,
  117. size_t count, loff_t *ppos)
  118. {
  119. u32 val;
  120. char buf[1024];
  121. ssize_t ret;
  122. int i;
  123. int pos = 0;
  124. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  125. const size_t bufsz = sizeof(buf);
  126. printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n",
  127. priv->dbgfs->sram_offset, priv->dbgfs->sram_len);
  128. iwl_grab_nic_access(priv);
  129. for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
  130. val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
  131. priv->dbgfs->sram_len - i);
  132. if (i < 4) {
  133. switch (i) {
  134. case 1:
  135. val &= BYTE1_MASK;
  136. break;
  137. case 2:
  138. val &= BYTE2_MASK;
  139. break;
  140. case 3:
  141. val &= BYTE3_MASK;
  142. break;
  143. }
  144. }
  145. pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
  146. }
  147. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  148. iwl_release_nic_access(priv);
  149. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  150. return ret;
  151. }
  152. static ssize_t iwl_dbgfs_sram_write(struct file *file,
  153. const char __user *user_buf,
  154. size_t count, loff_t *ppos)
  155. {
  156. struct iwl_priv *priv = file->private_data;
  157. char buf[64];
  158. int buf_size;
  159. u32 offset, len;
  160. memset(buf, 0, sizeof(buf));
  161. buf_size = min(count, sizeof(buf) - 1);
  162. if (copy_from_user(buf, user_buf, buf_size))
  163. return -EFAULT;
  164. if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
  165. priv->dbgfs->sram_offset = offset;
  166. priv->dbgfs->sram_len = len;
  167. } else {
  168. priv->dbgfs->sram_offset = 0;
  169. priv->dbgfs->sram_len = 0;
  170. }
  171. return count;
  172. }
  173. static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
  174. size_t count, loff_t *ppos)
  175. {
  176. struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
  177. struct iwl4965_station_entry *station;
  178. int max_sta = priv->hw_params.max_stations;
  179. char *buf;
  180. int i, j, pos = 0;
  181. ssize_t ret;
  182. /* Add 30 for initial string */
  183. const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
  184. DECLARE_MAC_BUF(mac);
  185. buf = kmalloc(bufsz, GFP_KERNEL);
  186. if(!buf)
  187. return -ENOMEM;
  188. pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
  189. priv->num_stations);
  190. for (i = 0; i < max_sta; i++) {
  191. station = &priv->stations[i];
  192. if (station->used) {
  193. pos += scnprintf(buf + pos, bufsz - pos,
  194. "station %d:\ngeneral data:\n", i+1);
  195. print_mac(mac, station->sta.sta.addr);
  196. pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
  197. station->sta.sta.sta_id);
  198. pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
  199. station->sta.mode);
  200. pos += scnprintf(buf + pos, bufsz - pos,
  201. "flags: 0x%x\n",
  202. station->sta.station_flags_msk);
  203. pos += scnprintf(buf + pos, bufsz - pos,
  204. "ps_status: %u\n", station->ps_status);
  205. pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
  206. pos += scnprintf(buf + pos, bufsz - pos,
  207. "seq_num\t\ttxq_id");
  208. #ifdef CONFIG_IWL4965_HT
  209. pos += scnprintf(buf + pos, bufsz - pos,
  210. "\tframe_count\twait_for_ba\t");
  211. pos += scnprintf(buf + pos, bufsz - pos,
  212. "start_idx\tbitmap0\t");
  213. pos += scnprintf(buf + pos, bufsz - pos,
  214. "bitmap1\trate_n_flags");
  215. #endif
  216. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  217. for (j = 0; j < MAX_TID_COUNT; j++) {
  218. pos += scnprintf(buf + pos, bufsz - pos,
  219. "[%d]:\t\t%u", j,
  220. station->tid[j].seq_number);
  221. #ifdef CONFIG_IWL4965_HT
  222. pos += scnprintf(buf + pos, bufsz - pos,
  223. "\t%u\t\t%u\t\t%u\t\t",
  224. station->tid[j].agg.txq_id,
  225. station->tid[j].agg.frame_count,
  226. station->tid[j].agg.wait_for_ba);
  227. pos += scnprintf(buf + pos, bufsz - pos,
  228. "%u\t%llu\t%u",
  229. station->tid[j].agg.start_idx,
  230. (unsigned long long)station->tid[j].agg.bitmap,
  231. station->tid[j].agg.rate_n_flags);
  232. #endif
  233. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  234. }
  235. pos += scnprintf(buf + pos, bufsz - pos, "\n");
  236. }
  237. }
  238. ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
  239. kfree(buf);
  240. return ret;
  241. }
  242. DEBUGFS_READ_WRITE_FILE_OPS(sram);
  243. DEBUGFS_READ_FILE_OPS(stations);
  244. DEBUGFS_READ_FILE_OPS(rx_statistics);
  245. DEBUGFS_READ_FILE_OPS(tx_statistics);
  246. /*
  247. * Create the debugfs files and directories
  248. *
  249. */
  250. int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
  251. {
  252. struct iwl_debugfs *dbgfs;
  253. dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
  254. if (!dbgfs) {
  255. goto err;
  256. }
  257. priv->dbgfs = dbgfs;
  258. dbgfs->name = name;
  259. dbgfs->dir_drv = debugfs_create_dir(name, NULL);
  260. if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)){
  261. goto err;
  262. }
  263. DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
  264. DEBUGFS_ADD_FILE(sram, data);
  265. DEBUGFS_ADD_FILE(stations, data);
  266. DEBUGFS_ADD_FILE(rx_statistics, data);
  267. DEBUGFS_ADD_FILE(tx_statistics, data);
  268. return 0;
  269. err:
  270. IWL_ERROR("Can't open the debugfs directory\n");
  271. iwl_dbgfs_unregister(priv);
  272. return -ENOENT;
  273. }
  274. EXPORT_SYMBOL(iwl_dbgfs_register);
  275. /**
  276. * Remove the debugfs files and directories
  277. *
  278. */
  279. void iwl_dbgfs_unregister(struct iwl_priv *priv)
  280. {
  281. if (!(priv->dbgfs))
  282. return;
  283. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
  284. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
  285. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
  286. DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
  287. DEBUGFS_REMOVE(priv->dbgfs->dir_data);
  288. DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
  289. kfree(priv->dbgfs);
  290. priv->dbgfs = NULL;
  291. }
  292. EXPORT_SYMBOL(iwl_dbgfs_unregister);