ehci-dbg.c 25 KB

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