blob: fcbbdfa2576618c5b7626274a842e38af639b53d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2001-2002 by David Brownell
David Brownell53bd6a62006-08-30 14:50:06 -07003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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
Oliver Neukum1c201632013-11-18 13:23:16 +010021#ifdef CONFIG_DYNAMIC_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23/* check the values in the HCSPARAMS register
24 * (host controller _Structural_ parameters)
25 * see EHCI spec, Table 2-4 for each value
26 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030027static void dbg_hcs_params(struct ehci_hcd *ehci, char *label)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +110029 u32 params = ehci_readl(ehci, &ehci->caps->hcs_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030031 ehci_dbg(ehci,
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 "%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n",
33 label, params,
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030034 HCS_DEBUG_PORT(params),
35 HCS_INDICATOR(params) ? " ind" : "",
36 HCS_N_CC(params),
37 HCS_N_PCC(params),
38 HCS_PORTROUTED(params) ? "" : " ordered",
39 HCS_PPC(params) ? "" : " !ppc",
40 HCS_N_PORTS(params)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 );
42 /* Port routing, per EHCI 0.95 Spec, Section 2.2.5 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030043 if (HCS_PORTROUTED(params)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 int i;
45 char buf [46], tmp [7], byte;
46
47 buf[0] = 0;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030048 for (i = 0; i < HCS_N_PORTS(params); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 // FIXME MIPS won't readb() ...
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030050 byte = readb(&ehci->caps->portroute[(i >> 1)]);
David Brownell53bd6a62006-08-30 14:50:06 -070051 sprintf(tmp, "%d ",
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf)));
53 strcat(buf, tmp);
54 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030055 ehci_dbg(ehci, "%s portroute %s\n", label, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 }
57}
58#else
59
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030060static inline void dbg_hcs_params(struct ehci_hcd *ehci, char *label) {}
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#endif
63
Oliver Neukum1c201632013-11-18 13:23:16 +010064#ifdef CONFIG_DYNAMIC_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66/* check the values in the HCCPARAMS register
67 * (host controller _Capability_ parameters)
68 * see EHCI Spec, Table 2-5 for each value
69 * */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030070static void dbg_hcc_params(struct ehci_hcd *ehci, char *label)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +110072 u32 params = ehci_readl(ehci, &ehci->caps->hcc_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030074 if (HCC_ISOC_CACHE(params)) {
75 ehci_dbg(ehci,
Stefan Roese6dbd6822007-05-01 09:29:37 -070076 "%s hcc_params %04x caching frame %s%s%s\n",
77 label, params,
78 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
79 HCC_CANPARK(params) ? " park" : "",
80 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 } else {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030082 ehci_dbg(ehci,
Alek Duaa4d8342010-06-04 15:47:54 +080083 "%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -070084 label,
85 params,
86 HCC_ISOC_THRES(params),
87 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
88 HCC_CANPARK(params) ? " park" : "",
Alek Duaa4d8342010-06-04 15:47:54 +080089 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "",
90 HCC_LPM(params) ? " LPM" : "",
91 HCC_PER_PORT_CHANGE_EVENT(params) ? " ppce" : "",
92 HCC_HW_PREFETCH(params) ? " hw prefetch" : "",
93 HCC_32FRAME_PERIODIC_LIST(params) ?
Masanari Iida855ef452012-02-17 23:06:47 +090094 " 32 periodic list" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
96}
97#else
98
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030099static inline void dbg_hcc_params(struct ehci_hcd *ehci, char *label) {}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101#endif
102
Oliver Neukum1c201632013-11-18 13:23:16 +0100103#ifdef CONFIG_DYNAMIC_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
David Rientjes82345092007-05-11 14:39:44 -0700105static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300106dbg_qtd(const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Stefan Roese6dbd6822007-05-01 09:29:37 -0700108 ehci_dbg(ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
109 hc32_to_cpup(ehci, &qtd->hw_next),
110 hc32_to_cpup(ehci, &qtd->hw_alt_next),
111 hc32_to_cpup(ehci, &qtd->hw_token),
112 hc32_to_cpup(ehci, &qtd->hw_buf [0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 if (qtd->hw_buf [1])
Stefan Roese6dbd6822007-05-01 09:29:37 -0700114 ehci_dbg(ehci, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
115 hc32_to_cpup(ehci, &qtd->hw_buf[1]),
116 hc32_to_cpup(ehci, &qtd->hw_buf[2]),
117 hc32_to_cpup(ehci, &qtd->hw_buf[3]),
118 hc32_to_cpup(ehci, &qtd->hw_buf[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
120
David Rientjes82345092007-05-11 14:39:44 -0700121static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300122dbg_qh(const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Alek Du3807e262009-07-14 07:23:29 +0800124 struct ehci_qh_hw *hw = qh->hw;
125
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300126 ehci_dbg(ehci, "%s qh %p n%08x info %x %x qtd %x\n", label,
Alek Du3807e262009-07-14 07:23:29 +0800127 qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current);
128 dbg_qtd("overlay", ehci, (struct ehci_qtd *) &hw->hw_qtd_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
David Rientjes82345092007-05-11 14:39:44 -0700131static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300132dbg_itd(const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300134 ehci_dbg(ehci, "%s [%d] itd %p, next %08x, urb %p\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700135 label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next),
136 itd->urb);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300137 ehci_dbg(ehci,
David Brownell53bd6a62006-08-30 14:50:06 -0700138 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700139 hc32_to_cpu(ehci, itd->hw_transaction[0]),
140 hc32_to_cpu(ehci, itd->hw_transaction[1]),
141 hc32_to_cpu(ehci, itd->hw_transaction[2]),
142 hc32_to_cpu(ehci, itd->hw_transaction[3]),
143 hc32_to_cpu(ehci, itd->hw_transaction[4]),
144 hc32_to_cpu(ehci, itd->hw_transaction[5]),
145 hc32_to_cpu(ehci, itd->hw_transaction[6]),
146 hc32_to_cpu(ehci, itd->hw_transaction[7]));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300147 ehci_dbg(ehci,
David Brownell53bd6a62006-08-30 14:50:06 -0700148 " buf: %08x %08x %08x %08x %08x %08x %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700149 hc32_to_cpu(ehci, itd->hw_bufp[0]),
150 hc32_to_cpu(ehci, itd->hw_bufp[1]),
151 hc32_to_cpu(ehci, itd->hw_bufp[2]),
152 hc32_to_cpu(ehci, itd->hw_bufp[3]),
153 hc32_to_cpu(ehci, itd->hw_bufp[4]),
154 hc32_to_cpu(ehci, itd->hw_bufp[5]),
155 hc32_to_cpu(ehci, itd->hw_bufp[6]));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300156 ehci_dbg(ehci, " index: %d %d %d %d %d %d %d %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 itd->index[0], itd->index[1], itd->index[2],
158 itd->index[3], itd->index[4], itd->index[5],
159 itd->index[6], itd->index[7]);
160}
161
David Rientjes82345092007-05-11 14:39:44 -0700162static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300163dbg_sitd(const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300165 ehci_dbg(ehci, "%s [%d] sitd %p, next %08x, urb %p\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700166 label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next),
167 sitd->urb);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300168 ehci_dbg(ehci,
David Brownell53bd6a62006-08-30 14:50:06 -0700169 " addr %08x sched %04x result %08x buf %08x %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700170 hc32_to_cpu(ehci, sitd->hw_fullspeed_ep),
171 hc32_to_cpu(ehci, sitd->hw_uframe),
172 hc32_to_cpu(ehci, sitd->hw_results),
173 hc32_to_cpu(ehci, sitd->hw_buf[0]),
174 hc32_to_cpu(ehci, sitd->hw_buf[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175}
176
David Rientjes82345092007-05-11 14:39:44 -0700177static int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300178dbg_status_buf(char *buf, unsigned len, const char *label, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300180 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800181 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 label, label [0] ? " " : "", status,
Alek Duaa4d8342010-06-04 15:47:54 +0800183 (status & STS_PPCE_MASK) ? " PPCE" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 (status & STS_ASS) ? " Async" : "",
185 (status & STS_PSS) ? " Periodic" : "",
186 (status & STS_RECL) ? " Recl" : "",
187 (status & STS_HALT) ? " Halt" : "",
188 (status & STS_IAA) ? " IAA" : "",
189 (status & STS_FATAL) ? " FATAL" : "",
190 (status & STS_FLR) ? " FLR" : "",
191 (status & STS_PCD) ? " PCD" : "",
192 (status & STS_ERR) ? " ERR" : "",
193 (status & STS_INT) ? " INT" : ""
194 );
195}
196
David Rientjes82345092007-05-11 14:39:44 -0700197static int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300198dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300200 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800201 "%s%sintrenable %02x%s%s%s%s%s%s%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 label, label [0] ? " " : "", enable,
Alek Duaa4d8342010-06-04 15:47:54 +0800203 (enable & STS_PPCE_MASK) ? " PPCE" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 (enable & STS_IAA) ? " IAA" : "",
205 (enable & STS_FATAL) ? " FATAL" : "",
206 (enable & STS_FLR) ? " FLR" : "",
207 (enable & STS_PCD) ? " PCD" : "",
208 (enable & STS_ERR) ? " ERR" : "",
209 (enable & STS_INT) ? " INT" : ""
210 );
211}
212
213static const char *const fls_strings [] =
214 { "1024", "512", "256", "??" };
215
216static int
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300217dbg_command_buf(char *buf, unsigned len, const char *label, u32 command)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300219 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800220 "%s%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s "
221 "period=%s%s %s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 label, label [0] ? " " : "", command,
Alek Duaa4d8342010-06-04 15:47:54 +0800223 (command & CMD_HIRD) ? " HIRD" : "",
224 (command & CMD_PPCEE) ? " PPCEE" : "",
225 (command & CMD_FSP) ? " FSP" : "",
226 (command & CMD_ASPE) ? " ASPE" : "",
227 (command & CMD_PSPE) ? " PSPE" : "",
228 (command & CMD_PARK) ? " park" : "(park)",
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300229 CMD_PARK_CNT(command),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 (command >> 16) & 0x3f,
231 (command & CMD_LRESET) ? " LReset" : "",
232 (command & CMD_IAAD) ? " IAAD" : "",
233 (command & CMD_ASE) ? " Async" : "",
234 (command & CMD_PSE) ? " Periodic" : "",
235 fls_strings [(command >> 2) & 0x3],
236 (command & CMD_RESET) ? " Reset" : "",
237 (command & CMD_RUN) ? "RUN" : "HALT"
238 );
239}
240
241static int
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300242dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
244 char *sig;
245
246 /* signaling state */
247 switch (status & (3 << 10)) {
248 case 0 << 10: sig = "se0"; break;
249 case 1 << 10: sig = "k"; break; /* low speed */
250 case 2 << 10: sig = "j"; break;
251 default: sig = "?"; break;
252 }
253
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300254 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800255 "%s%sport:%d status %06x %d %s%s%s%s%s%s "
256 "sig=%s%s%s%s%s%s%s%s%s%s%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 label, label [0] ? " " : "", port, status,
Alek Duaa4d8342010-06-04 15:47:54 +0800258 status>>25,/*device address */
259 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ACK ?
260 " ACK" : "",
261 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_NYET ?
262 " NYET" : "",
263 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_STALL ?
264 " STALL" : "",
265 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ERR ?
266 " ERR" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 (status & PORT_POWER) ? " POWER" : "",
268 (status & PORT_OWNER) ? " OWNER" : "",
269 sig,
Alek Duaa4d8342010-06-04 15:47:54 +0800270 (status & PORT_LPM) ? " LPM" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 (status & PORT_RESET) ? " RESET" : "",
272 (status & PORT_SUSPEND) ? " SUSPEND" : "",
273 (status & PORT_RESUME) ? " RESUME" : "",
274 (status & PORT_OCC) ? " OCC" : "",
275 (status & PORT_OC) ? " OC" : "",
276 (status & PORT_PEC) ? " PEC" : "",
277 (status & PORT_PE) ? " PE" : "",
278 (status & PORT_CSC) ? " CSC" : "",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700279 (status & PORT_CONNECT) ? " CONNECT" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
282#else
David Rientjes82345092007-05-11 14:39:44 -0700283static inline void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300284dbg_qh(char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{}
286
David Rientjes82345092007-05-11 14:39:44 -0700287static inline int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300288dbg_status_buf(char *buf, unsigned len, const char *label, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{ return 0; }
290
David Rientjes82345092007-05-11 14:39:44 -0700291static inline int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300292dbg_command_buf(char *buf, unsigned len, const char *label, u32 command)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{ return 0; }
294
David Rientjes82345092007-05-11 14:39:44 -0700295static inline int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300296dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{ return 0; }
298
David Rientjes82345092007-05-11 14:39:44 -0700299static inline int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300300dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{ return 0; }
302
Oliver Neukum1c201632013-11-18 13:23:16 +0100303#endif /* CONFIG_DYNAMIC_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305/* functions have the "wrong" filename when they're output... */
306#define dbg_status(ehci, label, status) { \
307 char _buf [80]; \
308 dbg_status_buf (_buf, sizeof _buf, label, status); \
309 ehci_dbg (ehci, "%s\n", _buf); \
310}
311
312#define dbg_cmd(ehci, label, command) { \
313 char _buf [80]; \
314 dbg_command_buf (_buf, sizeof _buf, label, command); \
315 ehci_dbg (ehci, "%s\n", _buf); \
316}
317
318#define dbg_port(ehci, label, port, status) { \
319 char _buf [80]; \
320 dbg_port_buf (_buf, sizeof _buf, label, port, status); \
321 ehci_dbg (ehci, "%s\n", _buf); \
322}
323
324/*-------------------------------------------------------------------------*/
325
326#ifdef STUB_DEBUG_FILES
327
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300328static inline void create_debug_files(struct ehci_hcd *bus) { }
329static inline void remove_debug_files(struct ehci_hcd *bus) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331#else
332
Tony Jones694cc202007-09-11 14:07:31 -0700333/* troubleshooting help: expose state in debugfs */
334
335static int debug_async_open(struct inode *, struct file *);
Alan Sternd0ce5c62013-10-11 11:29:13 -0400336static int debug_bandwidth_open(struct inode *, struct file *);
Tony Jones694cc202007-09-11 14:07:31 -0700337static int debug_periodic_open(struct inode *, struct file *);
338static int debug_registers_open(struct inode *, struct file *);
Alek Duaa4d8342010-06-04 15:47:54 +0800339
Tony Jones694cc202007-09-11 14:07:31 -0700340static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
341static int debug_close(struct inode *, struct file *);
342
343static const struct file_operations debug_async_fops = {
344 .owner = THIS_MODULE,
345 .open = debug_async_open,
346 .read = debug_output,
347 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200348 .llseek = default_llseek,
Tony Jones694cc202007-09-11 14:07:31 -0700349};
Alan Sternd0ce5c62013-10-11 11:29:13 -0400350static const struct file_operations debug_bandwidth_fops = {
351 .owner = THIS_MODULE,
352 .open = debug_bandwidth_open,
353 .read = debug_output,
354 .release = debug_close,
355 .llseek = default_llseek,
356};
Tony Jones694cc202007-09-11 14:07:31 -0700357static const struct file_operations debug_periodic_fops = {
358 .owner = THIS_MODULE,
359 .open = debug_periodic_open,
360 .read = debug_output,
361 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200362 .llseek = default_llseek,
Tony Jones694cc202007-09-11 14:07:31 -0700363};
364static const struct file_operations debug_registers_fops = {
365 .owner = THIS_MODULE,
366 .open = debug_registers_open,
367 .read = debug_output,
368 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200369 .llseek = default_llseek,
Tony Jones694cc202007-09-11 14:07:31 -0700370};
371
372static struct dentry *ehci_debug_root;
373
374struct debug_buffer {
375 ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
376 struct usb_bus *bus;
377 struct mutex mutex; /* protect filling of buffer */
378 size_t count; /* number of characters filled into buffer */
Ming Lei3c04e202008-09-18 23:06:21 +0800379 char *output_buf;
380 size_t alloc_size;
Tony Jones694cc202007-09-11 14:07:31 -0700381};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383#define speed_char(info1) ({ char tmp; \
384 switch (info1 & (3 << 12)) { \
Alan Stern4c53de72012-07-11 11:21:32 -0400385 case QH_FULL_SPEED: tmp = 'f'; break; \
386 case QH_LOW_SPEED: tmp = 'l'; break; \
387 case QH_HIGH_SPEED: tmp = 'h'; break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 default: tmp = '?'; break; \
Joe Perches2b84f922013-10-08 16:01:37 -0700389 } tmp; })
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Stefan Roese6dbd6822007-05-01 09:29:37 -0700391static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
Stefan Roese6dbd6822007-05-01 09:29:37 -0700393 __u32 v = hc32_to_cpu(ehci, token);
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (v & QTD_STS_ACTIVE)
396 return '*';
397 if (v & QTD_STS_HALT)
398 return '-';
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300399 if (!IS_SHORT_READ(v))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 return ' ';
401 /* tries to advance through hw_alt_next */
402 return '/';
403}
404
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300405static void qh_lines(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 struct ehci_hcd *ehci,
407 struct ehci_qh *qh,
408 char **nextp,
409 unsigned *sizep
410)
411{
412 u32 scratch;
413 u32 hw_curr;
414 struct list_head *entry;
415 struct ehci_qtd *td;
416 unsigned temp;
417 unsigned size = *sizep;
418 char *next = *nextp;
419 char mark;
Al Virofd05e722008-04-28 07:00:16 +0100420 __le32 list_end = EHCI_LIST_END(ehci);
Alek Du3807e262009-07-14 07:23:29 +0800421 struct ehci_qh_hw *hw = qh->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Alek Du3807e262009-07-14 07:23:29 +0800423 if (hw->hw_qtd_next == list_end) /* NEC does this */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 mark = '@';
425 else
Alek Du3807e262009-07-14 07:23:29 +0800426 mark = token_mark(ehci, hw->hw_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 if (mark == '/') { /* qh_alt_next controls qh advance? */
Alek Du3807e262009-07-14 07:23:29 +0800428 if ((hw->hw_alt_next & QTD_MASK(ehci))
429 == ehci->async->hw->hw_alt_next)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 mark = '#'; /* blocked */
Alek Du3807e262009-07-14 07:23:29 +0800431 else if (hw->hw_alt_next == list_end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 mark = '.'; /* use hw_qtd_next */
433 /* else alt_next points to some other qtd */
434 }
Alek Du3807e262009-07-14 07:23:29 +0800435 scratch = hc32_to_cpup(ehci, &hw->hw_info1);
436 hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300437 temp = scnprintf(next, size,
Alan Stern8ee10d62015-11-20 13:53:45 -0500438 "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)"
439 " [cur %08x next %08x buf[0] %08x]",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 qh, scratch & 0x007f,
441 speed_char (scratch),
442 (scratch >> 8) & 0x000f,
Alek Du3807e262009-07-14 07:23:29 +0800443 scratch, hc32_to_cpup(ehci, &hw->hw_info2),
444 hc32_to_cpup(ehci, &hw->hw_token), mark,
445 (cpu_to_hc32(ehci, QTD_TOGGLE) & hw->hw_token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 ? "data1" : "data0",
Alan Stern8ee10d62015-11-20 13:53:45 -0500447 (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f,
448 hc32_to_cpup(ehci, &hw->hw_current),
449 hc32_to_cpup(ehci, &hw->hw_qtd_next),
450 hc32_to_cpup(ehci, &hw->hw_buf[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 size -= temp;
452 next += temp;
453
454 /* hc may be modifying the list as we read it ... */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300455 list_for_each(entry, &qh->qtd_list) {
456 td = list_entry(entry, struct ehci_qtd, qtd_list);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700457 scratch = hc32_to_cpup(ehci, &td->hw_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 mark = ' ';
459 if (hw_curr == td->qtd_dma)
460 mark = '*';
Alek Du3807e262009-07-14 07:23:29 +0800461 else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 mark = '+';
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300463 else if (QTD_LENGTH(scratch)) {
Alek Du3807e262009-07-14 07:23:29 +0800464 if (td->hw_alt_next == ehci->async->hw->hw_alt_next)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 mark = '#';
Stefan Roese6dbd6822007-05-01 09:29:37 -0700466 else if (td->hw_alt_next != list_end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 mark = '/';
468 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300469 temp = snprintf(next, size,
Alan Stern8ee10d62015-11-20 13:53:45 -0500470 "\n\t%p%c%s len=%d %08x urb %p"
471 " [td %08x buf[0] %08x]",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 td, mark, ({ char *tmp;
473 switch ((scratch>>8)&0x03) {
474 case 0: tmp = "out"; break;
475 case 1: tmp = "in"; break;
476 case 2: tmp = "setup"; break;
477 default: tmp = "?"; break;
478 } tmp;}),
479 (scratch >> 16) & 0x7fff,
480 scratch,
Alan Stern8ee10d62015-11-20 13:53:45 -0500481 td->urb,
482 (u32) td->qtd_dma,
483 hc32_to_cpup(ehci, &td->hw_buf[0]));
roel kluine64a5212008-10-21 00:47:23 -0400484 if (size < temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 temp = size;
486 size -= temp;
487 next += temp;
488 if (temp == size)
489 goto done;
490 }
491
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300492 temp = snprintf(next, size, "\n");
roel kluine64a5212008-10-21 00:47:23 -0400493 if (size < temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 temp = size;
495 size -= temp;
496 next += temp;
497
498done:
499 *sizep = size;
500 *nextp = next;
501}
502
Tony Jones694cc202007-09-11 14:07:31 -0700503static ssize_t fill_async_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 struct usb_hcd *hcd;
506 struct ehci_hcd *ehci;
507 unsigned long flags;
508 unsigned temp, size;
509 char *next;
510 struct ehci_qh *qh;
511
Tony Jones694cc202007-09-11 14:07:31 -0700512 hcd = bus_to_hcd(buf->bus);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300513 ehci = hcd_to_ehci(hcd);
Ming Lei3c04e202008-09-18 23:06:21 +0800514 next = buf->output_buf;
515 size = buf->alloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Tony Jones694cc202007-09-11 14:07:31 -0700517 *next = 0;
518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 /* dumps a snapshot of the async schedule.
520 * usually empty except for long-term bulk reads, or head.
521 * one QH per line, and TDs we know about
522 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300523 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300525 qh_lines(ehci, qh, &next, &size);
Alan Stern6e018752013-03-22 13:31:45 -0400526 if (!list_empty(&ehci->async_unlink) && size > 0) {
Alan Stern99ac5b12012-07-11 11:21:38 -0400527 temp = scnprintf(next, size, "\nunlink =\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 size -= temp;
529 next += temp;
530
Alan Stern6e018752013-03-22 13:31:45 -0400531 list_for_each_entry(qh, &ehci->async_unlink, unlink_node) {
532 if (size <= 0)
533 break;
534 qh_lines(ehci, qh, &next, &size);
535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300537 spin_unlock_irqrestore(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Ming Lei3c04e202008-09-18 23:06:21 +0800539 return strlen(buf->output_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Alan Sternd0ce5c62013-10-11 11:29:13 -0400542static ssize_t fill_bandwidth_buffer(struct debug_buffer *buf)
543{
544 struct ehci_hcd *ehci;
Alan Sternb35c5002013-10-11 22:16:21 -0400545 struct ehci_tt *tt;
546 struct ehci_per_sched *ps;
Alan Sternd0ce5c62013-10-11 11:29:13 -0400547 unsigned temp, size;
548 char *next;
549 unsigned i;
550 u8 *bw;
Alan Sternb35c5002013-10-11 22:16:21 -0400551 u16 *bf;
552 u8 budget[EHCI_BANDWIDTH_SIZE];
Alan Sternd0ce5c62013-10-11 11:29:13 -0400553
554 ehci = hcd_to_ehci(bus_to_hcd(buf->bus));
555 next = buf->output_buf;
556 size = buf->alloc_size;
557
558 *next = 0;
559
560 spin_lock_irq(&ehci->lock);
561
562 /* Dump the HS bandwidth table */
563 temp = scnprintf(next, size,
564 "HS bandwidth allocation (us per microframe)\n");
565 size -= temp;
566 next += temp;
567 for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
568 bw = &ehci->bandwidth[i];
569 temp = scnprintf(next, size,
570 "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
571 i, bw[0], bw[1], bw[2], bw[3],
572 bw[4], bw[5], bw[6], bw[7]);
573 size -= temp;
574 next += temp;
575 }
Alan Sternb35c5002013-10-11 22:16:21 -0400576
577 /* Dump all the FS/LS tables */
578 list_for_each_entry(tt, &ehci->tt_list, tt_list) {
579 temp = scnprintf(next, size,
580 "\nTT %s port %d FS/LS bandwidth allocation (us per frame)\n",
581 dev_name(&tt->usb_tt->hub->dev),
582 tt->tt_port + !!tt->usb_tt->multi);
583 size -= temp;
584 next += temp;
585
586 bf = tt->bandwidth;
587 temp = scnprintf(next, size,
588 " %5u%5u%5u%5u%5u%5u%5u%5u\n",
589 bf[0], bf[1], bf[2], bf[3],
590 bf[4], bf[5], bf[6], bf[7]);
591 size -= temp;
592 next += temp;
593
594 temp = scnprintf(next, size,
595 "FS/LS budget (us per microframe)\n");
596 size -= temp;
597 next += temp;
598 compute_tt_budget(budget, tt);
599 for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
600 bw = &budget[i];
601 temp = scnprintf(next, size,
602 "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
603 i, bw[0], bw[1], bw[2], bw[3],
604 bw[4], bw[5], bw[6], bw[7]);
605 size -= temp;
606 next += temp;
607 }
608 list_for_each_entry(ps, &tt->ps_list, ps_list) {
609 temp = scnprintf(next, size,
610 "%s ep %02x: %4u @ %2u.%u+%u mask %04x\n",
611 dev_name(&ps->udev->dev),
612 ps->ep->desc.bEndpointAddress,
613 ps->tt_usecs,
614 ps->bw_phase, ps->phase_uf,
615 ps->bw_period, ps->cs_mask);
616 size -= temp;
617 next += temp;
618 }
619 }
Alan Sternd0ce5c62013-10-11 11:29:13 -0400620 spin_unlock_irq(&ehci->lock);
621
622 return next - buf->output_buf;
623}
624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#define DBG_SCHED_LIMIT 64
Tony Jones694cc202007-09-11 14:07:31 -0700626static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 struct usb_hcd *hcd;
629 struct ehci_hcd *ehci;
630 unsigned long flags;
631 union ehci_shadow p, *seen;
632 unsigned temp, size, seen_count;
633 char *next;
634 unsigned i;
Stefan Roese6dbd6822007-05-01 09:29:37 -0700635 __hc32 tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Greg Kroah-Hartman911fdb62015-04-30 11:32:50 +0200637 seen = kmalloc(DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC);
638 if (!seen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 return 0;
640 seen_count = 0;
641
Tony Jones694cc202007-09-11 14:07:31 -0700642 hcd = bus_to_hcd(buf->bus);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300643 ehci = hcd_to_ehci(hcd);
Ming Lei3c04e202008-09-18 23:06:21 +0800644 next = buf->output_buf;
645 size = buf->alloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300647 temp = scnprintf(next, size, "size = %d\n", ehci->periodic_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 size -= temp;
649 next += temp;
650
651 /* dump a snapshot of the periodic schedule.
652 * iso changes, interrupt usually doesn't.
653 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300654 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 for (i = 0; i < ehci->periodic_size; i++) {
656 p = ehci->pshadow [i];
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300657 if (likely(!p.ptr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 continue;
Stefan Roese6dbd6822007-05-01 09:29:37 -0700659 tag = Q_NEXT_TYPE(ehci, ehci->periodic [i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300661 temp = scnprintf(next, size, "%4d: ", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 size -= temp;
663 next += temp;
664
665 do {
Alek Du3807e262009-07-14 07:23:29 +0800666 struct ehci_qh_hw *hw;
667
Stefan Roese6dbd6822007-05-01 09:29:37 -0700668 switch (hc32_to_cpu(ehci, tag)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 case Q_TYPE_QH:
Alek Du3807e262009-07-14 07:23:29 +0800670 hw = p.qh->hw;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300671 temp = scnprintf(next, size, " qh%d-%04x/%p",
Alan Sternffa02482013-10-11 11:29:03 -0400672 p.qh->ps.period,
Stefan Roese6dbd6822007-05-01 09:29:37 -0700673 hc32_to_cpup(ehci,
Alek Du3807e262009-07-14 07:23:29 +0800674 &hw->hw_info2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 /* uframe masks */
David Brownell7dedacf2005-08-04 18:06:41 -0700676 & (QH_CMASK | QH_SMASK),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 p.qh);
678 size -= temp;
679 next += temp;
680 /* don't repeat what follows this qh */
681 for (temp = 0; temp < seen_count; temp++) {
682 if (seen [temp].ptr != p.ptr)
683 continue;
Ming Lei3c4bb712008-09-18 23:06:38 +0800684 if (p.qh->qh_next.ptr) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300685 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 " ...");
Ming Lei3c4bb712008-09-18 23:06:38 +0800687 size -= temp;
688 next += temp;
689 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 break;
691 }
692 /* show more info the first time around */
Ming Lei3c4bb712008-09-18 23:06:38 +0800693 if (temp == seen_count) {
Stefan Roese6dbd6822007-05-01 09:29:37 -0700694 u32 scratch = hc32_to_cpup(ehci,
Alek Du3807e262009-07-14 07:23:29 +0800695 &hw->hw_info1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 struct ehci_qtd *qtd;
697 char *type = "";
698
699 /* count tds, get ep direction */
700 temp = 0;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300701 list_for_each_entry(qtd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 &p.qh->qtd_list,
703 qtd_list) {
704 temp++;
Stefan Roese6dbd6822007-05-01 09:29:37 -0700705 switch (0x03 & (hc32_to_cpu(
706 ehci,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 qtd->hw_token) >> 8)) {
708 case 0: type = "out"; continue;
709 case 1: type = "in"; continue;
710 }
711 }
712
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300713 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 " (%c%d ep%d%s "
715 "[%d/%d] q%d p%d)",
716 speed_char (scratch),
717 scratch & 0x007f,
718 (scratch >> 8) & 0x000f, type,
Alan Sternffa02482013-10-11 11:29:03 -0400719 p.qh->ps.usecs,
720 p.qh->ps.c_usecs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 temp,
722 0x7ff & (scratch >> 16));
723
724 if (seen_count < DBG_SCHED_LIMIT)
725 seen [seen_count++].qh = p.qh;
726 } else
727 temp = 0;
Alan Stern17dcfc92012-09-19 17:00:55 -0400728 tag = Q_NEXT_TYPE(ehci, hw->hw_next);
729 p = p.qh->qh_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 break;
731 case Q_TYPE_FSTN:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300732 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 " fstn-%8x/%p", p.fstn->hw_prev,
734 p.fstn);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700735 tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 p = p.fstn->fstn_next;
737 break;
738 case Q_TYPE_ITD:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300739 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 " itd/%p", p.itd);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700741 tag = Q_NEXT_TYPE(ehci, p.itd->hw_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 p = p.itd->itd_next;
743 break;
744 case Q_TYPE_SITD:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300745 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 " sitd%d-%04x/%p",
Alan Sternffa02482013-10-11 11:29:03 -0400747 p.sitd->stream->ps.period,
Stefan Roese6dbd6822007-05-01 09:29:37 -0700748 hc32_to_cpup(ehci, &p.sitd->hw_uframe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 & 0x0000ffff,
750 p.sitd);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700751 tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 p = p.sitd->sitd_next;
753 break;
754 }
755 size -= temp;
756 next += temp;
757 } while (p.ptr);
758
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300759 temp = scnprintf(next, size, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 size -= temp;
761 next += temp;
762 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300763 spin_unlock_irqrestore(&ehci->lock, flags);
764 kfree(seen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Ming Lei3c04e202008-09-18 23:06:21 +0800766 return buf->alloc_size - size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768#undef DBG_SCHED_LIMIT
769
Alan Sterne8799902011-08-18 16:31:30 -0400770static const char *rh_state_string(struct ehci_hcd *ehci)
771{
772 switch (ehci->rh_state) {
773 case EHCI_RH_HALTED:
774 return "halted";
775 case EHCI_RH_SUSPENDED:
776 return "suspended";
777 case EHCI_RH_RUNNING:
778 return "running";
Alan Sternc0c53db2012-07-11 11:21:48 -0400779 case EHCI_RH_STOPPING:
780 return "stopping";
Alan Sterne8799902011-08-18 16:31:30 -0400781 }
782 return "?";
783}
784
Tony Jones694cc202007-09-11 14:07:31 -0700785static ssize_t fill_registers_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 struct usb_hcd *hcd;
788 struct ehci_hcd *ehci;
789 unsigned long flags;
790 unsigned temp, size, i;
791 char *next, scratch [80];
792 static char fmt [] = "%*s\n";
793 static char label [] = "";
794
Tony Jones694cc202007-09-11 14:07:31 -0700795 hcd = bus_to_hcd(buf->bus);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300796 ehci = hcd_to_ehci(hcd);
Ming Lei3c04e202008-09-18 23:06:21 +0800797 next = buf->output_buf;
798 size = buf->alloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300800 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Alan Stern541c7d42010-06-22 16:39:10 -0400802 if (!HCD_HW_ACCESSIBLE(hcd)) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300803 size = scnprintf(next, size,
Alan Stern2b70f072008-10-02 11:47:15 -0400804 "bus %s, device %s\n"
David Brownelld49d4312005-05-07 13:21:50 -0700805 "%s\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 "SUSPENDED (no register access)\n",
807 hcd->self.controller->bus->name,
Kay Sievers7071a3c2008-05-02 06:02:41 +0200808 dev_name(hcd->self.controller),
David Brownelld49d4312005-05-07 13:21:50 -0700809 hcd->product_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 goto done;
811 }
812
813 /* Capability Registers */
Jan Anderssonc4301312011-05-03 20:11:57 +0200814 i = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300815 temp = scnprintf(next, size,
Alan Stern2b70f072008-10-02 11:47:15 -0400816 "bus %s, device %s\n"
David Brownelld49d4312005-05-07 13:21:50 -0700817 "%s\n"
Alan Sterne8799902011-08-18 16:31:30 -0400818 "EHCI %x.%02x, rh state %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 hcd->self.controller->bus->name,
Kay Sievers7071a3c2008-05-02 06:02:41 +0200820 dev_name(hcd->self.controller),
David Brownelld49d4312005-05-07 13:21:50 -0700821 hcd->product_desc,
Alan Sterne8799902011-08-18 16:31:30 -0400822 i >> 8, i & 0x0ff, rh_state_string(ehci));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 size -= temp;
824 next += temp;
825
David Brownelld49d4312005-05-07 13:21:50 -0700826#ifdef CONFIG_PCI
827 /* EHCI 0.96 and later may have "extended capabilities" */
Yijing Wange10e6f42013-12-05 19:21:32 +0800828 if (dev_is_pci(hcd->self.controller)) {
David Brownelld49d4312005-05-07 13:21:50 -0700829 struct pci_dev *pdev;
830 u32 offset, cap, cap2;
831 unsigned count = 256/4;
832
833 pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700834 offset = HCC_EXT_CAPS(ehci_readl(ehci,
835 &ehci->caps->hcc_params));
David Brownelld49d4312005-05-07 13:21:50 -0700836 while (offset && count--) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300837 pci_read_config_dword(pdev, offset, &cap);
David Brownelld49d4312005-05-07 13:21:50 -0700838 switch (cap & 0xff) {
839 case 1:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300840 temp = scnprintf(next, size,
David Brownelld49d4312005-05-07 13:21:50 -0700841 "ownership %08x%s%s\n", cap,
842 (cap & (1 << 24)) ? " linux" : "",
843 (cap & (1 << 16)) ? " firmware" : "");
844 size -= temp;
845 next += temp;
846
847 offset += 4;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300848 pci_read_config_dword(pdev, offset, &cap2);
849 temp = scnprintf(next, size,
David Brownelld49d4312005-05-07 13:21:50 -0700850 "SMI sts/enable 0x%08x\n", cap2);
851 size -= temp;
852 next += temp;
853 break;
854 case 0: /* illegal reserved capability */
855 cap = 0;
856 /* FALLTHROUGH */
857 default: /* unknown */
858 break;
859 }
860 temp = (cap >> 8) & 0xff;
861 }
862 }
863#endif
864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 // FIXME interpret both types of params
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100866 i = ehci_readl(ehci, &ehci->caps->hcs_params);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300867 temp = scnprintf(next, size, "structural params 0x%08x\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 size -= temp;
869 next += temp;
870
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100871 i = ehci_readl(ehci, &ehci->caps->hcc_params);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300872 temp = scnprintf(next, size, "capability params 0x%08x\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 size -= temp;
874 next += temp;
875
876 /* Operational Registers */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300877 temp = dbg_status_buf(scratch, sizeof(scratch), label,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100878 ehci_readl(ehci, &ehci->regs->status));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300879 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 size -= temp;
881 next += temp;
882
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300883 temp = dbg_command_buf(scratch, sizeof(scratch), label,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100884 ehci_readl(ehci, &ehci->regs->command));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300885 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 size -= temp;
887 next += temp;
888
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300889 temp = dbg_intr_buf(scratch, sizeof(scratch), label,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100890 ehci_readl(ehci, &ehci->regs->intr_enable));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300891 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 size -= temp;
893 next += temp;
894
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300895 temp = scnprintf(next, size, "uframe %04x\n",
Alan Stern68aa95d2011-10-12 10:39:14 -0400896 ehci_read_frame_index(ehci));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 size -= temp;
898 next += temp;
899
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300900 for (i = 1; i <= HCS_N_PORTS(ehci->hcs_params); i++) {
901 temp = dbg_port_buf(scratch, sizeof(scratch), label, i,
Stefan Roese6dbd6822007-05-01 09:29:37 -0700902 ehci_readl(ehci,
903 &ehci->regs->port_status[i - 1]));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300904 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 size -= temp;
906 next += temp;
David Brownelld49d4312005-05-07 13:21:50 -0700907 if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300908 temp = scnprintf(next, size,
David Brownelld49d4312005-05-07 13:21:50 -0700909 " debug control %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700910 ehci_readl(ehci,
911 &ehci->debug->control));
David Brownelld49d4312005-05-07 13:21:50 -0700912 size -= temp;
913 next += temp;
914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 }
916
Alan Stern6e018752013-03-22 13:31:45 -0400917 if (!list_empty(&ehci->async_unlink)) {
Alan Stern99ac5b12012-07-11 11:21:38 -0400918 temp = scnprintf(next, size, "async unlink qh %p\n",
Alan Stern6e018752013-03-22 13:31:45 -0400919 list_first_entry(&ehci->async_unlink,
920 struct ehci_qh, unlink_node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 size -= temp;
922 next += temp;
923 }
924
925#ifdef EHCI_STATS
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300926 temp = scnprintf(next, size,
Alan Stern99ac5b12012-07-11 11:21:38 -0400927 "irq normal %ld err %ld iaa %ld (lost %ld)\n",
928 ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 ehci->stats.lost_iaa);
930 size -= temp;
931 next += temp;
932
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300933 temp = scnprintf(next, size, "complete %ld unlink %ld\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 ehci->stats.complete, ehci->stats.unlink);
935 size -= temp;
936 next += temp;
937#endif
938
939done:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300940 spin_unlock_irqrestore(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Ming Lei3c04e202008-09-18 23:06:21 +0800942 return buf->alloc_size - size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943}
Tony Jones694cc202007-09-11 14:07:31 -0700944
945static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
946 ssize_t (*fill_func)(struct debug_buffer *))
947{
948 struct debug_buffer *buf;
949
950 buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
951
952 if (buf) {
953 buf->bus = bus;
954 buf->fill_func = fill_func;
955 mutex_init(&buf->mutex);
Ming Lei3c04e202008-09-18 23:06:21 +0800956 buf->alloc_size = PAGE_SIZE;
Tony Jones694cc202007-09-11 14:07:31 -0700957 }
958
959 return buf;
960}
961
962static int fill_buffer(struct debug_buffer *buf)
963{
964 int ret = 0;
965
Ming Lei3c04e202008-09-18 23:06:21 +0800966 if (!buf->output_buf)
Jesper Juhl73f35c62010-11-09 00:10:52 +0100967 buf->output_buf = vmalloc(buf->alloc_size);
Tony Jones694cc202007-09-11 14:07:31 -0700968
Ming Lei3c04e202008-09-18 23:06:21 +0800969 if (!buf->output_buf) {
Tony Jones694cc202007-09-11 14:07:31 -0700970 ret = -ENOMEM;
971 goto out;
972 }
973
974 ret = buf->fill_func(buf);
975
976 if (ret >= 0) {
977 buf->count = ret;
978 ret = 0;
979 }
980
981out:
982 return ret;
983}
984
985static ssize_t debug_output(struct file *file, char __user *user_buf,
986 size_t len, loff_t *offset)
987{
988 struct debug_buffer *buf = file->private_data;
989 int ret = 0;
990
991 mutex_lock(&buf->mutex);
992 if (buf->count == 0) {
993 ret = fill_buffer(buf);
994 if (ret != 0) {
995 mutex_unlock(&buf->mutex);
996 goto out;
997 }
998 }
999 mutex_unlock(&buf->mutex);
1000
1001 ret = simple_read_from_buffer(user_buf, len, offset,
Ming Lei3c04e202008-09-18 23:06:21 +08001002 buf->output_buf, buf->count);
Tony Jones694cc202007-09-11 14:07:31 -07001003
1004out:
1005 return ret;
1006
1007}
1008
1009static int debug_close(struct inode *inode, struct file *file)
1010{
1011 struct debug_buffer *buf = file->private_data;
1012
1013 if (buf) {
Figo.zhangf8086a02009-06-06 20:31:49 +08001014 vfree(buf->output_buf);
Tony Jones694cc202007-09-11 14:07:31 -07001015 kfree(buf);
1016 }
1017
1018 return 0;
1019}
Alan Sternd0ce5c62013-10-11 11:29:13 -04001020
Tony Jones694cc202007-09-11 14:07:31 -07001021static int debug_async_open(struct inode *inode, struct file *file)
1022{
1023 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
1024
1025 return file->private_data ? 0 : -ENOMEM;
1026}
1027
Alan Sternd0ce5c62013-10-11 11:29:13 -04001028static int debug_bandwidth_open(struct inode *inode, struct file *file)
1029{
1030 file->private_data = alloc_buffer(inode->i_private,
1031 fill_bandwidth_buffer);
1032
1033 return file->private_data ? 0 : -ENOMEM;
1034}
1035
Tony Jones694cc202007-09-11 14:07:31 -07001036static int debug_periodic_open(struct inode *inode, struct file *file)
1037{
Ming Lei3c04e202008-09-18 23:06:21 +08001038 struct debug_buffer *buf;
1039 buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
1040 if (!buf)
1041 return -ENOMEM;
Tony Jones694cc202007-09-11 14:07:31 -07001042
Ming Lei3c04e202008-09-18 23:06:21 +08001043 buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE;
1044 file->private_data = buf;
1045 return 0;
Tony Jones694cc202007-09-11 14:07:31 -07001046}
1047
1048static int debug_registers_open(struct inode *inode, struct file *file)
1049{
1050 file->private_data = alloc_buffer(inode->i_private,
1051 fill_registers_buffer);
1052
1053 return file->private_data ? 0 : -ENOMEM;
1054}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -03001056static inline void create_debug_files(struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057{
Tony Jones694cc202007-09-11 14:07:31 -07001058 struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Tony Jones694cc202007-09-11 14:07:31 -07001060 ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
1061 if (!ehci->debug_dir)
Ming Lei185c9bc2010-07-28 22:33:28 +08001062 return;
Tony Jones694cc202007-09-11 14:07:31 -07001063
Ming Lei185c9bc2010-07-28 22:33:28 +08001064 if (!debugfs_create_file("async", S_IRUGO, ehci->debug_dir, bus,
1065 &debug_async_fops))
1066 goto file_error;
Tony Jones694cc202007-09-11 14:07:31 -07001067
Alan Sternd0ce5c62013-10-11 11:29:13 -04001068 if (!debugfs_create_file("bandwidth", S_IRUGO, ehci->debug_dir, bus,
1069 &debug_bandwidth_fops))
1070 goto file_error;
1071
Ming Lei185c9bc2010-07-28 22:33:28 +08001072 if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus,
1073 &debug_periodic_fops))
1074 goto file_error;
Tony Jones694cc202007-09-11 14:07:31 -07001075
Ming Lei185c9bc2010-07-28 22:33:28 +08001076 if (!debugfs_create_file("registers", S_IRUGO, ehci->debug_dir, bus,
1077 &debug_registers_fops))
1078 goto file_error;
Alek Duaa4d8342010-06-04 15:47:54 +08001079
Tony Jones694cc202007-09-11 14:07:31 -07001080 return;
1081
Ming Lei185c9bc2010-07-28 22:33:28 +08001082file_error:
1083 debugfs_remove_recursive(ehci->debug_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084}
1085
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -03001086static inline void remove_debug_files(struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087{
Ming Lei185c9bc2010-07-28 22:33:28 +08001088 debugfs_remove_recursive(ehci->debug_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089}
1090
1091#endif /* STUB_DEBUG_FILES */