2 * ADM5120 HCD (Host Controller Driver) for USB
4 * Copyright (C) 2007 Gabor Juhos <juhosg at 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 file is licenced under the GPL.
13 /*-------------------------------------------------------------------------*/
15 static inline char *ed_typestring(int ed_type
)
24 case PIPE_ISOCHRONOUS
:
27 return "(bad ed_type)";
30 static inline char *ed_statestring(int state
)
43 static inline char *pipestring(int pipe
)
45 return ed_typestring(usb_pipetype(pipe
));
48 static inline char *td_pidstring(u32 info
)
50 switch (info
& TD_DP
) {
61 static inline char *td_togglestring(u32 info
)
63 switch (info
& TD_T
) {
74 /*-------------------------------------------------------------------------*/
78 /* debug| print the main components of an URB
79 * small: 0) header + data packets 1) just header
81 static void __attribute__((unused
))
82 urb_print(struct admhcd
*ahcd
, struct urb
*urb
, char *str
, int small
)
84 unsigned int pipe
= urb
->pipe
;
86 if (!urb
->dev
|| !urb
->dev
->bus
) {
87 admhc_dbg(ahcd
, "%s URB: no dev", str
);
91 #ifndef ADMHC_VERBOSE_DEBUG
94 admhc_dbg(ahcd
, "URB-%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d "
98 usb_pipedevice (pipe
),
99 usb_pipeendpoint (pipe
),
100 usb_pipeout(pipe
)? "out" : "in",
104 urb
->transfer_buffer_length
,
107 #ifdef ADMHC_VERBOSE_DEBUG
111 if (usb_pipecontrol(pipe
)) {
112 admhc_dbg(ahcd
, "setup(8):");
113 for (i
= 0; i
< 8 ; i
++)
114 printk (" %02x", ((__u8
*) urb
->setup_packet
) [i
]);
117 if (urb
->transfer_buffer_length
> 0 && urb
->transfer_buffer
) {
118 admhc_dbg(ahcd
, "data(%d/%d):",
120 urb
->transfer_buffer_length
);
121 len
= usb_pipeout(pipe
)?
122 urb
->transfer_buffer_length
: urb
->actual_length
;
123 for (i
= 0; i
< 16 && i
< len
; i
++)
124 printk(" %02x", ((__u8
*)urb
->transfer_buffer
)[i
]);
125 printk("%s stat:%d\n", i
< len
? "...": "", urb
->status
);
128 #endif /* ADMHC_VERBOSE_DEBUG */
131 #define admhc_dbg_sw(ahcd, next, size, format, arg...) \
135 s_len = scnprintf(*next, *size, format, ## arg ); \
136 *size -= s_len; *next += s_len; \
138 admhc_dbg(ahcd,format, ## arg ); \
142 static void admhc_dump_intr_mask(struct admhcd
*ahcd
, char *label
, u32 mask
,
143 char **next
, unsigned *size
)
145 admhc_dbg_sw(ahcd
, next
, size
, "%s 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n",
148 (mask
& ADMHC_INTR_INTA
) ? " INTA" : "",
149 (mask
& ADMHC_INTR_FATI
) ? " FATI" : "",
150 (mask
& ADMHC_INTR_SWI
) ? " SWI" : "",
151 (mask
& ADMHC_INTR_TDC
) ? " TDC" : "",
152 (mask
& ADMHC_INTR_FNO
) ? " FNO" : "",
153 (mask
& ADMHC_INTR_SO
) ? " SO" : "",
154 (mask
& ADMHC_INTR_INSM
) ? " INSM" : "",
155 (mask
& ADMHC_INTR_BABI
) ? " BABI" : "",
156 (mask
& ADMHC_INTR_7
) ? " !7!" : "",
157 (mask
& ADMHC_INTR_6
) ? " !6!" : "",
158 (mask
& ADMHC_INTR_RESI
) ? " RESI" : "",
159 (mask
& ADMHC_INTR_SOFI
) ? " SOFI" : ""
163 static void maybe_print_eds(struct admhcd
*ahcd
, char *label
, u32 value
,
164 char **next
, unsigned *size
)
167 admhc_dbg_sw(ahcd
, next
, size
, "%s %08x\n", label
, value
);
170 static char *buss2string (int state
)
173 case ADMHC_BUSS_RESET
:
175 case ADMHC_BUSS_RESUME
:
177 case ADMHC_BUSS_OPER
:
178 return "operational";
179 case ADMHC_BUSS_SUSPEND
:
186 admhc_dump_status(struct admhcd
*ahcd
, char **next
, unsigned *size
)
188 struct admhcd_regs __iomem
*regs
= ahcd
->regs
;
191 temp
= admhc_readl(ahcd
, ®s
->gencontrol
);
192 admhc_dbg_sw(ahcd
, next
, size
,
193 "gencontrol 0x%08x%s%s%s%s\n",
195 (temp
& ADMHC_CTRL_UHFE
) ? " UHFE" : "",
196 (temp
& ADMHC_CTRL_SIR
) ? " SIR" : "",
197 (temp
& ADMHC_CTRL_DMAA
) ? " DMAA" : "",
198 (temp
& ADMHC_CTRL_SR
) ? " SR" : ""
201 temp
= admhc_readl(ahcd
, ®s
->host_control
);
202 admhc_dbg_sw(ahcd
, next
, size
,
203 "host_control 0x%08x BUSS=%s%s\n",
205 buss2string(temp
& ADMHC_HC_BUSS
),
206 (temp
& ADMHC_HC_DMAE
) ? " DMAE" : ""
209 admhc_dump_intr_mask(ahcd
, "int_status",
210 admhc_readl(ahcd
, ®s
->int_status
),
212 admhc_dump_intr_mask(ahcd
, "int_enable",
213 admhc_readl(ahcd
, ®s
->int_enable
),
216 maybe_print_eds(ahcd
, "hosthead",
217 admhc_readl(ahcd
, ®s
->hosthead
), next
, size
);
220 #define dbg_port_sw(hc,num,value,next,size) \
221 admhc_dbg_sw(hc, next, size, \
223 "0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
225 (temp & ADMHC_PS_PRSC) ? " PRSC" : "", \
226 (temp & ADMHC_PS_OCIC) ? " OCIC" : "", \
227 (temp & ADMHC_PS_PSSC) ? " PSSC" : "", \
228 (temp & ADMHC_PS_PESC) ? " PESC" : "", \
229 (temp & ADMHC_PS_CSC) ? " CSC" : "", \
231 (temp & ADMHC_PS_LSDA) ? " LSDA" : "", \
232 (temp & ADMHC_PS_PPS) ? " PPS" : "", \
233 (temp & ADMHC_PS_PRS) ? " PRS" : "", \
234 (temp & ADMHC_PS_POCI) ? " POCI" : "", \
235 (temp & ADMHC_PS_PSS) ? " PSS" : "", \
237 (temp & ADMHC_PS_PES) ? " PES" : "", \
238 (temp & ADMHC_PS_CCS) ? " CCS" : "" \
251 temp
= admhc_read_rhdesc(ahcd
);
256 admhc_dbg_sw(ahcd
, next
, size
,
257 "rhdesc %08x%s%s%s%s%s%s PPCM=%02x%s%s%s%s NUMP=%d(%d)\n",
259 (temp
& ADMHC_RH_CRWE
) ? " CRWE" : "",
260 (temp
& ADMHC_RH_OCIC
) ? " OCIC" : "",
261 (temp
& ADMHC_RH_LPSC
) ? " LPSC" : "",
262 (temp
& ADMHC_RH_LPSC
) ? " DRWE" : "",
263 (temp
& ADMHC_RH_LPSC
) ? " OCI" : "",
264 (temp
& ADMHC_RH_LPSC
) ? " LPS" : "",
265 ((temp
& ADMHC_RH_PPCM
) >> 16),
266 (temp
& ADMHC_RH_NOCP
) ? " NOCP" : "",
267 (temp
& ADMHC_RH_OCPM
) ? " OCPM" : "",
268 (temp
& ADMHC_RH_NPS
) ? " NPS" : "",
269 (temp
& ADMHC_RH_PSM
) ? " PSM" : "",
270 (temp
& ADMHC_RH_NUMP
), ahcd
->num_ports
274 for (i
= 0; i
< ahcd
->num_ports
; i
++) {
275 temp
= admhc_read_portstatus(ahcd
, i
);
276 dbg_port_sw(ahcd
, i
, temp
, next
, size
);
280 static void admhc_dump(struct admhcd
*ahcd
, int verbose
)
282 admhc_dbg(ahcd
, "ADMHC ahcd state\n");
284 /* dumps some of the state we know about */
285 admhc_dump_status(ahcd
, NULL
, NULL
);
286 admhc_dbg(ahcd
,"current frame #%04x\n",
287 admhc_frame_no(ahcd
));
289 admhc_dump_roothub(ahcd
, verbose
, NULL
, NULL
);
292 static const char data0
[] = "DATA0";
293 static const char data1
[] = "DATA1";
295 static void admhc_dump_td(const struct admhcd
*ahcd
, const char *label
,
300 admhc_dbg(ahcd
, "%s td %p; urb %p index %d; hwNextTD %08x\n",
303 hc32_to_cpup(ahcd
, &td
->hwNextTD
));
305 tmp
= hc32_to_cpup(ahcd
, &td
->hwINFO
);
306 admhc_dbg(ahcd
, " status %08x%s CC=%x EC=%d %s %s ISI=%x FN=%x\n",
308 (tmp
& TD_OWN
) ? " OWN" : "",
311 td_togglestring(tmp
),
316 tmp
= hc32_to_cpup(ahcd
, &td
->hwCBL
);
317 admhc_dbg(ahcd
, " dbp %08x; cbl %08x; LEN=%d%s\n",
318 hc32_to_cpup(ahcd
, &td
->hwDBP
),
321 (tmp
& TD_IE
) ? " IE" : "");
324 /* caller MUST own hcd spinlock if verbose is set! */
325 static void __attribute__((unused
))
326 admhc_dump_ed(const struct admhcd
*ahcd
, const char *label
,
327 const struct ed
*ed
, int verbose
)
329 u32 tmp
= hc32_to_cpu(ahcd
, ed
->hwINFO
);
331 admhc_dbg(ahcd
, "%s ed %p %s type %s; next ed %08x\n",
333 ed
, ed_statestring(ed
->state
), ed_typestring(ed
->type
),
334 hc32_to_cpup(ahcd
, &ed
->hwNextED
));
336 admhc_dbg(ahcd
, " info %08x MAX=%d%s%s%s%s EP=%d DEV=%d\n", tmp
,
338 (tmp
& ED_ISO
) ? " ISO" : "",
339 (tmp
& ED_SKIP
) ? " SKIP" : "",
340 (tmp
& ED_SPEED_FULL
) ? " FULL" : " LOW",
341 (tmp
& ED_INT
) ? " INT" : "",
345 tmp
= hc32_to_cpup(ahcd
, &ed
->hwHeadP
);
346 admhc_dbg(ahcd
, " tds: head %08x tail %08x %s%s%s\n",
348 hc32_to_cpup (ahcd
, &ed
->hwTailP
),
349 (tmp
& ED_C
) ? data1
: data0
,
350 (tmp
& ED_H
) ? " HALT" : "",
351 verbose
? " td list follows" : " (not listing)");
354 struct list_head
*tmp
;
356 /* use ed->td_list because HC concurrently modifies
357 * hwNextTD as it accumulates ed_donelist.
359 list_for_each(tmp
, &ed
->td_list
) {
361 td
= list_entry(tmp
, struct td
, td_list
);
362 admhc_dump_td (ahcd
, " ->", td
);
367 #else /* ifdef DEBUG */
369 static inline void urb_print(struct admhcd
*ahcd
, struct urb
* urb
, char * str
,
371 static inline void admhc_dump_ed(const struct admhcd
*ahcd
, const char *label
,
372 const struct ed
*ed
, int verbose
) {}
373 static inline void admhc_dump_td(const struct admhcd
*ahcd
, const char *label
,
374 const struct td
*td
) {}
375 static inline void admhc_dump(struct admhcd
*ahcd
, int verbose
) {}
377 #undef ADMHC_VERBOSE_DEBUG
381 /*-------------------------------------------------------------------------*/
383 #ifdef STUB_DEBUG_FILES
385 static inline void create_debug_files(struct admhcd
*bus
) { }
386 static inline void remove_debug_files(struct admhcd
*bus
) { }
391 show_list(struct admhcd
*ahcd
, char *buf
, size_t count
, struct ed
*ed
)
393 unsigned temp
, size
= count
;
398 /* dump a snapshot of the bulk or control schedule */
400 u32 info
= hc32_to_cpu(ahcd
, ed
->hwINFO
);
401 u32 headp
= hc32_to_cpu(ahcd
, ed
->hwHeadP
);
402 u32 tailp
= hc32_to_cpu(ahcd
, ed
->hwTailP
);
403 struct list_head
*entry
;
406 temp
= scnprintf(buf
, size
,
407 "ed/%p %s %s %cs dev%d ep%d %s%smax %d %08x%s%s %s"
410 ed_statestring(ed
->state
),
411 ed_typestring (ed
->type
),
412 (info
& ED_SPEED_FULL
) ? 'f' : 'l',
414 (info
>> ED_EN_SHIFT
) & ED_EN_MASK
,
415 (info
& ED_INT
) ? "INT " : "",
416 (info
& ED_ISO
) ? "ISO " : "",
417 (info
>> ED_MPS_SHIFT
) & ED_MPS_MASK
,
419 (info
& ED_SKIP
) ? " S" : "",
420 (headp
& ED_H
) ? " H" : "",
421 (headp
& ED_C
) ? data1
: data0
,
422 headp
& ED_MASK
,tailp
);
426 list_for_each(entry
, &ed
->td_list
) {
429 td
= list_entry(entry
, struct td
, td_list
);
430 info
= hc32_to_cpup (ahcd
, &td
->hwINFO
);
431 dbp
= hc32_to_cpup (ahcd
, &td
->hwDBP
);
432 cbl
= hc32_to_cpup (ahcd
, &td
->hwCBL
);
434 temp
= scnprintf(buf
, size
,
435 "\n\ttd/%p %s %d %s%scc=%x urb %p (%08x,%08x)",
439 (info
& TD_OWN
) ? "" : "DONE ",
440 (cbl
& TD_IE
) ? "IE " : "",
441 TD_CC_GET (info
), td
->urb
, info
, cbl
);
446 temp
= scnprintf(buf
, size
, "\n");
456 show_async(struct class_device
*class_dev
, char *buf
)
464 bus
= class_get_devdata(class_dev
);
465 hcd
= bus_to_hcd(bus
);
466 ahcd
= hcd_to_admhcd(hcd
);
468 /* display control and bulk lists together, for simplicity */
469 spin_lock_irqsave(&ahcd
->lock
, flags
);
470 temp
= show_list(ahcd
, buf
, PAGE_SIZE
, ahcd
->ed_head
);
471 spin_unlock_irqrestore(&ahcd
->lock
, flags
);
475 static CLASS_DEVICE_ATTR(async
, S_IRUGO
, show_async
, NULL
);
478 #define DBG_SCHED_LIMIT 64
481 show_periodic(struct class_device
*class_dev
, char *buf
)
486 struct ed
**seen
, *ed
;
488 unsigned temp
, size
, seen_count
;
492 if (!(seen
= kmalloc(DBG_SCHED_LIMIT
* sizeof *seen
, GFP_ATOMIC
)))
496 bus
= class_get_devdata(class_dev
);
497 hcd
= bus_to_hcd(bus
);
498 ahcd
= hcd_to_admhcd(hcd
);
502 temp
= scnprintf(next
, size
, "size = %d\n", NUM_INTS
);
506 /* dump a snapshot of the periodic schedule (and load) */
507 spin_lock_irqsave(&ahcd
->lock
, flags
);
508 for (i
= 0; i
< NUM_INTS
; i
++) {
509 if (!(ed
= ahcd
->periodic
[i
]))
512 temp
= scnprintf(next
, size
, "%2d [%3d]:", i
, ahcd
->load
[i
]);
517 temp
= scnprintf(next
, size
, " ed%d/%p",
521 for (temp
= 0; temp
< seen_count
; temp
++) {
522 if (seen
[temp
] == ed
)
526 /* show more info the first time around */
527 if (temp
== seen_count
) {
528 u32 info
= hc32_to_cpu (ahcd
, ed
->hwINFO
);
529 struct list_head
*entry
;
532 /* qlen measured here in TDs, not urbs */
533 list_for_each (entry
, &ed
->td_list
)
535 temp
= scnprintf(next
, size
,
536 " (%cs dev%d ep%d%s qlen %u"
538 (info
& ED_SPEED_FULL
) ? 'f' : 'l',
541 (info
& ED_ISO
) ? "iso" : "int",
545 (info
& ED_SKIP
) ? " K" : "",
547 cpu_to_hc32(ahcd
, ED_H
)) ?
552 if (seen_count
< DBG_SCHED_LIMIT
)
553 seen
[seen_count
++] = ed
;
558 /* we've seen it and what's after */
565 temp
= scnprintf(next
, size
, "\n");
569 spin_unlock_irqrestore(&ahcd
->lock
, flags
);
572 return PAGE_SIZE
- size
;
574 static CLASS_DEVICE_ATTR(periodic
, S_IRUGO
, show_periodic
, NULL
);
577 #undef DBG_SCHED_LIMIT
580 show_registers(struct class_device
*class_dev
, char *buf
)
585 struct admhcd_regs __iomem
*regs
;
591 bus
= class_get_devdata(class_dev
);
592 hcd
= bus_to_hcd(bus
);
593 ahcd
= hcd_to_admhcd(hcd
);
598 spin_lock_irqsave(&ahcd
->lock
, flags
);
600 /* dump driver info, then registers in spec order */
602 admhc_dbg_sw(ahcd
, &next
, &size
,
603 "bus %s, device %s\n"
605 "%s version " DRIVER_VERSION
"\n",
606 hcd
->self
.controller
->bus
->name
,
607 hcd
->self
.controller
->bus_id
,
611 if (bus
->controller
->power
.power_state
.event
) {
612 size
-= scnprintf(next
, size
,
613 "SUSPENDED (no register access)\n");
617 admhc_dump_status(ahcd
, &next
, &size
);
619 /* other registers mostly affect frame timings */
620 rdata
= admhc_readl(ahcd
, ®s
->fminterval
);
621 temp
= scnprintf(next
, size
,
622 "fmintvl 0x%08x %sFSLDP=0x%04x FI=0x%04x\n",
623 rdata
, (rdata
& ADMHC_SFI_FIT
) ? "FIT " : "",
624 (rdata
>> ADMHC_SFI_FSLDP_SHIFT
) & ADMHC_SFI_FSLDP_MASK
,
625 rdata
& ADMHC_SFI_FI_MASK
);
629 rdata
= admhc_readl(ahcd
, ®s
->fmnumber
);
630 temp
= scnprintf(next
, size
, "fmnumber 0x%08x %sFR=0x%04x FN=%04x\n",
631 rdata
, (rdata
& ADMHC_SFN_FRT
) ? "FRT " : "",
632 (rdata
>> ADMHC_SFN_FR_SHIFT
) & ADMHC_SFN_FR_MASK
,
633 rdata
& ADMHC_SFN_FN_MASK
);
637 /* TODO: use predefined bitmask */
638 rdata
= admhc_readl(ahcd
, ®s
->lsthresh
);
639 temp
= scnprintf(next
, size
, "lsthresh 0x%04x\n",
644 temp
= scnprintf(next
, size
, "hub poll timer: %s\n",
645 admhcd_to_hcd(ahcd
)->poll_rh
? "ON" : "OFF");
650 admhc_dump_roothub(ahcd
, 1, &next
, &size
);
653 spin_unlock_irqrestore(&ahcd
->lock
, flags
);
654 return PAGE_SIZE
- size
;
656 static CLASS_DEVICE_ATTR(registers
, S_IRUGO
, show_registers
, NULL
);
659 static inline void create_debug_files (struct admhcd
*ahcd
)
661 struct class_device
*cldev
= admhcd_to_hcd(ahcd
)->self
.class_dev
;
664 retval
= class_device_create_file(cldev
, &class_device_attr_async
);
665 retval
= class_device_create_file(cldev
, &class_device_attr_periodic
);
666 retval
= class_device_create_file(cldev
, &class_device_attr_registers
);
667 admhc_dbg(ahcd
, "created debug files\n");
670 static inline void remove_debug_files (struct admhcd
*ahcd
)
672 struct class_device
*cldev
= admhcd_to_hcd(ahcd
)->self
.class_dev
;
674 class_device_remove_file(cldev
, &class_device_attr_async
);
675 class_device_remove_file(cldev
, &class_device_attr_periodic
);
676 class_device_remove_file(cldev
, &class_device_attr_registers
);
681 /*-------------------------------------------------------------------------*/