1/* 2 * Copyright (c) 2001-2002 by David Brownell 3 * 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. 8 * 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 12 * for more details. 13 * 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. 17 */ 18 19/* this file is part of ehci-hcd.c */ 20 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 ) 29 30#ifdef VERBOSE_DEBUG 31# define vdbg dbg 32# define ehci_vdbg ehci_dbg 33#else 34# define vdbg(fmt,args...) do { } while (0) 35# define ehci_vdbg(ehci, fmt, args...) do { } while (0) 36#endif 37 38#ifdef DEBUG 39 40/* check the values in the HCSPARAMS register 41 * (host controller _Structural_ parameters) 42 * see EHCI spec, Table 2-4 for each value 43 */ 44static void dbg_hcs_params (struct ehci_hcd *ehci, char *label) 45{ 46 u32 params = ehci_readl(ehci, &ehci->caps->hcs_params); 47 48 ehci_dbg (ehci, 49 "%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n", 50 label, params, 51 HCS_DEBUG_PORT (params), 52 HCS_INDICATOR (params) ? " ind" : "", 53 HCS_N_CC (params), 54 HCS_N_PCC (params), 55 HCS_PORTROUTED (params) ? "" : " ordered", 56 HCS_PPC (params) ? "" : " !ppc", 57 HCS_N_PORTS (params) 58 ); 59 /* Port routing, per EHCI 0.95 Spec, Section 2.2.5 */ 60 if (HCS_PORTROUTED (params)) { 61 int i; 62 char buf [46], tmp [7], byte; 63 64 buf[0] = 0; 65 for (i = 0; i < HCS_N_PORTS (params); i++) { 66 byte = readb (&ehci->caps->portroute[(i>>1)]); 67 sprintf(tmp, "%d ", 68 ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf))); 69 strcat(buf, tmp); 70 } 71 ehci_dbg (ehci, "%s portroute %s\n", 72 label, buf); 73 } 74} 75#else 76 77static inline void dbg_hcs_params (struct ehci_hcd *ehci, char *label) {} 78 79#endif 80 81#ifdef DEBUG 82 83/* check the values in the HCCPARAMS register 84 * (host controller _Capability_ parameters) 85 * see EHCI Spec, Table 2-5 for each value 86 * */ 87static void dbg_hcc_params (struct ehci_hcd *ehci, char *label) 88{ 89 u32 params = ehci_readl(ehci, &ehci->caps->hcc_params); 90 91 if (HCC_ISOC_CACHE (params)) { 92 ehci_dbg (ehci, 93 "%s hcc_params %04x caching frame %s%s%s\n", 94 label, params, 95 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", 96 HCC_CANPARK(params) ? " park" : "", 97 HCC_64BIT_ADDR(params) ? " 64 bit addr" : ""); 98 } else { 99 ehci_dbg (ehci, 100 "%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n", 101 label, 102 params, 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" : ""); 112 } 113} 114#else 115 116static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {} 117 118#endif 119 120#ifdef DEBUG 121 122static void __maybe_unused 123dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd) 124{ 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])); 130 if (qtd->hw_buf [1]) 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])); 136} 137 138static void __maybe_unused 139dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) 140{ 141 struct ehci_qh_hw *hw = qh->hw; 142 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); 146} 147 148static void __maybe_unused 149dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd) 150{ 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), 153 itd->urb); 154 ehci_dbg (ehci, 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])); 164 ehci_dbg (ehci, 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]); 177} 178 179static void __maybe_unused 180dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd) 181{ 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), 184 sitd->urb); 185 ehci_dbg (ehci, 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])); 192} 193 194static int __maybe_unused 195dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) 196{ 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" : "" 211 ); 212} 213 214static int __maybe_unused 215dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable) 216{ 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" : "" 227 ); 228} 229 230static const char *const fls_strings [] = 231 { "1024", "512", "256", "??" }; 232 233static int 234dbg_command_buf (char *buf, unsigned len, const char *label, u32 command) 235{ 236 return scnprintf (buf, len, 237 "%s%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s " 238 "period=%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" 255 ); 256} 257 258static int 259dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status) 260{ 261 char *sig; 262 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; 269 } 270 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 ? 277 " ACK" : "", 278 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_NYET ? 279 " NYET" : "", 280 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_STALL ? 281 " STALL" : "", 282 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ERR ? 283 " ERR" : "", 284 (status & PORT_POWER) ? " POWER" : "", 285 (status & PORT_OWNER) ? " OWNER" : "", 286 sig, 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" : ""); 297} 298 299#else 300static inline void __maybe_unused 301dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) 302{} 303 304static inline int __maybe_unused 305dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) 306{ return 0; } 307 308static inline int __maybe_unused 309dbg_command_buf (char *buf, unsigned len, const char *label, u32 command) 310{ return 0; } 311 312static inline int __maybe_unused 313dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable) 314{ return 0; } 315 316static inline int __maybe_unused 317dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status) 318{ return 0; } 319 320#endif /* DEBUG */ 321 322/* functions have the "wrong" filename when they're output... */ 323#define dbg_status(ehci, label, status) { \ 324 char _buf [80]; \ 325 dbg_status_buf (_buf, sizeof _buf, label, status); \ 326 ehci_dbg (ehci, "%s\n", _buf); \ 327} 328 329#define dbg_cmd(ehci, label, command) { \ 330 char _buf [80]; \ 331 dbg_command_buf (_buf, sizeof _buf, label, command); \ 332 ehci_dbg (ehci, "%s\n", _buf); \ 333} 334 335#define dbg_port(ehci, label, port, status) { \ 336 char _buf [80]; \ 337 dbg_port_buf (_buf, sizeof _buf, label, port, status); \ 338 ehci_dbg (ehci, "%s\n", _buf); \ 339} 340 341/*-------------------------------------------------------------------------*/ 342 343#ifdef STUB_DEBUG_FILES 344 345static inline void create_debug_files (struct ehci_hcd *bus) { } 346static inline void remove_debug_files (struct ehci_hcd *bus) { } 347 348#else 349 350/* troubleshooting help: expose state in debugfs */ 351 352static int debug_async_open(struct inode *, struct file *); 353static int debug_periodic_open(struct inode *, struct file *); 354static int debug_registers_open(struct inode *, struct file *); 355static int debug_async_open(struct inode *, struct file *); 356static int debug_lpm_open(struct inode *, struct file *); 357static ssize_t debug_lpm_read(struct file *file, char __user *user_buf, 358 size_t count, loff_t *ppos); 359static ssize_t debug_lpm_write(struct file *file, const char __user *buffer, 360 size_t count, loff_t *ppos); 361static int debug_lpm_close(struct inode *inode, struct file *file); 362 363static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*); 364static int debug_close(struct inode *, struct file *); 365 366static const struct file_operations debug_async_fops = { 367 .owner = THIS_MODULE, 368 .open = debug_async_open, 369 .read = debug_output, 370 .release = debug_close, 371}; 372static const struct file_operations debug_periodic_fops = { 373 .owner = THIS_MODULE, 374 .open = debug_periodic_open, 375 .read = debug_output, 376 .release = debug_close, 377}; 378static const struct file_operations debug_registers_fops = { 379 .owner = THIS_MODULE, 380 .open = debug_registers_open, 381 .read = debug_output, 382 .release = debug_close, 383}; 384static 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, 390}; 391 392static struct dentry *ehci_debug_root; 393 394struct debug_buffer { 395 ssize_t (*fill_func)(struct debug_buffer *); /* fill method */ 396 struct usb_bus *bus; 397 struct mutex mutex; /* protect filling of buffer */ 398 size_t count; /* number of characters filled into buffer */ 399 char *output_buf; 400 size_t alloc_size; 401}; 402 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; \ 409 }; tmp; }) 410 411static inline char token_mark(struct ehci_hcd *ehci, __hc32 token) 412{ 413 __u32 v = hc32_to_cpu(ehci, token); 414 415 if (v & QTD_STS_ACTIVE) 416 return '*'; 417 if (v & QTD_STS_HALT) 418 return '-'; 419 if (!IS_SHORT_READ (v)) 420 return ' '; 421 /* tries to advance through hw_alt_next */ 422 return '/'; 423} 424 425static void qh_lines ( 426 struct ehci_hcd *ehci, 427 struct ehci_qh *qh, 428 char **nextp, 429 unsigned *sizep 430) 431{ 432 u32 scratch; 433 u32 hw_curr; 434 struct list_head *entry; 435 struct ehci_qtd *td; 436 unsigned temp; 437 unsigned size = *sizep; 438 char *next = *nextp; 439 char mark; 440 __le32 list_end = EHCI_LIST_END(ehci); 441 struct ehci_qh_hw *hw = qh->hw; 442 443 if (hw->hw_qtd_next == list_end) /* NEC does this */ 444 mark = '@'; 445 else 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 */ 454 } 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) 465 ? "data1" : "data0", 466 (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f); 467 size -= temp; 468 next += temp; 469 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); 474 mark = ' '; 475 if (hw_curr == td->qtd_dma) 476 mark = '*'; 477 else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma)) 478 mark = '+'; 479 else if (QTD_LENGTH (scratch)) { 480 if (td->hw_alt_next == ehci->async->hw->hw_alt_next) 481 mark = '#'; 482 else if (td->hw_alt_next != list_end) 483 mark = '/'; 484 } 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; 493 } tmp;}), 494 (scratch >> 16) & 0x7fff, 495 scratch, 496 td->urb); 497 if (size < temp) 498 temp = size; 499 size -= temp; 500 next += temp; 501 if (temp == size) 502 goto done; 503 } 504 505 temp = snprintf (next, size, "\n"); 506 if (size < temp) 507 temp = size; 508 size -= temp; 509 next += temp; 510 511done: 512 *sizep = size; 513 *nextp = next; 514} 515 516static ssize_t fill_async_buffer(struct debug_buffer *buf) 517{ 518 struct usb_hcd *hcd; 519 struct ehci_hcd *ehci; 520 unsigned long flags; 521 unsigned temp, size; 522 char *next; 523 struct ehci_qh *qh; 524 525 hcd = bus_to_hcd(buf->bus); 526 ehci = hcd_to_ehci (hcd); 527 next = buf->output_buf; 528 size = buf->alloc_size; 529 530 *next = 0; 531 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 535 */ 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"); 541 size -= temp; 542 next += temp; 543 544 for (qh = ehci->reclaim; size > 0 && qh; qh = qh->reclaim) 545 qh_lines (ehci, qh, &next, &size); 546 } 547 spin_unlock_irqrestore (&ehci->lock, flags); 548 549 return strlen(buf->output_buf); 550} 551 552#define DBG_SCHED_LIMIT 64 553static ssize_t fill_periodic_buffer(struct debug_buffer *buf) 554{ 555 struct usb_hcd *hcd; 556 struct ehci_hcd *ehci; 557 unsigned long flags; 558 union ehci_shadow p, *seen; 559 unsigned temp, size, seen_count; 560 char *next; 561 unsigned i; 562 __hc32 tag; 563 564 if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC))) 565 return 0; 566 seen_count = 0; 567 568 hcd = bus_to_hcd(buf->bus); 569 ehci = hcd_to_ehci (hcd); 570 next = buf->output_buf; 571 size = buf->alloc_size; 572 573 temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size); 574 size -= temp; 575 next += temp; 576 577 /* dump a snapshot of the periodic schedule. 578 * iso changes, interrupt usually doesn't. 579 */ 580 spin_lock_irqsave (&ehci->lock, flags); 581 for (i = 0; i < ehci->periodic_size; i++) { 582 p = ehci->pshadow [i]; 583 if (likely (!p.ptr)) 584 continue; 585 tag = Q_NEXT_TYPE(ehci, ehci->periodic [i]); 586 587 temp = scnprintf (next, size, "%4d: ", i); 588 size -= temp; 589 next += temp; 590 591 do { 592 struct ehci_qh_hw *hw; 593 594 switch (hc32_to_cpu(ehci, tag)) { 595 case Q_TYPE_QH: 596 hw = p.qh->hw; 597 temp = scnprintf (next, size, " qh%d-%04x/%p", 598 p.qh->period, 599 hc32_to_cpup(ehci, 600 &hw->hw_info2) 601 /* uframe masks */ 602 & (QH_CMASK | QH_SMASK), 603 p.qh); 604 size -= temp; 605 next += temp; 606 /* don't repeat what follows this qh */ 607 for (temp = 0; temp < seen_count; temp++) { 608 if (seen [temp].ptr != p.ptr) 609 continue; 610 if (p.qh->qh_next.ptr) { 611 temp = scnprintf (next, size, 612 " ..."); 613 size -= temp; 614 next += temp; 615 } 616 break; 617 } 618 /* show more info the first time around */ 619 if (temp == seen_count) { 620 u32 scratch = hc32_to_cpup(ehci, 621 &hw->hw_info1); 622 struct ehci_qtd *qtd; 623 char *type = ""; 624 625 /* count tds, get ep direction */ 626 temp = 0; 627 list_for_each_entry (qtd, 628 &p.qh->qtd_list, 629 qtd_list) { 630 temp++; 631 switch (0x03 & (hc32_to_cpu( 632 ehci, 633 qtd->hw_token) >> 8)) { 634 case 0: type = "out"; continue; 635 case 1: type = "in"; continue; 636 } 637 } 638 639 temp = scnprintf (next, size, 640 " (%c%d ep%d%s " 641 "[%d/%d] q%d p%d)", 642 speed_char (scratch), 643 scratch & 0x007f, 644 (scratch >> 8) & 0x000f, type, 645 p.qh->usecs, p.qh->c_usecs, 646 temp, 647 0x7ff & (scratch >> 16)); 648 649 if (seen_count < DBG_SCHED_LIMIT) 650 seen [seen_count++].qh = p.qh; 651 } else 652 temp = 0; 653 if (p.qh) { 654 tag = Q_NEXT_TYPE(ehci, hw->hw_next); 655 p = p.qh->qh_next; 656 } 657 break; 658 case Q_TYPE_FSTN: 659 temp = scnprintf (next, size, 660 " fstn-%8x/%p", p.fstn->hw_prev, 661 p.fstn); 662 tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next); 663 p = p.fstn->fstn_next; 664 break; 665 case Q_TYPE_ITD: 666 temp = scnprintf (next, size, 667 " itd/%p", p.itd); 668 tag = Q_NEXT_TYPE(ehci, p.itd->hw_next); 669 p = p.itd->itd_next; 670 break; 671 case Q_TYPE_SITD: 672 temp = scnprintf (next, size, 673 " sitd%d-%04x/%p", 674 p.sitd->stream->interval, 675 hc32_to_cpup(ehci, &p.sitd->hw_uframe) 676 & 0x0000ffff, 677 p.sitd); 678 tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next); 679 p = p.sitd->sitd_next; 680 break; 681 } 682 size -= temp; 683 next += temp; 684 } while (p.ptr); 685 686 temp = scnprintf (next, size, "\n"); 687 size -= temp; 688 next += temp; 689 } 690 spin_unlock_irqrestore (&ehci->lock, flags); 691 kfree (seen); 692 693 return buf->alloc_size - size; 694} 695#undef DBG_SCHED_LIMIT 696 697static ssize_t fill_registers_buffer(struct debug_buffer *buf) 698{ 699 struct usb_hcd *hcd; 700 struct ehci_hcd *ehci; 701 unsigned long flags; 702 unsigned temp, size, i; 703 char *next, scratch [80]; 704 static char fmt [] = "%*s\n"; 705 static char label [] = ""; 706 707 hcd = bus_to_hcd(buf->bus); 708 ehci = hcd_to_ehci (hcd); 709 next = buf->output_buf; 710 size = buf->alloc_size; 711 712 spin_lock_irqsave (&ehci->lock, flags); 713 714 if (!HCD_HW_ACCESSIBLE(hcd)) { 715 size = scnprintf (next, size, 716 "bus %s, device %s\n" 717 "%s\n" 718 "SUSPENDED (no register access)\n", 719 hcd->self.controller->bus->name, 720 dev_name(hcd->self.controller), 721 hcd->product_desc); 722 goto done; 723 } 724 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" 729 "%s\n" 730 "EHCI %x.%02x, hcd state %d\n", 731 hcd->self.controller->bus->name, 732 dev_name(hcd->self.controller), 733 hcd->product_desc, 734 i >> 8, i & 0x0ff, hcd->state); 735 size -= temp; 736 next += temp; 737 738#ifdef CONFIG_PCI 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; 744 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) { 751 case 1: 752 temp = scnprintf (next, size, 753 "ownership %08x%s%s\n", cap, 754 (cap & (1 << 24)) ? " linux" : "", 755 (cap & (1 << 16)) ? " firmware" : ""); 756 size -= temp; 757 next += temp; 758 759 offset += 4; 760 pci_read_config_dword (pdev, offset, &cap2); 761 temp = scnprintf (next, size, 762 "SMI sts/enable 0x%08x\n", cap2); 763 size -= temp; 764 next += temp; 765 break; 766 case 0: /* illegal reserved capability */ 767 cap = 0; 768 /* FALLTHROUGH */ 769 default: /* unknown */ 770 break; 771 } 772 temp = (cap >> 8) & 0xff; 773 } 774 } 775#endif 776 777 i = ehci_readl(ehci, &ehci->caps->hcs_params); 778 temp = scnprintf (next, size, "structural params 0x%08x\n", i); 779 size -= temp; 780 next += temp; 781 782 i = ehci_readl(ehci, &ehci->caps->hcc_params); 783 temp = scnprintf (next, size, "capability params 0x%08x\n", i); 784 size -= temp; 785 next += temp; 786 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); 791 size -= temp; 792 next += temp; 793 794 temp = dbg_command_buf (scratch, sizeof scratch, label, 795 ehci_readl(ehci, &ehci->regs->command)); 796 temp = scnprintf (next, size, fmt, temp, scratch); 797 size -= temp; 798 next += temp; 799 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); 803 size -= temp; 804 next += temp; 805 806 temp = scnprintf (next, size, "uframe %04x\n", 807 ehci_readl(ehci, &ehci->regs->frame_index)); 808 size -= temp; 809 next += temp; 810 811 for (i = 1; i <= HCS_N_PORTS (ehci->hcs_params); i++) { 812 temp = dbg_port_buf (scratch, sizeof scratch, label, i, 813 ehci_readl(ehci, 814 &ehci->regs->port_status[i - 1])); 815 temp = scnprintf (next, size, fmt, temp, scratch); 816 size -= temp; 817 next += temp; 818 if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) { 819 temp = scnprintf (next, size, 820 " debug control %08x\n", 821 ehci_readl(ehci, 822 &ehci->debug->control)); 823 size -= temp; 824 next += temp; 825 } 826 } 827 828 if (ehci->reclaim) { 829 temp = scnprintf(next, size, "reclaim qh %p\n", ehci->reclaim); 830 size -= temp; 831 next += temp; 832 } 833 834#ifdef EHCI_STATS 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); 839 size -= temp; 840 next += temp; 841 842 temp = scnprintf (next, size, "complete %ld unlink %ld\n", 843 ehci->stats.complete, ehci->stats.unlink); 844 size -= temp; 845 next += temp; 846#endif 847 848done: 849 spin_unlock_irqrestore (&ehci->lock, flags); 850 851 return buf->alloc_size - size; 852} 853 854static struct debug_buffer *alloc_buffer(struct usb_bus *bus, 855 ssize_t (*fill_func)(struct debug_buffer *)) 856{ 857 struct debug_buffer *buf; 858 859 buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL); 860 861 if (buf) { 862 buf->bus = bus; 863 buf->fill_func = fill_func; 864 mutex_init(&buf->mutex); 865 buf->alloc_size = PAGE_SIZE; 866 } 867 868 return buf; 869} 870 871static int fill_buffer(struct debug_buffer *buf) 872{ 873 int ret = 0; 874 875 if (!buf->output_buf) 876 buf->output_buf = (char *)vmalloc(buf->alloc_size); 877 878 if (!buf->output_buf) { 879 ret = -ENOMEM; 880 goto out; 881 } 882 883 ret = buf->fill_func(buf); 884 885 if (ret >= 0) { 886 buf->count = ret; 887 ret = 0; 888 } 889 890out: 891 return ret; 892} 893 894static ssize_t debug_output(struct file *file, char __user *user_buf, 895 size_t len, loff_t *offset) 896{ 897 struct debug_buffer *buf = file->private_data; 898 int ret = 0; 899 900 mutex_lock(&buf->mutex); 901 if (buf->count == 0) { 902 ret = fill_buffer(buf); 903 if (ret != 0) { 904 mutex_unlock(&buf->mutex); 905 goto out; 906 } 907 } 908 mutex_unlock(&buf->mutex); 909 910 ret = simple_read_from_buffer(user_buf, len, offset, 911 buf->output_buf, buf->count); 912 913out: 914 return ret; 915 916} 917 918static int debug_close(struct inode *inode, struct file *file) 919{ 920 struct debug_buffer *buf = file->private_data; 921 922 if (buf) { 923 vfree(buf->output_buf); 924 kfree(buf); 925 } 926 927 return 0; 928} 929static int debug_async_open(struct inode *inode, struct file *file) 930{ 931 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer); 932 933 return file->private_data ? 0 : -ENOMEM; 934} 935 936static int debug_periodic_open(struct inode *inode, struct file *file) 937{ 938 struct debug_buffer *buf; 939 buf = alloc_buffer(inode->i_private, fill_periodic_buffer); 940 if (!buf) 941 return -ENOMEM; 942 943 buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE; 944 file->private_data = buf; 945 return 0; 946} 947 948static int debug_registers_open(struct inode *inode, struct file *file) 949{ 950 file->private_data = alloc_buffer(inode->i_private, 951 fill_registers_buffer); 952 953 return file->private_data ? 0 : -ENOMEM; 954} 955 956static int debug_lpm_open(struct inode *inode, struct file *file) 957{ 958 file->private_data = inode->i_private; 959 return 0; 960} 961 962static int debug_lpm_close(struct inode *inode, struct file *file) 963{ 964 return 0; 965} 966 967static ssize_t debug_lpm_read(struct file *file, char __user *user_buf, 968 size_t count, loff_t *ppos) 969{ 970 /* TODO: show lpm stats */ 971 return 0; 972} 973 974static ssize_t debug_lpm_write(struct file *file, const char __user *user_buf, 975 size_t count, loff_t *ppos) 976{ 977 struct usb_hcd *hcd; 978 struct ehci_hcd *ehci; 979 char buf[50]; 980 size_t len; 981 u32 temp; 982 unsigned long port; 983 u32 __iomem *portsc ; 984 u32 params; 985 986 hcd = bus_to_hcd(file->private_data); 987 ehci = hcd_to_ehci(hcd); 988 989 len = min(count, sizeof(buf) - 1); 990 if (copy_from_user(buf, user_buf, len)) 991 return -EFAULT; 992 buf[len] = '\0'; 993 if (len > 0 && buf[len - 1] == '\n') 994 buf[len - 1] = '\0'; 995 996 if (strncmp(buf, "enable", 5) == 0) { 997 if (strict_strtoul(buf + 7, 10, &port)) 998 return -EINVAL; 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); 1002 return -ENODEV; 1003 } 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"); 1008 return -ENODEV; 1009 } 1010 temp |= PORT_LPM; 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) { 1014 unsigned long hird; 1015 if (strict_strtoul(buf + 5, 16, &hird)) 1016 return -EINVAL; 1017 printk(KERN_INFO "setting hird %s %lu\n", buf + 6, hird); 1018 temp = ehci_readl(ehci, &ehci->regs->command); 1019 temp &= ~CMD_HIRD; 1020 temp |= hird << 24; 1021 ehci_writel(ehci, temp, &ehci->regs->command); 1022 } else if (strncmp(buf, "disable", 7) == 0) { 1023 if (strict_strtoul(buf + 8, 10, &port)) 1024 return -EINVAL; 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); 1028 return -ENODEV; 1029 } 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"); 1034 return -ENODEV; 1035 } 1036 temp &= ~PORT_LPM; 1037 ehci_writel(ehci, temp, portsc); 1038 printk(KERN_INFO "disabled LPM for port %lu\n", port); 1039 } else 1040 return -EOPNOTSUPP; 1041 return count; 1042} 1043 1044static inline void create_debug_files (struct ehci_hcd *ehci) 1045{ 1046 struct usb_bus *bus = &ehci_to_hcd(ehci)->self; 1047 1048 ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root); 1049 if (!ehci->debug_dir) 1050 return; 1051 1052 if (!debugfs_create_file("async", S_IRUGO, ehci->debug_dir, bus, 1053 &debug_async_fops)) 1054 goto file_error; 1055 1056 if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus, 1057 &debug_periodic_fops)) 1058 goto file_error; 1059 1060 if (!debugfs_create_file("registers", S_IRUGO, ehci->debug_dir, bus, 1061 &debug_registers_fops)) 1062 goto file_error; 1063 1064 if (!debugfs_create_file("lpm", S_IRUGO|S_IWUSR, ehci->debug_dir, bus, 1065 &debug_lpm_fops)) 1066 goto file_error; 1067 1068 return; 1069 1070file_error: 1071 debugfs_remove_recursive(ehci->debug_dir); 1072} 1073 1074static inline void remove_debug_files (struct ehci_hcd *ehci) 1075{ 1076 debugfs_remove_recursive(ehci->debug_dir); 1077} 1078 1079#endif /* STUB_DEBUG_FILES */ 1080