greybus_trace.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Greybus driver and device API
  4. *
  5. * Copyright 2015 Google Inc.
  6. * Copyright 2015 Linaro Ltd.
  7. */
  8. #undef TRACE_SYSTEM
  9. #define TRACE_SYSTEM greybus
  10. #if !defined(_TRACE_GREYBUS_H) || defined(TRACE_HEADER_MULTI_READ)
  11. #define _TRACE_GREYBUS_H
  12. #include <linux/tracepoint.h>
  13. struct gb_message;
  14. struct gb_operation;
  15. struct gb_connection;
  16. struct gb_bundle;
  17. struct gb_host_device;
  18. DECLARE_EVENT_CLASS(gb_message,
  19. TP_PROTO(struct gb_message *message),
  20. TP_ARGS(message),
  21. TP_STRUCT__entry(
  22. __field(u16, size)
  23. __field(u16, operation_id)
  24. __field(u8, type)
  25. __field(u8, result)
  26. ),
  27. TP_fast_assign(
  28. __entry->size = le16_to_cpu(message->header->size);
  29. __entry->operation_id =
  30. le16_to_cpu(message->header->operation_id);
  31. __entry->type = message->header->type;
  32. __entry->result = message->header->result;
  33. ),
  34. TP_printk("size=%hu operation_id=0x%04x type=0x%02x result=0x%02x",
  35. __entry->size, __entry->operation_id,
  36. __entry->type, __entry->result)
  37. );
  38. #define DEFINE_MESSAGE_EVENT(name) \
  39. DEFINE_EVENT(gb_message, name, \
  40. TP_PROTO(struct gb_message *message), \
  41. TP_ARGS(message))
  42. /*
  43. * Occurs immediately before calling a host device's message_send()
  44. * method.
  45. */
  46. DEFINE_MESSAGE_EVENT(gb_message_send);
  47. /*
  48. * Occurs after an incoming request message has been received
  49. */
  50. DEFINE_MESSAGE_EVENT(gb_message_recv_request);
  51. /*
  52. * Occurs after an incoming response message has been received,
  53. * after its matching request has been found.
  54. */
  55. DEFINE_MESSAGE_EVENT(gb_message_recv_response);
  56. /*
  57. * Occurs after an operation has been canceled, possibly before the
  58. * cancellation is complete.
  59. */
  60. DEFINE_MESSAGE_EVENT(gb_message_cancel_outgoing);
  61. /*
  62. * Occurs when an incoming request is cancelled; if the response has
  63. * been queued for sending, this occurs after it is sent.
  64. */
  65. DEFINE_MESSAGE_EVENT(gb_message_cancel_incoming);
  66. /*
  67. * Occurs in the host driver message_send() function just prior to
  68. * handing off the data to be processed by hardware.
  69. */
  70. DEFINE_MESSAGE_EVENT(gb_message_submit);
  71. #undef DEFINE_MESSAGE_EVENT
  72. DECLARE_EVENT_CLASS(gb_operation,
  73. TP_PROTO(struct gb_operation *operation),
  74. TP_ARGS(operation),
  75. TP_STRUCT__entry(
  76. __field(u16, cport_id) /* CPort of HD side of connection */
  77. __field(u16, id) /* Operation ID */
  78. __field(u8, type)
  79. __field(unsigned long, flags)
  80. __field(int, active)
  81. __field(int, waiters)
  82. __field(int, errno)
  83. ),
  84. TP_fast_assign(
  85. __entry->cport_id = operation->connection->hd_cport_id;
  86. __entry->id = operation->id;
  87. __entry->type = operation->type;
  88. __entry->flags = operation->flags;
  89. __entry->active = operation->active;
  90. __entry->waiters = atomic_read(&operation->waiters);
  91. __entry->errno = operation->errno;
  92. ),
  93. TP_printk("id=%04x type=0x%02x cport_id=%04x flags=0x%lx active=%d waiters=%d errno=%d",
  94. __entry->id, __entry->cport_id, __entry->type, __entry->flags,
  95. __entry->active, __entry->waiters, __entry->errno)
  96. );
  97. #define DEFINE_OPERATION_EVENT(name) \
  98. DEFINE_EVENT(gb_operation, name, \
  99. TP_PROTO(struct gb_operation *operation), \
  100. TP_ARGS(operation))
  101. /*
  102. * Occurs after a new operation is created for an outgoing request
  103. * has been successfully created.
  104. */
  105. DEFINE_OPERATION_EVENT(gb_operation_create);
  106. /*
  107. * Occurs after a new core operation has been created.
  108. */
  109. DEFINE_OPERATION_EVENT(gb_operation_create_core);
  110. /*
  111. * Occurs after a new operation has been created for an incoming
  112. * request has been successfully created and initialized.
  113. */
  114. DEFINE_OPERATION_EVENT(gb_operation_create_incoming);
  115. /*
  116. * Occurs when the last reference to an operation has been dropped,
  117. * prior to freeing resources.
  118. */
  119. DEFINE_OPERATION_EVENT(gb_operation_destroy);
  120. /*
  121. * Occurs when an operation has been marked active, after updating
  122. * its active count.
  123. */
  124. DEFINE_OPERATION_EVENT(gb_operation_get_active);
  125. /*
  126. * Occurs when an operation has been marked active, before updating
  127. * its active count.
  128. */
  129. DEFINE_OPERATION_EVENT(gb_operation_put_active);
  130. #undef DEFINE_OPERATION_EVENT
  131. DECLARE_EVENT_CLASS(gb_connection,
  132. TP_PROTO(struct gb_connection *connection),
  133. TP_ARGS(connection),
  134. TP_STRUCT__entry(
  135. __field(int, hd_bus_id)
  136. __field(u8, bundle_id)
  137. /* name contains "hd_cport_id/intf_id:cport_id" */
  138. __dynamic_array(char, name, sizeof(connection->name))
  139. __field(enum gb_connection_state, state)
  140. __field(unsigned long, flags)
  141. ),
  142. TP_fast_assign(
  143. __entry->hd_bus_id = connection->hd->bus_id;
  144. __entry->bundle_id = connection->bundle ?
  145. connection->bundle->id : BUNDLE_ID_NONE;
  146. memcpy(__get_str(name), connection->name,
  147. sizeof(connection->name));
  148. __entry->state = connection->state;
  149. __entry->flags = connection->flags;
  150. ),
  151. TP_printk("hd_bus_id=%d bundle_id=0x%02x name=\"%s\" state=%u flags=0x%lx",
  152. __entry->hd_bus_id, __entry->bundle_id, __get_str(name),
  153. (unsigned int)__entry->state, __entry->flags)
  154. );
  155. #define DEFINE_CONNECTION_EVENT(name) \
  156. DEFINE_EVENT(gb_connection, name, \
  157. TP_PROTO(struct gb_connection *connection), \
  158. TP_ARGS(connection))
  159. /*
  160. * Occurs after a new connection is successfully created.
  161. */
  162. DEFINE_CONNECTION_EVENT(gb_connection_create);
  163. /*
  164. * Occurs when the last reference to a connection has been dropped,
  165. * before its resources are freed.
  166. */
  167. DEFINE_CONNECTION_EVENT(gb_connection_release);
  168. /*
  169. * Occurs when a new reference to connection is added, currently
  170. * only when a message over the connection is received.
  171. */
  172. DEFINE_CONNECTION_EVENT(gb_connection_get);
  173. /*
  174. * Occurs when a new reference to connection is dropped, after a
  175. * a received message is handled, or when the connection is
  176. * destroyed.
  177. */
  178. DEFINE_CONNECTION_EVENT(gb_connection_put);
  179. /*
  180. * Occurs when a request to enable a connection is made, either for
  181. * transmit only, or for both transmit and receive.
  182. */
  183. DEFINE_CONNECTION_EVENT(gb_connection_enable);
  184. /*
  185. * Occurs when a request to disable a connection is made, either for
  186. * receive only, or for both transmit and receive. Also occurs when
  187. * a request to forcefully disable a connection is made.
  188. */
  189. DEFINE_CONNECTION_EVENT(gb_connection_disable);
  190. #undef DEFINE_CONNECTION_EVENT
  191. DECLARE_EVENT_CLASS(gb_bundle,
  192. TP_PROTO(struct gb_bundle *bundle),
  193. TP_ARGS(bundle),
  194. TP_STRUCT__entry(
  195. __field(u8, intf_id)
  196. __field(u8, id)
  197. __field(u8, class)
  198. __field(size_t, num_cports)
  199. ),
  200. TP_fast_assign(
  201. __entry->intf_id = bundle->intf->interface_id;
  202. __entry->id = bundle->id;
  203. __entry->class = bundle->class;
  204. __entry->num_cports = bundle->num_cports;
  205. ),
  206. TP_printk("intf_id=0x%02x id=%02x class=0x%02x num_cports=%zu",
  207. __entry->intf_id, __entry->id, __entry->class,
  208. __entry->num_cports)
  209. );
  210. #define DEFINE_BUNDLE_EVENT(name) \
  211. DEFINE_EVENT(gb_bundle, name, \
  212. TP_PROTO(struct gb_bundle *bundle), \
  213. TP_ARGS(bundle))
  214. /*
  215. * Occurs after a new bundle is successfully created.
  216. */
  217. DEFINE_BUNDLE_EVENT(gb_bundle_create);
  218. /*
  219. * Occurs when the last reference to a bundle has been dropped,
  220. * before its resources are freed.
  221. */
  222. DEFINE_BUNDLE_EVENT(gb_bundle_release);
  223. /*
  224. * Occurs when a bundle is added to an interface when the interface
  225. * is enabled.
  226. */
  227. DEFINE_BUNDLE_EVENT(gb_bundle_add);
  228. /*
  229. * Occurs when a registered bundle gets destroyed, normally at the
  230. * time an interface is disabled.
  231. */
  232. DEFINE_BUNDLE_EVENT(gb_bundle_destroy);
  233. #undef DEFINE_BUNDLE_EVENT
  234. DECLARE_EVENT_CLASS(gb_interface,
  235. TP_PROTO(struct gb_interface *intf),
  236. TP_ARGS(intf),
  237. TP_STRUCT__entry(
  238. __field(u8, module_id)
  239. __field(u8, id) /* Interface id */
  240. __field(u8, device_id)
  241. __field(int, disconnected) /* bool */
  242. __field(int, ejected) /* bool */
  243. __field(int, active) /* bool */
  244. __field(int, enabled) /* bool */
  245. __field(int, mode_switch) /* bool */
  246. ),
  247. TP_fast_assign(
  248. __entry->module_id = intf->module->module_id;
  249. __entry->id = intf->interface_id;
  250. __entry->device_id = intf->device_id;
  251. __entry->disconnected = intf->disconnected;
  252. __entry->ejected = intf->ejected;
  253. __entry->active = intf->active;
  254. __entry->enabled = intf->enabled;
  255. __entry->mode_switch = intf->mode_switch;
  256. ),
  257. TP_printk("intf_id=%hhu device_id=%hhu module_id=%hhu D=%d J=%d A=%d E=%d M=%d",
  258. __entry->id, __entry->device_id, __entry->module_id,
  259. __entry->disconnected, __entry->ejected, __entry->active,
  260. __entry->enabled, __entry->mode_switch)
  261. );
  262. #define DEFINE_INTERFACE_EVENT(name) \
  263. DEFINE_EVENT(gb_interface, name, \
  264. TP_PROTO(struct gb_interface *intf), \
  265. TP_ARGS(intf))
  266. /*
  267. * Occurs after a new interface is successfully created.
  268. */
  269. DEFINE_INTERFACE_EVENT(gb_interface_create);
  270. /*
  271. * Occurs after the last reference to an interface has been dropped.
  272. */
  273. DEFINE_INTERFACE_EVENT(gb_interface_release);
  274. /*
  275. * Occurs after an interface been registerd.
  276. */
  277. DEFINE_INTERFACE_EVENT(gb_interface_add);
  278. /*
  279. * Occurs when a registered interface gets deregisterd.
  280. */
  281. DEFINE_INTERFACE_EVENT(gb_interface_del);
  282. /*
  283. * Occurs when a registered interface has been successfully
  284. * activated.
  285. */
  286. DEFINE_INTERFACE_EVENT(gb_interface_activate);
  287. /*
  288. * Occurs when an activated interface is being deactivated.
  289. */
  290. DEFINE_INTERFACE_EVENT(gb_interface_deactivate);
  291. /*
  292. * Occurs when an interface has been successfully enabled.
  293. */
  294. DEFINE_INTERFACE_EVENT(gb_interface_enable);
  295. /*
  296. * Occurs when an enabled interface is being disabled.
  297. */
  298. DEFINE_INTERFACE_EVENT(gb_interface_disable);
  299. #undef DEFINE_INTERFACE_EVENT
  300. DECLARE_EVENT_CLASS(gb_module,
  301. TP_PROTO(struct gb_module *module),
  302. TP_ARGS(module),
  303. TP_STRUCT__entry(
  304. __field(int, hd_bus_id)
  305. __field(u8, module_id)
  306. __field(size_t, num_interfaces)
  307. __field(int, disconnected) /* bool */
  308. ),
  309. TP_fast_assign(
  310. __entry->hd_bus_id = module->hd->bus_id;
  311. __entry->module_id = module->module_id;
  312. __entry->num_interfaces = module->num_interfaces;
  313. __entry->disconnected = module->disconnected;
  314. ),
  315. TP_printk("hd_bus_id=%d module_id=%hhu num_interfaces=%zu disconnected=%d",
  316. __entry->hd_bus_id, __entry->module_id,
  317. __entry->num_interfaces, __entry->disconnected)
  318. );
  319. #define DEFINE_MODULE_EVENT(name) \
  320. DEFINE_EVENT(gb_module, name, \
  321. TP_PROTO(struct gb_module *module), \
  322. TP_ARGS(module))
  323. /*
  324. * Occurs after a new module is successfully created, before
  325. * creating any of its interfaces.
  326. */
  327. DEFINE_MODULE_EVENT(gb_module_create);
  328. /*
  329. * Occurs after the last reference to a module has been dropped.
  330. */
  331. DEFINE_MODULE_EVENT(gb_module_release);
  332. /*
  333. * Occurs after a module is successfully created, before registering
  334. * any of its interfaces.
  335. */
  336. DEFINE_MODULE_EVENT(gb_module_add);
  337. /*
  338. * Occurs when a module is deleted, before deregistering its
  339. * interfaces.
  340. */
  341. DEFINE_MODULE_EVENT(gb_module_del);
  342. #undef DEFINE_MODULE_EVENT
  343. DECLARE_EVENT_CLASS(gb_host_device,
  344. TP_PROTO(struct gb_host_device *hd),
  345. TP_ARGS(hd),
  346. TP_STRUCT__entry(
  347. __field(int, bus_id)
  348. __field(size_t, num_cports)
  349. __field(size_t, buffer_size_max)
  350. ),
  351. TP_fast_assign(
  352. __entry->bus_id = hd->bus_id;
  353. __entry->num_cports = hd->num_cports;
  354. __entry->buffer_size_max = hd->buffer_size_max;
  355. ),
  356. TP_printk("bus_id=%d num_cports=%zu mtu=%zu",
  357. __entry->bus_id, __entry->num_cports,
  358. __entry->buffer_size_max)
  359. );
  360. #define DEFINE_HD_EVENT(name) \
  361. DEFINE_EVENT(gb_host_device, name, \
  362. TP_PROTO(struct gb_host_device *hd), \
  363. TP_ARGS(hd))
  364. /*
  365. * Occurs after a new host device is successfully created, before
  366. * its SVC has been set up.
  367. */
  368. DEFINE_HD_EVENT(gb_hd_create);
  369. /*
  370. * Occurs after the last reference to a host device has been
  371. * dropped.
  372. */
  373. DEFINE_HD_EVENT(gb_hd_release);
  374. /*
  375. * Occurs after a new host device has been added, after the
  376. * connection to its SVC has been enabled.
  377. */
  378. DEFINE_HD_EVENT(gb_hd_add);
  379. /*
  380. * Occurs when a host device is being disconnected from the AP USB
  381. * host controller.
  382. */
  383. DEFINE_HD_EVENT(gb_hd_del);
  384. /*
  385. * Occurs when a host device has passed received data to the Greybus
  386. * core, after it has been determined it is destined for a valid
  387. * CPort.
  388. */
  389. DEFINE_HD_EVENT(gb_hd_in);
  390. #undef DEFINE_HD_EVENT
  391. #endif /* _TRACE_GREYBUS_H */
  392. /* This part must be outside protection */
  393. #undef TRACE_INCLUDE_PATH
  394. #define TRACE_INCLUDE_PATH .
  395. /*
  396. * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal
  397. */
  398. #undef TRACE_INCLUDE_FILE
  399. #define TRACE_INCLUDE_FILE greybus_trace
  400. #include <trace/define_trace.h>