xhci-dbg.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. #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 = readl(&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 = readl(&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 = readl(&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 = readl(&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 = readl(&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 = readl(&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 = readl(&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 = readl(&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 = readl(&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_HSEIE) ? "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 = readl(&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. __le32 __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) readl(addr));
  144. addr++;
  145. }
  146. }
  147. }
  148. void xhci_print_ir_set(struct xhci_hcd *xhci, int set_num)
  149. {
  150. struct xhci_intr_reg __iomem *ir_set = &xhci->run_regs->ir_set[set_num];
  151. void __iomem *addr;
  152. u32 temp;
  153. u64 temp_64;
  154. addr = &ir_set->irq_pending;
  155. temp = readl(addr);
  156. if (temp == XHCI_INIT_VALUE)
  157. return;
  158. xhci_dbg(xhci, " %p: ir_set[%i]\n", ir_set, set_num);
  159. xhci_dbg(xhci, " %p: ir_set.pending = 0x%x\n", addr,
  160. (unsigned int)temp);
  161. addr = &ir_set->irq_control;
  162. temp = readl(addr);
  163. xhci_dbg(xhci, " %p: ir_set.control = 0x%x\n", addr,
  164. (unsigned int)temp);
  165. addr = &ir_set->erst_size;
  166. temp = readl(addr);
  167. xhci_dbg(xhci, " %p: ir_set.erst_size = 0x%x\n", addr,
  168. (unsigned int)temp);
  169. addr = &ir_set->rsvd;
  170. temp = readl(addr);
  171. if (temp != XHCI_INIT_VALUE)
  172. xhci_dbg(xhci, " WARN: %p: ir_set.rsvd = 0x%x\n",
  173. addr, (unsigned int)temp);
  174. addr = &ir_set->erst_base;
  175. temp_64 = xhci_read_64(xhci, addr);
  176. xhci_dbg(xhci, " %p: ir_set.erst_base = @%08llx\n",
  177. addr, temp_64);
  178. addr = &ir_set->erst_dequeue;
  179. temp_64 = xhci_read_64(xhci, addr);
  180. xhci_dbg(xhci, " %p: ir_set.erst_dequeue = @%08llx\n",
  181. addr, temp_64);
  182. }
  183. void xhci_print_run_regs(struct xhci_hcd *xhci)
  184. {
  185. u32 temp;
  186. int i;
  187. xhci_dbg(xhci, "xHCI runtime registers at %p:\n", xhci->run_regs);
  188. temp = readl(&xhci->run_regs->microframe_index);
  189. xhci_dbg(xhci, " %p: Microframe index = 0x%x\n",
  190. &xhci->run_regs->microframe_index,
  191. (unsigned int) temp);
  192. for (i = 0; i < 7; ++i) {
  193. temp = readl(&xhci->run_regs->rsvd[i]);
  194. if (temp != XHCI_INIT_VALUE)
  195. xhci_dbg(xhci, " WARN: %p: Rsvd[%i] = 0x%x\n",
  196. &xhci->run_regs->rsvd[i],
  197. i, (unsigned int) temp);
  198. }
  199. }
  200. void xhci_print_registers(struct xhci_hcd *xhci)
  201. {
  202. xhci_print_cap_regs(xhci);
  203. xhci_print_op_regs(xhci);
  204. xhci_print_ports(xhci);
  205. }
  206. void xhci_print_trb_offsets(struct xhci_hcd *xhci, union xhci_trb *trb)
  207. {
  208. int i;
  209. for (i = 0; i < 4; ++i)
  210. xhci_dbg(xhci, "Offset 0x%x = 0x%x\n",
  211. i*4, trb->generic.field[i]);
  212. }
  213. /**
  214. * Debug a transfer request block (TRB).
  215. */
  216. void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb)
  217. {
  218. u64 address;
  219. u32 type = le32_to_cpu(trb->link.control) & TRB_TYPE_BITMASK;
  220. switch (type) {
  221. case TRB_TYPE(TRB_LINK):
  222. xhci_dbg(xhci, "Link TRB:\n");
  223. xhci_print_trb_offsets(xhci, trb);
  224. address = le64_to_cpu(trb->link.segment_ptr);
  225. xhci_dbg(xhci, "Next ring segment DMA address = 0x%llx\n", address);
  226. xhci_dbg(xhci, "Interrupter target = 0x%x\n",
  227. GET_INTR_TARGET(le32_to_cpu(trb->link.intr_target)));
  228. xhci_dbg(xhci, "Cycle bit = %u\n",
  229. le32_to_cpu(trb->link.control) & TRB_CYCLE);
  230. xhci_dbg(xhci, "Toggle cycle bit = %u\n",
  231. le32_to_cpu(trb->link.control) & LINK_TOGGLE);
  232. xhci_dbg(xhci, "No Snoop bit = %u\n",
  233. le32_to_cpu(trb->link.control) & TRB_NO_SNOOP);
  234. break;
  235. case TRB_TYPE(TRB_TRANSFER):
  236. address = le64_to_cpu(trb->trans_event.buffer);
  237. /*
  238. * FIXME: look at flags to figure out if it's an address or if
  239. * the data is directly in the buffer field.
  240. */
  241. xhci_dbg(xhci, "DMA address or buffer contents= %llu\n", address);
  242. break;
  243. case TRB_TYPE(TRB_COMPLETION):
  244. address = le64_to_cpu(trb->event_cmd.cmd_trb);
  245. xhci_dbg(xhci, "Command TRB pointer = %llu\n", address);
  246. xhci_dbg(xhci, "Completion status = %u\n",
  247. GET_COMP_CODE(le32_to_cpu(trb->event_cmd.status)));
  248. xhci_dbg(xhci, "Flags = 0x%x\n",
  249. le32_to_cpu(trb->event_cmd.flags));
  250. break;
  251. default:
  252. xhci_dbg(xhci, "Unknown TRB with TRB type ID %u\n",
  253. (unsigned int) type>>10);
  254. xhci_print_trb_offsets(xhci, trb);
  255. break;
  256. }
  257. }
  258. /**
  259. * Debug a segment with an xHCI ring.
  260. *
  261. * @return The Link TRB of the segment, or NULL if there is no Link TRB
  262. * (which is a bug, since all segments must have a Link TRB).
  263. *
  264. * Prints out all TRBs in the segment, even those after the Link TRB.
  265. *
  266. * XXX: should we print out TRBs that the HC owns? As long as we don't
  267. * write, that should be fine... We shouldn't expect that the memory pointed to
  268. * by the TRB is valid at all. Do we care about ones the HC owns? Probably,
  269. * for HC debugging.
  270. */
  271. void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg)
  272. {
  273. int i;
  274. u64 addr = seg->dma;
  275. union xhci_trb *trb = seg->trbs;
  276. for (i = 0; i < TRBS_PER_SEGMENT; ++i) {
  277. trb = &seg->trbs[i];
  278. xhci_dbg(xhci, "@%016llx %08x %08x %08x %08x\n", addr,
  279. lower_32_bits(le64_to_cpu(trb->link.segment_ptr)),
  280. upper_32_bits(le64_to_cpu(trb->link.segment_ptr)),
  281. le32_to_cpu(trb->link.intr_target),
  282. le32_to_cpu(trb->link.control));
  283. addr += sizeof(*trb);
  284. }
  285. }
  286. void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring)
  287. {
  288. xhci_dbg(xhci, "Ring deq = %p (virt), 0x%llx (dma)\n",
  289. ring->dequeue,
  290. (unsigned long long)xhci_trb_virt_to_dma(ring->deq_seg,
  291. ring->dequeue));
  292. xhci_dbg(xhci, "Ring deq updated %u times\n",
  293. ring->deq_updates);
  294. xhci_dbg(xhci, "Ring enq = %p (virt), 0x%llx (dma)\n",
  295. ring->enqueue,
  296. (unsigned long long)xhci_trb_virt_to_dma(ring->enq_seg,
  297. ring->enqueue));
  298. xhci_dbg(xhci, "Ring enq updated %u times\n",
  299. ring->enq_updates);
  300. }
  301. /**
  302. * Debugging for an xHCI ring, which is a queue broken into multiple segments.
  303. *
  304. * Print out each segment in the ring. Check that the DMA address in
  305. * each link segment actually matches the segment's stored DMA address.
  306. * Check that the link end bit is only set at the end of the ring.
  307. * Check that the dequeue and enqueue pointers point to real data in this ring
  308. * (not some other ring).
  309. */
  310. void xhci_debug_ring(struct xhci_hcd *xhci, struct xhci_ring *ring)
  311. {
  312. /* FIXME: Throw an error if any segment doesn't have a Link TRB */
  313. struct xhci_segment *seg;
  314. struct xhci_segment *first_seg = ring->first_seg;
  315. xhci_debug_segment(xhci, first_seg);
  316. if (!ring->enq_updates && !ring->deq_updates) {
  317. xhci_dbg(xhci, " Ring has not been updated\n");
  318. return;
  319. }
  320. for (seg = first_seg->next; seg != first_seg; seg = seg->next)
  321. xhci_debug_segment(xhci, seg);
  322. }
  323. void xhci_dbg_ep_rings(struct xhci_hcd *xhci,
  324. unsigned int slot_id, unsigned int ep_index,
  325. struct xhci_virt_ep *ep)
  326. {
  327. int i;
  328. struct xhci_ring *ring;
  329. if (ep->ep_state & EP_HAS_STREAMS) {
  330. for (i = 1; i < ep->stream_info->num_streams; i++) {
  331. ring = ep->stream_info->stream_rings[i];
  332. xhci_dbg(xhci, "Dev %d endpoint %d stream ID %d:\n",
  333. slot_id, ep_index, i);
  334. xhci_debug_segment(xhci, ring->deq_seg);
  335. }
  336. } else {
  337. ring = ep->ring;
  338. if (!ring)
  339. return;
  340. xhci_dbg(xhci, "Dev %d endpoint ring %d:\n",
  341. slot_id, ep_index);
  342. xhci_debug_segment(xhci, ring->deq_seg);
  343. }
  344. }
  345. void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst)
  346. {
  347. u64 addr = erst->erst_dma_addr;
  348. int i;
  349. struct xhci_erst_entry *entry;
  350. for (i = 0; i < erst->num_entries; ++i) {
  351. entry = &erst->entries[i];
  352. xhci_dbg(xhci, "@%016llx %08x %08x %08x %08x\n",
  353. addr,
  354. lower_32_bits(le64_to_cpu(entry->seg_addr)),
  355. upper_32_bits(le64_to_cpu(entry->seg_addr)),
  356. le32_to_cpu(entry->seg_size),
  357. le32_to_cpu(entry->rsvd));
  358. addr += sizeof(*entry);
  359. }
  360. }
  361. void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci)
  362. {
  363. u64 val;
  364. val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
  365. xhci_dbg(xhci, "// xHC command ring deq ptr low bits + flags = @%08x\n",
  366. lower_32_bits(val));
  367. xhci_dbg(xhci, "// xHC command ring deq ptr high bits = @%08x\n",
  368. upper_32_bits(val));
  369. }
  370. /* Print the last 32 bytes for 64-byte contexts */
  371. static void dbg_rsvd64(struct xhci_hcd *xhci, u64 *ctx, dma_addr_t dma)
  372. {
  373. int i;
  374. for (i = 0; i < 4; ++i) {
  375. xhci_dbg(xhci, "@%p (virt) @%08llx "
  376. "(dma) %#08llx - rsvd64[%d]\n",
  377. &ctx[4 + i], (unsigned long long)dma,
  378. ctx[4 + i], i);
  379. dma += 8;
  380. }
  381. }
  382. char *xhci_get_slot_state(struct xhci_hcd *xhci,
  383. struct xhci_container_ctx *ctx)
  384. {
  385. struct xhci_slot_ctx *slot_ctx = xhci_get_slot_ctx(xhci, ctx);
  386. switch (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state))) {
  387. case SLOT_STATE_ENABLED:
  388. return "enabled/disabled";
  389. case SLOT_STATE_DEFAULT:
  390. return "default";
  391. case SLOT_STATE_ADDRESSED:
  392. return "addressed";
  393. case SLOT_STATE_CONFIGURED:
  394. return "configured";
  395. default:
  396. return "reserved";
  397. }
  398. }
  399. static void xhci_dbg_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx)
  400. {
  401. /* Fields are 32 bits wide, DMA addresses are in bytes */
  402. int field_size = 32 / 8;
  403. int i;
  404. struct xhci_slot_ctx *slot_ctx = xhci_get_slot_ctx(xhci, ctx);
  405. dma_addr_t dma = ctx->dma +
  406. ((unsigned long)slot_ctx - (unsigned long)ctx->bytes);
  407. int csz = HCC_64BYTE_CONTEXT(xhci->hcc_params);
  408. xhci_dbg(xhci, "Slot Context:\n");
  409. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - dev_info\n",
  410. &slot_ctx->dev_info,
  411. (unsigned long long)dma, slot_ctx->dev_info);
  412. dma += field_size;
  413. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - dev_info2\n",
  414. &slot_ctx->dev_info2,
  415. (unsigned long long)dma, slot_ctx->dev_info2);
  416. dma += field_size;
  417. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - tt_info\n",
  418. &slot_ctx->tt_info,
  419. (unsigned long long)dma, slot_ctx->tt_info);
  420. dma += field_size;
  421. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - dev_state\n",
  422. &slot_ctx->dev_state,
  423. (unsigned long long)dma, slot_ctx->dev_state);
  424. dma += field_size;
  425. for (i = 0; i < 4; ++i) {
  426. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - rsvd[%d]\n",
  427. &slot_ctx->reserved[i], (unsigned long long)dma,
  428. slot_ctx->reserved[i], i);
  429. dma += field_size;
  430. }
  431. if (csz)
  432. dbg_rsvd64(xhci, (u64 *)slot_ctx, dma);
  433. }
  434. static void xhci_dbg_ep_ctx(struct xhci_hcd *xhci,
  435. struct xhci_container_ctx *ctx,
  436. unsigned int last_ep)
  437. {
  438. int i, j;
  439. int last_ep_ctx = 31;
  440. /* Fields are 32 bits wide, DMA addresses are in bytes */
  441. int field_size = 32 / 8;
  442. int csz = HCC_64BYTE_CONTEXT(xhci->hcc_params);
  443. if (last_ep < 31)
  444. last_ep_ctx = last_ep + 1;
  445. for (i = 0; i < last_ep_ctx; ++i) {
  446. unsigned int epaddr = xhci_get_endpoint_address(i);
  447. struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, ctx, i);
  448. dma_addr_t dma = ctx->dma +
  449. ((unsigned long)ep_ctx - (unsigned long)ctx->bytes);
  450. xhci_dbg(xhci, "%s Endpoint %02d Context (ep_index %02d):\n",
  451. usb_endpoint_out(epaddr) ? "OUT" : "IN",
  452. epaddr & USB_ENDPOINT_NUMBER_MASK, i);
  453. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - ep_info\n",
  454. &ep_ctx->ep_info,
  455. (unsigned long long)dma, ep_ctx->ep_info);
  456. dma += field_size;
  457. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - ep_info2\n",
  458. &ep_ctx->ep_info2,
  459. (unsigned long long)dma, ep_ctx->ep_info2);
  460. dma += field_size;
  461. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08llx - deq\n",
  462. &ep_ctx->deq,
  463. (unsigned long long)dma, ep_ctx->deq);
  464. dma += 2*field_size;
  465. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - tx_info\n",
  466. &ep_ctx->tx_info,
  467. (unsigned long long)dma, ep_ctx->tx_info);
  468. dma += field_size;
  469. for (j = 0; j < 3; ++j) {
  470. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - rsvd[%d]\n",
  471. &ep_ctx->reserved[j],
  472. (unsigned long long)dma,
  473. ep_ctx->reserved[j], j);
  474. dma += field_size;
  475. }
  476. if (csz)
  477. dbg_rsvd64(xhci, (u64 *)ep_ctx, dma);
  478. }
  479. }
  480. void xhci_dbg_ctx(struct xhci_hcd *xhci,
  481. struct xhci_container_ctx *ctx,
  482. unsigned int last_ep)
  483. {
  484. int i;
  485. /* Fields are 32 bits wide, DMA addresses are in bytes */
  486. int field_size = 32 / 8;
  487. dma_addr_t dma = ctx->dma;
  488. int csz = HCC_64BYTE_CONTEXT(xhci->hcc_params);
  489. if (ctx->type == XHCI_CTX_TYPE_INPUT) {
  490. struct xhci_input_control_ctx *ctrl_ctx =
  491. xhci_get_input_control_ctx(ctx);
  492. if (!ctrl_ctx) {
  493. xhci_warn(xhci, "Could not get input context, bad type.\n");
  494. return;
  495. }
  496. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - drop flags\n",
  497. &ctrl_ctx->drop_flags, (unsigned long long)dma,
  498. ctrl_ctx->drop_flags);
  499. dma += field_size;
  500. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - add flags\n",
  501. &ctrl_ctx->add_flags, (unsigned long long)dma,
  502. ctrl_ctx->add_flags);
  503. dma += field_size;
  504. for (i = 0; i < 6; ++i) {
  505. xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - rsvd2[%d]\n",
  506. &ctrl_ctx->rsvd2[i], (unsigned long long)dma,
  507. ctrl_ctx->rsvd2[i], i);
  508. dma += field_size;
  509. }
  510. if (csz)
  511. dbg_rsvd64(xhci, (u64 *)ctrl_ctx, dma);
  512. }
  513. xhci_dbg_slot_ctx(xhci, ctx);
  514. xhci_dbg_ep_ctx(xhci, ctx, last_ep);
  515. }
  516. void xhci_dbg_trace(struct xhci_hcd *xhci, void (*trace)(struct va_format *),
  517. const char *fmt, ...)
  518. {
  519. struct va_format vaf;
  520. va_list args;
  521. va_start(args, fmt);
  522. vaf.fmt = fmt;
  523. vaf.va = &args;
  524. xhci_dbg(xhci, "%pV\n", &vaf);
  525. trace(&vaf);
  526. va_end(args);
  527. }
  528. EXPORT_SYMBOL_GPL(xhci_dbg_trace);