ehci-dbg.c 25 KB

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