Commit d714fb25 authored by Jae Hyun Yoo's avatar Jae Hyun Yoo Committed by Wolfram Sang

i2c: add tracepoints for I2C slave events

I2C slave events tracepoints can be enabled by:

	echo 1 > /sys/kernel/tracing/events/i2c_slave/enable

and logs in /sys/kernel/tracing/trace will look like:

	... i2c_slave: i2c-0 a=010 ret=0 WR_REQ []
	... i2c_slave: i2c-0 a=010 ret=0 WR_RCV [02]
	... i2c_slave: i2c-0 a=010 ret=0 WR_RCV [0c]
	... i2c_slave: i2c-0 a=010 ret=0   STOP []
	... i2c_slave: i2c-0 a=010 ret=0 RD_REQ [04]
	... i2c_slave: i2c-0 a=010 ret=0 RD_PRO [b4]
	... i2c_slave: i2c-0 a=010 ret=0  STOP []

formatted as:

	i2c-<adapter_nr>
	a=<addr>
	ret=<ret>	<- callback return value
	<event>
	[<data>]

trace printings can be selected by adding a filter like:

	echo adapter_nr==1 >/sys/kernel/tracing/events/i2c_slave/filter
Signed-off-by: default avatarJae Hyun Yoo <quic_jaehyoo@quicinc.com>
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent 3364c0ef
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
#include "i2c-core.h" #include "i2c-core.h"
#define CREATE_TRACE_POINTS
#include <trace/events/i2c_slave.h>
int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb) int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb)
{ {
int ret; int ret;
...@@ -79,6 +82,18 @@ int i2c_slave_unregister(struct i2c_client *client) ...@@ -79,6 +82,18 @@ int i2c_slave_unregister(struct i2c_client *client)
} }
EXPORT_SYMBOL_GPL(i2c_slave_unregister); EXPORT_SYMBOL_GPL(i2c_slave_unregister);
int i2c_slave_event(struct i2c_client *client,
enum i2c_slave_event event, u8 *val)
{
int ret = client->slave_cb(client, event, val);
if (trace_i2c_slave_enabled())
trace_i2c_slave(client, event, val, ret);
return ret;
}
EXPORT_SYMBOL_GPL(i2c_slave_event);
/** /**
* i2c_detect_slave_mode - detect operation mode * i2c_detect_slave_mode - detect operation mode
* @dev: The device owning the bus * @dev: The device owning the bus
......
...@@ -392,12 +392,8 @@ enum i2c_slave_event { ...@@ -392,12 +392,8 @@ enum i2c_slave_event {
int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb); int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb);
int i2c_slave_unregister(struct i2c_client *client); int i2c_slave_unregister(struct i2c_client *client);
bool i2c_detect_slave_mode(struct device *dev); bool i2c_detect_slave_mode(struct device *dev);
int i2c_slave_event(struct i2c_client *client,
static inline int i2c_slave_event(struct i2c_client *client, enum i2c_slave_event event, u8 *val);
enum i2c_slave_event event, u8 *val)
{
return client->slave_cb(client, event, val);
}
#else #else
static inline bool i2c_detect_slave_mode(struct device *dev) { return false; } static inline bool i2c_detect_slave_mode(struct device *dev) { return false; }
#endif #endif
......
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* I2C slave tracepoints
*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#undef TRACE_SYSTEM
#define TRACE_SYSTEM i2c_slave
#if !defined(_TRACE_I2C_SLAVE_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_I2C_SLAVE_H
#include <linux/i2c.h>
#include <linux/tracepoint.h>
TRACE_DEFINE_ENUM(I2C_SLAVE_READ_REQUESTED);
TRACE_DEFINE_ENUM(I2C_SLAVE_WRITE_REQUESTED);
TRACE_DEFINE_ENUM(I2C_SLAVE_READ_PROCESSED);
TRACE_DEFINE_ENUM(I2C_SLAVE_WRITE_RECEIVED);
TRACE_DEFINE_ENUM(I2C_SLAVE_STOP);
#define show_event_type(type) \
__print_symbolic(type, \
{ I2C_SLAVE_READ_REQUESTED, "RD_REQ" }, \
{ I2C_SLAVE_WRITE_REQUESTED, "WR_REQ" }, \
{ I2C_SLAVE_READ_PROCESSED, "RD_PRO" }, \
{ I2C_SLAVE_WRITE_RECEIVED, "WR_RCV" }, \
{ I2C_SLAVE_STOP, " STOP" })
TRACE_EVENT(i2c_slave,
TP_PROTO(const struct i2c_client *client, enum i2c_slave_event event,
__u8 *val, int cb_ret),
TP_ARGS(client, event, val, cb_ret),
TP_STRUCT__entry(
__field(int, adapter_nr )
__field(int, ret )
__field(__u16, addr )
__field(__u16, len )
__field(enum i2c_slave_event, event )
__array(__u8, buf, 1) ),
TP_fast_assign(
__entry->adapter_nr = client->adapter->nr;
__entry->addr = client->addr;
__entry->event = event;
__entry->ret = cb_ret;
switch (event) {
case I2C_SLAVE_READ_REQUESTED:
case I2C_SLAVE_READ_PROCESSED:
case I2C_SLAVE_WRITE_RECEIVED:
__entry->len = 1;
memcpy(__entry->buf, val, __entry->len);
break;
default:
__entry->len = 0;
break;
}
),
TP_printk("i2c-%d a=%03x ret=%d %s [%*phD]",
__entry->adapter_nr, __entry->addr, __entry->ret,
show_event_type(__entry->event), __entry->len, __entry->buf
));
#endif /* _TRACE_I2C_SLAVE_H */
/* This part must be outside protection */
#include <trace/define_trace.h>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment