ohci-dbg.c 20 KB

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