Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* SMBUS message transfer tracepoints
0003  *
0004  * Copyright (C) 2013 Red Hat, Inc. All Rights Reserved.
0005  * Written by David Howells (dhowells@redhat.com)
0006  */
0007 #undef TRACE_SYSTEM
0008 #define TRACE_SYSTEM smbus
0009 
0010 #if !defined(_TRACE_SMBUS_H) || defined(TRACE_HEADER_MULTI_READ)
0011 #define _TRACE_SMBUS_H
0012 
0013 #include <linux/i2c.h>
0014 #include <linux/tracepoint.h>
0015 
0016 /*
0017  * drivers/i2c/i2c-core-smbus.c
0018  */
0019 
0020 /*
0021  * i2c_smbus_xfer() write data or procedure call request
0022  */
0023 TRACE_EVENT_CONDITION(smbus_write,
0024     TP_PROTO(const struct i2c_adapter *adap,
0025          u16 addr, unsigned short flags,
0026          char read_write, u8 command, int protocol,
0027          const union i2c_smbus_data *data),
0028     TP_ARGS(adap, addr, flags, read_write, command, protocol, data),
0029     TP_CONDITION(read_write == I2C_SMBUS_WRITE ||
0030              protocol == I2C_SMBUS_PROC_CALL ||
0031              protocol == I2C_SMBUS_BLOCK_PROC_CALL),
0032     TP_STRUCT__entry(
0033         __field(int,    adapter_nr      )
0034         __field(__u16,  addr            )
0035         __field(__u16,  flags           )
0036         __field(__u8,   command         )
0037         __field(__u8,   len         )
0038         __field(__u32,  protocol        )
0039         __array(__u8, buf, I2C_SMBUS_BLOCK_MAX + 2) ),
0040     TP_fast_assign(
0041         __entry->adapter_nr = adap->nr;
0042         __entry->addr = addr;
0043         __entry->flags = flags;
0044         __entry->command = command;
0045         __entry->protocol = protocol;
0046 
0047         switch (protocol) {
0048         case I2C_SMBUS_BYTE_DATA:
0049             __entry->len = 1;
0050             goto copy;
0051         case I2C_SMBUS_WORD_DATA:
0052         case I2C_SMBUS_PROC_CALL:
0053             __entry->len = 2;
0054             goto copy;
0055         case I2C_SMBUS_BLOCK_DATA:
0056         case I2C_SMBUS_BLOCK_PROC_CALL:
0057         case I2C_SMBUS_I2C_BLOCK_DATA:
0058             __entry->len = data->block[0] + 1;
0059         copy:
0060             memcpy(__entry->buf, data->block, __entry->len);
0061             break;
0062         case I2C_SMBUS_QUICK:
0063         case I2C_SMBUS_BYTE:
0064         case I2C_SMBUS_I2C_BLOCK_BROKEN:
0065         default:
0066             __entry->len = 0;
0067         }
0068                ),
0069     TP_printk("i2c-%d a=%03x f=%04x c=%x %s l=%u [%*phD]",
0070           __entry->adapter_nr,
0071           __entry->addr,
0072           __entry->flags,
0073           __entry->command,
0074           __print_symbolic(__entry->protocol,
0075                    { I2C_SMBUS_QUICK,       "QUICK" },
0076                    { I2C_SMBUS_BYTE,        "BYTE"  },
0077                    { I2C_SMBUS_BYTE_DATA,       "BYTE_DATA" },
0078                    { I2C_SMBUS_WORD_DATA,       "WORD_DATA" },
0079                    { I2C_SMBUS_PROC_CALL,       "PROC_CALL" },
0080                    { I2C_SMBUS_BLOCK_DATA,      "BLOCK_DATA" },
0081                    { I2C_SMBUS_I2C_BLOCK_BROKEN,    "I2C_BLOCK_BROKEN" },
0082                    { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" },
0083                    { I2C_SMBUS_I2C_BLOCK_DATA,  "I2C_BLOCK_DATA" }),
0084           __entry->len,
0085           __entry->len, __entry->buf
0086           ));
0087 
0088 /*
0089  * i2c_smbus_xfer() read data request
0090  */
0091 TRACE_EVENT_CONDITION(smbus_read,
0092     TP_PROTO(const struct i2c_adapter *adap,
0093          u16 addr, unsigned short flags,
0094          char read_write, u8 command, int protocol),
0095     TP_ARGS(adap, addr, flags, read_write, command, protocol),
0096     TP_CONDITION(!(read_write == I2C_SMBUS_WRITE ||
0097                protocol == I2C_SMBUS_PROC_CALL ||
0098                protocol == I2C_SMBUS_BLOCK_PROC_CALL)),
0099     TP_STRUCT__entry(
0100         __field(int,    adapter_nr      )
0101         __field(__u16,  flags           )
0102         __field(__u16,  addr            )
0103         __field(__u8,   command         )
0104         __field(__u32,  protocol        )
0105         __array(__u8, buf, I2C_SMBUS_BLOCK_MAX + 2) ),
0106     TP_fast_assign(
0107         __entry->adapter_nr = adap->nr;
0108         __entry->addr = addr;
0109         __entry->flags = flags;
0110         __entry->command = command;
0111         __entry->protocol = protocol;
0112                ),
0113     TP_printk("i2c-%d a=%03x f=%04x c=%x %s",
0114           __entry->adapter_nr,
0115           __entry->addr,
0116           __entry->flags,
0117           __entry->command,
0118           __print_symbolic(__entry->protocol,
0119                    { I2C_SMBUS_QUICK,       "QUICK" },
0120                    { I2C_SMBUS_BYTE,        "BYTE"  },
0121                    { I2C_SMBUS_BYTE_DATA,       "BYTE_DATA" },
0122                    { I2C_SMBUS_WORD_DATA,       "WORD_DATA" },
0123                    { I2C_SMBUS_PROC_CALL,       "PROC_CALL" },
0124                    { I2C_SMBUS_BLOCK_DATA,      "BLOCK_DATA" },
0125                    { I2C_SMBUS_I2C_BLOCK_BROKEN,    "I2C_BLOCK_BROKEN" },
0126                    { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" },
0127                    { I2C_SMBUS_I2C_BLOCK_DATA,  "I2C_BLOCK_DATA" })
0128           ));
0129 
0130 /*
0131  * i2c_smbus_xfer() read data or procedure call reply
0132  */
0133 TRACE_EVENT_CONDITION(smbus_reply,
0134     TP_PROTO(const struct i2c_adapter *adap,
0135          u16 addr, unsigned short flags,
0136          char read_write, u8 command, int protocol,
0137          const union i2c_smbus_data *data, int res),
0138     TP_ARGS(adap, addr, flags, read_write, command, protocol, data, res),
0139     TP_CONDITION(res >= 0 && read_write == I2C_SMBUS_READ),
0140     TP_STRUCT__entry(
0141         __field(int,    adapter_nr      )
0142         __field(__u16,  addr            )
0143         __field(__u16,  flags           )
0144         __field(__u8,   command         )
0145         __field(__u8,   len         )
0146         __field(__u32,  protocol        )
0147         __array(__u8, buf, I2C_SMBUS_BLOCK_MAX + 2) ),
0148     TP_fast_assign(
0149         __entry->adapter_nr = adap->nr;
0150         __entry->addr = addr;
0151         __entry->flags = flags;
0152         __entry->command = command;
0153         __entry->protocol = protocol;
0154 
0155         switch (protocol) {
0156         case I2C_SMBUS_BYTE:
0157         case I2C_SMBUS_BYTE_DATA:
0158             __entry->len = 1;
0159             goto copy;
0160         case I2C_SMBUS_WORD_DATA:
0161         case I2C_SMBUS_PROC_CALL:
0162             __entry->len = 2;
0163             goto copy;
0164         case I2C_SMBUS_BLOCK_DATA:
0165         case I2C_SMBUS_BLOCK_PROC_CALL:
0166         case I2C_SMBUS_I2C_BLOCK_DATA:
0167             __entry->len = data->block[0] + 1;
0168         copy:
0169             memcpy(__entry->buf, data->block, __entry->len);
0170             break;
0171         case I2C_SMBUS_QUICK:
0172         case I2C_SMBUS_I2C_BLOCK_BROKEN:
0173         default:
0174             __entry->len = 0;
0175         }
0176                ),
0177     TP_printk("i2c-%d a=%03x f=%04x c=%x %s l=%u [%*phD]",
0178           __entry->adapter_nr,
0179           __entry->addr,
0180           __entry->flags,
0181           __entry->command,
0182           __print_symbolic(__entry->protocol,
0183                    { I2C_SMBUS_QUICK,       "QUICK" },
0184                    { I2C_SMBUS_BYTE,        "BYTE"  },
0185                    { I2C_SMBUS_BYTE_DATA,       "BYTE_DATA" },
0186                    { I2C_SMBUS_WORD_DATA,       "WORD_DATA" },
0187                    { I2C_SMBUS_PROC_CALL,       "PROC_CALL" },
0188                    { I2C_SMBUS_BLOCK_DATA,      "BLOCK_DATA" },
0189                    { I2C_SMBUS_I2C_BLOCK_BROKEN,    "I2C_BLOCK_BROKEN" },
0190                    { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" },
0191                    { I2C_SMBUS_I2C_BLOCK_DATA,  "I2C_BLOCK_DATA" }),
0192           __entry->len,
0193           __entry->len, __entry->buf
0194           ));
0195 
0196 /*
0197  * i2c_smbus_xfer() result
0198  */
0199 TRACE_EVENT(smbus_result,
0200         TP_PROTO(const struct i2c_adapter *adap,
0201              u16 addr, unsigned short flags,
0202              char read_write, u8 command, int protocol,
0203              int res),
0204         TP_ARGS(adap, addr, flags, read_write, command, protocol, res),
0205         TP_STRUCT__entry(
0206             __field(int,    adapter_nr      )
0207             __field(__u16,  addr            )
0208             __field(__u16,  flags           )
0209             __field(__u8,   read_write      )
0210             __field(__u8,   command         )
0211             __field(__s16,  res         )
0212             __field(__u32,  protocol        )
0213                  ),
0214         TP_fast_assign(
0215             __entry->adapter_nr = adap->nr;
0216             __entry->addr = addr;
0217             __entry->flags = flags;
0218             __entry->read_write = read_write;
0219             __entry->command = command;
0220             __entry->protocol = protocol;
0221             __entry->res = res;
0222                ),
0223         TP_printk("i2c-%d a=%03x f=%04x c=%x %s %s res=%d",
0224               __entry->adapter_nr,
0225               __entry->addr,
0226               __entry->flags,
0227               __entry->command,
0228               __print_symbolic(__entry->protocol,
0229                        { I2C_SMBUS_QUICK,       "QUICK" },
0230                        { I2C_SMBUS_BYTE,        "BYTE"  },
0231                        { I2C_SMBUS_BYTE_DATA,       "BYTE_DATA" },
0232                        { I2C_SMBUS_WORD_DATA,       "WORD_DATA" },
0233                        { I2C_SMBUS_PROC_CALL,       "PROC_CALL" },
0234                        { I2C_SMBUS_BLOCK_DATA,      "BLOCK_DATA" },
0235                        { I2C_SMBUS_I2C_BLOCK_BROKEN,    "I2C_BLOCK_BROKEN" },
0236                        { I2C_SMBUS_BLOCK_PROC_CALL, "BLOCK_PROC_CALL" },
0237                        { I2C_SMBUS_I2C_BLOCK_DATA,  "I2C_BLOCK_DATA" }),
0238               __entry->read_write == I2C_SMBUS_WRITE ? "wr" : "rd",
0239               __entry->res
0240               ));
0241 
0242 #endif /* _TRACE_SMBUS_H */
0243 
0244 /* This part must be outside protection */
0245 #include <trace/define_trace.h>