| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (c) 2001-2002 by David Brownell | 
| David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 3 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| David Brownell | 9776afc | 2008-02-01 11:42:05 -0800 | [diff] [blame] | 30 | #ifdef VERBOSE_DEBUG | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ | 
|  | 44 | static void dbg_hcs_params (struct ehci_hcd *ehci, char *label) | 
|  | 45 | { | 
| Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 46 | u32	params = ehci_readl(ehci, &ehci->caps->hcs_params); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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), | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 55 | HCS_PORTROUTED (params) ? "" : " ordered", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | // FIXME MIPS won't readb() ... | 
|  | 67 | byte = readb (&ehci->caps->portroute[(i>>1)]); | 
| David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 68 | sprintf(tmp, "%d ", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf))); | 
|  | 70 | strcat(buf, tmp); | 
|  | 71 | } | 
|  | 72 | ehci_dbg (ehci, "%s portroute %s\n", | 
|  | 73 | label, buf); | 
|  | 74 | } | 
|  | 75 | } | 
|  | 76 | #else | 
|  | 77 |  | 
|  | 78 | static inline void dbg_hcs_params (struct ehci_hcd *ehci, char *label) {} | 
|  | 79 |  | 
|  | 80 | #endif | 
|  | 81 |  | 
|  | 82 | #ifdef	DEBUG | 
|  | 83 |  | 
|  | 84 | /* check the values in the HCCPARAMS register | 
|  | 85 | * (host controller _Capability_ parameters) | 
|  | 86 | * see EHCI Spec, Table 2-5 for each value | 
|  | 87 | * */ | 
|  | 88 | static void dbg_hcc_params (struct ehci_hcd *ehci, char *label) | 
|  | 89 | { | 
| Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 90 | u32	params = ehci_readl(ehci, &ehci->caps->hcc_params); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 |  | 
|  | 92 | if (HCC_ISOC_CACHE (params)) { | 
|  | 93 | ehci_dbg (ehci, | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 94 | "%s hcc_params %04x caching frame %s%s%s\n", | 
|  | 95 | label, params, | 
|  | 96 | HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", | 
|  | 97 | HCC_CANPARK(params) ? " park" : "", | 
|  | 98 | HCC_64BIT_ADDR(params) ? " 64 bit addr" : ""); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } else { | 
|  | 100 | ehci_dbg (ehci, | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 101 | "%s hcc_params %04x thresh %d uframes %s%s%s\n", | 
|  | 102 | label, | 
|  | 103 | params, | 
|  | 104 | HCC_ISOC_THRES(params), | 
|  | 105 | HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", | 
|  | 106 | HCC_CANPARK(params) ? " park" : "", | 
|  | 107 | HCC_64BIT_ADDR(params) ? " 64 bit addr" : ""); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } | 
|  | 109 | } | 
|  | 110 | #else | 
|  | 111 |  | 
|  | 112 | static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {} | 
|  | 113 |  | 
|  | 114 | #endif | 
|  | 115 |  | 
|  | 116 | #ifdef	DEBUG | 
|  | 117 |  | 
| David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 118 | static void __maybe_unused | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd) | 
|  | 120 | { | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 121 | ehci_dbg(ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd, | 
|  | 122 | hc32_to_cpup(ehci, &qtd->hw_next), | 
|  | 123 | hc32_to_cpup(ehci, &qtd->hw_alt_next), | 
|  | 124 | hc32_to_cpup(ehci, &qtd->hw_token), | 
|  | 125 | hc32_to_cpup(ehci, &qtd->hw_buf [0])); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | if (qtd->hw_buf [1]) | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 127 | ehci_dbg(ehci, "  p1=%08x p2=%08x p3=%08x p4=%08x\n", | 
|  | 128 | hc32_to_cpup(ehci, &qtd->hw_buf[1]), | 
|  | 129 | hc32_to_cpup(ehci, &qtd->hw_buf[2]), | 
|  | 130 | hc32_to_cpup(ehci, &qtd->hw_buf[3]), | 
|  | 131 | hc32_to_cpup(ehci, &qtd->hw_buf[4])); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } | 
|  | 133 |  | 
| David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 134 | static void __maybe_unused | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) | 
|  | 136 | { | 
|  | 137 | ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label, | 
|  | 138 | qh, qh->hw_next, qh->hw_info1, qh->hw_info2, | 
|  | 139 | qh->hw_current); | 
|  | 140 | dbg_qtd ("overlay", ehci, (struct ehci_qtd *) &qh->hw_qtd_next); | 
|  | 141 | } | 
|  | 142 |  | 
| David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 143 | static void __maybe_unused | 
| David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 144 | dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { | 
|  | 146 | ehci_dbg (ehci, "%s [%d] itd %p, next %08x, urb %p\n", | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 147 | label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next), | 
|  | 148 | itd->urb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | ehci_dbg (ehci, | 
| David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 150 | "  trans: %08x %08x %08x %08x %08x %08x %08x %08x\n", | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 151 | hc32_to_cpu(ehci, itd->hw_transaction[0]), | 
|  | 152 | hc32_to_cpu(ehci, itd->hw_transaction[1]), | 
|  | 153 | hc32_to_cpu(ehci, itd->hw_transaction[2]), | 
|  | 154 | hc32_to_cpu(ehci, itd->hw_transaction[3]), | 
|  | 155 | hc32_to_cpu(ehci, itd->hw_transaction[4]), | 
|  | 156 | hc32_to_cpu(ehci, itd->hw_transaction[5]), | 
|  | 157 | hc32_to_cpu(ehci, itd->hw_transaction[6]), | 
|  | 158 | hc32_to_cpu(ehci, itd->hw_transaction[7])); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | ehci_dbg (ehci, | 
| David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 160 | "  buf:   %08x %08x %08x %08x %08x %08x %08x\n", | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 161 | hc32_to_cpu(ehci, itd->hw_bufp[0]), | 
|  | 162 | hc32_to_cpu(ehci, itd->hw_bufp[1]), | 
|  | 163 | hc32_to_cpu(ehci, itd->hw_bufp[2]), | 
|  | 164 | hc32_to_cpu(ehci, itd->hw_bufp[3]), | 
|  | 165 | hc32_to_cpu(ehci, itd->hw_bufp[4]), | 
|  | 166 | hc32_to_cpu(ehci, itd->hw_bufp[5]), | 
|  | 167 | hc32_to_cpu(ehci, itd->hw_bufp[6])); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | ehci_dbg (ehci, "  index: %d %d %d %d %d %d %d %d\n", | 
|  | 169 | itd->index[0], itd->index[1], itd->index[2], | 
|  | 170 | itd->index[3], itd->index[4], itd->index[5], | 
|  | 171 | itd->index[6], itd->index[7]); | 
|  | 172 | } | 
|  | 173 |  | 
| David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 174 | static void __maybe_unused | 
| David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 175 | dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { | 
|  | 177 | ehci_dbg (ehci, "%s [%d] sitd %p, next %08x, urb %p\n", | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 178 | label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next), | 
|  | 179 | sitd->urb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | ehci_dbg (ehci, | 
| David Brownell | 53bd6a6 | 2006-08-30 14:50:06 -0700 | [diff] [blame] | 181 | "  addr %08x sched %04x result %08x buf %08x %08x\n", | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 182 | hc32_to_cpu(ehci, sitd->hw_fullspeed_ep), | 
|  | 183 | hc32_to_cpu(ehci, sitd->hw_uframe), | 
|  | 184 | hc32_to_cpu(ehci, sitd->hw_results), | 
|  | 185 | hc32_to_cpu(ehci, sitd->hw_buf[0]), | 
|  | 186 | hc32_to_cpu(ehci, sitd->hw_buf[1])); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } | 
|  | 188 |  | 
| David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 189 | static int __maybe_unused | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) | 
|  | 191 | { | 
|  | 192 | return scnprintf (buf, len, | 
|  | 193 | "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s", | 
|  | 194 | label, label [0] ? " " : "", status, | 
|  | 195 | (status & STS_ASS) ? " Async" : "", | 
|  | 196 | (status & STS_PSS) ? " Periodic" : "", | 
|  | 197 | (status & STS_RECL) ? " Recl" : "", | 
|  | 198 | (status & STS_HALT) ? " Halt" : "", | 
|  | 199 | (status & STS_IAA) ? " IAA" : "", | 
|  | 200 | (status & STS_FATAL) ? " FATAL" : "", | 
|  | 201 | (status & STS_FLR) ? " FLR" : "", | 
|  | 202 | (status & STS_PCD) ? " PCD" : "", | 
|  | 203 | (status & STS_ERR) ? " ERR" : "", | 
|  | 204 | (status & STS_INT) ? " INT" : "" | 
|  | 205 | ); | 
|  | 206 | } | 
|  | 207 |  | 
| David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 208 | static int __maybe_unused | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable) | 
|  | 210 | { | 
|  | 211 | return scnprintf (buf, len, | 
|  | 212 | "%s%sintrenable %02x%s%s%s%s%s%s", | 
|  | 213 | label, label [0] ? " " : "", enable, | 
|  | 214 | (enable & STS_IAA) ? " IAA" : "", | 
|  | 215 | (enable & STS_FATAL) ? " FATAL" : "", | 
|  | 216 | (enable & STS_FLR) ? " FLR" : "", | 
|  | 217 | (enable & STS_PCD) ? " PCD" : "", | 
|  | 218 | (enable & STS_ERR) ? " ERR" : "", | 
|  | 219 | (enable & STS_INT) ? " INT" : "" | 
|  | 220 | ); | 
|  | 221 | } | 
|  | 222 |  | 
|  | 223 | static const char *const fls_strings [] = | 
|  | 224 | { "1024", "512", "256", "??" }; | 
|  | 225 |  | 
|  | 226 | static int | 
|  | 227 | dbg_command_buf (char *buf, unsigned len, const char *label, u32 command) | 
|  | 228 | { | 
|  | 229 | return scnprintf (buf, len, | 
|  | 230 | "%s%scommand %06x %s=%d ithresh=%d%s%s%s%s period=%s%s %s", | 
|  | 231 | label, label [0] ? " " : "", command, | 
|  | 232 | (command & CMD_PARK) ? "park" : "(park)", | 
|  | 233 | CMD_PARK_CNT (command), | 
|  | 234 | (command >> 16) & 0x3f, | 
|  | 235 | (command & CMD_LRESET) ? " LReset" : "", | 
|  | 236 | (command & CMD_IAAD) ? " IAAD" : "", | 
|  | 237 | (command & CMD_ASE) ? " Async" : "", | 
|  | 238 | (command & CMD_PSE) ? " Periodic" : "", | 
|  | 239 | fls_strings [(command >> 2) & 0x3], | 
|  | 240 | (command & CMD_RESET) ? " Reset" : "", | 
|  | 241 | (command & CMD_RUN) ? "RUN" : "HALT" | 
|  | 242 | ); | 
|  | 243 | } | 
|  | 244 |  | 
|  | 245 | static int | 
|  | 246 | dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status) | 
|  | 247 | { | 
|  | 248 | char	*sig; | 
|  | 249 |  | 
|  | 250 | /* signaling state */ | 
|  | 251 | switch (status & (3 << 10)) { | 
|  | 252 | case 0 << 10: sig = "se0"; break; | 
|  | 253 | case 1 << 10: sig = "k"; break;		/* low speed */ | 
|  | 254 | case 2 << 10: sig = "j"; break; | 
|  | 255 | default: sig = "?"; break; | 
|  | 256 | } | 
|  | 257 |  | 
|  | 258 | return scnprintf (buf, len, | 
| David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 259 | "%s%sport %d status %06x%s%s sig=%s%s%s%s%s%s%s%s%s%s", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | label, label [0] ? " " : "", port, status, | 
|  | 261 | (status & PORT_POWER) ? " POWER" : "", | 
|  | 262 | (status & PORT_OWNER) ? " OWNER" : "", | 
|  | 263 | sig, | 
|  | 264 | (status & PORT_RESET) ? " RESET" : "", | 
|  | 265 | (status & PORT_SUSPEND) ? " SUSPEND" : "", | 
|  | 266 | (status & PORT_RESUME) ? " RESUME" : "", | 
|  | 267 | (status & PORT_OCC) ? " OCC" : "", | 
|  | 268 | (status & PORT_OC) ? " OC" : "", | 
|  | 269 | (status & PORT_PEC) ? " PEC" : "", | 
|  | 270 | (status & PORT_PE) ? " PE" : "", | 
|  | 271 | (status & PORT_CSC) ? " CSC" : "", | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 272 | (status & PORT_CONNECT) ? " CONNECT" : ""); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | } | 
|  | 274 |  | 
|  | 275 | #else | 
| David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 276 | static inline void __maybe_unused | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) | 
|  | 278 | {} | 
|  | 279 |  | 
| David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 280 | static inline int __maybe_unused | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) | 
|  | 282 | { return 0; } | 
|  | 283 |  | 
| David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 284 | static inline int __maybe_unused | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | dbg_command_buf (char *buf, unsigned len, const char *label, u32 command) | 
|  | 286 | { return 0; } | 
|  | 287 |  | 
| David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 288 | static inline int __maybe_unused | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable) | 
|  | 290 | { return 0; } | 
|  | 291 |  | 
| David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 292 | static inline int __maybe_unused | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status) | 
|  | 294 | { return 0; } | 
|  | 295 |  | 
|  | 296 | #endif	/* DEBUG */ | 
|  | 297 |  | 
|  | 298 | /* functions have the "wrong" filename when they're output... */ | 
|  | 299 | #define dbg_status(ehci, label, status) { \ | 
|  | 300 | char _buf [80]; \ | 
|  | 301 | dbg_status_buf (_buf, sizeof _buf, label, status); \ | 
|  | 302 | ehci_dbg (ehci, "%s\n", _buf); \ | 
|  | 303 | } | 
|  | 304 |  | 
|  | 305 | #define dbg_cmd(ehci, label, command) { \ | 
|  | 306 | char _buf [80]; \ | 
|  | 307 | dbg_command_buf (_buf, sizeof _buf, label, command); \ | 
|  | 308 | ehci_dbg (ehci, "%s\n", _buf); \ | 
|  | 309 | } | 
|  | 310 |  | 
|  | 311 | #define dbg_port(ehci, label, port, status) { \ | 
|  | 312 | char _buf [80]; \ | 
|  | 313 | dbg_port_buf (_buf, sizeof _buf, label, port, status); \ | 
|  | 314 | ehci_dbg (ehci, "%s\n", _buf); \ | 
|  | 315 | } | 
|  | 316 |  | 
|  | 317 | /*-------------------------------------------------------------------------*/ | 
|  | 318 |  | 
|  | 319 | #ifdef STUB_DEBUG_FILES | 
|  | 320 |  | 
|  | 321 | static inline void create_debug_files (struct ehci_hcd *bus) { } | 
|  | 322 | static inline void remove_debug_files (struct ehci_hcd *bus) { } | 
|  | 323 |  | 
|  | 324 | #else | 
|  | 325 |  | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 326 | /* troubleshooting help: expose state in debugfs */ | 
|  | 327 |  | 
|  | 328 | static int debug_async_open(struct inode *, struct file *); | 
|  | 329 | static int debug_periodic_open(struct inode *, struct file *); | 
|  | 330 | static int debug_registers_open(struct inode *, struct file *); | 
|  | 331 | static int debug_async_open(struct inode *, struct file *); | 
|  | 332 | static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*); | 
|  | 333 | static int debug_close(struct inode *, struct file *); | 
|  | 334 |  | 
|  | 335 | static const struct file_operations debug_async_fops = { | 
|  | 336 | .owner		= THIS_MODULE, | 
|  | 337 | .open		= debug_async_open, | 
|  | 338 | .read		= debug_output, | 
|  | 339 | .release	= debug_close, | 
|  | 340 | }; | 
|  | 341 | static const struct file_operations debug_periodic_fops = { | 
|  | 342 | .owner		= THIS_MODULE, | 
|  | 343 | .open		= debug_periodic_open, | 
|  | 344 | .read		= debug_output, | 
|  | 345 | .release	= debug_close, | 
|  | 346 | }; | 
|  | 347 | static const struct file_operations debug_registers_fops = { | 
|  | 348 | .owner		= THIS_MODULE, | 
|  | 349 | .open		= debug_registers_open, | 
|  | 350 | .read		= debug_output, | 
|  | 351 | .release	= debug_close, | 
|  | 352 | }; | 
|  | 353 |  | 
|  | 354 | static struct dentry *ehci_debug_root; | 
|  | 355 |  | 
|  | 356 | struct debug_buffer { | 
|  | 357 | ssize_t (*fill_func)(struct debug_buffer *);	/* fill method */ | 
|  | 358 | struct usb_bus *bus; | 
|  | 359 | struct mutex mutex;	/* protect filling of buffer */ | 
|  | 360 | size_t count;		/* number of characters filled into buffer */ | 
|  | 361 | char *page; | 
|  | 362 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 |  | 
|  | 364 | #define speed_char(info1) ({ char tmp; \ | 
|  | 365 | switch (info1 & (3 << 12)) { \ | 
|  | 366 | case 0 << 12: tmp = 'f'; break; \ | 
|  | 367 | case 1 << 12: tmp = 'l'; break; \ | 
|  | 368 | case 2 << 12: tmp = 'h'; break; \ | 
|  | 369 | default: tmp = '?'; break; \ | 
|  | 370 | }; tmp; }) | 
|  | 371 |  | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 372 | static inline char token_mark(struct ehci_hcd *ehci, __hc32 token) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | { | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 374 | __u32 v = hc32_to_cpu(ehci, token); | 
|  | 375 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | if (v & QTD_STS_ACTIVE) | 
|  | 377 | return '*'; | 
|  | 378 | if (v & QTD_STS_HALT) | 
|  | 379 | return '-'; | 
|  | 380 | if (!IS_SHORT_READ (v)) | 
|  | 381 | return ' '; | 
|  | 382 | /* tries to advance through hw_alt_next */ | 
|  | 383 | return '/'; | 
|  | 384 | } | 
|  | 385 |  | 
|  | 386 | static void qh_lines ( | 
|  | 387 | struct ehci_hcd *ehci, | 
|  | 388 | struct ehci_qh *qh, | 
|  | 389 | char **nextp, | 
|  | 390 | unsigned *sizep | 
|  | 391 | ) | 
|  | 392 | { | 
|  | 393 | u32			scratch; | 
|  | 394 | u32			hw_curr; | 
|  | 395 | struct list_head	*entry; | 
|  | 396 | struct ehci_qtd		*td; | 
|  | 397 | unsigned		temp; | 
|  | 398 | unsigned		size = *sizep; | 
|  | 399 | char			*next = *nextp; | 
|  | 400 | char			mark; | 
| Al Viro | fd05e72 | 2008-04-28 07:00:16 +0100 | [diff] [blame] | 401 | __le32			list_end = EHCI_LIST_END(ehci); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 |  | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 403 | if (qh->hw_qtd_next == list_end)	/* NEC does this */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | mark = '@'; | 
|  | 405 | else | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 406 | mark = token_mark(ehci, qh->hw_token); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | if (mark == '/') {	/* qh_alt_next controls qh advance? */ | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 408 | if ((qh->hw_alt_next & QTD_MASK(ehci)) | 
|  | 409 | == ehci->async->hw_alt_next) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | mark = '#';	/* blocked */ | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 411 | else if (qh->hw_alt_next == list_end) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | mark = '.';	/* use hw_qtd_next */ | 
|  | 413 | /* else alt_next points to some other qtd */ | 
|  | 414 | } | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 415 | scratch = hc32_to_cpup(ehci, &qh->hw_info1); | 
|  | 416 | hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &qh->hw_current) : 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | temp = scnprintf (next, size, | 
|  | 418 | "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)", | 
|  | 419 | qh, scratch & 0x007f, | 
|  | 420 | speed_char (scratch), | 
|  | 421 | (scratch >> 8) & 0x000f, | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 422 | scratch, hc32_to_cpup(ehci, &qh->hw_info2), | 
|  | 423 | hc32_to_cpup(ehci, &qh->hw_token), mark, | 
|  | 424 | (cpu_to_hc32(ehci, QTD_TOGGLE) & qh->hw_token) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | ? "data1" : "data0", | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 426 | (hc32_to_cpup(ehci, &qh->hw_alt_next) >> 1) & 0x0f); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | size -= temp; | 
|  | 428 | next += temp; | 
|  | 429 |  | 
|  | 430 | /* hc may be modifying the list as we read it ... */ | 
|  | 431 | list_for_each (entry, &qh->qtd_list) { | 
|  | 432 | td = list_entry (entry, struct ehci_qtd, qtd_list); | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 433 | scratch = hc32_to_cpup(ehci, &td->hw_token); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | mark = ' '; | 
|  | 435 | if (hw_curr == td->qtd_dma) | 
|  | 436 | mark = '*'; | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 437 | else if (qh->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | mark = '+'; | 
|  | 439 | else if (QTD_LENGTH (scratch)) { | 
|  | 440 | if (td->hw_alt_next == ehci->async->hw_alt_next) | 
|  | 441 | mark = '#'; | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 442 | else if (td->hw_alt_next != list_end) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | mark = '/'; | 
|  | 444 | } | 
|  | 445 | temp = snprintf (next, size, | 
|  | 446 | "\n\t%p%c%s len=%d %08x urb %p", | 
|  | 447 | td, mark, ({ char *tmp; | 
|  | 448 | switch ((scratch>>8)&0x03) { | 
|  | 449 | case 0: tmp = "out"; break; | 
|  | 450 | case 1: tmp = "in"; break; | 
|  | 451 | case 2: tmp = "setup"; break; | 
|  | 452 | default: tmp = "?"; break; | 
|  | 453 | } tmp;}), | 
|  | 454 | (scratch >> 16) & 0x7fff, | 
|  | 455 | scratch, | 
|  | 456 | td->urb); | 
|  | 457 | if (temp < 0) | 
|  | 458 | temp = 0; | 
|  | 459 | else if (size < temp) | 
|  | 460 | temp = size; | 
|  | 461 | size -= temp; | 
|  | 462 | next += temp; | 
|  | 463 | if (temp == size) | 
|  | 464 | goto done; | 
|  | 465 | } | 
|  | 466 |  | 
|  | 467 | temp = snprintf (next, size, "\n"); | 
|  | 468 | if (temp < 0) | 
|  | 469 | temp = 0; | 
|  | 470 | else if (size < temp) | 
|  | 471 | temp = size; | 
|  | 472 | size -= temp; | 
|  | 473 | next += temp; | 
|  | 474 |  | 
|  | 475 | done: | 
|  | 476 | *sizep = size; | 
|  | 477 | *nextp = next; | 
|  | 478 | } | 
|  | 479 |  | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 480 | static ssize_t fill_async_buffer(struct debug_buffer *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | struct usb_hcd		*hcd; | 
|  | 483 | struct ehci_hcd		*ehci; | 
|  | 484 | unsigned long		flags; | 
|  | 485 | unsigned		temp, size; | 
|  | 486 | char			*next; | 
|  | 487 | struct ehci_qh		*qh; | 
|  | 488 |  | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 489 | hcd = bus_to_hcd(buf->bus); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | ehci = hcd_to_ehci (hcd); | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 491 | next = buf->page; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | size = PAGE_SIZE; | 
|  | 493 |  | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 494 | *next = 0; | 
|  | 495 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | /* dumps a snapshot of the async schedule. | 
|  | 497 | * usually empty except for long-term bulk reads, or head. | 
|  | 498 | * one QH per line, and TDs we know about | 
|  | 499 | */ | 
|  | 500 | spin_lock_irqsave (&ehci->lock, flags); | 
|  | 501 | for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh) | 
|  | 502 | qh_lines (ehci, qh, &next, &size); | 
|  | 503 | if (ehci->reclaim && size > 0) { | 
|  | 504 | temp = scnprintf (next, size, "\nreclaim =\n"); | 
|  | 505 | size -= temp; | 
|  | 506 | next += temp; | 
|  | 507 |  | 
|  | 508 | for (qh = ehci->reclaim; size > 0 && qh; qh = qh->reclaim) | 
|  | 509 | qh_lines (ehci, qh, &next, &size); | 
|  | 510 | } | 
|  | 511 | spin_unlock_irqrestore (&ehci->lock, flags); | 
|  | 512 |  | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 513 | return strlen(buf->page); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 |  | 
|  | 516 | #define DBG_SCHED_LIMIT 64 | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 517 | static ssize_t fill_periodic_buffer(struct debug_buffer *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | struct usb_hcd		*hcd; | 
|  | 520 | struct ehci_hcd		*ehci; | 
|  | 521 | unsigned long		flags; | 
|  | 522 | union ehci_shadow	p, *seen; | 
|  | 523 | unsigned		temp, size, seen_count; | 
|  | 524 | char			*next; | 
|  | 525 | unsigned		i; | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 526 | __hc32			tag; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 |  | 
| Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 528 | if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC))) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | return 0; | 
|  | 530 | seen_count = 0; | 
|  | 531 |  | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 532 | hcd = bus_to_hcd(buf->bus); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | ehci = hcd_to_ehci (hcd); | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 534 | next = buf->page; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | size = PAGE_SIZE; | 
|  | 536 |  | 
|  | 537 | temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size); | 
|  | 538 | size -= temp; | 
|  | 539 | next += temp; | 
|  | 540 |  | 
|  | 541 | /* dump a snapshot of the periodic schedule. | 
|  | 542 | * iso changes, interrupt usually doesn't. | 
|  | 543 | */ | 
|  | 544 | spin_lock_irqsave (&ehci->lock, flags); | 
|  | 545 | for (i = 0; i < ehci->periodic_size; i++) { | 
|  | 546 | p = ehci->pshadow [i]; | 
|  | 547 | if (likely (!p.ptr)) | 
|  | 548 | continue; | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 549 | tag = Q_NEXT_TYPE(ehci, ehci->periodic [i]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 |  | 
|  | 551 | temp = scnprintf (next, size, "%4d: ", i); | 
|  | 552 | size -= temp; | 
|  | 553 | next += temp; | 
|  | 554 |  | 
|  | 555 | do { | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 556 | switch (hc32_to_cpu(ehci, tag)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | case Q_TYPE_QH: | 
|  | 558 | temp = scnprintf (next, size, " qh%d-%04x/%p", | 
|  | 559 | p.qh->period, | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 560 | hc32_to_cpup(ehci, | 
|  | 561 | &p.qh->hw_info2) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | /* uframe masks */ | 
| David Brownell | 7dedacf | 2005-08-04 18:06:41 -0700 | [diff] [blame] | 563 | & (QH_CMASK | QH_SMASK), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | p.qh); | 
|  | 565 | size -= temp; | 
|  | 566 | next += temp; | 
|  | 567 | /* don't repeat what follows this qh */ | 
|  | 568 | for (temp = 0; temp < seen_count; temp++) { | 
|  | 569 | if (seen [temp].ptr != p.ptr) | 
|  | 570 | continue; | 
|  | 571 | if (p.qh->qh_next.ptr) | 
|  | 572 | temp = scnprintf (next, size, | 
|  | 573 | " ..."); | 
|  | 574 | p.ptr = NULL; | 
|  | 575 | break; | 
|  | 576 | } | 
|  | 577 | /* show more info the first time around */ | 
|  | 578 | if (temp == seen_count && p.ptr) { | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 579 | u32	scratch = hc32_to_cpup(ehci, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | &p.qh->hw_info1); | 
|  | 581 | struct ehci_qtd	*qtd; | 
|  | 582 | char		*type = ""; | 
|  | 583 |  | 
|  | 584 | /* count tds, get ep direction */ | 
|  | 585 | temp = 0; | 
|  | 586 | list_for_each_entry (qtd, | 
|  | 587 | &p.qh->qtd_list, | 
|  | 588 | qtd_list) { | 
|  | 589 | temp++; | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 590 | switch (0x03 & (hc32_to_cpu( | 
|  | 591 | ehci, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | qtd->hw_token) >> 8)) { | 
|  | 593 | case 0: type = "out"; continue; | 
|  | 594 | case 1: type = "in"; continue; | 
|  | 595 | } | 
|  | 596 | } | 
|  | 597 |  | 
|  | 598 | temp = scnprintf (next, size, | 
|  | 599 | " (%c%d ep%d%s " | 
|  | 600 | "[%d/%d] q%d p%d)", | 
|  | 601 | speed_char (scratch), | 
|  | 602 | scratch & 0x007f, | 
|  | 603 | (scratch >> 8) & 0x000f, type, | 
|  | 604 | p.qh->usecs, p.qh->c_usecs, | 
|  | 605 | temp, | 
|  | 606 | 0x7ff & (scratch >> 16)); | 
|  | 607 |  | 
|  | 608 | if (seen_count < DBG_SCHED_LIMIT) | 
|  | 609 | seen [seen_count++].qh = p.qh; | 
|  | 610 | } else | 
|  | 611 | temp = 0; | 
|  | 612 | if (p.qh) { | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 613 | tag = Q_NEXT_TYPE(ehci, p.qh->hw_next); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | p = p.qh->qh_next; | 
|  | 615 | } | 
|  | 616 | break; | 
|  | 617 | case Q_TYPE_FSTN: | 
|  | 618 | temp = scnprintf (next, size, | 
|  | 619 | " fstn-%8x/%p", p.fstn->hw_prev, | 
|  | 620 | p.fstn); | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 621 | tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | p = p.fstn->fstn_next; | 
|  | 623 | break; | 
|  | 624 | case Q_TYPE_ITD: | 
|  | 625 | temp = scnprintf (next, size, | 
|  | 626 | " itd/%p", p.itd); | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 627 | tag = Q_NEXT_TYPE(ehci, p.itd->hw_next); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | p = p.itd->itd_next; | 
|  | 629 | break; | 
|  | 630 | case Q_TYPE_SITD: | 
|  | 631 | temp = scnprintf (next, size, | 
|  | 632 | " sitd%d-%04x/%p", | 
|  | 633 | p.sitd->stream->interval, | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 634 | hc32_to_cpup(ehci, &p.sitd->hw_uframe) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | & 0x0000ffff, | 
|  | 636 | p.sitd); | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 637 | tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | p = p.sitd->sitd_next; | 
|  | 639 | break; | 
|  | 640 | } | 
|  | 641 | size -= temp; | 
|  | 642 | next += temp; | 
|  | 643 | } while (p.ptr); | 
|  | 644 |  | 
|  | 645 | temp = scnprintf (next, size, "\n"); | 
|  | 646 | size -= temp; | 
|  | 647 | next += temp; | 
|  | 648 | } | 
|  | 649 | spin_unlock_irqrestore (&ehci->lock, flags); | 
|  | 650 | kfree (seen); | 
|  | 651 |  | 
|  | 652 | return PAGE_SIZE - size; | 
|  | 653 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | #undef DBG_SCHED_LIMIT | 
|  | 655 |  | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 656 | static ssize_t fill_registers_buffer(struct debug_buffer *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | struct usb_hcd		*hcd; | 
|  | 659 | struct ehci_hcd		*ehci; | 
|  | 660 | unsigned long		flags; | 
|  | 661 | unsigned		temp, size, i; | 
|  | 662 | char			*next, scratch [80]; | 
|  | 663 | static char		fmt [] = "%*s\n"; | 
|  | 664 | static char		label [] = ""; | 
|  | 665 |  | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 666 | hcd = bus_to_hcd(buf->bus); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | ehci = hcd_to_ehci (hcd); | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 668 | next = buf->page; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | size = PAGE_SIZE; | 
|  | 670 |  | 
|  | 671 | spin_lock_irqsave (&ehci->lock, flags); | 
|  | 672 |  | 
| Alan Stern | 70a1c9e | 2008-03-06 17:00:58 -0500 | [diff] [blame] | 673 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | size = scnprintf (next, size, | 
|  | 675 | "bus %s, device %s (driver " DRIVER_VERSION ")\n" | 
| David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 676 | "%s\n" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | "SUSPENDED (no register access)\n", | 
|  | 678 | hcd->self.controller->bus->name, | 
| Kay Sievers | 7071a3c | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 679 | dev_name(hcd->self.controller), | 
| David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 680 | hcd->product_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | goto done; | 
|  | 682 | } | 
|  | 683 |  | 
|  | 684 | /* Capability Registers */ | 
| Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 685 | i = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | temp = scnprintf (next, size, | 
|  | 687 | "bus %s, device %s (driver " DRIVER_VERSION ")\n" | 
| David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 688 | "%s\n" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | "EHCI %x.%02x, hcd state %d\n", | 
|  | 690 | hcd->self.controller->bus->name, | 
| Kay Sievers | 7071a3c | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 691 | dev_name(hcd->self.controller), | 
| David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 692 | hcd->product_desc, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | i >> 8, i & 0x0ff, hcd->state); | 
|  | 694 | size -= temp; | 
|  | 695 | next += temp; | 
|  | 696 |  | 
| David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 697 | #ifdef	CONFIG_PCI | 
|  | 698 | /* EHCI 0.96 and later may have "extended capabilities" */ | 
|  | 699 | if (hcd->self.controller->bus == &pci_bus_type) { | 
|  | 700 | struct pci_dev	*pdev; | 
|  | 701 | u32		offset, cap, cap2; | 
|  | 702 | unsigned	count = 256/4; | 
|  | 703 |  | 
|  | 704 | pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller); | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 705 | offset = HCC_EXT_CAPS(ehci_readl(ehci, | 
|  | 706 | &ehci->caps->hcc_params)); | 
| David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 707 | while (offset && count--) { | 
|  | 708 | pci_read_config_dword (pdev, offset, &cap); | 
|  | 709 | switch (cap & 0xff) { | 
|  | 710 | case 1: | 
|  | 711 | temp = scnprintf (next, size, | 
|  | 712 | "ownership %08x%s%s\n", cap, | 
|  | 713 | (cap & (1 << 24)) ? " linux" : "", | 
|  | 714 | (cap & (1 << 16)) ? " firmware" : ""); | 
|  | 715 | size -= temp; | 
|  | 716 | next += temp; | 
|  | 717 |  | 
|  | 718 | offset += 4; | 
|  | 719 | pci_read_config_dword (pdev, offset, &cap2); | 
|  | 720 | temp = scnprintf (next, size, | 
|  | 721 | "SMI sts/enable 0x%08x\n", cap2); | 
|  | 722 | size -= temp; | 
|  | 723 | next += temp; | 
|  | 724 | break; | 
|  | 725 | case 0:		/* illegal reserved capability */ | 
|  | 726 | cap = 0; | 
|  | 727 | /* FALLTHROUGH */ | 
|  | 728 | default:		/* unknown */ | 
|  | 729 | break; | 
|  | 730 | } | 
|  | 731 | temp = (cap >> 8) & 0xff; | 
|  | 732 | } | 
|  | 733 | } | 
|  | 734 | #endif | 
|  | 735 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | // FIXME interpret both types of params | 
| Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 737 | i = ehci_readl(ehci, &ehci->caps->hcs_params); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | temp = scnprintf (next, size, "structural params 0x%08x\n", i); | 
|  | 739 | size -= temp; | 
|  | 740 | next += temp; | 
|  | 741 |  | 
| Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 742 | i = ehci_readl(ehci, &ehci->caps->hcc_params); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | temp = scnprintf (next, size, "capability params 0x%08x\n", i); | 
|  | 744 | size -= temp; | 
|  | 745 | next += temp; | 
|  | 746 |  | 
|  | 747 | /* Operational Registers */ | 
|  | 748 | temp = dbg_status_buf (scratch, sizeof scratch, label, | 
| Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 749 | ehci_readl(ehci, &ehci->regs->status)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | temp = scnprintf (next, size, fmt, temp, scratch); | 
|  | 751 | size -= temp; | 
|  | 752 | next += temp; | 
|  | 753 |  | 
|  | 754 | temp = dbg_command_buf (scratch, sizeof scratch, label, | 
| Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 755 | ehci_readl(ehci, &ehci->regs->command)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | temp = scnprintf (next, size, fmt, temp, scratch); | 
|  | 757 | size -= temp; | 
|  | 758 | next += temp; | 
|  | 759 |  | 
|  | 760 | temp = dbg_intr_buf (scratch, sizeof scratch, label, | 
| Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 761 | ehci_readl(ehci, &ehci->regs->intr_enable)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | temp = scnprintf (next, size, fmt, temp, scratch); | 
|  | 763 | size -= temp; | 
|  | 764 | next += temp; | 
|  | 765 |  | 
|  | 766 | temp = scnprintf (next, size, "uframe %04x\n", | 
| Benjamin Herrenschmidt | 083522d | 2006-12-15 06:54:08 +1100 | [diff] [blame] | 767 | ehci_readl(ehci, &ehci->regs->frame_index)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | size -= temp; | 
|  | 769 | next += temp; | 
|  | 770 |  | 
| David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 771 | for (i = 1; i <= HCS_N_PORTS (ehci->hcs_params); i++) { | 
|  | 772 | temp = dbg_port_buf (scratch, sizeof scratch, label, i, | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 773 | ehci_readl(ehci, | 
|  | 774 | &ehci->regs->port_status[i - 1])); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | temp = scnprintf (next, size, fmt, temp, scratch); | 
|  | 776 | size -= temp; | 
|  | 777 | next += temp; | 
| David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 778 | if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) { | 
|  | 779 | temp = scnprintf (next, size, | 
|  | 780 | "    debug control %08x\n", | 
| Stefan Roese | 6dbd682 | 2007-05-01 09:29:37 -0700 | [diff] [blame] | 781 | ehci_readl(ehci, | 
|  | 782 | &ehci->debug->control)); | 
| David Brownell | d49d431 | 2005-05-07 13:21:50 -0700 | [diff] [blame] | 783 | size -= temp; | 
|  | 784 | next += temp; | 
|  | 785 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | } | 
|  | 787 |  | 
|  | 788 | if (ehci->reclaim) { | 
| Alan Stern | 07d29b6 | 2007-12-11 16:05:30 -0500 | [diff] [blame] | 789 | temp = scnprintf(next, size, "reclaim qh %p\n", ehci->reclaim); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | size -= temp; | 
|  | 791 | next += temp; | 
|  | 792 | } | 
|  | 793 |  | 
|  | 794 | #ifdef EHCI_STATS | 
|  | 795 | temp = scnprintf (next, size, | 
|  | 796 | "irq normal %ld err %ld reclaim %ld (lost %ld)\n", | 
|  | 797 | ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim, | 
|  | 798 | ehci->stats.lost_iaa); | 
|  | 799 | size -= temp; | 
|  | 800 | next += temp; | 
|  | 801 |  | 
|  | 802 | temp = scnprintf (next, size, "complete %ld unlink %ld\n", | 
|  | 803 | ehci->stats.complete, ehci->stats.unlink); | 
|  | 804 | size -= temp; | 
|  | 805 | next += temp; | 
|  | 806 | #endif | 
|  | 807 |  | 
|  | 808 | done: | 
|  | 809 | spin_unlock_irqrestore (&ehci->lock, flags); | 
|  | 810 |  | 
|  | 811 | return PAGE_SIZE - size; | 
|  | 812 | } | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 813 |  | 
|  | 814 | static struct debug_buffer *alloc_buffer(struct usb_bus *bus, | 
|  | 815 | ssize_t (*fill_func)(struct debug_buffer *)) | 
|  | 816 | { | 
|  | 817 | struct debug_buffer *buf; | 
|  | 818 |  | 
|  | 819 | buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL); | 
|  | 820 |  | 
|  | 821 | if (buf) { | 
|  | 822 | buf->bus = bus; | 
|  | 823 | buf->fill_func = fill_func; | 
|  | 824 | mutex_init(&buf->mutex); | 
|  | 825 | } | 
|  | 826 |  | 
|  | 827 | return buf; | 
|  | 828 | } | 
|  | 829 |  | 
|  | 830 | static int fill_buffer(struct debug_buffer *buf) | 
|  | 831 | { | 
|  | 832 | int ret = 0; | 
|  | 833 |  | 
|  | 834 | if (!buf->page) | 
|  | 835 | buf->page = (char *)get_zeroed_page(GFP_KERNEL); | 
|  | 836 |  | 
|  | 837 | if (!buf->page) { | 
|  | 838 | ret = -ENOMEM; | 
|  | 839 | goto out; | 
|  | 840 | } | 
|  | 841 |  | 
|  | 842 | ret = buf->fill_func(buf); | 
|  | 843 |  | 
|  | 844 | if (ret >= 0) { | 
|  | 845 | buf->count = ret; | 
|  | 846 | ret = 0; | 
|  | 847 | } | 
|  | 848 |  | 
|  | 849 | out: | 
|  | 850 | return ret; | 
|  | 851 | } | 
|  | 852 |  | 
|  | 853 | static ssize_t debug_output(struct file *file, char __user *user_buf, | 
|  | 854 | size_t len, loff_t *offset) | 
|  | 855 | { | 
|  | 856 | struct debug_buffer *buf = file->private_data; | 
|  | 857 | int ret = 0; | 
|  | 858 |  | 
|  | 859 | mutex_lock(&buf->mutex); | 
|  | 860 | if (buf->count == 0) { | 
|  | 861 | ret = fill_buffer(buf); | 
|  | 862 | if (ret != 0) { | 
|  | 863 | mutex_unlock(&buf->mutex); | 
|  | 864 | goto out; | 
|  | 865 | } | 
|  | 866 | } | 
|  | 867 | mutex_unlock(&buf->mutex); | 
|  | 868 |  | 
|  | 869 | ret = simple_read_from_buffer(user_buf, len, offset, | 
|  | 870 | buf->page, buf->count); | 
|  | 871 |  | 
|  | 872 | out: | 
|  | 873 | return ret; | 
|  | 874 |  | 
|  | 875 | } | 
|  | 876 |  | 
|  | 877 | static int debug_close(struct inode *inode, struct file *file) | 
|  | 878 | { | 
|  | 879 | struct debug_buffer *buf = file->private_data; | 
|  | 880 |  | 
|  | 881 | if (buf) { | 
|  | 882 | if (buf->page) | 
|  | 883 | free_page((unsigned long)buf->page); | 
|  | 884 | kfree(buf); | 
|  | 885 | } | 
|  | 886 |  | 
|  | 887 | return 0; | 
|  | 888 | } | 
|  | 889 | static int debug_async_open(struct inode *inode, struct file *file) | 
|  | 890 | { | 
|  | 891 | file->private_data = alloc_buffer(inode->i_private, fill_async_buffer); | 
|  | 892 |  | 
|  | 893 | return file->private_data ? 0 : -ENOMEM; | 
|  | 894 | } | 
|  | 895 |  | 
|  | 896 | static int debug_periodic_open(struct inode *inode, struct file *file) | 
|  | 897 | { | 
|  | 898 | file->private_data = alloc_buffer(inode->i_private, | 
|  | 899 | fill_periodic_buffer); | 
|  | 900 |  | 
|  | 901 | return file->private_data ? 0 : -ENOMEM; | 
|  | 902 | } | 
|  | 903 |  | 
|  | 904 | static int debug_registers_open(struct inode *inode, struct file *file) | 
|  | 905 | { | 
|  | 906 | file->private_data = alloc_buffer(inode->i_private, | 
|  | 907 | fill_registers_buffer); | 
|  | 908 |  | 
|  | 909 | return file->private_data ? 0 : -ENOMEM; | 
|  | 910 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 |  | 
|  | 912 | static inline void create_debug_files (struct ehci_hcd *ehci) | 
|  | 913 | { | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 914 | struct usb_bus *bus = &ehci_to_hcd(ehci)->self; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 |  | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 916 | ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root); | 
|  | 917 | if (!ehci->debug_dir) | 
|  | 918 | goto dir_error; | 
|  | 919 |  | 
|  | 920 | ehci->debug_async = debugfs_create_file("async", S_IRUGO, | 
|  | 921 | ehci->debug_dir, bus, | 
|  | 922 | &debug_async_fops); | 
|  | 923 | if (!ehci->debug_async) | 
|  | 924 | goto async_error; | 
|  | 925 |  | 
|  | 926 | ehci->debug_periodic = debugfs_create_file("periodic", S_IRUGO, | 
|  | 927 | ehci->debug_dir, bus, | 
|  | 928 | &debug_periodic_fops); | 
|  | 929 | if (!ehci->debug_periodic) | 
|  | 930 | goto periodic_error; | 
|  | 931 |  | 
|  | 932 | ehci->debug_registers = debugfs_create_file("registers", S_IRUGO, | 
|  | 933 | ehci->debug_dir, bus, | 
|  | 934 | &debug_registers_fops); | 
|  | 935 | if (!ehci->debug_registers) | 
|  | 936 | goto registers_error; | 
|  | 937 | return; | 
|  | 938 |  | 
|  | 939 | registers_error: | 
|  | 940 | debugfs_remove(ehci->debug_periodic); | 
|  | 941 | periodic_error: | 
|  | 942 | debugfs_remove(ehci->debug_async); | 
|  | 943 | async_error: | 
|  | 944 | debugfs_remove(ehci->debug_dir); | 
|  | 945 | dir_error: | 
|  | 946 | ehci->debug_periodic = NULL; | 
|  | 947 | ehci->debug_async = NULL; | 
|  | 948 | ehci->debug_dir = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | } | 
|  | 950 |  | 
|  | 951 | static inline void remove_debug_files (struct ehci_hcd *ehci) | 
|  | 952 | { | 
| Tony Jones | 694cc20 | 2007-09-11 14:07:31 -0700 | [diff] [blame] | 953 | debugfs_remove(ehci->debug_registers); | 
|  | 954 | debugfs_remove(ehci->debug_periodic); | 
|  | 955 | debugfs_remove(ehci->debug_async); | 
|  | 956 | debugfs_remove(ehci->debug_dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | } | 
|  | 958 |  | 
|  | 959 | #endif /* STUB_DEBUG_FILES */ |