ohci-dbg.c 22 KB

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