linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next 0/5] spi: Introduce BPF based SPI mockup controller
@ 2023-11-04  6:46 Zhang Xiaoxu
  2023-11-04  6:46 ` [PATCH v3 -next 1/5] spi: mockup: Add SPI controller testing driver Zhang Xiaoxu
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Zhang Xiaoxu @ 2023-11-04  6:46 UTC (permalink / raw)
  To: zhangxiaoxu5, weiyongjun1, broonie, rostedt, mingo, frowand.list,
	linux-spi, linux-kernel

From: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>

v2->v3:
  Add configfs to configure and register the device;
  Fix some misspelling.

v1->v2:
  Use the new _controller() API
  P1. Move the license identifier to the entrie comment
  P2. Inherit tx_nbits/rx_nbits/cs_off/cs_change from the
      spi_transfer to the tracepoint
  P3. Removed.
  P4. Update the Document.

Zhang Xiaoxu (5):
  spi: mockup: Add SPI controller testing driver
  spi: mockup: Add writeable tracepoint for spi transfer
  spi: mockup: Add support register the device through configfs
  spi: mockup: Add speed and flags attribute support
  spi: mockup: Add documentation

 Documentation/spi/index.rst       |   1 +
 Documentation/spi/spi-mockup.rst  | 196 ++++++++++++
 drivers/spi/Kconfig               |  13 +
 drivers/spi/Makefile              |   1 +
 drivers/spi/spi-mockup.c          | 474 ++++++++++++++++++++++++++++++
 include/linux/spi/spi-mockup.h    |  17 ++
 include/trace/events/spi_mockup.h |  31 ++
 7 files changed, 733 insertions(+)
 create mode 100644 Documentation/spi/spi-mockup.rst
 create mode 100644 drivers/spi/spi-mockup.c
 create mode 100644 include/linux/spi/spi-mockup.h
 create mode 100644 include/trace/events/spi_mockup.h

-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 -next 1/5] spi: mockup: Add SPI controller testing driver
  2023-11-04  6:46 [PATCH -next 0/5] spi: Introduce BPF based SPI mockup controller Zhang Xiaoxu
@ 2023-11-04  6:46 ` Zhang Xiaoxu
  2023-11-06 11:59   ` Mark Brown
  2023-11-04  6:46 ` [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer Zhang Xiaoxu
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Zhang Xiaoxu @ 2023-11-04  6:46 UTC (permalink / raw)
  To: zhangxiaoxu5, weiyongjun1, broonie, rostedt, mingo, frowand.list,
	linux-spi, linux-kernel

From: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>

This enables SPI controller Testing driver, which provides a way to
test SPI subsystem.

This is accomplished by executing the following command:

$ echo adcxx1s 0 > /sys/class/spi_master/spi0/new_device

The name of the target driver and its chip select were used to
instantiate the device.

$ ls /sys/bus/spi/devices/spi0.0/hwmon/hwmon0/ -l
 total 0
 lrwxrwxrwx 1 root root    0 Aug 10 08:58 device -> ../../../spi0.0
 drwxr-xr-x 2 root root    0 Aug 10 08:58 power
 lrwxrwxrwx 1 root root    0 Aug 10 08:58 subsystem -> ../../../../../../../../class/hwmon
 -rw-r--r-- 1 root root 4096 Aug 10 08:58 uevent

Remove target device by executing the following command:
$ echo 0 > /sys/class/spi_master/spi0/delete_device

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 drivers/spi/Kconfig      |  12 +++
 drivers/spi/Makefile     |   1 +
 drivers/spi/spi-mockup.c | 211 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 224 insertions(+)
 create mode 100644 drivers/spi/spi-mockup.c

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 2c21d5b96fdc..9169081cfecb 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -1218,6 +1218,18 @@ config SPI_TLE62X0
 	  sysfs interface, with each line presented as a kind of GPIO
 	  exposing both switch control and diagnostic feedback.
 
+config SPI_MOCKUP
+	tristate "SPI controller Testing Driver"
+	depends on OF
+	help
+	  This enables SPI controller testing driver, which provides a way to
+	  test SPI subsystem.
+
+	  If you do build this module, be sure to read the notes and warnings
+	  in <file:Documentation/spi/spi-mockup.rst>.
+
+	  If you don't know what to do here, definitely say N.
+
 #
 # Add new SPI protocol masters in alphabetical order above this line
 #
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 6af54842b9fa..f28074e61df9 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_SPI_MEM)			+= spi-mem.o
 obj-$(CONFIG_SPI_MUX)			+= spi-mux.o
 obj-$(CONFIG_SPI_SPIDEV)		+= spidev.o
 obj-$(CONFIG_SPI_LOOPBACK_TEST)		+= spi-loopback-test.o
+obj-$(CONFIG_SPI_MOCKUP)		+= spi-mockup.o
 
 # SPI master controller drivers (bus)
 obj-$(CONFIG_SPI_ALTERA)		+= spi-altera-platform.o
