blob: e105ddfdf44030e90df807339abed84eeef13c30 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001// SPDX-License-Identifier: GPL-2.0
2/**
3 * debug.h - DesignWare USB3 DRD Controller Debug Header
4 *
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
6 *
7 * Authors: Felipe Balbi <balbi@ti.com>,
8 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
9 */
10
11#ifndef __DWC3_DEBUG_H
12#define __DWC3_DEBUG_H
13
14#include "core.h"
15
16/**
17 * dwc3_gadget_ep_cmd_string - returns endpoint command string
18 * @cmd: command code
19 */
20static inline const char *
21dwc3_gadget_ep_cmd_string(u8 cmd)
22{
23 switch (cmd) {
24 case DWC3_DEPCMD_DEPSTARTCFG:
25 return "Start New Configuration";
26 case DWC3_DEPCMD_ENDTRANSFER:
27 return "End Transfer";
28 case DWC3_DEPCMD_UPDATETRANSFER:
29 return "Update Transfer";
30 case DWC3_DEPCMD_STARTTRANSFER:
31 return "Start Transfer";
32 case DWC3_DEPCMD_CLEARSTALL:
33 return "Clear Stall";
34 case DWC3_DEPCMD_SETSTALL:
35 return "Set Stall";
36 case DWC3_DEPCMD_GETEPSTATE:
37 return "Get Endpoint State";
38 case DWC3_DEPCMD_SETTRANSFRESOURCE:
39 return "Set Endpoint Transfer Resource";
40 case DWC3_DEPCMD_SETEPCONFIG:
41 return "Set Endpoint Configuration";
42 default:
43 return "UNKNOWN command";
44 }
45}
46
47/**
48 * dwc3_gadget_generic_cmd_string - returns generic command string
49 * @cmd: command code
50 */
51static inline const char *
52dwc3_gadget_generic_cmd_string(u8 cmd)
53{
54 switch (cmd) {
55 case DWC3_DGCMD_SET_LMP:
56 return "Set LMP";
57 case DWC3_DGCMD_SET_PERIODIC_PAR:
58 return "Set Periodic Parameters";
59 case DWC3_DGCMD_XMIT_FUNCTION:
60 return "Transmit Function Wake Device Notification";
61 case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO:
62 return "Set Scratchpad Buffer Array Address Lo";
63 case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI:
64 return "Set Scratchpad Buffer Array Address Hi";
65 case DWC3_DGCMD_SELECTED_FIFO_FLUSH:
66 return "Selected FIFO Flush";
67 case DWC3_DGCMD_ALL_FIFO_FLUSH:
68 return "All FIFO Flush";
69 case DWC3_DGCMD_SET_ENDPOINT_NRDY:
70 return "Set Endpoint NRDY";
71 case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK:
72 return "Run SoC Bus Loopback Test";
73 default:
74 return "UNKNOWN";
75 }
76}
77
78/**
79 * dwc3_gadget_link_string - returns link name
80 * @link_state: link state code
81 */
82static inline const char *
83dwc3_gadget_link_string(enum dwc3_link_state link_state)
84{
85 switch (link_state) {
86 case DWC3_LINK_STATE_U0:
87 return "U0";
88 case DWC3_LINK_STATE_U1:
89 return "U1";
90 case DWC3_LINK_STATE_U2:
91 return "U2";
92 case DWC3_LINK_STATE_U3:
93 return "U3";
94 case DWC3_LINK_STATE_SS_DIS:
95 return "SS.Disabled";
96 case DWC3_LINK_STATE_RX_DET:
97 return "RX.Detect";
98 case DWC3_LINK_STATE_SS_INACT:
99 return "SS.Inactive";
100 case DWC3_LINK_STATE_POLL:
101 return "Polling";
102 case DWC3_LINK_STATE_RECOV:
103 return "Recovery";
104 case DWC3_LINK_STATE_HRESET:
105 return "Hot Reset";
106 case DWC3_LINK_STATE_CMPLY:
107 return "Compliance";
108 case DWC3_LINK_STATE_LPBK:
109 return "Loopback";
110 case DWC3_LINK_STATE_RESET:
111 return "Reset";
112 case DWC3_LINK_STATE_RESUME:
113 return "Resume";
114 default:
115 return "UNKNOWN link state\n";
116 }
117}
118
119/**
David Brazdil0f672f62019-12-10 10:32:29 +0000120 * dwc3_gadget_hs_link_string - returns highspeed and below link name
121 * @link_state: link state code
122 */
123static inline const char *
124dwc3_gadget_hs_link_string(enum dwc3_link_state link_state)
125{
126 switch (link_state) {
127 case DWC3_LINK_STATE_U0:
128 return "On";
129 case DWC3_LINK_STATE_U2:
130 return "Sleep";
131 case DWC3_LINK_STATE_U3:
132 return "Suspend";
133 case DWC3_LINK_STATE_SS_DIS:
134 return "Disconnected";
135 case DWC3_LINK_STATE_RX_DET:
136 return "Early Suspend";
137 case DWC3_LINK_STATE_RECOV:
138 return "Recovery";
139 case DWC3_LINK_STATE_RESET:
140 return "Reset";
141 case DWC3_LINK_STATE_RESUME:
142 return "Resume";
143 default:
144 return "UNKNOWN link state\n";
145 }
146}
147
148/**
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000149 * dwc3_trb_type_string - returns TRB type as a string
150 * @type: the type of the TRB
151 */
152static inline const char *dwc3_trb_type_string(unsigned int type)
153{
154 switch (type) {
155 case DWC3_TRBCTL_NORMAL:
156 return "normal";
157 case DWC3_TRBCTL_CONTROL_SETUP:
158 return "setup";
159 case DWC3_TRBCTL_CONTROL_STATUS2:
160 return "status2";
161 case DWC3_TRBCTL_CONTROL_STATUS3:
162 return "status3";
163 case DWC3_TRBCTL_CONTROL_DATA:
164 return "data";
165 case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
166 return "isoc-first";
167 case DWC3_TRBCTL_ISOCHRONOUS:
168 return "isoc";
169 case DWC3_TRBCTL_LINK_TRB:
170 return "link";
171 default:
172 return "UNKNOWN";
173 }
174}
175
176static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
177{
178 switch (state) {
179 case EP0_UNCONNECTED:
180 return "Unconnected";
181 case EP0_SETUP_PHASE:
182 return "Setup Phase";
183 case EP0_DATA_PHASE:
184 return "Data Phase";
185 case EP0_STATUS_PHASE:
186 return "Status Phase";
187 default:
188 return "UNKNOWN";
189 }
190}
191
192/**
193 * dwc3_gadget_event_string - returns event name
194 * @event: the event code
195 */
David Brazdil0f672f62019-12-10 10:32:29 +0000196static inline const char *dwc3_gadget_event_string(char *str, size_t size,
197 const struct dwc3_event_devt *event)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000198{
199 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
200
201 switch (event->type) {
202 case DWC3_DEVICE_EVENT_DISCONNECT:
David Brazdil0f672f62019-12-10 10:32:29 +0000203 snprintf(str, size, "Disconnect: [%s]",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000204 dwc3_gadget_link_string(state));
205 break;
206 case DWC3_DEVICE_EVENT_RESET:
David Brazdil0f672f62019-12-10 10:32:29 +0000207 snprintf(str, size, "Reset [%s]",
208 dwc3_gadget_link_string(state));
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000209 break;
210 case DWC3_DEVICE_EVENT_CONNECT_DONE:
David Brazdil0f672f62019-12-10 10:32:29 +0000211 snprintf(str, size, "Connection Done [%s]",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000212 dwc3_gadget_link_string(state));
213 break;
214 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
David Brazdil0f672f62019-12-10 10:32:29 +0000215 snprintf(str, size, "Link Change [%s]",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000216 dwc3_gadget_link_string(state));
217 break;
218 case DWC3_DEVICE_EVENT_WAKEUP:
David Brazdil0f672f62019-12-10 10:32:29 +0000219 snprintf(str, size, "WakeUp [%s]",
220 dwc3_gadget_link_string(state));
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000221 break;
222 case DWC3_DEVICE_EVENT_EOPF:
David Brazdil0f672f62019-12-10 10:32:29 +0000223 snprintf(str, size, "End-Of-Frame [%s]",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000224 dwc3_gadget_link_string(state));
225 break;
226 case DWC3_DEVICE_EVENT_SOF:
David Brazdil0f672f62019-12-10 10:32:29 +0000227 snprintf(str, size, "Start-Of-Frame [%s]",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000228 dwc3_gadget_link_string(state));
229 break;
230 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
David Brazdil0f672f62019-12-10 10:32:29 +0000231 snprintf(str, size, "Erratic Error [%s]",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000232 dwc3_gadget_link_string(state));
233 break;
234 case DWC3_DEVICE_EVENT_CMD_CMPL:
David Brazdil0f672f62019-12-10 10:32:29 +0000235 snprintf(str, size, "Command Complete [%s]",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000236 dwc3_gadget_link_string(state));
237 break;
238 case DWC3_DEVICE_EVENT_OVERFLOW:
David Brazdil0f672f62019-12-10 10:32:29 +0000239 snprintf(str, size, "Overflow [%s]",
240 dwc3_gadget_link_string(state));
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000241 break;
242 default:
David Brazdil0f672f62019-12-10 10:32:29 +0000243 snprintf(str, size, "UNKNOWN");
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000244 }
245
246 return str;
247}
248
249/**
250 * dwc3_ep_event_string - returns event name
251 * @event: then event code
252 */
David Brazdil0f672f62019-12-10 10:32:29 +0000253static inline const char *dwc3_ep_event_string(char *str, size_t size,
254 const struct dwc3_event_depevt *event, u32 ep0state)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000255{
256 u8 epnum = event->endpoint_number;
257 size_t len;
258 int status;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000259
Olivier Deprez0e641232021-09-23 10:07:05 +0200260 len = scnprintf(str, size, "ep%d%s: ", epnum >> 1,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000261 (epnum & 1) ? "in" : "out");
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000262
263 status = event->status;
264
265 switch (event->endpoint_event) {
266 case DWC3_DEPEVT_XFERCOMPLETE:
Olivier Deprez0e641232021-09-23 10:07:05 +0200267 len += scnprintf(str + len, size - len,
268 "Transfer Complete (%c%c%c)",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000269 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
270 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
271 status & DEPEVT_STATUS_LST ? 'L' : 'l');
272
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000273 if (epnum <= 1)
Olivier Deprez0e641232021-09-23 10:07:05 +0200274 scnprintf(str + len, size - len, " [%s]",
David Brazdil0f672f62019-12-10 10:32:29 +0000275 dwc3_ep0_state_string(ep0state));
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000276 break;
277 case DWC3_DEPEVT_XFERINPROGRESS:
Olivier Deprez0e641232021-09-23 10:07:05 +0200278 scnprintf(str + len, size - len,
279 "Transfer In Progress [%d] (%c%c%c)",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000280 event->parameters,
281 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
282 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
283 status & DEPEVT_STATUS_LST ? 'M' : 'm');
284 break;
285 case DWC3_DEPEVT_XFERNOTREADY:
Olivier Deprez0e641232021-09-23 10:07:05 +0200286 len += scnprintf(str + len, size - len,
287 "Transfer Not Ready [%d]%s",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000288 event->parameters,
289 status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
290 " (Active)" : " (Not Active)");
291
292 /* Control Endpoints */
293 if (epnum <= 1) {
294 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
295
296 switch (phase) {
297 case DEPEVT_STATUS_CONTROL_DATA:
Olivier Deprez0e641232021-09-23 10:07:05 +0200298 scnprintf(str + len, size - len,
David Brazdil0f672f62019-12-10 10:32:29 +0000299 " [Data Phase]");
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000300 break;
301 case DEPEVT_STATUS_CONTROL_STATUS:
Olivier Deprez0e641232021-09-23 10:07:05 +0200302 scnprintf(str + len, size - len,
David Brazdil0f672f62019-12-10 10:32:29 +0000303 " [Status Phase]");
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000304 }
305 }
306 break;
307 case DWC3_DEPEVT_RXTXFIFOEVT:
Olivier Deprez0e641232021-09-23 10:07:05 +0200308 scnprintf(str + len, size - len, "FIFO");
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000309 break;
310 case DWC3_DEPEVT_STREAMEVT:
311 status = event->status;
312
313 switch (status) {
314 case DEPEVT_STREAMEVT_FOUND:
Olivier Deprez0e641232021-09-23 10:07:05 +0200315 scnprintf(str + len, size - len, " Stream %d Found",
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000316 event->parameters);
317 break;
318 case DEPEVT_STREAMEVT_NOTFOUND:
319 default:
Olivier Deprez0e641232021-09-23 10:07:05 +0200320 scnprintf(str + len, size - len, " Stream Not Found");
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000321 break;
322 }
323
324 break;
325 case DWC3_DEPEVT_EPCMDCMPLT:
Olivier Deprez0e641232021-09-23 10:07:05 +0200326 scnprintf(str + len, size - len, "Endpoint Command Complete");
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000327 break;
328 default:
Olivier Deprez0e641232021-09-23 10:07:05 +0200329 scnprintf(str + len, size - len, "UNKNOWN");
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000330 }
331
332 return str;
333}
334
335/**
336 * dwc3_gadget_event_type_string - return event name
337 * @event: the event code
338 */
339static inline const char *dwc3_gadget_event_type_string(u8 event)
340{
341 switch (event) {
342 case DWC3_DEVICE_EVENT_DISCONNECT:
343 return "Disconnect";
344 case DWC3_DEVICE_EVENT_RESET:
345 return "Reset";
346 case DWC3_DEVICE_EVENT_CONNECT_DONE:
347 return "Connect Done";
348 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
349 return "Link Status Change";
350 case DWC3_DEVICE_EVENT_WAKEUP:
351 return "Wake-Up";
352 case DWC3_DEVICE_EVENT_HIBER_REQ:
353 return "Hibernation";
354 case DWC3_DEVICE_EVENT_EOPF:
355 return "End of Periodic Frame";
356 case DWC3_DEVICE_EVENT_SOF:
357 return "Start of Frame";
358 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
359 return "Erratic Error";
360 case DWC3_DEVICE_EVENT_CMD_CMPL:
361 return "Command Complete";
362 case DWC3_DEVICE_EVENT_OVERFLOW:
363 return "Overflow";
364 default:
365 return "UNKNOWN";
366 }
367}
368
David Brazdil0f672f62019-12-10 10:32:29 +0000369static inline const char *dwc3_decode_event(char *str, size_t size, u32 event,
370 u32 ep0state)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000371{
372 const union dwc3_event evt = (union dwc3_event) event;
373
374 if (evt.type.is_devspec)
David Brazdil0f672f62019-12-10 10:32:29 +0000375 return dwc3_gadget_event_string(str, size, &evt.devt);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000376 else
David Brazdil0f672f62019-12-10 10:32:29 +0000377 return dwc3_ep_event_string(str, size, &evt.depevt, ep0state);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000378}
379
380static inline const char *dwc3_ep_cmd_status_string(int status)
381{
382 switch (status) {
383 case -ETIMEDOUT:
384 return "Timed Out";
385 case 0:
386 return "Successful";
387 case DEPEVT_TRANSFER_NO_RESOURCE:
388 return "No Resource";
389 case DEPEVT_TRANSFER_BUS_EXPIRY:
390 return "Bus Expiry";
391 default:
392 return "UNKNOWN";
393 }
394}
395
396static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
397{
398 switch (status) {
399 case -ETIMEDOUT:
400 return "Timed Out";
401 case 0:
402 return "Successful";
403 case 1:
404 return "Error";
405 default:
406 return "UNKNOWN";
407 }
408}
409
410
411#ifdef CONFIG_DEBUG_FS
Olivier Deprez0e641232021-09-23 10:07:05 +0200412extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000413extern void dwc3_debugfs_init(struct dwc3 *);
414extern void dwc3_debugfs_exit(struct dwc3 *);
415#else
Olivier Deprez0e641232021-09-23 10:07:05 +0200416static inline void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
417{ }
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000418static inline void dwc3_debugfs_init(struct dwc3 *d)
419{ }
420static inline void dwc3_debugfs_exit(struct dwc3 *d)
421{ }
422#endif
423#endif /* __DWC3_DEBUG_H */