xhci-dbg.c 18 KB

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