blob: cb2d8d3f7f3d8d052bb3a94a924ce37100683bb4 [file] [log] [blame]
Felipe Balbi72246da2011-08-19 18:10:58 +03001/**
2 * debug.h - DesignWare USB3 DRD Controller Debug Header
3 *
4 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
Felipe Balbi72246da2011-08-19 18:10:58 +03005 *
6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 *
Felipe Balbi5945f782013-06-30 14:15:11 +03009 * 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 of
11 * the License as published by the Free Software Foundation.
Felipe Balbi72246da2011-08-19 18:10:58 +030012 *
Felipe Balbi5945f782013-06-30 14:15:11 +030013 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Felipe Balbi72246da2011-08-19 18:10:58 +030017 */
18
Felipe Balbi80977dc2014-08-19 16:37:22 -050019#ifndef __DWC3_DEBUG_H
20#define __DWC3_DEBUG_H
21
Felipe Balbi72246da2011-08-19 18:10:58 +030022#include "core.h"
23
Felipe Balbi80977dc2014-08-19 16:37:22 -050024/**
25 * dwc3_gadget_ep_cmd_string - returns endpoint command string
26 * @cmd: command code
27 */
28static inline const char *
29dwc3_gadget_ep_cmd_string(u8 cmd)
30{
31 switch (cmd) {
32 case DWC3_DEPCMD_DEPSTARTCFG:
33 return "Start New Configuration";
34 case DWC3_DEPCMD_ENDTRANSFER:
35 return "End Transfer";
36 case DWC3_DEPCMD_UPDATETRANSFER:
37 return "Update Transfer";
38 case DWC3_DEPCMD_STARTTRANSFER:
39 return "Start Transfer";
40 case DWC3_DEPCMD_CLEARSTALL:
41 return "Clear Stall";
42 case DWC3_DEPCMD_SETSTALL:
43 return "Set Stall";
44 case DWC3_DEPCMD_GETEPSTATE:
45 return "Get Endpoint State";
46 case DWC3_DEPCMD_SETTRANSFRESOURCE:
47 return "Set Endpoint Transfer Resource";
48 case DWC3_DEPCMD_SETEPCONFIG:
49 return "Set Endpoint Configuration";
50 default:
51 return "UNKNOWN command";
52 }
53}
54
55/**
56 * dwc3_gadget_generic_cmd_string - returns generic command string
57 * @cmd: command code
58 */
59static inline const char *
60dwc3_gadget_generic_cmd_string(u8 cmd)
61{
62 switch (cmd) {
63 case DWC3_DGCMD_SET_LMP:
64 return "Set LMP";
65 case DWC3_DGCMD_SET_PERIODIC_PAR:
66 return "Set Periodic Parameters";
67 case DWC3_DGCMD_XMIT_FUNCTION:
68 return "Transmit Function Wake Device Notification";
69 case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO:
70 return "Set Scratchpad Buffer Array Address Lo";
71 case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI:
72 return "Set Scratchpad Buffer Array Address Hi";
73 case DWC3_DGCMD_SELECTED_FIFO_FLUSH:
74 return "Selected FIFO Flush";
75 case DWC3_DGCMD_ALL_FIFO_FLUSH:
76 return "All FIFO Flush";
77 case DWC3_DGCMD_SET_ENDPOINT_NRDY:
78 return "Set Endpoint NRDY";
79 case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK:
80 return "Run SoC Bus Loopback Test";
81 default:
82 return "UNKNOWN";
83 }
84}
85
86/**
87 * dwc3_gadget_link_string - returns link name
88 * @link_state: link state code
89 */
90static inline const char *
91dwc3_gadget_link_string(enum dwc3_link_state link_state)
92{
93 switch (link_state) {
94 case DWC3_LINK_STATE_U0:
95 return "U0";
96 case DWC3_LINK_STATE_U1:
97 return "U1";
98 case DWC3_LINK_STATE_U2:
99 return "U2";
100 case DWC3_LINK_STATE_U3:
101 return "U3";
102 case DWC3_LINK_STATE_SS_DIS:
103 return "SS.Disabled";
104 case DWC3_LINK_STATE_RX_DET:
105 return "RX.Detect";
106 case DWC3_LINK_STATE_SS_INACT:
107 return "SS.Inactive";
108 case DWC3_LINK_STATE_POLL:
109 return "Polling";
110 case DWC3_LINK_STATE_RECOV:
111 return "Recovery";
112 case DWC3_LINK_STATE_HRESET:
113 return "Hot Reset";
114 case DWC3_LINK_STATE_CMPLY:
115 return "Compliance";
116 case DWC3_LINK_STATE_LPBK:
117 return "Loopback";
118 case DWC3_LINK_STATE_RESET:
119 return "Reset";
120 case DWC3_LINK_STATE_RESUME:
121 return "Resume";
122 default:
123 return "UNKNOWN link state\n";
124 }
125}
126
Felipe Balbib5c7ed52017-03-31 14:44:09 +0300127/**
128 * dwc3_trb_type_string - returns TRB type as a string
129 * @type: the type of the TRB
130 */
131static inline const char *dwc3_trb_type_string(unsigned int type)
132{
133 switch (type) {
134 case DWC3_TRBCTL_NORMAL:
135 return "normal";
136 case DWC3_TRBCTL_CONTROL_SETUP:
137 return "setup";
138 case DWC3_TRBCTL_CONTROL_STATUS2:
139 return "status2";
140 case DWC3_TRBCTL_CONTROL_STATUS3:
141 return "status3";
142 case DWC3_TRBCTL_CONTROL_DATA:
143 return "data";
144 case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
145 return "isoc-first";
146 case DWC3_TRBCTL_ISOCHRONOUS:
147 return "isoc";
148 case DWC3_TRBCTL_LINK_TRB:
149 return "link";
150 default:
151 return "UNKNOWN";
152 }
153}
154
Felipe Balbicdd72ac2016-09-26 13:22:21 +0300155static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
156{
157 switch (state) {
158 case EP0_UNCONNECTED:
159 return "Unconnected";
160 case EP0_SETUP_PHASE:
161 return "Setup Phase";
162 case EP0_DATA_PHASE:
163 return "Data Phase";
164 case EP0_STATUS_PHASE:
165 return "Status Phase";
166 default:
167 return "UNKNOWN";
168 }
169}
170
Felipe Balbi80977dc2014-08-19 16:37:22 -0500171/**
172 * dwc3_gadget_event_string - returns event name
173 * @event: the event code
174 */
Felipe Balbif75cacc2016-05-23 11:10:08 +0300175static inline const char *
176dwc3_gadget_event_string(const struct dwc3_event_devt *event)
Felipe Balbi80977dc2014-08-19 16:37:22 -0500177{
Felipe Balbif75cacc2016-05-23 11:10:08 +0300178 static char str[256];
179 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
180
181 switch (event->type) {
Felipe Balbi80977dc2014-08-19 16:37:22 -0500182 case DWC3_DEVICE_EVENT_DISCONNECT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300183 sprintf(str, "Disconnect: [%s]",
184 dwc3_gadget_link_string(state));
185 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500186 case DWC3_DEVICE_EVENT_RESET:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300187 sprintf(str, "Reset [%s]", dwc3_gadget_link_string(state));
188 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500189 case DWC3_DEVICE_EVENT_CONNECT_DONE:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300190 sprintf(str, "Connection Done [%s]",
191 dwc3_gadget_link_string(state));
192 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500193 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300194 sprintf(str, "Link Change [%s]",
195 dwc3_gadget_link_string(state));
196 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500197 case DWC3_DEVICE_EVENT_WAKEUP:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300198 sprintf(str, "WakeUp [%s]", dwc3_gadget_link_string(state));
199 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500200 case DWC3_DEVICE_EVENT_EOPF:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300201 sprintf(str, "End-Of-Frame [%s]",
202 dwc3_gadget_link_string(state));
203 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500204 case DWC3_DEVICE_EVENT_SOF:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300205 sprintf(str, "Start-Of-Frame [%s]",
206 dwc3_gadget_link_string(state));
207 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500208 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300209 sprintf(str, "Erratic Error [%s]",
210 dwc3_gadget_link_string(state));
211 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500212 case DWC3_DEVICE_EVENT_CMD_CMPL:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300213 sprintf(str, "Command Complete [%s]",
214 dwc3_gadget_link_string(state));
215 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500216 case DWC3_DEVICE_EVENT_OVERFLOW:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300217 sprintf(str, "Overflow [%s]", dwc3_gadget_link_string(state));
218 break;
219 default:
220 sprintf(str, "UNKNOWN");
Felipe Balbi80977dc2014-08-19 16:37:22 -0500221 }
222
Felipe Balbif75cacc2016-05-23 11:10:08 +0300223 return str;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500224}
225
226/**
227 * dwc3_ep_event_string - returns event name
228 * @event: then event code
229 */
Felipe Balbif75cacc2016-05-23 11:10:08 +0300230static inline const char *
Felipe Balbi43c96be2016-09-26 13:23:34 +0300231dwc3_ep_event_string(const struct dwc3_event_depevt *event, u32 ep0state)
Felipe Balbi80977dc2014-08-19 16:37:22 -0500232{
Felipe Balbif75cacc2016-05-23 11:10:08 +0300233 u8 epnum = event->endpoint_number;
234 static char str[256];
Felipe Balbi43c96be2016-09-26 13:23:34 +0300235 size_t len;
Felipe Balbif75cacc2016-05-23 11:10:08 +0300236 int status;
237 int ret;
238
239 ret = sprintf(str, "ep%d%s: ", epnum >> 1,
Felipe Balbi696fe692016-08-24 14:32:39 +0300240 (epnum & 1) ? "in" : "out");
Felipe Balbif75cacc2016-05-23 11:10:08 +0300241 if (ret < 0)
242 return "UNKNOWN";
243
244 switch (event->endpoint_event) {
Felipe Balbi80977dc2014-08-19 16:37:22 -0500245 case DWC3_DEPEVT_XFERCOMPLETE:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300246 strcat(str, "Transfer Complete");
Felipe Balbi43c96be2016-09-26 13:23:34 +0300247 len = strlen(str);
248
249 if (epnum <= 1)
250 sprintf(str + len, " [%s]", dwc3_ep0_state_string(ep0state));
Felipe Balbif75cacc2016-05-23 11:10:08 +0300251 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500252 case DWC3_DEPEVT_XFERINPROGRESS:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300253 strcat(str, "Transfer In-Progress");
254 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500255 case DWC3_DEPEVT_XFERNOTREADY:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300256 strcat(str, "Transfer Not Ready");
257 status = event->status & DEPEVT_STATUS_TRANSFER_ACTIVE;
258 strcat(str, status ? " (Active)" : " (Not Active)");
Felipe Balbi45a2af22016-09-26 12:54:04 +0300259
260 /* Control Endpoints */
261 if (epnum <= 1) {
262 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
263
264 switch (phase) {
265 case DEPEVT_STATUS_CONTROL_DATA:
266 strcat(str, " [Data Phase]");
267 break;
268 case DEPEVT_STATUS_CONTROL_STATUS:
269 strcat(str, " [Status Phase]");
270 }
271 }
Felipe Balbif75cacc2016-05-23 11:10:08 +0300272 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500273 case DWC3_DEPEVT_RXTXFIFOEVT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300274 strcat(str, "FIFO");
275 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500276 case DWC3_DEPEVT_STREAMEVT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300277 status = event->status;
278
279 switch (status) {
280 case DEPEVT_STREAMEVT_FOUND:
281 sprintf(str + ret, " Stream %d Found",
282 event->parameters);
283 break;
284 case DEPEVT_STREAMEVT_NOTFOUND:
285 default:
286 strcat(str, " Stream Not Found");
287 break;
288 }
289
290 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500291 case DWC3_DEPEVT_EPCMDCMPLT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300292 strcat(str, "Endpoint Command Complete");
293 break;
294 default:
295 sprintf(str, "UNKNOWN");
Felipe Balbi80977dc2014-08-19 16:37:22 -0500296 }
297
Felipe Balbif75cacc2016-05-23 11:10:08 +0300298 return str;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500299}
300
Felipe Balbie9960612014-08-19 16:49:20 -0500301/**
302 * dwc3_gadget_event_type_string - return event name
303 * @event: the event code
304 */
305static inline const char *dwc3_gadget_event_type_string(u8 event)
306{
307 switch (event) {
308 case DWC3_DEVICE_EVENT_DISCONNECT:
309 return "Disconnect";
310 case DWC3_DEVICE_EVENT_RESET:
311 return "Reset";
312 case DWC3_DEVICE_EVENT_CONNECT_DONE:
313 return "Connect Done";
314 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
315 return "Link Status Change";
316 case DWC3_DEVICE_EVENT_WAKEUP:
317 return "Wake-Up";
318 case DWC3_DEVICE_EVENT_HIBER_REQ:
319 return "Hibernation";
320 case DWC3_DEVICE_EVENT_EOPF:
321 return "End of Periodic Frame";
322 case DWC3_DEVICE_EVENT_SOF:
323 return "Start of Frame";
324 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
325 return "Erratic Error";
326 case DWC3_DEVICE_EVENT_CMD_CMPL:
327 return "Command Complete";
328 case DWC3_DEVICE_EVENT_OVERFLOW:
329 return "Overflow";
330 default:
331 return "UNKNOWN";
332 }
333}
334
Felipe Balbi43c96be2016-09-26 13:23:34 +0300335static inline const char *dwc3_decode_event(u32 event, u32 ep0state)
Felipe Balbif75cacc2016-05-23 11:10:08 +0300336{
337 const union dwc3_event evt = (union dwc3_event) event;
338
339 if (evt.type.is_devspec)
340 return dwc3_gadget_event_string(&evt.devt);
341 else
Felipe Balbi43c96be2016-09-26 13:23:34 +0300342 return dwc3_ep_event_string(&evt.depevt, ep0state);
Felipe Balbif75cacc2016-05-23 11:10:08 +0300343}
344
Felipe Balbi0933df12016-05-23 14:02:33 +0300345static inline const char *dwc3_ep_cmd_status_string(int status)
346{
347 switch (status) {
348 case -ETIMEDOUT:
349 return "Timed Out";
350 case 0:
351 return "Successful";
352 case DEPEVT_TRANSFER_NO_RESOURCE:
353 return "No Resource";
354 case DEPEVT_TRANSFER_BUS_EXPIRY:
355 return "Bus Expiry";
356 default:
357 return "UNKNOWN";
358 }
359}
360
Felipe Balbi71f7e702016-05-23 14:16:19 +0300361static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
362{
363 switch (status) {
364 case -ETIMEDOUT:
365 return "Timed Out";
366 case 0:
367 return "Successful";
368 case 1:
369 return "Error";
370 default:
371 return "UNKNOWN";
372 }
373}
374
Felipe Balbi57b14da2016-09-30 14:12:34 +0300375
Felipe Balbi72246da2011-08-19 18:10:58 +0300376#ifdef CONFIG_DEBUG_FS
Du, Changbin4e9f3112016-04-12 19:10:18 +0800377extern void dwc3_debugfs_init(struct dwc3 *);
Felipe Balbi72246da2011-08-19 18:10:58 +0300378extern void dwc3_debugfs_exit(struct dwc3 *);
379#else
Du, Changbin4e9f3112016-04-12 19:10:18 +0800380static inline void dwc3_debugfs_init(struct dwc3 *d)
381{ }
Felipe Balbi72246da2011-08-19 18:10:58 +0300382static inline void dwc3_debugfs_exit(struct dwc3 *d)
383{ }
384#endif
Felipe Balbi80977dc2014-08-19 16:37:22 -0500385#endif /* __DWC3_DEBUG_H */