xhci-dbg.c 15 KB

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