@@ -1232,6 +1232,7 @@ config SPI_TLE62X0
config SPI_MOCKUP
tristate "SPI controller Testing Driver"
+ select BPF_EVENTS
help
This enables SPI controller testing driver, which provides a way to
test SPI subsystem.
@@ -14,6 +14,9 @@
#include <linux/spi/spi.h>
#include <linux/configfs.h>
+#define CREATE_TRACE_POINTS
+#include <trace/events/spi_mockup.h>
+
#define MOCKUP_CHIPSELECT_MAX U16_MAX
struct spi_mockup_host {
@@ -421,13 +424,59 @@ static struct configfs_subsystem spi_mockup_config_subsys = {
}
};
+static int
+spi_mockup_transfer_writeable(struct spi_message *msg)
+{
+ struct spi_msg_ctx *ctx;
+ struct spi_transfer *t;
+ int ret = 0;
+
+ ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC);
+ if (!ctx)
+ return -ENOMEM;
+
+ list_for_each_entry(t, &msg->transfers, transfer_list) {
+ if (t->len > SPI_BUFSIZ_MAX)
+ return -E2BIG;
+
+ memset(ctx, 0, sizeof(*ctx));
+ ctx->cs_off = t->cs_off;
+ ctx->cs_change = t->cs_change;
+ ctx->tx_nbits = t->tx_nbits;
+ ctx->rx_nbits = t->rx_nbits;
+
+ if (t->tx_nbits)
+ memcpy(ctx->data, t->tx_buf, t->len);
+
+ trace_spi_transfer_writeable(ctx, msg->spi->chip_select, t->len);
+
+ if (ctx->ret) {
+ ret = ctx->ret;
+ break;
+ }
+
+ if (t->rx_nbits)
+ memcpy(t->rx_buf, ctx->data, t->len);
+ msg->actual_length += t->len;
+ }
+
+ kfree(ctx);
+
+ return ret;
+}
+
static int
spi_mockup_transfer(struct spi_controller *ctrl, struct spi_message *msg)
{
- msg->status = 0;
+ int ret = 0;
+
+ if (trace_spi_transfer_writeable_enabled())
+ ret = spi_mockup_transfer_writeable(msg);
+
+ msg->status = ret;
spi_finalize_current_message(ctrl);
- return 0;
+ return ret;
}
static int
new file mode 100644
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __LINUX_SPI_MOCKUP_H
+#define __LINUX_SPI_MOCKUP_H
+
+#define SPI_BUFSIZ_MAX 0x1000
+
+struct spi_msg_ctx {
+ int ret;
+ unsigned cs_off:1;
+ unsigned cs_change:1;
+ unsigned tx_nbits:3;
+ unsigned rx_nbits:3;
+ __u8 data[SPI_BUFSIZ_MAX];
+};
+
+#endif
new file mode 100644
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * SPI mockup controller transfer writeable tracepoint
+ *
+ * Copyright(c) 2022 Huawei Technologies Co., Ltd.
+ */
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM spi_mockup
+
+#if !defined(_TRACE_SPI_MOCKUP_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_SPI_MOCKUP_H
+
+#include <linux/tracepoint.h>
+#include <linux/spi/spi-mockup.h>
+
+#ifndef DECLARE_TRACE_WRITABLE
+#define DECLARE_TRACE_WRITABLE(call, proto, args, size) \
+ DECLARE_TRACE(call, PARAMS(proto), PARAMS(args))
+#endif
+
+DECLARE_TRACE_WRITABLE(spi_transfer_writeable,
+ TP_PROTO(struct spi_msg_ctx *msg, u8 chip_select, unsigned int len),
+ TP_ARGS(msg, chip_select, len),
+ sizeof(struct spi_msg_ctx)
+);
+
+#endif /* _TRACE_SPI_MOCKUP_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>