From patchwork Wed Feb 1 12:48:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 9549657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1883F60415 for ; Wed, 1 Feb 2017 12:49:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 069DB28422 for ; Wed, 1 Feb 2017 12:49:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF5E728437; Wed, 1 Feb 2017 12:49:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75CD328422 for ; Wed, 1 Feb 2017 12:49:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750990AbdBAMtQ (ORCPT ); Wed, 1 Feb 2017 07:49:16 -0500 Received: from mail-lf0-f50.google.com ([209.85.215.50]:35998 "EHLO mail-lf0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750984AbdBAMtQ (ORCPT ); Wed, 1 Feb 2017 07:49:16 -0500 Received: by mail-lf0-f50.google.com with SMTP id z134so227869759lff.3 for ; Wed, 01 Feb 2017 04:49:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AQ3Nf9owyL3Ox1JI7aL0X6EPdk4hRXLg1fY3xRXCvw0=; b=TZW+xNMzzFd6n/ookWe5Tu3krR/9ViD8DwCyNwLlzipf3QIgnhYcT+ZNWlTOy1Utls MTT+cu9eI7Djf3J/2s5lwPhkKFMw2eFRhjG1iEDDSBd7IvSCtJyXTbGwQIH6iwQdsvlz giVg6PR7tNinF/83LfhWuHKbIwC05lwPn0xtM= 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=AQ3Nf9owyL3Ox1JI7aL0X6EPdk4hRXLg1fY3xRXCvw0=; b=rv8l6cFvFriLzoc44RJRCEzlcJ4sgiKvhua45zI3ov09AYRXfd0t2jHt01SBjzamG6 TXzmaVtDecpjorQpytgokGcIr6SBIcse3LIhRelbpnu80fgWBK+6l2mIffyosd97MIPK /SyP9/PMgUYLvHhOLggae7seIkOWP7d+Z3dd/+czNeTmei3fvS7BfLKDF2l6U3t0VSEp Yas0JTeaesi5rNDDzBjzKPgvhS97slYreaEJ3fT8+0253h9LBA0aJTa3eNiEESIhEvAF Yc6QX+6JFX+SaQFR29MVquvoOd/7C8kS2O6F03bYb3GVcZDFQJxmxNAZzCzXMVowWO4N UHmw== X-Gm-Message-State: AIkVDXJWzLNSlQN81R6B916RbxeGJxSQJf/hrZwk2/CLuQZ1YneCFcO0QWZDSf0aiHqLf8fh X-Received: by 10.25.221.193 with SMTP id w62mr985951lfi.169.1485953354450; Wed, 01 Feb 2017 04:49:14 -0800 (PST) Received: from gnarp.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t126sm5707754lff.31.2017.02.01.04.49.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Feb 2017 04:49:13 -0800 (PST) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Chunyan Zhang , Baolin Wang , Linus Walleij Subject: [PATCH 10/10] mmc: core: start to break apart mmc_start_areq() Date: Wed, 1 Feb 2017 13:48:00 +0100 Message-Id: <20170201124800.13865-11-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170201124800.13865-1-linus.walleij@linaro.org> References: <20170201124800.13865-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This function is doing to many clever things at the same time under too many various conditions. Start to make things clearer by refactoring: break out the finalization of the previous asynchronous request to its own function mmc_finalize_areq(). We can get rid of the default assignment of status and let the call deal with this. Signed-off-by: Linus Walleij --- drivers/mmc/core/core.c | 65 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index a160c3a7777a..41b4cd01fccc 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -631,6 +631,37 @@ static void mmc_post_req(struct mmc_host *host, struct mmc_request *mrq, } /** + * mmc_finalize_areq() - finalize an asynchronous request + * @host: MMC host to finalize any ongoing request on + * @ret_stat: the status of the ongoing asynchronous request: + * will return MMC_BLK_SUCCESS if no request was + * going on. + */ +static enum mmc_blk_status mmc_finalize_areq(struct mmc_host *host) +{ + 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; + + /* + * Check BKOPS urgency for each R1 response + */ + if (host->card && mmc_card_mmc(host->card) && + ((mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1) || + (mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1B)) && + (host->areq->mrq->cmd->resp[0] & R1_EXCEPTION_EVENT)) { + mmc_start_bkops(host->card, true); + } + + return status; +} + +/** * mmc_start_areq - start an asynchronous request * @host: MMC host to start command * @areq: asynchronous request to start @@ -650,7 +681,7 @@ struct mmc_async_req *mmc_start_areq(struct mmc_host *host, struct mmc_async_req *areq, enum mmc_blk_status *ret_stat) { - enum mmc_blk_status status = MMC_BLK_SUCCESS; + enum mmc_blk_status status; int start_err = 0; struct mmc_async_req *data = host->areq; @@ -658,35 +689,25 @@ struct mmc_async_req *mmc_start_areq(struct mmc_host *host, if (areq) mmc_pre_req(host, areq->mrq); - if (host->areq) { - status = mmc_wait_for_data_req_done(host, host->areq->mrq); - if (status == MMC_BLK_NEW_REQUEST) { - if (ret_stat) - *ret_stat = status; - /* - * The previous request was not completed, - * nothing to return - */ - return NULL; - } - /* - * Check BKOPS urgency for each R1 response - */ - if (host->card && mmc_card_mmc(host->card) && - ((mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1) || - (mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1B)) && - (host->areq->mrq->cmd->resp[0] & R1_EXCEPTION_EVENT)) { - mmc_start_bkops(host->card, true); - } + /* Finalize previous request */ + status = mmc_finalize_areq(host); + + /* The previous request is still going on... */ + if (status == MMC_BLK_NEW_REQUEST) { + if (ret_stat) + *ret_stat = status; + return NULL; } + /* Fine so far, start the new request! */ if (status == MMC_BLK_SUCCESS && areq) start_err = __mmc_start_data_req(host, areq->mrq); + /* Postprocess the old request at this point */ if (host->areq) mmc_post_req(host, host->areq->mrq, 0); - /* Cancel a prepared request if it was not started. */ + /* Cancel a prepared request if it was not started. */ if ((status != MMC_BLK_SUCCESS || start_err) && areq) mmc_post_req(host, areq->mrq, -EINVAL);