[PATCH v3 0/3] Virtio SPI Linux driver

Harald Mommer
2024-03-26T11:30:47Z

This is the 3rd 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 successor of the 2nd 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@linaro.org> as
everything else was done.

Changes between non-RFC virtio SPI driver V2 and 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.

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 at the time of testing (tagged v6.8). An almost
identical driver version was tested on hardware using kernel v6.5.7.

Removed "Reviewed-by" from Viresh Kumar <viresh.kumar@linaro.org> again
as the changes while small may be considered as substantial.