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: 183056 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064143ile; Tue, 4 Feb 2020 00:55:08 -0800 (PST) X-Received: by 2002:a05:651c:448:: with SMTP id g8mr17007807ljg.35.1580806508495; Tue, 04 Feb 2020 00:55:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806508; cv=none; d=google.com; s=arc-20160816; b=X3F5QnGbRjjwG+7drvam8dL0S9fMuMudrQgNsy2unuc7liF+yJPHP45H1BWyHNbYLE 0nFqhhG9hhOgaFd+zR+U252Z5sZgencfbuUB9vIDr5P33LxzONOwf07ZIbUbpbnM0hjP xY1Dom/Wdrg4ynDt/RiF4dtLSEVVDn47D/AVp730sQY0K2sU9BfTPfNo4ZGz8BH7EIC3 zKXnwdI347KKElegARx7iEQimO/rhWpnNdp21TUySX1wG8958LvNl0wD091sQKn3ZZaw Ohaoj8FESCdP+VpvYFhBk5Zdw0SDWCTIas84bCGuc6t4+EILUs7teDmeUF81JbicNo7p rXEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=vtYL82EUWBDkrP3xF+FQMsvWNrmcMg1IbbGdl9pmLKg=; b=hX2wz60wBdKHl4ySdVOsF5qdjUqTlWdZKYRBN5tgyOlNUMjuAnb8nmWN6M7ORIWIhc iMMxN/v7tPs4wcRQgGerpXHQI3GEIG0jPr3bWWoCIdnW6ZIi75PZEqkOdIPHh2+k5LrR Jl0By7qvmU/VqxkIBHjeGEGK6NwL/Cm9LP6XWfWL3PN9EBHzGwsJbj0CrRzCGH3V47Wf Gbbgy19nNxm0fhXpp4VfimqWE5QAMVQ44YL9BEQ0eKUv2FIx03ivc+CAzZCYNpOZYnq7 uV7msXPgsJFwp6oVuUGmG6iAK1OXdlawfrUCz8TF1IiwDCKM3BciD8/wd072h8rZr142 K+RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i3tDDc6a; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i11sor12312744ljj.35.2020.02.04.00.55.08 for (Google Transport Security); Tue, 04 Feb 2020 00:55:08 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i3tDDc6a; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=fYWqW4ScEt9HTgPcOoRD5V/+7huOpoCsmcOtnHYFEMQRMR/VTbgUQ7J4KrcFYKYRZ2 Ki7wIcnt4y8DSRCQM1H25EEBjXqm+hBXgyF5SJPunfNvN2NRu//zVcvhSG8R96tt7dgv CxsH6NxPLyle7eilQV7s53Ijun7B0iGKbGceN3XJ4PxarfZgbK4IR/ZwCeHWxm26WmuI 6m+lojs/hP0I4NNMC5xYar7X40vFYVwa1X51VciQpIybS68cCumMzRqsvtsVD9TyJdwX 5IvfSy645bVGB5BvAtSWcnjA4hAA1PlcClVCKkrSoWXOFqxaeEPqSTT5Y/Vvrc9GeObj qruQ== X-Gm-Message-State: APjAAAWzjg/9qtm6yWiQ+vFGrFIxSXaPQ9aoyqjTx50CV39cnsga7bMK gfdT091isGZ6oymPL5M9MszPLarU 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) Return-Path: 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 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 --- drivers/mmc/core/mmc_ops.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.17.1 Reviewed-by: Ludovic Barre 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: 183057 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064162ile; Tue, 4 Feb 2020 00:55:10 -0800 (PST) X-Received: by 2002:a2e:9d3:: with SMTP id 202mr17122192ljj.60.1580806509939; Tue, 04 Feb 2020 00:55:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806509; cv=none; d=google.com; s=arc-20160816; b=DWGwPxf7du4xP4OMHKvkN1QE18gxip6nCsHZdcIJUF9diRrUjnkU9CYihdPWqMZPfI RYShJoVnhA/g4u0gtjWhthjWvGTdctEl8JMtA1zRZsGLarVT4Lp60VX4tZENbixrEUFi mexzcQfpERmWnxovEmYKPlriohZCTZEkgbEMU86T9cnyB4XZOeiJvXG3WEGtzERHQ/tv FhkkwOBAbZZmam3JnfzNkawcTHFJFsjzP5L0KVPKgZTdXVErmYY6mV0tTL1569p978D7 u/ACW6OK95N1UPcx4WUXp0y2INWRyhO9gyQTswYSrnB49d+r9ifdFC/5LjCerQWW5UfF R3hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=a7A+8EuI5CL4qmrNQ0e164pG8EiEQp/zBKjR7+3Tt3k=; b=nhvP9oB0wUsXBrw3hP/tcty+dJnyW9YvOrY2U8ZmkYCcDqD0pal55p8osyWe6UFBfs iG+WcuUhRwlztQJc+L48dlxeI5h+CKJ5RasjzN8Gl1BGYOzS7lgINzMnuaylSpvYfqXo +XwS9cgPqumfC9Hie7ZhZTZvnSsuIoTgTqMijH5CGDXnMAa5aonCWoyBYvXe7LdfbGYx V//mCPhQtiEGzIiDzf4XoGvhSHQsQFhJVZxPytRIwcQO4AIDi30IgRM5Kf7yLytJI1lb 6yihpFJq5KnetblIDnQKVWYIwgF0k8WdvIUdXYD2lLkrsaBWt9mfz1o8uVw6MSGJ+ONk oy3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xwBTVJug; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a26sor12365621ljn.0.2020.02.04.00.55.09 for (Google Transport Security); Tue, 04 Feb 2020 00:55:09 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xwBTVJug; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=emYlB05rzU8gS97aqmsHF40qNFcQuPsRyZjWppxD3C0PcVAK1Y7dKix9kIIrnA8abV G4EnbfCBtWpyEN+vPEdWeH8HuE2nIm+PJC3FVjPXm5r4B735bjhDPB50ZjX+s5yEIi+J gyCFiTVs+W11Q9ZZAMqHFxb1yCpVbS/FuFbkC0rVGrTno5MGYhce8Vk0c6EyaMhrrxtv scC3njwTl3GIBlETX9NpGlF9VKiS79R8ti4aM5NkzwEQyseuv7oRN938TX4MRdHYrkul LQCfCspF/zKU9b/AQNDlXKKUg9qnSdLZTxhjUBxl66IUKZWtYCaOnBnbGIXpGTLTV83K XPyQ== X-Gm-Message-State: APjAAAXMH9XnkqPRTOR449itIHAgyC5DWc+Iak6i+Js34UMA5jc3csoQ sMxj1ABCVFC7cvNPgFOJPZdy89U2 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) Return-Path: 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> 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(-) -- 2.17.1 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: 183058 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064179ile; Tue, 4 Feb 2020 00:55:11 -0800 (PST) X-Received: by 2002:a2e:b68c:: with SMTP id l12mr16267512ljo.36.1580806511579; Tue, 04 Feb 2020 00:55:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806511; cv=none; d=google.com; s=arc-20160816; b=gufFaMBaeYbYpKOlKyFbuzsJK4+DNJ6liO+6RCrt+ypH+tZvDVJkuz82qNhMO1jC3M C3eCZEvxGDbjEClPvcKP92x5dLKMch8S3Jrzn3mPcdiX4Wdw3SYvso0M09R+h+lpsTIM gyo3om71YKshZKS6vshFfWCfVyt5DVw8ryJOKYXJR4oxYXvAZ8jrSwiGdbk9bupHHuxB LMaE7Ox+47UQqtae9hCNqJEG4yzTGSCAeZYcaiWb1YAfQLCPDbUCuWaG3CoPlyBA5vhZ mioXCdgeh0IWzxYuuIUk7/Wm24x0RL+32vUo9fXHPBQscTAHWpBr3U4RIlXxhYQj9xfF ACfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0GJq9tA3Io62JheI7iBf2w6LOIrqQ/a6e8cUoQjZMmA=; b=RS/6CFImYIDrUNDr0ui99rIiNCd3aiZ4SebdA7dDJA8LMCZnkjHE16FfO4VW1oJTly HtxxaxjS5sThqWviYq7mIJE0liUxSSAREZJ3BRFYtw0T4w62AMuwz7gPKEGLjEvlIBS+ YLCQwXYjn47GiZU2fC98yWehtqeBP53o8GwYyg2tF38CokGnsKu8mPxSeQj2Cj0/UzJy Y8B2JaEryAIWNVKRCnjrz24+2iZ+vMe4iAjQvtDovYEH7ilTB8n8L1L27jQuDb5+EMDi 4lsc1iKstGv0wNMdVd2Sbof14/teeG3yEcC2pWNZEuUzUhwYR5dCEdltIrWOxVMe5tAW z3kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ViWufv1X; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h8sor12391450ljg.36.2020.02.04.00.55.11 for (Google Transport Security); Tue, 04 Feb 2020 00:55:11 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ViWufv1X; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=NRcQfDOIYnYFqOkqbP+SEEsdn+5O3kCP4YqoEHcuB/mN1g9tPCtyHfhccSXFIONi+/ DBTJdI6595AqShRZXTNk1BpZGvuhqTY1xSPHvif17xJyi+5MptiF6sYnmH+jZJ6fJyay cMOCmYxtQNB6cOTFjyfmBodBsTlNBEjgmKdVerC/qq4nA43zwEDTfIXJnz1vazQ7nsc2 WcYPpXAXDAPSGmpSJnUjnD1DUGlDZ1JB/YGoUtRxNWWcqq4it8M6NQp7IYutofa1Srap skbDFdTJe/+zaXz0YpmNgaRORhJv/kA3XnAdDc2xOmMN5I3d5OCt9GLppT9+Q9tPGRp9 PrVQ== X-Gm-Message-State: APjAAAXMEx6/ZsXLgsUOd/UiARVuojEhRslO7oZq+UKlZgtXwINrBNnW lFqnpwyqkCH3XOrJAdNYQRHCxfS6 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) Return-Path: 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> 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(-) -- 2.17.1 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: 183059 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064203ile; Tue, 4 Feb 2020 00:55:13 -0800 (PST) X-Received: by 2002:a2e:9b05:: with SMTP id u5mr16834796lji.59.1580806513122; Tue, 04 Feb 2020 00:55:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806513; cv=none; d=google.com; s=arc-20160816; b=z7L5w50Zt70X/i+91Ey5z/EeZVf0mJB/5iCcX2XvgfQhpBYMSFvbN9PeINqEJ1uJ9q GHi4AFa0H3tz1KLgT5Cw02WXEOy8lf9bXDe4JZV9mE/8dkMKV5uRR3v9mhmfR3ssZUCu AfpzK69ThjB2cLi/tO003e11z+AhKZXEauM4xW6eQoC0greifko3dmJ/cA6Kcx68ZV0W nJ8hHJ51iN2JXdBKwvBYmf9vM5mnuakgk2UTBvrRXyMo1HSj3Xf/APbYsxA9Zj/anrLH fFTTLVplOBDqIt7PYIi60nXOXTqIjH72oP2r1SDCIwYqUxuzIcou00aUl0kK3e9ylXUt Br6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oo1kARjEhP98lYPlpiOSceeqz5RhRUO7sBl5qQa8iZI=; b=PgTOlV+Us3WPr4FhyECbN7IpmsAcmtujiJ3clsxPcA8dVYor5Ip0usc8CF8tG2l1nB yG9ZJBZwGPx3+ZD6t5DH+YdATG92Of67BwgltayiYoTNCl/BG5O/mFDsDZTCOZJhfuS8 WoP5cpbBJWpKo/G6Mwba2JD/25XuNrt3bu7J4H1vLac8RJ3BbELAQWY4ahUNpo29Nywb jXvCBZq877FU7UJfzabmUaIAqTkYsACMsUUC3SWcbb5DnpyWA5wIFg1HvLRfNtZ/W9ba t8xSHnSqtyg06Kv+x/7cXlXpsEDtmY4VO5Raezf5cAfCEAqrjnO9VxtmXknHURmxbgWj zCRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AUuH5mHb; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h17sor5363390lfc.1.2020.02.04.00.55.12 for (Google Transport Security); Tue, 04 Feb 2020 00:55:13 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AUuH5mHb; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=dYG9w9DBXcIMgOb5egZpk1AwUOM3yBmpLIIlBsp4/ICsL31cOP8lUuPsSJOHDxG0Hl ClHqR9hUoEP2mH6umF0ydHgn9EdVkdW+YkH45DHwKTnHP+MY5x7VcbL3UoIg5lkUpl7p qWrS1mbksIE2Um2JqYDiBkCkAAUSZVDscMcFjeUb8sXjpG4jnuY823ij+5syQt4qRuka WPQ5g097nvLCbLGeKJ9bHoT7Ks9Jnbz9JXxhJQ0UOmiE8nqszWv3tJyAGC9B/CuVocS6 3JV4A+2FkWWL4uAy4xgSf2GyFHNfYS9673KWsA1rwjEf5c9mvkiz+W0exPqqKsKsTL6a HKDw== X-Gm-Message-State: APjAAAV4Nkfx3aHpW5c7QUNI59+lahT/WcNUtzRbSS0WZ6T6yZ4fNqKJ y+fEoHqQYB/McMsNuZLqGZBuRMXK 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) Return-Path: 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> 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(-) -- 2.17.1 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: 183060 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064223ile; Tue, 4 Feb 2020 00:55:14 -0800 (PST) X-Received: by 2002:a2e:a0d0:: with SMTP id f16mr16670837ljm.130.1580806514626; Tue, 04 Feb 2020 00:55:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806514; cv=none; d=google.com; s=arc-20160816; b=l2zVdLNJF7W2ovx3HtKPnnP9hpT0WJKpBVWe7jmLWIeMJvqoU2XNxuc3caGjWThJYI o0KLLGrKWDrECekft+CtBKKkAwky9Ao2t0YuAPe6OEmdFyQOAevaPTLIVg0BXArM2EH5 Uo2l9K1LefWtbJOO7LIk29mLX310DTiNXcB+rToZoaNFFiK5DqhUIaTMuuirW3kvK36g c2daEVSMhGXGLEYXpbdHmFVP/7Kd7WL5wJSaGO8b+DK4CiDgMemZwUFOcjoSwiG60C52 hp6VGdQmthAnyRz2JIvmHe/zx+TloY+BOLbB8c7ASwe2xs/GXrhfrKrLrwt60LjeHLBo H/KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2girTLUrGbScTtnIlZ6XuD1dV3M/k01nSyAhQZV11Z4=; b=fLo8Miidh/7n5sc2lgvZXD1oubhgdhmLIKt049jOoBBuduwW0irmhX7b6g1QrU0VcW jVF3I1L2cC53M8596RXblpuXmZBGlRZC0hQUP/u472xXckGFK3mbGwmOuJNftmBurq2U E9KEZtIN4pt67CsuDkQQzCBt2QhmavJorXvGbofDOmV7KkaM2jg1rClBijHuF1VARXbT DfLbU+xozhuWzhwphmucumVzyBedpSK7wLBa9zILk3wEjEuA5CgwWj20KcO2bkWQ+Qw6 lju3FvQk+r0z/WSlaUY9948cmJoQXRIykqrTIRY37vN/n/duvt68xf3ZkugKMACeYYz8 70IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vDKmHIT5; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m8sor5267815lfp.3.2020.02.04.00.55.14 for (Google Transport Security); Tue, 04 Feb 2020 00:55:14 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vDKmHIT5; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=MO0M4BEfNVnFwlFZm3hMfoCWARhsgb7p2bGPrNtMo4bZjfu4iwz5sK5FSrkXp+JKbZ JXqAeUxK8orGvIXPO21XWQx6RA2sNKI62Fpk1H5+Gi/E4qZNEnFBuK6IvtoG8u0Si2mC TTj70Y4GPXSVsnnJx9/fxAi1x/0RbQgk6NUUYv5HxdgqNl0oYlpA6rO1+Tpa0DBYBPM0 aLfooZw3LlOzzufNt0/iSyZaZADuC+vwwHTEpb1ieog1FtgBGpYW78/gcZLXBuooP2Om fPahv9MVii3RPqyRbID6K+qefls4GubTR8SR+1U22qNSbID+dyOZqRk6nvIuxykf2NkA MZjg== X-Gm-Message-State: APjAAAW1GQn/pwsjcnXKhNlt8/X1wc6xkl5Po42yOlh4DNgKeNrS4X6D scZRySxgsjgD39bSlgvSlT8S3GWfEzfGYw== 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) Return-Path: 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> 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(-) -- 2.17.1 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: 183061 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064257ile; Tue, 4 Feb 2020 00:55:16 -0800 (PST) X-Received: by 2002:a2e:9b03:: with SMTP id u3mr16761966lji.87.1580806516429; Tue, 04 Feb 2020 00:55:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806516; cv=none; d=google.com; s=arc-20160816; b=FV6AI2pLQxiitzT7m3WvcE6J617DX8hTyimqBiLx90cXlZ7WUkp4SQxDapnl92NjYj PH+uKr3pt529ZmGBZzjRTUvMMDBI7gPfWIyxwyU2hqeArBjDUPJaSnIiUHBUkPcn9Lq9 +sa9Y8eBCTa0K05yQnVVFdbQsfrLgM6WrPDRSfPT1vI/iQ4RlUD83q696Wqo4u9AaTjs ySIGqQrm7Pw/dUBJqPO1/OWCD/aev4FPVS7fG0q+BsPD1yAcG/zdsZWo1fXIUUGBcQlz UmLCcauuyxmkDGi/ubHWLSHcqFH7qffyruxSH8g6yPxoCSrXKJYoPNUZ8N+NTQHjRsub Lu7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EK9v+jTcdBM1CQqLn/KDsjlxwnI1HlWWrKAGRPO/Vyc=; b=aqM+10pm7M1YoiEyeWC54qtCgVhiQ5QrjB3aTUB9c3k4CB8YvBFjcWL9vlqH+7WLXk 2kxg+rB2Jn3/MOoA6/BdA2oFI4rkb8Q13Ui5oAQNzN+D0LIIO5SGylJWNfHUGwfC9QoH zaWZedAIHxp7Wrh2wdNb0t0LlY9+zg2TIpcHD1OufC0Dkwmy37098WbPcWll2DEBvFfJ indxkdr9UU5/Ov8OkZCDGqMgcrAqiqaTSQRUQN9uPrzFidRg+DIv2m7IeVtE++iZfZio Dr+A6oWrdLa/vZRYAKJALF74+eZ7wLGVi3aDwHdcXrCMCuFxOwZnUEPkClJF0spWS8sV +VMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ha6oLgAs; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a26sor12365835ljn.0.2020.02.04.00.55.16 for (Google Transport Security); Tue, 04 Feb 2020 00:55:16 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ha6oLgAs; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=ptl4tfmHFLrFkEcSYeKiLJbH+ms2gezYJgibLRu9mZLc7xdXNbwR39ZDfw5uqEqSb6 DzVdjLE0hnFkN7N7Vn4yD+CVgU99m/XNT6jjH6Wmjjp9c08yk9LtgyvAtoWDFwGuoAM7 tC3BThWhvSZZ1uXqa29M33rUhxsQbR7oRI29EPGKH9W22Bo8gn6dVvGj7/koOME8zawW ISordPMvUkXBvEzeggCvMLyWqFzKtKF+XYVp4xJRetrlcZU+4ND4z3/ogiOoUDBt/ezT fKPr87eiolmoXKoWExA54W53TYeBE1V5YgALlLmmIv1v2r9Y0IADq4+CYi/D/8d/of+O 8spg== X-Gm-Message-State: APjAAAUFB9WyQ9fgXRFuoxUuPnMa6ykWwwILx5GirT2BXkDLdKJM0vIy xOXlwTElOXIcfVEo0b15Qc75+Sk8 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) Return-Path: 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> 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(-) -- 2.17.1 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: 183062 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064270ile; Tue, 4 Feb 2020 00:55:18 -0800 (PST) X-Received: by 2002:a05:6512:4c6:: with SMTP id w6mr14233719lfq.157.1580806517935; Tue, 04 Feb 2020 00:55:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806517; cv=none; d=google.com; s=arc-20160816; b=lGTkYYQo2jj/+YHutV3G0Aq9L8Zd91HKARSMrlN4eFAzwU/aif92Q8pPzMpqQM/3qI N7IaOO+nrjW2ZdQBtZNaYaWbBrkRioegByM/RwQy37Eoj09KtWPgGgcBnYKmvQ3jxsgP 1LxZhGMoHNgJ3+QOeLizdf6hUs6A20Syp11qZG5bd3FAtywgMrnSrfwcaXFgLgaHsKN0 kAPbGRlMVHtlOfDrfvQ4R4pIJJjwLdHIVDvZ46k0ZFgaswCyCTrEJro0bcsbInwj5MWL fyav876shpO9mDmSEUR4wUgeVzBNj8vmNPhC7d738c7JKEvSF6hPzpY2LON1cyK8NFTD iUjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HwDebRrklVLgKidfwiVAchc7w1c7H8+6yL91Fz1oklE=; b=q1d53pXPl4s41XTbZzOMQ7AEQcZSKg6M4yElkUv4C/D7Np9MrftxUMGiP8pnB59pSP nqow49WiSZOihynoVwTDgN3FbCpGiBDQqsNAd7QFo/6hOy6yUGantggOWB/e3ZHNdDbw OZqeLVXa3nKJ9Qy1TrogWS0r3TimnvAXja4kjQzK44+7/QNU1d9/YmeSPRNWY/Hjm8n4 7joRXuTGa9Wd08HRbIX7J/bJpACYw40hr0ODc6BcIc/EwkPG15trVYARDs6ZD2SE4wwg ZEoKo0MwhQag++rgIOdxVlEJDKuBJ2E8FXqOkZDD5O6c+RAu+dbGGsVKt5/d7zHKfcDT jwIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bAo8GMut; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id p4sor12436760ljj.38.2020.02.04.00.55.17 for (Google Transport Security); Tue, 04 Feb 2020 00:55:17 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bAo8GMut; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=sErZKCcRU2TLnTmDkGty8RMnatOrtzq/amE+t6QOh4u+MccbbtkDL0iOQRHPxwQlqu S/pAt1fkENDiGdtW0DxUopudQSuq9vrx6Waxa67A3uBnbHhVNeOSmub5q+vBsQ1mEVMK +yzly1AKX9EkLXVwcy7UwiKysAlWOh/i6Mnu3RExrPPMFzi5OqHUqRVH3DoCVcsnOWKc tynsP3zKr98D7NtvHItPj6DkWo8m2aommdHh6f0lisi8RbwJZYOhTia30P6fRQwZHtwa lZ801goCdD5gXpt5uUOaG/YaQPVyOIRBqUZS+rmeE18QCYvLQ9GyfuXwZMEHIK7jSGCQ IjZQ== X-Gm-Message-State: APjAAAUdZa2E+0TbIJo6jOE9XfYVMF1LSNXqZtOYItdLbNf0Nxzz+Edr 4NMTqdR+Ynvmo+ZABH6xZqLbbIAh 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) Return-Path: 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> 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(-) -- 2.17.1 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: 183063 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064303ile; Tue, 4 Feb 2020 00:55:19 -0800 (PST) X-Received: by 2002:a2e:844e:: with SMTP id u14mr16685533ljh.183.1580806519652; Tue, 04 Feb 2020 00:55:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806519; cv=none; d=google.com; s=arc-20160816; b=IyV78MwSfdOoh1xpVm8VbUG3tURmKaxR+ANJsMN25Yas0hxflxw3NzrmcnOhPA/NIt TEBby3E/t7Am6poigG6J9NcItMWMMK6fM7jrbLdh2tN1qf7iDU7fN+rFEbqfaR+0g08s mfy24kFvDpclx6J/XfJFiZp8KuwFmNaJ/7ax5iXs7S7v68srYn85C3LL2OwyYthmCZ9O aqhEGuwliHuGJ3qUFXyIPtBrfoTj3K4rlYk3NW+L0tBOZl+NXe4LQhEIOVaRSP0jsou5 Q9EDJFMLwwVh9LiFlS6WztT/2IYASiWwHOC+JREpE2JrsfwSLyM3JQ9z+IhMNQwVQEM9 tR8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dhFxxDwJUKLwoCX90rahTvLMvFdyoyjOAB1gpaNjDR0=; b=kqEnV2FEL7ciXqMMg1lR5e+OaxevCOSsk+R8+gNoGWKiHevyOKO0SIyjK4PiYWgeAK LilBDnoBUL16zNgsaYuaWYNRg5fyDnGnMjm1yR7w08fVJ9C9FGiZ1wdPx/w9hhodGFzB QSaoaZgs5H/58o+eISBgyTNhV/1z9+7tKf3uXoVZlsE8lrN7o0yIxYFPwlZdA15TH+ll KhYpuN0wpJTClMTzHKibGeqT0y6sWGr/F+pdsQ0ir/G9x15wusrFXJN1783OSXIsaHSr VPB7fpQ+SjBlc4tZAeug7x4CGR/4lGx/HKaaYzBI9xCpeGoNFPnlpP7qzyo32E07mMLr vplw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HmBIPL1I; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b25sor5378445lfp.23.2020.02.04.00.55.19 for (Google Transport Security); Tue, 04 Feb 2020 00:55:19 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HmBIPL1I; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=Sb+paUMMbXwYvxMeOZTHg+jKypU+VOzhL6/FMcdTsLy8pZEsBKM6Bv6XFuh3Bp1W2P y9chm/+33jzpa5yd/piPQPNq63FEn3LR3oK3plGvCEShAFtt0Cm6qWMcWFmyONVCgdEJ LIGYbVER6yxMv0L384yJr+7i6abBwWoAYTXRAElAl2ELZAAU/tXj32LnlNH0wVpOdN0H z/7QFKL/sleWFZiqKA/ASfkPHTufoFDC1qJWh3Do/WlB3BMZuKccnkF8eIVoZy8t/5PN jH/8Q/j4Gblj2OwAc7QJJtD02qOcrMEsNHCZx4UQrGOPiOfOpJgPT9TW//hGsStphxDu fynw== X-Gm-Message-State: APjAAAUl6Jli/qkLsIinznW/Wo4k/NyewdLslC/uCR7wtzREqK+IbTEY RBylwraOIxJO7SGJr9cdUSR9tSQS 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) Return-Path: 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> 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(-) -- 2.17.1 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: 183064 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064325ile; Tue, 4 Feb 2020 00:55:21 -0800 (PST) X-Received: by 2002:a2e:9118:: with SMTP id m24mr16665176ljg.105.1580806521075; Tue, 04 Feb 2020 00:55:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806521; cv=none; d=google.com; s=arc-20160816; b=fd5Gdh2ggNR0taasSkBfBLMHD9DtfhsgsimMWZldSrcYi++0cRXjH4oiN2IKUtY2sO /jFihP1XJqWfPzfd/RqvMsKlbG+F7Tpk6sQn0+jGEcce9jHEQ+IsBB4MihhXNm+Pgeuu GIrLX10TmYvrfotC8OkhPNVF38UGu4bfBvSVCFEg56LwcWwdJQEH6zUFMzh/AmPfGrjY pyywUMD8x408MDxxnAu64NQPo/ysoHpgMhq///OHIB16mvLwZuaPyxA0rU0hyneIsSui dxnVg00eK0PdOFXvc5XP6GTIziDrRV5WrKe+KBMRabetUzoQRJydWYhj61tVS70mXwua C4yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PxbxjkKlNhhTJR8wRb3j/yvmTz9T7alicVi9qKEvd6o=; b=SlhWq5WsRDi0B9I8jCIKQ/UHO4sfCdqPTtAGw0ikxOhlUatg2tDdS1wEMaZwAVIKDT BazMarG5vaZpt+UtG4JXAelmGMocMlbhGxo77QKwRyBlY5/Xsd+pYAZmBJsfW8Ib7yG+ NHZF2LMyxJ6Ueup3PcHBw6285dBWnBvP4fFDYGJKGKA7Q2kkJqQavyLDsBDTySCbfVe4 NUvjb9aOALj7w19VKRTcAuNJD7ccWviVRCwBTOwS3u5huu0eyMrq/shL1/2BfCWqlXBx XnXHvMybcfAWIJL/KMUz6cbKbIjVDs3UP864K7nJ9jgF2FGWIFZKcPFJ90Us1UIgD5my jOtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ru9kADQD; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id q10sor12306246ljm.28.2020.02.04.00.55.20 for (Google Transport Security); Tue, 04 Feb 2020 00:55:21 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ru9kADQD; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=mjM67vbRivUu6M29uM8C7iaQAvDhYZ78zVx3BIs4CSxZfc77kx0b+y/OjavHYa5KfU 59YT4tcNpWqzljuq1x03MqaAtCqKiKtWSjTENCsqbcyKsHV/I+aoRHRVB0aUN2foJJCb 1kKBB+anPKFn8pBHHMLrSSrwuG77XTwUFrdic/RnpxK3e5+fhrGQDUB3m/jaRkkSzYV2 zYlELAOz3k71FVuDhQuO/lozOXS6lNcas7ps+0UAjjGoDDxbSVgKZJ+o/8MK7osmEx1a n/+Klqd6m4ARb6JKiPJcIjJlE9sj/Q6DbRK552ZRtCfnNSYqAe+lspE/U3HbG0eVJWcV mXTA== X-Gm-Message-State: APjAAAXBr9YcbQbCH+WSyrjdyUAEDWnzZKmqUr0lu58WIXu45ChoitgJ GHV3bpm1wN5spZDk8oBEdS0HS4+b 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) Return-Path: 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> 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(-) -- 2.17.1 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: 183065 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064349ile; Tue, 4 Feb 2020 00:55:23 -0800 (PST) X-Received: by 2002:a19:740a:: with SMTP id v10mr14048451lfe.65.1580806522803; Tue, 04 Feb 2020 00:55:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806522; cv=none; d=google.com; s=arc-20160816; b=QMq4cmhc8Q9IQXzRuQZ0iDd5nrd0V8sNdr/Oi3rshmtiCcOssolsQslFlHZBivGIzm u5iftbD+BR022VCNRdyaO39MohRlTucKg/OTn1M5Yj1G+5uIZ7BPX+P4znf5TycGD/Ad /3+DEYVV3L6Bc57sgkCm1nHjVn12luJR0Mw3+kEVaGYYpnSUohG414gqEmmdwHqaVC5P s0DfU/uzyMMxcyvVEgHF1OX26sRV37tqWaXatploQURXJeZd63xT/+xXqdXdQG6fKxf6 wmgO3L5HzJ/0QqY//VLAQDUF1+2AJugruhZk1w703PzANh0dPlBSENwMJNaNSKCyfKK4 fJJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4MoUz8e+cau8Xa7ChnTAxFphu0xbbPqaxCnfeEAChL0=; b=m6vFZFXiv7YyQSrho40UhSGrYjCCgyW0nXnH434tBg/V90GMknvDWm47tT86nTGU3w oCr2xcQGCTYzS1Ej81FYMH/4roGfIq2QIRyHhVQPyWf94LKttaJr3jFseuYeylzv3VZz LteHC2Q20wJkNjYQb3NFOzSe4Oi9GQaTKlkJT55mhT5hvCdGY5d+HVJdaeHmggmLzMNr bOvIgCSDVCoWdpHss/H9uLzA79Hb/pVF6cb3bx5blDyFy8LiBD5bo31nIMAnnBBtKZgS o0GMNT2T4MWBcgy8LODGsyBrbsgg0R1ErG3e+6Ihg3XiNeXa3uQmmeLLCe//z6ExC/Ut mlpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eHizTPsn; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id r2sor5311212lfi.66.2020.02.04.00.55.22 for (Google Transport Security); Tue, 04 Feb 2020 00:55:22 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eHizTPsn; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=c7wCEjax0/VKDL9yq9W3Q2LJduYDXQEmuKv5ZNtD1nFWG9vD8uG0exOnNvPDXFxNpX VZS40Ajg4ijuaCGckEYTgCWn1vB3j3v5snaSnkQarjwtXsFAJpm2ftB5G4HtSoJmhMvW L338J8fTizadQb3ZelpBG6PIDwxraKtJ6YC2d72Wzbopxeb2Q3iLLxX2dbi4UjeXXHlY wSrwWpykTRjFYMuwnRuNkq9wM9F2+iqDLRJeI06tDri5CTTevST6Jq9eoLPGs1Ic0fNI fS8gAs37jutjUxlst0NsGaErqh/cyjAj6aMS5dilNgykDM6QGPMC+4doGvUti64MTUSX uFRA== X-Gm-Message-State: APjAAAXNrX43hEeUijPEgPX3EVH7dTDlrYs3pBKJW5hDT25Q74MHeuhw EQ9T+QjTD74+P/ykz8G8sEVmG3+H 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) Return-Path: 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> 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(-) -- 2.17.1 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: 183066 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064358ile; Tue, 4 Feb 2020 00:55:24 -0800 (PST) X-Received: by 2002:a2e:809a:: with SMTP id i26mr17075721ljg.108.1580806524069; Tue, 04 Feb 2020 00:55:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806524; cv=none; d=google.com; s=arc-20160816; b=O+ep1WWn8Q6C6o3B4FugovopsGErSmYW/lgSG2lUON/b+pNq+twMw1t4WSckUyPxhW lv2Rfg2f7Oz19G4/JxDtyYsk5cwgDy+McktxOUVTK7QVzYuP8eBj+8kGLg0/W8N30hy2 VrIsCZs64gVSFYtbkXSQvMQUM15xlWFVUHaToh+EN3Iz2abHfRTd+goCoDt1NT4Q7ftc +rcBI04YhxruABc0dqdFOo3MnNWRIsU8GsGl0EZ/Vd32DGIXzX6LJq7CbCcCecgMc+RV /jhzs7yZiqszHHSU4qpK6nKNYXRfEmHCEid41VCvbHxJ6Luunt0nIfBPzEtt/bQ+G31a kfPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=76qzmT2N+APJISrybQoaQycmewwxQpEPkoOAn/iBjYI=; b=utXE+1a9browOKOsK2PaCvoZirDH/cyphVF+zjHGDJUfo5ZlREKNRcuq4Lsyaf/VW/ 2G/hJiZc0w/11jzZ9anin9/fTC9j0iGnx6dWiFZsuLpeiKx+6Rf7VXKJpnGPW0iFVhZW bGefwttQQRT059GWwxgYj0ocJ1CBGGwTKp37mm9VMBO/LOycjFj1gzso47Ug3K0ABEEw xbgiO66Dbwh/iyaS/AH4P2CPFJa16nXcB4569iVg8SNQVWCMTvji2vzgPEMUPoVyHqdW /NotaWRtFKgc5Lrpr2a29pVY+XDZ6mopqk3t/qvBfz3y5RJXLP4giY/mTFi+MIC7WYfa TpFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mRTuBhRB; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h18sor12302687ljj.14.2020.02.04.00.55.23 for (Google Transport Security); Tue, 04 Feb 2020 00:55:24 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mRTuBhRB; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=X9tzTaQlxM0P+XpZ5Uc8K31JcTOQWEuXkGdWY8E71pseXYhS738bMmnvZrGCEYREgb 0E1/T7zVuTpcgxjq2Eo57F0LvgZZdr/Hlvgf7UWLNSLGsPL2OB4gPc9Vxf7XM3XRsuaF VTT7nTTTNfl30BmGhQNUOn4R7d6RrpbMwsYSN0DNGdtbMdi+dG0okcK88ki4fJvdE7JH bPjrgtN+wrOBdqL4Q6kwJCIqRAjdz5pNWqiXhdePY+90MEfW7PjomuovbaEtGtGZY2yx k8ZypAJ79Ml5J4bkvn59HeSLrZKyJt+E2m1uWZV+Po1szdc3SiAbIgwkMzsnkFY3nFgC mjlQ== X-Gm-Message-State: APjAAAVz5WlpPGgwT1o8VTcxEo5Dm/xyUKYpWKjeNwQ+RJwT1msjDeaK m5PTf9jWDp9noCbQlbKPRChYOxyqD618eg== 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) Return-Path: 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> 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(-) -- 2.17.1 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: 183067 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064383ile; Tue, 4 Feb 2020 00:55:25 -0800 (PST) X-Received: by 2002:ac2:5f74:: with SMTP id c20mr14525818lfc.15.1580806525633; Tue, 04 Feb 2020 00:55:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806525; cv=none; d=google.com; s=arc-20160816; b=IABSdAQuoltk31ft4V+yNbUy4GHTOIjIv8uhjeY25N66uJTEU5HP37eogs6WmD/2wZ Ek2JPWwsk8QMiJS/AUlA0v2XUwWIxcp8QroWQSHmp8T3vSq4h7t+QWAI8+yaxfpz0S4y ReD7DolMyONr7IrTnFpadnW8BIHmtQOcYDJ3SBMyHxiuWEOZnKJbJ4v2tS5uEWEXgmrq YdloM4KblYVV1hR2Q0ngUG0sf10vwNBLLZy4uDnuz/Yf1AAy1/lfdMaQgazKH/A8Jrdv D3/UJVNh5ZDEKrGTCeAg8P7k+zvIYULXGCyz0zXqwrV/xIS/XBp/NCDUV1vL+PY6fD2q 0iiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KLjqRxjOu37hotK4LZ6sgid1xsi6x3z1IsXdytiYo/0=; b=OeorspGgLlib0U4hYvNVHD/W2Inc6jKGQ4YPY++Vydeu8fXUAa8I9P6rLAbsp8wVBq Z03kAQd9EU5OOiAnAOyEsLJWZ2ZNg3drrJL+mzlNkpRCOH6ijlE7mfa3yl+4v67WtYPn akBK5znbBshnDe6QqDKhV03+iYOG7dJVt91PSWfN8ERFF2LW4kM/88MerJhMG6DpfLGE kkBeD9ImY+y61DKHxSzXI9wch1rwCuY7ooLuTYlbjDEz7kAZ29m4uOqAagWT9y7RC9Ob IjPMFyLjMaYe/TwTn0jH4wsiZAt5nnU32zXMJYByDF8tU4a9au25xLrN/jhzQt25vQVV s15A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r5GdvLAX; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id q14sor12243566ljh.45.2020.02.04.00.55.25 for (Google Transport Security); Tue, 04 Feb 2020 00:55:25 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r5GdvLAX; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=cEGFxAbRiGRM8Bgy2s2jD8khp534xv6WU4XnY9qQODP9GjXskx07yaIFNRXRxZ9BKj zNdFLeeKXKFATy/d333jOr8wSqiGJwEMs33qjhZBB7bsIiW1UEBbrlY95Hcn3rO3D5TE lpOMKPBl8Ye9ybwuc5osLcD5urhycCjmbN0eL8f80cXk+YcoW7Ga1BfgTZe6VyfxX5sG q2t2Aywl27k2JTvnpAIUDVLln/pOIJD87NgksCwPayDzhscxTpsWv9DLFF9xeXc9pJAg KaZB4UGH4QFb4F5O6asZgdwFihduFwj0eoTogYIw/0hawu8J1TZ4yows6KTxbzJsRMlZ K4cA== X-Gm-Message-State: APjAAAVgVel42KZy/uCG+cghTzeGo2IAM9PjQyG98xLRjN6kaIP+fiqj cVLeID7aW0sZ2I6wT0XGY0W5TIpN 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) Return-Path: 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> 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 --- 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(-) -- 2.17.1 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 */ };