blob: 5724683cef16b0193877d482bc17c6c0a7024c8f [file] [log] [blame]
Sarah Sharp74c68742009-04-27 19:52:22 -07001/*
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
23#include "xhci.h"
24
25#define XHCI_INIT_VALUE 0x0
26
27/* Add verbose debugging later, just print everything for now */
28
29void xhci_dbg_regs(struct xhci_hcd *xhci)
30{
31 u32 temp;
32
33 xhci_dbg(xhci, "// xHCI capability registers at 0x%x:\n",
34 (unsigned int) xhci->cap_regs);
35 temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase);
36 xhci_dbg(xhci, "// @%x = 0x%x (CAPLENGTH AND HCIVERSION)\n",
37 (unsigned int) &xhci->cap_regs->hc_capbase,
38 (unsigned int) temp);
39 xhci_dbg(xhci, "// CAPLENGTH: 0x%x\n",
40 (unsigned int) HC_LENGTH(temp));
41#if 0
42 xhci_dbg(xhci, "// HCIVERSION: 0x%x\n",
43 (unsigned int) HC_VERSION(temp));
44#endif
45
46 xhci_dbg(xhci, "// xHCI operational registers at 0x%x:\n",
47 (unsigned int) xhci->op_regs);
48
49 temp = xhci_readl(xhci, &xhci->cap_regs->run_regs_off);
50 xhci_dbg(xhci, "// @%x = 0x%x RTSOFF\n",
51 (unsigned int) &xhci->cap_regs->run_regs_off,
52 (unsigned int) temp & RTSOFF_MASK);
53 xhci_dbg(xhci, "// xHCI runtime registers at 0x%x:\n",
54 (unsigned int) xhci->run_regs);
55
56 temp = xhci_readl(xhci, &xhci->cap_regs->db_off);
57 xhci_dbg(xhci, "// @%x = 0x%x DBOFF\n",
58 (unsigned int) &xhci->cap_regs->db_off, temp);
Sarah Sharp0ebbab32009-04-27 19:52:34 -070059 xhci_dbg(xhci, "// Doorbell array at 0x%x:\n",
60 (unsigned int) xhci->dba);
Sarah Sharp74c68742009-04-27 19:52:22 -070061}
62
63void xhci_print_cap_regs(struct xhci_hcd *xhci)
64{
65 u32 temp;
66
67 xhci_dbg(xhci, "xHCI capability registers at 0x%x:\n",
68 (unsigned int) xhci->cap_regs);
69
70 temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase);
71 xhci_dbg(xhci, "CAPLENGTH AND HCIVERSION 0x%x:\n",
72 (unsigned int) temp);
73 xhci_dbg(xhci, "CAPLENGTH: 0x%x\n",
74 (unsigned int) HC_LENGTH(temp));
75 xhci_dbg(xhci, "HCIVERSION: 0x%x\n",
76 (unsigned int) HC_VERSION(temp));
77
78 temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params1);
79 xhci_dbg(xhci, "HCSPARAMS 1: 0x%x\n",
80 (unsigned int) temp);
81 xhci_dbg(xhci, " Max device slots: %u\n",
82 (unsigned int) HCS_MAX_SLOTS(temp));
83 xhci_dbg(xhci, " Max interrupters: %u\n",
84 (unsigned int) HCS_MAX_INTRS(temp));
85 xhci_dbg(xhci, " Max ports: %u\n",
86 (unsigned int) HCS_MAX_PORTS(temp));
87
88 temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params2);
89 xhci_dbg(xhci, "HCSPARAMS 2: 0x%x\n",
90 (unsigned int) temp);
91 xhci_dbg(xhci, " Isoc scheduling threshold: %u\n",
92 (unsigned int) HCS_IST(temp));
93 xhci_dbg(xhci, " Maximum allowed segments in event ring: %u\n",
94 (unsigned int) HCS_ERST_MAX(temp));
95
96 temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params3);
97 xhci_dbg(xhci, "HCSPARAMS 3 0x%x:\n",
98 (unsigned int) temp);
99 xhci_dbg(xhci, " Worst case U1 device exit latency: %u\n",
100 (unsigned int) HCS_U1_LATENCY(temp));
101 xhci_dbg(xhci, " Worst case U2 device exit latency: %u\n",
102 (unsigned int) HCS_U2_LATENCY(temp));
103
104 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
105 xhci_dbg(xhci, "HCC PARAMS 0x%x:\n", (unsigned int) temp);
106 xhci_dbg(xhci, " HC generates %s bit addresses\n",
107 HCC_64BIT_ADDR(temp) ? "64" : "32");
108 /* FIXME */
109 xhci_dbg(xhci, " FIXME: more HCCPARAMS debugging\n");
110
111 temp = xhci_readl(xhci, &xhci->cap_regs->run_regs_off);
112 xhci_dbg(xhci, "RTSOFF 0x%x:\n", temp & RTSOFF_MASK);
113}
114
115void xhci_print_command_reg(struct xhci_hcd *xhci)
116{
117 u32 temp;
118
119 temp = xhci_readl(xhci, &xhci->op_regs->command);
120 xhci_dbg(xhci, "USBCMD 0x%x:\n", temp);
121 xhci_dbg(xhci, " HC is %s\n",
122 (temp & CMD_RUN) ? "running" : "being stopped");
123 xhci_dbg(xhci, " HC has %sfinished hard reset\n",
124 (temp & CMD_RESET) ? "not " : "");
125 xhci_dbg(xhci, " Event Interrupts %s\n",
126 (temp & CMD_EIE) ? "enabled " : "disabled");
127 xhci_dbg(xhci, " Host System Error Interrupts %s\n",
128 (temp & CMD_EIE) ? "enabled " : "disabled");
129 xhci_dbg(xhci, " HC has %sfinished light reset\n",
130 (temp & CMD_LRESET) ? "not " : "");
131}
132
133void xhci_print_status(struct xhci_hcd *xhci)
134{
135 u32 temp;
136
137 temp = xhci_readl(xhci, &xhci->op_regs->status);
138 xhci_dbg(xhci, "USBSTS 0x%x:\n", temp);
139 xhci_dbg(xhci, " Event ring is %sempty\n",
140 (temp & STS_EINT) ? "not " : "");
141 xhci_dbg(xhci, " %sHost System Error\n",
142 (temp & STS_FATAL) ? "WARNING: " : "No ");
143 xhci_dbg(xhci, " HC is %s\n",
144 (temp & STS_HALT) ? "halted" : "running");
145}
146
147void xhci_print_op_regs(struct xhci_hcd *xhci)
148{
149 xhci_dbg(xhci, "xHCI operational registers at 0x%x:\n",
150 (unsigned int) xhci->op_regs);
151 xhci_print_command_reg(xhci);
152 xhci_print_status(xhci);
153}
154
155void xhci_print_ir_set(struct xhci_hcd *xhci, struct intr_reg *ir_set, int set_num)
156{
157 void *addr;
158 u32 temp;
159
160 addr = &ir_set->irq_pending;
161 temp = xhci_readl(xhci, addr);
162 if (temp == XHCI_INIT_VALUE)
163 return;
164
165 xhci_dbg(xhci, " 0x%x: ir_set[%i]\n", (unsigned int) ir_set, set_num);
166
167 xhci_dbg(xhci, " 0x%x: ir_set.pending = 0x%x\n",
168 (unsigned int) addr, (unsigned int) temp);
169
170 addr = &ir_set->irq_control;
171 temp = xhci_readl(xhci, addr);
172 xhci_dbg(xhci, " 0x%x: ir_set.control = 0x%x\n",
173 (unsigned int) addr, (unsigned int) temp);
174
175 addr = &ir_set->erst_size;
176 temp = xhci_readl(xhci, addr);
177 xhci_dbg(xhci, " 0x%x: ir_set.erst_size = 0x%x\n",
178 (unsigned int) addr, (unsigned int) temp);
179
180 addr = &ir_set->rsvd;
181 temp = xhci_readl(xhci, addr);
182 if (temp != XHCI_INIT_VALUE)
183 xhci_dbg(xhci, " WARN: 0x%x: ir_set.rsvd = 0x%x\n",
184 (unsigned int) addr, (unsigned int) temp);
185
186 addr = &ir_set->erst_base[0];
187 temp = xhci_readl(xhci, addr);
188 xhci_dbg(xhci, " 0x%x: ir_set.erst_base[0] = 0x%x\n",
189 (unsigned int) addr, (unsigned int) temp);
190
191 addr = &ir_set->erst_base[1];
192 temp = xhci_readl(xhci, addr);
193 xhci_dbg(xhci, " 0x%x: ir_set.erst_base[1] = 0x%x\n",
194 (unsigned int) addr, (unsigned int) temp);
195
196 addr = &ir_set->erst_dequeue[0];
197 temp = xhci_readl(xhci, addr);
198 xhci_dbg(xhci, " 0x%x: ir_set.erst_dequeue[0] = 0x%x\n",
199 (unsigned int) addr, (unsigned int) temp);
200
201 addr = &ir_set->erst_dequeue[1];
202 temp = xhci_readl(xhci, addr);
203 xhci_dbg(xhci, " 0x%x: ir_set.erst_dequeue[1] = 0x%x\n",
204 (unsigned int) addr, (unsigned int) temp);
205}
206
207void xhci_print_run_regs(struct xhci_hcd *xhci)
208{
209 u32 temp;
210 int i;
211
212 xhci_dbg(xhci, "xHCI runtime registers at 0x%x:\n",
213 (unsigned int) xhci->run_regs);
214 temp = xhci_readl(xhci, &xhci->run_regs->microframe_index);
215 xhci_dbg(xhci, " 0x%x: Microframe index = 0x%x\n",
216 (unsigned int) &xhci->run_regs->microframe_index,
217 (unsigned int) temp);
218 for (i = 0; i < 7; ++i) {
219 temp = xhci_readl(xhci, &xhci->run_regs->rsvd[i]);
220 if (temp != XHCI_INIT_VALUE)
221 xhci_dbg(xhci, " WARN: 0x%x: Rsvd[%i] = 0x%x\n",
222 (unsigned int) &xhci->run_regs->rsvd[i],
223 i, (unsigned int) temp);
224 }
225}
226
227void xhci_print_registers(struct xhci_hcd *xhci)
228{
229 xhci_print_cap_regs(xhci);
230 xhci_print_op_regs(xhci);
231}
Sarah Sharp0ebbab32009-04-27 19:52:34 -0700232
233
234/**
235 * Debug a segment with an xHCI ring.
236 *
237 * @return The Link TRB of the segment, or NULL if there is no Link TRB
238 * (which is a bug, since all segments must have a Link TRB).
239 *
240 * Prints out all TRBs in the segment, even those after the Link TRB.
241 *
242 * XXX: should we print out TRBs that the HC owns? As long as we don't
243 * write, that should be fine... We shouldn't expect that the memory pointed to
244 * by the TRB is valid at all. Do we care about ones the HC owns? Probably,
245 * for HC debugging.
246 */
247void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg)
248{
249 int i;
250 u32 addr = (u32) seg->dma;
251 union xhci_trb *trb = seg->trbs;
252
253 for (i = 0; i < TRBS_PER_SEGMENT; ++i) {
254 trb = &seg->trbs[i];
255 xhci_dbg(xhci, "@%08x %08x %08x %08x %08x\n", addr,
256 (unsigned int) trb->link.segment_ptr[0],
257 (unsigned int) trb->link.segment_ptr[1],
258 (unsigned int) trb->link.intr_target,
259 (unsigned int) trb->link.control);
260 addr += sizeof(*trb);
261 }
262}
263
264/**
265 * Debugging for an xHCI ring, which is a queue broken into multiple segments.
266 *
267 * Print out each segment in the ring. Check that the DMA address in
268 * each link segment actually matches the segment's stored DMA address.
269 * Check that the link end bit is only set at the end of the ring.
270 * Check that the dequeue and enqueue pointers point to real data in this ring
271 * (not some other ring).
272 */
273void xhci_debug_ring(struct xhci_hcd *xhci, struct xhci_ring *ring)
274{
275 /* FIXME: Throw an error if any segment doesn't have a Link TRB */
276 struct xhci_segment *seg;
277 struct xhci_segment *first_seg = ring->first_seg;
278 xhci_debug_segment(xhci, first_seg);
279
280 for (seg = first_seg->next; seg != first_seg; seg = seg->next)
281 xhci_debug_segment(xhci, seg);
282}
283
284void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst)
285{
286 u32 addr = (u32) erst->erst_dma_addr;
287 int i;
288 struct xhci_erst_entry *entry;
289
290 for (i = 0; i < erst->num_entries; ++i) {
291 entry = &erst->entries[i];
292 xhci_dbg(xhci, "@%08x %08x %08x %08x %08x\n",
293 (unsigned int) addr,
294 (unsigned int) entry->seg_addr[0],
295 (unsigned int) entry->seg_addr[1],
296 (unsigned int) entry->seg_size,
297 (unsigned int) entry->rsvd);
298 addr += sizeof(*entry);
299 }
300}
301
302void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci)
303{
304 u32 val;
305
306 val = xhci_readl(xhci, &xhci->op_regs->cmd_ring[0]);
307 xhci_dbg(xhci, "// xHC command ring deq ptr low bits + flags = 0x%x\n", val);
308 val = xhci_readl(xhci, &xhci->op_regs->cmd_ring[1]);
309 xhci_dbg(xhci, "// xHC command ring deq ptr high bits = 0x%x\n", val);
310}