xhci-dbg.c 18 KB

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