ohci-dbg.c 19 KB

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