debug.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * debug.h - DesignWare USB3 DRD Controller Debug Header
  4. *
  5. * Copyright (C) 2010-2011 Texas Instruments Incorporated - https://www.ti.com
  6. *
  7. * Authors: Felipe Balbi <[email protected]>,
  8. * Sebastian Andrzej Siewior <[email protected]>
  9. */
  10. #ifndef __DWC3_DEBUG_H
  11. #define __DWC3_DEBUG_H
  12. #include "core.h"
  13. /**
  14. * dwc3_gadget_ep_cmd_string - returns endpoint command string
  15. * @cmd: command code
  16. */
  17. static inline const char *
  18. dwc3_gadget_ep_cmd_string(u8 cmd)
  19. {
  20. switch (cmd) {
  21. case DWC3_DEPCMD_DEPSTARTCFG:
  22. return "Start New Configuration";
  23. case DWC3_DEPCMD_ENDTRANSFER:
  24. return "End Transfer";
  25. case DWC3_DEPCMD_UPDATETRANSFER:
  26. return "Update Transfer";
  27. case DWC3_DEPCMD_STARTTRANSFER:
  28. return "Start Transfer";
  29. case DWC3_DEPCMD_CLEARSTALL:
  30. return "Clear Stall";
  31. case DWC3_DEPCMD_SETSTALL:
  32. return "Set Stall";
  33. case DWC3_DEPCMD_GETEPSTATE:
  34. return "Get Endpoint State";
  35. case DWC3_DEPCMD_SETTRANSFRESOURCE:
  36. return "Set Endpoint Transfer Resource";
  37. case DWC3_DEPCMD_SETEPCONFIG:
  38. return "Set Endpoint Configuration";
  39. default:
  40. return "UNKNOWN command";
  41. }
  42. }
  43. /**
  44. * dwc3_gadget_generic_cmd_string - returns generic command string
  45. * @cmd: command code
  46. */
  47. static inline const char *
  48. dwc3_gadget_generic_cmd_string(u8 cmd)
  49. {
  50. switch (cmd) {
  51. case DWC3_DGCMD_SET_LMP:
  52. return "Set LMP";
  53. case DWC3_DGCMD_SET_PERIODIC_PAR:
  54. return "Set Periodic Parameters";
  55. case DWC3_DGCMD_XMIT_FUNCTION:
  56. return "Transmit Function Wake Device Notification";
  57. case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO:
  58. return "Set Scratchpad Buffer Array Address Lo";
  59. case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI:
  60. return "Set Scratchpad Buffer Array Address Hi";
  61. case DWC3_DGCMD_SELECTED_FIFO_FLUSH:
  62. return "Selected FIFO Flush";
  63. case DWC3_DGCMD_ALL_FIFO_FLUSH:
  64. return "All FIFO Flush";
  65. case DWC3_DGCMD_SET_ENDPOINT_NRDY:
  66. return "Set Endpoint NRDY";
  67. case DWC3_DGCMD_SET_ENDPOINT_PRIME:
  68. return "Set Endpoint Prime";
  69. case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK:
  70. return "Run SoC Bus Loopback Test";
  71. default:
  72. return "UNKNOWN";
  73. }
  74. }
  75. /**
  76. * dwc3_gadget_link_string - returns link name
  77. * @link_state: link state code
  78. */
  79. static inline const char *
  80. dwc3_gadget_link_string(enum dwc3_link_state link_state)
  81. {
  82. switch (link_state) {
  83. case DWC3_LINK_STATE_U0:
  84. return "U0";
  85. case DWC3_LINK_STATE_U1:
  86. return "U1";
  87. case DWC3_LINK_STATE_U2:
  88. return "U2";
  89. case DWC3_LINK_STATE_U3:
  90. return "U3";
  91. case DWC3_LINK_STATE_SS_DIS:
  92. return "SS.Disabled";
  93. case DWC3_LINK_STATE_RX_DET:
  94. return "RX.Detect";
  95. case DWC3_LINK_STATE_SS_INACT:
  96. return "SS.Inactive";
  97. case DWC3_LINK_STATE_POLL:
  98. return "Polling";
  99. case DWC3_LINK_STATE_RECOV:
  100. return "Recovery";
  101. case DWC3_LINK_STATE_HRESET:
  102. return "Hot Reset";
  103. case DWC3_LINK_STATE_CMPLY:
  104. return "Compliance";
  105. case DWC3_LINK_STATE_LPBK:
  106. return "Loopback";
  107. case DWC3_LINK_STATE_RESET:
  108. return "Reset";
  109. case DWC3_LINK_STATE_RESUME:
  110. return "Resume";
  111. default:
  112. return "UNKNOWN link state";
  113. }
  114. }
  115. /**
  116. * dwc3_gadget_hs_link_string - returns highspeed and below link name
  117. * @link_state: link state code
  118. */
  119. static inline const char *
  120. dwc3_gadget_hs_link_string(enum dwc3_link_state link_state)
  121. {
  122. switch (link_state) {
  123. case DWC3_LINK_STATE_U0:
  124. return "On";
  125. case DWC3_LINK_STATE_U2:
  126. return "Sleep";
  127. case DWC3_LINK_STATE_U3:
  128. return "Suspend";
  129. case DWC3_LINK_STATE_SS_DIS:
  130. return "Disconnected";
  131. case DWC3_LINK_STATE_RX_DET:
  132. return "Early Suspend";
  133. case DWC3_LINK_STATE_RECOV:
  134. return "Recovery";
  135. case DWC3_LINK_STATE_RESET:
  136. return "Reset";
  137. case DWC3_LINK_STATE_RESUME:
  138. return "Resume";
  139. default:
  140. return "UNKNOWN link state";
  141. }
  142. }
  143. /**
  144. * dwc3_trb_type_string - returns TRB type as a string
  145. * @type: the type of the TRB
  146. */
  147. static inline const char *dwc3_trb_type_string(unsigned int type)
  148. {
  149. switch (type) {
  150. case DWC3_TRBCTL_NORMAL:
  151. return "normal";
  152. case DWC3_TRBCTL_CONTROL_SETUP:
  153. return "setup";
  154. case DWC3_TRBCTL_CONTROL_STATUS2:
  155. return "status2";
  156. case DWC3_TRBCTL_CONTROL_STATUS3:
  157. return "status3";
  158. case DWC3_TRBCTL_CONTROL_DATA:
  159. return "data";
  160. case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
  161. return "isoc-first";
  162. case DWC3_TRBCTL_ISOCHRONOUS:
  163. return "isoc";
  164. case DWC3_TRBCTL_LINK_TRB:
  165. return "link";
  166. default:
  167. return "UNKNOWN";
  168. }
  169. }
  170. static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
  171. {
  172. switch (state) {
  173. case EP0_UNCONNECTED:
  174. return "Unconnected";
  175. case EP0_SETUP_PHASE:
  176. return "Setup Phase";
  177. case EP0_DATA_PHASE:
  178. return "Data Phase";
  179. case EP0_STATUS_PHASE:
  180. return "Status Phase";
  181. default:
  182. return "UNKNOWN";
  183. }
  184. }
  185. /**
  186. * dwc3_gadget_event_string - returns event name
  187. * @event: the event code
  188. */
  189. static inline const char *dwc3_gadget_event_string(char *str, size_t size,
  190. const struct dwc3_event_devt *event)
  191. {
  192. enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
  193. switch (event->type) {
  194. case DWC3_DEVICE_EVENT_DISCONNECT:
  195. snprintf(str, size, "Disconnect: [%s]",
  196. dwc3_gadget_link_string(state));
  197. break;
  198. case DWC3_DEVICE_EVENT_RESET:
  199. snprintf(str, size, "Reset [%s]",
  200. dwc3_gadget_link_string(state));
  201. break;
  202. case DWC3_DEVICE_EVENT_CONNECT_DONE:
  203. snprintf(str, size, "Connection Done [%s]",
  204. dwc3_gadget_link_string(state));
  205. break;
  206. case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
  207. snprintf(str, size, "Link Change [%s]",
  208. dwc3_gadget_link_string(state));
  209. break;
  210. case DWC3_DEVICE_EVENT_WAKEUP:
  211. snprintf(str, size, "WakeUp [%s]",
  212. dwc3_gadget_link_string(state));
  213. break;
  214. case DWC3_DEVICE_EVENT_SUSPEND:
  215. snprintf(str, size, "Suspend [%s]",
  216. dwc3_gadget_link_string(state));
  217. break;
  218. case DWC3_DEVICE_EVENT_SOF:
  219. snprintf(str, size, "Start-Of-Frame [%s]",
  220. dwc3_gadget_link_string(state));
  221. break;
  222. case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
  223. snprintf(str, size, "Erratic Error [%s]",
  224. dwc3_gadget_link_string(state));
  225. break;
  226. case DWC3_DEVICE_EVENT_CMD_CMPL:
  227. snprintf(str, size, "Command Complete [%s]",
  228. dwc3_gadget_link_string(state));
  229. break;
  230. case DWC3_DEVICE_EVENT_OVERFLOW:
  231. snprintf(str, size, "Overflow [%s]",
  232. dwc3_gadget_link_string(state));
  233. break;
  234. default:
  235. snprintf(str, size, "UNKNOWN");
  236. }
  237. return str;
  238. }
  239. /**
  240. * dwc3_ep_event_string - returns event name
  241. * @event: then event code
  242. */
  243. static inline const char *dwc3_ep_event_string(char *str, size_t size,
  244. const struct dwc3_event_depevt *event, u32 ep0state)
  245. {
  246. u8 epnum = event->endpoint_number;
  247. size_t len;
  248. int status;
  249. len = scnprintf(str, size, "ep%d%s: ", epnum >> 1,
  250. (epnum & 1) ? "in" : "out");
  251. status = event->status;
  252. switch (event->endpoint_event) {
  253. case DWC3_DEPEVT_XFERCOMPLETE:
  254. len += scnprintf(str + len, size - len,
  255. "Transfer Complete (%c%c%c)",
  256. status & DEPEVT_STATUS_SHORT ? 'S' : 's',
  257. status & DEPEVT_STATUS_IOC ? 'I' : 'i',
  258. status & DEPEVT_STATUS_LST ? 'L' : 'l');
  259. if (epnum <= 1)
  260. scnprintf(str + len, size - len, " [%s]",
  261. dwc3_ep0_state_string(ep0state));
  262. break;
  263. case DWC3_DEPEVT_XFERINPROGRESS:
  264. scnprintf(str + len, size - len,
  265. "Transfer In Progress [%08x] (%c%c%c)",
  266. event->parameters,
  267. status & DEPEVT_STATUS_SHORT ? 'S' : 's',
  268. status & DEPEVT_STATUS_IOC ? 'I' : 'i',
  269. status & DEPEVT_STATUS_LST ? 'M' : 'm');
  270. break;
  271. case DWC3_DEPEVT_XFERNOTREADY:
  272. len += scnprintf(str + len, size - len,
  273. "Transfer Not Ready [%08x]%s",
  274. event->parameters,
  275. status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
  276. " (Active)" : " (Not Active)");
  277. /* Control Endpoints */
  278. if (epnum <= 1) {
  279. int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
  280. switch (phase) {
  281. case DEPEVT_STATUS_CONTROL_DATA:
  282. scnprintf(str + len, size - len,
  283. " [Data Phase]");
  284. break;
  285. case DEPEVT_STATUS_CONTROL_STATUS:
  286. scnprintf(str + len, size - len,
  287. " [Status Phase]");
  288. }
  289. }
  290. break;
  291. case DWC3_DEPEVT_RXTXFIFOEVT:
  292. scnprintf(str + len, size - len, "FIFO");
  293. break;
  294. case DWC3_DEPEVT_STREAMEVT:
  295. status = event->status;
  296. switch (status) {
  297. case DEPEVT_STREAMEVT_FOUND:
  298. scnprintf(str + len, size - len, " Stream %d Found",
  299. event->parameters);
  300. break;
  301. case DEPEVT_STREAMEVT_NOTFOUND:
  302. default:
  303. scnprintf(str + len, size - len, " Stream Not Found");
  304. break;
  305. }
  306. break;
  307. case DWC3_DEPEVT_EPCMDCMPLT:
  308. scnprintf(str + len, size - len, "Endpoint Command Complete");
  309. break;
  310. default:
  311. scnprintf(str + len, size - len, "UNKNOWN");
  312. }
  313. return str;
  314. }
  315. /**
  316. * dwc3_gadget_event_type_string - return event name
  317. * @event: the event code
  318. */
  319. static inline const char *dwc3_gadget_event_type_string(u8 event)
  320. {
  321. switch (event) {
  322. case DWC3_DEVICE_EVENT_DISCONNECT:
  323. return "Disconnect";
  324. case DWC3_DEVICE_EVENT_RESET:
  325. return "Reset";
  326. case DWC3_DEVICE_EVENT_CONNECT_DONE:
  327. return "Connect Done";
  328. case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
  329. return "Link Status Change";
  330. case DWC3_DEVICE_EVENT_WAKEUP:
  331. return "Wake-Up";
  332. case DWC3_DEVICE_EVENT_HIBER_REQ:
  333. return "Hibernation";
  334. case DWC3_DEVICE_EVENT_SUSPEND:
  335. return "Suspend";
  336. case DWC3_DEVICE_EVENT_SOF:
  337. return "Start of Frame";
  338. case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
  339. return "Erratic Error";
  340. case DWC3_DEVICE_EVENT_CMD_CMPL:
  341. return "Command Complete";
  342. case DWC3_DEVICE_EVENT_OVERFLOW:
  343. return "Overflow";
  344. default:
  345. return "UNKNOWN";
  346. }
  347. }
  348. static inline const char *dwc3_decode_event(char *str, size_t size, u32 event,
  349. u32 ep0state)
  350. {
  351. union dwc3_event evt;
  352. memcpy(&evt, &event, sizeof(event));
  353. if (evt.type.is_devspec)
  354. return dwc3_gadget_event_string(str, size, &evt.devt);
  355. else
  356. return dwc3_ep_event_string(str, size, &evt.depevt, ep0state);
  357. }
  358. static inline const char *dwc3_ep_cmd_status_string(int status)
  359. {
  360. switch (status) {
  361. case -ETIMEDOUT:
  362. return "Timed Out";
  363. case 0:
  364. return "Successful";
  365. case DEPEVT_TRANSFER_NO_RESOURCE:
  366. return "No Resource";
  367. case DEPEVT_TRANSFER_BUS_EXPIRY:
  368. return "Bus Expiry";
  369. default:
  370. return "UNKNOWN";
  371. }
  372. }
  373. static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
  374. {
  375. switch (status) {
  376. case -ETIMEDOUT:
  377. return "Timed Out";
  378. case 0:
  379. return "Successful";
  380. case 1:
  381. return "Error";
  382. default:
  383. return "UNKNOWN";
  384. }
  385. }
  386. #ifdef CONFIG_DEBUG_FS
  387. extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep);
  388. extern void dwc3_debugfs_remove_endpoint_dir(struct dwc3_ep *dep);
  389. extern void dwc3_debugfs_init(struct dwc3 *d);
  390. extern void dwc3_debugfs_exit(struct dwc3 *d);
  391. #else
  392. static inline void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
  393. { }
  394. static inline void dwc3_debugfs_remove_endpoint_dir(struct dwc3_ep *dep)
  395. { }
  396. static inline void dwc3_debugfs_init(struct dwc3 *d)
  397. { }
  398. static inline void dwc3_debugfs_exit(struct dwc3 *d)
  399. { }
  400. #endif
  401. #endif /* __DWC3_DEBUG_H */