ehci-dbg.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. /*
  2. * Copyright (c) 2001-2002 by David Brownell
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. /* this file is part of ehci-hcd.c */
  19. #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
  20. /* check the values in the HCSPARAMS register
  21. * (host controller _Structural_ parameters)
  22. * see EHCI spec, Table 2-4 for each value
  23. */
  24. static void dbg_hcs_params (struct ehci_hcd *ehci, char *label)
  25. {
  26. u32 params = ehci_readl(ehci, &ehci->caps->hcs_params);
  27. ehci_dbg (ehci,
  28. "%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n",
  29. label, params,
  30. HCS_DEBUG_PORT (params),
  31. HCS_INDICATOR (params) ? " ind" : "",
  32. HCS_N_CC (params),
  33. HCS_N_PCC (params),
  34. HCS_PORTROUTED (params) ? "" : " ordered",
  35. HCS_PPC (params) ? "" : " !ppc",
  36. HCS_N_PORTS (params)
  37. );
  38. /* Port routing, per EHCI 0.95 Spec, Section 2.2.5 */
  39. if (HCS_PORTROUTED (params)) {
  40. int i;
  41. char buf [46], tmp [7], byte;
  42. buf[0] = 0;
  43. for (i = 0; i < HCS_N_PORTS (params); i++) {
  44. // FIXME MIPS won't readb() ...
  45. byte = readb (&ehci->caps->portroute[(i>>1)]);
  46. sprintf(tmp, "%d ",
  47. ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf)));
  48. strcat(buf, tmp);
  49. }
  50. ehci_dbg (ehci, "%s portroute %s\n",
  51. label, buf);
  52. }
  53. }
  54. #else
  55. static inline void dbg_hcs_params (struct ehci_hcd *ehci, char *label) {}
  56. #endif
  57. #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
  58. /* check the values in the HCCPARAMS register
  59. * (host controller _Capability_ parameters)
  60. * see EHCI Spec, Table 2-5 for each value
  61. * */
  62. static void dbg_hcc_params (struct ehci_hcd *ehci, char *label)
  63. {
  64. u32 params = ehci_readl(ehci, &ehci->caps->hcc_params);
  65. if (HCC_ISOC_CACHE (params)) {
  66. ehci_dbg (ehci,
  67. "%s hcc_params %04x caching frame %s%s%s\n",
  68. label, params,
  69. HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
  70. HCC_CANPARK(params) ? " park" : "",
  71. HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
  72. } else {
  73. ehci_dbg (ehci,
  74. "%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n",
  75. label,
  76. params,
  77. HCC_ISOC_THRES(params),
  78. HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
  79. HCC_CANPARK(params) ? " park" : "",
  80. HCC_64BIT_ADDR(params) ? " 64 bit addr" : "",
  81. HCC_LPM(params) ? " LPM" : "",
  82. HCC_PER_PORT_CHANGE_EVENT(params) ? " ppce" : "",
  83. HCC_HW_PREFETCH(params) ? " hw prefetch" : "",
  84. HCC_32FRAME_PERIODIC_LIST(params) ?
  85. " 32 periodic list" : "");
  86. }
  87. }
  88. #else
  89. static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {}
  90. #endif
  91. #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
  92. static void __maybe_unused
  93. dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
  94. {
  95. ehci_dbg(ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
  96. hc32_to_cpup(ehci, &qtd->hw_next),
  97. hc32_to_cpup(ehci, &qtd->hw_alt_next),
  98. hc32_to_cpup(ehci, &qtd->hw_token),
  99. hc32_to_cpup(ehci, &qtd->hw_buf [0]));
  100. if (qtd->hw_buf [1])
  101. ehci_dbg(ehci, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
  102. hc32_to_cpup(ehci, &qtd->hw_buf[1]),
  103. hc32_to_cpup(ehci, &qtd->hw_buf[2]),
  104. hc32_to_cpup(ehci, &qtd->hw_buf[3]),
  105. hc32_to_cpup(ehci, &qtd->hw_buf[4]));
  106. }
  107. static void __maybe_unused
  108. dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
  109. {
  110. struct ehci_qh_hw *hw = qh->hw;
  111. ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label,
  112. qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current);
  113. dbg_qtd("overlay", ehci, (struct ehci_qtd *) &hw->hw_qtd_next);
  114. }
  115. static void __maybe_unused
  116. dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
  117. {
  118. ehci_dbg (ehci, "%s [%d] itd %p, next %08x, urb %p\n",
  119. label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next),
  120. itd->urb);
  121. ehci_dbg (ehci,
  122. " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  123. hc32_to_cpu(ehci, itd->hw_transaction[0]),
  124. hc32_to_cpu(ehci, itd->hw_transaction[1]),
  125. hc32_to_cpu(ehci, itd->hw_transaction[2]),
  126. hc32_to_cpu(ehci, itd->hw_transaction[3]),
  127. hc32_to_cpu(ehci, itd->hw_transaction[4]),
  128. hc32_to_cpu(ehci, itd->hw_transaction[5]),
  129. hc32_to_cpu(ehci, itd->hw_transaction[6]),
  130. hc32_to_cpu(ehci, itd->hw_transaction[7]));
  131. ehci_dbg (ehci,
  132. " buf: %08x %08x %08x %08x %08x %08x %08x\n",
  133. hc32_to_cpu(ehci, itd->hw_bufp[0]),
  134. hc32_to_cpu(ehci, itd->hw_bufp[1]),
  135. hc32_to_cpu(ehci, itd->hw_bufp[2]),
  136. hc32_to_cpu(ehci, itd->hw_bufp[3]),
  137. hc32_to_cpu(ehci, itd->hw_bufp[4]),
  138. hc32_to_cpu(ehci, itd->hw_bufp[5]),
  139. hc32_to_cpu(ehci, itd->hw_bufp[6]));
  140. ehci_dbg (ehci, " index: %d %d %d %d %d %d %d %d\n",
  141. itd->index[0], itd->index[1], itd->index[2],
  142. itd->index[3], itd->index[4], itd->index[5],
  143. itd->index[6], itd->index[7]);
  144. }
  145. static void __maybe_unused
  146. dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
  147. {
  148. ehci_dbg (ehci, "%s [%d] sitd %p, next %08x, urb %p\n",
  149. label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next),
  150. sitd->urb);
  151. ehci_dbg (ehci,
  152. " addr %08x sched %04x result %08x buf %08x %08x\n",
  153. hc32_to_cpu(ehci, sitd->hw_fullspeed_ep),
  154. hc32_to_cpu(ehci, sitd->hw_uframe),
  155. hc32_to_cpu(ehci, sitd->hw_results),
  156. hc32_to_cpu(ehci, sitd->hw_buf[0]),
  157. hc32_to_cpu(ehci, sitd->hw_buf[1]));
  158. }
  159. static int __maybe_unused
  160. dbg_status_buf (char *buf, unsigned len, const char *label, u32 status)
  161. {
  162. return scnprintf (buf, len,
  163. "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s%s",
  164. label, label [0] ? " " : "", status,
  165. (status & STS_PPCE_MASK) ? " PPCE" : "",
  166. (status & STS_ASS) ? " Async" : "",
  167. (status & STS_PSS) ? " Periodic" : "",
  168. (status & STS_RECL) ? " Recl" : "",
  169. (status & STS_HALT) ? " Halt" : "",
  170. (status & STS_IAA) ? " IAA" : "",
  171. (status & STS_FATAL) ? " FATAL" : "",
  172. (status & STS_FLR) ? " FLR" : "",
  173. (status & STS_PCD) ? " PCD" : "",
  174. (status & STS_ERR) ? " ERR" : "",
  175. (status & STS_INT) ? " INT" : ""
  176. );
  177. }
  178. static int __maybe_unused
  179. dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable)
  180. {
  181. return scnprintf (buf, len,
  182. "%s%sintrenable %02x%s%s%s%s%s%s%s",
  183. label, label [0] ? " " : "", enable,
  184. (enable & STS_PPCE_MASK) ? " PPCE" : "",
  185. (enable & STS_IAA) ? " IAA" : "",
  186. (enable & STS_FATAL) ? " FATAL" : "",
  187. (enable & STS_FLR) ? " FLR" : "",
  188. (enable & STS_PCD) ? " PCD" : "",
  189. (enable & STS_ERR) ? " ERR" : "",
  190. (enable & STS_INT) ? " INT" : ""
  191. );
  192. }
  193. static const char *const fls_strings [] =
  194. { "1024", "512", "256", "??" };
  195. static int
  196. dbg_command_buf (char *buf, unsigned len, const char *label, u32 command)
  197. {
  198. return scnprintf (buf, len,
  199. "%s%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s "
  200. "period=%s%s %s",
  201. label, label [0] ? " " : "", command,
  202. (command & CMD_HIRD) ? " HIRD" : "",
  203. (command & CMD_PPCEE) ? " PPCEE" : "",
  204. (command & CMD_FSP) ? " FSP" : "",
  205. (command & CMD_ASPE) ? " ASPE" : "",
  206. (command & CMD_PSPE) ? " PSPE" : "",
  207. (command & CMD_PARK) ? " park" : "(park)",
  208. CMD_PARK_CNT (command),
  209. (command >> 16) & 0x3f,
  210. (command & CMD_LRESET) ? " LReset" : "",
  211. (command & CMD_IAAD) ? " IAAD" : "",
  212. (command & CMD_ASE) ? " Async" : "",
  213. (command & CMD_PSE) ? " Periodic" : "",
  214. fls_strings [(command >> 2) & 0x3],
  215. (command & CMD_RESET) ? " Reset" : "",
  216. (command & CMD_RUN) ? "RUN" : "HALT"
  217. );
  218. }
  219. static int
  220. dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
  221. {
  222. char *sig;
  223. /* signaling state */
  224. switch (status & (3 << 10)) {
  225. case 0 << 10: sig = "se0"; break;
  226. case 1 << 10: sig = "k"; break; /* low speed */
  227. case 2 << 10: sig = "j"; break;
  228. default: sig = "?"; break;
  229. }
  230. return scnprintf (buf, len,
  231. "%s%sport:%d status %06x %d %s%s%s%s%s%s "
  232. "sig=%s%s%s%s%s%s%s%s%s%s%s",
  233. label, label [0] ? " " : "", port, status,
  234. status>>25,/*device address */
  235. (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ACK ?
  236. " ACK" : "",
  237. (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_NYET ?
  238. " NYET" : "",
  239. (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_STALL ?
  240. " STALL" : "",
  241. (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ERR ?
  242. " ERR" : "",
  243. (status & PORT_POWER) ? " POWER" : "",
  244. (status & PORT_OWNER) ? " OWNER" : "",
  245. sig,
  246. (status & PORT_LPM) ? " LPM" : "",
  247. (status & PORT_RESET) ? " RESET" : "",
  248. (status & PORT_SUSPEND) ? " SUSPEND" : "",
  249. (status & PORT_RESUME) ? " RESUME" : "",
  250. (status & PORT_OCC) ? " OCC" : "",
  251. (status & PORT_OC) ? " OC" : "",
  252. (status & PORT_PEC) ? " PEC" : "",
  253. (status & PORT_PE) ? " PE" : "",
  254. (status & PORT_CSC) ? " CSC" : "",
  255. (status & PORT_CONNECT) ? " CONNECT" : "");
  256. }
  257. #else
  258. static inline void __maybe_unused
  259. dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
  260. {}
  261. static inline int __maybe_unused
  262. dbg_status_buf (char *buf, unsigned len, const char *label, u32 status)
  263. { return 0; }
  264. static inline int __maybe_unused
  265. dbg_command_buf (char *buf, unsigned len, const char *label, u32 command)
  266. { return 0; }
  267. static inline int __maybe_unused
  268. dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable)
  269. { return 0; }
  270. static inline int __maybe_unused
  271. dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
  272. { return 0; }
  273. #endif /* DEBUG || CONFIG_DYNAMIC_DEBUG */
  274. /* functions have the "wrong" filename when they're output... */
  275. #define dbg_status(ehci, label, status) { \
  276. char _buf [80]; \
  277. dbg_status_buf (_buf, sizeof _buf, label, status); \
  278. ehci_dbg (ehci, "%s\n", _buf); \
  279. }
  280. #define dbg_cmd(ehci, label, command) { \
  281. char _buf [80]; \
  282. dbg_command_buf (_buf, sizeof _buf, label, command); \
  283. ehci_dbg (ehci, "%s\n", _buf); \
  284. }
  285. #define dbg_port(ehci, label, port, status) { \
  286. char _buf [80]; \
  287. dbg_port_buf (_buf, sizeof _buf, label, port, status); \
  288. ehci_dbg (ehci, "%s\n", _buf); \
  289. }
  290. /*-------------------------------------------------------------------------*/
  291. #ifdef STUB_DEBUG_FILES
  292. static inline void create_debug_files (struct ehci_hcd *bus) { }
  293. static inline void remove_debug_files (struct ehci_hcd *bus) { }
  294. #else
  295. /* troubleshooting help: expose state in debugfs */
  296. static int debug_async_open(struct inode *, struct file *);
  297. static int debug_bandwidth_open(struct inode *, struct file *);
  298. static int debug_periodic_open(struct inode *, struct file *);
  299. static int debug_registers_open(struct inode *, struct file *);
  300. static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
  301. static int debug_close(struct inode *, struct file *);
  302. static const struct file_operations debug_async_fops = {
  303. .owner = THIS_MODULE,
  304. .open = debug_async_open,
  305. .read = debug_output,
  306. .release = debug_close,
  307. .llseek = default_llseek,
  308. };
  309. static const struct file_operations debug_bandwidth_fops = {
  310. .owner = THIS_MODULE,
  311. .open = debug_bandwidth_open,
  312. .read = debug_output,
  313. .release = debug_close,
  314. .llseek = default_llseek,
  315. };
  316. static const struct file_operations debug_periodic_fops = {
  317. .owner = THIS_MODULE,
  318. .open = debug_periodic_open,
  319. .read = debug_output,
  320. .release = debug_close,
  321. .llseek = default_llseek,
  322. };
  323. static const struct file_operations debug_registers_fops = {
  324. .owner = THIS_MODULE,
  325. .open = debug_registers_open,
  326. .read = debug_output,
  327. .release = debug_close,
  328. .llseek = default_llseek,
  329. };
  330. static struct dentry *ehci_debug_root;
  331. struct debug_buffer {
  332. ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
  333. struct usb_bus *bus;
  334. struct mutex mutex; /* protect filling of buffer */
  335. size_t count; /* number of characters filled into buffer */
  336. char *output_buf;
  337. size_t alloc_size;
  338. };
  339. #define speed_char(info1) ({ char tmp; \
  340. switch (info1 & (3 << 12)) { \
  341. case QH_FULL_SPEED: tmp = 'f'; break; \
  342. case QH_LOW_SPEED: tmp = 'l'; break; \
  343. case QH_HIGH_SPEED: tmp = 'h'; break; \
  344. default: tmp = '?'; break; \
  345. } tmp; })
  346. static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
  347. {
  348. __u32 v = hc32_to_cpu(ehci, token);
  349. if (v & QTD_STS_ACTIVE)
  350. return '*';
  351. if (v & QTD_STS_HALT)
  352. return '-';
  353. if (!IS_SHORT_READ (v))
  354. return ' ';
  355. /* tries to advance through hw_alt_next */
  356. return '/';
  357. }
  358. static void qh_lines (
  359. struct ehci_hcd *ehci,
  360. struct ehci_qh *qh,
  361. char **nextp,
  362. unsigned *sizep
  363. )
  364. {
  365. u32 scratch;
  366. u32 hw_curr;
  367. struct list_head *entry;
  368. struct ehci_qtd *td;
  369. unsigned temp;
  370. unsigned size = *sizep;
  371. char *next = *nextp;
  372. char mark;
  373. __le32 list_end = EHCI_LIST_END(ehci);
  374. struct ehci_qh_hw *hw = qh->hw;
  375. if (hw->hw_qtd_next == list_end) /* NEC does this */
  376. mark = '@';
  377. else
  378. mark = token_mark(ehci, hw->hw_token);
  379. if (mark == '/') { /* qh_alt_next controls qh advance? */
  380. if ((hw->hw_alt_next & QTD_MASK(ehci))
  381. == ehci->async->hw->hw_alt_next)
  382. mark = '#'; /* blocked */
  383. else if (hw->hw_alt_next == list_end)
  384. mark = '.'; /* use hw_qtd_next */
  385. /* else alt_next points to some other qtd */
  386. }
  387. scratch = hc32_to_cpup(ehci, &hw->hw_info1);
  388. hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0;
  389. temp = scnprintf (next, size,
  390. "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)",
  391. qh, scratch & 0x007f,
  392. speed_char (scratch),
  393. (scratch >> 8) & 0x000f,
  394. scratch, hc32_to_cpup(ehci, &hw->hw_info2),
  395. hc32_to_cpup(ehci, &hw->hw_token), mark,
  396. (cpu_to_hc32(ehci, QTD_TOGGLE) & hw->hw_token)
  397. ? "data1" : "data0",
  398. (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f);
  399. size -= temp;
  400. next += temp;
  401. /* hc may be modifying the list as we read it ... */
  402. list_for_each (entry, &qh->qtd_list) {
  403. td = list_entry (entry, struct ehci_qtd, qtd_list);
  404. scratch = hc32_to_cpup(ehci, &td->hw_token);
  405. mark = ' ';
  406. if (hw_curr == td->qtd_dma)
  407. mark = '*';
  408. else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma))
  409. mark = '+';
  410. else if (QTD_LENGTH (scratch)) {
  411. if (td->hw_alt_next == ehci->async->hw->hw_alt_next)
  412. mark = '#';
  413. else if (td->hw_alt_next != list_end)
  414. mark = '/';
  415. }
  416. temp = snprintf (next, size,
  417. "\n\t%p%c%s len=%d %08x urb %p",
  418. td, mark, ({ char *tmp;
  419. switch ((scratch>>8)&0x03) {
  420. case 0: tmp = "out"; break;
  421. case 1: tmp = "in"; break;
  422. case 2: tmp = "setup"; break;
  423. default: tmp = "?"; break;
  424. } tmp;}),
  425. (scratch >> 16) & 0x7fff,
  426. scratch,
  427. td->urb);
  428. if (size < temp)
  429. temp = size;
  430. size -= temp;
  431. next += temp;
  432. if (temp == size)
  433. goto done;
  434. }
  435. temp = snprintf (next, size, "\n");
  436. if (size < temp)
  437. temp = size;
  438. size -= temp;
  439. next += temp;
  440. done:
  441. *sizep = size;
  442. *nextp = next;
  443. }
  444. static ssize_t fill_async_buffer(struct debug_buffer *buf)
  445. {
  446. struct usb_hcd *hcd;
  447. struct ehci_hcd *ehci;
  448. unsigned long flags;
  449. unsigned temp, size;
  450. char *next;
  451. struct ehci_qh *qh;
  452. hcd = bus_to_hcd(buf->bus);
  453. ehci = hcd_to_ehci (hcd);
  454. next = buf->output_buf;
  455. size = buf->alloc_size;
  456. *next = 0;
  457. /* dumps a snapshot of the async schedule.
  458. * usually empty except for long-term bulk reads, or head.
  459. * one QH per line, and TDs we know about
  460. */
  461. spin_lock_irqsave (&ehci->lock, flags);
  462. for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
  463. qh_lines (ehci, qh, &next, &size);
  464. if (!list_empty(&ehci->async_unlink) && size > 0) {
  465. temp = scnprintf(next, size, "\nunlink =\n");
  466. size -= temp;
  467. next += temp;
  468. list_for_each_entry(qh, &ehci->async_unlink, unlink_node) {
  469. if (size <= 0)
  470. break;
  471. qh_lines(ehci, qh, &next, &size);
  472. }
  473. }
  474. spin_unlock_irqrestore (&ehci->lock, flags);
  475. return strlen(buf->output_buf);
  476. }
  477. static ssize_t fill_bandwidth_buffer(struct debug_buffer *buf)
  478. {
  479. struct ehci_hcd *ehci;
  480. struct ehci_tt *tt;
  481. struct ehci_per_sched *ps;
  482. unsigned temp, size;
  483. char *next;
  484. unsigned i;
  485. u8 *bw;
  486. u16 *bf;
  487. u8 budget[EHCI_BANDWIDTH_SIZE];
  488. ehci = hcd_to_ehci(bus_to_hcd(buf->bus));
  489. next = buf->output_buf;
  490. size = buf->alloc_size;
  491. *next = 0;
  492. spin_lock_irq(&ehci->lock);
  493. /* Dump the HS bandwidth table */
  494. temp = scnprintf(next, size,
  495. "HS bandwidth allocation (us per microframe)\n");
  496. size -= temp;
  497. next += temp;
  498. for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
  499. bw = &ehci->bandwidth[i];
  500. temp = scnprintf(next, size,
  501. "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
  502. i, bw[0], bw[1], bw[2], bw[3],
  503. bw[4], bw[5], bw[6], bw[7]);
  504. size -= temp;
  505. next += temp;
  506. }
  507. /* Dump all the FS/LS tables */
  508. list_for_each_entry(tt, &ehci->tt_list, tt_list) {
  509. temp = scnprintf(next, size,
  510. "\nTT %s port %d FS/LS bandwidth allocation (us per frame)\n",
  511. dev_name(&tt->usb_tt->hub->dev),
  512. tt->tt_port + !!tt->usb_tt->multi);
  513. size -= temp;
  514. next += temp;
  515. bf = tt->bandwidth;
  516. temp = scnprintf(next, size,
  517. " %5u%5u%5u%5u%5u%5u%5u%5u\n",
  518. bf[0], bf[1], bf[2], bf[3],
  519. bf[4], bf[5], bf[6], bf[7]);
  520. size -= temp;
  521. next += temp;
  522. temp = scnprintf(next, size,
  523. "FS/LS budget (us per microframe)\n");
  524. size -= temp;
  525. next += temp;
  526. compute_tt_budget(budget, tt);
  527. for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
  528. bw = &budget[i];
  529. temp = scnprintf(next, size,
  530. "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
  531. i, bw[0], bw[1], bw[2], bw[3],
  532. bw[4], bw[5], bw[6], bw[7]);
  533. size -= temp;
  534. next += temp;
  535. }
  536. list_for_each_entry(ps, &tt->ps_list, ps_list) {
  537. temp = scnprintf(next, size,
  538. "%s ep %02x: %4u @ %2u.%u+%u mask %04x\n",
  539. dev_name(&ps->udev->dev),
  540. ps->ep->desc.bEndpointAddress,
  541. ps->tt_usecs,
  542. ps->bw_phase, ps->phase_uf,
  543. ps->bw_period, ps->cs_mask);
  544. size -= temp;
  545. next += temp;
  546. }
  547. }
  548. spin_unlock_irq(&ehci->lock);
  549. return next - buf->output_buf;
  550. }
  551. #define DBG_SCHED_LIMIT 64
  552. static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
  553. {
  554. struct usb_hcd *hcd;
  555. struct ehci_hcd *ehci;
  556. unsigned long flags;
  557. union ehci_shadow p, *seen;
  558. unsigned temp, size, seen_count;
  559. char *next;
  560. unsigned i;
  561. __hc32 tag;
  562. if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC)))
  563. return 0;
  564. seen_count = 0;
  565. hcd = bus_to_hcd(buf->bus);
  566. ehci = hcd_to_ehci (hcd);
  567. next = buf->output_buf;
  568. size = buf->alloc_size;
  569. temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size);
  570. size -= temp;
  571. next += temp;
  572. /* dump a snapshot of the periodic schedule.
  573. * iso changes, interrupt usually doesn't.
  574. */
  575. spin_lock_irqsave (&ehci->lock, flags);
  576. for (i = 0; i < ehci->periodic_size; i++) {
  577. p = ehci->pshadow [i];
  578. if (likely (!p.ptr))
  579. continue;
  580. tag = Q_NEXT_TYPE(ehci, ehci->periodic [i]);
  581. temp = scnprintf (next, size, "%4d: ", i);
  582. size -= temp;
  583. next += temp;
  584. do {
  585. struct ehci_qh_hw *hw;
  586. switch (hc32_to_cpu(ehci, tag)) {
  587. case Q_TYPE_QH:
  588. hw = p.qh->hw;
  589. temp = scnprintf (next, size, " qh%d-%04x/%p",
  590. p.qh->ps.period,
  591. hc32_to_cpup(ehci,
  592. &hw->hw_info2)
  593. /* uframe masks */
  594. & (QH_CMASK | QH_SMASK),
  595. p.qh);
  596. size -= temp;
  597. next += temp;
  598. /* don't repeat what follows this qh */
  599. for (temp = 0; temp < seen_count; temp++) {
  600. if (seen [temp].ptr != p.ptr)
  601. continue;
  602. if (p.qh->qh_next.ptr) {
  603. temp = scnprintf (next, size,
  604. " ...");
  605. size -= temp;
  606. next += temp;
  607. }
  608. break;
  609. }
  610. /* show more info the first time around */
  611. if (temp == seen_count) {
  612. u32 scratch = hc32_to_cpup(ehci,
  613. &hw->hw_info1);
  614. struct ehci_qtd *qtd;
  615. char *type = "";
  616. /* count tds, get ep direction */
  617. temp = 0;
  618. list_for_each_entry (qtd,
  619. &p.qh->qtd_list,
  620. qtd_list) {
  621. temp++;
  622. switch (0x03 & (hc32_to_cpu(
  623. ehci,
  624. qtd->hw_token) >> 8)) {
  625. case 0: type = "out"; continue;
  626. case 1: type = "in"; continue;
  627. }
  628. }
  629. temp = scnprintf (next, size,
  630. " (%c%d ep%d%s "
  631. "[%d/%d] q%d p%d)",
  632. speed_char (scratch),
  633. scratch & 0x007f,
  634. (scratch >> 8) & 0x000f, type,
  635. p.qh->ps.usecs,
  636. p.qh->ps.c_usecs,
  637. temp,
  638. 0x7ff & (scratch >> 16));
  639. if (seen_count < DBG_SCHED_LIMIT)
  640. seen [seen_count++].qh = p.qh;
  641. } else
  642. temp = 0;
  643. tag = Q_NEXT_TYPE(ehci, hw->hw_next);
  644. p = p.qh->qh_next;
  645. break;
  646. case Q_TYPE_FSTN:
  647. temp = scnprintf (next, size,
  648. " fstn-%8x/%p", p.fstn->hw_prev,
  649. p.fstn);
  650. tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next);
  651. p = p.fstn->fstn_next;
  652. break;
  653. case Q_TYPE_ITD:
  654. temp = scnprintf (next, size,
  655. " itd/%p", p.itd);
  656. tag = Q_NEXT_TYPE(ehci, p.itd->hw_next);
  657. p = p.itd->itd_next;
  658. break;
  659. case Q_TYPE_SITD:
  660. temp = scnprintf (next, size,
  661. " sitd%d-%04x/%p",
  662. p.sitd->stream->ps.period,
  663. hc32_to_cpup(ehci, &p.sitd->hw_uframe)
  664. & 0x0000ffff,
  665. p.sitd);
  666. tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next);
  667. p = p.sitd->sitd_next;
  668. break;
  669. }
  670. size -= temp;
  671. next += temp;
  672. } while (p.ptr);
  673. temp = scnprintf (next, size, "\n");
  674. size -= temp;
  675. next += temp;
  676. }
  677. spin_unlock_irqrestore (&ehci->lock, flags);
  678. kfree (seen);
  679. return buf->alloc_size - size;
  680. }
  681. #undef DBG_SCHED_LIMIT
  682. static const char *rh_state_string(struct ehci_hcd *ehci)
  683. {
  684. switch (ehci->rh_state) {
  685. case EHCI_RH_HALTED:
  686. return "halted";
  687. case EHCI_RH_SUSPENDED:
  688. return "suspended";
  689. case EHCI_RH_RUNNING:
  690. return "running";
  691. case EHCI_RH_STOPPING:
  692. return "stopping";
  693. }
  694. return "?";
  695. }
  696. static ssize_t fill_registers_buffer(struct debug_buffer *buf)
  697. {
  698. struct usb_hcd *hcd;
  699. struct ehci_hcd *ehci;
  700. unsigned long flags;
  701. unsigned temp, size, i;
  702. char *next, scratch [80];
  703. static char fmt [] = "%*s\n";
  704. static char label [] = "";
  705. hcd = bus_to_hcd(buf->bus);
  706. ehci = hcd_to_ehci (hcd);
  707. next = buf->output_buf;
  708. size = buf->alloc_size;
  709. spin_lock_irqsave (&ehci->lock, flags);
  710. if (!HCD_HW_ACCESSIBLE(hcd)) {
  711. size = scnprintf (next, size,
  712. "bus %s, device %s\n"
  713. "%s\n"
  714. "SUSPENDED (no register access)\n",
  715. hcd->self.controller->bus->name,
  716. dev_name(hcd->self.controller),
  717. hcd->product_desc);
  718. goto done;
  719. }
  720. /* Capability Registers */
  721. i = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  722. temp = scnprintf (next, size,
  723. "bus %s, device %s\n"
  724. "%s\n"
  725. "EHCI %x.%02x, rh state %s\n",
  726. hcd->self.controller->bus->name,
  727. dev_name(hcd->self.controller),
  728. hcd->product_desc,
  729. i >> 8, i & 0x0ff, rh_state_string(ehci));
  730. size -= temp;
  731. next += temp;
  732. #ifdef CONFIG_PCI
  733. /* EHCI 0.96 and later may have "extended capabilities" */
  734. if (hcd->self.controller->bus == &pci_bus_type) {
  735. struct pci_dev *pdev;
  736. u32 offset, cap, cap2;
  737. unsigned count = 256/4;
  738. pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
  739. offset = HCC_EXT_CAPS(ehci_readl(ehci,
  740. &ehci->caps->hcc_params));
  741. while (offset && count--) {
  742. pci_read_config_dword (pdev, offset, &cap);
  743. switch (cap & 0xff) {
  744. case 1:
  745. temp = scnprintf (next, size,
  746. "ownership %08x%s%s\n", cap,
  747. (cap & (1 << 24)) ? " linux" : "",
  748. (cap & (1 << 16)) ? " firmware" : "");
  749. size -= temp;
  750. next += temp;
  751. offset += 4;
  752. pci_read_config_dword (pdev, offset, &cap2);
  753. temp = scnprintf (next, size,
  754. "SMI sts/enable 0x%08x\n", cap2);
  755. size -= temp;
  756. next += temp;
  757. break;
  758. case 0: /* illegal reserved capability */
  759. cap = 0;
  760. /* FALLTHROUGH */
  761. default: /* unknown */
  762. break;
  763. }
  764. temp = (cap >> 8) & 0xff;
  765. }
  766. }
  767. #endif
  768. // FIXME interpret both types of params
  769. i = ehci_readl(ehci, &ehci->caps->hcs_params);
  770. temp = scnprintf (next, size, "structural params 0x%08x\n", i);
  771. size -= temp;
  772. next += temp;
  773. i = ehci_readl(ehci, &ehci->caps->hcc_params);
  774. temp = scnprintf (next, size, "capability params 0x%08x\n", i);
  775. size -= temp;
  776. next += temp;
  777. /* Operational Registers */
  778. temp = dbg_status_buf (scratch, sizeof scratch, label,
  779. ehci_readl(ehci, &ehci->regs->status));
  780. temp = scnprintf (next, size, fmt, temp, scratch);
  781. size -= temp;
  782. next += temp;
  783. temp = dbg_command_buf (scratch, sizeof scratch, label,
  784. ehci_readl(ehci, &ehci->regs->command));
  785. temp = scnprintf (next, size, fmt, temp, scratch);
  786. size -= temp;
  787. next += temp;
  788. temp = dbg_intr_buf (scratch, sizeof scratch, label,
  789. ehci_readl(ehci, &ehci->regs->intr_enable));
  790. temp = scnprintf (next, size, fmt, temp, scratch);
  791. size -= temp;
  792. next += temp;
  793. temp = scnprintf (next, size, "uframe %04x\n",
  794. ehci_read_frame_index(ehci));
  795. size -= temp;
  796. next += temp;
  797. for (i = 1; i <= HCS_N_PORTS (ehci->hcs_params); i++) {
  798. temp = dbg_port_buf (scratch, sizeof scratch, label, i,
  799. ehci_readl(ehci,
  800. &ehci->regs->port_status[i - 1]));
  801. temp = scnprintf (next, size, fmt, temp, scratch);
  802. size -= temp;
  803. next += temp;
  804. if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) {
  805. temp = scnprintf (next, size,
  806. " debug control %08x\n",
  807. ehci_readl(ehci,
  808. &ehci->debug->control));
  809. size -= temp;
  810. next += temp;
  811. }
  812. }
  813. if (!list_empty(&ehci->async_unlink)) {
  814. temp = scnprintf(next, size, "async unlink qh %p\n",
  815. list_first_entry(&ehci->async_unlink,
  816. struct ehci_qh, unlink_node));
  817. size -= temp;
  818. next += temp;
  819. }
  820. #ifdef EHCI_STATS
  821. temp = scnprintf (next, size,
  822. "irq normal %ld err %ld iaa %ld (lost %ld)\n",
  823. ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
  824. ehci->stats.lost_iaa);
  825. size -= temp;
  826. next += temp;
  827. temp = scnprintf (next, size, "complete %ld unlink %ld\n",
  828. ehci->stats.complete, ehci->stats.unlink);
  829. size -= temp;
  830. next += temp;
  831. #endif
  832. done:
  833. spin_unlock_irqrestore (&ehci->lock, flags);
  834. return buf->alloc_size - size;
  835. }
  836. static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
  837. ssize_t (*fill_func)(struct debug_buffer *))
  838. {
  839. struct debug_buffer *buf;
  840. buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
  841. if (buf) {
  842. buf->bus = bus;
  843. buf->fill_func = fill_func;
  844. mutex_init(&buf->mutex);
  845. buf->alloc_size = PAGE_SIZE;
  846. }
  847. return buf;
  848. }
  849. static int fill_buffer(struct debug_buffer *buf)
  850. {
  851. int ret = 0;
  852. if (!buf->output_buf)
  853. buf->output_buf = vmalloc(buf->alloc_size);
  854. if (!buf->output_buf) {
  855. ret = -ENOMEM;
  856. goto out;
  857. }
  858. ret = buf->fill_func(buf);
  859. if (ret >= 0) {
  860. buf->count = ret;
  861. ret = 0;
  862. }
  863. out:
  864. return ret;
  865. }
  866. static ssize_t debug_output(struct file *file, char __user *user_buf,
  867. size_t len, loff_t *offset)
  868. {
  869. struct debug_buffer *buf = file->private_data;
  870. int ret = 0;
  871. mutex_lock(&buf->mutex);
  872. if (buf->count == 0) {
  873. ret = fill_buffer(buf);
  874. if (ret != 0) {
  875. mutex_unlock(&buf->mutex);
  876. goto out;
  877. }
  878. }
  879. mutex_unlock(&buf->mutex);
  880. ret = simple_read_from_buffer(user_buf, len, offset,
  881. buf->output_buf, buf->count);
  882. out:
  883. return ret;
  884. }
  885. static int debug_close(struct inode *inode, struct file *file)
  886. {
  887. struct debug_buffer *buf = file->private_data;
  888. if (buf) {
  889. vfree(buf->output_buf);
  890. kfree(buf);
  891. }
  892. return 0;
  893. }
  894. static int debug_async_open(struct inode *inode, struct file *file)
  895. {
  896. file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
  897. return file->private_data ? 0 : -ENOMEM;
  898. }
  899. static int debug_bandwidth_open(struct inode *inode, struct file *file)
  900. {
  901. file->private_data = alloc_buffer(inode->i_private,
  902. fill_bandwidth_buffer);
  903. return file->private_data ? 0 : -ENOMEM;
  904. }
  905. static int debug_periodic_open(struct inode *inode, struct file *file)
  906. {
  907. struct debug_buffer *buf;
  908. buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
  909. if (!buf)
  910. return -ENOMEM;
  911. buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE;
  912. file->private_data = buf;
  913. return 0;
  914. }
  915. static int debug_registers_open(struct inode *inode, struct file *file)
  916. {
  917. file->private_data = alloc_buffer(inode->i_private,
  918. fill_registers_buffer);
  919. return file->private_data ? 0 : -ENOMEM;
  920. }
  921. static inline void create_debug_files (struct ehci_hcd *ehci)
  922. {
  923. struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
  924. ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
  925. if (!ehci->debug_dir)
  926. return;
  927. if (!debugfs_create_file("async", S_IRUGO, ehci->debug_dir, bus,
  928. &debug_async_fops))
  929. goto file_error;
  930. if (!debugfs_create_file("bandwidth", S_IRUGO, ehci->debug_dir, bus,
  931. &debug_bandwidth_fops))
  932. goto file_error;
  933. if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus,
  934. &debug_periodic_fops))
  935. goto file_error;
  936. if (!debugfs_create_file("registers", S_IRUGO, ehci->debug_dir, bus,
  937. &debug_registers_fops))
  938. goto file_error;
  939. return;
  940. file_error:
  941. debugfs_remove_recursive(ehci->debug_dir);
  942. }
  943. static inline void remove_debug_files (struct ehci_hcd *ehci)
  944. {
  945. debugfs_remove_recursive(ehci->debug_dir);
  946. }
  947. #endif /* STUB_DEBUG_FILES */