PageRenderTime 65ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/usb/host/ohci-dbg.c

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