2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
7 * This file is licenced under the GPL.
10 /*-------------------------------------------------------------------------*/
12 static inline char *ed_typestring(int ed_type
)
21 case PIPE_ISOCHRONOUS
:
24 return "(bad ed_type)";
27 static inline char *ed_statestring(int state
)
42 static inline char *pipestring(int pipe
)
44 return ed_typestring(usb_pipetype(pipe
));
47 static inline char *td_pidstring(u32 info
)
49 switch (info
& TD_DP
) {
60 static inline char *td_togglestring(u32 info
)
62 switch (info
& TD_T
) {
75 /* debug| print the main components of an URB
76 * small: 0) header + data packets 1) just header
78 static void __attribute__((unused
))
79 urb_print(struct admhcd
*ahcd
, struct urb
* urb
, char * str
, int small
)
81 unsigned int pipe
= urb
->pipe
;
83 if (!urb
->dev
|| !urb
->dev
->bus
) {
84 admhc_dbg(ahcd
, "%s URB: no dev", str
);
88 #ifndef ADMHC_VERBOSE_DEBUG
91 admhc_dbg(ahcd
, "URB-%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d "
96 usb_pipeendpoint(pipe
),
97 usb_pipeout(pipe
)? "out" : "in",
101 urb
->transfer_buffer_length
,
104 #ifdef ADMHC_VERBOSE_DEBUG
108 if (usb_pipecontrol(pipe
)) {
109 admhc_dbg(admhc
, "setup(8): ");
110 for (i
= 0; i
< 8 ; i
++)
111 printk (" %02x", ((__u8
*) urb
->setup_packet
) [i
]);
114 if (urb
->transfer_buffer_length
> 0 && urb
->transfer_buffer
) {
115 admhc_dbg(admhc
, "data(%d/%d): ",
117 urb
->transfer_buffer_length
);
118 len
= usb_pipeout(pipe
)?
119 urb
->transfer_buffer_length
: urb
->actual_length
;
120 for (i
= 0; i
< 16 && i
< len
; i
++)
121 printk (" %02x", ((__u8
*) urb
->transfer_buffer
) [i
]);
122 printk ("%s stat:%d\n", i
< len
? "...": "", urb
->status
);
125 #endif /* ADMHC_VERBOSE_DEBUG */
128 #define admhc_dbg_sw(ahcd, next, size, format, arg...) \
132 s_len = scnprintf(*next, *size, format, ## arg ); \
133 *size -= s_len; *next += s_len; \
135 admhc_dbg(ahcd,format, ## arg ); \
139 static void admhc_dump_intr_mask(struct admhcd
*ahcd
, char *label
, u32 mask
,
140 char **next
, unsigned *size
)
142 admhc_dbg_sw(ahcd
, next
, size
, "%s 0x%08x%s%s%s%s%s%s%s%s%s%s\n",
145 (mask
& ADMHC_INTR_INTA
) ? " INTA" : "",
146 (mask
& ADMHC_INTR_FATI
) ? " FATI" : "",
147 (mask
& ADMHC_INTR_SWI
) ? " SWI" : "",
148 (mask
& ADMHC_INTR_TDC
) ? " TDC" : "",
149 (mask
& ADMHC_INTR_FNO
) ? " FNO" : "",
150 (mask
& ADMHC_INTR_SO
) ? " SO" : "",
151 (mask
& ADMHC_INTR_INSM
) ? " INSM" : "",
152 (mask
& ADMHC_INTR_BABI
) ? " BABI" : "",
153 (mask
& ADMHC_INTR_RESI
) ? " RESI" : "",
154 (mask
& ADMHC_INTR_SOFI
) ? " SOFI" : ""
158 static void maybe_print_eds(struct admhcd
*ahcd
, char *label
, u32 value
,
159 char **next
, unsigned *size
)
162 admhc_dbg_sw(ahcd
, next
, size
, "%s %08x\n", label
, value
);
165 static char *buss2string (int state
)
168 case ADMHC_BUSS_RESET
:
170 case ADMHC_BUSS_RESUME
:
172 case ADMHC_BUSS_OPER
:
173 return "operational";
174 case ADMHC_BUSS_SUSPEND
:
181 admhc_dump_status(struct admhcd
*ahcd
, char **next
, unsigned *size
)
183 struct admhcd_regs __iomem
*regs
= ahcd
->regs
;
186 temp
= admhc_readl(ahcd
, ®s
->gencontrol
);
187 admhc_dbg_sw(ahcd
, next
, size
,
188 "gencontrol 0x%08x%s%s%s%s\n",
190 (temp
& ADMHC_CTRL_UHFE
) ? " UHFE" : "",
191 (temp
& ADMHC_CTRL_SIR
) ? " SIR" : "",
192 (temp
& ADMHC_CTRL_DMAA
) ? " DMAA" : "",
193 (temp
& ADMHC_CTRL_SR
) ? " SR" : ""
196 temp
= admhc_readl(ahcd
, ®s
->host_control
);
197 admhc_dbg_sw(ahcd
, next
, size
,
198 "host_control 0x%08x BUSS=%s%s\n",
200 buss2string(temp
& ADMHC_HC_BUSS
),
201 (temp
& ADMHC_HC_DMAE
) ? " DMAE" : ""
204 admhc_dump_intr_mask(ahcd
, "int_status",
205 admhc_readl(ahcd
, ®s
->int_status
),
207 admhc_dump_intr_mask(ahcd
, "int_enable",
208 admhc_readl(ahcd
, ®s
->int_enable
),
211 maybe_print_eds(ahcd
, "hosthead",
212 admhc_readl(ahcd
, ®s
->hosthead
), next
, size
);
215 #define dbg_port_sw(hc,num,value,next,size) \
216 admhc_dbg_sw(hc, next, size, \
218 "0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
220 (temp & ADMHC_PS_PRSC) ? " PRSC" : "", \
221 (temp & ADMHC_PS_OCIC) ? " OCIC" : "", \
222 (temp & ADMHC_PS_PSSC) ? " PSSC" : "", \
223 (temp & ADMHC_PS_PESC) ? " PESC" : "", \
224 (temp & ADMHC_PS_CSC) ? " CSC" : "", \
226 (temp & ADMHC_PS_LSDA) ? " LSDA" : "", \
227 (temp & ADMHC_PS_PPS) ? " PPS" : "", \
228 (temp & ADMHC_PS_PRS) ? " PRS" : "", \
229 (temp & ADMHC_PS_POCI) ? " POCI" : "", \
230 (temp & ADMHC_PS_PSS) ? " PSS" : "", \
232 (temp & ADMHC_PS_PES) ? " PES" : "", \
233 (temp & ADMHC_PS_CCS) ? " CCS" : "" \
246 temp
= admhc_get_rhdesc(ahcd
);
251 admhc_dbg_sw(ahcd
, next
, size
,
252 "rhdesc %08x%s%s%s%s%s%s PPCM=%02x%s%s%s%s NUMP=%d(%d)\n",
254 (temp
& ADMHC_RH_CRWE
) ? " CRWE" : "",
255 (temp
& ADMHC_RH_OCIC
) ? " OCIC" : "",
256 (temp
& ADMHC_RH_LPSC
) ? " LPSC" : "",
257 (temp
& ADMHC_RH_LPSC
) ? " DRWE" : "",
258 (temp
& ADMHC_RH_LPSC
) ? " OCI" : "",
259 (temp
& ADMHC_RH_LPSC
) ? " LPS" : "",
260 ((temp
& ADMHC_RH_PPCM
) >> 16),
261 (temp
& ADMHC_RH_NOCP
) ? " NOCP" : "",
262 (temp
& ADMHC_RH_OCPM
) ? " OCPM" : "",
263 (temp
& ADMHC_RH_NPS
) ? " NPS" : "",
264 (temp
& ADMHC_RH_PSM
) ? " PSM" : "",
265 (temp
& ADMHC_RH_NUMP
), ahcd
->num_ports
269 for (i
= 0; i
< ahcd
->num_ports
; i
++) {
270 temp
= admhc_get_portstatus(ahcd
, i
);
271 dbg_port_sw(ahcd
, i
, temp
, next
, size
);
275 static void admhc_dump(struct admhcd
*ahcd
, int verbose
)
277 admhc_dbg(ahcd
, "ADMHC ahcd state\n");
279 /* dumps some of the state we know about */
280 admhc_dump_status(ahcd
, NULL
, NULL
);
281 admhc_dbg(ahcd
,"current frame #%04x\n",
282 admhc_frame_no(ahcd
));
284 admhc_dump_roothub(ahcd
, verbose
, NULL
, NULL
);
287 static const char data0
[] = "DATA0";
288 static const char data1
[] = "DATA1";
290 static void admhc_dump_td(const struct admhcd
*ahcd
, const char *label
,
295 admhc_dbg(ahcd
, "%s td %p; urb %p index %d; hwNextTD %08x\n",
298 hc32_to_cpup(ahcd
, &td
->hwNextTD
));
300 tmp
= hc32_to_cpup(ahcd
, &td
->hwINFO
);
301 admhc_dbg(ahcd
, " status %08x%s CC=%x EC=%d %s %s ISI=%x FN=%x\n",
303 (tmp
& TD_OWN
) ? " OWN" : "",
306 td_togglestring(tmp
),
311 tmp
= hc32_to_cpup(ahcd
, &td
->hwCBL
);
312 admhc_dbg(ahcd
, " dbp %08x; cbl %08x; LEN=%d%s\n",
313 hc32_to_cpup(ahcd
, &td
->hwDBP
),
316 (tmp
& TD_IE
) ? " IE" : "");
319 static void admhc_dump_up(const struct admhcd
*ahcd
, const char *label
,
320 const struct urb_priv
*up
)
324 admhc_dbg(ahcd
, "%s urb/%p:\n", label
, up
->urb
);
325 for (i
= 0; i
< up
->td_cnt
; i
++) {
326 struct td
*td
= up
->td
[i
];
327 admhc_dump_td(ahcd
, " ->", td
);
331 /* caller MUST own hcd spinlock if verbose is set! */
332 static void __attribute__((unused
))
333 admhc_dump_ed(const struct admhcd
*ahcd
, const char *label
,
334 const struct ed
*ed
, int verbose
)
336 u32 tmp
= hc32_to_cpu(ahcd
, ed
->hwINFO
);
338 admhc_dbg(ahcd
, "%s ed %p %s type %s; next ed %08x\n",
340 ed
, ed_statestring(ed
->state
), ed_typestring(ed
->type
),
341 hc32_to_cpup(ahcd
, &ed
->hwNextED
));
343 admhc_dbg(ahcd
, " info %08x MAX=%d%s%s%s%s EP=%d DEV=%d\n", tmp
,
345 (tmp
& ED_ISO
) ? " ISO" : "",
346 (tmp
& ED_SKIP
) ? " SKIP" : "",
347 (tmp
& ED_SPEED_FULL
) ? " FULL" : " LOW",
348 (tmp
& ED_INT
) ? " INT" : "",
352 tmp
= hc32_to_cpup(ahcd
, &ed
->hwHeadP
);
353 admhc_dbg(ahcd
, " tds: head %08x tail %08x %s%s\n",
355 hc32_to_cpup(ahcd
, &ed
->hwTailP
),
356 (tmp
& ED_C
) ? data1
: data0
,
357 (tmp
& ED_H
) ? " HALT" : "");
360 admhc_dump_up(ahcd
, " active ", ed
->urb_active
);
362 if ((verbose
) && (!list_empty(&ed
->urb_pending
))) {
363 struct list_head
*entry
;
364 /* dump pending URBs */
365 list_for_each(entry
, &ed
->urb_pending
) {
367 up
= list_entry(entry
, struct urb_priv
, pending
);
368 admhc_dump_up(ahcd
, " pending ", up
);
373 #else /* ifdef DEBUG */
375 static inline void urb_print(struct urb
* urb
, char * str
, int small
) {}
376 static inline void admhc_dump_up(const struct admhcd
*ahcd
, const char *label
,
377 const struct urb_priv
*up
) {}
378 static inline void admhc_dump_ed(const struct admhcd
*ahcd
, const char *label
,
379 const struct ed
*ed
, int verbose
) {}
380 static inline void admhc_dump_td(const struct admhcd
*ahcd
, const char *label
,
381 const struct td
*td
) {}
382 static inline void admhc_dump(struct admhcd
*ahcd
, int verbose
) {}
384 #undef ADMHC_VERBOSE_DEBUG
388 /*-------------------------------------------------------------------------*/
390 #ifdef STUB_DEBUG_FILES
392 static inline void create_debug_files(struct admhcd
*bus
) { }
393 static inline void remove_debug_files(struct admhcd
*bus
) { }
398 show_urb_priv(struct admhcd
*ahcd
, char *buf
, size_t count
,
401 unsigned temp
, size
= count
;
407 temp
= scnprintf(buf
, size
,"\n\turb %p ", up
->urb
);
411 for (i
= 0; i
< up
->td_cnt
; i
++) {
416 info
= hc32_to_cpup(ahcd
, &td
->hwINFO
);
417 dbp
= hc32_to_cpup(ahcd
, &td
->hwDBP
);
418 cbl
= hc32_to_cpup(ahcd
, &td
->hwCBL
);
420 temp
= scnprintf(buf
, size
,
421 "\n\t\ttd %p %s %d %s%scc=%x (%08x,%08x)",
425 (info
& TD_OWN
) ? "WORK " : "DONE ",
426 (cbl
& TD_IE
) ? "IE " : "",
427 TD_CC_GET(info
), info
, cbl
);
436 show_list(struct admhcd
*ahcd
, char *buf
, size_t count
, struct ed
*ed
)
438 unsigned temp
, size
= count
;
443 /* dump a snapshot of the bulk or control schedule */
445 u32 info
= hc32_to_cpu(ahcd
, ed
->hwINFO
);
446 u32 headp
= hc32_to_cpu(ahcd
, ed
->hwHeadP
);
448 temp
= scnprintf(buf
, size
,
449 "ed/%p %s %cs dev%d ep%d %s%smax %d %08x%s%s %s",
451 ed_typestring (ed
->type
),
452 (info
& ED_SPEED_FULL
) ? 'f' : 'l',
454 (info
>> ED_EN_SHIFT
) & ED_EN_MASK
,
455 (info
& ED_INT
) ? "INT " : "",
456 (info
& ED_ISO
) ? "ISO " : "",
457 (info
>> ED_MPS_SHIFT
) & ED_MPS_MASK
,
459 (info
& ED_SKIP
) ? " S" : "",
460 (headp
& ED_H
) ? " H" : "",
461 (headp
& ED_C
) ? "DATA1" : "DATA0");
465 if (ed
->urb_active
) {
466 temp
= scnprintf(buf
, size
, "\nactive urb:");
470 temp
= show_urb_priv(ahcd
, buf
, size
, ed
->urb_active
);
475 if (!list_empty(&ed
->urb_pending
)) {
476 struct list_head
*entry
;
478 temp
= scnprintf(buf
, size
, "\npending urbs:");
482 list_for_each(entry
, &ed
->urb_pending
) {
484 up
= list_entry(entry
, struct urb_priv
,
487 temp
= show_urb_priv(ahcd
, buf
, size
, up
);
493 temp
= scnprintf(buf
, size
, "\n");
504 show_async(struct class_device
*class_dev
, char *buf
)
512 bus
= class_get_devdata(class_dev
);
513 hcd
= bus_to_hcd(bus
);
514 ahcd
= hcd_to_admhcd(hcd
);
516 /* display control and bulk lists together, for simplicity */
517 spin_lock_irqsave(&ahcd
->lock
, flags
);
518 temp
= show_list(ahcd
, buf
, PAGE_SIZE
, ahcd
->ed_head
);
519 spin_unlock_irqrestore(&ahcd
->lock
, flags
);
523 static CLASS_DEVICE_ATTR(async
, S_IRUGO
, show_async
, NULL
);
526 #define DBG_SCHED_LIMIT 64
529 show_periodic(struct class_device
*class_dev
, char *buf
)
535 struct ed
**seen
, *ed
;
537 unsigned temp
, size
, seen_count
;
541 if (!(seen
= kmalloc(DBG_SCHED_LIMIT
* sizeof *seen
, GFP_ATOMIC
)))
545 bus
= class_get_devdata(class_dev
);
546 hcd
= bus_to_hcd(bus
);
547 ahcd
= hcd_to_admhcd(hcd
);
551 temp
= scnprintf(next
, size
, "size = %d\n", NUM_INTS
);
555 /* dump a snapshot of the periodic schedule (and load) */
556 spin_lock_irqsave(&ahcd
->lock
, flags
);
557 for (i
= 0; i
< NUM_INTS
; i
++) {
558 if (!(ed
= ahcd
->periodic
[i
]))
561 temp
= scnprintf(next
, size
, "%2d [%3d]:", i
, ahcd
->load
[i
]);
566 temp
= scnprintf(next
, size
, " ed%d/%p",
570 for (temp
= 0; temp
< seen_count
; temp
++) {
571 if (seen
[temp
] == ed
)
575 /* show more info the first time around */
576 if (temp
== seen_count
) {
577 u32 info
= hc32_to_cpu (ahcd
, ed
->hwINFO
);
578 struct list_head
*entry
;
581 /* qlen measured here in TDs, not urbs */
582 list_for_each (entry
, &ed
->td_list
)
584 temp
= scnprintf(next
, size
,
585 " (%cs dev%d ep%d%s qlen %u"
587 (info
& ED_SPEED_FULL
) ? 'f' : 'l',
590 (info
& ED_ISO
) ? "iso" : "int",
594 (info
& ED_SKIP
) ? " K" : "",
596 cpu_to_hc32(ahcd
, ED_H
)) ?
601 if (seen_count
< DBG_SCHED_LIMIT
)
602 seen
[seen_count
++] = ed
;
607 /* we've seen it and what's after */
614 temp
= scnprintf(next
, size
, "\n");
618 spin_unlock_irqrestore(&ahcd
->lock
, flags
);
621 return PAGE_SIZE
- size
;
626 static CLASS_DEVICE_ATTR(periodic
, S_IRUGO
, show_periodic
, NULL
);
629 #undef DBG_SCHED_LIMIT
632 show_registers(struct class_device
*class_dev
, char *buf
)
637 struct admhcd_regs __iomem
*regs
;
643 bus
= class_get_devdata(class_dev
);
644 hcd
= bus_to_hcd(bus
);
645 ahcd
= hcd_to_admhcd(hcd
);
650 spin_lock_irqsave(&ahcd
->lock
, flags
);
652 /* dump driver info, then registers in spec order */
654 admhc_dbg_sw(ahcd
, &next
, &size
,
655 "bus %s, device %s\n"
657 "%s version " DRIVER_VERSION
"\n",
658 hcd
->self
.controller
->bus
->name
,
659 hcd
->self
.controller
->bus_id
,
663 if (bus
->controller
->power
.power_state
.event
) {
664 size
-= scnprintf(next
, size
,
665 "SUSPENDED (no register access)\n");
669 admhc_dump_status(ahcd
, &next
, &size
);
671 /* other registers mostly affect frame timings */
672 rdata
= admhc_readl(ahcd
, ®s
->fminterval
);
673 temp
= scnprintf(next
, size
,
674 "fmintvl 0x%08x %sFSLDP=0x%04x FI=0x%04x\n",
675 rdata
, (rdata
& ADMHC_SFI_FIT
) ? "FIT " : "",
676 (rdata
>> ADMHC_SFI_FSLDP_SHIFT
) & ADMHC_SFI_FSLDP_MASK
,
677 rdata
& ADMHC_SFI_FI_MASK
);
681 rdata
= admhc_readl(ahcd
, ®s
->fmnumber
);
682 temp
= scnprintf(next
, size
, "fmnumber 0x%08x %sFR=0x%04x FN=%04x\n",
683 rdata
, (rdata
& ADMHC_SFN_FRT
) ? "FRT " : "",
684 (rdata
>> ADMHC_SFN_FR_SHIFT
) & ADMHC_SFN_FR_MASK
,
685 rdata
& ADMHC_SFN_FN_MASK
);
689 /* TODO: use predefined bitmask */
690 rdata
= admhc_readl(ahcd
, ®s
->lsthresh
);
691 temp
= scnprintf(next
, size
, "lsthresh 0x%04x\n",
696 temp
= scnprintf(next
, size
, "hub poll timer: %s\n",
697 admhcd_to_hcd(ahcd
)->poll_rh
? "ON" : "OFF");
702 admhc_dump_roothub(ahcd
, 1, &next
, &size
);
705 spin_unlock_irqrestore(&ahcd
->lock
, flags
);
706 return PAGE_SIZE
- size
;
708 static CLASS_DEVICE_ATTR(registers
, S_IRUGO
, show_registers
, NULL
);
711 static inline void create_debug_files (struct admhcd
*ahcd
)
713 struct class_device
*cldev
= admhcd_to_hcd(ahcd
)->self
.class_dev
;
716 retval
= class_device_create_file(cldev
, &class_device_attr_async
);
717 retval
= class_device_create_file(cldev
, &class_device_attr_periodic
);
718 retval
= class_device_create_file(cldev
, &class_device_attr_registers
);
719 admhc_dbg(ahcd
, "created debug files\n");
722 static inline void remove_debug_files (struct admhcd
*ahcd
)
724 struct class_device
*cldev
= admhcd_to_hcd(ahcd
)->self
.class_dev
;
726 class_device_remove_file(cldev
, &class_device_attr_async
);
727 class_device_remove_file(cldev
, &class_device_attr_periodic
);
728 class_device_remove_file(cldev
, &class_device_attr_registers
);
733 /*-------------------------------------------------------------------------*/