From patchwork Wed Sep 11 13:14:40 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: 11141063 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DA8816B1 for ; Wed, 11 Sep 2019 13:15:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6CB232084D for ; Wed, 11 Sep 2019 13:15:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="J1a9/Mrh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728027AbfIKNPJ (ORCPT ); Wed, 11 Sep 2019 09:15:09 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34930 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727837AbfIKNPJ (ORCPT ); Wed, 11 Sep 2019 09:15:09 -0400 Received: by mail-pg1-f194.google.com with SMTP id n4so11527637pgv.2 for ; Wed, 11 Sep 2019 06:15:08 -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=IYDEgSPFjLDdl06FdD0mska3UeVnMuFPlikdbTqLEfM=; b=J1a9/MrhnWPIbUboK3cTgk4A0tTd9DLQObD6dYFIakNwJKr2+u3gkFlDUCe0XKce9D pZv9fXqKXZMYYVNfzRbj7Os02QlKqaIuYgH7Tj0c6hEoVSPW3hbHqpkpnSgQ6WEXyb1O yvrng83hWy1kfk1yYA/DLexdjHP0zAsUxlkD3ED+tcxcgJA/uOY9PCnlxfMyjUivBG1h 2Q/P6lAfT5Vk+1NfOLW9bRGEBcu0S9PPSLFxQYovvAhR9ZfHE5lonybtEjgkQSxcKpsg w1vp3uFe5lfuJjA80CMor5ePiv2Y2WTo1/FaqhhT1KtpvQsr+5CMJBGwB7arYsVYqmDT KVDg== 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=IYDEgSPFjLDdl06FdD0mska3UeVnMuFPlikdbTqLEfM=; b=fBH6BNL/QkZAxCuCZB1C74EbnFczSLJTxRyEtmDg1U1VpEw9gEFBU7VqXkwL1aiLNJ 4Zayvtr4+6Yv18vrRUjUKJWq12+apU52+/MlTUEO7GdoNi+pbRC4RgUs84YSXPuzU4Sa ftf6a4jcOPee1Vw+BoOxuRdVmxQKrRNafqVUf052FawLDsDJW+1fs0dwvyyq3EOd4vr8 i1bJBdD8azWmfl0JyWrlTcD1DitPARBZW7fdVcTk6CcPrtU/Y2phgAKzY1E59kzkEcS3 ErBfRggsKq5hr4Qg4YjM7xU9cvdtGHvs7gcP/kyG8Cp49bRvz8Y7wKkrcCk8ChngznZU g2yg== X-Gm-Message-State: APjAAAWPmCaY8L7jTqHTpgQTI8agcLcPYPU33/0oqkO8b2WRQ7dx48YW 8YiN8tEuyCL3/9DNHUX/CQv0ww== X-Google-Smtp-Source: APXvYqw2qxF4aItLm2cOKVKCuUlHw2cFWiRODNKosJ8OSFSExNiQMVi49VYbhUeQmYlaXx6Xm7Mlxw== X-Received: by 2002:a17:90a:bb86:: with SMTP id v6mr5257821pjr.84.1568207708381; Wed, 11 Sep 2019 06:15:08 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id e21sm6420120pgr.43.2019.09.11.06.15.04 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Sep 2019 06:15:07 -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, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] mmc: host: cqhci: Move the struct cqhci_slot into header file Date: Wed, 11 Sep 2019 21:14:40 +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 The struct cqhci_slot will be used by MMC software queue introducing by following patches, thus move it to the header file. Signed-off-by: Baolin Wang --- drivers/mmc/host/cqhci.c | 10 ---------- drivers/mmc/host/cqhci.h | 11 ++++++++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/mmc/host/cqhci.c b/drivers/mmc/host/cqhci.c index f7bdae5..57ff1cc 100644 --- a/drivers/mmc/host/cqhci.c +++ b/drivers/mmc/host/cqhci.c @@ -21,16 +21,6 @@ #define DCMD_SLOT 31 #define NUM_SLOTS 32 -struct cqhci_slot { - struct mmc_request *mrq; - unsigned int flags; -#define CQHCI_EXTERNAL_TIMEOUT BIT(0) -#define CQHCI_COMPLETED BIT(1) -#define CQHCI_HOST_CRC BIT(2) -#define CQHCI_HOST_TIMEOUT BIT(3) -#define CQHCI_HOST_OTHER BIT(4) -}; - static inline u8 *get_desc(struct cqhci_host *cq_host, u8 tag) { return cq_host->desc_base + (tag * cq_host->slot_sz); diff --git a/drivers/mmc/host/cqhci.h b/drivers/mmc/host/cqhci.h index def76e9..7b07bf24f 100644 --- a/drivers/mmc/host/cqhci.h +++ b/drivers/mmc/host/cqhci.h @@ -141,7 +141,16 @@ struct cqhci_host_ops; struct mmc_host; struct mmc_request; -struct cqhci_slot; + +struct cqhci_slot { + struct mmc_request *mrq; + unsigned int flags; +#define CQHCI_EXTERNAL_TIMEOUT BIT(0) +#define CQHCI_COMPLETED BIT(1) +#define CQHCI_HOST_CRC BIT(2) +#define CQHCI_HOST_TIMEOUT BIT(3) +#define CQHCI_HOST_OTHER BIT(4) +}; struct cqhci_host { const struct cqhci_host_ops *ops; From patchwork Wed Sep 11 13:14:41 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: 11141065 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 396D0112B for ; Wed, 11 Sep 2019 13:15:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EEABD206A5 for ; Wed, 11 Sep 2019 13:15:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="lyLcaXEy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728100AbfIKNPO (ORCPT ); Wed, 11 Sep 2019 09:15:14 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41711 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728099AbfIKNPN (ORCPT ); Wed, 11 Sep 2019 09:15:13 -0400 Received: by mail-pg1-f195.google.com with SMTP id x15so11504294pgg.8 for ; Wed, 11 Sep 2019 06:15:13 -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=iyv/kmDWbpjuWrxcPOL8t64uW6df/+/SOzTHDuVUdWo=; b=lyLcaXEyZHtWwRVOr1FEXEbdGQsDZZtMsWga82C5KgLhV1GwDFbng/nYuvCtdX7kwp BgByHBdbPk/NDtT/2CN/YXVLogcPRQLoJw8o4FklUu39TGE6ykPJFdcXNZyFBVH3N3K5 3xVTKGoVz7WA8CNPgmBKJrWoXt0hAZMfhhdoU8T8QKbkyhsrzEHLD/q/yThiPA8+D9rP NvlPBqrIfjysADAEcwXkSQQ/faqFMkX/2VqTxFLbV0hBDnEbbw2ZFxT4IMxUl4t9VcJX BojIvzV7ar/tkSHZopY+gzZn0acVMcBZdyqHI7wwHtvESTwzeqgYCjSejMv2LjtX7Suy Labw== 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=iyv/kmDWbpjuWrxcPOL8t64uW6df/+/SOzTHDuVUdWo=; b=ZuatcF3+xAsr9fMfxfxXzk8qDOQGWmWs9SZmCkPhI//XnOBJMbpKCbGql5WeUkn0WW 9WQQ1Aa6ZpALBikchgN8nJy2PURSDcSpThpD87AByab3zvYfhbCEfhXn/g6ALMmol9lJ Q3pEHR5/7MRuofa6Dc1imuJpUJxKQiUqRgKVoYGfahU5JZXgg2RHGhD1ihnia2ATjQXr grgNXEqEUcRo5W11VjaC1/swCCmrsLtFXe0bPmXzwhSviujxc4J1qV92LmlCYBVBMaez o4TESvplZH8MiYUB1SEAcNIfo18RxwS+GWCxMo+etMKmAemKiSRrFwUqfSnY78uBjRKo 2weQ== X-Gm-Message-State: APjAAAXjdRIJXrTkbeP9WjKkoa19XYmdiM85aqfW2w6BY51ZvOPsVwyy ovJ1wUBNXsIQRDMn3lvtfVtkWw== X-Google-Smtp-Source: APXvYqyComkr4gpaW+15QQJOCAYLDGbZdpuL9sZgM304sapsYKykpsb7RrPktrkAIOWJmBuKQb847A== X-Received: by 2002:a62:ce81:: with SMTP id y123mr1543940pfg.115.1568207712581; Wed, 11 Sep 2019 06:15:12 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id e21sm6420120pgr.43.2019.09.11.06.15.08 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Sep 2019 06:15:11 -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, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] mmc: Add MMC software queue support Date: Wed, 11 Sep 2019 21:14:41 +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 queue depth as 2 for software queue, that is enough to let the irq handler always trigger the next request without a context switch and then ask the blk_mq layer for the next one to get queued, as well as avoiding a long latency. From the fio testing data in cover letter, we can see the software queue can improve performance obviously with 4K block size, increasing about 52% for sequential read, increasing about 114% for random read, increasing about 81% for sequential write, and increasing about 127% for random 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 | 25 +++- drivers/mmc/host/Kconfig | 8 ++ drivers/mmc/host/Makefile | 1 + drivers/mmc/host/cqhci.h | 6 + drivers/mmc/host/sqhci.c | 345 +++++++++++++++++++++++++++++++++++++++++++++ drivers/mmc/host/sqhci.h | 35 +++++ include/linux/mmc/host.h | 3 + 9 files changed, 487 insertions(+), 10 deletions(-) create mode 100644 drivers/mmc/host/sqhci.c create mode 100644 drivers/mmc/host/sqhci.h 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 7102e2e..2c93c29 100644 --- a/drivers/mmc/core/queue.c +++ b/drivers/mmc/core/queue.c @@ -60,7 +60,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) @@ -122,12 +122,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); @@ -142,12 +144,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); @@ -158,6 +161,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); @@ -407,11 +413,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 14d89a1..d117f18 100644 --- a/drivers/mmc/host/Kconfig +++ b/drivers/mmc/host/Kconfig @@ -923,6 +923,14 @@ config MMC_CQHCI If unsure, say N. +config MMC_SQHCI + bool "Software Queue Host Controller Interface support" + help + This selects the Software Queue Host Controller Interface (SQHCI) + 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 7357871..a3588d4 100644 --- a/drivers/mmc/host/Makefile +++ b/drivers/mmc/host/Makefile @@ -97,6 +97,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_SQHCI) += sqhci.o ifeq ($(CONFIG_CB710_DEBUG),y) CFLAGS-cb710-mmc += -DDEBUG diff --git a/drivers/mmc/host/cqhci.h b/drivers/mmc/host/cqhci.h index 7b07bf24f..1769715 100644 --- a/drivers/mmc/host/cqhci.h +++ b/drivers/mmc/host/cqhci.h @@ -205,6 +205,12 @@ struct cqhci_host { struct completion halt_comp; wait_queue_head_t wait_queue; struct cqhci_slot *slot; + +#ifdef CONFIG_MMC_SQHCI + /* Software queue support */ + int next_tag; + struct mmc_request *mrq; +#endif }; struct cqhci_host_ops { diff --git a/drivers/mmc/host/sqhci.c b/drivers/mmc/host/sqhci.c new file mode 100644 index 0000000..e9c73d1 --- /dev/null +++ b/drivers/mmc/host/sqhci.c @@ -0,0 +1,345 @@ +// 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 + +#include "sqhci.h" + +#define SQHCI_NUM_SLOTS 2 +#define SQHCI_INVALID_TAG SQHCI_NUM_SLOTS + +static void sqhci_pump_requests(struct cqhci_host *sq_host) +{ + struct mmc_host *mmc = sq_host->mmc; + struct cqhci_slot *slot; + unsigned long flags; + + spin_lock_irqsave(&sq_host->lock, flags); + + /* Make sure we are not already running a request now */ + if (sq_host->mrq) { + spin_unlock_irqrestore(&sq_host->lock, flags); + return; + } + + /* Make sure there are remain requests need to pump */ + if (!sq_host->qcnt || !sq_host->enabled) { + spin_unlock_irqrestore(&sq_host->lock, flags); + return; + } + + slot = &sq_host->slot[sq_host->next_tag]; + sq_host->mrq = slot->mrq; + sq_host->qcnt--; + + spin_unlock_irqrestore(&sq_host->lock, flags); + + mmc->ops->request(mmc, sq_host->mrq); +} + +static void sqhci_update_next_tag(struct cqhci_host *sq_host, int remains) +{ + struct cqhci_slot *slot; + int tag; + + /* + * If there are no remain requests in software queue, then set a invalid + * tag. + */ + if (!remains) { + sq_host->next_tag = SQHCI_INVALID_TAG; + return; + } + + /* + * Increasing the next tag and check if the corresponding request is + * available, if yes, then we found a candidate request. + */ + if (++sq_host->next_tag != SQHCI_INVALID_TAG) { + slot = &sq_host->slot[sq_host->next_tag]; + if (slot->mrq) + return; + } + + /* Othersie we should iterate all slots to find a available tag. */ + for (tag = 0; tag < SQHCI_NUM_SLOTS; tag++) { + slot = &sq_host->slot[tag]; + if (slot->mrq) + break; + } + + if (tag == SQHCI_NUM_SLOTS) + tag = SQHCI_INVALID_TAG; + + sq_host->next_tag = tag; +} + +static void sqhci_post_request(struct cqhci_host *sq_host) +{ + unsigned long flags; + int remains; + + spin_lock_irqsave(&sq_host->lock, flags); + + remains = sq_host->qcnt; + sq_host->mrq = NULL; + + /* Update the next available tag to be queued. */ + sqhci_update_next_tag(sq_host, remains); + + if (sq_host->waiting_for_idle && !remains) { + sq_host->waiting_for_idle = false; + wake_up(&sq_host->wait_queue); + } + + /* Do not pump new request in recovery mode. */ + if (sq_host->recovery_halt) { + spin_unlock_irqrestore(&sq_host->lock, flags); + return; + } + + spin_unlock_irqrestore(&sq_host->lock, flags); + + /* + * Try to pump new request to host controller as fast as possible, + * after completing previous request. + */ + if (remains > 0) + sqhci_pump_requests(sq_host); +} + +/** + * sqhci_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 sqhci_finalize_request(struct mmc_host *mmc, struct mmc_request *mrq) +{ + struct cqhci_host *sq_host = mmc->cqe_private; + unsigned long flags; + + spin_lock_irqsave(&sq_host->lock, flags); + + if (!sq_host->enabled || !sq_host->mrq || sq_host->mrq != mrq) { + spin_unlock_irqrestore(&sq_host->lock, flags); + return false; + } + + /* + * Clear current completed slot request to make a room for new request. + */ + sq_host->slot[sq_host->next_tag].mrq = NULL; + + spin_unlock_irqrestore(&sq_host->lock, flags); + + mmc_cqe_request_done(mmc, sq_host->mrq); + + sqhci_post_request(sq_host); + + return true; +} +EXPORT_SYMBOL_GPL(sqhci_finalize_request); + +static void sqhci_recovery_start(struct mmc_host *mmc) +{ + struct cqhci_host *sq_host = mmc->cqe_private; + unsigned long flags; + + spin_lock_irqsave(&sq_host->lock, flags); + + sq_host->recovery_halt = true; + + spin_unlock_irqrestore(&sq_host->lock, flags); +} + +static void sqhci_recovery_finish(struct mmc_host *mmc) +{ + struct cqhci_host *sq_host = mmc->cqe_private; + int remains; + + spin_lock_irq(&sq_host->lock); + + sq_host->recovery_halt = false; + remains = sq_host->qcnt; + + spin_unlock_irq(&sq_host->lock); + + /* + * Try to pump new request if there are request pending in software + * queue after finishing recovery. + */ + if (remains > 0) + sqhci_pump_requests(sq_host); +} + +static int sqhci_request(struct mmc_host *mmc, struct mmc_request *mrq) +{ + struct cqhci_host *sq_host = mmc->cqe_private; + int tag = mrq->tag; + + spin_lock_irq(&sq_host->lock); + + if (!sq_host->enabled) { + spin_unlock_irq(&sq_host->lock); + return -ESHUTDOWN; + } + + /* Do not queue any new requests in recovery mode. */ + if (sq_host->recovery_halt) { + spin_unlock_irq(&sq_host->lock); + return -EBUSY; + } + + sq_host->slot[tag].mrq = mrq; + + /* + * Set the next tag as current request tag if no available + * next tag. + */ + if (sq_host->next_tag == SQHCI_INVALID_TAG) + sq_host->next_tag = tag; + + sq_host->qcnt++; + + spin_unlock_irq(&sq_host->lock); + + sqhci_pump_requests(sq_host); + + return 0; +} + +static void sqhci_post_req(struct mmc_host *mmc, struct mmc_request *mrq) +{ + if (mmc->ops->post_req) + mmc->ops->post_req(mmc, mrq, 0); +} + +static bool sqhci_queue_is_idle(struct cqhci_host *sq_host, int *ret) +{ + bool is_idle; + + spin_lock_irq(&sq_host->lock); + + is_idle = (!sq_host->mrq && !sq_host->qcnt) || + sq_host->recovery_halt; + + *ret = sq_host->recovery_halt ? -EBUSY : 0; + sq_host->waiting_for_idle = !is_idle; + + spin_unlock_irq(&sq_host->lock); + + return is_idle; +} + +static int sqhci_wait_for_idle(struct mmc_host *mmc) +{ + struct cqhci_host *sq_host = mmc->cqe_private; + int ret; + + wait_event(sq_host->wait_queue, + sqhci_queue_is_idle(sq_host, &ret)); + + return ret; +} + +static void sqhci_disable(struct mmc_host *mmc) +{ + struct cqhci_host *sq_host = mmc->cqe_private; + u32 timeout = 500; + int ret; + + spin_lock_irq(&sq_host->lock); + + if (!sq_host->enabled) { + spin_unlock_irq(&sq_host->lock); + return; + } + + spin_unlock_irq(&sq_host->lock); + + ret = wait_event_timeout(sq_host->wait_queue, + sqhci_queue_is_idle(sq_host, &ret), + msecs_to_jiffies(timeout)); + if (ret == 0) { + pr_warn("could not stop mmc software queue\n"); + return; + } + + spin_lock_irq(&sq_host->lock); + + sq_host->enabled = false; + + spin_unlock_irq(&sq_host->lock); +} + +static int sqhci_enable(struct mmc_host *mmc, struct mmc_card *card) +{ + struct cqhci_host *sq_host = mmc->cqe_private; + + spin_lock_irq(&sq_host->lock); + + if (sq_host->enabled) { + spin_unlock_irq(&sq_host->lock); + return -EBUSY; + } + + sq_host->enabled = true; + + spin_unlock_irq(&sq_host->lock); + + return 0; +} + +static const struct mmc_cqe_ops sqhci_ops = { + .cqe_enable = sqhci_enable, + .cqe_disable = sqhci_disable, + .cqe_request = sqhci_request, + .cqe_post_req = sqhci_post_req, + .cqe_wait_for_idle = sqhci_wait_for_idle, + .cqe_recovery_start = sqhci_recovery_start, + .cqe_recovery_finish = sqhci_recovery_finish, +}; + +int sqhci_init(struct cqhci_host *sq_host, struct mmc_host *mmc) +{ + sq_host->num_slots = SQHCI_NUM_SLOTS; + sq_host->next_tag = SQHCI_INVALID_TAG; + mmc->cqe_qdepth = SQHCI_NUM_SLOTS; + + sq_host->slot = devm_kcalloc(mmc_dev(mmc), sq_host->num_slots, + sizeof(struct cqhci_slot), GFP_KERNEL); + if (!sq_host->slot) + return -ENOMEM; + + sq_host->mmc = mmc; + sq_host->mmc->cqe_private = sq_host; + mmc->cqe_ops = &sqhci_ops; + + spin_lock_init(&sq_host->lock); + init_waitqueue_head(&sq_host->wait_queue); + + return 0; +} +EXPORT_SYMBOL_GPL(sqhci_init); + +void sqhci_suspend(struct mmc_host *mmc) +{ + sqhci_disable(mmc); +} +EXPORT_SYMBOL_GPL(sqhci_suspend); + +int sqhci_resume(struct mmc_host *mmc) +{ + return sqhci_enable(mmc, NULL); +} +EXPORT_SYMBOL_GPL(sqhci_resume); diff --git a/drivers/mmc/host/sqhci.h b/drivers/mmc/host/sqhci.h new file mode 100644 index 0000000..fdaaed0 --- /dev/null +++ b/drivers/mmc/host/sqhci.h @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef LINUX_MMC_SQHCI_H +#define LINUX_MMC_SQHCI_H + +#include "cqhci.h" + +#ifdef CONFIG_MMC_SQHCI +int sqhci_init(struct cqhci_host *cqv_host, struct mmc_host *mmc); +void sqhci_suspend(struct mmc_host *mmc); +int sqhci_resume(struct mmc_host *mmc); +bool sqhci_finalize_request(struct mmc_host *mmc, struct mmc_request *mrq); +#else +static inline int sqhci_init(struct cqhci_host *cqv_host, struct mmc_host *mmc) +{ + return -EINVAL; +} + +static inline void sqhci_suspend(struct mmc_host *mmc) +{ +} + +static inline int sqhci_resume(struct mmc_host *mmc) +{ + return 0; +} + +static inline bool sqhci_finalize_request(struct mmc_host *mmc, + struct mmc_request *mrq) +{ + return false; +} + +#endif + +#endif diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 4a351cb..706e2bc 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -459,6 +459,9 @@ struct mmc_host { bool cqe_enabled; bool cqe_on; + /* Software Queue support */ + bool swq_enabled; + unsigned long private[0] ____cacheline_aligned; }; From patchwork Wed Sep 11 13:14:42 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: 11141067 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51E27112B for ; Wed, 11 Sep 2019 13:15:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2FBC4206A5 for ; Wed, 11 Sep 2019 13:15:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="oOzx4iKT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728120AbfIKNPS (ORCPT ); Wed, 11 Sep 2019 09:15:18 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42072 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727826AbfIKNPS (ORCPT ); Wed, 11 Sep 2019 09:15:18 -0400 Received: by mail-pg1-f193.google.com with SMTP id p3so11500208pgb.9 for ; Wed, 11 Sep 2019 06:15: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=+JBkSI5LCUYcNi8/zrQxcvj8pwF/Tq3geiwHLKhqOig=; b=oOzx4iKT8AsUYK46/eoTaeYiT1jKbTwBB3LS2rh+omq4KknlrU4boetTyKuqTe47Ng ZPC/cisMt6KXFjGBcEoB1CTYqWQgVbuIvRjjOAlr5bl67oH4qgVXAUdC5gr7KCji77jT FHX7s5pY2hRKvzUpmt517zPlFGsBxAJ6qSM3ctXCvqE8ACPgD815DrbbPV5v3DMVrizQ CVRuB0HlWCzGKCFXrs5ijPj5Lad2R1jJtcXW/RS1hvt6NfLprx02d8hSMwONiFF6N8pR nXUvjQzs6VqZZpFuhOiu9h42svKfP4fhMFInUfJp4TvjDqRvGr83IubmszUW4y7Rb2sl ns+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:in-reply-to:references; bh=+JBkSI5LCUYcNi8/zrQxcvj8pwF/Tq3geiwHLKhqOig=; b=THjs2/1AspBGh8aZOtlBPiMWJAbYlC3Wd09Ly9qBoOvW1CNipgec0p24ui/p7h/M/Y MjvAgUXVjVMMztGYmV217mnL13F9ohdex/EF5n5/7gvxRsawckZrDQh7mrtJhySg12kJ U/jXzsaFPQ+lAT4zsYKp0IqlWzuginkIX0DEv7yWbLffjTsDw8/7P7s3x1MccrXT9rU8 YNh/CKFRDzXK6qaWUtyWUJKqgfc5TLN1X5QylEFXZ21KEoadg/9UlflUz0HbsF4HeTw5 krPk1eYAHBZiU5No4ucpV1t+LQ96falTE0TgEvYTPPRBayghvpDxkRl2kQtPWB4DnUqq FTzQ== X-Gm-Message-State: APjAAAUaif2yHk8Qtzhn8yl74TXhzhDa6ukgeDHroPsqJRRVIEhkmc8I 8OK11a9qLVUtAtfbjBmd42csjA== X-Google-Smtp-Source: APXvYqyz0f/JCciYHanh62R64szRSCDQjL2XiMkuzjgbIN/GVa48zSSdr2B/2dKutLtYsDeX8RodwQ== X-Received: by 2002:a17:90a:aa0a:: with SMTP id k10mr5496801pjq.18.1568207716409; Wed, 11 Sep 2019 06:15:16 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id e21sm6420120pgr.43.2019.09.11.06.15.12 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Sep 2019 06:15: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, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] mmc: host: sdhci: Add request_done ops for struct sdhci_ops Date: Wed, 11 Sep 2019 21:14:42 +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 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. Signed-off-by: Baolin Wang --- drivers/mmc/host/sdhci.c | 12 ++++++++++-- drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index a5dc5aa..b2c8695 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -2710,7 +2710,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; } @@ -3133,7 +3136,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 902f855..e9a476f 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -643,6 +643,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 Wed Sep 11 13:14:43 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: 11141069 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D0A214DB for ; Wed, 11 Sep 2019 13:15:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0BAC4206A5 for ; Wed, 11 Sep 2019 13:15:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="uyKc+aH4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728139AbfIKNPW (ORCPT ); Wed, 11 Sep 2019 09:15:22 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:37880 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728135AbfIKNPV (ORCPT ); Wed, 11 Sep 2019 09:15:21 -0400 Received: by mail-pf1-f193.google.com with SMTP id y5so10905724pfo.4 for ; Wed, 11 Sep 2019 06:15:21 -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=HJGZrNijsmlC5WTcQ4d8JI7jp4tO9JVLJxVcQXONoXo=; b=uyKc+aH4wratJZkJatOcySBRFbiAHLNyssKiIe5+5Gg+7LIiuamaypPhAC6tpNkoAi DtKNRqmoKD/BbzkoSATkV9Gm4UC5lDJRgz1Zr9hmpyv6faXhjpSSwYDcbJBjwcB1uznb nK8FFqbVs6fwO6tcPELepSySimc//fSBv5YkUYLwx0rR55tpmZo5MLAPKDr6BOEEZm4V miGE/jElyvvcUGhB1/QqJx9eTkyK8LqNtQ4KBgob1qHPfF5TJIgcA+HNmlMcDkVD4iMI h6Jsaz8DcEn8IoXxxJ0RPaxB5EJNH4DFlfs1O1+tywoaqTg685b4Qxgal76ncan4lDR1 hPew== 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=HJGZrNijsmlC5WTcQ4d8JI7jp4tO9JVLJxVcQXONoXo=; b=eUpFacmZ74+VVIMZH3MqUoXyxoCGS6oiTnbcQCC8dpODfher5AwTT5wl4hymW2fVhK Z8Yq27Jfhw/tA7ji5quo4Tl13R2ruGPd/RzQqoH+tqv3RnelvNE/MIeqtLue3Ssk7Z/h pyxtxg6n2Q9Z/Uz+PatEjYJ7ffpJrvB7/bsPbvXZuuURJmDZtGmRGV623AhsOCJqgN3H EILao9cumqzaLm7QB9puKiOMsP4n5CsyiiGjVRuBamNPtT1JWjcedHwPEx/5TEtBD/Q8 9PrPuIvLQU8n2PHqWTjPav9NBOkULLoyHcURT1iUYbbqSjuWaPLyP+W9MfCB9t2qgNjU QgQQ== X-Gm-Message-State: APjAAAX3HZvEzeWeMvQuKKaPAxyWLr1jO3U9jpTThM5qe/7mtQA29AGY GYnlHZ1a4auEc4J7/u2ZkMnqrQ== X-Google-Smtp-Source: APXvYqwaBtIn5Ydg+bFThEB8HKE8FUyy085EWCxRpciLQul2CPSU5IOFKxXZ+54lEHwo+5eJRhNwRg== X-Received: by 2002:a17:90a:17c5:: with SMTP id q63mr5449836pja.106.1568207720620; Wed, 11 Sep 2019 06:15:20 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id e21sm6420120pgr.43.2019.09.11.06.15.16 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Sep 2019 06:15: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, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] mmc: host: sdhci-sprd: Add software queue support Date: Wed, 11 Sep 2019 21:14:43 +0800 Message-Id: <351897e271069582a7ce7775fd803d556b5bebde.1568206300.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 software queue support to improve the performance. Signed-off-by: Baolin Wang --- drivers/mmc/host/Kconfig | 1 + drivers/mmc/host/sdhci-sprd.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig index d117f18..862e8e9 100644 --- a/drivers/mmc/host/Kconfig +++ b/drivers/mmc/host/Kconfig @@ -619,6 +619,7 @@ config MMC_SDHCI_SPRD depends on ARCH_SPRD depends on MMC_SDHCI_PLTFM select MMC_SDHCI_IO_ACCESSORS + select MMC_SQHCI help This selects the SDIO Host Controller in Spreadtrum SoCs, this driver supports R11(IP version: R11P0). diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c index d07b979..f6f157f 100644 --- a/drivers/mmc/host/sdhci-sprd.c +++ b/drivers/mmc/host/sdhci-sprd.c @@ -19,6 +19,7 @@ #include #include "sdhci-pltfm.h" +#include "sqhci.h" /* SDHCI_ARGUMENT2 register high 16bit */ #define SDHCI_SPRD_ARG2_STUFF GENMASK(31, 16) @@ -379,6 +380,16 @@ static unsigned int sdhci_sprd_get_ro(struct sdhci_host *host) return 0; } +static void sdhci_sprd_request_done(struct sdhci_host *host, + struct mmc_request *mrq) +{ + /* Validate if the request was from software queue firstly. */ + if (sqhci_finalize_request(host->mmc, mrq)) + return; + + mmc_request_done(host->mmc, mrq); +} + static struct sdhci_ops sdhci_sprd_ops = { .read_l = sdhci_sprd_readl, .write_l = sdhci_sprd_writel, @@ -392,6 +403,7 @@ static unsigned int sdhci_sprd_get_ro(struct sdhci_host *host) .hw_reset = sdhci_sprd_hw_reset, .get_max_timeout_count = sdhci_sprd_get_max_timeout_count, .get_ro = sdhci_sprd_get_ro, + .request_done = sdhci_sprd_request_done, }; static void sdhci_sprd_request(struct mmc_host *mmc, struct mmc_request *mrq) @@ -521,6 +533,7 @@ static int sdhci_sprd_probe(struct platform_device *pdev) { struct sdhci_host *host; struct sdhci_sprd_host *sprd_host; + struct cqhci_host *sq_host; struct clk *clk; int ret = 0; @@ -631,6 +644,16 @@ static int sdhci_sprd_probe(struct platform_device *pdev) sprd_host->flags = host->flags; + sq_host = devm_kzalloc(&pdev->dev, sizeof(*sq_host), GFP_KERNEL); + if (!sq_host) { + ret = -ENOMEM; + goto err_cleanup_host; + } + + ret = sqhci_init(sq_host, host->mmc); + if (ret) + goto err_cleanup_host; + ret = __sdhci_add_host(host); if (ret) goto err_cleanup_host; @@ -689,6 +712,7 @@ static int sdhci_sprd_runtime_suspend(struct device *dev) struct sdhci_host *host = dev_get_drvdata(dev); struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host); + sqhci_suspend(host->mmc); sdhci_runtime_suspend_host(host); clk_disable_unprepare(sprd_host->clk_sdio); @@ -717,6 +741,8 @@ static int sdhci_sprd_runtime_resume(struct device *dev) goto clk_disable; sdhci_runtime_resume_host(host, 1); + sqhci_resume(host->mmc); + return 0; clk_disable: