From patchwork Sun Aug 20 21:39:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 110486 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp521438qge; Sun, 20 Aug 2017 14:39:30 -0700 (PDT) X-Received: by 10.98.49.67 with SMTP id x64mr15381964pfx.22.1503265170136; Sun, 20 Aug 2017 14:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503265170; cv=none; d=google.com; s=arc-20160816; b=zIB1aHATmQJ9zTVlgmT6dxOTva+iwZ1d5FSdBq7Xfpc1DxXQg4qB4DPk/u3xgEPnq2 XWTd49UPjujB4WngwRTTeHzsoZbWdysKJlWV66AQl5Nxm8mUiOPglgaexU0Gsv/8mwzX S7/ofe5chUaAul1P9qlxaxl2JwMy4eP3KBH5ghCBdYtKbCrXgEUmKRf8k7iU88AgfMUr Z9xIIjLoaYEwm4uF6Q58lv5NC/DrFr/vEhPqSHXfwUkYOcMTz7NBmF/aA60Ptmq2u92B ruJDe9ObqfwTv9Gl4T+vJYTYiHTf5qy+ycFsr7jqw9oa573eCHK7k2otE8EUZcBpZoRQ GZzw== 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=vOTlB4T2EkZu/aWkC96cEnbdb8Phd0Ib2Y7crqicML0=; b=YglY1JJvLsM+yKrR4DhIH7ozfPszkK1X84IWVI13Ozu0Ebn7PXIsyUj+M9PzLkgKWp FuIkNwxmwxPDSsIqMegO1UleSOzrhVILV6iWcrXjweCcRDwfFplTLKdyIGSr9NXPTca9 X6qo5GU+QHW5hQ0PNStR3Ab2zi2NvjumVLvNHnVSX9CO0cFA7vKz4SaT8xSt8U8r4Rc0 1gc4CnhdreKsiib6AJ1dtw5QYT4DU2TRmXJqgP0YH4eblMrapNsGz2U1w1ln63UiAFJn XnjVOmtQTGPBXfJt7s/pmyEkkyAILWeh1fpIFjBrGnm+bMRTUhp9GH+lWhZNzGwGwqhf iKlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bC52Tyd1; 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 z1si3544613pgn.611.2017.08.20.14.39.29; Sun, 20 Aug 2017 14:39: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=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bC52Tyd1; 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 S1753355AbdHTVj3 (ORCPT + 6 others); Sun, 20 Aug 2017 17:39:29 -0400 Received: from mail-lf0-f54.google.com ([209.85.215.54]:32976 "EHLO mail-lf0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753300AbdHTVj2 (ORCPT ); Sun, 20 Aug 2017 17:39:28 -0400 Received: by mail-lf0-f54.google.com with SMTP id d17so59771964lfe.0 for ; Sun, 20 Aug 2017 14:39:27 -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=a5TiBTxB31mcjIpLD6mI0Dtu9wwRix1AEhRHkD8loEg=; b=bC52Tyd1300Dotu0zjDrrgrfkLZg0dVMYTi5GR2IPRc4l3RTS1H2sPAY/Eu6RDSbJH YXvQXxvD6d5+Jo8BvhGIp+raFIK3fYMtJo9A1S1IT/mHMZkNZ2zE8u/5BvO+iW4kGHoc g2OywAgKs9evVYB25fvixKWyq5M17mUJPjJYg= 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=a5TiBTxB31mcjIpLD6mI0Dtu9wwRix1AEhRHkD8loEg=; b=T3AjGZbf4smjZ9gLrrm3Z6j2AarkplfqqgDqksk21CFzbk7qID6aPMoQwIOuzKhR8o kXvWuSBpolIgGH38Gem4MwLjzQHSnqWxa20UVpKojPy3KcJr/shWae+ZyKEcY4XNs9ZL yFyj0CcvW6aE+GQivrfq2VNwA697ysCXfMWZZehzJbVdPWWXK3X3lTmmSwLVP8tzschn DpsRf8zGie4bA8VpiFVWv5oFu030VCL85I099lojwndmI5XQmUNOvuFzORl22p7uBNue 5ceezwCMKdkzSZUBbzA24co8GG8TcUNmB2nE0/iRMqqO/7OkwkpH+0ZXk8ICxnFnlcIW aQyA== X-Gm-Message-State: AHYfb5gvBoZAKPvM5Fcp7e7IEt7QfvzF9pJEs7a7o7WQxwSfwByfsUT6 GgHzwjdRfhmYz6mfUdQFCg== X-Received: by 10.25.22.104 with SMTP id m101mr2580447lfi.104.1503265166417; Sun, 20 Aug 2017 14:39:26 -0700 (PDT) Received: from genomnajs.bredbandsbolaget.se (c-097b71d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.123.9]) by smtp.gmail.com with ESMTPSA id f136sm2381830lff.34.2017.08.20.14.39.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Aug 2017 14:39:25 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Linus Walleij Subject: [PATCH 3/8 v5] mmc: debugfs: Move block debugfs into block module Date: Sun, 20 Aug 2017 23:39:08 +0200 Message-Id: <20170820213913.9737-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170820213913.9737-1-linus.walleij@linaro.org> References: <20170820213913.9737-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org If we don't have the block layer enabled, we do not present card status and extcsd in the debugfs. Debugfs is not ABI, and maintaining files of no relevance for non-block devices comes at a high maintenance cost if we shall support it with the block layer compiled out. The debugfs entries suffer from all the same starvation issues as the other userspace things, under e.g. a heavy dd operation. The expected number of debugfs users utilizing these two debugfs files is already low as there is an ioctl() to get the same information using the mmc-tools, and of these few users the expected number of people using it on SDIO or combo cards are expected to be zero. 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. On the other hand it moves some debugfs code from debugfs.c and into block.c. Tested during heavy dd load by cat:in the status file. Signed-off-by: Linus Walleij --- ChangeLog v4->v5: - Rebased, resending ChangeLog v3->v4: - Squash all the refactorings of these operations into a big commit simply moving all the debugfs over to the block layer and only creating the files from there. - Avoid the whole middle-step of creating #if IS_ENABLED() that was required to move it stepwise from the debugfs file to the block file. --- drivers/mmc/core/block.c | 143 +++++++++++++++++++++++++++++++++++++++++++++ drivers/mmc/core/debugfs.c | 89 ---------------------------- drivers/mmc/core/queue.h | 4 ++ 3 files changed, 147 insertions(+), 89 deletions(-) -- 2.13.5 -- 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 30b8b979ea62..6c91e125ab72 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -1177,6 +1178,8 @@ static void mmc_blk_issue_drv_op(struct mmc_queue *mq, struct request *req) struct mmc_card *card = mq->card; struct mmc_blk_data *md = mq->blkdata; struct mmc_blk_ioc_data **idata; + u8 **ext_csd; + u32 status; int ret; int i; @@ -1206,6 +1209,15 @@ 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; + case MMC_DRV_OP_GET_EXT_CSD: + ext_csd = mq_rq->drv_op_data; + ret = mmc_get_ext_csd(card, ext_csd); + break; default: pr_err("%s: unknown driver specific operation\n", md->disk->disk_name); @@ -2246,6 +2258,134 @@ static int mmc_add_disk(struct mmc_blk_data *md) return ret; } +#ifdef CONFIG_DEBUG_FS + +static int mmc_dbg_card_status_get(void *data, u64 *val) +{ + struct mmc_card *card = data; + 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; +} +DEFINE_SIMPLE_ATTRIBUTE(mmc_dbg_card_status_fops, mmc_dbg_card_status_get, + NULL, "%08llx\n"); + +/* That is two digits * 512 + 1 for newline */ +#define EXT_CSD_STR_LEN 1025 + +static int mmc_ext_csd_open(struct inode *inode, struct file *filp) +{ + struct mmc_card *card = inode->i_private; + struct mmc_blk_data *md = dev_get_drvdata(&card->dev); + struct mmc_queue *mq = &md->queue; + struct request *req; + char *buf; + ssize_t n = 0; + u8 *ext_csd; + int err, i; + + buf = kmalloc(EXT_CSD_STR_LEN + 1, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + /* Ask the block layer for the EXT CSD */ + req = blk_get_request(mq->queue, REQ_OP_DRV_IN, __GFP_RECLAIM); + req_to_mmc_queue_req(req)->drv_op = MMC_DRV_OP_GET_EXT_CSD; + req_to_mmc_queue_req(req)->drv_op_data = &ext_csd; + blk_execute_rq(mq->queue, NULL, req, 0); + err = req_to_mmc_queue_req(req)->drv_op_result; + if (err) { + pr_err("FAILED %d\n", err); + goto out_free; + } + + for (i = 0; i < 512; i++) + n += sprintf(buf + n, "%02x", ext_csd[i]); + n += sprintf(buf + n, "\n"); + + if (n != EXT_CSD_STR_LEN) { + err = -EINVAL; + goto out_free; + } + + filp->private_data = buf; + kfree(ext_csd); + return 0; + +out_free: + kfree(buf); + return err; +} + +static ssize_t mmc_ext_csd_read(struct file *filp, char __user *ubuf, + size_t cnt, loff_t *ppos) +{ + char *buf = filp->private_data; + + return simple_read_from_buffer(ubuf, cnt, ppos, + buf, EXT_CSD_STR_LEN); +} + +static int mmc_ext_csd_release(struct inode *inode, struct file *file) +{ + kfree(file->private_data); + return 0; +} + +static const struct file_operations mmc_dbg_ext_csd_fops = { + .open = mmc_ext_csd_open, + .read = mmc_ext_csd_read, + .release = mmc_ext_csd_release, + .llseek = default_llseek, +}; + +static int mmc_blk_add_debugfs(struct mmc_card *card) +{ + struct dentry *root; + + if (!card->debugfs_root) + return 0; + + root = card->debugfs_root; + + if (mmc_card_mmc(card) || mmc_card_sd(card)) { + if (!debugfs_create_file("status", S_IRUSR, root, card, + &mmc_dbg_card_status_fops)) + return -EIO; + } + + if (mmc_card_mmc(card)) { + if (!debugfs_create_file("ext_csd", S_IRUSR, root, card, + &mmc_dbg_ext_csd_fops)) + return -EIO; + } + + return 0; +} + + +#else + +static int mmc_blk_add_debugfs(struct mmc_card *card) +{ + return 0; +} + +#endif /* CONFIG_DEBUG_FS */ + static int mmc_blk_probe(struct mmc_card *card) { struct mmc_blk_data *md, *part_md; @@ -2282,6 +2422,9 @@ static int mmc_blk_probe(struct mmc_card *card) goto out; } + /* Add two debugfs entries */ + mmc_blk_add_debugfs(card); + pm_runtime_set_autosuspend_delay(&card->dev, 3000); pm_runtime_use_autosuspend(&card->dev); diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c index a1fba5732d66..01e459a34f33 100644 --- a/drivers/mmc/core/debugfs.c +++ b/drivers/mmc/core/debugfs.c @@ -281,85 +281,6 @@ void mmc_remove_host_debugfs(struct mmc_host *host) debugfs_remove_recursive(host->debugfs_root); } -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; -} -DEFINE_SIMPLE_ATTRIBUTE(mmc_dbg_card_status_fops, mmc_dbg_card_status_get, - NULL, "%08llx\n"); - -#define EXT_CSD_STR_LEN 1025 - -static int mmc_ext_csd_open(struct inode *inode, struct file *filp) -{ - struct mmc_card *card = inode->i_private; - char *buf; - ssize_t n = 0; - u8 *ext_csd; - int err, i; - - buf = kmalloc(EXT_CSD_STR_LEN + 1, GFP_KERNEL); - if (!buf) - return -ENOMEM; - - mmc_get_card(card); - err = mmc_get_ext_csd(card, &ext_csd); - mmc_put_card(card); - if (err) - goto out_free; - - for (i = 0; i < 512; i++) - n += sprintf(buf + n, "%02x", ext_csd[i]); - n += sprintf(buf + n, "\n"); - - if (n != EXT_CSD_STR_LEN) { - err = -EINVAL; - goto out_free; - } - - filp->private_data = buf; - kfree(ext_csd); - return 0; - -out_free: - kfree(buf); - return err; -} - -static ssize_t mmc_ext_csd_read(struct file *filp, char __user *ubuf, - size_t cnt, loff_t *ppos) -{ - char *buf = filp->private_data; - - return simple_read_from_buffer(ubuf, cnt, ppos, - buf, EXT_CSD_STR_LEN); -} - -static int mmc_ext_csd_release(struct inode *inode, struct file *file) -{ - kfree(file->private_data); - return 0; -} - -static const struct file_operations mmc_dbg_ext_csd_fops = { - .open = mmc_ext_csd_open, - .read = mmc_ext_csd_read, - .release = mmc_ext_csd_release, - .llseek = default_llseek, -}; - void mmc_add_card_debugfs(struct mmc_card *card) { struct mmc_host *host = card->host; @@ -382,16 +303,6 @@ void mmc_add_card_debugfs(struct mmc_card *card) if (!debugfs_create_x32("state", S_IRUSR, root, &card->state)) goto err; - if (mmc_card_mmc(card) || mmc_card_sd(card)) - if (!debugfs_create_file("status", S_IRUSR, root, card, - &mmc_dbg_card_status_fops)) - goto err; - - if (mmc_card_mmc(card)) - if (!debugfs_create_file("ext_csd", S_IRUSR, root, card, - &mmc_dbg_ext_csd_fops)) - goto err; - return; err: diff --git a/drivers/mmc/core/queue.h b/drivers/mmc/core/queue.h index cf26a15a64bf..04fc89360a7a 100644 --- a/drivers/mmc/core/queue.h +++ b/drivers/mmc/core/queue.h @@ -36,10 +36,14 @@ 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 + * @MMC_DRV_OP_GET_EXT_CSD: get the EXT CSD from an eMMC card */ enum mmc_drv_op { MMC_DRV_OP_IOCTL, MMC_DRV_OP_BOOT_WP, + MMC_DRV_OP_GET_CARD_STATUS, + MMC_DRV_OP_GET_EXT_CSD, }; struct mmc_queue_req {