ehci-dbg.c 28 KB

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