smbus.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* SMBUS message transfer tracepoints
  3. *
  4. * Copyright (C) 2013 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #undef TRACE_SYSTEM
  8. #define TRACE_SYSTEM smbus
  9. #if !defined(_TRACE_SMBUS_H) || defined(TRACE_HEADER_MULTI_READ)
  10. #define _TRACE_SMBUS_H
  11. #include <linux/i2c.h>
  12. #include <linux/tracepoint.h>
  13. /*
  14. * drivers/i2c/i2c-core-smbus.c
  15. */
  16. /*
  17. * i2c_smbus_xfer() write data or procedure call request
  18. */
  19. TRACE_EVENT_CONDITION(smbus_write,
  20. TP_PROTO(const struct i2c_adapter *adap,
  21. u16 addr, unsigned short flags,
  22. char read_write, u8 command, int protocol,
  23. const union i2c_smbus_data *data),
  24. TP_ARGS(adap, addr, flags, read_write, command, protocol, data),
  25. TP_CONDITION(read_write == I2C_SMBUS_WRITE ||
  26. protocol == I2C_SMBUS_PROC_CALL ||
  27. protocol == I2C_SMBUS_BLOCK_PROC_CALL),
  28. TP_STRUCT__entry(
  29. __field(int, adapter_nr )
  30. __field(__u16, addr )
  31. __field(__u16, flags )
  32. __field(__u8, command )
  33. __field(__u8, len )
  34. __field(__u32, protocol )
  35. __array(__u8, buf, I2C_SMBUS_BLOCK_MAX + 2) ),
  36. TP_fast_assign(
  37. __entry->adapter_nr = adap->nr;
  38. __entry->addr = addr;
  39. __entry->flags = flags;
  40. __entry->command = command;
  41. __entry->protocol = protocol;
  42. switch (protocol) {
  43. case I2C_SMBUS_BYTE_DATA:
  44. __entry->len = 1;
  45. goto copy;
  46. case I2C_SMBUS_WORD_DATA:
  47. case I2C_SMBUS_PROC_CALL:
  48. __entry->len = 2;
  49. goto copy;
  50. case I2C_SMBUS_BLOCK_DATA:
  51. case I2C_SMBUS_BLOCK_PROC_CALL:
  52. case I2C_SMBUS_I2C_BLOCK_DATA:
  53. __entry->len = data->block[0] + 1;
  54. copy:
  55. memcpy(__entry->buf, data->block, __entry->len);
  56. break;
  57. case I2C_SMBUS_QUICK:
  58. case I2C_SMBUS_BYTE:
  59. case I2C_SMBUS_I2C_BLOCK_BROKEN:
  60. default:
  61. __entry->len = 0;
  62. }
  63. ),
  64. TP_printk("i2c-%d a=%03x f=%04x c=%x %s l=%u [%*phD]",
  65. __entry->adapter_nr,
  66. __entry->addr,
  67. __entry->flags,
  68. __entry->command,
  69. __print_symbolic(__entry->protocol,
  70. { I2C_SMBUS_QUICK, "QUICK" },
  71. { I2C_SMBUS_BYTE, "BYTE" },
  72. { I2C_SMBUS_BYTE_DATA, "BYTE_DATA" },
  73. { I2C_SMBUS_WORD_DATA, "WORD_DATA" },
  74. { I2C_SMBUS_PROC_CALL, "PROC_CALL" },
  75. { I2C_SMBUS_BLOCK_DATA, "BLOCK_DATA" },
  76. { I2C_SMBUS_I2C_BLOCK_BROKEN, "I2C_BLOCK_BROKEN" },
  77. { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" },
  78. { I2C_SMBUS_I2C_BLOCK_DATA, "I2C_BLOCK_DATA" }),
  79. __entry->len,
  80. __entry->len, __entry->buf
  81. ));
  82. /*
  83. * i2c_smbus_xfer() read data request
  84. */
  85. TRACE_EVENT_CONDITION(smbus_read,
  86. TP_PROTO(const struct i2c_adapter *adap,
  87. u16 addr, unsigned short flags,
  88. char read_write, u8 command, int protocol),
  89. TP_ARGS(adap, addr, flags, read_write, command, protocol),
  90. TP_CONDITION(!(read_write == I2C_SMBUS_WRITE ||
  91. protocol == I2C_SMBUS_PROC_CALL ||
  92. protocol == I2C_SMBUS_BLOCK_PROC_CALL)),
  93. TP_STRUCT__entry(
  94. __field(int, adapter_nr )
  95. __field(__u16, flags )
  96. __field(__u16, addr )
  97. __field(__u8, command )
  98. __field(__u32, protocol )
  99. __array(__u8, buf, I2C_SMBUS_BLOCK_MAX + 2) ),
  100. TP_fast_assign(
  101. __entry->adapter_nr = adap->nr;
  102. __entry->addr = addr;
  103. __entry->flags = flags;
  104. __entry->command = command;
  105. __entry->protocol = protocol;
  106. ),
  107. TP_printk("i2c-%d a=%03x f=%04x c=%x %s",
  108. __entry->adapter_nr,
  109. __entry->addr,
  110. __entry->flags,
  111. __entry->command,
  112. __print_symbolic(__entry->protocol,
  113. { I2C_SMBUS_QUICK, "QUICK" },
  114. { I2C_SMBUS_BYTE, "BYTE" },
  115. { I2C_SMBUS_BYTE_DATA, "BYTE_DATA" },
  116. { I2C_SMBUS_WORD_DATA, "WORD_DATA" },
  117. { I2C_SMBUS_PROC_CALL, "PROC_CALL" },
  118. { I2C_SMBUS_BLOCK_DATA, "BLOCK_DATA" },
  119. { I2C_SMBUS_I2C_BLOCK_BROKEN, "I2C_BLOCK_BROKEN" },
  120. { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" },
  121. { I2C_SMBUS_I2C_BLOCK_DATA, "I2C_BLOCK_DATA" })
  122. ));
  123. /*
  124. * i2c_smbus_xfer() read data or procedure call reply
  125. */
  126. TRACE_EVENT_CONDITION(smbus_reply,
  127. TP_PROTO(const struct i2c_adapter *adap,
  128. u16 addr, unsigned short flags,
  129. char read_write, u8 command, int protocol,
  130. const union i2c_smbus_data *data, int res),
  131. TP_ARGS(adap, addr, flags, read_write, command, protocol, data, res),
  132. TP_CONDITION(res >= 0 && read_write == I2C_SMBUS_READ),
  133. TP_STRUCT__entry(
  134. __field(int, adapter_nr )
  135. __field(__u16, addr )
  136. __field(__u16, flags )
  137. __field(__u8, command )
  138. __field(__u8, len )
  139. __field(__u32, protocol )
  140. __array(__u8, buf, I2C_SMBUS_BLOCK_MAX + 2) ),
  141. TP_fast_assign(
  142. __entry->adapter_nr = adap->nr;
  143. __entry->addr = addr;
  144. __entry->flags = flags;
  145. __entry->command = command;
  146. __entry->protocol = protocol;
  147. switch (protocol) {
  148. case I2C_SMBUS_BYTE:
  149. case I2C_SMBUS_BYTE_DATA:
  150. __entry->len = 1;
  151. goto copy;
  152. case I2C_SMBUS_WORD_DATA:
  153. case I2C_SMBUS_PROC_CALL:
  154. __entry->len = 2;
  155. goto copy;
  156. case I2C_SMBUS_BLOCK_DATA:
  157. case I2C_SMBUS_BLOCK_PROC_CALL:
  158. case I2C_SMBUS_I2C_BLOCK_DATA:
  159. __entry->len = data->block[0] + 1;
  160. copy:
  161. memcpy(__entry->buf, data->block, __entry->len);
  162. break;
  163. case I2C_SMBUS_QUICK:
  164. case I2C_SMBUS_I2C_BLOCK_BROKEN:
  165. default:
  166. __entry->len = 0;
  167. }
  168. ),
  169. TP_printk("i2c-%d a=%03x f=%04x c=%x %s l=%u [%*phD]",
  170. __entry->adapter_nr,
  171. __entry->addr,
  172. __entry->flags,
  173. __entry->command,
  174. __print_symbolic(__entry->protocol,
  175. { I2C_SMBUS_QUICK, "QUICK" },
  176. { I2C_SMBUS_BYTE, "BYTE" },
  177. { I2C_SMBUS_BYTE_DATA, "BYTE_DATA" },
  178. { I2C_SMBUS_WORD_DATA, "WORD_DATA" },
  179. { I2C_SMBUS_PROC_CALL, "PROC_CALL" },
  180. { I2C_SMBUS_BLOCK_DATA, "BLOCK_DATA" },
  181. { I2C_SMBUS_I2C_BLOCK_BROKEN, "I2C_BLOCK_BROKEN" },
  182. { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" },
  183. { I2C_SMBUS_I2C_BLOCK_DATA, "I2C_BLOCK_DATA" }),
  184. __entry->len,
  185. __entry->len, __entry->buf
  186. ));
  187. /*
  188. * i2c_smbus_xfer() result
  189. */
  190. TRACE_EVENT(smbus_result,
  191. TP_PROTO(const struct i2c_adapter *adap,
  192. u16 addr, unsigned short flags,
  193. char read_write, u8 command, int protocol,
  194. int res),
  195. TP_ARGS(adap, addr, flags, read_write, command, protocol, res),
  196. TP_STRUCT__entry(
  197. __field(int, adapter_nr )
  198. __field(__u16, addr )
  199. __field(__u16, flags )
  200. __field(__u8, read_write )
  201. __field(__u8, command )
  202. __field(__s16, res )
  203. __field(__u32, protocol )
  204. ),
  205. TP_fast_assign(
  206. __entry->adapter_nr = adap->nr;
  207. __entry->addr = addr;
  208. __entry->flags = flags;
  209. __entry->read_write = read_write;
  210. __entry->command = command;
  211. __entry->protocol = protocol;
  212. __entry->res = res;
  213. ),
  214. TP_printk("i2c-%d a=%03x f=%04x c=%x %s %s res=%d",
  215. __entry->adapter_nr,
  216. __entry->addr,
  217. __entry->flags,
  218. __entry->command,
  219. __print_symbolic(__entry->protocol,
  220. { I2C_SMBUS_QUICK, "QUICK" },
  221. { I2C_SMBUS_BYTE, "BYTE" },
  222. { I2C_SMBUS_BYTE_DATA, "BYTE_DATA" },
  223. { I2C_SMBUS_WORD_DATA, "WORD_DATA" },
  224. { I2C_SMBUS_PROC_CALL, "PROC_CALL" },
  225. { I2C_SMBUS_BLOCK_DATA, "BLOCK_DATA" },
  226. { I2C_SMBUS_I2C_BLOCK_BROKEN, "I2C_BLOCK_BROKEN" },
  227. { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" },
  228. { I2C_SMBUS_I2C_BLOCK_DATA, "I2C_BLOCK_DATA" }),
  229. __entry->read_write == I2C_SMBUS_WRITE ? "wr" : "rd",
  230. __entry->res
  231. ));
  232. #endif /* _TRACE_SMBUS_H */
  233. /* This part must be outside protection */
  234. #include <trace/define_trace.h>