[PATCH v10 0/3] Virtio SPI Linux driver

Haixu Cui posted 3 patches 3 weeks, 3 days ago
[PATCH v10 0/3] Virtio SPI Linux driver
Posted by Haixu Cui 3 weeks, 3 days ago
This is the 10th version of the virtio SPI Linux driver patch series which is
intended to be compliant with the upcoming virtio specification
version 1.4. The specification can be found in repository:
https://github.com/oasis-tcs/virtio-spec.git branch virtio-1.4.

The original contributor Harald submitted:
RFC v1 to RFC v3
non-RFC v1 to non-RFC v3

I continued the work and submitted:
RFC v4 to RFC v8
non-RFC v4, v9

This submission is labeled as v10 to maintain continuity and clarity.
It builds upon non-RFC v9, and incorporates feedback from the community
and testing improvements.

Changes between v9 and v10:
- Remove support for reading "spi,bus-num" property in virtio_spi_probe.
- Refine initialization of spi_req variable.
- Update MAINTAINERS: change mailing list from
  virtualization@lists.linux-foundation.org to virtualization@lists.linux.dev.

Changes between non-RFC v4 and v9:
- Updated macro definition to use SPI_MODE_X_MASK instead of manually
  listing individual flags.
- Restructured struct virtio_spi_req to improve cache alignment and
  layout efficiency.
- Replaced manual comparison logic with max() for word delay calculation.
- Removed unnecessary u suffix from unsigned int initializations.
- Simplified memory cleanup by using __free(kfree) for spi_req.
- Standardized error variable naming from err to ret across the driver.
- Removed redundant ACPI_COMPANION_SET() call to avoid inconsistency
  with device_set_node().
- Corrected logic for reading spi,bus-num property.
- eplaced return err with return dev_err_probe for cleaner error reporting.
- Used dev_to_virtio() in power management callbacks.
- Added virtualization@lists.linux-foundation.org as the mailing list
  for patch discussions.

Changes between RFC V8 and non-RFC V4:
- Replaced BUILD_BUG_ON with static_assert for SPI mode constants to
  improve compile-time validation.
- Introduced VIRTIO_SPI_MODE_MASK macro to simplify SPI mode bit masking.
- Removed unnecessary __cacheline_aligned attributes from buffer
  pointers in virtio_spi_req.
- Simplified type casting in delay conversions by removing redundant
  (u32) casts.
- Replaced manual virtqueue cleanup with devm_add_action_or_reset()
  for automatic resource management.
- Migrated controller registration to devm_spi_register_controller()
  for better lifecycle handling.
- Updated power management callbacks to use struct device * and
  added virtio_spi_pm_ops
- Standardized bit macros in virtio_spi.h from BIT(x) to _BITUL(x) for
  type safety.
- Improved documentation comments in virtio_spi_config for clarity
  and consistency.

Changes between RFC V7 and RFC V8:
- Restored original Copyright.

Changes between RFC V6 and RFC V7:
- Restored original MODULE_AUTHOR information in the driver source file.
- Reinstated the original Signed-off-by tags.

Changes between RFC V5 and RFC V6:
- Dynamically allocate the virtio_spi_req structure instead of keeping
  it as a member of virtio_spi_priv.
- Remove redundant comments.

Changes between RFC V4 and RFC V5:
- Use dev_err_probe instead of dev_err in virtio_spi_probe function
  to improve error handling.
- Add comments to virtio_spi_set_delays function and revise several
  field descriptions in mode_func_supported for improved clarity.
- Update bitmask definitions from (1 << n) to BIT(n) to enhance code
  readability.

Changes between non-RFC V3 and RFC V4
- Remove the logic code for statically creating SPI devices through
  the spi_new_device function.
- Add ACPI support.
- According to Hillf Danton's comment, use init_completion instead of
  reinit_completion in virtio_spi_transfer_one function.

Changes between non-RFC V2 and non-RFC V3
- Child spi device tree nodes are supported now.
  If a child spi device tree node exists the setup of the user mode SPI
  device is done by spi_register_controller() and the driver itself does
  not call spi_new_device() any more to setup the chip selects.
  If there is no device tree child node the SPI device sets up the user
  mode SPI devices autonomously as it was before.
  
