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