blob: 73ab200332f05ca2423603d1a481d1f85b1ee42b [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 ",
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -030049 (i & 0x1) ? byte & 0xf : (byte >> 4) & 0xf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 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}
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -030056/*
57 * check the values in the HCCPARAMS register
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 * (host controller _Capability_ parameters)
59 * see EHCI Spec, Table 2-5 for each value
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -030060 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030061static void dbg_hcc_params(struct ehci_hcd *ehci, char *label)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +110063 u32 params = ehci_readl(ehci, &ehci->caps->hcc_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030065 if (HCC_ISOC_CACHE(params)) {
66 ehci_dbg(ehci,
Stefan Roese6dbd6822007-05-01 09:29:37 -070067 "%s hcc_params %04x caching frame %s%s%s\n",
68 label, params,
69 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
70 HCC_CANPARK(params) ? " park" : "",
71 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 } else {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030073 ehci_dbg(ehci,
Alek Duaa4d8342010-06-04 15:47:54 +080074 "%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -070075 label,
76 params,
77 HCC_ISOC_THRES(params),
78 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
79 HCC_CANPARK(params) ? " park" : "",
Alek Duaa4d8342010-06-04 15:47:54 +080080 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "",
81 HCC_LPM(params) ? " LPM" : "",
82 HCC_PER_PORT_CHANGE_EVENT(params) ? " ppce" : "",
83 HCC_HW_PREFETCH(params) ? " hw prefetch" : "",
84 HCC_32FRAME_PERIODIC_LIST(params) ?
Masanari Iida855ef452012-02-17 23:06:47 +090085 " 32 periodic list" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 }
87}
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
David Rientjes82345092007-05-11 14:39:44 -070089static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030090dbg_qtd(const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Vamsi Krishna Samavedamf826f832016-11-03 17:06:34 -070092 ehci_dbg(ehci, "%s td %pK n%08x %08x t%08x p0=%08x\n", label, qtd,
Stefan Roese6dbd6822007-05-01 09:29:37 -070093 hc32_to_cpup(ehci, &qtd->hw_next),
94 hc32_to_cpup(ehci, &qtd->hw_alt_next),
95 hc32_to_cpup(ehci, &qtd->hw_token),
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -030096 hc32_to_cpup(ehci, &qtd->hw_buf[0]));
97 if (qtd->hw_buf[1])
Stefan Roese6dbd6822007-05-01 09:29:37 -070098 ehci_dbg(ehci, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
99 hc32_to_cpup(ehci, &qtd->hw_buf[1]),
100 hc32_to_cpup(ehci, &qtd->hw_buf[2]),
101 hc32_to_cpup(ehci, &qtd->hw_buf[3]),
102 hc32_to_cpup(ehci, &qtd->hw_buf[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
David Rientjes82345092007-05-11 14:39:44 -0700105static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300106dbg_qh(const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Alek Du3807e262009-07-14 07:23:29 +0800108 struct ehci_qh_hw *hw = qh->hw;
109
Vamsi Krishna Samavedamf826f832016-11-03 17:06:34 -0700110 ehci_dbg(ehci, "%s qh %pK n%08x info %x %x qtd %x\n", label,
Alek Du3807e262009-07-14 07:23:29 +0800111 qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current);
112 dbg_qtd("overlay", ehci, (struct ehci_qtd *) &hw->hw_qtd_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
David Rientjes82345092007-05-11 14:39:44 -0700115static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300116dbg_itd(const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
Vamsi Krishna Samavedamf826f832016-11-03 17:06:34 -0700118 ehci_dbg(ehci, "%s [%d] itd %pK, next %08x, urb %p\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700119 label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next),
120 itd->urb);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300121 ehci_dbg(ehci,
David Brownell53bd6a62006-08-30 14:50:06 -0700122 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700123 hc32_to_cpu(ehci, itd->hw_transaction[0]),
124 hc32_to_cpu(ehci, itd->hw_transaction[1]),
125 hc32_to_cpu(ehci, itd->hw_transaction[2]),
126 hc32_to_cpu(ehci, itd->hw_transaction[3]),
127 hc32_to_cpu(ehci, itd->hw_transaction[4]),
128 hc32_to_cpu(ehci, itd->hw_transaction[5]),
129 hc32_to_cpu(ehci, itd->hw_transaction[6]),
130 hc32_to_cpu(ehci, itd->hw_transaction[7]));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300131 ehci_dbg(ehci,
David Brownell53bd6a62006-08-30 14:50:06 -0700132 " buf: %08x %08x %08x %08x %08x %08x %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700133 hc32_to_cpu(ehci, itd->hw_bufp[0]),
134 hc32_to_cpu(ehci, itd->hw_bufp[1]),
135 hc32_to_cpu(ehci, itd->hw_bufp[2]),
136 hc32_to_cpu(ehci, itd->hw_bufp[3]),
137 hc32_to_cpu(ehci, itd->hw_bufp[4]),
138 hc32_to_cpu(ehci, itd->hw_bufp[5]),
139 hc32_to_cpu(ehci, itd->hw_bufp[6]));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300140 ehci_dbg(ehci, " index: %d %d %d %d %d %d %d %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 itd->index[0], itd->index[1], itd->index[2],
142 itd->index[3], itd->index[4], itd->index[5],
143 itd->index[6], itd->index[7]);
144}
145
David Rientjes82345092007-05-11 14:39:44 -0700146static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300147dbg_sitd(const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Vamsi Krishna Samavedamf826f832016-11-03 17:06:34 -0700149 ehci_dbg(ehci, "%s [%d] sitd %pK, next %08x, urb %p\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700150 label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next),
151 sitd->urb);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300152 ehci_dbg(ehci,
David Brownell53bd6a62006-08-30 14:50:06 -0700153 " addr %08x sched %04x result %08x buf %08x %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700154 hc32_to_cpu(ehci, sitd->hw_fullspeed_ep),
155 hc32_to_cpu(ehci, sitd->hw_uframe),
156 hc32_to_cpu(ehci, sitd->hw_results),
157 hc32_to_cpu(ehci, sitd->hw_buf[0]),
158 hc32_to_cpu(ehci, sitd->hw_buf[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
David Rientjes82345092007-05-11 14:39:44 -0700161static int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300162dbg_status_buf(char *buf, unsigned len, const char *label, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300164 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800165 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s%s",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300166 label, label[0] ? " " : "", status,
Alek Duaa4d8342010-06-04 15:47:54 +0800167 (status & STS_PPCE_MASK) ? " PPCE" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 (status & STS_ASS) ? " Async" : "",
169 (status & STS_PSS) ? " Periodic" : "",
170 (status & STS_RECL) ? " Recl" : "",
171 (status & STS_HALT) ? " Halt" : "",
172 (status & STS_IAA) ? " IAA" : "",
173 (status & STS_FATAL) ? " FATAL" : "",
174 (status & STS_FLR) ? " FLR" : "",
175 (status & STS_PCD) ? " PCD" : "",
176 (status & STS_ERR) ? " ERR" : "",
Geyslan G. Bem78698d62016-01-25 22:44:57 -0300177 (status & STS_INT) ? " INT" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
David Rientjes82345092007-05-11 14:39:44 -0700180static int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300181dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300183 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800184 "%s%sintrenable %02x%s%s%s%s%s%s%s",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300185 label, label[0] ? " " : "", enable,
Alek Duaa4d8342010-06-04 15:47:54 +0800186 (enable & STS_PPCE_MASK) ? " PPCE" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 (enable & STS_IAA) ? " IAA" : "",
188 (enable & STS_FATAL) ? " FATAL" : "",
189 (enable & STS_FLR) ? " FLR" : "",
190 (enable & STS_PCD) ? " PCD" : "",
191 (enable & STS_ERR) ? " ERR" : "",
Geyslan G. Bem78698d62016-01-25 22:44:57 -0300192 (enable & STS_INT) ? " INT" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300195static const char *const fls_strings[] = { "1024", "512", "256", "??" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197static int
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300198dbg_command_buf(char *buf, unsigned len, const char *label, u32 command)
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%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s "
202 "period=%s%s %s",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300203 label, label[0] ? " " : "", command,
Alek Duaa4d8342010-06-04 15:47:54 +0800204 (command & CMD_HIRD) ? " HIRD" : "",
205 (command & CMD_PPCEE) ? " PPCEE" : "",
206 (command & CMD_FSP) ? " FSP" : "",
207 (command & CMD_ASPE) ? " ASPE" : "",
208 (command & CMD_PSPE) ? " PSPE" : "",
209 (command & CMD_PARK) ? " park" : "(park)",
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300210 CMD_PARK_CNT(command),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 (command >> 16) & 0x3f,
212 (command & CMD_LRESET) ? " LReset" : "",
213 (command & CMD_IAAD) ? " IAAD" : "",
214 (command & CMD_ASE) ? " Async" : "",
215 (command & CMD_PSE) ? " Periodic" : "",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300216 fls_strings[(command >> 2) & 0x3],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 (command & CMD_RESET) ? " Reset" : "",
Geyslan G. Bem78698d62016-01-25 22:44:57 -0300218 (command & CMD_RUN) ? "RUN" : "HALT");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
221static int
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300222dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
224 char *sig;
225
226 /* signaling state */
227 switch (status & (3 << 10)) {
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300228 case 0 << 10:
229 sig = "se0";
230 break;
231 case 1 << 10: /* low speed */
232 sig = "k";
233 break;
234 case 2 << 10:
235 sig = "j";
236 break;
237 default:
238 sig = "?";
239 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 }
241
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300242 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800243 "%s%sport:%d status %06x %d %s%s%s%s%s%s "
244 "sig=%s%s%s%s%s%s%s%s%s%s%s",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300245 label, label[0] ? " " : "", port, status,
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -0300246 status >> 25, /*device address */
247 (status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_ACK ?
Alek Duaa4d8342010-06-04 15:47:54 +0800248 " ACK" : "",
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -0300249 (status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_NYET ?
Alek Duaa4d8342010-06-04 15:47:54 +0800250 " NYET" : "",
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -0300251 (status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_STALL ?
Alek Duaa4d8342010-06-04 15:47:54 +0800252 " STALL" : "",
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -0300253 (status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_ERR ?
Alek Duaa4d8342010-06-04 15:47:54 +0800254 " ERR" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 (status & PORT_POWER) ? " POWER" : "",
256 (status & PORT_OWNER) ? " OWNER" : "",
257 sig,
Alek Duaa4d8342010-06-04 15:47:54 +0800258 (status & PORT_LPM) ? " LPM" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 (status & PORT_RESET) ? " RESET" : "",
260 (status & PORT_SUSPEND) ? " SUSPEND" : "",
261 (status & PORT_RESUME) ? " RESUME" : "",
262 (status & PORT_OCC) ? " OCC" : "",
263 (status & PORT_OC) ? " OC" : "",
264 (status & PORT_PEC) ? " PEC" : "",
265 (status & PORT_PE) ? " PE" : "",
266 (status & PORT_CSC) ? " CSC" : "",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700267 (status & PORT_CONNECT) ? " CONNECT" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268}
269
Geyslan G. Bem1f8e5af2016-01-25 22:45:02 -0300270static inline void
271dbg_status(struct ehci_hcd *ehci, const char *label, u32 status)
272{
273 char buf[80];
274
275 dbg_status_buf(buf, sizeof(buf), label, status);
276 ehci_dbg(ehci, "%s\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
Geyslan G. Bem1f8e5af2016-01-25 22:45:02 -0300279static inline void
280dbg_cmd(struct ehci_hcd *ehci, const char *label, u32 command)
281{
282 char buf[80];
283
284 dbg_command_buf(buf, sizeof(buf), label, command);
285 ehci_dbg(ehci, "%s\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
287
Geyslan G. Bem1f8e5af2016-01-25 22:45:02 -0300288static inline void
289dbg_port(struct ehci_hcd *ehci, const char *label, int port, u32 status)
290{
291 char buf[80];
292
293 dbg_port_buf(buf, sizeof(buf), label, port, status);
294 ehci_dbg(ehci, "%s\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
297/*-------------------------------------------------------------------------*/
298
Tony Jones694cc202007-09-11 14:07:31 -0700299/* troubleshooting help: expose state in debugfs */
300
301static int debug_async_open(struct inode *, struct file *);
Alan Sternd0ce5c62013-10-11 11:29:13 -0400302static int debug_bandwidth_open(struct inode *, struct file *);
Tony Jones694cc202007-09-11 14:07:31 -0700303static int debug_periodic_open(struct inode *, struct file *);
304static int debug_registers_open(struct inode *, struct file *);
Alek Duaa4d8342010-06-04 15:47:54 +0800305
Tony Jones694cc202007-09-11 14:07:31 -0700306static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
307static int debug_close(struct inode *, struct file *);
308
309static const struct file_operations debug_async_fops = {
310 .owner = THIS_MODULE,
311 .open = debug_async_open,
312 .read = debug_output,
313 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200314 .llseek = default_llseek,
Tony Jones694cc202007-09-11 14:07:31 -0700315};
Geyslan G. Beme1666312016-01-25 22:45:01 -0300316
Alan Sternd0ce5c62013-10-11 11:29:13 -0400317static const struct file_operations debug_bandwidth_fops = {
318 .owner = THIS_MODULE,
319 .open = debug_bandwidth_open,
320 .read = debug_output,
321 .release = debug_close,
322 .llseek = default_llseek,
323};
Geyslan G. Beme1666312016-01-25 22:45:01 -0300324
Tony Jones694cc202007-09-11 14:07:31 -0700325static const struct file_operations debug_periodic_fops = {
326 .owner = THIS_MODULE,
327 .open = debug_periodic_open,
328 .read = debug_output,
329 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200330 .llseek = default_llseek,
Tony Jones694cc202007-09-11 14:07:31 -0700331};
Geyslan G. Beme1666312016-01-25 22:45:01 -0300332
Tony Jones694cc202007-09-11 14:07:31 -0700333static const struct file_operations debug_registers_fops = {
334 .owner = THIS_MODULE,
335 .open = debug_registers_open,
336 .read = debug_output,
337 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200338 .llseek = default_llseek,
Tony Jones694cc202007-09-11 14:07:31 -0700339};
340
341static struct dentry *ehci_debug_root;
342
343struct debug_buffer {
344 ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
345 struct usb_bus *bus;
346 struct mutex mutex; /* protect filling of buffer */
347 size_t count; /* number of characters filled into buffer */
Ming Lei3c04e202008-09-18 23:06:21 +0800348 char *output_buf;
349 size_t alloc_size;
Tony Jones694cc202007-09-11 14:07:31 -0700350};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Geyslan G. Bem1f8e5af2016-01-25 22:45:02 -0300352static inline char speed_char(u32 info1)
353{
354 switch (info1 & (3 << 12)) {
355 case QH_FULL_SPEED:
356 return 'f';
357 case QH_LOW_SPEED:
358 return 'l';
359 case QH_HIGH_SPEED:
360 return 'h';
361 default:
362 return '?';
363 }
364}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Stefan Roese6dbd6822007-05-01 09:29:37 -0700366static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
Stefan Roese6dbd6822007-05-01 09:29:37 -0700368 __u32 v = hc32_to_cpu(ehci, token);
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 if (v & QTD_STS_ACTIVE)
371 return '*';
372 if (v & QTD_STS_HALT)
373 return '-';
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300374 if (!IS_SHORT_READ(v))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 return ' ';
376 /* tries to advance through hw_alt_next */
377 return '/';
378}
379
Geyslan G. Bemc768ffb2016-01-25 22:45:00 -0300380static void qh_lines(struct ehci_hcd *ehci, struct ehci_qh *qh,
381 char **nextp, unsigned *sizep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
383 u32 scratch;
384 u32 hw_curr;
385 struct list_head *entry;
386 struct ehci_qtd *td;
387 unsigned temp;
388 unsigned size = *sizep;
389 char *next = *nextp;
390 char mark;
Al Virofd05e722008-04-28 07:00:16 +0100391 __le32 list_end = EHCI_LIST_END(ehci);
Alek Du3807e262009-07-14 07:23:29 +0800392 struct ehci_qh_hw *hw = qh->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Alek Du3807e262009-07-14 07:23:29 +0800394 if (hw->hw_qtd_next == list_end) /* NEC does this */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 mark = '@';
396 else
Alek Du3807e262009-07-14 07:23:29 +0800397 mark = token_mark(ehci, hw->hw_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 if (mark == '/') { /* qh_alt_next controls qh advance? */
Alek Du3807e262009-07-14 07:23:29 +0800399 if ((hw->hw_alt_next & QTD_MASK(ehci))
400 == ehci->async->hw->hw_alt_next)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 mark = '#'; /* blocked */
Alek Du3807e262009-07-14 07:23:29 +0800402 else if (hw->hw_alt_next == list_end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 mark = '.'; /* use hw_qtd_next */
404 /* else alt_next points to some other qtd */
405 }
Alek Du3807e262009-07-14 07:23:29 +0800406 scratch = hc32_to_cpup(ehci, &hw->hw_info1);
407 hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300408 temp = scnprintf(next, size,
Vamsi Krishna Samavedamf826f832016-11-03 17:06:34 -0700409 "qh/%pK dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)"
Alan Stern8ee10d62015-11-20 13:53:45 -0500410 " [cur %08x next %08x buf[0] %08x]",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 qh, scratch & 0x007f,
412 speed_char (scratch),
413 (scratch >> 8) & 0x000f,
Alek Du3807e262009-07-14 07:23:29 +0800414 scratch, hc32_to_cpup(ehci, &hw->hw_info2),
415 hc32_to_cpup(ehci, &hw->hw_token), mark,
416 (cpu_to_hc32(ehci, QTD_TOGGLE) & hw->hw_token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 ? "data1" : "data0",
Alan Stern8ee10d62015-11-20 13:53:45 -0500418 (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f,
419 hc32_to_cpup(ehci, &hw->hw_current),
420 hc32_to_cpup(ehci, &hw->hw_qtd_next),
421 hc32_to_cpup(ehci, &hw->hw_buf[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 size -= temp;
423 next += temp;
424
425 /* hc may be modifying the list as we read it ... */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300426 list_for_each(entry, &qh->qtd_list) {
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300427 char *type;
428
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300429 td = list_entry(entry, struct ehci_qtd, qtd_list);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700430 scratch = hc32_to_cpup(ehci, &td->hw_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 mark = ' ';
Geyslan G. Bem04b8ad42016-01-25 22:45:06 -0300432 if (hw_curr == td->qtd_dma) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 mark = '*';
Geyslan G. Bem04b8ad42016-01-25 22:45:06 -0300434 } else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 mark = '+';
Geyslan G. Bem04b8ad42016-01-25 22:45:06 -0300436 } else if (QTD_LENGTH(scratch)) {
Alek Du3807e262009-07-14 07:23:29 +0800437 if (td->hw_alt_next == ehci->async->hw->hw_alt_next)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 mark = '#';
Stefan Roese6dbd6822007-05-01 09:29:37 -0700439 else if (td->hw_alt_next != list_end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 mark = '/';
441 }
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300442 switch ((scratch >> 8) & 0x03) {
443 case 0:
444 type = "out";
445 break;
446 case 1:
447 type = "in";
448 break;
449 case 2:
450 type = "setup";
451 break;
452 default:
453 type = "?";
454 break;
455 }
Geyslan G. Bema5355972016-01-25 22:44:59 -0300456 temp = scnprintf(next, size,
Vamsi Krishna Samavedamf826f832016-11-03 17:06:34 -0700457 "\n\t%pK%c%s len=%d %08x urb %pK"
Alan Stern8ee10d62015-11-20 13:53:45 -0500458 " [td %08x buf[0] %08x]",
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300459 td, mark, type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 (scratch >> 16) & 0x7fff,
461 scratch,
Alan Stern8ee10d62015-11-20 13:53:45 -0500462 td->urb,
463 (u32) td->qtd_dma,
464 hc32_to_cpup(ehci, &td->hw_buf[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 size -= temp;
466 next += temp;
467 if (temp == size)
468 goto done;
469 }
470
Geyslan G. Bema5355972016-01-25 22:44:59 -0300471 temp = scnprintf(next, size, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 size -= temp;
473 next += temp;
474
475done:
476 *sizep = size;
477 *nextp = next;
478}
479
Tony Jones694cc202007-09-11 14:07:31 -0700480static ssize_t fill_async_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 struct usb_hcd *hcd;
483 struct ehci_hcd *ehci;
484 unsigned long flags;
485 unsigned temp, size;
486 char *next;
487 struct ehci_qh *qh;
488
Tony Jones694cc202007-09-11 14:07:31 -0700489 hcd = bus_to_hcd(buf->bus);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300490 ehci = hcd_to_ehci(hcd);
Ming Lei3c04e202008-09-18 23:06:21 +0800491 next = buf->output_buf;
492 size = buf->alloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Tony Jones694cc202007-09-11 14:07:31 -0700494 *next = 0;
495
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -0300496 /*
497 * dumps a snapshot of the async schedule.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 * usually empty except for long-term bulk reads, or head.
499 * one QH per line, and TDs we know about
500 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300501 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300503 qh_lines(ehci, qh, &next, &size);
Alan Stern6e018752013-03-22 13:31:45 -0400504 if (!list_empty(&ehci->async_unlink) && size > 0) {
Alan Stern99ac5b12012-07-11 11:21:38 -0400505 temp = scnprintf(next, size, "\nunlink =\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 size -= temp;
507 next += temp;
508
Alan Stern6e018752013-03-22 13:31:45 -0400509 list_for_each_entry(qh, &ehci->async_unlink, unlink_node) {
510 if (size <= 0)
511 break;
512 qh_lines(ehci, qh, &next, &size);
513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300515 spin_unlock_irqrestore(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Ming Lei3c04e202008-09-18 23:06:21 +0800517 return strlen(buf->output_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Alan Sternd0ce5c62013-10-11 11:29:13 -0400520static ssize_t fill_bandwidth_buffer(struct debug_buffer *buf)
521{
522 struct ehci_hcd *ehci;
Alan Sternb35c5002013-10-11 22:16:21 -0400523 struct ehci_tt *tt;
524 struct ehci_per_sched *ps;
Alan Sternd0ce5c62013-10-11 11:29:13 -0400525 unsigned temp, size;
526 char *next;
527 unsigned i;
528 u8 *bw;
Alan Sternb35c5002013-10-11 22:16:21 -0400529 u16 *bf;
530 u8 budget[EHCI_BANDWIDTH_SIZE];
Alan Sternd0ce5c62013-10-11 11:29:13 -0400531
532 ehci = hcd_to_ehci(bus_to_hcd(buf->bus));
533 next = buf->output_buf;
534 size = buf->alloc_size;
535
536 *next = 0;
537
538 spin_lock_irq(&ehci->lock);
539
540 /* Dump the HS bandwidth table */
541 temp = scnprintf(next, size,
542 "HS bandwidth allocation (us per microframe)\n");
543 size -= temp;
544 next += temp;
545 for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
546 bw = &ehci->bandwidth[i];
547 temp = scnprintf(next, size,
548 "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
549 i, bw[0], bw[1], bw[2], bw[3],
550 bw[4], bw[5], bw[6], bw[7]);
551 size -= temp;
552 next += temp;
553 }
Alan Sternb35c5002013-10-11 22:16:21 -0400554
555 /* Dump all the FS/LS tables */
556 list_for_each_entry(tt, &ehci->tt_list, tt_list) {
557 temp = scnprintf(next, size,
558 "\nTT %s port %d FS/LS bandwidth allocation (us per frame)\n",
559 dev_name(&tt->usb_tt->hub->dev),
560 tt->tt_port + !!tt->usb_tt->multi);
561 size -= temp;
562 next += temp;
563
564 bf = tt->bandwidth;
565 temp = scnprintf(next, size,
566 " %5u%5u%5u%5u%5u%5u%5u%5u\n",
567 bf[0], bf[1], bf[2], bf[3],
568 bf[4], bf[5], bf[6], bf[7]);
569 size -= temp;
570 next += temp;
571
572 temp = scnprintf(next, size,
573 "FS/LS budget (us per microframe)\n");
574 size -= temp;
575 next += temp;
576 compute_tt_budget(budget, tt);
577 for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
578 bw = &budget[i];
579 temp = scnprintf(next, size,
580 "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
581 i, bw[0], bw[1], bw[2], bw[3],
582 bw[4], bw[5], bw[6], bw[7]);
583 size -= temp;
584 next += temp;
585 }
586 list_for_each_entry(ps, &tt->ps_list, ps_list) {
587 temp = scnprintf(next, size,
588 "%s ep %02x: %4u @ %2u.%u+%u mask %04x\n",
589 dev_name(&ps->udev->dev),
590 ps->ep->desc.bEndpointAddress,
591 ps->tt_usecs,
592 ps->bw_phase, ps->phase_uf,
593 ps->bw_period, ps->cs_mask);
594 size -= temp;
595 next += temp;
596 }
597 }
Alan Sternd0ce5c62013-10-11 11:29:13 -0400598 spin_unlock_irq(&ehci->lock);
599
600 return next - buf->output_buf;
601}
602
Geyslan G. Bem3fd29002016-01-25 22:45:08 -0300603static unsigned output_buf_tds_dir(char *buf, struct ehci_hcd *ehci,
604 struct ehci_qh_hw *hw, struct ehci_qh *qh, unsigned size)
605{
606 u32 scratch = hc32_to_cpup(ehci, &hw->hw_info1);
607 struct ehci_qtd *qtd;
608 char *type = "";
609 unsigned temp = 0;
610
611 /* count tds, get ep direction */
612 list_for_each_entry(qtd, &qh->qtd_list, qtd_list) {
613 temp++;
614 switch ((hc32_to_cpu(ehci, qtd->hw_token) >> 8) & 0x03) {
615 case 0:
616 type = "out";
617 continue;
618 case 1:
619 type = "in";
620 continue;
621 }
622 }
623
624 return scnprintf(buf, size, " (%c%d ep%d%s [%d/%d] q%d p%d)",
625 speed_char(scratch), scratch & 0x007f,
626 (scratch >> 8) & 0x000f, type, qh->ps.usecs,
627 qh->ps.c_usecs, temp, 0x7ff & (scratch >> 16));
628}
629
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630#define DBG_SCHED_LIMIT 64
Tony Jones694cc202007-09-11 14:07:31 -0700631static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 struct usb_hcd *hcd;
634 struct ehci_hcd *ehci;
635 unsigned long flags;
636 union ehci_shadow p, *seen;
637 unsigned temp, size, seen_count;
638 char *next;
639 unsigned i;
Stefan Roese6dbd6822007-05-01 09:29:37 -0700640 __hc32 tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Geyslan G. Bemcb272522016-01-25 22:45:07 -0300642 seen = kmalloc_array(DBG_SCHED_LIMIT, sizeof(*seen), GFP_ATOMIC);
Greg Kroah-Hartman911fdb62015-04-30 11:32:50 +0200643 if (!seen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 return 0;
645 seen_count = 0;
646
Tony Jones694cc202007-09-11 14:07:31 -0700647 hcd = bus_to_hcd(buf->bus);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300648 ehci = hcd_to_ehci(hcd);
Ming Lei3c04e202008-09-18 23:06:21 +0800649 next = buf->output_buf;
650 size = buf->alloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300652 temp = scnprintf(next, size, "size = %d\n", ehci->periodic_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 size -= temp;
654 next += temp;
655
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -0300656 /*
657 * dump a snapshot of the periodic schedule.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 * iso changes, interrupt usually doesn't.
659 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300660 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 for (i = 0; i < ehci->periodic_size; i++) {
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300662 p = ehci->pshadow[i];
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300663 if (likely(!p.ptr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 continue;
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300665 tag = Q_NEXT_TYPE(ehci, ehci->periodic[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300667 temp = scnprintf(next, size, "%4d: ", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 size -= temp;
669 next += temp;
670
671 do {
Alek Du3807e262009-07-14 07:23:29 +0800672 struct ehci_qh_hw *hw;
673
Stefan Roese6dbd6822007-05-01 09:29:37 -0700674 switch (hc32_to_cpu(ehci, tag)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 case Q_TYPE_QH:
Alek Du3807e262009-07-14 07:23:29 +0800676 hw = p.qh->hw;
Vamsi Krishna Samavedamf826f832016-11-03 17:06:34 -0700677 temp = scnprintf(next, size, " qh%d-%04x/%pK",
Alan Sternffa02482013-10-11 11:29:03 -0400678 p.qh->ps.period,
Stefan Roese6dbd6822007-05-01 09:29:37 -0700679 hc32_to_cpup(ehci,
Alek Du3807e262009-07-14 07:23:29 +0800680 &hw->hw_info2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 /* uframe masks */
David Brownell7dedacf2005-08-04 18:06:41 -0700682 & (QH_CMASK | QH_SMASK),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 p.qh);
684 size -= temp;
685 next += temp;
686 /* don't repeat what follows this qh */
687 for (temp = 0; temp < seen_count; temp++) {
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300688 if (seen[temp].ptr != p.ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 continue;
Ming Lei3c4bb712008-09-18 23:06:38 +0800690 if (p.qh->qh_next.ptr) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300691 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 " ...");
Ming Lei3c4bb712008-09-18 23:06:38 +0800693 size -= temp;
694 next += temp;
695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 break;
697 }
698 /* show more info the first time around */
Ming Lei3c4bb712008-09-18 23:06:38 +0800699 if (temp == seen_count) {
Geyslan G. Bem3fd29002016-01-25 22:45:08 -0300700 temp = output_buf_tds_dir(next, ehci,
701 hw, p.qh, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
703 if (seen_count < DBG_SCHED_LIMIT)
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300704 seen[seen_count++].qh = p.qh;
Geyslan G. Bem04b8ad42016-01-25 22:45:06 -0300705 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 temp = 0;
Geyslan G. Bem04b8ad42016-01-25 22:45:06 -0300707 }
Alan Stern17dcfc92012-09-19 17:00:55 -0400708 tag = Q_NEXT_TYPE(ehci, hw->hw_next);
709 p = p.qh->qh_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 break;
711 case Q_TYPE_FSTN:
Vamsi Krishna Samavedamf826f832016-11-03 17:06:34 -0700712 temp = scnprintf (next, size,
713 " fstn-%8x/%pK", p.fstn->hw_prev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 p.fstn);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700715 tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 p = p.fstn->fstn_next;
717 break;
718 case Q_TYPE_ITD:
Vamsi Krishna Samavedamf826f832016-11-03 17:06:34 -0700719 temp = scnprintf (next, size,
720 " itd/%pK", p.itd);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700721 tag = Q_NEXT_TYPE(ehci, p.itd->hw_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 p = p.itd->itd_next;
723 break;
724 case Q_TYPE_SITD:
Vamsi Krishna Samavedamf826f832016-11-03 17:06:34 -0700725 temp = scnprintf (next, size,
726 " sitd%d-%04x/%pK",
Alan Sternffa02482013-10-11 11:29:03 -0400727 p.sitd->stream->ps.period,
Stefan Roese6dbd6822007-05-01 09:29:37 -0700728 hc32_to_cpup(ehci, &p.sitd->hw_uframe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 & 0x0000ffff,
730 p.sitd);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700731 tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 p = p.sitd->sitd_next;
733 break;
734 }
735 size -= temp;
736 next += temp;
737 } while (p.ptr);
738
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300739 temp = scnprintf(next, size, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 size -= temp;
741 next += temp;
742 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300743 spin_unlock_irqrestore(&ehci->lock, flags);
744 kfree(seen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Ming Lei3c04e202008-09-18 23:06:21 +0800746 return buf->alloc_size - size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748#undef DBG_SCHED_LIMIT
749
Alan Sterne8799902011-08-18 16:31:30 -0400750static const char *rh_state_string(struct ehci_hcd *ehci)
751{
752 switch (ehci->rh_state) {
753 case EHCI_RH_HALTED:
754 return "halted";
755 case EHCI_RH_SUSPENDED:
756 return "suspended";
757 case EHCI_RH_RUNNING:
758 return "running";
Alan Sternc0c53db2012-07-11 11:21:48 -0400759 case EHCI_RH_STOPPING:
760 return "stopping";
Alan Sterne8799902011-08-18 16:31:30 -0400761 }
762 return "?";
763}
764
Tony Jones694cc202007-09-11 14:07:31 -0700765static ssize_t fill_registers_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 struct usb_hcd *hcd;
768 struct ehci_hcd *ehci;
769 unsigned long flags;
770 unsigned temp, size, i;
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300771 char *next, scratch[80];
772 static char fmt[] = "%*s\n";
773 static char label[] = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Tony Jones694cc202007-09-11 14:07:31 -0700775 hcd = bus_to_hcd(buf->bus);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300776 ehci = hcd_to_ehci(hcd);
Ming Lei3c04e202008-09-18 23:06:21 +0800777 next = buf->output_buf;
778 size = buf->alloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300780 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Alan Stern541c7d42010-06-22 16:39:10 -0400782 if (!HCD_HW_ACCESSIBLE(hcd)) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300783 size = scnprintf(next, size,
Alan Stern2b70f072008-10-02 11:47:15 -0400784 "bus %s, device %s\n"
David Brownelld49d4312005-05-07 13:21:50 -0700785 "%s\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 "SUSPENDED (no register access)\n",
787 hcd->self.controller->bus->name,
Kay Sievers7071a3c2008-05-02 06:02:41 +0200788 dev_name(hcd->self.controller),
David Brownelld49d4312005-05-07 13:21:50 -0700789 hcd->product_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 goto done;
791 }
792
793 /* Capability Registers */
Jan Anderssonc4301312011-05-03 20:11:57 +0200794 i = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300795 temp = scnprintf(next, size,
Alan Stern2b70f072008-10-02 11:47:15 -0400796 "bus %s, device %s\n"
David Brownelld49d4312005-05-07 13:21:50 -0700797 "%s\n"
Alan Sterne8799902011-08-18 16:31:30 -0400798 "EHCI %x.%02x, rh state %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 hcd->self.controller->bus->name,
Kay Sievers7071a3c2008-05-02 06:02:41 +0200800 dev_name(hcd->self.controller),
David Brownelld49d4312005-05-07 13:21:50 -0700801 hcd->product_desc,
Alan Sterne8799902011-08-18 16:31:30 -0400802 i >> 8, i & 0x0ff, rh_state_string(ehci));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 size -= temp;
804 next += temp;
805
David Brownelld49d4312005-05-07 13:21:50 -0700806#ifdef CONFIG_PCI
807 /* EHCI 0.96 and later may have "extended capabilities" */
Yijing Wange10e6f42013-12-05 19:21:32 +0800808 if (dev_is_pci(hcd->self.controller)) {
David Brownelld49d4312005-05-07 13:21:50 -0700809 struct pci_dev *pdev;
810 u32 offset, cap, cap2;
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -0300811 unsigned count = 256 / 4;
David Brownelld49d4312005-05-07 13:21:50 -0700812
813 pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700814 offset = HCC_EXT_CAPS(ehci_readl(ehci,
815 &ehci->caps->hcc_params));
David Brownelld49d4312005-05-07 13:21:50 -0700816 while (offset && count--) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300817 pci_read_config_dword(pdev, offset, &cap);
David Brownelld49d4312005-05-07 13:21:50 -0700818 switch (cap & 0xff) {
819 case 1:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300820 temp = scnprintf(next, size,
David Brownelld49d4312005-05-07 13:21:50 -0700821 "ownership %08x%s%s\n", cap,
822 (cap & (1 << 24)) ? " linux" : "",
823 (cap & (1 << 16)) ? " firmware" : "");
824 size -= temp;
825 next += temp;
826
827 offset += 4;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300828 pci_read_config_dword(pdev, offset, &cap2);
829 temp = scnprintf(next, size,
David Brownelld49d4312005-05-07 13:21:50 -0700830 "SMI sts/enable 0x%08x\n", cap2);
831 size -= temp;
832 next += temp;
833 break;
834 case 0: /* illegal reserved capability */
835 cap = 0;
836 /* FALLTHROUGH */
837 default: /* unknown */
838 break;
839 }
Colin Ian King08dd0382017-11-07 16:45:04 +0000840 offset = (cap >> 8) & 0xff;
David Brownelld49d4312005-05-07 13:21:50 -0700841 }
842 }
843#endif
844
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -0300845 /* FIXME interpret both types of params */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100846 i = ehci_readl(ehci, &ehci->caps->hcs_params);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300847 temp = scnprintf(next, size, "structural params 0x%08x\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 size -= temp;
849 next += temp;
850
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100851 i = ehci_readl(ehci, &ehci->caps->hcc_params);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300852 temp = scnprintf(next, size, "capability params 0x%08x\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 size -= temp;
854 next += temp;
855
856 /* Operational Registers */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300857 temp = dbg_status_buf(scratch, sizeof(scratch), label,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100858 ehci_readl(ehci, &ehci->regs->status));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300859 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 size -= temp;
861 next += temp;
862
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300863 temp = dbg_command_buf(scratch, sizeof(scratch), label,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100864 ehci_readl(ehci, &ehci->regs->command));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300865 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 size -= temp;
867 next += temp;
868
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300869 temp = dbg_intr_buf(scratch, sizeof(scratch), label,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100870 ehci_readl(ehci, &ehci->regs->intr_enable));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300871 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 size -= temp;
873 next += temp;
874
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300875 temp = scnprintf(next, size, "uframe %04x\n",
Alan Stern68aa95d2011-10-12 10:39:14 -0400876 ehci_read_frame_index(ehci));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 size -= temp;
878 next += temp;
879
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300880 for (i = 1; i <= HCS_N_PORTS(ehci->hcs_params); i++) {
881 temp = dbg_port_buf(scratch, sizeof(scratch), label, i,
Stefan Roese6dbd6822007-05-01 09:29:37 -0700882 ehci_readl(ehci,
883 &ehci->regs->port_status[i - 1]));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300884 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 size -= temp;
886 next += temp;
David Brownelld49d4312005-05-07 13:21:50 -0700887 if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300888 temp = scnprintf(next, size,
David Brownelld49d4312005-05-07 13:21:50 -0700889 " debug control %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700890 ehci_readl(ehci,
891 &ehci->debug->control));
David Brownelld49d4312005-05-07 13:21:50 -0700892 size -= temp;
893 next += temp;
894 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 }
896
Alan Stern6e018752013-03-22 13:31:45 -0400897 if (!list_empty(&ehci->async_unlink)) {
Vamsi Krishna Samavedamf826f832016-11-03 17:06:34 -0700898 temp = scnprintf(next, size, "async unlink qh %pK\n",
Alan Stern6e018752013-03-22 13:31:45 -0400899 list_first_entry(&ehci->async_unlink,
900 struct ehci_qh, unlink_node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 size -= temp;
902 next += temp;
903 }
904
905#ifdef EHCI_STATS
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300906 temp = scnprintf(next, size,
Alan Stern99ac5b12012-07-11 11:21:38 -0400907 "irq normal %ld err %ld iaa %ld (lost %ld)\n",
908 ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 ehci->stats.lost_iaa);
910 size -= temp;
911 next += temp;
912
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300913 temp = scnprintf(next, size, "complete %ld unlink %ld\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 ehci->stats.complete, ehci->stats.unlink);
915 size -= temp;
916 next += temp;
917#endif
918
919done:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300920 spin_unlock_irqrestore(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Ming Lei3c04e202008-09-18 23:06:21 +0800922 return buf->alloc_size - size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923}
Tony Jones694cc202007-09-11 14:07:31 -0700924
925static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
Geyslan G. Bemc768ffb2016-01-25 22:45:00 -0300926 ssize_t (*fill_func)(struct debug_buffer *))
Tony Jones694cc202007-09-11 14:07:31 -0700927{
928 struct debug_buffer *buf;
929
Geyslan G. Bem12ef7dd2016-01-25 22:45:05 -0300930 buf = kzalloc(sizeof(*buf), GFP_KERNEL);
Tony Jones694cc202007-09-11 14:07:31 -0700931
932 if (buf) {
933 buf->bus = bus;
934 buf->fill_func = fill_func;
935 mutex_init(&buf->mutex);
Ming Lei3c04e202008-09-18 23:06:21 +0800936 buf->alloc_size = PAGE_SIZE;
Tony Jones694cc202007-09-11 14:07:31 -0700937 }
938
939 return buf;
940}
941
942static int fill_buffer(struct debug_buffer *buf)
943{
944 int ret = 0;
945
Ming Lei3c04e202008-09-18 23:06:21 +0800946 if (!buf->output_buf)
Jesper Juhl73f35c62010-11-09 00:10:52 +0100947 buf->output_buf = vmalloc(buf->alloc_size);
Tony Jones694cc202007-09-11 14:07:31 -0700948
Ming Lei3c04e202008-09-18 23:06:21 +0800949 if (!buf->output_buf) {
Tony Jones694cc202007-09-11 14:07:31 -0700950 ret = -ENOMEM;
951 goto out;
952 }
953
954 ret = buf->fill_func(buf);
955
956 if (ret >= 0) {
957 buf->count = ret;
958 ret = 0;
959 }
960
961out:
962 return ret;
963}
964
965static ssize_t debug_output(struct file *file, char __user *user_buf,
Geyslan G. Bemc768ffb2016-01-25 22:45:00 -0300966 size_t len, loff_t *offset)
Tony Jones694cc202007-09-11 14:07:31 -0700967{
968 struct debug_buffer *buf = file->private_data;
969 int ret = 0;
970
971 mutex_lock(&buf->mutex);
972 if (buf->count == 0) {
973 ret = fill_buffer(buf);
974 if (ret != 0) {
975 mutex_unlock(&buf->mutex);
976 goto out;
977 }
978 }
979 mutex_unlock(&buf->mutex);
980
981 ret = simple_read_from_buffer(user_buf, len, offset,
Ming Lei3c04e202008-09-18 23:06:21 +0800982 buf->output_buf, buf->count);
Tony Jones694cc202007-09-11 14:07:31 -0700983
984out:
985 return ret;
Tony Jones694cc202007-09-11 14:07:31 -0700986}
987
988static int debug_close(struct inode *inode, struct file *file)
989{
990 struct debug_buffer *buf = file->private_data;
991
992 if (buf) {
Figo.zhangf8086a02009-06-06 20:31:49 +0800993 vfree(buf->output_buf);
Tony Jones694cc202007-09-11 14:07:31 -0700994 kfree(buf);
995 }
996
997 return 0;
998}
Alan Sternd0ce5c62013-10-11 11:29:13 -0400999
Tony Jones694cc202007-09-11 14:07:31 -07001000static int debug_async_open(struct inode *inode, struct file *file)
1001{
1002 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
1003
1004 return file->private_data ? 0 : -ENOMEM;
1005}
1006
Alan Sternd0ce5c62013-10-11 11:29:13 -04001007static int debug_bandwidth_open(struct inode *inode, struct file *file)
1008{
1009 file->private_data = alloc_buffer(inode->i_private,
1010 fill_bandwidth_buffer);
1011
1012 return file->private_data ? 0 : -ENOMEM;
1013}
1014
Tony Jones694cc202007-09-11 14:07:31 -07001015static int debug_periodic_open(struct inode *inode, struct file *file)
1016{
Ming Lei3c04e202008-09-18 23:06:21 +08001017 struct debug_buffer *buf;
Geyslan G. Bem8d587d62016-01-25 22:45:03 -03001018
Ming Lei3c04e202008-09-18 23:06:21 +08001019 buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
1020 if (!buf)
1021 return -ENOMEM;
Tony Jones694cc202007-09-11 14:07:31 -07001022
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -03001023 buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8) * PAGE_SIZE;
Ming Lei3c04e202008-09-18 23:06:21 +08001024 file->private_data = buf;
1025 return 0;
Tony Jones694cc202007-09-11 14:07:31 -07001026}
1027
1028static int debug_registers_open(struct inode *inode, struct file *file)
1029{
1030 file->private_data = alloc_buffer(inode->i_private,
1031 fill_registers_buffer);
1032
1033 return file->private_data ? 0 : -ENOMEM;
1034}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -03001036static inline void create_debug_files(struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037{
Tony Jones694cc202007-09-11 14:07:31 -07001038 struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Tony Jones694cc202007-09-11 14:07:31 -07001040 ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
1041 if (!ehci->debug_dir)
Ming Lei185c9bc2010-07-28 22:33:28 +08001042 return;
Tony Jones694cc202007-09-11 14:07:31 -07001043
Ming Lei185c9bc2010-07-28 22:33:28 +08001044 if (!debugfs_create_file("async", S_IRUGO, ehci->debug_dir, bus,
1045 &debug_async_fops))
1046 goto file_error;
Tony Jones694cc202007-09-11 14:07:31 -07001047
Alan Sternd0ce5c62013-10-11 11:29:13 -04001048 if (!debugfs_create_file("bandwidth", S_IRUGO, ehci->debug_dir, bus,
1049 &debug_bandwidth_fops))
1050 goto file_error;
1051
Ming Lei185c9bc2010-07-28 22:33:28 +08001052 if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus,
1053 &debug_periodic_fops))
1054 goto file_error;
Tony Jones694cc202007-09-11 14:07:31 -07001055
Ming Lei185c9bc2010-07-28 22:33:28 +08001056 if (!debugfs_create_file("registers", S_IRUGO, ehci->debug_dir, bus,
1057 &debug_registers_fops))
1058 goto file_error;
Alek Duaa4d8342010-06-04 15:47:54 +08001059
Tony Jones694cc202007-09-11 14:07:31 -07001060 return;
1061
Ming Lei185c9bc2010-07-28 22:33:28 +08001062file_error:
1063 debugfs_remove_recursive(ehci->debug_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064}
1065
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -03001066static inline void remove_debug_files(struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
Ming Lei185c9bc2010-07-28 22:33:28 +08001068 debugfs_remove_recursive(ehci->debug_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069}
1070
Alan Stern128f8b3d2016-04-29 15:19:56 -04001071#else /* CONFIG_DYNAMIC_DEBUG */
1072
1073static inline void dbg_hcs_params(struct ehci_hcd *ehci, char *label) { }
1074static inline void dbg_hcc_params(struct ehci_hcd *ehci, char *label) { }
1075
1076static inline void __maybe_unused dbg_qh(const char *label,
1077 struct ehci_hcd *ehci, struct ehci_qh *qh) { }
1078
1079static inline int __maybe_unused dbg_status_buf(const char *buf,
1080 unsigned int len, const char *label, u32 status)
1081{ return 0; }
1082
1083static inline int __maybe_unused dbg_command_buf(const char *buf,
1084 unsigned int len, const char *label, u32 command)
1085{ return 0; }
1086
1087static inline int __maybe_unused dbg_intr_buf(const char *buf,
1088 unsigned int len, const char *label, u32 enable)
1089{ return 0; }
1090
1091static inline int __maybe_unused dbg_port_buf(char *buf,
1092 unsigned int len, const char *label, int port, u32 status)
1093{ return 0; }
1094
1095static inline void dbg_status(struct ehci_hcd *ehci, const char *label,
1096 u32 status) { }
1097static inline void dbg_cmd(struct ehci_hcd *ehci, const char *label,
1098 u32 command) { }
1099static inline void dbg_port(struct ehci_hcd *ehci, const char *label,
1100 int port, u32 status) { }
1101
1102static inline void create_debug_files(struct ehci_hcd *bus) { }
1103static inline void remove_debug_files(struct ehci_hcd *bus) { }
1104
Geyslan G. Bem93df42b2016-01-25 22:45:09 -03001105#endif /* CONFIG_DYNAMIC_DEBUG */