blob: 1025713ebdd1c6a5e57179cc99b91f621363cece [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 *
Felipe Balbi3587f362017-04-28 11:28:35 +0300176dwc3_gadget_event_string(char *str, const struct dwc3_event_devt *event)
Felipe Balbi80977dc2014-08-19 16:37:22 -0500177{
Felipe Balbif75cacc2016-05-23 11:10:08 +0300178 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
179
180 switch (event->type) {
Felipe Balbi80977dc2014-08-19 16:37:22 -0500181 case DWC3_DEVICE_EVENT_DISCONNECT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300182 sprintf(str, "Disconnect: [%s]",
183 dwc3_gadget_link_string(state));
184 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500185 case DWC3_DEVICE_EVENT_RESET:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300186 sprintf(str, "Reset [%s]", dwc3_gadget_link_string(state));
187 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500188 case DWC3_DEVICE_EVENT_CONNECT_DONE:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300189 sprintf(str, "Connection Done [%s]",
190 dwc3_gadget_link_string(state));
191 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500192 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300193 sprintf(str, "Link Change [%s]",
194 dwc3_gadget_link_string(state));
195 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500196 case DWC3_DEVICE_EVENT_WAKEUP:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300197 sprintf(str, "WakeUp [%s]", dwc3_gadget_link_string(state));
198 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500199 case DWC3_DEVICE_EVENT_EOPF:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300200 sprintf(str, "End-Of-Frame [%s]",
201 dwc3_gadget_link_string(state));
202 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500203 case DWC3_DEVICE_EVENT_SOF:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300204 sprintf(str, "Start-Of-Frame [%s]",
205 dwc3_gadget_link_string(state));
206 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500207 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300208 sprintf(str, "Erratic Error [%s]",
209 dwc3_gadget_link_string(state));
210 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500211 case DWC3_DEVICE_EVENT_CMD_CMPL:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300212 sprintf(str, "Command Complete [%s]",
213 dwc3_gadget_link_string(state));
214 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500215 case DWC3_DEVICE_EVENT_OVERFLOW:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300216 sprintf(str, "Overflow [%s]", dwc3_gadget_link_string(state));
217 break;
218 default:
219 sprintf(str, "UNKNOWN");
Felipe Balbi80977dc2014-08-19 16:37:22 -0500220 }
221
Felipe Balbif75cacc2016-05-23 11:10:08 +0300222 return str;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500223}
224
225/**
226 * dwc3_ep_event_string - returns event name
227 * @event: then event code
228 */
Felipe Balbif75cacc2016-05-23 11:10:08 +0300229static inline const char *
Felipe Balbi3587f362017-04-28 11:28:35 +0300230dwc3_ep_event_string(char *str, const struct dwc3_event_depevt *event,
231 u32 ep0state)
Felipe Balbi80977dc2014-08-19 16:37:22 -0500232{
Felipe Balbif75cacc2016-05-23 11:10:08 +0300233 u8 epnum = event->endpoint_number;
Felipe Balbi43c96be2016-09-26 13:23:34 +0300234 size_t len;
Felipe Balbif75cacc2016-05-23 11:10:08 +0300235 int status;
236 int ret;
237
238 ret = sprintf(str, "ep%d%s: ", epnum >> 1,
Felipe Balbi696fe692016-08-24 14:32:39 +0300239 (epnum & 1) ? "in" : "out");
Felipe Balbif75cacc2016-05-23 11:10:08 +0300240 if (ret < 0)
241 return "UNKNOWN";
242
243 switch (event->endpoint_event) {
Felipe Balbi80977dc2014-08-19 16:37:22 -0500244 case DWC3_DEPEVT_XFERCOMPLETE:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300245 strcat(str, "Transfer Complete");
Felipe Balbi43c96be2016-09-26 13:23:34 +0300246 len = strlen(str);
247
248 if (epnum <= 1)
249 sprintf(str + len, " [%s]", dwc3_ep0_state_string(ep0state));
Felipe Balbif75cacc2016-05-23 11:10:08 +0300250 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500251 case DWC3_DEPEVT_XFERINPROGRESS:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300252 strcat(str, "Transfer In-Progress");
253 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500254 case DWC3_DEPEVT_XFERNOTREADY:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300255 strcat(str, "Transfer Not Ready");
256 status = event->status & DEPEVT_STATUS_TRANSFER_ACTIVE;
257 strcat(str, status ? " (Active)" : " (Not Active)");
Felipe Balbi45a2af22016-09-26 12:54:04 +0300258
259 /* Control Endpoints */
260 if (epnum <= 1) {
261 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
262
263 switch (phase) {
264 case DEPEVT_STATUS_CONTROL_DATA:
265 strcat(str, " [Data Phase]");
266 break;
267 case DEPEVT_STATUS_CONTROL_STATUS:
268 strcat(str, " [Status Phase]");
269 }
270 }
Felipe Balbif75cacc2016-05-23 11:10:08 +0300271 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500272 case DWC3_DEPEVT_RXTXFIFOEVT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300273 strcat(str, "FIFO");
274 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500275 case DWC3_DEPEVT_STREAMEVT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300276 status = event->status;
277
278 switch (status) {
279 case DEPEVT_STREAMEVT_FOUND:
280 sprintf(str + ret, " Stream %d Found",
281 event->parameters);
282 break;
283 case DEPEVT_STREAMEVT_NOTFOUND:
284 default:
285 strcat(str, " Stream Not Found");
286 break;
287 }
288
289 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500290 case DWC3_DEPEVT_EPCMDCMPLT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300291 strcat(str, "Endpoint Command Complete");
292 break;
293 default:
294 sprintf(str, "UNKNOWN");
Felipe Balbi80977dc2014-08-19 16:37:22 -0500295 }
296
Felipe Balbif75cacc2016-05-23 11:10:08 +0300297 return str;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500298}
299
Felipe Balbie9960612014-08-19 16:49:20 -0500300/**
301 * dwc3_gadget_event_type_string - return event name
302 * @event: the event code
303 */
304static inline const char *dwc3_gadget_event_type_string(u8 event)
305{
306 switch (event) {
307 case DWC3_DEVICE_EVENT_DISCONNECT:
308 return "Disconnect";
309 case DWC3_DEVICE_EVENT_RESET:
310 return "Reset";
311 case DWC3_DEVICE_EVENT_CONNECT_DONE:
312 return "Connect Done";
313 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
314 return "Link Status Change";
315 case DWC3_DEVICE_EVENT_WAKEUP:
316 return "Wake-Up";
317 case DWC3_DEVICE_EVENT_HIBER_REQ:
318 return "Hibernation";
319 case DWC3_DEVICE_EVENT_EOPF:
320 return "End of Periodic Frame";
321 case DWC3_DEVICE_EVENT_SOF:
322 return "Start of Frame";
323 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
324 return "Erratic Error";
325 case DWC3_DEVICE_EVENT_CMD_CMPL:
326 return "Command Complete";
327 case DWC3_DEVICE_EVENT_OVERFLOW:
328 return "Overflow";
329 default:
330 return "UNKNOWN";
331 }
332}
333
Felipe Balbi3587f362017-04-28 11:28:35 +0300334static inline const char *dwc3_decode_event(char *str, u32 event, u32 ep0state)
Felipe Balbif75cacc2016-05-23 11:10:08 +0300335{
336 const union dwc3_event evt = (union dwc3_event) event;
337
338 if (evt.type.is_devspec)
Felipe Balbi3587f362017-04-28 11:28:35 +0300339 return dwc3_gadget_event_string(str, &evt.devt);
Felipe Balbif75cacc2016-05-23 11:10:08 +0300340 else
Felipe Balbi3587f362017-04-28 11:28:35 +0300341 return dwc3_ep_event_string(str, &evt.depevt, ep0state);
Felipe Balbif75cacc2016-05-23 11:10:08 +0300342}
343
Felipe Balbi0933df12016-05-23 14:02:33 +0300344static inline const char *dwc3_ep_cmd_status_string(int status)
345{
346 switch (status) {
347 case -ETIMEDOUT:
348 return "Timed Out";
349 case 0:
350 return "Successful";
351 case DEPEVT_TRANSFER_NO_RESOURCE:
352 return "No Resource";
353 case DEPEVT_TRANSFER_BUS_EXPIRY:
354 return "Bus Expiry";
355 default:
356 return "UNKNOWN";
357 }
358}
359
Felipe Balbi71f7e702016-05-23 14:16:19 +0300360static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
361{
362 switch (status) {
363 case -ETIMEDOUT:
364 return "Timed Out";
365 case 0:
366 return "Successful";
367 case 1:
368 return "Error";
369 default:
370 return "UNKNOWN";
371 }
372}
373
Felipe Balbi57b14da2016-09-30 14:12:34 +0300374
Felipe Balbi72246da2011-08-19 18:10:58 +0300375#ifdef CONFIG_DEBUG_FS
Du, Changbin4e9f3112016-04-12 19:10:18 +0800376extern void dwc3_debugfs_init(struct dwc3 *);
Felipe Balbi72246da2011-08-19 18:10:58 +0300377extern void dwc3_debugfs_exit(struct dwc3 *);
378#else
Du, Changbin4e9f3112016-04-12 19:10:18 +0800379static inline void dwc3_debugfs_init(struct dwc3 *d)
380{ }
Felipe Balbi72246da2011-08-19 18:10:58 +0300381static inline void dwc3_debugfs_exit(struct dwc3 *d)
382{ }
383#endif
Felipe Balbi80977dc2014-08-19 16:37:22 -0500384#endif /* __DWC3_DEBUG_H */