blob: 7fb21d01b3d032fa09487412812bd852f2d10705 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0+
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Copyright (c) 2001-2002 by David Brownell
David Brownell53bd6a62006-08-30 14:50:06 -07004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 */
16
17/* this file is part of ehci-hcd.c */
18
Oliver Neukum1c201632013-11-18 13:23:16 +010019#ifdef CONFIG_DYNAMIC_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -030021/*
22 * check the values in the HCSPARAMS register
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 * (host controller _Structural_ parameters)
24 * see EHCI spec, Table 2-4 for each value
25 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030026static void dbg_hcs_params(struct ehci_hcd *ehci, char *label)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +110028 u32 params = ehci_readl(ehci, &ehci->caps->hcs_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030030 ehci_dbg(ehci,
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 "%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n",
32 label, params,
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030033 HCS_DEBUG_PORT(params),
34 HCS_INDICATOR(params) ? " ind" : "",
35 HCS_N_CC(params),
36 HCS_N_PCC(params),
37 HCS_PORTROUTED(params) ? "" : " ordered",
38 HCS_PPC(params) ? "" : " !ppc",
Geyslan G. Bem78698d62016-01-25 22:44:57 -030039 HCS_N_PORTS(params));
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 /* Port routing, per EHCI 0.95 Spec, Section 2.2.5 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030041 if (HCS_PORTROUTED(params)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 int i;
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -030043 char buf[46], tmp[7], byte;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 buf[0] = 0;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030046 for (i = 0; i < HCS_N_PORTS(params); i++) {
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -030047 /* FIXME MIPS won't readb() ... */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030048 byte = readb(&ehci->caps->portroute[(i >> 1)]);
David Brownell53bd6a62006-08-30 14:50:06 -070049 sprintf(tmp, "%d ",
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -030050 (i & 0x1) ? byte & 0xf : (byte >> 4) & 0xf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 strcat(buf, tmp);
52 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030053 ehci_dbg(ehci, "%s portroute %s\n", label, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 }
55}
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -030057/*
58 * check the values in the HCCPARAMS register
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 * (host controller _Capability_ parameters)
60 * see EHCI Spec, Table 2-5 for each value
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -030061 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030062static void dbg_hcc_params(struct ehci_hcd *ehci, char *label)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +110064 u32 params = ehci_readl(ehci, &ehci->caps->hcc_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030066 if (HCC_ISOC_CACHE(params)) {
67 ehci_dbg(ehci,
Stefan Roese6dbd6822007-05-01 09:29:37 -070068 "%s hcc_params %04x caching frame %s%s%s\n",
69 label, params,
70 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
71 HCC_CANPARK(params) ? " park" : "",
72 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 } else {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030074 ehci_dbg(ehci,
Alek Duaa4d8342010-06-04 15:47:54 +080075 "%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -070076 label,
77 params,
78 HCC_ISOC_THRES(params),
79 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
80 HCC_CANPARK(params) ? " park" : "",
Alek Duaa4d8342010-06-04 15:47:54 +080081 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "",
82 HCC_LPM(params) ? " LPM" : "",
83 HCC_PER_PORT_CHANGE_EVENT(params) ? " ppce" : "",
84 HCC_HW_PREFETCH(params) ? " hw prefetch" : "",
85 HCC_32FRAME_PERIODIC_LIST(params) ?
Masanari Iida855ef452012-02-17 23:06:47 +090086 " 32 periodic list" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88}
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
David Rientjes82345092007-05-11 14:39:44 -070090static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -030091dbg_qtd(const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
Stefan Roese6dbd6822007-05-01 09:29:37 -070093 ehci_dbg(ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
94 hc32_to_cpup(ehci, &qtd->hw_next),
95 hc32_to_cpup(ehci, &qtd->hw_alt_next),
96 hc32_to_cpup(ehci, &qtd->hw_token),
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -030097 hc32_to_cpup(ehci, &qtd->hw_buf[0]));
98 if (qtd->hw_buf[1])
Stefan Roese6dbd6822007-05-01 09:29:37 -070099 ehci_dbg(ehci, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
100 hc32_to_cpup(ehci, &qtd->hw_buf[1]),
101 hc32_to_cpup(ehci, &qtd->hw_buf[2]),
102 hc32_to_cpup(ehci, &qtd->hw_buf[3]),
103 hc32_to_cpup(ehci, &qtd->hw_buf[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
David Rientjes82345092007-05-11 14:39:44 -0700106static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300107dbg_qh(const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
Alek Du3807e262009-07-14 07:23:29 +0800109 struct ehci_qh_hw *hw = qh->hw;
110
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300111 ehci_dbg(ehci, "%s qh %p n%08x info %x %x qtd %x\n", label,
Alek Du3807e262009-07-14 07:23:29 +0800112 qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current);
113 dbg_qtd("overlay", ehci, (struct ehci_qtd *) &hw->hw_qtd_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
David Rientjes82345092007-05-11 14:39:44 -0700116static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300117dbg_itd(const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300119 ehci_dbg(ehci, "%s [%d] itd %p, next %08x, urb %p\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700120 label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next),
121 itd->urb);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300122 ehci_dbg(ehci,
David Brownell53bd6a62006-08-30 14:50:06 -0700123 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700124 hc32_to_cpu(ehci, itd->hw_transaction[0]),
125 hc32_to_cpu(ehci, itd->hw_transaction[1]),
126 hc32_to_cpu(ehci, itd->hw_transaction[2]),
127 hc32_to_cpu(ehci, itd->hw_transaction[3]),
128 hc32_to_cpu(ehci, itd->hw_transaction[4]),
129 hc32_to_cpu(ehci, itd->hw_transaction[5]),
130 hc32_to_cpu(ehci, itd->hw_transaction[6]),
131 hc32_to_cpu(ehci, itd->hw_transaction[7]));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300132 ehci_dbg(ehci,
David Brownell53bd6a62006-08-30 14:50:06 -0700133 " buf: %08x %08x %08x %08x %08x %08x %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700134 hc32_to_cpu(ehci, itd->hw_bufp[0]),
135 hc32_to_cpu(ehci, itd->hw_bufp[1]),
136 hc32_to_cpu(ehci, itd->hw_bufp[2]),
137 hc32_to_cpu(ehci, itd->hw_bufp[3]),
138 hc32_to_cpu(ehci, itd->hw_bufp[4]),
139 hc32_to_cpu(ehci, itd->hw_bufp[5]),
140 hc32_to_cpu(ehci, itd->hw_bufp[6]));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300141 ehci_dbg(ehci, " index: %d %d %d %d %d %d %d %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 itd->index[0], itd->index[1], itd->index[2],
143 itd->index[3], itd->index[4], itd->index[5],
144 itd->index[6], itd->index[7]);
145}
146
David Rientjes82345092007-05-11 14:39:44 -0700147static void __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300148dbg_sitd(const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300150 ehci_dbg(ehci, "%s [%d] sitd %p, next %08x, urb %p\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700151 label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next),
152 sitd->urb);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300153 ehci_dbg(ehci,
David Brownell53bd6a62006-08-30 14:50:06 -0700154 " addr %08x sched %04x result %08x buf %08x %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700155 hc32_to_cpu(ehci, sitd->hw_fullspeed_ep),
156 hc32_to_cpu(ehci, sitd->hw_uframe),
157 hc32_to_cpu(ehci, sitd->hw_results),
158 hc32_to_cpu(ehci, sitd->hw_buf[0]),
159 hc32_to_cpu(ehci, sitd->hw_buf[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
David Rientjes82345092007-05-11 14:39:44 -0700162static int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300163dbg_status_buf(char *buf, unsigned len, const char *label, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300165 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800166 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s%s",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300167 label, label[0] ? " " : "", status,
Alek Duaa4d8342010-06-04 15:47:54 +0800168 (status & STS_PPCE_MASK) ? " PPCE" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 (status & STS_ASS) ? " Async" : "",
170 (status & STS_PSS) ? " Periodic" : "",
171 (status & STS_RECL) ? " Recl" : "",
172 (status & STS_HALT) ? " Halt" : "",
173 (status & STS_IAA) ? " IAA" : "",
174 (status & STS_FATAL) ? " FATAL" : "",
175 (status & STS_FLR) ? " FLR" : "",
176 (status & STS_PCD) ? " PCD" : "",
177 (status & STS_ERR) ? " ERR" : "",
Geyslan G. Bem78698d62016-01-25 22:44:57 -0300178 (status & STS_INT) ? " INT" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179}
180
David Rientjes82345092007-05-11 14:39:44 -0700181static int __maybe_unused
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300182dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300184 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800185 "%s%sintrenable %02x%s%s%s%s%s%s%s",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300186 label, label[0] ? " " : "", enable,
Alek Duaa4d8342010-06-04 15:47:54 +0800187 (enable & STS_PPCE_MASK) ? " PPCE" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 (enable & STS_IAA) ? " IAA" : "",
189 (enable & STS_FATAL) ? " FATAL" : "",
190 (enable & STS_FLR) ? " FLR" : "",
191 (enable & STS_PCD) ? " PCD" : "",
192 (enable & STS_ERR) ? " ERR" : "",
Geyslan G. Bem78698d62016-01-25 22:44:57 -0300193 (enable & STS_INT) ? " INT" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300196static const char *const fls_strings[] = { "1024", "512", "256", "??" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198static int
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300199dbg_command_buf(char *buf, unsigned len, const char *label, u32 command)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300201 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800202 "%s%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s "
203 "period=%s%s %s",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300204 label, label[0] ? " " : "", command,
Alek Duaa4d8342010-06-04 15:47:54 +0800205 (command & CMD_HIRD) ? " HIRD" : "",
206 (command & CMD_PPCEE) ? " PPCEE" : "",
207 (command & CMD_FSP) ? " FSP" : "",
208 (command & CMD_ASPE) ? " ASPE" : "",
209 (command & CMD_PSPE) ? " PSPE" : "",
210 (command & CMD_PARK) ? " park" : "(park)",
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300211 CMD_PARK_CNT(command),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 (command >> 16) & 0x3f,
213 (command & CMD_LRESET) ? " LReset" : "",
214 (command & CMD_IAAD) ? " IAAD" : "",
215 (command & CMD_ASE) ? " Async" : "",
216 (command & CMD_PSE) ? " Periodic" : "",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300217 fls_strings[(command >> 2) & 0x3],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 (command & CMD_RESET) ? " Reset" : "",
Geyslan G. Bem78698d62016-01-25 22:44:57 -0300219 (command & CMD_RUN) ? "RUN" : "HALT");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
221
222static int
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300223dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
225 char *sig;
226
227 /* signaling state */
228 switch (status & (3 << 10)) {
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300229 case 0 << 10:
230 sig = "se0";
231 break;
232 case 1 << 10: /* low speed */
233 sig = "k";
234 break;
235 case 2 << 10:
236 sig = "j";
237 break;
238 default:
239 sig = "?";
240 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 }
242
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300243 return scnprintf(buf, len,
Alek Duaa4d8342010-06-04 15:47:54 +0800244 "%s%sport:%d status %06x %d %s%s%s%s%s%s "
245 "sig=%s%s%s%s%s%s%s%s%s%s%s",
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300246 label, label[0] ? " " : "", port, status,
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -0300247 status >> 25, /*device address */
248 (status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_ACK ?
Alek Duaa4d8342010-06-04 15:47:54 +0800249 " ACK" : "",
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -0300250 (status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_NYET ?
Alek Duaa4d8342010-06-04 15:47:54 +0800251 " NYET" : "",
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -0300252 (status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_STALL ?
Alek Duaa4d8342010-06-04 15:47:54 +0800253 " STALL" : "",
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -0300254 (status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_ERR ?
Alek Duaa4d8342010-06-04 15:47:54 +0800255 " ERR" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 (status & PORT_POWER) ? " POWER" : "",
257 (status & PORT_OWNER) ? " OWNER" : "",
258 sig,
Alek Duaa4d8342010-06-04 15:47:54 +0800259 (status & PORT_LPM) ? " LPM" : "",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 (status & PORT_RESET) ? " RESET" : "",
261 (status & PORT_SUSPEND) ? " SUSPEND" : "",
262 (status & PORT_RESUME) ? " RESUME" : "",
263 (status & PORT_OCC) ? " OCC" : "",
264 (status & PORT_OC) ? " OC" : "",
265 (status & PORT_PEC) ? " PEC" : "",
266 (status & PORT_PE) ? " PE" : "",
267 (status & PORT_CSC) ? " CSC" : "",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700268 (status & PORT_CONNECT) ? " CONNECT" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269}
270
Geyslan G. Bem1f8e5af2016-01-25 22:45:02 -0300271static inline void
272dbg_status(struct ehci_hcd *ehci, const char *label, u32 status)
273{
274 char buf[80];
275
276 dbg_status_buf(buf, sizeof(buf), label, status);
277 ehci_dbg(ehci, "%s\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278}
279
Geyslan G. Bem1f8e5af2016-01-25 22:45:02 -0300280static inline void
281dbg_cmd(struct ehci_hcd *ehci, const char *label, u32 command)
282{
283 char buf[80];
284
285 dbg_command_buf(buf, sizeof(buf), label, command);
286 ehci_dbg(ehci, "%s\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
288
Geyslan G. Bem1f8e5af2016-01-25 22:45:02 -0300289static inline void
290dbg_port(struct ehci_hcd *ehci, const char *label, int port, u32 status)
291{
292 char buf[80];
293
294 dbg_port_buf(buf, sizeof(buf), label, port, status);
295 ehci_dbg(ehci, "%s\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
298/*-------------------------------------------------------------------------*/
299
Tony Jones694cc202007-09-11 14:07:31 -0700300/* troubleshooting help: expose state in debugfs */
301
302static int debug_async_open(struct inode *, struct file *);
Alan Sternd0ce5c62013-10-11 11:29:13 -0400303static int debug_bandwidth_open(struct inode *, struct file *);
Tony Jones694cc202007-09-11 14:07:31 -0700304static int debug_periodic_open(struct inode *, struct file *);
305static int debug_registers_open(struct inode *, struct file *);
Alek Duaa4d8342010-06-04 15:47:54 +0800306
Tony Jones694cc202007-09-11 14:07:31 -0700307static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
308static int debug_close(struct inode *, struct file *);
309
310static const struct file_operations debug_async_fops = {
311 .owner = THIS_MODULE,
312 .open = debug_async_open,
313 .read = debug_output,
314 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200315 .llseek = default_llseek,
Tony Jones694cc202007-09-11 14:07:31 -0700316};
Geyslan G. Beme1666312016-01-25 22:45:01 -0300317
Alan Sternd0ce5c62013-10-11 11:29:13 -0400318static const struct file_operations debug_bandwidth_fops = {
319 .owner = THIS_MODULE,
320 .open = debug_bandwidth_open,
321 .read = debug_output,
322 .release = debug_close,
323 .llseek = default_llseek,
324};
Geyslan G. Beme1666312016-01-25 22:45:01 -0300325
Tony Jones694cc202007-09-11 14:07:31 -0700326static const struct file_operations debug_periodic_fops = {
327 .owner = THIS_MODULE,
328 .open = debug_periodic_open,
329 .read = debug_output,
330 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200331 .llseek = default_llseek,
Tony Jones694cc202007-09-11 14:07:31 -0700332};
Geyslan G. Beme1666312016-01-25 22:45:01 -0300333
Tony Jones694cc202007-09-11 14:07:31 -0700334static const struct file_operations debug_registers_fops = {
335 .owner = THIS_MODULE,
336 .open = debug_registers_open,
337 .read = debug_output,
338 .release = debug_close,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200339 .llseek = default_llseek,
Tony Jones694cc202007-09-11 14:07:31 -0700340};
341
342static struct dentry *ehci_debug_root;
343
344struct debug_buffer {
345 ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
346 struct usb_bus *bus;
347 struct mutex mutex; /* protect filling of buffer */
348 size_t count; /* number of characters filled into buffer */
Ming Lei3c04e202008-09-18 23:06:21 +0800349 char *output_buf;
350 size_t alloc_size;
Tony Jones694cc202007-09-11 14:07:31 -0700351};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Geyslan G. Bem1f8e5af2016-01-25 22:45:02 -0300353static inline char speed_char(u32 info1)
354{
355 switch (info1 & (3 << 12)) {
356 case QH_FULL_SPEED:
357 return 'f';
358 case QH_LOW_SPEED:
359 return 'l';
360 case QH_HIGH_SPEED:
361 return 'h';
362 default:
363 return '?';
364 }
365}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Stefan Roese6dbd6822007-05-01 09:29:37 -0700367static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Stefan Roese6dbd6822007-05-01 09:29:37 -0700369 __u32 v = hc32_to_cpu(ehci, token);
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 if (v & QTD_STS_ACTIVE)
372 return '*';
373 if (v & QTD_STS_HALT)
374 return '-';
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300375 if (!IS_SHORT_READ(v))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return ' ';
377 /* tries to advance through hw_alt_next */
378 return '/';
379}
380
Geyslan G. Bemc768ffb2016-01-25 22:45:00 -0300381static void qh_lines(struct ehci_hcd *ehci, struct ehci_qh *qh,
382 char **nextp, unsigned *sizep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
384 u32 scratch;
385 u32 hw_curr;
386 struct list_head *entry;
387 struct ehci_qtd *td;
388 unsigned temp;
389 unsigned size = *sizep;
390 char *next = *nextp;
391 char mark;
Al Virofd05e722008-04-28 07:00:16 +0100392 __le32 list_end = EHCI_LIST_END(ehci);
Alek Du3807e262009-07-14 07:23:29 +0800393 struct ehci_qh_hw *hw = qh->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Alek Du3807e262009-07-14 07:23:29 +0800395 if (hw->hw_qtd_next == list_end) /* NEC does this */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 mark = '@';
397 else
Alek Du3807e262009-07-14 07:23:29 +0800398 mark = token_mark(ehci, hw->hw_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (mark == '/') { /* qh_alt_next controls qh advance? */
Alek Du3807e262009-07-14 07:23:29 +0800400 if ((hw->hw_alt_next & QTD_MASK(ehci))
401 == ehci->async->hw->hw_alt_next)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 mark = '#'; /* blocked */
Alek Du3807e262009-07-14 07:23:29 +0800403 else if (hw->hw_alt_next == list_end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 mark = '.'; /* use hw_qtd_next */
405 /* else alt_next points to some other qtd */
406 }
Alek Du3807e262009-07-14 07:23:29 +0800407 scratch = hc32_to_cpup(ehci, &hw->hw_info1);
408 hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300409 temp = scnprintf(next, size,
Alan Stern8ee10d62015-11-20 13:53:45 -0500410 "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)"
411 " [cur %08x next %08x buf[0] %08x]",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 qh, scratch & 0x007f,
413 speed_char (scratch),
414 (scratch >> 8) & 0x000f,
Alek Du3807e262009-07-14 07:23:29 +0800415 scratch, hc32_to_cpup(ehci, &hw->hw_info2),
416 hc32_to_cpup(ehci, &hw->hw_token), mark,
417 (cpu_to_hc32(ehci, QTD_TOGGLE) & hw->hw_token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 ? "data1" : "data0",
Alan Stern8ee10d62015-11-20 13:53:45 -0500419 (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f,
420 hc32_to_cpup(ehci, &hw->hw_current),
421 hc32_to_cpup(ehci, &hw->hw_qtd_next),
422 hc32_to_cpup(ehci, &hw->hw_buf[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 size -= temp;
424 next += temp;
425
426 /* hc may be modifying the list as we read it ... */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300427 list_for_each(entry, &qh->qtd_list) {
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300428 char *type;
429
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300430 td = list_entry(entry, struct ehci_qtd, qtd_list);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700431 scratch = hc32_to_cpup(ehci, &td->hw_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 mark = ' ';
Geyslan G. Bem04b8ad42016-01-25 22:45:06 -0300433 if (hw_curr == td->qtd_dma) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 mark = '*';
Geyslan G. Bem04b8ad42016-01-25 22:45:06 -0300435 } else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 mark = '+';
Geyslan G. Bem04b8ad42016-01-25 22:45:06 -0300437 } else if (QTD_LENGTH(scratch)) {
Alek Du3807e262009-07-14 07:23:29 +0800438 if (td->hw_alt_next == ehci->async->hw->hw_alt_next)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 mark = '#';
Stefan Roese6dbd6822007-05-01 09:29:37 -0700440 else if (td->hw_alt_next != list_end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 mark = '/';
442 }
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300443 switch ((scratch >> 8) & 0x03) {
444 case 0:
445 type = "out";
446 break;
447 case 1:
448 type = "in";
449 break;
450 case 2:
451 type = "setup";
452 break;
453 default:
454 type = "?";
455 break;
456 }
Geyslan G. Bema5355972016-01-25 22:44:59 -0300457 temp = scnprintf(next, size,
Alan Stern8ee10d62015-11-20 13:53:45 -0500458 "\n\t%p%c%s len=%d %08x urb %p"
459 " [td %08x buf[0] %08x]",
Geyslan G. Bem5bb95ec2016-01-25 22:44:56 -0300460 td, mark, type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 (scratch >> 16) & 0x7fff,
462 scratch,
Alan Stern8ee10d62015-11-20 13:53:45 -0500463 td->urb,
464 (u32) td->qtd_dma,
465 hc32_to_cpup(ehci, &td->hw_buf[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 size -= temp;
467 next += temp;
468 if (temp == size)
469 goto done;
470 }
471
Geyslan G. Bema5355972016-01-25 22:44:59 -0300472 temp = scnprintf(next, size, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 size -= temp;
474 next += temp;
475
476done:
477 *sizep = size;
478 *nextp = next;
479}
480
Tony Jones694cc202007-09-11 14:07:31 -0700481static ssize_t fill_async_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 struct usb_hcd *hcd;
484 struct ehci_hcd *ehci;
485 unsigned long flags;
486 unsigned temp, size;
487 char *next;
488 struct ehci_qh *qh;
489
Tony Jones694cc202007-09-11 14:07:31 -0700490 hcd = bus_to_hcd(buf->bus);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300491 ehci = hcd_to_ehci(hcd);
Ming Lei3c04e202008-09-18 23:06:21 +0800492 next = buf->output_buf;
493 size = buf->alloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Tony Jones694cc202007-09-11 14:07:31 -0700495 *next = 0;
496
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -0300497 /*
498 * dumps a snapshot of the async schedule.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 * usually empty except for long-term bulk reads, or head.
500 * one QH per line, and TDs we know about
501 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300502 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300504 qh_lines(ehci, qh, &next, &size);
Alan Stern6e018752013-03-22 13:31:45 -0400505 if (!list_empty(&ehci->async_unlink) && size > 0) {
Alan Stern99ac5b12012-07-11 11:21:38 -0400506 temp = scnprintf(next, size, "\nunlink =\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 size -= temp;
508 next += temp;
509
Alan Stern6e018752013-03-22 13:31:45 -0400510 list_for_each_entry(qh, &ehci->async_unlink, unlink_node) {
511 if (size <= 0)
512 break;
513 qh_lines(ehci, qh, &next, &size);
514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300516 spin_unlock_irqrestore(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Ming Lei3c04e202008-09-18 23:06:21 +0800518 return strlen(buf->output_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Alan Sternd0ce5c62013-10-11 11:29:13 -0400521static ssize_t fill_bandwidth_buffer(struct debug_buffer *buf)
522{
523 struct ehci_hcd *ehci;
Alan Sternb35c5002013-10-11 22:16:21 -0400524 struct ehci_tt *tt;
525 struct ehci_per_sched *ps;
Alan Sternd0ce5c62013-10-11 11:29:13 -0400526 unsigned temp, size;
527 char *next;
528 unsigned i;
529 u8 *bw;
Alan Sternb35c5002013-10-11 22:16:21 -0400530 u16 *bf;
531 u8 budget[EHCI_BANDWIDTH_SIZE];
Alan Sternd0ce5c62013-10-11 11:29:13 -0400532
533 ehci = hcd_to_ehci(bus_to_hcd(buf->bus));
534 next = buf->output_buf;
535 size = buf->alloc_size;
536
537 *next = 0;
538
539 spin_lock_irq(&ehci->lock);
540
541 /* Dump the HS bandwidth table */
542 temp = scnprintf(next, size,
543 "HS bandwidth allocation (us per microframe)\n");
544 size -= temp;
545 next += temp;
546 for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
547 bw = &ehci->bandwidth[i];
548 temp = scnprintf(next, size,
549 "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
550 i, bw[0], bw[1], bw[2], bw[3],
551 bw[4], bw[5], bw[6], bw[7]);
552 size -= temp;
553 next += temp;
554 }
Alan Sternb35c5002013-10-11 22:16:21 -0400555
556 /* Dump all the FS/LS tables */
557 list_for_each_entry(tt, &ehci->tt_list, tt_list) {
558 temp = scnprintf(next, size,
559 "\nTT %s port %d FS/LS bandwidth allocation (us per frame)\n",
560 dev_name(&tt->usb_tt->hub->dev),
561 tt->tt_port + !!tt->usb_tt->multi);
562 size -= temp;
563 next += temp;
564
565 bf = tt->bandwidth;
566 temp = scnprintf(next, size,
567 " %5u%5u%5u%5u%5u%5u%5u%5u\n",
568 bf[0], bf[1], bf[2], bf[3],
569 bf[4], bf[5], bf[6], bf[7]);
570 size -= temp;
571 next += temp;
572
573 temp = scnprintf(next, size,
574 "FS/LS budget (us per microframe)\n");
575 size -= temp;
576 next += temp;
577 compute_tt_budget(budget, tt);
578 for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
579 bw = &budget[i];
580 temp = scnprintf(next, size,
581 "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
582 i, bw[0], bw[1], bw[2], bw[3],
583 bw[4], bw[5], bw[6], bw[7]);
584 size -= temp;
585 next += temp;
586 }
587 list_for_each_entry(ps, &tt->ps_list, ps_list) {
588 temp = scnprintf(next, size,
589 "%s ep %02x: %4u @ %2u.%u+%u mask %04x\n",
590 dev_name(&ps->udev->dev),
591 ps->ep->desc.bEndpointAddress,
592 ps->tt_usecs,
593 ps->bw_phase, ps->phase_uf,
594 ps->bw_period, ps->cs_mask);
595 size -= temp;
596 next += temp;
597 }
598 }
Alan Sternd0ce5c62013-10-11 11:29:13 -0400599 spin_unlock_irq(&ehci->lock);
600
601 return next - buf->output_buf;
602}
603
Geyslan G. Bem3fd29002016-01-25 22:45:08 -0300604static unsigned output_buf_tds_dir(char *buf, struct ehci_hcd *ehci,
605 struct ehci_qh_hw *hw, struct ehci_qh *qh, unsigned size)
606{
607 u32 scratch = hc32_to_cpup(ehci, &hw->hw_info1);
608 struct ehci_qtd *qtd;
609 char *type = "";
610 unsigned temp = 0;
611
612 /* count tds, get ep direction */
613 list_for_each_entry(qtd, &qh->qtd_list, qtd_list) {
614 temp++;
615 switch ((hc32_to_cpu(ehci, qtd->hw_token) >> 8) & 0x03) {
616 case 0:
617 type = "out";
618 continue;
619 case 1:
620 type = "in";
621 continue;
622 }
623 }
624
625 return scnprintf(buf, size, " (%c%d ep%d%s [%d/%d] q%d p%d)",
626 speed_char(scratch), scratch & 0x007f,
627 (scratch >> 8) & 0x000f, type, qh->ps.usecs,
628 qh->ps.c_usecs, temp, 0x7ff & (scratch >> 16));
629}
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631#define DBG_SCHED_LIMIT 64
Tony Jones694cc202007-09-11 14:07:31 -0700632static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 struct usb_hcd *hcd;
635 struct ehci_hcd *ehci;
636 unsigned long flags;
637 union ehci_shadow p, *seen;
638 unsigned temp, size, seen_count;
639 char *next;
640 unsigned i;
Stefan Roese6dbd6822007-05-01 09:29:37 -0700641 __hc32 tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Geyslan G. Bemcb272522016-01-25 22:45:07 -0300643 seen = kmalloc_array(DBG_SCHED_LIMIT, sizeof(*seen), GFP_ATOMIC);
Greg Kroah-Hartman911fdb62015-04-30 11:32:50 +0200644 if (!seen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 return 0;
646 seen_count = 0;
647
Tony Jones694cc202007-09-11 14:07:31 -0700648 hcd = bus_to_hcd(buf->bus);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300649 ehci = hcd_to_ehci(hcd);
Ming Lei3c04e202008-09-18 23:06:21 +0800650 next = buf->output_buf;
651 size = buf->alloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300653 temp = scnprintf(next, size, "size = %d\n", ehci->periodic_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 size -= temp;
655 next += temp;
656
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -0300657 /*
658 * dump a snapshot of the periodic schedule.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 * iso changes, interrupt usually doesn't.
660 */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300661 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 for (i = 0; i < ehci->periodic_size; i++) {
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300663 p = ehci->pshadow[i];
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300664 if (likely(!p.ptr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 continue;
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300666 tag = Q_NEXT_TYPE(ehci, ehci->periodic[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300668 temp = scnprintf(next, size, "%4d: ", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 size -= temp;
670 next += temp;
671
672 do {
Alek Du3807e262009-07-14 07:23:29 +0800673 struct ehci_qh_hw *hw;
674
Stefan Roese6dbd6822007-05-01 09:29:37 -0700675 switch (hc32_to_cpu(ehci, tag)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 case Q_TYPE_QH:
Alek Du3807e262009-07-14 07:23:29 +0800677 hw = p.qh->hw;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300678 temp = scnprintf(next, size, " qh%d-%04x/%p",
Alan Sternffa02482013-10-11 11:29:03 -0400679 p.qh->ps.period,
Stefan Roese6dbd6822007-05-01 09:29:37 -0700680 hc32_to_cpup(ehci,
Alek Du3807e262009-07-14 07:23:29 +0800681 &hw->hw_info2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 /* uframe masks */
David Brownell7dedacf2005-08-04 18:06:41 -0700683 & (QH_CMASK | QH_SMASK),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 p.qh);
685 size -= temp;
686 next += temp;
687 /* don't repeat what follows this qh */
688 for (temp = 0; temp < seen_count; temp++) {
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300689 if (seen[temp].ptr != p.ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 continue;
Ming Lei3c4bb712008-09-18 23:06:38 +0800691 if (p.qh->qh_next.ptr) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300692 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 " ...");
Ming Lei3c4bb712008-09-18 23:06:38 +0800694 size -= temp;
695 next += temp;
696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 break;
698 }
699 /* show more info the first time around */
Ming Lei3c4bb712008-09-18 23:06:38 +0800700 if (temp == seen_count) {
Geyslan G. Bem3fd29002016-01-25 22:45:08 -0300701 temp = output_buf_tds_dir(next, ehci,
702 hw, p.qh, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
704 if (seen_count < DBG_SCHED_LIMIT)
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300705 seen[seen_count++].qh = p.qh;
Geyslan G. Bem04b8ad42016-01-25 22:45:06 -0300706 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 temp = 0;
Geyslan G. Bem04b8ad42016-01-25 22:45:06 -0300708 }
Alan Stern17dcfc92012-09-19 17:00:55 -0400709 tag = Q_NEXT_TYPE(ehci, hw->hw_next);
710 p = p.qh->qh_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 break;
712 case Q_TYPE_FSTN:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300713 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 " fstn-%8x/%p", p.fstn->hw_prev,
715 p.fstn);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700716 tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 p = p.fstn->fstn_next;
718 break;
719 case Q_TYPE_ITD:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300720 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 " itd/%p", p.itd);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700722 tag = Q_NEXT_TYPE(ehci, p.itd->hw_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 p = p.itd->itd_next;
724 break;
725 case Q_TYPE_SITD:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300726 temp = scnprintf(next, size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 " sitd%d-%04x/%p",
Alan Sternffa02482013-10-11 11:29:03 -0400728 p.sitd->stream->ps.period,
Stefan Roese6dbd6822007-05-01 09:29:37 -0700729 hc32_to_cpup(ehci, &p.sitd->hw_uframe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 & 0x0000ffff,
731 p.sitd);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700732 tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 p = p.sitd->sitd_next;
734 break;
735 }
736 size -= temp;
737 next += temp;
738 } while (p.ptr);
739
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300740 temp = scnprintf(next, size, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 size -= temp;
742 next += temp;
743 }
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300744 spin_unlock_irqrestore(&ehci->lock, flags);
745 kfree(seen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Ming Lei3c04e202008-09-18 23:06:21 +0800747 return buf->alloc_size - size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749#undef DBG_SCHED_LIMIT
750
Alan Sterne8799902011-08-18 16:31:30 -0400751static const char *rh_state_string(struct ehci_hcd *ehci)
752{
753 switch (ehci->rh_state) {
754 case EHCI_RH_HALTED:
755 return "halted";
756 case EHCI_RH_SUSPENDED:
757 return "suspended";
758 case EHCI_RH_RUNNING:
759 return "running";
Alan Sternc0c53db2012-07-11 11:21:48 -0400760 case EHCI_RH_STOPPING:
761 return "stopping";
Alan Sterne8799902011-08-18 16:31:30 -0400762 }
763 return "?";
764}
765
Tony Jones694cc202007-09-11 14:07:31 -0700766static ssize_t fill_registers_buffer(struct debug_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 struct usb_hcd *hcd;
769 struct ehci_hcd *ehci;
770 unsigned long flags;
771 unsigned temp, size, i;
Geyslan G. Bem1cb1d1c2016-01-25 22:44:54 -0300772 char *next, scratch[80];
773 static char fmt[] = "%*s\n";
774 static char label[] = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Tony Jones694cc202007-09-11 14:07:31 -0700776 hcd = bus_to_hcd(buf->bus);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300777 ehci = hcd_to_ehci(hcd);
Ming Lei3c04e202008-09-18 23:06:21 +0800778 next = buf->output_buf;
779 size = buf->alloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300781 spin_lock_irqsave(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Alan Stern541c7d42010-06-22 16:39:10 -0400783 if (!HCD_HW_ACCESSIBLE(hcd)) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300784 size = scnprintf(next, size,
Alan Stern2b70f072008-10-02 11:47:15 -0400785 "bus %s, device %s\n"
David Brownelld49d4312005-05-07 13:21:50 -0700786 "%s\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 "SUSPENDED (no register access)\n",
788 hcd->self.controller->bus->name,
Kay Sievers7071a3c2008-05-02 06:02:41 +0200789 dev_name(hcd->self.controller),
David Brownelld49d4312005-05-07 13:21:50 -0700790 hcd->product_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 goto done;
792 }
793
794 /* Capability Registers */
Jan Anderssonc4301312011-05-03 20:11:57 +0200795 i = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300796 temp = scnprintf(next, size,
Alan Stern2b70f072008-10-02 11:47:15 -0400797 "bus %s, device %s\n"
David Brownelld49d4312005-05-07 13:21:50 -0700798 "%s\n"
Alan Sterne8799902011-08-18 16:31:30 -0400799 "EHCI %x.%02x, rh state %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 hcd->self.controller->bus->name,
Kay Sievers7071a3c2008-05-02 06:02:41 +0200801 dev_name(hcd->self.controller),
David Brownelld49d4312005-05-07 13:21:50 -0700802 hcd->product_desc,
Alan Sterne8799902011-08-18 16:31:30 -0400803 i >> 8, i & 0x0ff, rh_state_string(ehci));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 size -= temp;
805 next += temp;
806
yuan linyu2c93e792017-02-25 19:20:55 +0800807#ifdef CONFIG_USB_PCI
David Brownelld49d4312005-05-07 13:21:50 -0700808 /* EHCI 0.96 and later may have "extended capabilities" */
Yijing Wange10e6f42013-12-05 19:21:32 +0800809 if (dev_is_pci(hcd->self.controller)) {
David Brownelld49d4312005-05-07 13:21:50 -0700810 struct pci_dev *pdev;
811 u32 offset, cap, cap2;
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -0300812 unsigned count = 256 / 4;
David Brownelld49d4312005-05-07 13:21:50 -0700813
814 pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
Stefan Roese6dbd6822007-05-01 09:29:37 -0700815 offset = HCC_EXT_CAPS(ehci_readl(ehci,
816 &ehci->caps->hcc_params));
David Brownelld49d4312005-05-07 13:21:50 -0700817 while (offset && count--) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300818 pci_read_config_dword(pdev, offset, &cap);
David Brownelld49d4312005-05-07 13:21:50 -0700819 switch (cap & 0xff) {
820 case 1:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300821 temp = scnprintf(next, size,
David Brownelld49d4312005-05-07 13:21:50 -0700822 "ownership %08x%s%s\n", cap,
823 (cap & (1 << 24)) ? " linux" : "",
824 (cap & (1 << 16)) ? " firmware" : "");
825 size -= temp;
826 next += temp;
827
828 offset += 4;
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300829 pci_read_config_dword(pdev, offset, &cap2);
830 temp = scnprintf(next, size,
David Brownelld49d4312005-05-07 13:21:50 -0700831 "SMI sts/enable 0x%08x\n", cap2);
832 size -= temp;
833 next += temp;
834 break;
835 case 0: /* illegal reserved capability */
836 cap = 0;
837 /* FALLTHROUGH */
838 default: /* unknown */
839 break;
840 }
841 temp = (cap >> 8) & 0xff;
842 }
843 }
844#endif
845
Geyslan G. Bem0784b4d2016-01-25 22:44:55 -0300846 /* FIXME interpret both types of params */
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100847 i = ehci_readl(ehci, &ehci->caps->hcs_params);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300848 temp = scnprintf(next, size, "structural params 0x%08x\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 size -= temp;
850 next += temp;
851
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100852 i = ehci_readl(ehci, &ehci->caps->hcc_params);
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300853 temp = scnprintf(next, size, "capability params 0x%08x\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 size -= temp;
855 next += temp;
856
857 /* Operational Registers */
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300858 temp = dbg_status_buf(scratch, sizeof(scratch), label,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100859 ehci_readl(ehci, &ehci->regs->status));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300860 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 size -= temp;
862 next += temp;
863
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300864 temp = dbg_command_buf(scratch, sizeof(scratch), label,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100865 ehci_readl(ehci, &ehci->regs->command));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300866 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 size -= temp;
868 next += temp;
869
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300870 temp = dbg_intr_buf(scratch, sizeof(scratch), label,
Benjamin Herrenschmidt083522d2006-12-15 06:54:08 +1100871 ehci_readl(ehci, &ehci->regs->intr_enable));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300872 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 size -= temp;
874 next += temp;
875
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300876 temp = scnprintf(next, size, "uframe %04x\n",
Alan Stern68aa95d2011-10-12 10:39:14 -0400877 ehci_read_frame_index(ehci));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 size -= temp;
879 next += temp;
880
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300881 for (i = 1; i <= HCS_N_PORTS(ehci->hcs_params); i++) {
882 temp = dbg_port_buf(scratch, sizeof(scratch), label, i,
Stefan Roese6dbd6822007-05-01 09:29:37 -0700883 ehci_readl(ehci,
884 &ehci->regs->port_status[i - 1]));
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300885 temp = scnprintf(next, size, fmt, temp, scratch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 size -= temp;
887 next += temp;
David Brownelld49d4312005-05-07 13:21:50 -0700888 if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) {
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300889 temp = scnprintf(next, size,
David Brownelld49d4312005-05-07 13:21:50 -0700890 " debug control %08x\n",
Stefan Roese6dbd6822007-05-01 09:29:37 -0700891 ehci_readl(ehci,
892 &ehci->debug->control));
David Brownelld49d4312005-05-07 13:21:50 -0700893 size -= temp;
894 next += temp;
895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
897
Alan Stern6e018752013-03-22 13:31:45 -0400898 if (!list_empty(&ehci->async_unlink)) {
Alan Stern99ac5b12012-07-11 11:21:38 -0400899 temp = scnprintf(next, size, "async unlink qh %p\n",
Alan Stern6e018752013-03-22 13:31:45 -0400900 list_first_entry(&ehci->async_unlink,
901 struct ehci_qh, unlink_node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 size -= temp;
903 next += temp;
904 }
905
906#ifdef EHCI_STATS
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300907 temp = scnprintf(next, size,
Alan Stern99ac5b12012-07-11 11:21:38 -0400908 "irq normal %ld err %ld iaa %ld (lost %ld)\n",
909 ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 ehci->stats.lost_iaa);
911 size -= temp;
912 next += temp;
913
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300914 temp = scnprintf(next, size, "complete %ld unlink %ld\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 ehci->stats.complete, ehci->stats.unlink);
916 size -= temp;
917 next += temp;
918#endif
919
920done:
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -0300921 spin_unlock_irqrestore(&ehci->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
Ming Lei3c04e202008-09-18 23:06:21 +0800923 return buf->alloc_size - size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924}
Tony Jones694cc202007-09-11 14:07:31 -0700925
926static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
Geyslan G. Bemc768ffb2016-01-25 22:45:00 -0300927 ssize_t (*fill_func)(struct debug_buffer *))
Tony Jones694cc202007-09-11 14:07:31 -0700928{
929 struct debug_buffer *buf;
930
Geyslan G. Bem12ef7dd2016-01-25 22:45:05 -0300931 buf = kzalloc(sizeof(*buf), GFP_KERNEL);
Tony Jones694cc202007-09-11 14:07:31 -0700932
933 if (buf) {
934 buf->bus = bus;
935 buf->fill_func = fill_func;
936 mutex_init(&buf->mutex);
Ming Lei3c04e202008-09-18 23:06:21 +0800937 buf->alloc_size = PAGE_SIZE;
Tony Jones694cc202007-09-11 14:07:31 -0700938 }
939
940 return buf;
941}
942
943static int fill_buffer(struct debug_buffer *buf)
944{
945 int ret = 0;
946
Ming Lei3c04e202008-09-18 23:06:21 +0800947 if (!buf->output_buf)
Jesper Juhl73f35c62010-11-09 00:10:52 +0100948 buf->output_buf = vmalloc(buf->alloc_size);
Tony Jones694cc202007-09-11 14:07:31 -0700949
Ming Lei3c04e202008-09-18 23:06:21 +0800950 if (!buf->output_buf) {
Tony Jones694cc202007-09-11 14:07:31 -0700951 ret = -ENOMEM;
952 goto out;
953 }
954
955 ret = buf->fill_func(buf);
956
957 if (ret >= 0) {
958 buf->count = ret;
959 ret = 0;
960 }
961
962out:
963 return ret;
964}
965
966static ssize_t debug_output(struct file *file, char __user *user_buf,
Geyslan G. Bemc768ffb2016-01-25 22:45:00 -0300967 size_t len, loff_t *offset)
Tony Jones694cc202007-09-11 14:07:31 -0700968{
969 struct debug_buffer *buf = file->private_data;
970 int ret = 0;
971
972 mutex_lock(&buf->mutex);
973 if (buf->count == 0) {
974 ret = fill_buffer(buf);
975 if (ret != 0) {
976 mutex_unlock(&buf->mutex);
977 goto out;
978 }
979 }
980 mutex_unlock(&buf->mutex);
981
982 ret = simple_read_from_buffer(user_buf, len, offset,
Ming Lei3c04e202008-09-18 23:06:21 +0800983 buf->output_buf, buf->count);
Tony Jones694cc202007-09-11 14:07:31 -0700984
985out:
986 return ret;
Tony Jones694cc202007-09-11 14:07:31 -0700987}
988
989static int debug_close(struct inode *inode, struct file *file)
990{
991 struct debug_buffer *buf = file->private_data;
992
993 if (buf) {
Figo.zhangf8086a02009-06-06 20:31:49 +0800994 vfree(buf->output_buf);
Tony Jones694cc202007-09-11 14:07:31 -0700995 kfree(buf);
996 }
997
998 return 0;
999}
Alan Sternd0ce5c62013-10-11 11:29:13 -04001000
Tony Jones694cc202007-09-11 14:07:31 -07001001static int debug_async_open(struct inode *inode, struct file *file)
1002{
1003 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
1004
1005 return file->private_data ? 0 : -ENOMEM;
1006}
1007
Alan Sternd0ce5c62013-10-11 11:29:13 -04001008static int debug_bandwidth_open(struct inode *inode, struct file *file)
1009{
1010 file->private_data = alloc_buffer(inode->i_private,
1011 fill_bandwidth_buffer);
1012
1013 return file->private_data ? 0 : -ENOMEM;
1014}
1015
Tony Jones694cc202007-09-11 14:07:31 -07001016static int debug_periodic_open(struct inode *inode, struct file *file)
1017{
Ming Lei3c04e202008-09-18 23:06:21 +08001018 struct debug_buffer *buf;
Geyslan G. Bem8d587d62016-01-25 22:45:03 -03001019
Ming Lei3c04e202008-09-18 23:06:21 +08001020 buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
1021 if (!buf)
1022 return -ENOMEM;
Tony Jones694cc202007-09-11 14:07:31 -07001023
Geyslan G. Bemc2fb0172016-01-25 22:44:58 -03001024 buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8) * PAGE_SIZE;
Ming Lei3c04e202008-09-18 23:06:21 +08001025 file->private_data = buf;
1026 return 0;
Tony Jones694cc202007-09-11 14:07:31 -07001027}
1028
1029static int debug_registers_open(struct inode *inode, struct file *file)
1030{
1031 file->private_data = alloc_buffer(inode->i_private,
1032 fill_registers_buffer);
1033
1034 return file->private_data ? 0 : -ENOMEM;
1035}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -03001037static inline void create_debug_files(struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038{
Tony Jones694cc202007-09-11 14:07:31 -07001039 struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
Tony Jones694cc202007-09-11 14:07:31 -07001041 ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
1042 if (!ehci->debug_dir)
Ming Lei185c9bc2010-07-28 22:33:28 +08001043 return;
Tony Jones694cc202007-09-11 14:07:31 -07001044
Ming Lei185c9bc2010-07-28 22:33:28 +08001045 if (!debugfs_create_file("async", S_IRUGO, ehci->debug_dir, bus,
1046 &debug_async_fops))
1047 goto file_error;
Tony Jones694cc202007-09-11 14:07:31 -07001048
Alan Sternd0ce5c62013-10-11 11:29:13 -04001049 if (!debugfs_create_file("bandwidth", S_IRUGO, ehci->debug_dir, bus,
1050 &debug_bandwidth_fops))
1051 goto file_error;
1052
Ming Lei185c9bc2010-07-28 22:33:28 +08001053 if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus,
1054 &debug_periodic_fops))
1055 goto file_error;
Tony Jones694cc202007-09-11 14:07:31 -07001056
Ming Lei185c9bc2010-07-28 22:33:28 +08001057 if (!debugfs_create_file("registers", S_IRUGO, ehci->debug_dir, bus,
1058 &debug_registers_fops))
1059 goto file_error;
Alek Duaa4d8342010-06-04 15:47:54 +08001060
Tony Jones694cc202007-09-11 14:07:31 -07001061 return;
1062
Ming Lei185c9bc2010-07-28 22:33:28 +08001063file_error:
1064 debugfs_remove_recursive(ehci->debug_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065}
1066
Geyslan G. Bem668ab0d2016-01-25 22:44:53 -03001067static inline void remove_debug_files(struct ehci_hcd *ehci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068{
Ming Lei185c9bc2010-07-28 22:33:28 +08001069 debugfs_remove_recursive(ehci->debug_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070}
1071
Alan Stern128f8b3d2016-04-29 15:19:56 -04001072#else /* CONFIG_DYNAMIC_DEBUG */
1073
1074static inline void dbg_hcs_params(struct ehci_hcd *ehci, char *label) { }
1075static inline void dbg_hcc_params(struct ehci_hcd *ehci, char *label) { }
1076
1077static inline void __maybe_unused dbg_qh(const char *label,
1078 struct ehci_hcd *ehci, struct ehci_qh *qh) { }
1079
1080static inline int __maybe_unused dbg_status_buf(const char *buf,
1081 unsigned int len, const char *label, u32 status)
1082{ return 0; }
1083
1084static inline int __maybe_unused dbg_command_buf(const char *buf,
1085 unsigned int len, const char *label, u32 command)
1086{ return 0; }
1087
1088static inline int __maybe_unused dbg_intr_buf(const char *buf,
1089 unsigned int len, const char *label, u32 enable)
1090{ return 0; }
1091
1092static inline int __maybe_unused dbg_port_buf(char *buf,
1093 unsigned int len, const char *label, int port, u32 status)
1094{ return 0; }
1095
1096static inline void dbg_status(struct ehci_hcd *ehci, const char *label,
1097 u32 status) { }
1098static inline void dbg_cmd(struct ehci_hcd *ehci, const char *label,
1099 u32 command) { }
1100static inline void dbg_port(struct ehci_hcd *ehci, const char *label,
1101 int port, u32 status) { }
1102
1103static inline void create_debug_files(struct ehci_hcd *bus) { }
1104static inline void remove_debug_files(struct ehci_hcd *bus) { }
1105
Geyslan G. Bem93df42b2016-01-25 22:45:09 -03001106#endif /* CONFIG_DYNAMIC_DEBUG */