ohci-dbg.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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)
  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, size;
  419. unsigned long flags;
  420. ohci = buf->ohci;
  421. size = PAGE_SIZE;
  422. /* display control and bulk lists together, for simplicity */
  423. spin_lock_irqsave (&ohci->lock, flags);
  424. temp = show_list(ohci, buf->page, size, ohci->ed_controltail);
  425. temp += show_list(ohci, buf->page + temp, size - temp,
  426. ohci->ed_bulktail);
  427. spin_unlock_irqrestore (&ohci->lock, flags);
  428. return temp;
  429. }
  430. #define DBG_SCHED_LIMIT 64
  431. static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
  432. {
  433. struct ohci_hcd *ohci;
  434. struct ed **seen, *ed;
  435. unsigned long flags;
  436. unsigned temp, size, seen_count;
  437. char *next;
  438. unsigned i;
  439. seen = kmalloc(DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC);
  440. if (!seen)
  441. return 0;
  442. seen_count = 0;
  443. ohci = buf->ohci;
  444. next = buf->page;
  445. size = PAGE_SIZE;
  446. temp = scnprintf (next, size, "size = %d\n", NUM_INTS);
  447. size -= temp;
  448. next += temp;
  449. /* dump a snapshot of the periodic schedule (and load) */
  450. spin_lock_irqsave (&ohci->lock, flags);
  451. for (i = 0; i < NUM_INTS; i++) {
  452. ed = ohci->periodic[i];
  453. if (!ed)
  454. continue;
  455. temp = scnprintf (next, size, "%2d [%3d]:", i, ohci->load [i]);
  456. size -= temp;
  457. next += temp;
  458. do {
  459. temp = scnprintf (next, size, " ed%d/%p",
  460. ed->interval, ed);
  461. size -= temp;
  462. next += temp;
  463. for (temp = 0; temp < seen_count; temp++) {
  464. if (seen [temp] == ed)
  465. break;
  466. }
  467. /* show more info the first time around */
  468. if (temp == seen_count) {
  469. u32 info = hc32_to_cpu (ohci, ed->hwINFO);
  470. struct list_head *entry;
  471. unsigned qlen = 0;
  472. /* qlen measured here in TDs, not urbs */
  473. list_for_each (entry, &ed->td_list)
  474. qlen++;
  475. temp = scnprintf (next, size,
  476. " (%cs dev%d ep%d%s-%s qlen %u"
  477. " max %d %08x%s%s)",
  478. (info & ED_LOWSPEED) ? 'l' : 'f',
  479. info & 0x7f,
  480. (info >> 7) & 0xf,
  481. (info & ED_IN) ? "in" : "out",
  482. (info & ED_ISO) ? "iso" : "int",
  483. qlen,
  484. 0x03ff & (info >> 16),
  485. info,
  486. (info & ED_SKIP) ? " K" : "",
  487. (ed->hwHeadP &
  488. cpu_to_hc32(ohci, ED_H)) ?
  489. " H" : "");
  490. size -= temp;
  491. next += temp;
  492. if (seen_count < DBG_SCHED_LIMIT)
  493. seen [seen_count++] = ed;
  494. ed = ed->ed_next;
  495. } else {
  496. /* we've seen it and what's after */
  497. temp = 0;
  498. ed = NULL;
  499. }
  500. } while (ed);
  501. temp = scnprintf (next, size, "\n");
  502. size -= temp;
  503. next += temp;
  504. }
  505. spin_unlock_irqrestore (&ohci->lock, flags);
  506. kfree (seen);
  507. return PAGE_SIZE - size;
  508. }
  509. #undef DBG_SCHED_LIMIT
  510. static ssize_t fill_registers_buffer(struct debug_buffer *buf)
  511. {
  512. struct usb_hcd *hcd;
  513. struct ohci_hcd *ohci;
  514. struct ohci_regs __iomem *regs;
  515. unsigned long flags;
  516. unsigned temp, size;
  517. char *next;
  518. u32 rdata;
  519. ohci = buf->ohci;
  520. hcd = ohci_to_hcd(ohci);
  521. regs = ohci->regs;
  522. next = buf->page;
  523. size = PAGE_SIZE;
  524. spin_lock_irqsave (&ohci->lock, flags);
  525. /* dump driver info, then registers in spec order */
  526. ohci_dbg_nosw(ohci, &next, &size,
  527. "bus %s, device %s\n"
  528. "%s\n"
  529. "%s\n",
  530. hcd->self.controller->bus->name,
  531. dev_name(hcd->self.controller),
  532. hcd->product_desc,
  533. hcd_name);
  534. if (!HCD_HW_ACCESSIBLE(hcd)) {
  535. size -= scnprintf (next, size,
  536. "SUSPENDED (no register access)\n");
  537. goto done;
  538. }
  539. ohci_dump_status(ohci, &next, &size);
  540. /* hcca */
  541. if (ohci->hcca)
  542. ohci_dbg_nosw(ohci, &next, &size,
  543. "hcca frame 0x%04x\n", ohci_frame_no(ohci));
  544. /* other registers mostly affect frame timings */
  545. rdata = ohci_readl (ohci, &regs->fminterval);
  546. temp = scnprintf (next, size,
  547. "fmintvl 0x%08x %sFSMPS=0x%04x FI=0x%04x\n",
  548. rdata, (rdata >> 31) ? "FIT " : "",
  549. (rdata >> 16) & 0xefff, rdata & 0xffff);
  550. size -= temp;
  551. next += temp;
  552. rdata = ohci_readl (ohci, &regs->fmremaining);
  553. temp = scnprintf (next, size, "fmremaining 0x%08x %sFR=0x%04x\n",
  554. rdata, (rdata >> 31) ? "FRT " : "",
  555. rdata & 0x3fff);
  556. size -= temp;
  557. next += temp;
  558. rdata = ohci_readl (ohci, &regs->periodicstart);
  559. temp = scnprintf (next, size, "periodicstart 0x%04x\n",
  560. rdata & 0x3fff);
  561. size -= temp;
  562. next += temp;
  563. rdata = ohci_readl (ohci, &regs->lsthresh);
  564. temp = scnprintf (next, size, "lsthresh 0x%04x\n",
  565. rdata & 0x3fff);
  566. size -= temp;
  567. next += temp;
  568. temp = scnprintf (next, size, "hub poll timer %s\n",
  569. HCD_POLL_RH(ohci_to_hcd(ohci)) ? "ON" : "off");
  570. size -= temp;
  571. next += temp;
  572. /* roothub */
  573. ohci_dump_roothub (ohci, 1, &next, &size);
  574. done:
  575. spin_unlock_irqrestore (&ohci->lock, flags);
  576. return PAGE_SIZE - size;
  577. }
  578. static struct debug_buffer *alloc_buffer(struct ohci_hcd *ohci,
  579. ssize_t (*fill_func)(struct debug_buffer *))
  580. {
  581. struct debug_buffer *buf;
  582. buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
  583. if (buf) {
  584. buf->ohci = ohci;
  585. buf->fill_func = fill_func;
  586. mutex_init(&buf->mutex);
  587. }
  588. return buf;
  589. }
  590. static int fill_buffer(struct debug_buffer *buf)
  591. {
  592. int ret = 0;
  593. if (!buf->page)
  594. buf->page = (char *)get_zeroed_page(GFP_KERNEL);
  595. if (!buf->page) {
  596. ret = -ENOMEM;
  597. goto out;
  598. }
  599. ret = buf->fill_func(buf);
  600. if (ret >= 0) {
  601. buf->count = ret;
  602. ret = 0;
  603. }
  604. out:
  605. return ret;
  606. }
  607. static ssize_t debug_output(struct file *file, char __user *user_buf,
  608. size_t len, loff_t *offset)
  609. {
  610. struct debug_buffer *buf = file->private_data;
  611. int ret = 0;
  612. mutex_lock(&buf->mutex);
  613. if (buf->count == 0) {
  614. ret = fill_buffer(buf);
  615. if (ret != 0) {
  616. mutex_unlock(&buf->mutex);
  617. goto out;
  618. }
  619. }
  620. mutex_unlock(&buf->mutex);
  621. ret = simple_read_from_buffer(user_buf, len, offset,
  622. buf->page, buf->count);
  623. out:
  624. return ret;
  625. }
  626. static int debug_close(struct inode *inode, struct file *file)
  627. {
  628. struct debug_buffer *buf = file->private_data;
  629. if (buf) {
  630. if (buf->page)
  631. free_page((unsigned long)buf->page);
  632. kfree(buf);
  633. }
  634. return 0;
  635. }
  636. static int debug_async_open(struct inode *inode, struct file *file)
  637. {
  638. file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
  639. return file->private_data ? 0 : -ENOMEM;
  640. }
  641. static int debug_periodic_open(struct inode *inode, struct file *file)
  642. {
  643. file->private_data = alloc_buffer(inode->i_private,
  644. fill_periodic_buffer);
  645. return file->private_data ? 0 : -ENOMEM;
  646. }
  647. static int debug_registers_open(struct inode *inode, struct file *file)
  648. {
  649. file->private_data = alloc_buffer(inode->i_private,
  650. fill_registers_buffer);
  651. return file->private_data ? 0 : -ENOMEM;
  652. }
  653. static inline void create_debug_files (struct ohci_hcd *ohci)
  654. {
  655. struct usb_bus *bus = &ohci_to_hcd(ohci)->self;
  656. ohci->debug_dir = debugfs_create_dir(bus->bus_name, ohci_debug_root);
  657. if (!ohci->debug_dir)
  658. goto dir_error;
  659. ohci->debug_async = debugfs_create_file("async", S_IRUGO,
  660. ohci->debug_dir, ohci,
  661. &debug_async_fops);
  662. if (!ohci->debug_async)
  663. goto async_error;
  664. ohci->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
  665. ohci->debug_dir, ohci,
  666. &debug_periodic_fops);
  667. if (!ohci->debug_periodic)
  668. goto periodic_error;
  669. ohci->debug_registers = debugfs_create_file("registers", S_IRUGO,
  670. ohci->debug_dir, ohci,
  671. &debug_registers_fops);
  672. if (!ohci->debug_registers)
  673. goto registers_error;
  674. ohci_dbg (ohci, "created debug files\n");
  675. return;
  676. registers_error:
  677. debugfs_remove(ohci->debug_periodic);
  678. periodic_error:
  679. debugfs_remove(ohci->debug_async);
  680. async_error:
  681. debugfs_remove(ohci->debug_dir);
  682. dir_error:
  683. ohci->debug_periodic = NULL;
  684. ohci->debug_async = NULL;
  685. ohci->debug_dir = NULL;
  686. }
  687. static inline void remove_debug_files (struct ohci_hcd *ohci)
  688. {
  689. debugfs_remove(ohci->debug_registers);
  690. debugfs_remove(ohci->debug_periodic);
  691. debugfs_remove(ohci->debug_async);
  692. debugfs_remove(ohci->debug_dir);
  693. }
  694. /*-------------------------------------------------------------------------*/