From patchwork Fri May 19 13:37:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 100195 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp319269qge; Fri, 19 May 2017 06:38:06 -0700 (PDT) X-Received: by 10.98.34.22 with SMTP id i22mr10800381pfi.103.1495201086481; Fri, 19 May 2017 06:38:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495201086; cv=none; d=google.com; s=arc-20160816; b=sdIRmn290xFfa4gCn5oRWAgjoMj2UCIrN+Rem7Q3Mk0tKJ5EIZF7+Wwg/TMnXTtuqY UTUfkuX+rw63y4a7FOEP0LDmD9NvmQvgLUIXv0QeGXcoUTiLkfUCyslthJ5jiYKjc1zR ALi66yFcEzUv9UXJf7X41mzGJMjlJ+uISAyeXYM3nPBdIIKcj4MXm+/wYTaewR9zlmza 30Mjm1OB+l+57lLWQHTL3FX1q/49v22y4IWrvvr/Qc1rCOtiV+exrxGGlSP/CHMH1sKl 9WrGz1/bSpX/zyNF+Nq58tVAnbZWmsNhWirzaZeoHeuGvwMiJ3H5i2ajO9CgMKoh6W/2 wDsw== 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:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=i4DvHYo9Ajx4kXSYhAzSvGA/pefR8XwnP0iruElyMLQ=; b=0qFizd3hZgQt+idICewmv2kNedcuOuSox68z4zhOp9ypKwK46p9vFU4Nj+7YJ2hKHi LNrgvOhbN9ot/hvaHGvYMkrv92nU12LVq4WpTlSrfOMApENtzlmusdyr8cSZ1OnY0yMh tXfb3pRbPF59zJY1DwcsXBAKzypDwLKw7qWI3rl88dAJXThjeTkefhayTVCGtjWKyFnq Ul3eEzWPPOkZmX95AkTDSNF2WOFbodi7q5Jh2HA/3zWpwz2EQ6IH8zTw7esjcDoX8YNi HF9zbHA6YX6qcsDO91ZBtr16cZZTp3sn7GqQscBLdgHlMqgbkbr0yZrcBJbtzIB/uOi5 ANBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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=fail (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 33si8689720plb.270.2017.05.19.06.38.06; Fri, 19 May 2017 06:38:06 -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=neutral (body hash did not verify) header.i=@linaro.org; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755321AbdESNiF (ORCPT + 6 others); Fri, 19 May 2017 09:38:05 -0400 Received: from mail-lf0-f43.google.com ([209.85.215.43]:36565 "EHLO mail-lf0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755276AbdESNiE (ORCPT ); Fri, 19 May 2017 09:38:04 -0400 Received: by mail-lf0-f43.google.com with SMTP id h4so1210801lfj.3 for ; Fri, 19 May 2017 06:38:03 -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; bh=fmEucGws7S1v0M3gh8izDsrTv5jnZLx7diAoviYtzBw=; b=WemFlcU+GU8g6z5jFApdOQmNlgBEnADgczf0FjwmoU67Rfke87TTsvbl23ZCNzUkDg TUrJSOtzqYK/0E87kflCBzs5qSq4KV7Jns2eLbSu0pSGxXoSvp++Txh9jPr+T76+OtTV D7TRTBODJ3vlrsx4W4koawSeVMqQET0IcBJIU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fmEucGws7S1v0M3gh8izDsrTv5jnZLx7diAoviYtzBw=; b=qKdZBV5ALiRMliwziTThSK/Wt96qKlKppdtKU9RQAc9XeiVMlrL7KZGYBeZ7x6ZYU5 DJllgKyAedd8S1hpliRhaaLMdMEyjapP0P3oLG9CezahIE5BDvClAR/TTHtEpg58XYoB Vbkg8uq/mLrjvyWQqgjdJ9B79qqdax5NOdwSbwkj0TX19d7grRKFOeBW5rY/gZcKNTmU pHgFILk4vCt2yDz3RihgrRDed/53WWIVrJ+xVsRSRRRC3G6WJfoYbEm7u+KyT8qlbPQs t9fmnMDoTXh6cUaTF+kK4xv2CB8ej9a6nzctSYsB8/4yJ8WkaNtpyqUQfnX2sdZaAhV5 FN2w== X-Gm-Message-State: AODbwcDhdVhjw2NlzU6eNTumGUqfAFliJsjcoH+se+2EyOb4nXuZ4Ai2 Nf5XlmrYg+vD2jzk X-Received: by 10.25.40.81 with SMTP id o78mr2119915lfo.157.1495201082377; Fri, 19 May 2017 06:38:02 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id 19sm1514130ljf.32.2017.05.19.06.38.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 May 2017 06:38:01 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Paolo Valente , Avri Altman , Linus Walleij Subject: [PATCH 5/6] mmc: debugfs: Move card status retrieveal into the block layer Date: Fri, 19 May 2017 15:37:31 +0200 Message-Id: <20170519133732.27470-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170519133732.27470-1-linus.walleij@linaro.org> References: <20170519133732.27470-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The debugfs file "status" (in e.g. /debug/mmc3/mmc3:0001) is only available if and only if the card used is an (e)MMC or SD card, not for SDIO, as can be seen from this guard in mmc_add_card_debugfs(); if (mmc_card_mmc(card) || mmc_card_sd(card)) (...create debugfs "status" entry...) Further this debugfs entry suffers from all the same starvation issues as the other userspace things, under e.g. a heavy dd operation. It is therefore logical to move this over to the block layer when it is enabled, using the new custom requests and issue it using the block request queue. This makes this debugfs card access land under the request queue host lock instead of orthogonally taking the lock. Tested during heavy dd load by cat:in the status file. We add IS_ENABLED() guards and keep the code snippet just issueing the card status as a static inline in the header so we can still have card status working when the block layer is compiled out. Keeping two copies of mmc_dbg_card_status_get() around seems to be a necessary evil to be able to have the MMC/SD stack working with the block layer disabled: under these circumstances, the code must simply take another path. Signed-off-by: Linus Walleij --- drivers/mmc/core/block.c | 28 ++++++++++++++++++++++++++++ drivers/mmc/core/block.h | 37 +++++++++++++++++++++++++++++++++++++ drivers/mmc/core/debugfs.c | 15 ++------------- drivers/mmc/core/queue.h | 2 ++ 4 files changed, 69 insertions(+), 13 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 52635120a0a5..8858798d1349 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1191,6 +1191,7 @@ static void mmc_blk_issue_drv_op(struct mmc_queue *mq, struct request *req) struct mmc_queue_req *mq_rq; struct mmc_card *card = mq->card; struct mmc_blk_data *md = mq->blkdata; + u32 status; int ret; int i; @@ -1219,6 +1220,11 @@ static void mmc_blk_issue_drv_op(struct mmc_queue *mq, struct request *req) card->ext_csd.boot_ro_lock |= EXT_CSD_BOOT_WP_B_PWR_WP_EN; break; + case MMC_DRV_OP_GET_CARD_STATUS: + ret = mmc_send_status(card, &status); + if (!ret) + ret = status; + break; default: pr_err("%s: unknown driver specific operation\n", md->disk->disk_name); @@ -1968,6 +1974,28 @@ void mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) mmc_put_card(card); } +/* Called from debugfs for MMC/SD cards */ +int mmc_blk_card_status_get(struct mmc_card *card, u64 *val) +{ + struct mmc_blk_data *md = dev_get_drvdata(&card->dev); + struct mmc_queue *mq = &md->queue; + struct request *req; + int ret; + + /* Ask the block layer about the card status */ + req = blk_get_request(mq->queue, REQ_OP_DRV_IN, __GFP_RECLAIM); + req_to_mmc_queue_req(req)->drv_op = MMC_DRV_OP_GET_CARD_STATUS; + blk_execute_rq(mq->queue, NULL, req, 0); + ret = req_to_mmc_queue_req(req)->drv_op_result; + if (ret >= 0) { + *val = ret; + ret = 0; + } + + return ret; +} +EXPORT_SYMBOL(mmc_blk_card_status_get); + static inline int mmc_blk_readonly(struct mmc_card *card) { return mmc_card_readonly(card) || diff --git a/drivers/mmc/core/block.h b/drivers/mmc/core/block.h index 860ca7c8df86..1e26755a864b 100644 --- a/drivers/mmc/core/block.h +++ b/drivers/mmc/core/block.h @@ -1,9 +1,46 @@ #ifndef _MMC_CORE_BLOCK_H #define _MMC_CORE_BLOCK_H +#include +#include "core.h" +#include "mmc_ops.h" + struct mmc_queue; struct request; +#if IS_ENABLED(CONFIG_MMC_BLOCK) + void mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req); +int mmc_blk_card_status_get(struct mmc_card *card, u64 *val); + +#else + +/* + * Small stub functions to be used when the block layer is not + * enabled, e.g. for pure SDIO without MMC/SD configurations. + */ + +static inline void mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) +{ + return; +} + +static inline int mmc_blk_card_status_get(struct mmc_card *card, u64 *val) +{ + u32 status; + int ret; + + mmc_get_card(card); + + ret = mmc_send_status(card, &status); + if (!ret) + *val = status; + + mmc_put_card(card); + + return ret; +} + +#endif /* IS_ENABLED(CONFIG_MMC_BLOCK) */ #endif diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c index a1fba5732d66..ce5b921c7d96 100644 --- a/drivers/mmc/core/debugfs.c +++ b/drivers/mmc/core/debugfs.c @@ -19,6 +19,7 @@ #include #include +#include "block.h" #include "core.h" #include "card.h" #include "host.h" @@ -283,19 +284,7 @@ void mmc_remove_host_debugfs(struct mmc_host *host) static int mmc_dbg_card_status_get(void *data, u64 *val) { - struct mmc_card *card = data; - u32 status; - int ret; - - mmc_get_card(card); - - ret = mmc_send_status(data, &status); - if (!ret) - *val = status; - - mmc_put_card(card); - - return ret; + return mmc_blk_card_status_get(data, val); } DEFINE_SIMPLE_ATTRIBUTE(mmc_dbg_card_status_fops, mmc_dbg_card_status_get, NULL, "%08llx\n"); diff --git a/drivers/mmc/core/queue.h b/drivers/mmc/core/queue.h index 361b46408e0f..2b39717453a5 100644 --- a/drivers/mmc/core/queue.h +++ b/drivers/mmc/core/queue.h @@ -36,10 +36,12 @@ struct mmc_blk_request { * enum mmc_drv_op - enumerates the operations in the mmc_queue_req * @MMC_DRV_OP_IOCTL: ioctl operation * @MMC_DRV_OP_BOOT_WP: write protect boot partitions + * @MMC_DRV_OP_GET_CARD_STATUS: get card status */ enum mmc_drv_op { MMC_DRV_OP_IOCTL, MMC_DRV_OP_BOOT_WP, + MMC_DRV_OP_GET_CARD_STATUS, }; struct mmc_queue_req {