xref: /openbmc/linux/drivers/usb/host/ehci-dbg.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
15fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0+
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * Copyright (c) 2001-2002 by David Brownell
41da177e4SLinus Torvalds  */
51da177e4SLinus Torvalds 
61da177e4SLinus Torvalds /* this file is part of ehci-hcd.c */
71da177e4SLinus Torvalds 
81c20163dSOliver Neukum #ifdef CONFIG_DYNAMIC_DEBUG
91da177e4SLinus Torvalds 
100784b4d5SGeyslan G. Bem /*
110784b4d5SGeyslan G. Bem  * check the values in the HCSPARAMS register
121da177e4SLinus Torvalds  * (host controller _Structural_ parameters)
131da177e4SLinus Torvalds  * see EHCI spec, Table 2-4 for each value
141da177e4SLinus Torvalds  */
dbg_hcs_params(struct ehci_hcd * ehci,char * label)151da177e4SLinus Torvalds static void dbg_hcs_params(struct ehci_hcd *ehci, char *label)
161da177e4SLinus Torvalds {
17083522d7SBenjamin Herrenschmidt 	u32	params = ehci_readl(ehci, &ehci->caps->hcs_params);
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds 	ehci_dbg(ehci,
201da177e4SLinus Torvalds 		"%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n",
211da177e4SLinus Torvalds 		label, params,
221da177e4SLinus Torvalds 		HCS_DEBUG_PORT(params),
231da177e4SLinus Torvalds 		HCS_INDICATOR(params) ? " ind" : "",
241da177e4SLinus Torvalds 		HCS_N_CC(params),
251da177e4SLinus Torvalds 		HCS_N_PCC(params),
261da177e4SLinus Torvalds 		HCS_PORTROUTED(params) ? "" : " ordered",
271da177e4SLinus Torvalds 		HCS_PPC(params) ? "" : " !ppc",
2878698d66SGeyslan G. Bem 		HCS_N_PORTS(params));
291da177e4SLinus Torvalds 	/* Port routing, per EHCI 0.95 Spec, Section 2.2.5 */
301da177e4SLinus Torvalds 	if (HCS_PORTROUTED(params)) {
311da177e4SLinus Torvalds 		int i;
321da177e4SLinus Torvalds 		char buf[46], tmp[7], byte;
331da177e4SLinus Torvalds 
341da177e4SLinus Torvalds 		buf[0] = 0;
351da177e4SLinus Torvalds 		for (i = 0; i < HCS_N_PORTS(params); i++) {
360784b4d5SGeyslan G. Bem 			/* FIXME MIPS won't readb() ... */
371da177e4SLinus Torvalds 			byte = readb(&ehci->caps->portroute[(i >> 1)]);
381da177e4SLinus Torvalds 			sprintf(tmp, "%d ",
39c2fb0171SGeyslan G. Bem 				(i & 0x1) ? byte & 0xf : (byte >> 4) & 0xf);
401da177e4SLinus Torvalds 			strcat(buf, tmp);
411da177e4SLinus Torvalds 		}
42668ab0dbSGeyslan G. Bem 		ehci_dbg(ehci, "%s portroute %s\n", label, buf);
431da177e4SLinus Torvalds 	}
441da177e4SLinus Torvalds }
451da177e4SLinus Torvalds 
460784b4d5SGeyslan G. Bem /*
470784b4d5SGeyslan G. Bem  * check the values in the HCCPARAMS register
481da177e4SLinus Torvalds  * (host controller _Capability_ parameters)
491da177e4SLinus Torvalds  * see EHCI Spec, Table 2-5 for each value
500784b4d5SGeyslan G. Bem  */
dbg_hcc_params(struct ehci_hcd * ehci,char * label)511da177e4SLinus Torvalds static void dbg_hcc_params(struct ehci_hcd *ehci, char *label)
521da177e4SLinus Torvalds {
53083522d7SBenjamin Herrenschmidt 	u32	params = ehci_readl(ehci, &ehci->caps->hcc_params);
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds 	if (HCC_ISOC_CACHE(params)) {
561da177e4SLinus Torvalds 		ehci_dbg(ehci,
571da177e4SLinus Torvalds 			"%s hcc_params %04x caching frame %s%s%s\n",
581da177e4SLinus Torvalds 			label, params,
591da177e4SLinus Torvalds 			HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
601da177e4SLinus Torvalds 			HCC_CANPARK(params) ? " park" : "",
611da177e4SLinus Torvalds 			HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
621da177e4SLinus Torvalds 	} else {
631da177e4SLinus Torvalds 		ehci_dbg(ehci,
64aa4d8342SAlek Du 			"%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n",
651da177e4SLinus Torvalds 			label,
661da177e4SLinus Torvalds 			params,
671da177e4SLinus Torvalds 			HCC_ISOC_THRES(params),
681da177e4SLinus Torvalds 			HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
691da177e4SLinus Torvalds 			HCC_CANPARK(params) ? " park" : "",
70aa4d8342SAlek Du 			HCC_64BIT_ADDR(params) ? " 64 bit addr" : "",
71aa4d8342SAlek Du 			HCC_LPM(params) ? " LPM" : "",
72aa4d8342SAlek Du 			HCC_PER_PORT_CHANGE_EVENT(params) ? " ppce" : "",
73aa4d8342SAlek Du 			HCC_HW_PREFETCH(params) ? " hw prefetch" : "",
74aa4d8342SAlek Du 			HCC_32FRAME_PERIODIC_LIST(params) ?
75855ef452SMasanari Iida 				" 32 periodic list" : "");
761da177e4SLinus Torvalds 	}
771da177e4SLinus Torvalds }
781da177e4SLinus Torvalds 
798234509cSDavid Rientjes static void __maybe_unused
dbg_qtd(const char * label,struct ehci_hcd * ehci,struct ehci_qtd * qtd)801da177e4SLinus Torvalds dbg_qtd(const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
811da177e4SLinus Torvalds {
821da177e4SLinus Torvalds 	ehci_dbg(ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
836dbd682bSStefan Roese 		hc32_to_cpup(ehci, &qtd->hw_next),
846dbd682bSStefan Roese 		hc32_to_cpup(ehci, &qtd->hw_alt_next),
856dbd682bSStefan Roese 		hc32_to_cpup(ehci, &qtd->hw_token),
866dbd682bSStefan Roese 		hc32_to_cpup(ehci, &qtd->hw_buf[0]));
871da177e4SLinus Torvalds 	if (qtd->hw_buf[1])
881da177e4SLinus Torvalds 		ehci_dbg(ehci, "  p1=%08x p2=%08x p3=%08x p4=%08x\n",
896dbd682bSStefan Roese 			hc32_to_cpup(ehci, &qtd->hw_buf[1]),
906dbd682bSStefan Roese 			hc32_to_cpup(ehci, &qtd->hw_buf[2]),
916dbd682bSStefan Roese 			hc32_to_cpup(ehci, &qtd->hw_buf[3]),
926dbd682bSStefan Roese 			hc32_to_cpup(ehci, &qtd->hw_buf[4]));
931da177e4SLinus Torvalds }
941da177e4SLinus Torvalds 
958234509cSDavid Rientjes static void __maybe_unused
dbg_qh(const char * label,struct ehci_hcd * ehci,struct ehci_qh * qh)961da177e4SLinus Torvalds dbg_qh(const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
971da177e4SLinus Torvalds {
983807e26dSAlek Du 	struct ehci_qh_hw *hw = qh->hw;
993807e26dSAlek Du 
1001da177e4SLinus Torvalds 	ehci_dbg(ehci, "%s qh %p n%08x info %x %x qtd %x\n", label,
1013807e26dSAlek Du 		qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current);
1023807e26dSAlek Du 	dbg_qtd("overlay", ehci, (struct ehci_qtd *) &hw->hw_qtd_next);
1031da177e4SLinus Torvalds }
1041da177e4SLinus Torvalds 
1058234509cSDavid Rientjes static void __maybe_unused
dbg_itd(const char * label,struct ehci_hcd * ehci,struct ehci_itd * itd)1061da177e4SLinus Torvalds dbg_itd(const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
1071da177e4SLinus Torvalds {
1081da177e4SLinus Torvalds 	ehci_dbg(ehci, "%s [%d] itd %p, next %08x, urb %p\n",
1096dbd682bSStefan Roese 		label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next),
1106dbd682bSStefan Roese 		itd->urb);
1111da177e4SLinus Torvalds 	ehci_dbg(ehci,
1121da177e4SLinus Torvalds 		"  trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
1136dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_transaction[0]),
1146dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_transaction[1]),
1156dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_transaction[2]),
1166dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_transaction[3]),
1176dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_transaction[4]),
1186dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_transaction[5]),
1196dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_transaction[6]),
1206dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_transaction[7]));
1211da177e4SLinus Torvalds 	ehci_dbg(ehci,
1221da177e4SLinus Torvalds 		"  buf:   %08x %08x %08x %08x %08x %08x %08x\n",
1236dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_bufp[0]),
1246dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_bufp[1]),
1256dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_bufp[2]),
1266dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_bufp[3]),
1276dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_bufp[4]),
1286dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_bufp[5]),
1296dbd682bSStefan Roese 		hc32_to_cpu(ehci, itd->hw_bufp[6]));
1301da177e4SLinus Torvalds 	ehci_dbg(ehci, "  index: %d %d %d %d %d %d %d %d\n",
1311da177e4SLinus Torvalds 		itd->index[0], itd->index[1], itd->index[2],
1321da177e4SLinus Torvalds 		itd->index[3], itd->index[4], itd->index[5],
1331da177e4SLinus Torvalds 		itd->index[6], itd->index[7]);
1341da177e4SLinus Torvalds }
1351da177e4SLinus Torvalds 
1368234509cSDavid Rientjes static void __maybe_unused
dbg_sitd(const char * label,struct ehci_hcd * ehci,struct ehci_sitd * sitd)1371da177e4SLinus Torvalds dbg_sitd(const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
1381da177e4SLinus Torvalds {
1391da177e4SLinus Torvalds 	ehci_dbg(ehci, "%s [%d] sitd %p, next %08x, urb %p\n",
1406dbd682bSStefan Roese 		label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next),
1416dbd682bSStefan Roese 		sitd->urb);
1421da177e4SLinus Torvalds 	ehci_dbg(ehci,
1431da177e4SLinus Torvalds 		"  addr %08x sched %04x result %08x buf %08x %08x\n",
1446dbd682bSStefan Roese 		hc32_to_cpu(ehci, sitd->hw_fullspeed_ep),
1456dbd682bSStefan Roese 		hc32_to_cpu(ehci, sitd->hw_uframe),
1466dbd682bSStefan Roese 		hc32_to_cpu(ehci, sitd->hw_results),
1476dbd682bSStefan Roese 		hc32_to_cpu(ehci, sitd->hw_buf[0]),
1486dbd682bSStefan Roese 		hc32_to_cpu(ehci, sitd->hw_buf[1]));
1491da177e4SLinus Torvalds }
1501da177e4SLinus Torvalds 
1518234509cSDavid Rientjes static int __maybe_unused
dbg_status_buf(char * buf,unsigned len,const char * label,u32 status)1521da177e4SLinus Torvalds dbg_status_buf(char *buf, unsigned len, const char *label, u32 status)
1531da177e4SLinus Torvalds {
1541da177e4SLinus Torvalds 	return scnprintf(buf, len,
155aa4d8342SAlek Du 		"%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s%s",
1561da177e4SLinus Torvalds 		label, label[0] ? " " : "", status,
157aa4d8342SAlek Du 		(status & STS_PPCE_MASK) ? " PPCE" : "",
1581da177e4SLinus Torvalds 		(status & STS_ASS) ? " Async" : "",
1591da177e4SLinus Torvalds 		(status & STS_PSS) ? " Periodic" : "",
1601da177e4SLinus Torvalds 		(status & STS_RECL) ? " Recl" : "",
1611da177e4SLinus Torvalds 		(status & STS_HALT) ? " Halt" : "",
1621da177e4SLinus Torvalds 		(status & STS_IAA) ? " IAA" : "",
1631da177e4SLinus Torvalds 		(status & STS_FATAL) ? " FATAL" : "",
1641da177e4SLinus Torvalds 		(status & STS_FLR) ? " FLR" : "",
1651da177e4SLinus Torvalds 		(status & STS_PCD) ? " PCD" : "",
1661da177e4SLinus Torvalds 		(status & STS_ERR) ? " ERR" : "",
16778698d66SGeyslan G. Bem 		(status & STS_INT) ? " INT" : "");
1681da177e4SLinus Torvalds }
1691da177e4SLinus Torvalds 
1708234509cSDavid Rientjes static int __maybe_unused
dbg_intr_buf(char * buf,unsigned len,const char * label,u32 enable)1711da177e4SLinus Torvalds dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable)
1721da177e4SLinus Torvalds {
1731da177e4SLinus Torvalds 	return scnprintf(buf, len,
174aa4d8342SAlek Du 		"%s%sintrenable %02x%s%s%s%s%s%s%s",
1751da177e4SLinus Torvalds 		label, label[0] ? " " : "", enable,
176aa4d8342SAlek Du 		(enable & STS_PPCE_MASK) ? " PPCE" : "",
1771da177e4SLinus Torvalds 		(enable & STS_IAA) ? " IAA" : "",
1781da177e4SLinus Torvalds 		(enable & STS_FATAL) ? " FATAL" : "",
1791da177e4SLinus Torvalds 		(enable & STS_FLR) ? " FLR" : "",
1801da177e4SLinus Torvalds 		(enable & STS_PCD) ? " PCD" : "",
1811da177e4SLinus Torvalds 		(enable & STS_ERR) ? " ERR" : "",
18278698d66SGeyslan G. Bem 		(enable & STS_INT) ? " INT" : "");
1831da177e4SLinus Torvalds }
1841da177e4SLinus Torvalds 
1851cb1d1c0SGeyslan G. Bem static const char *const fls_strings[] = { "1024", "512", "256", "??" };
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds static int
dbg_command_buf(char * buf,unsigned len,const char * label,u32 command)1881da177e4SLinus Torvalds dbg_command_buf(char *buf, unsigned len, const char *label, u32 command)
1891da177e4SLinus Torvalds {
1901da177e4SLinus Torvalds 	return scnprintf(buf, len,
191aa4d8342SAlek Du 		"%s%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s "
192aa4d8342SAlek Du 		"period=%s%s %s",
1931da177e4SLinus Torvalds 		label, label[0] ? " " : "", command,
194aa4d8342SAlek Du 		(command & CMD_HIRD) ? " HIRD" : "",
195aa4d8342SAlek Du 		(command & CMD_PPCEE) ? " PPCEE" : "",
196aa4d8342SAlek Du 		(command & CMD_FSP) ? " FSP" : "",
197aa4d8342SAlek Du 		(command & CMD_ASPE) ? " ASPE" : "",
198aa4d8342SAlek Du 		(command & CMD_PSPE) ? " PSPE" : "",
1991da177e4SLinus Torvalds 		(command & CMD_PARK) ? " park" : "(park)",
2001da177e4SLinus Torvalds 		CMD_PARK_CNT(command),
2011da177e4SLinus Torvalds 		(command >> 16) & 0x3f,
2021da177e4SLinus Torvalds 		(command & CMD_LRESET) ? " LReset" : "",
2031da177e4SLinus Torvalds 		(command & CMD_IAAD) ? " IAAD" : "",
2041da177e4SLinus Torvalds 		(command & CMD_ASE) ? " Async" : "",
2051da177e4SLinus Torvalds 		(command & CMD_PSE) ? " Periodic" : "",
2061da177e4SLinus Torvalds 		fls_strings[(command >> 2) & 0x3],
2071da177e4SLinus Torvalds 		(command & CMD_RESET) ? " Reset" : "",
20878698d66SGeyslan G. Bem 		(command & CMD_RUN) ? "RUN" : "HALT");
2091da177e4SLinus Torvalds }
2101da177e4SLinus Torvalds 
2111da177e4SLinus Torvalds static int
dbg_port_buf(char * buf,unsigned len,const char * label,int port,u32 status)2121da177e4SLinus Torvalds dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status)
2131da177e4SLinus Torvalds {
2141da177e4SLinus Torvalds 	char	*sig;
2151da177e4SLinus Torvalds 
2161da177e4SLinus Torvalds 	/* signaling state */
2171da177e4SLinus Torvalds 	switch (status & (3 << 10)) {
2185bb95ec8SGeyslan G. Bem 	case 0 << 10:
2195bb95ec8SGeyslan G. Bem 		sig = "se0";
2205bb95ec8SGeyslan G. Bem 		break;
2215bb95ec8SGeyslan G. Bem 	case 1 << 10: /* low speed */
2225bb95ec8SGeyslan G. Bem 		sig = "k";
2235bb95ec8SGeyslan G. Bem 		break;
2245bb95ec8SGeyslan G. Bem 	case 2 << 10:
2255bb95ec8SGeyslan G. Bem 		sig = "j";
2265bb95ec8SGeyslan G. Bem 		break;
2275bb95ec8SGeyslan G. Bem 	default:
2285bb95ec8SGeyslan G. Bem 		sig = "?";
2295bb95ec8SGeyslan G. Bem 		break;
2301da177e4SLinus Torvalds 	}
2311da177e4SLinus Torvalds 
2321da177e4SLinus Torvalds 	return scnprintf(buf, len,
233aa4d8342SAlek Du 		"%s%sport:%d status %06x %d %s%s%s%s%s%s "
234aa4d8342SAlek Du 		"sig=%s%s%s%s%s%s%s%s%s%s%s",
2351da177e4SLinus Torvalds 		label, label[0] ? " " : "", port, status,
236aa4d8342SAlek Du 		status >> 25, /*device address */
237aa4d8342SAlek Du 		(status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_ACK ?
238aa4d8342SAlek Du 						" ACK" : "",
239aa4d8342SAlek Du 		(status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_NYET ?
240aa4d8342SAlek Du 						" NYET" : "",
241aa4d8342SAlek Du 		(status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_STALL ?
242aa4d8342SAlek Du 						" STALL" : "",
243aa4d8342SAlek Du 		(status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_ERR ?
244aa4d8342SAlek Du 						" ERR" : "",
2451da177e4SLinus Torvalds 		(status & PORT_POWER) ? " POWER" : "",
2461da177e4SLinus Torvalds 		(status & PORT_OWNER) ? " OWNER" : "",
2471da177e4SLinus Torvalds 		sig,
248aa4d8342SAlek Du 		(status & PORT_LPM) ? " LPM" : "",
2491da177e4SLinus Torvalds 		(status & PORT_RESET) ? " RESET" : "",
2501da177e4SLinus Torvalds 		(status & PORT_SUSPEND) ? " SUSPEND" : "",
2511da177e4SLinus Torvalds 		(status & PORT_RESUME) ? " RESUME" : "",
2521da177e4SLinus Torvalds 		(status & PORT_OCC) ? " OCC" : "",
2531da177e4SLinus Torvalds 		(status & PORT_OC) ? " OC" : "",
2541da177e4SLinus Torvalds 		(status & PORT_PEC) ? " PEC" : "",
2551da177e4SLinus Torvalds 		(status & PORT_PE) ? " PE" : "",
2561da177e4SLinus Torvalds 		(status & PORT_CSC) ? " CSC" : "",
2576dbd682bSStefan Roese 		(status & PORT_CONNECT) ? " CONNECT" : "");
2581da177e4SLinus Torvalds }
2591da177e4SLinus Torvalds 
2601f8e5afdSGeyslan G. Bem static inline void
dbg_status(struct ehci_hcd * ehci,const char * label,u32 status)2611f8e5afdSGeyslan G. Bem dbg_status(struct ehci_hcd *ehci, const char *label, u32 status)
2621f8e5afdSGeyslan G. Bem {
2631f8e5afdSGeyslan G. Bem 	char buf[80];
2641f8e5afdSGeyslan G. Bem 
2651f8e5afdSGeyslan G. Bem 	dbg_status_buf(buf, sizeof(buf), label, status);
2661f8e5afdSGeyslan G. Bem 	ehci_dbg(ehci, "%s\n", buf);
2671da177e4SLinus Torvalds }
2681da177e4SLinus Torvalds 
2691f8e5afdSGeyslan G. Bem static inline void
dbg_cmd(struct ehci_hcd * ehci,const char * label,u32 command)2701f8e5afdSGeyslan G. Bem dbg_cmd(struct ehci_hcd *ehci, const char *label, u32 command)
2711f8e5afdSGeyslan G. Bem {
2721f8e5afdSGeyslan G. Bem 	char buf[80];
2731f8e5afdSGeyslan G. Bem 
2741f8e5afdSGeyslan G. Bem 	dbg_command_buf(buf, sizeof(buf), label, command);
2751f8e5afdSGeyslan G. Bem 	ehci_dbg(ehci, "%s\n", buf);
2761da177e4SLinus Torvalds }
2771da177e4SLinus Torvalds 
2781f8e5afdSGeyslan G. Bem static inline void
dbg_port(struct ehci_hcd * ehci,const char * label,int port,u32 status)2791f8e5afdSGeyslan G. Bem dbg_port(struct ehci_hcd *ehci, const char *label, int port, u32 status)
2801f8e5afdSGeyslan G. Bem {
2811f8e5afdSGeyslan G. Bem 	char buf[80];
2821f8e5afdSGeyslan G. Bem 
2831f8e5afdSGeyslan G. Bem 	dbg_port_buf(buf, sizeof(buf), label, port, status);
2841f8e5afdSGeyslan G. Bem 	ehci_dbg(ehci, "%s\n", buf);
2851da177e4SLinus Torvalds }
2861da177e4SLinus Torvalds 
2871da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
2881da177e4SLinus Torvalds 
289694cc208STony Jones /* troubleshooting help: expose state in debugfs */
290694cc208STony Jones 
291694cc208STony Jones static int debug_async_open(struct inode *, struct file *);
292d0ce5c6bSAlan Stern static int debug_bandwidth_open(struct inode *, struct file *);
293694cc208STony Jones static int debug_periodic_open(struct inode *, struct file *);
294694cc208STony Jones static int debug_registers_open(struct inode *, struct file *);
295aa4d8342SAlek Du 
296694cc208STony Jones static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
297694cc208STony Jones static int debug_close(struct inode *, struct file *);
298694cc208STony Jones 
299694cc208STony Jones static const struct file_operations debug_async_fops = {
300694cc208STony Jones 	.owner		= THIS_MODULE,
301694cc208STony Jones 	.open		= debug_async_open,
302694cc208STony Jones 	.read		= debug_output,
303694cc208STony Jones 	.release	= debug_close,
3046038f373SArnd Bergmann 	.llseek		= default_llseek,
305694cc208STony Jones };
306e1666317SGeyslan G. Bem 
307d0ce5c6bSAlan Stern static const struct file_operations debug_bandwidth_fops = {
308d0ce5c6bSAlan Stern 	.owner		= THIS_MODULE,
309d0ce5c6bSAlan Stern 	.open		= debug_bandwidth_open,
310d0ce5c6bSAlan Stern 	.read		= debug_output,
311d0ce5c6bSAlan Stern 	.release	= debug_close,
312d0ce5c6bSAlan Stern 	.llseek		= default_llseek,
313d0ce5c6bSAlan Stern };
314e1666317SGeyslan G. Bem 
315694cc208STony Jones static const struct file_operations debug_periodic_fops = {
316694cc208STony Jones 	.owner		= THIS_MODULE,
317694cc208STony Jones 	.open		= debug_periodic_open,
318694cc208STony Jones 	.read		= debug_output,
319694cc208STony Jones 	.release	= debug_close,
3206038f373SArnd Bergmann 	.llseek		= default_llseek,
321694cc208STony Jones };
322e1666317SGeyslan G. Bem 
323694cc208STony Jones static const struct file_operations debug_registers_fops = {
324694cc208STony Jones 	.owner		= THIS_MODULE,
325694cc208STony Jones 	.open		= debug_registers_open,
326694cc208STony Jones 	.read		= debug_output,
327694cc208STony Jones 	.release	= debug_close,
3286038f373SArnd Bergmann 	.llseek		= default_llseek,
329694cc208STony Jones };
330694cc208STony Jones 
331694cc208STony Jones static struct dentry *ehci_debug_root;
332694cc208STony Jones 
333694cc208STony Jones struct debug_buffer {
334694cc208STony Jones 	ssize_t (*fill_func)(struct debug_buffer *);	/* fill method */
335694cc208STony Jones 	struct usb_bus *bus;
336694cc208STony Jones 	struct mutex mutex;	/* protect filling of buffer */
337694cc208STony Jones 	size_t count;		/* number of characters filled into buffer */
3383c04e20eSMing Lei 	char *output_buf;
3393c04e20eSMing Lei 	size_t alloc_size;
340694cc208STony Jones };
3411da177e4SLinus Torvalds 
speed_char(u32 info1)3421f8e5afdSGeyslan G. Bem static inline char speed_char(u32 info1)
3431f8e5afdSGeyslan G. Bem {
3441f8e5afdSGeyslan G. Bem 	switch (info1 & (3 << 12)) {
3451f8e5afdSGeyslan G. Bem 	case QH_FULL_SPEED:
3461f8e5afdSGeyslan G. Bem 		return 'f';
3471f8e5afdSGeyslan G. Bem 	case QH_LOW_SPEED:
3481f8e5afdSGeyslan G. Bem 		return 'l';
3491f8e5afdSGeyslan G. Bem 	case QH_HIGH_SPEED:
3501f8e5afdSGeyslan G. Bem 		return 'h';
3511f8e5afdSGeyslan G. Bem 	default:
3521f8e5afdSGeyslan G. Bem 		return '?';
3531f8e5afdSGeyslan G. Bem 	}
3541f8e5afdSGeyslan G. Bem }
3551da177e4SLinus Torvalds 
token_mark(struct ehci_hcd * ehci,__hc32 token)3566dbd682bSStefan Roese static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
3571da177e4SLinus Torvalds {
3586dbd682bSStefan Roese 	__u32 v = hc32_to_cpu(ehci, token);
3596dbd682bSStefan Roese 
3601da177e4SLinus Torvalds 	if (v & QTD_STS_ACTIVE)
3611da177e4SLinus Torvalds 		return '*';
3621da177e4SLinus Torvalds 	if (v & QTD_STS_HALT)
3631da177e4SLinus Torvalds 		return '-';
3641da177e4SLinus Torvalds 	if (!IS_SHORT_READ(v))
3651da177e4SLinus Torvalds 		return ' ';
3661da177e4SLinus Torvalds 	/* tries to advance through hw_alt_next */
3671da177e4SLinus Torvalds 	return '/';
3681da177e4SLinus Torvalds }
3691da177e4SLinus Torvalds 
qh_lines(struct ehci_hcd * ehci,struct ehci_qh * qh,char ** nextp,unsigned * sizep)370c768ffb8SGeyslan G. Bem static void qh_lines(struct ehci_hcd *ehci, struct ehci_qh *qh,
371c768ffb8SGeyslan G. Bem 		char **nextp, unsigned *sizep)
3721da177e4SLinus Torvalds {
3731da177e4SLinus Torvalds 	u32			scratch;
3741da177e4SLinus Torvalds 	u32			hw_curr;
3751da177e4SLinus Torvalds 	struct list_head	*entry;
3761da177e4SLinus Torvalds 	struct ehci_qtd		*td;
3771da177e4SLinus Torvalds 	unsigned		temp;
3781da177e4SLinus Torvalds 	unsigned		size = *sizep;
3791da177e4SLinus Torvalds 	char			*next = *nextp;
3801da177e4SLinus Torvalds 	char			mark;
381fd05e720SAl Viro 	__le32			list_end = EHCI_LIST_END(ehci);
3823807e26dSAlek Du 	struct ehci_qh_hw	*hw = qh->hw;
3831da177e4SLinus Torvalds 
3843807e26dSAlek Du 	if (hw->hw_qtd_next == list_end)	/* NEC does this */
3851da177e4SLinus Torvalds 		mark = '@';
3861da177e4SLinus Torvalds 	else
3873807e26dSAlek Du 		mark = token_mark(ehci, hw->hw_token);
3881da177e4SLinus Torvalds 	if (mark == '/') {	/* qh_alt_next controls qh advance? */
3893807e26dSAlek Du 		if ((hw->hw_alt_next & QTD_MASK(ehci))
3903807e26dSAlek Du 				== ehci->async->hw->hw_alt_next)
3911da177e4SLinus Torvalds 			mark = '#';	/* blocked */
3923807e26dSAlek Du 		else if (hw->hw_alt_next == list_end)
3931da177e4SLinus Torvalds 			mark = '.';	/* use hw_qtd_next */
3941da177e4SLinus Torvalds 		/* else alt_next points to some other qtd */
3951da177e4SLinus Torvalds 	}
3963807e26dSAlek Du 	scratch = hc32_to_cpup(ehci, &hw->hw_info1);
3973807e26dSAlek Du 	hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0;
3981da177e4SLinus Torvalds 	temp = scnprintf(next, size,
3998ee10d62SAlan Stern 			"qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)"
4008ee10d62SAlan Stern 			" [cur %08x next %08x buf[0] %08x]",
4011da177e4SLinus Torvalds 			qh, scratch & 0x007f,
4021da177e4SLinus Torvalds 			speed_char (scratch),
4031da177e4SLinus Torvalds 			(scratch >> 8) & 0x000f,
4043807e26dSAlek Du 			scratch, hc32_to_cpup(ehci, &hw->hw_info2),
4053807e26dSAlek Du 			hc32_to_cpup(ehci, &hw->hw_token), mark,
4063807e26dSAlek Du 			(cpu_to_hc32(ehci, QTD_TOGGLE) & hw->hw_token)
4071da177e4SLinus Torvalds 				? "data1" : "data0",
4088ee10d62SAlan Stern 			(hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f,
4098ee10d62SAlan Stern 			hc32_to_cpup(ehci, &hw->hw_current),
4108ee10d62SAlan Stern 			hc32_to_cpup(ehci, &hw->hw_qtd_next),
4118ee10d62SAlan Stern 			hc32_to_cpup(ehci, &hw->hw_buf[0]));
4121da177e4SLinus Torvalds 	size -= temp;
4131da177e4SLinus Torvalds 	next += temp;
4141da177e4SLinus Torvalds 
4151da177e4SLinus Torvalds 	/* hc may be modifying the list as we read it ... */
4161da177e4SLinus Torvalds 	list_for_each(entry, &qh->qtd_list) {
4175bb95ec8SGeyslan G. Bem 		char *type;
4185bb95ec8SGeyslan G. Bem 
4191da177e4SLinus Torvalds 		td = list_entry(entry, struct ehci_qtd, qtd_list);
4206dbd682bSStefan Roese 		scratch = hc32_to_cpup(ehci, &td->hw_token);
4211da177e4SLinus Torvalds 		mark = ' ';
42204b8ad43SGeyslan G. Bem 		if (hw_curr == td->qtd_dma) {
4231da177e4SLinus Torvalds 			mark = '*';
42404b8ad43SGeyslan G. Bem 		} else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma)) {
4251da177e4SLinus Torvalds 			mark = '+';
42604b8ad43SGeyslan G. Bem 		} else if (QTD_LENGTH(scratch)) {
4273807e26dSAlek Du 			if (td->hw_alt_next == ehci->async->hw->hw_alt_next)
4281da177e4SLinus Torvalds 				mark = '#';
4296dbd682bSStefan Roese 			else if (td->hw_alt_next != list_end)
4301da177e4SLinus Torvalds 				mark = '/';
4311da177e4SLinus Torvalds 		}
4325bb95ec8SGeyslan G. Bem 		switch ((scratch >> 8) & 0x03) {
4335bb95ec8SGeyslan G. Bem 		case 0:
4345bb95ec8SGeyslan G. Bem 			type = "out";
4355bb95ec8SGeyslan G. Bem 			break;
4365bb95ec8SGeyslan G. Bem 		case 1:
4375bb95ec8SGeyslan G. Bem 			type = "in";
4385bb95ec8SGeyslan G. Bem 			break;
4395bb95ec8SGeyslan G. Bem 		case 2:
4405bb95ec8SGeyslan G. Bem 			type = "setup";
4415bb95ec8SGeyslan G. Bem 			break;
4425bb95ec8SGeyslan G. Bem 		default:
4435bb95ec8SGeyslan G. Bem 			type = "?";
4445bb95ec8SGeyslan G. Bem 			break;
4455bb95ec8SGeyslan G. Bem 		}
446a5355977SGeyslan G. Bem 		temp = scnprintf(next, size,
4478ee10d62SAlan Stern 				"\n\t%p%c%s len=%d %08x urb %p"
4488ee10d62SAlan Stern 				" [td %08x buf[0] %08x]",
4495bb95ec8SGeyslan G. Bem 				td, mark, type,
4501da177e4SLinus Torvalds 				(scratch >> 16) & 0x7fff,
4511da177e4SLinus Torvalds 				scratch,
4528ee10d62SAlan Stern 				td->urb,
4538ee10d62SAlan Stern 				(u32) td->qtd_dma,
4548ee10d62SAlan Stern 				hc32_to_cpup(ehci, &td->hw_buf[0]));
4551da177e4SLinus Torvalds 		size -= temp;
4561da177e4SLinus Torvalds 		next += temp;
4571da177e4SLinus Torvalds 		if (temp == size)
4581da177e4SLinus Torvalds 			goto done;
4591da177e4SLinus Torvalds 	}
4601da177e4SLinus Torvalds 
461a5355977SGeyslan G. Bem 	temp = scnprintf(next, size, "\n");
4621da177e4SLinus Torvalds 	size -= temp;
4631da177e4SLinus Torvalds 	next += temp;
4641da177e4SLinus Torvalds 
4651da177e4SLinus Torvalds done:
4661da177e4SLinus Torvalds 	*sizep = size;
4671da177e4SLinus Torvalds 	*nextp = next;
4681da177e4SLinus Torvalds }
4691da177e4SLinus Torvalds 
fill_async_buffer(struct debug_buffer * buf)470694cc208STony Jones static ssize_t fill_async_buffer(struct debug_buffer *buf)
4711da177e4SLinus Torvalds {
4721da177e4SLinus Torvalds 	struct usb_hcd		*hcd;
4731da177e4SLinus Torvalds 	struct ehci_hcd		*ehci;
4741da177e4SLinus Torvalds 	unsigned long		flags;
4751da177e4SLinus Torvalds 	unsigned		temp, size;
4761da177e4SLinus Torvalds 	char			*next;
4771da177e4SLinus Torvalds 	struct ehci_qh		*qh;
4781da177e4SLinus Torvalds 
479694cc208STony Jones 	hcd = bus_to_hcd(buf->bus);
4801da177e4SLinus Torvalds 	ehci = hcd_to_ehci(hcd);
4813c04e20eSMing Lei 	next = buf->output_buf;
4823c04e20eSMing Lei 	size = buf->alloc_size;
4831da177e4SLinus Torvalds 
484694cc208STony Jones 	*next = 0;
485694cc208STony Jones 
4860784b4d5SGeyslan G. Bem 	/*
4870784b4d5SGeyslan G. Bem 	 * dumps a snapshot of the async schedule.
4881da177e4SLinus Torvalds 	 * usually empty except for long-term bulk reads, or head.
4891da177e4SLinus Torvalds 	 * one QH per line, and TDs we know about
4901da177e4SLinus Torvalds 	 */
4911da177e4SLinus Torvalds 	spin_lock_irqsave(&ehci->lock, flags);
4921da177e4SLinus Torvalds 	for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
4931da177e4SLinus Torvalds 		qh_lines(ehci, qh, &next, &size);
4946e018751SAlan Stern 	if (!list_empty(&ehci->async_unlink) && size > 0) {
49599ac5b1eSAlan Stern 		temp = scnprintf(next, size, "\nunlink =\n");
4961da177e4SLinus Torvalds 		size -= temp;
4971da177e4SLinus Torvalds 		next += temp;
4981da177e4SLinus Torvalds 
4996e018751SAlan Stern 		list_for_each_entry(qh, &ehci->async_unlink, unlink_node) {
5006e018751SAlan Stern 			if (size <= 0)
5016e018751SAlan Stern 				break;
5021da177e4SLinus Torvalds 			qh_lines(ehci, qh, &next, &size);
5031da177e4SLinus Torvalds 		}
5046e018751SAlan Stern 	}
5051da177e4SLinus Torvalds 	spin_unlock_irqrestore(&ehci->lock, flags);
5061da177e4SLinus Torvalds 
5073c04e20eSMing Lei 	return strlen(buf->output_buf);
5081da177e4SLinus Torvalds }
5091da177e4SLinus Torvalds 
fill_bandwidth_buffer(struct debug_buffer * buf)510d0ce5c6bSAlan Stern static ssize_t fill_bandwidth_buffer(struct debug_buffer *buf)
511d0ce5c6bSAlan Stern {
512d0ce5c6bSAlan Stern 	struct ehci_hcd		*ehci;
513b35c5009SAlan Stern 	struct ehci_tt		*tt;
514b35c5009SAlan Stern 	struct ehci_per_sched	*ps;
515d0ce5c6bSAlan Stern 	unsigned		temp, size;
516d0ce5c6bSAlan Stern 	char			*next;
517d0ce5c6bSAlan Stern 	unsigned		i;
518d0ce5c6bSAlan Stern 	u8			*bw;
519b35c5009SAlan Stern 	u16			*bf;
520b35c5009SAlan Stern 	u8			budget[EHCI_BANDWIDTH_SIZE];
521d0ce5c6bSAlan Stern 
522d0ce5c6bSAlan Stern 	ehci = hcd_to_ehci(bus_to_hcd(buf->bus));
523d0ce5c6bSAlan Stern 	next = buf->output_buf;
524d0ce5c6bSAlan Stern 	size = buf->alloc_size;
525d0ce5c6bSAlan Stern 
526d0ce5c6bSAlan Stern 	*next = 0;
527d0ce5c6bSAlan Stern 
528d0ce5c6bSAlan Stern 	spin_lock_irq(&ehci->lock);
529d0ce5c6bSAlan Stern 
530d0ce5c6bSAlan Stern 	/* Dump the HS bandwidth table */
531d0ce5c6bSAlan Stern 	temp = scnprintf(next, size,
532d0ce5c6bSAlan Stern 			"HS bandwidth allocation (us per microframe)\n");
533d0ce5c6bSAlan Stern 	size -= temp;
534d0ce5c6bSAlan Stern 	next += temp;
535d0ce5c6bSAlan Stern 	for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
536d0ce5c6bSAlan Stern 		bw = &ehci->bandwidth[i];
537d0ce5c6bSAlan Stern 		temp = scnprintf(next, size,
538d0ce5c6bSAlan Stern 				"%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
539d0ce5c6bSAlan Stern 				i, bw[0], bw[1], bw[2], bw[3],
540d0ce5c6bSAlan Stern 					bw[4], bw[5], bw[6], bw[7]);
541d0ce5c6bSAlan Stern 		size -= temp;
542d0ce5c6bSAlan Stern 		next += temp;
543d0ce5c6bSAlan Stern 	}
544b35c5009SAlan Stern 
545b35c5009SAlan Stern 	/* Dump all the FS/LS tables */
546b35c5009SAlan Stern 	list_for_each_entry(tt, &ehci->tt_list, tt_list) {
547b35c5009SAlan Stern 		temp = scnprintf(next, size,
548b35c5009SAlan Stern 				"\nTT %s port %d  FS/LS bandwidth allocation (us per frame)\n",
549b35c5009SAlan Stern 				dev_name(&tt->usb_tt->hub->dev),
550b35c5009SAlan Stern 				tt->tt_port + !!tt->usb_tt->multi);
551b35c5009SAlan Stern 		size -= temp;
552b35c5009SAlan Stern 		next += temp;
553b35c5009SAlan Stern 
554b35c5009SAlan Stern 		bf = tt->bandwidth;
555b35c5009SAlan Stern 		temp = scnprintf(next, size,
556b35c5009SAlan Stern 				"  %5u%5u%5u%5u%5u%5u%5u%5u\n",
557b35c5009SAlan Stern 				bf[0], bf[1], bf[2], bf[3],
558b35c5009SAlan Stern 					bf[4], bf[5], bf[6], bf[7]);
559b35c5009SAlan Stern 		size -= temp;
560b35c5009SAlan Stern 		next += temp;
561b35c5009SAlan Stern 
562b35c5009SAlan Stern 		temp = scnprintf(next, size,
563b35c5009SAlan Stern 				"FS/LS budget (us per microframe)\n");
564b35c5009SAlan Stern 		size -= temp;
565b35c5009SAlan Stern 		next += temp;
566b35c5009SAlan Stern 		compute_tt_budget(budget, tt);
567b35c5009SAlan Stern 		for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
568b35c5009SAlan Stern 			bw = &budget[i];
569b35c5009SAlan Stern 			temp = scnprintf(next, size,
570b35c5009SAlan Stern 					"%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
571b35c5009SAlan Stern 					i, bw[0], bw[1], bw[2], bw[3],
572b35c5009SAlan Stern 						bw[4], bw[5], bw[6], bw[7]);
573b35c5009SAlan Stern 			size -= temp;
574b35c5009SAlan Stern 			next += temp;
575b35c5009SAlan Stern 		}
576b35c5009SAlan Stern 		list_for_each_entry(ps, &tt->ps_list, ps_list) {
577b35c5009SAlan Stern 			temp = scnprintf(next, size,
578b35c5009SAlan Stern 					"%s ep %02x:  %4u @ %2u.%u+%u mask %04x\n",
579b35c5009SAlan Stern 					dev_name(&ps->udev->dev),
580b35c5009SAlan Stern 					ps->ep->desc.bEndpointAddress,
581b35c5009SAlan Stern 					ps->tt_usecs,
582b35c5009SAlan Stern 					ps->bw_phase, ps->phase_uf,
583b35c5009SAlan Stern 					ps->bw_period, ps->cs_mask);
584b35c5009SAlan Stern 			size -= temp;
585b35c5009SAlan Stern 			next += temp;
586b35c5009SAlan Stern 		}
587b35c5009SAlan Stern 	}
588d0ce5c6bSAlan Stern 	spin_unlock_irq(&ehci->lock);
589d0ce5c6bSAlan Stern 
590d0ce5c6bSAlan Stern 	return next - buf->output_buf;
591d0ce5c6bSAlan Stern }
592d0ce5c6bSAlan Stern 
output_buf_tds_dir(char * buf,struct ehci_hcd * ehci,struct ehci_qh_hw * hw,struct ehci_qh * qh,unsigned size)5933fd29009SGeyslan G. Bem static unsigned output_buf_tds_dir(char *buf, struct ehci_hcd *ehci,
5943fd29009SGeyslan G. Bem 		struct ehci_qh_hw *hw, struct ehci_qh *qh, unsigned size)
5953fd29009SGeyslan G. Bem {
5963fd29009SGeyslan G. Bem 	u32			scratch = hc32_to_cpup(ehci, &hw->hw_info1);
5973fd29009SGeyslan G. Bem 	struct ehci_qtd		*qtd;
5983fd29009SGeyslan G. Bem 	char			*type = "";
5993fd29009SGeyslan G. Bem 	unsigned		temp = 0;
6003fd29009SGeyslan G. Bem 
6013fd29009SGeyslan G. Bem 	/* count tds, get ep direction */
6023fd29009SGeyslan G. Bem 	list_for_each_entry(qtd, &qh->qtd_list, qtd_list) {
6033fd29009SGeyslan G. Bem 		temp++;
6043fd29009SGeyslan G. Bem 		switch ((hc32_to_cpu(ehci, qtd->hw_token) >> 8)	& 0x03) {
6053fd29009SGeyslan G. Bem 		case 0:
6063fd29009SGeyslan G. Bem 			type = "out";
6073fd29009SGeyslan G. Bem 			continue;
6083fd29009SGeyslan G. Bem 		case 1:
6093fd29009SGeyslan G. Bem 			type = "in";
6103fd29009SGeyslan G. Bem 			continue;
6113fd29009SGeyslan G. Bem 		}
6123fd29009SGeyslan G. Bem 	}
6133fd29009SGeyslan G. Bem 
6143fd29009SGeyslan G. Bem 	return scnprintf(buf, size, " (%c%d ep%d%s [%d/%d] q%d p%d)",
6153fd29009SGeyslan G. Bem 			speed_char(scratch), scratch & 0x007f,
6163fd29009SGeyslan G. Bem 			(scratch >> 8) & 0x000f, type, qh->ps.usecs,
6173fd29009SGeyslan G. Bem 			qh->ps.c_usecs, temp, 0x7ff & (scratch >> 16));
6183fd29009SGeyslan G. Bem }
6193fd29009SGeyslan G. Bem 
6201da177e4SLinus Torvalds #define DBG_SCHED_LIMIT 64
fill_periodic_buffer(struct debug_buffer * buf)621694cc208STony Jones static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
6221da177e4SLinus Torvalds {
6231da177e4SLinus Torvalds 	struct usb_hcd		*hcd;
6241da177e4SLinus Torvalds 	struct ehci_hcd		*ehci;
6251da177e4SLinus Torvalds 	unsigned long		flags;
6261da177e4SLinus Torvalds 	union ehci_shadow	p, *seen;
6271da177e4SLinus Torvalds 	unsigned		temp, size, seen_count;
6281da177e4SLinus Torvalds 	char			*next;
6291da177e4SLinus Torvalds 	unsigned		i;
6306dbd682bSStefan Roese 	__hc32			tag;
6311da177e4SLinus Torvalds 
632cb272521SGeyslan G. Bem 	seen = kmalloc_array(DBG_SCHED_LIMIT, sizeof(*seen), GFP_ATOMIC);
633911fdb6eSGreg Kroah-Hartman 	if (!seen)
6341da177e4SLinus Torvalds 		return 0;
6351da177e4SLinus Torvalds 	seen_count = 0;
6361da177e4SLinus Torvalds 
637694cc208STony Jones 	hcd = bus_to_hcd(buf->bus);
6381da177e4SLinus Torvalds 	ehci = hcd_to_ehci(hcd);
6393c04e20eSMing Lei 	next = buf->output_buf;
6403c04e20eSMing Lei 	size = buf->alloc_size;
6411da177e4SLinus Torvalds 
6421da177e4SLinus Torvalds 	temp = scnprintf(next, size, "size = %d\n", ehci->periodic_size);
6431da177e4SLinus Torvalds 	size -= temp;
6441da177e4SLinus Torvalds 	next += temp;
6451da177e4SLinus Torvalds 
6460784b4d5SGeyslan G. Bem 	/*
6470784b4d5SGeyslan G. Bem 	 * dump a snapshot of the periodic schedule.
6481da177e4SLinus Torvalds 	 * iso changes, interrupt usually doesn't.
6491da177e4SLinus Torvalds 	 */
6501da177e4SLinus Torvalds 	spin_lock_irqsave(&ehci->lock, flags);
6511da177e4SLinus Torvalds 	for (i = 0; i < ehci->periodic_size; i++) {
6521da177e4SLinus Torvalds 		p = ehci->pshadow[i];
6531da177e4SLinus Torvalds 		if (likely(!p.ptr))
6541da177e4SLinus Torvalds 			continue;
6556dbd682bSStefan Roese 		tag = Q_NEXT_TYPE(ehci, ehci->periodic[i]);
6561da177e4SLinus Torvalds 
6571da177e4SLinus Torvalds 		temp = scnprintf(next, size, "%4d: ", i);
6581da177e4SLinus Torvalds 		size -= temp;
6591da177e4SLinus Torvalds 		next += temp;
6601da177e4SLinus Torvalds 
6611da177e4SLinus Torvalds 		do {
6623807e26dSAlek Du 			struct ehci_qh_hw *hw;
6633807e26dSAlek Du 
6646dbd682bSStefan Roese 			switch (hc32_to_cpu(ehci, tag)) {
6651da177e4SLinus Torvalds 			case Q_TYPE_QH:
6663807e26dSAlek Du 				hw = p.qh->hw;
6671da177e4SLinus Torvalds 				temp = scnprintf(next, size, " qh%d-%04x/%p",
668ffa0248eSAlan Stern 						p.qh->ps.period,
6696dbd682bSStefan Roese 						hc32_to_cpup(ehci,
6703807e26dSAlek Du 							&hw->hw_info2)
6711da177e4SLinus Torvalds 							/* uframe masks */
6727dedacf4SDavid Brownell 							& (QH_CMASK | QH_SMASK),
6731da177e4SLinus Torvalds 						p.qh);
6741da177e4SLinus Torvalds 				size -= temp;
6751da177e4SLinus Torvalds 				next += temp;
6761da177e4SLinus Torvalds 				/* don't repeat what follows this qh */
6771da177e4SLinus Torvalds 				for (temp = 0; temp < seen_count; temp++) {
6781da177e4SLinus Torvalds 					if (seen[temp].ptr != p.ptr)
6791da177e4SLinus Torvalds 						continue;
6803c4bb71fSMing Lei 					if (p.qh->qh_next.ptr) {
6811da177e4SLinus Torvalds 						temp = scnprintf(next, size,
6821da177e4SLinus Torvalds 							" ...");
6833c4bb71fSMing Lei 						size -= temp;
6843c4bb71fSMing Lei 						next += temp;
6853c4bb71fSMing Lei 					}
6861da177e4SLinus Torvalds 					break;
6871da177e4SLinus Torvalds 				}
6881da177e4SLinus Torvalds 				/* show more info the first time around */
6893c4bb71fSMing Lei 				if (temp == seen_count) {
6903fd29009SGeyslan G. Bem 					temp = output_buf_tds_dir(next, ehci,
6913fd29009SGeyslan G. Bem 						hw, p.qh, size);
6921da177e4SLinus Torvalds 
6931da177e4SLinus Torvalds 					if (seen_count < DBG_SCHED_LIMIT)
6941da177e4SLinus Torvalds 						seen[seen_count++].qh = p.qh;
69504b8ad43SGeyslan G. Bem 				} else {
6961da177e4SLinus Torvalds 					temp = 0;
69704b8ad43SGeyslan G. Bem 				}
6983807e26dSAlek Du 				tag = Q_NEXT_TYPE(ehci, hw->hw_next);
6991da177e4SLinus Torvalds 				p = p.qh->qh_next;
7001da177e4SLinus Torvalds 				break;
7011da177e4SLinus Torvalds 			case Q_TYPE_FSTN:
7021da177e4SLinus Torvalds 				temp = scnprintf(next, size,
7031da177e4SLinus Torvalds 					" fstn-%8x/%p", p.fstn->hw_prev,
7041da177e4SLinus Torvalds 					p.fstn);
7056dbd682bSStefan Roese 				tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next);
7061da177e4SLinus Torvalds 				p = p.fstn->fstn_next;
7071da177e4SLinus Torvalds 				break;
7081da177e4SLinus Torvalds 			case Q_TYPE_ITD:
7091da177e4SLinus Torvalds 				temp = scnprintf(next, size,
7101da177e4SLinus Torvalds 					" itd/%p", p.itd);
7116dbd682bSStefan Roese 				tag = Q_NEXT_TYPE(ehci, p.itd->hw_next);
7121da177e4SLinus Torvalds 				p = p.itd->itd_next;
7131da177e4SLinus Torvalds 				break;
7141da177e4SLinus Torvalds 			case Q_TYPE_SITD:
7151da177e4SLinus Torvalds 				temp = scnprintf(next, size,
7161da177e4SLinus Torvalds 					" sitd%d-%04x/%p",
717ffa0248eSAlan Stern 					p.sitd->stream->ps.period,
7186dbd682bSStefan Roese 					hc32_to_cpup(ehci, &p.sitd->hw_uframe)
7191da177e4SLinus Torvalds 						& 0x0000ffff,
7201da177e4SLinus Torvalds 					p.sitd);
7216dbd682bSStefan Roese 				tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next);
7221da177e4SLinus Torvalds 				p = p.sitd->sitd_next;
7231da177e4SLinus Torvalds 				break;
7241da177e4SLinus Torvalds 			}
7251da177e4SLinus Torvalds 			size -= temp;
7261da177e4SLinus Torvalds 			next += temp;
7271da177e4SLinus Torvalds 		} while (p.ptr);
7281da177e4SLinus Torvalds 
7291da177e4SLinus Torvalds 		temp = scnprintf(next, size, "\n");
7301da177e4SLinus Torvalds 		size -= temp;
7311da177e4SLinus Torvalds 		next += temp;
7321da177e4SLinus Torvalds 	}
7331da177e4SLinus Torvalds 	spin_unlock_irqrestore(&ehci->lock, flags);
7341da177e4SLinus Torvalds 	kfree(seen);
7351da177e4SLinus Torvalds 
7363c04e20eSMing Lei 	return buf->alloc_size - size;
7371da177e4SLinus Torvalds }
7381da177e4SLinus Torvalds #undef DBG_SCHED_LIMIT
7391da177e4SLinus Torvalds 
rh_state_string(struct ehci_hcd * ehci)740e8799906SAlan Stern static const char *rh_state_string(struct ehci_hcd *ehci)
741e8799906SAlan Stern {
742e8799906SAlan Stern 	switch (ehci->rh_state) {
743e8799906SAlan Stern 	case EHCI_RH_HALTED:
744e8799906SAlan Stern 		return "halted";
745e8799906SAlan Stern 	case EHCI_RH_SUSPENDED:
746e8799906SAlan Stern 		return "suspended";
747e8799906SAlan Stern 	case EHCI_RH_RUNNING:
748e8799906SAlan Stern 		return "running";
749c0c53dbcSAlan Stern 	case EHCI_RH_STOPPING:
750c0c53dbcSAlan Stern 		return "stopping";
751e8799906SAlan Stern 	}
752e8799906SAlan Stern 	return "?";
753e8799906SAlan Stern }
754e8799906SAlan Stern 
fill_registers_buffer(struct debug_buffer * buf)755694cc208STony Jones static ssize_t fill_registers_buffer(struct debug_buffer *buf)
7561da177e4SLinus Torvalds {
7571da177e4SLinus Torvalds 	struct usb_hcd		*hcd;
7581da177e4SLinus Torvalds 	struct ehci_hcd		*ehci;
7591da177e4SLinus Torvalds 	unsigned long		flags;
7601da177e4SLinus Torvalds 	unsigned		temp, size, i;
7611da177e4SLinus Torvalds 	char			*next, scratch[80];
7621da177e4SLinus Torvalds 	static char		fmt[] = "%*s\n";
7631da177e4SLinus Torvalds 	static char		label[] = "";
7641da177e4SLinus Torvalds 
765694cc208STony Jones 	hcd = bus_to_hcd(buf->bus);
7661da177e4SLinus Torvalds 	ehci = hcd_to_ehci(hcd);
7673c04e20eSMing Lei 	next = buf->output_buf;
7683c04e20eSMing Lei 	size = buf->alloc_size;
7691da177e4SLinus Torvalds 
7701da177e4SLinus Torvalds 	spin_lock_irqsave(&ehci->lock, flags);
7711da177e4SLinus Torvalds 
772541c7d43SAlan Stern 	if (!HCD_HW_ACCESSIBLE(hcd)) {
7731da177e4SLinus Torvalds 		size = scnprintf(next, size,
7742b70f073SAlan Stern 			"bus %s, device %s\n"
775d49d4317SDavid Brownell 			"%s\n"
7761da177e4SLinus Torvalds 			"SUSPENDED (no register access)\n",
7771da177e4SLinus Torvalds 			hcd->self.controller->bus->name,
7787071a3ceSKay Sievers 			dev_name(hcd->self.controller),
779d49d4317SDavid Brownell 			hcd->product_desc);
7801da177e4SLinus Torvalds 		goto done;
7811da177e4SLinus Torvalds 	}
7821da177e4SLinus Torvalds 
7831da177e4SLinus Torvalds 	/* Capability Registers */
784c430131aSJan Andersson 	i = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
7851da177e4SLinus Torvalds 	temp = scnprintf(next, size,
7862b70f073SAlan Stern 		"bus %s, device %s\n"
787d49d4317SDavid Brownell 		"%s\n"
788e8799906SAlan Stern 		"EHCI %x.%02x, rh state %s\n",
7891da177e4SLinus Torvalds 		hcd->self.controller->bus->name,
7907071a3ceSKay Sievers 		dev_name(hcd->self.controller),
791d49d4317SDavid Brownell 		hcd->product_desc,
792e8799906SAlan Stern 		i >> 8, i & 0x0ff, rh_state_string(ehci));
7931da177e4SLinus Torvalds 	size -= temp;
7941da177e4SLinus Torvalds 	next += temp;
7951da177e4SLinus Torvalds 
7962c93e790Syuan linyu #ifdef	CONFIG_USB_PCI
797d49d4317SDavid Brownell 	/* EHCI 0.96 and later may have "extended capabilities" */
798e10e6f43SYijing Wang 	if (dev_is_pci(hcd->self.controller)) {
799d49d4317SDavid Brownell 		struct pci_dev	*pdev;
800d49d4317SDavid Brownell 		u32		offset, cap, cap2;
801d49d4317SDavid Brownell 		unsigned	count = 256 / 4;
802d49d4317SDavid Brownell 
803d49d4317SDavid Brownell 		pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
8046dbd682bSStefan Roese 		offset = HCC_EXT_CAPS(ehci_readl(ehci,
8056dbd682bSStefan Roese 				&ehci->caps->hcc_params));
806d49d4317SDavid Brownell 		while (offset && count--) {
807d49d4317SDavid Brownell 			pci_read_config_dword(pdev, offset, &cap);
808d49d4317SDavid Brownell 			switch (cap & 0xff) {
809d49d4317SDavid Brownell 			case 1:
810d49d4317SDavid Brownell 				temp = scnprintf(next, size,
811d49d4317SDavid Brownell 					"ownership %08x%s%s\n", cap,
812d49d4317SDavid Brownell 					(cap & (1 << 24)) ? " linux" : "",
813d49d4317SDavid Brownell 					(cap & (1 << 16)) ? " firmware" : "");
814d49d4317SDavid Brownell 				size -= temp;
815d49d4317SDavid Brownell 				next += temp;
816d49d4317SDavid Brownell 
817d49d4317SDavid Brownell 				offset += 4;
818d49d4317SDavid Brownell 				pci_read_config_dword(pdev, offset, &cap2);
819d49d4317SDavid Brownell 				temp = scnprintf(next, size,
820d49d4317SDavid Brownell 					"SMI sts/enable 0x%08x\n", cap2);
821d49d4317SDavid Brownell 				size -= temp;
822d49d4317SDavid Brownell 				next += temp;
823d49d4317SDavid Brownell 				break;
824d49d4317SDavid Brownell 			case 0:		/* illegal reserved capability */
825d49d4317SDavid Brownell 				cap = 0;
8268b84724eSGustavo A. R. Silva 				fallthrough;
827d49d4317SDavid Brownell 			default:		/* unknown */
828d49d4317SDavid Brownell 				break;
829d49d4317SDavid Brownell 			}
8301d5a3158SColin Ian King 			offset = (cap >> 8) & 0xff;
831d49d4317SDavid Brownell 		}
832d49d4317SDavid Brownell 	}
833d49d4317SDavid Brownell #endif
834d49d4317SDavid Brownell 
8350784b4d5SGeyslan G. Bem 	/* FIXME interpret both types of params */
836083522d7SBenjamin Herrenschmidt 	i = ehci_readl(ehci, &ehci->caps->hcs_params);
8371da177e4SLinus Torvalds 	temp = scnprintf(next, size, "structural params 0x%08x\n", i);
8381da177e4SLinus Torvalds 	size -= temp;
8391da177e4SLinus Torvalds 	next += temp;
8401da177e4SLinus Torvalds 
841083522d7SBenjamin Herrenschmidt 	i = ehci_readl(ehci, &ehci->caps->hcc_params);
8421da177e4SLinus Torvalds 	temp = scnprintf(next, size, "capability params 0x%08x\n", i);
8431da177e4SLinus Torvalds 	size -= temp;
8441da177e4SLinus Torvalds 	next += temp;
8451da177e4SLinus Torvalds 
8461da177e4SLinus Torvalds 	/* Operational Registers */
847668ab0dbSGeyslan G. Bem 	temp = dbg_status_buf(scratch, sizeof(scratch), label,
848083522d7SBenjamin Herrenschmidt 			ehci_readl(ehci, &ehci->regs->status));
8491da177e4SLinus Torvalds 	temp = scnprintf(next, size, fmt, temp, scratch);
8501da177e4SLinus Torvalds 	size -= temp;
8511da177e4SLinus Torvalds 	next += temp;
8521da177e4SLinus Torvalds 
853668ab0dbSGeyslan G. Bem 	temp = dbg_command_buf(scratch, sizeof(scratch), label,
854083522d7SBenjamin Herrenschmidt 			ehci_readl(ehci, &ehci->regs->command));
8551da177e4SLinus Torvalds 	temp = scnprintf(next, size, fmt, temp, scratch);
8561da177e4SLinus Torvalds 	size -= temp;
8571da177e4SLinus Torvalds 	next += temp;
8581da177e4SLinus Torvalds 
859668ab0dbSGeyslan G. Bem 	temp = dbg_intr_buf(scratch, sizeof(scratch), label,
860083522d7SBenjamin Herrenschmidt 			ehci_readl(ehci, &ehci->regs->intr_enable));
8611da177e4SLinus Torvalds 	temp = scnprintf(next, size, fmt, temp, scratch);
8621da177e4SLinus Torvalds 	size -= temp;
8631da177e4SLinus Torvalds 	next += temp;
8641da177e4SLinus Torvalds 
8651da177e4SLinus Torvalds 	temp = scnprintf(next, size, "uframe %04x\n",
86668aa95d5SAlan Stern 			ehci_read_frame_index(ehci));
8671da177e4SLinus Torvalds 	size -= temp;
8681da177e4SLinus Torvalds 	next += temp;
8691da177e4SLinus Torvalds 
870d49d4317SDavid Brownell 	for (i = 1; i <= HCS_N_PORTS(ehci->hcs_params); i++) {
871668ab0dbSGeyslan G. Bem 		temp = dbg_port_buf(scratch, sizeof(scratch), label, i,
8726dbd682bSStefan Roese 				ehci_readl(ehci,
8736dbd682bSStefan Roese 					&ehci->regs->port_status[i - 1]));
8741da177e4SLinus Torvalds 		temp = scnprintf(next, size, fmt, temp, scratch);
8751da177e4SLinus Torvalds 		size -= temp;
8761da177e4SLinus Torvalds 		next += temp;
877d49d4317SDavid Brownell 		if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) {
878d49d4317SDavid Brownell 			temp = scnprintf(next, size,
879d49d4317SDavid Brownell 					"    debug control %08x\n",
8806dbd682bSStefan Roese 					ehci_readl(ehci,
8816dbd682bSStefan Roese 						&ehci->debug->control));
882d49d4317SDavid Brownell 			size -= temp;
883d49d4317SDavid Brownell 			next += temp;
884d49d4317SDavid Brownell 		}
8851da177e4SLinus Torvalds 	}
8861da177e4SLinus Torvalds 
8876e018751SAlan Stern 	if (!list_empty(&ehci->async_unlink)) {
88899ac5b1eSAlan Stern 		temp = scnprintf(next, size, "async unlink qh %p\n",
8896e018751SAlan Stern 				list_first_entry(&ehci->async_unlink,
8906e018751SAlan Stern 						struct ehci_qh, unlink_node));
8911da177e4SLinus Torvalds 		size -= temp;
8921da177e4SLinus Torvalds 		next += temp;
8931da177e4SLinus Torvalds 	}
8941da177e4SLinus Torvalds 
8951da177e4SLinus Torvalds #ifdef EHCI_STATS
8961da177e4SLinus Torvalds 	temp = scnprintf(next, size,
89799ac5b1eSAlan Stern 		"irq normal %ld err %ld iaa %ld (lost %ld)\n",
89899ac5b1eSAlan Stern 		ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
8991da177e4SLinus Torvalds 		ehci->stats.lost_iaa);
9001da177e4SLinus Torvalds 	size -= temp;
9011da177e4SLinus Torvalds 	next += temp;
9021da177e4SLinus Torvalds 
9031da177e4SLinus Torvalds 	temp = scnprintf(next, size, "complete %ld unlink %ld\n",
9041da177e4SLinus Torvalds 		ehci->stats.complete, ehci->stats.unlink);
9051da177e4SLinus Torvalds 	size -= temp;
9061da177e4SLinus Torvalds 	next += temp;
9071da177e4SLinus Torvalds #endif
9081da177e4SLinus Torvalds 
9091da177e4SLinus Torvalds done:
9101da177e4SLinus Torvalds 	spin_unlock_irqrestore(&ehci->lock, flags);
9111da177e4SLinus Torvalds 
9123c04e20eSMing Lei 	return buf->alloc_size - size;
9131da177e4SLinus Torvalds }
914694cc208STony Jones 
alloc_buffer(struct usb_bus * bus,ssize_t (* fill_func)(struct debug_buffer *))915694cc208STony Jones static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
916694cc208STony Jones 		ssize_t (*fill_func)(struct debug_buffer *))
917694cc208STony Jones {
918694cc208STony Jones 	struct debug_buffer *buf;
919694cc208STony Jones 
92012ef7dd9SGeyslan G. Bem 	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
921694cc208STony Jones 
922694cc208STony Jones 	if (buf) {
923694cc208STony Jones 		buf->bus = bus;
924694cc208STony Jones 		buf->fill_func = fill_func;
925694cc208STony Jones 		mutex_init(&buf->mutex);
9263c04e20eSMing Lei 		buf->alloc_size = PAGE_SIZE;
927694cc208STony Jones 	}
928694cc208STony Jones 
929694cc208STony Jones 	return buf;
930694cc208STony Jones }
931694cc208STony Jones 
fill_buffer(struct debug_buffer * buf)932694cc208STony Jones static int fill_buffer(struct debug_buffer *buf)
933694cc208STony Jones {
934*6d705bf9SSergey Shtylyov 	int ret;
935694cc208STony Jones 
9363c04e20eSMing Lei 	if (!buf->output_buf)
93773f35c60SJesper Juhl 		buf->output_buf = vmalloc(buf->alloc_size);
938694cc208STony Jones 
9393c04e20eSMing Lei 	if (!buf->output_buf) {
940694cc208STony Jones 		ret = -ENOMEM;
941694cc208STony Jones 		goto out;
942694cc208STony Jones 	}
943694cc208STony Jones 
944694cc208STony Jones 	ret = buf->fill_func(buf);
945694cc208STony Jones 
946694cc208STony Jones 	if (ret >= 0) {
947694cc208STony Jones 		buf->count = ret;
948694cc208STony Jones 		ret = 0;
949694cc208STony Jones 	}
950694cc208STony Jones 
951694cc208STony Jones out:
952694cc208STony Jones 	return ret;
953694cc208STony Jones }
954694cc208STony Jones 
debug_output(struct file * file,char __user * user_buf,size_t len,loff_t * offset)955694cc208STony Jones static ssize_t debug_output(struct file *file, char __user *user_buf,
956694cc208STony Jones 		size_t len, loff_t *offset)
957694cc208STony Jones {
958694cc208STony Jones 	struct debug_buffer *buf = file->private_data;
959*6d705bf9SSergey Shtylyov 	int ret;
960694cc208STony Jones 
961694cc208STony Jones 	mutex_lock(&buf->mutex);
962694cc208STony Jones 	if (buf->count == 0) {
963694cc208STony Jones 		ret = fill_buffer(buf);
964694cc208STony Jones 		if (ret != 0) {
965694cc208STony Jones 			mutex_unlock(&buf->mutex);
966694cc208STony Jones 			goto out;
967694cc208STony Jones 		}
968694cc208STony Jones 	}
969694cc208STony Jones 	mutex_unlock(&buf->mutex);
970694cc208STony Jones 
971694cc208STony Jones 	ret = simple_read_from_buffer(user_buf, len, offset,
9723c04e20eSMing Lei 				      buf->output_buf, buf->count);
973694cc208STony Jones 
974694cc208STony Jones out:
975694cc208STony Jones 	return ret;
976694cc208STony Jones }
977694cc208STony Jones 
debug_close(struct inode * inode,struct file * file)978694cc208STony Jones static int debug_close(struct inode *inode, struct file *file)
979694cc208STony Jones {
980694cc208STony Jones 	struct debug_buffer *buf = file->private_data;
981694cc208STony Jones 
982694cc208STony Jones 	if (buf) {
9833c04e20eSMing Lei 		vfree(buf->output_buf);
984694cc208STony Jones 		kfree(buf);
985694cc208STony Jones 	}
986694cc208STony Jones 
987694cc208STony Jones 	return 0;
988694cc208STony Jones }
989d0ce5c6bSAlan Stern 
debug_async_open(struct inode * inode,struct file * file)990694cc208STony Jones static int debug_async_open(struct inode *inode, struct file *file)
991694cc208STony Jones {
992694cc208STony Jones 	file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
993694cc208STony Jones 
994694cc208STony Jones 	return file->private_data ? 0 : -ENOMEM;
995694cc208STony Jones }
996694cc208STony Jones 
debug_bandwidth_open(struct inode * inode,struct file * file)997d0ce5c6bSAlan Stern static int debug_bandwidth_open(struct inode *inode, struct file *file)
998d0ce5c6bSAlan Stern {
999d0ce5c6bSAlan Stern 	file->private_data = alloc_buffer(inode->i_private,
1000d0ce5c6bSAlan Stern 			fill_bandwidth_buffer);
1001d0ce5c6bSAlan Stern 
1002d0ce5c6bSAlan Stern 	return file->private_data ? 0 : -ENOMEM;
1003d0ce5c6bSAlan Stern }
1004d0ce5c6bSAlan Stern 
debug_periodic_open(struct inode * inode,struct file * file)1005694cc208STony Jones static int debug_periodic_open(struct inode *inode, struct file *file)
1006694cc208STony Jones {
10073c04e20eSMing Lei 	struct debug_buffer *buf;
10088d587d64SGeyslan G. Bem 
10093c04e20eSMing Lei 	buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
10103c04e20eSMing Lei 	if (!buf)
10113c04e20eSMing Lei 		return -ENOMEM;
1012694cc208STony Jones 
10133c04e20eSMing Lei 	buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8) * PAGE_SIZE;
10143c04e20eSMing Lei 	file->private_data = buf;
10153c04e20eSMing Lei 	return 0;
1016694cc208STony Jones }
1017694cc208STony Jones 
debug_registers_open(struct inode * inode,struct file * file)1018694cc208STony Jones static int debug_registers_open(struct inode *inode, struct file *file)
1019694cc208STony Jones {
1020694cc208STony Jones 	file->private_data = alloc_buffer(inode->i_private,
1021694cc208STony Jones 					  fill_registers_buffer);
1022694cc208STony Jones 
1023694cc208STony Jones 	return file->private_data ? 0 : -ENOMEM;
1024694cc208STony Jones }
10251da177e4SLinus Torvalds 
create_debug_files(struct ehci_hcd * ehci)10261da177e4SLinus Torvalds static inline void create_debug_files(struct ehci_hcd *ehci)
10271da177e4SLinus Torvalds {
1028694cc208STony Jones 	struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
10291da177e4SLinus Torvalds 
1030694cc208STony Jones 	ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
1031694cc208STony Jones 
1032b8fc7743SGreg Kroah-Hartman 	debugfs_create_file("async", S_IRUGO, ehci->debug_dir, bus,
1033b8fc7743SGreg Kroah-Hartman 			    &debug_async_fops);
1034b8fc7743SGreg Kroah-Hartman 	debugfs_create_file("bandwidth", S_IRUGO, ehci->debug_dir, bus,
1035b8fc7743SGreg Kroah-Hartman 			    &debug_bandwidth_fops);
1036b8fc7743SGreg Kroah-Hartman 	debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus,
1037b8fc7743SGreg Kroah-Hartman 			    &debug_periodic_fops);
1038b8fc7743SGreg Kroah-Hartman 	debugfs_create_file("registers", S_IRUGO, ehci->debug_dir, bus,
1039b8fc7743SGreg Kroah-Hartman 			    &debug_registers_fops);
10401da177e4SLinus Torvalds }
10411da177e4SLinus Torvalds 
remove_debug_files(struct ehci_hcd * ehci)10421da177e4SLinus Torvalds static inline void remove_debug_files(struct ehci_hcd *ehci)
10431da177e4SLinus Torvalds {
1044185c9bcfSMing Lei 	debugfs_remove_recursive(ehci->debug_dir);
10451da177e4SLinus Torvalds }
10461da177e4SLinus Torvalds 
1047128f8b3dSAlan Stern #else /* CONFIG_DYNAMIC_DEBUG */
1048128f8b3dSAlan Stern 
dbg_hcs_params(struct ehci_hcd * ehci,char * label)1049128f8b3dSAlan Stern static inline void dbg_hcs_params(struct ehci_hcd *ehci, char *label) { }
dbg_hcc_params(struct ehci_hcd * ehci,char * label)1050128f8b3dSAlan Stern static inline void dbg_hcc_params(struct ehci_hcd *ehci, char *label) { }
1051128f8b3dSAlan Stern 
dbg_qh(const char * label,struct ehci_hcd * ehci,struct ehci_qh * qh)1052128f8b3dSAlan Stern static inline void __maybe_unused dbg_qh(const char *label,
1053128f8b3dSAlan Stern 		struct ehci_hcd *ehci, struct ehci_qh *qh) { }
1054128f8b3dSAlan Stern 
dbg_status_buf(const char * buf,unsigned int len,const char * label,u32 status)1055128f8b3dSAlan Stern static inline int __maybe_unused dbg_status_buf(const char *buf,
1056128f8b3dSAlan Stern 		unsigned int len, const char *label, u32 status)
1057128f8b3dSAlan Stern { return 0; }
1058128f8b3dSAlan Stern 
dbg_command_buf(const char * buf,unsigned int len,const char * label,u32 command)1059128f8b3dSAlan Stern static inline int __maybe_unused dbg_command_buf(const char *buf,
1060128f8b3dSAlan Stern 		unsigned int len, const char *label, u32 command)
1061128f8b3dSAlan Stern { return 0; }
1062128f8b3dSAlan Stern 
dbg_intr_buf(const char * buf,unsigned int len,const char * label,u32 enable)1063128f8b3dSAlan Stern static inline int __maybe_unused dbg_intr_buf(const char *buf,
1064128f8b3dSAlan Stern 		unsigned int len, const char *label, u32 enable)
1065128f8b3dSAlan Stern { return 0; }
1066128f8b3dSAlan Stern 
dbg_port_buf(char * buf,unsigned int len,const char * label,int port,u32 status)1067128f8b3dSAlan Stern static inline int __maybe_unused dbg_port_buf(char *buf,
1068128f8b3dSAlan Stern 		unsigned int len, const char *label, int port, u32 status)
1069128f8b3dSAlan Stern { return 0; }
1070128f8b3dSAlan Stern 
dbg_status(struct ehci_hcd * ehci,const char * label,u32 status)1071128f8b3dSAlan Stern static inline void dbg_status(struct ehci_hcd *ehci, const char *label,
1072128f8b3dSAlan Stern 		u32 status) { }
dbg_cmd(struct ehci_hcd * ehci,const char * label,u32 command)1073128f8b3dSAlan Stern static inline void dbg_cmd(struct ehci_hcd *ehci, const char *label,
1074128f8b3dSAlan Stern 		u32 command) { }
dbg_port(struct ehci_hcd * ehci,const char * label,int port,u32 status)1075128f8b3dSAlan Stern static inline void dbg_port(struct ehci_hcd *ehci, const char *label,
1076128f8b3dSAlan Stern 		int port, u32 status) { }
1077128f8b3dSAlan Stern 
create_debug_files(struct ehci_hcd * bus)1078128f8b3dSAlan Stern static inline void create_debug_files(struct ehci_hcd *bus) { }
remove_debug_files(struct ehci_hcd * bus)1079128f8b3dSAlan Stern static inline void remove_debug_files(struct ehci_hcd *bus) { }
1080128f8b3dSAlan Stern 
108193df42baSGeyslan G. Bem #endif /* CONFIG_DYNAMIC_DEBUG */
1082