debug.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Wireless Host Controller (WHC) debug.
  3. *
  4. * Copyright (C) 2008 Cambridge Silicon Radio Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/slab.h>
  19. #include <linux/kernel.h>
  20. #include <linux/debugfs.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/export.h>
  23. #include "../../wusbcore/wusbhc.h"
  24. #include "whcd.h"
  25. struct whc_dbg {
  26. struct dentry *di_f;
  27. struct dentry *asl_f;
  28. struct dentry *pzl_f;
  29. };
  30. static void qset_print(struct seq_file *s, struct whc_qset *qset)
  31. {
  32. static const char *qh_type[] = {
  33. "ctrl", "isoc", "bulk", "intr", "rsvd", "rsvd", "rsvd", "lpintr", };
  34. struct whc_std *std;
  35. struct urb *urb = NULL;
  36. int i;
  37. seq_printf(s, "qset %08x", (u32)qset->qset_dma);
  38. if (&qset->list_node == qset->whc->async_list.prev) {
  39. seq_printf(s, " (dummy)\n");
  40. } else {
  41. seq_printf(s, " ep%d%s-%s maxpkt: %d\n",
  42. qset->qh.info1 & 0x0f,
  43. (qset->qh.info1 >> 4) & 0x1 ? "in" : "out",
  44. qh_type[(qset->qh.info1 >> 5) & 0x7],
  45. (qset->qh.info1 >> 16) & 0xffff);
  46. }
  47. seq_printf(s, " -> %08x\n", (u32)qset->qh.link);
  48. seq_printf(s, " info: %08x %08x %08x\n",
  49. qset->qh.info1, qset->qh.info2, qset->qh.info3);
  50. seq_printf(s, " sts: %04x errs: %d curwin: %08x\n",
  51. qset->qh.status, qset->qh.err_count, qset->qh.cur_window);
  52. seq_printf(s, " TD: sts: %08x opts: %08x\n",
  53. qset->qh.overlay.qtd.status, qset->qh.overlay.qtd.options);
  54. for (i = 0; i < WHCI_QSET_TD_MAX; i++) {
  55. seq_printf(s, " %c%c TD[%d]: sts: %08x opts: %08x ptr: %08x\n",
  56. i == qset->td_start ? 'S' : ' ',
  57. i == qset->td_end ? 'E' : ' ',
  58. i, qset->qtd[i].status, qset->qtd[i].options,
  59. (u32)qset->qtd[i].page_list_ptr);
  60. }
  61. seq_printf(s, " ntds: %d\n", qset->ntds);
  62. list_for_each_entry(std, &qset->stds, list_node) {
  63. if (urb != std->urb) {
  64. urb = std->urb;
  65. seq_printf(s, " urb %p transferred: %d bytes\n", urb,
  66. urb->actual_length);
  67. }
  68. if (std->qtd)
  69. seq_printf(s, " sTD[%td]: %zu bytes @ %08x\n",
  70. std->qtd - &qset->qtd[0],
  71. std->len, std->num_pointers ?
  72. (u32)(std->pl_virt[0].buf_ptr) : (u32)std->dma_addr);
  73. else
  74. seq_printf(s, " sTD[-]: %zd bytes @ %08x\n",
  75. std->len, std->num_pointers ?
  76. (u32)(std->pl_virt[0].buf_ptr) : (u32)std->dma_addr);
  77. }
  78. }
  79. static int di_print(struct seq_file *s, void *p)
  80. {
  81. struct whc *whc = s->private;
  82. int d;
  83. for (d = 0; d < whc->n_devices; d++) {
  84. struct di_buf_entry *di = &whc->di_buf[d];
  85. seq_printf(s, "DI[%d]\n", d);
  86. seq_printf(s, " availability: %*pb\n",
  87. UWB_NUM_MAS, (unsigned long *)di->availability_info);
  88. seq_printf(s, " %c%c key idx: %d dev addr: %d\n",
  89. (di->addr_sec_info & WHC_DI_SECURE) ? 'S' : ' ',
  90. (di->addr_sec_info & WHC_DI_DISABLE) ? 'D' : ' ',
  91. (di->addr_sec_info & WHC_DI_KEY_IDX_MASK) >> 8,
  92. (di->addr_sec_info & WHC_DI_DEV_ADDR_MASK));
  93. }
  94. return 0;
  95. }
  96. static int asl_print(struct seq_file *s, void *p)
  97. {
  98. struct whc *whc = s->private;
  99. struct whc_qset *qset;
  100. list_for_each_entry(qset, &whc->async_list, list_node) {
  101. qset_print(s, qset);
  102. }
  103. return 0;
  104. }
  105. static int pzl_print(struct seq_file *s, void *p)
  106. {
  107. struct whc *whc = s->private;
  108. struct whc_qset *qset;
  109. int period;
  110. for (period = 0; period < 5; period++) {
  111. seq_printf(s, "Period %d\n", period);
  112. list_for_each_entry(qset, &whc->periodic_list[period], list_node) {
  113. qset_print(s, qset);
  114. }
  115. }
  116. return 0;
  117. }
  118. static int di_open(struct inode *inode, struct file *file)
  119. {
  120. return single_open(file, di_print, inode->i_private);
  121. }
  122. static int asl_open(struct inode *inode, struct file *file)
  123. {
  124. return single_open(file, asl_print, inode->i_private);
  125. }
  126. static int pzl_open(struct inode *inode, struct file *file)
  127. {
  128. return single_open(file, pzl_print, inode->i_private);
  129. }
  130. static const struct file_operations di_fops = {
  131. .open = di_open,
  132. .read = seq_read,
  133. .llseek = seq_lseek,
  134. .release = single_release,
  135. .owner = THIS_MODULE,
  136. };
  137. static const struct file_operations asl_fops = {
  138. .open = asl_open,
  139. .read = seq_read,
  140. .llseek = seq_lseek,
  141. .release = single_release,
  142. .owner = THIS_MODULE,
  143. };
  144. static const struct file_operations pzl_fops = {
  145. .open = pzl_open,
  146. .read = seq_read,
  147. .llseek = seq_lseek,
  148. .release = single_release,
  149. .owner = THIS_MODULE,
  150. };
  151. void whc_dbg_init(struct whc *whc)
  152. {
  153. if (whc->wusbhc.pal.debugfs_dir == NULL)
  154. return;
  155. whc->dbg = kzalloc(sizeof(struct whc_dbg), GFP_KERNEL);
  156. if (whc->dbg == NULL)
  157. return;
  158. whc->dbg->di_f = debugfs_create_file("di", 0444,
  159. whc->wusbhc.pal.debugfs_dir, whc,
  160. &di_fops);
  161. whc->dbg->asl_f = debugfs_create_file("asl", 0444,
  162. whc->wusbhc.pal.debugfs_dir, whc,
  163. &asl_fops);
  164. whc->dbg->pzl_f = debugfs_create_file("pzl", 0444,
  165. whc->wusbhc.pal.debugfs_dir, whc,
  166. &pzl_fops);
  167. }
  168. void whc_dbg_clean_up(struct whc *whc)
  169. {
  170. if (whc->dbg) {
  171. debugfs_remove(whc->dbg->pzl_f);
  172. debugfs_remove(whc->dbg->asl_f);
  173. debugfs_remove(whc->dbg->di_f);
  174. kfree(whc->dbg);
  175. }
  176. }