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)
40 static inline char *pipestring(int pipe)
42 return ed_typestring(usb_pipetype(pipe));
45 static inline char *td_pidstring(u32 info)
47 switch (info & TD_DP) {
58 static inline char *td_togglestring(u32 info)
60 switch (info & TD_T) {
71 /*-------------------------------------------------------------------------*/
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 "
95 usb_pipedevice (pipe),
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(ahcd, "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(ahcd, "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 /* caller MUST own hcd spinlock if verbose is set! */
322 static void __attribute__((unused))
323 admhc_dump_ed(const struct admhcd *ahcd, const char *label,
324 const struct ed *ed, int verbose)
326 u32 tmp = hc32_to_cpu(ahcd, ed->hwINFO);
328 admhc_dbg(ahcd, "%s ed %p %s type %s; next ed %08x\n",
330 ed, ed_statestring(ed->state), ed_typestring(ed->type),
331 hc32_to_cpup(ahcd, &ed->hwNextED));
333 admhc_dbg(ahcd, " info %08x MAX=%d%s%s%s%s EP=%d DEV=%d\n", tmp,
335 (tmp & ED_ISO) ? " ISO" : "",
336 (tmp & ED_SKIP) ? " SKIP" : "",
337 (tmp & ED_SPEED_FULL) ? " FULL" : " LOW",
338 (tmp & ED_INT) ? " INT" : "",
342 tmp = hc32_to_cpup(ahcd, &ed->hwHeadP);
343 admhc_dbg(ahcd, " tds: head %08x tail %08x %s%s%s\n",
345 hc32_to_cpup (ahcd, &ed->hwTailP),
346 (tmp & ED_C) ? data1 : data0,
347 (tmp & ED_H) ? " HALT" : "",
348 verbose ? " td list follows" : " (not listing)");
351 struct list_head *tmp;
353 /* use ed->td_list because HC concurrently modifies
354 * hwNextTD as it accumulates ed_donelist.
356 list_for_each(tmp, &ed->td_list) {
358 td = list_entry(tmp, struct td, td_list);
359 admhc_dump_td (ahcd, " ->", td);
364 #else /* ifdef DEBUG */
366 static inline void urb_print(struct admhcd *ahcd, struct urb * urb, char * str,
368 static inline void admhc_dump_ed(const struct admhcd *ahcd, const char *label,
369 const struct ed *ed, int verbose) {}
370 static inline void admhc_dump_td(const struct admhcd *ahcd, const char *label,
371 const struct td *td) {}
372 static inline void admhc_dump(struct admhcd *ahcd, int verbose) {}
374 #undef ADMHC_VERBOSE_DEBUG
378 /*-------------------------------------------------------------------------*/
380 #ifdef STUB_DEBUG_FILES
382 static inline void create_debug_files(struct admhcd *bus) { }
383 static inline void remove_debug_files(struct admhcd *bus) { }
388 show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed)
390 unsigned temp, size = count;
395 /* dump a snapshot of the bulk or control schedule */
397 u32 info = hc32_to_cpu(ahcd, ed->hwINFO);
398 u32 headp = hc32_to_cpu(ahcd, ed->hwHeadP);
399 u32 tailp = hc32_to_cpu(ahcd, ed->hwTailP);
400 struct list_head *entry;
403 temp = scnprintf(buf, size,
404 "ed/%p %s %s %cs dev%d ep%d %s%smax %d %08x%s%s %s"
407 ed_statestring(ed->state),
408 ed_typestring (ed->type),
409 (info & ED_SPEED_FULL) ? 'f' : 'l',
411 (info >> ED_EN_SHIFT) & ED_EN_MASK,
412 (info & ED_INT) ? "INT " : "",
413 (info & ED_ISO) ? "ISO " : "",
414 (info >> ED_MPS_SHIFT) & ED_MPS_MASK ,
416 (info & ED_SKIP) ? " S" : "",
417 (headp & ED_H) ? " H" : "",
418 (headp & ED_C) ? data1 : data0,
419 headp & ED_MASK,tailp);
423 list_for_each(entry, &ed->td_list) {
426 td = list_entry(entry, struct td, td_list);
427 info = hc32_to_cpup (ahcd, &td->hwINFO);
428 dbp = hc32_to_cpup (ahcd, &td->hwDBP);
429 cbl = hc32_to_cpup (ahcd, &td->hwCBL);
431 temp = scnprintf(buf, size,
432 "\n\ttd/%p %s %d %s%scc=%x urb %p (%08x,%08x)",
436 (info & TD_OWN) ? "" : "DONE ",
437 (cbl & TD_IE) ? "IE " : "",
438 TD_CC_GET (info), td->urb, info, cbl);
443 temp = scnprintf(buf, size, "\n");
453 show_async(struct class_device *class_dev, char *buf)
461 bus = class_get_devdata(class_dev);
462 hcd = bus_to_hcd(bus);
463 ahcd = hcd_to_admhcd(hcd);
465 /* display control and bulk lists together, for simplicity */
466 spin_lock_irqsave(&ahcd->lock, flags);
467 temp = show_list(ahcd, buf, PAGE_SIZE, ahcd->ed_head);
468 spin_unlock_irqrestore(&ahcd->lock, flags);
472 static CLASS_DEVICE_ATTR(async, S_IRUGO, show_async, NULL);
475 #define DBG_SCHED_LIMIT 64
478 show_periodic(struct class_device *class_dev, char *buf)
483 struct ed **seen, *ed;
485 unsigned temp, size, seen_count;
489 if (!(seen = kmalloc(DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC)))
493 bus = class_get_devdata(class_dev);
494 hcd = bus_to_hcd(bus);
495 ahcd = hcd_to_admhcd(hcd);
499 temp = scnprintf(next, size, "size = %d\n", NUM_INTS);
503 /* dump a snapshot of the periodic schedule (and load) */
504 spin_lock_irqsave(&ahcd->lock, flags);
505 for (i = 0; i < NUM_INTS; i++) {
506 if (!(ed = ahcd->periodic [i]))
509 temp = scnprintf(next, size, "%2d [%3d]:", i, ahcd->load [i]);
514 temp = scnprintf(next, size, " ed%d/%p",
518 for (temp = 0; temp < seen_count; temp++) {
519 if (seen [temp] == ed)
523 /* show more info the first time around */
524 if (temp == seen_count) {
525 u32 info = hc32_to_cpu (ahcd, ed->hwINFO);
526 struct list_head *entry;
529 /* qlen measured here in TDs, not urbs */
530 list_for_each (entry, &ed->td_list)
532 temp = scnprintf(next, size,
533 " (%cs dev%d ep%d%s qlen %u"
535 (info & ED_SPEED_FULL) ? 'f' : 'l',
538 (info & ED_ISO) ? "iso" : "int",
542 (info & ED_SKIP) ? " K" : "",
544 cpu_to_hc32(ahcd, ED_H)) ?
549 if (seen_count < DBG_SCHED_LIMIT)
550 seen [seen_count++] = ed;
555 /* we've seen it and what's after */
562 temp = scnprintf(next, size, "\n");
566 spin_unlock_irqrestore(&ahcd->lock, flags);
569 return PAGE_SIZE - size;
571 static CLASS_DEVICE_ATTR(periodic, S_IRUGO, show_periodic, NULL);
574 #undef DBG_SCHED_LIMIT
577 show_registers(struct class_device *class_dev, char *buf)
582 struct admhcd_regs __iomem *regs;
588 bus = class_get_devdata(class_dev);
589 hcd = bus_to_hcd(bus);
590 ahcd = hcd_to_admhcd(hcd);
595 spin_lock_irqsave(&ahcd->lock, flags);
597 /* dump driver info, then registers in spec order */
599 admhc_dbg_sw(ahcd, &next, &size,
600 "bus %s, device %s\n"
602 "%s version " DRIVER_VERSION "\n",
603 hcd->self.controller->bus->name,
604 hcd->self.controller->bus_id,
608 if (bus->controller->power.power_state.event) {
609 size -= scnprintf(next, size,
610 "SUSPENDED (no register access)\n");
614 admhc_dump_status(ahcd, &next, &size);
616 /* other registers mostly affect frame timings */
617 rdata = admhc_readl(ahcd, ®s->fminterval);
618 temp = scnprintf(next, size,
619 "fmintvl 0x%08x %sFSLDP=0x%04x FI=0x%04x\n",
620 rdata, (rdata & ADMHC_SFI_FIT) ? "FIT " : "",
621 (rdata >> ADMHC_SFI_FSLDP_SHIFT) & ADMHC_SFI_FSLDP_MASK,
622 rdata & ADMHC_SFI_FI_MASK);
626 rdata = admhc_readl(ahcd, ®s->fmnumber);
627 temp = scnprintf(next, size, "fmnumber 0x%08x %sFR=0x%04x FN=%04x\n",
628 rdata, (rdata & ADMHC_SFN_FRT) ? "FRT " : "",
629 (rdata >> ADMHC_SFN_FR_SHIFT) & ADMHC_SFN_FR_MASK,
630 rdata & ADMHC_SFN_FN_MASK);
634 /* TODO: use predefined bitmask */
635 rdata = admhc_readl(ahcd, ®s->lsthresh);
636 temp = scnprintf(next, size, "lsthresh 0x%04x\n",
641 temp = scnprintf(next, size, "hub poll timer: %s\n",
642 admhcd_to_hcd(ahcd)->poll_rh ? "ON" : "OFF");
647 admhc_dump_roothub(ahcd, 1, &next, &size);
650 spin_unlock_irqrestore(&ahcd->lock, flags);
651 return PAGE_SIZE - size;
653 static CLASS_DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
656 static inline void create_debug_files (struct admhcd *ahcd)
658 struct class_device *cldev = admhcd_to_hcd(ahcd)->self.class_dev;
661 retval = class_device_create_file(cldev, &class_device_attr_async);
662 retval = class_device_create_file(cldev, &class_device_attr_periodic);
663 retval = class_device_create_file(cldev, &class_device_attr_registers);
664 admhc_dbg(ahcd, "created debug files\n");
667 static inline void remove_debug_files (struct admhcd *ahcd)
669 struct class_device *cldev = admhcd_to_hcd(ahcd)->self.class_dev;
671 class_device_remove_file(cldev, &class_device_attr_async);
672 class_device_remove_file(cldev, &class_device_attr_periodic);
673 class_device_remove_file(cldev, &class_device_attr_registers);
678 /*-------------------------------------------------------------------------*/