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 *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");
249 static inline void dwc3_decode_get_status(__u8 t
, __u16 i
, __u16 l
, char *str
,
252 switch (t
& USB_RECIP_MASK
) {
253 case USB_RECIP_DEVICE
:
254 snprintf(str
, size
, "Get Device Status(Length = %d)", l
);
256 case USB_RECIP_INTERFACE
:
257 snprintf(str
, size
, "Get Interface Status(Intf = %d, Length = %d)",
260 case USB_RECIP_ENDPOINT
:
261 snprintf(str
, size
, "Get Endpoint Status(ep%d%s)",
263 i
& USB_DIR_IN
? "in" : "out");
268 static inline void dwc3_decode_set_clear_feature(__u8 t
, __u8 b
, __u16 v
,
269 __u16 i
, char *str
, size_t size
)
271 switch (t
& USB_RECIP_MASK
) {
272 case USB_RECIP_DEVICE
:
273 snprintf(str
, size
, "%s Device Feature(%s%s)",
274 b
== USB_REQ_CLEAR_FEATURE
? "Clear" : "Set",
277 case USB_DEVICE_SELF_POWERED
:
280 case USB_DEVICE_REMOTE_WAKEUP
:
283 case USB_DEVICE_TEST_MODE
:
286 case USB_DEVICE_U1_ENABLE
:
289 case USB_DEVICE_U2_ENABLE
:
292 case USB_DEVICE_LTM_ENABLE
:
298 v
== USB_DEVICE_TEST_MODE
?
308 s
= ": TEST_SE0_NAK";
314 s
= ": TEST_FORCE_EN";
320 case USB_RECIP_INTERFACE
:
321 snprintf(str
, size
, "%s Interface Feature(%s)",
322 b
== USB_REQ_CLEAR_FEATURE
? "Clear" : "Set",
323 v
== USB_INTRF_FUNC_SUSPEND
?
324 "Function Suspend" : "UNKNOWN");
326 case USB_RECIP_ENDPOINT
:
327 snprintf(str
, size
, "%s Endpoint Feature(%s ep%d%s)",
328 b
== USB_REQ_CLEAR_FEATURE
? "Clear" : "Set",
329 v
== USB_ENDPOINT_HALT
? "Halt" : "UNKNOWN",
331 i
& USB_DIR_IN
? "in" : "out");
336 static inline void dwc3_decode_set_address(__u16 v
, char *str
, size_t size
)
338 snprintf(str
, size
, "Set Address(Addr = %02x)", v
);
341 static inline void dwc3_decode_get_set_descriptor(__u8 t
, __u8 b
, __u16 v
,
342 __u16 i
, __u16 l
, char *str
, size_t size
)
344 snprintf(str
, size
, "%s %s Descriptor(Index = %d, Length = %d)",
345 b
== USB_REQ_GET_DESCRIPTOR
? "Get" : "Set",
357 case USB_DT_INTERFACE
:
360 case USB_DT_ENDPOINT
:
363 case USB_DT_DEVICE_QUALIFIER
:
364 s
= "Device Qualifier";
366 case USB_DT_OTHER_SPEED_CONFIG
:
367 s
= "Other Speed Config";
369 case USB_DT_INTERFACE_POWER
:
370 s
= "Interface Power";
378 case USB_DT_INTERFACE_ASSOCIATION
:
379 s
= "Interface Association";
384 case USB_DT_DEVICE_CAPABILITY
:
385 s
= "Device Capability";
387 case USB_DT_PIPE_USAGE
:
390 case USB_DT_SS_ENDPOINT_COMP
:
391 s
= "SS Endpoint Companion";
393 case USB_DT_SSP_ISOC_ENDPOINT_COMP
:
394 s
= "SSP Isochronous Endpoint Companion";
399 } s
; }), v
& 0xff, l
);
403 static inline void dwc3_decode_get_configuration(__u16 l
, char *str
,
406 snprintf(str
, size
, "Get Configuration(Length = %d)", l
);
409 static inline void dwc3_decode_set_configuration(__u8 v
, char *str
, size_t size
)
411 snprintf(str
, size
, "Set Configuration(Config = %d)", v
);
414 static inline void dwc3_decode_get_intf(__u16 i
, __u16 l
, char *str
,
417 snprintf(str
, size
, "Get Interface(Intf = %d, Length = %d)", i
, l
);
420 static inline void dwc3_decode_set_intf(__u8 v
, __u16 i
, char *str
, size_t size
)
422 snprintf(str
, size
, "Set Interface(Intf = %d, Alt.Setting = %d)", i
, v
);
425 static inline void dwc3_decode_synch_frame(__u16 i
, __u16 l
, char *str
,
428 snprintf(str
, size
, "Synch Frame(Endpoint = %d, Length = %d)", i
, l
);
431 static inline void dwc3_decode_set_sel(__u16 l
, char *str
, size_t size
)
433 snprintf(str
, size
, "Set SEL(Length = %d)", l
);
436 static inline void dwc3_decode_set_isoch_delay(__u8 v
, char *str
, size_t size
)
438 snprintf(str
, size
, "Set Isochronous Delay(Delay = %d ns)", v
);
442 * dwc3_decode_ctrl - returns a string represetion of ctrl request
444 static inline const char *dwc3_decode_ctrl(char *str
, size_t size
,
445 __u8 bRequestType
, __u8 bRequest
, __u16 wValue
, __u16 wIndex
,
449 case USB_REQ_GET_STATUS
:
450 dwc3_decode_get_status(bRequestType
, wIndex
, wLength
, str
,
453 case USB_REQ_CLEAR_FEATURE
:
454 case USB_REQ_SET_FEATURE
:
455 dwc3_decode_set_clear_feature(bRequestType
, bRequest
, wValue
,
458 case USB_REQ_SET_ADDRESS
:
459 dwc3_decode_set_address(wValue
, str
, size
);
461 case USB_REQ_GET_DESCRIPTOR
:
462 case USB_REQ_SET_DESCRIPTOR
:
463 dwc3_decode_get_set_descriptor(bRequestType
, bRequest
, wValue
,
464 wIndex
, wLength
, str
, size
);
466 case USB_REQ_GET_CONFIGURATION
:
467 dwc3_decode_get_configuration(wLength
, str
, size
);
469 case USB_REQ_SET_CONFIGURATION
:
470 dwc3_decode_set_configuration(wValue
, str
, size
);
472 case USB_REQ_GET_INTERFACE
:
473 dwc3_decode_get_intf(wIndex
, wLength
, str
, size
);
475 case USB_REQ_SET_INTERFACE
:
476 dwc3_decode_set_intf(wValue
, wIndex
, str
, size
);
478 case USB_REQ_SYNCH_FRAME
:
479 dwc3_decode_synch_frame(wIndex
, wLength
, str
, size
);
481 case USB_REQ_SET_SEL
:
482 dwc3_decode_set_sel(wLength
, str
, size
);
484 case USB_REQ_SET_ISOCH_DELAY
:
485 dwc3_decode_set_isoch_delay(wValue
, str
, size
);
488 snprintf(str
, size
, "%02x %02x %02x %02x %02x %02x %02x %02x",
489 bRequestType
, bRequest
,
490 cpu_to_le16(wValue
) & 0xff,
491 cpu_to_le16(wValue
) >> 8,
492 cpu_to_le16(wIndex
) & 0xff,
493 cpu_to_le16(wIndex
) >> 8,
494 cpu_to_le16(wLength
) & 0xff,
495 cpu_to_le16(wLength
) >> 8);
502 * dwc3_ep_event_string - returns event name
503 * @event: then event code
505 static inline const char *dwc3_ep_event_string(char *str
, size_t size
,
506 const struct dwc3_event_depevt
*event
, u32 ep0state
)
508 u8 epnum
= event
->endpoint_number
;
513 ret
= snprintf(str
, size
, "ep%d%s: ", epnum
>> 1,
514 (epnum
& 1) ? "in" : "out");
518 status
= event
->status
;
520 switch (event
->endpoint_event
) {
521 case DWC3_DEPEVT_XFERCOMPLETE
:
523 snprintf(str
+ len
, size
- len
, "Transfer Complete (%c%c%c)",
524 status
& DEPEVT_STATUS_SHORT
? 'S' : 's',
525 status
& DEPEVT_STATUS_IOC
? 'I' : 'i',
526 status
& DEPEVT_STATUS_LST
? 'L' : 'l');
531 snprintf(str
+ len
, size
- len
, " [%s]",
532 dwc3_ep0_state_string(ep0state
));
534 case DWC3_DEPEVT_XFERINPROGRESS
:
537 snprintf(str
+ len
, size
- len
, "Transfer In Progress [%d] (%c%c%c)",
539 status
& DEPEVT_STATUS_SHORT
? 'S' : 's',
540 status
& DEPEVT_STATUS_IOC
? 'I' : 'i',
541 status
& DEPEVT_STATUS_LST
? 'M' : 'm');
543 case DWC3_DEPEVT_XFERNOTREADY
:
546 snprintf(str
+ len
, size
- len
, "Transfer Not Ready [%d]%s",
548 status
& DEPEVT_STATUS_TRANSFER_ACTIVE
?
549 " (Active)" : " (Not Active)");
553 /* Control Endpoints */
555 int phase
= DEPEVT_STATUS_CONTROL_PHASE(event
->status
);
558 case DEPEVT_STATUS_CONTROL_DATA
:
559 snprintf(str
+ ret
, size
- ret
,
562 case DEPEVT_STATUS_CONTROL_STATUS
:
563 snprintf(str
+ ret
, size
- ret
,
568 case DWC3_DEPEVT_RXTXFIFOEVT
:
569 snprintf(str
+ ret
, size
- ret
, "FIFO");
571 case DWC3_DEPEVT_STREAMEVT
:
572 status
= event
->status
;
575 case DEPEVT_STREAMEVT_FOUND
:
576 snprintf(str
+ ret
, size
- ret
, " Stream %d Found",
579 case DEPEVT_STREAMEVT_NOTFOUND
:
581 snprintf(str
+ ret
, size
- ret
, " Stream Not Found");
586 case DWC3_DEPEVT_EPCMDCMPLT
:
587 snprintf(str
+ ret
, size
- ret
, "Endpoint Command Complete");
590 snprintf(str
, size
, "UNKNOWN");
597 * dwc3_gadget_event_type_string - return event name
598 * @event: the event code
600 static inline const char *dwc3_gadget_event_type_string(u8 event
)
603 case DWC3_DEVICE_EVENT_DISCONNECT
:
605 case DWC3_DEVICE_EVENT_RESET
:
607 case DWC3_DEVICE_EVENT_CONNECT_DONE
:
608 return "Connect Done";
609 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE
:
610 return "Link Status Change";
611 case DWC3_DEVICE_EVENT_WAKEUP
:
613 case DWC3_DEVICE_EVENT_HIBER_REQ
:
614 return "Hibernation";
615 case DWC3_DEVICE_EVENT_EOPF
:
616 return "End of Periodic Frame";
617 case DWC3_DEVICE_EVENT_SOF
:
618 return "Start of Frame";
619 case DWC3_DEVICE_EVENT_ERRATIC_ERROR
:
620 return "Erratic Error";
621 case DWC3_DEVICE_EVENT_CMD_CMPL
:
622 return "Command Complete";
623 case DWC3_DEVICE_EVENT_OVERFLOW
:
630 static inline const char *dwc3_decode_event(char *str
, size_t size
, u32 event
,
633 const union dwc3_event evt
= (union dwc3_event
) event
;
635 if (evt
.type
.is_devspec
)
636 return dwc3_gadget_event_string(str
, size
, &evt
.devt
);
638 return dwc3_ep_event_string(str
, size
, &evt
.depevt
, ep0state
);
641 static inline const char *dwc3_ep_cmd_status_string(int status
)
648 case DEPEVT_TRANSFER_NO_RESOURCE
:
649 return "No Resource";
650 case DEPEVT_TRANSFER_BUS_EXPIRY
:
657 static inline const char *dwc3_gadget_generic_cmd_status_string(int status
)
672 #ifdef CONFIG_DEBUG_FS
673 extern void dwc3_debugfs_init(struct dwc3
*);
674 extern void dwc3_debugfs_exit(struct dwc3
*);
676 static inline void dwc3_debugfs_init(struct dwc3
*d
)
678 static inline void dwc3_debugfs_exit(struct dwc3
*d
)
681 #endif /* __DWC3_DEBUG_H */