blob: e925a6b73005f9d20cb5ca671466b6e6c935093f [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0
Felipe Balbi72246da2011-08-19 18:10:58 +03002/**
3 * debug.h - DesignWare USB3 DRD Controller Debug Header
4 *
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
Felipe Balbi72246da2011-08-19 18:10:58 +03006 *
7 * Authors: Felipe Balbi <balbi@ti.com>,
8 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Felipe Balbi72246da2011-08-19 18:10:58 +03009 */
10
Felipe Balbi80977dc2014-08-19 16:37:22 -050011#ifndef __DWC3_DEBUG_H
12#define __DWC3_DEBUG_H
13
Felipe Balbi72246da2011-08-19 18:10:58 +030014#include "core.h"
15
Felipe Balbi80977dc2014-08-19 16:37:22 -050016/**
17 * dwc3_gadget_ep_cmd_string - returns endpoint command string
18 * @cmd: command code
19 */
20static inline const char *
21dwc3_gadget_ep_cmd_string(u8 cmd)
22{
23 switch (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:
33 return "Clear Stall";
34 case DWC3_DEPCMD_SETSTALL:
35 return "Set Stall";
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";
42 default:
43 return "UNKNOWN command";
44 }
45}
46
47/**
48 * dwc3_gadget_generic_cmd_string - returns generic command string
49 * @cmd: command code
50 */
51static inline const char *
52dwc3_gadget_generic_cmd_string(u8 cmd)
53{
54 switch (cmd) {
55 case DWC3_DGCMD_SET_LMP:
56 return "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";
73 default:
74 return "UNKNOWN";
75 }
76}
77
78/**
79 * dwc3_gadget_link_string - returns link name
80 * @link_state: link state code
81 */
82static inline const char *
83dwc3_gadget_link_string(enum dwc3_link_state link_state)
84{
85 switch (link_state) {
86 case DWC3_LINK_STATE_U0:
87 return "U0";
88 case DWC3_LINK_STATE_U1:
89 return "U1";
90 case DWC3_LINK_STATE_U2:
91 return "U2";
92 case DWC3_LINK_STATE_U3:
93 return "U3";
94 case DWC3_LINK_STATE_SS_DIS:
95 return "SS.Disabled";
96 case DWC3_LINK_STATE_RX_DET:
97 return "RX.Detect";
98 case DWC3_LINK_STATE_SS_INACT:
99 return "SS.Inactive";
100 case DWC3_LINK_STATE_POLL:
101 return "Polling";
102 case DWC3_LINK_STATE_RECOV:
103 return "Recovery";
104 case DWC3_LINK_STATE_HRESET:
105 return "Hot Reset";
106 case DWC3_LINK_STATE_CMPLY:
107 return "Compliance";
108 case DWC3_LINK_STATE_LPBK:
109 return "Loopback";
110 case DWC3_LINK_STATE_RESET:
111 return "Reset";
112 case DWC3_LINK_STATE_RESUME:
113 return "Resume";
114 default:
115 return "UNKNOWN link state\n";
116 }
117}
118
Felipe Balbib5c7ed52017-03-31 14:44:09 +0300119/**
Thinh Nguyen0d36ded2018-11-07 17:55:19 -0800120 * dwc3_gadget_hs_link_string - returns highspeed and below link name
121 * @link_state: link state code
122 */
123static inline const char *
124dwc3_gadget_hs_link_string(enum dwc3_link_state link_state)
125{
126 switch (link_state) {
127 case DWC3_LINK_STATE_U0:
128 return "On";
129 case DWC3_LINK_STATE_U2:
130 return "Sleep";
131 case DWC3_LINK_STATE_U3:
132 return "Suspend";
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:
138 return "Recovery";
139 case DWC3_LINK_STATE_RESET:
140 return "Reset";
141 case DWC3_LINK_STATE_RESUME:
142 return "Resume";
143 default:
144 return "UNKNOWN link state\n";
145 }
146}
147
148/**
Felipe Balbib5c7ed52017-03-31 14:44:09 +0300149 * dwc3_trb_type_string - returns TRB type as a string
150 * @type: the type of the TRB
151 */
152static inline const char *dwc3_trb_type_string(unsigned int type)
153{
154 switch (type) {
155 case DWC3_TRBCTL_NORMAL:
156 return "normal";
157 case DWC3_TRBCTL_CONTROL_SETUP:
158 return "setup";
159 case DWC3_TRBCTL_CONTROL_STATUS2:
160 return "status2";
161 case DWC3_TRBCTL_CONTROL_STATUS3:
162 return "status3";
163 case DWC3_TRBCTL_CONTROL_DATA:
164 return "data";
165 case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
166 return "isoc-first";
167 case DWC3_TRBCTL_ISOCHRONOUS:
168 return "isoc";
169 case DWC3_TRBCTL_LINK_TRB:
170 return "link";
171 default:
172 return "UNKNOWN";
173 }
174}
175
Felipe Balbicdd72ac2016-09-26 13:22:21 +0300176static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
177{
178 switch (state) {
179 case EP0_UNCONNECTED:
180 return "Unconnected";
181 case EP0_SETUP_PHASE:
182 return "Setup Phase";
183 case EP0_DATA_PHASE:
184 return "Data Phase";
185 case EP0_STATUS_PHASE:
186 return "Status Phase";
187 default:
188 return "UNKNOWN";
189 }
190}
191
Felipe Balbi80977dc2014-08-19 16:37:22 -0500192/**
193 * dwc3_gadget_event_string - returns event name
194 * @event: the event code
195 */
Felipe Balbi7790b352019-02-04 15:43:38 +0200196static inline const char *dwc3_gadget_event_string(char *str, size_t size,
197 const struct dwc3_event_devt *event)
Felipe Balbi80977dc2014-08-19 16:37:22 -0500198{
Felipe Balbif75cacc2016-05-23 11:10:08 +0300199 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
200
201 switch (event->type) {
Felipe Balbi80977dc2014-08-19 16:37:22 -0500202 case DWC3_DEVICE_EVENT_DISCONNECT:
Felipe Balbi7790b352019-02-04 15:43:38 +0200203 snprintf(str, size, "Disconnect: [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300204 dwc3_gadget_link_string(state));
205 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500206 case DWC3_DEVICE_EVENT_RESET:
Felipe Balbi7790b352019-02-04 15:43:38 +0200207 snprintf(str, size, "Reset [%s]",
208 dwc3_gadget_link_string(state));
Felipe Balbif75cacc2016-05-23 11:10:08 +0300209 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500210 case DWC3_DEVICE_EVENT_CONNECT_DONE:
Felipe Balbi7790b352019-02-04 15:43:38 +0200211 snprintf(str, size, "Connection Done [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300212 dwc3_gadget_link_string(state));
213 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500214 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
Felipe Balbi7790b352019-02-04 15:43:38 +0200215 snprintf(str, size, "Link Change [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300216 dwc3_gadget_link_string(state));
217 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500218 case DWC3_DEVICE_EVENT_WAKEUP:
Felipe Balbi7790b352019-02-04 15:43:38 +0200219 snprintf(str, size, "WakeUp [%s]",
220 dwc3_gadget_link_string(state));
Felipe Balbif75cacc2016-05-23 11:10:08 +0300221 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500222 case DWC3_DEVICE_EVENT_EOPF:
Felipe Balbi7790b352019-02-04 15:43:38 +0200223 snprintf(str, size, "End-Of-Frame [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300224 dwc3_gadget_link_string(state));
225 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500226 case DWC3_DEVICE_EVENT_SOF:
Felipe Balbi7790b352019-02-04 15:43:38 +0200227 snprintf(str, size, "Start-Of-Frame [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300228 dwc3_gadget_link_string(state));
229 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500230 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
Felipe Balbi7790b352019-02-04 15:43:38 +0200231 snprintf(str, size, "Erratic Error [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300232 dwc3_gadget_link_string(state));
233 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500234 case DWC3_DEVICE_EVENT_CMD_CMPL:
Felipe Balbi7790b352019-02-04 15:43:38 +0200235 snprintf(str, size, "Command Complete [%s]",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300236 dwc3_gadget_link_string(state));
237 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500238 case DWC3_DEVICE_EVENT_OVERFLOW:
Felipe Balbi7790b352019-02-04 15:43:38 +0200239 snprintf(str, size, "Overflow [%s]",
240 dwc3_gadget_link_string(state));
Felipe Balbif75cacc2016-05-23 11:10:08 +0300241 break;
242 default:
Felipe Balbi7790b352019-02-04 15:43:38 +0200243 snprintf(str, size, "UNKNOWN");
Felipe Balbi80977dc2014-08-19 16:37:22 -0500244 }
245
Felipe Balbif75cacc2016-05-23 11:10:08 +0300246 return str;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500247}
248
Felipe Balbi7790b352019-02-04 15:43:38 +0200249static inline void dwc3_decode_get_status(__u8 t, __u16 i, __u16 l, char *str,
250 size_t size)
Felipe Balbiaf324232017-04-26 16:09:09 +0300251{
252 switch (t & USB_RECIP_MASK) {
253 case USB_RECIP_INTERFACE:
Felipe Balbi7790b352019-02-04 15:43:38 +0200254 snprintf(str, size, "Get Interface Status(Intf = %d, Length = %d)",
255 i, l);
Felipe Balbiaf324232017-04-26 16:09:09 +0300256 break;
257 case USB_RECIP_ENDPOINT:
Felipe Balbi7790b352019-02-04 15:43:38 +0200258 snprintf(str, size, "Get Endpoint Status(ep%d%s)",
Felipe Balbiaf324232017-04-26 16:09:09 +0300259 i & ~USB_DIR_IN,
260 i & USB_DIR_IN ? "in" : "out");
261 break;
262 }
263}
264
265static inline void dwc3_decode_set_clear_feature(__u8 t, __u8 b, __u16 v,
Felipe Balbi7790b352019-02-04 15:43:38 +0200266 __u16 i, char *str, size_t size)
Felipe Balbiaf324232017-04-26 16:09:09 +0300267{
268 switch (t & USB_RECIP_MASK) {
269 case USB_RECIP_DEVICE:
Felipe Balbi7790b352019-02-04 15:43:38 +0200270 snprintf(str, size, "%s Device Feature(%s%s)",
Felipe Balbiaf324232017-04-26 16:09:09 +0300271 b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
272 ({char *s;
273 switch (v) {
274 case USB_DEVICE_SELF_POWERED:
275 s = "Self Powered";
276 break;
277 case USB_DEVICE_REMOTE_WAKEUP:
278 s = "Remote Wakeup";
279 break;
280 case USB_DEVICE_TEST_MODE:
281 s = "Test Mode";
282 break;
Felipe Balbi0c5d2952017-11-09 15:00:46 +0200283 case USB_DEVICE_U1_ENABLE:
284 s = "U1 Enable";
285 break;
286 case USB_DEVICE_U2_ENABLE:
287 s = "U2 Enable";
288 break;
289 case USB_DEVICE_LTM_ENABLE:
290 s = "LTM Enable";
291 break;
Felipe Balbiaf324232017-04-26 16:09:09 +0300292 default:
293 s = "UNKNOWN";
294 } s; }),
295 v == USB_DEVICE_TEST_MODE ?
296 ({ char *s;
297 switch (i) {
298 case TEST_J:
299 s = ": TEST_J";
300 break;
301 case TEST_K:
302 s = ": TEST_K";
303 break;
304 case TEST_SE0_NAK:
305 s = ": TEST_SE0_NAK";
306 break;
307 case TEST_PACKET:
308 s = ": TEST_PACKET";
309 break;
310 case TEST_FORCE_EN:
311 s = ": TEST_FORCE_EN";
312 break;
313 default:
314 s = ": UNKNOWN";
315 } s; }) : "");
316 break;
317 case USB_RECIP_INTERFACE:
Felipe Balbi7790b352019-02-04 15:43:38 +0200318 snprintf(str, size, "%s Interface Feature(%s)",
Felipe Balbiaf324232017-04-26 16:09:09 +0300319 b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
320 v == USB_INTRF_FUNC_SUSPEND ?
321 "Function Suspend" : "UNKNOWN");
322 break;
323 case USB_RECIP_ENDPOINT:
Felipe Balbi7790b352019-02-04 15:43:38 +0200324 snprintf(str, size, "%s Endpoint Feature(%s ep%d%s)",
Felipe Balbiaf324232017-04-26 16:09:09 +0300325 b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
326 v == USB_ENDPOINT_HALT ? "Halt" : "UNKNOWN",
327 i & ~USB_DIR_IN,
328 i & USB_DIR_IN ? "in" : "out");
329 break;
330 }
331}
332
Felipe Balbi7790b352019-02-04 15:43:38 +0200333static inline void dwc3_decode_set_address(__u16 v, char *str, size_t size)
Felipe Balbiaf324232017-04-26 16:09:09 +0300334{
Felipe Balbi7790b352019-02-04 15:43:38 +0200335 snprintf(str, size, "Set Address(Addr = %02x)", v);
Felipe Balbiaf324232017-04-26 16:09:09 +0300336}
337
338static inline void dwc3_decode_get_set_descriptor(__u8 t, __u8 b, __u16 v,
Felipe Balbi7790b352019-02-04 15:43:38 +0200339 __u16 i, __u16 l, char *str, size_t size)
Felipe Balbiaf324232017-04-26 16:09:09 +0300340{
Felipe Balbi7790b352019-02-04 15:43:38 +0200341 snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)",
Felipe Balbiaf324232017-04-26 16:09:09 +0300342 b == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set",
343 ({ char *s;
344 switch (v >> 8) {
345 case USB_DT_DEVICE:
346 s = "Device";
347 break;
348 case USB_DT_CONFIG:
349 s = "Configuration";
350 break;
351 case USB_DT_STRING:
352 s = "String";
353 break;
354 case USB_DT_INTERFACE:
355 s = "Interface";
356 break;
357 case USB_DT_ENDPOINT:
358 s = "Endpoint";
359 break;
360 case USB_DT_DEVICE_QUALIFIER:
361 s = "Device Qualifier";
362 break;
363 case USB_DT_OTHER_SPEED_CONFIG:
364 s = "Other Speed Config";
365 break;
366 case USB_DT_INTERFACE_POWER:
367 s = "Interface Power";
368 break;
369 case USB_DT_OTG:
370 s = "OTG";
371 break;
372 case USB_DT_DEBUG:
373 s = "Debug";
374 break;
375 case USB_DT_INTERFACE_ASSOCIATION:
376 s = "Interface Association";
377 break;
378 case USB_DT_BOS:
379 s = "BOS";
380 break;
381 case USB_DT_DEVICE_CAPABILITY:
382 s = "Device Capability";
383 break;
384 case USB_DT_PIPE_USAGE:
385 s = "Pipe Usage";
386 break;
387 case USB_DT_SS_ENDPOINT_COMP:
388 s = "SS Endpoint Companion";
389 break;
390 case USB_DT_SSP_ISOC_ENDPOINT_COMP:
391 s = "SSP Isochronous Endpoint Companion";
392 break;
393 default:
394 s = "UNKNOWN";
395 break;
396 } s; }), v & 0xff, l);
397}
398
399
Felipe Balbi7790b352019-02-04 15:43:38 +0200400static inline void dwc3_decode_get_configuration(__u16 l, char *str,
401 size_t size)
Felipe Balbiaf324232017-04-26 16:09:09 +0300402{
Felipe Balbi7790b352019-02-04 15:43:38 +0200403 snprintf(str, size, "Get Configuration(Length = %d)", l);
Felipe Balbiaf324232017-04-26 16:09:09 +0300404}
405
Felipe Balbi7790b352019-02-04 15:43:38 +0200406static inline void dwc3_decode_set_configuration(__u8 v, char *str, size_t size)
Felipe Balbiaf324232017-04-26 16:09:09 +0300407{
Felipe Balbi7790b352019-02-04 15:43:38 +0200408 snprintf(str, size, "Set Configuration(Config = %d)", v);
Felipe Balbiaf324232017-04-26 16:09:09 +0300409}
410
Felipe Balbi7790b352019-02-04 15:43:38 +0200411static inline void dwc3_decode_get_intf(__u16 i, __u16 l, char *str,
412 size_t size)
Felipe Balbiaf324232017-04-26 16:09:09 +0300413{
Felipe Balbi7790b352019-02-04 15:43:38 +0200414 snprintf(str, size, "Get Interface(Intf = %d, Length = %d)", i, l);
Felipe Balbiaf324232017-04-26 16:09:09 +0300415}
416
Felipe Balbi7790b352019-02-04 15:43:38 +0200417static inline void dwc3_decode_set_intf(__u8 v, __u16 i, char *str, size_t size)
Felipe Balbiaf324232017-04-26 16:09:09 +0300418{
Felipe Balbi7790b352019-02-04 15:43:38 +0200419 snprintf(str, size, "Set Interface(Intf = %d, Alt.Setting = %d)", i, v);
Felipe Balbiaf324232017-04-26 16:09:09 +0300420}
421
Felipe Balbi7790b352019-02-04 15:43:38 +0200422static inline void dwc3_decode_synch_frame(__u16 i, __u16 l, char *str,
423 size_t size)
Felipe Balbiaf324232017-04-26 16:09:09 +0300424{
Felipe Balbi7790b352019-02-04 15:43:38 +0200425 snprintf(str, size, "Synch Frame(Endpoint = %d, Length = %d)", i, l);
Felipe Balbiaf324232017-04-26 16:09:09 +0300426}
427
Felipe Balbi7790b352019-02-04 15:43:38 +0200428static inline void dwc3_decode_set_sel(__u16 l, char *str, size_t size)
Felipe Balbiaf324232017-04-26 16:09:09 +0300429{
Felipe Balbi7790b352019-02-04 15:43:38 +0200430 snprintf(str, size, "Set SEL(Length = %d)", l);
Felipe Balbiaf324232017-04-26 16:09:09 +0300431}
432
Felipe Balbi7790b352019-02-04 15:43:38 +0200433static inline void dwc3_decode_set_isoch_delay(__u8 v, char *str, size_t size)
Felipe Balbiaf324232017-04-26 16:09:09 +0300434{
Felipe Balbi7790b352019-02-04 15:43:38 +0200435 snprintf(str, size, "Set Isochronous Delay(Delay = %d ns)", v);
Felipe Balbiaf324232017-04-26 16:09:09 +0300436}
437
438/**
439 * dwc3_decode_ctrl - returns a string represetion of ctrl request
440 */
Felipe Balbi7790b352019-02-04 15:43:38 +0200441static inline const char *dwc3_decode_ctrl(char *str, size_t size,
442 __u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex,
443 __u16 wLength)
Felipe Balbiaf324232017-04-26 16:09:09 +0300444{
445 switch (bRequest) {
446 case USB_REQ_GET_STATUS:
Felipe Balbi7790b352019-02-04 15:43:38 +0200447 dwc3_decode_get_status(bRequestType, wIndex, wLength, str,
448 size);
Felipe Balbiaf324232017-04-26 16:09:09 +0300449 break;
450 case USB_REQ_CLEAR_FEATURE:
451 case USB_REQ_SET_FEATURE:
452 dwc3_decode_set_clear_feature(bRequestType, bRequest, wValue,
Felipe Balbi7790b352019-02-04 15:43:38 +0200453 wIndex, str, size);
Felipe Balbiaf324232017-04-26 16:09:09 +0300454 break;
455 case USB_REQ_SET_ADDRESS:
Felipe Balbi7790b352019-02-04 15:43:38 +0200456 dwc3_decode_set_address(wValue, str, size);
Felipe Balbiaf324232017-04-26 16:09:09 +0300457 break;
458 case USB_REQ_GET_DESCRIPTOR:
459 case USB_REQ_SET_DESCRIPTOR:
460 dwc3_decode_get_set_descriptor(bRequestType, bRequest, wValue,
Felipe Balbi7790b352019-02-04 15:43:38 +0200461 wIndex, wLength, str, size);
Felipe Balbiaf324232017-04-26 16:09:09 +0300462 break;
463 case USB_REQ_GET_CONFIGURATION:
Felipe Balbi7790b352019-02-04 15:43:38 +0200464 dwc3_decode_get_configuration(wLength, str, size);
Felipe Balbiaf324232017-04-26 16:09:09 +0300465 break;
466 case USB_REQ_SET_CONFIGURATION:
Felipe Balbi7790b352019-02-04 15:43:38 +0200467 dwc3_decode_set_configuration(wValue, str, size);
Felipe Balbiaf324232017-04-26 16:09:09 +0300468 break;
469 case USB_REQ_GET_INTERFACE:
Felipe Balbi7790b352019-02-04 15:43:38 +0200470 dwc3_decode_get_intf(wIndex, wLength, str, size);
Felipe Balbiaf324232017-04-26 16:09:09 +0300471 break;
472 case USB_REQ_SET_INTERFACE:
Felipe Balbi7790b352019-02-04 15:43:38 +0200473 dwc3_decode_set_intf(wValue, wIndex, str, size);
Felipe Balbiaf324232017-04-26 16:09:09 +0300474 break;
475 case USB_REQ_SYNCH_FRAME:
Felipe Balbi7790b352019-02-04 15:43:38 +0200476 dwc3_decode_synch_frame(wIndex, wLength, str, size);
Felipe Balbiaf324232017-04-26 16:09:09 +0300477 break;
478 case USB_REQ_SET_SEL:
Felipe Balbi7790b352019-02-04 15:43:38 +0200479 dwc3_decode_set_sel(wLength, str, size);
Felipe Balbiaf324232017-04-26 16:09:09 +0300480 break;
481 case USB_REQ_SET_ISOCH_DELAY:
Felipe Balbi7790b352019-02-04 15:43:38 +0200482 dwc3_decode_set_isoch_delay(wValue, str, size);
Felipe Balbiaf324232017-04-26 16:09:09 +0300483 break;
484 default:
Felipe Balbi7790b352019-02-04 15:43:38 +0200485 snprintf(str, size, "%02x %02x %02x %02x %02x %02x %02x %02x",
Felipe Balbiaf324232017-04-26 16:09:09 +0300486 bRequestType, bRequest,
487 cpu_to_le16(wValue) & 0xff,
488 cpu_to_le16(wValue) >> 8,
489 cpu_to_le16(wIndex) & 0xff,
490 cpu_to_le16(wIndex) >> 8,
491 cpu_to_le16(wLength) & 0xff,
492 cpu_to_le16(wLength) >> 8);
493 }
494
495 return str;
496}
497
Felipe Balbi80977dc2014-08-19 16:37:22 -0500498/**
499 * dwc3_ep_event_string - returns event name
500 * @event: then event code
501 */
Felipe Balbi7790b352019-02-04 15:43:38 +0200502static inline const char *dwc3_ep_event_string(char *str, size_t size,
503 const struct dwc3_event_depevt *event, u32 ep0state)
Felipe Balbi80977dc2014-08-19 16:37:22 -0500504{
Felipe Balbif75cacc2016-05-23 11:10:08 +0300505 u8 epnum = event->endpoint_number;
Felipe Balbi43c96be2016-09-26 13:23:34 +0300506 size_t len;
Felipe Balbif75cacc2016-05-23 11:10:08 +0300507 int status;
508 int ret;
509
Felipe Balbi7790b352019-02-04 15:43:38 +0200510 ret = snprintf(str, size, "ep%d%s: ", epnum >> 1,
Felipe Balbi696fe692016-08-24 14:32:39 +0300511 (epnum & 1) ? "in" : "out");
Felipe Balbif75cacc2016-05-23 11:10:08 +0300512 if (ret < 0)
513 return "UNKNOWN";
514
Felipe Balbib27972b2018-04-06 11:03:19 +0300515 status = event->status;
516
Felipe Balbif75cacc2016-05-23 11:10:08 +0300517 switch (event->endpoint_event) {
Felipe Balbi80977dc2014-08-19 16:37:22 -0500518 case DWC3_DEPEVT_XFERCOMPLETE:
Felipe Balbib27972b2018-04-06 11:03:19 +0300519 len = strlen(str);
Felipe Balbi7790b352019-02-04 15:43:38 +0200520 snprintf(str + len, size - len, "Transfer Complete (%c%c%c)",
Felipe Balbib27972b2018-04-06 11:03:19 +0300521 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
522 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
523 status & DEPEVT_STATUS_LST ? 'L' : 'l');
524
Felipe Balbi43c96be2016-09-26 13:23:34 +0300525 len = strlen(str);
526
527 if (epnum <= 1)
Felipe Balbi7790b352019-02-04 15:43:38 +0200528 snprintf(str + len, size - len, " [%s]",
529 dwc3_ep0_state_string(ep0state));
Felipe Balbif75cacc2016-05-23 11:10:08 +0300530 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500531 case DWC3_DEPEVT_XFERINPROGRESS:
Felipe Balbib27972b2018-04-06 11:03:19 +0300532 len = strlen(str);
533
Felipe Balbi7790b352019-02-04 15:43:38 +0200534 snprintf(str + len, size - len, "Transfer In Progress [%d] (%c%c%c)",
Felipe Balbie1d542f2018-04-11 10:31:53 +0300535 event->parameters,
Felipe Balbib27972b2018-04-06 11:03:19 +0300536 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
537 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
538 status & DEPEVT_STATUS_LST ? 'M' : 'm');
Felipe Balbif75cacc2016-05-23 11:10:08 +0300539 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500540 case DWC3_DEPEVT_XFERNOTREADY:
Felipe Balbie1d542f2018-04-11 10:31:53 +0300541 len = strlen(str);
542
Felipe Balbi7790b352019-02-04 15:43:38 +0200543 snprintf(str + len, size - len, "Transfer Not Ready [%d]%s",
Felipe Balbie1d542f2018-04-11 10:31:53 +0300544 event->parameters,
545 status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
Felipe Balbib27972b2018-04-06 11:03:19 +0300546 " (Active)" : " (Not Active)");
Felipe Balbi45a2af22016-09-26 12:54:04 +0300547
548 /* Control Endpoints */
549 if (epnum <= 1) {
550 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
551
552 switch (phase) {
553 case DEPEVT_STATUS_CONTROL_DATA:
554 strcat(str, " [Data Phase]");
555 break;
556 case DEPEVT_STATUS_CONTROL_STATUS:
557 strcat(str, " [Status Phase]");
558 }
559 }
Felipe Balbif75cacc2016-05-23 11:10:08 +0300560 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500561 case DWC3_DEPEVT_RXTXFIFOEVT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300562 strcat(str, "FIFO");
563 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500564 case DWC3_DEPEVT_STREAMEVT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300565 status = event->status;
566
567 switch (status) {
568 case DEPEVT_STREAMEVT_FOUND:
Felipe Balbi7790b352019-02-04 15:43:38 +0200569 snprintf(str + ret, size - ret, " Stream %d Found",
Felipe Balbif75cacc2016-05-23 11:10:08 +0300570 event->parameters);
571 break;
572 case DEPEVT_STREAMEVT_NOTFOUND:
573 default:
574 strcat(str, " Stream Not Found");
575 break;
576 }
577
578 break;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500579 case DWC3_DEPEVT_EPCMDCMPLT:
Felipe Balbif75cacc2016-05-23 11:10:08 +0300580 strcat(str, "Endpoint Command Complete");
581 break;
582 default:
Felipe Balbi7790b352019-02-04 15:43:38 +0200583 snprintf(str, size, "UNKNOWN");
Felipe Balbi80977dc2014-08-19 16:37:22 -0500584 }
585
Felipe Balbif75cacc2016-05-23 11:10:08 +0300586 return str;
Felipe Balbi80977dc2014-08-19 16:37:22 -0500587}
588
Felipe Balbie9960612014-08-19 16:49:20 -0500589/**
590 * dwc3_gadget_event_type_string - return event name
591 * @event: the event code
592 */
593static inline const char *dwc3_gadget_event_type_string(u8 event)
594{
595 switch (event) {
596 case DWC3_DEVICE_EVENT_DISCONNECT:
597 return "Disconnect";
598 case DWC3_DEVICE_EVENT_RESET:
599 return "Reset";
600 case DWC3_DEVICE_EVENT_CONNECT_DONE:
601 return "Connect Done";
602 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
603 return "Link Status Change";
604 case DWC3_DEVICE_EVENT_WAKEUP:
605 return "Wake-Up";
606 case DWC3_DEVICE_EVENT_HIBER_REQ:
607 return "Hibernation";
608 case DWC3_DEVICE_EVENT_EOPF:
609 return "End of Periodic Frame";
610 case DWC3_DEVICE_EVENT_SOF:
611 return "Start of Frame";
612 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
613 return "Erratic Error";
614 case DWC3_DEVICE_EVENT_CMD_CMPL:
615 return "Command Complete";
616 case DWC3_DEVICE_EVENT_OVERFLOW:
617 return "Overflow";
618 default:
619 return "UNKNOWN";
620 }
621}
622
Felipe Balbi7790b352019-02-04 15:43:38 +0200623static inline const char *dwc3_decode_event(char *str, size_t size, u32 event,
624 u32 ep0state)
Felipe Balbif75cacc2016-05-23 11:10:08 +0300625{
626 const union dwc3_event evt = (union dwc3_event) event;
627
628 if (evt.type.is_devspec)
Felipe Balbi7790b352019-02-04 15:43:38 +0200629 return dwc3_gadget_event_string(str, size, &evt.devt);
Felipe Balbif75cacc2016-05-23 11:10:08 +0300630 else
Felipe Balbi7790b352019-02-04 15:43:38 +0200631 return dwc3_ep_event_string(str, size, &evt.depevt, ep0state);
Felipe Balbif75cacc2016-05-23 11:10:08 +0300632}
633
Felipe Balbi0933df12016-05-23 14:02:33 +0300634static inline const char *dwc3_ep_cmd_status_string(int status)
635{
636 switch (status) {
637 case -ETIMEDOUT:
638 return "Timed Out";
639 case 0:
640 return "Successful";
641 case DEPEVT_TRANSFER_NO_RESOURCE:
642 return "No Resource";
643 case DEPEVT_TRANSFER_BUS_EXPIRY:
644 return "Bus Expiry";
645 default:
646 return "UNKNOWN";
647 }
648}
649
Felipe Balbi71f7e702016-05-23 14:16:19 +0300650static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
651{
652 switch (status) {
653 case -ETIMEDOUT:
654 return "Timed Out";
655 case 0:
656 return "Successful";
657 case 1:
658 return "Error";
659 default:
660 return "UNKNOWN";
661 }
662}
663
Felipe Balbi57b14da2016-09-30 14:12:34 +0300664
Felipe Balbi72246da2011-08-19 18:10:58 +0300665#ifdef CONFIG_DEBUG_FS
Du, Changbin4e9f3112016-04-12 19:10:18 +0800666extern void dwc3_debugfs_init(struct dwc3 *);
Felipe Balbi72246da2011-08-19 18:10:58 +0300667extern void dwc3_debugfs_exit(struct dwc3 *);
668#else
Du, Changbin4e9f3112016-04-12 19:10:18 +0800669static inline void dwc3_debugfs_init(struct dwc3 *d)
670{ }
Felipe Balbi72246da2011-08-19 18:10:58 +0300671static inline void dwc3_debugfs_exit(struct dwc3 *d)
672{ }
673#endif
Felipe Balbi80977dc2014-08-19 16:37:22 -0500674#endif /* __DWC3_DEBUG_H */