From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795902442; b=kNZh/MZw3mz21ZAasSMoue0UUmxYkwGizMofSqmMfQFF1rCvu8i5+k91neS9yAFHxLc2 ms2x2khDCwcxeWFyv+K9LxsB15FXqZSmFmBbiMFZKSBhI3nUuLrMM8Cn5YXiQIWJzNHlN +P3XLq9erQS6LB/LNAx82NpQrH73qExIMWbX3o3DfWzbIO3kfDcC+BpspQztezWPg9kca ClfgBjqFeMkRlHvwJBaWgVyZgwInSf0//YRYeJrMPfNhYAAdFGXy93i1IWXYa1pmiwylJ JeRU2CfOeXpJOokbSLQQ1aDank19e9sueMm7WApV/+22D31eZP6v3dr0i9hKp/n/hWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795902442; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: In-Reply-To:References:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=g8QPDXSPym5orLzMD6scHg+6ql6vfZ5JutSEyBzkVQs=; b=rF90uECaxTwp+Xg+q6SWBzk5EBKwH2tVc+mbarvlKYHCUBIyqHWJv7QCjS6PtsJdz09p GIRZsCYc5oxGWa1dZAJL39lFM7w2TaAkVGmPje5A5+geJI0jTnE4Dh2+G0WlYgxFO56Ki 1SHonL/bRruv/BKXMqFlVdGJcq28ZIs6HOsYH7oYnQEOSeG8yV9DJ3/XcgqtQwEQ0GxPL LD90DaDnGIoEPRQYlvQ/Pl0uI/qHYN9h5y9frUoDgrMgw2MpWhXUO2Zb5zIr+Dmfpkibu 218uY84ZEeWQyffT9IHIggJHbO+GyJOjQxD/WO7eSvuTD9Ajjscwx3R9qnxRfh6lnwQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RB7l5Mkp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D1DF606A31C; Sat, 28 Nov 2026 21:47:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RB7l5Mkp Received: by smtp.kernel.org (Postfix) with ESMTPSA id AECDE1F00893; Sat, 28 Nov 2026 21:47:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795902442; bh=g8QPDXSPym5orLzMD6scHg+6ql6vfZ5JutSEyBzkVQs=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=RB7l5Mkps4QE27Hz/78qk/XRemtd1fUdaxzorenlKqkQK9jc8/mRKUlQ4Giu1g2MR rIIwR/yrMU9OhC6g5GgxYy5CxL6eR6sqmqqjNdFjYW7loIjlpTxXXzmYduab8RNgOx Dd/YLUVhWUHT5bKtMNWuas2K+BgYUkwrVa1/XYAFJTQu8JK8n9L8mggGtEpOSlQQUa ocjASXPfJuOZX+Fs+qsgkZoBKlXwXR7ANq2yre1R7+Lu/nf4j7VMsvbNwb2B3HazU+ VMtIBzqZ4uu3CDV43LgZK+nYy6MCiaD39ItIzD5TJHxdHpi0fiSS/se0sr01XNhxXn PBL0jUgSkz+rA== Date: Sat, 28 Nov 2026 21:47:15 +0000 From: Jonathan Cameron To: Radu Sabau via B4 Relay Cc: radu.sabau@analog.com, Nuno =?UTF-8?B?U8Oh?= , Michael Hennerich , David Lechner , Andy Shevchenko , Ramona Gradinariu , linux-iio@vger.kernel.org, linux@analog.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/7] iio: imu: adis: Add a kfifo buffer setup helper for FIFO devices Message-ID: <20261128214715.1791222b@jic23-hlaptop> In-Reply-To: <20261123-adis-fifo-v1-2-f6ad9e493e19@analog.com> References: <20261123-adis-fifo-v1-0-f6ad9e493e19@analog.com> <20261123-adis-fifo-v1-2-f6ad9e493e19@analog.com> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 23 Nov 2026 15:25:26 +0200 Radu Sabau via B4 Relay wrote: > From: Radu Sabau > > Devices with a hardware FIFO (has_fifo) currently go through the > triggered buffer: the FIFO interrupt is requested with > iio_trigger_generic_data_rdy_poll() as its thread function, which calls > iio_trigger_poll() from the IRQ thread, and the samples are read from a > trigger handler. iio_trigger_poll() is meant to be called from hard > interrupt context, and the FIFO then depends on whatever trigger is > selected. > > Add devm_adis_setup_kfifo_buffer() for such devices. It sets up a kfifo > buffer and requests the FIFO interrupt as a oneshot threaded IRQ running a > handler supplied by the driver, which reads the FIFO and pushes the > samples. The interrupt is requested disabled, and the driver enables and > disables it with enable_irq() and disable_irq() from its buffer setup > functions. This is done without the adis lock, which the handler takes. Why is it masked host side rather than than device side? The rules around host side masking are vague and inconsistent for instance on whether interrupts that come whilst it is disabled are dropped or queued up. As a result device side masking is much preferred. > > The trigger/current_trigger attribute is user visible on the existing FIFO > devices, so add devm_adis_register_fifo_trigger() for them to keep it. It > registers a trigger with the usual name and sets INDIO_HARDWARE_TRIGGERED > so the attribute exists. The buffer runs in software mode, so the trigger > has no effect on it: writing it is accepted and ignored, as > hid-sensor-trigger does for the same reason. New drivers do not need it. > > No driver uses the helpers yet. > > Signed-off-by: Radu Sabau A few things inline. > diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c > index 501da4eaef69..e49e02adeda6 100644 > --- a/drivers/iio/imu/adis_buffer.c > +++ b/drivers/iio/imu/adis_buffer.c > @@ -15,6 +15,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -220,3 +221,47 @@ devm_adis_setup_buffer_and_trigger_with_attrs(struct adis *adis, struct iio_dev > adis); > } > EXPORT_SYMBOL_NS_GPL(devm_adis_setup_buffer_and_trigger_with_attrs, "IIO_ADISLIB"); > + > +/** > + * devm_adis_setup_kfifo_buffer() - Sets up a kfifo buffer for a FIFO adis device > + * @adis: The adis device > + * @indio_dev: The IIO device > + * @thread_fn: Threaded interrupt handler which reads the device FIFO and > + * pushes the samples to the buffer. It is called with @indio_dev > + * as dev_id. > + * @ops: Optional buffer setup functions, may be NULL. > + * @buffer_attrs: Extra buffer attributes. > + * > + * Returns 0 on success, a negative error code otherwise. > + * > + * Unlike devm_adis_setup_buffer_and_trigger_with_attrs(), the samples are not > + * captured from a trigger handler. The device FIFO interrupt is requested as a > + * threaded oneshot IRQ running @thread_fn, and the data goes straight to a > + * kfifo buffer. The IRQ is requested disabled and the driver enables and > + * disables it with enable_irq() and disable_irq() from its buffer setup > + * functions, without holding the adis lock. Devices which already had a > + * trigger/current_trigger attribute can keep it with > + * devm_adis_register_fifo_trigger(). > + */ > +int devm_adis_setup_kfifo_buffer(struct adis *adis, struct iio_dev *indio_dev, > + irq_handler_t thread_fn, > + const struct iio_buffer_setup_ops *ops, > + const struct iio_dev_attr **buffer_attrs) > +{ > + int ret; > + > + ret = devm_iio_kfifo_buffer_setup_ext(&adis->spi->dev, indio_dev, ops, > + buffer_attrs); Does it work without the irq? > + if (ret) > + return ret; > + > + if (adis->spi->irq) { > + ret = devm_adis_request_fifo_irq(adis, indio_dev, thread_fn); > + if (ret) > + return ret; > + } > + > + return devm_add_action_or_reset(&adis->spi->dev, adis_buffer_cleanup, > + adis); > +} > +EXPORT_SYMBOL_NS_GPL(devm_adis_setup_kfifo_buffer, "IIO_ADISLIB"); > diff --git a/drivers/iio/imu/adis_trigger.c b/drivers/iio/imu/adis_trigger.c > index 3e6a7af6ab01..ea8661bff901 100644 > --- a/drivers/iio/imu/adis_trigger.c > +++ b/drivers/iio/imu/adis_trigger.c > + > +/** > + * devm_adis_register_fifo_trigger() - Registers the legacy trigger of a FIFO device > + * @adis: The adis device > + * @indio_dev: The IIO device > + * > + * Registers an IIO trigger named after the device. It is never used to push > + * samples, as the data goes to a kfifo buffer. It only keeps the > + * trigger/current_trigger interface of devices that always had it, so writing > + * it is accepted but has no effect. New drivers do not need it. We want to keep the current_trigger interface for existing parts but not add it for new ones. There can't be a regression on devices we haven't supported yet. So I think we either need to push the setting of INDIO_HARDWARE_TRIGGERED to the caller or have multiple helpers for the different cases. > + * > + * Returns 0 on success or a negative error code > + */ > +int devm_adis_register_fifo_trigger(struct adis *adis, struct iio_dev *indio_dev) > +{ > + adis->trig = devm_iio_trigger_alloc(&adis->spi->dev, "%s-dev%d", > + indio_dev->name, > + iio_device_id(indio_dev)); > + if (!adis->trig) > + return -ENOMEM; > + > + indio_dev->modes |= INDIO_HARDWARE_TRIGGERED; > + > + return devm_iio_trigger_register(&adis->spi->dev, adis->trig); > +} > +EXPORT_SYMBOL_NS_GPL(devm_adis_register_fifo_trigger, "IIO_ADISLIB"); >