[PATCH v2 0/3] Virtio SPI Linux driver

From: Harald Mommer
Date: Mon Mar 04 2024 - 10:47:12 EST


This is the 2nd non-RFC version of a virtio SPI Linux driver which is
intended to be compliant with the 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.

This driver is the direct successor of the 1st non-RFC virtio driver.

Changes between 1st and 2nd virtio SPI driver RFC:

- 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.

Changes between 2nd and 3rd virtio SPI driver RFC:

- 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 3rd virtio SPI driver RFC and non-RFC driver 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 1st non-RFC virtio SPI driver and non-RFC driver 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@xxxxxxxxxx> as
everything else was done.

The virtio SPI driver was smoke tested on qemu using OpenSynergy's
proprietary virtio SPI device doing a SPI backend simulation on top of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
branch next/stable (tagged v6.8-rc7). Changes between v1 and v2 are so
small that target test of the adapted version of the driver on Linux 6.5
with target hardware providing a physical SPI backend device was
omitted, there were no code change code paths normally taken.