Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp41468lfv; Tue, 12 Apr 2022 16:27:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXt/ohbU6VzBcSkq5zMNriu/0+X7luinm0q0FP/iTBRr9jZBVHxpglJlFcjxEBFVNp5yPn X-Received: by 2002:a17:90a:b307:b0:1bd:37f3:f0fc with SMTP id d7-20020a17090ab30700b001bd37f3f0fcmr7564461pjr.132.1649806064069; Tue, 12 Apr 2022 16:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649806064; cv=none; d=google.com; s=arc-20160816; b=XvCjVP0v9dmh8C44oZrodNiAwu/rGAGjhkcqdsVH2z+AgZjl0UhBPA/GqjkqfNEW35 fXbkBaA454aRUocE0eSfvu3LuUhUuvgzR4jRjlOUmnUVtzS7dL1y5n111JOplqlSROLC anVynklUOcIq1kfKaGxUIs4n5m2hMOAApVbdzJAJCKj3xw3O2LEhZ94GKAx+sZ2BsNgr 1SQi0T27ovIjXQZBmm8Rp6fpfN23aIBkwN02qY5ZfIlIIsyaP0P8ICLT8gNG/GNJw+xg ZqS/u6kUSJblw+MFF956YcqxNppYdPYpk3Ri99zaekf3YpCE2keXKPmOA3sihYzWG5fO EeFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TYhdgRrAg34SGsyeYKcMOapOrrTnFlU0CvzhQO1bW+g=; b=Ss0rho+4FkRjWrQWzLSUn3t0IZ13npxokwIK+CiCMm2QsFiHxViD1DT2rVo8n9VTmH LaUhTBWIY5WQeySI0axN0L7taBcHdgcBX60+IwSWGkbAcIR5jjuQkp/8VMHVpKhjGKJV R6fm+ynqg0fQWzd4WlVQ9gywwPnz/7BC6UEGJsSVPd+LTVlFIAvsNAg8rELCk9Sob431 OyCexzueDtPkl6WJnBXs7d/6NSjL0KoRqGSsUYt2gtn5T9dn1TTv7//e4YLrzEHjIwYR bEekDckybQ9a+E1BfaILyywsvL8qMtVFDZgEuUq3Y0hJXkKSipsiCid5cEteS55MAbBi gk6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bGaAGG0J; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t12-20020a17090a448c00b001cbbe3349a8si3540092pjg.70.2022.04.12.16.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 16:27:44 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bGaAGG0J; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A40021AC434; Tue, 12 Apr 2022 14:20:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356555AbiDLIKo (ORCPT + 99 others); Tue, 12 Apr 2022 04:10:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353690AbiDLHZw (ORCPT ); Tue, 12 Apr 2022 03:25:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C22C326548; Tue, 12 Apr 2022 00:03:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 79FDEB81B4D; Tue, 12 Apr 2022 07:03:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF7E5C385A6; Tue, 12 Apr 2022 07:03:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649747022; bh=bWuNbO3Fbvl23uTLrLPtZAQFj3dcCqzwr4PEGeLC0wM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bGaAGG0J0dsYK4obEdYygFOf+d8D5in5+k3sjX7AiOouSMrMbyE73utW379PZMMz1 QHMlGBW0U2DyxPxdUx8lqkg5JDgMW4ImyGV4qM8vsnJgleXlrlY1nyFmKqvwkOKKik esEbEagrCnP+xqVh4kv+0NDopUviLFvBlVul/ako= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Loehle , Andy Shevchenko , Ulf Hansson Subject: [PATCH 5.16 216/285] mmc: block: Check for errors after write on SPI Date: Tue, 12 Apr 2022 08:31:13 +0200 Message-Id: <20220412062949.893581043@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412062943.670770901@linuxfoundation.org> References: <20220412062943.670770901@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christian Löhle commit 5d435933376962b107bd76970912e7e80247dcc7 upstream. Introduce a SEND_STATUS check for writes through SPI to not mark an unsuccessful write as successful. Since SPI SD/MMC does not have states, after a write, the card will just hold the line LOW until it is ready again. The driver marks the write therefore as completed as soon as it reads something other than all zeroes. The driver does not distinguish from a card no longer signalling busy and it being disconnected (and the line being pulled-up by the host). This lead to writes being marked as successful when disconnecting a busy card. Now the card is ensured to be still connected by an additional CMD13, just like non-SPI is ensured to go back to TRAN state. While at it and since we already poll for the post-write status anyway, we might as well check for SPIs error bits (any of them). The disconnecting card problem is reproducable for me after continuous write activity and randomly disconnecting, around every 20-50 tries on SPI DS for some card. Fixes: 7213d175e3b6f ("MMC/SD card driver learns SPI") Cc: stable@vger.kernel.org Signed-off-by: Christian Loehle Reviewed-by: Andy Shevchenko Link: https://lore.kernel.org/r/76f6f5d2b35543bab3dfe438f268609c@hyperstone.com Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/block.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1880,6 +1880,31 @@ static inline bool mmc_blk_rq_error(stru brq->data.error || brq->cmd.resp[0] & CMD_ERRORS; } +static int mmc_spi_err_check(struct mmc_card *card) +{ + u32 status = 0; + int err; + + /* + * SPI does not have a TRAN state we have to wait on, instead the + * card is ready again when it no longer holds the line LOW. + * We still have to ensure two things here before we know the write + * was successful: + * 1. The card has not disconnected during busy and we actually read our + * own pull-up, thinking it was still connected, so ensure it + * still responds. + * 2. Check for any error bits, in particular R1_SPI_IDLE to catch a + * just reconnected card after being disconnected during busy. + */ + err = __mmc_send_status(card, &status, 0); + if (err) + return err; + /* All R1 and R2 bits of SPI are errors in our case */ + if (status) + return -EIO; + return 0; +} + static int mmc_blk_busy_cb(void *cb_data, bool *busy) { struct mmc_blk_busy_data *data = cb_data; @@ -1903,9 +1928,16 @@ static int mmc_blk_card_busy(struct mmc_ struct mmc_blk_busy_data cb_data; int err; - if (mmc_host_is_spi(card->host) || rq_data_dir(req) == READ) + if (rq_data_dir(req) == READ) return 0; + if (mmc_host_is_spi(card->host)) { + err = mmc_spi_err_check(card); + if (err) + mqrq->brq.data.bytes_xfered = 0; + return err; + } + cb_data.card = card; cb_data.status = 0; err = __mmc_poll_for_busy(card, MMC_BLK_TIMEOUT_MS, &mmc_blk_busy_cb,