diff --git a/drivers/spi/spi-mockup.c b/drivers/spi/spi-mockup.c
new file mode 100644
index 000000000000..683a0fc43f0d
--- /dev/null
+++ b/drivers/spi/spi-mockup.c
@@ -0,0 +1,211 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * SPI controller Testing Driver
+ *
+ * Copyright(c) 2022 Huawei Technologies Co., Ltd.
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+
+#define MOCKUP_CHIPSELECT_MAX		8
+
+struct mockup_spi {
+	struct mutex lock;
+	struct spi_device *devs[MOCKUP_CHIPSELECT_MAX];
+};
+
+static struct spi_controller *to_spi_controller(struct device *dev)
+{
+	return container_of(dev, struct spi_controller, dev);
+}
+
+static ssize_t
+new_device_store(struct device *dev, struct device_attribute *attr,
+		 const char *buf, size_t count)
+{
+	struct spi_controller *ctrl = to_spi_controller(dev);
+	struct spi_board_info info;
+	struct mockup_spi *mock;
+	struct spi_device *spi;
+	char *blank, end;
+	int status;
+
+	memset(&info, 0, sizeof(struct spi_board_info));
+
+	blank = strchr(buf, ' ');
+	if (!blank) {
+		dev_err(dev, "%s: Extra parameters\n", "new_device");
+		return -EINVAL;
+	}
+
+	if (blank - buf > SPI_NAME_SIZE - 1) {
+		dev_err(dev, "%s: Invalid device name\n", "new_device");
+		return -EINVAL;
+	}
+
+	memcpy(info.modalias, buf, blank - buf);
+
+	status = sscanf(++blank, "%hi%c", &info.chip_select, &end);
+	if (status < 1) {
+		dev_err(dev, "%s: Can't parse SPI chipselect\n", "new_device");
+		return -EINVAL;
+	}
+
+	if (status > 1 && end != '\n') {
+		dev_err(dev, "%s: Extra parameters\n", "new_device");
+		return -EINVAL;
+	}
+
+	if (info.chip_select >= ctrl->num_chipselect) {
+		dev_err(dev, "%s: Invalid chip_select\n", "new_device");
+		return -EINVAL;
+	}
+
+	mock = spi_controller_get_devdata(ctrl);
+	mutex_lock(&mock->lock);
+
+	if (mock->devs[info.chip_select]) {
+		dev_err(dev, "%s: Chipselect %d already in use\n",
+			"new_device", info.chip_select);
+		mutex_unlock(&mock->lock);
+		return -EINVAL;
+	}
+
+	spi = spi_new_device(ctrl, &info);
+	if (!spi) {
+		mutex_unlock(&mock->lock);
+		return -ENOMEM;
+	}
+	mock->devs[info.chip_select] = spi;
+
+	mutex_unlock(&mock->lock);
+
+	dev_info(dev, "%s: Instantiated device %s at 0x%02x\n", "new_device",
+		 info.modalias, info.chip_select);
+
+	return count;
+}
+static DEVICE_ATTR_WO(new_device);
+
+static ssize_t
+delete_device_store(struct device *dev, struct device_attribute *attr,
+		    const char *buf, size_t count)
+{
+	struct spi_controller *ctrl = to_spi_controller(dev);
+	struct mockup_spi *mock;
+	struct spi_device *spi;
+	unsigned short chip;
+	char end;
+	int res;
+
+	/* Parse parameters, reject extra parameters */
+	res = sscanf(buf, "%hi%c", &chip, &end);
+	if (res < 1) {
+		dev_err(dev, "%s: Can't parse SPI address\n", "delete_device");
+		return -EINVAL;
+	}
+	if (res > 1  && end != '\n') {
+		dev_err(dev, "%s: Extra parameters\n", "delete_device");
+		return -EINVAL;
+	}
+
+	if (chip >= ctrl->num_chipselect) {
+		dev_err(dev, "%s: Invalid chip_select\n", "delete_device");
+		return -EINVAL;
+	}
+
+	mock = spi_controller_get_devdata(ctrl);
+	mutex_lock(&mock->lock);
+
+	spi = mock->devs[chip];
+	if (!spi) {
+		mutex_unlock(&mock->lock);
+		dev_err(dev, "%s: Invalid chip_select\n", "delete_device");
+		return -ENOENT;
+	}
+
+	dev_info(dev, "%s: Deleting device %s at 0x%02hx\n", "delete_device",
+		 dev_name(&spi->dev), chip);
+
+	spi_unregister_device(spi);
+	mock->devs[chip] = NULL;
+
+	mutex_unlock(&mock->lock);
+
+	return count;
+}
+static DEVICE_ATTR_WO(delete_device);
+
+static struct attribute *spi_mockup_attrs[] = {
+	&dev_attr_new_device.attr,
+	&dev_attr_delete_device.attr,
+	NULL
+};
+ATTRIBUTE_GROUPS(spi_mockup);
+
+static int spi_mockup_transfer(struct spi_controller *ctrl,
+			       struct spi_message *msg)
+{
+	msg->status = 0;
+	spi_finalize_current_message(ctrl);
+
+	return 0;
+}
+
+static int spi_mockup_probe(struct platform_device *pdev)
+{
+	int ret;
+	struct mockup_spi *mock;
+	struct spi_controller *ctrl;
+
+	ctrl = spi_alloc_host(&pdev->dev, sizeof(struct mockup_spi));
+	if (!ctrl) {
+		pr_err("failed to alloc spi controller\n");
+		return -ENOMEM;
+	}
+
+	platform_set_drvdata(pdev, ctrl);
+
+	ctrl->dev.of_node = pdev->dev.of_node;
+	ctrl->dev.groups = spi_mockup_groups;
+	ctrl->num_chipselect = MOCKUP_CHIPSELECT_MAX;
+	ctrl->mode_bits = SPI_MODE_USER_MASK;
+	ctrl->bus_num = 0;
+	ctrl->transfer_one_message = spi_mockup_transfer;
+
+	mock = spi_controller_get_devdata(ctrl);
+	mutex_init(&mock->lock);
+
+	ret = devm_spi_register_controller(&pdev->dev, ctrl);
+	if (ret) {
+		spi_controller_put(ctrl);
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct of_device_id spi_mockup_match[] = {
+	{ .compatible = "spi-mockup", },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, spi_mockup_match);
+
+static struct platform_driver spi_mockup_driver = {
+	.probe = spi_mockup_probe,
+	.driver = {
+		.name = "spi-mockup",
+		.of_match_table = spi_mockup_match,
+	},
+};
+module_platform_driver(spi_mockup_driver);
+
+MODULE_AUTHOR("Wei Yongjun <weiyongjun1@huawei.com>");
+MODULE_DESCRIPTION("SPI controller Testing Driver");
+MODULE_LICENSE("GPL");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer
  2023-11-04  6:46 [PATCH -next 0/5] spi: Introduce BPF based SPI mockup controller Zhang Xiaoxu
  2023-11-04  6:46 ` [PATCH v3 -next 1/5] spi: mockup: Add SPI controller testing driver Zhang Xiaoxu
@ 2023-11-04  6:46 ` Zhang Xiaoxu
  2023-11-04  9:58   ` kernel test robot
  2023-11-04 11:10   ` kernel test robot
  2023-11-04  6:46 ` [PATCH v3 -next 3/5] spi: mockup: Add support register the device through configfs Zhang Xiaoxu
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 12+ messages in thread
From: Zhang Xiaoxu @ 2023-11-04  6:46 UTC (permalink / raw)
  To: zhangxiaoxu5, weiyongjun1, broonie, rostedt, mingo, frowand.list,
	linux-spi, linux-kernel

From: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>

Add writeable tracepoint for transfer_one_message(), then bpf program
can be used to control read and write data from spi host, as mockup
chip's expectation.

For example:

  #include "vmlinux.h"
  #include <bpf/bpf_helpers.h>
  #include <bpf/bpf_tracing.h>

  SEC("raw_tp.w/spi_transfer_writeable")
  int BPF_PROG(spi_transfer_writeable_test, struct spi_msg_ctx *msg,
               u8 chip, unsigned int len)
  {
      if (msg->tx_nbits)
          msg->data[0] = 0x20;

      return 0;
  }

  char LICENSE[] SEC("license") = "GPL";

This will be useful for writing spi device mockup backend.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 drivers/spi/Kconfig               |  1 +
 drivers/spi/spi-mockup.c          | 52 +++++++++++++++++++++++++++++--
 include/linux/spi/spi-mockup.h    | 17 ++++++++++
 include/trace/events/spi_mockup.h | 31 ++++++++++++++++++
 4 files changed, 99 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/spi/spi-mockup.h
 create mode 100644 include/trace/events/spi_mockup.h

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 9169081cfecb..871e3824b8eb 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -1221,6 +1221,7 @@ config SPI_TLE62X0
 config SPI_MOCKUP
 	tristate "SPI controller Testing Driver"
 	depends on OF
+	select BPF_EVENTS
 	help
 	  This enables SPI controller testing driver, which provides a way to
 	  test SPI subsystem.
diff --git a/drivers/spi/spi-mockup.c b/drivers/spi/spi-mockup.c
index 683a0fc43f0d..fcaaa61bdb38 100644
--- a/drivers/spi/spi-mockup.c
+++ b/drivers/spi/spi-mockup.c
@@ -13,6 +13,9 @@
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/spi_mockup.h>
+
 #define MOCKUP_CHIPSELECT_MAX		8
 
 struct mockup_spi {
@@ -149,13 +152,58 @@ static struct attribute *spi_mockup_attrs[] = {
 };
 ATTRIBUTE_GROUPS(spi_mockup);
 
+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 spi_mockup_probe(struct platform_device *pdev)
diff --git a/include/linux/spi/spi-mockup.h b/include/linux/spi/spi-mockup.h
new file mode 100644
index 000000000000..224894b416fb
--- /dev/null
+++ b/include/linux/spi/spi-mockup.h
@@ -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
diff --git a/include/trace/events/spi_mockup.h b/include/trace/events/spi_mockup.h
new file mode 100644
index 000000000000..46debf26a5e3
--- /dev/null
+++ b/include/trace/events/spi_mockup.h
@@ -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>
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 -next 3/5] spi: mockup: Add support register the device through configfs
  2023-11-04  6:46 [PATCH -next 0/5] spi: Introduce BPF based SPI mockup controller Zhang Xiaoxu
  2023-11-04  6:46 ` [PATCH v3 -next 1/5] spi: mockup: Add SPI controller testing driver Zhang Xiaoxu
  2023-11-04  6:46 ` [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer Zhang Xiaoxu
@ 2023-11-04  6:46 ` Zhang Xiaoxu
  2023-11-04  6:46 ` [PATCH v3 -next 4/5] spi: mockup: Add speed and flags attribute support Zhang Xiaoxu
  2023-11-04  6:46 ` [PATCH v3 -next 5/5] spi: mockup: Add documentation Zhang Xiaoxu
  4 siblings, 0 replies; 12+ messages in thread
From: Zhang Xiaoxu @ 2023-11-04  6:46 UTC (permalink / raw)
  To: zhangxiaoxu5, weiyongjun1, broonie, rostedt, mingo, frowand.list,
	linux-spi, linux-kernel

From: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>

This enable/disable the spi mockup device through the configfs:

  mkdir /sys/kernel/config/spi-mockup/spi0

  echo 1 > /sys/kernel/config/spi-mockup/spi0/enable
  echo 1 > /sys/kernel/config/spi-mockup/spi0/disable

Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 drivers/spi/spi-mockup.c | 163 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 161 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-mockup.c b/drivers/spi/spi-mockup.c
index fcaaa61bdb38..b449a2b7cdd4 100644
--- a/drivers/spi/spi-mockup.c
+++ b/drivers/spi/spi-mockup.c
@@ -12,6 +12,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
+#include <linux/configfs.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/spi_mockup.h>
@@ -224,7 +225,7 @@ static int spi_mockup_probe(struct platform_device *pdev)
 	ctrl->dev.groups = spi_mockup_groups;
 	ctrl->num_chipselect = MOCKUP_CHIPSELECT_MAX;
 	ctrl->mode_bits = SPI_MODE_USER_MASK;
-	ctrl->bus_num = 0;
+	ctrl->bus_num = pdev->id;
 	ctrl->transfer_one_message = spi_mockup_transfer;
 
 	mock = spi_controller_get_devdata(ctrl);
@@ -252,7 +253,165 @@ static struct platform_driver spi_mockup_driver = {
 		.of_match_table = spi_mockup_match,
 	},
 };
-module_platform_driver(spi_mockup_driver);
+
+struct spi_mockup_device {
+	struct config_group group;
+	unsigned int bus_nr;
+	struct mutex lock;
+	struct platform_device *pdev;
+};
+
+static struct spi_mockup_device *to_spi_mockup_dev(struct config_item *item)
+{
+	struct config_group *group = to_config_group(item);
+
+	return container_of(group, struct spi_mockup_device, group);
+}
+
+static ssize_t
+spi_mockup_enable_store(struct config_item *item, const char *page, size_t len)
+{
+	int ret = len;
+	struct platform_device_info pdevinfo = {0};
+	struct spi_mockup_device *dev = to_spi_mockup_dev(item);
+
+	mutex_lock(&dev->lock);
+	if (dev->pdev) {
+		ret = -EEXIST;
+		goto out;
+	}
+
+	pdevinfo.name = "spi-mockup";
+	pdevinfo.id = dev->bus_nr;
+	dev->pdev = platform_device_register_full(&pdevinfo);
+	if (IS_ERR(dev->pdev)) {
+		ret = PTR_ERR(dev->pdev);
+		dev->pdev = NULL;
+		goto out;
+	}
+out:
+	mutex_unlock(&dev->lock);
+	return ret;
+}
+CONFIGFS_ATTR_WO(spi_mockup_, enable);
+
+static ssize_t
+spi_mockup_disable_store(struct config_item *item, const char *page, size_t len)
+{
+	int ret = len;
+	struct spi_mockup_device *dev = to_spi_mockup_dev(item);
+
+	mutex_lock(&dev->lock);
+	if (!dev->pdev) {
+		ret = -ENODEV;
+		goto out;
+	}
+
+	platform_device_unregister(dev->pdev);
+	dev->pdev = NULL;
+out:
+	mutex_unlock(&dev->lock);
+	return ret;
+}
+CONFIGFS_ATTR_WO(spi_mockup_, disable);
+
+static struct configfs_attribute *spi_mockup_configfs_attrs[] = {
+	&spi_mockup_attr_enable,
+	&spi_mockup_attr_disable,
+	NULL,
+};
+
+static const struct config_item_type spi_mockup_device_config_group_type = {
+	.ct_owner	= THIS_MODULE,
+	.ct_attrs	= spi_mockup_configfs_attrs,
+};
+
+static struct config_group *
+spi_mockup_config_make_device_group(struct config_group *group,
+				    const char *name)
+{
+	int ret, nchar;
+	unsigned int nr;
+	struct spi_mockup_device *dev;
+
+	ret = sscanf(name, "spi%u%n", &nr, &nchar);
+	if (ret != 1 || nchar != strlen(name))
+		return ERR_PTR(-EINVAL);
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return ERR_PTR(-ENOMEM);
+
+	dev->bus_nr = nr;
+	mutex_init(&dev->lock);
+
+	config_group_init_type_name(&dev->group, name,
+				    &spi_mockup_device_config_group_type);
+
+	return &dev->group;
+}
+
+static void spi_mockup_config_group_release(struct config_item *item)
+{
+	struct spi_mockup_device *dev = to_spi_mockup_dev(item);
+
+	kfree(dev);
+}
+
+static struct configfs_item_operations spi_mockup_config_item_ops = {
+	.release = spi_mockup_config_group_release,
+};
+
+static struct configfs_group_operations spi_mockup_config_group_ops = {
+	.make_group = spi_mockup_config_make_device_group,
+};
+
+static const struct config_item_type spi_mockup_config_type = {
+	.ct_owner	= THIS_MODULE,
+	.ct_group_ops	= &spi_mockup_config_group_ops,
+	.ct_item_ops	= &spi_mockup_config_item_ops,
+};
+
+static struct configfs_subsystem spi_mockup_config_subsys = {
+	.su_group = {
+		.cg_item = {
+			.ci_namebuf = "spi-mockup",
+			.ci_type = &spi_mockup_config_type,
+		}
+	}
+};
+
+static int __init spi_mockup_init(void)
+{
+	int ret;
+
+	ret = platform_driver_register(&spi_mockup_driver);
+	if (ret) {
+		pr_err("spi mockup driver registering failed with %d\n", ret);
+		return ret;
+	}
+
+	config_group_init(&spi_mockup_config_subsys.su_group);
+	mutex_init(&spi_mockup_config_subsys.su_mutex);
+	ret = configfs_register_subsystem(&spi_mockup_config_subsys);
+	if (ret) {
+		pr_err("spi mockup configfs registering failed with %d\n", ret);
+		mutex_destroy(&spi_mockup_config_subsys.su_mutex);
+		platform_driver_unregister(&spi_mockup_driver);
+		return ret;
+	}
+
+	return ret;
+}
+module_init(spi_mockup_init);
+
+static void __exit spi_mockup_exit(void)
+{
+	configfs_unregister_subsystem(&spi_mockup_config_subsys);
+	mutex_destroy(&spi_mockup_config_subsys.su_mutex);
+	return platform_driver_unregister(&spi_mockup_driver);
+}
+module_exit(spi_mockup_exit);
 
 MODULE_AUTHOR("Wei Yongjun <weiyongjun1@huawei.com>");
 MODULE_DESCRIPTION("SPI controller Testing Driver");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 -next 4/5] spi: mockup: Add speed and flags attribute support
  2023-11-04  6:46 [PATCH -next 0/5] spi: Introduce BPF based SPI mockup controller Zhang Xiaoxu
                   ` (2 preceding siblings ...)
  2023-11-04  6:46 ` [PATCH v3 -next 3/5] spi: mockup: Add support register the device through configfs Zhang Xiaoxu
