ehci-dbg.c 29 KB

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