trace.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Thunderbolt tracing support
  4. *
  5. * Copyright (C) 2024, Intel Corporation
  6. * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
  7. * Gil Fine <gil.fine@intel.com>
  8. */
  9. #undef TRACE_SYSTEM
  10. #define TRACE_SYSTEM thunderbolt
  11. #if !defined(TB_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ)
  12. #define TB_TRACE_H_
  13. #include <linux/trace_seq.h>
  14. #include <linux/tracepoint.h>
  15. #include "tb_msgs.h"
  16. #define tb_cfg_type_name(type) { type, #type }
  17. #define show_type_name(val) \
  18. __print_symbolic(val, \
  19. tb_cfg_type_name(TB_CFG_PKG_READ), \
  20. tb_cfg_type_name(TB_CFG_PKG_WRITE), \
  21. tb_cfg_type_name(TB_CFG_PKG_ERROR), \
  22. tb_cfg_type_name(TB_CFG_PKG_NOTIFY_ACK), \
  23. tb_cfg_type_name(TB_CFG_PKG_EVENT), \
  24. tb_cfg_type_name(TB_CFG_PKG_XDOMAIN_REQ), \
  25. tb_cfg_type_name(TB_CFG_PKG_XDOMAIN_RESP), \
  26. tb_cfg_type_name(TB_CFG_PKG_OVERRIDE), \
  27. tb_cfg_type_name(TB_CFG_PKG_RESET), \
  28. tb_cfg_type_name(TB_CFG_PKG_ICM_EVENT), \
  29. tb_cfg_type_name(TB_CFG_PKG_ICM_CMD), \
  30. tb_cfg_type_name(TB_CFG_PKG_ICM_RESP))
  31. #ifndef TB_TRACE_HELPERS
  32. #define TB_TRACE_HELPERS
  33. static inline const char *show_data_read_write(struct trace_seq *p,
  34. const u32 *data)
  35. {
  36. const struct cfg_read_pkg *msg = (const struct cfg_read_pkg *)data;
  37. const char *ret = trace_seq_buffer_ptr(p);
  38. trace_seq_printf(p, "offset=%#x, len=%u, port=%d, config=%#x, seq=%d, ",
  39. msg->addr.offset, msg->addr.length, msg->addr.port,
  40. msg->addr.space, msg->addr.seq);
  41. return ret;
  42. }
  43. static inline const char *show_data_error(struct trace_seq *p, const u32 *data)
  44. {
  45. const struct cfg_error_pkg *msg = (const struct cfg_error_pkg *)data;
  46. const char *ret = trace_seq_buffer_ptr(p);
  47. trace_seq_printf(p, "error=%#x, port=%d, plug=%#x, ", msg->error,
  48. msg->port, msg->pg);
  49. return ret;
  50. }
  51. static inline const char *show_data_event(struct trace_seq *p, const u32 *data)
  52. {
  53. const struct cfg_event_pkg *msg = (const struct cfg_event_pkg *)data;
  54. const char *ret = trace_seq_buffer_ptr(p);
  55. trace_seq_printf(p, "port=%d, unplug=%#x, ", msg->port, msg->unplug);
  56. return ret;
  57. }
  58. static inline const char *show_route(struct trace_seq *p, const u32 *data)
  59. {
  60. const struct tb_cfg_header *header = (const struct tb_cfg_header *)data;
  61. const char *ret = trace_seq_buffer_ptr(p);
  62. trace_seq_printf(p, "route=%llx, ", tb_cfg_get_route(header));
  63. return ret;
  64. }
  65. static inline const char *show_data(struct trace_seq *p, u8 type,
  66. const u32 *data, u32 length)
  67. {
  68. const char *ret = trace_seq_buffer_ptr(p);
  69. const char *prefix = "";
  70. int i;
  71. switch (type) {
  72. case TB_CFG_PKG_READ:
  73. case TB_CFG_PKG_WRITE:
  74. show_route(p, data);
  75. show_data_read_write(p, data);
  76. break;
  77. case TB_CFG_PKG_ERROR:
  78. show_route(p, data);
  79. show_data_error(p, data);
  80. break;
  81. case TB_CFG_PKG_EVENT:
  82. show_route(p, data);
  83. show_data_event(p, data);
  84. break;
  85. case TB_CFG_PKG_ICM_EVENT:
  86. case TB_CFG_PKG_ICM_CMD:
  87. case TB_CFG_PKG_ICM_RESP:
  88. /* ICM messages always target the host router */
  89. trace_seq_puts(p, "route=0, ");
  90. break;
  91. default:
  92. show_route(p, data);
  93. break;
  94. }
  95. trace_seq_printf(p, "data=[");
  96. for (i = 0; i < length; i++) {
  97. trace_seq_printf(p, "%s0x%08x", prefix, data[i]);
  98. prefix = ", ";
  99. }
  100. trace_seq_printf(p, "]");
  101. trace_seq_putc(p, 0);
  102. return ret;
  103. }
  104. #endif
  105. DECLARE_EVENT_CLASS(tb_raw,
  106. TP_PROTO(int index, u8 type, const void *data, size_t size),
  107. TP_ARGS(index, type, data, size),
  108. TP_STRUCT__entry(
  109. __field(int, index)
  110. __field(u8, type)
  111. __field(size_t, size)
  112. __dynamic_array(u32, data, size / 4)
  113. ),
  114. TP_fast_assign(
  115. __entry->index = index;
  116. __entry->type = type;
  117. __entry->size = size / 4;
  118. memcpy(__get_dynamic_array(data), data, size);
  119. ),
  120. TP_printk("type=%s, size=%zd, domain=%d, %s",
  121. show_type_name(__entry->type), __entry->size, __entry->index,
  122. show_data(p, __entry->type, __get_dynamic_array(data),
  123. __entry->size)
  124. )
  125. );
  126. DEFINE_EVENT(tb_raw, tb_tx,
  127. TP_PROTO(int index, u8 type, const void *data, size_t size),
  128. TP_ARGS(index, type, data, size)
  129. );
  130. DEFINE_EVENT(tb_raw, tb_event,
  131. TP_PROTO(int index, u8 type, const void *data, size_t size),
  132. TP_ARGS(index, type, data, size)
  133. );
  134. TRACE_EVENT(tb_rx,
  135. TP_PROTO(int index, u8 type, const void *data, size_t size, bool dropped),
  136. TP_ARGS(index, type, data, size, dropped),
  137. TP_STRUCT__entry(
  138. __field(int, index)
  139. __field(u8, type)
  140. __field(size_t, size)
  141. __dynamic_array(u32, data, size / 4)
  142. __field(bool, dropped)
  143. ),
  144. TP_fast_assign(
  145. __entry->index = index;
  146. __entry->type = type;
  147. __entry->size = size / 4;
  148. memcpy(__get_dynamic_array(data), data, size);
  149. __entry->dropped = dropped;
  150. ),
  151. TP_printk("type=%s, dropped=%u, size=%zd, domain=%d, %s",
  152. show_type_name(__entry->type), __entry->dropped,
  153. __entry->size, __entry->index,
  154. show_data(p, __entry->type, __get_dynamic_array(data),
  155. __entry->size)
  156. )
  157. );
  158. #endif /* TB_TRACE_H_ */
  159. #undef TRACE_INCLUDE_PATH
  160. #define TRACE_INCLUDE_PATH .
  161. #undef TRACE_INCLUDE_FILE
  162. #define TRACE_INCLUDE_FILE trace
  163. /* This part must be outside protection */
  164. #include <trace/define_trace.h>