Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * debug.h - DesignWare USB3 DRD Controller Debug Header
0004  *
0005  * Copyright (C) 2010-2011 Texas Instruments Incorporated - https://www.ti.com
0006  *
0007  * Authors: Felipe Balbi <balbi@ti.com>,
0008  *      Sebastian Andrzej Siewior <bigeasy@linutronix.de>
0009  */
0010 
0011 #ifndef __DWC3_DEBUG_H
0012 #define __DWC3_DEBUG_H
0013 
0014 #include "core.h"
0015 
0016 /**
0017  * dwc3_gadget_ep_cmd_string - returns endpoint command string
0018  * @cmd: command code
0019  */
0020 static inline const char *
0021 dwc3_gadget_ep_cmd_string(u8 cmd)
0022 {
0023     switch (cmd) {
0024     case DWC3_DEPCMD_DEPSTARTCFG:
0025         return "Start New Configuration";
0026     case DWC3_DEPCMD_ENDTRANSFER:
0027         return "End Transfer";
0028     case DWC3_DEPCMD_UPDATETRANSFER:
0029         return "Update Transfer";
0030     case DWC3_DEPCMD_STARTTRANSFER:
0031         return "Start Transfer";
0032     case DWC3_DEPCMD_CLEARSTALL:
0033         return "Clear Stall";
0034     case DWC3_DEPCMD_SETSTALL:
0035         return "Set Stall";
0036     case DWC3_DEPCMD_GETEPSTATE:
0037         return "Get Endpoint State";
0038     case DWC3_DEPCMD_SETTRANSFRESOURCE:
0039         return "Set Endpoint Transfer Resource";
0040     case DWC3_DEPCMD_SETEPCONFIG:
0041         return "Set Endpoint Configuration";
0042     default:
0043         return "UNKNOWN command";
0044     }
0045 }
0046 
0047 /**
0048  * dwc3_gadget_generic_cmd_string - returns generic command string
0049  * @cmd: command code
0050  */
0051 static inline const char *
0052 dwc3_gadget_generic_cmd_string(u8 cmd)
0053 {
0054     switch (cmd) {
0055     case DWC3_DGCMD_SET_LMP:
0056         return "Set LMP";
0057     case DWC3_DGCMD_SET_PERIODIC_PAR:
0058         return "Set Periodic Parameters";
0059     case DWC3_DGCMD_XMIT_FUNCTION:
0060         return "Transmit Function Wake Device Notification";
0061     case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO:
0062         return "Set Scratchpad Buffer Array Address Lo";
0063     case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI:
0064         return "Set Scratchpad Buffer Array Address Hi";
0065     case DWC3_DGCMD_SELECTED_FIFO_FLUSH:
0066         return "Selected FIFO Flush";
0067     case DWC3_DGCMD_ALL_FIFO_FLUSH:
0068         return "All FIFO Flush";
0069     case DWC3_DGCMD_SET_ENDPOINT_NRDY:
0070         return "Set Endpoint NRDY";
0071     case DWC3_DGCMD_SET_ENDPOINT_PRIME:
0072         return "Set Endpoint Prime";
0073     case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK:
0074         return "Run SoC Bus Loopback Test";
0075     default:
0076         return "UNKNOWN";
0077     }
0078 }
0079 
0080 /**
0081  * dwc3_gadget_link_string - returns link name
0082  * @link_state: link state code
0083  */
0084 static inline const char *
0085 dwc3_gadget_link_string(enum dwc3_link_state link_state)
0086 {
0087     switch (link_state) {
0088     case DWC3_LINK_STATE_U0:
0089         return "U0";
0090     case DWC3_LINK_STATE_U1:
0091         return "U1";
0092     case DWC3_LINK_STATE_U2:
0093         return "U2";
0094     case DWC3_LINK_STATE_U3:
0095         return "U3";
0096     case DWC3_LINK_STATE_SS_DIS:
0097         return "SS.Disabled";
0098     case DWC3_LINK_STATE_RX_DET:
0099         return "RX.Detect";
0100     case DWC3_LINK_STATE_SS_INACT:
0101         return "SS.Inactive";
0102     case DWC3_LINK_STATE_POLL:
0103         return "Polling";
0104     case DWC3_LINK_STATE_RECOV:
0105         return "Recovery";
0106     case DWC3_LINK_STATE_HRESET:
0107         return "Hot Reset";
0108     case DWC3_LINK_STATE_CMPLY:
0109         return "Compliance";
0110     case DWC3_LINK_STATE_LPBK:
0111         return "Loopback";
0112     case DWC3_LINK_STATE_RESET:
0113         return "Reset";
0114     case DWC3_LINK_STATE_RESUME:
0115         return "Resume";
0116     default:
0117         return "UNKNOWN link state";
0118     }
0119 }
0120 
0121 /**
0122  * dwc3_gadget_hs_link_string - returns highspeed and below link name
0123  * @link_state: link state code
0124  */
0125 static inline const char *
0126 dwc3_gadget_hs_link_string(enum dwc3_link_state link_state)
0127 {
0128     switch (link_state) {
0129     case DWC3_LINK_STATE_U0:
0130         return "On";
0131     case DWC3_LINK_STATE_U2:
0132         return "Sleep";
0133     case DWC3_LINK_STATE_U3:
0134         return "Suspend";
0135     case DWC3_LINK_STATE_SS_DIS:
0136         return "Disconnected";
0137     case DWC3_LINK_STATE_RX_DET:
0138         return "Early Suspend";
0139     case DWC3_LINK_STATE_RECOV:
0140         return "Recovery";
0141     case DWC3_LINK_STATE_RESET:
0142         return "Reset";
0143     case DWC3_LINK_STATE_RESUME:
0144         return "Resume";
0145     default:
0146         return "UNKNOWN link state";
0147     }
0148 }
0149 
0150 /**
0151  * dwc3_trb_type_string - returns TRB type as a string
0152  * @type: the type of the TRB
0153  */
0154 static inline const char *dwc3_trb_type_string(unsigned int type)
0155 {
0156     switch (type) {
0157     case DWC3_TRBCTL_NORMAL:
0158         return "normal";
0159     case DWC3_TRBCTL_CONTROL_SETUP:
0160         return "setup";
0161     case DWC3_TRBCTL_CONTROL_STATUS2:
0162         return "status2";
0163     case DWC3_TRBCTL_CONTROL_STATUS3:
0164         return "status3";
0165     case DWC3_TRBCTL_CONTROL_DATA:
0166         return "data";
0167     case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
0168         return "isoc-first";
0169     case DWC3_TRBCTL_ISOCHRONOUS:
0170         return "isoc";
0171     case DWC3_TRBCTL_LINK_TRB:
0172         return "link";
0173     default:
0174         return "UNKNOWN";
0175     }
0176 }
0177 
0178 static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
0179 {
0180     switch (state) {
0181     case EP0_UNCONNECTED:
0182         return "Unconnected";
0183     case EP0_SETUP_PHASE:
0184         return "Setup Phase";
0185     case EP0_DATA_PHASE:
0186         return "Data Phase";
0187     case EP0_STATUS_PHASE:
0188         return "Status Phase";
0189     default:
0190         return "UNKNOWN";
0191     }
0192 }
0193 
0194 /**
0195  * dwc3_gadget_event_string - returns event name
0196  * @event: the event code
0197  */
0198 static inline const char *dwc3_gadget_event_string(char *str, size_t size,
0199         const struct dwc3_event_devt *event)
0200 {
0201     enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
0202 
0203     switch (event->type) {
0204     case DWC3_DEVICE_EVENT_DISCONNECT:
0205         snprintf(str, size, "Disconnect: [%s]",
0206                 dwc3_gadget_link_string(state));
0207         break;
0208     case DWC3_DEVICE_EVENT_RESET:
0209         snprintf(str, size, "Reset [%s]",
0210                 dwc3_gadget_link_string(state));
0211         break;
0212     case DWC3_DEVICE_EVENT_CONNECT_DONE:
0213         snprintf(str, size, "Connection Done [%s]",
0214                 dwc3_gadget_link_string(state));
0215         break;
0216     case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
0217         snprintf(str, size, "Link Change [%s]",
0218                 dwc3_gadget_link_string(state));
0219         break;
0220     case DWC3_DEVICE_EVENT_WAKEUP:
0221         snprintf(str, size, "WakeUp [%s]",
0222                 dwc3_gadget_link_string(state));
0223         break;
0224     case DWC3_DEVICE_EVENT_SUSPEND:
0225         snprintf(str, size, "Suspend [%s]",
0226                 dwc3_gadget_link_string(state));
0227         break;
0228     case DWC3_DEVICE_EVENT_SOF:
0229         snprintf(str, size, "Start-Of-Frame [%s]",
0230                 dwc3_gadget_link_string(state));
0231         break;
0232     case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
0233         snprintf(str, size, "Erratic Error [%s]",
0234                 dwc3_gadget_link_string(state));
0235         break;
0236     case DWC3_DEVICE_EVENT_CMD_CMPL:
0237         snprintf(str, size, "Command Complete [%s]",
0238                 dwc3_gadget_link_string(state));
0239         break;
0240     case DWC3_DEVICE_EVENT_OVERFLOW:
0241         snprintf(str, size, "Overflow [%s]",
0242                 dwc3_gadget_link_string(state));
0243         break;
0244     default:
0245         snprintf(str, size, "UNKNOWN");
0246     }
0247 
0248     return str;
0249 }
0250 
0251 /**
0252  * dwc3_ep_event_string - returns event name
0253  * @event: then event code
0254  */
0255 static inline const char *dwc3_ep_event_string(char *str, size_t size,
0256         const struct dwc3_event_depevt *event, u32 ep0state)
0257 {
0258     u8 epnum = event->endpoint_number;
0259     size_t len;
0260     int status;
0261 
0262     len = scnprintf(str, size, "ep%d%s: ", epnum >> 1,
0263             (epnum & 1) ? "in" : "out");
0264 
0265     status = event->status;
0266 
0267     switch (event->endpoint_event) {
0268     case DWC3_DEPEVT_XFERCOMPLETE:
0269         len += scnprintf(str + len, size - len,
0270                 "Transfer Complete (%c%c%c)",
0271                 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
0272                 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
0273                 status & DEPEVT_STATUS_LST ? 'L' : 'l');
0274 
0275         if (epnum <= 1)
0276             scnprintf(str + len, size - len, " [%s]",
0277                     dwc3_ep0_state_string(ep0state));
0278         break;
0279     case DWC3_DEPEVT_XFERINPROGRESS:
0280         scnprintf(str + len, size - len,
0281                 "Transfer In Progress [%d] (%c%c%c)",
0282                 event->parameters,
0283                 status & DEPEVT_STATUS_SHORT ? 'S' : 's',
0284                 status & DEPEVT_STATUS_IOC ? 'I' : 'i',
0285                 status & DEPEVT_STATUS_LST ? 'M' : 'm');
0286         break;
0287     case DWC3_DEPEVT_XFERNOTREADY:
0288         len += scnprintf(str + len, size - len,
0289                 "Transfer Not Ready [%d]%s",
0290                 event->parameters,
0291                 status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
0292                 " (Active)" : " (Not Active)");
0293 
0294         /* Control Endpoints */
0295         if (epnum <= 1) {
0296             int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
0297 
0298             switch (phase) {
0299             case DEPEVT_STATUS_CONTROL_DATA:
0300                 scnprintf(str + len, size - len,
0301                         " [Data Phase]");
0302                 break;
0303             case DEPEVT_STATUS_CONTROL_STATUS:
0304                 scnprintf(str + len, size - len,
0305                         " [Status Phase]");
0306             }
0307         }
0308         break;
0309     case DWC3_DEPEVT_RXTXFIFOEVT:
0310         scnprintf(str + len, size - len, "FIFO");
0311         break;
0312     case DWC3_DEPEVT_STREAMEVT:
0313         status = event->status;
0314 
0315         switch (status) {
0316         case DEPEVT_STREAMEVT_FOUND:
0317             scnprintf(str + len, size - len, " Stream %d Found",
0318                     event->parameters);
0319             break;
0320         case DEPEVT_STREAMEVT_NOTFOUND:
0321         default:
0322             scnprintf(str + len, size - len, " Stream Not Found");
0323             break;
0324         }
0325 
0326         break;
0327     case DWC3_DEPEVT_EPCMDCMPLT:
0328         scnprintf(str + len, size - len, "Endpoint Command Complete");
0329         break;
0330     default:
0331         scnprintf(str + len, size - len, "UNKNOWN");
0332     }
0333 
0334     return str;
0335 }
0336 
0337 /**
0338  * dwc3_gadget_event_type_string - return event name
0339  * @event: the event code
0340  */
0341 static inline const char *dwc3_gadget_event_type_string(u8 event)
0342 {
0343     switch (event) {
0344     case DWC3_DEVICE_EVENT_DISCONNECT:
0345         return "Disconnect";
0346     case DWC3_DEVICE_EVENT_RESET:
0347         return "Reset";
0348     case DWC3_DEVICE_EVENT_CONNECT_DONE:
0349         return "Connect Done";
0350     case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
0351         return "Link Status Change";
0352     case DWC3_DEVICE_EVENT_WAKEUP:
0353         return "Wake-Up";
0354     case DWC3_DEVICE_EVENT_HIBER_REQ:
0355         return "Hibernation";
0356     case DWC3_DEVICE_EVENT_SUSPEND:
0357         return "Suspend";
0358     case DWC3_DEVICE_EVENT_SOF:
0359         return "Start of Frame";
0360     case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
0361         return "Erratic Error";
0362     case DWC3_DEVICE_EVENT_CMD_CMPL:
0363         return "Command Complete";
0364     case DWC3_DEVICE_EVENT_OVERFLOW:
0365         return "Overflow";
0366     default:
0367         return "UNKNOWN";
0368     }
0369 }
0370 
0371 static inline const char *dwc3_decode_event(char *str, size_t size, u32 event,
0372         u32 ep0state)
0373 {
0374     union dwc3_event evt;
0375 
0376     memcpy(&evt, &event, sizeof(event));
0377 
0378     if (evt.type.is_devspec)
0379         return dwc3_gadget_event_string(str, size, &evt.devt);
0380     else
0381         return dwc3_ep_event_string(str, size, &evt.depevt, ep0state);
0382 }
0383 
0384 static inline const char *dwc3_ep_cmd_status_string(int status)
0385 {
0386     switch (status) {
0387     case -ETIMEDOUT:
0388         return "Timed Out";
0389     case 0:
0390         return "Successful";
0391     case DEPEVT_TRANSFER_NO_RESOURCE:
0392         return "No Resource";
0393     case DEPEVT_TRANSFER_BUS_EXPIRY:
0394         return "Bus Expiry";
0395     default:
0396         return "UNKNOWN";
0397     }
0398 }
0399 
0400 static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
0401 {
0402     switch (status) {
0403     case -ETIMEDOUT:
0404         return "Timed Out";
0405     case 0:
0406         return "Successful";
0407     case 1:
0408         return "Error";
0409     default:
0410         return "UNKNOWN";
0411     }
0412 }
0413 
0414 
0415 #ifdef CONFIG_DEBUG_FS
0416 extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep);
0417 extern void dwc3_debugfs_init(struct dwc3 *d);
0418 extern void dwc3_debugfs_exit(struct dwc3 *d);
0419 #else
0420 static inline void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
0421 {  }
0422 static inline void dwc3_debugfs_init(struct dwc3 *d)
0423 {  }
0424 static inline void dwc3_debugfs_exit(struct dwc3 *d)
0425 {  }
0426 #endif
0427 #endif /* __DWC3_DEBUG_H */