mbox series

[-next,0/5] spi: Introduce BPF based SPI mockup controller

Message ID 20231104064650.972687-1-zhangxiaoxu@huaweicloud.com
Headers show
Series spi: Introduce BPF based SPI mockup controller | expand

Message

Zhang Xiaoxu Nov. 4, 2023, 6:46 a.m. UTC
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

Comments

Mark Brown Nov. 6, 2023, 11:59 a.m. UTC | #1
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.
Zhang Xiaoxu Nov. 18, 2023, 11:07 a.m. UTC | #2
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.