xhci-dbg.c 17 KB

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