1 /* SPDX-License-Identifier: GPL-2.0 */
3 * debug.h - DesignWare USB3 DRD Controller Debug Header
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - https://www.ti.com
7 * Authors: Felipe Balbi <balbi@ti.com>,
8 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
11 #ifndef __DWC3_DEBUG_H
12 #define __DWC3_DEBUG_H
17 * dwc3_gadget_ep_cmd_string - returns endpoint command string
20 static inline const char *
21 dwc3_gadget_ep_cmd_string(u8 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:
34 case DWC3_DEPCMD_SETSTALL:
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";
43 return "UNKNOWN command";
48 * dwc3_gadget_generic_cmd_string - returns generic command string
51 static inline const char *
52 dwc3_gadget_generic_cmd_string(u8 cmd)
55 case DWC3_DGCMD_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";
71 case DWC3_DGCMD_SET_ENDPOINT_PRIME:
72 return "Set Endpoint Prime";
73 case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK:
74 return "Run SoC Bus Loopback Test";
75 case DWC3_DGCMD_DEV_NOTIFICATION:
76 return "Device Notification";
83 * dwc3_gadget_link_string - returns link name
84 * @link_state: link state code
86 static inline const char *
87 dwc3_gadget_link_string(enum dwc3_link_state link_state)
90 case DWC3_LINK_STATE_U0:
92 case DWC3_LINK_STATE_U1:
94 case DWC3_LINK_STATE_U2:
96 case DWC3_LINK_STATE_U3:
98 case DWC3_LINK_STATE_SS_DIS:
100 case DWC3_LINK_STATE_RX_DET:
102 case DWC3_LINK_STATE_SS_INACT:
103 return "SS.Inactive";
104 case DWC3_LINK_STATE_POLL:
106 case DWC3_LINK_STATE_RECOV:
108 case DWC3_LINK_STATE_HRESET:
110 case DWC3_LINK_STATE_CMPLY:
112 case DWC3_LINK_STATE_LPBK:
114 case DWC3_LINK_STATE_RESET:
116 case DWC3_LINK_STATE_RESUME:
119 return "UNKNOWN link state";
124 * dwc3_gadget_hs_link_string - returns highspeed and below link name
125 * @link_state: link state code
127 static inline const char *
128 dwc3_gadget_hs_link_string(enum dwc3_link_state link_state)
130 switch (link_state) {
131 case DWC3_LINK_STATE_U0:
133 case DWC3_LINK_STATE_U2:
135 case DWC3_LINK_STATE_U3:
137 case DWC3_LINK_STATE_SS_DIS:
138 return "Disconnected";
139 case DWC3_LINK_STATE_RX_DET:
140 return "Early Suspend";
141 case DWC3_LINK_STATE_RECOV:
143 case DWC3_LINK_STATE_RESET:
145 case DWC3_LINK_STATE_RESUME:
148 return "UNKNOWN link state";
153 * dwc3_trb_type_string - returns TRB type as a string
154 * @type: the type of the TRB
156 static inline const char *dwc3_trb_type_string(unsigned int type)
159 case DWC3_TRBCTL_NORMAL:
161 case DWC3_TRBCTL_CONTROL_SETUP:
163 case DWC3_TRBCTL_CONTROL_STATUS2:
165 case DWC3_TRBCTL_CONTROL_STATUS3:
167 case DWC3_TRBCTL_CONTROL_DATA:
169 case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
171 case DWC3_TRBCTL_ISOCHRONOUS:
173 case DWC3_TRBCTL_LINK_TRB:
180 static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
183 case EP0_UNCONNECTED:
184 return "Unconnected";
185 case EP0_SETUP_PHASE:
186 return "Setup Phase";
189 case EP0_STATUS_PHASE:
190 return "Status Phase";
197 * dwc3_gadget_event_string - returns event name
198 * @event: the event code
200 static inline const char *dwc3_gadget_event_string(char *str, size_t size,
201 const struct dwc3_event_devt *event)
203 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
205 switch (event->type) {
206 case DWC3_DEVICE_EVENT_DISCONNECT:
207 snprintf(str, size, "Disconnect: [%s]",
208 dwc3_gadget_link_string(state));
210 case DWC3_DEVICE_EVENT_RESET:
211 snprintf(str, size, "Reset [%s]",
212 dwc3_gadget_link_string(state));
214 case DWC3_DEVICE_EVENT_CONNECT_DONE:
215 snprintf(str, size, "Connection Done [%s]",
216 dwc3_gadget_link_string(state));
218 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
219 snprintf(str, size, "Link Change [%s]",
220 dwc3_gadget_link_string(state));
222 case DWC3_DEVICE_EVENT_WAKEUP:
223 snprintf(str, size, "WakeUp [%s]",
224 dwc3_gadget_link_string(state));
226 case DWC3_DEVICE_EVENT_SUSPEND:
227 snprintf(str, size, "Suspend [%s]",
228 dwc3_gadget_link_string(state));
230 case DWC3_DEVICE_EVENT_SOF:
231 snprintf(str, size, "Start-Of-Frame [%s]",
232 dwc3_gadget_link_string(state));
234 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
235 snprintf(str, size, "Erratic Error [%s]",
236 dwc3_gadget_link_string(state));
238 case DWC3_DEVICE_EVENT_CMD_CMPL:
239 snprintf(str, size, "Command Complete [%s]",
240 dwc3_gadget_link_string(state));
242 case DWC3_DEVICE_EVENT_OVERFLOW:
243 snprintf(str, size, "Overflow [%s]",
244 dwc3_gadget_link_string(state));
247 snprintf(str, size, "UNKNOWN");
254 * dwc3_ep_event_string - returns event name
255 * @event: then event code
257 static inline const char *dwc3_ep_event_string(char *str, size_t size,
258 const struct dwc3_event_depevt *event, u32 ep0state)
260 u8 epnum = event->endpoint_number;
264 len = scnprintf(str, size, "ep%d%s: ", epnum >> 1,
265 (epnum & 1) ? "in" : "out");
267 status = event->status;
269 switch (event->endpoint_event) {
270 case DWC3_DEPEVT_XFERCOMPLETE:
271 len += scnprintf(str + len, size - len,
272 "Transfer Complete (%c%c%c)",
273 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
274 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
275 status & DEPEVT_STATUS_LST ? 'L' : 'l');
278 scnprintf(str + len, size - len, " [%s]",
279 dwc3_ep0_state_string(ep0state));
281 case DWC3_DEPEVT_XFERINPROGRESS:
282 scnprintf(str + len, size - len,
283 "Transfer In Progress [%08x] (%c%c%c)",
285 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
286 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
287 status & DEPEVT_STATUS_LST ? 'M' : 'm');
289 case DWC3_DEPEVT_XFERNOTREADY:
290 len += scnprintf(str + len, size - len,
291 "Transfer Not Ready [%08x]%s",
293 status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
294 " (Active)" : " (Not Active)");
296 /* Control Endpoints */
298 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
301 case DEPEVT_STATUS_CONTROL_DATA:
302 scnprintf(str + len, size - len,
305 case DEPEVT_STATUS_CONTROL_STATUS:
306 scnprintf(str + len, size - len,
311 case DWC3_DEPEVT_RXTXFIFOEVT:
312 scnprintf(str + len, size - len, "FIFO");
314 case DWC3_DEPEVT_STREAMEVT:
315 status = event->status;
318 case DEPEVT_STREAMEVT_FOUND:
319 scnprintf(str + len, size - len, " Stream %d Found",
322 case DEPEVT_STREAMEVT_NOTFOUND:
324 scnprintf(str + len, size - len, " Stream Not Found");
329 case DWC3_DEPEVT_EPCMDCMPLT:
330 scnprintf(str + len, size - len, "Endpoint Command Complete");
333 scnprintf(str + len, size - len, "UNKNOWN");
340 * dwc3_gadget_event_type_string - return event name
341 * @event: the event code
343 static inline const char *dwc3_gadget_event_type_string(u8 event)
346 case DWC3_DEVICE_EVENT_DISCONNECT:
348 case DWC3_DEVICE_EVENT_RESET:
350 case DWC3_DEVICE_EVENT_CONNECT_DONE:
351 return "Connect Done";
352 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
353 return "Link Status Change";
354 case DWC3_DEVICE_EVENT_WAKEUP:
356 case DWC3_DEVICE_EVENT_HIBER_REQ:
357 return "Hibernation";
358 case DWC3_DEVICE_EVENT_SUSPEND:
360 case DWC3_DEVICE_EVENT_SOF:
361 return "Start of Frame";
362 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
363 return "Erratic Error";
364 case DWC3_DEVICE_EVENT_CMD_CMPL:
365 return "Command Complete";
366 case DWC3_DEVICE_EVENT_OVERFLOW:
373 static inline const char *dwc3_decode_event(char *str, size_t size, u32 event,
376 union dwc3_event evt;
378 memcpy(&evt, &event, sizeof(event));
380 if (evt.type.is_devspec)
381 return dwc3_gadget_event_string(str, size, &evt.devt);
383 return dwc3_ep_event_string(str, size, &evt.depevt, ep0state);
386 static inline const char *dwc3_ep_cmd_status_string(int status)
393 case DEPEVT_TRANSFER_NO_RESOURCE:
394 return "No Resource";
395 case DEPEVT_TRANSFER_BUS_EXPIRY:
402 static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
417 #ifdef CONFIG_DEBUG_FS
418 extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep);
419 extern void dwc3_debugfs_remove_endpoint_dir(struct dwc3_ep *dep);
420 extern void dwc3_debugfs_init(struct dwc3 *d);
421 extern void dwc3_debugfs_exit(struct dwc3 *d);
423 static inline void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
425 static inline void dwc3_debugfs_remove_endpoint_dir(struct dwc3_ep *dep)
427 static inline void dwc3_debugfs_init(struct dwc3 *d)
429 static inline void dwc3_debugfs_exit(struct dwc3 *d)
432 #endif /* __DWC3_DEBUG_H */