ohci-dbg.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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 __FILE__ ": setup(8):");
  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 __FILE__ ": data(%d/%d):",
  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. };
  371. static const struct file_operations debug_periodic_fops = {
  372. .owner = THIS_MODULE,
  373. .open = debug_periodic_open,
  374. .read = debug_output,
  375. .release = debug_close,
  376. };
  377. static const struct file_operations debug_registers_fops = {
  378. .owner = THIS_MODULE,
  379. .open = debug_registers_open,
  380. .read = debug_output,
  381. .release = debug_close,
  382. };
  383. static struct dentry *ohci_debug_root;
  384. struct debug_buffer {
  385. ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
  386. struct ohci_hcd *ohci;
  387. struct mutex mutex; /* protect filling of buffer */
  388. size_t count; /* number of characters filled into buffer */
  389. char *page;
  390. };
  391. static ssize_t
  392. show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
  393. {
  394. unsigned temp, size = count;
  395. if (!ed)
  396. return 0;
  397. /* print first --> last */
  398. while (ed->ed_prev)
  399. ed = ed->ed_prev;
  400. /* dump a snapshot of the bulk or control schedule */
  401. while (ed) {
  402. u32 info = hc32_to_cpu (ohci, ed->hwINFO);
  403. u32 headp = hc32_to_cpu (ohci, ed->hwHeadP);
  404. struct list_head *entry;
  405. struct td *td;
  406. temp = scnprintf (buf, size,
  407. "ed/%p %cs dev%d ep%d%s max %d %08x%s%s %s",
  408. ed,
  409. (info & ED_LOWSPEED) ? 'l' : 'f',
  410. info & 0x7f,
  411. (info >> 7) & 0xf,
  412. (info & ED_IN) ? "in" : "out",
  413. 0x03ff & (info >> 16),
  414. info,
  415. (info & ED_SKIP) ? " s" : "",
  416. (headp & ED_H) ? " H" : "",
  417. (headp & ED_C) ? data1 : data0);
  418. size -= temp;
  419. buf += temp;
  420. list_for_each (entry, &ed->td_list) {
  421. u32 cbp, be;
  422. td = list_entry (entry, struct td, td_list);
  423. info = hc32_to_cpup (ohci, &td->hwINFO);
  424. cbp = hc32_to_cpup (ohci, &td->hwCBP);
  425. be = hc32_to_cpup (ohci, &td->hwBE);
  426. temp = scnprintf (buf, size,
  427. "\n\ttd %p %s %d cc=%x urb %p (%08x)",
  428. td,
  429. ({ char *pid;
  430. switch (info & TD_DP) {
  431. case TD_DP_SETUP: pid = "setup"; break;
  432. case TD_DP_IN: pid = "in"; break;
  433. case TD_DP_OUT: pid = "out"; break;
  434. default: pid = "(?)"; break;
  435. } pid;}),
  436. cbp ? (be + 1 - cbp) : 0,
  437. TD_CC_GET (info), td->urb, info);
  438. size -= temp;
  439. buf += temp;
  440. }
  441. temp = scnprintf (buf, size, "\n");
  442. size -= temp;
  443. buf += temp;
  444. ed = ed->ed_next;
  445. }
  446. return count - size;
  447. }
  448. static ssize_t fill_async_buffer(struct debug_buffer *buf)
  449. {
  450. struct ohci_hcd *ohci;
  451. size_t temp;
  452. unsigned long flags;
  453. ohci = buf->ohci;
  454. /* display control and bulk lists together, for simplicity */
  455. spin_lock_irqsave (&ohci->lock, flags);
  456. temp = show_list(ohci, buf->page, buf->count, ohci->ed_controltail);
  457. temp += show_list(ohci, buf->page + temp, buf->count - temp,
  458. ohci->ed_bulktail);
  459. spin_unlock_irqrestore (&ohci->lock, flags);
  460. return temp;
  461. }
  462. #define DBG_SCHED_LIMIT 64
  463. static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
  464. {
  465. struct ohci_hcd *ohci;
  466. struct ed **seen, *ed;
  467. unsigned long flags;
  468. unsigned temp, size, seen_count;
  469. char *next;
  470. unsigned i;
  471. if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC)))
  472. return 0;
  473. seen_count = 0;
  474. ohci = buf->ohci;
  475. next = buf->page;
  476. size = PAGE_SIZE;
  477. temp = scnprintf (next, size, "size = %d\n", NUM_INTS);
  478. size -= temp;
  479. next += temp;
  480. /* dump a snapshot of the periodic schedule (and load) */
  481. spin_lock_irqsave (&ohci->lock, flags);
  482. for (i = 0; i < NUM_INTS; i++) {
  483. if (!(ed = ohci->periodic [i]))
  484. continue;
  485. temp = scnprintf (next, size, "%2d [%3d]:", i, ohci->load [i]);
  486. size -= temp;
  487. next += temp;
  488. do {
  489. temp = scnprintf (next, size, " ed%d/%p",
  490. ed->interval, ed);
  491. size -= temp;
  492. next += temp;
  493. for (temp = 0; temp < seen_count; temp++) {
  494. if (seen [temp] == ed)
  495. break;
  496. }
  497. /* show more info the first time around */
  498. if (temp == seen_count) {
  499. u32 info = hc32_to_cpu (ohci, ed->hwINFO);
  500. struct list_head *entry;
  501. unsigned qlen = 0;
  502. /* qlen measured here in TDs, not urbs */
  503. list_for_each (entry, &ed->td_list)
  504. qlen++;
  505. temp = scnprintf (next, size,
  506. " (%cs dev%d ep%d%s-%s qlen %u"
  507. " max %d %08x%s%s)",
  508. (info & ED_LOWSPEED) ? 'l' : 'f',
  509. info & 0x7f,
  510. (info >> 7) & 0xf,
  511. (info & ED_IN) ? "in" : "out",
  512. (info & ED_ISO) ? "iso" : "int",
  513. qlen,
  514. 0x03ff & (info >> 16),
  515. info,
  516. (info & ED_SKIP) ? " K" : "",
  517. (ed->hwHeadP &
  518. cpu_to_hc32(ohci, ED_H)) ?
  519. " H" : "");
  520. size -= temp;
  521. next += temp;
  522. if (seen_count < DBG_SCHED_LIMIT)
  523. seen [seen_count++] = ed;
  524. ed = ed->ed_next;
  525. } else {
  526. /* we've seen it and what's after */
  527. temp = 0;
  528. ed = NULL;
  529. }
  530. } while (ed);
  531. temp = scnprintf (next, size, "\n");
  532. size -= temp;
  533. next += temp;
  534. }
  535. spin_unlock_irqrestore (&ohci->lock, flags);
  536. kfree (seen);
  537. return PAGE_SIZE - size;
  538. }
  539. #undef DBG_SCHED_LIMIT
  540. static ssize_t fill_registers_buffer(struct debug_buffer *buf)
  541. {
  542. struct usb_hcd *hcd;
  543. struct ohci_hcd *ohci;
  544. struct ohci_regs __iomem *regs;
  545. unsigned long flags;
  546. unsigned temp, size;
  547. char *next;
  548. u32 rdata;
  549. ohci = buf->ohci;
  550. hcd = ohci_to_hcd(ohci);
  551. regs = ohci->regs;
  552. next = buf->page;
  553. size = PAGE_SIZE;
  554. spin_lock_irqsave (&ohci->lock, flags);
  555. /* dump driver info, then registers in spec order */
  556. ohci_dbg_sw (ohci, &next, &size,
  557. "bus %s, device %s\n"
  558. "%s\n"
  559. "%s\n",
  560. hcd->self.controller->bus->name,
  561. dev_name(hcd->self.controller),
  562. hcd->product_desc,
  563. hcd_name);
  564. if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
  565. size -= scnprintf (next, size,
  566. "SUSPENDED (no register access)\n");
  567. goto done;
  568. }
  569. ohci_dump_status(ohci, &next, &size);
  570. /* hcca */
  571. if (ohci->hcca)
  572. ohci_dbg_sw (ohci, &next, &size,
  573. "hcca frame 0x%04x\n", ohci_frame_no(ohci));
  574. /* other registers mostly affect frame timings */
  575. rdata = ohci_readl (ohci, &regs->fminterval);
  576. temp = scnprintf (next, size,
  577. "fmintvl 0x%08x %sFSMPS=0x%04x FI=0x%04x\n",
  578. rdata, (rdata >> 31) ? "FIT " : "",
  579. (rdata >> 16) & 0xefff, rdata & 0xffff);
  580. size -= temp;
  581. next += temp;
  582. rdata = ohci_readl (ohci, &regs->fmremaining);
  583. temp = scnprintf (next, size, "fmremaining 0x%08x %sFR=0x%04x\n",
  584. rdata, (rdata >> 31) ? "FRT " : "",
  585. rdata & 0x3fff);
  586. size -= temp;
  587. next += temp;
  588. rdata = ohci_readl (ohci, &regs->periodicstart);
  589. temp = scnprintf (next, size, "periodicstart 0x%04x\n",
  590. rdata & 0x3fff);
  591. size -= temp;
  592. next += temp;
  593. rdata = ohci_readl (ohci, &regs->lsthresh);
  594. temp = scnprintf (next, size, "lsthresh 0x%04x\n",
  595. rdata & 0x3fff);
  596. size -= temp;
  597. next += temp;
  598. temp = scnprintf (next, size, "hub poll timer %s\n",
  599. ohci_to_hcd(ohci)->poll_rh ? "ON" : "off");
  600. size -= temp;
  601. next += temp;
  602. /* roothub */
  603. ohci_dump_roothub (ohci, 1, &next, &size);
  604. done:
  605. spin_unlock_irqrestore (&ohci->lock, flags);
  606. return PAGE_SIZE - size;
  607. }
  608. static struct debug_buffer *alloc_buffer(struct ohci_hcd *ohci,
  609. ssize_t (*fill_func)(struct debug_buffer *))
  610. {
  611. struct debug_buffer *buf;
  612. buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
  613. if (buf) {
  614. buf->ohci = ohci;
  615. buf->fill_func = fill_func;
  616. mutex_init(&buf->mutex);
  617. }
  618. return buf;
  619. }
  620. static int fill_buffer(struct debug_buffer *buf)
  621. {
  622. int ret = 0;
  623. if (!buf->page)
  624. buf->page = (char *)get_zeroed_page(GFP_KERNEL);
  625. if (!buf->page) {
  626. ret = -ENOMEM;
  627. goto out;
  628. }
  629. ret = buf->fill_func(buf);
  630. if (ret >= 0) {
  631. buf->count = ret;
  632. ret = 0;
  633. }
  634. out:
  635. return ret;
  636. }
  637. static ssize_t debug_output(struct file *file, char __user *user_buf,
  638. size_t len, loff_t *offset)
  639. {
  640. struct debug_buffer *buf = file->private_data;
  641. int ret = 0;
  642. mutex_lock(&buf->mutex);
  643. if (buf->count == 0) {
  644. ret = fill_buffer(buf);
  645. if (ret != 0) {
  646. mutex_unlock(&buf->mutex);
  647. goto out;
  648. }
  649. }
  650. mutex_unlock(&buf->mutex);
  651. ret = simple_read_from_buffer(user_buf, len, offset,
  652. buf->page, buf->count);
  653. out:
  654. return ret;
  655. }
  656. static int debug_close(struct inode *inode, struct file *file)
  657. {
  658. struct debug_buffer *buf = file->private_data;
  659. if (buf) {
  660. if (buf->page)
  661. free_page((unsigned long)buf->page);
  662. kfree(buf);
  663. }
  664. return 0;
  665. }
  666. static int debug_async_open(struct inode *inode, struct file *file)
  667. {
  668. file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
  669. return file->private_data ? 0 : -ENOMEM;
  670. }
  671. static int debug_periodic_open(struct inode *inode, struct file *file)
  672. {
  673. file->private_data = alloc_buffer(inode->i_private,
  674. fill_periodic_buffer);
  675. return file->private_data ? 0 : -ENOMEM;
  676. }
  677. static int debug_registers_open(struct inode *inode, struct file *file)
  678. {
  679. file->private_data = alloc_buffer(inode->i_private,
  680. fill_registers_buffer);
  681. return file->private_data ? 0 : -ENOMEM;
  682. }
  683. static inline void create_debug_files (struct ohci_hcd *ohci)
  684. {
  685. struct usb_bus *bus = &ohci_to_hcd(ohci)->self;
  686. ohci->debug_dir = debugfs_create_dir(bus->bus_name, ohci_debug_root);
  687. if (!ohci->debug_dir)
  688. goto dir_error;
  689. ohci->debug_async = debugfs_create_file("async", S_IRUGO,
  690. ohci->debug_dir, ohci,
  691. &debug_async_fops);
  692. if (!ohci->debug_async)
  693. goto async_error;
  694. ohci->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
  695. ohci->debug_dir, ohci,
  696. &debug_periodic_fops);
  697. if (!ohci->debug_periodic)
  698. goto periodic_error;
  699. ohci->debug_registers = debugfs_create_file("registers", S_IRUGO,
  700. ohci->debug_dir, ohci,
  701. &debug_registers_fops);
  702. if (!ohci->debug_registers)
  703. goto registers_error;
  704. ohci_dbg (ohci, "created debug files\n");
  705. return;
  706. registers_error:
  707. debugfs_remove(ohci->debug_periodic);
  708. periodic_error:
  709. debugfs_remove(ohci->debug_async);
  710. async_error:
  711. debugfs_remove(ohci->debug_dir);
  712. dir_error:
  713. ohci->debug_periodic = NULL;
  714. ohci->debug_async = NULL;
  715. ohci->debug_dir = NULL;
  716. }
  717. static inline void remove_debug_files (struct ohci_hcd *ohci)
  718. {
  719. debugfs_remove(ohci->debug_registers);
  720. debugfs_remove(ohci->debug_periodic);
  721. debugfs_remove(ohci->debug_async);
  722. debugfs_remove(ohci->debug_dir);
  723. }
  724. #endif
  725. /*-------------------------------------------------------------------------*/