From patchwork Wed Jun 15 13:01:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ritesh Harjani X-Patchwork-Id: 9178511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A3D8D6021C for ; Wed, 15 Jun 2016 13:03:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94E3A2012F for ; Wed, 15 Jun 2016 13:03:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8990727C26; Wed, 15 Jun 2016 13:03:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83BE62012F for ; Wed, 15 Jun 2016 13:03:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753293AbcFONDF (ORCPT ); Wed, 15 Jun 2016 09:03:05 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:43774 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753154AbcFONDD (ORCPT ); Wed, 15 Jun 2016 09:03:03 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 3369B612D3; Wed, 15 Jun 2016 13:03:03 +0000 (UTC) Received: from rharjani-linux.qualcomm.com (unknown [202.46.23.54]) (using TLSv1.1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: riteshh@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 18224613A2; Wed, 15 Jun 2016 13:02:56 +0000 (UTC) From: Ritesh Harjani To: ulf.hansson@linaro.org, linux-mmc@vger.kernel.org Cc: adrian.hunter@intel.com, alex.lemberg@sandisk.com, mateusz.nowak@intel.com, Yuliy.Izrailov@sandisk.com, jh80.chung@samsung.com, dongas86@gmail.com, asutoshd@codeaurora.org, zhangfei.gao@gmail.com, sthumma@codeaurora.org, kdorfman@codeaurora.org, david.griego@linaro.org, stummala@codeaurora.org, venkatg@codeaurora.org, Ritesh Harjani Subject: [PATCH RFC 08/10] mmc: core: Add halt support Date: Wed, 15 Jun 2016 18:31:12 +0530 Message-Id: <1465995674-15816-9-git-send-email-riteshh@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1465995674-15816-1-git-send-email-riteshh@codeaurora.org> References: <1465995674-15816-1-git-send-email-riteshh@codeaurora.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Asutosh Das Halt is a controller feature that can change the controller mode from command-queue to legacy. This feature is very helpful in error cases. Signed-off-by: Asutosh Das Signed-off-by: Venkat Gopalakrishnan [riteshh@codeaurora.org: fixed merge conflicts] Signed-off-by: Ritesh Harjani --- drivers/mmc/card/queue.c | 1 + drivers/mmc/core/core.c | 33 +++++++++++++++++++++++++++++++++ include/linux/mmc/core.h | 1 + include/linux/mmc/host.h | 17 +++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c index 32f9726..37423ab 100644 --- a/drivers/mmc/card/queue.c +++ b/drivers/mmc/card/queue.c @@ -50,6 +50,7 @@ static inline bool mmc_cmdq_should_pull_reqs(struct mmc_host *host, struct mmc_cmdq_context_info *ctx) { if (test_bit(CMDQ_STATE_DCMD_ACTIVE, &ctx->curr_state) || + mmc_host_halt(host) || test_bit(CMDQ_STATE_ERR, &ctx->curr_state)) { pr_debug("%s: %s: skip pulling reqs: state: %lu\n", mmc_hostname(host), __func__, ctx->curr_state); diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index ce5e303..6f97841 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -596,6 +596,39 @@ void mmc_cmdq_post_req(struct mmc_host *host, struct mmc_request *mrq, int err) } EXPORT_SYMBOL(mmc_cmdq_post_req); +/** + * mmc_cmdq_halt - halt/un-halt the command queue engine + * @host: host instance + * @halt: true - halt, un-halt otherwise + * + * Host halts the command queue engine. It should complete + * the ongoing transfer and release the bus. + * All legacy commands can be sent upon successful + * completion of this function. + * Returns 0 on success, negative otherwise + */ +int mmc_cmdq_halt(struct mmc_host *host, bool halt) +{ + int err = 0; + + if ((halt && mmc_host_halt(host)) || + (!halt && !mmc_host_halt(host))) + return -EINVAL; + + if (host->cmdq_ops->halt) { + err = host->cmdq_ops->halt(host, halt); + if (!err && halt) + mmc_host_set_halt(host); + else if (!err && !halt) + mmc_host_clr_halt(host); + } else { + err = -ENOSYS; + } + + return err; +} +EXPORT_SYMBOL(mmc_cmdq_halt); + int mmc_cmdq_start_req(struct mmc_host *host, struct mmc_cmdq_req *cmdq_req) { struct mmc_request *mrq = &cmdq_req->mrq; diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h index 7b3a60c..92aa8cc 100644 --- a/include/linux/mmc/core.h +++ b/include/linux/mmc/core.h @@ -143,6 +143,7 @@ struct mmc_card; struct mmc_async_req; struct mmc_cmdq_req; +extern int mmc_cmdq_halt(struct mmc_host *host, bool enable); extern void mmc_cmdq_post_req(struct mmc_host *host, struct mmc_request *mrq, int err); extern int mmc_cmdq_start_req(struct mmc_host *host, diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 135a83e..f2fb79a 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -85,6 +85,7 @@ struct mmc_cmdq_host_ops { int (*request)(struct mmc_host *host, struct mmc_request *mrq); void (*post_req)(struct mmc_host *host, struct mmc_request *mrq, int err); + int (*halt)(struct mmc_host *host, bool halt); }; struct mmc_host_ops { @@ -216,6 +217,7 @@ struct mmc_cmdq_context_info { unsigned long curr_state; #define CMDQ_STATE_ERR 0 #define CMDQ_STATE_DCMD_ACTIVE 1 +#define CMDQ_STATE_HALT 2 /* no free tag available */ unsigned long req_starved; }; @@ -534,6 +536,21 @@ static inline int mmc_host_packed_wr(struct mmc_host *host) return host->caps2 & MMC_CAP2_PACKED_WR; } +static inline void mmc_host_set_halt(struct mmc_host *host) +{ + set_bit(CMDQ_STATE_HALT, &host->cmdq_ctx.curr_state); +} + +static inline void mmc_host_clr_halt(struct mmc_host *host) +{ + clear_bit(CMDQ_STATE_HALT, &host->cmdq_ctx.curr_state); +} + +static inline int mmc_host_halt(struct mmc_host *host) +{ + return test_bit(CMDQ_STATE_HALT, &host->cmdq_ctx.curr_state); +} + static inline int mmc_card_hs(struct mmc_card *card) { return card->host->ios.timing == MMC_TIMING_SD_HS ||