source: mainline/uspace/drv/bus/usb/xhci/debug.c@ 56257ba

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 56257ba was 0bb4738, checked in by Jenda <jenda.jzqk73@…>, 8 years ago

xhci_dump_port: dump all values

  • Property mode set to 100644
File size: 9.0 KB
Line 
1/*
2 * Copyright (c) 2017 Ondrej Hlavaty
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup drvusbxhci
30 * @{
31 */
32/** @file
33 * Memory-mapped register structures of the xHC.
34 */
35
36#include <inttypes.h>
37#include <byteorder.h>
38#include <usb/debug.h>
39
40#include "hw_struct/trb.h"
41#include "debug.h"
42#include "hc.h"
43
44#define PX "\t%-21s = "
45
46#define DUMP_REG_FIELD(ptr, title, size, ...) \
47 usb_log_debug2(PX "%" PRIu##size, title, XHCI_REG_RD_FIELD(ptr, size, ##__VA_ARGS__))
48
49#define DUMP_REG_RANGE(ptr, title, size, ...) \
50 usb_log_debug2(PX "%" PRIu##size, title, XHCI_REG_RD_RANGE(ptr, size, ##__VA_ARGS__))
51
52#define DUMP_REG_FLAG(ptr, title, size, ...) \
53 usb_log_debug2(PX "%s", title, XHCI_REG_RD_FLAG(ptr, size, ##__VA_ARGS__) ? "true" : "false")
54
55#define DUMP_REG_INNER(set, title, field, size, type, ...) \
56 DUMP_REG_##type(&(set)->field, title, size, ##__VA_ARGS__)
57
58#define DUMP_REG(set, c) DUMP_REG_INNER(set, #c, c)
59
60/**
61 * Dumps all capability registers.
62 */
63void xhci_dump_cap_regs(const xhci_cap_regs_t *cap)
64{
65 usb_log_debug2("Capabilities:");
66
67 DUMP_REG(cap, XHCI_CAP_LENGTH);
68 DUMP_REG(cap, XHCI_CAP_VERSION);
69 DUMP_REG(cap, XHCI_CAP_MAX_SLOTS);
70 DUMP_REG(cap, XHCI_CAP_MAX_INTRS);
71 DUMP_REG(cap, XHCI_CAP_MAX_PORTS);
72 DUMP_REG(cap, XHCI_CAP_IST);
73 DUMP_REG(cap, XHCI_CAP_ERST_MAX);
74 usb_log_debug2(PX "%u", "Max Scratchpad bufs", xhci_get_max_spbuf(cap));
75 DUMP_REG(cap, XHCI_CAP_SPR);
76 DUMP_REG(cap, XHCI_CAP_U1EL);
77 DUMP_REG(cap, XHCI_CAP_U2EL);
78 DUMP_REG(cap, XHCI_CAP_AC64);
79 DUMP_REG(cap, XHCI_CAP_BNC);
80 DUMP_REG(cap, XHCI_CAP_CSZ);
81 DUMP_REG(cap, XHCI_CAP_PPC);
82 DUMP_REG(cap, XHCI_CAP_PIND);
83 DUMP_REG(cap, XHCI_CAP_C);
84 DUMP_REG(cap, XHCI_CAP_LTC);
85 DUMP_REG(cap, XHCI_CAP_NSS);
86 DUMP_REG(cap, XHCI_CAP_PAE);
87 DUMP_REG(cap, XHCI_CAP_SPC);
88 DUMP_REG(cap, XHCI_CAP_SEC);
89 DUMP_REG(cap, XHCI_CAP_CFC);
90 DUMP_REG(cap, XHCI_CAP_MAX_PSA_SIZE);
91 DUMP_REG(cap, XHCI_CAP_XECP);
92 DUMP_REG(cap, XHCI_CAP_DBOFF);
93 DUMP_REG(cap, XHCI_CAP_RTSOFF);
94 DUMP_REG(cap, XHCI_CAP_U3C);
95 DUMP_REG(cap, XHCI_CAP_CMC);
96 DUMP_REG(cap, XHCI_CAP_FSC);
97 DUMP_REG(cap, XHCI_CAP_CTC);
98 DUMP_REG(cap, XHCI_CAP_LEC);
99 DUMP_REG(cap, XHCI_CAP_CIC);
100}
101
102void xhci_dump_port(const xhci_port_regs_t *port)
103{
104 DUMP_REG(port, XHCI_PORT_CCS);
105 DUMP_REG(port, XHCI_PORT_PED);
106 DUMP_REG(port, XHCI_PORT_OCA);
107 DUMP_REG(port, XHCI_PORT_PR);
108 DUMP_REG(port, XHCI_PORT_PLS);
109 DUMP_REG(port, XHCI_PORT_PP);
110 DUMP_REG(port, XHCI_PORT_PS);
111 DUMP_REG(port, XHCI_PORT_PIC);
112 DUMP_REG(port, XHCI_PORT_LWS);
113 DUMP_REG(port, XHCI_PORT_CSC);
114 DUMP_REG(port, XHCI_PORT_PEC);
115 DUMP_REG(port, XHCI_PORT_WRC);
116 DUMP_REG(port, XHCI_PORT_OCC);
117 DUMP_REG(port, XHCI_PORT_PRC);
118 DUMP_REG(port, XHCI_PORT_PLC);
119 DUMP_REG(port, XHCI_PORT_CEC);
120 DUMP_REG(port, XHCI_PORT_CAS);
121 DUMP_REG(port, XHCI_PORT_WCE);
122 DUMP_REG(port, XHCI_PORT_WDE);
123 DUMP_REG(port, XHCI_PORT_WOE);
124 DUMP_REG(port, XHCI_PORT_DR);
125 DUMP_REG(port, XHCI_PORT_WPR);
126}
127
128void xhci_dump_state(const xhci_hc_t *hc)
129{
130 usb_log_debug2("Operational registers:");
131
132 DUMP_REG(hc->op_regs, XHCI_OP_RS);
133 DUMP_REG(hc->op_regs, XHCI_OP_HCRST);
134 DUMP_REG(hc->op_regs, XHCI_OP_INTE);
135 DUMP_REG(hc->op_regs, XHCI_OP_HSEE);
136 DUMP_REG(hc->op_regs, XHCI_OP_LHCRST);
137 DUMP_REG(hc->op_regs, XHCI_OP_CSS);
138 DUMP_REG(hc->op_regs, XHCI_OP_CRS);
139 DUMP_REG(hc->op_regs, XHCI_OP_EWE);
140 DUMP_REG(hc->op_regs, XHCI_OP_EU3S);
141 DUMP_REG(hc->op_regs, XHCI_OP_CME);
142 DUMP_REG(hc->op_regs, XHCI_OP_HCH);
143 DUMP_REG(hc->op_regs, XHCI_OP_HSE);
144 DUMP_REG(hc->op_regs, XHCI_OP_EINT);
145 DUMP_REG(hc->op_regs, XHCI_OP_PCD);
146 DUMP_REG(hc->op_regs, XHCI_OP_SSS);
147 DUMP_REG(hc->op_regs, XHCI_OP_RSS);
148 DUMP_REG(hc->op_regs, XHCI_OP_SRE);
149 DUMP_REG(hc->op_regs, XHCI_OP_CNR);
150 DUMP_REG(hc->op_regs, XHCI_OP_HCE);
151 DUMP_REG(hc->op_regs, XHCI_OP_PAGESIZE);
152 DUMP_REG(hc->op_regs, XHCI_OP_NOTIFICATION);
153 DUMP_REG(hc->op_regs, XHCI_OP_RCS);
154 DUMP_REG(hc->op_regs, XHCI_OP_CS);
155 DUMP_REG(hc->op_regs, XHCI_OP_CA);
156 DUMP_REG(hc->op_regs, XHCI_OP_CRR);
157 DUMP_REG(hc->op_regs, XHCI_OP_CRCR_LO);
158 DUMP_REG(hc->op_regs, XHCI_OP_CRCR_HI);
159 DUMP_REG(hc->op_regs, XHCI_OP_DCBAAP_LO);
160 DUMP_REG(hc->op_regs, XHCI_OP_DCBAAP_HI);
161 DUMP_REG(hc->rt_regs, XHCI_RT_MFINDEX);
162
163 usb_log_debug2("Interrupter 0 state:");
164 DUMP_REG(&hc->rt_regs->ir[0], XHCI_INTR_IP);
165 DUMP_REG(&hc->rt_regs->ir[0], XHCI_INTR_IE);
166 DUMP_REG(&hc->rt_regs->ir[0], XHCI_INTR_IMI);
167 DUMP_REG(&hc->rt_regs->ir[0], XHCI_INTR_IMC);
168 DUMP_REG(&hc->rt_regs->ir[0], XHCI_INTR_ERSTSZ);
169 DUMP_REG(&hc->rt_regs->ir[0], XHCI_INTR_ERSTBA_LO);
170 DUMP_REG(&hc->rt_regs->ir[0], XHCI_INTR_ERSTBA_HI);
171 DUMP_REG(&hc->rt_regs->ir[0], XHCI_INTR_ERDP_LO);
172 DUMP_REG(&hc->rt_regs->ir[0], XHCI_INTR_ERDP_HI);
173}
174
175void xhci_dump_ports(const xhci_hc_t *hc)
176{
177 const size_t num_ports = XHCI_REG_RD(hc->cap_regs, XHCI_CAP_MAX_PORTS);
178 for (size_t i = 0; i < num_ports; i++) {
179 usb_log_debug2("Port %zu state:", i);
180
181 xhci_dump_port(&hc->op_regs->portrs[i]);
182 }
183}
184
185static const char *trb_types [] = {
186 [0] = "<empty>",
187#define TRB(t) [XHCI_TRB_TYPE_##t] = #t
188 TRB(NORMAL),
189 TRB(SETUP_STAGE),
190 TRB(DATA_STAGE),
191 TRB(STATUS_STAGE),
192 TRB(ISOCH),
193 TRB(LINK),
194 TRB(EVENT_DATA),
195 TRB(NO_OP),
196 TRB(ENABLE_SLOT_CMD),
197 TRB(DISABLE_SLOT_CMD),
198 TRB(ADDRESS_DEVICE_CMD),
199 TRB(CONFIGURE_ENDPOINT_CMD),
200 TRB(EVALUATE_CONTEXT_CMD),
201 TRB(RESET_ENDPOINT_CMD),
202 TRB(STOP_ENDPOINT_CMD),
203 TRB(SET_TR_DEQUEUE_POINTER_CMD),
204 TRB(RESET_DEVICE_CMD),
205 TRB(FORCE_EVENT_CMD),
206 TRB(NEGOTIATE_BANDWIDTH_CMD),
207 TRB(SET_LATENCY_TOLERANCE_VALUE_CMD),
208 TRB(GET_PORT_BANDWIDTH_CMD),
209 TRB(FORCE_HEADER_CMD),
210 TRB(NO_OP_CMD),
211 TRB(TRANSFER_EVENT),
212 TRB(COMMAND_COMPLETION_EVENT),
213 TRB(PORT_STATUS_CHANGE_EVENT),
214 TRB(BANDWIDTH_REQUEST_EVENT),
215 TRB(DOORBELL_EVENT),
216 TRB(HOST_CONTROLLER_EVENT),
217 TRB(DEVICE_NOTIFICATION_EVENT),
218 TRB(MFINDEX_WRAP_EVENT),
219#undef TRB
220 [XHCI_TRB_TYPE_MAX] = NULL,
221};
222
223const char *xhci_trb_str_type(unsigned type)
224{
225 static char type_buf [20];
226
227 if (type < XHCI_TRB_TYPE_MAX && trb_types[type] != NULL)
228 return trb_types[type];
229
230 snprintf(type_buf, sizeof(type_buf), "<unknown (%u)>", type);
231 return type_buf;
232}
233
234void xhci_dump_trb(const xhci_trb_t *trb)
235{
236 usb_log_debug2("TRB(%p): type %s, cycle %u", trb, xhci_trb_str_type(TRB_TYPE(*trb)), TRB_CYCLE(*trb));
237}
238
239static const char *ec_ids [] = {
240 [0] = "<empty>",
241#define EC(t) [XHCI_EC_##t] = #t
242 EC(USB_LEGACY),
243 EC(SUPPORTED_PROTOCOL),
244 EC(EXTENDED_POWER_MANAGEMENT),
245 EC(IOV),
246 EC(MSI),
247 EC(LOCALMEM),
248 EC(DEBUG),
249 EC(MSIX),
250#undef EC
251 [XHCI_EC_MAX] = NULL
252};
253
254const char *xhci_ec_str_id(unsigned id)
255{
256 static char buf [20];
257
258 if (id < XHCI_EC_MAX && ec_ids[id] != NULL)
259 return ec_ids[id];
260
261 snprintf(buf, sizeof(buf), "<unknown (%u)>", id);
262 return buf;
263}
264
265static void xhci_dump_psi(const xhci_psi_t *psi)
266{
267 static const char speed_exp [] = " KMG";
268 static const char *psi_types [] = { "", " rsvd", " RX", " TX" };
269
270 usb_log_debug("Speed %u%s: %5u %cb/s, %s",
271 XHCI_REG_RD(psi, XHCI_PSI_PSIV),
272 psi_types[XHCI_REG_RD(psi, XHCI_PSI_PLT)],
273 XHCI_REG_RD(psi, XHCI_PSI_PSIM),
274 speed_exp[XHCI_REG_RD(psi, XHCI_PSI_PSIE)],
275 XHCI_REG_RD(psi, XHCI_PSI_PFD) ? "full-duplex" : "");
276}
277
278void xhci_dump_extcap(const xhci_extcap_t *ec)
279{
280 xhci_sp_name_t name;
281 unsigned ports_from, ports_to;
282
283 unsigned id = XHCI_REG_RD(ec, XHCI_EC_CAP_ID);
284 usb_log_debug("Extended capability %s", xhci_ec_str_id(id));
285
286 switch (id) {
287 case XHCI_EC_SUPPORTED_PROTOCOL:
288 name.packed = host2uint32_t_le(XHCI_REG_RD(ec, XHCI_EC_SP_NAME));
289 ports_from = XHCI_REG_RD(ec, XHCI_EC_SP_CP_OFF);
290 ports_to = ports_from + XHCI_REG_RD(ec, XHCI_EC_SP_CP_COUNT) - 1;
291 usb_log_debug("\tProtocol %.4s%u.%u, ports %u-%u", name.str,
292 XHCI_REG_RD(ec, XHCI_EC_SP_MAJOR),
293 XHCI_REG_RD(ec, XHCI_EC_SP_MINOR),
294 ports_from, ports_to);
295
296 unsigned psic = XHCI_REG_RD(ec, XHCI_EC_SP_PSIC);
297 for (unsigned i = 0; i < psic; i++)
298 xhci_dump_psi(xhci_extcap_psi(ec, i));
299 break;
300 }
301}
302
303/**
304 * @}
305 */
Note: See TracBrowser for help on using the repository browser.