debug.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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 <balbi@ti.com>,
  8. * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  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. case DWC3_DGCMD_DEV_NOTIFICATION:
  72. return "Device Notification";
  73. default:
  74. return "UNKNOWN";
  75. }
  76. }
  77. /**
  78. * dwc3_gadget_link_string - returns link name
  79. * @link_state: link state code
  80. */
  81. static inline const char *
  82. dwc3_gadget_link_string(enum dwc3_link_state link_state)
  83. {
  84. switch (link_state) {
  85. case DWC3_LINK_STATE_U0:
  86. return "U0";
  87. case DWC3_LINK_STATE_U1:
  88. return "U1";
  89. case DWC3_LINK_STATE_U2:
  90. return "U2";
  91. case DWC3_LINK_STATE_U3:
  92. return "U3";
  93. case DWC3_LINK_STATE_SS_DIS:
  94. return "SS.Disabled";
  95. case DWC3_LINK_STATE_RX_DET:
  96. return "RX.Detect";
  97. case DWC3_LINK_STATE_SS_INACT:
  98. return "SS.Inactive";
  99. case DWC3_LINK_STATE_POLL:
  100. return "Polling";
  101. case DWC3_LINK_STATE_RECOV:
  102. return "Recovery";
  103. case DWC3_LINK_STATE_HRESET:
  104. return "Hot Reset";
  105. case DWC3_LINK_STATE_CMPLY:
  106. return "Compliance";
  107. case DWC3_LINK_STATE_LPBK:
  108. return "Loopback";
  109. case DWC3_LINK_STATE_RESET:
  110. return "Reset";
  111. case DWC3_LINK_STATE_RESUME:
  112. return "Resume";
  113. default:
  114. return "UNKNOWN link state";
  115. }
  116. }
  117. /**
  118. * dwc3_gadget_hs_link_string - returns highspeed and below link name
  119. * @link_state: link state code
  120. */
  121. static inline const char *
  122. dwc3_gadget_hs_link_string(enum dwc3_link_state link_state)
  123. {
  124. switch (link_state) {
  125. case DWC3_LINK_STATE_U0:
  126. return "On";
  127. case DWC3_LINK_STATE_U2:
  128. return "Sleep";
  129. case DWC3_LINK_STATE_U3:
  130. return "Suspend";
  131. case DWC3_LINK_STATE_SS_DIS:
  132. return "Disconnected";
  133. case DWC3_LINK_STATE_RX_DET:
  134. return "Early Suspend";
  135. case DWC3_LINK_STATE_RECOV:
  136. return "Recovery";
  137. case DWC3_LINK_STATE_RESET:
  138. return "Reset";
  139. case DWC3_LINK_STATE_RESUME:
  140. return "Resume";
  141. default:
  142. return "UNKNOWN link state";
  143. }
  144. }
  145. /**
  146. * dwc3_trb_type_string - returns TRB type as a string
  147. * @type: the type of the TRB
  148. */
  149. static inline const char *dwc3_trb_type_string(unsigned int type)
  150. {
  151. switch (type) {
  152. case DWC3_TRBCTL_NORMAL:
  153. return "normal";
  154. case DWC3_TRBCTL_CONTROL_SETUP:
  155. return "setup";
  156. case DWC3_TRBCTL_CONTROL_STATUS2:
  157. return "status2";
  158. case DWC3_TRBCTL_CONTROL_STATUS3:
  159. return "status3";
  160. case DWC3_TRBCTL_CONTROL_DATA:
  161. return "data";
  162. case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
  163. return "isoc-first";
  164. case DWC3_TRBCTL_ISOCHRONOUS:
  165. return "isoc";
  166. case DWC3_TRBCTL_LINK_TRB:
  167. return "link";
  168. default:
  169. return "UNKNOWN";
  170. }
  171. }
  172. static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
  173. {
  174. switch (state) {
  175. case EP0_UNCONNECTED:
  176. return "Unconnected";
  177. case EP0_SETUP_PHASE:
  178. return "Setup Phase";
  179. case EP0_DATA_PHASE:
  180. return "Data Phase";
  181. case EP0_STATUS_PHASE:
  182. return "Status Phase";
  183. default:
  184. return "UNKNOWN";
  185. }
  186. }
  187. /**
  188. * dwc3_gadget_event_string - returns event name
  189. * @event: the event code
  190. */
  191. static inline const char *dwc3_gadget_event_string(char *str, size_t size,
  192. const struct dwc3_event_devt *event)
  193. {
  194. enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
  195. switch (event->type) {
  196. case DWC3_DEVICE_EVENT_DISCONNECT:
  197. snprintf(str, size, "Disconnect: [%s]",
  198. dwc3_gadget_link_string(state));
  199. break;
  200. case DWC3_DEVICE_EVENT_RESET:
  201. snprintf(str, size, "Reset [%s]",
  202. dwc3_gadget_link_string(state));
  203. break;
  204. case DWC3_DEVICE_EVENT_CONNECT_DONE:
  205. snprintf(str, size, "Connection Done [%s]",
  206. dwc3_gadget_link_string(state));
  207. break;
  208. case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
  209. snprintf(str, size, "Link Change [%s]",
  210. dwc3_gadget_link_string(state));
  211. break;
  212. case DWC3_DEVICE_EVENT_WAKEUP:
  213. snprintf(str, size, "WakeUp [%s]",
  214. dwc3_gadget_link_string(state));
  215. break;
  216. case DWC3_DEVICE_EVENT_SUSPEND:
  217. snprintf(str, size, "Suspend [%s]",
  218. dwc3_gadget_link_string(state));
  219. break;
  220. case DWC3_DEVICE_EVENT_SOF:
  221. snprintf(str, size, "Start-Of-Frame [%s]",
  222. dwc3_gadget_link_string(state));
  223. break;
  224. case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
  225. snprintf(str, size, "Erratic Error [%s]",
  226. dwc3_gadget_link_string(state));
  227. break;
  228. case DWC3_DEVICE_EVENT_CMD_CMPL:
  229. snprintf(str, size, "Command Complete [%s]",
  230. dwc3_gadget_link_string(state));
  231. break;
  232. case DWC3_DEVICE_EVENT_OVERFLOW:
  233. snprintf(str, size, "Overflow [%s]",
  234. dwc3_gadget_link_string(state));
  235. break;
  236. default:
  237. snprintf(str, size, "UNKNOWN");
  238. }
  239. return str;
  240. }
  241. /**
  242. * dwc3_ep_event_string - returns event name
  243. * @event: then event code
  244. */
  245. static inline const char *dwc3_ep_event_string(char *str, size_t size,
  246. const struct dwc3_event_depevt *event, u32 ep0state)
  247. {
  248. u8 epnum = event->endpoint_number;
  249. size_t len;
  250. int status;
  251. len = scnprintf(str, size, "ep%d%s: ", epnum >> 1,
  252. (epnum & 1) ? "in" : "out");
  253. status = event->status;
  254. switch (event->endpoint_event) {
  255. case DWC3_DEPEVT_XFERCOMPLETE:
  256. len += scnprintf(str + len, size - len,
  257. "Transfer Complete (%c%c%c)",
  258. status & DEPEVT_STATUS_SHORT ? 'S' : 's',
  259. status & DEPEVT_STATUS_IOC ? 'I' : 'i',
  260. status & DEPEVT_STATUS_LST ? 'L' : 'l');
  261. if (epnum <= 1)
  262. scnprintf(str + len, size - len, " [%s]",
  263. dwc3_ep0_state_string(ep0state));
  264. break;
  265. case DWC3_DEPEVT_XFERINPROGRESS:
  266. scnprintf(str + len, size - len,
  267. "Transfer In Progress [%08x] (%c%c%c)",
  268. event->parameters,
  269. status & DEPEVT_STATUS_SHORT ? 'S' : 's',
  270. status & DEPEVT_STATUS_IOC ? 'I' : 'i',
  271. status & DEPEVT_STATUS_LST ? 'M' : 'm');
  272. break;
  273. case DWC3_DEPEVT_XFERNOTREADY:
  274. len += scnprintf(str + len, size - len,
  275. "Transfer Not Ready [%08x]%s",
  276. event->parameters,
  277. status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
  278. " (Active)" : " (Not Active)");
  279. /* Control Endpoints */
  280. if (epnum <= 1) {
  281. int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
  282. switch (phase) {
  283. case DEPEVT_STATUS_CONTROL_DATA:
  284. scnprintf(str + len, size - len,
  285. " [Data Phase]");
  286. break;
  287. case DEPEVT_STATUS_CONTROL_STATUS:
  288. scnprintf(str + len, size - len,
  289. " [Status Phase]");
  290. }
  291. }
  292. break;
  293. case DWC3_DEPEVT_RXTXFIFOEVT:
  294. scnprintf(str + len, size - len, "FIFO");
  295. break;
  296. case DWC3_DEPEVT_STREAMEVT:
  297. status = event->status;
  298. switch (status) {
  299. case DEPEVT_STREAMEVT_FOUND:
  300. scnprintf(str + len, size - len, " Stream %d Found",
  301. event->parameters);
  302. break;
  303. case DEPEVT_STREAMEVT_NOTFOUND:
  304. default:
  305. scnprintf(str + len, size - len, " Stream Not Found");
  306. break;
  307. }
  308. break;
  309. case DWC3_DEPEVT_EPCMDCMPLT:
  310. scnprintf(str + len, size - len, "Endpoint Command Complete");
  311. break;
  312. default:
  313. scnprintf(str + len, size - len, "UNKNOWN");
  314. }
  315. return str;
  316. }
  317. /**
  318. * dwc3_gadget_event_type_string - return event name
  319. * @event: the event code
  320. */
  321. static inline const char *dwc3_gadget_event_type_string(u8 event)
  322. {
  323. switch (event) {
  324. case DWC3_DEVICE_EVENT_DISCONNECT:
  325. return "Disconnect";
  326. case DWC3_DEVICE_EVENT_RESET:
  327. return "Reset";
  328. case DWC3_DEVICE_EVENT_CONNECT_DONE:
  329. return "Connect Done";
  330. case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
  331. return "Link Status Change";
  332. case DWC3_DEVICE_EVENT_WAKEUP:
  333. return "Wake-Up";
  334. case DWC3_DEVICE_EVENT_HIBER_REQ:
  335. return "Hibernation";
  336. case DWC3_DEVICE_EVENT_SUSPEND:
  337. return "Suspend";
  338. case DWC3_DEVICE_EVENT_SOF:
  339. return "Start of Frame";
  340. case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
  341. return "Erratic Error";
  342. case DWC3_DEVICE_EVENT_CMD_CMPL:
  343. return "Command Complete";
  344. case DWC3_DEVICE_EVENT_OVERFLOW:
  345. return "Overflow";
  346. default:
  347. return "UNKNOWN";
  348. }
  349. }
  350. static inline const char *dwc3_decode_event(char *str, size_t size, u32 event,
  351. u32 ep0state)
  352. {
  353. union dwc3_event evt;
  354. memcpy(&evt, &event, sizeof(event));
  355. if (evt.type.is_devspec)
  356. return dwc3_gadget_event_string(str, size, &evt.devt);
  357. else
  358. return dwc3_ep_event_string(str, size, &evt.depevt, ep0state);
  359. }
  360. static inline const char *dwc3_ep_cmd_status_string(int status)
  361. {
  362. switch (status) {
  363. case -ETIMEDOUT:
  364. return "Timed Out";
  365. case 0:
  366. return "Successful";
  367. case DEPEVT_TRANSFER_NO_RESOURCE:
  368. return "No Resource";
  369. case DEPEVT_TRANSFER_BUS_EXPIRY:
  370. return "Bus Expiry";
  371. default:
  372. return "UNKNOWN";
  373. }
  374. }
  375. static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
  376. {
  377. switch (status) {
  378. case -ETIMEDOUT:
  379. return "Timed Out";
  380. case 0:
  381. return "Successful";
  382. case 1:
  383. return "Error";
  384. default:
  385. return "UNKNOWN";
  386. }
  387. }
  388. #ifdef CONFIG_DEBUG_FS
  389. extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep);
  390. extern void dwc3_debugfs_remove_endpoint_dir(struct dwc3_ep *dep);
  391. extern void dwc3_debugfs_init(struct dwc3 *d);
  392. extern void dwc3_debugfs_exit(struct dwc3 *d);
  393. #else
  394. static inline void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
  395. { }
  396. static inline void dwc3_debugfs_remove_endpoint_dir(struct dwc3_ep *dep)
  397. { }
  398. static inline void dwc3_debugfs_init(struct dwc3 *d)
  399. { }
  400. static inline void dwc3_debugfs_exit(struct dwc3 *d)
  401. { }
  402. #endif
  403. #endif /* __DWC3_DEBUG_H */