adm5120-dbg.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. /*
  2. * ADM5120 HCD (Host Controller Driver) for USB
  3. *
  4. * Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
  5. *
  6. * This file was derived from: drivers/usb/host/ohci-dbg.c
  7. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  8. * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published
  12. * by the Free Software Foundation.
  13. *
  14. */
  15. /*-------------------------------------------------------------------------*/
  16. static inline char *ed_typestring(int ed_type)
  17. {
  18. switch (ed_type) {
  19. case PIPE_CONTROL:
  20. return "ctrl";
  21. case PIPE_BULK:
  22. return "bulk";
  23. case PIPE_INTERRUPT:
  24. return "intr";
  25. case PIPE_ISOCHRONOUS:
  26. return "isoc";
  27. }
  28. return "(bad ed_type)";
  29. }
  30. static inline char *ed_statestring(int state)
  31. {
  32. switch (state) {
  33. case ED_IDLE:
  34. return "IDLE";
  35. case ED_UNLINK:
  36. return "UNLINK";
  37. case ED_OPER:
  38. return "OPER";
  39. }
  40. return "?STATE";
  41. }
  42. static inline char *pipestring(int pipe)
  43. {
  44. return ed_typestring(usb_pipetype(pipe));
  45. }
  46. static inline char *td_pidstring(u32 info)
  47. {
  48. switch (info & TD_DP) {
  49. case TD_DP_SETUP:
  50. return "SETUP";
  51. case TD_DP_IN:
  52. return "IN";
  53. case TD_DP_OUT:
  54. return "OUT";
  55. }
  56. return "?PID";
  57. }
  58. static inline char *td_togglestring(u32 info)
  59. {
  60. switch (info & TD_T) {
  61. case TD_T_DATA0:
  62. return "DATA0";
  63. case TD_T_DATA1:
  64. return "DATA1";
  65. case TD_T_CARRY:
  66. return "CARRY";
  67. }
  68. return "?TOGGLE";
  69. }
  70. /*-------------------------------------------------------------------------*/
  71. #ifdef DEBUG
  72. /* debug| print the main components of an URB
  73. * small: 0) header + data packets 1) just header
  74. */
  75. static void __attribute__((unused))
  76. urb_print(struct admhcd *ahcd, struct urb *urb, char *str, int small, int status)
  77. {
  78. unsigned int pipe = urb->pipe;
  79. if (!urb->dev || !urb->dev->bus) {
  80. admhc_dbg(ahcd, "%s URB: no dev", str);
  81. return;
  82. }
  83. #ifndef ADMHC_VERBOSE_DEBUG
  84. if (status != 0)
  85. #endif
  86. admhc_dbg(ahcd, "URB-%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d "
  87. "stat=%d\n",
  88. str,
  89. urb,
  90. usb_pipedevice(pipe),
  91. usb_pipeendpoint(pipe),
  92. usb_pipeout(pipe) ? "out" : "in",
  93. pipestring(pipe),
  94. urb->transfer_flags,
  95. urb->actual_length,
  96. urb->transfer_buffer_length,
  97. status);
  98. #ifdef ADMHC_VERBOSE_DEBUG
  99. if (!small) {
  100. int i, len;
  101. if (usb_pipecontrol(pipe)) {
  102. admhc_dbg(ahcd, "setup(8):");
  103. for (i = 0; i < 8 ; i++)
  104. printk(KERN_INFO" %02x", ((__u8 *)urb->setup_packet)[i]);
  105. printk(KERN_INFO "\n");
  106. }
  107. if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) {
  108. admhc_dbg(ahcd, "data(%d/%d):",
  109. urb->actual_length,
  110. urb->transfer_buffer_length);
  111. len = usb_pipeout(pipe) ?
  112. urb->transfer_buffer_length : urb->actual_length;
  113. for (i = 0; i < 16 && i < len; i++)
  114. printk(KERN_INFO " %02x", ((__u8 *)urb->transfer_buffer)[i]);
  115. printk(KERN_INFO "%s stat:%d\n", i < len ? "..." : "", status);
  116. }
  117. }
  118. #endif /* ADMHC_VERBOSE_DEBUG */
  119. }
  120. #define admhc_dbg_sw(ahcd, next, size, format, arg...) \
  121. do { \
  122. if (next) { \
  123. unsigned s_len; \
  124. s_len = scnprintf(*next, *size, format, ## arg); \
  125. *size -= s_len; *next += s_len; \
  126. } else \
  127. admhc_dbg(ahcd, format, ## arg); \
  128. } while (0);
  129. static void admhc_dump_intr_mask(struct admhcd *ahcd, char *label, u32 mask,
  130. char **next, unsigned *size)
  131. {
  132. admhc_dbg_sw(ahcd, next, size, "%s 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n",
  133. label,
  134. mask,
  135. (mask & ADMHC_INTR_INTA) ? " INTA" : "",
  136. (mask & ADMHC_INTR_FATI) ? " FATI" : "",
  137. (mask & ADMHC_INTR_SWI) ? " SWI" : "",
  138. (mask & ADMHC_INTR_TDC) ? " TDC" : "",
  139. (mask & ADMHC_INTR_FNO) ? " FNO" : "",
  140. (mask & ADMHC_INTR_SO) ? " SO" : "",
  141. (mask & ADMHC_INTR_INSM) ? " INSM" : "",
  142. (mask & ADMHC_INTR_BABI) ? " BABI" : "",
  143. (mask & ADMHC_INTR_7) ? " !7!" : "",
  144. (mask & ADMHC_INTR_6) ? " !6!" : "",
  145. (mask & ADMHC_INTR_RESI) ? " RESI" : "",
  146. (mask & ADMHC_INTR_SOFI) ? " SOFI" : ""
  147. );
  148. }
  149. static void maybe_print_eds(struct admhcd *ahcd, char *label, u32 value,
  150. char **next, unsigned *size)
  151. {
  152. if (value)
  153. admhc_dbg_sw(ahcd, next, size, "%s %08x\n", label, value);
  154. }
  155. static char *buss2string(int state)
  156. {
  157. switch (state) {
  158. case ADMHC_BUSS_RESET:
  159. return "reset";
  160. case ADMHC_BUSS_RESUME:
  161. return "resume";
  162. case ADMHC_BUSS_OPER:
  163. return "operational";
  164. case ADMHC_BUSS_SUSPEND:
  165. return "suspend";
  166. }
  167. return "?state";
  168. }
  169. static void
  170. admhc_dump_status(struct admhcd *ahcd, char **next, unsigned *size)
  171. {
  172. struct admhcd_regs __iomem *regs = ahcd->regs;
  173. u32 temp;
  174. temp = admhc_readl(ahcd, &regs->gencontrol);
  175. admhc_dbg_sw(ahcd, next, size,
  176. "gencontrol 0x%08x%s%s%s%s\n",
  177. temp,
  178. (temp & ADMHC_CTRL_UHFE) ? " UHFE" : "",
  179. (temp & ADMHC_CTRL_SIR) ? " SIR" : "",
  180. (temp & ADMHC_CTRL_DMAA) ? " DMAA" : "",
  181. (temp & ADMHC_CTRL_SR) ? " SR" : ""
  182. );
  183. temp = admhc_readl(ahcd, &regs->host_control);
  184. admhc_dbg_sw(ahcd, next, size,
  185. "host_control 0x%08x BUSS=%s%s\n",
  186. temp,
  187. buss2string(temp & ADMHC_HC_BUSS),
  188. (temp & ADMHC_HC_DMAE) ? " DMAE" : ""
  189. );
  190. admhc_dump_intr_mask(ahcd, "int_status",
  191. admhc_readl(ahcd, &regs->int_status),
  192. next, size);
  193. admhc_dump_intr_mask(ahcd, "int_enable",
  194. admhc_readl(ahcd, &regs->int_enable),
  195. next, size);
  196. maybe_print_eds(ahcd, "hosthead",
  197. admhc_readl(ahcd, &regs->hosthead), next, size);
  198. }
  199. #define dbg_port_sw(hc, num, value, next, size) \
  200. admhc_dbg_sw(hc, next, size, \
  201. "portstatus [%d] " \
  202. "0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\n", \
  203. num, temp, \
  204. (temp & ADMHC_PS_PRSC) ? " PRSC" : "", \
  205. (temp & ADMHC_PS_OCIC) ? " OCIC" : "", \
  206. (temp & ADMHC_PS_PSSC) ? " PSSC" : "", \
  207. (temp & ADMHC_PS_PESC) ? " PESC" : "", \
  208. (temp & ADMHC_PS_CSC) ? " CSC" : "", \
  209. \
  210. (temp & ADMHC_PS_LSDA) ? " LSDA" : "", \
  211. (temp & ADMHC_PS_PPS) ? " PPS" : "", \
  212. (temp & ADMHC_PS_PRS) ? " PRS" : "", \
  213. (temp & ADMHC_PS_POCI) ? " POCI" : "", \
  214. (temp & ADMHC_PS_PSS) ? " PSS" : "", \
  215. \
  216. (temp & ADMHC_PS_PES) ? " PES" : "", \
  217. (temp & ADMHC_PS_CCS) ? " CCS" : "" \
  218. );
  219. static void
  220. admhc_dump_roothub(
  221. struct admhcd *ahcd,
  222. int verbose,
  223. char **next,
  224. unsigned *size)
  225. {
  226. u32 temp, i;
  227. temp = admhc_read_rhdesc(ahcd);
  228. if (temp == ~(u32)0)
  229. return;
  230. if (verbose) {
  231. admhc_dbg_sw(ahcd, next, size,
  232. "rhdesc %08x%s%s%s%s%s%s PPCM=%02x%s%s%s%s NUMP=%d(%d)\n",
  233. temp,
  234. (temp & ADMHC_RH_CRWE) ? " CRWE" : "",
  235. (temp & ADMHC_RH_OCIC) ? " OCIC" : "",
  236. (temp & ADMHC_RH_LPSC) ? " LPSC" : "",
  237. (temp & ADMHC_RH_LPSC) ? " DRWE" : "",
  238. (temp & ADMHC_RH_LPSC) ? " OCI" : "",
  239. (temp & ADMHC_RH_LPSC) ? " LPS" : "",
  240. ((temp & ADMHC_RH_PPCM) >> 16),
  241. (temp & ADMHC_RH_NOCP) ? " NOCP" : "",
  242. (temp & ADMHC_RH_OCPM) ? " OCPM" : "",
  243. (temp & ADMHC_RH_NPS) ? " NPS" : "",
  244. (temp & ADMHC_RH_PSM) ? " PSM" : "",
  245. (temp & ADMHC_RH_NUMP), ahcd->num_ports
  246. );
  247. }
  248. for (i = 0; i < ahcd->num_ports; i++) {
  249. temp = admhc_read_portstatus(ahcd, i);
  250. dbg_port_sw(ahcd, i, temp, next, size);
  251. }
  252. }
  253. static void admhc_dump(struct admhcd *ahcd, int verbose)
  254. {
  255. admhc_dbg(ahcd, "ADMHC ahcd state\n");
  256. /* dumps some of the state we know about */
  257. admhc_dump_status(ahcd, NULL, NULL);
  258. admhc_dbg(ahcd, "current frame #%04x\n",
  259. admhc_frame_no(ahcd));
  260. admhc_dump_roothub(ahcd, verbose, NULL, NULL);
  261. }
  262. static const char data0[] = "DATA0";
  263. static const char data1[] = "DATA1";
  264. static void admhc_dump_td(const struct admhcd *ahcd, const char *label,
  265. const struct td *td)
  266. {
  267. u32 tmp;
  268. admhc_dbg(ahcd, "%s td %p; urb %p index %d; hwNextTD %08x\n",
  269. label, td,
  270. td->urb, td->index,
  271. hc32_to_cpup(ahcd, &td->hwNextTD));
  272. tmp = hc32_to_cpup(ahcd, &td->hwINFO);
  273. admhc_dbg(ahcd, " status %08x%s CC=%x EC=%d %s %s ISI=%x FN=%x\n",
  274. tmp,
  275. (tmp & TD_OWN) ? " OWN" : "",
  276. TD_CC_GET(tmp),
  277. TD_EC_GET(tmp),
  278. td_togglestring(tmp),
  279. td_pidstring(tmp),
  280. TD_ISI_GET(tmp),
  281. TD_FN_GET(tmp));
  282. tmp = hc32_to_cpup(ahcd, &td->hwCBL);
  283. admhc_dbg(ahcd, " dbp %08x; cbl %08x; LEN=%d%s\n",
  284. hc32_to_cpup(ahcd, &td->hwDBP),
  285. tmp,
  286. TD_BL_GET(tmp),
  287. (tmp & TD_IE) ? " IE" : "");
  288. }
  289. /* caller MUST own hcd spinlock if verbose is set! */
  290. static void __attribute__((unused))
  291. admhc_dump_ed(const struct admhcd *ahcd, const char *label,
  292. const struct ed *ed, int verbose)
  293. {
  294. u32 tmp = hc32_to_cpu(ahcd, ed->hwINFO);
  295. admhc_dbg(ahcd, "%s ed %p %s type %s; next ed %08x\n",
  296. label,
  297. ed, ed_statestring(ed->state), ed_typestring(ed->type),
  298. hc32_to_cpup(ahcd, &ed->hwNextED));
  299. admhc_dbg(ahcd, " info %08x MAX=%d%s%s%s%s EP=%d DEV=%d\n", tmp,
  300. ED_MPS_GET(tmp),
  301. (tmp & ED_ISO) ? " ISO" : "",
  302. (tmp & ED_SKIP) ? " SKIP" : "",
  303. (tmp & ED_SPEED_FULL) ? " FULL" : " LOW",
  304. (tmp & ED_INT) ? " INT" : "",
  305. ED_EN_GET(tmp),
  306. ED_FA_GET(tmp));
  307. tmp = hc32_to_cpup(ahcd, &ed->hwHeadP);
  308. admhc_dbg(ahcd, " tds: head %08x tail %08x %s%s%s\n",
  309. tmp & TD_MASK,
  310. hc32_to_cpup(ahcd, &ed->hwTailP),
  311. (tmp & ED_C) ? data1 : data0,
  312. (tmp & ED_H) ? " HALT" : "",
  313. verbose ? " td list follows" : " (not listing)");
  314. if (verbose) {
  315. struct list_head *tmp;
  316. /* use ed->td_list because HC concurrently modifies
  317. * hwNextTD as it accumulates ed_donelist.
  318. */
  319. list_for_each(tmp, &ed->td_list) {
  320. struct td *td;
  321. td = list_entry(tmp, struct td, td_list);
  322. admhc_dump_td(ahcd, " ->", td);
  323. }
  324. }
  325. }
  326. #else /* ifdef DEBUG */
  327. static inline void urb_print(struct admhcd *ahcd, struct urb * urb, char * str,
  328. int small, int status) {}
  329. static inline void admhc_dump_ed(const struct admhcd *ahcd, const char *label,
  330. const struct ed *ed, int verbose) {}
  331. static inline void admhc_dump_td(const struct admhcd *ahcd, const char *label,
  332. const struct td *td) {}
  333. static inline void admhc_dump(struct admhcd *ahcd, int verbose) {}
  334. #undef ADMHC_VERBOSE_DEBUG
  335. #endif /* DEBUG */
  336. /*-------------------------------------------------------------------------*/
  337. #ifdef STUB_DEBUG_FILES
  338. static inline void create_debug_files(struct admhcd *bus) { }
  339. static inline void remove_debug_files(struct admhcd *bus) { }
  340. #else
  341. static int debug_async_open(struct inode *, struct file *);
  342. static int debug_periodic_open(struct inode *, struct file *);
  343. static int debug_registers_open(struct inode *, struct file *);
  344. static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
  345. static int debug_close(struct inode *, struct file *);
  346. static const struct file_operations debug_async_fops = {
  347. .owner = THIS_MODULE,
  348. .open = debug_async_open,
  349. .read = debug_output,
  350. .release = debug_close,
  351. .llseek = default_llseek,
  352. };
  353. static const struct file_operations debug_periodic_fops = {
  354. .owner = THIS_MODULE,
  355. .open = debug_periodic_open,
  356. .read = debug_output,
  357. .release = debug_close,
  358. .llseek = default_llseek,
  359. };
  360. static const struct file_operations debug_registers_fops = {
  361. .owner = THIS_MODULE,
  362. .open = debug_registers_open,
  363. .read = debug_output,
  364. .release = debug_close,
  365. .llseek = default_llseek,
  366. };
  367. static struct dentry *admhc_debug_root;
  368. struct debug_buffer {
  369. ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
  370. struct admhcd *ahcd;
  371. struct mutex mutex; /* protect filling of buffer */
  372. size_t count; /* number of characters filled into buffer */
  373. char *page;
  374. };
  375. static ssize_t
  376. show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed)
  377. {
  378. unsigned temp;
  379. unsigned size = count;
  380. if (!ed)
  381. return 0;
  382. /* dump a snapshot of the bulk or control schedule */
  383. while (ed) {
  384. u32 info = hc32_to_cpu(ahcd, ed->hwINFO);
  385. u32 headp = hc32_to_cpu(ahcd, ed->hwHeadP);
  386. u32 tailp = hc32_to_cpu(ahcd, ed->hwTailP);
  387. struct list_head *entry;
  388. struct td *td;
  389. temp = scnprintf(buf, size,
  390. "ed/%p %s %s %cs dev%d ep%d %s%smax %d %08x%s%s %s"
  391. " h:%08x t:%08x",
  392. ed,
  393. ed_statestring(ed->state),
  394. ed_typestring(ed->type),
  395. (info & ED_SPEED_FULL) ? 'f' : 'l',
  396. info & ED_FA_MASK,
  397. (info >> ED_EN_SHIFT) & ED_EN_MASK,
  398. (info & ED_INT) ? "INT " : "",
  399. (info & ED_ISO) ? "ISO " : "",
  400. (info >> ED_MPS_SHIFT) & ED_MPS_MASK ,
  401. info,
  402. (info & ED_SKIP) ? " S" : "",
  403. (headp & ED_H) ? " H" : "",
  404. (headp & ED_C) ? data1 : data0,
  405. headp & ED_MASK, tailp);
  406. size -= temp;
  407. buf += temp;
  408. list_for_each(entry, &ed->td_list) {
  409. u32 dbp, cbl;
  410. td = list_entry(entry, struct td, td_list);
  411. info = hc32_to_cpup(ahcd, &td->hwINFO);
  412. dbp = hc32_to_cpup(ahcd, &td->hwDBP);
  413. cbl = hc32_to_cpup(ahcd, &td->hwCBL);
  414. temp = scnprintf(buf, size,
  415. "\n\ttd/%p %s %d %s%scc=%x urb %p (%08x,%08x)",
  416. td,
  417. td_pidstring(info),
  418. TD_BL_GET(cbl),
  419. (info & TD_OWN) ? "" : "DONE ",
  420. (cbl & TD_IE) ? "IE " : "",
  421. TD_CC_GET(info), td->urb, info, cbl);
  422. size -= temp;
  423. buf += temp;
  424. }
  425. temp = scnprintf(buf, size, "\n");
  426. size -= temp;
  427. buf += temp;
  428. ed = ed->ed_next;
  429. }
  430. return count - size;
  431. }
  432. static ssize_t fill_async_buffer(struct debug_buffer *buf)
  433. {
  434. struct admhcd *ahcd;
  435. size_t temp;
  436. unsigned long flags;
  437. ahcd = buf->ahcd;
  438. spin_lock_irqsave(&ahcd->lock, flags);
  439. temp = show_list(ahcd, buf->page, PAGE_SIZE, ahcd->ed_head);
  440. spin_unlock_irqrestore(&ahcd->lock, flags);
  441. return temp;
  442. }
  443. #define DBG_SCHED_LIMIT 64
  444. static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
  445. {
  446. struct admhcd *ahcd;
  447. struct ed **seen, *ed;
  448. unsigned long flags;
  449. unsigned temp, size, seen_count;
  450. char *next;
  451. unsigned i;
  452. seen = kmalloc(DBG_SCHED_LIMIT * sizeof(*seen), GFP_ATOMIC);
  453. if (!seen)
  454. return 0;
  455. seen_count = 0;
  456. ahcd = buf->ahcd;
  457. next = buf->page;
  458. size = PAGE_SIZE;
  459. temp = scnprintf(next, size, "size = %d\n", NUM_INTS);
  460. size -= temp;
  461. next += temp;
  462. /* dump a snapshot of the periodic schedule (and load) */
  463. spin_lock_irqsave(&ahcd->lock, flags);
  464. for (i = 0; i < NUM_INTS; i++) {
  465. ed = ahcd->periodic[i];
  466. if (!ed)
  467. continue;
  468. temp = scnprintf(next, size, "%2d [%3d]:", i, ahcd->load[i]);
  469. size -= temp;
  470. next += temp;
  471. do {
  472. temp = scnprintf(next, size, " ed%d/%p",
  473. ed->interval, ed);
  474. size -= temp;
  475. next += temp;
  476. for (temp = 0; temp < seen_count; temp++) {
  477. if (seen[temp] == ed)
  478. break;
  479. }
  480. /* show more info the first time around */
  481. if (temp == seen_count) {
  482. u32 info = hc32_to_cpu(ahcd, ed->hwINFO);
  483. struct list_head *entry;
  484. unsigned qlen = 0;
  485. /* qlen measured here in TDs, not urbs */
  486. list_for_each(entry, &ed->td_list)
  487. qlen++;
  488. temp = scnprintf(next, size,
  489. " (%cs dev%d ep%d%s qlen %u"
  490. " max %d %08x%s%s)",
  491. (info & ED_SPEED_FULL) ? 'f' : 'l',
  492. ED_FA_GET(info),
  493. ED_EN_GET(info),
  494. (info & ED_ISO) ? "iso" : "int",
  495. qlen,
  496. ED_MPS_GET(info),
  497. info,
  498. (info & ED_SKIP) ? " K" : "",
  499. (ed->hwHeadP &
  500. cpu_to_hc32(ahcd, ED_H)) ?
  501. " H" : "");
  502. size -= temp;
  503. next += temp;
  504. if (seen_count < DBG_SCHED_LIMIT)
  505. seen[seen_count++] = ed;
  506. ed = ed->ed_next;
  507. } else {
  508. /* we've seen it and what's after */
  509. temp = 0;
  510. ed = NULL;
  511. }
  512. } while (ed);
  513. temp = scnprintf(next, size, "\n");
  514. size -= temp;
  515. next += temp;
  516. }
  517. spin_unlock_irqrestore(&ahcd->lock, flags);
  518. kfree(seen);
  519. return PAGE_SIZE - size;
  520. }
  521. #undef DBG_SCHED_LIMIT
  522. static ssize_t fill_registers_buffer(struct debug_buffer *buf)
  523. {
  524. struct usb_hcd *hcd;
  525. struct admhcd *ahcd;
  526. struct admhcd_regs __iomem *regs;
  527. unsigned long flags;
  528. unsigned temp, size;
  529. char *next;
  530. u32 rdata;
  531. ahcd = buf->ahcd;
  532. hcd = admhc_to_hcd(ahcd);
  533. regs = ahcd->regs;
  534. next = buf->page;
  535. size = PAGE_SIZE;
  536. spin_lock_irqsave(&ahcd->lock, flags);
  537. /* dump driver info, then registers in spec order */
  538. admhc_dbg_sw(ahcd, &next, &size,
  539. "bus %s, device %s\n"
  540. "%s\n"
  541. "%s\n",
  542. hcd->self.controller->bus->name,
  543. dev_name(hcd->self.controller),
  544. hcd->product_desc,
  545. hcd_name);
  546. if (!HCD_HW_ACCESSIBLE(hcd)) {
  547. size -= scnprintf(next, size,
  548. "SUSPENDED (no register access)\n");
  549. goto done;
  550. }
  551. admhc_dump_status(ahcd, &next, &size);
  552. /* other registers mostly affect frame timings */
  553. rdata = admhc_readl(ahcd, &regs->fminterval);
  554. temp = scnprintf(next, size,
  555. "fmintvl 0x%08x %sFSLDP=0x%04x FI=0x%04x\n",
  556. rdata, (rdata & ADMHC_SFI_FIT) ? "FIT " : "",
  557. (rdata >> ADMHC_SFI_FSLDP_SHIFT) & ADMHC_SFI_FSLDP_MASK,
  558. rdata & ADMHC_SFI_FI_MASK);
  559. size -= temp;
  560. next += temp;
  561. rdata = admhc_readl(ahcd, &regs->fmnumber);
  562. temp = scnprintf(next, size, "fmnumber 0x%08x %sFR=0x%04x FN=%04x\n",
  563. rdata, (rdata & ADMHC_SFN_FRT) ? "FRT " : "",
  564. (rdata >> ADMHC_SFN_FR_SHIFT) & ADMHC_SFN_FR_MASK,
  565. rdata & ADMHC_SFN_FN_MASK);
  566. size -= temp;
  567. next += temp;
  568. /* TODO: use predefined bitmask */
  569. rdata = admhc_readl(ahcd, &regs->lsthresh);
  570. temp = scnprintf(next, size, "lsthresh 0x%04x\n",
  571. rdata & 0x3fff);
  572. size -= temp;
  573. next += temp;
  574. temp = scnprintf(next, size, "hub poll timer: %s\n",
  575. admhcd_to_hcd(ahcd)->poll_rh ? "ON" : "OFF");
  576. size -= temp;
  577. next += temp;
  578. /* roothub */
  579. admhc_dump_roothub(ahcd, 1, &next, &size);
  580. done:
  581. spin_unlock_irqrestore(&ahcd->lock, flags);
  582. return PAGE_SIZE - size;
  583. }
  584. static struct debug_buffer *alloc_buffer(struct admhcd *ahcd,
  585. ssize_t (*fill_func)(struct debug_buffer *))
  586. {
  587. struct debug_buffer *buf;
  588. buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
  589. if (buf) {
  590. buf->ahcd = ahcd;
  591. buf->fill_func = fill_func;
  592. mutex_init(&buf->mutex);
  593. }
  594. return buf;
  595. }
  596. static int fill_buffer(struct debug_buffer *buf)
  597. {
  598. int ret = 0;
  599. if (!buf->page)
  600. buf->page = (char *)get_zeroed_page(GFP_KERNEL);
  601. if (!buf->page) {
  602. ret = -ENOMEM;
  603. goto out;
  604. }
  605. ret = buf->fill_func(buf);
  606. if (ret >= 0) {
  607. buf->count = ret;
  608. ret = 0;
  609. }
  610. out:
  611. return ret;
  612. }
  613. static ssize_t debug_output(struct file *file, char __user *user_buf,
  614. size_t len, loff_t *offset)
  615. {
  616. struct debug_buffer *buf = file->private_data;
  617. int ret = 0;
  618. mutex_lock(&buf->mutex);
  619. if (buf->count == 0) {
  620. ret = fill_buffer(buf);
  621. if (ret != 0) {
  622. mutex_unlock(&buf->mutex);
  623. goto out;
  624. }
  625. }
  626. mutex_unlock(&buf->mutex);
  627. ret = simple_read_from_buffer(user_buf, len, offset,
  628. buf->page, buf->count);
  629. out:
  630. return ret;
  631. }
  632. static int debug_close(struct inode *inode, struct file *file)
  633. {
  634. struct debug_buffer *buf = file->private_data;
  635. if (buf) {
  636. if (buf->page)
  637. free_page((unsigned long)buf->page);
  638. kfree(buf);
  639. }
  640. return 0;
  641. }
  642. static int debug_async_open(struct inode *inode, struct file *file)
  643. {
  644. file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
  645. return file->private_data ? 0 : -ENOMEM;
  646. }
  647. static int debug_periodic_open(struct inode *inode, struct file *file)
  648. {
  649. file->private_data = alloc_buffer(inode->i_private,
  650. fill_periodic_buffer);
  651. return file->private_data ? 0 : -ENOMEM;
  652. }
  653. static int debug_registers_open(struct inode *inode, struct file *file)
  654. {
  655. file->private_data = alloc_buffer(inode->i_private,
  656. fill_registers_buffer);
  657. return file->private_data ? 0 : -ENOMEM;
  658. }
  659. static inline void create_debug_files(struct admhcd *ahcd)
  660. {
  661. struct usb_bus *bus = &admhcd_to_hcd(ahcd)->self;
  662. ahcd->debug_dir = debugfs_create_dir(bus->bus_name, admhc_debug_root);
  663. if (!ahcd->debug_dir)
  664. goto dir_error;
  665. ahcd->debug_async = debugfs_create_file("async", S_IRUGO,
  666. ahcd->debug_dir, ahcd,
  667. &debug_async_fops);
  668. if (!ahcd->debug_async)
  669. goto async_error;
  670. ahcd->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
  671. ahcd->debug_dir, ahcd,
  672. &debug_periodic_fops);
  673. if (!ahcd->debug_periodic)
  674. goto periodic_error;
  675. ahcd->debug_registers = debugfs_create_file("registers", S_IRUGO,
  676. ahcd->debug_dir, ahcd,
  677. &debug_registers_fops);
  678. if (!ahcd->debug_registers)
  679. goto registers_error;
  680. admhc_dbg(ahcd, "created debug files\n");
  681. return;
  682. registers_error:
  683. debugfs_remove(ahcd->debug_periodic);
  684. periodic_error:
  685. debugfs_remove(ahcd->debug_async);
  686. async_error:
  687. debugfs_remove(ahcd->debug_dir);
  688. dir_error:
  689. ahcd->debug_periodic = NULL;
  690. ahcd->debug_async = NULL;
  691. ahcd->debug_dir = NULL;
  692. }
  693. static inline void remove_debug_files(struct admhcd *ahcd)
  694. {
  695. debugfs_remove(ahcd->debug_registers);
  696. debugfs_remove(ahcd->debug_periodic);
  697. debugfs_remove(ahcd->debug_async);
  698. debugfs_remove(ahcd->debug_dir);
  699. }
  700. #endif
  701. /*-------------------------------------------------------------------------*/