Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1 | /** |
| 2 | * debug.h - DesignWare USB3 DRD Controller Debug Header |
| 3 | * |
| 4 | * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 5 | * |
| 6 | * Authors: Felipe Balbi <balbi@ti.com>, |
| 7 | * Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| 8 | * |
Felipe Balbi | 5945f78 | 2013-06-30 14:15:11 +0300 | [diff] [blame] | 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. |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 12 | * |
Felipe Balbi | 5945f78 | 2013-06-30 14:15:11 +0300 | [diff] [blame] | 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. |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 17 | */ |
| 18 | |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 19 | #ifndef __DWC3_DEBUG_H |
| 20 | #define __DWC3_DEBUG_H |
| 21 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 22 | #include "core.h" |
| 23 | |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 24 | /** |
| 25 | * dwc3_gadget_ep_cmd_string - returns endpoint command string |
| 26 | * @cmd: command code |
| 27 | */ |
| 28 | static inline const char * |
| 29 | dwc3_gadget_ep_cmd_string(u8 cmd) |
| 30 | { |
| 31 | switch (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: |
| 41 | return "Clear Stall"; |
| 42 | case DWC3_DEPCMD_SETSTALL: |
| 43 | return "Set Stall"; |
| 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"; |
| 50 | default: |
| 51 | return "UNKNOWN command"; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * dwc3_gadget_generic_cmd_string - returns generic command string |
| 57 | * @cmd: command code |
| 58 | */ |
| 59 | static inline const char * |
| 60 | dwc3_gadget_generic_cmd_string(u8 cmd) |
| 61 | { |
| 62 | switch (cmd) { |
| 63 | case DWC3_DGCMD_SET_LMP: |
| 64 | return "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"; |
| 81 | default: |
| 82 | return "UNKNOWN"; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * dwc3_gadget_link_string - returns link name |
| 88 | * @link_state: link state code |
| 89 | */ |
| 90 | static inline const char * |
| 91 | dwc3_gadget_link_string(enum dwc3_link_state link_state) |
| 92 | { |
| 93 | switch (link_state) { |
| 94 | case DWC3_LINK_STATE_U0: |
| 95 | return "U0"; |
| 96 | case DWC3_LINK_STATE_U1: |
| 97 | return "U1"; |
| 98 | case DWC3_LINK_STATE_U2: |
| 99 | return "U2"; |
| 100 | case DWC3_LINK_STATE_U3: |
| 101 | return "U3"; |
| 102 | case DWC3_LINK_STATE_SS_DIS: |
| 103 | return "SS.Disabled"; |
| 104 | case DWC3_LINK_STATE_RX_DET: |
| 105 | return "RX.Detect"; |
| 106 | case DWC3_LINK_STATE_SS_INACT: |
| 107 | return "SS.Inactive"; |
| 108 | case DWC3_LINK_STATE_POLL: |
| 109 | return "Polling"; |
| 110 | case DWC3_LINK_STATE_RECOV: |
| 111 | return "Recovery"; |
| 112 | case DWC3_LINK_STATE_HRESET: |
| 113 | return "Hot Reset"; |
| 114 | case DWC3_LINK_STATE_CMPLY: |
| 115 | return "Compliance"; |
| 116 | case DWC3_LINK_STATE_LPBK: |
| 117 | return "Loopback"; |
| 118 | case DWC3_LINK_STATE_RESET: |
| 119 | return "Reset"; |
| 120 | case DWC3_LINK_STATE_RESUME: |
| 121 | return "Resume"; |
| 122 | default: |
| 123 | return "UNKNOWN link state\n"; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * dwc3_gadget_event_string - returns event name |
| 129 | * @event: the event code |
| 130 | */ |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 131 | static inline const char * |
| 132 | dwc3_gadget_event_string(const struct dwc3_event_devt *event) |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 133 | { |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 134 | static char str[256]; |
| 135 | enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK; |
| 136 | |
| 137 | switch (event->type) { |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 138 | case DWC3_DEVICE_EVENT_DISCONNECT: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 139 | sprintf(str, "Disconnect: [%s]", |
| 140 | dwc3_gadget_link_string(state)); |
| 141 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 142 | case DWC3_DEVICE_EVENT_RESET: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 143 | sprintf(str, "Reset [%s]", dwc3_gadget_link_string(state)); |
| 144 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 145 | case DWC3_DEVICE_EVENT_CONNECT_DONE: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 146 | sprintf(str, "Connection Done [%s]", |
| 147 | dwc3_gadget_link_string(state)); |
| 148 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 149 | case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 150 | sprintf(str, "Link Change [%s]", |
| 151 | dwc3_gadget_link_string(state)); |
| 152 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 153 | case DWC3_DEVICE_EVENT_WAKEUP: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 154 | sprintf(str, "WakeUp [%s]", dwc3_gadget_link_string(state)); |
| 155 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 156 | case DWC3_DEVICE_EVENT_EOPF: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 157 | sprintf(str, "End-Of-Frame [%s]", |
| 158 | dwc3_gadget_link_string(state)); |
| 159 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 160 | case DWC3_DEVICE_EVENT_SOF: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 161 | sprintf(str, "Start-Of-Frame [%s]", |
| 162 | dwc3_gadget_link_string(state)); |
| 163 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 164 | case DWC3_DEVICE_EVENT_ERRATIC_ERROR: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 165 | sprintf(str, "Erratic Error [%s]", |
| 166 | dwc3_gadget_link_string(state)); |
| 167 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 168 | case DWC3_DEVICE_EVENT_CMD_CMPL: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 169 | sprintf(str, "Command Complete [%s]", |
| 170 | dwc3_gadget_link_string(state)); |
| 171 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 172 | case DWC3_DEVICE_EVENT_OVERFLOW: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 173 | sprintf(str, "Overflow [%s]", dwc3_gadget_link_string(state)); |
| 174 | break; |
| 175 | default: |
| 176 | sprintf(str, "UNKNOWN"); |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 177 | } |
| 178 | |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 179 | return str; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /** |
| 183 | * dwc3_ep_event_string - returns event name |
| 184 | * @event: then event code |
| 185 | */ |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 186 | static inline const char * |
| 187 | dwc3_ep_event_string(const struct dwc3_event_depevt *event) |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 188 | { |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 189 | u8 epnum = event->endpoint_number; |
| 190 | static char str[256]; |
| 191 | int status; |
| 192 | int ret; |
| 193 | |
| 194 | ret = sprintf(str, "ep%d%s: ", epnum >> 1, |
| 195 | (epnum & 1) ? "in" : "in"); |
| 196 | if (ret < 0) |
| 197 | return "UNKNOWN"; |
| 198 | |
| 199 | switch (event->endpoint_event) { |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 200 | case DWC3_DEPEVT_XFERCOMPLETE: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 201 | strcat(str, "Transfer Complete"); |
| 202 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 203 | case DWC3_DEPEVT_XFERINPROGRESS: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 204 | strcat(str, "Transfer In-Progress"); |
| 205 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 206 | case DWC3_DEPEVT_XFERNOTREADY: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 207 | strcat(str, "Transfer Not Ready"); |
| 208 | status = event->status & DEPEVT_STATUS_TRANSFER_ACTIVE; |
| 209 | strcat(str, status ? " (Active)" : " (Not Active)"); |
| 210 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 211 | case DWC3_DEPEVT_RXTXFIFOEVT: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 212 | strcat(str, "FIFO"); |
| 213 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 214 | case DWC3_DEPEVT_STREAMEVT: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 215 | status = event->status; |
| 216 | |
| 217 | switch (status) { |
| 218 | case DEPEVT_STREAMEVT_FOUND: |
| 219 | sprintf(str + ret, " Stream %d Found", |
| 220 | event->parameters); |
| 221 | break; |
| 222 | case DEPEVT_STREAMEVT_NOTFOUND: |
| 223 | default: |
| 224 | strcat(str, " Stream Not Found"); |
| 225 | break; |
| 226 | } |
| 227 | |
| 228 | break; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 229 | case DWC3_DEPEVT_EPCMDCMPLT: |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 230 | strcat(str, "Endpoint Command Complete"); |
| 231 | break; |
| 232 | default: |
| 233 | sprintf(str, "UNKNOWN"); |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 234 | } |
| 235 | |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 236 | return str; |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 237 | } |
| 238 | |
Felipe Balbi | e996061 | 2014-08-19 16:49:20 -0500 | [diff] [blame] | 239 | /** |
| 240 | * dwc3_gadget_event_type_string - return event name |
| 241 | * @event: the event code |
| 242 | */ |
| 243 | static inline const char *dwc3_gadget_event_type_string(u8 event) |
| 244 | { |
| 245 | switch (event) { |
| 246 | case DWC3_DEVICE_EVENT_DISCONNECT: |
| 247 | return "Disconnect"; |
| 248 | case DWC3_DEVICE_EVENT_RESET: |
| 249 | return "Reset"; |
| 250 | case DWC3_DEVICE_EVENT_CONNECT_DONE: |
| 251 | return "Connect Done"; |
| 252 | case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE: |
| 253 | return "Link Status Change"; |
| 254 | case DWC3_DEVICE_EVENT_WAKEUP: |
| 255 | return "Wake-Up"; |
| 256 | case DWC3_DEVICE_EVENT_HIBER_REQ: |
| 257 | return "Hibernation"; |
| 258 | case DWC3_DEVICE_EVENT_EOPF: |
| 259 | return "End of Periodic Frame"; |
| 260 | case DWC3_DEVICE_EVENT_SOF: |
| 261 | return "Start of Frame"; |
| 262 | case DWC3_DEVICE_EVENT_ERRATIC_ERROR: |
| 263 | return "Erratic Error"; |
| 264 | case DWC3_DEVICE_EVENT_CMD_CMPL: |
| 265 | return "Command Complete"; |
| 266 | case DWC3_DEVICE_EVENT_OVERFLOW: |
| 267 | return "Overflow"; |
| 268 | default: |
| 269 | return "UNKNOWN"; |
| 270 | } |
| 271 | } |
| 272 | |
Felipe Balbi | f75cacc | 2016-05-23 11:10:08 +0300 | [diff] [blame] | 273 | static inline const char *dwc3_decode_event(u32 event) |
| 274 | { |
| 275 | const union dwc3_event evt = (union dwc3_event) event; |
| 276 | |
| 277 | if (evt.type.is_devspec) |
| 278 | return dwc3_gadget_event_string(&evt.devt); |
| 279 | else |
| 280 | return dwc3_ep_event_string(&evt.depevt); |
| 281 | } |
| 282 | |
Felipe Balbi | 0933df1 | 2016-05-23 14:02:33 +0300 | [diff] [blame] | 283 | static inline const char *dwc3_ep_cmd_status_string(int status) |
| 284 | { |
| 285 | switch (status) { |
| 286 | case -ETIMEDOUT: |
| 287 | return "Timed Out"; |
| 288 | case 0: |
| 289 | return "Successful"; |
| 290 | case DEPEVT_TRANSFER_NO_RESOURCE: |
| 291 | return "No Resource"; |
| 292 | case DEPEVT_TRANSFER_BUS_EXPIRY: |
| 293 | return "Bus Expiry"; |
| 294 | default: |
| 295 | return "UNKNOWN"; |
| 296 | } |
| 297 | } |
| 298 | |
Felipe Balbi | 71f7e70 | 2016-05-23 14:16:19 +0300 | [diff] [blame^] | 299 | static inline const char *dwc3_gadget_generic_cmd_status_string(int status) |
| 300 | { |
| 301 | switch (status) { |
| 302 | case -ETIMEDOUT: |
| 303 | return "Timed Out"; |
| 304 | case 0: |
| 305 | return "Successful"; |
| 306 | case 1: |
| 307 | return "Error"; |
| 308 | default: |
| 309 | return "UNKNOWN"; |
| 310 | } |
| 311 | } |
| 312 | |
Felipe Balbi | 2c4cbe6e5 | 2014-04-30 17:45:10 -0500 | [diff] [blame] | 313 | void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...); |
| 314 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 315 | #ifdef CONFIG_DEBUG_FS |
Du, Changbin | 4e9f311 | 2016-04-12 19:10:18 +0800 | [diff] [blame] | 316 | extern void dwc3_debugfs_init(struct dwc3 *); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 317 | extern void dwc3_debugfs_exit(struct dwc3 *); |
| 318 | #else |
Du, Changbin | 4e9f311 | 2016-04-12 19:10:18 +0800 | [diff] [blame] | 319 | static inline void dwc3_debugfs_init(struct dwc3 *d) |
| 320 | { } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 321 | static inline void dwc3_debugfs_exit(struct dwc3 *d) |
| 322 | { } |
| 323 | #endif |
Felipe Balbi | 80977dc | 2014-08-19 16:37:22 -0500 | [diff] [blame] | 324 | #endif /* __DWC3_DEBUG_H */ |