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\n";
120 * dwc3_trb_type_string - returns TRB type as a string
121 * @type: the type of the TRB
123 static inline const char *dwc3_trb_type_string(unsigned int type)
126 case DWC3_TRBCTL_NORMAL:
128 case DWC3_TRBCTL_CONTROL_SETUP:
130 case DWC3_TRBCTL_CONTROL_STATUS2:
132 case DWC3_TRBCTL_CONTROL_STATUS3:
134 case DWC3_TRBCTL_CONTROL_DATA:
136 case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
138 case DWC3_TRBCTL_ISOCHRONOUS:
140 case DWC3_TRBCTL_LINK_TRB:
147 static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
150 case EP0_UNCONNECTED:
151 return "Unconnected";
152 case EP0_SETUP_PHASE:
153 return "Setup Phase";
156 case EP0_STATUS_PHASE:
157 return "Status Phase";
164 * dwc3_gadget_event_string - returns event name
165 * @event: the event code
167 static inline const char *
168 dwc3_gadget_event_string(char *str, const struct dwc3_event_devt *event)
170 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
172 switch (event->type) {
173 case DWC3_DEVICE_EVENT_DISCONNECT:
174 sprintf(str, "Disconnect: [%s]",
175 dwc3_gadget_link_string(state));
177 case DWC3_DEVICE_EVENT_RESET:
178 sprintf(str, "Reset [%s]", dwc3_gadget_link_string(state));
180 case DWC3_DEVICE_EVENT_CONNECT_DONE:
181 sprintf(str, "Connection Done [%s]",
182 dwc3_gadget_link_string(state));
184 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
185 sprintf(str, "Link Change [%s]",
186 dwc3_gadget_link_string(state));
188 case DWC3_DEVICE_EVENT_WAKEUP:
189 sprintf(str, "WakeUp [%s]", dwc3_gadget_link_string(state));
191 case DWC3_DEVICE_EVENT_EOPF:
192 sprintf(str, "End-Of-Frame [%s]",
193 dwc3_gadget_link_string(state));
195 case DWC3_DEVICE_EVENT_SOF:
196 sprintf(str, "Start-Of-Frame [%s]",
197 dwc3_gadget_link_string(state));
199 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
200 sprintf(str, "Erratic Error [%s]",
201 dwc3_gadget_link_string(state));
203 case DWC3_DEVICE_EVENT_CMD_CMPL:
204 sprintf(str, "Command Complete [%s]",
205 dwc3_gadget_link_string(state));
207 case DWC3_DEVICE_EVENT_OVERFLOW:
208 sprintf(str, "Overflow [%s]", dwc3_gadget_link_string(state));
211 sprintf(str, "UNKNOWN");
217 static inline void dwc3_decode_get_status(__u8 t, __u16 i, __u16 l, char *str)
219 switch (t & USB_RECIP_MASK) {
220 case USB_RECIP_INTERFACE:
221 sprintf(str, "Get Interface Status(Intf = %d, Length = %d)",
224 case USB_RECIP_ENDPOINT:
225 sprintf(str, "Get Endpoint Status(ep%d%s)",
227 i & USB_DIR_IN ? "in" : "out");
232 static inline void dwc3_decode_set_clear_feature(__u8 t, __u8 b, __u16 v,
235 switch (t & USB_RECIP_MASK) {
236 case USB_RECIP_DEVICE:
237 sprintf(str, "%s Device Feature(%s%s)",
238 b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
241 case USB_DEVICE_SELF_POWERED:
244 case USB_DEVICE_REMOTE_WAKEUP:
247 case USB_DEVICE_TEST_MODE:
253 v == USB_DEVICE_TEST_MODE ?
263 s = ": TEST_SE0_NAK";
269 s = ": TEST_FORCE_EN";
275 case USB_RECIP_INTERFACE:
276 sprintf(str, "%s Interface Feature(%s)",
277 b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
278 v == USB_INTRF_FUNC_SUSPEND ?
279 "Function Suspend" : "UNKNOWN");
281 case USB_RECIP_ENDPOINT:
282 sprintf(str, "%s Endpoint Feature(%s ep%d%s)",
283 b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
284 v == USB_ENDPOINT_HALT ? "Halt" : "UNKNOWN",
286 i & USB_DIR_IN ? "in" : "out");
291 static inline void dwc3_decode_set_address(__u16 v, char *str)
293 sprintf(str, "Set Address(Addr = %02x)", v);
296 static inline void dwc3_decode_get_set_descriptor(__u8 t, __u8 b, __u16 v,
297 __u16 i, __u16 l, char *str)
299 sprintf(str, "%s %s Descriptor(Index = %d, Length = %d)",
300 b == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set",
312 case USB_DT_INTERFACE:
315 case USB_DT_ENDPOINT:
318 case USB_DT_DEVICE_QUALIFIER:
319 s = "Device Qualifier";
321 case USB_DT_OTHER_SPEED_CONFIG:
322 s = "Other Speed Config";
324 case USB_DT_INTERFACE_POWER:
325 s = "Interface Power";
333 case USB_DT_INTERFACE_ASSOCIATION:
334 s = "Interface Association";
339 case USB_DT_DEVICE_CAPABILITY:
340 s = "Device Capability";
342 case USB_DT_PIPE_USAGE:
345 case USB_DT_SS_ENDPOINT_COMP:
346 s = "SS Endpoint Companion";
348 case USB_DT_SSP_ISOC_ENDPOINT_COMP:
349 s = "SSP Isochronous Endpoint Companion";
354 } s; }), v & 0xff, l);
358 static inline void dwc3_decode_get_configuration(__u16 l, char *str)
360 sprintf(str, "Get Configuration(Length = %d)", l);
363 static inline void dwc3_decode_set_configuration(__u8 v, char *str)
365 sprintf(str, "Set Configuration(Config = %d)", v);
368 static inline void dwc3_decode_get_intf(__u16 i, __u16 l, char *str)
370 sprintf(str, "Get Interface(Intf = %d, Length = %d)", i, l);
373 static inline void dwc3_decode_set_intf(__u8 v, __u16 i, char *str)
375 sprintf(str, "Set Interface(Intf = %d, Alt.Setting = %d)", i, v);
378 static inline void dwc3_decode_synch_frame(__u16 i, __u16 l, char *str)
380 sprintf(str, "Synch Frame(Endpoint = %d, Length = %d)", i, l);
383 static inline void dwc3_decode_set_sel(__u16 l, char *str)
385 sprintf(str, "Set SEL(Length = %d)", l);
388 static inline void dwc3_decode_set_isoch_delay(__u8 v, char *str)
390 sprintf(str, "Set Isochronous Delay(Delay = %d ns)", v);
394 * dwc3_decode_ctrl - returns a string represetion of ctrl request
396 static inline const char *dwc3_decode_ctrl(char *str, __u8 bRequestType,
397 __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength)
400 case USB_REQ_GET_STATUS:
401 dwc3_decode_get_status(bRequestType, wIndex, wLength, str);
403 case USB_REQ_CLEAR_FEATURE:
404 case USB_REQ_SET_FEATURE:
405 dwc3_decode_set_clear_feature(bRequestType, bRequest, wValue,
408 case USB_REQ_SET_ADDRESS:
409 dwc3_decode_set_address(wValue, str);
411 case USB_REQ_GET_DESCRIPTOR:
412 case USB_REQ_SET_DESCRIPTOR:
413 dwc3_decode_get_set_descriptor(bRequestType, bRequest, wValue,
414 wIndex, wLength, str);
416 case USB_REQ_GET_CONFIGURATION:
417 dwc3_decode_get_configuration(wLength, str);
419 case USB_REQ_SET_CONFIGURATION:
420 dwc3_decode_set_configuration(wValue, str);
422 case USB_REQ_GET_INTERFACE:
423 dwc3_decode_get_intf(wIndex, wLength, str);
425 case USB_REQ_SET_INTERFACE:
426 dwc3_decode_set_intf(wValue, wIndex, str);
428 case USB_REQ_SYNCH_FRAME:
429 dwc3_decode_synch_frame(wIndex, wLength, str);
431 case USB_REQ_SET_SEL:
432 dwc3_decode_set_sel(wLength, str);
434 case USB_REQ_SET_ISOCH_DELAY:
435 dwc3_decode_set_isoch_delay(wValue, str);
438 sprintf(str, "%02x %02x %02x %02x %02x %02x %02x %02x",
439 bRequestType, bRequest,
440 cpu_to_le16(wValue) & 0xff,
441 cpu_to_le16(wValue) >> 8,
442 cpu_to_le16(wIndex) & 0xff,
443 cpu_to_le16(wIndex) >> 8,
444 cpu_to_le16(wLength) & 0xff,
445 cpu_to_le16(wLength) >> 8);
452 * dwc3_ep_event_string - returns event name
453 * @event: then event code
455 static inline const char *
456 dwc3_ep_event_string(char *str, const struct dwc3_event_depevt *event,
459 u8 epnum = event->endpoint_number;
464 ret = sprintf(str, "ep%d%s: ", epnum >> 1,
465 (epnum & 1) ? "in" : "out");
469 switch (event->endpoint_event) {
470 case DWC3_DEPEVT_XFERCOMPLETE:
471 strcat(str, "Transfer Complete");
475 sprintf(str + len, " [%s]", dwc3_ep0_state_string(ep0state));
477 case DWC3_DEPEVT_XFERINPROGRESS:
478 strcat(str, "Transfer In-Progress");
480 case DWC3_DEPEVT_XFERNOTREADY:
481 strcat(str, "Transfer Not Ready");
482 status = event->status & DEPEVT_STATUS_TRANSFER_ACTIVE;
483 strcat(str, status ? " (Active)" : " (Not Active)");
485 /* Control Endpoints */
487 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
490 case DEPEVT_STATUS_CONTROL_DATA:
491 strcat(str, " [Data Phase]");
493 case DEPEVT_STATUS_CONTROL_STATUS:
494 strcat(str, " [Status Phase]");
498 case DWC3_DEPEVT_RXTXFIFOEVT:
501 case DWC3_DEPEVT_STREAMEVT:
502 status = event->status;
505 case DEPEVT_STREAMEVT_FOUND:
506 sprintf(str + ret, " Stream %d Found",
509 case DEPEVT_STREAMEVT_NOTFOUND:
511 strcat(str, " Stream Not Found");
516 case DWC3_DEPEVT_EPCMDCMPLT:
517 strcat(str, "Endpoint Command Complete");
520 sprintf(str, "UNKNOWN");
527 * dwc3_gadget_event_type_string - return event name
528 * @event: the event code
530 static inline const char *dwc3_gadget_event_type_string(u8 event)
533 case DWC3_DEVICE_EVENT_DISCONNECT:
535 case DWC3_DEVICE_EVENT_RESET:
537 case DWC3_DEVICE_EVENT_CONNECT_DONE:
538 return "Connect Done";
539 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
540 return "Link Status Change";
541 case DWC3_DEVICE_EVENT_WAKEUP:
543 case DWC3_DEVICE_EVENT_HIBER_REQ:
544 return "Hibernation";
545 case DWC3_DEVICE_EVENT_EOPF:
546 return "End of Periodic Frame";
547 case DWC3_DEVICE_EVENT_SOF:
548 return "Start of Frame";
549 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
550 return "Erratic Error";
551 case DWC3_DEVICE_EVENT_CMD_CMPL:
552 return "Command Complete";
553 case DWC3_DEVICE_EVENT_OVERFLOW:
560 static inline const char *dwc3_decode_event(char *str, u32 event, u32 ep0state)
562 const union dwc3_event evt = (union dwc3_event) event;
564 if (evt.type.is_devspec)
565 return dwc3_gadget_event_string(str, &evt.devt);
567 return dwc3_ep_event_string(str, &evt.depevt, ep0state);
570 static inline const char *dwc3_ep_cmd_status_string(int status)
577 case DEPEVT_TRANSFER_NO_RESOURCE:
578 return "No Resource";
579 case DEPEVT_TRANSFER_BUS_EXPIRY:
586 static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
601 #ifdef CONFIG_DEBUG_FS
602 extern void dwc3_debugfs_init(struct dwc3 *);
603 extern void dwc3_debugfs_exit(struct dwc3 *);
605 static inline void dwc3_debugfs_init(struct dwc3 *d)
607 static inline void dwc3_debugfs_exit(struct dwc3 *d)
610 #endif /* __DWC3_DEBUG_H */