blob: fe8abee315511c4f3a9185822ad48d00d606206a [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
127/**
128 * dwc3_gadget_event_string - returns event name
129 * @event: the event code
130 */
Felipe Balbif75cacc2016-05-23 11:10:08 +0300131static inline const char *
132dwc3_gadget_event_string(const struct dwc3_event_devt *event)
Felipe Balbi80977dc2014-08-19 16:37:22 -0500133{
Felipe Balbif75cacc2016-05-23 11:10:08 +0300134 static char str[256];
135 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
136
137 switch (event->type) {
Felipe Balbi80977dc2014-08-19 16:37:22 -0500138 case DWC3_DEVICE_EVENT_DISCONNECT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300139 sprintf(str, "Disconnect: [%s]",
140 dwc3_gadget_link_string(state));
141 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500142 case DWC3_DEVICE_EVENT_RESET:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300143 sprintf(str, "Reset [%s]", dwc3_gadget_link_string(state));
144 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500145 case DWC3_DEVICE_EVENT_CONNECT_DONE:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300146 sprintf(str, "Connection Done [%s]",
147 dwc3_gadget_link_string(state));
148 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500149 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300150 sprintf(str, "Link Change [%s]",
151 dwc3_gadget_link_string(state));
152 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500153 case DWC3_DEVICE_EVENT_WAKEUP:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300154 sprintf(str, "WakeUp [%s]", dwc3_gadget_link_string(state));
155 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500156 case DWC3_DEVICE_EVENT_EOPF:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300157 sprintf(str, "End-Of-Frame [%s]",
158 dwc3_gadget_link_string(state));
159 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500160 case DWC3_DEVICE_EVENT_SOF:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300161 sprintf(str, "Start-Of-Frame [%s]",
162 dwc3_gadget_link_string(state));
163 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500164 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300165 sprintf(str, "Erratic Error [%s]",
166 dwc3_gadget_link_string(state));
167 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500168 case DWC3_DEVICE_EVENT_CMD_CMPL:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300169 sprintf(str, "Command Complete [%s]",
170 dwc3_gadget_link_string(state));
171 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500172 case DWC3_DEVICE_EVENT_OVERFLOW:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300173 sprintf(str, "Overflow [%s]", dwc3_gadget_link_string(state));
174 break;
175 default:
176 sprintf(str, "UNKNOWN");
Felipe Balbi80977dc2014-08-19 16:37:22 -0500177 }
178
Felipe Balbif75cacc2016-05-23 11:10:08 +0300179 return str;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500180}
181
182/**
183 * dwc3_ep_event_string - returns event name
184 * @event: then event code
185 */
Felipe Balbif75cacc2016-05-23 11:10:08 +0300186static inline const char *
187dwc3_ep_event_string(const struct dwc3_event_depevt *event)
Felipe Balbi80977dc2014-08-19 16:37:22 -0500188{
Felipe Balbif75cacc2016-05-23 11:10:08 +0300189 u8 epnum = event->endpoint_number;
190 static char str[256];
191 int status;
192 int ret;
193
194 ret = sprintf(str, "ep%d%s: ", epnum >> 1,
Felipe Balbi696fe692016-08-24 14:32:39 +0300195 (epnum & 1) ? "in" : "out");
Felipe Balbif75cacc2016-05-23 11:10:08 +0300196 if (ret < 0)
197 return "UNKNOWN";
198
199 switch (event->endpoint_event) {
Felipe Balbi80977dc2014-08-19 16:37:22 -0500200 case DWC3_DEPEVT_XFERCOMPLETE:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300201 strcat(str, "Transfer Complete");
202 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500203 case DWC3_DEPEVT_XFERINPROGRESS:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300204 strcat(str, "Transfer In-Progress");
205 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500206 case DWC3_DEPEVT_XFERNOTREADY:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300207 strcat(str, "Transfer Not Ready");
208 status = event->status & DEPEVT_STATUS_TRANSFER_ACTIVE;
209 strcat(str, status ? " (Active)" : " (Not Active)");
Felipe Balbi45a2af22016-09-26 12:54:04 +0300210
211 /* Control Endpoints */
212 if (epnum <= 1) {
213 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
214
215 switch (phase) {
216 case DEPEVT_STATUS_CONTROL_DATA:
217 strcat(str, " [Data Phase]");
218 break;
219 case DEPEVT_STATUS_CONTROL_STATUS:
220 strcat(str, " [Status Phase]");
221 }
222 }
Felipe Balbif75cacc2016-05-23 11:10:08 +0300223 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500224 case DWC3_DEPEVT_RXTXFIFOEVT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300225 strcat(str, "FIFO");
226 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500227 case DWC3_DEPEVT_STREAMEVT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300228 status = event->status;
229
230 switch (status) {
231 case DEPEVT_STREAMEVT_FOUND:
232 sprintf(str + ret, " Stream %d Found",
233 event->parameters);
234 break;
235 case DEPEVT_STREAMEVT_NOTFOUND:
236 default:
237 strcat(str, " Stream Not Found");
238 break;
239 }
240
241 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500242 case DWC3_DEPEVT_EPCMDCMPLT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300243 strcat(str, "Endpoint Command Complete");
244 break;
245 default:
246 sprintf(str, "UNKNOWN");
Felipe Balbi80977dc2014-08-19 16:37:22 -0500247 }
248
Felipe Balbif75cacc2016-05-23 11:10:08 +0300249 return str;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500250}
251
Felipe Balbie9960612014-08-19 16:49:20 -0500252/**
253 * dwc3_gadget_event_type_string - return event name
254 * @event: the event code
255 */
256static inline const char *dwc3_gadget_event_type_string(u8 event)
257{
258 switch (event) {
259 case DWC3_DEVICE_EVENT_DISCONNECT:
260 return "Disconnect";
261 case DWC3_DEVICE_EVENT_RESET:
262 return "Reset";
263 case DWC3_DEVICE_EVENT_CONNECT_DONE:
264 return "Connect Done";
265 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
266 return "Link Status Change";
267 case DWC3_DEVICE_EVENT_WAKEUP:
268 return "Wake-Up";
269 case DWC3_DEVICE_EVENT_HIBER_REQ:
270 return "Hibernation";
271 case DWC3_DEVICE_EVENT_EOPF:
272 return "End of Periodic Frame";
273 case DWC3_DEVICE_EVENT_SOF:
274 return "Start of Frame";
275 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
276 return "Erratic Error";
277 case DWC3_DEVICE_EVENT_CMD_CMPL:
278 return "Command Complete";
279 case DWC3_DEVICE_EVENT_OVERFLOW:
280 return "Overflow";
281 default:
282 return "UNKNOWN";
283 }
284}
285
Felipe Balbif75cacc2016-05-23 11:10:08 +0300286static inline const char *dwc3_decode_event(u32 event)
287{
288 const union dwc3_event evt = (union dwc3_event) event;
289
290 if (evt.type.is_devspec)
291 return dwc3_gadget_event_string(&evt.devt);
292 else
293 return dwc3_ep_event_string(&evt.depevt);
294}
295
Felipe Balbi0933df12016-05-23 14:02:33 +0300296static inline const char *dwc3_ep_cmd_status_string(int status)
297{
298 switch (status) {
299 case -ETIMEDOUT:
300 return "Timed Out";
301 case 0:
302 return "Successful";
303 case DEPEVT_TRANSFER_NO_RESOURCE:
304 return "No Resource";
305 case DEPEVT_TRANSFER_BUS_EXPIRY:
306 return "Bus Expiry";
307 default:
308 return "UNKNOWN";
309 }
310}
311
Felipe Balbi71f7e702016-05-23 14:16:19 +0300312static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
313{
314 switch (status) {
315 case -ETIMEDOUT:
316 return "Timed Out";
317 case 0:
318 return "Successful";
319 case 1:
320 return "Error";
321 default:
322 return "UNKNOWN";
323 }
324}
325
Felipe Balbi2c4cbe6e52014-04-30 17:45:10 -0500326void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...);
327
Felipe Balbi72246da2011-08-19 18:10:58 +0300328#ifdef CONFIG_DEBUG_FS
Du, Changbin4e9f3112016-04-12 19:10:18 +0800329extern void dwc3_debugfs_init(struct dwc3 *);
Felipe Balbi72246da2011-08-19 18:10:58 +0300330extern void dwc3_debugfs_exit(struct dwc3 *);
331#else
Du, Changbin4e9f3112016-04-12 19:10:18 +0800332static inline void dwc3_debugfs_init(struct dwc3 *d)
333{ }
Felipe Balbi72246da2011-08-19 18:10:58 +0300334static inline void dwc3_debugfs_exit(struct dwc3 *d)
335{ }
336#endif
Felipe Balbi80977dc2014-08-19 16:37:22 -0500337#endif /* __DWC3_DEBUG_H */