blob: d223c54115f4a16abcb8a72a5642497da33c8dea [file] [log] [blame]
Nishad Kamdarb33f69f2020-03-28 15:34:46 +05301/* SPDX-License-Identifier: GPL-2.0 */
Aditya Srivastava27088e002021-03-29 19:21:08 +05302/*
Felipe Balbi72246da2011-08-19 18:10:58 +03003 * debug.h - DesignWare USB3 DRD Controller Debug Header
4 *
Alexander A. Klimov10623b82020-07-11 15:58:04 +02005 * Copyright (C) 2010-2011 Texas Instruments Incorporated - https://www.ti.com
Felipe Balbi72246da2011-08-19 18:10:58 +03006 *
7 * Authors: Felipe Balbi <balbi@ti.com>,
8 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Felipe Balbi72246da2011-08-19 18:10:58 +03009 */
10
Felipe Balbi80977dc2014-08-19 16:37:22 -050011#ifndef __DWC3_DEBUG_H
12#define __DWC3_DEBUG_H
13
Felipe Balbi72246da2011-08-19 18:10:58 +030014#include "core.h"
15
Felipe Balbi80977dc2014-08-19 16:37:22 -050016/**
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";
Thinh Nguyen140ca4c2020-05-05 19:47:09 -070071 case DWC3_DGCMD_SET_ENDPOINT_PRIME:
72 return "Set Endpoint Prime";
Felipe Balbi80977dc2014-08-19 16:37:22 -050073 case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK:
74 return "Run SoC Bus Loopback Test";
75 default:
76 return "UNKNOWN";
77 }
78}
79
80/**
81 * dwc3_gadget_link_string - returns link name
82 * @link_state: link state code
83 */
84static inline const char *
85dwc3_gadget_link_string(enum dwc3_link_state link_state)
86{
87 switch (link_state) {
88 case DWC3_LINK_STATE_U0:
89 return "U0";
90 case DWC3_LINK_STATE_U1:
91 return "U1";
92 case DWC3_LINK_STATE_U2:
93 return "U2";
94 case DWC3_LINK_STATE_U3:
95 return "U3";
96 case DWC3_LINK_STATE_SS_DIS:
97 return "SS.Disabled";
98 case DWC3_LINK_STATE_RX_DET:
99 return "RX.Detect";
100 case DWC3_LINK_STATE_SS_INACT:
101 return "SS.Inactive";
102 case DWC3_LINK_STATE_POLL:
103 return "Polling";
104 case DWC3_LINK_STATE_RECOV:
105 return "Recovery";
106 case DWC3_LINK_STATE_HRESET:
107 return "Hot Reset";
108 case DWC3_LINK_STATE_CMPLY:
109 return "Compliance";
110 case DWC3_LINK_STATE_LPBK:
111 return "Loopback";
112 case DWC3_LINK_STATE_RESET:
113 return "Reset";
114 case DWC3_LINK_STATE_RESUME:
115 return "Resume";
116 default:
Thinh Nguyen038761c2019-10-22 12:10:16 -0700117 return "UNKNOWN link state";
Felipe Balbi80977dc2014-08-19 16:37:22 -0500118 }
119}
120
Felipe Balbib5c7ed52017-03-31 14:44:09 +0300121/**
Thinh Nguyen0d36ded2018-11-07 17:55:19 -0800122 * dwc3_gadget_hs_link_string - returns highspeed and below link name
123 * @link_state: link state code
124 */
125static inline const char *
126dwc3_gadget_hs_link_string(enum dwc3_link_state link_state)
127{
128 switch (link_state) {
129 case DWC3_LINK_STATE_U0:
130 return "On";
131 case DWC3_LINK_STATE_U2:
132 return "Sleep";
133 case DWC3_LINK_STATE_U3:
134 return "Suspend";
135 case DWC3_LINK_STATE_SS_DIS:
136 return "Disconnected";
137 case DWC3_LINK_STATE_RX_DET:
138 return "Early Suspend";
139 case DWC3_LINK_STATE_RECOV:
140 return "Recovery";
141 case DWC3_LINK_STATE_RESET:
142 return "Reset";
143 case DWC3_LINK_STATE_RESUME:
144 return "Resume";
145 default:
Thinh Nguyen038761c2019-10-22 12:10:16 -0700146 return "UNKNOWN link state";
Thinh Nguyen0d36ded2018-11-07 17:55:19 -0800147 }
148}
149
150/**
Felipe Balbib5c7ed52017-03-31 14:44:09 +0300151 * dwc3_trb_type_string - returns TRB type as a string
152 * @type: the type of the TRB
153 */
154static inline const char *dwc3_trb_type_string(unsigned int type)
155{
156 switch (type) {
157 case DWC3_TRBCTL_NORMAL:
158 return "normal";
159 case DWC3_TRBCTL_CONTROL_SETUP:
160 return "setup";
161 case DWC3_TRBCTL_CONTROL_STATUS2:
162 return "status2";
163 case DWC3_TRBCTL_CONTROL_STATUS3:
164 return "status3";
165 case DWC3_TRBCTL_CONTROL_DATA:
166 return "data";
167 case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
168 return "isoc-first";
169 case DWC3_TRBCTL_ISOCHRONOUS:
170 return "isoc";
171 case DWC3_TRBCTL_LINK_TRB:
172 return "link";
173 default:
174 return "UNKNOWN";
175 }
176}
177
Felipe Balbicdd72ac2016-09-26 13:22:21 +0300178static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
179{
180 switch (state) {
181 case EP0_UNCONNECTED:
182 return "Unconnected";
183 case EP0_SETUP_PHASE:
184 return "Setup Phase";
185 case EP0_DATA_PHASE:
186 return "Data Phase";
187 case EP0_STATUS_PHASE:
188 return "Status Phase";
189 default:
190 return "UNKNOWN";
191 }
192}
193
Felipe Balbi80977dc2014-08-19 16:37:22 -0500194/**
195 * dwc3_gadget_event_string - returns event name
196 * @event: the event code
197 */
Felipe Balbi7790b352019-02-04 15:43:38 +0200198static inline const char *dwc3_gadget_event_string(char *str, size_t size,
199 const struct dwc3_event_devt *event)
Felipe Balbi80977dc2014-08-19 16:37:22 -0500200{
Felipe Balbif75cacc2016-05-23 11:10:08 +0300201 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
202
203 switch (event->type) {
Felipe Balbi80977dc2014-08-19 16:37:22 -0500204 case DWC3_DEVICE_EVENT_DISCONNECT:
Felipe Balbi7790b352019-02-04 15:43:38 +0200205 snprintf(str, size, "Disconnect: [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300206 dwc3_gadget_link_string(state));
207 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500208 case DWC3_DEVICE_EVENT_RESET:
Felipe Balbi7790b352019-02-04 15:43:38 +0200209 snprintf(str, size, "Reset [%s]",
210 dwc3_gadget_link_string(state));
Felipe Balbif75cacc2016-05-23 11:10:08 +0300211 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500212 case DWC3_DEVICE_EVENT_CONNECT_DONE:
Felipe Balbi7790b352019-02-04 15:43:38 +0200213 snprintf(str, size, "Connection Done [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300214 dwc3_gadget_link_string(state));
215 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500216 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
Felipe Balbi7790b352019-02-04 15:43:38 +0200217 snprintf(str, size, "Link Change [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300218 dwc3_gadget_link_string(state));
219 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500220 case DWC3_DEVICE_EVENT_WAKEUP:
Felipe Balbi7790b352019-02-04 15:43:38 +0200221 snprintf(str, size, "WakeUp [%s]",
222 dwc3_gadget_link_string(state));
Felipe Balbif75cacc2016-05-23 11:10:08 +0300223 break;
Jack Pham6f26ebb2021-04-28 02:01:11 -0700224 case DWC3_DEVICE_EVENT_SUSPEND:
225 snprintf(str, size, "Suspend [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300226 dwc3_gadget_link_string(state));
227 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500228 case DWC3_DEVICE_EVENT_SOF:
Felipe Balbi7790b352019-02-04 15:43:38 +0200229 snprintf(str, size, "Start-Of-Frame [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300230 dwc3_gadget_link_string(state));
231 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500232 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
Felipe Balbi7790b352019-02-04 15:43:38 +0200233 snprintf(str, size, "Erratic Error [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300234 dwc3_gadget_link_string(state));
235 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500236 case DWC3_DEVICE_EVENT_CMD_CMPL:
Felipe Balbi7790b352019-02-04 15:43:38 +0200237 snprintf(str, size, "Command Complete [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300238 dwc3_gadget_link_string(state));
239 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500240 case DWC3_DEVICE_EVENT_OVERFLOW:
Felipe Balbi7790b352019-02-04 15:43:38 +0200241 snprintf(str, size, "Overflow [%s]",
242 dwc3_gadget_link_string(state));
Felipe Balbif75cacc2016-05-23 11:10:08 +0300243 break;
244 default:
Felipe Balbi7790b352019-02-04 15:43:38 +0200245 snprintf(str, size, "UNKNOWN");
Felipe Balbi80977dc2014-08-19 16:37:22 -0500246 }
247
Felipe Balbif75cacc2016-05-23 11:10:08 +0300248 return str;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500249}
250
251/**
252 * dwc3_ep_event_string - returns event name
253 * @event: then event code
254 */
Felipe Balbi7790b352019-02-04 15:43:38 +0200255static inline const char *dwc3_ep_event_string(char *str, size_t size,
256 const struct dwc3_event_depevt *event, u32 ep0state)
Felipe Balbi80977dc2014-08-19 16:37:22 -0500257{
Felipe Balbif75cacc2016-05-23 11:10:08 +0300258 u8 epnum = event->endpoint_number;
Felipe Balbi43c96be2016-09-26 13:23:34 +0300259 size_t len;
Felipe Balbif75cacc2016-05-23 11:10:08 +0300260 int status;
Felipe Balbif75cacc2016-05-23 11:10:08 +0300261
Colin Ian Kingb32196e2020-02-10 09:51:39 +0000262 len = scnprintf(str, size, "ep%d%s: ", epnum >> 1,
Felipe Balbi696fe692016-08-24 14:32:39 +0300263 (epnum & 1) ? "in" : "out");
Felipe Balbif75cacc2016-05-23 11:10:08 +0300264
Felipe Balbib27972b2018-04-06 11:03:19 +0300265 status = event->status;
266
Felipe Balbif75cacc2016-05-23 11:10:08 +0300267 switch (event->endpoint_event) {
Felipe Balbi80977dc2014-08-19 16:37:22 -0500268 case DWC3_DEPEVT_XFERCOMPLETE:
Colin Ian Kingb32196e2020-02-10 09:51:39 +0000269 len += scnprintf(str + len, size - len,
270 "Transfer Complete (%c%c%c)",
Felipe Balbib27972b2018-04-06 11:03:19 +0300271 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
272 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
273 status & DEPEVT_STATUS_LST ? 'L' : 'l');
274
Felipe Balbi43c96be2016-09-26 13:23:34 +0300275 if (epnum <= 1)
Colin Ian Kingb32196e2020-02-10 09:51:39 +0000276 scnprintf(str + len, size - len, " [%s]",
Felipe Balbi7790b352019-02-04 15:43:38 +0200277 dwc3_ep0_state_string(ep0state));
Felipe Balbif75cacc2016-05-23 11:10:08 +0300278 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500279 case DWC3_DEPEVT_XFERINPROGRESS:
Colin Ian Kingb32196e2020-02-10 09:51:39 +0000280 scnprintf(str + len, size - len,
281 "Transfer In Progress [%d] (%c%c%c)",
Felipe Balbie1d542f2018-04-11 10:31:53 +0300282 event->parameters,
Felipe Balbib27972b2018-04-06 11:03:19 +0300283 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
284 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
285 status & DEPEVT_STATUS_LST ? 'M' : 'm');
Felipe Balbif75cacc2016-05-23 11:10:08 +0300286 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500287 case DWC3_DEPEVT_XFERNOTREADY:
Colin Ian Kingb32196e2020-02-10 09:51:39 +0000288 len += scnprintf(str + len, size - len,
289 "Transfer Not Ready [%d]%s",
Felipe Balbie1d542f2018-04-11 10:31:53 +0300290 event->parameters,
291 status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
Felipe Balbib27972b2018-04-06 11:03:19 +0300292 " (Active)" : " (Not Active)");
Felipe Balbi45a2af22016-09-26 12:54:04 +0300293
294 /* Control Endpoints */
295 if (epnum <= 1) {
296 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
297
298 switch (phase) {
299 case DEPEVT_STATUS_CONTROL_DATA:
Colin Ian Kingb32196e2020-02-10 09:51:39 +0000300 scnprintf(str + len, size - len,
Felipe Balbi1381a512019-02-05 09:00:14 +0200301 " [Data Phase]");
Felipe Balbi45a2af22016-09-26 12:54:04 +0300302 break;
303 case DEPEVT_STATUS_CONTROL_STATUS:
Colin Ian Kingb32196e2020-02-10 09:51:39 +0000304 scnprintf(str + len, size - len,
Felipe Balbi1381a512019-02-05 09:00:14 +0200305 " [Status Phase]");
Felipe Balbi45a2af22016-09-26 12:54:04 +0300306 }
307 }
Felipe Balbif75cacc2016-05-23 11:10:08 +0300308 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500309 case DWC3_DEPEVT_RXTXFIFOEVT:
Colin Ian Kingb32196e2020-02-10 09:51:39 +0000310 scnprintf(str + len, size - len, "FIFO");
Felipe Balbif75cacc2016-05-23 11:10:08 +0300311 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500312 case DWC3_DEPEVT_STREAMEVT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300313 status = event->status;
314
315 switch (status) {
316 case DEPEVT_STREAMEVT_FOUND:
Colin Ian Kingb32196e2020-02-10 09:51:39 +0000317 scnprintf(str + len, size - len, " Stream %d Found",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300318 event->parameters);
319 break;
320 case DEPEVT_STREAMEVT_NOTFOUND:
321 default:
Colin Ian Kingb32196e2020-02-10 09:51:39 +0000322 scnprintf(str + len, size - len, " Stream Not Found");
Felipe Balbif75cacc2016-05-23 11:10:08 +0300323 break;
324 }
325
326 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500327 case DWC3_DEPEVT_EPCMDCMPLT:
Colin Ian Kingb32196e2020-02-10 09:51:39 +0000328 scnprintf(str + len, size - len, "Endpoint Command Complete");
Felipe Balbif75cacc2016-05-23 11:10:08 +0300329 break;
330 default:
Colin Ian Kingb32196e2020-02-10 09:51:39 +0000331 scnprintf(str + len, size - len, "UNKNOWN");
Felipe Balbi80977dc2014-08-19 16:37:22 -0500332 }
333
Felipe Balbif75cacc2016-05-23 11:10:08 +0300334 return str;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500335}
336
Felipe Balbie9960612014-08-19 16:49:20 -0500337/**
338 * dwc3_gadget_event_type_string - return event name
339 * @event: the event code
340 */
341static inline const char *dwc3_gadget_event_type_string(u8 event)
342{
343 switch (event) {
344 case DWC3_DEVICE_EVENT_DISCONNECT:
345 return "Disconnect";
346 case DWC3_DEVICE_EVENT_RESET:
347 return "Reset";
348 case DWC3_DEVICE_EVENT_CONNECT_DONE:
349 return "Connect Done";
350 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
351 return "Link Status Change";
352 case DWC3_DEVICE_EVENT_WAKEUP:
353 return "Wake-Up";
354 case DWC3_DEVICE_EVENT_HIBER_REQ:
355 return "Hibernation";
Jack Pham6f26ebb2021-04-28 02:01:11 -0700356 case DWC3_DEVICE_EVENT_SUSPEND:
357 return "Suspend";
Felipe Balbie9960612014-08-19 16:49:20 -0500358 case DWC3_DEVICE_EVENT_SOF:
359 return "Start of Frame";
360 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
361 return "Erratic Error";
362 case DWC3_DEVICE_EVENT_CMD_CMPL:
363 return "Command Complete";
364 case DWC3_DEVICE_EVENT_OVERFLOW:
365 return "Overflow";
366 default:
367 return "UNKNOWN";
368 }
369}
370
Felipe Balbi7790b352019-02-04 15:43:38 +0200371static inline const char *dwc3_decode_event(char *str, size_t size, u32 event,
372 u32 ep0state)
Felipe Balbif75cacc2016-05-23 11:10:08 +0300373{
Felipe Balbi27c7ab02020-08-13 08:24:21 +0300374 union dwc3_event evt;
375
376 memcpy(&evt, &event, sizeof(event));
Felipe Balbif75cacc2016-05-23 11:10:08 +0300377
378 if (evt.type.is_devspec)
Felipe Balbi7790b352019-02-04 15:43:38 +0200379 return dwc3_gadget_event_string(str, size, &evt.devt);
Felipe Balbif75cacc2016-05-23 11:10:08 +0300380 else
Felipe Balbi7790b352019-02-04 15:43:38 +0200381 return dwc3_ep_event_string(str, size, &evt.depevt, ep0state);
Felipe Balbif75cacc2016-05-23 11:10:08 +0300382}
383
Felipe Balbi0933df12016-05-23 14:02:33 +0300384static inline const char *dwc3_ep_cmd_status_string(int status)
385{
386 switch (status) {
387 case -ETIMEDOUT:
388 return "Timed Out";
389 case 0:
390 return "Successful";
391 case DEPEVT_TRANSFER_NO_RESOURCE:
392 return "No Resource";
393 case DEPEVT_TRANSFER_BUS_EXPIRY:
394 return "Bus Expiry";
395 default:
396 return "UNKNOWN";
397 }
398}
399
Felipe Balbi71f7e702016-05-23 14:16:19 +0300400static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
401{
402 switch (status) {
403 case -ETIMEDOUT:
404 return "Timed Out";
405 case 0:
406 return "Successful";
407 case 1:
408 return "Error";
409 default:
410 return "UNKNOWN";
411 }
412}
413
Felipe Balbi57b14da2016-09-30 14:12:34 +0300414
Felipe Balbi72246da2011-08-19 18:10:58 +0300415#ifdef CONFIG_DEBUG_FS
Jack Pham8d396bb02021-05-29 12:29:32 -0700416extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep);
Felipe Balbi035cbca2020-08-13 08:33:05 +0300417extern void dwc3_debugfs_init(struct dwc3 *d);
418extern void dwc3_debugfs_exit(struct dwc3 *d);
Felipe Balbi72246da2011-08-19 18:10:58 +0300419#else
Jack Pham8d396bb02021-05-29 12:29:32 -0700420static inline void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
421{ }
Du, Changbin4e9f3112016-04-12 19:10:18 +0800422static inline void dwc3_debugfs_init(struct dwc3 *d)
423{ }
Felipe Balbi72246da2011-08-19 18:10:58 +0300424static inline void dwc3_debugfs_exit(struct dwc3 *d)
425{ }
426#endif
Felipe Balbi80977dc2014-08-19 16:37:22 -0500427#endif /* __DWC3_DEBUG_H */