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 <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 ssize_t iwm_debugfs_txq_read(struct file *filp, char __user *buffer,
  87. size_t count, loff_t *ppos)
  88. {
  89. struct iwm_priv *iwm = filp->private_data;
  90. char *buf;
  91. int i, buf_len = 4096;
  92. size_t len = 0;
  93. ssize_t ret;
  94. if (*ppos != 0)
  95. return 0;
  96. if (count < sizeof(buf))
  97. return -ENOSPC;
  98. buf = kzalloc(buf_len, GFP_KERNEL);
  99. if (!buf)
  100. return -ENOMEM;
  101. for (i = 0; i < IWM_TX_QUEUES; i++) {
  102. struct iwm_tx_queue *txq = &iwm->txq[i];
  103. struct sk_buff *skb;
  104. int j;
  105. unsigned long flags;
  106. spin_lock_irqsave(&txq->queue.lock, flags);
  107. skb = (struct sk_buff *)&txq->queue;
  108. len += snprintf(buf + len, buf_len - len, "TXQ #%d\n", i);
  109. len += snprintf(buf + len, buf_len - len, "\tStopped: %d\n",
  110. __netif_subqueue_stopped(iwm_to_ndev(iwm),
  111. txq->id));
  112. len += snprintf(buf + len, buf_len - len, "\tConcat count:%d\n",
  113. txq->concat_count);
  114. len += snprintf(buf + len, buf_len - len, "\tQueue len: %d\n",
  115. skb_queue_len(&txq->queue));
  116. for (j = 0; j < skb_queue_len(&txq->queue); j++) {
  117. struct iwm_tx_info *tx_info;
  118. skb = skb->next;
  119. tx_info = skb_to_tx_info(skb);
  120. len += snprintf(buf + len, buf_len - len,
  121. "\tSKB #%d\n", j);
  122. len += snprintf(buf + len, buf_len - len,
  123. "\t\tsta: %d\n", tx_info->sta);
  124. len += snprintf(buf + len, buf_len - len,
  125. "\t\tcolor: %d\n", tx_info->color);
  126. len += snprintf(buf + len, buf_len - len,
  127. "\t\ttid: %d\n", tx_info->tid);
  128. }
  129. spin_unlock_irqrestore(&txq->queue.lock, flags);
  130. spin_lock_irqsave(&txq->stopped_queue.lock, flags);
  131. len += snprintf(buf + len, buf_len - len,
  132. "\tStopped Queue len: %d\n",
  133. skb_queue_len(&txq->stopped_queue));
  134. for (j = 0; j < skb_queue_len(&txq->stopped_queue); j++) {
  135. struct iwm_tx_info *tx_info;
  136. skb = skb->next;
  137. tx_info = skb_to_tx_info(skb);
  138. len += snprintf(buf + len, buf_len - len,
  139. "\tSKB #%d\n", j);
  140. len += snprintf(buf + len, buf_len - len,
  141. "\t\tsta: %d\n", tx_info->sta);
  142. len += snprintf(buf + len, buf_len - len,
  143. "\t\tcolor: %d\n", tx_info->color);
  144. len += snprintf(buf + len, buf_len - len,
  145. "\t\ttid: %d\n", tx_info->tid);
  146. }
  147. spin_unlock_irqrestore(&txq->stopped_queue.lock, flags);
  148. }
  149. ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
  150. kfree(buf);
  151. return ret;
  152. }
  153. static ssize_t iwm_debugfs_tx_credit_read(struct file *filp,
  154. char __user *buffer,
  155. size_t count, loff_t *ppos)
  156. {
  157. struct iwm_priv *iwm = filp->private_data;
  158. struct iwm_tx_credit *credit = &iwm->tx_credit;
  159. char *buf;
  160. int i, buf_len = 4096;
  161. size_t len = 0;
  162. ssize_t ret;
  163. if (*ppos != 0)
  164. return 0;
  165. if (count < sizeof(buf))
  166. return -ENOSPC;
  167. buf = kzalloc(buf_len, GFP_KERNEL);
  168. if (!buf)
  169. return -ENOMEM;
  170. len += snprintf(buf + len, buf_len - len,
  171. "NR pools: %d\n", credit->pool_nr);
  172. len += snprintf(buf + len, buf_len - len,
  173. "pools map: 0x%lx\n", credit->full_pools_map);
  174. len += snprintf(buf + len, buf_len - len, "\n### POOLS ###\n");
  175. for (i = 0; i < IWM_MACS_OUT_GROUPS; i++) {
  176. len += snprintf(buf + len, buf_len - len,
  177. "pools entry #%d\n", i);
  178. len += snprintf(buf + len, buf_len - len,
  179. "\tid: %d\n",
  180. credit->pools[i].id);
  181. len += snprintf(buf + len, buf_len - len,
  182. "\tsid: %d\n",
  183. credit->pools[i].sid);
  184. len += snprintf(buf + len, buf_len - len,
  185. "\tmin_pages: %d\n",
  186. credit->pools[i].min_pages);
  187. len += snprintf(buf + len, buf_len - len,
  188. "\tmax_pages: %d\n",
  189. credit->pools[i].max_pages);
  190. len += snprintf(buf + len, buf_len - len,
  191. "\talloc_pages: %d\n",
  192. credit->pools[i].alloc_pages);
  193. len += snprintf(buf + len, buf_len - len,
  194. "\tfreed_pages: %d\n",
  195. credit->pools[i].total_freed_pages);
  196. }
  197. len += snprintf(buf + len, buf_len - len, "\n### SPOOLS ###\n");
  198. for (i = 0; i < IWM_MACS_OUT_SGROUPS; i++) {
  199. len += snprintf(buf + len, buf_len - len,
  200. "spools entry #%d\n", i);
  201. len += snprintf(buf + len, buf_len - len,
  202. "\tid: %d\n",
  203. credit->spools[i].id);
  204. len += snprintf(buf + len, buf_len - len,
  205. "\tmax_pages: %d\n",
  206. credit->spools[i].max_pages);
  207. len += snprintf(buf + len, buf_len - len,
  208. "\talloc_pages: %d\n",
  209. credit->spools[i].alloc_pages);
  210. }
  211. ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
  212. kfree(buf);
  213. return ret;
  214. }
  215. static ssize_t iwm_debugfs_rx_ticket_read(struct file *filp,
  216. char __user *buffer,
  217. size_t count, loff_t *ppos)
  218. {
  219. struct iwm_priv *iwm = filp->private_data;
  220. struct iwm_rx_ticket_node *ticket;
  221. char *buf;
  222. int buf_len = 4096, i;
  223. size_t len = 0;
  224. ssize_t ret;
  225. if (*ppos != 0)
  226. return 0;
  227. if (count < sizeof(buf))
  228. return -ENOSPC;
  229. buf = kzalloc(buf_len, GFP_KERNEL);
  230. if (!buf)
  231. return -ENOMEM;
  232. spin_lock(&iwm->ticket_lock);
  233. list_for_each_entry(ticket, &iwm->rx_tickets, node) {
  234. len += snprintf(buf + len, buf_len - len, "Ticket #%d\n",
  235. ticket->ticket->id);
  236. len += snprintf(buf + len, buf_len - len, "\taction: 0x%x\n",
  237. ticket->ticket->action);
  238. len += snprintf(buf + len, buf_len - len, "\tflags: 0x%x\n",
  239. ticket->ticket->flags);
  240. }
  241. spin_unlock(&iwm->ticket_lock);
  242. for (i = 0; i < IWM_RX_ID_HASH; i++) {
  243. struct iwm_rx_packet *packet;
  244. struct list_head *pkt_list = &iwm->rx_packets[i];
  245. if (!list_empty(pkt_list)) {
  246. len += snprintf(buf + len, buf_len - len,
  247. "Packet hash #%d\n", i);
  248. spin_lock(&iwm->packet_lock[i]);
  249. list_for_each_entry(packet, pkt_list, node) {
  250. len += snprintf(buf + len, buf_len - len,
  251. "\tPacket id: %d\n",
  252. packet->id);
  253. len += snprintf(buf + len, buf_len - len,
  254. "\tPacket length: %lu\n",
  255. packet->pkt_size);
  256. }
  257. spin_unlock(&iwm->packet_lock[i]);
  258. }
  259. }
  260. ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
  261. kfree(buf);
  262. return ret;
  263. }
  264. static ssize_t iwm_debugfs_fw_err_read(struct file *filp,
  265. char __user *buffer,
  266. size_t count, loff_t *ppos)
  267. {
  268. struct iwm_priv *iwm = filp->private_data;
  269. char buf[512];
  270. int buf_len = 512;
  271. size_t len = 0;
  272. if (*ppos != 0)
  273. return 0;
  274. if (count < sizeof(buf))
  275. return -ENOSPC;
  276. if (!iwm->last_fw_err)
  277. return -ENOMEM;
  278. if (iwm->last_fw_err->line_num == 0)
  279. goto out;
  280. len += snprintf(buf + len, buf_len - len, "%cMAC FW ERROR:\n",
  281. (le32_to_cpu(iwm->last_fw_err->category) == UMAC_SYS_ERR_CAT_LMAC)
  282. ? 'L' : 'U');
  283. len += snprintf(buf + len, buf_len - len,
  284. "\tCategory: %d\n",
  285. le32_to_cpu(iwm->last_fw_err->category));
  286. len += snprintf(buf + len, buf_len - len,
  287. "\tStatus: 0x%x\n",
  288. le32_to_cpu(iwm->last_fw_err->status));
  289. len += snprintf(buf + len, buf_len - len,
  290. "\tPC: 0x%x\n",
  291. le32_to_cpu(iwm->last_fw_err->pc));
  292. len += snprintf(buf + len, buf_len - len,
  293. "\tblink1: %d\n",
  294. le32_to_cpu(iwm->last_fw_err->blink1));
  295. len += snprintf(buf + len, buf_len - len,
  296. "\tblink2: %d\n",
  297. le32_to_cpu(iwm->last_fw_err->blink2));
  298. len += snprintf(buf + len, buf_len - len,
  299. "\tilink1: %d\n",
  300. le32_to_cpu(iwm->last_fw_err->ilink1));
  301. len += snprintf(buf + len, buf_len - len,
  302. "\tilink2: %d\n",
  303. le32_to_cpu(iwm->last_fw_err->ilink2));
  304. len += snprintf(buf + len, buf_len - len,
  305. "\tData1: 0x%x\n",
  306. le32_to_cpu(iwm->last_fw_err->data1));
  307. len += snprintf(buf + len, buf_len - len,
  308. "\tData2: 0x%x\n",
  309. le32_to_cpu(iwm->last_fw_err->data2));
  310. len += snprintf(buf + len, buf_len - len,
  311. "\tLine number: %d\n",
  312. le32_to_cpu(iwm->last_fw_err->line_num));
  313. len += snprintf(buf + len, buf_len - len,
  314. "\tUMAC status: 0x%x\n",
  315. le32_to_cpu(iwm->last_fw_err->umac_status));
  316. len += snprintf(buf + len, buf_len - len,
  317. "\tLMAC status: 0x%x\n",
  318. le32_to_cpu(iwm->last_fw_err->lmac_status));
  319. len += snprintf(buf + len, buf_len - len,
  320. "\tSDIO status: 0x%x\n",
  321. le32_to_cpu(iwm->last_fw_err->sdio_status));
  322. out:
  323. return simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
  324. }
  325. static const struct file_operations iwm_debugfs_txq_fops = {
  326. .owner = THIS_MODULE,
  327. .open = simple_open,
  328. .read = iwm_debugfs_txq_read,
  329. .llseek = default_llseek,
  330. };
  331. static const struct file_operations iwm_debugfs_tx_credit_fops = {
  332. .owner = THIS_MODULE,
  333. .open = simple_open,
  334. .read = iwm_debugfs_tx_credit_read,
  335. .llseek = default_llseek,
  336. };
  337. static const struct file_operations iwm_debugfs_rx_ticket_fops = {
  338. .owner = THIS_MODULE,
  339. .open = simple_open,
  340. .read = iwm_debugfs_rx_ticket_read,
  341. .llseek = default_llseek,
  342. };
  343. static const struct file_operations iwm_debugfs_fw_err_fops = {
  344. .owner = THIS_MODULE,
  345. .open = simple_open,
  346. .read = iwm_debugfs_fw_err_read,
  347. .llseek = default_llseek,
  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. }