Changes between non-RFC V1 and non-RFC V2
- Remove some comments stating the obvious
- Remove error trace when devm_spi_alloc_host() failed as this is habit
- Add some blank lines to improve readabilty
- Last TODO comment removed which was used to trigger some discussion.
  Discussion did not take place, most probably the code below is correct
  as it is
- Abstained from replacing "Cannot " by "Failed to " in error messages
  as the wording "Cannot " is frequently used even when "Failed to " has
  the majority. Announced this, heard nothing about this, so added the
  "Reviewed-by" from Viresh Kumar <viresh.kumar@linaro.org> as
  everything else was done.

Changes between RFC V3 and non-RFC V1:
- Address kernel test robot comment which revealed an actual bug
- Rework some comments in the code addressing review comments
- Remove a TODO comment which has served it's purpose
- Allocate struct virtio_spi_req spi_req only once at startup
- Use callback transfer_one instead of transfer_one_message to simplify
  and shorten code. Due to this rework in the affected function(s) some
  additional changes:
  - Do init_completion() only once at startup, for re-initialization
    now reinit_completion() is used
  - Translate result codes VIRTIO_SPI_PARAM_ERR and VIRTIO_SPI_TRANS_ERR
    to appropriate Linux error codes -EINVAL and -EIO

Changes between RFC V2 and RFC V3:
- Order header inclusion alphabetically.
- Add Viresh Kumar's "signed-off" to the header files.
- Rework virtio_spi_one_transfer
  - Rework the delays according to Haixu Cui's advise. Delays are now
    handled in a new sub-function virtio_spi_set_delays.
  - Minor change: Re-formulate arguments of sg_init_one.
- Rework virtio_spi_probe
  - Replace some goto in error paths by return.
  - Add spi_unregister_controller to an error path. Abstained from
    using devm_spi_register_controller to keep order of
    de-initialization in virtio_spi_remove.
  - Add deletion of vqueue to all error paths taken after the virtqueues
    have been initialized.

Changes between RFC V1 and RFC V2:
- Update from virtio SPI draft specification V4 to V10.
- Incorporate review comments gotten from the community.
- A proposal for a performance enhancement having more than only one SPI
  message in flight had to be kept out. The more complicated code would
  have caused an unacceptable project risk now.

The driver was smoke tested on QEMU using:
- Qualcomm's target hardware with a physical SPI backend device via
  vhost-user protocol (Linux v6.12).
- OpenSynergy's proprietary virtio SPI device simulating a SPI backend
  on top of linux-next.git (v6.8).
- Regression tested on physical hardware using kernel v6.5.7.
Re: [PATCH v10 0/3] Virtio SPI Linux driver
Posted by Mark Brown 1 week, 2 days ago
On Mon, 08 Sep 2025 17:23:45 +0800, Haixu Cui wrote:
> This is the 10th version of the virtio SPI Linux driver patch series which is
> intended to be compliant with the upcoming virtio specification
> version 1.4. The specification can be found in repository:
> https://github.com/oasis-tcs/virtio-spec.git branch virtio-1.4.
> 
> The original contributor Harald submitted:
> RFC v1 to RFC v3
> non-RFC v1 to non-RFC v3
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/3] virtio: Add ID for virtio SPI
      commit: d9a2211dd3aee3ef29fc675f70a1941bc3f4f51f
[2/3] virtio-spi: Add virtio-spi.h
      commit: 6a1f3390fafeafe130b8128b3047452b92911a98
[3/3] SPI: Add virtio SPI driver
      commit: f98cabe3f6cf6396b3ae0264800d9b53d7612433

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
Re: [PATCH v10 0/3] Virtio SPI Linux driver
Posted by Mark Brown 2 weeks ago
On Mon, Sep 08, 2025 at 05:23:45PM +0800, Haixu Cui wrote:
> This is the 10th version of the virtio SPI Linux driver patch series which is
> intended to be compliant with the upcoming virtio specification
> version 1.4. The specification can be found in repository:
> https://github.com/oasis-tcs/virtio-spec.git branch virtio-1.4.

Does anyone have any thoughts on this?  It feels like we're mostly ready
here.