1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-1.0+
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * OHCI HCD (Host Controller Driver) for USB.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
6*4882a593Smuzhiyun * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * This file is licenced under the GPL.
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #define edstring(ed_type) ({ char *temp; \
14*4882a593Smuzhiyun switch (ed_type) { \
15*4882a593Smuzhiyun case PIPE_CONTROL: temp = "ctrl"; break; \
16*4882a593Smuzhiyun case PIPE_BULK: temp = "bulk"; break; \
17*4882a593Smuzhiyun case PIPE_INTERRUPT: temp = "intr"; break; \
18*4882a593Smuzhiyun default: temp = "isoc"; break; \
19*4882a593Smuzhiyun } temp;})
20*4882a593Smuzhiyun #define pipestring(pipe) edstring(usb_pipetype(pipe))
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #define ohci_dbg_sw(ohci, next, size, format, arg...) \
24*4882a593Smuzhiyun do { \
25*4882a593Smuzhiyun if (next != NULL) { \
26*4882a593Smuzhiyun unsigned s_len; \
27*4882a593Smuzhiyun s_len = scnprintf (*next, *size, format, ## arg ); \
28*4882a593Smuzhiyun *size -= s_len; *next += s_len; \
29*4882a593Smuzhiyun } else \
30*4882a593Smuzhiyun ohci_dbg(ohci,format, ## arg ); \
31*4882a593Smuzhiyun } while (0);
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun /* Version for use where "next" is the address of a local variable */
34*4882a593Smuzhiyun #define ohci_dbg_nosw(ohci, next, size, format, arg...) \
35*4882a593Smuzhiyun do { \
36*4882a593Smuzhiyun unsigned s_len; \
37*4882a593Smuzhiyun s_len = scnprintf(*next, *size, format, ## arg); \
38*4882a593Smuzhiyun *size -= s_len; *next += s_len; \
39*4882a593Smuzhiyun } while (0);
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun
ohci_dump_intr_mask(struct ohci_hcd * ohci,char * label,u32 mask,char ** next,unsigned * size)42*4882a593Smuzhiyun static void ohci_dump_intr_mask (
43*4882a593Smuzhiyun struct ohci_hcd *ohci,
44*4882a593Smuzhiyun char *label,
45*4882a593Smuzhiyun u32 mask,
46*4882a593Smuzhiyun char **next,
47*4882a593Smuzhiyun unsigned *size)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun ohci_dbg_sw (ohci, next, size, "%s 0x%08x%s%s%s%s%s%s%s%s%s\n",
50*4882a593Smuzhiyun label,
51*4882a593Smuzhiyun mask,
52*4882a593Smuzhiyun (mask & OHCI_INTR_MIE) ? " MIE" : "",
53*4882a593Smuzhiyun (mask & OHCI_INTR_OC) ? " OC" : "",
54*4882a593Smuzhiyun (mask & OHCI_INTR_RHSC) ? " RHSC" : "",
55*4882a593Smuzhiyun (mask & OHCI_INTR_FNO) ? " FNO" : "",
56*4882a593Smuzhiyun (mask & OHCI_INTR_UE) ? " UE" : "",
57*4882a593Smuzhiyun (mask & OHCI_INTR_RD) ? " RD" : "",
58*4882a593Smuzhiyun (mask & OHCI_INTR_SF) ? " SF" : "",
59*4882a593Smuzhiyun (mask & OHCI_INTR_WDH) ? " WDH" : "",
60*4882a593Smuzhiyun (mask & OHCI_INTR_SO) ? " SO" : ""
61*4882a593Smuzhiyun );
62*4882a593Smuzhiyun }
63*4882a593Smuzhiyun
maybe_print_eds(struct ohci_hcd * ohci,char * label,u32 value,char ** next,unsigned * size)64*4882a593Smuzhiyun static void maybe_print_eds (
65*4882a593Smuzhiyun struct ohci_hcd *ohci,
66*4882a593Smuzhiyun char *label,
67*4882a593Smuzhiyun u32 value,
68*4882a593Smuzhiyun char **next,
69*4882a593Smuzhiyun unsigned *size)
70*4882a593Smuzhiyun {
71*4882a593Smuzhiyun if (value)
72*4882a593Smuzhiyun ohci_dbg_sw (ohci, next, size, "%s %08x\n", label, value);
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun
hcfs2string(int state)75*4882a593Smuzhiyun static char *hcfs2string (int state)
76*4882a593Smuzhiyun {
77*4882a593Smuzhiyun switch (state) {
78*4882a593Smuzhiyun case OHCI_USB_RESET: return "reset";
79*4882a593Smuzhiyun case OHCI_USB_RESUME: return "resume";
80*4882a593Smuzhiyun case OHCI_USB_OPER: return "operational";
81*4882a593Smuzhiyun case OHCI_USB_SUSPEND: return "suspend";
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun return "?";
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun
rh_state_string(struct ohci_hcd * ohci)86*4882a593Smuzhiyun static const char *rh_state_string(struct ohci_hcd *ohci)
87*4882a593Smuzhiyun {
88*4882a593Smuzhiyun switch (ohci->rh_state) {
89*4882a593Smuzhiyun case OHCI_RH_HALTED:
90*4882a593Smuzhiyun return "halted";
91*4882a593Smuzhiyun case OHCI_RH_SUSPENDED:
92*4882a593Smuzhiyun return "suspended";
93*4882a593Smuzhiyun case OHCI_RH_RUNNING:
94*4882a593Smuzhiyun return "running";
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun return "?";
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun // dump control and status registers
100*4882a593Smuzhiyun static void
ohci_dump_status(struct ohci_hcd * controller,char ** next,unsigned * size)101*4882a593Smuzhiyun ohci_dump_status (struct ohci_hcd *controller, char **next, unsigned *size)
102*4882a593Smuzhiyun {
103*4882a593Smuzhiyun struct ohci_regs __iomem *regs = controller->regs;
104*4882a593Smuzhiyun u32 temp;
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun temp = ohci_readl (controller, ®s->revision) & 0xff;
107*4882a593Smuzhiyun ohci_dbg_sw (controller, next, size,
108*4882a593Smuzhiyun "OHCI %d.%d, %s legacy support registers, rh state %s\n",
109*4882a593Smuzhiyun 0x03 & (temp >> 4), (temp & 0x0f),
110*4882a593Smuzhiyun (temp & 0x0100) ? "with" : "NO",
111*4882a593Smuzhiyun rh_state_string(controller));
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun temp = ohci_readl (controller, ®s->control);
114*4882a593Smuzhiyun ohci_dbg_sw (controller, next, size,
115*4882a593Smuzhiyun "control 0x%03x%s%s%s HCFS=%s%s%s%s%s CBSR=%d\n",
116*4882a593Smuzhiyun temp,
117*4882a593Smuzhiyun (temp & OHCI_CTRL_RWE) ? " RWE" : "",
118*4882a593Smuzhiyun (temp & OHCI_CTRL_RWC) ? " RWC" : "",
119*4882a593Smuzhiyun (temp & OHCI_CTRL_IR) ? " IR" : "",
120*4882a593Smuzhiyun hcfs2string (temp & OHCI_CTRL_HCFS),
121*4882a593Smuzhiyun (temp & OHCI_CTRL_BLE) ? " BLE" : "",
122*4882a593Smuzhiyun (temp & OHCI_CTRL_CLE) ? " CLE" : "",
123*4882a593Smuzhiyun (temp & OHCI_CTRL_IE) ? " IE" : "",
124*4882a593Smuzhiyun (temp & OHCI_CTRL_PLE) ? " PLE" : "",
125*4882a593Smuzhiyun temp & OHCI_CTRL_CBSR
126*4882a593Smuzhiyun );
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun temp = ohci_readl (controller, ®s->cmdstatus);
129*4882a593Smuzhiyun ohci_dbg_sw (controller, next, size,
130*4882a593Smuzhiyun "cmdstatus 0x%05x SOC=%d%s%s%s%s\n", temp,
131*4882a593Smuzhiyun (temp & OHCI_SOC) >> 16,
132*4882a593Smuzhiyun (temp & OHCI_OCR) ? " OCR" : "",
133*4882a593Smuzhiyun (temp & OHCI_BLF) ? " BLF" : "",
134*4882a593Smuzhiyun (temp & OHCI_CLF) ? " CLF" : "",
135*4882a593Smuzhiyun (temp & OHCI_HCR) ? " HCR" : ""
136*4882a593Smuzhiyun );
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun ohci_dump_intr_mask (controller, "intrstatus",
139*4882a593Smuzhiyun ohci_readl (controller, ®s->intrstatus),
140*4882a593Smuzhiyun next, size);
141*4882a593Smuzhiyun ohci_dump_intr_mask (controller, "intrenable",
142*4882a593Smuzhiyun ohci_readl (controller, ®s->intrenable),
143*4882a593Smuzhiyun next, size);
144*4882a593Smuzhiyun // intrdisable always same as intrenable
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun maybe_print_eds (controller, "ed_periodcurrent",
147*4882a593Smuzhiyun ohci_readl (controller, ®s->ed_periodcurrent),
148*4882a593Smuzhiyun next, size);
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun maybe_print_eds (controller, "ed_controlhead",
151*4882a593Smuzhiyun ohci_readl (controller, ®s->ed_controlhead),
152*4882a593Smuzhiyun next, size);
153*4882a593Smuzhiyun maybe_print_eds (controller, "ed_controlcurrent",
154*4882a593Smuzhiyun ohci_readl (controller, ®s->ed_controlcurrent),
155*4882a593Smuzhiyun next, size);
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun maybe_print_eds (controller, "ed_bulkhead",
158*4882a593Smuzhiyun ohci_readl (controller, ®s->ed_bulkhead),
159*4882a593Smuzhiyun next, size);
160*4882a593Smuzhiyun maybe_print_eds (controller, "ed_bulkcurrent",
161*4882a593Smuzhiyun ohci_readl (controller, ®s->ed_bulkcurrent),
162*4882a593Smuzhiyun next, size);
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun maybe_print_eds (controller, "donehead",
165*4882a593Smuzhiyun ohci_readl (controller, ®s->donehead), next, size);
166*4882a593Smuzhiyun }
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun #define dbg_port_sw(hc,num,value,next,size) \
169*4882a593Smuzhiyun ohci_dbg_sw (hc, next, size, \
170*4882a593Smuzhiyun "roothub.portstatus [%d] " \
171*4882a593Smuzhiyun "0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
172*4882a593Smuzhiyun num, temp, \
173*4882a593Smuzhiyun (temp & RH_PS_PRSC) ? " PRSC" : "", \
174*4882a593Smuzhiyun (temp & RH_PS_OCIC) ? " OCIC" : "", \
175*4882a593Smuzhiyun (temp & RH_PS_PSSC) ? " PSSC" : "", \
176*4882a593Smuzhiyun (temp & RH_PS_PESC) ? " PESC" : "", \
177*4882a593Smuzhiyun (temp & RH_PS_CSC) ? " CSC" : "", \
178*4882a593Smuzhiyun \
179*4882a593Smuzhiyun (temp & RH_PS_LSDA) ? " LSDA" : "", \
180*4882a593Smuzhiyun (temp & RH_PS_PPS) ? " PPS" : "", \
181*4882a593Smuzhiyun (temp & RH_PS_PRS) ? " PRS" : "", \
182*4882a593Smuzhiyun (temp & RH_PS_POCI) ? " POCI" : "", \
183*4882a593Smuzhiyun (temp & RH_PS_PSS) ? " PSS" : "", \
184*4882a593Smuzhiyun \
185*4882a593Smuzhiyun (temp & RH_PS_PES) ? " PES" : "", \
186*4882a593Smuzhiyun (temp & RH_PS_CCS) ? " CCS" : "" \
187*4882a593Smuzhiyun );
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun static void
ohci_dump_roothub(struct ohci_hcd * controller,int verbose,char ** next,unsigned * size)191*4882a593Smuzhiyun ohci_dump_roothub (
192*4882a593Smuzhiyun struct ohci_hcd *controller,
193*4882a593Smuzhiyun int verbose,
194*4882a593Smuzhiyun char **next,
195*4882a593Smuzhiyun unsigned *size)
196*4882a593Smuzhiyun {
197*4882a593Smuzhiyun u32 temp, i;
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun temp = roothub_a (controller);
200*4882a593Smuzhiyun if (temp == ~(u32)0)
201*4882a593Smuzhiyun return;
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun if (verbose) {
204*4882a593Smuzhiyun ohci_dbg_sw (controller, next, size,
205*4882a593Smuzhiyun "roothub.a %08x POTPGT=%d%s%s%s%s%s NDP=%d(%d)\n", temp,
206*4882a593Smuzhiyun ((temp & RH_A_POTPGT) >> 24) & 0xff,
207*4882a593Smuzhiyun (temp & RH_A_NOCP) ? " NOCP" : "",
208*4882a593Smuzhiyun (temp & RH_A_OCPM) ? " OCPM" : "",
209*4882a593Smuzhiyun (temp & RH_A_DT) ? " DT" : "",
210*4882a593Smuzhiyun (temp & RH_A_NPS) ? " NPS" : "",
211*4882a593Smuzhiyun (temp & RH_A_PSM) ? " PSM" : "",
212*4882a593Smuzhiyun (temp & RH_A_NDP), controller->num_ports
213*4882a593Smuzhiyun );
214*4882a593Smuzhiyun temp = roothub_b (controller);
215*4882a593Smuzhiyun ohci_dbg_sw (controller, next, size,
216*4882a593Smuzhiyun "roothub.b %08x PPCM=%04x DR=%04x\n",
217*4882a593Smuzhiyun temp,
218*4882a593Smuzhiyun (temp & RH_B_PPCM) >> 16,
219*4882a593Smuzhiyun (temp & RH_B_DR)
220*4882a593Smuzhiyun );
221*4882a593Smuzhiyun temp = roothub_status (controller);
222*4882a593Smuzhiyun ohci_dbg_sw (controller, next, size,
223*4882a593Smuzhiyun "roothub.status %08x%s%s%s%s%s%s\n",
224*4882a593Smuzhiyun temp,
225*4882a593Smuzhiyun (temp & RH_HS_CRWE) ? " CRWE" : "",
226*4882a593Smuzhiyun (temp & RH_HS_OCIC) ? " OCIC" : "",
227*4882a593Smuzhiyun (temp & RH_HS_LPSC) ? " LPSC" : "",
228*4882a593Smuzhiyun (temp & RH_HS_DRWE) ? " DRWE" : "",
229*4882a593Smuzhiyun (temp & RH_HS_OCI) ? " OCI" : "",
230*4882a593Smuzhiyun (temp & RH_HS_LPS) ? " LPS" : ""
231*4882a593Smuzhiyun );
232*4882a593Smuzhiyun }
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun for (i = 0; i < controller->num_ports; i++) {
235*4882a593Smuzhiyun temp = roothub_portstatus (controller, i);
236*4882a593Smuzhiyun dbg_port_sw (controller, i, temp, next, size);
237*4882a593Smuzhiyun }
238*4882a593Smuzhiyun }
239*4882a593Smuzhiyun
ohci_dump(struct ohci_hcd * controller)240*4882a593Smuzhiyun static void ohci_dump(struct ohci_hcd *controller)
241*4882a593Smuzhiyun {
242*4882a593Smuzhiyun ohci_dbg (controller, "OHCI controller state\n");
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun // dumps some of the state we know about
245*4882a593Smuzhiyun ohci_dump_status (controller, NULL, NULL);
246*4882a593Smuzhiyun if (controller->hcca)
247*4882a593Smuzhiyun ohci_dbg (controller,
248*4882a593Smuzhiyun "hcca frame #%04x\n", ohci_frame_no(controller));
249*4882a593Smuzhiyun ohci_dump_roothub (controller, 1, NULL, NULL);
250*4882a593Smuzhiyun }
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun static const char data0 [] = "DATA0";
253*4882a593Smuzhiyun static const char data1 [] = "DATA1";
254*4882a593Smuzhiyun
ohci_dump_td(const struct ohci_hcd * ohci,const char * label,const struct td * td)255*4882a593Smuzhiyun static void ohci_dump_td (const struct ohci_hcd *ohci, const char *label,
256*4882a593Smuzhiyun const struct td *td)
257*4882a593Smuzhiyun {
258*4882a593Smuzhiyun u32 tmp = hc32_to_cpup (ohci, &td->hwINFO);
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun ohci_dbg (ohci, "%s td %p%s; urb %p index %d; hw next td %08x\n",
261*4882a593Smuzhiyun label, td,
262*4882a593Smuzhiyun (tmp & TD_DONE) ? " (DONE)" : "",
263*4882a593Smuzhiyun td->urb, td->index,
264*4882a593Smuzhiyun hc32_to_cpup (ohci, &td->hwNextTD));
265*4882a593Smuzhiyun if ((tmp & TD_ISO) == 0) {
266*4882a593Smuzhiyun const char *toggle, *pid;
267*4882a593Smuzhiyun u32 cbp, be;
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun switch (tmp & TD_T) {
270*4882a593Smuzhiyun case TD_T_DATA0: toggle = data0; break;
271*4882a593Smuzhiyun case TD_T_DATA1: toggle = data1; break;
272*4882a593Smuzhiyun case TD_T_TOGGLE: toggle = "(CARRY)"; break;
273*4882a593Smuzhiyun default: toggle = "(?)"; break;
274*4882a593Smuzhiyun }
275*4882a593Smuzhiyun switch (tmp & TD_DP) {
276*4882a593Smuzhiyun case TD_DP_SETUP: pid = "SETUP"; break;
277*4882a593Smuzhiyun case TD_DP_IN: pid = "IN"; break;
278*4882a593Smuzhiyun case TD_DP_OUT: pid = "OUT"; break;
279*4882a593Smuzhiyun default: pid = "(bad pid)"; break;
280*4882a593Smuzhiyun }
281*4882a593Smuzhiyun ohci_dbg (ohci, " info %08x CC=%x %s DI=%d %s %s\n", tmp,
282*4882a593Smuzhiyun TD_CC_GET(tmp), /* EC, */ toggle,
283*4882a593Smuzhiyun (tmp & TD_DI) >> 21, pid,
284*4882a593Smuzhiyun (tmp & TD_R) ? "R" : "");
285*4882a593Smuzhiyun cbp = hc32_to_cpup (ohci, &td->hwCBP);
286*4882a593Smuzhiyun be = hc32_to_cpup (ohci, &td->hwBE);
287*4882a593Smuzhiyun ohci_dbg (ohci, " cbp %08x be %08x (len %d)\n", cbp, be,
288*4882a593Smuzhiyun cbp ? (be + 1 - cbp) : 0);
289*4882a593Smuzhiyun } else {
290*4882a593Smuzhiyun unsigned i;
291*4882a593Smuzhiyun ohci_dbg (ohci, " info %08x CC=%x FC=%d DI=%d SF=%04x\n", tmp,
292*4882a593Smuzhiyun TD_CC_GET(tmp),
293*4882a593Smuzhiyun (tmp >> 24) & 0x07,
294*4882a593Smuzhiyun (tmp & TD_DI) >> 21,
295*4882a593Smuzhiyun tmp & 0x0000ffff);
296*4882a593Smuzhiyun ohci_dbg (ohci, " bp0 %08x be %08x\n",
297*4882a593Smuzhiyun hc32_to_cpup (ohci, &td->hwCBP) & ~0x0fff,
298*4882a593Smuzhiyun hc32_to_cpup (ohci, &td->hwBE));
299*4882a593Smuzhiyun for (i = 0; i < MAXPSW; i++) {
300*4882a593Smuzhiyun u16 psw = ohci_hwPSW (ohci, td, i);
301*4882a593Smuzhiyun int cc = (psw >> 12) & 0x0f;
302*4882a593Smuzhiyun ohci_dbg (ohci, " psw [%d] = %2x, CC=%x %s=%d\n", i,
303*4882a593Smuzhiyun psw, cc,
304*4882a593Smuzhiyun (cc >= 0x0e) ? "OFFSET" : "SIZE",
305*4882a593Smuzhiyun psw & 0x0fff);
306*4882a593Smuzhiyun }
307*4882a593Smuzhiyun }
308*4882a593Smuzhiyun }
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun /* caller MUST own hcd spinlock if verbose is set! */
311*4882a593Smuzhiyun static void __maybe_unused
ohci_dump_ed(const struct ohci_hcd * ohci,const char * label,const struct ed * ed,int verbose)312*4882a593Smuzhiyun ohci_dump_ed (const struct ohci_hcd *ohci, const char *label,
313*4882a593Smuzhiyun const struct ed *ed, int verbose)
314*4882a593Smuzhiyun {
315*4882a593Smuzhiyun u32 tmp = hc32_to_cpu (ohci, ed->hwINFO);
316*4882a593Smuzhiyun char *type = "";
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun ohci_dbg (ohci, "%s, ed %p state 0x%x type %s; next ed %08x\n",
319*4882a593Smuzhiyun label,
320*4882a593Smuzhiyun ed, ed->state, edstring (ed->type),
321*4882a593Smuzhiyun hc32_to_cpup (ohci, &ed->hwNextED));
322*4882a593Smuzhiyun switch (tmp & (ED_IN|ED_OUT)) {
323*4882a593Smuzhiyun case ED_OUT: type = "-OUT"; break;
324*4882a593Smuzhiyun case ED_IN: type = "-IN"; break;
325*4882a593Smuzhiyun /* else from TDs ... control */
326*4882a593Smuzhiyun }
327*4882a593Smuzhiyun ohci_dbg (ohci,
328*4882a593Smuzhiyun " info %08x MAX=%d%s%s%s%s EP=%d%s DEV=%d\n", tmp,
329*4882a593Smuzhiyun 0x03ff & (tmp >> 16),
330*4882a593Smuzhiyun (tmp & ED_DEQUEUE) ? " DQ" : "",
331*4882a593Smuzhiyun (tmp & ED_ISO) ? " ISO" : "",
332*4882a593Smuzhiyun (tmp & ED_SKIP) ? " SKIP" : "",
333*4882a593Smuzhiyun (tmp & ED_LOWSPEED) ? " LOW" : "",
334*4882a593Smuzhiyun 0x000f & (tmp >> 7),
335*4882a593Smuzhiyun type,
336*4882a593Smuzhiyun 0x007f & tmp);
337*4882a593Smuzhiyun tmp = hc32_to_cpup (ohci, &ed->hwHeadP);
338*4882a593Smuzhiyun ohci_dbg (ohci, " tds: head %08x %s%s tail %08x%s\n",
339*4882a593Smuzhiyun tmp,
340*4882a593Smuzhiyun (tmp & ED_C) ? data1 : data0,
341*4882a593Smuzhiyun (tmp & ED_H) ? " HALT" : "",
342*4882a593Smuzhiyun hc32_to_cpup (ohci, &ed->hwTailP),
343*4882a593Smuzhiyun verbose ? "" : " (not listing)");
344*4882a593Smuzhiyun if (verbose) {
345*4882a593Smuzhiyun struct list_head *tmp;
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun /* use ed->td_list because HC concurrently modifies
348*4882a593Smuzhiyun * hwNextTD as it accumulates ed_donelist.
349*4882a593Smuzhiyun */
350*4882a593Smuzhiyun list_for_each (tmp, &ed->td_list) {
351*4882a593Smuzhiyun struct td *td;
352*4882a593Smuzhiyun td = list_entry (tmp, struct td, td_list);
353*4882a593Smuzhiyun ohci_dump_td (ohci, " ->", td);
354*4882a593Smuzhiyun }
355*4882a593Smuzhiyun }
356*4882a593Smuzhiyun }
357*4882a593Smuzhiyun
358*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
359*4882a593Smuzhiyun
360*4882a593Smuzhiyun static int debug_async_open(struct inode *, struct file *);
361*4882a593Smuzhiyun static int debug_periodic_open(struct inode *, struct file *);
362*4882a593Smuzhiyun static int debug_registers_open(struct inode *, struct file *);
363*4882a593Smuzhiyun static int debug_async_open(struct inode *, struct file *);
364*4882a593Smuzhiyun static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
365*4882a593Smuzhiyun static int debug_close(struct inode *, struct file *);
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun static const struct file_operations debug_async_fops = {
368*4882a593Smuzhiyun .owner = THIS_MODULE,
369*4882a593Smuzhiyun .open = debug_async_open,
370*4882a593Smuzhiyun .read = debug_output,
371*4882a593Smuzhiyun .release = debug_close,
372*4882a593Smuzhiyun .llseek = default_llseek,
373*4882a593Smuzhiyun };
374*4882a593Smuzhiyun static const struct file_operations debug_periodic_fops = {
375*4882a593Smuzhiyun .owner = THIS_MODULE,
376*4882a593Smuzhiyun .open = debug_periodic_open,
377*4882a593Smuzhiyun .read = debug_output,
378*4882a593Smuzhiyun .release = debug_close,
379*4882a593Smuzhiyun .llseek = default_llseek,
380*4882a593Smuzhiyun };
381*4882a593Smuzhiyun static const struct file_operations debug_registers_fops = {
382*4882a593Smuzhiyun .owner = THIS_MODULE,
383*4882a593Smuzhiyun .open = debug_registers_open,
384*4882a593Smuzhiyun .read = debug_output,
385*4882a593Smuzhiyun .release = debug_close,
386*4882a593Smuzhiyun .llseek = default_llseek,
387*4882a593Smuzhiyun };
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun static struct dentry *ohci_debug_root;
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun struct debug_buffer {
392*4882a593Smuzhiyun ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
393*4882a593Smuzhiyun struct ohci_hcd *ohci;
394*4882a593Smuzhiyun struct mutex mutex; /* protect filling of buffer */
395*4882a593Smuzhiyun size_t count; /* number of characters filled into buffer */
396*4882a593Smuzhiyun char *page;
397*4882a593Smuzhiyun };
398*4882a593Smuzhiyun
399*4882a593Smuzhiyun static ssize_t
show_list(struct ohci_hcd * ohci,char * buf,size_t count,struct ed * ed)400*4882a593Smuzhiyun show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
401*4882a593Smuzhiyun {
402*4882a593Smuzhiyun unsigned temp, size = count;
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun if (!ed)
405*4882a593Smuzhiyun return 0;
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun /* print first --> last */
408*4882a593Smuzhiyun while (ed->ed_prev)
409*4882a593Smuzhiyun ed = ed->ed_prev;
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun /* dump a snapshot of the bulk or control schedule */
412*4882a593Smuzhiyun while (ed) {
413*4882a593Smuzhiyun u32 info = hc32_to_cpu (ohci, ed->hwINFO);
414*4882a593Smuzhiyun u32 headp = hc32_to_cpu (ohci, ed->hwHeadP);
415*4882a593Smuzhiyun struct list_head *entry;
416*4882a593Smuzhiyun struct td *td;
417*4882a593Smuzhiyun
418*4882a593Smuzhiyun temp = scnprintf (buf, size,
419*4882a593Smuzhiyun "ed/%p %cs dev%d ep%d%s max %d %08x%s%s %s",
420*4882a593Smuzhiyun ed,
421*4882a593Smuzhiyun (info & ED_LOWSPEED) ? 'l' : 'f',
422*4882a593Smuzhiyun info & 0x7f,
423*4882a593Smuzhiyun (info >> 7) & 0xf,
424*4882a593Smuzhiyun (info & ED_IN) ? "in" : "out",
425*4882a593Smuzhiyun 0x03ff & (info >> 16),
426*4882a593Smuzhiyun info,
427*4882a593Smuzhiyun (info & ED_SKIP) ? " s" : "",
428*4882a593Smuzhiyun (headp & ED_H) ? " H" : "",
429*4882a593Smuzhiyun (headp & ED_C) ? data1 : data0);
430*4882a593Smuzhiyun size -= temp;
431*4882a593Smuzhiyun buf += temp;
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun list_for_each (entry, &ed->td_list) {
434*4882a593Smuzhiyun u32 cbp, be;
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun td = list_entry (entry, struct td, td_list);
437*4882a593Smuzhiyun info = hc32_to_cpup (ohci, &td->hwINFO);
438*4882a593Smuzhiyun cbp = hc32_to_cpup (ohci, &td->hwCBP);
439*4882a593Smuzhiyun be = hc32_to_cpup (ohci, &td->hwBE);
440*4882a593Smuzhiyun temp = scnprintf (buf, size,
441*4882a593Smuzhiyun "\n\ttd %p %s %d cc=%x urb %p (%08x)",
442*4882a593Smuzhiyun td,
443*4882a593Smuzhiyun ({ char *pid;
444*4882a593Smuzhiyun switch (info & TD_DP) {
445*4882a593Smuzhiyun case TD_DP_SETUP: pid = "setup"; break;
446*4882a593Smuzhiyun case TD_DP_IN: pid = "in"; break;
447*4882a593Smuzhiyun case TD_DP_OUT: pid = "out"; break;
448*4882a593Smuzhiyun default: pid = "(?)"; break;
449*4882a593Smuzhiyun } pid;}),
450*4882a593Smuzhiyun cbp ? (be + 1 - cbp) : 0,
451*4882a593Smuzhiyun TD_CC_GET (info), td->urb, info);
452*4882a593Smuzhiyun size -= temp;
453*4882a593Smuzhiyun buf += temp;
454*4882a593Smuzhiyun }
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun temp = scnprintf (buf, size, "\n");
457*4882a593Smuzhiyun size -= temp;
458*4882a593Smuzhiyun buf += temp;
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun ed = ed->ed_next;
461*4882a593Smuzhiyun }
462*4882a593Smuzhiyun return count - size;
463*4882a593Smuzhiyun }
464*4882a593Smuzhiyun
fill_async_buffer(struct debug_buffer * buf)465*4882a593Smuzhiyun static ssize_t fill_async_buffer(struct debug_buffer *buf)
466*4882a593Smuzhiyun {
467*4882a593Smuzhiyun struct ohci_hcd *ohci;
468*4882a593Smuzhiyun size_t temp, size;
469*4882a593Smuzhiyun unsigned long flags;
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun ohci = buf->ohci;
472*4882a593Smuzhiyun size = PAGE_SIZE;
473*4882a593Smuzhiyun
474*4882a593Smuzhiyun /* display control and bulk lists together, for simplicity */
475*4882a593Smuzhiyun spin_lock_irqsave (&ohci->lock, flags);
476*4882a593Smuzhiyun temp = show_list(ohci, buf->page, size, ohci->ed_controltail);
477*4882a593Smuzhiyun temp += show_list(ohci, buf->page + temp, size - temp,
478*4882a593Smuzhiyun ohci->ed_bulktail);
479*4882a593Smuzhiyun spin_unlock_irqrestore (&ohci->lock, flags);
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun return temp;
482*4882a593Smuzhiyun }
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun #define DBG_SCHED_LIMIT 64
485*4882a593Smuzhiyun
fill_periodic_buffer(struct debug_buffer * buf)486*4882a593Smuzhiyun static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
487*4882a593Smuzhiyun {
488*4882a593Smuzhiyun struct ohci_hcd *ohci;
489*4882a593Smuzhiyun struct ed **seen, *ed;
490*4882a593Smuzhiyun unsigned long flags;
491*4882a593Smuzhiyun unsigned temp, size, seen_count;
492*4882a593Smuzhiyun char *next;
493*4882a593Smuzhiyun unsigned i;
494*4882a593Smuzhiyun
495*4882a593Smuzhiyun seen = kmalloc_array(DBG_SCHED_LIMIT, sizeof(*seen), GFP_ATOMIC);
496*4882a593Smuzhiyun if (!seen)
497*4882a593Smuzhiyun return 0;
498*4882a593Smuzhiyun seen_count = 0;
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun ohci = buf->ohci;
501*4882a593Smuzhiyun next = buf->page;
502*4882a593Smuzhiyun size = PAGE_SIZE;
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun temp = scnprintf (next, size, "size = %d\n", NUM_INTS);
505*4882a593Smuzhiyun size -= temp;
506*4882a593Smuzhiyun next += temp;
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun /* dump a snapshot of the periodic schedule (and load) */
509*4882a593Smuzhiyun spin_lock_irqsave (&ohci->lock, flags);
510*4882a593Smuzhiyun for (i = 0; i < NUM_INTS; i++) {
511*4882a593Smuzhiyun ed = ohci->periodic[i];
512*4882a593Smuzhiyun if (!ed)
513*4882a593Smuzhiyun continue;
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun temp = scnprintf (next, size, "%2d [%3d]:", i, ohci->load [i]);
516*4882a593Smuzhiyun size -= temp;
517*4882a593Smuzhiyun next += temp;
518*4882a593Smuzhiyun
519*4882a593Smuzhiyun do {
520*4882a593Smuzhiyun temp = scnprintf (next, size, " ed%d/%p",
521*4882a593Smuzhiyun ed->interval, ed);
522*4882a593Smuzhiyun size -= temp;
523*4882a593Smuzhiyun next += temp;
524*4882a593Smuzhiyun for (temp = 0; temp < seen_count; temp++) {
525*4882a593Smuzhiyun if (seen [temp] == ed)
526*4882a593Smuzhiyun break;
527*4882a593Smuzhiyun }
528*4882a593Smuzhiyun
529*4882a593Smuzhiyun /* show more info the first time around */
530*4882a593Smuzhiyun if (temp == seen_count) {
531*4882a593Smuzhiyun u32 info = hc32_to_cpu (ohci, ed->hwINFO);
532*4882a593Smuzhiyun struct list_head *entry;
533*4882a593Smuzhiyun unsigned qlen = 0;
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun /* qlen measured here in TDs, not urbs */
536*4882a593Smuzhiyun list_for_each (entry, &ed->td_list)
537*4882a593Smuzhiyun qlen++;
538*4882a593Smuzhiyun
539*4882a593Smuzhiyun temp = scnprintf (next, size,
540*4882a593Smuzhiyun " (%cs dev%d ep%d%s-%s qlen %u"
541*4882a593Smuzhiyun " max %d %08x%s%s)",
542*4882a593Smuzhiyun (info & ED_LOWSPEED) ? 'l' : 'f',
543*4882a593Smuzhiyun info & 0x7f,
544*4882a593Smuzhiyun (info >> 7) & 0xf,
545*4882a593Smuzhiyun (info & ED_IN) ? "in" : "out",
546*4882a593Smuzhiyun (info & ED_ISO) ? "iso" : "int",
547*4882a593Smuzhiyun qlen,
548*4882a593Smuzhiyun 0x03ff & (info >> 16),
549*4882a593Smuzhiyun info,
550*4882a593Smuzhiyun (info & ED_SKIP) ? " K" : "",
551*4882a593Smuzhiyun (ed->hwHeadP &
552*4882a593Smuzhiyun cpu_to_hc32(ohci, ED_H)) ?
553*4882a593Smuzhiyun " H" : "");
554*4882a593Smuzhiyun size -= temp;
555*4882a593Smuzhiyun next += temp;
556*4882a593Smuzhiyun
557*4882a593Smuzhiyun if (seen_count < DBG_SCHED_LIMIT)
558*4882a593Smuzhiyun seen [seen_count++] = ed;
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun ed = ed->ed_next;
561*4882a593Smuzhiyun
562*4882a593Smuzhiyun } else {
563*4882a593Smuzhiyun /* we've seen it and what's after */
564*4882a593Smuzhiyun temp = 0;
565*4882a593Smuzhiyun ed = NULL;
566*4882a593Smuzhiyun }
567*4882a593Smuzhiyun
568*4882a593Smuzhiyun } while (ed);
569*4882a593Smuzhiyun
570*4882a593Smuzhiyun temp = scnprintf (next, size, "\n");
571*4882a593Smuzhiyun size -= temp;
572*4882a593Smuzhiyun next += temp;
573*4882a593Smuzhiyun }
574*4882a593Smuzhiyun spin_unlock_irqrestore (&ohci->lock, flags);
575*4882a593Smuzhiyun kfree (seen);
576*4882a593Smuzhiyun
577*4882a593Smuzhiyun return PAGE_SIZE - size;
578*4882a593Smuzhiyun }
579*4882a593Smuzhiyun #undef DBG_SCHED_LIMIT
580*4882a593Smuzhiyun
fill_registers_buffer(struct debug_buffer * buf)581*4882a593Smuzhiyun static ssize_t fill_registers_buffer(struct debug_buffer *buf)
582*4882a593Smuzhiyun {
583*4882a593Smuzhiyun struct usb_hcd *hcd;
584*4882a593Smuzhiyun struct ohci_hcd *ohci;
585*4882a593Smuzhiyun struct ohci_regs __iomem *regs;
586*4882a593Smuzhiyun unsigned long flags;
587*4882a593Smuzhiyun unsigned temp, size;
588*4882a593Smuzhiyun char *next;
589*4882a593Smuzhiyun u32 rdata;
590*4882a593Smuzhiyun
591*4882a593Smuzhiyun ohci = buf->ohci;
592*4882a593Smuzhiyun hcd = ohci_to_hcd(ohci);
593*4882a593Smuzhiyun regs = ohci->regs;
594*4882a593Smuzhiyun next = buf->page;
595*4882a593Smuzhiyun size = PAGE_SIZE;
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun spin_lock_irqsave (&ohci->lock, flags);
598*4882a593Smuzhiyun
599*4882a593Smuzhiyun /* dump driver info, then registers in spec order */
600*4882a593Smuzhiyun
601*4882a593Smuzhiyun ohci_dbg_nosw(ohci, &next, &size,
602*4882a593Smuzhiyun "bus %s, device %s\n"
603*4882a593Smuzhiyun "%s\n"
604*4882a593Smuzhiyun "%s\n",
605*4882a593Smuzhiyun hcd->self.controller->bus->name,
606*4882a593Smuzhiyun dev_name(hcd->self.controller),
607*4882a593Smuzhiyun hcd->product_desc,
608*4882a593Smuzhiyun hcd_name);
609*4882a593Smuzhiyun
610*4882a593Smuzhiyun if (!HCD_HW_ACCESSIBLE(hcd)) {
611*4882a593Smuzhiyun size -= scnprintf (next, size,
612*4882a593Smuzhiyun "SUSPENDED (no register access)\n");
613*4882a593Smuzhiyun goto done;
614*4882a593Smuzhiyun }
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun ohci_dump_status(ohci, &next, &size);
617*4882a593Smuzhiyun
618*4882a593Smuzhiyun /* hcca */
619*4882a593Smuzhiyun if (ohci->hcca)
620*4882a593Smuzhiyun ohci_dbg_nosw(ohci, &next, &size,
621*4882a593Smuzhiyun "hcca frame 0x%04x\n", ohci_frame_no(ohci));
622*4882a593Smuzhiyun
623*4882a593Smuzhiyun /* other registers mostly affect frame timings */
624*4882a593Smuzhiyun rdata = ohci_readl (ohci, ®s->fminterval);
625*4882a593Smuzhiyun temp = scnprintf (next, size,
626*4882a593Smuzhiyun "fmintvl 0x%08x %sFSMPS=0x%04x FI=0x%04x\n",
627*4882a593Smuzhiyun rdata, (rdata >> 31) ? "FIT " : "",
628*4882a593Smuzhiyun (rdata >> 16) & 0xefff, rdata & 0xffff);
629*4882a593Smuzhiyun size -= temp;
630*4882a593Smuzhiyun next += temp;
631*4882a593Smuzhiyun
632*4882a593Smuzhiyun rdata = ohci_readl (ohci, ®s->fmremaining);
633*4882a593Smuzhiyun temp = scnprintf (next, size, "fmremaining 0x%08x %sFR=0x%04x\n",
634*4882a593Smuzhiyun rdata, (rdata >> 31) ? "FRT " : "",
635*4882a593Smuzhiyun rdata & 0x3fff);
636*4882a593Smuzhiyun size -= temp;
637*4882a593Smuzhiyun next += temp;
638*4882a593Smuzhiyun
639*4882a593Smuzhiyun rdata = ohci_readl (ohci, ®s->periodicstart);
640*4882a593Smuzhiyun temp = scnprintf (next, size, "periodicstart 0x%04x\n",
641*4882a593Smuzhiyun rdata & 0x3fff);
642*4882a593Smuzhiyun size -= temp;
643*4882a593Smuzhiyun next += temp;
644*4882a593Smuzhiyun
645*4882a593Smuzhiyun rdata = ohci_readl (ohci, ®s->lsthresh);
646*4882a593Smuzhiyun temp = scnprintf (next, size, "lsthresh 0x%04x\n",
647*4882a593Smuzhiyun rdata & 0x3fff);
648*4882a593Smuzhiyun size -= temp;
649*4882a593Smuzhiyun next += temp;
650*4882a593Smuzhiyun
651*4882a593Smuzhiyun temp = scnprintf (next, size, "hub poll timer %s\n",
652*4882a593Smuzhiyun HCD_POLL_RH(ohci_to_hcd(ohci)) ? "ON" : "off");
653*4882a593Smuzhiyun size -= temp;
654*4882a593Smuzhiyun next += temp;
655*4882a593Smuzhiyun
656*4882a593Smuzhiyun /* roothub */
657*4882a593Smuzhiyun ohci_dump_roothub (ohci, 1, &next, &size);
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun done:
660*4882a593Smuzhiyun spin_unlock_irqrestore (&ohci->lock, flags);
661*4882a593Smuzhiyun
662*4882a593Smuzhiyun return PAGE_SIZE - size;
663*4882a593Smuzhiyun }
664*4882a593Smuzhiyun
alloc_buffer(struct ohci_hcd * ohci,ssize_t (* fill_func)(struct debug_buffer *))665*4882a593Smuzhiyun static struct debug_buffer *alloc_buffer(struct ohci_hcd *ohci,
666*4882a593Smuzhiyun ssize_t (*fill_func)(struct debug_buffer *))
667*4882a593Smuzhiyun {
668*4882a593Smuzhiyun struct debug_buffer *buf;
669*4882a593Smuzhiyun
670*4882a593Smuzhiyun buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
671*4882a593Smuzhiyun
672*4882a593Smuzhiyun if (buf) {
673*4882a593Smuzhiyun buf->ohci = ohci;
674*4882a593Smuzhiyun buf->fill_func = fill_func;
675*4882a593Smuzhiyun mutex_init(&buf->mutex);
676*4882a593Smuzhiyun }
677*4882a593Smuzhiyun
678*4882a593Smuzhiyun return buf;
679*4882a593Smuzhiyun }
680*4882a593Smuzhiyun
fill_buffer(struct debug_buffer * buf)681*4882a593Smuzhiyun static int fill_buffer(struct debug_buffer *buf)
682*4882a593Smuzhiyun {
683*4882a593Smuzhiyun int ret = 0;
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun if (!buf->page)
686*4882a593Smuzhiyun buf->page = (char *)get_zeroed_page(GFP_KERNEL);
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun if (!buf->page) {
689*4882a593Smuzhiyun ret = -ENOMEM;
690*4882a593Smuzhiyun goto out;
691*4882a593Smuzhiyun }
692*4882a593Smuzhiyun
693*4882a593Smuzhiyun ret = buf->fill_func(buf);
694*4882a593Smuzhiyun
695*4882a593Smuzhiyun if (ret >= 0) {
696*4882a593Smuzhiyun buf->count = ret;
697*4882a593Smuzhiyun ret = 0;
698*4882a593Smuzhiyun }
699*4882a593Smuzhiyun
700*4882a593Smuzhiyun out:
701*4882a593Smuzhiyun return ret;
702*4882a593Smuzhiyun }
703*4882a593Smuzhiyun
debug_output(struct file * file,char __user * user_buf,size_t len,loff_t * offset)704*4882a593Smuzhiyun static ssize_t debug_output(struct file *file, char __user *user_buf,
705*4882a593Smuzhiyun size_t len, loff_t *offset)
706*4882a593Smuzhiyun {
707*4882a593Smuzhiyun struct debug_buffer *buf = file->private_data;
708*4882a593Smuzhiyun int ret = 0;
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun mutex_lock(&buf->mutex);
711*4882a593Smuzhiyun if (buf->count == 0) {
712*4882a593Smuzhiyun ret = fill_buffer(buf);
713*4882a593Smuzhiyun if (ret != 0) {
714*4882a593Smuzhiyun mutex_unlock(&buf->mutex);
715*4882a593Smuzhiyun goto out;
716*4882a593Smuzhiyun }
717*4882a593Smuzhiyun }
718*4882a593Smuzhiyun mutex_unlock(&buf->mutex);
719*4882a593Smuzhiyun
720*4882a593Smuzhiyun ret = simple_read_from_buffer(user_buf, len, offset,
721*4882a593Smuzhiyun buf->page, buf->count);
722*4882a593Smuzhiyun
723*4882a593Smuzhiyun out:
724*4882a593Smuzhiyun return ret;
725*4882a593Smuzhiyun
726*4882a593Smuzhiyun }
727*4882a593Smuzhiyun
debug_close(struct inode * inode,struct file * file)728*4882a593Smuzhiyun static int debug_close(struct inode *inode, struct file *file)
729*4882a593Smuzhiyun {
730*4882a593Smuzhiyun struct debug_buffer *buf = file->private_data;
731*4882a593Smuzhiyun
732*4882a593Smuzhiyun if (buf) {
733*4882a593Smuzhiyun if (buf->page)
734*4882a593Smuzhiyun free_page((unsigned long)buf->page);
735*4882a593Smuzhiyun kfree(buf);
736*4882a593Smuzhiyun }
737*4882a593Smuzhiyun
738*4882a593Smuzhiyun return 0;
739*4882a593Smuzhiyun }
debug_async_open(struct inode * inode,struct file * file)740*4882a593Smuzhiyun static int debug_async_open(struct inode *inode, struct file *file)
741*4882a593Smuzhiyun {
742*4882a593Smuzhiyun file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
743*4882a593Smuzhiyun
744*4882a593Smuzhiyun return file->private_data ? 0 : -ENOMEM;
745*4882a593Smuzhiyun }
746*4882a593Smuzhiyun
debug_periodic_open(struct inode * inode,struct file * file)747*4882a593Smuzhiyun static int debug_periodic_open(struct inode *inode, struct file *file)
748*4882a593Smuzhiyun {
749*4882a593Smuzhiyun file->private_data = alloc_buffer(inode->i_private,
750*4882a593Smuzhiyun fill_periodic_buffer);
751*4882a593Smuzhiyun
752*4882a593Smuzhiyun return file->private_data ? 0 : -ENOMEM;
753*4882a593Smuzhiyun }
754*4882a593Smuzhiyun
debug_registers_open(struct inode * inode,struct file * file)755*4882a593Smuzhiyun static int debug_registers_open(struct inode *inode, struct file *file)
756*4882a593Smuzhiyun {
757*4882a593Smuzhiyun file->private_data = alloc_buffer(inode->i_private,
758*4882a593Smuzhiyun fill_registers_buffer);
759*4882a593Smuzhiyun
760*4882a593Smuzhiyun return file->private_data ? 0 : -ENOMEM;
761*4882a593Smuzhiyun }
create_debug_files(struct ohci_hcd * ohci)762*4882a593Smuzhiyun static inline void create_debug_files (struct ohci_hcd *ohci)
763*4882a593Smuzhiyun {
764*4882a593Smuzhiyun struct usb_bus *bus = &ohci_to_hcd(ohci)->self;
765*4882a593Smuzhiyun struct dentry *root;
766*4882a593Smuzhiyun
767*4882a593Smuzhiyun root = debugfs_create_dir(bus->bus_name, ohci_debug_root);
768*4882a593Smuzhiyun ohci->debug_dir = root;
769*4882a593Smuzhiyun
770*4882a593Smuzhiyun debugfs_create_file("async", S_IRUGO, root, ohci, &debug_async_fops);
771*4882a593Smuzhiyun debugfs_create_file("periodic", S_IRUGO, root, ohci,
772*4882a593Smuzhiyun &debug_periodic_fops);
773*4882a593Smuzhiyun debugfs_create_file("registers", S_IRUGO, root, ohci,
774*4882a593Smuzhiyun &debug_registers_fops);
775*4882a593Smuzhiyun
776*4882a593Smuzhiyun ohci_dbg (ohci, "created debug files\n");
777*4882a593Smuzhiyun }
778*4882a593Smuzhiyun
remove_debug_files(struct ohci_hcd * ohci)779*4882a593Smuzhiyun static inline void remove_debug_files (struct ohci_hcd *ohci)
780*4882a593Smuzhiyun {
781*4882a593Smuzhiyun debugfs_remove_recursive(ohci->debug_dir);
782*4882a593Smuzhiyun }
783*4882a593Smuzhiyun
784*4882a593Smuzhiyun /*-------------------------------------------------------------------------*/
785*4882a593Smuzhiyun
786