debug.h 7.9 KB

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