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