debug.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 "../../wusbcore/wusbhc.h"
  23. #include "whcd.h"
  24. struct whc_dbg {
  25. struct dentry *di_f;
  26. struct dentry *asl_f;
  27. struct dentry *pzl_f;
  28. };
  29. static void qset_print(struct seq_file *s, struct whc_qset *qset)
  30. {
  31. static const char *qh_type[] = {
  32. "ctrl", "isoc", "bulk", "intr", "rsvd", "rsvd", "rsvd", "lpintr", };
  33. struct whc_std *std;
  34. struct urb *urb = NULL;
  35. int i;
  36. seq_printf(s, "qset %08x", (u32)qset->qset_dma);
  37. if (&qset->list_node == qset->whc->async_list.prev) {
  38. seq_printf(s, " (dummy)\n");
  39. } else {
  40. seq_printf(s, " ep%d%s-%s maxpkt: %d\n",
  41. qset->qh.info1 & 0x0f,
  42. (qset->qh.info1 >> 4) & 0x1 ? "in" : "out",
  43. qh_type[(qset->qh.info1 >> 5) & 0x7],
  44. (qset->qh.info1 >> 16) & 0xffff);
  45. }
  46. seq_printf(s, " -> %08x\n", (u32)qset->qh.link);
  47. seq_printf(s, " info: %08x %08x %08x\n",
  48. qset->qh.info1, qset->qh.info2, qset->qh.info3);
  49. seq_printf(s, " sts: %04x errs: %d curwin: %08x\n",
  50. qset->qh.status, qset->qh.err_count, qset->qh.cur_window);
  51. seq_printf(s, " TD: sts: %08x opts: %08x\n",
  52. qset->qh.overlay.qtd.status, qset->qh.overlay.qtd.options);
  53. for (i = 0; i < WHCI_QSET_TD_MAX; i++) {
  54. seq_printf(s, " %c%c TD[%d]: sts: %08x opts: %08x ptr: %08x\n",
  55. i == qset->td_start ? 'S' : ' ',
  56. i == qset->td_end ? 'E' : ' ',
  57. i, qset->qtd[i].status, qset->qtd[i].options,
  58. (u32)qset->qtd[i].page_list_ptr);
  59. }
  60. seq_printf(s, " ntds: %d\n", qset->ntds);
  61. list_for_each_entry(std, &qset->stds, list_node) {
  62. if (urb != std->urb) {
  63. urb = std->urb;
  64. seq_printf(s, " urb %p transferred: %d bytes\n", urb,
  65. urb->actual_length);
  66. }
  67. if (std->qtd)
  68. seq_printf(s, " sTD[%td]: %zu bytes @ %08x\n",
  69. std->qtd - &qset->qtd[0],
  70. std->len, std->num_pointers ?
  71. (u32)(std->pl_virt[0].buf_ptr) : (u32)std->dma_addr);
  72. else
  73. seq_printf(s, " sTD[-]: %zd bytes @ %08x\n",
  74. std->len, std->num_pointers ?
  75. (u32)(std->pl_virt[0].buf_ptr) : (u32)std->dma_addr);
  76. }
  77. }
  78. static int di_print(struct seq_file *s, void *p)
  79. {
  80. struct whc *whc = s->private;
  81. char buf[72];
  82. int d;
  83. for (d = 0; d < whc->n_devices; d++) {
  84. struct di_buf_entry *di = &whc->di_buf[d];
  85. bitmap_scnprintf(buf, sizeof(buf),
  86. (unsigned long *)di->availability_info, UWB_NUM_MAS);
  87. seq_printf(s, "DI[%d]\n", d);
  88. seq_printf(s, " availability: %s\n", buf);
  89. seq_printf(s, " %c%c key idx: %d dev addr: %d\n",
  90. (di->addr_sec_info & WHC_DI_SECURE) ? 'S' : ' ',
  91. (di->addr_sec_info & WHC_DI_DISABLE) ? 'D' : ' ',
  92. (di->addr_sec_info & WHC_DI_KEY_IDX_MASK) >> 8,
  93. (di->addr_sec_info & WHC_DI_DEV_ADDR_MASK));
  94. }
  95. return 0;
  96. }
  97. static int asl_print(struct seq_file *s, void *p)
  98. {
  99. struct whc *whc = s->private;
  100. struct whc_qset *qset;
  101. list_for_each_entry(qset, &whc->async_list, list_node) {
  102. qset_print(s, qset);
  103. }
  104. return 0;
  105. }
  106. static int pzl_print(struct seq_file *s, void *p)
  107. {
  108. struct whc *whc = s->private;
  109. struct whc_qset *qset;
  110. int period;
  111. for (period = 0; period < 5; period++) {
  112. seq_printf(s, "Period %d\n", period);
  113. list_for_each_entry(qset, &whc->periodic_list[period], list_node) {
  114. qset_print(s, qset);
  115. }
  116. }
  117. return 0;
  118. }
  119. static int di_open(struct inode *inode, struct file *file)
  120. {
  121. return single_open(file, di_print, inode->i_private);
  122. }
  123. static int asl_open(struct inode *inode, struct file *file)
  124. {
  125. return single_open(file, asl_print, inode->i_private);
  126. }
  127. static int pzl_open(struct inode *inode, struct file *file)
  128. {
  129. return single_open(file, pzl_print, inode->i_private);
  130. }
  131. static const struct file_operations di_fops = {
  132. .open = di_open,
  133. .read = seq_read,
  134. .llseek = seq_lseek,
  135. .release = single_release,
  136. .owner = THIS_MODULE,
  137. };
  138. static const struct file_operations asl_fops = {
  139. .open = asl_open,
  140. .read = seq_read,
  141. .llseek = seq_lseek,
  142. .release = single_release,
  143. .owner = THIS_MODULE,
  144. };
  145. static const struct file_operations pzl_fops = {
  146. .open = pzl_open,
  147. .read = seq_read,
  148. .llseek = seq_lseek,
  149. .release = single_release,
  150. .owner = THIS_MODULE,
  151. };
  152. void whc_dbg_init(struct whc *whc)
  153. {
  154. if (whc->wusbhc.pal.debugfs_dir == NULL)
  155. return;
  156. whc->dbg = kzalloc(sizeof(struct whc_dbg), GFP_KERNEL);
  157. if (whc->dbg == NULL)
  158. return;
  159. whc->dbg->di_f = debugfs_create_file("di", 0444,
  160. whc->wusbhc.pal.debugfs_dir, whc,
  161. &di_fops);
  162. whc->dbg->asl_f = debugfs_create_file("asl", 0444,
  163. whc->wusbhc.pal.debugfs_dir, whc,
  164. &asl_fops);
  165. whc->dbg->pzl_f = debugfs_create_file("pzl", 0444,
  166. whc->wusbhc.pal.debugfs_dir, whc,
  167. &pzl_fops);
  168. }
  169. void whc_dbg_clean_up(struct whc *whc)
  170. {
  171. if (whc->dbg) {
  172. debugfs_remove(whc->dbg->pzl_f);
  173. debugfs_remove(whc->dbg->asl_f);
  174. debugfs_remove(whc->dbg->di_f);
  175. kfree(whc->dbg);
  176. }
  177. }