From patchwork Tue Feb 4 08:54:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11364183 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 319EC92A for ; Tue, 4 Feb 2020 08:55:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0F7222087E for ; Tue, 4 Feb 2020 08:55:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="i3tDDc6a" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726230AbgBDIzK (ORCPT ); Tue, 4 Feb 2020 03:55:10 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:36082 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbgBDIzK (ORCPT ); Tue, 4 Feb 2020 03:55:10 -0500 Received: by mail-lj1-f194.google.com with SMTP id r19so17696812ljg.3 for ; Tue, 04 Feb 2020 00:55:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vtYL82EUWBDkrP3xF+FQMsvWNrmcMg1IbbGdl9pmLKg=; b=i3tDDc6aNncLBfno+CF9PvHHIe9LC37uz8BU1mB3hoQjRPMCyA818sMS4QVXOcITDi aOBr76AxjAgP4blPOM3eCJR0SxfLPTy85Rr0UiFmTzEKvFd5b3XdDiwjAZt8qOYGE8ND IO1KjvhW3hCtFLSUF9qIv9GUP6vPICSxs3XNonFVP80OlpRJm3EbL1se7otV6D40R8cZ NSbx38+HRnS9/w3MOWOIeKWUOUiirgbNduhbQ6ACapMlhaj6lKhwk+o1ODXS2Wu+IxNf 8yk7rHwj0ccApMqFxv1+q7GJoNjTdQ3anAyimt7kN0IC2moA0yE98rpZ6r4nIb0yAanW PJ+w== 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=vtYL82EUWBDkrP3xF+FQMsvWNrmcMg1IbbGdl9pmLKg=; b=ZGQ6f3NviKrb2oiJmD9wUaWcxfyfGjWOY7uyl0ZEBIo0TQhxuCpjL2Zmqsa729oVE9 w0x1XICxOkt3iJVgIH4cZDImozO8A2AehEJ/fHcTjeelZp5KbBKGKunTKWr5uSde0ONh Q/n/CDEu5dI3PMbd8MudNMNGP+z8QSA5dI8zKP7UPpPy6jQOssOJ4Q2EpFTayHMZvAfY fDl3afRtQolJ8LEWFZ+pwWcQNPLhAqQFl0EFbKUT219P1sUlQntf2AH3+JBEuXd3509O xVHn5Gto2p+42SaUwkCTYC2CBIUgfvagrujXNr1fhDcJD4TBjqQyPi4G5B8NbpbTe4Sl DK6A== X-Gm-Message-State: APjAAAWoCzkc+D5IfogberCaP99wp2062QL0h6ab0EBDBR70Gt8MXjxQ jMXIN1UdM2MoYK8bOa9QEBWkntRsekk= X-Google-Smtp-Source: APXvYqz5spGAUW9o4w2qNMgMVIQ2JfXKXFKTIuPHMl1XH50sWB5BNVu+ybfkyBGD2CiytzzUTFHinQ== X-Received: by 2002:a05:651c:102c:: with SMTP id w12mr16795849ljm.53.1580806508034; Tue, 04 Feb 2020 00:55:08 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:07 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 01/12] mmc: core: Throttle polling rate for CMD6 Date: Tue, 4 Feb 2020 09:54:38 +0100 Message-Id: <20200204085449.32585-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org In mmc_poll_for_busy() we loop continuously, either by sending a CMD13 or by invoking the ->card_busy() host ops, as to detect when the card stops signaling busy. This behaviour is problematic as it may cause CPU hogging, especially when the busy signal time reaches beyond a few ms. Let's fix the issue by adding a throttling mechanism, that inserts a usleep_range() in between the polling attempts. The sleep range starts at 16-32us, but increases for each loop by a factor of 2, up until the range reaches ~32-64ms. In this way, we are able to keep the loop fine-grained enough for short busy signaling times, while also not hogging the CPU for longer times. Note that, this change is inspired by the similar throttling mechanism that we already use for mmc_do_erase(). Reported-by: Michał Mirosław Signed-off-by: Ulf Hansson Reviewed-by: Ludovic Barre --- drivers/mmc/core/mmc_ops.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index da425ee2d9bf..446a37cc2a86 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -456,6 +456,7 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, struct mmc_host *host = card->host; int err; unsigned long timeout; + unsigned int udelay = 32, udelay_max = 32768; u32 status = 0; bool expired = false; bool busy = false; @@ -500,6 +501,13 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, mmc_hostname(host), __func__); return -ETIMEDOUT; } + + /* Throttle the polling rate to avoid hogging the CPU. */ + if (busy) { + usleep_range(udelay, udelay * 2); + if (udelay < udelay_max) + udelay *= 2; + } } while (busy); return 0; From patchwork Tue Feb 4 08:54:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11364185 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 987A892A for ; Tue, 4 Feb 2020 08:55:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7749D21775 for ; Tue, 4 Feb 2020 08:55:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xwBTVJug" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726053AbgBDIzM (ORCPT ); Tue, 4 Feb 2020 03:55:12 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:34097 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726196AbgBDIzL (ORCPT ); Tue, 4 Feb 2020 03:55:11 -0500 Received: by mail-lj1-f196.google.com with SMTP id x7so17723785ljc.1 for ; Tue, 04 Feb 2020 00:55:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=a7A+8EuI5CL4qmrNQ0e164pG8EiEQp/zBKjR7+3Tt3k=; b=xwBTVJugDpgLIqbNn7+t71r9h8/eqPT77/WoaGkit1MM1tgcfvoCRsbUbjwLZFIVoV HyWubAHxwlm8jAMjd4CGbCBHzOiZfjTR2pX98ZMkP3o2ts2ORvCVJB9atDfQQ2p1giXZ xBpKX+EA5xD0YgLkHPX6eRFPcCX8l/B3UHyFL/b5aiSA65s02amy1fQbAag7xHiOQb6m uuyi29nMqbiip/ZDFJ7HepK1R/uy219FJ5G5ej8HMUwZ3WW6BTMufJrUKq0Z2QOD6HM8 Mnjt2semfJ0VyY1NyoKrjzIEpBIzpKVEg13stQh0lKATi9fwAMvW0cNAKm0uyn4zLgX3 gNxw== 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; bh=a7A+8EuI5CL4qmrNQ0e164pG8EiEQp/zBKjR7+3Tt3k=; b=I5Hji6RwZOZWw9iE1hm3bdj39NwWiibDkTr1J5pVtTkzJpo3egR/9G+Cx2HkeEbwno WFCE5yQ+M7Af6ds35C6gaSP7neusTsKgHLoSrUy5TA7MWY/ds9kKcp6rvn9ky/5EPc2q NIGuNLEv9arLF4sq96i/deg2Q/5Ju4q+9h5sY+d+XQkMfAdHLTXygQhioIPCdfz3hChV /bh9iTTwbylmIRkorRzDOysWyDqY3h0ddV1xhQ9+VD5kf3en78gEtkP2Pfb5dhs0ik2j 4vsjOHI0EHeWe+iIjAB0wnQYOUhqGvDhXjm/iAZhv9Pv9BD2jLIw62RmUzYRxzNGvD9i sMgQ== X-Gm-Message-State: APjAAAVnABDFxzXfM5ecyttxTiaFoSCc3q+PyDhUaaaEZIXba5TvKFrt 9udBSzRlCQsu27/0K1NLaRhufcj60Cc= X-Google-Smtp-Source: APXvYqzHIRvaxK/AtXGkNR+2KxETLtsvk6DqS3y7G647+OpwPxuHp/s0NRS32/TREbKx/SFYsMcSfA== X-Received: by 2002:a2e:8755:: with SMTP id q21mr17091485ljj.156.1580806509559; Tue, 04 Feb 2020 00:55:09 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:08 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 02/12] mmc: core: Drop unused define Date: Tue, 4 Feb 2020 09:54:39 +0100 Message-Id: <20200204085449.32585-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The last user of MMC_OPS_TIMEOUT_MS was recently removed, however the define stayed around. Let's remove it. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc_ops.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 446a37cc2a86..35df97fe9cdc 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -19,7 +19,6 @@ #include "host.h" #include "mmc_ops.h" -#define MMC_OPS_TIMEOUT_MS (10 * 60 * 1000) /* 10min*/ #define MMC_BKOPS_TIMEOUT_MS (120 * 1000) /* 120s */ #define MMC_CACHE_FLUSH_TIMEOUT_MS (30 * 1000) /* 30s */ From patchwork Tue Feb 4 08:54:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11364187 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 062EB13A4 for ; Tue, 4 Feb 2020 08:55:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D057A21744 for ; Tue, 4 Feb 2020 08:55:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ViWufv1X" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726370AbgBDIzO (ORCPT ); Tue, 4 Feb 2020 03:55:14 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:35090 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726196AbgBDIzO (ORCPT ); Tue, 4 Feb 2020 03:55:14 -0500 Received: by mail-lj1-f194.google.com with SMTP id q8so17692432ljb.2 for ; Tue, 04 Feb 2020 00:55:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0GJq9tA3Io62JheI7iBf2w6LOIrqQ/a6e8cUoQjZMmA=; b=ViWufv1Xr+96Cd+lNIA+1z8HqQv1biss1J2rnTS0V+hDssQrciUWVmRT9y+QhIWMj0 IK3TUARrTJxGz3wD+hzZDHnamKkWUiD0ecRfCJX9bjqMlZnyHhC1lASK4VG9+5352YsH S799L2WwarvSuDMYYPgZFKbEQlT9gkJQ8WZDijpa44DQAT8fh3PXbEWqypTK9vlzxf9c T0s/mDqtT7pF5AWxKWWFskWyEb3Q6AtRrp3gSr2VTjSNmV/VjrLsxk/56vl+oQIOD8xX 0FGkFcMiCsFUtuCZu8KsS0VJKSghpJ0IVbKGidDi3p3hTahwZ/+C/RjQeBg/t6w7efIm J/6w== 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; bh=0GJq9tA3Io62JheI7iBf2w6LOIrqQ/a6e8cUoQjZMmA=; b=gBBEptLeN0HfhJVURR9KbWK+syv3zZgaKL6688dzvIDOAd/l/m16wPK0LT0EF+3fU4 weBmM7tNcwEgeeR7IXb3ZV64FtTS/47TrFEAxY9BqTr8t0jUa5iReYLuHQrdRcnL9z6t n+tTSSeCuGQC7nhryhiZ9WhKLEZ0b12UciGJookB25N8FdBwkvGT3IN14nY0pTkEkkYK nxBFonH6tDhi4Y+InUmb3wEj12+oA5IPZqaMHOYlnk+uf2H71S8XaqomHn6aiRBrDBH5 pMYt9uyEz2XpmpCVeDzQdRjfAYTnMs6je1vKzDa6GR1EJQw55HTAhltJcuK6/QhJwr1G mtzA== X-Gm-Message-State: APjAAAU99iNtz4ojb3UEKi/Ly3Q98+lo3UOE7vyOiTq/GGv1M/LsYZLb kvccJ371NT0rpAs6yP+NT2stH3S3l8Q= X-Google-Smtp-Source: APXvYqygbLawlcN0vVzBEz9H+kbNUCy252g+HSsYbyPjhrnKq/k+OTmLVe4pOiopdtj2tpFKQPRaTA== X-Received: by 2002:a2e:b80e:: with SMTP id u14mr17053415ljo.17.1580806511074; Tue, 04 Feb 2020 00:55:11 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:10 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 03/12] mmc: core: Extend mmc_switch_status() to rid of __mmc_switch_status() Date: Tue, 4 Feb 2020 09:54:40 +0100 Message-Id: <20200204085449.32585-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org To simplify code, let's extend mmc_switch_status() to cope with needs addressed in __mmc_switch_status(). Then move all users to the updated mmc_switch_status() API and drop __mmc_switch_status() altogether. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc.c | 16 ++++++++-------- drivers/mmc/core/mmc_ops.c | 9 ++------- drivers/mmc/core/mmc_ops.h | 3 +-- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index f6912ded652d..8a1f64065a47 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -1173,7 +1173,7 @@ static int mmc_select_hs400(struct mmc_card *card) max_dtr = card->ext_csd.hs_max_dtr; mmc_set_clock(host, max_dtr); - err = mmc_switch_status(card); + err = mmc_switch_status(card, true); if (err) goto out_err; @@ -1211,7 +1211,7 @@ static int mmc_select_hs400(struct mmc_card *card) if (host->ops->hs400_complete) host->ops->hs400_complete(host); - err = mmc_switch_status(card); + err = mmc_switch_status(card, true); if (err) goto out_err; @@ -1249,7 +1249,7 @@ int mmc_hs400_to_hs200(struct mmc_card *card) mmc_set_timing(host, MMC_TIMING_MMC_DDR52); - err = mmc_switch_status(card); + err = mmc_switch_status(card, true); if (err) goto out_err; @@ -1265,7 +1265,7 @@ int mmc_hs400_to_hs200(struct mmc_card *card) if (host->ops->hs400_downgrade) host->ops->hs400_downgrade(host); - err = mmc_switch_status(card); + err = mmc_switch_status(card, true); if (err) goto out_err; @@ -1285,7 +1285,7 @@ int mmc_hs400_to_hs200(struct mmc_card *card) * failed. If there really is a problem, we would expect tuning will * fail and the result ends up the same. */ - err = __mmc_switch_status(card, false); + err = mmc_switch_status(card, false); if (err) goto out_err; @@ -1366,7 +1366,7 @@ static int mmc_select_hs400es(struct mmc_card *card) } mmc_set_timing(host, MMC_TIMING_MMC_HS); - err = mmc_switch_status(card); + err = mmc_switch_status(card, true); if (err) goto out_err; @@ -1407,7 +1407,7 @@ static int mmc_select_hs400es(struct mmc_card *card) if (host->ops->hs400_enhanced_strobe) host->ops->hs400_enhanced_strobe(host, &host->ios); - err = mmc_switch_status(card); + err = mmc_switch_status(card, true); if (err) goto out_err; @@ -1468,7 +1468,7 @@ static int mmc_select_hs200(struct mmc_card *card) * switch failed. If there really is a problem, we would expect * tuning will fail and the result ends up the same. */ - err = __mmc_switch_status(card, false); + err = mmc_switch_status(card, false); /* * mmc_select_timing() assumes timing has not changed if diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 35df97fe9cdc..d2371612d536 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -430,7 +430,7 @@ static int mmc_switch_status_error(struct mmc_host *host, u32 status) } /* Caller must hold re-tuning */ -int __mmc_switch_status(struct mmc_card *card, bool crc_err_fatal) +int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal) { u32 status; int err; @@ -444,11 +444,6 @@ int __mmc_switch_status(struct mmc_card *card, bool crc_err_fatal) return mmc_switch_status_error(card->host, status); } -int mmc_switch_status(struct mmc_card *card) -{ - return __mmc_switch_status(card, true); -} - static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, bool send_status, bool retry_crc_err) { @@ -594,7 +589,7 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, mmc_set_timing(host, timing); if (send_status) { - err = mmc_switch_status(card); + err = mmc_switch_status(card, true); if (err && timing) mmc_set_timing(host, old_timing); } diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h index 8f2f9475716d..09dee8a466a0 100644 --- a/drivers/mmc/core/mmc_ops.h +++ b/drivers/mmc/core/mmc_ops.h @@ -29,8 +29,7 @@ int mmc_bus_test(struct mmc_card *card, u8 bus_width); int mmc_interrupt_hpi(struct mmc_card *card); int mmc_can_ext_csd(struct mmc_card *card); int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd); -int mmc_switch_status(struct mmc_card *card); -int __mmc_switch_status(struct mmc_card *card, bool crc_err_fatal); +int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal); int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, unsigned int timeout_ms, unsigned char timing, bool use_busy_signal, bool send_status, bool retry_crc_err); From patchwork Tue Feb 4 08:54:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11364189 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E989F13A4 for ; Tue, 4 Feb 2020 08:55:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BDD5B2087E for ; Tue, 4 Feb 2020 08:55:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="AUuH5mHb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726371AbgBDIzQ (ORCPT ); Tue, 4 Feb 2020 03:55:16 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:41689 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726343AbgBDIzQ (ORCPT ); Tue, 4 Feb 2020 03:55:16 -0500 Received: by mail-lf1-f67.google.com with SMTP id m30so11616115lfp.8 for ; Tue, 04 Feb 2020 00:55:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oo1kARjEhP98lYPlpiOSceeqz5RhRUO7sBl5qQa8iZI=; b=AUuH5mHbfdO0ptVloZto0bqI1nhiIzw/tiAZA6uR9t4iYf9c+gCCZ1bw5YEmJUAjeY eq49ZKn2fPLB2LeRXMB+9oR/o2qhxwtA7x2jQYKc7kOK5fh/sZglW1zy+yiifPGRXOGn /vXxNwIsFb30FQMPKBRlbtHHIQTmpDdm6aNSFn5KmPPHlOCkCyWgRe9TZFNjOqT4vvwk rvfm9laQtncLlFR4vSbrF9I/bBqGGZOk+10+a72KpvuYLf729usIhFiRlhUVPiGHcjWG C20Lsg9NcpJkz3qjP8EFZnrSi+maJPgnpcXX5D6674UCu/w6agCIAckq+Oxg7bNGYaUC DRcA== 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; bh=oo1kARjEhP98lYPlpiOSceeqz5RhRUO7sBl5qQa8iZI=; b=B+CM8H6ZTBF2KKtaOav3srPJvlvoIa2HdEgfGhRSvRazbimKEyrTabaWUhuBDn4HR3 H+p0X8Nm+0yT0/PKkGJwc8GAe51Cl8Wzhxw/bNe6h/McpmYM6iXP+/P0PPByguQTezha 872zSxIUeh73E3TRYFa/TUW5f24AcgmKCki8SKjOp3px4mYUScWPSP/08MN3Pcpzl10f EIfxttLQh2LfUtBJtQT6EB/O9BWXy9/Q0uHlTpe5lAFfWcpTGFCqXuzn9EP6+k//LLbv psavOGIqO8Zm4gdRU9CPWNPql1YdxP1Uma5ZUum60YMaNx0ni9V/7zXeKIK+TWslqMIA vpfw== X-Gm-Message-State: APjAAAXS8aTf+y3NJmZhh6e+g8cej6+pASKkNi3QCbDdhivpNE2lRLoW kOZmetNG+p1Fb8txkQXrS7JW/9bDyrc= X-Google-Smtp-Source: APXvYqzuAkLU0jn7W/55jifg0tyovaiaOysa+fQtbTBeeb3vRL2rGVgA4VBAsbln4wFuNCaC1UM4TA== X-Received: by 2002:a19:c014:: with SMTP id q20mr14613516lff.209.1580806512657; Tue, 04 Feb 2020 00:55:12 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:12 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 04/12] mmc: core: Drop redundant in-parameter to __mmc_switch() Date: Tue, 4 Feb 2020 09:54:41 +0100 Message-Id: <20200204085449.32585-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The use_busy_signal in-parameter is set true by all callers of __mmc_switch(), hence it's redundant so drop it. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc.c | 22 +++++++++++----------- drivers/mmc/core/mmc_ops.c | 11 +++-------- drivers/mmc/core/mmc_ops.h | 2 +- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 8a1f64065a47..648c1c79282f 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -1055,7 +1055,7 @@ static int mmc_select_hs(struct mmc_card *card) err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS, card->ext_csd.generic_cmd6_time, MMC_TIMING_MMC_HS, - true, true, true); + true, true); if (err) pr_warn("%s: switch to high-speed failed, err:%d\n", mmc_hostname(card->host), err); @@ -1087,7 +1087,7 @@ static int mmc_select_hs_ddr(struct mmc_card *card) ext_csd_bits, card->ext_csd.generic_cmd6_time, MMC_TIMING_MMC_DDR52, - true, true, true); + true, true); if (err) { pr_err("%s: switch to bus width %d ddr failed\n", mmc_hostname(host), 1 << bus_width); @@ -1155,7 +1155,7 @@ static int mmc_select_hs400(struct mmc_card *card) err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, val, card->ext_csd.generic_cmd6_time, 0, - true, false, true); + false, true); if (err) { pr_err("%s: switch to high-speed from hs200 failed, err:%d\n", mmc_hostname(host), err); @@ -1197,7 +1197,7 @@ static int mmc_select_hs400(struct mmc_card *card) err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, val, card->ext_csd.generic_cmd6_time, 0, - true, false, true); + false, true); if (err) { pr_err("%s: switch to hs400 failed, err:%d\n", mmc_hostname(host), err); @@ -1243,7 +1243,7 @@ int mmc_hs400_to_hs200(struct mmc_card *card) val = EXT_CSD_TIMING_HS; err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, val, card->ext_csd.generic_cmd6_time, 0, - true, false, true); + false, true); if (err) goto out_err; @@ -1256,7 +1256,7 @@ int mmc_hs400_to_hs200(struct mmc_card *card) /* Switch HS DDR to HS */ err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_8, card->ext_csd.generic_cmd6_time, - 0, true, false, true); + 0, false, true); if (err) goto out_err; @@ -1274,7 +1274,7 @@ int mmc_hs400_to_hs200(struct mmc_card *card) card->drive_strength << EXT_CSD_DRV_STR_SHIFT; err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, val, card->ext_csd.generic_cmd6_time, 0, - true, false, true); + false, true); if (err) goto out_err; @@ -1358,7 +1358,7 @@ static int mmc_select_hs400es(struct mmc_card *card) err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS, card->ext_csd.generic_cmd6_time, 0, - true, false, true); + false, true); if (err) { pr_err("%s: switch to hs for hs400es failed, err:%d\n", mmc_hostname(host), err); @@ -1392,7 +1392,7 @@ static int mmc_select_hs400es(struct mmc_card *card) err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, val, card->ext_csd.generic_cmd6_time, 0, - true, false, true); + false, true); if (err) { pr_err("%s: switch to hs400es failed, err:%d\n", mmc_hostname(host), err); @@ -1457,7 +1457,7 @@ static int mmc_select_hs200(struct mmc_card *card) err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, val, card->ext_csd.generic_cmd6_time, 0, - true, false, true); + false, true); if (err) goto err; old_timing = host->ios.timing; @@ -1955,7 +1955,7 @@ static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_POWER_OFF_NOTIFICATION, - notify_type, timeout, 0, true, false, false); + notify_type, timeout, 0, false, false); if (err) pr_err("%s: Power Off Notification timed out, %u\n", mmc_hostname(card->host), timeout); diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index d2371612d536..1c5b23d99b77 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -516,7 +516,6 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, * @timeout_ms: timeout (ms) for operation performed by register write, * timeout of zero implies maximum possible timeout * @timing: new timing to change to - * @use_busy_signal: use the busy signal as response type * @send_status: send status cmd to poll for busy * @retry_crc_err: retry when CRC errors when polling with CMD13 for busy * @@ -524,12 +523,12 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, */ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, unsigned int timeout_ms, unsigned char timing, - bool use_busy_signal, bool send_status, bool retry_crc_err) + bool send_status, bool retry_crc_err) { struct mmc_host *host = card->host; int err; struct mmc_command cmd = {}; - bool use_r1b_resp = use_busy_signal; + bool use_r1b_resp = true; unsigned char old_timing = host->ios.timing; mmc_retune_hold(host); @@ -569,10 +568,6 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, if (err) goto out; - /* No need to check card status in case of unblocking command */ - if (!use_busy_signal) - goto out; - /*If SPI or used HW busy detection above, then we don't need to poll. */ if (((host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp) || mmc_host_is_spi(host)) @@ -603,7 +598,7 @@ int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, unsigned int timeout_ms) { return __mmc_switch(card, set, index, value, timeout_ms, 0, - true, true, false); + true, false); } EXPORT_SYMBOL_GPL(mmc_switch); diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h index 09dee8a466a0..de0c509a3a38 100644 --- a/drivers/mmc/core/mmc_ops.h +++ b/drivers/mmc/core/mmc_ops.h @@ -32,7 +32,7 @@ int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd); int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal); int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, unsigned int timeout_ms, unsigned char timing, - bool use_busy_signal, bool send_status, bool retry_crc_err); + bool send_status, bool retry_crc_err); int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, unsigned int timeout_ms); void mmc_run_bkops(struct mmc_card *card); From patchwork Tue Feb 4 08:54:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11364191 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D02092A for ; Tue, 4 Feb 2020 08:55:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B871217BA for ; Tue, 4 Feb 2020 08:55:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="vDKmHIT5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726343AbgBDIzQ (ORCPT ); Tue, 4 Feb 2020 03:55:16 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:34137 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726196AbgBDIzQ (ORCPT ); Tue, 4 Feb 2020 03:55:16 -0500 Received: by mail-lf1-f66.google.com with SMTP id l18so11666593lfc.1 for ; Tue, 04 Feb 2020 00:55:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2girTLUrGbScTtnIlZ6XuD1dV3M/k01nSyAhQZV11Z4=; b=vDKmHIT5SDHsU9AK2bliTZLOcwGrBErh4K4eL0mY7bbEi0vVlSIXMd85Kh8qHNxpan 2RA/AFaZDs26iPqQBKFN09w4b53IsxcInpI0DEqU/pC0c00qPcwlqZZ45L73qnICUFTP uBeahzGzY1XOdmPcO4SS6kOFPA3XScC4JRKhPY0LV0VrTB7xvKWaW9fmAvnTZOQcM04U 8ZAD7GUDMwXLIQYWfhHikG+YOnwUlztoPMlVK2eB/6bwq5+rr7GS2vzDfWSwQx5wehd0 rajVNGMphU0qdpGKOCR7kZOkjDxHT387OyzmgiipcbpKJ0pTMa47ScXGnUXgq+3wMcBX AwSw== 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; bh=2girTLUrGbScTtnIlZ6XuD1dV3M/k01nSyAhQZV11Z4=; b=XvIA8YjVpmYgaLZKJWVblA/PdU965B2x76lYuDN10bt904AsU1sf0H89N3pqXYTXKO wzPOAFRPTJ0xivbierjGDQl5CB6qWkiQWwss+lPkkyErC2WDTBVzL4IvyErKdd0s/wFs EC9t3t4slTDkq/m1zDLrdNhS+xQi3aV8aaUBkaSPnkoTcvHnPPgyHSFLP6YS57vBOTei jnlekfOKqe6au5DiUkT+I5Zq8CTjKrCv6wo5+rPOXswkCNDzrCi80oWFtn5BzzOrZ92i CyF+H+FDmOOKjcR2+yTovD3cIkIfsDUqccjGI1r0Kd+7pDMUa2hka1832SsVDy9FTaUc hP9Q== X-Gm-Message-State: APjAAAUnAOWwICjnU8gFNSLA84WaHFtrirkUagb2KkDMIb4VWs3O/Ts7 UNr5ZD1RQK8kC8RIuHN98jWdYjdqVB0= X-Google-Smtp-Source: APXvYqwItyiLwKsf8ISebzKyLOSOTh9kkAWc+OYwODu5zqEDn0xrZfc6wmeVnXoaphVk6c0c4RoJng== X-Received: by 2002:a19:c014:: with SMTP id q20mr14543505lff.208.1580806514216; Tue, 04 Feb 2020 00:55:14 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:13 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 05/12] mmc: core: Split up mmc_poll_for_busy() Date: Tue, 4 Feb 2020 09:54:42 +0100 Message-Id: <20200204085449.32585-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org To make the code more readable, move the part that gets the busy status of the card out into a separate function, mmc_busy_status(). Then call it from mmc_poll_for_busy(). Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc_ops.c | 47 +++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 1c5b23d99b77..c17b13aacc6e 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -444,6 +444,34 @@ int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal) return mmc_switch_status_error(card->host, status); } +static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err, + bool *busy) +{ + struct mmc_host *host = card->host; + u32 status = 0; + int err; + + if (host->ops->card_busy) { + *busy = host->ops->card_busy(host); + return 0; + } + + err = mmc_send_status(card, &status); + if (retry_crc_err && err == -EILSEQ) { + *busy = true; + return 0; + } + if (err) + return err; + + err = mmc_switch_status_error(card->host, status); + if (err) + return err; + + *busy = R1_CURRENT_STATE(status) == R1_STATE_PRG; + return 0; +} + static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, bool send_status, bool retry_crc_err) { @@ -451,7 +479,6 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, int err; unsigned long timeout; unsigned int udelay = 32, udelay_max = 32768; - u32 status = 0; bool expired = false; bool busy = false; @@ -473,21 +500,9 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, */ expired = time_after(jiffies, timeout); - if (host->ops->card_busy) { - busy = host->ops->card_busy(host); - } else { - err = mmc_send_status(card, &status); - if (retry_crc_err && err == -EILSEQ) { - busy = true; - } else if (err) { - return err; - } else { - err = mmc_switch_status_error(host, status); - if (err) - return err; - busy = R1_CURRENT_STATE(status) == R1_STATE_PRG; - } - } + err = mmc_busy_status(card, retry_crc_err, &busy); + if (err) + return err; /* Timeout if the device still remains busy. */ if (expired && busy) { From patchwork Tue Feb 4 08:54:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11364193 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 085D813A4 for ; Tue, 4 Feb 2020 08:55:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB1D721775 for ; Tue, 4 Feb 2020 08:55:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ha6oLgAs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726375AbgBDIzS (ORCPT ); Tue, 4 Feb 2020 03:55:18 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:40658 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726196AbgBDIzS (ORCPT ); Tue, 4 Feb 2020 03:55:18 -0500 Received: by mail-lj1-f195.google.com with SMTP id n18so17662327ljo.7 for ; Tue, 04 Feb 2020 00:55:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EK9v+jTcdBM1CQqLn/KDsjlxwnI1HlWWrKAGRPO/Vyc=; b=ha6oLgAsulQR18W68tnvXp5MLS5yfM9h3Q19tvLAUsoBRkcJHx/JJ/yGhc1wY8PpU8 wrclzY/BzdTJoWoxXBASOKu4XftVufVPzvBuS1cxTlTytBnhXjcigZ+fx+Z0quSQuAZh eNHj6mVVsDRenvF4OL9qvYPxr/yOVynAHJLi5pecRrVSFHepZfCraVjC84CATuohZHeu jpj6GfiPP5OfT9n45RaGsGyBoUd20EQ5DfwG52nLPRzQTfUXZftlulNHE8sEHIyXFsIx v9lUrPMa9TsWWRVJcBHMNdD+/VHbmgNgEz+8yzvY5DFATcpHsQnggs/lIt4cynhZWXNq HHWQ== 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; bh=EK9v+jTcdBM1CQqLn/KDsjlxwnI1HlWWrKAGRPO/Vyc=; b=dcEwXWp/QkbLU6OCf9+Zj4MmZr+xKgGZ3svxdpl7JVHGeqIlZJ0jpuHhVgX5L0Oiab 02EEah6s0DCJHWF038DpdkSNrtFuKwy5VTnD6AY5FtY+rkFwOVDyH1iNmQQFavgdLZeS FlSE80VLf3+8PPOZ6rGomGHRNaWxACozpm9gzNAs02I9qbIz2KglWDfwsMxa+ijpzd7q ObFBWZr0JqbY8JizapBZo0HzbXXEgOKBwurxnFqCFZZyNnUzBVHSOI2wXaV37A7MN8T0 9ABpIqfJ3zoo+iuofghnJ3668ZHc8QU1d8iFd+P3DVWFLmWDKgdkRHe4haeM3+WtvTbS H3QA== X-Gm-Message-State: APjAAAXXspRwTUz4vL3CLXeywlyG37/EwwaD3n5+QA1KqZiwRJJQxlIT kpqjJ2PppALI3GIFXH56CggtQ6I5p0A= X-Google-Smtp-Source: APXvYqyMUlhNDDLuQnCnx3vW7zBKi3KAOhXIBQCsZHigT9gEe0pQfFAFeaXBGykKRdwwJxB5h8gsHg== X-Received: by 2002:a2e:995a:: with SMTP id r26mr17410355ljj.78.1580806516016; Tue, 04 Feb 2020 00:55:16 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:15 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 06/12] mmc: core: Enable re-use of mmc_blk_in_tran_state() Date: Tue, 4 Feb 2020 09:54:43 +0100 Message-Id: <20200204085449.32585-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org To allow subsequent changes to re-use the code from the static function mmc_blk_in_tran_state(), let's move it to a public header. While at it, let's also rename it to mmc_ready_for_data(), as to try to better describe its purpose. Signed-off-by: Ulf Hansson --- drivers/mmc/core/block.c | 24 ++++-------------------- include/linux/mmc/mmc.h | 10 ++++++++++ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 663d87924e5e..8ac12e3fff27 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -436,16 +436,6 @@ static int ioctl_do_sanitize(struct mmc_card *card) return err; } -static inline bool mmc_blk_in_tran_state(u32 status) -{ - /* - * Some cards mishandle the status bits, so make sure to check both the - * busy indication and the card state. - */ - return status & R1_READY_FOR_DATA && - (R1_CURRENT_STATE(status) == R1_STATE_TRAN); -} - static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms, u32 *resp_errs) { @@ -477,13 +467,7 @@ static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms, __func__, status); return -ETIMEDOUT; } - - /* - * Some cards mishandle the status bits, - * so make sure to check both the busy - * indication and the card state. - */ - } while (!mmc_blk_in_tran_state(status)); + } while (!mmc_ready_for_data(status)); return err; } @@ -1666,7 +1650,7 @@ static void mmc_blk_read_single(struct mmc_queue *mq, struct request *req) goto error_exit; if (!mmc_host_is_spi(host) && - !mmc_blk_in_tran_state(status)) { + !mmc_ready_for_data(status)) { err = mmc_blk_fix_state(card, req); if (err) goto error_exit; @@ -1726,7 +1710,7 @@ static bool mmc_blk_status_error(struct request *req, u32 status) return brq->cmd.resp[0] & CMD_ERRORS || brq->stop.resp[0] & stop_err_bits || status & stop_err_bits || - (rq_data_dir(req) == WRITE && !mmc_blk_in_tran_state(status)); + (rq_data_dir(req) == WRITE && !mmc_ready_for_data(status)); } static inline bool mmc_blk_cmd_started(struct mmc_blk_request *brq) @@ -1788,7 +1772,7 @@ static void mmc_blk_mq_rw_recovery(struct mmc_queue *mq, struct request *req) /* Try to get back to "tran" state */ if (!mmc_host_is_spi(mq->card->host) && - (err || !mmc_blk_in_tran_state(status))) + (err || !mmc_ready_for_data(status))) err = mmc_blk_fix_state(mq->card, req); /* diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h index 897a87c4c827..4b85ef05a906 100644 --- a/include/linux/mmc/mmc.h +++ b/include/linux/mmc/mmc.h @@ -161,6 +161,16 @@ static inline bool mmc_op_multi(u32 opcode) #define R1_STATE_PRG 7 #define R1_STATE_DIS 8 +static inline bool mmc_ready_for_data(u32 status) +{ + /* + * Some cards mishandle the status bits, so make sure to check both the + * busy indication and the card state. + */ + return status & R1_READY_FOR_DATA && + R1_CURRENT_STATE(status) == R1_STATE_TRAN; +} + /* * MMC/SD in SPI mode reports R1 status always, and R2 for SEND_STATUS * R1 is the low order byte; R2 is the next highest byte, when present. From patchwork Tue Feb 4 08:54:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11364195 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0619413A4 for ; Tue, 4 Feb 2020 08:55:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D22FC21744 for ; Tue, 4 Feb 2020 08:55:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bAo8GMut" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726406AbgBDIzV (ORCPT ); Tue, 4 Feb 2020 03:55:21 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41461 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726196AbgBDIzV (ORCPT ); Tue, 4 Feb 2020 03:55:21 -0500 Received: by mail-lj1-f196.google.com with SMTP id h23so17694849ljc.8 for ; Tue, 04 Feb 2020 00:55:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HwDebRrklVLgKidfwiVAchc7w1c7H8+6yL91Fz1oklE=; b=bAo8GMut8ZjWRtKyXCSHaye3xTLNgyT6mpHK8vINZrV1rELokXMV+JtCngT6qEUsQP g4spROSGU0INQUEgvlRSPPj9I6KUwxtQ39wuooKIBZURGjFjkzeCxDIQCq3jsMFaBMZO AZh4pCU8crJNa+Yk+M/kbCuiFzZ2jTUnmySYZfNdRgE2ncVEN5+D97YSjVWhbSFI/QZf ZpLjVG2KX3J4Tpxwp7Jce01stmchbl6rLhBXd7ojON/4ht63tPj3ter9til6gIHkkn/c vW7mxZdjci2OlijwIsHRd9UEyDv9zYOO8Wg5WxpTjXpeMNF9n+zqtypPbmn7IMgO2/xJ 180Q== 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; bh=HwDebRrklVLgKidfwiVAchc7w1c7H8+6yL91Fz1oklE=; b=YcsDVSuuvrIFtIj0wTEP+HHJMTl8X/HBtusrzalSUo7nROk8yHG1p0QOKt/iRQt+ZV WsieTQ4Myopd9aVn6BUlW7mmywHxvgmvUYaZ1ZB7dvc9y1Hyt9e24WXYvnBeTN4aUonL mcXWuJIN+I11RtM/NuNxO6i2cqD0KAIqRPtYQUVUtwAYBtbtBBbNvVmN4mNh6olnRklx oBbW5kETRTVAOKfq3K9TY5wTqmagpdE3dqGPVOsEhYNR/mlpAUfLXwuIfhv2RZRbg1wA L8JjceeuRVBXdODmR4REqtsJ7XA9TJnYytVTfSDVcsUMBzGG8yLDIiXgCc0+X13l7BZ+ sa7g== X-Gm-Message-State: APjAAAVYzQ19Wh/HiVhN9shKyYx1ulCXZuc/RQmlVR3H+dLYxOBXForb UPI9scNWTQN+kZQP16rD8LSGpS+HCdo= X-Google-Smtp-Source: APXvYqzIqvoS373Ujxxhc+HIzb+LltY67F8iDrdbGB2IDZ7FD8K3h8fWuQDTv3CaYNLN6e/+kslrvA== X-Received: by 2002:a2e:9a01:: with SMTP id o1mr17111793lji.247.1580806517553; Tue, 04 Feb 2020 00:55:17 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:16 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 07/12] mmc: core: Update CMD13 busy check for CMD6 commands Date: Tue, 4 Feb 2020 09:54:44 +0100 Message-Id: <20200204085449.32585-8-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Through mmc_poll_for_busy() a CMD13 may be sent to get the status of the (e)MMC card. If the state of the card is R1_STATE_PRG, the card is considered as being busy, which means we continue to poll with CMD13. This seems to be sufficient, but it's also unnecessary fragile, as it means a new command/request could potentially be sent to the card when it's in an unknown state. To try to improve the situation, but also to move towards a more consistent CMD13 polling behaviour in the mmc core, let's deploy the same policy we use for regular I/O write requests. In other words, let's check that card returns to the R1_STATE_TRAN and that the R1_READY_FOR_DATA bit is set in the CMD13 response, before exiting the polling loop. Note that, potentially this changed behaviour could lead to unnecessary waiting for the timeout to expire, if the card for some reason, moves to an unexpected error state. However, as we bail out from the polling loop when R1_SWITCH_ERROR bit is set or when the CMD13 fails, this shouldn't be an issue. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index c17b13aacc6e..c14e24570b4e 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -468,7 +468,7 @@ static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err, if (err) return err; - *busy = R1_CURRENT_STATE(status) == R1_STATE_PRG; + *busy = !mmc_ready_for_data(status); return 0; } From patchwork Tue Feb 4 08:54:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11364197 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B488C92A for ; Tue, 4 Feb 2020 08:55:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8142921744 for ; Tue, 4 Feb 2020 08:55:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="HmBIPL1I" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726196AbgBDIzW (ORCPT ); Tue, 4 Feb 2020 03:55:22 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:36959 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbgBDIzV (ORCPT ); Tue, 4 Feb 2020 03:55:21 -0500 Received: by mail-lf1-f67.google.com with SMTP id b15so11651327lfc.4 for ; Tue, 04 Feb 2020 00:55:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dhFxxDwJUKLwoCX90rahTvLMvFdyoyjOAB1gpaNjDR0=; b=HmBIPL1IiIS5Iy0IF/WVJ03hd1Mp1oBR7RlgZmVxd0DgNnwrMFGPsqqhnSIYMthEtb D8RkrugqbII51Zmble1Ef0hjj7mUKMm9Q/SBZeN+7atMFQlYSbruhK5r+DGsaqpRraMu f8aAlDXX2u04LhGFDz9Mjk/v0vgGNgZmMY5gUFV1QVGV8aXmxTLW4/YJL+8un1cWKFjl nYDXKuKqU+IGIxHTh2zfXzxlsKUzFIUIyTC8LiKv5Pyh2NMOE0DSC0ETQpITgt+eMrcf KK7c0fpGEKO5GLSE8qdnSS+ns7DriHOBvENTxC1qlY8d4exm9KMHEO/iNMiMSpfRPGMq Grvg== 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; bh=dhFxxDwJUKLwoCX90rahTvLMvFdyoyjOAB1gpaNjDR0=; b=qu9ZxLrTIqwaaCAKYkMnOnwHxqJ/Oh8dVwmr9JO5llzHdWMaM2KyRgCdnZztSlqsWE DMNK1k3Zk81O/bheAlXNrPMfcXe0sGL1OMXKADobhiBreFlgYC7Xqtq1YWJBwClET3kq swo6y9zZP3O1DDCKs5Xr9ycYpMtymecpptdkZ17bTr21SQHD2SCN8fGrKHApXLAEm5I9 YyDT+5EMrSd7WmMTJvEzlBTEbELb66oqNhxm2jLw5AycNZgKOaVghxA7JGnSW/b4XJMi j3dkcVUmSPlsw31O5MGfqyPC2SNmvNgA4Pje3IfSrEgMBkukV/w7nnedF71Pz/zsOgnz +J+w== X-Gm-Message-State: APjAAAWYSSt6I4jCadG80BpKwLErNxz2nTbQiCfH3UG+Rn67CxhoM2tN FdH9y5dQKK0rO8o5FS9wNrq6fUC72vU= X-Google-Smtp-Source: APXvYqxhxo3lUSX7fVwBs4DYVvPjzYUCpEfzxo0MqI0b0yuM7qaAfZm/BIeDe1tW5Sb6Pyco0IQdLg== X-Received: by 2002:ac2:5f59:: with SMTP id 25mr14334983lfz.193.1580806519186; Tue, 04 Feb 2020 00:55:19 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:18 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 08/12] mmc: core: Convert to mmc_poll_for_busy() for erase/trim/discard Date: Tue, 4 Feb 2020 09:54:45 +0100 Message-Id: <20200204085449.32585-9-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Rather than open coding the polling loop in mmc_do_erase(), let's convert to use mmc_poll_for_busy(). To allow a slightly different error parsing during polling, compared to the __mmc_switch() case, a new in-parameter to mmc_poll_for_busy() is needed, but other than that the conversion is straight forward. Besides addressing the open coding issue, moving to mmc_poll_for_busy() for erase/trim/discard improves the behaviour according to below. - Adds support for polling via the optional ->card_busy() host ops. - Returns zero to indicate success when the final polling attempt finds the card non-busy, even if the timeout expired. - Exits the polling loop when state moves to R1_STATE_TRAN, rather than when leaving R1_STATE_PRG. - Decreases the starting range for throttling to 32-64us. Signed-off-by: Ulf Hansson --- drivers/mmc/core/core.c | 36 ++---------------------------------- drivers/mmc/core/mmc_ops.c | 30 ++++++++++++++++++++++++------ drivers/mmc/core/mmc_ops.h | 7 +++++++ 3 files changed, 33 insertions(+), 40 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index aa54d359dab7..6b38c194d74f 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1658,8 +1658,6 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from, struct mmc_command cmd = {}; unsigned int qty = 0, busy_timeout = 0; bool use_r1b_resp = false; - unsigned long timeout; - int loop_udelay=64, udelay_max=32768; int err; mmc_retune_hold(card->host); @@ -1760,38 +1758,8 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from, if ((card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp) goto out; - timeout = jiffies + msecs_to_jiffies(busy_timeout); - do { - memset(&cmd, 0, sizeof(struct mmc_command)); - cmd.opcode = MMC_SEND_STATUS; - cmd.arg = card->rca << 16; - cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; - /* Do not retry else we can't see errors */ - err = mmc_wait_for_cmd(card->host, &cmd, 0); - if (err || R1_STATUS(cmd.resp[0])) { - pr_err("error %d requesting status %#x\n", - err, cmd.resp[0]); - err = -EIO; - goto out; - } - - /* Timeout if the device never becomes ready for data and - * never leaves the program state. - */ - if (time_after(jiffies, timeout)) { - pr_err("%s: Card stuck in programming state! %s\n", - mmc_hostname(card->host), __func__); - err = -EIO; - goto out; - } - if ((cmd.resp[0] & R1_READY_FOR_DATA) && - R1_CURRENT_STATE(cmd.resp[0]) != R1_STATE_PRG) - break; - - usleep_range(loop_udelay, loop_udelay*2); - if (loop_udelay < udelay_max) - loop_udelay *= 2; - } while (1); + /* Let's poll to find out when the erase operation completes. */ + err = mmc_poll_for_busy(card, busy_timeout, MMC_BUSY_ERASE); out: mmc_retune_release(card->host); diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index c14e24570b4e..5643277a4eeb 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -445,7 +445,7 @@ int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal) } static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err, - bool *busy) + enum mmc_busy_cmd busy_cmd, bool *busy) { struct mmc_host *host = card->host; u32 status = 0; @@ -464,7 +464,17 @@ static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err, if (err) return err; - err = mmc_switch_status_error(card->host, status); + switch (busy_cmd) { + case MMC_BUSY_CMD6: + err = mmc_switch_status_error(card->host, status); + break; + case MMC_BUSY_ERASE: + err = R1_STATUS(status) ? -EIO : 0; + break; + default: + err = -EINVAL; + } + if (err) return err; @@ -472,8 +482,9 @@ static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err, return 0; } -static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, - bool send_status, bool retry_crc_err) +static int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, + bool send_status, bool retry_crc_err, + enum mmc_busy_cmd busy_cmd) { struct mmc_host *host = card->host; int err; @@ -500,7 +511,7 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, */ expired = time_after(jiffies, timeout); - err = mmc_busy_status(card, retry_crc_err, &busy); + err = mmc_busy_status(card, retry_crc_err, busy_cmd, &busy); if (err) return err; @@ -522,6 +533,12 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, return 0; } +int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, + enum mmc_busy_cmd busy_cmd) +{ + return __mmc_poll_for_busy(card, timeout_ms, true, false, busy_cmd); +} + /** * __mmc_switch - modify EXT_CSD register * @card: the MMC card associated with the data transfer @@ -589,7 +606,8 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, goto out_tim; /* Let's try to poll to find out when the command is completed. */ - err = mmc_poll_for_busy(card, timeout_ms, send_status, retry_crc_err); + err = __mmc_poll_for_busy(card, timeout_ms, send_status, retry_crc_err, + MMC_BUSY_CMD6); if (err) goto out; diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h index de0c509a3a38..8cd05fb583da 100644 --- a/drivers/mmc/core/mmc_ops.h +++ b/drivers/mmc/core/mmc_ops.h @@ -10,6 +10,11 @@ #include +enum mmc_busy_cmd { + MMC_BUSY_CMD6, + MMC_BUSY_ERASE, +}; + struct mmc_host; struct mmc_card; @@ -30,6 +35,8 @@ int mmc_interrupt_hpi(struct mmc_card *card); int mmc_can_ext_csd(struct mmc_card *card); int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd); int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal); +int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, + enum mmc_busy_cmd busy_cmd); int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, unsigned int timeout_ms, unsigned char timing, bool send_status, bool retry_crc_err); From patchwork Tue Feb 4 08:54:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11364199 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D16813A4 for ; Tue, 4 Feb 2020 08:55:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3AEE82087E for ; Tue, 4 Feb 2020 08:55:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ru9kADQD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726479AbgBDIzX (ORCPT ); Tue, 4 Feb 2020 03:55:23 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:38697 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbgBDIzX (ORCPT ); Tue, 4 Feb 2020 03:55:23 -0500 Received: by mail-lj1-f195.google.com with SMTP id w1so17711266ljh.5 for ; Tue, 04 Feb 2020 00:55:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PxbxjkKlNhhTJR8wRb3j/yvmTz9T7alicVi9qKEvd6o=; b=ru9kADQD0UXkQwACZ1GbT3/7W1cbzO3TD6QfNYomaEic6ZW8/P8bpbj/lQDza77mgj saohAAZU31Y25zx4SvlEShhJrwpWpH3KACfbY+YSNlCjrZqDt2/VXjA/kTrDci3R4Lkb 4KMgVDun7UUS+70S52mzQgWv3q07xb8H8k6qk+mY8S+Z8eOJTj6niSB0wB9RqInRnfqm FL/K3avNb8/22wUk1TdX0Hs4bNabuaX9PNU1zeVNGFoFpu2EEuYo8aZO2gXuL9VRYKDA LFDTELOQn8Gnha2wzuoXcZly7kbC9iJgdqvbbGY9sIbwiqOi/IZYo57KL9vpoesoYvMu Y88w== 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; bh=PxbxjkKlNhhTJR8wRb3j/yvmTz9T7alicVi9qKEvd6o=; b=JstS7p2l9N383SdCFPr61c04EQ3KdvbZ9bdi/3Yqz/mF0Z21nDxG4EghTtxiMgQzW/ 4/RSFIpWU4dRKRDShVoVY4IIKUC7ZavXjrlp1uNUlxtBQqbu4Uk/1OdMULOxCZ8XO3Is LBDAwakFMdy+1oMgeo8s5Sp3mp/6ZvkGLFrMVlGIvtCCv96cft48gEO3zQ1y5L8QyOvX EGKJXGel6019223PtpILMBeIkMD8ijNaHmyYuK8q9+4lf9K1YWWC8jSUmBEsXcxc0+68 wz75G1gJm8COYTognUAc9OHfypF0hPSgvxjdx9c1wpDHfNhgRRMdK2cjD73EiZ+is68d VaYg== X-Gm-Message-State: APjAAAUEIRjY3OMTaB37C9haaDloIM1Sj3pQGAoyO9YYn8LNIvKWo1vF 48kda/y2nklZd9uSOvWq5odAAZMVLLI= X-Google-Smtp-Source: APXvYqxBCaIkCrcu5yJjmmxvB9EeCOgJ6U/zMI4geDwFqG525WpbeRBDbVdUFdJRhrvZBnZgPwV8dQ== X-Received: by 2002:a2e:9e19:: with SMTP id e25mr17858308ljk.179.1580806520658; Tue, 04 Feb 2020 00:55:20 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:20 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 09/12] mmc: core: Drop redundant out-parameter to mmc_send_hpi_cmd() Date: Tue, 4 Feb 2020 09:54:46 +0100 Message-Id: <20200204085449.32585-10-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The 'u32 *status' is unused by the caller, so let's drop it. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc_ops.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 5643277a4eeb..4d8f90d01740 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -827,7 +827,7 @@ int mmc_bus_test(struct mmc_card *card, u8 bus_width) return mmc_send_bus_test(card, card->host, MMC_BUS_TEST_R, width); } -static int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status) +static int mmc_send_hpi_cmd(struct mmc_card *card) { struct mmc_command cmd = {}; unsigned int opcode; @@ -849,8 +849,6 @@ static int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status) err, cmd.resp[0]); return err; } - if (status) - *status = cmd.resp[0]; return 0; } @@ -899,7 +897,7 @@ int mmc_interrupt_hpi(struct mmc_card *card) goto out; } - err = mmc_send_hpi_cmd(card, &status); + err = mmc_send_hpi_cmd(card); if (err) goto out; From patchwork Tue Feb 4 08:54:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11364201 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 49EF013A4 for ; Tue, 4 Feb 2020 08:55:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 272F42087E for ; Tue, 4 Feb 2020 08:55:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="eHizTPsn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726513AbgBDIzZ (ORCPT ); Tue, 4 Feb 2020 03:55:25 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:38821 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbgBDIzZ (ORCPT ); Tue, 4 Feb 2020 03:55:25 -0500 Received: by mail-lf1-f66.google.com with SMTP id r14so11636623lfm.5 for ; Tue, 04 Feb 2020 00:55:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4MoUz8e+cau8Xa7ChnTAxFphu0xbbPqaxCnfeEAChL0=; b=eHizTPsnr1OuaxkljuFvA0GqC4CKdaPoYVpAxKqjyXiKJbjxcsyGVaNmHuM/aCVmSj 8EpJotdRKkCcFIiiwxWwQEVFid2SGGI8FeToEKXasAmZvM19XrNlHcTHEUEVTAvDDX30 OaAG+WFqy8A78zqMAMSUBu3WBPMtn4Zw7Rscsy1Am2ueocR/OTfm8LNiEUBXY4uEGFQO BSTJno3fdP37LAIHlZsyBvFHVmihFR9Mpx1u7HF5gh85DJMA481xbRUs895qlrsqAfei aRIQICJcNDcIrZCTifg3GSoc1NKyz//SRTsxcUXBEXpnIrxhIh2LyfODwRRbvTjuUTG0 x6bA== 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; bh=4MoUz8e+cau8Xa7ChnTAxFphu0xbbPqaxCnfeEAChL0=; b=OqVwdMSc5XhJrQXiO/X7DnN3K7310VtEbzfSs6WRLked0hz4s+jDY2anmMg9uLyvpk tFMfzQ9k9WnXirdPHCdjhRpdYCtf9wtw3N5O3cuIs3aVgorIllRbxW1xQan1jESuC0lf plG13OiI9Pik2q7pjCMPXWshPQjeHaE98ZrZU0GKKnIM2wtkke0v7L/ZDl00uvFRWamn KHY0RoyirNslkGgWowPvhO+ODsgJnSGwMAzT2RBLk3r15dMHU9RXTorljz6AON4m3/c4 jgckkdB1+nDaqWAnZ2hCIWEIqIi+rXB72g1w6DQm1u835KjBE2WsT95ICwINSMZJKExJ Z4kg== X-Gm-Message-State: APjAAAWnPVgQQhuTf9uxCca+Vn6M0v3ahYfN84g3WecKA+4/KJgZ/sPa dTSjoWshkuyrrJY2jfaQRn3FJbD960o= X-Google-Smtp-Source: APXvYqycLBF/cQ1QLZbuX0A3oqIaEhvd983hPS/2XotETjrWa0tuCjLI/wsSJfbiArTwQtN+brBGyw== X-Received: by 2002:ac2:485c:: with SMTP id 28mr14319585lfy.118.1580806522261; Tue, 04 Feb 2020 00:55:22 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:21 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 10/12] mmc: core: Convert to mmc_poll_for_busy() for HPI commands Date: Tue, 4 Feb 2020 09:54:47 +0100 Message-Id: <20200204085449.32585-11-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Rather than open coding the polling loop in mmc_interrupt_hpi(), let's convert to use mmc_poll_for_busy(). Note that, moving to mmc_poll_for_busy() for HPI also improves the behaviour according to below. - Adds support for polling via the optional ->card_busy() host ops. - Require R1_READY_FOR_DATA to be set in the CMD13 response before exiting the polling loop. - Adds a throttling mechanism to avoid CPU hogging when polling. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc_ops.c | 20 +++++--------------- drivers/mmc/core/mmc_ops.h | 1 + 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 4d8f90d01740..87d54a559b31 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -471,6 +471,8 @@ static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err, case MMC_BUSY_ERASE: err = R1_STATUS(status) ? -EIO : 0; break; + case MMC_BUSY_HPI: + break; default: err = -EINVAL; } @@ -829,6 +831,7 @@ int mmc_bus_test(struct mmc_card *card, u8 bus_width) static int mmc_send_hpi_cmd(struct mmc_card *card) { + unsigned int busy_timeout_ms = card->ext_csd.out_of_int_time; struct mmc_command cmd = {}; unsigned int opcode; int err; @@ -850,7 +853,8 @@ static int mmc_send_hpi_cmd(struct mmc_card *card) return err; } - return 0; + /* Let's poll to find out when the HPI request completes. */ + return mmc_poll_for_busy(card, busy_timeout_ms, MMC_BUSY_HPI); } /** @@ -864,7 +868,6 @@ int mmc_interrupt_hpi(struct mmc_card *card) { int err; u32 status; - unsigned long prg_wait; if (!card->ext_csd.hpi_en) { pr_info("%s: HPI enable bit unset\n", mmc_hostname(card->host)); @@ -898,19 +901,6 @@ int mmc_interrupt_hpi(struct mmc_card *card) } err = mmc_send_hpi_cmd(card); - if (err) - goto out; - - prg_wait = jiffies + msecs_to_jiffies(card->ext_csd.out_of_int_time); - do { - err = mmc_send_status(card, &status); - - if (!err && R1_CURRENT_STATE(status) == R1_STATE_TRAN) - break; - if (time_after(jiffies, prg_wait)) - err = -ETIMEDOUT; - } while (!err); - out: return err; } diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h index 8cd05fb583da..38dcfeeaf6d5 100644 --- a/drivers/mmc/core/mmc_ops.h +++ b/drivers/mmc/core/mmc_ops.h @@ -13,6 +13,7 @@ enum mmc_busy_cmd { MMC_BUSY_CMD6, MMC_BUSY_ERASE, + MMC_BUSY_HPI, }; struct mmc_host; From patchwork Tue Feb 4 08:54:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11364203 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C90F092A for ; Tue, 4 Feb 2020 08:55:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A842B21744 for ; Tue, 4 Feb 2020 08:55:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="mRTuBhRB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726362AbgBDIz0 (ORCPT ); Tue, 4 Feb 2020 03:55:26 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:37802 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726506AbgBDIz0 (ORCPT ); Tue, 4 Feb 2020 03:55:26 -0500 Received: by mail-lj1-f193.google.com with SMTP id v17so17690070ljg.4 for ; Tue, 04 Feb 2020 00:55:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=76qzmT2N+APJISrybQoaQycmewwxQpEPkoOAn/iBjYI=; b=mRTuBhRBZ82PkPR7LXi/V9bxQp3U2BR2gSjOJVux+AEKQNVsxPOp1fXrgaQWGUBvRs FPuJfvGjDQeUpv+X2frr21Oz/3aiaXuIGiqznJF7edUyw1w3hEYX2XTFV2Z9UA8wd/4D mU6OHbfHnKKoPwXdA6h+GVJSbcjaxNFuOu6yC5bYNtZxqQ7KwGiOgLMt0xHxn2fvCt+6 ZjgwTrGw7UVMvVMoYjSStHvKUKRBEO2odeGKXsRK/biDa33GRLWKpGfe2cBAQqAKMBxC Qt97cO9ASTdzjFpCN/mltO51UOc58eKmA9CfkuLW7vXKTQNAGb5Tof+mQlWl7LWkgLz5 AFdw== 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; bh=76qzmT2N+APJISrybQoaQycmewwxQpEPkoOAn/iBjYI=; b=jcWFnvmqe2y7EIgBHI5rzUrxfjtUloSfKyqGfuovolM3X7m1z2QP0kJHk9aIXH06Gm REl1hLOuAEyxvQOVY86WvSYaVXGlAWN66AEC0WTnJ8s4Xld29AGUsrtZ0nyyqccvL+KS kJgJkIH461V6JtR6PVtHvz5vozF+cP8jUktW82HdJYSCMaW9LyqdEngfBFlMR2CTzxBo TebezobFnyg552aOGPrc9SQkqP778nGKrykde7MJScQFohObzjSBovWsGPTELMD+6UKT Zr6oLb1W4CWMvJwmC543GPyN56ktvm1mHH/wMEnEyg2DpoNSTwhVk5M4fdAHbwXxIpXa 0Gkw== X-Gm-Message-State: APjAAAU5UG/0a9qx8uN0xkoXCncP7ogVUxjxActaNbClNYG7/iAkJl9h 0gam8m1mj4OfjPml+PEPEJy5X7AuX8o= X-Google-Smtp-Source: APXvYqyk36ZqUcx/HJiF7kdli1JGrsdOSnZT4EvHE34Z+OOUynosTyy8bF3k69/OJn9iK5jum8m1XQ== X-Received: by 2002:a2e:9b05:: with SMTP id u5mr16835282lji.59.1580806523679; Tue, 04 Feb 2020 00:55:23 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:23 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 11/12] mmc: core: Fixup support for HW busy detection for HPI commands Date: Tue, 4 Feb 2020 09:54:48 +0100 Message-Id: <20200204085449.32585-12-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org In case the host specify a max_busy_timeout, we need to validate that the needed timeout for the HPI command conforms to that requirement. If that's not the case, let's convert from a R1B response to a R1 response, as to instruct the host to avoid HW busy detection. Additionally, when R1B is used we must also inform the host about the busy timeout for the command, so let's do that via updating cmd.busy_timeout. Finally, when R1B is used and in case the host supports HW busy detection, there should be no need for doing polling, so then skip that. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc_ops.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 87d54a559b31..aa0cab190cd8 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -832,27 +832,41 @@ int mmc_bus_test(struct mmc_card *card, u8 bus_width) static int mmc_send_hpi_cmd(struct mmc_card *card) { unsigned int busy_timeout_ms = card->ext_csd.out_of_int_time; + struct mmc_host *host = card->host; + bool use_r1b_resp = true; struct mmc_command cmd = {}; - unsigned int opcode; int err; - opcode = card->ext_csd.hpi_cmd; - if (opcode == MMC_STOP_TRANSMISSION) + cmd.opcode = card->ext_csd.hpi_cmd; + cmd.arg = card->rca << 16 | 1; + + /* + * Make sure the host's max_busy_timeout fit the needed timeout for HPI. + * In case it doesn't, let's instruct the host to avoid HW busy + * detection, by using a R1 response instead of R1B. + */ + if (host->max_busy_timeout && busy_timeout_ms > host->max_busy_timeout) + use_r1b_resp = false; + + if (cmd.opcode == MMC_STOP_TRANSMISSION && use_r1b_resp) { cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; - else if (opcode == MMC_SEND_STATUS) + cmd.busy_timeout = busy_timeout_ms; + } else { cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; + use_r1b_resp = false; + } - cmd.opcode = opcode; - cmd.arg = card->rca << 16 | 1; - - err = mmc_wait_for_cmd(card->host, &cmd, 0); + err = mmc_wait_for_cmd(host, &cmd, 0); if (err) { - pr_warn("%s: error %d interrupting operation. " - "HPI command response %#x\n", mmc_hostname(card->host), - err, cmd.resp[0]); + pr_warn("%s: HPI error %d. Command response %#x\n", + mmc_hostname(host), err, cmd.resp[0]); return err; } + /* No need to poll when using HW busy detection. */ + if (host->caps & MMC_CAP_WAIT_WHILE_BUSY && use_r1b_resp) + return 0; + /* Let's poll to find out when the HPI request completes. */ return mmc_poll_for_busy(card, busy_timeout_ms, MMC_BUSY_HPI); } From patchwork Tue Feb 4 08:54:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11364205 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2EAC692A for ; Tue, 4 Feb 2020 08:55:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0CB5321744 for ; Tue, 4 Feb 2020 08:55:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="r5GdvLAX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726553AbgBDIz2 (ORCPT ); Tue, 4 Feb 2020 03:55:28 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:43913 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726506AbgBDIz2 (ORCPT ); Tue, 4 Feb 2020 03:55:28 -0500 Received: by mail-lj1-f196.google.com with SMTP id a13so17650965ljm.10 for ; Tue, 04 Feb 2020 00:55:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KLjqRxjOu37hotK4LZ6sgid1xsi6x3z1IsXdytiYo/0=; b=r5GdvLAXN9EdLzVKnNrEIQlTqye2BCI+enOv/sqW+eNnO41xvphgSQ+xKMnCMSRJDM /3J0K6p27Ll3Eu3aUjPPf/VMbNgmDsNx9ZNL05Yajs/wGE8i0ITNJnBLrwhrCdq55h1e 5ScBvEc3pZo1MDGiTa7LYf95U6otdEDxAe8J18l5p0OsB/zfjIsDRVXKO/4/gKHY0ukK huGNt/yAFmwIlpf0oCvd++l1p5gWVolqk8ZprpzwKsyw2ptX0AOg77tlMCKpUYQLFrB0 JgbC7wJW7tkDses99Pig4geGlbqndqEFdmbo4iZQI4j/jS/BJ9G2flz09MNX00lUJIrb af4Q== 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; bh=KLjqRxjOu37hotK4LZ6sgid1xsi6x3z1IsXdytiYo/0=; b=j1puiG3YNNADIt/G1ERUv6zUisz4YO0zWiO530U873P0mWJBvh3a3QGDSxvUfzju/t 4KVUVzNixFpZDvnFEyVqyrpWJu7WgN0xifq1nfBzIKu7b5FCd8A450VXZI/m6C1uhYAy J8Tk1o9dORoQ7v9QIZ2BX2Nv1lVZkF3eTkM1Tbyo/AbquoyzbazDLR5AdiKv9OfkWd65 sAenefjtA/avpe9F+Lypxk3rAHYzKDM+JyhnQIrF0h5Y3kp1uYu9iT/5QOjkUDDyJMQp KOAgJTH2XWM8rq1MdH1pqEfi1hFRhJfZTFUCoV7GhdEvIyaKbp7CWTd40tCjz551YHH3 by5Q== X-Gm-Message-State: APjAAAXExmcdd9RBUzFkJPr5qkiJHk1NtPy7NQ+hXTRLPIuumPVBpWoN GBj0An7QO6bKJcfyiYvDqkwlXNOP62A= X-Google-Smtp-Source: APXvYqzyE9gMGXnT5ZFghzMWHqfr+J/2GenIi3CD0MpPlBQcqyhts9H7Vi4hlfbeXiaqRqMRpIq2DQ== X-Received: by 2002:a2e:808a:: with SMTP id i10mr16669196ljg.151.1580806525240; Tue, 04 Feb 2020 00:55:25 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:24 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 12/12] mmc: core: Re-work the error path for the eMMC sanitize command Date: Tue, 4 Feb 2020 09:54:49 +0100 Message-Id: <20200204085449.32585-13-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The error path for sanitize operations that returns with a -ETIMEDOUT error code, is for some reason very tightly coupled with the internal request handling code of the mmc core. For example, mmc_wait_for_req_done() runs code at completion of requests, to check specific sanitize errors. This is inefficient, as at it affects all types of requests. To improve the behaviour, let's move the error management for sanitize requests into ioctl_do_sanitize(), as it's really there it belongs. Moving the error handling requires retuning to be held, so let's do that. While updating this code, let's also take the opportunity to clean it up a bit. Signed-off-by: Ulf Hansson Reported-by: kbuild test robot --- drivers/mmc/core/block.c | 33 +++++++++++++++++++-------------- drivers/mmc/core/core.c | 17 ----------------- drivers/mmc/core/mmc_ops.c | 3 --- include/linux/mmc/core.h | 3 --- 4 files changed, 19 insertions(+), 37 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 8ac12e3fff27..db59c51052df 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -410,29 +410,34 @@ static int mmc_blk_ioctl_copy_to_user(struct mmc_ioc_cmd __user *ic_ptr, static int ioctl_do_sanitize(struct mmc_card *card) { + struct mmc_host *host = card->host; int err; if (!mmc_can_sanitize(card)) { - pr_warn("%s: %s - SANITIZE is not supported\n", - mmc_hostname(card->host), __func__); - err = -EOPNOTSUPP; - goto out; + pr_warn("%s: SANITIZE is not supported\n", mmc_hostname(host)); + return -EOPNOTSUPP; } - pr_debug("%s: %s - SANITIZE IN PROGRESS...\n", - mmc_hostname(card->host), __func__); + pr_debug("%s: SANITIZE IN PROGRESS...\n", mmc_hostname(host)); - err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, - EXT_CSD_SANITIZE_START, 1, - MMC_SANITIZE_REQ_TIMEOUT); + mmc_retune_hold(host); + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_SANITIZE_START, + 1, MMC_SANITIZE_REQ_TIMEOUT); if (err) - pr_err("%s: %s - EXT_CSD_SANITIZE_START failed. err=%d\n", - mmc_hostname(card->host), __func__, err); + pr_err("%s: SANITIZE failed err=%d\n", mmc_hostname(host), err); - pr_debug("%s: %s - SANITIZE COMPLETED\n", mmc_hostname(card->host), - __func__); -out: + /* + * If the santize operation timed out, the card is probably still busy + * in the R1_STATE_PRG. Rather than continue to wait, let's try to abort + * it with a HPI command to get back into R1_STATE_TRAN. + */ + if (err == -ETIMEDOUT && !mmc_interrupt_hpi(card)) + pr_warn("%s: Sanitize aborted\n", mmc_hostname(host)); + + mmc_retune_release(host); + + pr_debug("%s: SANITIZE COMPLETED\n", mmc_hostname(host)); return err; } diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 6b38c194d74f..95db8ffbdd35 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -403,23 +403,6 @@ void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq) cmd = mrq->cmd; - /* - * If host has timed out waiting for the sanitize - * to complete, card might be still in programming state - * so let's try to bring the card out of programming - * state. - */ - if (cmd->sanitize_busy && cmd->error == -ETIMEDOUT) { - if (!mmc_interrupt_hpi(host->card)) { - pr_warn("%s: %s: Interrupted sanitize\n", - mmc_hostname(host), __func__); - cmd->error = 0; - break; - } else { - pr_err("%s: %s: Failed to interrupt sanitize\n", - mmc_hostname(host), __func__); - } - } if (!cmd->error || !cmd->retries || mmc_card_removed(host->card)) break; diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index aa0cab190cd8..c08f8b723a3b 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -595,9 +595,6 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, cmd.flags |= MMC_RSP_SPI_R1 | MMC_RSP_R1; } - if (index == EXT_CSD_SANITIZE_START) - cmd.sanitize_busy = true; - err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); if (err) goto out; diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h index b7ba8810a3b5..29aa50711626 100644 --- a/include/linux/mmc/core.h +++ b/include/linux/mmc/core.h @@ -107,9 +107,6 @@ struct mmc_command { */ unsigned int busy_timeout; /* busy detect timeout in ms */ - /* Set this flag only for blocking sanitize request */ - bool sanitize_busy; - struct mmc_data *data; /* data segment associated with cmd */ struct mmc_request *mrq; /* associated request */ };