lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250622160054.31cc5103@jic23-huawei>
Date: Sun, 22 Jun 2025 16:00:54 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: David Lechner <dlechner@...libre.com>
Cc: Michael Hennerich <Michael.Hennerich@...log.com>, Nuno Sá
 <nuno.sa@...log.com>, Andy Shevchenko <andy@...nel.org>, Rob Herring
 <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley
 <conor+dt@...nel.org>, Mark Brown <broonie@...nel.org>,
 linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
 devicetree@...r.kernel.org, linux-spi@...r.kernel.org
Subject: Re: [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support

On Fri, 20 Jun 2025 17:20:14 -0500
David Lechner <dlechner@...libre.com> wrote:

> Add SPI offload support to the ad_sigma_delta module.
> 
> When the SPI controller has SPI offload capabilities, the module will
> now use that for buffered reads instead of the RDY interrupt trigger.
> 
> Drivers that use the ad_sigma_delta module will have to opt into this
> by setting supports_spi_offload since each driver will likely need
> additional changes before SPI offload can be used. This will allow us
> to gradually enable SPI offload support for each driver.
> 
> Signed-off-by: David Lechner <dlechner@...libre.com>

A few queries inline that again are more about the original code than what
you change here.

Jonathan

> ---
>  drivers/iio/adc/ad_sigma_delta.c       | 160 +++++++++++++++++++++++----------
>  include/linux/iio/adc/ad_sigma_delta.h |  14 +++
>  2 files changed, 129 insertions(+), 45 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index a9b97f5d4107a2e1bb74877d30403445e9b04a44..449b0756be96d3f864a6e7f070467ad7311bf7d5 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -14,11 +14,13 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/slab.h>
> +#include <linux/spi/offload/consumer.h>
>  #include <linux/spi/spi.h>
>  #include <linux/types.h>
>  #include <linux/unaligned.h>
>  
>  #include <linux/iio/adc/ad_sigma_delta.h>
> +#include <linux/iio/buffer-dmaengine.h>
>  #include <linux/iio/buffer.h>
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
> @@ -460,8 +462,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
>  	struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
>  	const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type;
>  	struct spi_transfer *xfer = sigma_delta->sample_xfer;
> -	unsigned int i, slot, samples_buf_size;
> -	unsigned int channel, scan_size;
> +	unsigned int i, slot, channel;
>  	u8 *samples_buf;
>  	int ret;
>  
> @@ -489,23 +490,33 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
>  	sigma_delta->active_slots = slot;
>  	sigma_delta->current_slot = 0;
>  
> -	if (sigma_delta->active_slots > 1) {
> -		ret = ad_sigma_delta_append_status(sigma_delta, true);
> -		if (ret)
> -			return ret;
> -	}
> +	if (ad_sigma_delta_has_spi_offload(sigma_delta)) {
> +		xfer[1].offload_flags = SPI_OFFLOAD_XFER_RX_STREAM;
> +		xfer[1].bits_per_word = scan_type->realbits;
> +		xfer[1].len = spi_bpw_to_bytes(scan_type->realbits);
> +	} else {
> +		unsigned int samples_buf_size, scan_size;
>  
> -	samples_buf_size = ALIGN(slot * scan_type->storagebits, 8);
> -	samples_buf_size += sizeof(int64_t);
> -	samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
> -				    samples_buf_size, GFP_KERNEL);
> -	if (!samples_buf)
> -		return -ENOMEM;
> +		if (sigma_delta->active_slots > 1) {
> +			ret = ad_sigma_delta_append_status(sigma_delta, true);
> +			if (ret)
> +				return ret;
> +		}
>  
> -	sigma_delta->samples_buf = samples_buf;
> -	scan_size = BITS_TO_BYTES(scan_type->realbits + scan_type->shift);
> -	xfer[1].rx_buf = &sigma_delta->rx_buf[scan_size == 3 ? 1 : 0];
> -	xfer[1].len = scan_size + (sigma_delta->status_appended ? 1 : 0);
> +		samples_buf_size = ALIGN(slot * scan_type->storagebits, 8);

The code I queried earlier is moved here, so make sure to carry through
any changes if it is indeed wrong!

> +		samples_buf_size += sizeof(int64_t);
> +		samples_buf = devm_krealloc(&sigma_delta->spi->dev,
> +					    sigma_delta->samples_buf,
> +					    samples_buf_size, GFP_KERNEL);
> +		if (!samples_buf)
> +			return -ENOMEM;
> +
> +		sigma_delta->samples_buf = samples_buf;
> +		scan_size = BITS_TO_BYTES(scan_type->realbits + scan_type->shift);
> +
> +		xfer[1].rx_buf = &sigma_delta->rx_buf[scan_size == 3 ? 1 : 0];
> +		xfer[1].len = scan_size + (sigma_delta->status_appended ? 1 : 0);
> +	}
>  	xfer[1].cs_change = 1;
>  
>  	if (sigma_delta->info->has_registers) {

> @@ -670,7 +700,8 @@ static irqreturn_t ad_sd_data_rdy_trig_poll(int irq, void *private)
>  	if ((!sigma_delta->rdy_gpiod || gpiod_get_value(sigma_delta->rdy_gpiod)) &&
>  	    ad_sd_disable_irq(sigma_delta)) {
>  		complete(&sigma_delta->completion);
> -		iio_trigger_poll(sigma_delta->trig);
> +		if (sigma_delta->trig)

Is this defensive or can we actually get here with out a trigger?
I would have thought in the offload case (so no trigger here) we'd not call this
function at all.  Mind you, can't we get here with no trigger when doing
a calibration or simple read normally?  

> +			iio_trigger_poll(sigma_delta->trig);
>  
>  		return IRQ_HANDLED;
>  	}



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