blob: b287fc6ab29e25e3b81ee1f75193d09bf1ba29b8 [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 Balbicdd72ac2016-09-26 13:22:21 +0300127static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
128{
129 switch (state) {
130 case EP0_UNCONNECTED:
131 return "Unconnected";
132 case EP0_SETUP_PHASE:
133 return "Setup Phase";
134 case EP0_DATA_PHASE:
135 return "Data Phase";
136 case EP0_STATUS_PHASE:
137 return "Status Phase";
138 default:
139 return "UNKNOWN";
140 }
141}
142
Felipe Balbi80977dc2014-08-19 16:37:22 -0500143/**
144 * dwc3_gadget_event_string - returns event name
145 * @event: the event code
146 */
Felipe Balbif75cacc2016-05-23 11:10:08 +0300147static inline const char *
148dwc3_gadget_event_string(const struct dwc3_event_devt *event)
Felipe Balbi80977dc2014-08-19 16:37:22 -0500149{
Felipe Balbif75cacc2016-05-23 11:10:08 +0300150 static char str[256];
151 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
152
153 switch (event->type) {
Felipe Balbi80977dc2014-08-19 16:37:22 -0500154 case DWC3_DEVICE_EVENT_DISCONNECT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300155 sprintf(str, "Disconnect: [%s]",
156 dwc3_gadget_link_string(state));
157 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500158 case DWC3_DEVICE_EVENT_RESET:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300159 sprintf(str, "Reset [%s]", dwc3_gadget_link_string(state));
160 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500161 case DWC3_DEVICE_EVENT_CONNECT_DONE:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300162 sprintf(str, "Connection Done [%s]",
163 dwc3_gadget_link_string(state));
164 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500165 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300166 sprintf(str, "Link Change [%s]",
167 dwc3_gadget_link_string(state));
168 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500169 case DWC3_DEVICE_EVENT_WAKEUP:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300170 sprintf(str, "WakeUp [%s]", dwc3_gadget_link_string(state));
171 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500172 case DWC3_DEVICE_EVENT_EOPF:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300173 sprintf(str, "End-Of-Frame [%s]",
174 dwc3_gadget_link_string(state));
175 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500176 case DWC3_DEVICE_EVENT_SOF:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300177 sprintf(str, "Start-Of-Frame [%s]",
178 dwc3_gadget_link_string(state));
179 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500180 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300181 sprintf(str, "Erratic Error [%s]",
182 dwc3_gadget_link_string(state));
183 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500184 case DWC3_DEVICE_EVENT_CMD_CMPL:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300185 sprintf(str, "Command Complete [%s]",
186 dwc3_gadget_link_string(state));
187 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500188 case DWC3_DEVICE_EVENT_OVERFLOW:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300189 sprintf(str, "Overflow [%s]", dwc3_gadget_link_string(state));
190 break;
191 default:
192 sprintf(str, "UNKNOWN");
Felipe Balbi80977dc2014-08-19 16:37:22 -0500193 }
194
Felipe Balbif75cacc2016-05-23 11:10:08 +0300195 return str;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500196}
197
198/**
199 * dwc3_ep_event_string - returns event name
200 * @event: then event code
201 */
Felipe Balbif75cacc2016-05-23 11:10:08 +0300202static inline const char *
Felipe Balbi43c96be2016-09-26 13:23:34 +0300203dwc3_ep_event_string(const struct dwc3_event_depevt *event, u32 ep0state)
Felipe Balbi80977dc2014-08-19 16:37:22 -0500204{
Felipe Balbif75cacc2016-05-23 11:10:08 +0300205 u8 epnum = event->endpoint_number;
206 static char str[256];
Felipe Balbi43c96be2016-09-26 13:23:34 +0300207 size_t len;
Felipe Balbif75cacc2016-05-23 11:10:08 +0300208 int status;
209 int ret;
210
211 ret = sprintf(str, "ep%d%s: ", epnum >> 1,
Felipe Balbi696fe692016-08-24 14:32:39 +0300212 (epnum & 1) ? "in" : "out");
Felipe Balbif75cacc2016-05-23 11:10:08 +0300213 if (ret < 0)
214 return "UNKNOWN";
215
216 switch (event->endpoint_event) {
Felipe Balbi80977dc2014-08-19 16:37:22 -0500217 case DWC3_DEPEVT_XFERCOMPLETE:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300218 strcat(str, "Transfer Complete");
Felipe Balbi43c96be2016-09-26 13:23:34 +0300219 len = strlen(str);
220
221 if (epnum <= 1)
222 sprintf(str + len, " [%s]", dwc3_ep0_state_string(ep0state));
Felipe Balbif75cacc2016-05-23 11:10:08 +0300223 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500224 case DWC3_DEPEVT_XFERINPROGRESS:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300225 strcat(str, "Transfer In-Progress");
226 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500227 case DWC3_DEPEVT_XFERNOTREADY:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300228 strcat(str, "Transfer Not Ready");
229 status = event->status & DEPEVT_STATUS_TRANSFER_ACTIVE;
230 strcat(str, status ? " (Active)" : " (Not Active)");
Felipe Balbi45a2af22016-09-26 12:54:04 +0300231
232 /* Control Endpoints */
233 if (epnum <= 1) {
234 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
235
236 switch (phase) {
237 case DEPEVT_STATUS_CONTROL_DATA:
238 strcat(str, " [Data Phase]");
239 break;
240 case DEPEVT_STATUS_CONTROL_STATUS:
241 strcat(str, " [Status Phase]");
242 }
243 }
Felipe Balbif75cacc2016-05-23 11:10:08 +0300244 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500245 case DWC3_DEPEVT_RXTXFIFOEVT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300246 strcat(str, "FIFO");
247 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500248 case DWC3_DEPEVT_STREAMEVT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300249 status = event->status;
250
251 switch (status) {
252 case DEPEVT_STREAMEVT_FOUND:
253 sprintf(str + ret, " Stream %d Found",
254 event->parameters);
255 break;
256 case DEPEVT_STREAMEVT_NOTFOUND:
257 default:
258 strcat(str, " Stream Not Found");
259 break;
260 }
261
262 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500263 case DWC3_DEPEVT_EPCMDCMPLT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300264 strcat(str, "Endpoint Command Complete");
265 break;
266 default:
267 sprintf(str, "UNKNOWN");
Felipe Balbi80977dc2014-08-19 16:37:22 -0500268 }
269
Felipe Balbif75cacc2016-05-23 11:10:08 +0300270 return str;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500271}
272
Felipe Balbie9960612014-08-19 16:49:20 -0500273/**
274 * dwc3_gadget_event_type_string - return event name
275 * @event: the event code
276 */
277static inline const char *dwc3_gadget_event_type_string(u8 event)
278{
279 switch (event) {
280 case DWC3_DEVICE_EVENT_DISCONNECT:
281 return "Disconnect";
282 case DWC3_DEVICE_EVENT_RESET:
283 return "Reset";
284 case DWC3_DEVICE_EVENT_CONNECT_DONE:
285 return "Connect Done";
286 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
287 return "Link Status Change";
288 case DWC3_DEVICE_EVENT_WAKEUP:
289 return "Wake-Up";
290 case DWC3_DEVICE_EVENT_HIBER_REQ:
291 return "Hibernation";
292 case DWC3_DEVICE_EVENT_EOPF:
293 return "End of Periodic Frame";
294 case DWC3_DEVICE_EVENT_SOF:
295 return "Start of Frame";
296 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
297 return "Erratic Error";
298 case DWC3_DEVICE_EVENT_CMD_CMPL:
299 return "Command Complete";
300 case DWC3_DEVICE_EVENT_OVERFLOW:
301 return "Overflow";
302 default:
303 return "UNKNOWN";
304 }
305}
306
Felipe Balbi43c96be2016-09-26 13:23:34 +0300307static inline const char *dwc3_decode_event(u32 event, u32 ep0state)
Felipe Balbif75cacc2016-05-23 11:10:08 +0300308{
309 const union dwc3_event evt = (union dwc3_event) event;
310
311 if (evt.type.is_devspec)
312 return dwc3_gadget_event_string(&evt.devt);
313 else
Felipe Balbi43c96be2016-09-26 13:23:34 +0300314 return dwc3_ep_event_string(&evt.depevt, ep0state);
Felipe Balbif75cacc2016-05-23 11:10:08 +0300315}
316
Felipe Balbi0933df12016-05-23 14:02:33 +0300317static inline const char *dwc3_ep_cmd_status_string(int status)
318{
319 switch (status) {
320 case -ETIMEDOUT:
321 return "Timed Out";
322 case 0:
323 return "Successful";
324 case DEPEVT_TRANSFER_NO_RESOURCE:
325 return "No Resource";
326 case DEPEVT_TRANSFER_BUS_EXPIRY:
327 return "Bus Expiry";
328 default:
329 return "UNKNOWN";
330 }
331}
332
Felipe Balbi71f7e702016-05-23 14:16:19 +0300333static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
334{
335 switch (status) {
336 case -ETIMEDOUT:
337 return "Timed Out";
338 case 0:
339 return "Successful";
340 case 1:
341 return "Error";
342 default:
343 return "UNKNOWN";
344 }
345}
346
Felipe Balbi2c4cbe6e52014-04-30 17:45:10 -0500347void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...);
348
Felipe Balbi72246da2011-08-19 18:10:58 +0300349#ifdef CONFIG_DEBUG_FS
Du, Changbin4e9f3112016-04-12 19:10:18 +0800350extern void dwc3_debugfs_init(struct dwc3 *);
Felipe Balbi72246da2011-08-19 18:10:58 +0300351extern void dwc3_debugfs_exit(struct dwc3 *);
352#else
Du, Changbin4e9f3112016-04-12 19:10:18 +0800353static inline void dwc3_debugfs_init(struct dwc3 *d)
354{ }
Felipe Balbi72246da2011-08-19 18:10:58 +0300355static inline void dwc3_debugfs_exit(struct dwc3 *d)
356{ }
357#endif
Felipe Balbi80977dc2014-08-19 16:37:22 -0500358#endif /* __DWC3_DEBUG_H */