ehci-dbg.c 29 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. #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 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 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 peridic 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 %p 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 %p 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 %p, next %08x, urb %p\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 %p, next %08x, urb %p\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 int debug_lpm_open(struct inode *, struct file *);
  314. static ssize_t debug_lpm_read(struct file *file, char __user *user_buf,
  315. size_t count, loff_t *ppos);
  316. static ssize_t debug_lpm_write(struct file *file, const char __user *buffer,
  317. size_t count, loff_t *ppos);
  318. static int debug_lpm_close(struct inode *inode, struct file *file);
  319. static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
  320. static int debug_close(struct inode *, struct file *);
  321. static const struct file_operations debug_async_fops = {
  322. .owner = THIS_MODULE,
  323. .open = debug_async_open,
  324. .read = debug_output,
  325. .release = debug_close,
  326. .llseek = default_llseek,
  327. };
  328. static const struct file_operations debug_periodic_fops = {
  329. .owner = THIS_MODULE,
  330. .open = debug_periodic_open,
  331. .read = debug_output,
  332. .release = debug_close,
  333. .llseek = default_llseek,
  334. };
  335. static const struct file_operations debug_registers_fops = {
  336. .owner = THIS_MODULE,
  337. .open = debug_registers_open,
  338. .read = debug_output,
  339. .release = debug_close,
  340. .llseek = default_llseek,
  341. };
  342. static const struct file_operations debug_lpm_fops = {
  343. .owner = THIS_MODULE,
  344. .open = debug_lpm_open,
  345. .read = debug_lpm_read,
  346. .write = debug_lpm_write,
  347. .release = debug_lpm_close,
  348. .llseek = noop_llseek,
  349. };
  350. static struct dentry *ehci_debug_root;
  351. struct debug_buffer {
  352. ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
  353. struct usb_bus *bus;
  354. struct mutex mutex; /* protect filling of buffer */
  355. size_t count; /* number of characters filled into buffer */
  356. char *output_buf;
  357. size_t alloc_size;
  358. };
  359. #define speed_char(info1) ({ char tmp; \
  360. switch (info1 & (3 << 12)) { \
  361. case 0 << 12: tmp = 'f'; break; \
  362. case 1 << 12: tmp = 'l'; break; \
  363. case 2 << 12: tmp = 'h'; break; \
  364. default: tmp = '?'; break; \
  365. }; tmp; })
  366. static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
  367. {
  368. __u32 v = hc32_to_cpu(ehci, token);
  369. if (v & QTD_STS_ACTIVE)
  370. return '*';
  371. if (v & QTD_STS_HALT)
  372. return '-';
  373. if (!IS_SHORT_READ (v))
  374. return ' ';
  375. /* tries to advance through hw_alt_next */
  376. return '/';
  377. }
  378. static void qh_lines (
  379. struct ehci_hcd *ehci,
  380. struct ehci_qh *qh,
  381. char **nextp,
  382. unsigned *sizep
  383. )
  384. {
  385. u32 scratch;
  386. u32 hw_curr;
  387. struct list_head *entry;
  388. struct ehci_qtd *td;
  389. unsigned temp;
  390. unsigned size = *sizep;
  391. char *next = *nextp;
  392. char mark;
  393. __le32 list_end = EHCI_LIST_END(ehci);
  394. struct ehci_qh_hw *hw = qh->hw;
  395. if (hw->hw_qtd_next == list_end) /* NEC does this */
  396. mark = '@';
  397. else
  398. mark = token_mark(ehci, hw->hw_token);
  399. if (mark == '/') { /* qh_alt_next controls qh advance? */
  400. if ((hw->hw_alt_next & QTD_MASK(ehci))
  401. == ehci->async->hw->hw_alt_next)
  402. mark = '#'; /* blocked */
  403. else if (hw->hw_alt_next == list_end)
  404. mark = '.'; /* use hw_qtd_next */
  405. /* else alt_next points to some other qtd */
  406. }
  407. scratch = hc32_to_cpup(ehci, &hw->hw_info1);
  408. hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0;
  409. temp = scnprintf (next, size,
  410. "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)",
  411. qh, scratch & 0x007f,
  412. speed_char (scratch),
  413. (scratch >> 8) & 0x000f,
  414. scratch, hc32_to_cpup(ehci, &hw->hw_info2),
  415. hc32_to_cpup(ehci, &hw->hw_token), mark,
  416. (cpu_to_hc32(ehci, QTD_TOGGLE) & hw->hw_token)
  417. ? "data1" : "data0",
  418. (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f);
  419. size -= temp;
  420. next += temp;
  421. /* hc may be modifying the list as we read it ... */
  422. list_for_each (entry, &qh->qtd_list) {
  423. td = list_entry (entry, struct ehci_qtd, qtd_list);
  424. scratch = hc32_to_cpup(ehci, &td->hw_token);
  425. mark = ' ';
  426. if (hw_curr == td->qtd_dma)
  427. mark = '*';
  428. else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma))
  429. mark = '+';
  430. else if (QTD_LENGTH (scratch)) {
  431. if (td->hw_alt_next == ehci->async->hw->hw_alt_next)
  432. mark = '#';
  433. else if (td->hw_alt_next != list_end)
  434. mark = '/';
  435. }
  436. temp = snprintf (next, size,
  437. "\n\t%p%c%s len=%d %08x urb %p",
  438. td, mark, ({ char *tmp;
  439. switch ((scratch>>8)&0x03) {
  440. case 0: tmp = "out"; break;
  441. case 1: tmp = "in"; break;
  442. case 2: tmp = "setup"; break;
  443. default: tmp = "?"; break;
  444. } tmp;}),
  445. (scratch >> 16) & 0x7fff,
  446. scratch,
  447. td->urb);
  448. if (size < temp)
  449. temp = size;
  450. size -= temp;
  451. next += temp;
  452. if (temp == size)
  453. goto done;
  454. }
  455. temp = snprintf (next, size, "\n");
  456. if (size < temp)
  457. temp = size;
  458. size -= temp;
  459. next += temp;
  460. done:
  461. *sizep = size;
  462. *nextp = next;
  463. }
  464. static ssize_t fill_async_buffer(struct debug_buffer *buf)
  465. {
  466. struct usb_hcd *hcd;
  467. struct ehci_hcd *ehci;
  468. unsigned long flags;
  469. unsigned temp, size;
  470. char *next;
  471. struct ehci_qh *qh;
  472. hcd = bus_to_hcd(buf->bus);
  473. ehci = hcd_to_ehci (hcd);
  474. next = buf->output_buf;
  475. size = buf->alloc_size;
  476. *next = 0;
  477. /* dumps a snapshot of the async schedule.
  478. * usually empty except for long-term bulk reads, or head.
  479. * one QH per line, and TDs we know about
  480. */
  481. spin_lock_irqsave (&ehci->lock, flags);
  482. for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
  483. qh_lines (ehci, qh, &next, &size);
  484. if (ehci->reclaim && size > 0) {
  485. temp = scnprintf (next, size, "\nreclaim =\n");
  486. size -= temp;
  487. next += temp;
  488. for (qh = ehci->reclaim; size > 0 && qh; qh = qh->reclaim)
  489. qh_lines (ehci, qh, &next, &size);
  490. }
  491. spin_unlock_irqrestore (&ehci->lock, flags);
  492. return strlen(buf->output_buf);
  493. }
  494. #define DBG_SCHED_LIMIT 64
  495. static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
  496. {
  497. struct usb_hcd *hcd;
  498. struct ehci_hcd *ehci;
  499. unsigned long flags;
  500. union ehci_shadow p, *seen;
  501. unsigned temp, size, seen_count;
  502. char *next;
  503. unsigned i;
  504. __hc32 tag;
  505. if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC)))
  506. return 0;
  507. seen_count = 0;
  508. hcd = bus_to_hcd(buf->bus);
  509. ehci = hcd_to_ehci (hcd);
  510. next = buf->output_buf;
  511. size = buf->alloc_size;
  512. temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size);
  513. size -= temp;
  514. next += temp;
  515. /* dump a snapshot of the periodic schedule.
  516. * iso changes, interrupt usually doesn't.
  517. */
  518. spin_lock_irqsave (&ehci->lock, flags);
  519. for (i = 0; i < ehci->periodic_size; i++) {
  520. p = ehci->pshadow [i];
  521. if (likely (!p.ptr))
  522. continue;
  523. tag = Q_NEXT_TYPE(ehci, ehci->periodic [i]);
  524. temp = scnprintf (next, size, "%4d: ", i);
  525. size -= temp;
  526. next += temp;
  527. do {
  528. struct ehci_qh_hw *hw;
  529. switch (hc32_to_cpu(ehci, tag)) {
  530. case Q_TYPE_QH:
  531. hw = p.qh->hw;
  532. temp = scnprintf (next, size, " qh%d-%04x/%p",
  533. p.qh->period,
  534. hc32_to_cpup(ehci,
  535. &hw->hw_info2)
  536. /* uframe masks */
  537. & (QH_CMASK | QH_SMASK),
  538. p.qh);
  539. size -= temp;
  540. next += temp;
  541. /* don't repeat what follows this qh */
  542. for (temp = 0; temp < seen_count; temp++) {
  543. if (seen [temp].ptr != p.ptr)
  544. continue;
  545. if (p.qh->qh_next.ptr) {
  546. temp = scnprintf (next, size,
  547. " ...");
  548. size -= temp;
  549. next += temp;
  550. }
  551. break;
  552. }
  553. /* show more info the first time around */
  554. if (temp == seen_count) {
  555. u32 scratch = hc32_to_cpup(ehci,
  556. &hw->hw_info1);
  557. struct ehci_qtd *qtd;
  558. char *type = "";
  559. /* count tds, get ep direction */
  560. temp = 0;
  561. list_for_each_entry (qtd,
  562. &p.qh->qtd_list,
  563. qtd_list) {
  564. temp++;
  565. switch (0x03 & (hc32_to_cpu(
  566. ehci,
  567. qtd->hw_token) >> 8)) {
  568. case 0: type = "out"; continue;
  569. case 1: type = "in"; continue;
  570. }
  571. }
  572. temp = scnprintf (next, size,
  573. " (%c%d ep%d%s "
  574. "[%d/%d] q%d p%d)",
  575. speed_char (scratch),
  576. scratch & 0x007f,
  577. (scratch >> 8) & 0x000f, type,
  578. p.qh->usecs, p.qh->c_usecs,
  579. temp,
  580. 0x7ff & (scratch >> 16));
  581. if (seen_count < DBG_SCHED_LIMIT)
  582. seen [seen_count++].qh = p.qh;
  583. } else
  584. temp = 0;
  585. if (p.qh) {
  586. tag = Q_NEXT_TYPE(ehci, hw->hw_next);
  587. p = p.qh->qh_next;
  588. }
  589. break;
  590. case Q_TYPE_FSTN:
  591. temp = scnprintf (next, size,
  592. " fstn-%8x/%p", p.fstn->hw_prev,
  593. p.fstn);
  594. tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next);
  595. p = p.fstn->fstn_next;
  596. break;
  597. case Q_TYPE_ITD:
  598. temp = scnprintf (next, size,
  599. " itd/%p", p.itd);
  600. tag = Q_NEXT_TYPE(ehci, p.itd->hw_next);
  601. p = p.itd->itd_next;
  602. break;
  603. case Q_TYPE_SITD:
  604. temp = scnprintf (next, size,
  605. " sitd%d-%04x/%p",
  606. p.sitd->stream->interval,
  607. hc32_to_cpup(ehci, &p.sitd->hw_uframe)
  608. & 0x0000ffff,
  609. p.sitd);
  610. tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next);
  611. p = p.sitd->sitd_next;
  612. break;
  613. }
  614. size -= temp;
  615. next += temp;
  616. } while (p.ptr);
  617. temp = scnprintf (next, size, "\n");
  618. size -= temp;
  619. next += temp;
  620. }
  621. spin_unlock_irqrestore (&ehci->lock, flags);
  622. kfree (seen);
  623. return buf->alloc_size - size;
  624. }
  625. #undef DBG_SCHED_LIMIT
  626. static ssize_t fill_registers_buffer(struct debug_buffer *buf)
  627. {
  628. struct usb_hcd *hcd;
  629. struct ehci_hcd *ehci;
  630. unsigned long flags;
  631. unsigned temp, size, i;
  632. char *next, scratch [80];
  633. static char fmt [] = "%*s\n";
  634. static char label [] = "";
  635. hcd = bus_to_hcd(buf->bus);
  636. ehci = hcd_to_ehci (hcd);
  637. next = buf->output_buf;
  638. size = buf->alloc_size;
  639. spin_lock_irqsave (&ehci->lock, flags);
  640. if (!HCD_HW_ACCESSIBLE(hcd)) {
  641. size = scnprintf (next, size,
  642. "bus %s, device %s\n"
  643. "%s\n"
  644. "SUSPENDED (no register access)\n",
  645. hcd->self.controller->bus->name,
  646. dev_name(hcd->self.controller),
  647. hcd->product_desc);
  648. goto done;
  649. }
  650. /* Capability Registers */
  651. i = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  652. temp = scnprintf (next, size,
  653. "bus %s, device %s\n"
  654. "%s\n"
  655. "EHCI %x.%02x, hcd state %d\n",
  656. hcd->self.controller->bus->name,
  657. dev_name(hcd->self.controller),
  658. hcd->product_desc,
  659. i >> 8, i & 0x0ff, hcd->state);
  660. size -= temp;
  661. next += temp;
  662. #ifdef CONFIG_PCI
  663. /* EHCI 0.96 and later may have "extended capabilities" */
  664. if (hcd->self.controller->bus == &pci_bus_type) {
  665. struct pci_dev *pdev;
  666. u32 offset, cap, cap2;
  667. unsigned count = 256/4;
  668. pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
  669. offset = HCC_EXT_CAPS(ehci_readl(ehci,
  670. &ehci->caps->hcc_params));
  671. while (offset && count--) {
  672. pci_read_config_dword (pdev, offset, &cap);
  673. switch (cap & 0xff) {
  674. case 1:
  675. temp = scnprintf (next, size,
  676. "ownership %08x%s%s\n", cap,
  677. (cap & (1 << 24)) ? " linux" : "",
  678. (cap & (1 << 16)) ? " firmware" : "");
  679. size -= temp;
  680. next += temp;
  681. offset += 4;
  682. pci_read_config_dword (pdev, offset, &cap2);
  683. temp = scnprintf (next, size,
  684. "SMI sts/enable 0x%08x\n", cap2);
  685. size -= temp;
  686. next += temp;
  687. break;
  688. case 0: /* illegal reserved capability */
  689. cap = 0;
  690. /* FALLTHROUGH */
  691. default: /* unknown */
  692. break;
  693. }
  694. temp = (cap >> 8) & 0xff;
  695. }
  696. }
  697. #endif
  698. // FIXME interpret both types of params
  699. i = ehci_readl(ehci, &ehci->caps->hcs_params);
  700. temp = scnprintf (next, size, "structural params 0x%08x\n", i);
  701. size -= temp;
  702. next += temp;
  703. i = ehci_readl(ehci, &ehci->caps->hcc_params);
  704. temp = scnprintf (next, size, "capability params 0x%08x\n", i);
  705. size -= temp;
  706. next += temp;
  707. /* Operational Registers */
  708. temp = dbg_status_buf (scratch, sizeof scratch, label,
  709. ehci_readl(ehci, &ehci->regs->status));
  710. temp = scnprintf (next, size, fmt, temp, scratch);
  711. size -= temp;
  712. next += temp;
  713. temp = dbg_command_buf (scratch, sizeof scratch, label,
  714. ehci_readl(ehci, &ehci->regs->command));
  715. temp = scnprintf (next, size, fmt, temp, scratch);
  716. size -= temp;
  717. next += temp;
  718. temp = dbg_intr_buf (scratch, sizeof scratch, label,
  719. ehci_readl(ehci, &ehci->regs->intr_enable));
  720. temp = scnprintf (next, size, fmt, temp, scratch);
  721. size -= temp;
  722. next += temp;
  723. temp = scnprintf (next, size, "uframe %04x\n",
  724. ehci_read_frame_index(ehci));
  725. size -= temp;
  726. next += temp;
  727. for (i = 1; i <= HCS_N_PORTS (ehci->hcs_params); i++) {
  728. temp = dbg_port_buf (scratch, sizeof scratch, label, i,
  729. ehci_readl(ehci,
  730. &ehci->regs->port_status[i - 1]));
  731. temp = scnprintf (next, size, fmt, temp, scratch);
  732. size -= temp;
  733. next += temp;
  734. if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) {
  735. temp = scnprintf (next, size,
  736. " debug control %08x\n",
  737. ehci_readl(ehci,
  738. &ehci->debug->control));
  739. size -= temp;
  740. next += temp;
  741. }
  742. }
  743. if (ehci->reclaim) {
  744. temp = scnprintf(next, size, "reclaim qh %p\n", ehci->reclaim);
  745. size -= temp;
  746. next += temp;
  747. }
  748. #ifdef EHCI_STATS
  749. temp = scnprintf (next, size,
  750. "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
  751. ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
  752. ehci->stats.lost_iaa);
  753. size -= temp;
  754. next += temp;
  755. temp = scnprintf (next, size, "complete %ld unlink %ld\n",
  756. ehci->stats.complete, ehci->stats.unlink);
  757. size -= temp;
  758. next += temp;
  759. #endif
  760. done:
  761. spin_unlock_irqrestore (&ehci->lock, flags);
  762. return buf->alloc_size - size;
  763. }
  764. static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
  765. ssize_t (*fill_func)(struct debug_buffer *))
  766. {
  767. struct debug_buffer *buf;
  768. buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
  769. if (buf) {
  770. buf->bus = bus;
  771. buf->fill_func = fill_func;
  772. mutex_init(&buf->mutex);
  773. buf->alloc_size = PAGE_SIZE;
  774. }
  775. return buf;
  776. }
  777. static int fill_buffer(struct debug_buffer *buf)
  778. {
  779. int ret = 0;
  780. if (!buf->output_buf)
  781. buf->output_buf = vmalloc(buf->alloc_size);
  782. if (!buf->output_buf) {
  783. ret = -ENOMEM;
  784. goto out;
  785. }
  786. ret = buf->fill_func(buf);
  787. if (ret >= 0) {
  788. buf->count = ret;
  789. ret = 0;
  790. }
  791. out:
  792. return ret;
  793. }
  794. static ssize_t debug_output(struct file *file, char __user *user_buf,
  795. size_t len, loff_t *offset)
  796. {
  797. struct debug_buffer *buf = file->private_data;
  798. int ret = 0;
  799. mutex_lock(&buf->mutex);
  800. if (buf->count == 0) {
  801. ret = fill_buffer(buf);
  802. if (ret != 0) {
  803. mutex_unlock(&buf->mutex);
  804. goto out;
  805. }
  806. }
  807. mutex_unlock(&buf->mutex);
  808. ret = simple_read_from_buffer(user_buf, len, offset,
  809. buf->output_buf, buf->count);
  810. out:
  811. return ret;
  812. }
  813. static int debug_close(struct inode *inode, struct file *file)
  814. {
  815. struct debug_buffer *buf = file->private_data;
  816. if (buf) {
  817. vfree(buf->output_buf);
  818. kfree(buf);
  819. }
  820. return 0;
  821. }
  822. static int debug_async_open(struct inode *inode, struct file *file)
  823. {
  824. file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
  825. return file->private_data ? 0 : -ENOMEM;
  826. }
  827. static int debug_periodic_open(struct inode *inode, struct file *file)
  828. {
  829. struct debug_buffer *buf;
  830. buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
  831. if (!buf)
  832. return -ENOMEM;
  833. buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE;
  834. file->private_data = buf;
  835. return 0;
  836. }
  837. static int debug_registers_open(struct inode *inode, struct file *file)
  838. {
  839. file->private_data = alloc_buffer(inode->i_private,
  840. fill_registers_buffer);
  841. return file->private_data ? 0 : -ENOMEM;
  842. }
  843. static int debug_lpm_open(struct inode *inode, struct file *file)
  844. {
  845. file->private_data = inode->i_private;
  846. return 0;
  847. }
  848. static int debug_lpm_close(struct inode *inode, struct file *file)
  849. {
  850. return 0;
  851. }
  852. static ssize_t debug_lpm_read(struct file *file, char __user *user_buf,
  853. size_t count, loff_t *ppos)
  854. {
  855. /* TODO: show lpm stats */
  856. return 0;
  857. }
  858. static ssize_t debug_lpm_write(struct file *file, const char __user *user_buf,
  859. size_t count, loff_t *ppos)
  860. {
  861. struct usb_hcd *hcd;
  862. struct ehci_hcd *ehci;
  863. char buf[50];
  864. size_t len;
  865. u32 temp;
  866. unsigned long port;
  867. u32 __iomem *portsc ;
  868. u32 params;
  869. hcd = bus_to_hcd(file->private_data);
  870. ehci = hcd_to_ehci(hcd);
  871. len = min(count, sizeof(buf) - 1);
  872. if (copy_from_user(buf, user_buf, len))
  873. return -EFAULT;
  874. buf[len] = '\0';
  875. if (len > 0 && buf[len - 1] == '\n')
  876. buf[len - 1] = '\0';
  877. if (strncmp(buf, "enable", 5) == 0) {
  878. if (strict_strtoul(buf + 7, 10, &port))
  879. return -EINVAL;
  880. params = ehci_readl(ehci, &ehci->caps->hcs_params);
  881. if (port > HCS_N_PORTS(params)) {
  882. ehci_dbg(ehci, "ERR: LPM on bad port %lu\n", port);
  883. return -ENODEV;
  884. }
  885. portsc = &ehci->regs->port_status[port-1];
  886. temp = ehci_readl(ehci, portsc);
  887. if (!(temp & PORT_DEV_ADDR)) {
  888. ehci_dbg(ehci, "LPM: no device attached\n");
  889. return -ENODEV;
  890. }
  891. temp |= PORT_LPM;
  892. ehci_writel(ehci, temp, portsc);
  893. printk(KERN_INFO "force enable LPM for port %lu\n", port);
  894. } else if (strncmp(buf, "hird=", 5) == 0) {
  895. unsigned long hird;
  896. if (strict_strtoul(buf + 5, 16, &hird))
  897. return -EINVAL;
  898. printk(KERN_INFO "setting hird %s %lu\n", buf + 6, hird);
  899. temp = ehci_readl(ehci, &ehci->regs->command);
  900. temp &= ~CMD_HIRD;
  901. temp |= hird << 24;
  902. ehci_writel(ehci, temp, &ehci->regs->command);
  903. } else if (strncmp(buf, "disable", 7) == 0) {
  904. if (strict_strtoul(buf + 8, 10, &port))
  905. return -EINVAL;
  906. params = ehci_readl(ehci, &ehci->caps->hcs_params);
  907. if (port > HCS_N_PORTS(params)) {
  908. ehci_dbg(ehci, "ERR: LPM off bad port %lu\n", port);
  909. return -ENODEV;
  910. }
  911. portsc = &ehci->regs->port_status[port-1];
  912. temp = ehci_readl(ehci, portsc);
  913. if (!(temp & PORT_DEV_ADDR)) {
  914. ehci_dbg(ehci, "ERR: no device attached\n");
  915. return -ENODEV;
  916. }
  917. temp &= ~PORT_LPM;
  918. ehci_writel(ehci, temp, portsc);
  919. printk(KERN_INFO "disabled LPM for port %lu\n", port);
  920. } else
  921. return -EOPNOTSUPP;
  922. return count;
  923. }
  924. static inline void create_debug_files (struct ehci_hcd *ehci)
  925. {
  926. struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
  927. ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
  928. if (!ehci->debug_dir)
  929. return;
  930. if (!debugfs_create_file("async", S_IRUGO, ehci->debug_dir, bus,
  931. &debug_async_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. if (!debugfs_create_file("lpm", S_IRUGO|S_IWUSR, ehci->debug_dir, bus,
  940. &debug_lpm_fops))
  941. goto file_error;
  942. return;
  943. file_error:
  944. debugfs_remove_recursive(ehci->debug_dir);
  945. }
  946. static inline void remove_debug_files (struct ehci_hcd *ehci)
  947. {
  948. debugfs_remove_recursive(ehci->debug_dir);
  949. }
  950. #endif /* STUB_DEBUG_FILES */