debug.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
  122. {
  123. switch (state) {
  124. case EP0_UNCONNECTED:
  125. return "Unconnected";
  126. case EP0_SETUP_PHASE:
  127. return "Setup Phase";
  128. case EP0_DATA_PHASE:
  129. return "Data Phase";
  130. case EP0_STATUS_PHASE:
  131. return "Status Phase";
  132. default:
  133. return "UNKNOWN";
  134. }
  135. }
  136. /**
  137. * dwc3_gadget_event_string - returns event name
  138. * @event: the event code
  139. */
  140. static inline const char *
  141. dwc3_gadget_event_string(const struct dwc3_event_devt *event)
  142. {
  143. static char str[256];
  144. enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
  145. switch (event->type) {
  146. case DWC3_DEVICE_EVENT_DISCONNECT:
  147. sprintf(str, "Disconnect: [%s]",
  148. dwc3_gadget_link_string(state));
  149. break;
  150. case DWC3_DEVICE_EVENT_RESET:
  151. sprintf(str, "Reset [%s]", dwc3_gadget_link_string(state));
  152. break;
  153. case DWC3_DEVICE_EVENT_CONNECT_DONE:
  154. sprintf(str, "Connection Done [%s]",
  155. dwc3_gadget_link_string(state));
  156. break;
  157. case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
  158. sprintf(str, "Link Change [%s]",
  159. dwc3_gadget_link_string(state));
  160. break;
  161. case DWC3_DEVICE_EVENT_WAKEUP:
  162. sprintf(str, "WakeUp [%s]", dwc3_gadget_link_string(state));
  163. break;
  164. case DWC3_DEVICE_EVENT_EOPF:
  165. sprintf(str, "End-Of-Frame [%s]",
  166. dwc3_gadget_link_string(state));
  167. break;
  168. case DWC3_DEVICE_EVENT_SOF:
  169. sprintf(str, "Start-Of-Frame [%s]",
  170. dwc3_gadget_link_string(state));
  171. break;
  172. case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
  173. sprintf(str, "Erratic Error [%s]",
  174. dwc3_gadget_link_string(state));
  175. break;
  176. case DWC3_DEVICE_EVENT_CMD_CMPL:
  177. sprintf(str, "Command Complete [%s]",
  178. dwc3_gadget_link_string(state));
  179. break;
  180. case DWC3_DEVICE_EVENT_OVERFLOW:
  181. sprintf(str, "Overflow [%s]", dwc3_gadget_link_string(state));
  182. break;
  183. default:
  184. sprintf(str, "UNKNOWN");
  185. }
  186. return str;
  187. }
  188. /**
  189. * dwc3_ep_event_string - returns event name
  190. * @event: then event code
  191. */
  192. static inline const char *
  193. dwc3_ep_event_string(const struct dwc3_event_depevt *event, u32 ep0state)
  194. {
  195. u8 epnum = event->endpoint_number;
  196. static char str[256];
  197. size_t len;
  198. int status;
  199. int ret;
  200. ret = sprintf(str, "ep%d%s: ", epnum >> 1,
  201. (epnum & 1) ? "in" : "out");
  202. if (ret < 0)
  203. return "UNKNOWN";
  204. switch (event->endpoint_event) {
  205. case DWC3_DEPEVT_XFERCOMPLETE:
  206. strcat(str, "Transfer Complete");
  207. len = strlen(str);
  208. if (epnum <= 1)
  209. sprintf(str + len, " [%s]", dwc3_ep0_state_string(ep0state));
  210. break;
  211. case DWC3_DEPEVT_XFERINPROGRESS:
  212. strcat(str, "Transfer In-Progress");
  213. break;
  214. case DWC3_DEPEVT_XFERNOTREADY:
  215. strcat(str, "Transfer Not Ready");
  216. status = event->status & DEPEVT_STATUS_TRANSFER_ACTIVE;
  217. strcat(str, status ? " (Active)" : " (Not Active)");
  218. /* Control Endpoints */
  219. if (epnum <= 1) {
  220. int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
  221. switch (phase) {
  222. case DEPEVT_STATUS_CONTROL_DATA:
  223. strcat(str, " [Data Phase]");
  224. break;
  225. case DEPEVT_STATUS_CONTROL_STATUS:
  226. strcat(str, " [Status Phase]");
  227. }
  228. }
  229. break;
  230. case DWC3_DEPEVT_RXTXFIFOEVT:
  231. strcat(str, "FIFO");
  232. break;
  233. case DWC3_DEPEVT_STREAMEVT:
  234. status = event->status;
  235. switch (status) {
  236. case DEPEVT_STREAMEVT_FOUND:
  237. sprintf(str + ret, " Stream %d Found",
  238. event->parameters);
  239. break;
  240. case DEPEVT_STREAMEVT_NOTFOUND:
  241. default:
  242. strcat(str, " Stream Not Found");
  243. break;
  244. }
  245. break;
  246. case DWC3_DEPEVT_EPCMDCMPLT:
  247. strcat(str, "Endpoint Command Complete");
  248. break;
  249. default:
  250. sprintf(str, "UNKNOWN");
  251. }
  252. return str;
  253. }
  254. /**
  255. * dwc3_gadget_event_type_string - return event name
  256. * @event: the event code
  257. */
  258. static inline const char *dwc3_gadget_event_type_string(u8 event)
  259. {
  260. switch (event) {
  261. case DWC3_DEVICE_EVENT_DISCONNECT:
  262. return "Disconnect";
  263. case DWC3_DEVICE_EVENT_RESET:
  264. return "Reset";
  265. case DWC3_DEVICE_EVENT_CONNECT_DONE:
  266. return "Connect Done";
  267. case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
  268. return "Link Status Change";
  269. case DWC3_DEVICE_EVENT_WAKEUP:
  270. return "Wake-Up";
  271. case DWC3_DEVICE_EVENT_HIBER_REQ:
  272. return "Hibernation";
  273. case DWC3_DEVICE_EVENT_EOPF:
  274. return "End of Periodic Frame";
  275. case DWC3_DEVICE_EVENT_SOF:
  276. return "Start of Frame";
  277. case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
  278. return "Erratic Error";
  279. case DWC3_DEVICE_EVENT_CMD_CMPL:
  280. return "Command Complete";
  281. case DWC3_DEVICE_EVENT_OVERFLOW:
  282. return "Overflow";
  283. default:
  284. return "UNKNOWN";
  285. }
  286. }
  287. static inline const char *dwc3_decode_event(u32 event, u32 ep0state)
  288. {
  289. const union dwc3_event evt = (union dwc3_event) event;
  290. if (evt.type.is_devspec)
  291. return dwc3_gadget_event_string(&evt.devt);
  292. else
  293. return dwc3_ep_event_string(&evt.depevt, ep0state);
  294. }
  295. static inline const char *dwc3_ep_cmd_status_string(int status)
  296. {
  297. switch (status) {
  298. case -ETIMEDOUT:
  299. return "Timed Out";
  300. case 0:
  301. return "Successful";
  302. case DEPEVT_TRANSFER_NO_RESOURCE:
  303. return "No Resource";
  304. case DEPEVT_TRANSFER_BUS_EXPIRY:
  305. return "Bus Expiry";
  306. default:
  307. return "UNKNOWN";
  308. }
  309. }
  310. static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
  311. {
  312. switch (status) {
  313. case -ETIMEDOUT:
  314. return "Timed Out";
  315. case 0:
  316. return "Successful";
  317. case 1:
  318. return "Error";
  319. default:
  320. return "UNKNOWN";
  321. }
  322. }
  323. void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...);
  324. #ifdef CONFIG_DEBUG_FS
  325. extern void dwc3_debugfs_init(struct dwc3 *);
  326. extern void dwc3_debugfs_exit(struct dwc3 *);
  327. #else
  328. static inline void dwc3_debugfs_init(struct dwc3 *d)
  329. { }
  330. static inline void dwc3_debugfs_exit(struct dwc3 *d)
  331. { }
  332. #endif
  333. #endif /* __DWC3_DEBUG_H */