debugfs.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /*
  2. * Intel Wireless Multicomm 3200 WiFi driver
  3. *
  4. * Copyright (C) 2009 Intel Corporation <ilw@linux.intel.com>
  5. * Samuel Ortiz <samuel.ortiz@intel.com>
  6. * Zhu Yi <yi.zhu@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License version
  10. * 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301, USA.
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/bitops.h>
  25. #include <linux/debugfs.h>
  26. #include "iwm.h"
  27. #include "bus.h"
  28. #include "rx.h"
  29. #include "debug.h"
  30. static struct {
  31. u8 id;
  32. char *name;
  33. } iwm_debug_module[__IWM_DM_NR] = {
  34. {IWM_DM_BOOT, "boot"},
  35. {IWM_DM_FW, "fw"},
  36. {IWM_DM_SDIO, "sdio"},
  37. {IWM_DM_NTF, "ntf"},
  38. {IWM_DM_RX, "rx"},
  39. {IWM_DM_TX, "tx"},
  40. {IWM_DM_MLME, "mlme"},
  41. {IWM_DM_CMD, "cmd"},
  42. {IWM_DM_WEXT, "wext"},
  43. };
  44. #define add_dbg_module(dbg, name, id, initlevel) \
  45. do { \
  46. struct dentry *d; \
  47. dbg.dbg_module[id] = (initlevel); \
  48. d = debugfs_create_x8(name, 0600, dbg.dbgdir, \
  49. &(dbg.dbg_module[id])); \
  50. if (!IS_ERR(d)) \
  51. dbg.dbg_module_dentries[id] = d; \
  52. } while (0)
  53. static int iwm_debugfs_u32_read(void *data, u64 *val)
  54. {
  55. struct iwm_priv *iwm = data;
  56. *val = iwm->dbg.dbg_level;
  57. return 0;
  58. }
  59. static int iwm_debugfs_dbg_level_write(void *data, u64 val)
  60. {
  61. struct iwm_priv *iwm = data;
  62. int i;
  63. iwm->dbg.dbg_level = val;
  64. for (i = 0; i < __IWM_DM_NR; i++)
  65. iwm->dbg.dbg_module[i] = val;
  66. return 0;
  67. }
  68. DEFINE_SIMPLE_ATTRIBUTE(fops_iwm_dbg_level,
  69. iwm_debugfs_u32_read, iwm_debugfs_dbg_level_write,
  70. "%llu\n");
  71. static int iwm_debugfs_dbg_modules_write(void *data, u64 val)
  72. {
  73. struct iwm_priv *iwm = data;
  74. int i, bit;
  75. iwm->dbg.dbg_modules = val;
  76. for (i = 0; i < __IWM_DM_NR; i++)
  77. iwm->dbg.dbg_module[i] = 0;
  78. for_each_bit(bit, &iwm->dbg.dbg_modules, __IWM_DM_NR)
  79. iwm->dbg.dbg_module[bit] = iwm->dbg.dbg_level;
  80. return 0;
  81. }
  82. DEFINE_SIMPLE_ATTRIBUTE(fops_iwm_dbg_modules,
  83. iwm_debugfs_u32_read, iwm_debugfs_dbg_modules_write,
  84. "%llu\n");
  85. static int iwm_txrx_open(struct inode *inode, struct file *filp)
  86. {
  87. filp->private_data = inode->i_private;
  88. return 0;
  89. }
  90. static ssize_t iwm_debugfs_txq_read(struct file *filp, char __user *buffer,
  91. size_t count, loff_t *ppos)
  92. {
  93. struct iwm_priv *iwm = filp->private_data;
  94. char *buf;
  95. int i, buf_len = 4096;
  96. size_t len = 0;
  97. ssize_t ret;
  98. if (*ppos != 0)
  99. return 0;
  100. if (count < sizeof(buf))
  101. return -ENOSPC;
  102. buf = kzalloc(buf_len, GFP_KERNEL);
  103. if (!buf)
  104. return -ENOMEM;
  105. for (i = 0; i < IWM_TX_QUEUES; i++) {
  106. struct iwm_tx_queue *txq = &iwm->txq[i];
  107. struct sk_buff *skb;
  108. int j;
  109. unsigned long flags;
  110. spin_lock_irqsave(&txq->queue.lock, flags);
  111. skb = (struct sk_buff *)&txq->queue;
  112. len += snprintf(buf + len, buf_len - len, "TXQ #%d\n", i);
  113. len += snprintf(buf + len, buf_len - len, "\tStopped: %d\n",
  114. __netif_subqueue_stopped(iwm_to_ndev(iwm),
  115. txq->id));
  116. len += snprintf(buf + len, buf_len - len, "\tConcat count:%d\n",
  117. txq->concat_count);
  118. len += snprintf(buf + len, buf_len - len, "\tQueue len: %d\n",
  119. skb_queue_len(&txq->queue));
  120. for (j = 0; j < skb_queue_len(&txq->queue); j++) {
  121. struct iwm_tx_info *tx_info;
  122. skb = skb->next;
  123. tx_info = skb_to_tx_info(skb);
  124. len += snprintf(buf + len, buf_len - len,
  125. "\tSKB #%d\n", j);
  126. len += snprintf(buf + len, buf_len - len,
  127. "\t\tsta: %d\n", tx_info->sta);
  128. len += snprintf(buf + len, buf_len - len,
  129. "\t\tcolor: %d\n", tx_info->color);
  130. len += snprintf(buf + len, buf_len - len,
  131. "\t\ttid: %d\n", tx_info->tid);
  132. }
  133. spin_unlock_irqrestore(&txq->queue.lock, flags);
  134. }
  135. ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
  136. kfree(buf);
  137. return ret;
  138. }
  139. static ssize_t iwm_debugfs_tx_credit_read(struct file *filp,
  140. char __user *buffer,
  141. size_t count, loff_t *ppos)
  142. {
  143. struct iwm_priv *iwm = filp->private_data;
  144. struct iwm_tx_credit *credit = &iwm->tx_credit;
  145. char *buf;
  146. int i, buf_len = 4096;
  147. size_t len = 0;
  148. ssize_t ret;
  149. if (*ppos != 0)
  150. return 0;
  151. if (count < sizeof(buf))
  152. return -ENOSPC;
  153. buf = kzalloc(buf_len, GFP_KERNEL);
  154. if (!buf)
  155. return -ENOMEM;
  156. len += snprintf(buf + len, buf_len - len,
  157. "NR pools: %d\n", credit->pool_nr);
  158. len += snprintf(buf + len, buf_len - len,
  159. "pools map: 0x%lx\n", credit->full_pools_map);
  160. len += snprintf(buf + len, buf_len - len, "\n### POOLS ###\n");
  161. for (i = 0; i < IWM_MACS_OUT_GROUPS; i++) {
  162. len += snprintf(buf + len, buf_len - len,
  163. "pools entry #%d\n", i);
  164. len += snprintf(buf + len, buf_len - len,
  165. "\tid: %d\n",
  166. credit->pools[i].id);
  167. len += snprintf(buf + len, buf_len - len,
  168. "\tsid: %d\n",
  169. credit->pools[i].sid);
  170. len += snprintf(buf + len, buf_len - len,
  171. "\tmin_pages: %d\n",
  172. credit->pools[i].min_pages);
  173. len += snprintf(buf + len, buf_len - len,
  174. "\tmax_pages: %d\n",
  175. credit->pools[i].max_pages);
  176. len += snprintf(buf + len, buf_len - len,
  177. "\talloc_pages: %d\n",
  178. credit->pools[i].alloc_pages);
  179. len += snprintf(buf + len, buf_len - len,
  180. "\tfreed_pages: %d\n",
  181. credit->pools[i].total_freed_pages);
  182. }
  183. len += snprintf(buf + len, buf_len - len, "\n### SPOOLS ###\n");
  184. for (i = 0; i < IWM_MACS_OUT_SGROUPS; i++) {
  185. len += snprintf(buf + len, buf_len - len,
  186. "spools entry #%d\n", i);
  187. len += snprintf(buf + len, buf_len - len,
  188. "\tid: %d\n",
  189. credit->spools[i].id);
  190. len += snprintf(buf + len, buf_len - len,
  191. "\tmax_pages: %d\n",
  192. credit->spools[i].max_pages);
  193. len += snprintf(buf + len, buf_len - len,
  194. "\talloc_pages: %d\n",
  195. credit->spools[i].alloc_pages);
  196. }
  197. ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
  198. kfree(buf);
  199. return ret;
  200. }
  201. static ssize_t iwm_debugfs_rx_ticket_read(struct file *filp,
  202. char __user *buffer,
  203. size_t count, loff_t *ppos)
  204. {
  205. struct iwm_priv *iwm = filp->private_data;
  206. struct iwm_rx_ticket_node *ticket, *next;
  207. char *buf;
  208. int buf_len = 4096, i;
  209. size_t len = 0;
  210. ssize_t ret;
  211. if (*ppos != 0)
  212. return 0;
  213. if (count < sizeof(buf))
  214. return -ENOSPC;
  215. buf = kzalloc(buf_len, GFP_KERNEL);
  216. if (!buf)
  217. return -ENOMEM;
  218. list_for_each_entry_safe(ticket, next, &iwm->rx_tickets, node) {
  219. len += snprintf(buf + len, buf_len - len, "Ticket #%d\n",
  220. ticket->ticket->id);
  221. len += snprintf(buf + len, buf_len - len, "\taction: 0x%x\n",
  222. ticket->ticket->action);
  223. len += snprintf(buf + len, buf_len - len, "\tflags: 0x%x\n",
  224. ticket->ticket->flags);
  225. }
  226. for (i = 0; i < IWM_RX_ID_HASH; i++) {
  227. struct iwm_rx_packet *packet, *nxt;
  228. struct list_head *pkt_list = &iwm->rx_packets[i];
  229. if (!list_empty(pkt_list)) {
  230. len += snprintf(buf + len, buf_len - len,
  231. "Packet hash #%d\n", i);
  232. list_for_each_entry_safe(packet, nxt, pkt_list, node) {
  233. len += snprintf(buf + len, buf_len - len,
  234. "\tPacket id: %d\n",
  235. packet->id);
  236. len += snprintf(buf + len, buf_len - len,
  237. "\tPacket length: %lu\n",
  238. packet->pkt_size);
  239. }
  240. }
  241. }
  242. ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
  243. kfree(buf);
  244. return ret;
  245. }
  246. static const struct file_operations iwm_debugfs_txq_fops = {
  247. .owner = THIS_MODULE,
  248. .open = iwm_txrx_open,
  249. .read = iwm_debugfs_txq_read,
  250. };
  251. static const struct file_operations iwm_debugfs_tx_credit_fops = {
  252. .owner = THIS_MODULE,
  253. .open = iwm_txrx_open,
  254. .read = iwm_debugfs_tx_credit_read,
  255. };
  256. static const struct file_operations iwm_debugfs_rx_ticket_fops = {
  257. .owner = THIS_MODULE,
  258. .open = iwm_txrx_open,
  259. .read = iwm_debugfs_rx_ticket_read,
  260. };
  261. int iwm_debugfs_init(struct iwm_priv *iwm)
  262. {
  263. int i, result;
  264. char devdir[16];
  265. iwm->dbg.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
  266. result = PTR_ERR(iwm->dbg.rootdir);
  267. if (!result || IS_ERR(iwm->dbg.rootdir)) {
  268. if (result == -ENODEV) {
  269. IWM_ERR(iwm, "DebugFS (CONFIG_DEBUG_FS) not "
  270. "enabled in kernel config\n");
  271. result = 0; /* No debugfs support */
  272. }
  273. IWM_ERR(iwm, "Couldn't create rootdir: %d\n", result);
  274. goto error;
  275. }
  276. snprintf(devdir, sizeof(devdir), "%s", wiphy_name(iwm_to_wiphy(iwm)));
  277. iwm->dbg.devdir = debugfs_create_dir(devdir, iwm->dbg.rootdir);
  278. result = PTR_ERR(iwm->dbg.devdir);
  279. if (IS_ERR(iwm->dbg.devdir) && (result != -ENODEV)) {
  280. IWM_ERR(iwm, "Couldn't create devdir: %d\n", result);
  281. goto error;
  282. }
  283. iwm->dbg.dbgdir = debugfs_create_dir("debug", iwm->dbg.devdir);
  284. result = PTR_ERR(iwm->dbg.dbgdir);
  285. if (IS_ERR(iwm->dbg.dbgdir) && (result != -ENODEV)) {
  286. IWM_ERR(iwm, "Couldn't create dbgdir: %d\n", result);
  287. goto error;
  288. }
  289. iwm->dbg.rxdir = debugfs_create_dir("rx", iwm->dbg.devdir);
  290. result = PTR_ERR(iwm->dbg.rxdir);
  291. if (IS_ERR(iwm->dbg.rxdir) && (result != -ENODEV)) {
  292. IWM_ERR(iwm, "Couldn't create rx dir: %d\n", result);
  293. goto error;
  294. }
  295. iwm->dbg.txdir = debugfs_create_dir("tx", iwm->dbg.devdir);
  296. result = PTR_ERR(iwm->dbg.txdir);
  297. if (IS_ERR(iwm->dbg.txdir) && (result != -ENODEV)) {
  298. IWM_ERR(iwm, "Couldn't create tx dir: %d\n", result);
  299. goto error;
  300. }
  301. iwm->dbg.busdir = debugfs_create_dir("bus", iwm->dbg.devdir);
  302. result = PTR_ERR(iwm->dbg.busdir);
  303. if (IS_ERR(iwm->dbg.busdir) && (result != -ENODEV)) {
  304. IWM_ERR(iwm, "Couldn't create bus dir: %d\n", result);
  305. goto error;
  306. }
  307. if (iwm->bus_ops->debugfs_init) {
  308. result = iwm->bus_ops->debugfs_init(iwm, iwm->dbg.busdir);
  309. if (result < 0) {
  310. IWM_ERR(iwm, "Couldn't create bus entry: %d\n", result);
  311. goto error;
  312. }
  313. }
  314. iwm->dbg.dbg_level = IWM_DL_NONE;
  315. iwm->dbg.dbg_level_dentry =
  316. debugfs_create_file("level", 0200, iwm->dbg.dbgdir, iwm,
  317. &fops_iwm_dbg_level);
  318. result = PTR_ERR(iwm->dbg.dbg_level_dentry);
  319. if (IS_ERR(iwm->dbg.dbg_level_dentry) && (result != -ENODEV)) {
  320. IWM_ERR(iwm, "Couldn't create dbg_level: %d\n", result);
  321. goto error;
  322. }
  323. iwm->dbg.dbg_modules = IWM_DM_DEFAULT;
  324. iwm->dbg.dbg_modules_dentry =
  325. debugfs_create_file("modules", 0200, iwm->dbg.dbgdir, iwm,
  326. &fops_iwm_dbg_modules);
  327. result = PTR_ERR(iwm->dbg.dbg_modules_dentry);
  328. if (IS_ERR(iwm->dbg.dbg_modules_dentry) && (result != -ENODEV)) {
  329. IWM_ERR(iwm, "Couldn't create dbg_modules: %d\n", result);
  330. goto error;
  331. }
  332. for (i = 0; i < __IWM_DM_NR; i++)
  333. add_dbg_module(iwm->dbg, iwm_debug_module[i].name,
  334. iwm_debug_module[i].id, IWM_DL_DEFAULT);
  335. iwm->dbg.txq_dentry = debugfs_create_file("queues", 0200,
  336. iwm->dbg.txdir, iwm,
  337. &iwm_debugfs_txq_fops);
  338. result = PTR_ERR(iwm->dbg.txq_dentry);
  339. if (IS_ERR(iwm->dbg.txq_dentry) && (result != -ENODEV)) {
  340. IWM_ERR(iwm, "Couldn't create tx queue: %d\n", result);
  341. goto error;
  342. }
  343. iwm->dbg.tx_credit_dentry = debugfs_create_file("credits", 0200,
  344. iwm->dbg.txdir, iwm,
  345. &iwm_debugfs_tx_credit_fops);
  346. result = PTR_ERR(iwm->dbg.tx_credit_dentry);
  347. if (IS_ERR(iwm->dbg.tx_credit_dentry) && (result != -ENODEV)) {
  348. IWM_ERR(iwm, "Couldn't create tx credit: %d\n", result);
  349. goto error;
  350. }
  351. iwm->dbg.rx_ticket_dentry = debugfs_create_file("tickets", 0200,
  352. iwm->dbg.rxdir, iwm,
  353. &iwm_debugfs_rx_ticket_fops);
  354. result = PTR_ERR(iwm->dbg.rx_ticket_dentry);
  355. if (IS_ERR(iwm->dbg.rx_ticket_dentry) && (result != -ENODEV)) {
  356. IWM_ERR(iwm, "Couldn't create rx ticket: %d\n", result);
  357. goto error;
  358. }
  359. return 0;
  360. error:
  361. return result;
  362. }
  363. void iwm_debugfs_exit(struct iwm_priv *iwm)
  364. {
  365. int i;
  366. for (i = 0; i < __IWM_DM_NR; i++)
  367. debugfs_remove(iwm->dbg.dbg_module_dentries[i]);
  368. debugfs_remove(iwm->dbg.dbg_modules_dentry);
  369. debugfs_remove(iwm->dbg.dbg_level_dentry);
  370. debugfs_remove(iwm->dbg.txq_dentry);
  371. debugfs_remove(iwm->dbg.tx_credit_dentry);
  372. debugfs_remove(iwm->dbg.rx_ticket_dentry);
  373. if (iwm->bus_ops->debugfs_exit)
  374. iwm->bus_ops->debugfs_exit(iwm);
  375. debugfs_remove(iwm->dbg.busdir);
  376. debugfs_remove(iwm->dbg.dbgdir);
  377. debugfs_remove(iwm->dbg.txdir);
  378. debugfs_remove(iwm->dbg.rxdir);
  379. debugfs_remove(iwm->dbg.devdir);
  380. debugfs_remove(iwm->dbg.rootdir);
  381. }