From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63766C2BBCF for ; Thu, 17 Dec 2020 22:31:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22C09238A0 for ; Thu, 17 Dec 2020 22:31:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732152AbgLQWa5 (ORCPT ); Thu, 17 Dec 2020 17:30:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731867AbgLQWa4 (ORCPT ); Thu, 17 Dec 2020 17:30:56 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAC5CC061257 for ; Thu, 17 Dec 2020 14:29:38 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id n16so85759pgm.0 for ; Thu, 17 Dec 2020 14:29:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0vo+nW0dH46P2KHLc68abpdc4ZQATo0Haicb01r3gGc=; b=dbCU0DJ2thR9h4Iz7w1YVlFi+HfxzId5hJDFxlm3vZnAzRN4afmLNoXle64azsK4sg XbtjvivnBA8YgZchJk+neKH7GPHzVcuu/P02D4TEJFR9kqh+pt+StIQr9H6CfHjIykP6 DNwkmHOCIbIB/9vTRoIFtHqF22NYbFmtJ7rvI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0vo+nW0dH46P2KHLc68abpdc4ZQATo0Haicb01r3gGc=; b=TCdHKwDgF+Nlh6xP+1atoi1wi5+dTgTywjHoAGFKLktQHFUX9sVYhs263BpbGgvihI gs8CAm5tx0/Rk6/aas5CaYMAuuZXIUKwMe9cbAHsjL0fp5rSfDeRX+0Jx8182odJjQ6q /HQ8zYkMOGSsiw+Y6ur2TH4NVaIlP3lZh3ubyinyroyTiRQFLz8B4t0PL9cA2ae273Mr xuuqQQHtSfd4QENedE6FnTdfk5GydzBiJSgavywJbEFazmK12UQLAKvv2uSxI3K2aIRk JNMt1croplrNt9OH4/urpyszP/ScJOMABw//MXOR//WOjVpv1QtWY8OINiUCVF2mzTSh fTAQ== X-Gm-Message-State: AOAM532Bl8CDn3tpTBMWt+PmH0VNGfoaIFx3EOwcxaLPIrVgwUQdJQ4k K38h4kJ2CpO03zOFlfvnWrDggA== X-Google-Smtp-Source: ABdhPJwu2sL7WtP1xSDUnnnfQFJiRPkWMbpq8CPaTFt/Z+ZvMZIuOdvbcWPtbycwcQe24LffmO4WxA== X-Received: by 2002:a63:5845:: with SMTP id i5mr1291424pgm.355.1608244178430; Thu, 17 Dec 2020 14:29:38 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:42b0:34ff:fe3d:58e6]) by smtp.gmail.com with ESMTPSA id gm18sm5805850pjb.55.2020.12.17.14.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Dec 2020 14:29:37 -0800 (PST) From: Douglas Anderson To: Mark Brown Cc: msavaliy@qti.qualcomm.com, Stephen Boyd , akashast@codeaurora.org, Roja Rani Yarubandi , Douglas Anderson , Andy Gross , Bjorn Andersson , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org Subject: [PATCH v3 3/4] spi: spi-geni-qcom: Don't try to set CS if an xfer is pending Date: Thu, 17 Dec 2020 14:29:13 -0800 Message-Id: <20201217142842.v3.3.I07afdedcc49655c5d26880f8df9170aac5792378@changeid> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201217142842.v3.1.I99ee04f0cb823415df59bd4f550d6ff5756e43d6@changeid> References: <20201217142842.v3.1.I99ee04f0cb823415df59bd4f550d6ff5756e43d6@changeid> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If we get a timeout sending then this happens: spi_transfer_one_message() ->transfer_one() AKA spi_geni_transfer_one() setup_fifo_xfer() mas->cur_xfer = non-NULL spi_transfer_wait() => TIMES OUT if (msg->status != -EINPROGRESS) goto out if (ret != 0 ...) spi_set_cs() ->set_cs AKA spi_geni_set_cs() # mas->cur_xfer is non-NULL The above happens _before_ the SPI core calls ->handle_err() AKA handle_fifo_timeout(). Unfortunately that won't work so well on geni. If we got a timeout transferring then it's likely that our interrupt handler is blocked, but we need that same interrupt handler to run and the command channel to be unblocked in order to adjust the chip select. Trying to set the chip select doesn't crash us but ends up confusing our state machine and leads to messages like: Premature done. rx_rem = 32 bpw8 Let's just drop the chip select request in this case. We can detect the case because cur_xfer is non-NULL--it would have been set to NULL in the interrupt handler if the previous transfer had finished. Sure, we might leave the chip select in the wrong state but it's likely it was going to fail anyway and this avoids getting the driver even more confused about what it's doing. The SPI core in general assumes that setting chip select is a simple operation that doesn't fail. Yet another reason to just reconfigure the chip select line as GPIOs. Signed-off-by: Douglas Anderson --- Changes in v3: - xfter => xfer in error message. - More obvious in commit message how this happens Changes in v2: - ("spi: spi-geni-qcom: Don't try to set CS if an xfer is pending") new for v2. drivers/spi/spi-geni-qcom.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c index cf3db40ae5ba..b3ba092db489 100644 --- a/drivers/spi/spi-geni-qcom.c +++ b/drivers/spi/spi-geni-qcom.c @@ -207,9 +207,14 @@ static void spi_geni_set_cs(struct spi_device *slv, bool set_flag) goto exit; } - mas->cs_flag = set_flag; - spin_lock_irq(&mas->lock); + if (mas->cur_xfer) { + dev_err(mas->dev, "Can't set CS when prev xfer running\n"); + spin_unlock_irq(&mas->lock); + goto exit; + } + + mas->cs_flag = set_flag; reinit_completion(&mas->cs_done); if (set_flag) geni_se_setup_m_cmd(se, SPI_CS_ASSERT, 0); -- 2.29.2.684.gfbc64c5ab5-goog