Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp837452lqo; Fri, 10 May 2024 17:51:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU4+9I8XAnX3S5k/2ZxmUUDsH9aqvsbLuho9/Etf3qEs5IYxUUCzE/wGQATRtOPqzCgoj6MLpstN6QwgYOn/dJ2QhyWhpRBbl9ZuBjIeQ== X-Google-Smtp-Source: AGHT+IE0X9i7cl2vcnPpS8QAffzqnQeqqLFvaGMQX5HZXAKm91MQNMqx8bHct7+MzSZV8g969SVh X-Received: by 2002:a05:6358:2925:b0:183:6427:10b5 with SMTP id e5c5f4694b2df-193bcfc7770mr542182855d.21.1715388678800; Fri, 10 May 2024 17:51:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715388678; cv=pass; d=google.com; s=arc-20160816; b=u9RRosHXMF2NrnCYIs+P1uHhYFK/u24MgnSbfnjOJTTiohH2QehigD+WiRGH4dwzI6 VcFc/KC0f/7JfVVjOQakSeWcMZ1zT/uSFjwQRZup2nZo492Z5XK8zIYIDXGxHHyD+zn5 0IznqL71a6vxHCZfwFV3xoxyxgDtnt0qcVmxCEHnXPJq3r+bgRb+2CTS+noQyV5sp/+t JKzouH1QPNjS1vVmCy6Sy8qDchhRv9vfSvM5jit6DgQ4mir/PFNXndP6eybAnkBCpmju qU4IyXdijPpuP7aO8VbpxOLU9qH92DQWex+ryWelau+LLB5UhDakIJjqJjjS4uHKiHmT 5DBg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=E9avosEdgbBSX3dha6GG6j80VLMTNNyJjLCB0lyPzg0=; fh=GpAwVk1Ka66RmpCPhEG1aPKIeML3Sm0Uc1iAMZsUEkw=; b=i3Bys80dy5UpOag6X5m+P48XH923n+zUg3IKyKfis4jLmVBfu1wwmf26+9xSLMlWvz e6Zm17naNN2p1tU3FxkFgvPtNsqLOOlwTIXYjQigXZ8a41QtZRd2lbLO8XkYv848t78Q jCcjVj2evoH+APK4/JFYuCevW0utuSPWNLDQQnSkaKQ/WItIq76zgyd2ag/UilkOK+cR pGBkWNHx6Mtz69PzdF/P8DbJLAbkHbEfFRNY4w0bOJX8jdXY616lwdpWgV2ZTMux3Fl0 O4MJop0OS7aQCDk3XnAROx3wPft5PgQwIXK6FcFzXvAtO+2Y/9atavFpo9msS409ydxi ZHGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=I348MkFP; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-176327-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176327-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-63411347331si5052557a12.438.2024.05.10.17.51.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 17:51:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176327-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=I348MkFP; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-176327-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176327-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 33F45B2328A for ; Sat, 11 May 2024 00:51:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4ACA1BC23; Sat, 11 May 2024 00:50:04 +0000 (UTC) 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: 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 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-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: 8bit 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, struct spi_message *message) 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) + != xfer->offload_flags) + return -EINVAL; + } } message->status = -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(struct 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 operations. + * @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 controller @@ -751,6 +753,7 @@ struct spi_controller { const struct spi_controller_mem_caps *mem_caps; /* Operations for controllers with offload support. */ + unsigned int offload_xfer_flags; const struct spi_controller_offload_ops *offload_ops; /* 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 features * @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 { u32 effective_speed_hz; + 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; -- 2.43.2