1 // SPDX-License-Identifier: GPL-2.0
3 * debug.h - DesignWare USB3 DRD Controller Debug Header
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
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_RUN_SOC_BUS_LOOPBACK:
72 return "Run SoC Bus Loopback Test";
79 * dwc3_gadget_link_string - returns link name
80 * @link_state: link state code
82 static inline const char *
83 dwc3_gadget_link_string(enum dwc3_link_state link_state)
86 case DWC3_LINK_STATE_U0:
88 case DWC3_LINK_STATE_U1:
90 case DWC3_LINK_STATE_U2:
92 case DWC3_LINK_STATE_U3:
94 case DWC3_LINK_STATE_SS_DIS:
96 case DWC3_LINK_STATE_RX_DET:
98 case DWC3_LINK_STATE_SS_INACT:
100 case DWC3_LINK_STATE_POLL:
102 case DWC3_LINK_STATE_RECOV:
104 case DWC3_LINK_STATE_HRESET:
106 case DWC3_LINK_STATE_CMPLY:
108 case DWC3_LINK_STATE_LPBK:
110 case DWC3_LINK_STATE_RESET:
112 case DWC3_LINK_STATE_RESUME:
115 return "UNKNOWN link state";
120 * dwc3_gadget_hs_link_string - returns highspeed and below link name
121 * @link_state: link state code
123 static inline const char *
124 dwc3_gadget_hs_link_string(enum dwc3_link_state link_state)
126 switch (link_state) {
127 case DWC3_LINK_STATE_U0:
129 case DWC3_LINK_STATE_U2:
131 case DWC3_LINK_STATE_U3:
133 case DWC3_LINK_STATE_SS_DIS:
134 return "Disconnected";
135 case DWC3_LINK_STATE_RX_DET:
136 return "Early Suspend";
137 case DWC3_LINK_STATE_RECOV:
139 case DWC3_LINK_STATE_RESET:
141 case DWC3_LINK_STATE_RESUME:
144 return "UNKNOWN link state";
149 * dwc3_trb_type_string - returns TRB type as a string
150 * @type: the type of the TRB
152 static inline const char *dwc3_trb_type_string(unsigned int type)
155 case DWC3_TRBCTL_NORMAL:
157 case DWC3_TRBCTL_CONTROL_SETUP:
159 case DWC3_TRBCTL_CONTROL_STATUS2:
161 case DWC3_TRBCTL_CONTROL_STATUS3:
163 case DWC3_TRBCTL_CONTROL_DATA:
165 case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
167 case DWC3_TRBCTL_ISOCHRONOUS:
169 case DWC3_TRBCTL_LINK_TRB:
176 static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
179 case EP0_UNCONNECTED:
180 return "Unconnected";
181 case EP0_SETUP_PHASE:
182 return "Setup Phase";
185 case EP0_STATUS_PHASE:
186 return "Status Phase";
193 * dwc3_gadget_event_string - returns event name
194 * @event: the event code
196 static inline const char *dwc3_gadget_event_string(char *str, size_t size,
197 const struct dwc3_event_devt *event)
199 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
201 switch (event->type) {
202 case DWC3_DEVICE_EVENT_DISCONNECT:
203 snprintf(str, size, "Disconnect: [%s]",
204 dwc3_gadget_link_string(state));
206 case DWC3_DEVICE_EVENT_RESET:
207 snprintf(str, size, "Reset [%s]",
208 dwc3_gadget_link_string(state));
210 case DWC3_DEVICE_EVENT_CONNECT_DONE:
211 snprintf(str, size, "Connection Done [%s]",
212 dwc3_gadget_link_string(state));
214 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
215 snprintf(str, size, "Link Change [%s]",
216 dwc3_gadget_link_string(state));
218 case DWC3_DEVICE_EVENT_WAKEUP:
219 snprintf(str, size, "WakeUp [%s]",
220 dwc3_gadget_link_string(state));
222 case DWC3_DEVICE_EVENT_EOPF:
223 snprintf(str, size, "End-Of-Frame [%s]",
224 dwc3_gadget_link_string(state));
226 case DWC3_DEVICE_EVENT_SOF:
227 snprintf(str, size, "Start-Of-Frame [%s]",
228 dwc3_gadget_link_string(state));
230 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
231 snprintf(str, size, "Erratic Error [%s]",
232 dwc3_gadget_link_string(state));
234 case DWC3_DEVICE_EVENT_CMD_CMPL:
235 snprintf(str, size, "Command Complete [%s]",
236 dwc3_gadget_link_string(state));
238 case DWC3_DEVICE_EVENT_OVERFLOW:
239 snprintf(str, size, "Overflow [%s]",
240 dwc3_gadget_link_string(state));
243 snprintf(str, size, "UNKNOWN");
250 * dwc3_ep_event_string - returns event name
251 * @event: then event code
253 static inline const char *dwc3_ep_event_string(char *str, size_t size,
254 const struct dwc3_event_depevt *event, u32 ep0state)
256 u8 epnum = event->endpoint_number;
260 len = scnprintf(str, size, "ep%d%s: ", epnum >> 1,
261 (epnum & 1) ? "in" : "out");
263 status = event->status;
265 switch (event->endpoint_event) {
266 case DWC3_DEPEVT_XFERCOMPLETE:
267 len += scnprintf(str + len, size - len,
268 "Transfer Complete (%c%c%c)",
269 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
270 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
271 status & DEPEVT_STATUS_LST ? 'L' : 'l');
274 scnprintf(str + len, size - len, " [%s]",
275 dwc3_ep0_state_string(ep0state));
277 case DWC3_DEPEVT_XFERINPROGRESS:
278 scnprintf(str + len, size - len,
279 "Transfer In Progress [%d] (%c%c%c)",
281 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
282 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
283 status & DEPEVT_STATUS_LST ? 'M' : 'm');
285 case DWC3_DEPEVT_XFERNOTREADY:
286 len += scnprintf(str + len, size - len,
287 "Transfer Not Ready [%d]%s",
289 status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
290 " (Active)" : " (Not Active)");
292 /* Control Endpoints */
294 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
297 case DEPEVT_STATUS_CONTROL_DATA:
298 scnprintf(str + len, size - len,
301 case DEPEVT_STATUS_CONTROL_STATUS:
302 scnprintf(str + len, size - len,
307 case DWC3_DEPEVT_RXTXFIFOEVT:
308 scnprintf(str + len, size - len, "FIFO");
310 case DWC3_DEPEVT_STREAMEVT:
311 status = event->status;
314 case DEPEVT_STREAMEVT_FOUND:
315 scnprintf(str + len, size - len, " Stream %d Found",
318 case DEPEVT_STREAMEVT_NOTFOUND:
320 scnprintf(str + len, size - len, " Stream Not Found");
325 case DWC3_DEPEVT_EPCMDCMPLT:
326 scnprintf(str + len, size - len, "Endpoint Command Complete");
329 scnprintf(str + len, size - len, "UNKNOWN");
336 * dwc3_gadget_event_type_string - return event name
337 * @event: the event code
339 static inline const char *dwc3_gadget_event_type_string(u8 event)
342 case DWC3_DEVICE_EVENT_DISCONNECT:
344 case DWC3_DEVICE_EVENT_RESET:
346 case DWC3_DEVICE_EVENT_CONNECT_DONE:
347 return "Connect Done";
348 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
349 return "Link Status Change";
350 case DWC3_DEVICE_EVENT_WAKEUP:
352 case DWC3_DEVICE_EVENT_HIBER_REQ:
353 return "Hibernation";
354 case DWC3_DEVICE_EVENT_EOPF:
355 return "End of Periodic Frame";
356 case DWC3_DEVICE_EVENT_SOF:
357 return "Start of Frame";
358 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
359 return "Erratic Error";
360 case DWC3_DEVICE_EVENT_CMD_CMPL:
361 return "Command Complete";
362 case DWC3_DEVICE_EVENT_OVERFLOW:
369 static inline const char *dwc3_decode_event(char *str, size_t size, u32 event,
372 const union dwc3_event evt = (union dwc3_event) event;
374 if (evt.type.is_devspec)
375 return dwc3_gadget_event_string(str, size, &evt.devt);
377 return dwc3_ep_event_string(str, size, &evt.depevt, ep0state);
380 static inline const char *dwc3_ep_cmd_status_string(int status)
387 case DEPEVT_TRANSFER_NO_RESOURCE:
388 return "No Resource";
389 case DEPEVT_TRANSFER_BUS_EXPIRY:
396 static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
411 #ifdef CONFIG_DEBUG_FS
412 extern void dwc3_debugfs_init(struct dwc3 *);
413 extern void dwc3_debugfs_exit(struct dwc3 *);
415 static inline void dwc3_debugfs_init(struct dwc3 *d)
417 static inline void dwc3_debugfs_exit(struct dwc3 *d)
420 #endif /* __DWC3_DEBUG_H */