debug.h 9.2 KB

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