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
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_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_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\n";
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 *
197 dwc3_gadget_event_string(char *str, 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 sprintf(str, "Disconnect: [%s]",
204 dwc3_gadget_link_string(state));
206 case DWC3_DEVICE_EVENT_RESET:
207 sprintf(str, "Reset [%s]", dwc3_gadget_link_string(state));
209 case DWC3_DEVICE_EVENT_CONNECT_DONE:
210 sprintf(str, "Connection Done [%s]",
211 dwc3_gadget_link_string(state));
213 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
214 sprintf(str, "Link Change [%s]",
215 dwc3_gadget_link_string(state));
217 case DWC3_DEVICE_EVENT_WAKEUP:
218 sprintf(str, "WakeUp [%s]", dwc3_gadget_link_string(state));
220 case DWC3_DEVICE_EVENT_EOPF:
221 sprintf(str, "End-Of-Frame [%s]",
222 dwc3_gadget_link_string(state));
224 case DWC3_DEVICE_EVENT_SOF:
225 sprintf(str, "Start-Of-Frame [%s]",
226 dwc3_gadget_link_string(state));
228 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
229 sprintf(str, "Erratic Error [%s]",
230 dwc3_gadget_link_string(state));
232 case DWC3_DEVICE_EVENT_CMD_CMPL:
233 sprintf(str, "Command Complete [%s]",
234 dwc3_gadget_link_string(state));
236 case DWC3_DEVICE_EVENT_OVERFLOW:
237 sprintf(str, "Overflow [%s]", dwc3_gadget_link_string(state));
240 sprintf(str, "UNKNOWN");
246 static inline void dwc3_decode_get_status(__u8 t, __u16 i, __u16 l, char *str)
248 switch (t & USB_RECIP_MASK) {
249 case USB_RECIP_INTERFACE:
250 sprintf(str, "Get Interface Status(Intf = %d, Length = %d)",
253 case USB_RECIP_ENDPOINT:
254 sprintf(str, "Get Endpoint Status(ep%d%s)",
256 i & USB_DIR_IN ? "in" : "out");
261 static inline void dwc3_decode_set_clear_feature(__u8 t, __u8 b, __u16 v,
264 switch (t & USB_RECIP_MASK) {
265 case USB_RECIP_DEVICE:
266 sprintf(str, "%s Device Feature(%s%s)",
267 b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
270 case USB_DEVICE_SELF_POWERED:
273 case USB_DEVICE_REMOTE_WAKEUP:
276 case USB_DEVICE_TEST_MODE:
279 case USB_DEVICE_U1_ENABLE:
282 case USB_DEVICE_U2_ENABLE:
285 case USB_DEVICE_LTM_ENABLE:
291 v == USB_DEVICE_TEST_MODE ?
301 s = ": TEST_SE0_NAK";
307 s = ": TEST_FORCE_EN";
313 case USB_RECIP_INTERFACE:
314 sprintf(str, "%s Interface Feature(%s)",
315 b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
316 v == USB_INTRF_FUNC_SUSPEND ?
317 "Function Suspend" : "UNKNOWN");
319 case USB_RECIP_ENDPOINT:
320 sprintf(str, "%s Endpoint Feature(%s ep%d%s)",
321 b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
322 v == USB_ENDPOINT_HALT ? "Halt" : "UNKNOWN",
324 i & USB_DIR_IN ? "in" : "out");
329 static inline void dwc3_decode_set_address(__u16 v, char *str)
331 sprintf(str, "Set Address(Addr = %02x)", v);
334 static inline void dwc3_decode_get_set_descriptor(__u8 t, __u8 b, __u16 v,
335 __u16 i, __u16 l, char *str)
337 sprintf(str, "%s %s Descriptor(Index = %d, Length = %d)",
338 b == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set",
350 case USB_DT_INTERFACE:
353 case USB_DT_ENDPOINT:
356 case USB_DT_DEVICE_QUALIFIER:
357 s = "Device Qualifier";
359 case USB_DT_OTHER_SPEED_CONFIG:
360 s = "Other Speed Config";
362 case USB_DT_INTERFACE_POWER:
363 s = "Interface Power";
371 case USB_DT_INTERFACE_ASSOCIATION:
372 s = "Interface Association";
377 case USB_DT_DEVICE_CAPABILITY:
378 s = "Device Capability";
380 case USB_DT_PIPE_USAGE:
383 case USB_DT_SS_ENDPOINT_COMP:
384 s = "SS Endpoint Companion";
386 case USB_DT_SSP_ISOC_ENDPOINT_COMP:
387 s = "SSP Isochronous Endpoint Companion";
392 } s; }), v & 0xff, l);
396 static inline void dwc3_decode_get_configuration(__u16 l, char *str)
398 sprintf(str, "Get Configuration(Length = %d)", l);
401 static inline void dwc3_decode_set_configuration(__u8 v, char *str)
403 sprintf(str, "Set Configuration(Config = %d)", v);
406 static inline void dwc3_decode_get_intf(__u16 i, __u16 l, char *str)
408 sprintf(str, "Get Interface(Intf = %d, Length = %d)", i, l);
411 static inline void dwc3_decode_set_intf(__u8 v, __u16 i, char *str)
413 sprintf(str, "Set Interface(Intf = %d, Alt.Setting = %d)", i, v);
416 static inline void dwc3_decode_synch_frame(__u16 i, __u16 l, char *str)
418 sprintf(str, "Synch Frame(Endpoint = %d, Length = %d)", i, l);
421 static inline void dwc3_decode_set_sel(__u16 l, char *str)
423 sprintf(str, "Set SEL(Length = %d)", l);
426 static inline void dwc3_decode_set_isoch_delay(__u8 v, char *str)
428 sprintf(str, "Set Isochronous Delay(Delay = %d ns)", v);
432 * dwc3_decode_ctrl - returns a string represetion of ctrl request
434 static inline const char *dwc3_decode_ctrl(char *str, __u8 bRequestType,
435 __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength)
438 case USB_REQ_GET_STATUS:
439 dwc3_decode_get_status(bRequestType, wIndex, wLength, str);
441 case USB_REQ_CLEAR_FEATURE:
442 case USB_REQ_SET_FEATURE:
443 dwc3_decode_set_clear_feature(bRequestType, bRequest, wValue,
446 case USB_REQ_SET_ADDRESS:
447 dwc3_decode_set_address(wValue, str);
449 case USB_REQ_GET_DESCRIPTOR:
450 case USB_REQ_SET_DESCRIPTOR:
451 dwc3_decode_get_set_descriptor(bRequestType, bRequest, wValue,
452 wIndex, wLength, str);
454 case USB_REQ_GET_CONFIGURATION:
455 dwc3_decode_get_configuration(wLength, str);
457 case USB_REQ_SET_CONFIGURATION:
458 dwc3_decode_set_configuration(wValue, str);
460 case USB_REQ_GET_INTERFACE:
461 dwc3_decode_get_intf(wIndex, wLength, str);
463 case USB_REQ_SET_INTERFACE:
464 dwc3_decode_set_intf(wValue, wIndex, str);
466 case USB_REQ_SYNCH_FRAME:
467 dwc3_decode_synch_frame(wIndex, wLength, str);
469 case USB_REQ_SET_SEL:
470 dwc3_decode_set_sel(wLength, str);
472 case USB_REQ_SET_ISOCH_DELAY:
473 dwc3_decode_set_isoch_delay(wValue, str);
476 sprintf(str, "%02x %02x %02x %02x %02x %02x %02x %02x",
477 bRequestType, bRequest,
478 cpu_to_le16(wValue) & 0xff,
479 cpu_to_le16(wValue) >> 8,
480 cpu_to_le16(wIndex) & 0xff,
481 cpu_to_le16(wIndex) >> 8,
482 cpu_to_le16(wLength) & 0xff,
483 cpu_to_le16(wLength) >> 8);
490 * dwc3_ep_event_string - returns event name
491 * @event: then event code
493 static inline const char *
494 dwc3_ep_event_string(char *str, const struct dwc3_event_depevt *event,
497 u8 epnum = event->endpoint_number;
502 ret = sprintf(str, "ep%d%s: ", epnum >> 1,
503 (epnum & 1) ? "in" : "out");
507 status = event->status;
509 switch (event->endpoint_event) {
510 case DWC3_DEPEVT_XFERCOMPLETE:
512 sprintf(str + len, "Transfer Complete (%c%c%c)",
513 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
514 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
515 status & DEPEVT_STATUS_LST ? 'L' : 'l');
520 sprintf(str + len, " [%s]", dwc3_ep0_state_string(ep0state));
522 case DWC3_DEPEVT_XFERINPROGRESS:
525 sprintf(str + len, "Transfer In Progress [%d] (%c%c%c)",
527 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
528 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
529 status & DEPEVT_STATUS_LST ? 'M' : 'm');
531 case DWC3_DEPEVT_XFERNOTREADY:
534 sprintf(str + len, "Transfer Not Ready [%d]%s",
536 status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
537 " (Active)" : " (Not Active)");
539 /* Control Endpoints */
541 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
544 case DEPEVT_STATUS_CONTROL_DATA:
545 strcat(str, " [Data Phase]");
547 case DEPEVT_STATUS_CONTROL_STATUS:
548 strcat(str, " [Status Phase]");
552 case DWC3_DEPEVT_RXTXFIFOEVT:
555 case DWC3_DEPEVT_STREAMEVT:
556 status = event->status;
559 case DEPEVT_STREAMEVT_FOUND:
560 sprintf(str + ret, " Stream %d Found",
563 case DEPEVT_STREAMEVT_NOTFOUND:
565 strcat(str, " Stream Not Found");
570 case DWC3_DEPEVT_EPCMDCMPLT:
571 strcat(str, "Endpoint Command Complete");
574 sprintf(str, "UNKNOWN");
581 * dwc3_gadget_event_type_string - return event name
582 * @event: the event code
584 static inline const char *dwc3_gadget_event_type_string(u8 event)
587 case DWC3_DEVICE_EVENT_DISCONNECT:
589 case DWC3_DEVICE_EVENT_RESET:
591 case DWC3_DEVICE_EVENT_CONNECT_DONE:
592 return "Connect Done";
593 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
594 return "Link Status Change";
595 case DWC3_DEVICE_EVENT_WAKEUP:
597 case DWC3_DEVICE_EVENT_HIBER_REQ:
598 return "Hibernation";
599 case DWC3_DEVICE_EVENT_EOPF:
600 return "End of Periodic Frame";
601 case DWC3_DEVICE_EVENT_SOF:
602 return "Start of Frame";
603 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
604 return "Erratic Error";
605 case DWC3_DEVICE_EVENT_CMD_CMPL:
606 return "Command Complete";
607 case DWC3_DEVICE_EVENT_OVERFLOW:
614 static inline const char *dwc3_decode_event(char *str, u32 event, u32 ep0state)
616 const union dwc3_event evt = (union dwc3_event) event;
618 if (evt.type.is_devspec)
619 return dwc3_gadget_event_string(str, &evt.devt);
621 return dwc3_ep_event_string(str, &evt.depevt, ep0state);
624 static inline const char *dwc3_ep_cmd_status_string(int status)
631 case DEPEVT_TRANSFER_NO_RESOURCE:
632 return "No Resource";
633 case DEPEVT_TRANSFER_BUS_EXPIRY:
640 static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
655 #ifdef CONFIG_DEBUG_FS
656 extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep);
657 extern void dwc3_debugfs_init(struct dwc3 *);
658 extern void dwc3_debugfs_exit(struct dwc3 *);
660 static inline void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
662 static inline void dwc3_debugfs_init(struct dwc3 *d)
664 static inline void dwc3_debugfs_exit(struct dwc3 *d)
667 #endif /* __DWC3_DEBUG_H */