From patchwork Fri Nov 17 20:13:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 744878 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF650C5AE4B for ; Fri, 17 Nov 2023 20:14:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235749AbjKQUOZ (ORCPT ); Fri, 17 Nov 2023 15:14:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346234AbjKQUOU (ORCPT ); Fri, 17 Nov 2023 15:14:20 -0500 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4FDD1731 for ; Fri, 17 Nov 2023 12:14:01 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3b6ce6fac81so1439813b6e.1 for ; Fri, 17 Nov 2023 12:14:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1700252041; x=1700856841; 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=ja9GtlZjFcJxKQ+nfaNBwXl6V3JiSfQSXjsqjsMOXR4=; b=qeHkjhHMpbe+odDvMjcQssxmn9Jowjsrg73ntJ+RtcqkYbOiVvW5PZhwUrE4EK/xCh 1UDziF6/w3MfjL88xjkyZ3J5yLtUKySnM+qRrvzH759BslAaVqwVrf4bA+fLv1PlLESn ayjRjGQAZpwhXLGHM+OLdddEOL0xDC6gb6mZiGevesvubH2tm1CrFOvGgWefZHL906E2 yFEY1FhhH2QYdyiDUdspgMiwd9dixwAfbcsScBQmh1LBI6lfEC99UC8YHOdDUS1Tdh2A ktVLlKVKV4XQjg8Y17nkCpCHLXEb0NPON6TXTe/ao7zz7kq7TJm/OUnUGzkDtCuKOz6I zmqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700252041; x=1700856841; 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=ja9GtlZjFcJxKQ+nfaNBwXl6V3JiSfQSXjsqjsMOXR4=; b=W8zEuKJXa1lGI4TjKk1B2RNuNlqD9+vie11UY8sjVKE/2JuRZEnpdo7DYV8PAqHze2 rZI8aiH0XUZ0IUWnT/82qWqQqr7PzskBbvuxlJj/BNYHm02iJuXXpYvKp5dQ1x8Q9oaE 8Avr4hzYBxXrBbMAVzPnMd0ctxMWMC0KQMGrv7JwipaH/ID909QgjYSIM+onl72SY2Ag 5GOPWr4huY6QdkgFVeLk5KViapSfyY9V+odwyXpogHkKScLJXSxt7el2x8NptUNsV3dH BDya+4r005pIjgTTS1YjzGCeaUhUG1Wq+qQ8vJGdauPoQb+EGbadSU1qgTfzBO1cYKO/ Y4nQ== X-Gm-Message-State: AOJu0YxjR3oH9aRCdCZj5odw1shQFlb5VrJOi1M8sX2VgySpVZcHp9KR /CkhWZ3T662OwTjZo/8nqwwKikXV8hLiFks72K8wew== X-Google-Smtp-Source: AGHT+IEDfybKnOu/GGZq916PIuwCUX/WXL1yy1MdxiH5bac/b8Q9vM1y0sN41DdLNS8Rd6WpsgoCyg== X-Received: by 2002:a05:6808:1315:b0:3b5:6462:3191 with SMTP id y21-20020a056808131500b003b564623191mr555089oiv.48.1700252041296; Fri, 17 Nov 2023 12:14:01 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id l21-20020a544515000000b003a8560a9d34sm393814oil.25.2023.11.17.12.14.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 12:14:00 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Lars-Peter Clausen , linux-kernel@vger.kernel.org Subject: [PATCH 12/14] spi: axi-spi-engine: remove struct spi_engine::msg Date: Fri, 17 Nov 2023 14:13:03 -0600 Message-ID: <20231117-axi-spi-engine-series-1-v1-12-cc59db999b87@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> References: <20231117-axi-spi-engine-series-1-v1-0-cc59db999b87@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org In the AXI SPI Engine driver, the struct spi_engine::msg member was used to keep track of the current message being processed. The SPI core is already keeping track of this, so we don't need to duplicate the effort. In most cases, we already have a pointer to the current message, so we can pass it directly to the functions that need it. In the one case where we don't have a pointer to the current message, we can get it from struct spi_controller::cur_msg. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 60 +++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 120001dbc4dc..c39f478f34a7 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -112,8 +112,6 @@ struct spi_engine { spinlock_t lock; void __iomem *base; - - struct spi_message *msg; struct ida sync_ida; unsigned int int_enable; @@ -252,10 +250,9 @@ static int spi_engine_compile_message(struct spi_engine *spi_engine, return 0; } -static void spi_engine_xfer_next(struct spi_engine *spi_engine, +static void spi_engine_xfer_next(struct spi_message *msg, struct spi_transfer **_xfer) { - struct spi_message *msg = spi_engine->msg; struct spi_transfer *xfer = *_xfer; if (!xfer) { @@ -270,13 +267,13 @@ static void spi_engine_xfer_next(struct spi_engine *spi_engine, *_xfer = xfer; } -static void spi_engine_tx_next(struct spi_engine *spi_engine) +static void spi_engine_tx_next(struct spi_message *msg) { - struct spi_engine_message_state *st = spi_engine->msg->state; + struct spi_engine_message_state *st = msg->state; struct spi_transfer *xfer = st->tx_xfer; do { - spi_engine_xfer_next(spi_engine, &xfer); + spi_engine_xfer_next(msg, &xfer); } while (xfer && !xfer->tx_buf); st->tx_xfer = xfer; @@ -288,13 +285,13 @@ static void spi_engine_tx_next(struct spi_engine *spi_engine) } } -static void spi_engine_rx_next(struct spi_engine *spi_engine) +static void spi_engine_rx_next(struct spi_message *msg) { - struct spi_engine_message_state *st = spi_engine->msg->state; + struct spi_engine_message_state *st = msg->state; struct spi_transfer *xfer = st->rx_xfer; do { - spi_engine_xfer_next(spi_engine, &xfer); + spi_engine_xfer_next(msg, &xfer); } while (xfer && !xfer->rx_buf); st->rx_xfer = xfer; @@ -306,10 +303,11 @@ static void spi_engine_rx_next(struct spi_engine *spi_engine) } } -static bool spi_engine_write_cmd_fifo(struct spi_engine *spi_engine) +static bool spi_engine_write_cmd_fifo(struct spi_engine *spi_engine, + struct spi_message *msg) { void __iomem *addr = spi_engine->base + SPI_ENGINE_REG_CMD_FIFO; - struct spi_engine_message_state *st = spi_engine->msg->state; + struct spi_engine_message_state *st = msg->state; unsigned int n, m, i; const uint16_t *buf; @@ -327,10 +325,11 @@ static bool spi_engine_write_cmd_fifo(struct spi_engine *spi_engine) return st->cmd_length != 0; } -static bool spi_engine_write_tx_fifo(struct spi_engine *spi_engine) +static bool spi_engine_write_tx_fifo(struct spi_engine *spi_engine, + struct spi_message *msg) { void __iomem *addr = spi_engine->base + SPI_ENGINE_REG_SDO_DATA_FIFO; - struct spi_engine_message_state *st = spi_engine->msg->state; + struct spi_engine_message_state *st = msg->state; unsigned int n, m, i; const uint8_t *buf; @@ -344,16 +343,17 @@ static bool spi_engine_write_tx_fifo(struct spi_engine *spi_engine) st->tx_length -= m; n -= m; if (st->tx_length == 0) - spi_engine_tx_next(spi_engine); + spi_engine_tx_next(msg); } return st->tx_length != 0; } -static bool spi_engine_read_rx_fifo(struct spi_engine *spi_engine) +static bool spi_engine_read_rx_fifo(struct spi_engine *spi_engine, + struct spi_message *msg) { void __iomem *addr = spi_engine->base + SPI_ENGINE_REG_SDI_DATA_FIFO; - struct spi_engine_message_state *st = spi_engine->msg->state; + struct spi_engine_message_state *st = msg->state; unsigned int n, m, i; uint8_t *buf; @@ -367,7 +367,7 @@ static bool spi_engine_read_rx_fifo(struct spi_engine *spi_engine) st->rx_length -= m; n -= m; if (st->rx_length == 0) - spi_engine_rx_next(spi_engine); + spi_engine_rx_next(msg); } return st->rx_length != 0; @@ -376,6 +376,7 @@ static bool spi_engine_read_rx_fifo(struct spi_engine *spi_engine) static irqreturn_t spi_engine_irq(int irq, void *devid) { struct spi_controller *host = devid; + struct spi_message *msg = host->cur_msg; struct spi_engine *spi_engine = spi_controller_get_devdata(host); unsigned int disable_int = 0; unsigned int pending; @@ -393,29 +394,26 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) spin_lock(&spi_engine->lock); if (pending & SPI_ENGINE_INT_CMD_ALMOST_EMPTY) { - if (!spi_engine_write_cmd_fifo(spi_engine)) + if (!spi_engine_write_cmd_fifo(spi_engine, msg)) disable_int |= SPI_ENGINE_INT_CMD_ALMOST_EMPTY; } if (pending & SPI_ENGINE_INT_SDO_ALMOST_EMPTY) { - if (!spi_engine_write_tx_fifo(spi_engine)) + if (!spi_engine_write_tx_fifo(spi_engine, msg)) disable_int |= SPI_ENGINE_INT_SDO_ALMOST_EMPTY; } if (pending & (SPI_ENGINE_INT_SDI_ALMOST_FULL | SPI_ENGINE_INT_SYNC)) { - if (!spi_engine_read_rx_fifo(spi_engine)) + if (!spi_engine_read_rx_fifo(spi_engine, msg)) disable_int |= SPI_ENGINE_INT_SDI_ALMOST_FULL; } - if (pending & SPI_ENGINE_INT_SYNC && spi_engine->msg) { - struct spi_engine_message_state *st = spi_engine->msg->state; + if (pending & SPI_ENGINE_INT_SYNC && msg) { + struct spi_engine_message_state *st = msg->state; if (completed_id == st->sync_id) { - struct spi_message *msg = spi_engine->msg; - msg->status = 0; msg->actual_length = msg->frame_length; - spi_engine->msg = NULL; spi_finalize_current_message(host); disable_int |= SPI_ENGINE_INT_SYNC; } @@ -499,16 +497,14 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, spin_lock_irqsave(&spi_engine->lock, flags); - spi_engine->msg = msg; - - if (spi_engine_write_cmd_fifo(spi_engine)) + if (spi_engine_write_cmd_fifo(spi_engine, msg)) int_enable |= SPI_ENGINE_INT_CMD_ALMOST_EMPTY; - spi_engine_tx_next(spi_engine); - if (spi_engine_write_tx_fifo(spi_engine)) + spi_engine_tx_next(msg); + if (spi_engine_write_tx_fifo(spi_engine, msg)) int_enable |= SPI_ENGINE_INT_SDO_ALMOST_EMPTY; - spi_engine_rx_next(spi_engine); + spi_engine_rx_next(msg); if (st->rx_length != 0) int_enable |= SPI_ENGINE_INT_SDI_ALMOST_FULL;