From patchwork Tue Oct 29 05:43:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 177981 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp4376137ill; Mon, 28 Oct 2019 22:44:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoExR2kJhhbmiMooBbJNjxrAOvpuNw08jNcVTZjJ/64j9lLYj/v+4kQysPwaRaPq6cKuKZ X-Received: by 2002:a17:906:1d4d:: with SMTP id o13mr1499089ejh.196.1572327861730; Mon, 28 Oct 2019 22:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572327861; cv=none; d=google.com; s=arc-20160816; b=U89b/UJAIHztXboVtMx+LZKgN9Ow1bZkcGQAML1pX6vlu1X+7rGNz0mo1fSIgnTZUa NaLQVgZZfTZmi8jUKH2aNkV7YLfofPnequpynhCLvnImQ47j6s8Yf3jMcPffA1S4vaRF f5rTIP4J7N25acQxTK01VbXR2Y+/4ys2U3tX+7Rcm3b0FIsPoKX++Zecm6r0nCSXyPvT Gq1MWNChSe0v5ymwEimkzZbcrAilaPexTAhMUsAAhY7O1wg6aNyGbkQbRIha8YClfqk/ WXHsNZhExasAU6EUcXt77LLblkLJZSdR3xkJQGWVlOTpgNyBkZWtlnd6jfIQ6WXq5k+8 QLAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=ksMByVugGoeKVqQdqoiQK1gUk1ZG1bkEIqQisl6szOs=; b=ygZg9EYToFw+Ti0Dp5ABpO4AVoPnR1aEtF9uG3frDceb5gaN0iC6BYOPUXal1XGxdp bvMoi7ip/fSJYX64IC3w3NaVcK/owRI1FNl7lcYnklJ368us0JSuDIPmRagQ1fzKWIPN 4jC90zdxcCV0UPc4mavmerj6gq9tceZTBESU57blGCxn1sws8OvfyhTdmhJcJuBp3kMx 81Zp/uJYuG3INQn2ax6y11p7xKs9pjgsjWfB2n1kY3aUhrd/Pw3ka/gUq2n9h1vKZxmM w9auWfkhW78oD8WCvONNg+ewjcCphLnqFeLUb/g4tvkg1CdME+dLXlCI38ymdnn21D9k yGjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SM1ea3Lb; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si8659870edd.54.2019.10.28.22.44.21; Mon, 28 Oct 2019 22:44:21 -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=pass header.i=@linaro.org header.s=google header.b=SM1ea3Lb; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732107AbfJ2FoS (ORCPT + 5 others); Tue, 29 Oct 2019 01:44:18 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42173 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732106AbfJ2FoS (ORCPT ); Tue, 29 Oct 2019 01:44:18 -0400 Received: by mail-pf1-f196.google.com with SMTP id 21so8714826pfj.9 for ; Mon, 28 Oct 2019 22:44:16 -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 :in-reply-to:references; bh=ksMByVugGoeKVqQdqoiQK1gUk1ZG1bkEIqQisl6szOs=; b=SM1ea3LbiTCeDcuQzySb+I24JnRkPSNJlHcSbenv491wG9Qc2AtIpYVGcFsfftXgt1 r1CKoX+yC31ocqxHoADJAJmEBCq83nHrX6ZDO/lxCRdVug+nA4x7v1G9O8FX19sTA1ev FnNBccQLGrvHRqX8a1DFDPqM0OpO4FaVmYqfYKINPup54CV/vIz7UJ5lKZ8mufZjjWge 5URzj6o7trj8sPac4oTKXz9EQ1lnFRb4PnQGjO1T0zztzggcmefUogHfMSSNq0UOJQFF cFdhMg0H7oywCze4U/hx6y24Zxopo+ZzKkP3xE8667C98t5JJ9FLjyN1w/cow7G+WFqA nu6g== 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:in-reply-to:references; bh=ksMByVugGoeKVqQdqoiQK1gUk1ZG1bkEIqQisl6szOs=; b=b2B04SN2mVrU5a/Y8ViXbiKjU2LIh2g/sgI5JqdeKtTAv4gY5xwHwwaZWXvpd0vr5C KdSLRMtWi69glvgepWDmVFVBAK3VRpnPGAXvnUpJqrme+UdY6cUT0zVfOKZMZY87jrsn iWc6qQHH+vIjM8q7QAKIRJ3620t7U3PDV2tHKpAETpSMvbodeOAhq9pnpQJk94dQoNd3 PsKn/O0T5ckgycdrTWx0hQiGZDoGNdLEWAu9ESQBlg2Dr3kNGVJgRB5Gbs+bi/eVzouq EQlD54B/X5XvBEY/zSI/X7oP7g4tMse9jEf+Sj3QFqKC/+4AdvlJhRLRcHamC/ryDeKA fHMw== X-Gm-Message-State: APjAAAU5ruqge2FUWI44LwKzpmHUp8UiBcig5dgyctV+ifqaGVVSybJY IRUeQcf4YHv/ZsDD1dU4PweTNA== X-Received: by 2002:a62:1c4:: with SMTP id 187mr7875416pfb.92.1572327856117; Mon, 28 Oct 2019 22:44:16 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id j25sm12026231pfi.113.2019.10.28.22.44.11 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Oct 2019 22:44:15 -0700 (PDT) From: Baolin Wang To: adrian.hunter@intel.com, ulf.hansson@linaro.org, asutoshd@codeaurora.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, arnd@arndb.de, linus.walleij@linaro.org, vincent.guittot@linaro.org, baolin.wang@linaro.org, baolin.wang7@gmail.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 1/4] mmc: Add MMC host software queue support Date: Tue, 29 Oct 2019 13:43:19 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Now the MMC read/write stack will always wait for previous request is completed by mmc_blk_rw_wait(), before sending a new request to hardware, or queue a work to complete request, that will bring context switching overhead, especially for high I/O per second rates, to affect the IO performance. Thus this patch introduces MMC software queue interface based on the hardware command queue engine's interfaces, which is similar with the hardware command queue engine's idea, that can remove the context switching. Moreover we set the default queue depth as 32 for software queue, which allows more requests to be prepared, merged and inserted into IO scheduler to improve performance, but we only allow 2 requests in flight, that is enough to let the irq handler always trigger the next request without a context switch, as well as avoiding a long latency. >From the fio testing data in cover letter, we can see the software queue can improve some performance with 4K block size, increasing about 16% for random read, increasing about 90% for random write, though no obvious improvement for sequential read and write. Moreover we can expand the software queue interface to support MMC packed request or packed command in future. Signed-off-by: Baolin Wang --- drivers/mmc/core/block.c | 61 ++++++++ drivers/mmc/core/mmc.c | 13 +- drivers/mmc/core/queue.c | 33 ++++- drivers/mmc/host/Kconfig | 7 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/mmc_hsq.c | 344 ++++++++++++++++++++++++++++++++++++++++++++ drivers/mmc/host/mmc_hsq.h | 30 ++++ include/linux/mmc/host.h | 3 + 8 files changed, 482 insertions(+), 10 deletions(-) create mode 100644 drivers/mmc/host/mmc_hsq.c create mode 100644 drivers/mmc/host/mmc_hsq.h -- 1.7.9.5 diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 2c71a43..870462c 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -168,6 +168,11 @@ struct mmc_rpmb_data { static inline int mmc_blk_part_switch(struct mmc_card *card, unsigned int part_type); +static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq, + struct mmc_card *card, + int disable_multi, + struct mmc_queue *mq); +static void mmc_blk_swq_req_done(struct mmc_request *mrq); static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk) { @@ -1569,9 +1574,30 @@ static int mmc_blk_cqe_issue_flush(struct mmc_queue *mq, struct request *req) return mmc_blk_cqe_start_req(mq->card->host, mrq); } +static int mmc_blk_swq_issue_rw_rq(struct mmc_queue *mq, struct request *req) +{ + struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req); + struct mmc_host *host = mq->card->host; + int err; + + mmc_blk_rw_rq_prep(mqrq, mq->card, 0, mq); + mqrq->brq.mrq.done = mmc_blk_swq_req_done; + mmc_pre_req(host, &mqrq->brq.mrq); + + err = mmc_cqe_start_req(host, &mqrq->brq.mrq); + if (err) + mmc_post_req(host, &mqrq->brq.mrq, err); + + return err; +} + static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue *mq, struct request *req) { struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req); + struct mmc_host *host = mq->card->host; + + if (host->swq_enabled) + return mmc_blk_swq_issue_rw_rq(mq, req); mmc_blk_data_prep(mq, mqrq, 0, NULL, NULL); @@ -1957,6 +1983,41 @@ static void mmc_blk_urgent_bkops(struct mmc_queue *mq, mmc_run_bkops(mq->card); } +static void mmc_blk_swq_req_done(struct mmc_request *mrq) +{ + struct mmc_queue_req *mqrq = + container_of(mrq, struct mmc_queue_req, brq.mrq); + struct request *req = mmc_queue_req_to_req(mqrq); + struct request_queue *q = req->q; + struct mmc_queue *mq = q->queuedata; + struct mmc_host *host = mq->card->host; + unsigned long flags; + + if (mmc_blk_rq_error(&mqrq->brq) || + mmc_blk_urgent_bkops_needed(mq, mqrq)) { + spin_lock_irqsave(&mq->lock, flags); + mq->recovery_needed = true; + mq->recovery_req = req; + spin_unlock_irqrestore(&mq->lock, flags); + + host->cqe_ops->cqe_recovery_start(host); + + schedule_work(&mq->recovery_work); + return; + } + + mmc_blk_rw_reset_success(mq, req); + + /* + * Block layer timeouts race with completions which means the normal + * completion path cannot be used during recovery. + */ + if (mq->in_recovery) + mmc_blk_cqe_complete_rq(mq, req); + else + blk_mq_complete_request(req); +} + void mmc_blk_mq_complete(struct request *req) { struct mmc_queue *mq = req->q->queuedata; diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index c880489..8eac1a2 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -1852,15 +1852,22 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, */ card->reenable_cmdq = card->ext_csd.cmdq_en; - if (card->ext_csd.cmdq_en && !host->cqe_enabled) { + if (host->cqe_ops && !host->cqe_enabled) { err = host->cqe_ops->cqe_enable(host, card); if (err) { pr_err("%s: Failed to enable CQE, error %d\n", mmc_hostname(host), err); } else { host->cqe_enabled = true; - pr_info("%s: Command Queue Engine enabled\n", - mmc_hostname(host)); + + if (card->ext_csd.cmdq_en) { + pr_info("%s: Command Queue Engine enabled\n", + mmc_hostname(host)); + } else { + host->swq_enabled = true; + pr_info("%s: Software Queue enabled\n", + mmc_hostname(host)); + } } } diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c index 9edc086..d9086c1 100644 --- a/drivers/mmc/core/queue.c +++ b/drivers/mmc/core/queue.c @@ -62,7 +62,7 @@ enum mmc_issue_type mmc_issue_type(struct mmc_queue *mq, struct request *req) { struct mmc_host *host = mq->card->host; - if (mq->use_cqe) + if (mq->use_cqe && !host->swq_enabled) return mmc_cqe_issue_type(host, req); if (req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_WRITE) @@ -124,12 +124,14 @@ static enum blk_eh_timer_return mmc_mq_timed_out(struct request *req, { struct request_queue *q = req->q; struct mmc_queue *mq = q->queuedata; + struct mmc_card *card = mq->card; + struct mmc_host *host = card->host; unsigned long flags; int ret; spin_lock_irqsave(&mq->lock, flags); - if (mq->recovery_needed || !mq->use_cqe) + if (mq->recovery_needed || !mq->use_cqe || host->swq_enabled) ret = BLK_EH_RESET_TIMER; else ret = mmc_cqe_timed_out(req); @@ -144,12 +146,13 @@ static void mmc_mq_recovery_handler(struct work_struct *work) struct mmc_queue *mq = container_of(work, struct mmc_queue, recovery_work); struct request_queue *q = mq->queue; + struct mmc_host *host = mq->card->host; mmc_get_card(mq->card, &mq->ctx); mq->in_recovery = true; - if (mq->use_cqe) + if (mq->use_cqe && !host->swq_enabled) mmc_blk_cqe_recovery(mq); else mmc_blk_mq_recovery(mq); @@ -160,6 +163,9 @@ static void mmc_mq_recovery_handler(struct work_struct *work) mq->recovery_needed = false; spin_unlock_irq(&mq->lock); + if (host->swq_enabled) + host->cqe_ops->cqe_recovery_finish(host); + mmc_put_card(mq->card, &mq->ctx); blk_mq_run_hw_queues(q, true); @@ -279,6 +285,14 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx, } break; case MMC_ISSUE_ASYNC: + /* + * For MMC host software queue, we only allow 2 requests in + * flight to avoid a long latency. + */ + if (host->swq_enabled && mq->in_flight[issue_type] > 2) { + spin_unlock_irq(&mq->lock); + return BLK_STS_RESOURCE; + } break; default: /* @@ -430,11 +444,16 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card) * The queue depth for CQE must match the hardware because the request * tag is used to index the hardware queue. */ - if (mq->use_cqe) - mq->tag_set.queue_depth = - min_t(int, card->ext_csd.cmdq_depth, host->cqe_qdepth); - else + if (mq->use_cqe) { + if (host->swq_enabled) + mq->tag_set.queue_depth = host->cqe_qdepth; + else + mq->tag_set.queue_depth = + min_t(int, card->ext_csd.cmdq_depth, host->cqe_qdepth); + } else { mq->tag_set.queue_depth = MMC_QUEUE_DEPTH; + } + mq->tag_set.numa_node = NUMA_NO_NODE; mq->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING; mq->tag_set.nr_hw_queues = 1; diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig index 49ea02c..efa4019 100644 --- a/drivers/mmc/host/Kconfig +++ b/drivers/mmc/host/Kconfig @@ -936,6 +936,13 @@ config MMC_CQHCI If unsure, say N. +config MMC_HSQ + tristate "MMC Host Software Queue support" + help + This selects the Software Queue support. + + If unsure, say N. + config MMC_TOSHIBA_PCI tristate "Toshiba Type A SD/MMC Card Interface Driver" depends on PCI diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile index 11c4598..c14b439 100644 --- a/drivers/mmc/host/Makefile +++ b/drivers/mmc/host/Makefile @@ -98,6 +98,7 @@ obj-$(CONFIG_MMC_SDHCI_BRCMSTB) += sdhci-brcmstb.o obj-$(CONFIG_MMC_SDHCI_OMAP) += sdhci-omap.o obj-$(CONFIG_MMC_SDHCI_SPRD) += sdhci-sprd.o obj-$(CONFIG_MMC_CQHCI) += cqhci.o +obj-$(CONFIG_MMC_HSQ) += mmc_hsq.o ifeq ($(CONFIG_CB710_DEBUG),y) CFLAGS-cb710-mmc += -DDEBUG diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c new file mode 100644 index 0000000..f5a4f93 --- /dev/null +++ b/drivers/mmc/host/mmc_hsq.c @@ -0,0 +1,344 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * MMC software queue support based on command queue interfaces + * + * Copyright (C) 2019 Linaro, Inc. + * Author: Baolin Wang + */ + +#include +#include + +#include "mmc_hsq.h" + +#define HSQ_NUM_SLOTS 32 +#define HSQ_INVALID_TAG HSQ_NUM_SLOTS + +static void mmc_hsq_pump_requests(struct mmc_hsq *hsq) +{ + struct mmc_host *mmc = hsq->mmc; + struct hsq_slot *slot; + unsigned long flags; + + spin_lock_irqsave(&hsq->lock, flags); + + /* Make sure we are not already running a request now */ + if (hsq->mrq) { + spin_unlock_irqrestore(&hsq->lock, flags); + return; + } + + /* Make sure there are remain requests need to pump */ + if (!hsq->qcnt || !hsq->enabled) { + spin_unlock_irqrestore(&hsq->lock, flags); + return; + } + + slot = &hsq->slot[hsq->next_tag]; + hsq->mrq = slot->mrq; + hsq->qcnt--; + + spin_unlock_irqrestore(&hsq->lock, flags); + + mmc->ops->request(mmc, hsq->mrq); +} + +static void mmc_hsq_update_next_tag(struct mmc_hsq *hsq, int remains) +{ + struct hsq_slot *slot; + int tag; + + /* + * If there are no remain requests in software queue, then set a invalid + * tag. + */ + if (!remains) { + hsq->next_tag = HSQ_INVALID_TAG; + return; + } + + /* + * Increasing the next tag and check if the corresponding request is + * available, if yes, then we found a candidate request. + */ + if (++hsq->next_tag != HSQ_INVALID_TAG) { + slot = &hsq->slot[hsq->next_tag]; + if (slot->mrq) + return; + } + + /* Othersie we should iterate all slots to find a available tag. */ + for (tag = 0; tag < HSQ_NUM_SLOTS; tag++) { + slot = &hsq->slot[tag]; + if (slot->mrq) + break; + } + + if (tag == HSQ_NUM_SLOTS) + tag = HSQ_INVALID_TAG; + + hsq->next_tag = tag; +} + +static void mmc_hsq_post_request(struct mmc_hsq *hsq) +{ + unsigned long flags; + int remains; + + spin_lock_irqsave(&hsq->lock, flags); + + remains = hsq->qcnt; + hsq->mrq = NULL; + + /* Update the next available tag to be queued. */ + mmc_hsq_update_next_tag(hsq, remains); + + if (hsq->waiting_for_idle && !remains) { + hsq->waiting_for_idle = false; + wake_up(&hsq->wait_queue); + } + + /* Do not pump new request in recovery mode. */ + if (hsq->recovery_halt) { + spin_unlock_irqrestore(&hsq->lock, flags); + return; + } + + spin_unlock_irqrestore(&hsq->lock, flags); + + /* + * Try to pump new request to host controller as fast as possible, + * after completing previous request. + */ + if (remains > 0) + mmc_hsq_pump_requests(hsq); +} + +/** + * mmc_hsq_finalize_request - finalize one request if the request is done + * @mmc: the host controller + * @mrq: the request need to be finalized + * + * Return true if we finalized the corresponding request in software queue, + * otherwise return false. + */ +bool mmc_hsq_finalize_request(struct mmc_host *mmc, struct mmc_request *mrq) +{ + struct mmc_hsq *hsq = mmc->cqe_private; + unsigned long flags; + + spin_lock_irqsave(&hsq->lock, flags); + + if (!hsq->enabled || !hsq->mrq || hsq->mrq != mrq) { + spin_unlock_irqrestore(&hsq->lock, flags); + return false; + } + + /* + * Clear current completed slot request to make a room for new request. + */ + hsq->slot[hsq->next_tag].mrq = NULL; + + spin_unlock_irqrestore(&hsq->lock, flags); + + mmc_cqe_request_done(mmc, hsq->mrq); + + mmc_hsq_post_request(hsq); + + return true; +} +EXPORT_SYMBOL_GPL(mmc_hsq_finalize_request); + +static void mmc_hsq_recovery_start(struct mmc_host *mmc) +{ + struct mmc_hsq *hsq = mmc->cqe_private; + unsigned long flags; + + spin_lock_irqsave(&hsq->lock, flags); + + hsq->recovery_halt = true; + + spin_unlock_irqrestore(&hsq->lock, flags); +} + +static void mmc_hsq_recovery_finish(struct mmc_host *mmc) +{ + struct mmc_hsq *hsq = mmc->cqe_private; + int remains; + + spin_lock_irq(&hsq->lock); + + hsq->recovery_halt = false; + remains = hsq->qcnt; + + spin_unlock_irq(&hsq->lock); + + /* + * Try to pump new request if there are request pending in software + * queue after finishing recovery. + */ + if (remains > 0) + mmc_hsq_pump_requests(hsq); +} + +static int mmc_hsq_request(struct mmc_host *mmc, struct mmc_request *mrq) +{ + struct mmc_hsq *hsq = mmc->cqe_private; + int tag = mrq->tag; + + spin_lock_irq(&hsq->lock); + + if (!hsq->enabled) { + spin_unlock_irq(&hsq->lock); + return -ESHUTDOWN; + } + + /* Do not queue any new requests in recovery mode. */ + if (hsq->recovery_halt) { + spin_unlock_irq(&hsq->lock); + return -EBUSY; + } + + hsq->slot[tag].mrq = mrq; + + /* + * Set the next tag as current request tag if no available + * next tag. + */ + if (hsq->next_tag == HSQ_INVALID_TAG) + hsq->next_tag = tag; + + hsq->qcnt++; + + spin_unlock_irq(&hsq->lock); + + mmc_hsq_pump_requests(hsq); + + return 0; +} + +static void mmc_hsq_post_req(struct mmc_host *mmc, struct mmc_request *mrq) +{ + if (mmc->ops->post_req) + mmc->ops->post_req(mmc, mrq, 0); +} + +static bool mmc_hsq_queue_is_idle(struct mmc_hsq *hsq, int *ret) +{ + bool is_idle; + + spin_lock_irq(&hsq->lock); + + is_idle = (!hsq->mrq && !hsq->qcnt) || + hsq->recovery_halt; + + *ret = hsq->recovery_halt ? -EBUSY : 0; + hsq->waiting_for_idle = !is_idle; + + spin_unlock_irq(&hsq->lock); + + return is_idle; +} + +static int mmc_hsq_wait_for_idle(struct mmc_host *mmc) +{ + struct mmc_hsq *hsq = mmc->cqe_private; + int ret; + + wait_event(hsq->wait_queue, + mmc_hsq_queue_is_idle(hsq, &ret)); + + return ret; +} + +static void mmc_hsq_disable(struct mmc_host *mmc) +{ + struct mmc_hsq *hsq = mmc->cqe_private; + u32 timeout = 500; + int ret; + + spin_lock_irq(&hsq->lock); + + if (!hsq->enabled) { + spin_unlock_irq(&hsq->lock); + return; + } + + spin_unlock_irq(&hsq->lock); + + ret = wait_event_timeout(hsq->wait_queue, + mmc_hsq_queue_is_idle(hsq, &ret), + msecs_to_jiffies(timeout)); + if (ret == 0) { + pr_warn("could not stop mmc software queue\n"); + return; + } + + spin_lock_irq(&hsq->lock); + + hsq->enabled = false; + + spin_unlock_irq(&hsq->lock); +} + +static int mmc_hsq_enable(struct mmc_host *mmc, struct mmc_card *card) +{ + struct mmc_hsq *hsq = mmc->cqe_private; + + spin_lock_irq(&hsq->lock); + + if (hsq->enabled) { + spin_unlock_irq(&hsq->lock); + return -EBUSY; + } + + hsq->enabled = true; + + spin_unlock_irq(&hsq->lock); + + return 0; +} + +static const struct mmc_cqe_ops mmc_hsq_ops = { + .cqe_enable = mmc_hsq_enable, + .cqe_disable = mmc_hsq_disable, + .cqe_request = mmc_hsq_request, + .cqe_post_req = mmc_hsq_post_req, + .cqe_wait_for_idle = mmc_hsq_wait_for_idle, + .cqe_recovery_start = mmc_hsq_recovery_start, + .cqe_recovery_finish = mmc_hsq_recovery_finish, +}; + +int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc) +{ + hsq->num_slots = HSQ_NUM_SLOTS; + hsq->next_tag = HSQ_INVALID_TAG; + mmc->cqe_qdepth = HSQ_NUM_SLOTS; + + hsq->slot = devm_kcalloc(mmc_dev(mmc), hsq->num_slots, + sizeof(struct hsq_slot), GFP_KERNEL); + if (!hsq->slot) + return -ENOMEM; + + hsq->mmc = mmc; + hsq->mmc->cqe_private = hsq; + mmc->cqe_ops = &mmc_hsq_ops; + + spin_lock_init(&hsq->lock); + init_waitqueue_head(&hsq->wait_queue); + + return 0; +} +EXPORT_SYMBOL_GPL(mmc_hsq_init); + +void mmc_hsq_suspend(struct mmc_host *mmc) +{ + mmc_hsq_disable(mmc); +} +EXPORT_SYMBOL_GPL(mmc_hsq_suspend); + +int mmc_hsq_resume(struct mmc_host *mmc) +{ + return mmc_hsq_enable(mmc, NULL); +} +EXPORT_SYMBOL_GPL(mmc_hsq_resume); diff --git a/drivers/mmc/host/mmc_hsq.h b/drivers/mmc/host/mmc_hsq.h new file mode 100644 index 0000000..d51beb7 --- /dev/null +++ b/drivers/mmc/host/mmc_hsq.h @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef LINUX_MMC_HSQ_H +#define LINUX_MMC_HSQ_H + +struct hsq_slot { + struct mmc_request *mrq; +}; + +struct mmc_hsq { + struct mmc_host *mmc; + struct mmc_request *mrq; + wait_queue_head_t wait_queue; + struct hsq_slot *slot; + spinlock_t lock; + + int next_tag; + int num_slots; + int qcnt; + + bool enabled; + bool waiting_for_idle; + bool recovery_halt; +}; + +int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc); +void mmc_hsq_suspend(struct mmc_host *mmc); +int mmc_hsq_resume(struct mmc_host *mmc); +bool mmc_hsq_finalize_request(struct mmc_host *mmc, struct mmc_request *mrq); + +#endif diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index ba70338..3931aa3 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -462,6 +462,9 @@ struct mmc_host { bool cqe_enabled; bool cqe_on; + /* Software Queue support */ + bool swq_enabled; + unsigned long private[0] ____cacheline_aligned; }; From patchwork Tue Oct 29 05:43:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 177982 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp4376156ill; Mon, 28 Oct 2019 22:44:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqycnM8SsPTAvSkYJzNkmKxB/2sER5f9XMpm7gKPc+oe2eLyLC2A3dPCMCzw9pRMlkl9fqZm X-Received: by 2002:a50:91f6:: with SMTP id h51mr23290815eda.99.1572327862674; Mon, 28 Oct 2019 22:44:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572327862; cv=none; d=google.com; s=arc-20160816; b=cEtZ5U7FdvLTL10WRBBTixNacd9FJ/U56vbynCA0mx9wwaYdz28QfArMree5OvEIeS RWa1UweJPibE8rzPmQ+t267L8J6T/JrLOUbB3mXO6ppzUv3MV8jy7a+bVvpt2QGMc0w2 EYSzOhQLn+yyBWGGNj6gDu0WGqdwBDZWyGFMDASNRrgaNs8lpxj8DgUs4jWMopPL4aCt KoxiSOEVW7viVhbw2CrRHXHwXwHe4ilHANUxrMabJz425LZPqAGeygWC4xbwOAbbO9X+ 5QLSQ4lVLDpEVOD50F7coCz581Lxpsaj+1XH0q/+IkqNQTRAg9WHpoVt06e0gir35Hsx qpyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=ILB8a88XETD+WUMe0JJMqsMts/FAHmPFp1FBBYuuKZE=; b=O4dJrcUKYl3IWa7+TeFnHVDSmb6/jMHuBs8XYlyPqZM3izFVXqc7k9Rmti0vCOvDO8 Coh4E9a2g2R+Rusa12TgdpNzl1vhQyGOqlmA3HrKARtBSdE1D6rsrAUTvZPaJ3QVpS7+ LMHgd5FgFixM1zMbf1MCYLn/CygI0EaNpcsn6Cvt1MiemI+GQ6tBOjx2iFPYOZMAw9AR vdxXief56O40OSvHKGP+NwDLDum5IpA45QcfetXxnlzhMVGlipwRsgzkKlrnC6ZB/Cym ITm2X1winSpByjSWWXJT/qndTYmoD/+fkWLQ90XjIUdoyjckjujtok1he4aTaO2CcC1M UVfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gmuv+cyr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si8659870edd.54.2019.10.28.22.44.22; Mon, 28 Oct 2019 22:44:22 -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=pass header.i=@linaro.org header.s=google header.b=gmuv+cyr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732141AbfJ2FoV (ORCPT + 5 others); Tue, 29 Oct 2019 01:44:21 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38693 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732103AbfJ2FoV (ORCPT ); Tue, 29 Oct 2019 01:44:21 -0400 Received: by mail-pf1-f194.google.com with SMTP id c13so8735608pfp.5 for ; Mon, 28 Oct 2019 22:44:20 -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 :in-reply-to:references; bh=ILB8a88XETD+WUMe0JJMqsMts/FAHmPFp1FBBYuuKZE=; b=gmuv+cyr7iHWELt6YHpGGTGNrHr/dSHU9vseTrEDPPehaRYVKqTt12YSkaQPzUpXq8 44+HvgIGJjd1BkTc0S/DKdleOZJ54mGsJK2dM1a1Fk5K0jfNOWLHQzNKe4iJnuVsr555 bnvFspkeCwM92tzJVGBV/M66crEo5mN+6MJ96Q4VhbofCEfXXYbz/bgzbMoo0bMWPGSP UO/KHyK5aadFe1VjRIfLnekNaW9j3tq5JClHAWTCVMZbBmSQM3Dkp7XaNeRmu3fEcSNC taTNxGVCKrpg6PEvzUrGkoX6Nf2sHFTsQriiGQKngj4wI8ZBSyTwFO7/Sctgf2jCvkhM roZQ== 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:in-reply-to:references; bh=ILB8a88XETD+WUMe0JJMqsMts/FAHmPFp1FBBYuuKZE=; b=Za7CdpMdyAxb1jDj30qmcVtNm7Cyp25+tBtiVuomKzfx8T71L85n/28Du0fTjCDfq+ 0DafNFVpN+bgWdcyhqJYiCWY6DvNW1ciKtj8f5p4mpOAivfheTpFfwDmeoDFWGAkMMfw pkAE1LSXNLLi246MY44s4WbgZQXuNZalKW6LtrwzRIJ4hqyBAzrsQ484LUko7Zxswi8I p8ZhFYsRU8wYY4wDFuux8asqH4Y2LVM7EGJWB3uT8U7ZGq0Qe9DmureMhsdse0tbSnkb q4nJSHm1CC0G6sS1QfW1hnmK2FTELIttLrbfqXmNE0nLkiSwRc3HD85yAQmvOMfU69AD 7ldA== X-Gm-Message-State: APjAAAUCOWtoyaxj1ORyNZtjiJ+2x8YXiQpf0rhvaWauXtjbbwldvO7G pIsboNjNTlB5hsymBkySVqPYvQ== X-Received: by 2002:a17:90a:a416:: with SMTP id y22mr4000686pjp.74.1572327860555; Mon, 28 Oct 2019 22:44:20 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id j25sm12026231pfi.113.2019.10.28.22.44.16 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Oct 2019 22:44:19 -0700 (PDT) From: Baolin Wang To: adrian.hunter@intel.com, ulf.hansson@linaro.org, asutoshd@codeaurora.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, arnd@arndb.de, linus.walleij@linaro.org, vincent.guittot@linaro.org, baolin.wang@linaro.org, baolin.wang7@gmail.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 2/4] mmc: host: sdhci: Add request_done ops for struct sdhci_ops Date: Tue, 29 Oct 2019 13:43:20 +0800 Message-Id: <94603120e6431f0ce35af78935bfe7dddda4850b.1572326519.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Add request_done ops for struct sdhci_ops as a preparation in case some host controllers have different method to complete one request, such as supporting request completion of MMC software queue. Suggested-by: Adrian Hunter Signed-off-by: Baolin Wang --- drivers/mmc/host/sdhci.c | 12 ++++++++++-- drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) -- 1.7.9.5 diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index b056400..850241f 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -2729,7 +2729,10 @@ static bool sdhci_request_done(struct sdhci_host *host) spin_unlock_irqrestore(&host->lock, flags); - mmc_request_done(host->mmc, mrq); + if (host->ops->request_done) + host->ops->request_done(host, mrq); + else + mmc_request_done(host->mmc, mrq); return false; } @@ -3157,7 +3160,12 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) /* Process mrqs ready for immediate completion */ for (i = 0; i < SDHCI_MAX_MRQS; i++) { - if (mrqs_done[i]) + if (!mrqs_done[i]) + continue; + + if (host->ops->request_done) + host->ops->request_done(host, mrqs_done[i]); + else mmc_request_done(host->mmc, mrqs_done[i]); } diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index 0ed3e0e..d89cdb9 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -644,6 +644,8 @@ struct sdhci_ops { void (*voltage_switch)(struct sdhci_host *host); void (*adma_write_desc)(struct sdhci_host *host, void **desc, dma_addr_t addr, int len, unsigned int cmd); + void (*request_done)(struct sdhci_host *host, + struct mmc_request *mrq); }; #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS From patchwork Tue Oct 29 05:43:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 177984 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp4376271ill; Mon, 28 Oct 2019 22:44:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHCgNMQNEid15cY5+ttorzno1xCC2p4IZqg6+1cDjCocSzmDIG1ECriZTuUCQM1vrn2ucr X-Received: by 2002:a17:906:557:: with SMTP id k23mr1398371eja.165.1572327870652; Mon, 28 Oct 2019 22:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572327870; cv=none; d=google.com; s=arc-20160816; b=USg/sWi3quO3zzp77ds+NNMSZOFGPne5gw3a9KwfF1AZcS/lBVWkewFH7hD1ySgaAW zaOYEp9PtP7eQHvgZaMthmB5tBW/srWUBxUQ3ylcz/39TD+5h82RE609Co5Vt4GYuiUg qXP69KG8oYboPMiOZV1ElU7/Jk8qKgllb1hvYbX46sYhDo84vS2VnPzBsJcs2pkIRo6a Vy3p6ydt6AKsCo9EVY8O7KBT6ZwISGPj8ktIwYhpQiwkg7hVJGuLviSZYfnR9e3tFaHW lr5TJmo+OV8r13TMzgFD9CBHQTyfzpYY1c1EMnIbnTFa9lrSJW73h/pKW4mzMWEE+yVR Ub8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=83cwCYPV9/yZeBbO6OKSaXzRco+5H2vE0myUuYv1K0w=; b=y7yxcjDh5201y7rGT1PreSKJFJpfhj6tdKE0r53GPo/mxta9cijoFe79RxuOaDXrY+ vcnVvNP7kHrLFMOjPVmlCUHnvkYKAOxStPYRjgOqZPzUTfPGJ1Vut0vlWiecs+93bLdh 2RYEKQZohTnbe1YHUkfjfGXNFXg5mXycN9BT57Qyajg/SXdkCEt0UkKQX255b9j/2L5T wQ69Dtm3TBd9xVd4iIJtK9qA7vd1+eTxBO9kOBveUMxGwRBYIQ+Dix+fNDdCiA0FC359 6GwE6F2JYkj7Qd3SD+acIcLCg7I0gHb0HZVGl05BzuCS4PDNYbP71fQ9/1niZloJy0z+ k+cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i8xCDqqF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f31si9776832edf.75.2019.10.28.22.44.30; Mon, 28 Oct 2019 22:44: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=pass header.i=@linaro.org header.s=google header.b=i8xCDqqF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732193AbfJ2Foa (ORCPT + 5 others); Tue, 29 Oct 2019 01:44:30 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:41261 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732187AbfJ2Fo3 (ORCPT ); Tue, 29 Oct 2019 01:44:29 -0400 Received: by mail-pf1-f195.google.com with SMTP id p26so4589916pfq.8 for ; Mon, 28 Oct 2019 22:44:29 -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 :in-reply-to:references; bh=83cwCYPV9/yZeBbO6OKSaXzRco+5H2vE0myUuYv1K0w=; b=i8xCDqqFLqESmBlE8SMdB2SxgTpUiuigZdOv0dF6UhQTdT6DMVdtGscyfJylUALb7W 7Zglap20Z8e2SmfrgB1wZd9azPS9aS8aBUBMQgynNmALQJXJt9W5INUkJqb9e4eSTV6p 6fvxAv+stC2iqsbGAkPd/UF0U5dLDEvZg8Z6SQpSmjv4cdE08Lu1wm+9XYhImDV05vRC 8dTOovwOTr11L8O+L05/HFmwtCnH8qactHO4IAAZO+qqTmXg0vMqFoldW1WA5uwmwbDG yKNDBvCPKO+GcALdGc/IOmyoB1yDDWuB7jPWsJAv7vTM6y7RTMiDlWHFe9uu7imtI5Yw P4qw== 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:in-reply-to:references; bh=83cwCYPV9/yZeBbO6OKSaXzRco+5H2vE0myUuYv1K0w=; b=BOKSFf50xBX9QkLJeTXUeg35ZKgGZRfK09ud7ZEK1MCz9L1tTLH5ObBMMU2+p60Ysu 0rTKVd6eLicKMq6/OSo83NB6LvKx2YUtvEUZgGPDaDT3ZN6On/P+tZqUXzShVLMxd+xk ja3UuwVQ52ABoP0Zzi6UcsDjknugJ4b0xwnbrVIKee3gXFNeFKzFXgZ2/9l8AB6j2EsL trs/FqvqML1vdotFgQ1WR5c88/57sWwbKNHXKeAjBdrnDxX9eca2Ye6dkCH9qOdlBvv2 P3/rTFyjRtJPkU7T4u3xLd725FhKRVO6Zpdaugzc5kwj6NQK9NtOsLLsLuFL+y96ZMsc ERNw== X-Gm-Message-State: APjAAAXm5OcpzEhohzMm1kIJlSz16GcbF+JlYXcubKnaYOtoy7pbP4tN VIviRkWydJtTCNrq3dtltvD/ZQ== X-Received: by 2002:a63:1a46:: with SMTP id a6mr24146910pgm.3.1572327868852; Mon, 28 Oct 2019 22:44:28 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id j25sm12026231pfi.113.2019.10.28.22.44.24 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Oct 2019 22:44:28 -0700 (PDT) From: Baolin Wang To: adrian.hunter@intel.com, ulf.hansson@linaro.org, asutoshd@codeaurora.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, arnd@arndb.de, linus.walleij@linaro.org, vincent.guittot@linaro.org, baolin.wang@linaro.org, baolin.wang7@gmail.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 4/4] mmc: host: sdhci: Add a variable to defer to complete data requests if needed Date: Tue, 29 Oct 2019 13:43:22 +0800 Message-Id: <19910a2f34b9be81f64637a5a5fc8d07bd5f4885.1572326519.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org When using the host software queue, it will trigger the next request in irq handler without a context switch. But the sdhci_request() can not be called in interrupt context when using host software queue for some host drivers, due to the get_cd() ops can be sleepable. But for some host drivers, such as Spreadtrum host driver, the card is nonremovable, so the get_cd() ops is not sleepable, which means we can complete the data request and trigger the next request in irq handler to remove the context switch for the Spreadtrum host driver. Thus we still need introduce a variable in struct sdhci_host to indicate that we will always to defer to complete data requests if the sdhci_request() can not be called in interrupt context for some host drivers, when using the host software queue. Suggested-by: Adrian Hunter Signed-off-by: Baolin Wang --- drivers/mmc/host/sdhci.c | 2 +- drivers/mmc/host/sdhci.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) -- 1.7.9.5 diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 850241f..9cf2130 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -3035,7 +3035,7 @@ static inline bool sdhci_defer_done(struct sdhci_host *host, { struct mmc_data *data = mrq->data; - return host->pending_reset || + return host->pending_reset || (host->always_defer_done && data) || ((host->flags & SDHCI_REQ_USE_DMA) && data && data->host_cookie == COOKIE_MAPPED); } diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index d89cdb9..38fbd18 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -533,6 +533,7 @@ struct sdhci_host { bool pending_reset; /* Cmd/data reset is pending */ bool irq_wake_enabled; /* IRQ wakeup is enabled */ bool v4_mode; /* Host Version 4 Enable */ + bool always_defer_done; /* Always defer to complete data requests */ struct mmc_request *mrqs_done[SDHCI_MAX_MRQS]; /* Requests done */ struct mmc_command *cmd; /* Current command */