debugfs.c 13 KB

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