2 * Copyright (c) 2001-2002 by David Brownell
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* this file is part of ehci-hcd.c */
21 #define ehci_dbg(ehci, fmt, args...) \
22 dev_dbg (ehci_to_hcd(ehci)->self.controller , fmt , ## args )
23 #define ehci_err(ehci, fmt, args...) \
24 dev_err (ehci_to_hcd(ehci)->self.controller , fmt , ## args )
25 #define ehci_info(ehci, fmt, args...) \
26 dev_info (ehci_to_hcd(ehci)->self.controller , fmt , ## args )
27 #define ehci_warn(ehci, fmt, args...) \
28 dev_warn (ehci_to_hcd(ehci)->self.controller , fmt , ## args )
32 # define ehci_vdbg ehci_dbg
34 # define vdbg(fmt,args...) do { } while (0)
35 # define ehci_vdbg(ehci, fmt, args...) do { } while (0)
40 /* check the values in the HCSPARAMS register
41 * (host controller _Structural_ parameters)
42 * see EHCI spec, Table 2-4 for each value
44 static void dbg_hcs_params (struct ehci_hcd
*ehci
, char *label
)
46 u32 params
= ehci_readl(ehci
, &ehci
->caps
->hcs_params
);
49 "%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n",
51 HCS_DEBUG_PORT (params
),
52 HCS_INDICATOR (params
) ? " ind" : "",
55 HCS_PORTROUTED (params
) ? "" : " ordered",
56 HCS_PPC (params
) ? "" : " !ppc",
59 /* Port routing, per EHCI 0.95 Spec, Section 2.2.5 */
60 if (HCS_PORTROUTED (params
)) {
62 char buf
[46], tmp
[7], byte
;
65 for (i
= 0; i
< HCS_N_PORTS (params
); i
++) {
66 byte
= readb (&ehci
->caps
->portroute
[(i
>>1)]);
68 ((i
& 0x1) ? ((byte
)&0xf) : ((byte
>>4)&0xf)));
71 ehci_dbg (ehci
, "%s portroute %s\n",
77 static inline void dbg_hcs_params (struct ehci_hcd
*ehci
, char *label
) {}
83 /* check the values in the HCCPARAMS register
84 * (host controller _Capability_ parameters)
85 * see EHCI Spec, Table 2-5 for each value
87 static void dbg_hcc_params (struct ehci_hcd
*ehci
, char *label
)
89 u32 params
= ehci_readl(ehci
, &ehci
->caps
->hcc_params
);
91 if (HCC_ISOC_CACHE (params
)) {
93 "%s hcc_params %04x caching frame %s%s%s\n",
95 HCC_PGM_FRAMELISTLEN(params
) ? "256/512/1024" : "1024",
96 HCC_CANPARK(params
) ? " park" : "",
97 HCC_64BIT_ADDR(params
) ? " 64 bit addr" : "");
100 "%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n",
103 HCC_ISOC_THRES(params
),
104 HCC_PGM_FRAMELISTLEN(params
) ? "256/512/1024" : "1024",
105 HCC_CANPARK(params
) ? " park" : "",
106 HCC_64BIT_ADDR(params
) ? " 64 bit addr" : "",
107 HCC_LPM(params
) ? " LPM" : "",
108 HCC_PER_PORT_CHANGE_EVENT(params
) ? " ppce" : "",
109 HCC_HW_PREFETCH(params
) ? " hw prefetch" : "",
110 HCC_32FRAME_PERIODIC_LIST(params
) ?
111 " 32 peridic list" : "");
116 static inline void dbg_hcc_params (struct ehci_hcd
*ehci
, char *label
) {}
122 static void __maybe_unused
123 dbg_qtd (const char *label
, struct ehci_hcd
*ehci
, struct ehci_qtd
*qtd
)
125 ehci_dbg(ehci
, "%s td %p n%08x %08x t%08x p0=%08x\n", label
, qtd
,
126 hc32_to_cpup(ehci
, &qtd
->hw_next
),
127 hc32_to_cpup(ehci
, &qtd
->hw_alt_next
),
128 hc32_to_cpup(ehci
, &qtd
->hw_token
),
129 hc32_to_cpup(ehci
, &qtd
->hw_buf
[0]));
131 ehci_dbg(ehci
, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
132 hc32_to_cpup(ehci
, &qtd
->hw_buf
[1]),
133 hc32_to_cpup(ehci
, &qtd
->hw_buf
[2]),
134 hc32_to_cpup(ehci
, &qtd
->hw_buf
[3]),
135 hc32_to_cpup(ehci
, &qtd
->hw_buf
[4]));
138 static void __maybe_unused
139 dbg_qh (const char *label
, struct ehci_hcd
*ehci
, struct ehci_qh
*qh
)
141 struct ehci_qh_hw
*hw
= qh
->hw
;
143 ehci_dbg (ehci
, "%s qh %p n%08x info %x %x qtd %x\n", label
,
144 qh
, hw
->hw_next
, hw
->hw_info1
, hw
->hw_info2
, hw
->hw_current
);
145 dbg_qtd("overlay", ehci
, (struct ehci_qtd
*) &hw
->hw_qtd_next
);
148 static void __maybe_unused
149 dbg_itd (const char *label
, struct ehci_hcd
*ehci
, struct ehci_itd
*itd
)
151 ehci_dbg (ehci
, "%s [%d] itd %p, next %08x, urb %p\n",
152 label
, itd
->frame
, itd
, hc32_to_cpu(ehci
, itd
->hw_next
),
155 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
156 hc32_to_cpu(ehci
, itd
->hw_transaction
[0]),
157 hc32_to_cpu(ehci
, itd
->hw_transaction
[1]),
158 hc32_to_cpu(ehci
, itd
->hw_transaction
[2]),
159 hc32_to_cpu(ehci
, itd
->hw_transaction
[3]),
160 hc32_to_cpu(ehci
, itd
->hw_transaction
[4]),
161 hc32_to_cpu(ehci
, itd
->hw_transaction
[5]),
162 hc32_to_cpu(ehci
, itd
->hw_transaction
[6]),
163 hc32_to_cpu(ehci
, itd
->hw_transaction
[7]));
165 " buf: %08x %08x %08x %08x %08x %08x %08x\n",
166 hc32_to_cpu(ehci
, itd
->hw_bufp
[0]),
167 hc32_to_cpu(ehci
, itd
->hw_bufp
[1]),
168 hc32_to_cpu(ehci
, itd
->hw_bufp
[2]),
169 hc32_to_cpu(ehci
, itd
->hw_bufp
[3]),
170 hc32_to_cpu(ehci
, itd
->hw_bufp
[4]),
171 hc32_to_cpu(ehci
, itd
->hw_bufp
[5]),
172 hc32_to_cpu(ehci
, itd
->hw_bufp
[6]));
173 ehci_dbg (ehci
, " index: %d %d %d %d %d %d %d %d\n",
174 itd
->index
[0], itd
->index
[1], itd
->index
[2],
175 itd
->index
[3], itd
->index
[4], itd
->index
[5],
176 itd
->index
[6], itd
->index
[7]);
179 static void __maybe_unused
180 dbg_sitd (const char *label
, struct ehci_hcd
*ehci
, struct ehci_sitd
*sitd
)
182 ehci_dbg (ehci
, "%s [%d] sitd %p, next %08x, urb %p\n",
183 label
, sitd
->frame
, sitd
, hc32_to_cpu(ehci
, sitd
->hw_next
),
186 " addr %08x sched %04x result %08x buf %08x %08x\n",
187 hc32_to_cpu(ehci
, sitd
->hw_fullspeed_ep
),
188 hc32_to_cpu(ehci
, sitd
->hw_uframe
),
189 hc32_to_cpu(ehci
, sitd
->hw_results
),
190 hc32_to_cpu(ehci
, sitd
->hw_buf
[0]),
191 hc32_to_cpu(ehci
, sitd
->hw_buf
[1]));
194 static int __maybe_unused
195 dbg_status_buf (char *buf
, unsigned len
, const char *label
, u32 status
)
197 return scnprintf (buf
, len
,
198 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s%s",
199 label
, label
[0] ? " " : "", status
,
200 (status
& STS_PPCE_MASK
) ? " PPCE" : "",
201 (status
& STS_ASS
) ? " Async" : "",
202 (status
& STS_PSS
) ? " Periodic" : "",
203 (status
& STS_RECL
) ? " Recl" : "",
204 (status
& STS_HALT
) ? " Halt" : "",
205 (status
& STS_IAA
) ? " IAA" : "",
206 (status
& STS_FATAL
) ? " FATAL" : "",
207 (status
& STS_FLR
) ? " FLR" : "",
208 (status
& STS_PCD
) ? " PCD" : "",
209 (status
& STS_ERR
) ? " ERR" : "",
210 (status
& STS_INT
) ? " INT" : ""
214 static int __maybe_unused
215 dbg_intr_buf (char *buf
, unsigned len
, const char *label
, u32 enable
)
217 return scnprintf (buf
, len
,
218 "%s%sintrenable %02x%s%s%s%s%s%s%s",
219 label
, label
[0] ? " " : "", enable
,
220 (enable
& STS_PPCE_MASK
) ? " PPCE" : "",
221 (enable
& STS_IAA
) ? " IAA" : "",
222 (enable
& STS_FATAL
) ? " FATAL" : "",
223 (enable
& STS_FLR
) ? " FLR" : "",
224 (enable
& STS_PCD
) ? " PCD" : "",
225 (enable
& STS_ERR
) ? " ERR" : "",
226 (enable
& STS_INT
) ? " INT" : ""
230 static const char *const fls_strings
[] =
231 { "1024", "512", "256", "??" };
234 dbg_command_buf (char *buf
, unsigned len
, const char *label
, u32 command
)
236 return scnprintf (buf
, len
,
237 "%s%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s "
239 label
, label
[0] ? " " : "", command
,
240 (command
& CMD_HIRD
) ? " HIRD" : "",
241 (command
& CMD_PPCEE
) ? " PPCEE" : "",
242 (command
& CMD_FSP
) ? " FSP" : "",
243 (command
& CMD_ASPE
) ? " ASPE" : "",
244 (command
& CMD_PSPE
) ? " PSPE" : "",
245 (command
& CMD_PARK
) ? " park" : "(park)",
246 CMD_PARK_CNT (command
),
247 (command
>> 16) & 0x3f,
248 (command
& CMD_LRESET
) ? " LReset" : "",
249 (command
& CMD_IAAD
) ? " IAAD" : "",
250 (command
& CMD_ASE
) ? " Async" : "",
251 (command
& CMD_PSE
) ? " Periodic" : "",
252 fls_strings
[(command
>> 2) & 0x3],
253 (command
& CMD_RESET
) ? " Reset" : "",
254 (command
& CMD_RUN
) ? "RUN" : "HALT"
259 dbg_port_buf (char *buf
, unsigned len
, const char *label
, int port
, u32 status
)
263 /* signaling state */
264 switch (status
& (3 << 10)) {
265 case 0 << 10: sig
= "se0"; break;
266 case 1 << 10: sig
= "k"; break; /* low speed */
267 case 2 << 10: sig
= "j"; break;
268 default: sig
= "?"; break;
271 return scnprintf (buf
, len
,
272 "%s%sport:%d status %06x %d %s%s%s%s%s%s "
273 "sig=%s%s%s%s%s%s%s%s%s%s%s",
274 label
, label
[0] ? " " : "", port
, status
,
275 status
>>25,/*device address */
276 (status
& PORT_SSTS
)>>23 == PORTSC_SUSPEND_STS_ACK
?
278 (status
& PORT_SSTS
)>>23 == PORTSC_SUSPEND_STS_NYET
?
280 (status
& PORT_SSTS
)>>23 == PORTSC_SUSPEND_STS_STALL
?
282 (status
& PORT_SSTS
)>>23 == PORTSC_SUSPEND_STS_ERR
?
284 (status
& PORT_POWER
) ? " POWER" : "",
285 (status
& PORT_OWNER
) ? " OWNER" : "",
287 (status
& PORT_LPM
) ? " LPM" : "",
288 (status
& PORT_RESET
) ? " RESET" : "",
289 (status
& PORT_SUSPEND
) ? " SUSPEND" : "",
290 (status
& PORT_RESUME
) ? " RESUME" : "",
291 (status
& PORT_OCC
) ? " OCC" : "",
292 (status
& PORT_OC
) ? " OC" : "",
293 (status
& PORT_PEC
) ? " PEC" : "",
294 (status
& PORT_PE
) ? " PE" : "",
295 (status
& PORT_CSC
) ? " CSC" : "",
296 (status
& PORT_CONNECT
) ? " CONNECT" : "");
300 static inline void __maybe_unused
301 dbg_qh (char *label
, struct ehci_hcd
*ehci
, struct ehci_qh
*qh
)
304 static inline int __maybe_unused
305 dbg_status_buf (char *buf
, unsigned len
, const char *label
, u32 status
)
308 static inline int __maybe_unused
309 dbg_command_buf (char *buf
, unsigned len
, const char *label
, u32 command
)
312 static inline int __maybe_unused
313 dbg_intr_buf (char *buf
, unsigned len
, const char *label
, u32 enable
)
316 static inline int __maybe_unused
317 dbg_port_buf (char *buf
, unsigned len
, const char *label
, int port
, u32 status
)
322 /* functions have the "wrong" filename when they're output... */
323 #define dbg_status(ehci, label, status) { \
325 dbg_status_buf (_buf, sizeof _buf, label, status); \
326 ehci_dbg (ehci, "%s\n", _buf); \
329 #define dbg_cmd(ehci, label, command) { \
331 dbg_command_buf (_buf, sizeof _buf, label, command); \
332 ehci_dbg (ehci, "%s\n", _buf); \
335 #define dbg_port(ehci, label, port, status) { \
337 dbg_port_buf (_buf, sizeof _buf, label, port, status); \
338 ehci_dbg (ehci, "%s\n", _buf); \
341 /*-------------------------------------------------------------------------*/
343 #ifdef STUB_DEBUG_FILES
345 static inline void create_debug_files (struct ehci_hcd
*bus
) { }
346 static inline void remove_debug_files (struct ehci_hcd
*bus
) { }
350 /* troubleshooting help: expose state in debugfs */
352 static int debug_async_open(struct inode
*, struct file
*);
353 static int debug_periodic_open(struct inode
*, struct file
*);
354 static int debug_registers_open(struct inode
*, struct file
*);
355 static int debug_async_open(struct inode
*, struct file
*);
356 static int debug_lpm_open(struct inode
*, struct file
*);
357 static ssize_t
debug_lpm_read(struct file
*file
, char __user
*user_buf
,
358 size_t count
, loff_t
*ppos
);
359 static ssize_t
debug_lpm_write(struct file
*file
, const char __user
*buffer
,
360 size_t count
, loff_t
*ppos
);
361 static int debug_lpm_close(struct inode
*inode
, struct file
*file
);
363 static ssize_t
debug_output(struct file
*, char __user
*, size_t, loff_t
*);
364 static int debug_close(struct inode
*, struct file
*);
366 static const struct file_operations debug_async_fops
= {
367 .owner
= THIS_MODULE
,
368 .open
= debug_async_open
,
369 .read
= debug_output
,
370 .release
= debug_close
,
372 static const struct file_operations debug_periodic_fops
= {
373 .owner
= THIS_MODULE
,
374 .open
= debug_periodic_open
,
375 .read
= debug_output
,
376 .release
= debug_close
,
378 static const struct file_operations debug_registers_fops
= {
379 .owner
= THIS_MODULE
,
380 .open
= debug_registers_open
,
381 .read
= debug_output
,
382 .release
= debug_close
,
384 static const struct file_operations debug_lpm_fops
= {
385 .owner
= THIS_MODULE
,
386 .open
= debug_lpm_open
,
387 .read
= debug_lpm_read
,
388 .write
= debug_lpm_write
,
389 .release
= debug_lpm_close
,
392 static struct dentry
*ehci_debug_root
;
394 struct debug_buffer
{
395 ssize_t (*fill_func
)(struct debug_buffer
*); /* fill method */
397 struct mutex mutex
; /* protect filling of buffer */
398 size_t count
; /* number of characters filled into buffer */
403 #define speed_char(info1) ({ char tmp; \
404 switch (info1 & (3 << 12)) { \
405 case 0 << 12: tmp = 'f'; break; \
406 case 1 << 12: tmp = 'l'; break; \
407 case 2 << 12: tmp = 'h'; break; \
408 default: tmp = '?'; break; \
411 static inline char token_mark(struct ehci_hcd
*ehci
, __hc32 token
)
413 __u32 v
= hc32_to_cpu(ehci
, token
);
415 if (v
& QTD_STS_ACTIVE
)
417 if (v
& QTD_STS_HALT
)
419 if (!IS_SHORT_READ (v
))
421 /* tries to advance through hw_alt_next */
425 static void qh_lines (
426 struct ehci_hcd
*ehci
,
434 struct list_head
*entry
;
437 unsigned size
= *sizep
;
440 __le32 list_end
= EHCI_LIST_END(ehci
);
441 struct ehci_qh_hw
*hw
= qh
->hw
;
443 if (hw
->hw_qtd_next
== list_end
) /* NEC does this */
446 mark
= token_mark(ehci
, hw
->hw_token
);
447 if (mark
== '/') { /* qh_alt_next controls qh advance? */
448 if ((hw
->hw_alt_next
& QTD_MASK(ehci
))
449 == ehci
->async
->hw
->hw_alt_next
)
450 mark
= '#'; /* blocked */
451 else if (hw
->hw_alt_next
== list_end
)
452 mark
= '.'; /* use hw_qtd_next */
453 /* else alt_next points to some other qtd */
455 scratch
= hc32_to_cpup(ehci
, &hw
->hw_info1
);
456 hw_curr
= (mark
== '*') ? hc32_to_cpup(ehci
, &hw
->hw_current
) : 0;
457 temp
= scnprintf (next
, size
,
458 "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)",
459 qh
, scratch
& 0x007f,
460 speed_char (scratch
),
461 (scratch
>> 8) & 0x000f,
462 scratch
, hc32_to_cpup(ehci
, &hw
->hw_info2
),
463 hc32_to_cpup(ehci
, &hw
->hw_token
), mark
,
464 (cpu_to_hc32(ehci
, QTD_TOGGLE
) & hw
->hw_token
)
466 (hc32_to_cpup(ehci
, &hw
->hw_alt_next
) >> 1) & 0x0f);
470 /* hc may be modifying the list as we read it ... */
471 list_for_each (entry
, &qh
->qtd_list
) {
472 td
= list_entry (entry
, struct ehci_qtd
, qtd_list
);
473 scratch
= hc32_to_cpup(ehci
, &td
->hw_token
);
475 if (hw_curr
== td
->qtd_dma
)
477 else if (hw
->hw_qtd_next
== cpu_to_hc32(ehci
, td
->qtd_dma
))
479 else if (QTD_LENGTH (scratch
)) {
480 if (td
->hw_alt_next
== ehci
->async
->hw
->hw_alt_next
)
482 else if (td
->hw_alt_next
!= list_end
)
485 temp
= snprintf (next
, size
,
486 "\n\t%p%c%s len=%d %08x urb %p",
487 td
, mark
, ({ char *tmp
;
488 switch ((scratch
>>8)&0x03) {
489 case 0: tmp
= "out"; break;
490 case 1: tmp
= "in"; break;
491 case 2: tmp
= "setup"; break;
492 default: tmp
= "?"; break;
494 (scratch
>> 16) & 0x7fff,
505 temp
= snprintf (next
, size
, "\n");
516 static ssize_t
fill_async_buffer(struct debug_buffer
*buf
)
519 struct ehci_hcd
*ehci
;
525 hcd
= bus_to_hcd(buf
->bus
);
526 ehci
= hcd_to_ehci (hcd
);
527 next
= buf
->output_buf
;
528 size
= buf
->alloc_size
;
532 /* dumps a snapshot of the async schedule.
533 * usually empty except for long-term bulk reads, or head.
534 * one QH per line, and TDs we know about
536 spin_lock_irqsave (&ehci
->lock
, flags
);
537 for (qh
= ehci
->async
->qh_next
.qh
; size
> 0 && qh
; qh
= qh
->qh_next
.qh
)
538 qh_lines (ehci
, qh
, &next
, &size
);
539 if (ehci
->reclaim
&& size
> 0) {
540 temp
= scnprintf (next
, size
, "\nreclaim =\n");
544 for (qh
= ehci
->reclaim
; size
> 0 && qh
; qh
= qh
->reclaim
)
545 qh_lines (ehci
, qh
, &next
, &size
);
547 spin_unlock_irqrestore (&ehci
->lock
, flags
);
549 return strlen(buf
->output_buf
);
552 #define DBG_SCHED_LIMIT 64
553 static ssize_t
fill_periodic_buffer(struct debug_buffer
*buf
)
556 struct ehci_hcd
*ehci
;
558 union ehci_shadow p
, *seen
;
559 unsigned temp
, size
, seen_count
;
564 if (!(seen
= kmalloc (DBG_SCHED_LIMIT
* sizeof *seen
, GFP_ATOMIC
)))
568 hcd
= bus_to_hcd(buf
->bus
);
569 ehci
= hcd_to_ehci (hcd
);
570 next
= buf
->output_buf
;
571 size
= buf
->alloc_size
;
573 temp
= scnprintf (next
, size
, "size = %d\n", ehci
->periodic_size
);
577 /* dump a snapshot of the periodic schedule.
578 * iso changes, interrupt usually doesn't.
580 spin_lock_irqsave (&ehci
->lock
, flags
);
581 for (i
= 0; i
< ehci
->periodic_size
; i
++) {
582 p
= ehci
->pshadow
[i
];
585 tag
= Q_NEXT_TYPE(ehci
, ehci
->periodic
[i
]);
587 temp
= scnprintf (next
, size
, "%4d: ", i
);
592 struct ehci_qh_hw
*hw
;
594 switch (hc32_to_cpu(ehci
, tag
)) {
597 temp
= scnprintf (next
, size
, " qh%d-%04x/%p",
602 & (QH_CMASK
| QH_SMASK
),
606 /* don't repeat what follows this qh */
607 for (temp
= 0; temp
< seen_count
; temp
++) {
608 if (seen
[temp
].ptr
!= p
.ptr
)
610 if (p
.qh
->qh_next
.ptr
) {
611 temp
= scnprintf (next
, size
,
618 /* show more info the first time around */
619 if (temp
== seen_count
) {
620 u32 scratch
= hc32_to_cpup(ehci
,
622 struct ehci_qtd
*qtd
;
625 /* count tds, get ep direction */
627 list_for_each_entry (qtd
,
631 switch (0x03 & (hc32_to_cpu(
633 qtd
->hw_token
) >> 8)) {
634 case 0: type
= "out"; continue;
635 case 1: type
= "in"; continue;
639 temp
= scnprintf (next
, size
,
642 speed_char (scratch
),
644 (scratch
>> 8) & 0x000f, type
,
645 p
.qh
->usecs
, p
.qh
->c_usecs
,
647 0x7ff & (scratch
>> 16));
649 if (seen_count
< DBG_SCHED_LIMIT
)
650 seen
[seen_count
++].qh
= p
.qh
;
654 tag
= Q_NEXT_TYPE(ehci
, hw
->hw_next
);
659 temp
= scnprintf (next
, size
,
660 " fstn-%8x/%p", p
.fstn
->hw_prev
,
662 tag
= Q_NEXT_TYPE(ehci
, p
.fstn
->hw_next
);
663 p
= p
.fstn
->fstn_next
;
666 temp
= scnprintf (next
, size
,
668 tag
= Q_NEXT_TYPE(ehci
, p
.itd
->hw_next
);
672 temp
= scnprintf (next
, size
,
674 p
.sitd
->stream
->interval
,
675 hc32_to_cpup(ehci
, &p
.sitd
->hw_uframe
)
678 tag
= Q_NEXT_TYPE(ehci
, p
.sitd
->hw_next
);
679 p
= p
.sitd
->sitd_next
;
686 temp
= scnprintf (next
, size
, "\n");
690 spin_unlock_irqrestore (&ehci
->lock
, flags
);
693 return buf
->alloc_size
- size
;
695 #undef DBG_SCHED_LIMIT
697 static ssize_t
fill_registers_buffer(struct debug_buffer
*buf
)
700 struct ehci_hcd
*ehci
;
702 unsigned temp
, size
, i
;
703 char *next
, scratch
[80];
704 static char fmt
[] = "%*s\n";
705 static char label
[] = "";
707 hcd
= bus_to_hcd(buf
->bus
);
708 ehci
= hcd_to_ehci (hcd
);
709 next
= buf
->output_buf
;
710 size
= buf
->alloc_size
;
712 spin_lock_irqsave (&ehci
->lock
, flags
);
714 if (!HCD_HW_ACCESSIBLE(hcd
)) {
715 size
= scnprintf (next
, size
,
716 "bus %s, device %s\n"
718 "SUSPENDED (no register access)\n",
719 hcd
->self
.controller
->bus
->name
,
720 dev_name(hcd
->self
.controller
),
725 /* Capability Registers */
726 i
= HC_VERSION(ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
727 temp
= scnprintf (next
, size
,
728 "bus %s, device %s\n"
730 "EHCI %x.%02x, hcd state %d\n",
731 hcd
->self
.controller
->bus
->name
,
732 dev_name(hcd
->self
.controller
),
734 i
>> 8, i
& 0x0ff, hcd
->state
);
739 /* EHCI 0.96 and later may have "extended capabilities" */
740 if (hcd
->self
.controller
->bus
== &pci_bus_type
) {
741 struct pci_dev
*pdev
;
742 u32 offset
, cap
, cap2
;
743 unsigned count
= 256/4;
745 pdev
= to_pci_dev(ehci_to_hcd(ehci
)->self
.controller
);
746 offset
= HCC_EXT_CAPS(ehci_readl(ehci
,
747 &ehci
->caps
->hcc_params
));
748 while (offset
&& count
--) {
749 pci_read_config_dword (pdev
, offset
, &cap
);
750 switch (cap
& 0xff) {
752 temp
= scnprintf (next
, size
,
753 "ownership %08x%s%s\n", cap
,
754 (cap
& (1 << 24)) ? " linux" : "",
755 (cap
& (1 << 16)) ? " firmware" : "");
760 pci_read_config_dword (pdev
, offset
, &cap2
);
761 temp
= scnprintf (next
, size
,
762 "SMI sts/enable 0x%08x\n", cap2
);
766 case 0: /* illegal reserved capability */
769 default: /* unknown */
772 temp
= (cap
>> 8) & 0xff;
777 i
= ehci_readl(ehci
, &ehci
->caps
->hcs_params
);
778 temp
= scnprintf (next
, size
, "structural params 0x%08x\n", i
);
782 i
= ehci_readl(ehci
, &ehci
->caps
->hcc_params
);
783 temp
= scnprintf (next
, size
, "capability params 0x%08x\n", i
);
787 /* Operational Registers */
788 temp
= dbg_status_buf (scratch
, sizeof scratch
, label
,
789 ehci_readl(ehci
, &ehci
->regs
->status
));
790 temp
= scnprintf (next
, size
, fmt
, temp
, scratch
);
794 temp
= dbg_command_buf (scratch
, sizeof scratch
, label
,
795 ehci_readl(ehci
, &ehci
->regs
->command
));
796 temp
= scnprintf (next
, size
, fmt
, temp
, scratch
);
800 temp
= dbg_intr_buf (scratch
, sizeof scratch
, label
,
801 ehci_readl(ehci
, &ehci
->regs
->intr_enable
));
802 temp
= scnprintf (next
, size
, fmt
, temp
, scratch
);
806 temp
= scnprintf (next
, size
, "uframe %04x\n",
807 ehci_readl(ehci
, &ehci
->regs
->frame_index
));
811 for (i
= 1; i
<= HCS_N_PORTS (ehci
->hcs_params
); i
++) {
812 temp
= dbg_port_buf (scratch
, sizeof scratch
, label
, i
,
814 &ehci
->regs
->port_status
[i
- 1]));
815 temp
= scnprintf (next
, size
, fmt
, temp
, scratch
);
818 if (i
== HCS_DEBUG_PORT(ehci
->hcs_params
) && ehci
->debug
) {
819 temp
= scnprintf (next
, size
,
820 " debug control %08x\n",
822 &ehci
->debug
->control
));
829 temp
= scnprintf(next
, size
, "reclaim qh %p\n", ehci
->reclaim
);
835 temp
= scnprintf (next
, size
,
836 "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
837 ehci
->stats
.normal
, ehci
->stats
.error
, ehci
->stats
.reclaim
,
838 ehci
->stats
.lost_iaa
);
842 temp
= scnprintf (next
, size
, "complete %ld unlink %ld\n",
843 ehci
->stats
.complete
, ehci
->stats
.unlink
);
849 spin_unlock_irqrestore (&ehci
->lock
, flags
);
851 return buf
->alloc_size
- size
;
854 static struct debug_buffer
*alloc_buffer(struct usb_bus
*bus
,
855 ssize_t (*fill_func
)(struct debug_buffer
*))
857 struct debug_buffer
*buf
;
859 buf
= kzalloc(sizeof(struct debug_buffer
), GFP_KERNEL
);
863 buf
->fill_func
= fill_func
;
864 mutex_init(&buf
->mutex
);
865 buf
->alloc_size
= PAGE_SIZE
;
871 static int fill_buffer(struct debug_buffer
*buf
)
875 if (!buf
->output_buf
)
876 buf
->output_buf
= (char *)vmalloc(buf
->alloc_size
);
878 if (!buf
->output_buf
) {
883 ret
= buf
->fill_func(buf
);
894 static ssize_t
debug_output(struct file
*file
, char __user
*user_buf
,
895 size_t len
, loff_t
*offset
)
897 struct debug_buffer
*buf
= file
->private_data
;
900 mutex_lock(&buf
->mutex
);
901 if (buf
->count
== 0) {
902 ret
= fill_buffer(buf
);
904 mutex_unlock(&buf
->mutex
);
908 mutex_unlock(&buf
->mutex
);
910 ret
= simple_read_from_buffer(user_buf
, len
, offset
,
911 buf
->output_buf
, buf
->count
);
918 static int debug_close(struct inode
*inode
, struct file
*file
)
920 struct debug_buffer
*buf
= file
->private_data
;
923 vfree(buf
->output_buf
);
929 static int debug_async_open(struct inode
*inode
, struct file
*file
)
931 file
->private_data
= alloc_buffer(inode
->i_private
, fill_async_buffer
);
933 return file
->private_data
? 0 : -ENOMEM
;
936 static int debug_periodic_open(struct inode
*inode
, struct file
*file
)
938 struct debug_buffer
*buf
;
939 buf
= alloc_buffer(inode
->i_private
, fill_periodic_buffer
);
943 buf
->alloc_size
= (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE
;
944 file
->private_data
= buf
;
948 static int debug_registers_open(struct inode
*inode
, struct file
*file
)
950 file
->private_data
= alloc_buffer(inode
->i_private
,
951 fill_registers_buffer
);
953 return file
->private_data
? 0 : -ENOMEM
;
956 static int debug_lpm_open(struct inode
*inode
, struct file
*file
)
958 file
->private_data
= inode
->i_private
;
962 static int debug_lpm_close(struct inode
*inode
, struct file
*file
)
967 static ssize_t
debug_lpm_read(struct file
*file
, char __user
*user_buf
,
968 size_t count
, loff_t
*ppos
)
970 /* TODO: show lpm stats */
974 static ssize_t
debug_lpm_write(struct file
*file
, const char __user
*user_buf
,
975 size_t count
, loff_t
*ppos
)
978 struct ehci_hcd
*ehci
;
983 u32 __iomem
*portsc
;
986 hcd
= bus_to_hcd(file
->private_data
);
987 ehci
= hcd_to_ehci(hcd
);
989 len
= min(count
, sizeof(buf
) - 1);
990 if (copy_from_user(buf
, user_buf
, len
))
993 if (len
> 0 && buf
[len
- 1] == '\n')
996 if (strncmp(buf
, "enable", 5) == 0) {
997 if (strict_strtoul(buf
+ 7, 10, &port
))
999 params
= ehci_readl(ehci
, &ehci
->caps
->hcs_params
);
1000 if (port
> HCS_N_PORTS(params
)) {
1001 ehci_dbg(ehci
, "ERR: LPM on bad port %lu\n", port
);
1004 portsc
= &ehci
->regs
->port_status
[port
-1];
1005 temp
= ehci_readl(ehci
, portsc
);
1006 if (!(temp
& PORT_DEV_ADDR
)) {
1007 ehci_dbg(ehci
, "LPM: no device attached\n");
1011 ehci_writel(ehci
, temp
, portsc
);
1012 printk(KERN_INFO
"force enable LPM for port %lu\n", port
);
1013 } else if (strncmp(buf
, "hird=", 5) == 0) {
1015 if (strict_strtoul(buf
+ 5, 16, &hird
))
1017 printk(KERN_INFO
"setting hird %s %lu\n", buf
+ 6, hird
);
1018 temp
= ehci_readl(ehci
, &ehci
->regs
->command
);
1021 ehci_writel(ehci
, temp
, &ehci
->regs
->command
);
1022 } else if (strncmp(buf
, "disable", 7) == 0) {
1023 if (strict_strtoul(buf
+ 8, 10, &port
))
1025 params
= ehci_readl(ehci
, &ehci
->caps
->hcs_params
);
1026 if (port
> HCS_N_PORTS(params
)) {
1027 ehci_dbg(ehci
, "ERR: LPM off bad port %lu\n", port
);
1030 portsc
= &ehci
->regs
->port_status
[port
-1];
1031 temp
= ehci_readl(ehci
, portsc
);
1032 if (!(temp
& PORT_DEV_ADDR
)) {
1033 ehci_dbg(ehci
, "ERR: no device attached\n");
1037 ehci_writel(ehci
, temp
, portsc
);
1038 printk(KERN_INFO
"disabled LPM for port %lu\n", port
);
1044 static inline void create_debug_files (struct ehci_hcd
*ehci
)
1046 struct usb_bus
*bus
= &ehci_to_hcd(ehci
)->self
;
1048 ehci
->debug_dir
= debugfs_create_dir(bus
->bus_name
, ehci_debug_root
);
1049 if (!ehci
->debug_dir
)
1052 if (!debugfs_create_file("async", S_IRUGO
, ehci
->debug_dir
, bus
,
1056 if (!debugfs_create_file("periodic", S_IRUGO
, ehci
->debug_dir
, bus
,
1057 &debug_periodic_fops
))
1060 if (!debugfs_create_file("registers", S_IRUGO
, ehci
->debug_dir
, bus
,
1061 &debug_registers_fops
))
1064 if (!debugfs_create_file("lpm", S_IRUGO
|S_IWUSR
, ehci
->debug_dir
, bus
,
1071 debugfs_remove_recursive(ehci
->debug_dir
);
1074 static inline void remove_debug_files (struct ehci_hcd
*ehci
)
1076 debugfs_remove_recursive(ehci
->debug_dir
);
1079 #endif /* STUB_DEBUG_FILES */