smbus.h 7.5 KB

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