ehci-dbg.c 29 KB

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