From patchwork Thu Mar 19 10:54:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 11447023 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 1F7E117E6 for ; Thu, 19 Mar 2020 10:55:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1DC320752 for ; Thu, 19 Mar 2020 10:55:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uju42OeH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726188AbgCSKzS (ORCPT ); Thu, 19 Mar 2020 06:55:18 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:33627 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725787AbgCSKzR (ORCPT ); Thu, 19 Mar 2020 06:55:17 -0400 Received: by mail-pl1-f193.google.com with SMTP id g18so920516plq.0; Thu, 19 Mar 2020 03:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=RnuPX1r2mFAI/A72C+v2CFVMojx/n50SdvshtlGYixw=; b=uju42OeHSKtnyKRnPW1/YiV8qcIg56COqPIBfv6T0yM96+14MRNYNXhO15JGSNMSJQ DAXxYbt/6N1eJA1CGoaTGvUvlTfWDeH52NsRlvwn7pfVdCTHbYyAPQs3YLA0ceVHJjgD y+RUtHvZvHbCpm6wtolwaRdlQr4WdvO/CaGVZmdNzAKFsYeWikHi3OnB9xZuuzqa6ZK/ zUrYwPK9HcWfNbeEhKGn+trtatj3cjrD5lHmPGj7rVkMQ/PpcccYIq1fDgOPmC6vfY5q MglNkGGihIVKEdvJZJ9oNU8ttpsCOqv9+Aiw5uaxHJe5w2TrHJXA2hvAkGL3exWRKv3F +5EQ== 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=RnuPX1r2mFAI/A72C+v2CFVMojx/n50SdvshtlGYixw=; b=W5KeSwyi8pwjCKgp1UO0tjlJRpY3cBolLKDuaKmEqSAl3lsS3xsyaB4LnqThMF9ISr Hk+q08NKz5cMTUpxxFjUQUyCCuZ18H9z0Xs65iJtWE7BuuAOE+JUWueMhtdodqK+WfQZ 5fJmv1huaRC0eBWXfy/+nRiUhzWrMqwbBjsOlV47ZagFyXyj0SATHpWMSFZO+OjYzwc6 KebfTPSDjTblbAOeFF0zEtUkN7wi99qJorY6PhrLJUmBSb4yRg6njB8/1UMpA8RFZGQQ gkBl2BKOQDWsdREg+LHW+1GsYb3CefYbWDi0eBwOBIKYH+ceLDsxmRhuxR79rB1ScI0C VJbg== X-Gm-Message-State: ANhLgQ1bYmTxrMf3/vKEbt/qLg7HHb9dV6ND+snGmld7sNlI2eKgGFFP Fhynk9vhYpEi9cO4Qc/+r+rGRV14 X-Google-Smtp-Source: ADFU+vuvIE63is1kB36eE0cb1LIYFHHZbai9871V3uGGAcY1un7kWo3JvaH9wsIRNYjOxXUS1C8C6w== X-Received: by 2002:a17:902:207:: with SMTP id 7mr3072020plc.216.1584615316285; Thu, 19 Mar 2020 03:55:16 -0700 (PDT) Received: from sh03840pcu.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id f6sm2209949pfk.99.2020.03.19.03.55.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2020 03:55:15 -0700 (PDT) From: Baolin Wang To: adrian.hunter@intel.com, ulf.hansson@linaro.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, baolin.wang7@gmail.com, arnd@arndb.de, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] mmc: host: Introduce the request_atomic() for the host Date: Thu, 19 Mar 2020 18:54:19 +0800 Message-Id: X-Mailer: git-send-email 1.9.1 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 SD host controller can process one request in the atomic context if the card is nonremovable, which means we can submit next request in the irq hard handler when using the MMC host software queue to reduce the latency. Thus this patch adds a new API request_atomic() for the host controller, as well as adding support for host software queue to submit a request by the new request_atomic() API. Suggested-by: Adrian Hunter Signed-off-by: Baolin Wang --- drivers/mmc/host/mmc_hsq.c | 5 ++++- include/linux/mmc/host.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c index 59d2776..fdbaa98 100644 --- a/drivers/mmc/host/mmc_hsq.c +++ b/drivers/mmc/host/mmc_hsq.c @@ -41,7 +41,10 @@ static void mmc_hsq_pump_requests(struct mmc_hsq *hsq) spin_unlock_irqrestore(&hsq->lock, flags); - mmc->ops->request(mmc, hsq->mrq); + if (mmc->ops->request_atomic) + mmc->ops->request_atomic(mmc, hsq->mrq); + else + mmc->ops->request(mmc, hsq->mrq); } static void mmc_hsq_update_next_tag(struct mmc_hsq *hsq, int remains) diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 562ed06..787a7b5 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -92,6 +92,9 @@ struct mmc_host_ops { int err); void (*pre_req)(struct mmc_host *host, struct mmc_request *req); void (*request)(struct mmc_host *host, struct mmc_request *req); + /* Submit one request to host in atomic context. */ + int (*request_atomic)(struct mmc_host *host, + struct mmc_request *req); /* * Avoid calling the next three functions too often or in a "fast From patchwork Thu Mar 19 10:54:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 11447029 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 2F9EB17E6 for ; Thu, 19 Mar 2020 10:55:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 04F8E20774 for ; Thu, 19 Mar 2020 10:55:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V/B8JAwY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727166AbgCSKzV (ORCPT ); Thu, 19 Mar 2020 06:55:21 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:50808 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725787AbgCSKzU (ORCPT ); Thu, 19 Mar 2020 06:55:20 -0400 Received: by mail-pj1-f66.google.com with SMTP id v13so869918pjb.0; Thu, 19 Mar 2020 03:55:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=yPu+Tsh1vDBZEMyMTwJs45J9Q+S4JNSfOUTW+nfLI0I=; b=V/B8JAwYgx2pDyQwqdGWZmIy+yLQe2pXcMPuFZWaPvnj3upkP9Csx1S+tqr/tdvfSV 0DfQ6Ryhq3FNaHjN2chEFpasaEgwSsQPc4ALSfhPuhvXYALZyERShtEQ7IagBXZC1zwh NJxONjJJuNOvgn9hl/6OKA7ndQlrvANLieBn2Uc/YUP2bQPmFsMqY1gp7SSsKjFcy7ax FC/eqad6WxN2B1iyDruttTOdjJcy5gRw6Z4QNn19qxKimhCRwdwBlD2B8/1hVDPShu9h pbToXBkOa1XXLgqTCVQyV8Cad9ieDSRGhwecaMptaZ/fQyU8Ll/RXCf6TWf+XrOyzbre Kalw== 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=yPu+Tsh1vDBZEMyMTwJs45J9Q+S4JNSfOUTW+nfLI0I=; b=l99v11SqHFvfmvkzhjz8A+UBdkh9jYy+4/+7qOmSBDB54bhM3Jc8hIwYE9IE0024rI 4131MA00JhkOmmGUCKcTiuwFYn/yOmm6HuzESJLcZKfJ7uOlMtWx9asgnH0E8U9JTWsq VJC0YyDqERDe8VEzg4iW9jCXwiDcXXY3WSgzQuSXPlf3lFviRH7U8zthGmw/KIYEVaOF GAxRJCzjCbMwec/nlzi2rRB8qFiUnANln+EzIgVi5Rf9Pb9gGzzA6L+6y4TjZlSqavUe hTS+w5x+Gm4Vu6ffTR4iVu01rriwxx25qzkdkq3Ku4lIYGYBS7dYiAFFC4y/pVX3xmKM kfXw== X-Gm-Message-State: ANhLgQ0NB1VWIZ3pl1x/KxiKKQ3ULUipzl5rmdg8yoppb+2AcLJU6j36 wojl1OgOqPPujmsTa8C9sw8= X-Google-Smtp-Source: ADFU+vuZlkT0wvI3GWKvr/tjlaWpJZv+n3i9HlYNHUBN0BRxpQi5a4UBmK71smj1CmKtrOAlVpNICQ== X-Received: by 2002:a17:90a:5d85:: with SMTP id t5mr3221589pji.126.1584615319129; Thu, 19 Mar 2020 03:55:19 -0700 (PDT) Received: from sh03840pcu.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id f6sm2209949pfk.99.2020.03.19.03.55.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2020 03:55:18 -0700 (PDT) From: Baolin Wang To: adrian.hunter@intel.com, ulf.hansson@linaro.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, baolin.wang7@gmail.com, arnd@arndb.de, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/4] mmc: host: sdhci: Implement the request_atomic() API Date: Thu, 19 Mar 2020 18:54:20 +0800 Message-Id: <485c1fc03e31007bf1464e94693569509c41d366.1584615043.git.baolin.wang7@gmail.com> X-Mailer: git-send-email 1.9.1 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 Implement the request_atomic() ops for the sdhci driver to process one request in the atomic context if the card is nonremovable. Moreover, add a boolean parameter for sdhci_send_command() function to indicate if need poll the inhibit bits, which can avoid time-consuming polling in interrupt context by returning BUSY if we met this unusual case through request_atomic() API. Signed-off-by: Baolin Wang --- drivers/mmc/host/sdhci.c | 65 +++++++++++++++++++++++++++++++++++------------- drivers/mmc/host/sdhci.h | 4 ++- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 9c37451..8f4b985 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1538,14 +1538,15 @@ static void sdhci_finish_data(struct sdhci_host *host) } else { /* Avoid triggering warning in sdhci_send_command() */ host->cmd = NULL; - sdhci_send_command(host, data->stop); + sdhci_send_command(host, data->stop, true); } } else { __sdhci_finish_mrq(host, data->mrq); } } -void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) +int sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd, + bool polling) { int flags; u32 mask; @@ -1573,13 +1574,26 @@ void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) mask &= ~SDHCI_DATA_INHIBIT; while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) { - if (timeout == 0) { + if (!polling) { + pr_err("%s: Controller has not released inhibit bit(s), try again.\n", + mmc_hostname(host->mmc)); + + /* + * HSQ may send a command in interrupt context without + * polling the busy signaling, which means we should + * return BUSY if controller has not released inhibit + * bits to allow HSQ trying to send request again in + * non-atomic context. so we should not finish this + * request here. + */ + return -EBUSY; + } else if (timeout == 0) { pr_err("%s: Controller never released inhibit bit(s).\n", mmc_hostname(host->mmc)); sdhci_dumpregs(host); cmd->error = -EIO; sdhci_finish_mrq(host, cmd->mrq); - return; + return -EIO; } timeout--; mdelay(1); @@ -1609,7 +1623,7 @@ void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) mmc_hostname(host->mmc)); cmd->error = -EINVAL; sdhci_finish_mrq(host, cmd->mrq); - return; + return -EINVAL; } if (!(cmd->flags & MMC_RSP_PRESENT)) @@ -1644,6 +1658,8 @@ void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) sdhci_external_dma_pre_transfer(host, cmd); sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND); + + return 0; } EXPORT_SYMBOL_GPL(sdhci_send_command); @@ -1706,7 +1722,7 @@ static void sdhci_finish_command(struct sdhci_host *host) /* Finished CMD23, now send actual command. */ if (cmd == cmd->mrq->sbc) { - sdhci_send_command(host, cmd->mrq->cmd); + sdhci_send_command(host, cmd->mrq->cmd, true); } else { /* Processed actual command. */ @@ -2016,16 +2032,12 @@ void sdhci_set_power(struct sdhci_host *host, unsigned char mode, * * \*****************************************************************************/ -void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) +static int sdhci_start_request(struct mmc_host *mmc, struct mmc_request *mrq, + int present, bool polling) { - struct sdhci_host *host; - int present; + struct sdhci_host *host = mmc_priv(mmc); unsigned long flags; - - host = mmc_priv(mmc); - - /* Firstly check card presence */ - present = mmc->ops->get_cd(mmc); + int ret; spin_lock_irqsave(&host->lock, flags); @@ -2033,15 +2045,34 @@ void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) if (!present || host->flags & SDHCI_DEVICE_DEAD) { mrq->cmd->error = -ENOMEDIUM; + ret = -ENOMEDIUM; sdhci_finish_mrq(host, mrq); } else { if (mrq->sbc && !(host->flags & SDHCI_AUTO_CMD23)) - sdhci_send_command(host, mrq->sbc); + ret = sdhci_send_command(host, mrq->sbc, polling); else - sdhci_send_command(host, mrq->cmd); + ret = sdhci_send_command(host, mrq->cmd, polling); } spin_unlock_irqrestore(&host->lock, flags); + + return ret; +} + +int sdhci_request_atomic(struct mmc_host *mmc, struct mmc_request *mrq) +{ + return sdhci_start_request(mmc, mrq, 1, false); +} +EXPORT_SYMBOL_GPL(sdhci_request_atomic); + +void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) +{ + int present; + + /* Firstly check card presence */ + present = mmc->ops->get_cd(mmc); + + sdhci_start_request(mmc, mrq, present, true); } EXPORT_SYMBOL_GPL(sdhci_request); @@ -2581,7 +2612,7 @@ void sdhci_send_tuning(struct sdhci_host *host, u32 opcode) */ sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE); - sdhci_send_command(host, &cmd); + sdhci_send_command(host, &cmd, true); host->cmd = NULL; diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index cac2d97..73e15c5 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -759,7 +759,8 @@ void __sdhci_read_caps(struct sdhci_host *host, const u16 *ver, int __sdhci_add_host(struct sdhci_host *host); int sdhci_add_host(struct sdhci_host *host); void sdhci_remove_host(struct sdhci_host *host, int dead); -void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd); +int sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd, + bool polling); static inline void sdhci_read_caps(struct sdhci_host *host) { @@ -775,6 +776,7 @@ void sdhci_set_power(struct sdhci_host *host, unsigned char mode, void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode, unsigned short vdd); void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq); +int sdhci_request_atomic(struct mmc_host *mmc, struct mmc_request *mrq); void sdhci_set_bus_width(struct sdhci_host *host, int width); void sdhci_reset(struct sdhci_host *host, u8 mask); void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing); From patchwork Thu Mar 19 10:54:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 11447025 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 766AA14B4 for ; Thu, 19 Mar 2020 10:55:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 555AC2078A for ; Thu, 19 Mar 2020 10:55:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uWRptmxy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725787AbgCSKzX (ORCPT ); Thu, 19 Mar 2020 06:55:23 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:36861 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727195AbgCSKzX (ORCPT ); Thu, 19 Mar 2020 06:55:23 -0400 Received: by mail-pj1-f68.google.com with SMTP id nu11so857249pjb.1; Thu, 19 Mar 2020 03:55:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=2B71Ilx38FSmc8wtIe4i237uiN3P11n9fl8wswTG+HE=; b=uWRptmxyg3U3LYbhlzQ1GX5LHM29toqGAeh/iTGNMSJMaU6hU4GxvfC2mGdIKL5XOR 8Ylc9TXDmov3+Eq2Z+zoh575WObZ6/cQ00Dh6MC6JwRRHUast/13omM0fYuSCvjQd4En vsg2mEIGf67A5JUZ1b3exnvLUIIQuJGI68cBW4gMmKGnhV7j07KX0EYKVDfJdIP/Es7T PlKra7VCaT+kpKUIO/PHVlaky0CQ5MBaOgoNeuTdcGLCn+Esnx11Jc0Ia+eYEHxcTDBh uIbPn2U8KEXVDMac/y2jJxF+TB5qOv9s3pLR9ruGqONw4QoclslkNZruKEwujOUHQOp9 F7nw== 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=2B71Ilx38FSmc8wtIe4i237uiN3P11n9fl8wswTG+HE=; b=t3NptdDftdjBIYlLdS7gny0GV5FF/g94+CwmMxYm/jFETa4pZ+GZnySEXZ0uox1La6 wjwbLQTc2hYVrAARL/ap2Ye6+cIFnWp3MqXq9CM4j86kynjxpnsXSA6stHJxKn4WMv5C O6UkpiUfLxVZPucrGha67P2OQcD7Pt1kBCzV3OfGf7TyU66yhDCfR900ciM7V5I8y6rw e+kkJQu+tt4Mihnkk1nckMZZ+zKy0a+t1uUTlwJVmaEVsJL823ZQSTBvDa6yaTSmOS9d InoWIVhqHiRUpArt5kfRmueg1HJdhONUvG5U4Ou/dhxWt0aOxoyVIWEtcjK3CrlcNZea oxmw== X-Gm-Message-State: ANhLgQ2zYW0Czv3w8GKMx1LQp8VaCbs14sJ85Mw48hhPcOnUCUOwGx3/ VIEBZr3NEHFaHGXuodKdqq0= X-Google-Smtp-Source: ADFU+vsFEpAuM+5N+ZYE6kuKGwTC3gEdyrqajza+qMi1FhU5I3Lk7C/a8gFJz6dQsVjg5slK2UalPw== X-Received: by 2002:a17:90a:654a:: with SMTP id f10mr3233621pjs.50.1584615321880; Thu, 19 Mar 2020 03:55:21 -0700 (PDT) Received: from sh03840pcu.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id f6sm2209949pfk.99.2020.03.19.03.55.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2020 03:55:21 -0700 (PDT) From: Baolin Wang To: adrian.hunter@intel.com, ulf.hansson@linaro.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, baolin.wang7@gmail.com, arnd@arndb.de, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/4] mmc: host: hsq: Handle an unusual case of returing busy Date: Thu, 19 Mar 2020 18:54:21 +0800 Message-Id: X-Mailer: git-send-email 1.9.1 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 There is an unusual case that the card is busy when trying to send a command, and we can not polling the card status in interrupt context by using request_atomic() to dispatch requests. Thus we should queue a work to try again in the non-atomic context in case the host releases the busy signal later. Signed-off-by: Baolin Wang --- drivers/mmc/host/mmc_hsq.c | 37 ++++++++++++++++++++++++++++++++++++- drivers/mmc/host/mmc_hsq.h | 1 + 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c index fdbaa98..3edad11 100644 --- a/drivers/mmc/host/mmc_hsq.c +++ b/drivers/mmc/host/mmc_hsq.c @@ -15,11 +15,33 @@ #define HSQ_NUM_SLOTS 64 #define HSQ_INVALID_TAG HSQ_NUM_SLOTS +static void mmc_hsq_retry_handler(struct work_struct *work) +{ + struct mmc_hsq *hsq = container_of(work, struct mmc_hsq, retry_work); + struct mmc_host *mmc = hsq->mmc; + struct mmc_request *mrq = hsq->mrq; + struct mmc_data *data = mrq->data; + + if (mmc->ops->request) { + mmc->ops->request(mmc, mrq); + return; + } + + /* + * If host does not supply the callback in normal context to + * handle request, just finish this request. + */ + data->error = -EBUSY; + data->bytes_xfered = 0; + mmc_hsq_finalize_request(mmc, mrq); +} + static void mmc_hsq_pump_requests(struct mmc_hsq *hsq) { struct mmc_host *mmc = hsq->mmc; struct hsq_slot *slot; unsigned long flags; + int ret = 0; spin_lock_irqsave(&hsq->lock, flags); @@ -42,9 +64,21 @@ static void mmc_hsq_pump_requests(struct mmc_hsq *hsq) spin_unlock_irqrestore(&hsq->lock, flags); if (mmc->ops->request_atomic) - mmc->ops->request_atomic(mmc, hsq->mrq); + ret = mmc->ops->request_atomic(mmc, hsq->mrq); else mmc->ops->request(mmc, hsq->mrq); + + /* + * If returning BUSY from request_atomic(), which means the card + * may be busy now, and we should change to non-atomic context to + * try again for this unusual case, to avoid time-consuming operations + * in the atomic context. + * + * Note: we can ignore other error cases, since the host driver + * will handle them. + */ + if (ret == -EBUSY) + schedule_work(&hsq->retry_work); } static void mmc_hsq_update_next_tag(struct mmc_hsq *hsq, int remains) @@ -327,6 +361,7 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc) hsq->mmc->cqe_private = hsq; mmc->cqe_ops = &mmc_hsq_ops; + INIT_WORK(&hsq->retry_work, mmc_hsq_retry_handler); spin_lock_init(&hsq->lock); init_waitqueue_head(&hsq->wait_queue); diff --git a/drivers/mmc/host/mmc_hsq.h b/drivers/mmc/host/mmc_hsq.h index d51beb7..81f6c4f 100644 --- a/drivers/mmc/host/mmc_hsq.h +++ b/drivers/mmc/host/mmc_hsq.h @@ -12,6 +12,7 @@ struct mmc_hsq { wait_queue_head_t wait_queue; struct hsq_slot *slot; spinlock_t lock; + struct work_struct retry_work; int next_tag; int num_slots; From patchwork Thu Mar 19 10:54:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 11447027 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 D695217E6 for ; Thu, 19 Mar 2020 10:55:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B482A20752 for ; Thu, 19 Mar 2020 10:55:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="brNWfESJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727195AbgCSKz0 (ORCPT ); Thu, 19 Mar 2020 06:55:26 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:35154 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727216AbgCSKzZ (ORCPT ); Thu, 19 Mar 2020 06:55:25 -0400 Received: by mail-pf1-f196.google.com with SMTP id u68so1241841pfb.2; Thu, 19 Mar 2020 03:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=X5441Jy2VbGV6dbzgZxForefu3q50NuP2ovt+obRsE4=; b=brNWfESJSuqO+4+09IIvPRsaedOM8E/pS6J73eUynhP08GAvpMo/aK/w8QFA2Qg4bE roRO7HwQklcJpIqr8DjAl101c1rL3bCjonnjy21/3z0aZVIEGqxms6VjEBh9/zeNBgDX 0/i9r9yIF5mn5kA2/nudMZkZ9I5SBLDzJrCIwrUpjNS6d1lbaQHkpDEsevmhXW9xPSvd L4K7qOZ3LX5XksSK7+b0jsbddBkE1gCFTegQVUeAci6TtPWImJCeChHjWECuPSrK2wBl 1lmbyImG54W9cU36DqP+5dkLYxTNLBPHidlVPVz4E/Ponii9ozXALQnCvcfZZwo4qIuM ntVg== 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=X5441Jy2VbGV6dbzgZxForefu3q50NuP2ovt+obRsE4=; b=VIRpZzMVZ7/H6Kvfoi/rwlpzZ53RsCY65LE7lFsEXNPpRjUkjW5ZJcKN67G0P2/MQ0 WEEDiztk7ODan6Sv+BIscHccDk734chB3ZxAypKnBXONg1/a70D7OGTSNXYsmI+a0eVg v9lfvdvht3wWq8+kx/pGLvrgj1qLq1yVBiqSbjwTcZzeFuWiXuWr2YYheYnSkTIx1Fzh oMd9Cz84bu5DB10pxibysBhxDt+0SRw+Ht7KCiTDpddVsFGrUG5V1vGLIc810N7EbPcJ HrU1MxF6Evk96EOvsQV4bmlO6Q7SDDc80RvnQpUtszEJBP/fJZCRWGNG5pFhIfpyr2oX UWHQ== X-Gm-Message-State: ANhLgQ0GgNGdIISeZp1YY1bQmO/n5Jpdow9fVJIszp050rrWPXrPLsI8 v804HU/4Qk1aEHpgiaxfSkM= X-Google-Smtp-Source: ADFU+vvwr8HV9kNS8ey2y7NUz400nhpNIeCWQcMYfi1GWHsCIpQjBM3WTOp+//wfnfqtqKg2GfParg== X-Received: by 2002:a63:7c5b:: with SMTP id l27mr573245pgn.414.1584615324647; Thu, 19 Mar 2020 03:55:24 -0700 (PDT) Received: from sh03840pcu.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id f6sm2209949pfk.99.2020.03.19.03.55.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2020 03:55:24 -0700 (PDT) From: Baolin Wang To: adrian.hunter@intel.com, ulf.hansson@linaro.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, baolin.wang7@gmail.com, arnd@arndb.de, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/4] mmc: host: sdhci-sprd: Implement the request_atomic() API Date: Thu, 19 Mar 2020 18:54:22 +0800 Message-Id: <2a7469f93323b6fc80176affa92f9396942a56e3.1584615043.git.baolin.wang7@gmail.com> X-Mailer: git-send-email 1.9.1 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 Implement the request_atomic() API for nonremovable cards, that means we can submit next request in the irq hard handler context to reduce latency. Moreover factor out the AUTO CMD23 checking into a separate function to reduce duplicate code. Signed-off-by: Baolin Wang --- drivers/mmc/host/sdhci-sprd.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c index 2ab42c5..bc7a8cb 100644 --- a/drivers/mmc/host/sdhci-sprd.c +++ b/drivers/mmc/host/sdhci-sprd.c @@ -406,7 +406,8 @@ static void sdhci_sprd_request_done(struct sdhci_host *host, .request_done = sdhci_sprd_request_done, }; -static void sdhci_sprd_request(struct mmc_host *mmc, struct mmc_request *mrq) +static void sdhci_sprd_check_auto_cmd23(struct mmc_host *mmc, + struct mmc_request *mrq) { struct sdhci_host *host = mmc_priv(mmc); struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host); @@ -422,10 +423,23 @@ static void sdhci_sprd_request(struct mmc_host *mmc, struct mmc_request *mrq) mrq->sbc && (mrq->sbc->arg & SDHCI_SPRD_ARG2_STUFF) && (host->flags & SDHCI_AUTO_CMD23)) host->flags &= ~SDHCI_AUTO_CMD23; +} + +static void sdhci_sprd_request(struct mmc_host *mmc, struct mmc_request *mrq) +{ + sdhci_sprd_check_auto_cmd23(mmc, mrq); sdhci_request(mmc, mrq); } +static int sdhci_sprd_request_atomic(struct mmc_host *mmc, + struct mmc_request *mrq) +{ + sdhci_sprd_check_auto_cmd23(mmc, mrq); + + return sdhci_request_atomic(mmc, mrq); +} + static int sdhci_sprd_voltage_switch(struct mmc_host *mmc, struct mmc_ios *ios) { struct sdhci_host *host = mmc_priv(mmc); @@ -561,6 +575,11 @@ static int sdhci_sprd_probe(struct platform_device *pdev) if (ret) goto pltfm_free; + if (!mmc_card_is_removable(host->mmc)) + host->mmc_host_ops.request_atomic = sdhci_sprd_request_atomic; + else + host->always_defer_done = true; + sprd_host = TO_SPRD_HOST(host); sdhci_sprd_phy_param_parse(sprd_host, pdev->dev.of_node); @@ -654,8 +673,6 @@ static int sdhci_sprd_probe(struct platform_device *pdev) if (ret) goto err_cleanup_host; - host->always_defer_done = true; - ret = __sdhci_add_host(host); if (ret) goto err_cleanup_host;