@ 2023-11-04  6:46 ` Zhang Xiaoxu
  2023-11-04 11:10   ` kernel test robot
  2023-11-04  6:46 ` [PATCH v3 -next 5/5] spi: mockup: Add documentation Zhang Xiaoxu
  4 siblings, 1 reply; 12+ messages in thread
From: Zhang Xiaoxu @ 2023-11-04  6:46 UTC (permalink / raw)
  To: zhangxiaoxu5, weiyongjun1, broonie, rostedt, mingo, frowand.list,
	linux-spi, linux-kernel

From: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>

This enable configure the spi speed and flags through configfs:

  echo 40000 > /sys/kernel/config/spi-mockup/spi0/min_speed
  echo 25000000 > /sys/kernel/config/spi-mockup/spi0/max_speed
  echo 0 > /sys/kernel/config/spi-mockup/spi0/flags
  echo 8 > /sys/kernel/config/spi-mockup/spi0/num_cs

Then enable the device can use the special config:

  echo 1 > /sys/kernel/config/spi-mockup/spi0/enable

Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 drivers/spi/spi-mockup.c | 55 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/drivers/spi/spi-mockup.c b/drivers/spi/spi-mockup.c
index b449a2b7cdd4..06848504d144 100644
--- a/drivers/spi/spi-mockup.c
+++ b/drivers/spi/spi-mockup.c
@@ -207,11 +207,19 @@ static int spi_mockup_transfer(struct spi_controller *ctrl,
 	return ret;
 }
 
+struct spi_mockup_priv_data {
+	u32 min_speed;
+	u32 max_speed;
+	u16 flags;
+	u16 num_cs;
+};
+
 static int spi_mockup_probe(struct platform_device *pdev)
 {
 	int ret;
 	struct mockup_spi *mock;
 	struct spi_controller *ctrl;
+	struct spi_mockup_priv_data *data;
 
 	ctrl = spi_alloc_host(&pdev->dev, sizeof(struct mockup_spi));
 	if (!ctrl) {
@@ -228,6 +236,14 @@ static int spi_mockup_probe(struct platform_device *pdev)
 	ctrl->bus_num = pdev->id;
 	ctrl->transfer_one_message = spi_mockup_transfer;
 
+	data = dev_get_platdata(&pdev->dev);
+	if (data) {
+		ctrl->min_speed_hz = data->min_speed;
+		ctrl->max_speed_hz = data->max_speed;
+		ctrl->flags = data->flags;
+		ctrl->num_chipselect = data->num_cs;
+	}
+
 	mock = spi_controller_get_devdata(ctrl);
 	mutex_init(&mock->lock);
 
@@ -259,6 +275,7 @@ struct spi_mockup_device {
 	unsigned int bus_nr;
 	struct mutex lock;
 	struct platform_device *pdev;
+	struct spi_mockup_priv_data data;
 };
 
 static struct spi_mockup_device *to_spi_mockup_dev(struct config_item *item)
@@ -283,6 +300,9 @@ spi_mockup_enable_store(struct config_item *item, const char *page, size_t len)
 
 	pdevinfo.name = "spi-mockup";
 	pdevinfo.id = dev->bus_nr;
+	pdevinfo.data = &dev->data;
+	pdevinfo.size_data = sizeof(dev->data);
+
 	dev->pdev = platform_device_register_full(&pdevinfo);
 	if (IS_ERR(dev->pdev)) {
 		ret = PTR_ERR(dev->pdev);
@@ -315,9 +335,43 @@ spi_mockup_disable_store(struct config_item *item, const char *page, size_t len)
 }
 CONFIGFS_ATTR_WO(spi_mockup_, disable);
 
+#define SPI_MOCKUP_ATTR(type, name) \
+static ssize_t spi_mockup_ ## name ## _store(struct config_item *item,	   \
+					     const char *page, size_t len) \
+{									   \
+	int ret;							   \
+	type val;							   \
+	struct spi_mockup_device *dev = to_spi_mockup_dev(item);	   \
+									   \
+	mutex_lock(&dev->lock);						   \
+	if (dev->pdev) {						   \
+		ret = -EBUSY;						   \
+		goto out;						   \
+	}								   \
+									   \
+	ret = kstrto ## type(page, 0, &val);				   \
+	if (ret)							   \
+		goto out;						   \
+									   \
+	dev->data.name = val;						   \
+out:									   \
+	mutex_unlock(&dev->lock);					   \
+	return ret ? ret : len;						   \
+}									   \
+CONFIGFS_ATTR_WO(spi_mockup_, name)					   \
+
+SPI_MOCKUP_ATTR(u32, min_speed)
+SPI_MOCKUP_ATTR(u32, max_speed)
+SPI_MOCKUP_ATTR(u16, flags)
+SPI_MOCKUP_ATTR(u16, num_cs)
+
 static struct configfs_attribute *spi_mockup_configfs_attrs[] = {
 	&spi_mockup_attr_enable,
 	&spi_mockup_attr_disable,
+	&spi_mockup_attr_min_speed,
+	&spi_mockup_attr_max_speed,
+	&spi_mockup_attr_flags,
+	&spi_mockup_attr_num_cs,
 	NULL,
 };
 
@@ -342,6 +396,7 @@ spi_mockup_config_make_device_group(struct config_group *group,
 	if (!dev)
 		return ERR_PTR(-ENOMEM);
 
+	dev->data.num_cs = MOCKUP_CHIPSELECT_MAX;
 	dev->bus_nr = nr;
 	mutex_init(&dev->lock);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 -next 5/5] spi: mockup: Add documentation
  2023-11-04  6:46 [PATCH -next 0/5] spi: Introduce BPF based SPI mockup controller Zhang Xiaoxu
                   ` (3 preceding siblings ...)
  2023-11-04  6:46 ` [PATCH v3 -next 4/5] spi: mockup: Add speed and flags attribute support Zhang Xiaoxu
@ 2023-11-04  6:46 ` Zhang Xiaoxu
  2023-11-06 13:09   ` Mark Brown
  4 siblings, 1 reply; 12+ messages in thread
From: Zhang Xiaoxu @ 2023-11-04  6:46 UTC (permalink / raw)
  To: zhangxiaoxu5, weiyongjun1, broonie, rostedt, mingo, frowand.list,
	linux-spi, linux-kernel

From: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>

Add documentation for the SPI mockup controller driver.
This include the tutorial for how to mockup a spi device.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 Documentation/spi/index.rst      |   1 +
 Documentation/spi/spi-mockup.rst | 196 +++++++++++++++++++++++++++++++
 2 files changed, 197 insertions(+)
 create mode 100644 Documentation/spi/spi-mockup.rst

diff --git a/Documentation/spi/index.rst b/Documentation/spi/index.rst
index 06c34ea11bcf..a8f4f5cd0f09 100644
--- a/Documentation/spi/index.rst
+++ b/Documentation/spi/index.rst
@@ -13,6 +13,7 @@ Serial Peripheral Interface (SPI)
    pxa2xx
    spi-lm70llp
    spi-sc18is602
+   spi-mockup
 
 .. only::  subproject and html
 
diff --git a/Documentation/spi/spi-mockup.rst b/Documentation/spi/spi-mockup.rst
new file mode 100644
index 000000000000..dd9feb81535e
--- /dev/null
+++ b/Documentation/spi/spi-mockup.rst
@@ -0,0 +1,196 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==========
+spi-mockup
+==========
+
+Description
+===========
+
+This module is a very simple fake SPI controller driver. It implements
+a BPF based interface to mockup SPI device.
+
+No hardware is needed nor associated with this module. It will respond
+spi message by BPF program attached to spi_transfer_writeable tracepoint
+by reading from or writing BPF maps.
+
+The typical use-case is like this:
+        1. load EBPF program as device's backend
+        2. create target chip device
+
+Example
+=======
+
+This example show how to mock a MTD device by using spi-mockup driver.
+
+Compile your copy of the kernel source. Make sure to configure the spi-mockup
+and the target chip driver as a module.
+
+Register the spi mockup device.
+
+::
+
+  $ mkdir /sys/kernel/config/spi-mockup/spi0
+
+  # configure the spi mockup attribute
+  $ echo 40000 > /sys/kernel/config/spi-mockup/spi0/min_speed
+  $ echo 25000000 > /sys/kernel/config/spi-mockup/spi0/max_speed
+  $ echo 0 > /sys/kernel/config/spi-mockup/spi0/flags
+  $ echo 8 > /sys/kernel/config/spi-mockup/spi0/num_cs
+
+  # enable the spi mockup device
+  $ echo 1 > /sys/kernel/config/spi-mockup/spi0/enable
+
+Write a BPF program as device's backup.
+
+::
+
+  #define MCHP23K256_CMD_WRITE_STATUS   0x01
+  #define MCHP23K256_CMD_WRITE          0x02
+  #define MCHP23K256_CMD_READ           0x03
+
+  #define CHIP_REGS_SIZE		0x20000
+
+  #define MAX_CMD_SIZE		        4
+
+  struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, CHIP_REGS_SIZE);
+	__type(key, __u32);
+	__type(value, __u8);
+  } regs_mchp23k256 SEC(".maps");
+
+  static unsigned int chip_reg = 0;
+
+  static int spi_transfer_read(struct spi_msg_ctx *msg, unsigned int len)
+  {
+	int i, key;
+	u8 *reg;
+
+	for (i = 0; i < len && i < sizeof(msg->data); i++) {
+		key = i + chip_reg;
+
+		reg = bpf_map_lookup_elem(&regs_mchp23k256, &key);
+		if (!reg) {
+			bpf_printk("key %d not exists", key);
+			return -EINVAL;
+		}
+
+		msg->data[i] = *reg;
+	}
+
+	return 0;
+  }
+
+  static int spi_transfer_write(struct spi_msg_ctx *msg, unsigned int len)
+  {
+	u8 opcode = msg->data[0], value;
+	int i, key;
+
+	switch (opcode) {
+	case MCHP23K256_CMD_READ:
+	case MCHP23K256_CMD_WRITE:
+		if (len < 2)
+			return -EINVAL;
+
+		chip_reg = 0;
+		for (i = 0; i < MAX_CMD_SIZE && i < len - 1; i++)
+			chip_reg = (chip_reg << 8) + msg->data[1 + i];
+
+		return 0;
+	case MCHP23K256_CMD_WRITE_STATUS:
+		// ignore write status
+		return 0;
+	default:
+		break;
+	}
+
+	for (i = 0; i < len && i < sizeof(msg->data); i++) {
+		value = msg->data[i];
+		key = chip_reg + i;
+
+		if (bpf_map_update_elem(&regs_mchp23k256, &key, &value,
+					BPF_EXIST)) {
+			bpf_printk("key %d not exists", key);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+  }
+
+  SEC("raw_tp.w/spi_transfer_writeable")
+  int BPF_PROG(mtd_mchp23k256, struct spi_msg_ctx *msg, u8 chip, unsigned int len)
+  {
+	int ret = 0;
+
+	if (msg->tx_nbits)
+		ret = spi_transfer_write(msg, len);
+	else if (msg->rx_nbits)
+		ret = spi_transfer_read(msg, len);
+
+	return ret;
+  }
+
+  char LICENSE[] SEC("license") = "GPL";
+
+Use bpftool to load the BPF program.
+
+::
+
+  $ bpftool prog load mtd-mchp23k256.o /sys/fs/bpf/mtd_mchp23k256 autoattach
+
+
+This is accomplished by executing the following command:
+
+::
+
+  $ echo mchp23k256 0 > /sys/class/spi_master/spi0/new_device
+
+
+The name of the target driver and its chip select were used to instantiate
+the device.
+
+Now, the mchp23k256 MTD device named /dev/mtd0 has been created successfully.
+
+::
+
+  $ ls /sys/bus/spi/devices/spi0.0/mtd/
+  mtd0  mtd0ro
+
+  $ cat /sys/class/mtd/mtd0/name
+  spi0.0
+
+  $ hexdump /dev/mtd0
+  0000000 0000 0000 0000 0000 0000 0000 0000 0000
+  *
+  0008000
+
+  $echo aaaa > /dev/mtd0
+
+  $ hexdump /dev/mtd0
+  0000000 6161 6161 000a 0000 0000 0000 0000 0000
+  0000010 0000 0000 0000 0000 0000 0000 0000 0000
+  *
+  0008000
+
+  $ bpftool map update name regs_mchp23k256 key 0 0 0 0 value 0
+
+  $ hexdump /dev/mtd0
+  0000000 6100 6161 000a 0000 0000 0000 0000 0000
+  0000010 0000 0000 0000 0000 0000 0000 0000 0000
+  *
+  0008000
+
+Remove the mockup device by executing the following command:
+
+::
+
+  $ echo 0 > /sys/class/spi_master/spi0/delete_device
+
+Remove the spi mockup device by executing the following command:
+
+::
+
+  $ echo 0 > /sys/kernel/config/spi-mockup/spi0/disable
+  $ rmdir /sys/kernel/config/spi-mockup/spi0
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer
  2023-11-04  6:46 ` [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer Zhang Xiaoxu
@ 2023-11-04  9:58   ` kernel test robot
  2023-11-04 11:10   ` kernel test robot
  1 sibling, 0 replies; 12+ messages in thread
From: kernel test robot @ 2023-11-04  9:58 UTC (permalink / raw)
  To: Zhang Xiaoxu, zhangxiaoxu5, weiyongjun1, broonie, rostedt, mingo,
	frowand.list, linux-spi, linux-kernel
  Cc: oe-kbuild-all

Hi Zhang,

kernel test robot noticed the following build warnings:

[auto build test WARNING on next-20231103]

url:    https://github.com/intel-lab-lkp/linux/commits/Zhang-Xiaoxu/spi-mockup-Add-SPI-controller-testing-driver/20231104-144859
base:   next-20231103
patch link:    https://lore.kernel.org/r/20231104064650.972687-3-zhangxiaoxu%40huaweicloud.com
patch subject: [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20231104/202311041721.m13CvbG0-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231104/202311041721.m13CvbG0-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311041721.m13CvbG0-lkp@intel.com/

All warnings (new ones prefixed by >>):

    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                                         ^~
   include/asm-generic/rwonce.h:55:27: note: in definition of macro '__WRITE_ONCE'
      55 |         *(volatile typeof(x) *)&(x) = (val);                            \
         |                           ^
   include/asm-generic/barrier.h:198:9: note: in expansion of macro 'WRITE_ONCE'
     198 |         WRITE_ONCE(*p, v);                                              \
         |         ^~~~~~~~~~
   include/linux/rcupdate.h:500:17: note: in expansion of macro 'smp_store_release'
     500 |                 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
         |                 ^~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:17: note: in expansion of macro 'rcu_assign_pointer'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                 ^~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:41: error: 'struct perf_event' has no member named 'tp_event'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                                         ^~
   include/asm-generic/rwonce.h:55:34: note: in definition of macro '__WRITE_ONCE'
      55 |         *(volatile typeof(x) *)&(x) = (val);                            \
         |                                  ^
   include/asm-generic/barrier.h:198:9: note: in expansion of macro 'WRITE_ONCE'
     198 |         WRITE_ONCE(*p, v);                                              \
         |         ^~~~~~~~~~
   include/linux/rcupdate.h:500:17: note: in expansion of macro 'smp_store_release'
     500 |                 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
         |                 ^~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:17: note: in expansion of macro 'rcu_assign_pointer'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                 ^~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:41: error: 'struct perf_event' has no member named 'tp_event'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                                         ^~
   include/asm-generic/rwonce.h:55:40: note: in definition of macro '__WRITE_ONCE'
      55 |         *(volatile typeof(x) *)&(x) = (val);                            \
         |                                        ^~~
   include/asm-generic/barrier.h:198:9: note: in expansion of macro 'WRITE_ONCE'
     198 |         WRITE_ONCE(*p, v);                                              \
         |         ^~~~~~~~~~
   include/linux/rcupdate.h:500:17: note: in expansion of macro 'smp_store_release'
     500 |                 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
         |                 ^~~~~~~~~~~~~~~~~
   include/linux/rcupdate.h:500:39: note: in expansion of macro 'RCU_INITIALIZER'
     500 |                 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
         |                                       ^~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:17: note: in expansion of macro 'rcu_assign_pointer'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                 ^~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:41: error: 'struct perf_event' has no member named 'tp_event'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                                         ^~
   include/asm-generic/rwonce.h:55:40: note: in definition of macro '__WRITE_ONCE'
      55 |         *(volatile typeof(x) *)&(x) = (val);                            \
         |                                        ^~~
   include/asm-generic/barrier.h:198:9: note: in expansion of macro 'WRITE_ONCE'
     198 |         WRITE_ONCE(*p, v);                                              \
         |         ^~~~~~~~~~
   include/linux/rcupdate.h:500:17: note: in expansion of macro 'smp_store_release'
     500 |                 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
         |                 ^~~~~~~~~~~~~~~~~
   include/linux/rcupdate.h:500:39: note: in expansion of macro 'RCU_INITIALIZER'
     500 |                 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
         |                                       ^~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:17: note: in expansion of macro 'rcu_assign_pointer'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                 ^~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2225:27: error: 'struct perf_event' has no member named 'prog'
    2225 |         bpf_prog_put(event->prog);
         |                           ^~
   kernel/trace/bpf_trace.c:2226:14: error: 'struct perf_event' has no member named 'prog'
    2226 |         event->prog = NULL;
         |              ^~
   kernel/trace/bpf_trace.c: In function 'perf_event_query_prog_array':
   kernel/trace/bpf_trace.c:2242:18: error: 'struct perf_event' has no member named 'attr'
    2242 |         if (event->attr.type != PERF_TYPE_TRACEPOINT)
         |                  ^~
   kernel/trace/bpf_trace.c:2261:48: error: 'struct perf_event' has no member named 'tp_event'
    2261 |         progs = bpf_event_rcu_dereference(event->tp_event->prog_array);
         |                                                ^~
   include/linux/rcupdate.h:445:19: note: in definition of macro '__rcu_dereference_protected'
     445 |         ((typeof(*p) __force __kernel *)(p)); \
         |                   ^
   kernel/trace/bpf_trace.c:42:9: note: in expansion of macro 'rcu_dereference_protected'
      42 |         rcu_dereference_protected(p, lockdep_is_held(&bpf_event_mutex))
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2261:17: note: in expansion of macro 'bpf_event_rcu_dereference'
    2261 |         progs = bpf_event_rcu_dereference(event->tp_event->prog_array);
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2261:48: error: 'struct perf_event' has no member named 'tp_event'
    2261 |         progs = bpf_event_rcu_dereference(event->tp_event->prog_array);
         |                                                ^~
   include/linux/rcupdate.h:445:42: note: in definition of macro '__rcu_dereference_protected'
     445 |         ((typeof(*p) __force __kernel *)(p)); \
         |                                          ^
   kernel/trace/bpf_trace.c:42:9: note: in expansion of macro 'rcu_dereference_protected'
      42 |         rcu_dereference_protected(p, lockdep_is_held(&bpf_event_mutex))
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2261:17: note: in expansion of macro 'bpf_event_rcu_dereference'
    2261 |         progs = bpf_event_rcu_dereference(event->tp_event->prog_array);
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c: At top level:
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run1' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2345:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2345 | BPF_TRACE_DEFN_x(1);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run2' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2346:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2346 | BPF_TRACE_DEFN_x(2);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run3' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2347:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2347 | BPF_TRACE_DEFN_x(3);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run4' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2348:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2348 | BPF_TRACE_DEFN_x(4);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run5' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2349:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2349 | BPF_TRACE_DEFN_x(5);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run6' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2350:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2350 | BPF_TRACE_DEFN_x(6);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run7' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2351:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2351 | BPF_TRACE_DEFN_x(7);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run8' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2352:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2352 | BPF_TRACE_DEFN_x(8);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run9' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2353:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2353 | BPF_TRACE_DEFN_x(9);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run10' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2354:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2354 | BPF_TRACE_DEFN_x(10);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run11' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2355:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2355 | BPF_TRACE_DEFN_x(11);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run12' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2356:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2356 | BPF_TRACE_DEFN_x(12);
         | ^~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c: In function 'bpf_get_perf_event_info':
   kernel/trace/bpf_trace.c:2395:21: error: 'const struct perf_event' has no member named 'prog'
    2395 |         prog = event->prog;
         |                     ^~
   kernel/trace/bpf_trace.c:2404:22: error: 'const struct perf_event' has no member named 'tp_event'
    2404 |         flags = event->tp_event->flags;
         |                      ^~
   kernel/trace/bpf_trace.c:2406:53: error: 'const struct perf_event' has no member named 'tp_event'
    2406 |         is_syscall_tp = is_syscall_trace_event(event->tp_event);
         |                                                     ^~
   kernel/trace/bpf_trace.c:2409:45: error: 'const struct perf_event' has no member named 'tp_event'
    2409 |                 *buf = is_tracepoint ? event->tp_event->tp->name
         |                                             ^~
   kernel/trace/bpf_trace.c:2410:45: error: 'const struct perf_event' has no member named 'tp_event'
    2410 |                                      : event->tp_event->name;
         |                                             ^~
   kernel/trace/bpf_trace.c: In function '____bpf_get_attach_cookie_pe':
>> kernel/trace/bpf_trace.c:1155:1: warning: control reaches end of non-void function [-Wreturn-type]
    1155 | }
         | ^
   cc1: some warnings being treated as errors

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for BPF_EVENTS
   Depends on [n]: FTRACE [=n] && BPF_SYSCALL [=y] && (KPROBE_EVENTS [=n] || UPROBE_EVENTS [=n]) && PERF_EVENTS [=n]
   Selected by [y]:
   - SPI_MOCKUP [=y] && SPI [=y] && SPI_MASTER [=y] && OF [=y]


vim +/bpf_trace_run1 +2337 kernel/trace/bpf_trace.c

c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2335  
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2336  #define BPF_TRACE_DEFN_x(x)						\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28 @2337  	void bpf_trace_run##x(struct bpf_prog *prog,			\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2338  			      REPEAT(x, SARG, __DL_COM, __SEQ_0_11))	\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2339  	{								\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2340  		u64 args[x];						\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2341  		REPEAT(x, COPY, __DL_SEM, __SEQ_0_11);			\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2342  		__bpf_trace_run(prog, args);				\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2343  	}								\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2344  	EXPORT_SYMBOL_GPL(bpf_trace_run##x)
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2345  BPF_TRACE_DEFN_x(1);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2346  BPF_TRACE_DEFN_x(2);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2347  BPF_TRACE_DEFN_x(3);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2348  BPF_TRACE_DEFN_x(4);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2349  BPF_TRACE_DEFN_x(5);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2350  BPF_TRACE_DEFN_x(6);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2351  BPF_TRACE_DEFN_x(7);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2352  BPF_TRACE_DEFN_x(8);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2353  BPF_TRACE_DEFN_x(9);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2354  BPF_TRACE_DEFN_x(10);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2355  BPF_TRACE_DEFN_x(11);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2356  BPF_TRACE_DEFN_x(12);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2357  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 -next 4/5] spi: mockup: Add speed and flags attribute support
  2023-11-04  6:46 ` [PATCH v3 -next 4/5] spi: mockup: Add speed and flags attribute support Zhang Xiaoxu
@ 2023-11-04 11:10   ` kernel test robot
  0 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2023-11-04 11:10 UTC (permalink / raw)
  To: Zhang Xiaoxu, zhangxiaoxu5, weiyongjun1, broonie, rostedt, mingo,
	frowand.list, linux-spi, linux-kernel
  Cc: oe-kbuild-all

Hi Zhang,

kernel test robot noticed the following build warnings:

[auto build test WARNING on next-20231103]

url:    https://github.com/intel-lab-lkp/linux/commits/Zhang-Xiaoxu/spi-mockup-Add-SPI-controller-testing-driver/20231104-144859
base:   next-20231103
patch link:    https://lore.kernel.org/r/20231104064650.972687-5-zhangxiaoxu%40huaweicloud.com
patch subject: [PATCH v3 -next 4/5] spi: mockup: Add speed and flags attribute support
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20231104/202311041823.CPs0Ymwh-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231104/202311041823.CPs0Ymwh-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311041823.CPs0Ymwh-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/spi/spi-mockup.c:339:1: error: expected ',' or ';' before 'static'
     339 | static ssize_t spi_mockup_ ## name ## _store(struct config_item *item,     \
         | ^~~~~~
   drivers/spi/spi-mockup.c:364:1: note: in expansion of macro 'SPI_MOCKUP_ATTR'
     364 | SPI_MOCKUP_ATTR(u32, max_speed)
         | ^~~~~~~~~~~~~~~
   In file included from drivers/spi/spi-mockup.c:15:
   drivers/spi/spi-mockup.c:361:18: error: 'spi_mockup_max_speed_store' undeclared here (not in a function); did you mean 'spi_mockup_min_speed_store'?
     361 | CONFIGFS_ATTR_WO(spi_mockup_, name)                                        \
         |                  ^~~~~~~~~~~
   include/linux/configfs.h:145:27: note: in definition of macro 'CONFIGFS_ATTR_WO'
     145 |         .store          = _pfx##_name##_store,          \
         |                           ^~~~
   drivers/spi/spi-mockup.c:364:1: note: in expansion of macro 'SPI_MOCKUP_ATTR'
     364 | SPI_MOCKUP_ATTR(u32, max_speed)
         | ^~~~~~~~~~~~~~~
   drivers/spi/spi-mockup.c:339:1: error: expected ',' or ';' before 'static'
     339 | static ssize_t spi_mockup_ ## name ## _store(struct config_item *item,     \
         | ^~~~~~
   drivers/spi/spi-mockup.c:365:1: note: in expansion of macro 'SPI_MOCKUP_ATTR'
     365 | SPI_MOCKUP_ATTR(u16, flags)
         | ^~~~~~~~~~~~~~~
   drivers/spi/spi-mockup.c:361:18: error: 'spi_mockup_flags_store' undeclared here (not in a function); did you mean 'spi_mockup_enable_store'?
     361 | CONFIGFS_ATTR_WO(spi_mockup_, name)                                        \
         |                  ^~~~~~~~~~~
   include/linux/configfs.h:145:27: note: in definition of macro 'CONFIGFS_ATTR_WO'
     145 |         .store          = _pfx##_name##_store,          \
         |                           ^~~~
   drivers/spi/spi-mockup.c:365:1: note: in expansion of macro 'SPI_MOCKUP_ATTR'
     365 | SPI_MOCKUP_ATTR(u16, flags)
         | ^~~~~~~~~~~~~~~
   drivers/spi/spi-mockup.c:339:1: error: expected ',' or ';' before 'static'
     339 | static ssize_t spi_mockup_ ## name ## _store(struct config_item *item,     \
         | ^~~~~~
   drivers/spi/spi-mockup.c:366:1: note: in expansion of macro 'SPI_MOCKUP_ATTR'
     366 | SPI_MOCKUP_ATTR(u16, num_cs)
         | ^~~~~~~~~~~~~~~
   drivers/spi/spi-mockup.c:361:18: error: 'spi_mockup_num_cs_store' undeclared here (not in a function); did you mean 'spi_mockup_enable_store'?
     361 | CONFIGFS_ATTR_WO(spi_mockup_, name)                                        \
         |                  ^~~~~~~~~~~
   include/linux/configfs.h:145:27: note: in definition of macro 'CONFIGFS_ATTR_WO'
     145 |         .store          = _pfx##_name##_store,          \
         |                           ^~~~
   drivers/spi/spi-mockup.c:366:1: note: in expansion of macro 'SPI_MOCKUP_ATTR'
     366 | SPI_MOCKUP_ATTR(u16, num_cs)
         | ^~~~~~~~~~~~~~~
   drivers/spi/spi-mockup.c:368:1: error: expected ',' or ';' before 'static'
     368 | static struct configfs_attribute *spi_mockup_configfs_attrs[] = {
         | ^~~~~~
   drivers/spi/spi-mockup.c:380:27: error: 'spi_mockup_configfs_attrs' undeclared here (not in a function); did you mean 'spi_mockup_attrs'?
     380 |         .ct_attrs       = spi_mockup_configfs_attrs,
         |                           ^~~~~~~~~~~~~~~~~~~~~~~~~
         |                           spi_mockup_attrs
>> drivers/spi/spi-mockup.c:361:18: warning: 'spi_mockup_attr_num_cs' defined but not used [-Wunused-variable]
     361 | CONFIGFS_ATTR_WO(spi_mockup_, name)                                        \
         |                  ^~~~~~~~~~~
   include/linux/configfs.h:141:34: note: in definition of macro 'CONFIGFS_ATTR_WO'
     141 | static struct configfs_attribute _pfx##attr_##_name = { \
         |                                  ^~~~
   drivers/spi/spi-mockup.c:366:1: note: in expansion of macro 'SPI_MOCKUP_ATTR'
     366 | SPI_MOCKUP_ATTR(u16, num_cs)
         | ^~~~~~~~~~~~~~~
>> drivers/spi/spi-mockup.c:361:18: warning: 'spi_mockup_attr_flags' defined but not used [-Wunused-variable]
     361 | CONFIGFS_ATTR_WO(spi_mockup_, name)                                        \
         |                  ^~~~~~~~~~~
   include/linux/configfs.h:141:34: note: in definition of macro 'CONFIGFS_ATTR_WO'
     141 | static struct configfs_attribute _pfx##attr_##_name = { \
         |                                  ^~~~
   drivers/spi/spi-mockup.c:365:1: note: in expansion of macro 'SPI_MOCKUP_ATTR'
     365 | SPI_MOCKUP_ATTR(u16, flags)
         | ^~~~~~~~~~~~~~~
>> drivers/spi/spi-mockup.c:361:18: warning: 'spi_mockup_attr_max_speed' defined but not used [-Wunused-variable]
     361 | CONFIGFS_ATTR_WO(spi_mockup_, name)                                        \
         |                  ^~~~~~~~~~~
   include/linux/configfs.h:141:34: note: in definition of macro 'CONFIGFS_ATTR_WO'
     141 | static struct configfs_attribute _pfx##attr_##_name = { \
         |                                  ^~~~
   drivers/spi/spi-mockup.c:364:1: note: in expansion of macro 'SPI_MOCKUP_ATTR'
     364 | SPI_MOCKUP_ATTR(u32, max_speed)
         | ^~~~~~~~~~~~~~~
>> drivers/spi/spi-mockup.c:361:18: warning: 'spi_mockup_attr_min_speed' defined but not used [-Wunused-variable]
     361 | CONFIGFS_ATTR_WO(spi_mockup_, name)                                        \
         |                  ^~~~~~~~~~~
   include/linux/configfs.h:141:34: note: in definition of macro 'CONFIGFS_ATTR_WO'
     141 | static struct configfs_attribute _pfx##attr_##_name = { \
         |                                  ^~~~
   drivers/spi/spi-mockup.c:363:1: note: in expansion of macro 'SPI_MOCKUP_ATTR'
     363 | SPI_MOCKUP_ATTR(u32, min_speed)
         | ^~~~~~~~~~~~~~~
>> drivers/spi/spi-mockup.c:336:18: warning: 'spi_mockup_attr_disable' defined but not used [-Wunused-variable]
     336 | CONFIGFS_ATTR_WO(spi_mockup_, disable);
         |                  ^~~~~~~~~~~
   include/linux/configfs.h:141:34: note: in definition of macro 'CONFIGFS_ATTR_WO'
     141 | static struct configfs_attribute _pfx##attr_##_name = { \
         |                                  ^~~~
>> drivers/spi/spi-mockup.c:316:18: warning: 'spi_mockup_attr_enable' defined but not used [-Wunused-variable]
     316 | CONFIGFS_ATTR_WO(spi_mockup_, enable);
         |                  ^~~~~~~~~~~
   include/linux/configfs.h:141:34: note: in definition of macro 'CONFIGFS_ATTR_WO'
     141 | static struct configfs_attribute _pfx##attr_##_name = { \
         |                                  ^~~~

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for BPF_EVENTS
   Depends on [n]: FTRACE [=n] && BPF_SYSCALL [=y] && (KPROBE_EVENTS [=n] || UPROBE_EVENTS [=n]) && PERF_EVENTS [=n]
   Selected by [y]:
   - SPI_MOCKUP [=y] && SPI [=y] && SPI_MASTER [=y] && OF [=y]


vim +/spi_mockup_attr_num_cs +361 drivers/spi/spi-mockup.c

   287	
   288	static ssize_t
   289	spi_mockup_enable_store(struct config_item *item, const char *page, size_t len)
   290	{
   291		int ret = len;
   292		struct platform_device_info pdevinfo = {0};
   293		struct spi_mockup_device *dev = to_spi_mockup_dev(item);
   294	
   295		mutex_lock(&dev->lock);
   296		if (dev->pdev) {
   297			ret = -EEXIST;
   298			goto out;
   299		}
   300	
   301		pdevinfo.name = "spi-mockup";
   302		pdevinfo.id = dev->bus_nr;
   303		pdevinfo.data = &dev->data;
   304		pdevinfo.size_data = sizeof(dev->data);
   305	
   306		dev->pdev = platform_device_register_full(&pdevinfo);
   307		if (IS_ERR(dev->pdev)) {
   308			ret = PTR_ERR(dev->pdev);
   309			dev->pdev = NULL;
   310			goto out;
   311		}
   312	out:
   313		mutex_unlock(&dev->lock);
   314		return ret;
   315	}
 > 316	CONFIGFS_ATTR_WO(spi_mockup_, enable);
   317	
   318	static ssize_t
   319	spi_mockup_disable_store(struct config_item *item, const char *page, size_t len)
   320	{
   321		int ret = len;
   322		struct spi_mockup_device *dev = to_spi_mockup_dev(item);
   323	
   324		mutex_lock(&dev->lock);
   325		if (!dev->pdev) {
   326			ret = -ENODEV;
   327			goto out;
   328		}
   329	
   330		platform_device_unregister(dev->pdev);
   331		dev->pdev = NULL;
   332	out:
   333		mutex_unlock(&dev->lock);
   334		return ret;
   335	}
 > 336	CONFIGFS_ATTR_WO(spi_mockup_, disable);
   337	
   338	#define SPI_MOCKUP_ATTR(type, name) \
   339	static ssize_t spi_mockup_ ## name ## _store(struct config_item *item,	   \
   340						     const char *page, size_t len) \
   341	{									   \
   342		int ret;							   \
   343		type val;							   \
   344		struct spi_mockup_device *dev = to_spi_mockup_dev(item);	   \
   345										   \
   346		mutex_lock(&dev->lock);						   \
   347		if (dev->pdev) {						   \
   348			ret = -EBUSY;						   \
   349			goto out;						   \
   350		}								   \
   351										   \
   352		ret = kstrto ## type(page, 0, &val);				   \
   353		if (ret)							   \
   354			goto out;						   \
   355										   \
   356		dev->data.name = val;						   \
   357	out:									   \
   358		mutex_unlock(&dev->lock);					   \
   359		return ret ? ret : len;						   \
   360	}									   \
 > 361	CONFIGFS_ATTR_WO(spi_mockup_, name)					   \
   362	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer
  2023-11-04  6:46 ` [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer Zhang Xiaoxu
  2023-11-04  9:58   ` kernel test robot
@ 2023-11-04 11:10   ` kernel test robot
  1 sibling, 0 replies; 12+ messages in thread
From: kernel test robot @ 2023-11-04 11:10 UTC (permalink / raw)
  To: Zhang Xiaoxu, zhangxiaoxu5, weiyongjun1, broonie, rostedt, mingo,
	frowand.list, linux-spi, linux-kernel
  Cc: oe-kbuild-all

Hi Zhang,

kernel test robot noticed the following build warnings:

[auto build test WARNING on next-20231103]

url:    https://github.com/intel-lab-lkp/linux/commits/Zhang-Xiaoxu/spi-mockup-Add-SPI-controller-testing-driver/20231104-144859
base:   next-20231103
patch link:    https://lore.kernel.org/r/20231104064650.972687-3-zhangxiaoxu%40huaweicloud.com
patch subject: [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer
config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20231104/202311041825.n8iCJiNe-lkp@intel.com/config)
compiler: mips-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231104/202311041825.n8iCJiNe-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311041825.n8iCJiNe-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/trace/trace_events.h:27,
                    from include/trace/define_trace.h:102,
                    from include/trace/events/spi_mockup.h:31,
                    from drivers/spi/spi-mockup.c:17:
>> include/trace/stages/init.h:2:23: warning: 'str__spi_mockup__trace_system_name' defined but not used [-Wunused-const-variable=]
       2 | #define __app__(x, y) str__##x##y
         |                       ^~~~~
   include/trace/stages/init.h:3:21: note: in expansion of macro '__app__'
       3 | #define __app(x, y) __app__(x, y)
         |                     ^~~~~~~
   include/trace/stages/init.h:5:29: note: in expansion of macro '__app'
       5 | #define TRACE_SYSTEM_STRING __app(TRACE_SYSTEM_VAR,__trace_system_name)
         |                             ^~~~~
   include/trace/stages/init.h:8:27: note: in expansion of macro 'TRACE_SYSTEM_STRING'
       8 |         static const char TRACE_SYSTEM_STRING[] =       \
         |                           ^~~~~~~~~~~~~~~~~~~
   include/trace/stages/init.h:11:1: note: in expansion of macro 'TRACE_MAKE_SYSTEM_STR'
      11 | TRACE_MAKE_SYSTEM_STR();
         | ^~~~~~~~~~~~~~~~~~~~~


vim +/str__spi_mockup__trace_system_name +2 include/trace/stages/init.h

af6b9668e85ffd Steven Rostedt (Google  2022-03-03 @2) #define __app__(x, y) str__##x##y
af6b9668e85ffd Steven Rostedt (Google  2022-03-03  3) #define __app(x, y) __app__(x, y)
af6b9668e85ffd Steven Rostedt (Google  2022-03-03  4) 

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 -next 1/5] spi: mockup: Add SPI controller testing driver
  2023-11-04  6:46 ` [PATCH v3 -next 1/5] spi: mockup: Add SPI controller testing driver Zhang Xiaoxu
@ 2023-11-06 11:59   ` Mark Brown
  2023-11-18 11:07     ` huaweicloud
  0 siblings, 1 reply; 12+ messages in thread
From: Mark Brown @ 2023-11-06 11:59 UTC (permalink / raw)
  To: Zhang Xiaoxu
  Cc: zhangxiaoxu5, weiyongjun1, rostedt, mingo, frowand.list,
	linux-spi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1756 bytes --]

On Sat, Nov 04, 2023 at 02:46:46PM +0800, Zhang Xiaoxu wrote:

> This is accomplished by executing the following command:
> 
> $ echo adcxx1s 0 > /sys/class/spi_master/spi0/new_device

That's not a valid sysfs format, sysfs requires one value per file.
configfs might be a better fit?

> +config SPI_MOCKUP
> +	tristate "SPI controller Testing Driver"
> +	depends on OF

Why would this depend on DT?  Given that any test SPI controller is a
virtual device it should never appear in DT and we probably shouldn't
require providing DT for the created devices even if we implement
support for that, only some devices might care.
`
> +++ b/drivers/spi/spi-mockup.c
> @@ -0,0 +1,211 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * SPI controller Testing Driver
> + *
> + * Copyright(c) 2022 Huawei Technologies Co., Ltd.
> + */

Please keep the entire comment a C++ one so things look more
intentional.

> +#define MOCKUP_CHIPSELECT_MAX		8

Why would we have a hard coded limit here?

> +	blank = strchr(buf, ' ');
> +	if (!blank) {
> +		dev_err(dev, "%s: Extra parameters\n", "new_device");
> +		return -EINVAL;
> +	}

There is no point in using %s to render a constant string.

> +static const struct of_device_id spi_mockup_match[] = {
> +	{ .compatible = "spi-mockup", },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, spi_mockup_match);

If we were going to instantiate this via DT we'd need a binding, but as
I indicated above since this is purely virtual and not even something
like virtual hardware provided by a VMM but rather just something kernel
internal we should probably not be using DT at all.  Providing a device
facing DT interface might be useful, but that's a second stage thing.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 -next 5/5] spi: mockup: Add documentation
  2023-11-04  6:46 ` [PATCH v3 -next 5/5] spi: mockup: Add documentation Zhang Xiaoxu
