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) {