xhci-dbg.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * xHCI host controller driver
  3. *
  4. * Copyright (C) 2008 Intel Corp.
  5. *
  6. * Author: Sarah Sharp
  7. * Some code borrowed from the Linux EHCI driver.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software Foundation,
  20. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include "xhci.h"
  23. #define XHCI_INIT_VALUE 0x0
  24. /* Add verbose debugging later, just print everything for now */
  25. void xhci_dbg_regs(struct xhci_hcd *xhci)
  26. {
  27. u32 temp;
  28. xhci_dbg(xhci, "// xHCI capability registers at %p:\n",
  29. xhci->cap_regs);
  30. temp = readl(&xhci->cap_regs->hc_capbase);
  31. xhci_dbg(xhci, "// @%p = 0x%x (CAPLENGTH AND HCIVERSION)\n",
  32. &xhci->cap_regs->hc_capbase, temp);
  33. xhci_dbg(xhci, "// CAPLENGTH: 0x%x\n",
  34. (unsigned int) HC_LENGTH(temp));
  35. xhci_dbg(xhci, "// HCIVERSION: 0x%x\n",
  36. (unsigned int) HC_VERSION(temp));
  37. xhci_dbg(xhci, "// xHCI operational registers at %p:\n", xhci->op_regs);
  38. temp = readl(&xhci->cap_regs->run_regs_off);
  39. xhci_dbg(xhci, "// @%p = 0x%x RTSOFF\n",
  40. &xhci->cap_regs->run_regs_off,
  41. (unsigned int) temp & RTSOFF_MASK);
  42. xhci_dbg(xhci, "// xHCI runtime registers at %p:\n", xhci->run_regs);
  43. temp = readl(&xhci->cap_regs->db_off);
  44. xhci_dbg(xhci, "// @%p = 0x%x DBOFF\n", &xhci->cap_regs->db_off, temp);
  45. xhci_dbg(xhci, "// Doorbell array at %p:\n", xhci->dba);
  46. }
  47. static void xhci_print_cap_regs(struct xhci_hcd *xhci)
  48. {
  49. u32 temp;
  50. u32 hci_version;
  51. xhci_dbg(xhci, "xHCI capability registers at %p:\n", xhci->cap_regs);
  52. temp = readl(&xhci->cap_regs->hc_capbase);
  53. hci_version = HC_VERSION(temp);
  54. xhci_dbg(xhci, "CAPLENGTH AND HCIVERSION 0x%x:\n",
  55. (unsigned int) temp);
  56. xhci_dbg(xhci, "CAPLENGTH: 0x%x\n",
  57. (unsigned int) HC_LENGTH(temp));
  58. xhci_dbg(xhci, "HCIVERSION: 0x%x\n", hci_version);
  59. temp = readl(&xhci->cap_regs->hcs_params1);
  60. xhci_dbg(xhci, "HCSPARAMS 1: 0x%x\n",
  61. (unsigned int) temp);
  62. xhci_dbg(xhci, " Max device slots: %u\n",
  63. (unsigned int) HCS_MAX_SLOTS(temp));
  64. xhci_dbg(xhci, " Max interrupters: %u\n",
  65. (unsigned int) HCS_MAX_INTRS(temp));
  66. xhci_dbg(xhci, " Max ports: %u\n",
  67. (unsigned int) HCS_MAX_PORTS(temp));
  68. temp = readl(&xhci->cap_regs->hcs_params2);
  69. xhci_dbg(xhci, "HCSPARAMS 2: 0x%x\n",
  70. (unsigned int) temp);
  71. xhci_dbg(xhci, " Isoc scheduling threshold: %u\n",
  72. (unsigned int) HCS_IST(temp));
  73. xhci_dbg(xhci, " Maximum allowed segments in event ring: %u\n",
  74. (unsigned int) HCS_ERST_MAX(temp));
  75. temp = readl(&xhci->cap_regs->hcs_params3);
  76. xhci_dbg(xhci, "HCSPARAMS 3 0x%x:\n",
  77. (unsigned int) temp);
  78. xhci_dbg(xhci, " Worst case U1 device exit latency: %u\n",
  79. (unsigned int) HCS_U1_LATENCY(temp));
  80. xhci_dbg(xhci, " Worst case U2 device exit latency: %u\n",
  81. (unsigned int) HCS_U2_LATENCY(temp));
  82. temp = readl(&xhci->cap_regs->hcc_params);
  83. xhci_dbg(xhci, "HCC PARAMS 0x%x:\n", (unsigned int) temp);
  84. xhci_dbg(xhci, " HC generates %s bit addresses\n",
  85. HCC_64BIT_ADDR(temp) ? "64" : "32");
  86. xhci_dbg(xhci, " HC %s Contiguous Frame ID Capability\n",
  87. HCC_CFC(temp) ? "has" : "hasn't");
  88. xhci_dbg(xhci, " HC %s generate Stopped - Short Package event\n",
  89. HCC_SPC(temp) ? "can" : "can't");
  90. /* FIXME */
  91. xhci_dbg(xhci, " FIXME: more HCCPARAMS debugging\n");
  92. temp = readl(&xhci->cap_regs->run_regs_off);
  93. xhci_dbg(xhci, "RTSOFF 0x%x:\n", temp & RTSOFF_MASK);
  94. /* xhci 1.1 controllers have the HCCPARAMS2 register */
  95. if (hci_version > 0x100) {
  96. temp = readl(&xhci->cap_regs->hcc_params2);
  97. xhci_dbg(xhci, "HCC PARAMS2 0x%x:\n", (unsigned int) temp);
  98. xhci_dbg(xhci, " HC %s Force save context capability",
  99. HCC2_FSC(temp) ? "supports" : "doesn't support");
  100. xhci_dbg(xhci, " HC %s Large ESIT Payload Capability",
  101. HCC2_LEC(temp) ? "supports" : "doesn't support");
  102. xhci_dbg(xhci, " HC %s Extended TBC capability",
  103. HCC2_ETC(temp) ? "supports" : "doesn't support");
  104. }
  105. }
  106. static void xhci_print_command_reg(struct xhci_hcd *xhci)
  107. {
  108. u32 temp;
  109. temp = readl(&xhci->op_regs->command);
  110. xhci_dbg(xhci, "USBCMD 0x%x:\n", temp);
  111. xhci_dbg(xhci, " HC is %s\n",
  112. (temp & CMD_RUN) ? "running" : "being stopped");
  113. xhci_dbg(xhci, " HC has %sfinished hard reset\n",
  114. (temp & CMD_RESET) ? "not " : "");
  115. xhci_dbg(xhci, " Event Interrupts %s\n",
  116. (temp & CMD_EIE) ? "enabled " : "disabled");
  117. xhci_dbg(xhci, " Host System Error Interrupts %s\n",
  118. (temp & CMD_HSEIE) ? "enabled " : "disabled");
  119. xhci_dbg(xhci, " HC has %sfinished light reset\n",
  120. (temp & CMD_LRESET) ? "not " : "");
  121. }
  122. static void xhci_print_status(struct xhci_hcd *xhci)
  123. {
  124. u32 temp;
  125. temp = readl(&xhci->op_regs->status);
  126. xhci_dbg(xhci, "USBSTS 0x%x:\n", temp);
  127. xhci_dbg(xhci, " Event ring is %sempty\n",
  128. (temp & STS_EINT) ? "not " : "");
  129. xhci_dbg(xhci, " %sHost System Error\n",
  130. (temp & STS_FATAL) ? "WARNING: " : "No ");
  131. xhci_dbg(xhci, " HC is %s\n",
  132. (temp & STS_HALT) ? "halted" : "running");
  133. }
  134. static void xhci_print_op_regs(struct xhci_hcd *xhci)
  135. {
  136. xhci_dbg(xhci, "xHCI operational registers at %p:\n", xhci->op_regs);
  137. xhci_print_command_reg(xhci);
  138. xhci_print_status(xhci);
  139. }
  140. static void xhci_print_ports(struct xhci_hcd *xhci)
  141. {
  142. __le32 __iomem *addr;
  143. int i, j;
  144. int ports;
  145. char *names[NUM_PORT_REGS] = {
  146. "status",
  147. "power",
  148. "link",
  149. "reserved",
  150. };
  151. ports = HCS_MAX_PORTS(xhci->hcs_params1);
  152. addr = &xhci->op_regs->port_status_base;
  153. for (i = 0; i < ports; i++) {
  154. for (j = 0; j < NUM_PORT_REGS; j++) {
  155. xhci_dbg(xhci, "%p port %s reg = 0x%x\n",
  156. addr, names[j],
  157. (unsigned int) readl(addr));
  158. addr++;
  159. }
  160. }
  161. }
  162. void xhci_print_ir_set(struct xhci_hcd *xhci, int set_num)
  163. {
  164. struct xhci_intr_reg __iomem *ir_set = &xhci->run_regs->ir_set[set_num];
  165. void __iomem *addr;
  166. u32 temp;
  167. u64 temp_64;
  168. addr = &ir_set->irq_pending;
  169. temp = readl(addr);
  170. if (temp == XHCI_INIT_VALUE)
  171. return;
  172. xhci_dbg(xhci, " %p: ir_set[%i]\n", ir_set, set_num);
  173. xhci_dbg(xhci, " %p: ir_set.pending = 0x%x\n", addr,
  174. (unsigned int)temp);
  175. addr = &ir_set->irq_control;
  176. temp = readl(addr);
  177. xhci_dbg(xhci, " %p: ir_set.control = 0x%x\n", addr,
  178. (unsigned int)temp);
  179. addr = &ir_set->erst_size;
  180. temp = readl(addr);
  181. xhci_dbg(xhci, " %p: ir_set.erst_size = 0x%x\n", addr,
  182. (unsigned int)temp);
  183. addr = &ir_set->rsvd;
  184. temp = readl(addr);
  185. if (temp != XHCI_INIT_VALUE)
  186. xhci_dbg(xhci, " WARN: %p: ir_set.rsvd = 0x%x\n",
  187. addr, (unsigned int)temp);
  188. addr = &ir_set->erst_base;
  189. temp_64 = xhci_read_64(xhci, addr);
  190. xhci_dbg(xhci, " %p: ir_set.erst_base = @%08llx\n",
  191. addr, temp_64);
  192. addr = &ir_set->erst_dequeue;
  193. temp_64 = xhci_read_64(xhci, addr);
  194. xhci_dbg(xhci, " %p: ir_set.erst_dequeue = @%08llx\n",
  195. addr, temp_64);
  196. }
  197. void xhci_print_run_regs(struct xhci_hcd *xhci)
  198. {
  199. u32 temp;
  200. int i;
  201. xhci_dbg(xhci, "xHCI runtime registers at %p:\n", xhci->run_regs);
  202. temp = readl(&xhci->run_regs->microframe_index);
  203. xhci_dbg(xhci, " %p: Microframe index = 0x%x\n",
  204. &xhci->run_regs->microframe_index,
  205. (unsigned int) temp);
  206. for (i = 0; i < 7; i++) {
  207. temp = readl(&xhci->run_regs->rsvd[i]);
  208. if (temp != XHCI_INIT_VALUE)
  209. xhci_dbg(xhci, " WARN: %p: Rsvd[%i] = 0x%x\n",
  210. &xhci->run_regs->rsvd[i],
  211. i, (unsigned int) temp);
  212. }
  213. }
  214. void xhci_print_registers(struct xhci_hcd *xhci)
  215. {
  216. xhci_print_cap_regs(xhci);
  217. xhci_print_op_regs(xhci);
  218. xhci_print_ports(xhci);
  219. }
  220. void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst)
  221. {
  222. u64 addr = erst->erst_dma_addr;
  223. int i;
  224. struct xhci_erst_entry *entry;
  225. for (i = 0; i < erst->num_entries; i++) {
  226. entry = &erst->entries[i];
  227. xhci_dbg(xhci, "@%016llx %08x %08x %08x %08x\n",
  228. addr,
  229. lower_32_bits(le64_to_cpu(entry->seg_addr)),
  230. upper_32_bits(le64_to_cpu(entry->seg_addr)),
  231. le32_to_cpu(entry->seg_size),
  232. le32_to_cpu(entry->rsvd));
  233. addr += sizeof(*entry);
  234. }
  235. }
  236. void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci)
  237. {
  238. u64 val;
  239. val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
  240. xhci_dbg(xhci, "// xHC command ring deq ptr low bits + flags = @%08x\n",
  241. lower_32_bits(val));
  242. xhci_dbg(xhci, "// xHC command ring deq ptr high bits = @%08x\n",
  243. upper_32_bits(val));
  244. }
  245. char *xhci_get_slot_state(struct xhci_hcd *xhci,
  246. struct xhci_container_ctx *ctx)
  247. {
  248. struct xhci_slot_ctx *slot_ctx = xhci_get_slot_ctx(xhci, ctx);
  249. int state = GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state));
  250. return xhci_slot_state_string(state);
  251. }
  252. void xhci_dbg_trace(struct xhci_hcd *xhci, void (*trace)(struct va_format *),
  253. const char *fmt, ...)
  254. {
  255. struct va_format vaf;
  256. va_list args;
  257. va_start(args, fmt);
  258. vaf.fmt = fmt;
  259. vaf.va = &args;
  260. xhci_dbg(xhci, "%pV\n", &vaf);
  261. trace(&vaf);
  262. va_end(args);
  263. }
  264. EXPORT_SYMBOL_GPL(xhci_dbg_trace);