From patchwork Tue Mar 28 08:40:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 96118 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1602419qgd; Tue, 28 Mar 2017 01:41:30 -0700 (PDT) X-Received: by 10.84.178.195 with SMTP id z61mr34250776plb.139.1490690490917; Tue, 28 Mar 2017 01:41:30 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u184si3533806pgd.21.2017.03.28.01.41.30; Tue, 28 Mar 2017 01:41:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754537AbdC1Il3 (ORCPT + 5 others); Tue, 28 Mar 2017 04:41:29 -0400 Received: from mail-lf0-f53.google.com ([209.85.215.53]:36277 "EHLO mail-lf0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754563AbdC1Il2 (ORCPT ); Tue, 28 Mar 2017 04:41:28 -0400 Received: by mail-lf0-f53.google.com with SMTP id x137so33901294lff.3 for ; Tue, 28 Mar 2017 01:40:46 -0700 (PDT) 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=OVqwl5e3oquAlH330rQL6dUGpLarK9OGsT6SIBGJd2g=; b=hOzxp2vP7q4IiA2ackHAwJw+gn8FeT7PrpODYKWwGeiNSn0wmKscB4DMqq9zY4laoM mL520wCgrrQK7KShEfbkQ+zNyDN9Jrdf5/is9cKiuOXGGmWjZmxQLKCcJzk8NUjbS3cR Ey2FdWNjwGdj66xcL6+6F8h7hayBWaUjHSMyU= 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=OVqwl5e3oquAlH330rQL6dUGpLarK9OGsT6SIBGJd2g=; b=imcDQHYqgOc68rEV/gbnQ4uMW8VHbbpDE00B/0uMbjC5Yr7nUHeUXc86P3xgqH8r8X MNtmuP1M3jwo56uEGcB/p7+a8tlfe/ZaPhBAvRrYUqYB8Tf3Mi8ckCGW3pvKtlnMHFPp uvm1fg7hwEfPBoMA3uvIJ2s0Heu6S9XVn5xBGtnto1wy0CmCm57fm5cBZdNWN/bwRDOJ +aiJVaVeMDSZNMo0XEm3jxUhDxblL1WmlV6kbb20rAEtn9ON9tWA6qLJmz6++hdpeQwk eF5NiDX6efPs5wbLhDtYxNr9a4gKC1Wk3nZVHnyg9w+dBLFOxy0PIWMHToAmnfIxTxDk pQtw== X-Gm-Message-State: AFeK/H3W9nU6Nt1iY0MKxSVba7RHAyw1gG5LySBDDJELqOblGIZDmp+pByVJTSEQN2CinwpU X-Received: by 10.25.21.37 with SMTP id l37mr12092745lfi.146.1490690445808; Tue, 28 Mar 2017 01:40:45 -0700 (PDT) Received: from localhost.localdomain (c-357171d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.113.53]) by smtp.gmail.com with ESMTPSA id s13sm539590ljd.3.2017.03.28.01.40.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Mar 2017 01:40:44 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Bartlomiej Zolnierkiewicz , Linus Walleij Subject: [PATCH 1/3] mmc: core: move some code in mmc_start_areq() Date: Tue, 28 Mar 2017 10:40:29 +0200 Message-Id: <20170328084031.11995-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170328084031.11995-1-linus.walleij@linaro.org> References: <20170328084031.11995-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org "previous" is a better name for the variable storing the previous asynchronous request, better than the opaque name "data" atleast. We see that we assign the return status to the returned variable on all code paths, so we might as well just do that immediately after calling mmc_finalize_areq(). Reviewed-by: Bartlomiej Zolnierkiewicz Signed-off-by: Linus Walleij --- drivers/mmc/core/core.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 926e0fde07d7..b8468950e59d 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -683,7 +683,7 @@ struct mmc_async_req *mmc_start_areq(struct mmc_host *host, { enum mmc_blk_status status; int start_err = 0; - struct mmc_async_req *data = host->areq; + struct mmc_async_req *previous = host->areq; /* Prepare a new request */ if (areq) @@ -691,13 +691,12 @@ struct mmc_async_req *mmc_start_areq(struct mmc_host *host, /* Finalize previous request */ status = mmc_finalize_areq(host); + if (ret_stat) + *ret_stat = status; /* The previous request is still going on... */ - if (status == MMC_BLK_NEW_REQUEST) { - if (ret_stat) - *ret_stat = status; + if (status == MMC_BLK_NEW_REQUEST) return NULL; - } /* Fine so far, start the new request! */ if (status == MMC_BLK_SUCCESS && areq) @@ -716,9 +715,7 @@ struct mmc_async_req *mmc_start_areq(struct mmc_host *host, else host->areq = areq; - if (ret_stat) - *ret_stat = status; - return data; + return previous; } EXPORT_SYMBOL(mmc_start_areq); From patchwork Tue Mar 28 08:40:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 96121 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1602482qgd; Tue, 28 Mar 2017 01:41:42 -0700 (PDT) X-Received: by 10.98.159.149 with SMTP id v21mr30689553pfk.57.1490690502793; Tue, 28 Mar 2017 01:41:42 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u184si3533806pgd.21.2017.03.28.01.41.42; Tue, 28 Mar 2017 01:41:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754713AbdC1Ilm (ORCPT + 5 others); Tue, 28 Mar 2017 04:41:42 -0400 Received: from mail-lf0-f51.google.com ([209.85.215.51]:33805 "EHLO mail-lf0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754673AbdC1Il3 (ORCPT ); Tue, 28 Mar 2017 04:41:29 -0400 Received: by mail-lf0-f51.google.com with SMTP id z15so33934089lfd.1 for ; Tue, 28 Mar 2017 01:40:50 -0700 (PDT) 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=xWLaPosRYwkHs/L3LesYOQrMbEHQPCAiKjMLayVKt2E=; b=GZJFDMvaRr4VhT7RbBlyHqhNvqUttrj+4SqeGS1vGVqq3cMod4/OaGh3XjCCaJAg8y K6UWoqsBKc9JuYbPKuks7niaR0fcaCdriLmKWa3eIDXFKyESJ9P8Ej3Eeow1A4Wp9Qzw TG/1IWUss0lKDB8upsNCrdRPxFYzKeDAlSpLs= 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=xWLaPosRYwkHs/L3LesYOQrMbEHQPCAiKjMLayVKt2E=; b=TSrEyiBoqQE9xjFOSsz3+cS23nlZBrO+oat7aMauz1uYrRPqQ53nqGTXOTFcOgAuL4 YcZEfLbYLSPxJH1tdh789PlPfPgz3IHcIzoPlIM5tYp3pwDxYj1gidCs/AVMH125bYPY 0uucAYXCWwiAXjjv5bVCEYJtK+LS8SekvKQ8l8ECfYNh2cU+v93e/u7XufEPhvv5jrU3 g2YHE+QQJOpyCS9yWvgjpPAZqjkBmPRVQsyF/y6Qri+At0aKZn6vfSouxW1ll1BO7gdm ZlTw49jfHh3fh4Ki/nP7Ez7+7Bx4Rkmusn1ukiFw9pbsae3S4WjY6AN/tTvtoKViQlEW 4hQg== X-Gm-Message-State: AFeK/H145Pur1KGtc9OCSx/G8hewmE32mYgwkuP2epXUC69vR9mLfoohTqOULByc3nkz8bqE X-Received: by 10.25.198.19 with SMTP id w19mr12841850lff.175.1490690449059; Tue, 28 Mar 2017 01:40:49 -0700 (PDT) Received: from localhost.localdomain (c-357171d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.113.53]) by smtp.gmail.com with ESMTPSA id s13sm539590ljd.3.2017.03.28.01.40.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Mar 2017 01:40:48 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Bartlomiej Zolnierkiewicz , Linus Walleij Subject: [PATCH 2/3] mmc: core: refactor asynchronous request finalization Date: Tue, 28 Mar 2017 10:40:30 +0200 Message-Id: <20170328084031.11995-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170328084031.11995-1-linus.walleij@linaro.org> References: <20170328084031.11995-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org mmc_wait_for_data_req_done() is called in exactly one place, and having it spread out is making things hard to oversee. Factor this function into mmc_finalize_areq(). Reviewed-by: Bartlomiej Zolnierkiewicz Signed-off-by: Linus Walleij --- drivers/mmc/core/core.c | 86 +++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 53 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index b8468950e59d..c0b3f80c1f39 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -485,56 +485,6 @@ static int __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq) return err; } -/* - * mmc_wait_for_data_req_done() - wait for request completed - * @host: MMC host to prepare the command. - * @mrq: MMC request to wait for - * - * Blocks MMC context till host controller will ack end of data request - * execution or new request notification arrives from the block layer. - * Handles command retries. - * - * Returns enum mmc_blk_status after checking errors. - */ -static enum mmc_blk_status mmc_wait_for_data_req_done(struct mmc_host *host, - struct mmc_request *mrq) -{ - struct mmc_command *cmd; - struct mmc_context_info *context_info = &host->context_info; - enum mmc_blk_status status; - - while (1) { - wait_event_interruptible(context_info->wait, - (context_info->is_done_rcv || - context_info->is_new_req)); - - if (context_info->is_done_rcv) { - context_info->is_done_rcv = false; - cmd = mrq->cmd; - - if (!cmd->error || !cmd->retries || - mmc_card_removed(host->card)) { - status = host->areq->err_check(host->card, - host->areq); - break; /* return status */ - } else { - mmc_retune_recheck(host); - pr_info("%s: req failed (CMD%u): %d, retrying...\n", - mmc_hostname(host), - cmd->opcode, cmd->error); - cmd->retries--; - cmd->error = 0; - __mmc_start_request(host, mrq); - continue; /* wait for done/new event again */ - } - } - - return MMC_BLK_NEW_REQUEST; - } - mmc_retune_release(host); - return status; -} - void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq) { struct mmc_command *cmd; @@ -639,14 +589,44 @@ static void mmc_post_req(struct mmc_host *host, struct mmc_request *mrq, */ static enum mmc_blk_status mmc_finalize_areq(struct mmc_host *host) { + struct mmc_context_info *context_info = &host->context_info; enum mmc_blk_status status; if (!host->areq) return MMC_BLK_SUCCESS; - status = mmc_wait_for_data_req_done(host, host->areq->mrq); - if (status == MMC_BLK_NEW_REQUEST) - return status; + while (1) { + wait_event_interruptible(context_info->wait, + (context_info->is_done_rcv || + context_info->is_new_req)); + + if (context_info->is_done_rcv) { + struct mmc_command *cmd; + + context_info->is_done_rcv = false; + cmd = host->areq->mrq->cmd; + + if (!cmd->error || !cmd->retries || + mmc_card_removed(host->card)) { + status = host->areq->err_check(host->card, + host->areq); + break; /* return status */ + } else { + mmc_retune_recheck(host); + pr_info("%s: req failed (CMD%u): %d, retrying...\n", + mmc_hostname(host), + cmd->opcode, cmd->error); + cmd->retries--; + cmd->error = 0; + __mmc_start_request(host, host->areq->mrq); + continue; /* wait for done/new event again */ + } + } + + return MMC_BLK_NEW_REQUEST; + } + + mmc_retune_release(host); /* * Check BKOPS urgency for each R1 response From patchwork Tue Mar 28 08:40:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 96120 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1602477qgd; Tue, 28 Mar 2017 01:41:41 -0700 (PDT) X-Received: by 10.99.143.88 with SMTP id r24mr29612117pgn.177.1490690501808; Tue, 28 Mar 2017 01:41:41 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u184si3533806pgd.21.2017.03.28.01.41.41; Tue, 28 Mar 2017 01:41:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754563AbdC1Ila (ORCPT + 5 others); Tue, 28 Mar 2017 04:41:30 -0400 Received: from mail-lf0-f45.google.com ([209.85.215.45]:33821 "EHLO mail-lf0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754678AbdC1Il3 (ORCPT ); Tue, 28 Mar 2017 04:41:29 -0400 Received: by mail-lf0-f45.google.com with SMTP id z15so33934770lfd.1 for ; Tue, 28 Mar 2017 01:40:53 -0700 (PDT) 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=8N3VKfwaZhhOGWfaoUMVbFf50ocncLdFHhWvQCIjahY=; b=Z0I+o1NzmmUz7REhsFRm91rvYeLo3g1AoNrcnW0XGrFdwfWyKIQZd/9kwtbkfk4fTM 9UVmZLCi8fHZl2G26838Hcvk3MQwYyQrWa7xhar25r9zBO1Zp6FvsPHm/6X3T9PMKHdq KdRkBS/sXFkQMQ1yc/YBmEoRmVUc3hEWRI1yE= 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=8N3VKfwaZhhOGWfaoUMVbFf50ocncLdFHhWvQCIjahY=; b=TQMzK0T5YYsUc074vBpIl8t+VKH00rxn2UixXPHpa6c2j/Alji5LanrKJkePWPBdlo XYIXKRpyW7fdxShVs1faHGS3Xjas+0BBP/xMPI20dlMMiM/2z+RWjcSs6ysLd+pZOXIa 6X9lKqP28+nMDFo2xMNIGziokadmB8Jclp8rZOiUWZDdgLlW0gyzQG378DwhzAJMjKvf iMcKtBH3P6YfHp8LtQWbgd74NQxfodvouaKkDeqPPgJqY14THz1YZOd29CJqTF2h/sx5 kqK6aXHv2xnH9IAQj6iDC7laDXhFYCpLp0GPxLSVh1KMZPu3Lmi01XfGsiVZGFsCCOYS uz6g== X-Gm-Message-State: AFeK/H2pBpI3DZE41wT+f6b26/IzCq0TsOIJm5Ij0HoQZtDt8JN9v/9F+G2MT8lgSlZIlm26 X-Received: by 10.25.190.2 with SMTP id o2mr6200274lff.80.1490690452141; Tue, 28 Mar 2017 01:40:52 -0700 (PDT) Received: from localhost.localdomain (c-357171d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.113.53]) by smtp.gmail.com with ESMTPSA id s13sm539590ljd.3.2017.03.28.01.40.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Mar 2017 01:40:50 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Bartlomiej Zolnierkiewicz , Linus Walleij Subject: [PATCH 3/3] mmc: core: refactor mmc_request_done() Date: Tue, 28 Mar 2017 10:40:31 +0200 Message-Id: <20170328084031.11995-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170328084031.11995-1-linus.walleij@linaro.org> References: <20170328084031.11995-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org We have this construction: if (a && b && !c) finalize; else block; finalize; Which is equivalent by boolean logic to: if (!a || !b || c) block; finalize; Which is simpler code. Reviewed-by: Bartlomiej Zolnierkiewicz Signed-off-by: Linus Walleij --- drivers/mmc/core/core.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index c0b3f80c1f39..86314fa85dd2 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -172,14 +172,16 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq) trace_mmc_request_done(host, mrq); - if (err && cmd->retries && !mmc_card_removed(host->card)) { - /* - * Request starter must handle retries - see - * mmc_wait_for_req_done(). - */ - if (mrq->done) - mrq->done(mrq); - } else { + /* + * We list various conditions for the command to be considered + * properly done: + * + * - There was no error, OK fine then + * - We are not doing some kind of retry + * - The card was removed (...so just complete everything no matter + * if there are errors or retries) + */ + if (!err || !cmd->retries || mmc_card_removed(host->card)) { mmc_should_fail_request(host, mrq); if (!host->ongoing_mrq) @@ -211,10 +213,13 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq) mrq->stop->resp[0], mrq->stop->resp[1], mrq->stop->resp[2], mrq->stop->resp[3]); } - - if (mrq->done) - mrq->done(mrq); } + /* + * Request starter must handle retries - see + * mmc_wait_for_req_done(). + */ + if (mrq->done) + mrq->done(mrq); } EXPORT_SYMBOL(mmc_request_done);