@ 2023-11-06 13:09   ` Mark Brown
  0 siblings, 0 replies; 12+ messages in thread
From: Mark Brown @ 2023-11-06 13:09 UTC (permalink / raw)
  To: Zhang Xiaoxu
  Cc: zhangxiaoxu5, weiyongjun1, rostedt, mingo, frowand.list,
	linux-spi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 691 bytes --]

On Sat, Nov 04, 2023 at 02:46:50PM +0800, Zhang Xiaoxu wrote:
> From: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
> 
> Add documentation for the SPI mockup controller driver.
> This include the tutorial for how to mockup a spi device.
> 
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>

Could we also get a kselftest that demonstrates how to use this in an
actually executable form - it could probably just be the tutorial
program from the docs stored somewhere?  That would both help ensure
continuous testing and be a bit easier for people to pick up since it
would show the whole flow rather than assuming knowledge.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 -next 1/5] spi: mockup: Add SPI controller testing driver
  2023-11-06 11:59   ` Mark Brown
@ 2023-11-18 11:07     ` huaweicloud
  0 siblings, 0 replies; 12+ messages in thread
From: huaweicloud @ 2023-11-18 11:07 UTC (permalink / raw)
  To: Mark Brown
  Cc: zhangxiaoxu5, weiyongjun1, rostedt, mingo, frowand.list,
	linux-spi, linux-kernel

Hi Mark,

Thanks for your review.

Most of the comments have been modified. and the v4 has been sent
to the maillist, as has the KDDV (Kernel Device Driver Verfication)
test framework based on python unittests.

Looking forward for your comments.

Thanks.


在 2023/11/6 19:59, Mark Brown 写道:
> On Sat, Nov 04, 2023 at 02:46:46PM +0800, Zhang Xiaoxu wrote:
> 
>> This is accomplished by executing the following command:
>>
>> $ echo adcxx1s 0 > /sys/class/spi_master/spi0/new_device
> 
> That's not a valid sysfs format, sysfs requires one value per file.
> configfs might be a better fit?
> 
>> +config SPI_MOCKUP
>> +	tristate "SPI controller Testing Driver"
>> +	depends on OF
> 
> Why would this depend on DT?  Given that any test SPI controller is a
> virtual device it should never appear in DT and we probably shouldn't
> require providing DT for the created devices even if we implement
> support for that, only some devices might care.
> `
>> +++ b/drivers/spi/spi-mockup.c
>> @@ -0,0 +1,211 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * SPI controller Testing Driver
>> + *
>> + * Copyright(c) 2022 Huawei Technologies Co., Ltd.
>> + */
> 
> Please keep the entire comment a C++ one so things look more
> intentional.
> 
>> +#define MOCKUP_CHIPSELECT_MAX		8
> 
> Why would we have a hard coded limit here?
When register the spi controller, we need to specify the maximun
number of chips. Modify it to U16_MAX in next version.
> 
>> +	blank = strchr(buf, ' ');
>> +	if (!blank) {
>> +		dev_err(dev, "%s: Extra parameters\n", "new_device");
>> +		return -EINVAL;
>> +	}
> 
> There is no point in using %s to render a constant string.
> 
>> +static const struct of_device_id spi_mockup_match[] = {
>> +	{ .compatible = "spi-mockup", },
>> +	{ }
>> +};
>> +MODULE_DEVICE_TABLE(of, spi_mockup_match);
> 
> If we were going to instantiate this via DT we'd need a binding, but as
> I indicated above since this is purely virtual and not even something
> like virtual hardware provided by a VMM but rather just something kernel
> internal we should probably not be using DT at all.  Providing a device
> facing DT interface might be useful, but that's a second stage thing.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-11-18 11:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-04  6:46 [PATCH -next 0/5] spi: Introduce BPF based SPI mockup controller Zhang Xiaoxu
2023-11-04  6:46 ` [PATCH v3 -next 1/5] spi: mockup: Add SPI controller testing driver Zhang Xiaoxu
2023-11-06 11:59   ` Mark Brown
2023-11-18 11:07     ` huaweicloud
2023-11-04  6:46 ` [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer Zhang Xiaoxu
2023-11-04  9:58   ` kernel test robot
2023-11-04 11:10   ` kernel test robot
2023-11-04  6:46 ` [PATCH v3 -next 3/5] spi: mockup: Add support register the device through configfs Zhang Xiaoxu
2023-11-04  6:46 ` [PATCH v3 -next 4/5] spi: mockup: Add speed and flags attribute support Zhang Xiaoxu
2023-11-04 11:10   ` kernel test robot
2023-11-04  6:46 ` [PATCH v3 -next 5/5] spi: mockup: Add documentation Zhang Xiaoxu
2023-11-06 13:09   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).