ohci-dbg.c 21 KB

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