xhci-dbg.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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 0x%x:\n",
  29. (unsigned int) xhci->cap_regs);
  30. temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase);
  31. xhci_dbg(xhci, "// @%x = 0x%x (CAPLENGTH AND HCIVERSION)\n",
  32. (unsigned int) &xhci->cap_regs->hc_capbase,
  33. (unsigned int) temp);
  34. xhci_dbg(xhci, "// CAPLENGTH: 0x%x\n",
  35. (unsigned int) HC_LENGTH(temp));
  36. #if 0
  37. xhci_dbg(xhci, "// HCIVERSION: 0x%x\n",
  38. (unsigned int) HC_VERSION(temp));
  39. #endif
  40. xhci_dbg(xhci, "// xHCI operational registers at 0x%x:\n",
  41. (unsigned int) xhci->op_regs);
  42. temp = xhci_readl(xhci, &xhci->cap_regs->run_regs_off);
  43. xhci_dbg(xhci, "// @%x = 0x%x RTSOFF\n",
  44. (unsigned int) &xhci->cap_regs->run_regs_off,
  45. (unsigned int) temp & RTSOFF_MASK);
  46. xhci_dbg(xhci, "// xHCI runtime registers at 0x%x:\n",
  47. (unsigned int) xhci->run_regs);
  48. temp = xhci_readl(xhci, &xhci->cap_regs->db_off);
  49. xhci_dbg(xhci, "// @%x = 0x%x DBOFF\n",
  50. (unsigned int) &xhci->cap_regs->db_off, temp);
  51. xhci_dbg(xhci, "// Doorbell array at 0x%x:\n",
  52. (unsigned int) xhci->dba);
  53. }
  54. void xhci_print_cap_regs(struct xhci_hcd *xhci)
  55. {
  56. u32 temp;
  57. xhci_dbg(xhci, "xHCI capability registers at 0x%x:\n",
  58. (unsigned int) xhci->cap_regs);
  59. temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase);
  60. xhci_dbg(xhci, "CAPLENGTH AND HCIVERSION 0x%x:\n",
  61. (unsigned int) temp);
  62. xhci_dbg(xhci, "CAPLENGTH: 0x%x\n",
  63. (unsigned int) HC_LENGTH(temp));
  64. xhci_dbg(xhci, "HCIVERSION: 0x%x\n",
  65. (unsigned int) HC_VERSION(temp));
  66. temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params1);
  67. xhci_dbg(xhci, "HCSPARAMS 1: 0x%x\n",
  68. (unsigned int) temp);
  69. xhci_dbg(xhci, " Max device slots: %u\n",
  70. (unsigned int) HCS_MAX_SLOTS(temp));
  71. xhci_dbg(xhci, " Max interrupters: %u\n",
  72. (unsigned int) HCS_MAX_INTRS(temp));
  73. xhci_dbg(xhci, " Max ports: %u\n",
  74. (unsigned int) HCS_MAX_PORTS(temp));
  75. temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params2);
  76. xhci_dbg(xhci, "HCSPARAMS 2: 0x%x\n",
  77. (unsigned int) temp);
  78. xhci_dbg(xhci, " Isoc scheduling threshold: %u\n",
  79. (unsigned int) HCS_IST(temp));
  80. xhci_dbg(xhci, " Maximum allowed segments in event ring: %u\n",
  81. (unsigned int) HCS_ERST_MAX(temp));
  82. temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params3);
  83. xhci_dbg(xhci, "HCSPARAMS 3 0x%x:\n",
  84. (unsigned int) temp);
  85. xhci_dbg(xhci, " Worst case U1 device exit latency: %u\n",
  86. (unsigned int) HCS_U1_LATENCY(temp));
  87. xhci_dbg(xhci, " Worst case U2 device exit latency: %u\n",
  88. (unsigned int) HCS_U2_LATENCY(temp));
  89. temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
  90. xhci_dbg(xhci, "HCC PARAMS 0x%x:\n", (unsigned int) temp);
  91. xhci_dbg(xhci, " HC generates %s bit addresses\n",
  92. HCC_64BIT_ADDR(temp) ? "64" : "32");
  93. /* FIXME */
  94. xhci_dbg(xhci, " FIXME: more HCCPARAMS debugging\n");
  95. temp = xhci_readl(xhci, &xhci->cap_regs->run_regs_off);
  96. xhci_dbg(xhci, "RTSOFF 0x%x:\n", temp & RTSOFF_MASK);
  97. }
  98. void xhci_print_command_reg(struct xhci_hcd *xhci)
  99. {
  100. u32 temp;
  101. temp = xhci_readl(xhci, &xhci->op_regs->command);
  102. xhci_dbg(xhci, "USBCMD 0x%x:\n", temp);
  103. xhci_dbg(xhci, " HC is %s\n",
  104. (temp & CMD_RUN) ? "running" : "being stopped");
  105. xhci_dbg(xhci, " HC has %sfinished hard reset\n",
  106. (temp & CMD_RESET) ? "not " : "");
  107. xhci_dbg(xhci, " Event Interrupts %s\n",
  108. (temp & CMD_EIE) ? "enabled " : "disabled");
  109. xhci_dbg(xhci, " Host System Error Interrupts %s\n",
  110. (temp & CMD_EIE) ? "enabled " : "disabled");
  111. xhci_dbg(xhci, " HC has %sfinished light reset\n",
  112. (temp & CMD_LRESET) ? "not " : "");
  113. }
  114. void xhci_print_status(struct xhci_hcd *xhci)
  115. {
  116. u32 temp;
  117. temp = xhci_readl(xhci, &xhci->op_regs->status);
  118. xhci_dbg(xhci, "USBSTS 0x%x:\n", temp);
  119. xhci_dbg(xhci, " Event ring is %sempty\n",
  120. (temp & STS_EINT) ? "not " : "");
  121. xhci_dbg(xhci, " %sHost System Error\n",
  122. (temp & STS_FATAL) ? "WARNING: " : "No ");
  123. xhci_dbg(xhci, " HC is %s\n",
  124. (temp & STS_HALT) ? "halted" : "running");
  125. }
  126. void xhci_print_op_regs(struct xhci_hcd *xhci)
  127. {
  128. xhci_dbg(xhci, "xHCI operational registers at 0x%x:\n",
  129. (unsigned int) xhci->op_regs);
  130. xhci_print_command_reg(xhci);
  131. xhci_print_status(xhci);
  132. }
  133. void xhci_print_ir_set(struct xhci_hcd *xhci, struct intr_reg *ir_set, int set_num)
  134. {
  135. void *addr;
  136. u32 temp;
  137. addr = &ir_set->irq_pending;
  138. temp = xhci_readl(xhci, addr);
  139. if (temp == XHCI_INIT_VALUE)
  140. return;
  141. xhci_dbg(xhci, " 0x%x: ir_set[%i]\n", (unsigned int) ir_set, set_num);
  142. xhci_dbg(xhci, " 0x%x: ir_set.pending = 0x%x\n",
  143. (unsigned int) addr, (unsigned int) temp);
  144. addr = &ir_set->irq_control;
  145. temp = xhci_readl(xhci, addr);
  146. xhci_dbg(xhci, " 0x%x: ir_set.control = 0x%x\n",
  147. (unsigned int) addr, (unsigned int) temp);
  148. addr = &ir_set->erst_size;
  149. temp = xhci_readl(xhci, addr);
  150. xhci_dbg(xhci, " 0x%x: ir_set.erst_size = 0x%x\n",
  151. (unsigned int) addr, (unsigned int) temp);
  152. addr = &ir_set->rsvd;
  153. temp = xhci_readl(xhci, addr);
  154. if (temp != XHCI_INIT_VALUE)
  155. xhci_dbg(xhci, " WARN: 0x%x: ir_set.rsvd = 0x%x\n",
  156. (unsigned int) addr, (unsigned int) temp);
  157. addr = &ir_set->erst_base[0];
  158. temp = xhci_readl(xhci, addr);
  159. xhci_dbg(xhci, " 0x%x: ir_set.erst_base[0] = 0x%x\n",
  160. (unsigned int) addr, (unsigned int) temp);
  161. addr = &ir_set->erst_base[1];
  162. temp = xhci_readl(xhci, addr);
  163. xhci_dbg(xhci, " 0x%x: ir_set.erst_base[1] = 0x%x\n",
  164. (unsigned int) addr, (unsigned int) temp);
  165. addr = &ir_set->erst_dequeue[0];
  166. temp = xhci_readl(xhci, addr);
  167. xhci_dbg(xhci, " 0x%x: ir_set.erst_dequeue[0] = 0x%x\n",
  168. (unsigned int) addr, (unsigned int) temp);
  169. addr = &ir_set->erst_dequeue[1];
  170. temp = xhci_readl(xhci, addr);
  171. xhci_dbg(xhci, " 0x%x: ir_set.erst_dequeue[1] = 0x%x\n",
  172. (unsigned int) addr, (unsigned int) temp);
  173. }
  174. void xhci_print_run_regs(struct xhci_hcd *xhci)
  175. {
  176. u32 temp;
  177. int i;
  178. xhci_dbg(xhci, "xHCI runtime registers at 0x%x:\n",
  179. (unsigned int) xhci->run_regs);
  180. temp = xhci_readl(xhci, &xhci->run_regs->microframe_index);
  181. xhci_dbg(xhci, " 0x%x: Microframe index = 0x%x\n",
  182. (unsigned int) &xhci->run_regs->microframe_index,
  183. (unsigned int) temp);
  184. for (i = 0; i < 7; ++i) {
  185. temp = xhci_readl(xhci, &xhci->run_regs->rsvd[i]);
  186. if (temp != XHCI_INIT_VALUE)
  187. xhci_dbg(xhci, " WARN: 0x%x: Rsvd[%i] = 0x%x\n",
  188. (unsigned int) &xhci->run_regs->rsvd[i],
  189. i, (unsigned int) temp);
  190. }
  191. }
  192. void xhci_print_registers(struct xhci_hcd *xhci)
  193. {
  194. xhci_print_cap_regs(xhci);
  195. xhci_print_op_regs(xhci);
  196. }
  197. void xhci_print_trb_offsets(struct xhci_hcd *xhci, union xhci_trb *trb)
  198. {
  199. int i;
  200. for (i = 0; i < 4; ++i)
  201. xhci_dbg(xhci, "Offset 0x%x = 0x%x\n",
  202. i*4, trb->generic.field[i]);
  203. }
  204. /**
  205. * Debug a transfer request block (TRB).
  206. */
  207. void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb)
  208. {
  209. u64 address;
  210. u32 type = xhci_readl(xhci, &trb->link.control) & TRB_TYPE_BITMASK;
  211. switch (type) {
  212. case TRB_TYPE(TRB_LINK):
  213. xhci_dbg(xhci, "Link TRB:\n");
  214. xhci_print_trb_offsets(xhci, trb);
  215. address = trb->link.segment_ptr[0] +
  216. (((u64) trb->link.segment_ptr[1]) << 32);
  217. xhci_dbg(xhci, "Next ring segment DMA address = 0x%llx\n", address);
  218. xhci_dbg(xhci, "Interrupter target = 0x%x\n",
  219. GET_INTR_TARGET(trb->link.intr_target));
  220. xhci_dbg(xhci, "Cycle bit = %u\n",
  221. (unsigned int) (trb->link.control & TRB_CYCLE));
  222. xhci_dbg(xhci, "Toggle cycle bit = %u\n",
  223. (unsigned int) (trb->link.control & LINK_TOGGLE));
  224. xhci_dbg(xhci, "No Snoop bit = %u\n",
  225. (unsigned int) (trb->link.control & TRB_NO_SNOOP));
  226. break;
  227. case TRB_TYPE(TRB_TRANSFER):
  228. address = trb->trans_event.buffer[0] +
  229. (((u64) trb->trans_event.buffer[1]) << 32);
  230. /*
  231. * FIXME: look at flags to figure out if it's an address or if
  232. * the data is directly in the buffer field.
  233. */
  234. xhci_dbg(xhci, "DMA address or buffer contents= %llu\n", address);
  235. break;
  236. case TRB_TYPE(TRB_COMPLETION):
  237. address = trb->event_cmd.cmd_trb[0] +
  238. (((u64) trb->event_cmd.cmd_trb[1]) << 32);
  239. xhci_dbg(xhci, "Command TRB pointer = %llu\n", address);
  240. xhci_dbg(xhci, "Completion status = %u\n",
  241. (unsigned int) GET_COMP_CODE(trb->event_cmd.status));
  242. xhci_dbg(xhci, "Flags = 0x%x\n", (unsigned int) trb->event_cmd.flags);
  243. break;
  244. default:
  245. xhci_dbg(xhci, "Unknown TRB with TRB type ID %u\n",
  246. (unsigned int) type>>10);
  247. xhci_print_trb_offsets(xhci, trb);
  248. break;
  249. }
  250. }
  251. /**
  252. * Debug a segment with an xHCI ring.
  253. *
  254. * @return The Link TRB of the segment, or NULL if there is no Link TRB
  255. * (which is a bug, since all segments must have a Link TRB).
  256. *
  257. * Prints out all TRBs in the segment, even those after the Link TRB.
  258. *
  259. * XXX: should we print out TRBs that the HC owns? As long as we don't
  260. * write, that should be fine... We shouldn't expect that the memory pointed to
  261. * by the TRB is valid at all. Do we care about ones the HC owns? Probably,
  262. * for HC debugging.
  263. */
  264. void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg)
  265. {
  266. int i;
  267. u32 addr = (u32) seg->dma;
  268. union xhci_trb *trb = seg->trbs;
  269. for (i = 0; i < TRBS_PER_SEGMENT; ++i) {
  270. trb = &seg->trbs[i];
  271. xhci_dbg(xhci, "@%08x %08x %08x %08x %08x\n", addr,
  272. (unsigned int) trb->link.segment_ptr[0],
  273. (unsigned int) trb->link.segment_ptr[1],
  274. (unsigned int) trb->link.intr_target,
  275. (unsigned int) trb->link.control);
  276. addr += sizeof(*trb);
  277. }
  278. }
  279. void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring)
  280. {
  281. xhci_dbg(xhci, "Ring deq = 0x%x (virt), 0x%x (dma)\n",
  282. (unsigned int) ring->dequeue,
  283. trb_virt_to_dma(ring->deq_seg, ring->dequeue));
  284. xhci_dbg(xhci, "Ring deq updated %u times\n",
  285. ring->deq_updates);
  286. xhci_dbg(xhci, "Ring enq = 0x%x (virt), 0x%x (dma)\n",
  287. (unsigned int) ring->enqueue,
  288. trb_virt_to_dma(ring->enq_seg, ring->enqueue));
  289. xhci_dbg(xhci, "Ring enq updated %u times\n",
  290. ring->enq_updates);
  291. }
  292. /**
  293. * Debugging for an xHCI ring, which is a queue broken into multiple segments.
  294. *
  295. * Print out each segment in the ring. Check that the DMA address in
  296. * each link segment actually matches the segment's stored DMA address.
  297. * Check that the link end bit is only set at the end of the ring.
  298. * Check that the dequeue and enqueue pointers point to real data in this ring
  299. * (not some other ring).
  300. */
  301. void xhci_debug_ring(struct xhci_hcd *xhci, struct xhci_ring *ring)
  302. {
  303. /* FIXME: Throw an error if any segment doesn't have a Link TRB */
  304. struct xhci_segment *seg;
  305. struct xhci_segment *first_seg = ring->first_seg;
  306. xhci_debug_segment(xhci, first_seg);
  307. if (!ring->enq_updates && !ring->deq_updates) {
  308. xhci_dbg(xhci, " Ring has not been updated\n");
  309. return;
  310. }
  311. for (seg = first_seg->next; seg != first_seg; seg = seg->next)
  312. xhci_debug_segment(xhci, seg);
  313. }
  314. void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst)
  315. {
  316. u32 addr = (u32) erst->erst_dma_addr;
  317. int i;
  318. struct xhci_erst_entry *entry;
  319. for (i = 0; i < erst->num_entries; ++i) {
  320. entry = &erst->entries[i];
  321. xhci_dbg(xhci, "@%08x %08x %08x %08x %08x\n",
  322. (unsigned int) addr,
  323. (unsigned int) entry->seg_addr[0],
  324. (unsigned int) entry->seg_addr[1],
  325. (unsigned int) entry->seg_size,
  326. (unsigned int) entry->rsvd);
  327. addr += sizeof(*entry);
  328. }
  329. }
  330. void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci)
  331. {
  332. u32 val;
  333. val = xhci_readl(xhci, &xhci->op_regs->cmd_ring[0]);
  334. xhci_dbg(xhci, "// xHC command ring deq ptr low bits + flags = 0x%x\n", val);
  335. val = xhci_readl(xhci, &xhci->op_regs->cmd_ring[1]);
  336. xhci_dbg(xhci, "// xHC command ring deq ptr high bits = 0x%x\n", val);
  337. }