Skip to content

Commit d714fb2

Browse files
Jae Hyun Yoowsakernel
authored andcommitted
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: Jae Hyun Yoo <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 3364c0e commit d714fb2

File tree

3 files changed

+84
-6
lines changed

3 files changed

+84
-6
lines changed

drivers/i2c/i2c-core-slave.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
#include "i2c-core.h"
1616

17+
#define CREATE_TRACE_POINTS
18+
#include <trace/events/i2c_slave.h>
19+
1720
int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb)
1821
{
1922
int ret;
@@ -79,6 +82,18 @@ int i2c_slave_unregister(struct i2c_client *client)
7982
}
8083
EXPORT_SYMBOL_GPL(i2c_slave_unregister);
8184

85+
int i2c_slave_event(struct i2c_client *client,
86+
enum i2c_slave_event event, u8 *val)
87+
{
88+
int ret = client->slave_cb(client, event, val);
89+
90+
if (trace_i2c_slave_enabled())
91+
trace_i2c_slave(client, event, val, ret);
92+
93+
return ret;
94+
}
95+
EXPORT_SYMBOL_GPL(i2c_slave_event);
96+
8297
/**
8398
* i2c_detect_slave_mode - detect operation mode
8499
* @dev: The device owning the bus

include/linux/i2c.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,8 @@ enum i2c_slave_event {
392392
int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb);
393393
int i2c_slave_unregister(struct i2c_client *client);
394394
bool i2c_detect_slave_mode(struct device *dev);
395-
396-
static inline int i2c_slave_event(struct i2c_client *client,
397-
enum i2c_slave_event event, u8 *val)
398-
{
399-
return client->slave_cb(client, event, val);
400-
}
395+
int i2c_slave_event(struct i2c_client *client,
396+
enum i2c_slave_event event, u8 *val);
401397
#else
402398
static inline bool i2c_detect_slave_mode(struct device *dev) { return false; }
403399
#endif

include/trace/events/i2c_slave.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* I2C slave tracepoints
4+
*
5+
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
6+
*/
7+
#undef TRACE_SYSTEM
8+
#define TRACE_SYSTEM i2c_slave
9+
10+
#if !defined(_TRACE_I2C_SLAVE_H) || defined(TRACE_HEADER_MULTI_READ)
11+
#define _TRACE_I2C_SLAVE_H
12+
13+
#include <linux/i2c.h>
14+
#include <linux/tracepoint.h>
15+
16+
TRACE_DEFINE_ENUM(I2C_SLAVE_READ_REQUESTED);
17+
TRACE_DEFINE_ENUM(I2C_SLAVE_WRITE_REQUESTED);
18+
TRACE_DEFINE_ENUM(I2C_SLAVE_READ_PROCESSED);
19+
TRACE_DEFINE_ENUM(I2C_SLAVE_WRITE_RECEIVED);
20+
TRACE_DEFINE_ENUM(I2C_SLAVE_STOP);
21+
22+
#define show_event_type(type) \
23+
__print_symbolic(type, \
24+
{ I2C_SLAVE_READ_REQUESTED, "RD_REQ" }, \
25+
{ I2C_SLAVE_WRITE_REQUESTED, "WR_REQ" }, \
26+
{ I2C_SLAVE_READ_PROCESSED, "RD_PRO" }, \
27+
{ I2C_SLAVE_WRITE_RECEIVED, "WR_RCV" }, \
28+
{ I2C_SLAVE_STOP, " STOP" })
29+
30+
TRACE_EVENT(i2c_slave,
31+
TP_PROTO(const struct i2c_client *client, enum i2c_slave_event event,
32+
__u8 *val, int cb_ret),
33+
TP_ARGS(client, event, val, cb_ret),
34+
TP_STRUCT__entry(
35+
__field(int, adapter_nr )
36+
__field(int, ret )
37+
__field(__u16, addr )
38+
__field(__u16, len )
39+
__field(enum i2c_slave_event, event )
40+
__array(__u8, buf, 1) ),
41+
42+
TP_fast_assign(
43+
__entry->adapter_nr = client->adapter->nr;
44+
__entry->addr = client->addr;
45+
__entry->event = event;
46+
__entry->ret = cb_ret;
47+
switch (event) {
48+
case I2C_SLAVE_READ_REQUESTED:
49+
case I2C_SLAVE_READ_PROCESSED:
50+
case I2C_SLAVE_WRITE_RECEIVED:
51+
__entry->len = 1;
52+
memcpy(__entry->buf, val, __entry->len);
53+
break;
54+
default:
55+
__entry->len = 0;
56+
break;
57+
}
58+
),
59+
TP_printk("i2c-%d a=%03x ret=%d %s [%*phD]",
60+
__entry->adapter_nr, __entry->addr, __entry->ret,
61+
show_event_type(__entry->event), __entry->len, __entry->buf
62+
));
63+
64+
#endif /* _TRACE_I2C_SLAVE_H */
65+
66+
/* This part must be outside protection */
67+
#include <trace/define_trace.h>

0 commit comments

Comments
 (0)