debugfs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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/slab.h>
  24. #include <linux/kernel.h>
  25. #include <linux/bitops.h>
  26. #include <linux/debugfs.h>
  27. #include <linux/export.h>
  28. #include "iwm.h"
  29. #include "bus.h"
  30. #include "rx.h"
  31. #include "debug.h"
  32. static struct {
  33. u8 id;
  34. char *name;
  35. } iwm_debug_module[__IWM_DM_NR] = {
  36. {IWM_DM_BOOT, "boot"},
  37. {IWM_DM_FW, "fw"},
  38. {IWM_DM_SDIO, "sdio"},
  39. {IWM_DM_NTF, "ntf"},
  40. {IWM_DM_RX, "rx"},
  41. {IWM_DM_TX, "tx"},
  42. {IWM_DM_MLME, "mlme"},
  43. {IWM_DM_CMD, "cmd"},
  44. {IWM_DM_WEXT, "wext"},
  45. };
  46. #define add_dbg_module(dbg, name, id, initlevel) \
  47. do { \
  48. dbg.dbg_module[id] = (initlevel); \
  49. dbg.dbg_module_dentries[id] = \
  50. debugfs_create_x8(name, 0600, \
  51. dbg.dbgdir, \
  52. &(dbg.dbg_module[id])); \
  53. } while (0)
  54. static int iwm_debugfs_u32_read(void *data, u64 *val)
  55. {
  56. struct iwm_priv *iwm = data;
  57. *val = iwm->dbg.dbg_level;
  58. return 0;
  59. }
  60. static int iwm_debugfs_dbg_level_write(void *data, u64 val)
  61. {
  62. struct iwm_priv *iwm = data;
  63. int i;
  64. iwm->dbg.dbg_level = val;
  65. for (i = 0; i < __IWM_DM_NR; i++)
  66. iwm->dbg.dbg_module[i] = val;
  67. return 0;
  68. }
  69. DEFINE_SIMPLE_ATTRIBUTE(fops_iwm_dbg_level,
  70. iwm_debugfs_u32_read, iwm_debugfs_dbg_level_write,
  71. "%llu\n");
  72. static int iwm_debugfs_dbg_modules_write(void *data, u64 val)
  73. {
  74. struct iwm_priv *iwm = data;
  75. int i, bit;
  76. iwm->dbg.dbg_modules = val;
  77. for (i = 0; i < __IWM_DM_NR; i++)
  78. iwm->dbg.dbg_module[i] = 0;
  79. for_each_set_bit(bit, &iwm->dbg.dbg_modules, __IWM_DM_NR)
  80. iwm->dbg.dbg_module[bit] = iwm->dbg.dbg_level;
  81. return 0;
  82. }
  83. DEFINE_SIMPLE_ATTRIBUTE(fops_iwm_dbg_modules,
  84. iwm_debugfs_u32_read, iwm_debugfs_dbg_modules_write,
  85. "%llu\n");
  86. static int iwm_generic_open(struct inode *inode, struct file *filp)
  87. {
  88. filp->private_data = inode->i_private;
  89. return 0;
  90. }
  91. static ssize_t iwm_debugfs_txq_read(struct file *filp, char __user *buffer,
  92. size_t count, loff_t *ppos)
  93. {
  94. struct iwm_priv *iwm = filp->private_data;
  95. char *buf;
  96. int i, buf_len = 4096;
  97. size_t len = 0;
  98. ssize_t ret;
  99. if (*ppos != 0)
  100. return 0;
  101. if (count < sizeof(buf))
  102. return -ENOSPC;
  103. buf = kzalloc(buf_len, GFP_KERNEL);
  104. if (!buf)
  105. return -ENOMEM;
  106. for (i = 0; i < IWM_TX_QUEUES; i++) {
  107. struct iwm_tx_queue *txq = &iwm->txq[i];
  108. struct sk_buff *skb;
  109. int j;
  110. unsigned long flags;
  111. spin_lock_irqsave(&txq->queue.lock, flags);
  112. skb = (struct sk_buff *)&txq->queue;
  113. len += snprintf(buf + len, buf_len - len, "TXQ #%d\n", i);
  114. len += snprintf(buf + len, buf_len - len, "\tStopped: %d\n",
  115. __netif_subqueue_stopped(iwm_to_ndev(iwm),
  116. txq->id));
  117. len += snprintf(buf + len, buf_len - len, "\tConcat count:%d\n",
  118. txq->concat_count);
  119. len += snprintf(buf + len, buf_len - len, "\tQueue len: %d\n",
  120. skb_queue_len(&txq->queue));
  121. for (j = 0; j < skb_queue_len(&txq->queue); j++) {
  122. struct iwm_tx_info *tx_info;
  123. skb = skb->next;
  124. tx_info = skb_to_tx_info(skb);
  125. len += snprintf(buf + len, buf_len - len,
  126. "\tSKB #%d\n", j);
  127. len += snprintf(buf + len, buf_len - len,
  128. "\t\tsta: %d\n", tx_info->sta);
  129. len += snprintf(buf + len, buf_len - len,
  130. "\t\tcolor: %d\n", tx_info->color);
  131. len += snprintf(buf + len, buf_len - len,
  132. "\t\ttid: %d\n", tx_info->tid);
  133. }
  134. spin_unlock_irqrestore(&txq->queue.lock, flags);
  135. spin_lock_irqsave(&txq->stopped_queue.lock, flags);
  136. len += snprintf(buf + len, buf_len - len,
  137. "\tStopped Queue len: %d\n",
  138. skb_queue_len(&txq->stopped_queue));
  139. for (j = 0; j < skb_queue_len(&txq->stopped_queue); j++) {
  140. struct iwm_tx_info *tx_info;
  141. skb = skb->next;
  142. tx_info = skb_to_tx_info(skb);
  143. len += snprintf(buf + len, buf_len - len,
  144. "\tSKB #%d\n", j);
  145. len += snprintf(buf + len, buf_len - len,
  146. "\t\tsta: %d\n", tx_info->sta);
  147. len += snprintf(buf + len, buf_len - len,
  148. "\t\tcolor: %d\n", tx_info->color);
  149. len += snprintf(buf + len, buf_len - len,
  150. "\t\ttid: %d\n", tx_info->tid);
  151. }
  152. spin_unlock_irqrestore(&txq->stopped_queue.lock, flags);
  153. }
  154. ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
  155. kfree(buf);
  156. return ret;
  157. }
  158. static ssize_t iwm_debugfs_tx_credit_read(struct file *filp,
  159. char __user *buffer,
  160. size_t count, loff_t *ppos)
  161. {
  162. struct iwm_priv *iwm = filp->private_data;
  163. struct iwm_tx_credit *credit = &iwm->tx_credit;
  164. char *buf;
  165. int i, buf_len = 4096;
  166. size_t len = 0;
  167. ssize_t ret;
  168. if (*ppos != 0)
  169. return 0;
  170. if (count < sizeof(buf))
  171. return -ENOSPC;
  172. buf = kzalloc(buf_len, GFP_KERNEL);
  173. if (!buf)
  174. return -ENOMEM;
  175. len += snprintf(buf + len, buf_len - len,
  176. "NR pools: %d\n", credit->pool_nr);
  177. len += snprintf(buf + len, buf_len - len,
  178. "pools map: 0x%lx\n", credit->full_pools_map);
  179. len += snprintf(buf + len, buf_len - len, "\n### POOLS ###\n");
  180. for (i = 0; i < IWM_MACS_OUT_GROUPS; i++) {
  181. len += snprintf(buf + len, buf_len - len,
  182. "pools entry #%d\n", i);
  183. len += snprintf(buf + len, buf_len - len,
  184. "\tid: %d\n",
  185. credit->pools[i].id);
  186. len += snprintf(buf + len, buf_len - len,
  187. "\tsid: %d\n",
  188. credit->pools[i].sid);
  189. len += snprintf(buf + len, buf_len - len,
  190. "\tmin_pages: %d\n",
  191. credit->pools[i].min_pages);
  192. len += snprintf(buf + len, buf_len - len,
  193. "\tmax_pages: %d\n",
  194. credit->pools[i].max_pages);
  195. len += snprintf(buf + len, buf_len - len,
  196. "\talloc_pages: %d\n",
  197. credit->pools[i].alloc_pages);
  198. len += snprintf(buf + len, buf_len - len,
  199. "\tfreed_pages: %d\n",
  200. credit->pools[i].total_freed_pages);
  201. }
  202. len += snprintf(buf + len, buf_len - len, "\n### SPOOLS ###\n");
  203. for (i = 0; i < IWM_MACS_OUT_SGROUPS; i++) {
  204. len += snprintf(buf + len, buf_len - len,
  205. "spools entry #%d\n", i);
  206. len += snprintf(buf + len, buf_len - len,
  207. "\tid: %d\n",
  208. credit->spools[i].id);
  209. len += snprintf(buf + len, buf_len - len,
  210. "\tmax_pages: %d\n",
  211. credit->spools[i].max_pages);
  212. len += snprintf(buf + len, buf_len - len,
  213. "\talloc_pages: %d\n",
  214. credit->spools[i].alloc_pages);
  215. }
  216. ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
  217. kfree(buf);
  218. return ret;
  219. }
  220. static ssize_t iwm_debugfs_rx_ticket_read(struct file *filp,
  221. char __user *buffer,
  222. size_t count, loff_t *ppos)
  223. {
  224. struct iwm_priv *iwm = filp->private_data;
  225. struct iwm_rx_ticket_node *ticket;
  226. char *buf;
  227. int buf_len = 4096, i;
  228. size_t len = 0;
  229. ssize_t ret;
  230. if (*ppos != 0)
  231. return 0;
  232. if (count < sizeof(buf))
  233. return -ENOSPC;
  234. buf = kzalloc(buf_len, GFP_KERNEL);
  235. if (!buf)
  236. return -ENOMEM;
  237. spin_lock(&iwm->ticket_lock);
  238. list_for_each_entry(ticket, &iwm->rx_tickets, node) {
  239. len += snprintf(buf + len, buf_len - len, "Ticket #%d\n",
  240. ticket->ticket->id);
  241. len += snprintf(buf + len, buf_len - len, "\taction: 0x%x\n",
  242. ticket->ticket->action);
  243. len += snprintf(buf + len, buf_len - len, "\tflags: 0x%x\n",
  244. ticket->ticket->flags);
  245. }
  246. spin_unlock(&iwm->ticket_lock);
  247. for (i = 0; i < IWM_RX_ID_HASH; i++) {
  248. struct iwm_rx_packet *packet;
  249. struct list_head *pkt_list = &iwm->rx_packets[i];
  250. if (!list_empty(pkt_list)) {
  251. len += snprintf(buf + len, buf_len - len,
  252. "Packet hash #%d\n", i);
  253. spin_lock(&iwm->packet_lock[i]);
  254. list_for_each_entry(packet, pkt_list, node) {
  255. len += snprintf(buf + len, buf_len - len,
  256. "\tPacket id: %d\n",
  257. packet->id);
  258. len += snprintf(buf + len, buf_len - len,
  259. "\tPacket length: %lu\n",
  260. packet->pkt_size);
  261. }
  262. spin_unlock(&iwm->packet_lock[i]);
  263. }
  264. }
  265. ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
  266. kfree(buf);
  267. return ret;
  268. }
  269. static ssize_t iwm_debugfs_fw_err_read(struct file *filp,
  270. char __user *buffer,
  271. size_t count, loff_t *ppos)
  272. {
  273. struct iwm_priv *iwm = filp->private_data;
  274. char buf[512];
  275. int buf_len = 512;
  276. size_t len = 0;
  277. if (*ppos != 0)
  278. return 0;
  279. if (count < sizeof(buf))
  280. return -ENOSPC;
  281. if (!iwm->last_fw_err)
  282. return -ENOMEM;
  283. if (iwm->last_fw_err->line_num == 0)
  284. goto out;
  285. len += snprintf(buf + len, buf_len - len, "%cMAC FW ERROR:\n",
  286. (le32_to_cpu(iwm->last_fw_err->category) == UMAC_SYS_ERR_CAT_LMAC)
  287. ? 'L' : 'U');
  288. len += snprintf(buf + len, buf_len - len,
  289. "\tCategory: %d\n",
  290. le32_to_cpu(iwm->last_fw_err->category));
  291. len += snprintf(buf + len, buf_len - len,
  292. "\tStatus: 0x%x\n",
  293. le32_to_cpu(iwm->last_fw_err->status));
  294. len += snprintf(buf + len, buf_len - len,
  295. "\tPC: 0x%x\n",
  296. le32_to_cpu(iwm->last_fw_err->pc));
  297. len += snprintf(buf + len, buf_len - len,
  298. "\tblink1: %d\n",
  299. le32_to_cpu(iwm->last_fw_err->blink1));
  300. len += snprintf(buf + len, buf_len - len,
  301. "\tblink2: %d\n",
  302. le32_to_cpu(iwm->last_fw_err->blink2));
  303. len += snprintf(buf + len, buf_len - len,
  304. "\tilink1: %d\n",
  305. le32_to_cpu(iwm->last_fw_err->ilink1));
  306. len += snprintf(buf + len, buf_len - len,
  307. "\tilink2: %d\n",
  308. le32_to_cpu(iwm->last_fw_err->ilink2));
  309. len += snprintf(buf + len, buf_len - len,
  310. "\tData1: 0x%x\n",
  311. le32_to_cpu(iwm->last_fw_err->data1));
  312. len += snprintf(buf + len, buf_len - len,
  313. "\tData2: 0x%x\n",
  314. le32_to_cpu(iwm->last_fw_err->data2));
  315. len += snprintf(buf + len, buf_len - len,
  316. "\tLine number: %d\n",
  317. le32_to_cpu(iwm->last_fw_err->line_num));
  318. len += snprintf(buf + len, buf_len - len,
  319. "\tUMAC status: 0x%x\n",
  320. le32_to_cpu(iwm->last_fw_err->umac_status));
  321. len += snprintf(buf + len, buf_len - len,
  322. "\tLMAC status: 0x%x\n",
  323. le32_to_cpu(iwm->last_fw_err->lmac_status));
  324. len += snprintf(buf + len, buf_len - len,
  325. "\tSDIO status: 0x%x\n",
  326. le32_to_cpu(iwm->last_fw_err->sdio_status));
  327. out:
  328. return simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
  329. }
  330. static const struct file_operations iwm_debugfs_txq_fops = {
  331. .owner = THIS_MODULE,
  332. .open = iwm_generic_open,
  333. .read = iwm_debugfs_txq_read,
  334. .llseek = default_llseek,
  335. };
  336. static const struct file_operations iwm_debugfs_tx_credit_fops = {
  337. .owner = THIS_MODULE,
  338. .open = iwm_generic_open,
  339. .read = iwm_debugfs_tx_credit_read,
  340. .llseek = default_llseek,
  341. };
  342. static const struct file_operations iwm_debugfs_rx_ticket_fops = {
  343. .owner = THIS_MODULE,
  344. .open = iwm_generic_open,
  345. .read = iwm_debugfs_rx_ticket_read,
  346. .llseek = default_llseek,
  347. };
  348. static const struct file_operations iwm_debugfs_fw_err_fops = {
  349. .owner = THIS_MODULE,
  350. .open = iwm_generic_open,
  351. .read = iwm_debugfs_fw_err_read,
  352. .llseek = default_llseek,
  353. };
  354. void iwm_debugfs_init(struct iwm_priv *iwm)
  355. {
  356. int i;
  357. iwm->dbg.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
  358. iwm->dbg.devdir = debugfs_create_dir(wiphy_name(iwm_to_wiphy(iwm)),
  359. iwm->dbg.rootdir);
  360. iwm->dbg.dbgdir = debugfs_create_dir("debug", iwm->dbg.devdir);
  361. iwm->dbg.rxdir = debugfs_create_dir("rx", iwm->dbg.devdir);
  362. iwm->dbg.txdir = debugfs_create_dir("tx", iwm->dbg.devdir);
  363. iwm->dbg.busdir = debugfs_create_dir("bus", iwm->dbg.devdir);
  364. if (iwm->bus_ops->debugfs_init)
  365. iwm->bus_ops->debugfs_init(iwm, iwm->dbg.busdir);
  366. iwm->dbg.dbg_level = IWM_DL_NONE;
  367. iwm->dbg.dbg_level_dentry =
  368. debugfs_create_file("level", 0200, iwm->dbg.dbgdir, iwm,
  369. &fops_iwm_dbg_level);
  370. iwm->dbg.dbg_modules = IWM_DM_DEFAULT;
  371. iwm->dbg.dbg_modules_dentry =
  372. debugfs_create_file("modules", 0200, iwm->dbg.dbgdir, iwm,
  373. &fops_iwm_dbg_modules);
  374. for (i = 0; i < __IWM_DM_NR; i++)
  375. add_dbg_module(iwm->dbg, iwm_debug_module[i].name,
  376. iwm_debug_module[i].id, IWM_DL_DEFAULT);
  377. iwm->dbg.txq_dentry = debugfs_create_file("queues", 0200,
  378. iwm->dbg.txdir, iwm,
  379. &iwm_debugfs_txq_fops);
  380. iwm->dbg.tx_credit_dentry = debugfs_create_file("credits", 0200,
  381. iwm->dbg.txdir, iwm,
  382. &iwm_debugfs_tx_credit_fops);
  383. iwm->dbg.rx_ticket_dentry = debugfs_create_file("tickets", 0200,
  384. iwm->dbg.rxdir, iwm,
  385. &iwm_debugfs_rx_ticket_fops);
  386. iwm->dbg.fw_err_dentry = debugfs_create_file("last_fw_err", 0200,
  387. iwm->dbg.dbgdir, iwm,
  388. &iwm_debugfs_fw_err_fops);
  389. }
  390. void iwm_debugfs_exit(struct iwm_priv *iwm)
  391. {
  392. int i;
  393. for (i = 0; i < __IWM_DM_NR; i++)
  394. debugfs_remove(iwm->dbg.dbg_module_dentries[i]);
  395. debugfs_remove(iwm->dbg.dbg_modules_dentry);
  396. debugfs_remove(iwm->dbg.dbg_level_dentry);
  397. debugfs_remove(iwm->dbg.txq_dentry);
  398. debugfs_remove(iwm->dbg.tx_credit_dentry);
  399. debugfs_remove(iwm->dbg.rx_ticket_dentry);
  400. debugfs_remove(iwm->dbg.fw_err_dentry);
  401. if (iwm->bus_ops->debugfs_exit)
  402. iwm->bus_ops->debugfs_exit(iwm);
  403. debugfs_remove(iwm->dbg.busdir);
  404. debugfs_remove(iwm->dbg.dbgdir);
  405. debugfs_remove(iwm->dbg.txdir);
  406. debugfs_remove(iwm->dbg.rxdir);
  407. debugfs_remove(iwm->dbg.devdir);
  408. debugfs_remove(iwm->dbg.rootdir);
  409. }