blob: 3b423e122423d5c55b60a69bd7e836c66e734bbe [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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 */
15
16/* this file is part of ehci-hcd.c */
17
Oliver Neukum1c201632013-11-18 13:23:16 +010018#ifdef CONFIG_DYNAMIC_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -030020/*
21 * check the values in the HCSPARAMS register
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 * (host controller _Structural_ parameters)
23 * see EHCI spec, Table 2-4 for each value
24 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030025static void dbg_hcs_params(struct ehci_hcd *ehci, char *label)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +110027 u32 params = ehci_readl(ehci, &ehci->caps->hcs_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030029 ehci_dbg(ehci,
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 "%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n",
31 label, params,
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030032 HCS_DEBUG_PORT(params),
33 HCS_INDICATOR(params) ? " ind" : "",
34 HCS_N_CC(params),
35 HCS_N_PCC(params),
36 HCS_PORTROUTED(params) ? "" : " ordered",
37 HCS_PPC(params) ? "" : " !ppc",
Geyslan G. Bem78698d62016-01-25 22:44:57 -030038 HCS_N_PORTS(params));
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 /* Port routing, per EHCI 0.95 Spec, Section 2.2.5 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030040 if (HCS_PORTROUTED(params)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 int i;
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -030042 char buf[46], tmp[7], byte;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44 buf[0] = 0;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030045 for (i = 0; i < HCS_N_PORTS(params); i++) {
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -030046 /* FIXME MIPS won't readb() ... */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030047 byte = readb(&ehci->caps->portroute[(i >> 1)]);
David Brownell53bd6a62006-08-30 14:50:06 -070048 sprintf(tmp, "%d ",
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf)));
50 strcat(buf, tmp);
51 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030052 ehci_dbg(ehci, "%s portroute %s\n", label, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 }
54}
55#else
56
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030057static inline void dbg_hcs_params(struct ehci_hcd *ehci, char *label) {}
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59#endif
60
Oliver Neukum1c201632013-11-18 13:23:16 +010061#ifdef CONFIG_DYNAMIC_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -030063/*
64 * check the values in the HCCPARAMS register
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 * (host controller _Capability_ parameters)
66 * see EHCI Spec, Table 2-5 for each value
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -030067 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030068static void dbg_hcc_params(struct ehci_hcd *ehci, char *label)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +110070 u32 params = ehci_readl(ehci, &ehci->caps->hcc_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030072 if (HCC_ISOC_CACHE(params)) {
73 ehci_dbg(ehci,
Stefan Roese6dbd6822007-05-01 09:29:37 -070074 "%s hcc_params %04x caching frame %s%s%s\n",
75 label, params,
76 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
77 HCC_CANPARK(params) ? " park" : "",
78 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 } else {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030080 ehci_dbg(ehci,
Alek Duaa4d8342010-06-04 15:47:54 +080081 "%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -070082 label,
83 params,
84 HCC_ISOC_THRES(params),
85 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
86 HCC_CANPARK(params) ? " park" : "",
Alek Duaa4d8342010-06-04 15:47:54 +080087 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "",
88 HCC_LPM(params) ? " LPM" : "",
89 HCC_PER_PORT_CHANGE_EVENT(params) ? " ppce" : "",
90 HCC_HW_PREFETCH(params) ? " hw prefetch" : "",
91 HCC_32FRAME_PERIODIC_LIST(params) ?
Masanari Iida855ef452012-02-17 23:06:47 +090092 " 32 periodic list" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 }
94}
95#else
96
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030097static inline void dbg_hcc_params(struct ehci_hcd *ehci, char *label) {}
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99#endif
100
Oliver Neukum1c201632013-11-18 13:23:16 +0100101#ifdef CONFIG_DYNAMIC_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
David Rientjes82345092007-05-11 14:39:44 -0700103static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300104dbg_qtd(const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Stefan Roese6dbd6822007-05-01 09:29:37 -0700106 ehci_dbg(ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
107 hc32_to_cpup(ehci, &qtd->hw_next),
108 hc32_to_cpup(ehci, &qtd->hw_alt_next),
109 hc32_to_cpup(ehci, &qtd->hw_token),
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300110 hc32_to_cpup(ehci, &qtd->hw_buf[0]));
111 if (qtd->hw_buf[1])
Stefan Roese6dbd6822007-05-01 09:29:37 -0700112 ehci_dbg(ehci, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
113 hc32_to_cpup(ehci, &qtd->hw_buf[1]),
114 hc32_to_cpup(ehci, &qtd->hw_buf[2]),
115 hc32_to_cpup(ehci, &qtd->hw_buf[3]),
116 hc32_to_cpup(ehci, &qtd->hw_buf[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117}
118
David Rientjes82345092007-05-11 14:39:44 -0700119static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300120dbg_qh(const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Alek Du3807e262009-07-14 07:23:29 +0800122 struct ehci_qh_hw *hw = qh->hw;
123
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300124 ehci_dbg(ehci, "%s qh %p n%08x info %x %x qtd %x\n", label,
Alek Du3807e262009-07-14 07:23:29 +0800125 qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current);
126 dbg_qtd("overlay", ehci, (struct ehci_qtd *) &hw->hw_qtd_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
David Rientjes82345092007-05-11 14:39:44 -0700129static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300130dbg_itd(const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300132 ehci_dbg(ehci, "%s [%d] itd %p, next %08x, urb %p\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700133 label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next),
134 itd->urb);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300135 ehci_dbg(ehci,
David Brownell53bd6a62006-08-30 14:50:06 -0700136 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700137 hc32_to_cpu(ehci, itd->hw_transaction[0]),
138 hc32_to_cpu(ehci, itd->hw_transaction[1]),
139 hc32_to_cpu(ehci, itd->hw_transaction[2]),
140 hc32_to_cpu(ehci, itd->hw_transaction[3]),
141 hc32_to_cpu(ehci, itd->hw_transaction[4]),
142 hc32_to_cpu(ehci, itd->hw_transaction[5]),
143 hc32_to_cpu(ehci, itd->hw_transaction[6]),
144 hc32_to_cpu(ehci, itd->hw_transaction[7]));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300145 ehci_dbg(ehci,
David Brownell53bd6a62006-08-30 14:50:06 -0700146 " buf: %08x %08x %08x %08x %08x %08x %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700147 hc32_to_cpu(ehci, itd->hw_bufp[0]),
148 hc32_to_cpu(ehci, itd->hw_bufp[1]),
149 hc32_to_cpu(ehci, itd->hw_bufp[2]),
150 hc32_to_cpu(ehci, itd->hw_bufp[3]),
151 hc32_to_cpu(ehci, itd->hw_bufp[4]),
152 hc32_to_cpu(ehci, itd->hw_bufp[5]),
153 hc32_to_cpu(ehci, itd->hw_bufp[6]));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300154 ehci_dbg(ehci, " index: %d %d %d %d %d %d %d %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 itd->index[0], itd->index[1], itd->index[2],
156 itd->index[3], itd->index[4], itd->index[5],
157 itd->index[6], itd->index[7]);
158}
159
David Rientjes82345092007-05-11 14:39:44 -0700160static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300161dbg_sitd(const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300163 ehci_dbg(ehci, "%s [%d] sitd %p, next %08x, urb %p\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700164 label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next),
165 sitd->urb);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300166 ehci_dbg(ehci,
David Brownell53bd6a62006-08-30 14:50:06 -0700167 " addr %08x sched %04x result %08x buf %08x %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700168 hc32_to_cpu(ehci, sitd->hw_fullspeed_ep),
169 hc32_to_cpu(ehci, sitd->hw_uframe),
170 hc32_to_cpu(ehci, sitd->hw_results),
171 hc32_to_cpu(ehci, sitd->hw_buf[0]),
172 hc32_to_cpu(ehci, sitd->hw_buf[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173}
174
David Rientjes82345092007-05-11 14:39:44 -0700175static int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300176dbg_status_buf(char *buf, unsigned len, const char *label, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300178 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800179 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s%s",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300180 label, label[0] ? " " : "", status,
Alek Duaa4d8342010-06-04 15:47:54 +0800181 (status & STS_PPCE_MASK) ? " PPCE" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 (status & STS_ASS) ? " Async" : "",
183 (status & STS_PSS) ? " Periodic" : "",
184 (status & STS_RECL) ? " Recl" : "",
185 (status & STS_HALT) ? " Halt" : "",
186 (status & STS_IAA) ? " IAA" : "",
187 (status & STS_FATAL) ? " FATAL" : "",
188 (status & STS_FLR) ? " FLR" : "",
189 (status & STS_PCD) ? " PCD" : "",
190 (status & STS_ERR) ? " ERR" : "",
Geyslan G. Bem78698d62016-01-25 22:44:57 -0300191 (status & STS_INT) ? " INT" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192}
193
David Rientjes82345092007-05-11 14:39:44 -0700194static int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300195dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300197 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800198 "%s%sintrenable %02x%s%s%s%s%s%s%s",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300199 label, label[0] ? " " : "", enable,
Alek Duaa4d8342010-06-04 15:47:54 +0800200 (enable & STS_PPCE_MASK) ? " PPCE" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 (enable & STS_IAA) ? " IAA" : "",
202 (enable & STS_FATAL) ? " FATAL" : "",
203 (enable & STS_FLR) ? " FLR" : "",
204 (enable & STS_PCD) ? " PCD" : "",
205 (enable & STS_ERR) ? " ERR" : "",
Geyslan G. Bem78698d62016-01-25 22:44:57 -0300206 (enable & STS_INT) ? " INT" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300209static const char *const fls_strings[] = { "1024", "512", "256", "??" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211static int
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300212dbg_command_buf(char *buf, unsigned len, const char *label, u32 command)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300214 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800215 "%s%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s "
216 "period=%s%s %s",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300217 label, label[0] ? " " : "", command,
Alek Duaa4d8342010-06-04 15:47:54 +0800218 (command & CMD_HIRD) ? " HIRD" : "",
219 (command & CMD_PPCEE) ? " PPCEE" : "",
220 (command & CMD_FSP) ? " FSP" : "",
221 (command & CMD_ASPE) ? " ASPE" : "",
222 (command & CMD_PSPE) ? " PSPE" : "",
223 (command & CMD_PARK) ? " park" : "(park)",
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300224 CMD_PARK_CNT(command),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 (command >> 16) & 0x3f,
226 (command & CMD_LRESET) ? " LReset" : "",
227 (command & CMD_IAAD) ? " IAAD" : "",
228 (command & CMD_ASE) ? " Async" : "",
229 (command & CMD_PSE) ? " Periodic" : "",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300230 fls_strings[(command >> 2) & 0x3],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 (command & CMD_RESET) ? " Reset" : "",
Geyslan G. Bem78698d62016-01-25 22:44:57 -0300232 (command & CMD_RUN) ? "RUN" : "HALT");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
235static int
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300236dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
238 char *sig;
239
240 /* signaling state */
241 switch (status & (3 << 10)) {
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300242 case 0 << 10:
243 sig = "se0";
244 break;
245 case 1 << 10: /* low speed */
246 sig = "k";
247 break;
248 case 2 << 10:
249 sig = "j";
250 break;
251 default:
252 sig = "?";
253 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 }
255
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300256 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800257 "%s%sport:%d status %06x %d %s%s%s%s%s%s "
258 "sig=%s%s%s%s%s%s%s%s%s%s%s",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300259 label, label[0] ? " " : "", port, status,
Alek Duaa4d8342010-06-04 15:47:54 +0800260 status>>25,/*device address */
261 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ACK ?
262 " ACK" : "",
263 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_NYET ?
264 " NYET" : "",
265 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_STALL ?
266 " STALL" : "",
267 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ERR ?
268 " ERR" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 (status & PORT_POWER) ? " POWER" : "",
270 (status & PORT_OWNER) ? " OWNER" : "",
271 sig,
Alek Duaa4d8342010-06-04 15:47:54 +0800272 (status & PORT_LPM) ? " LPM" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 (status & PORT_RESET) ? " RESET" : "",
274 (status & PORT_SUSPEND) ? " SUSPEND" : "",
275 (status & PORT_RESUME) ? " RESUME" : "",
276 (status & PORT_OCC) ? " OCC" : "",
277 (status & PORT_OC) ? " OC" : "",
278 (status & PORT_PEC) ? " PEC" : "",
279 (status & PORT_PE) ? " PE" : "",
280 (status & PORT_CSC) ? " CSC" : "",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700281 (status & PORT_CONNECT) ? " CONNECT" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
284#else
David Rientjes82345092007-05-11 14:39:44 -0700285static inline void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300286dbg_qh(char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{}
288
David Rientjes82345092007-05-11 14:39:44 -0700289static inline int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300290dbg_status_buf(char *buf, unsigned len, const char *label, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{ return 0; }
292
David Rientjes82345092007-05-11 14:39:44 -0700293static inline int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300294dbg_command_buf(char *buf, unsigned len, const char *label, u32 command)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{ return 0; }
296
David Rientjes82345092007-05-11 14:39:44 -0700297static inline int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300298dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{ return 0; }
300
David Rientjes82345092007-05-11 14:39:44 -0700301static inline int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300302dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{ return 0; }
304
Oliver Neukum1c201632013-11-18 13:23:16 +0100305#endif /* CONFIG_DYNAMIC_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307/* functions have the "wrong" filename when they're output... */
308#define dbg_status(ehci, label, status) { \
309 char _buf [80]; \
310 dbg_status_buf (_buf, sizeof _buf, label, status); \
311 ehci_dbg (ehci, "%s\n", _buf); \
312}
313
314#define dbg_cmd(ehci, label, command) { \
315 char _buf [80]; \
316 dbg_command_buf (_buf, sizeof _buf, label, command); \
317 ehci_dbg (ehci, "%s\n", _buf); \
318}
319
320#define dbg_port(ehci, label, port, status) { \
321 char _buf [80]; \
322 dbg_port_buf (_buf, sizeof _buf, label, port, status); \
323 ehci_dbg (ehci, "%s\n", _buf); \
324}
325
326/*-------------------------------------------------------------------------*/
327
328#ifdef STUB_DEBUG_FILES
329
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300330static inline void create_debug_files(struct ehci_hcd *bus) { }
331static inline void remove_debug_files(struct ehci_hcd *bus) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333#else
334
Tony Jones694cc202007-09-11 14:07:31 -0700335/* troubleshooting help: expose state in debugfs */
336
337static int debug_async_open(struct inode *, struct file *);
Alan Sternd0ce5c62013-10-11 11:29:13 -0400338static int debug_bandwidth_open(struct inode *, struct file *);
Tony Jones694cc202007-09-11 14:07:31 -0700339static int debug_periodic_open(struct inode *, struct file *);
340static int debug_registers_open(struct inode *, struct file *);
Alek Duaa4d8342010-06-04 15:47:54 +0800341
Tony Jones694cc202007-09-11 14:07:31 -0700342static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
343static int debug_close(struct inode *, struct file *);
344
345static const struct file_operations debug_async_fops = {
346 .owner = THIS_MODULE,
347 .open = debug_async_open,
348 .read = debug_output,
349 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200350 .llseek = default_llseek,
Tony Jones694cc202007-09-11 14:07:31 -0700351};
Alan Sternd0ce5c62013-10-11 11:29:13 -0400352static const struct file_operations debug_bandwidth_fops = {
353 .owner = THIS_MODULE,
354 .open = debug_bandwidth_open,
355 .read = debug_output,
356 .release = debug_close,
357 .llseek = default_llseek,
358};
Tony Jones694cc202007-09-11 14:07:31 -0700359static const struct file_operations debug_periodic_fops = {
360 .owner = THIS_MODULE,
361 .open = debug_periodic_open,
362 .read = debug_output,
363 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200364 .llseek = default_llseek,
Tony Jones694cc202007-09-11 14:07:31 -0700365};
366static const struct file_operations debug_registers_fops = {
367 .owner = THIS_MODULE,
368 .open = debug_registers_open,
369 .read = debug_output,
370 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200371 .llseek = default_llseek,
Tony Jones694cc202007-09-11 14:07:31 -0700372};
373
374static struct dentry *ehci_debug_root;
375
376struct debug_buffer {
377 ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
378 struct usb_bus *bus;
379 struct mutex mutex; /* protect filling of buffer */
380 size_t count; /* number of characters filled into buffer */
Ming Lei3c04e202008-09-18 23:06:21 +0800381 char *output_buf;
382 size_t alloc_size;
Tony Jones694cc202007-09-11 14:07:31 -0700383};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385#define speed_char(info1) ({ char tmp; \
386 switch (info1 & (3 << 12)) { \
Alan Stern4c53de72012-07-11 11:21:32 -0400387 case QH_FULL_SPEED: tmp = 'f'; break; \
388 case QH_LOW_SPEED: tmp = 'l'; break; \
389 case QH_HIGH_SPEED: tmp = 'h'; break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 default: tmp = '?'; break; \
Joe Perches2b84f922013-10-08 16:01:37 -0700391 } tmp; })
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Stefan Roese6dbd6822007-05-01 09:29:37 -0700393static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
Stefan Roese6dbd6822007-05-01 09:29:37 -0700395 __u32 v = hc32_to_cpu(ehci, token);
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 if (v & QTD_STS_ACTIVE)
398 return '*';
399 if (v & QTD_STS_HALT)
400 return '-';
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300401 if (!IS_SHORT_READ(v))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 return ' ';
403 /* tries to advance through hw_alt_next */
404 return '/';
405}
406
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300407static void qh_lines(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 struct ehci_hcd *ehci,
409 struct ehci_qh *qh,
410 char **nextp,
411 unsigned *sizep
412)
413{
414 u32 scratch;
415 u32 hw_curr;
416 struct list_head *entry;
417 struct ehci_qtd *td;
418 unsigned temp;
419 unsigned size = *sizep;
420 char *next = *nextp;
421 char mark;
Al Virofd05e722008-04-28 07:00:16 +0100422 __le32 list_end = EHCI_LIST_END(ehci);
Alek Du3807e262009-07-14 07:23:29 +0800423 struct ehci_qh_hw *hw = qh->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Alek Du3807e262009-07-14 07:23:29 +0800425 if (hw->hw_qtd_next == list_end) /* NEC does this */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 mark = '@';
427 else
Alek Du3807e262009-07-14 07:23:29 +0800428 mark = token_mark(ehci, hw->hw_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 if (mark == '/') { /* qh_alt_next controls qh advance? */
Alek Du3807e262009-07-14 07:23:29 +0800430 if ((hw->hw_alt_next & QTD_MASK(ehci))
431 == ehci->async->hw->hw_alt_next)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 mark = '#'; /* blocked */
Alek Du3807e262009-07-14 07:23:29 +0800433 else if (hw->hw_alt_next == list_end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 mark = '.'; /* use hw_qtd_next */
435 /* else alt_next points to some other qtd */
436 }
Alek Du3807e262009-07-14 07:23:29 +0800437 scratch = hc32_to_cpup(ehci, &hw->hw_info1);
438 hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300439 temp = scnprintf(next, size,
Alan Stern8ee10d62015-11-20 13:53:45 -0500440 "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)"
441 " [cur %08x next %08x buf[0] %08x]",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 qh, scratch & 0x007f,
443 speed_char (scratch),
444 (scratch >> 8) & 0x000f,
Alek Du3807e262009-07-14 07:23:29 +0800445 scratch, hc32_to_cpup(ehci, &hw->hw_info2),
446 hc32_to_cpup(ehci, &hw->hw_token), mark,
447 (cpu_to_hc32(ehci, QTD_TOGGLE) & hw->hw_token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 ? "data1" : "data0",
Alan Stern8ee10d62015-11-20 13:53:45 -0500449 (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f,
450 hc32_to_cpup(ehci, &hw->hw_current),
451 hc32_to_cpup(ehci, &hw->hw_qtd_next),
452 hc32_to_cpup(ehci, &hw->hw_buf[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 size -= temp;
454 next += temp;
455
456 /* hc may be modifying the list as we read it ... */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300457 list_for_each(entry, &qh->qtd_list) {
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300458 char *type;
459
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300460 td = list_entry(entry, struct ehci_qtd, qtd_list);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700461 scratch = hc32_to_cpup(ehci, &td->hw_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 mark = ' ';
463 if (hw_curr == td->qtd_dma)
464 mark = '*';
Alek Du3807e262009-07-14 07:23:29 +0800465 else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 mark = '+';
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300467 else if (QTD_LENGTH(scratch)) {
Alek Du3807e262009-07-14 07:23:29 +0800468 if (td->hw_alt_next == ehci->async->hw->hw_alt_next)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 mark = '#';
Stefan Roese6dbd6822007-05-01 09:29:37 -0700470 else if (td->hw_alt_next != list_end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 mark = '/';
472 }
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300473 switch ((scratch >> 8) & 0x03) {
474 case 0:
475 type = "out";
476 break;
477 case 1:
478 type = "in";
479 break;
480 case 2:
481 type = "setup";
482 break;
483 default:
484 type = "?";
485 break;
486 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300487 temp = snprintf(next, size,
Alan Stern8ee10d62015-11-20 13:53:45 -0500488 "\n\t%p%c%s len=%d %08x urb %p"
489 " [td %08x buf[0] %08x]",
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300490 td, mark, type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 (scratch >> 16) & 0x7fff,
492 scratch,
Alan Stern8ee10d62015-11-20 13:53:45 -0500493 td->urb,
494 (u32) td->qtd_dma,
495 hc32_to_cpup(ehci, &td->hw_buf[0]));
roel kluine64a5212008-10-21 00:47:23 -0400496 if (size < temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 temp = size;
498 size -= temp;
499 next += temp;
500 if (temp == size)
501 goto done;
502 }
503
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300504 temp = snprintf(next, size, "\n");
roel kluine64a5212008-10-21 00:47:23 -0400505 if (size < temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 temp = size;
507 size -= temp;
508 next += temp;
509
510done:
511 *sizep = size;
512 *nextp = next;
513}
514
Tony Jones694cc202007-09-11 14:07:31 -0700515static ssize_t fill_async_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 struct usb_hcd *hcd;
518 struct ehci_hcd *ehci;
519 unsigned long flags;
520 unsigned temp, size;
521 char *next;
522 struct ehci_qh *qh;
523
Tony Jones694cc202007-09-11 14:07:31 -0700524 hcd = bus_to_hcd(buf->bus);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300525 ehci = hcd_to_ehci(hcd);
Ming Lei3c04e202008-09-18 23:06:21 +0800526 next = buf->output_buf;
527 size = buf->alloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Tony Jones694cc202007-09-11 14:07:31 -0700529 *next = 0;
530
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -0300531 /*
532 * dumps a snapshot of the async schedule.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 * usually empty except for long-term bulk reads, or head.
534 * one QH per line, and TDs we know about
535 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300536 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300538 qh_lines(ehci, qh, &next, &size);
Alan Stern6e018752013-03-22 13:31:45 -0400539 if (!list_empty(&ehci->async_unlink) && size > 0) {
Alan Stern99ac5b12012-07-11 11:21:38 -0400540 temp = scnprintf(next, size, "\nunlink =\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 size -= temp;
542 next += temp;
543
Alan Stern6e018752013-03-22 13:31:45 -0400544 list_for_each_entry(qh, &ehci->async_unlink, unlink_node) {
545 if (size <= 0)
546 break;
547 qh_lines(ehci, qh, &next, &size);
548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300550 spin_unlock_irqrestore(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Ming Lei3c04e202008-09-18 23:06:21 +0800552 return strlen(buf->output_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Alan Sternd0ce5c62013-10-11 11:29:13 -0400555static ssize_t fill_bandwidth_buffer(struct debug_buffer *buf)
556{
557 struct ehci_hcd *ehci;
Alan Sternb35c5002013-10-11 22:16:21 -0400558 struct ehci_tt *tt;
559 struct ehci_per_sched *ps;
Alan Sternd0ce5c62013-10-11 11:29:13 -0400560 unsigned temp, size;
561 char *next;
562 unsigned i;
563 u8 *bw;
Alan Sternb35c5002013-10-11 22:16:21 -0400564 u16 *bf;
565 u8 budget[EHCI_BANDWIDTH_SIZE];
Alan Sternd0ce5c62013-10-11 11:29:13 -0400566
567 ehci = hcd_to_ehci(bus_to_hcd(buf->bus));
568 next = buf->output_buf;
569 size = buf->alloc_size;
570
571 *next = 0;
572
573 spin_lock_irq(&ehci->lock);
574
575 /* Dump the HS bandwidth table */
576 temp = scnprintf(next, size,
577 "HS bandwidth allocation (us per microframe)\n");
578 size -= temp;
579 next += temp;
580 for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
581 bw = &ehci->bandwidth[i];
582 temp = scnprintf(next, size,
583 "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
584 i, bw[0], bw[1], bw[2], bw[3],
585 bw[4], bw[5], bw[6], bw[7]);
586 size -= temp;
587 next += temp;
588 }
Alan Sternb35c5002013-10-11 22:16:21 -0400589
590 /* Dump all the FS/LS tables */
591 list_for_each_entry(tt, &ehci->tt_list, tt_list) {
592 temp = scnprintf(next, size,
593 "\nTT %s port %d FS/LS bandwidth allocation (us per frame)\n",
594 dev_name(&tt->usb_tt->hub->dev),
595 tt->tt_port + !!tt->usb_tt->multi);
596 size -= temp;
597 next += temp;
598
599 bf = tt->bandwidth;
600 temp = scnprintf(next, size,
601 " %5u%5u%5u%5u%5u%5u%5u%5u\n",
602 bf[0], bf[1], bf[2], bf[3],
603 bf[4], bf[5], bf[6], bf[7]);
604 size -= temp;
605 next += temp;
606
607 temp = scnprintf(next, size,
608 "FS/LS budget (us per microframe)\n");
609 size -= temp;
610 next += temp;
611 compute_tt_budget(budget, tt);
612 for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
613 bw = &budget[i];
614 temp = scnprintf(next, size,
615 "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
616 i, bw[0], bw[1], bw[2], bw[3],
617 bw[4], bw[5], bw[6], bw[7]);
618 size -= temp;
619 next += temp;
620 }
621 list_for_each_entry(ps, &tt->ps_list, ps_list) {
622 temp = scnprintf(next, size,
623 "%s ep %02x: %4u @ %2u.%u+%u mask %04x\n",
624 dev_name(&ps->udev->dev),
625 ps->ep->desc.bEndpointAddress,
626 ps->tt_usecs,
627 ps->bw_phase, ps->phase_uf,
628 ps->bw_period, ps->cs_mask);
629 size -= temp;
630 next += temp;
631 }
632 }
Alan Sternd0ce5c62013-10-11 11:29:13 -0400633 spin_unlock_irq(&ehci->lock);
634
635 return next - buf->output_buf;
636}
637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638#define DBG_SCHED_LIMIT 64
Tony Jones694cc202007-09-11 14:07:31 -0700639static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 struct usb_hcd *hcd;
642 struct ehci_hcd *ehci;
643 unsigned long flags;
644 union ehci_shadow p, *seen;
645 unsigned temp, size, seen_count;
646 char *next;
647 unsigned i;
Stefan Roese6dbd6822007-05-01 09:29:37 -0700648 __hc32 tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Greg Kroah-Hartman911fdb62015-04-30 11:32:50 +0200650 seen = kmalloc(DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC);
651 if (!seen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 return 0;
653 seen_count = 0;
654
Tony Jones694cc202007-09-11 14:07:31 -0700655 hcd = bus_to_hcd(buf->bus);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300656 ehci = hcd_to_ehci(hcd);
Ming Lei3c04e202008-09-18 23:06:21 +0800657 next = buf->output_buf;
658 size = buf->alloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300660 temp = scnprintf(next, size, "size = %d\n", ehci->periodic_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 size -= temp;
662 next += temp;
663
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -0300664 /*
665 * dump a snapshot of the periodic schedule.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 * iso changes, interrupt usually doesn't.
667 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300668 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 for (i = 0; i < ehci->periodic_size; i++) {
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300670 p = ehci->pshadow[i];
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300671 if (likely(!p.ptr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 continue;
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300673 tag = Q_NEXT_TYPE(ehci, ehci->periodic[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300675 temp = scnprintf(next, size, "%4d: ", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 size -= temp;
677 next += temp;
678
679 do {
Alek Du3807e262009-07-14 07:23:29 +0800680 struct ehci_qh_hw *hw;
681
Stefan Roese6dbd6822007-05-01 09:29:37 -0700682 switch (hc32_to_cpu(ehci, tag)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 case Q_TYPE_QH:
Alek Du3807e262009-07-14 07:23:29 +0800684 hw = p.qh->hw;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300685 temp = scnprintf(next, size, " qh%d-%04x/%p",
Alan Sternffa02482013-10-11 11:29:03 -0400686 p.qh->ps.period,
Stefan Roese6dbd6822007-05-01 09:29:37 -0700687 hc32_to_cpup(ehci,
Alek Du3807e262009-07-14 07:23:29 +0800688 &hw->hw_info2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 /* uframe masks */
David Brownell7dedacf2005-08-04 18:06:41 -0700690 & (QH_CMASK | QH_SMASK),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 p.qh);
692 size -= temp;
693 next += temp;
694 /* don't repeat what follows this qh */
695 for (temp = 0; temp < seen_count; temp++) {
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300696 if (seen[temp].ptr != p.ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 continue;
Ming Lei3c4bb712008-09-18 23:06:38 +0800698 if (p.qh->qh_next.ptr) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300699 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 " ...");
Ming Lei3c4bb712008-09-18 23:06:38 +0800701 size -= temp;
702 next += temp;
703 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 break;
705 }
706 /* show more info the first time around */
Ming Lei3c4bb712008-09-18 23:06:38 +0800707 if (temp == seen_count) {
Stefan Roese6dbd6822007-05-01 09:29:37 -0700708 u32 scratch = hc32_to_cpup(ehci,
Alek Du3807e262009-07-14 07:23:29 +0800709 &hw->hw_info1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 struct ehci_qtd *qtd;
711 char *type = "";
712
713 /* count tds, get ep direction */
714 temp = 0;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300715 list_for_each_entry(qtd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 &p.qh->qtd_list,
717 qtd_list) {
718 temp++;
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300719 switch ((hc32_to_cpu(ehci,
720 qtd->hw_token) >> 8)
721 & 0x03) {
722 case 0:
723 type = "out";
724 continue;
725 case 1:
726 type = "in";
727 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 }
729 }
730
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300731 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 " (%c%d ep%d%s "
733 "[%d/%d] q%d p%d)",
734 speed_char (scratch),
735 scratch & 0x007f,
736 (scratch >> 8) & 0x000f, type,
Alan Sternffa02482013-10-11 11:29:03 -0400737 p.qh->ps.usecs,
738 p.qh->ps.c_usecs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 temp,
740 0x7ff & (scratch >> 16));
741
742 if (seen_count < DBG_SCHED_LIMIT)
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300743 seen[seen_count++].qh = p.qh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 } else
745 temp = 0;
Alan Stern17dcfc92012-09-19 17:00:55 -0400746 tag = Q_NEXT_TYPE(ehci, hw->hw_next);
747 p = p.qh->qh_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 break;
749 case Q_TYPE_FSTN:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300750 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 " fstn-%8x/%p", p.fstn->hw_prev,
752 p.fstn);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700753 tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 p = p.fstn->fstn_next;
755 break;
756 case Q_TYPE_ITD:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300757 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 " itd/%p", p.itd);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700759 tag = Q_NEXT_TYPE(ehci, p.itd->hw_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 p = p.itd->itd_next;
761 break;
762 case Q_TYPE_SITD:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300763 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 " sitd%d-%04x/%p",
Alan Sternffa02482013-10-11 11:29:03 -0400765 p.sitd->stream->ps.period,
Stefan Roese6dbd6822007-05-01 09:29:37 -0700766 hc32_to_cpup(ehci, &p.sitd->hw_uframe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 & 0x0000ffff,
768 p.sitd);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700769 tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 p = p.sitd->sitd_next;
771 break;
772 }
773 size -= temp;
774 next += temp;
775 } while (p.ptr);
776
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300777 temp = scnprintf(next, size, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 size -= temp;
779 next += temp;
780 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300781 spin_unlock_irqrestore(&ehci->lock, flags);
782 kfree(seen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Ming Lei3c04e202008-09-18 23:06:21 +0800784 return buf->alloc_size - size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786#undef DBG_SCHED_LIMIT
787
Alan Sterne8799902011-08-18 16:31:30 -0400788static const char *rh_state_string(struct ehci_hcd *ehci)
789{
790 switch (ehci->rh_state) {
791 case EHCI_RH_HALTED:
792 return "halted";
793 case EHCI_RH_SUSPENDED:
794 return "suspended";
795 case EHCI_RH_RUNNING:
796 return "running";
Alan Sternc0c53db2012-07-11 11:21:48 -0400797 case EHCI_RH_STOPPING:
798 return "stopping";
Alan Sterne8799902011-08-18 16:31:30 -0400799 }
800 return "?";
801}
802
Tony Jones694cc202007-09-11 14:07:31 -0700803static ssize_t fill_registers_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 struct usb_hcd *hcd;
806 struct ehci_hcd *ehci;
807 unsigned long flags;
808 unsigned temp, size, i;
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300809 char *next, scratch[80];
810 static char fmt[] = "%*s\n";
811 static char label[] = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
Tony Jones694cc202007-09-11 14:07:31 -0700813 hcd = bus_to_hcd(buf->bus);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300814 ehci = hcd_to_ehci(hcd);
Ming Lei3c04e202008-09-18 23:06:21 +0800815 next = buf->output_buf;
816 size = buf->alloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300818 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Alan Stern541c7d42010-06-22 16:39:10 -0400820 if (!HCD_HW_ACCESSIBLE(hcd)) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300821 size = scnprintf(next, size,
Alan Stern2b70f072008-10-02 11:47:15 -0400822 "bus %s, device %s\n"
David Brownelld49d4312005-05-07 13:21:50 -0700823 "%s\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 "SUSPENDED (no register access)\n",
825 hcd->self.controller->bus->name,
Kay Sievers7071a3c2008-05-02 06:02:41 +0200826 dev_name(hcd->self.controller),
David Brownelld49d4312005-05-07 13:21:50 -0700827 hcd->product_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 goto done;
829 }
830
831 /* Capability Registers */
Jan Anderssonc4301312011-05-03 20:11:57 +0200832 i = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300833 temp = scnprintf(next, size,
Alan Stern2b70f072008-10-02 11:47:15 -0400834 "bus %s, device %s\n"
David Brownelld49d4312005-05-07 13:21:50 -0700835 "%s\n"
Alan Sterne8799902011-08-18 16:31:30 -0400836 "EHCI %x.%02x, rh state %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 hcd->self.controller->bus->name,
Kay Sievers7071a3c2008-05-02 06:02:41 +0200838 dev_name(hcd->self.controller),
David Brownelld49d4312005-05-07 13:21:50 -0700839 hcd->product_desc,
Alan Sterne8799902011-08-18 16:31:30 -0400840 i >> 8, i & 0x0ff, rh_state_string(ehci));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 size -= temp;
842 next += temp;
843
David Brownelld49d4312005-05-07 13:21:50 -0700844#ifdef CONFIG_PCI
845 /* EHCI 0.96 and later may have "extended capabilities" */
Yijing Wange10e6f42013-12-05 19:21:32 +0800846 if (dev_is_pci(hcd->self.controller)) {
David Brownelld49d4312005-05-07 13:21:50 -0700847 struct pci_dev *pdev;
848 u32 offset, cap, cap2;
849 unsigned count = 256/4;
850
851 pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700852 offset = HCC_EXT_CAPS(ehci_readl(ehci,
853 &ehci->caps->hcc_params));
David Brownelld49d4312005-05-07 13:21:50 -0700854 while (offset && count--) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300855 pci_read_config_dword(pdev, offset, &cap);
David Brownelld49d4312005-05-07 13:21:50 -0700856 switch (cap & 0xff) {
857 case 1:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300858 temp = scnprintf(next, size,
David Brownelld49d4312005-05-07 13:21:50 -0700859 "ownership %08x%s%s\n", cap,
860 (cap & (1 << 24)) ? " linux" : "",
861 (cap & (1 << 16)) ? " firmware" : "");
862 size -= temp;
863 next += temp;
864
865 offset += 4;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300866 pci_read_config_dword(pdev, offset, &cap2);
867 temp = scnprintf(next, size,
David Brownelld49d4312005-05-07 13:21:50 -0700868 "SMI sts/enable 0x%08x\n", cap2);
869 size -= temp;
870 next += temp;
871 break;
872 case 0: /* illegal reserved capability */
873 cap = 0;
874 /* FALLTHROUGH */
875 default: /* unknown */
876 break;
877 }
878 temp = (cap >> 8) & 0xff;
879 }
880 }
881#endif
882
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -0300883 /* FIXME interpret both types of params */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100884 i = ehci_readl(ehci, &ehci->caps->hcs_params);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300885 temp = scnprintf(next, size, "structural params 0x%08x\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 size -= temp;
887 next += temp;
888
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100889 i = ehci_readl(ehci, &ehci->caps->hcc_params);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300890 temp = scnprintf(next, size, "capability params 0x%08x\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 size -= temp;
892 next += temp;
893
894 /* Operational Registers */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300895 temp = dbg_status_buf(scratch, sizeof(scratch), label,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100896 ehci_readl(ehci, &ehci->regs->status));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300897 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 size -= temp;
899 next += temp;
900
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300901 temp = dbg_command_buf(scratch, sizeof(scratch), label,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100902 ehci_readl(ehci, &ehci->regs->command));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300903 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 size -= temp;
905 next += temp;
906
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300907 temp = dbg_intr_buf(scratch, sizeof(scratch), label,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100908 ehci_readl(ehci, &ehci->regs->intr_enable));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300909 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 size -= temp;
911 next += temp;
912
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300913 temp = scnprintf(next, size, "uframe %04x\n",
Alan Stern68aa95d2011-10-12 10:39:14 -0400914 ehci_read_frame_index(ehci));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 size -= temp;
916 next += temp;
917
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300918 for (i = 1; i <= HCS_N_PORTS(ehci->hcs_params); i++) {
919 temp = dbg_port_buf(scratch, sizeof(scratch), label, i,
Stefan Roese6dbd6822007-05-01 09:29:37 -0700920 ehci_readl(ehci,
921 &ehci->regs->port_status[i - 1]));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300922 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 size -= temp;
924 next += temp;
David Brownelld49d4312005-05-07 13:21:50 -0700925 if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300926 temp = scnprintf(next, size,
David Brownelld49d4312005-05-07 13:21:50 -0700927 " debug control %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700928 ehci_readl(ehci,
929 &ehci->debug->control));
David Brownelld49d4312005-05-07 13:21:50 -0700930 size -= temp;
931 next += temp;
932 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 }
934
Alan Stern6e018752013-03-22 13:31:45 -0400935 if (!list_empty(&ehci->async_unlink)) {
Alan Stern99ac5b12012-07-11 11:21:38 -0400936 temp = scnprintf(next, size, "async unlink qh %p\n",
Alan Stern6e018752013-03-22 13:31:45 -0400937 list_first_entry(&ehci->async_unlink,
938 struct ehci_qh, unlink_node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 size -= temp;
940 next += temp;
941 }
942
943#ifdef EHCI_STATS
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300944 temp = scnprintf(next, size,
Alan Stern99ac5b12012-07-11 11:21:38 -0400945 "irq normal %ld err %ld iaa %ld (lost %ld)\n",
946 ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 ehci->stats.lost_iaa);
948 size -= temp;
949 next += temp;
950
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300951 temp = scnprintf(next, size, "complete %ld unlink %ld\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 ehci->stats.complete, ehci->stats.unlink);
953 size -= temp;
954 next += temp;
955#endif
956
957done:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300958 spin_unlock_irqrestore(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
Ming Lei3c04e202008-09-18 23:06:21 +0800960 return buf->alloc_size - size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961}
Tony Jones694cc202007-09-11 14:07:31 -0700962
963static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
964 ssize_t (*fill_func)(struct debug_buffer *))
965{
966 struct debug_buffer *buf;
967
968 buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
969
970 if (buf) {
971 buf->bus = bus;
972 buf->fill_func = fill_func;
973 mutex_init(&buf->mutex);
Ming Lei3c04e202008-09-18 23:06:21 +0800974 buf->alloc_size = PAGE_SIZE;
Tony Jones694cc202007-09-11 14:07:31 -0700975 }
976
977 return buf;
978}
979
980static int fill_buffer(struct debug_buffer *buf)
981{
982 int ret = 0;
983
Ming Lei3c04e202008-09-18 23:06:21 +0800984 if (!buf->output_buf)
Jesper Juhl73f35c62010-11-09 00:10:52 +0100985 buf->output_buf = vmalloc(buf->alloc_size);
Tony Jones694cc202007-09-11 14:07:31 -0700986
Ming Lei3c04e202008-09-18 23:06:21 +0800987 if (!buf->output_buf) {
Tony Jones694cc202007-09-11 14:07:31 -0700988 ret = -ENOMEM;
989 goto out;
990 }
991
992 ret = buf->fill_func(buf);
993
994 if (ret >= 0) {
995 buf->count = ret;
996 ret = 0;
997 }
998
999out:
1000 return ret;
1001}
1002
1003static ssize_t debug_output(struct file *file, char __user *user_buf,
1004 size_t len, loff_t *offset)
1005{
1006 struct debug_buffer *buf = file->private_data;
1007 int ret = 0;
1008
1009 mutex_lock(&buf->mutex);
1010 if (buf->count == 0) {
1011 ret = fill_buffer(buf);
1012 if (ret != 0) {
1013 mutex_unlock(&buf->mutex);
1014 goto out;
1015 }
1016 }
1017 mutex_unlock(&buf->mutex);
1018
1019 ret = simple_read_from_buffer(user_buf, len, offset,
Ming Lei3c04e202008-09-18 23:06:21 +08001020 buf->output_buf, buf->count);
Tony Jones694cc202007-09-11 14:07:31 -07001021
1022out:
1023 return ret;
1024
1025}
1026
1027static int debug_close(struct inode *inode, struct file *file)
1028{
1029 struct debug_buffer *buf = file->private_data;
1030
1031 if (buf) {
Figo.zhangf8086a02009-06-06 20:31:49 +08001032 vfree(buf->output_buf);
Tony Jones694cc202007-09-11 14:07:31 -07001033 kfree(buf);
1034 }
1035
1036 return 0;
1037}
Alan Sternd0ce5c62013-10-11 11:29:13 -04001038
Tony Jones694cc202007-09-11 14:07:31 -07001039static int debug_async_open(struct inode *inode, struct file *file)
1040{
1041 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
1042
1043 return file->private_data ? 0 : -ENOMEM;
1044}
1045
Alan Sternd0ce5c62013-10-11 11:29:13 -04001046static int debug_bandwidth_open(struct inode *inode, struct file *file)
1047{
1048 file->private_data = alloc_buffer(inode->i_private,
1049 fill_bandwidth_buffer);
1050
1051 return file->private_data ? 0 : -ENOMEM;
1052}
1053
Tony Jones694cc202007-09-11 14:07:31 -07001054static int debug_periodic_open(struct inode *inode, struct file *file)
1055{
Ming Lei3c04e202008-09-18 23:06:21 +08001056 struct debug_buffer *buf;
1057 buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
1058 if (!buf)
1059 return -ENOMEM;
Tony Jones694cc202007-09-11 14:07:31 -07001060
Ming Lei3c04e202008-09-18 23:06:21 +08001061 buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE;
1062 file->private_data = buf;
1063 return 0;
Tony Jones694cc202007-09-11 14:07:31 -07001064}
1065
1066static int debug_registers_open(struct inode *inode, struct file *file)
1067{
1068 file->private_data = alloc_buffer(inode->i_private,
1069 fill_registers_buffer);
1070
1071 return file->private_data ? 0 : -ENOMEM;
1072}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -03001074static inline void create_debug_files(struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
Tony Jones694cc202007-09-11 14:07:31 -07001076 struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Tony Jones694cc202007-09-11 14:07:31 -07001078 ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
1079 if (!ehci->debug_dir)
Ming Lei185c9bc2010-07-28 22:33:28 +08001080 return;
Tony Jones694cc202007-09-11 14:07:31 -07001081
Ming Lei185c9bc2010-07-28 22:33:28 +08001082 if (!debugfs_create_file("async", S_IRUGO, ehci->debug_dir, bus,
1083 &debug_async_fops))
1084 goto file_error;
Tony Jones694cc202007-09-11 14:07:31 -07001085
Alan Sternd0ce5c62013-10-11 11:29:13 -04001086 if (!debugfs_create_file("bandwidth", S_IRUGO, ehci->debug_dir, bus,
1087 &debug_bandwidth_fops))
1088 goto file_error;
1089
Ming Lei185c9bc2010-07-28 22:33:28 +08001090 if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus,
1091 &debug_periodic_fops))
1092 goto file_error;
Tony Jones694cc202007-09-11 14:07:31 -07001093
Ming Lei185c9bc2010-07-28 22:33:28 +08001094 if (!debugfs_create_file("registers", S_IRUGO, ehci->debug_dir, bus,
1095 &debug_registers_fops))
1096 goto file_error;
Alek Duaa4d8342010-06-04 15:47:54 +08001097
Tony Jones694cc202007-09-11 14:07:31 -07001098 return;
1099
Ming Lei185c9bc2010-07-28 22:33:28 +08001100file_error:
1101 debugfs_remove_recursive(ehci->debug_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102}
1103
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -03001104static inline void remove_debug_files(struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105{
Ming Lei185c9bc2010-07-28 22:33:28 +08001106 debugfs_remove_recursive(ehci->debug_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107}
1108
1109#endif /* STUB_DEBUG_FILES */