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";
81 * dwc3_gadget_link_string - returns link name
82 * @link_state: link state code
84 static inline const char *
85 dwc3_gadget_link_string(enum dwc3_link_state link_state)
88 case DWC3_LINK_STATE_U0:
90 case DWC3_LINK_STATE_U1:
92 case DWC3_LINK_STATE_U2:
94 case DWC3_LINK_STATE_U3:
96 case DWC3_LINK_STATE_SS_DIS:
98 case DWC3_LINK_STATE_RX_DET:
100 case DWC3_LINK_STATE_SS_INACT:
101 return "SS.Inactive";
102 case DWC3_LINK_STATE_POLL:
104 case DWC3_LINK_STATE_RECOV:
106 case DWC3_LINK_STATE_HRESET:
108 case DWC3_LINK_STATE_CMPLY:
110 case DWC3_LINK_STATE_LPBK:
112 case DWC3_LINK_STATE_RESET:
114 case DWC3_LINK_STATE_RESUME:
117 return "UNKNOWN link state";
122 * dwc3_gadget_hs_link_string - returns highspeed and below link name
123 * @link_state: link state code
125 static inline const char *
126 dwc3_gadget_hs_link_string(enum dwc3_link_state link_state)
128 switch (link_state) {
129 case DWC3_LINK_STATE_U0:
131 case DWC3_LINK_STATE_U2:
133 case DWC3_LINK_STATE_U3:
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:
141 case DWC3_LINK_STATE_RESET:
143 case DWC3_LINK_STATE_RESUME:
146 return "UNKNOWN link state";
151 * dwc3_trb_type_string - returns TRB type as a string
152 * @type: the type of the TRB
154 static inline const char *dwc3_trb_type_string(unsigned int type)
157 case DWC3_TRBCTL_NORMAL:
159 case DWC3_TRBCTL_CONTROL_SETUP:
161 case DWC3_TRBCTL_CONTROL_STATUS2:
163 case DWC3_TRBCTL_CONTROL_STATUS3:
165 case DWC3_TRBCTL_CONTROL_DATA:
167 case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
169 case DWC3_TRBCTL_ISOCHRONOUS:
171 case DWC3_TRBCTL_LINK_TRB:
178 static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
181 case EP0_UNCONNECTED:
182 return "Unconnected";
183 case EP0_SETUP_PHASE:
184 return "Setup Phase";
187 case EP0_STATUS_PHASE:
188 return "Status Phase";
195 * dwc3_gadget_event_string - returns event name
196 * @event: the event code
198 static inline const char *dwc3_gadget_event_string(char *str, size_t size,
199 const struct dwc3_event_devt *event)
201 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
203 switch (event->type) {
204 case DWC3_DEVICE_EVENT_DISCONNECT:
205 snprintf(str, size, "Disconnect: [%s]",
206 dwc3_gadget_link_string(state));
208 case DWC3_DEVICE_EVENT_RESET:
209 snprintf(str, size, "Reset [%s]",
210 dwc3_gadget_link_string(state));
212 case DWC3_DEVICE_EVENT_CONNECT_DONE:
213 snprintf(str, size, "Connection Done [%s]",
214 dwc3_gadget_link_string(state));
216 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
217 snprintf(str, size, "Link Change [%s]",
218 dwc3_gadget_link_string(state));
220 case DWC3_DEVICE_EVENT_WAKEUP:
221 snprintf(str, size, "WakeUp [%s]",
222 dwc3_gadget_link_string(state));
224 case DWC3_DEVICE_EVENT_SUSPEND:
225 snprintf(str, size, "Suspend [%s]",
226 dwc3_gadget_link_string(state));
228 case DWC3_DEVICE_EVENT_SOF:
229 snprintf(str, size, "Start-Of-Frame [%s]",
230 dwc3_gadget_link_string(state));
232 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
233 snprintf(str, size, "Erratic Error [%s]",
234 dwc3_gadget_link_string(state));
236 case DWC3_DEVICE_EVENT_CMD_CMPL:
237 snprintf(str, size, "Command Complete [%s]",
238 dwc3_gadget_link_string(state));
240 case DWC3_DEVICE_EVENT_OVERFLOW:
241 snprintf(str, size, "Overflow [%s]",
242 dwc3_gadget_link_string(state));
245 snprintf(str, size, "UNKNOWN");
252 * dwc3_ep_event_string - returns event name
253 * @event: then event code
255 static inline const char *dwc3_ep_event_string(char *str, size_t size,
256 const struct dwc3_event_depevt *event, u32 ep0state)
258 u8 epnum = event->endpoint_number;
262 len = scnprintf(str, size, "ep%d%s: ", epnum >> 1,
263 (epnum & 1) ? "in" : "out");
265 status = event->status;
267 switch (event->endpoint_event) {
268 case DWC3_DEPEVT_XFERCOMPLETE:
269 len += scnprintf(str + len, size - len,
270 "Transfer Complete (%c%c%c)",
271 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
272 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
273 status & DEPEVT_STATUS_LST ? 'L' : 'l');
276 scnprintf(str + len, size - len, " [%s]",
277 dwc3_ep0_state_string(ep0state));
279 case DWC3_DEPEVT_XFERINPROGRESS:
280 scnprintf(str + len, size - len,
281 "Transfer In Progress [%d] (%c%c%c)",
283 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
284 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
285 status & DEPEVT_STATUS_LST ? 'M' : 'm');
287 case DWC3_DEPEVT_XFERNOTREADY:
288 len += scnprintf(str + len, size - len,
289 "Transfer Not Ready [%d]%s",
291 status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
292 " (Active)" : " (Not Active)");
294 /* Control Endpoints */
296 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
299 case DEPEVT_STATUS_CONTROL_DATA:
300 scnprintf(str + len, size - len,
303 case DEPEVT_STATUS_CONTROL_STATUS:
304 scnprintf(str + len, size - len,
309 case DWC3_DEPEVT_RXTXFIFOEVT:
310 scnprintf(str + len, size - len, "FIFO");
312 case DWC3_DEPEVT_STREAMEVT:
313 status = event->status;
316 case DEPEVT_STREAMEVT_FOUND:
317 scnprintf(str + len, size - len, " Stream %d Found",
320 case DEPEVT_STREAMEVT_NOTFOUND:
322 scnprintf(str + len, size - len, " Stream Not Found");
327 case DWC3_DEPEVT_EPCMDCMPLT:
328 scnprintf(str + len, size - len, "Endpoint Command Complete");
331 scnprintf(str + len, size - len, "UNKNOWN");
338 * dwc3_gadget_event_type_string - return event name
339 * @event: the event code
341 static inline const char *dwc3_gadget_event_type_string(u8 event)
344 case DWC3_DEVICE_EVENT_DISCONNECT:
346 case DWC3_DEVICE_EVENT_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:
354 case DWC3_DEVICE_EVENT_HIBER_REQ:
355 return "Hibernation";
356 case DWC3_DEVICE_EVENT_SUSPEND:
358 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:
371 static inline const char *dwc3_decode_event(char *str, size_t size, u32 event,
374 union dwc3_event evt;
376 memcpy(&evt, &event, sizeof(event));
378 if (evt.type.is_devspec)
379 return dwc3_gadget_event_string(str, size, &evt.devt);
381 return dwc3_ep_event_string(str, size, &evt.depevt, ep0state);
384 static inline const char *dwc3_ep_cmd_status_string(int status)
391 case DEPEVT_TRANSFER_NO_RESOURCE:
392 return "No Resource";
393 case DEPEVT_TRANSFER_BUS_EXPIRY:
400 static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
415 #ifdef CONFIG_DEBUG_FS
416 extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep);
417 extern void dwc3_debugfs_init(struct dwc3 *d);
418 extern void dwc3_debugfs_exit(struct dwc3 *d);
420 static inline void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
422 static inline void dwc3_debugfs_init(struct dwc3 *d)
424 static inline void dwc3_debugfs_exit(struct dwc3 *d)
427 #endif /* __DWC3_DEBUG_H */