2 * debug.h - DesignWare USB3 DRD Controller Debug Header
4 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 of
11 * the License as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #ifndef __DWC3_DEBUG_H
20 #define __DWC3_DEBUG_H
25 * dwc3_gadget_ep_cmd_string - returns endpoint command string
28 static inline const char *
29 dwc3_gadget_ep_cmd_string(u8 cmd)
32 case DWC3_DEPCMD_DEPSTARTCFG:
33 return "Start New Configuration";
34 case DWC3_DEPCMD_ENDTRANSFER:
35 return "End Transfer";
36 case DWC3_DEPCMD_UPDATETRANSFER:
37 return "Update Transfer";
38 case DWC3_DEPCMD_STARTTRANSFER:
39 return "Start Transfer";
40 case DWC3_DEPCMD_CLEARSTALL:
42 case DWC3_DEPCMD_SETSTALL:
44 case DWC3_DEPCMD_GETEPSTATE:
45 return "Get Endpoint State";
46 case DWC3_DEPCMD_SETTRANSFRESOURCE:
47 return "Set Endpoint Transfer Resource";
48 case DWC3_DEPCMD_SETEPCONFIG:
49 return "Set Endpoint Configuration";
51 return "UNKNOWN command";
56 * dwc3_gadget_generic_cmd_string - returns generic command string
59 static inline const char *
60 dwc3_gadget_generic_cmd_string(u8 cmd)
63 case DWC3_DGCMD_SET_LMP:
65 case DWC3_DGCMD_SET_PERIODIC_PAR:
66 return "Set Periodic Parameters";
67 case DWC3_DGCMD_XMIT_FUNCTION:
68 return "Transmit Function Wake Device Notification";
69 case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO:
70 return "Set Scratchpad Buffer Array Address Lo";
71 case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI:
72 return "Set Scratchpad Buffer Array Address Hi";
73 case DWC3_DGCMD_SELECTED_FIFO_FLUSH:
74 return "Selected FIFO Flush";
75 case DWC3_DGCMD_ALL_FIFO_FLUSH:
76 return "All FIFO Flush";
77 case DWC3_DGCMD_SET_ENDPOINT_NRDY:
78 return "Set Endpoint NRDY";
79 case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK:
80 return "Run SoC Bus Loopback Test";
87 * dwc3_gadget_link_string - returns link name
88 * @link_state: link state code
90 static inline const char *
91 dwc3_gadget_link_string(enum dwc3_link_state link_state)
94 case DWC3_LINK_STATE_U0:
96 case DWC3_LINK_STATE_U1:
98 case DWC3_LINK_STATE_U2:
100 case DWC3_LINK_STATE_U3:
102 case DWC3_LINK_STATE_SS_DIS:
103 return "SS.Disabled";
104 case DWC3_LINK_STATE_RX_DET:
106 case DWC3_LINK_STATE_SS_INACT:
107 return "SS.Inactive";
108 case DWC3_LINK_STATE_POLL:
110 case DWC3_LINK_STATE_RECOV:
112 case DWC3_LINK_STATE_HRESET:
114 case DWC3_LINK_STATE_CMPLY:
116 case DWC3_LINK_STATE_LPBK:
118 case DWC3_LINK_STATE_RESET:
120 case DWC3_LINK_STATE_RESUME:
123 return "UNKNOWN link state\n";
128 * dwc3_gadget_hs_link_string - returns highspeed and below link name
129 * @link_state: link state code
131 static inline const char *
132 dwc3_gadget_hs_link_string(enum dwc3_link_state link_state)
134 switch (link_state) {
135 case DWC3_LINK_STATE_U0:
137 case DWC3_LINK_STATE_U2:
139 case DWC3_LINK_STATE_U3:
141 case DWC3_LINK_STATE_SS_DIS:
142 return "Disconnected";
143 case DWC3_LINK_STATE_RX_DET:
144 return "Early Suspend";
145 case DWC3_LINK_STATE_RECOV:
147 case DWC3_LINK_STATE_RESET:
149 case DWC3_LINK_STATE_RESUME:
152 return "UNKNOWN link state\n";
157 * dwc3_trb_type_string - returns TRB type as a string
158 * @type: the type of the TRB
160 static inline const char *dwc3_trb_type_string(unsigned int type)
163 case DWC3_TRBCTL_NORMAL:
165 case DWC3_TRBCTL_CONTROL_SETUP:
167 case DWC3_TRBCTL_CONTROL_STATUS2:
169 case DWC3_TRBCTL_CONTROL_STATUS3:
171 case DWC3_TRBCTL_CONTROL_DATA:
173 case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
175 case DWC3_TRBCTL_ISOCHRONOUS:
177 case DWC3_TRBCTL_LINK_TRB:
184 static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
187 case EP0_UNCONNECTED:
188 return "Unconnected";
189 case EP0_SETUP_PHASE:
190 return "Setup Phase";
193 case EP0_STATUS_PHASE:
194 return "Status Phase";
201 * dwc3_gadget_event_string - returns event name
202 * @event: the event code
204 static inline const char *
205 dwc3_gadget_event_string(char *str, const struct dwc3_event_devt *event)
207 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
209 switch (event->type) {
210 case DWC3_DEVICE_EVENT_DISCONNECT:
211 sprintf(str, "Disconnect: [%s]",
212 dwc3_gadget_link_string(state));
214 case DWC3_DEVICE_EVENT_RESET:
215 sprintf(str, "Reset [%s]", dwc3_gadget_link_string(state));
217 case DWC3_DEVICE_EVENT_CONNECT_DONE:
218 sprintf(str, "Connection Done [%s]",
219 dwc3_gadget_link_string(state));
221 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
222 sprintf(str, "Link Change [%s]",
223 dwc3_gadget_link_string(state));
225 case DWC3_DEVICE_EVENT_WAKEUP:
226 sprintf(str, "WakeUp [%s]", dwc3_gadget_link_string(state));
228 case DWC3_DEVICE_EVENT_EOPF:
229 sprintf(str, "End-Of-Frame [%s]",
230 dwc3_gadget_link_string(state));
232 case DWC3_DEVICE_EVENT_SOF:
233 sprintf(str, "Start-Of-Frame [%s]",
234 dwc3_gadget_link_string(state));
236 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
237 sprintf(str, "Erratic Error [%s]",
238 dwc3_gadget_link_string(state));
240 case DWC3_DEVICE_EVENT_CMD_CMPL:
241 sprintf(str, "Command Complete [%s]",
242 dwc3_gadget_link_string(state));
244 case DWC3_DEVICE_EVENT_OVERFLOW:
245 sprintf(str, "Overflow [%s]", dwc3_gadget_link_string(state));
248 sprintf(str, "UNKNOWN");
254 static inline void dwc3_decode_get_status(__u8 t, __u16 i, __u16 l, char *str)
256 switch (t & USB_RECIP_MASK) {
257 case USB_RECIP_INTERFACE:
258 sprintf(str, "Get Interface Status(Intf = %d, Length = %d)",
261 case USB_RECIP_ENDPOINT:
262 sprintf(str, "Get Endpoint Status(ep%d%s)",
264 i & USB_DIR_IN ? "in" : "out");
269 static inline void dwc3_decode_set_clear_feature(__u8 t, __u8 b, __u16 v,
272 switch (t & USB_RECIP_MASK) {
273 case USB_RECIP_DEVICE:
274 sprintf(str, "%s Device Feature(%s%s)",
275 b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
278 case USB_DEVICE_SELF_POWERED:
281 case USB_DEVICE_REMOTE_WAKEUP:
284 case USB_DEVICE_TEST_MODE:
290 v == USB_DEVICE_TEST_MODE ?
300 s = ": TEST_SE0_NAK";
306 s = ": TEST_FORCE_EN";
312 case USB_RECIP_INTERFACE:
313 sprintf(str, "%s Interface Feature(%s)",
314 b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
315 v == USB_INTRF_FUNC_SUSPEND ?
316 "Function Suspend" : "UNKNOWN");
318 case USB_RECIP_ENDPOINT:
319 sprintf(str, "%s Endpoint Feature(%s ep%d%s)",
320 b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
321 v == USB_ENDPOINT_HALT ? "Halt" : "UNKNOWN",
323 i & USB_DIR_IN ? "in" : "out");
328 static inline void dwc3_decode_set_address(__u16 v, char *str)
330 sprintf(str, "Set Address(Addr = %02x)", v);
333 static inline void dwc3_decode_get_set_descriptor(__u8 t, __u8 b, __u16 v,
334 __u16 i, __u16 l, char *str)
336 sprintf(str, "%s %s Descriptor(Index = %d, Length = %d)",
337 b == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set",
349 case USB_DT_INTERFACE:
352 case USB_DT_ENDPOINT:
355 case USB_DT_DEVICE_QUALIFIER:
356 s = "Device Qualifier";
358 case USB_DT_OTHER_SPEED_CONFIG:
359 s = "Other Speed Config";
361 case USB_DT_INTERFACE_POWER:
362 s = "Interface Power";
370 case USB_DT_INTERFACE_ASSOCIATION:
371 s = "Interface Association";
376 case USB_DT_DEVICE_CAPABILITY:
377 s = "Device Capability";
379 case USB_DT_PIPE_USAGE:
382 case USB_DT_SS_ENDPOINT_COMP:
383 s = "SS Endpoint Companion";
385 case USB_DT_SSP_ISOC_ENDPOINT_COMP:
386 s = "SSP Isochronous Endpoint Companion";
391 } s; }), v & 0xff, l);
395 static inline void dwc3_decode_get_configuration(__u16 l, char *str)
397 sprintf(str, "Get Configuration(Length = %d)", l);
400 static inline void dwc3_decode_set_configuration(__u8 v, char *str)
402 sprintf(str, "Set Configuration(Config = %d)", v);
405 static inline void dwc3_decode_get_intf(__u16 i, __u16 l, char *str)
407 sprintf(str, "Get Interface(Intf = %d, Length = %d)", i, l);
410 static inline void dwc3_decode_set_intf(__u8 v, __u16 i, char *str)
412 sprintf(str, "Set Interface(Intf = %d, Alt.Setting = %d)", i, v);
415 static inline void dwc3_decode_synch_frame(__u16 i, __u16 l, char *str)
417 sprintf(str, "Synch Frame(Endpoint = %d, Length = %d)", i, l);
420 static inline void dwc3_decode_set_sel(__u16 l, char *str)
422 sprintf(str, "Set SEL(Length = %d)", l);
425 static inline void dwc3_decode_set_isoch_delay(__u8 v, char *str)
427 sprintf(str, "Set Isochronous Delay(Delay = %d ns)", v);
431 * dwc3_decode_ctrl - returns a string represetion of ctrl request
433 static inline const char *dwc3_decode_ctrl(char *str, __u8 bRequestType,
434 __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength)
437 case USB_REQ_GET_STATUS:
438 dwc3_decode_get_status(bRequestType, wIndex, wLength, str);
440 case USB_REQ_CLEAR_FEATURE:
441 case USB_REQ_SET_FEATURE:
442 dwc3_decode_set_clear_feature(bRequestType, bRequest, wValue,
445 case USB_REQ_SET_ADDRESS:
446 dwc3_decode_set_address(wValue, str);
448 case USB_REQ_GET_DESCRIPTOR:
449 case USB_REQ_SET_DESCRIPTOR:
450 dwc3_decode_get_set_descriptor(bRequestType, bRequest, wValue,
451 wIndex, wLength, str);
453 case USB_REQ_GET_CONFIGURATION:
454 dwc3_decode_get_configuration(wLength, str);
456 case USB_REQ_SET_CONFIGURATION:
457 dwc3_decode_set_configuration(wValue, str);
459 case USB_REQ_GET_INTERFACE:
460 dwc3_decode_get_intf(wIndex, wLength, str);
462 case USB_REQ_SET_INTERFACE:
463 dwc3_decode_set_intf(wValue, wIndex, str);
465 case USB_REQ_SYNCH_FRAME:
466 dwc3_decode_synch_frame(wIndex, wLength, str);
468 case USB_REQ_SET_SEL:
469 dwc3_decode_set_sel(wLength, str);
471 case USB_REQ_SET_ISOCH_DELAY:
472 dwc3_decode_set_isoch_delay(wValue, str);
475 sprintf(str, "%02x %02x %02x %02x %02x %02x %02x %02x",
476 bRequestType, bRequest,
477 cpu_to_le16(wValue) & 0xff,
478 cpu_to_le16(wValue) >> 8,
479 cpu_to_le16(wIndex) & 0xff,
480 cpu_to_le16(wIndex) >> 8,
481 cpu_to_le16(wLength) & 0xff,
482 cpu_to_le16(wLength) >> 8);
489 * dwc3_ep_event_string - returns event name
490 * @event: then event code
492 static inline const char *
493 dwc3_ep_event_string(char *str, const struct dwc3_event_depevt *event,
496 u8 epnum = event->endpoint_number;
501 ret = sprintf(str, "ep%d%s: ", epnum >> 1,
502 (epnum & 1) ? "in" : "out");
506 switch (event->endpoint_event) {
507 case DWC3_DEPEVT_XFERCOMPLETE:
508 strcat(str, "Transfer Complete");
512 sprintf(str + len, " [%s]", dwc3_ep0_state_string(ep0state));
514 case DWC3_DEPEVT_XFERINPROGRESS:
515 strcat(str, "Transfer In-Progress");
517 case DWC3_DEPEVT_XFERNOTREADY:
518 strcat(str, "Transfer Not Ready");
519 status = event->status & DEPEVT_STATUS_TRANSFER_ACTIVE;
520 strcat(str, status ? " (Active)" : " (Not Active)");
522 /* Control Endpoints */
524 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
527 case DEPEVT_STATUS_CONTROL_DATA:
528 strcat(str, " [Data Phase]");
530 case DEPEVT_STATUS_CONTROL_STATUS:
531 strcat(str, " [Status Phase]");
535 case DWC3_DEPEVT_RXTXFIFOEVT:
538 case DWC3_DEPEVT_STREAMEVT:
539 status = event->status;
542 case DEPEVT_STREAMEVT_FOUND:
543 sprintf(str + ret, " Stream %d Found",
546 case DEPEVT_STREAMEVT_NOTFOUND:
548 strcat(str, " Stream Not Found");
553 case DWC3_DEPEVT_EPCMDCMPLT:
554 strcat(str, "Endpoint Command Complete");
557 sprintf(str, "UNKNOWN");
564 * dwc3_gadget_event_type_string - return event name
565 * @event: the event code
567 static inline const char *dwc3_gadget_event_type_string(u8 event)
570 case DWC3_DEVICE_EVENT_DISCONNECT:
572 case DWC3_DEVICE_EVENT_RESET:
574 case DWC3_DEVICE_EVENT_CONNECT_DONE:
575 return "Connect Done";
576 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
577 return "Link Status Change";
578 case DWC3_DEVICE_EVENT_WAKEUP:
580 case DWC3_DEVICE_EVENT_HIBER_REQ:
581 return "Hibernation";
582 case DWC3_DEVICE_EVENT_EOPF:
583 return "End of Periodic Frame";
584 case DWC3_DEVICE_EVENT_SOF:
585 return "Start of Frame";
586 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
587 return "Erratic Error";
588 case DWC3_DEVICE_EVENT_CMD_CMPL:
589 return "Command Complete";
590 case DWC3_DEVICE_EVENT_OVERFLOW:
597 static inline const char *dwc3_decode_event(char *str, u32 event, u32 ep0state)
599 const union dwc3_event evt = (union dwc3_event) event;
601 if (evt.type.is_devspec)
602 return dwc3_gadget_event_string(str, &evt.devt);
604 return dwc3_ep_event_string(str, &evt.depevt, ep0state);
607 static inline const char *dwc3_ep_cmd_status_string(int status)
614 case DEPEVT_TRANSFER_NO_RESOURCE:
615 return "No Resource";
616 case DEPEVT_TRANSFER_BUS_EXPIRY:
623 static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
638 #ifdef CONFIG_DEBUG_FS
639 extern void dwc3_debugfs_init(struct dwc3 *);
640 extern void dwc3_debugfs_exit(struct dwc3 *);
642 static inline void dwc3_debugfs_init(struct dwc3 *d)
644 static inline void dwc3_debugfs_exit(struct dwc3 *d)
647 #endif /* __DWC3_DEBUG_H */