2 * ADM5120 HCD (Host Controller Driver) for USB
4 * Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
6 * This file was derived from: drivers/usb/host/ohci-dbg.c
7 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
8 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
16 /*-------------------------------------------------------------------------*/
18 static inline char *ed_typestring(int ed_type)
27 case PIPE_ISOCHRONOUS:
30 return "(bad ed_type)";
33 static inline char *ed_statestring(int state)
46 static inline char *pipestring(int pipe)
48 return ed_typestring(usb_pipetype(pipe));
51 static inline char *td_pidstring(u32 info)
53 switch (info & TD_DP) {
64 static inline char *td_togglestring(u32 info)
66 switch (info & TD_T) {
77 /*-------------------------------------------------------------------------*/
81 /* debug| print the main components of an URB
82 * small: 0) header + data packets 1) just header
84 static void __attribute__((unused))
85 urb_print(struct admhcd *ahcd, struct urb *urb, char *str, int small, int status)
87 unsigned int pipe = urb->pipe;
89 if (!urb->dev || !urb->dev->bus) {
90 admhc_dbg(ahcd, "%s URB: no dev", str);
94 #ifndef ADMHC_VERBOSE_DEBUG
97 admhc_dbg(ahcd, "URB-%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d "
101 usb_pipedevice(pipe),
102 usb_pipeendpoint(pipe),
103 usb_pipeout(pipe) ? "out" : "in",
107 urb->transfer_buffer_length,
110 #ifdef ADMHC_VERBOSE_DEBUG
114 if (usb_pipecontrol(pipe)) {
115 admhc_dbg(ahcd, "setup(8):");
116 for (i = 0; i < 8 ; i++)
117 printk(KERN_INFO" %02x", ((__u8 *)urb->setup_packet)[i]);
118 printk(KERN_INFO "\n");
120 if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) {
121 admhc_dbg(ahcd, "data(%d/%d):",
123 urb->transfer_buffer_length);
124 len = usb_pipeout(pipe) ?
125 urb->transfer_buffer_length : urb->actual_length;
126 for (i = 0; i < 16 && i < len; i++)
127 printk(KERN_INFO " %02x", ((__u8 *)urb->transfer_buffer)[i]);
128 printk(KERN_INFO "%s stat:%d\n", i < len ? "..." : "", status);
131 #endif /* ADMHC_VERBOSE_DEBUG */
134 #define admhc_dbg_sw(ahcd, next, size, format, arg...) \
138 s_len = scnprintf(*next, *size, format, ## arg); \
139 *size -= s_len; *next += s_len; \
141 admhc_dbg(ahcd, format, ## arg); \
145 static void admhc_dump_intr_mask(struct admhcd *ahcd, char *label, u32 mask,
146 char **next, unsigned *size)
148 admhc_dbg_sw(ahcd, next, size, "%s 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n",
151 (mask & ADMHC_INTR_INTA) ? " INTA" : "",
152 (mask & ADMHC_INTR_FATI) ? " FATI" : "",
153 (mask & ADMHC_INTR_SWI) ? " SWI" : "",
154 (mask & ADMHC_INTR_TDC) ? " TDC" : "",
155 (mask & ADMHC_INTR_FNO) ? " FNO" : "",
156 (mask & ADMHC_INTR_SO) ? " SO" : "",
157 (mask & ADMHC_INTR_INSM) ? " INSM" : "",
158 (mask & ADMHC_INTR_BABI) ? " BABI" : "",
159 (mask & ADMHC_INTR_7) ? " !7!" : "",
160 (mask & ADMHC_INTR_6) ? " !6!" : "",
161 (mask & ADMHC_INTR_RESI) ? " RESI" : "",
162 (mask & ADMHC_INTR_SOFI) ? " SOFI" : ""
166 static void maybe_print_eds(struct admhcd *ahcd, char *label, u32 value,
167 char **next, unsigned *size)
170 admhc_dbg_sw(ahcd, next, size, "%s %08x\n", label, value);
173 static char *buss2string(int state)
176 case ADMHC_BUSS_RESET:
178 case ADMHC_BUSS_RESUME:
180 case ADMHC_BUSS_OPER:
181 return "operational";
182 case ADMHC_BUSS_SUSPEND:
189 admhc_dump_status(struct admhcd *ahcd, char **next, unsigned *size)
191 struct admhcd_regs __iomem *regs = ahcd->regs;
194 temp = admhc_readl(ahcd, ®s->gencontrol);
195 admhc_dbg_sw(ahcd, next, size,
196 "gencontrol 0x%08x%s%s%s%s\n",
198 (temp & ADMHC_CTRL_UHFE) ? " UHFE" : "",
199 (temp & ADMHC_CTRL_SIR) ? " SIR" : "",
200 (temp & ADMHC_CTRL_DMAA) ? " DMAA" : "",
201 (temp & ADMHC_CTRL_SR) ? " SR" : ""
204 temp = admhc_readl(ahcd, ®s->host_control);
205 admhc_dbg_sw(ahcd, next, size,
206 "host_control 0x%08x BUSS=%s%s\n",
208 buss2string(temp & ADMHC_HC_BUSS),
209 (temp & ADMHC_HC_DMAE) ? " DMAE" : ""
212 admhc_dump_intr_mask(ahcd, "int_status",
213 admhc_readl(ahcd, ®s->int_status),
215 admhc_dump_intr_mask(ahcd, "int_enable",
216 admhc_readl(ahcd, ®s->int_enable),
219 maybe_print_eds(ahcd, "hosthead",
220 admhc_readl(ahcd, ®s->hosthead), next, size);
223 #define dbg_port_sw(hc, num, value, next, size) \
224 admhc_dbg_sw(hc, next, size, \
226 "0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
228 (temp & ADMHC_PS_PRSC) ? " PRSC" : "", \
229 (temp & ADMHC_PS_OCIC) ? " OCIC" : "", \
230 (temp & ADMHC_PS_PSSC) ? " PSSC" : "", \
231 (temp & ADMHC_PS_PESC) ? " PESC" : "", \
232 (temp & ADMHC_PS_CSC) ? " CSC" : "", \
234 (temp & ADMHC_PS_LSDA) ? " LSDA" : "", \
235 (temp & ADMHC_PS_PPS) ? " PPS" : "", \
236 (temp & ADMHC_PS_PRS) ? " PRS" : "", \
237 (temp & ADMHC_PS_POCI) ? " POCI" : "", \
238 (temp & ADMHC_PS_PSS) ? " PSS" : "", \
240 (temp & ADMHC_PS_PES) ? " PES" : "", \
241 (temp & ADMHC_PS_CCS) ? " CCS" : "" \
254 temp = admhc_read_rhdesc(ahcd);
259 admhc_dbg_sw(ahcd, next, size,
260 "rhdesc %08x%s%s%s%s%s%s PPCM=%02x%s%s%s%s NUMP=%d(%d)\n",
262 (temp & ADMHC_RH_CRWE) ? " CRWE" : "",
263 (temp & ADMHC_RH_OCIC) ? " OCIC" : "",
264 (temp & ADMHC_RH_LPSC) ? " LPSC" : "",
265 (temp & ADMHC_RH_LPSC) ? " DRWE" : "",
266 (temp & ADMHC_RH_LPSC) ? " OCI" : "",
267 (temp & ADMHC_RH_LPSC) ? " LPS" : "",
268 ((temp & ADMHC_RH_PPCM) >> 16),
269 (temp & ADMHC_RH_NOCP) ? " NOCP" : "",
270 (temp & ADMHC_RH_OCPM) ? " OCPM" : "",
271 (temp & ADMHC_RH_NPS) ? " NPS" : "",
272 (temp & ADMHC_RH_PSM) ? " PSM" : "",
273 (temp & ADMHC_RH_NUMP), ahcd->num_ports
277 for (i = 0; i < ahcd->num_ports; i++) {
278 temp = admhc_read_portstatus(ahcd, i);
279 dbg_port_sw(ahcd, i, temp, next, size);
283 static void admhc_dump(struct admhcd *ahcd, int verbose)
285 admhc_dbg(ahcd, "ADMHC ahcd state\n");
287 /* dumps some of the state we know about */
288 admhc_dump_status(ahcd, NULL, NULL);
289 admhc_dbg(ahcd, "current frame #%04x\n",
290 admhc_frame_no(ahcd));
292 admhc_dump_roothub(ahcd, verbose, NULL, NULL);
295 static const char data0[] = "DATA0";
296 static const char data1[] = "DATA1";
298 static void admhc_dump_td(const struct admhcd *ahcd, const char *label,
303 admhc_dbg(ahcd, "%s td %p; urb %p index %d; hwNextTD %08x\n",
306 hc32_to_cpup(ahcd, &td->hwNextTD));
308 tmp = hc32_to_cpup(ahcd, &td->hwINFO);
309 admhc_dbg(ahcd, " status %08x%s CC=%x EC=%d %s %s ISI=%x FN=%x\n",
311 (tmp & TD_OWN) ? " OWN" : "",
314 td_togglestring(tmp),
319 tmp = hc32_to_cpup(ahcd, &td->hwCBL);
320 admhc_dbg(ahcd, " dbp %08x; cbl %08x; LEN=%d%s\n",
321 hc32_to_cpup(ahcd, &td->hwDBP),
324 (tmp & TD_IE) ? " IE" : "");
327 /* caller MUST own hcd spinlock if verbose is set! */
328 static void __attribute__((unused))
329 admhc_dump_ed(const struct admhcd *ahcd, const char *label,
330 const struct ed *ed, int verbose)
332 u32 tmp = hc32_to_cpu(ahcd, ed->hwINFO);
334 admhc_dbg(ahcd, "%s ed %p %s type %s; next ed %08x\n",
336 ed, ed_statestring(ed->state), ed_typestring(ed->type),
337 hc32_to_cpup(ahcd, &ed->hwNextED));
339 admhc_dbg(ahcd, " info %08x MAX=%d%s%s%s%s EP=%d DEV=%d\n", tmp,
341 (tmp & ED_ISO) ? " ISO" : "",
342 (tmp & ED_SKIP) ? " SKIP" : "",
343 (tmp & ED_SPEED_FULL) ? " FULL" : " LOW",
344 (tmp & ED_INT) ? " INT" : "",
348 tmp = hc32_to_cpup(ahcd, &ed->hwHeadP);
349 admhc_dbg(ahcd, " tds: head %08x tail %08x %s%s%s\n",
351 hc32_to_cpup(ahcd, &ed->hwTailP),
352 (tmp & ED_C) ? data1 : data0,
353 (tmp & ED_H) ? " HALT" : "",
354 verbose ? " td list follows" : " (not listing)");
357 struct list_head *tmp;
359 /* use ed->td_list because HC concurrently modifies
360 * hwNextTD as it accumulates ed_donelist.
362 list_for_each(tmp, &ed->td_list) {
364 td = list_entry(tmp, struct td, td_list);
365 admhc_dump_td(ahcd, " ->", td);
370 #else /* ifdef DEBUG */
372 static inline void urb_print(struct admhcd *ahcd, struct urb * urb, char * str,
373 int small, int status) {}
374 static inline void admhc_dump_ed(const struct admhcd *ahcd, const char *label,
375 const struct ed *ed, int verbose) {}
376 static inline void admhc_dump_td(const struct admhcd *ahcd, const char *label,
377 const struct td *td) {}
378 static inline void admhc_dump(struct admhcd *ahcd, int verbose) {}
380 #undef ADMHC_VERBOSE_DEBUG
384 /*-------------------------------------------------------------------------*/
386 #ifdef STUB_DEBUG_FILES
388 static inline void create_debug_files(struct admhcd *bus) { }
389 static inline void remove_debug_files(struct admhcd *bus) { }
393 static int debug_async_open(struct inode *, struct file *);
394 static int debug_periodic_open(struct inode *, struct file *);
395 static int debug_registers_open(struct inode *, struct file *);
396 static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
397 static int debug_close(struct inode *, struct file *);
399 static const struct file_operations debug_async_fops = {
400 .owner = THIS_MODULE,
401 .open = debug_async_open,
402 .read = debug_output,
403 .release = debug_close,
404 .llseek = default_llseek,
406 static const struct file_operations debug_periodic_fops = {
407 .owner = THIS_MODULE,
408 .open = debug_periodic_open,
409 .read = debug_output,
410 .release = debug_close,
411 .llseek = default_llseek,
413 static const struct file_operations debug_registers_fops = {
414 .owner = THIS_MODULE,
415 .open = debug_registers_open,
416 .read = debug_output,
417 .release = debug_close,
418 .llseek = default_llseek,
421 static struct dentry *admhc_debug_root;
423 struct debug_buffer {
424 ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
426 struct mutex mutex; /* protect filling of buffer */
427 size_t count; /* number of characters filled into buffer */
432 show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed)
435 unsigned size = count;
440 /* dump a snapshot of the bulk or control schedule */
442 u32 info = hc32_to_cpu(ahcd, ed->hwINFO);
443 u32 headp = hc32_to_cpu(ahcd, ed->hwHeadP);
444 u32 tailp = hc32_to_cpu(ahcd, ed->hwTailP);
445 struct list_head *entry;
448 temp = scnprintf(buf, size,
449 "ed/%p %s %s %cs dev%d ep%d %s%smax %d %08x%s%s %s"
452 ed_statestring(ed->state),
453 ed_typestring(ed->type),
454 (info & ED_SPEED_FULL) ? 'f' : 'l',
456 (info >> ED_EN_SHIFT) & ED_EN_MASK,
457 (info & ED_INT) ? "INT " : "",
458 (info & ED_ISO) ? "ISO " : "",
459 (info >> ED_MPS_SHIFT) & ED_MPS_MASK ,
461 (info & ED_SKIP) ? " S" : "",
462 (headp & ED_H) ? " H" : "",
463 (headp & ED_C) ? data1 : data0,
464 headp & ED_MASK, tailp);
468 list_for_each(entry, &ed->td_list) {
471 td = list_entry(entry, struct td, td_list);
472 info = hc32_to_cpup(ahcd, &td->hwINFO);
473 dbp = hc32_to_cpup(ahcd, &td->hwDBP);
474 cbl = hc32_to_cpup(ahcd, &td->hwCBL);
476 temp = scnprintf(buf, size,
477 "\n\ttd/%p %s %d %s%scc=%x urb %p (%08x,%08x)",
481 (info & TD_OWN) ? "" : "DONE ",
482 (cbl & TD_IE) ? "IE " : "",
483 TD_CC_GET(info), td->urb, info, cbl);
488 temp = scnprintf(buf, size, "\n");
498 static ssize_t fill_async_buffer(struct debug_buffer *buf)
506 spin_lock_irqsave(&ahcd->lock, flags);
507 temp = show_list(ahcd, buf->page, PAGE_SIZE, ahcd->ed_head);
508 spin_unlock_irqrestore(&ahcd->lock, flags);
514 #define DBG_SCHED_LIMIT 64
516 static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
519 struct ed **seen, *ed;
521 unsigned temp, size, seen_count;
525 seen = kmalloc(DBG_SCHED_LIMIT * sizeof(*seen), GFP_ATOMIC);
534 temp = scnprintf(next, size, "size = %d\n", NUM_INTS);
538 /* dump a snapshot of the periodic schedule (and load) */
539 spin_lock_irqsave(&ahcd->lock, flags);
540 for (i = 0; i < NUM_INTS; i++) {
541 ed = ahcd->periodic[i];
545 temp = scnprintf(next, size, "%2d [%3d]:", i, ahcd->load[i]);
550 temp = scnprintf(next, size, " ed%d/%p",
554 for (temp = 0; temp < seen_count; temp++) {
555 if (seen[temp] == ed)
559 /* show more info the first time around */
560 if (temp == seen_count) {
561 u32 info = hc32_to_cpu(ahcd, ed->hwINFO);
562 struct list_head *entry;
565 /* qlen measured here in TDs, not urbs */
566 list_for_each(entry, &ed->td_list)
568 temp = scnprintf(next, size,
569 " (%cs dev%d ep%d%s qlen %u"
571 (info & ED_SPEED_FULL) ? 'f' : 'l',
574 (info & ED_ISO) ? "iso" : "int",
578 (info & ED_SKIP) ? " K" : "",
580 cpu_to_hc32(ahcd, ED_H)) ?
585 if (seen_count < DBG_SCHED_LIMIT)
586 seen[seen_count++] = ed;
591 /* we've seen it and what's after */
598 temp = scnprintf(next, size, "\n");
602 spin_unlock_irqrestore(&ahcd->lock, flags);
605 return PAGE_SIZE - size;
609 #undef DBG_SCHED_LIMIT
611 static ssize_t fill_registers_buffer(struct debug_buffer *buf)
615 struct admhcd_regs __iomem *regs;
622 hcd = admhc_to_hcd(ahcd);
627 spin_lock_irqsave(&ahcd->lock, flags);
629 /* dump driver info, then registers in spec order */
631 admhc_dbg_sw(ahcd, &next, &size,
632 "bus %s, device %s\n"
635 hcd->self.controller->bus->name,
636 dev_name(hcd->self.controller),
640 if (!HCD_HW_ACCESSIBLE(hcd)) {
641 size -= scnprintf(next, size,
642 "SUSPENDED (no register access)\n");
646 admhc_dump_status(ahcd, &next, &size);
648 /* other registers mostly affect frame timings */
649 rdata = admhc_readl(ahcd, ®s->fminterval);
650 temp = scnprintf(next, size,
651 "fmintvl 0x%08x %sFSLDP=0x%04x FI=0x%04x\n",
652 rdata, (rdata & ADMHC_SFI_FIT) ? "FIT " : "",
653 (rdata >> ADMHC_SFI_FSLDP_SHIFT) & ADMHC_SFI_FSLDP_MASK,
654 rdata & ADMHC_SFI_FI_MASK);
658 rdata = admhc_readl(ahcd, ®s->fmnumber);
659 temp = scnprintf(next, size, "fmnumber 0x%08x %sFR=0x%04x FN=%04x\n",
660 rdata, (rdata & ADMHC_SFN_FRT) ? "FRT " : "",
661 (rdata >> ADMHC_SFN_FR_SHIFT) & ADMHC_SFN_FR_MASK,
662 rdata & ADMHC_SFN_FN_MASK);
666 /* TODO: use predefined bitmask */
667 rdata = admhc_readl(ahcd, ®s->lsthresh);
668 temp = scnprintf(next, size, "lsthresh 0x%04x\n",
673 temp = scnprintf(next, size, "hub poll timer: %s\n",
674 admhcd_to_hcd(ahcd)->poll_rh ? "ON" : "OFF");
679 admhc_dump_roothub(ahcd, 1, &next, &size);
682 spin_unlock_irqrestore(&ahcd->lock, flags);
683 return PAGE_SIZE - size;
687 static struct debug_buffer *alloc_buffer(struct admhcd *ahcd,
688 ssize_t (*fill_func)(struct debug_buffer *))
690 struct debug_buffer *buf;
692 buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
696 buf->fill_func = fill_func;
697 mutex_init(&buf->mutex);
703 static int fill_buffer(struct debug_buffer *buf)
708 buf->page = (char *)get_zeroed_page(GFP_KERNEL);
715 ret = buf->fill_func(buf);
726 static ssize_t debug_output(struct file *file, char __user *user_buf,
727 size_t len, loff_t *offset)
729 struct debug_buffer *buf = file->private_data;
732 mutex_lock(&buf->mutex);
733 if (buf->count == 0) {
734 ret = fill_buffer(buf);
736 mutex_unlock(&buf->mutex);
740 mutex_unlock(&buf->mutex);
742 ret = simple_read_from_buffer(user_buf, len, offset,
743 buf->page, buf->count);
749 static int debug_close(struct inode *inode, struct file *file)
751 struct debug_buffer *buf = file->private_data;
755 free_page((unsigned long)buf->page);
762 static int debug_async_open(struct inode *inode, struct file *file)
764 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
766 return file->private_data ? 0 : -ENOMEM;
769 static int debug_periodic_open(struct inode *inode, struct file *file)
771 file->private_data = alloc_buffer(inode->i_private,
772 fill_periodic_buffer);
774 return file->private_data ? 0 : -ENOMEM;
777 static int debug_registers_open(struct inode *inode, struct file *file)
779 file->private_data = alloc_buffer(inode->i_private,
780 fill_registers_buffer);
782 return file->private_data ? 0 : -ENOMEM;
785 static inline void create_debug_files(struct admhcd *ahcd)
787 struct usb_bus *bus = &admhcd_to_hcd(ahcd)->self;
789 ahcd->debug_dir = debugfs_create_dir(bus->bus_name, admhc_debug_root);
790 if (!ahcd->debug_dir)
793 ahcd->debug_async = debugfs_create_file("async", S_IRUGO,
794 ahcd->debug_dir, ahcd,
796 if (!ahcd->debug_async)
799 ahcd->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
800 ahcd->debug_dir, ahcd,
801 &debug_periodic_fops);
802 if (!ahcd->debug_periodic)
805 ahcd->debug_registers = debugfs_create_file("registers", S_IRUGO,
806 ahcd->debug_dir, ahcd,
807 &debug_registers_fops);
808 if (!ahcd->debug_registers)
809 goto registers_error;
811 admhc_dbg(ahcd, "created debug files\n");
815 debugfs_remove(ahcd->debug_periodic);
817 debugfs_remove(ahcd->debug_async);
819 debugfs_remove(ahcd->debug_dir);
821 ahcd->debug_periodic = NULL;
822 ahcd->debug_async = NULL;
823 ahcd->debug_dir = NULL;
826 static inline void remove_debug_files(struct admhcd *ahcd)
828 debugfs_remove(ahcd->debug_registers);
829 debugfs_remove(ahcd->debug_periodic);
830 debugfs_remove(ahcd->debug_async);
831 debugfs_remove(ahcd->debug_dir);
836 /*-------------------------------------------------------------------------*/