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%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_7
) ? " !7!" : "",
154 (mask
& ADMHC_INTR_6
) ? " !6!" : "",
155 (mask
& ADMHC_INTR_RESI
) ? " RESI" : "",
156 (mask
& ADMHC_INTR_SOFI
) ? " SOFI" : ""
160 static void maybe_print_eds(struct admhcd
*ahcd
, char *label
, u32 value
,
161 char **next
, unsigned *size
)
164 admhc_dbg_sw(ahcd
, next
, size
, "%s %08x\n", label
, value
);
167 static char *buss2string (int state
)
170 case ADMHC_BUSS_RESET
:
172 case ADMHC_BUSS_RESUME
:
174 case ADMHC_BUSS_OPER
:
175 return "operational";
176 case ADMHC_BUSS_SUSPEND
:
183 admhc_dump_status(struct admhcd
*ahcd
, char **next
, unsigned *size
)
185 struct admhcd_regs __iomem
*regs
= ahcd
->regs
;
188 temp
= admhc_readl(ahcd
, ®s
->gencontrol
);
189 admhc_dbg_sw(ahcd
, next
, size
,
190 "gencontrol 0x%08x%s%s%s%s\n",
192 (temp
& ADMHC_CTRL_UHFE
) ? " UHFE" : "",
193 (temp
& ADMHC_CTRL_SIR
) ? " SIR" : "",
194 (temp
& ADMHC_CTRL_DMAA
) ? " DMAA" : "",
195 (temp
& ADMHC_CTRL_SR
) ? " SR" : ""
198 temp
= admhc_readl(ahcd
, ®s
->host_control
);
199 admhc_dbg_sw(ahcd
, next
, size
,
200 "host_control 0x%08x BUSS=%s%s\n",
202 buss2string(temp
& ADMHC_HC_BUSS
),
203 (temp
& ADMHC_HC_DMAE
) ? " DMAE" : ""
206 admhc_dump_intr_mask(ahcd
, "int_status",
207 admhc_readl(ahcd
, ®s
->int_status
),
209 admhc_dump_intr_mask(ahcd
, "int_enable",
210 admhc_readl(ahcd
, ®s
->int_enable
),
213 maybe_print_eds(ahcd
, "hosthead",
214 admhc_readl(ahcd
, ®s
->hosthead
), next
, size
);
217 #define dbg_port_sw(hc,num,value,next,size) \
218 admhc_dbg_sw(hc, next, size, \
220 "0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
222 (temp & ADMHC_PS_PRSC) ? " PRSC" : "", \
223 (temp & ADMHC_PS_OCIC) ? " OCIC" : "", \
224 (temp & ADMHC_PS_PSSC) ? " PSSC" : "", \
225 (temp & ADMHC_PS_PESC) ? " PESC" : "", \
226 (temp & ADMHC_PS_CSC) ? " CSC" : "", \
228 (temp & ADMHC_PS_LSDA) ? " LSDA" : "", \
229 (temp & ADMHC_PS_PPS) ? " PPS" : "", \
230 (temp & ADMHC_PS_PRS) ? " PRS" : "", \
231 (temp & ADMHC_PS_POCI) ? " POCI" : "", \
232 (temp & ADMHC_PS_PSS) ? " PSS" : "", \
234 (temp & ADMHC_PS_PES) ? " PES" : "", \
235 (temp & ADMHC_PS_CCS) ? " CCS" : "" \
248 temp
= admhc_read_rhdesc(ahcd
);
253 admhc_dbg_sw(ahcd
, next
, size
,
254 "rhdesc %08x%s%s%s%s%s%s PPCM=%02x%s%s%s%s NUMP=%d(%d)\n",
256 (temp
& ADMHC_RH_CRWE
) ? " CRWE" : "",
257 (temp
& ADMHC_RH_OCIC
) ? " OCIC" : "",
258 (temp
& ADMHC_RH_LPSC
) ? " LPSC" : "",
259 (temp
& ADMHC_RH_LPSC
) ? " DRWE" : "",
260 (temp
& ADMHC_RH_LPSC
) ? " OCI" : "",
261 (temp
& ADMHC_RH_LPSC
) ? " LPS" : "",
262 ((temp
& ADMHC_RH_PPCM
) >> 16),
263 (temp
& ADMHC_RH_NOCP
) ? " NOCP" : "",
264 (temp
& ADMHC_RH_OCPM
) ? " OCPM" : "",
265 (temp
& ADMHC_RH_NPS
) ? " NPS" : "",
266 (temp
& ADMHC_RH_PSM
) ? " PSM" : "",
267 (temp
& ADMHC_RH_NUMP
), ahcd
->num_ports
271 for (i
= 0; i
< ahcd
->num_ports
; i
++) {
272 temp
= admhc_read_portstatus(ahcd
, i
);
273 dbg_port_sw(ahcd
, i
, temp
, next
, size
);
277 static void admhc_dump(struct admhcd
*ahcd
, int verbose
)
279 admhc_dbg(ahcd
, "ADMHC ahcd state\n");
281 /* dumps some of the state we know about */
282 admhc_dump_status(ahcd
, NULL
, NULL
);
283 admhc_dbg(ahcd
,"current frame #%04x\n",
284 admhc_frame_no(ahcd
));
286 admhc_dump_roothub(ahcd
, verbose
, NULL
, NULL
);
289 static const char data0
[] = "DATA0";
290 static const char data1
[] = "DATA1";
292 static void admhc_dump_td(const struct admhcd
*ahcd
, const char *label
,
297 admhc_dbg(ahcd
, "%s td %p; urb %p index %d; hwNextTD %08x\n",
300 hc32_to_cpup(ahcd
, &td
->hwNextTD
));
302 tmp
= hc32_to_cpup(ahcd
, &td
->hwINFO
);
303 admhc_dbg(ahcd
, " status %08x%s CC=%x EC=%d %s %s ISI=%x FN=%x\n",
305 (tmp
& TD_OWN
) ? " OWN" : "",
308 td_togglestring(tmp
),
313 tmp
= hc32_to_cpup(ahcd
, &td
->hwCBL
);
314 admhc_dbg(ahcd
, " dbp %08x; cbl %08x; LEN=%d%s\n",
315 hc32_to_cpup(ahcd
, &td
->hwDBP
),
318 (tmp
& TD_IE
) ? " IE" : "");
321 static void admhc_dump_up(const struct admhcd
*ahcd
, const char *label
,
322 const struct urb_priv
*up
)
326 admhc_dbg(ahcd
, "%s urb/%p:\n", label
, up
->urb
);
327 for (i
= 0; i
< up
->td_cnt
; i
++) {
328 struct td
*td
= up
->td
[i
];
329 admhc_dump_td(ahcd
, " ->", td
);
333 /* caller MUST own hcd spinlock if verbose is set! */
334 static void __attribute__((unused
))
335 admhc_dump_ed(const struct admhcd
*ahcd
, const char *label
,
336 const struct ed
*ed
, int verbose
)
338 u32 tmp
= hc32_to_cpu(ahcd
, ed
->hwINFO
);
340 admhc_dbg(ahcd
, "%s ed %p %s type %s; next ed %08x\n",
342 ed
, ed_statestring(ed
->state
), ed_typestring(ed
->type
),
343 hc32_to_cpup(ahcd
, &ed
->hwNextED
));
345 admhc_dbg(ahcd
, " info %08x MAX=%d%s%s%s%s EP=%d DEV=%d\n", tmp
,
347 (tmp
& ED_ISO
) ? " ISO" : "",
348 (tmp
& ED_SKIP
) ? " SKIP" : "",
349 (tmp
& ED_SPEED_FULL
) ? " FULL" : " LOW",
350 (tmp
& ED_INT
) ? " INT" : "",
354 tmp
= hc32_to_cpup(ahcd
, &ed
->hwHeadP
);
355 admhc_dbg(ahcd
, " tds: head %08x tail %08x %s%s\n",
357 hc32_to_cpup(ahcd
, &ed
->hwTailP
),
358 (tmp
& ED_C
) ? data1
: data0
,
359 (tmp
& ED_H
) ? " HALT" : "");
362 admhc_dump_up(ahcd
, " active ", ed
->urb_active
);
364 if ((verbose
) && (!list_empty(&ed
->urb_pending
))) {
365 struct list_head
*entry
;
366 /* dump pending URBs */
367 list_for_each(entry
, &ed
->urb_pending
) {
369 up
= list_entry(entry
, struct urb_priv
, pending
);
370 admhc_dump_up(ahcd
, " pending ", up
);
375 #else /* ifdef DEBUG */
377 static inline void urb_print(struct urb
* urb
, char * str
, int small
) {}
378 static inline void admhc_dump_up(const struct admhcd
*ahcd
, const char *label
,
379 const struct urb_priv
*up
) {}
380 static inline void admhc_dump_ed(const struct admhcd
*ahcd
, const char *label
,
381 const struct ed
*ed
, int verbose
) {}
382 static inline void admhc_dump_td(const struct admhcd
*ahcd
, const char *label
,
383 const struct td
*td
) {}
384 static inline void admhc_dump(struct admhcd
*ahcd
, int verbose
) {}
386 #undef ADMHC_VERBOSE_DEBUG
390 /*-------------------------------------------------------------------------*/
392 #ifdef STUB_DEBUG_FILES
394 static inline void create_debug_files(struct admhcd
*bus
) { }
395 static inline void remove_debug_files(struct admhcd
*bus
) { }
400 show_urb_priv(struct admhcd
*ahcd
, char *buf
, size_t count
,
403 unsigned temp
, size
= count
;
409 temp
= scnprintf(buf
, size
,"\n\turb %p ", up
->urb
);
413 for (i
= 0; i
< up
->td_cnt
; i
++) {
418 info
= hc32_to_cpup(ahcd
, &td
->hwINFO
);
419 dbp
= hc32_to_cpup(ahcd
, &td
->hwDBP
);
420 cbl
= hc32_to_cpup(ahcd
, &td
->hwCBL
);
422 temp
= scnprintf(buf
, size
,
423 "\n\t\ttd %p %s %d %s%scc=%x (%08x,%08x)",
427 (info
& TD_OWN
) ? "WORK " : "DONE ",
428 (cbl
& TD_IE
) ? "IE " : "",
429 TD_CC_GET(info
), info
, cbl
);
438 show_list(struct admhcd
*ahcd
, char *buf
, size_t count
, struct ed
*ed
)
440 unsigned temp
, size
= count
;
445 /* dump a snapshot of the bulk or control schedule */
447 u32 info
= hc32_to_cpu(ahcd
, ed
->hwINFO
);
448 u32 headp
= hc32_to_cpu(ahcd
, ed
->hwHeadP
);
450 temp
= scnprintf(buf
, size
,
451 "ed/%p %s %cs dev%d ep%d %s%smax %d %08x%s%s %s",
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");
467 if (ed
->urb_active
) {
468 temp
= scnprintf(buf
, size
, "\nactive urb:");
472 temp
= show_urb_priv(ahcd
, buf
, size
, ed
->urb_active
);
477 if (!list_empty(&ed
->urb_pending
)) {
478 struct list_head
*entry
;
480 temp
= scnprintf(buf
, size
, "\npending urbs:");
484 list_for_each(entry
, &ed
->urb_pending
) {
486 up
= list_entry(entry
, struct urb_priv
,
489 temp
= show_urb_priv(ahcd
, buf
, size
, up
);
495 temp
= scnprintf(buf
, size
, "\n");
506 show_async(struct class_device
*class_dev
, char *buf
)
514 bus
= class_get_devdata(class_dev
);
515 hcd
= bus_to_hcd(bus
);
516 ahcd
= hcd_to_admhcd(hcd
);
518 /* display control and bulk lists together, for simplicity */
519 spin_lock_irqsave(&ahcd
->lock
, flags
);
520 temp
= show_list(ahcd
, buf
, PAGE_SIZE
, ahcd
->ed_head
);
521 spin_unlock_irqrestore(&ahcd
->lock
, flags
);
525 static CLASS_DEVICE_ATTR(async
, S_IRUGO
, show_async
, NULL
);
528 show_registers(struct class_device
*class_dev
, char *buf
)
533 struct admhcd_regs __iomem
*regs
;
539 bus
= class_get_devdata(class_dev
);
540 hcd
= bus_to_hcd(bus
);
541 ahcd
= hcd_to_admhcd(hcd
);
546 spin_lock_irqsave(&ahcd
->lock
, flags
);
548 /* dump driver info, then registers in spec order */
550 admhc_dbg_sw(ahcd
, &next
, &size
,
551 "bus %s, device %s\n"
553 "%s version " DRIVER_VERSION
"\n",
554 hcd
->self
.controller
->bus
->name
,
555 hcd
->self
.controller
->bus_id
,
559 if (bus
->controller
->power
.power_state
.event
) {
560 size
-= scnprintf(next
, size
,
561 "SUSPENDED (no register access)\n");
565 admhc_dump_status(ahcd
, &next
, &size
);
567 /* other registers mostly affect frame timings */
568 rdata
= admhc_readl(ahcd
, ®s
->fminterval
);
569 temp
= scnprintf(next
, size
,
570 "fmintvl 0x%08x %sFSLDP=0x%04x FI=0x%04x\n",
571 rdata
, (rdata
& ADMHC_SFI_FIT
) ? "FIT " : "",
572 (rdata
>> ADMHC_SFI_FSLDP_SHIFT
) & ADMHC_SFI_FSLDP_MASK
,
573 rdata
& ADMHC_SFI_FI_MASK
);
577 rdata
= admhc_readl(ahcd
, ®s
->fmnumber
);
578 temp
= scnprintf(next
, size
, "fmnumber 0x%08x %sFR=0x%04x FN=%04x\n",
579 rdata
, (rdata
& ADMHC_SFN_FRT
) ? "FRT " : "",
580 (rdata
>> ADMHC_SFN_FR_SHIFT
) & ADMHC_SFN_FR_MASK
,
581 rdata
& ADMHC_SFN_FN_MASK
);
585 /* TODO: use predefined bitmask */
586 rdata
= admhc_readl(ahcd
, ®s
->lsthresh
);
587 temp
= scnprintf(next
, size
, "lsthresh 0x%04x\n",
592 temp
= scnprintf(next
, size
, "hub poll timer: %s\n",
593 admhcd_to_hcd(ahcd
)->poll_rh
? "ON" : "OFF");
598 admhc_dump_roothub(ahcd
, 1, &next
, &size
);
601 spin_unlock_irqrestore(&ahcd
->lock
, flags
);
602 return PAGE_SIZE
- size
;
604 static CLASS_DEVICE_ATTR(registers
, S_IRUGO
, show_registers
, NULL
);
607 static inline void create_debug_files (struct admhcd
*ahcd
)
609 struct class_device
*cldev
= admhcd_to_hcd(ahcd
)->self
.class_dev
;
612 retval
= class_device_create_file(cldev
, &class_device_attr_async
);
613 retval
= class_device_create_file(cldev
, &class_device_attr_registers
);
614 admhc_dbg(ahcd
, "created debug files\n");
617 static inline void remove_debug_files (struct admhcd
*ahcd
)
619 struct class_device
*cldev
= admhcd_to_hcd(ahcd
)->self
.class_dev
;
621 class_device_remove_file(cldev
, &class_device_attr_async
);
622 class_device_remove_file(cldev
, &class_device_attr_registers
);
627 /*-------------------------------------------------------------------------*/