From nobody Mon Feb 9 20:32:23 2026 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0787910958 for ; Sat, 11 May 2024 00:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715388603; cv=none; b=oEyf4H1qNfLmyVG6mbNBQ9ua378mObD3ihLezeJpMf/YXytg2ON/glSEW0xpwCwQ2SESPfOihxsdUUEJBV6Vcdb+ib9oeAhlW/Ciy8Fwfs0qAt6fx4QxH62rLVPxtcKr7h+13WohvQ7xcZDfjEip5nDfDBojNUzTiIwCZVMWoP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715388603; c=relaxed/simple; bh=h8IEiY34+3Sx3CIFgaB3bbWMmMeu0qPkNGGmC8siC3M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nQVO0bByV3nz/cycYcsenI9CdrJtb9BIYMAmbEY/a83MNbRJQnXwjZGjv9CPFD6oOStTA1M4f4SaQSC4CUW0DQbJ5SfCYReUzhTNg605m4uQpFxNw0gkiqMJle4pZTV2oaJJzCYT2lMdTYgh7zthmvZ3jjvpGJpUYv1LD2WXWsU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=I348MkFP; arc=none smtp.client-ip=209.85.161.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="I348MkFP" Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5aa28cde736so1517150eaf.1 for ; Fri, 10 May 2024 17:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1715388600; x=1715993400; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E9avosEdgbBSX3dha6GG6j80VLMTNNyJjLCB0lyPzg0=; b=I348MkFPYgz4UGsp8pm08TTEs8rDAJdCzNDAolDrrHfWIlgJVdh/HqE5Th2DR/XD56 yOz9sTIbVefJpSwAh+cNmAWCtPcKrinC7lMUFFTk97BJBs8GMaeLNv1vpshthz+g0GjL pbDNc0KC3COxrqUq4qyevIya45msb8rjpDVxCZBtGLAxyAaJyVtWBcm2jiNfkvX3c2oF yV+w6cEOUoLNPnbynSeKOz6XOtHE30Sg0QV7WrwTnZZH9CeZyq0V2ut9VFYzpLlDE2y7 XYFpjlT6x2FZ6nL5nOPzDArQX4zzeWir3LwS9cH2zRw5BhFIBLdJyaeWRpoqguIOyg5j Ys4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715388600; x=1715993400; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E9avosEdgbBSX3dha6GG6j80VLMTNNyJjLCB0lyPzg0=; b=T8JYz/xQ3VIFPPFgIXcyH0pnuCJNyOy15YUX1VGlBadsrruOpxwboyzGOOxqwb8eDc kk0MlIsN931BGnh6XvQEMFR/yUgZK29ulbgS+sKKWs/SO6H00pmyujAWILqczaTOvroH YDWPTux4G3y3cUr/CHugM6ZXK+D42cglXds2Notz4+WAEhdGNAn+5ipXbbrQB711V2XP 0HbP7vCOjojDTwBW7QJk8QBnQ++HLK5fXcqRt5aGsfYzLa91KLaBTDwPp5MXJhQtdnmf Vhf/71UM+zXHJ80cQLJYeGLncB2sYL1xNu+qioKVt1ymwbqN2g2Xj9SDjzr5p3WstjL6 sgzg== X-Forwarded-Encrypted: i=1; AJvYcCVgqqfTKuJmwHPh1DeH3XJeDyYPPY1zftNTmjqaD1leQJ5pCjI1o0BACWEgheMuWUGS+KLwqu2qkhge4NGdyaiqwQwRjDDqiNtt6RQl X-Gm-Message-State: AOJu0YwGI0XW+4kecp5RqdyVdLeRPvRmJ64P9lMijG2k6W5GmbiUpfkE kg7QD+FrwlXIsrpTXcIMTc0Zhj9cgxzNB1AWEMns7Rvby/AsgFWQUHfNsl6XZ8A= X-Google-Smtp-Source: AGHT+IHUqtShftifs93lP5ZXYqlRl7bulmdlCopbK5h5izie+OAx3wEuV9iUi7VdLK8osidQhFAkdw== X-Received: by 2002:a4a:904:0:b0:5b2:bc0:f38b with SMTP id 006d021491bc7-5b281956dc0mr4721017eaf.5.1715388600118; Fri, 10 May 2024 17:50:00 -0700 (PDT) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5b29015a3dbsm321132eaf.46.2024.05.10.17.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 17:49:59 -0700 (PDT) From: David Lechner To: Mark Brown , Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , =?utf-8?q?Nuno_S=C3=A1?= Cc: David Lechner , Michael Hennerich , Lars-Peter Clausen , David Jander , Martin Sperl , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Subject: [PATCH RFC v2 4/8] spi: add offload xfer flags Date: Fri, 10 May 2024 19:44:27 -0500 Message-ID: <20240510-dlech-mainline-spi-engine-offload-2-v2-4-8707a870c435@baylibre.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240510-dlech-mainline-spi-engine-offload-2-v2-0-8707a870c435@baylibre.com> References: <20240510-dlech-mainline-spi-engine-offload-2-v2-0-8707a870c435@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: quoted-printable Most configuration of SPI offloads is handles opaquely using the ID handle that is passed to the various offload functions. However, there are some offload features that need to be controller on a per transfer basis. This patch adds a flags field to the spi_transfer structure to allow specifying such features. The first feature to be added is the ability to stream data to/from a hardware sink/source rather than using a tx or rx buffer. Additional flags can be added in the future as needed. A flags field is also added to the controller struct for controllers to indicate which flags are supported. This allows for generic checking of offload capabilities during __spi_validate() so that each controller doesn't have to provide their own validation. Signed-off-by: David Lechner --- v2 changes: This is also split out from "spi: add core support for controllers with offload capabilities". In the previous version, we were using (void *)-1 as a sentinel value that could be assigned, e.g. to rx_buf. But this was naive since there is core code that would try to dereference this pointer. So instead, we've added a new flags field to the spi_transfer structure for this sort of thing. This also has the advantage of being able to be used in the future for other arbitrary features. --- drivers/spi/spi.c | 10 ++++++++++ include/linux/spi/spi.h | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 9ad7b04c26a6..4d34ccf91fd4 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -4189,6 +4189,16 @@ static int __spi_validate(struct spi_device *spi, st= ruct spi_message *message) =20 if (_spi_xfer_word_delay_update(xfer, spi)) return -EINVAL; + + /* make sure controller supports required offload features */ + if (xfer->offload_flags) { + if (!message->offload) + return -EINVAL; + + if ((xfer->offload_flags & ctlr->offload_xfer_flags) + !=3D xfer->offload_flags) + return -EINVAL; + } } =20 message->status =3D -EINPROGRESS; diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index ec8d875d31ff..42c39c17ba5a 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -501,6 +501,8 @@ extern struct spi_device *spi_new_ancillary_device(stru= ct spi_device *spi, u8 ch * This field is optional and should only be implemented if the * controller has native support for memory like operations. * @mem_caps: controller capabilities for the handling of memory operation= s. + * @offload_xfer_flags: flags supported by this controller for offloading + * transfers. See struct spi_transfer for the list of flags. * @offload_ops: operations for controllers with offload support. * @unprepare_message: undo any work done by prepare_message(). * @slave_abort: abort the ongoing transfer request on an SPI slave contro= ller @@ -751,6 +753,7 @@ struct spi_controller { const struct spi_controller_mem_caps *mem_caps; =20 /* Operations for controllers with offload support. */ + unsigned int offload_xfer_flags; const struct spi_controller_offload_ops *offload_ops; =20 /* GPIO chip select */ @@ -991,6 +994,7 @@ struct spi_res { * @transfer_list: transfers are sequenced through @spi_message.transfers * @tx_sg: Scatterlist for transmit, currently not for client use * @rx_sg: Scatterlist for receive, currently not for client use + * @offload_flags: flags for xfers that use special hardware offload featu= res * @ptp_sts_word_pre: The word (subject to bits_per_word semantics) offset * within @tx_buf for which the SPI device is requesting that the time * snapshot for this transfer begins. Upon completing the SPI transfer, @@ -1107,6 +1111,12 @@ struct spi_transfer { =20 u32 effective_speed_hz; =20 + unsigned int offload_flags; +/* this is write xfer but TX uses external data stream rather than tx_buf = */ +#define SPI_OFFLOAD_XFER_TX_STREAM BIT(0) +/* this is read xfer but RX uses external data stream rather than rx_buf */ +#define SPI_OFFLOAD_XFER_RX_STREAM BIT(1) + unsigned int ptp_sts_word_pre; unsigned int ptp_sts_word_post; =20 --=20 2.43.2