From patchwork Thu Jun 8 08:54:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 103352 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp2337053qgd; Thu, 8 Jun 2017 01:54:32 -0700 (PDT) X-Received: by 10.99.111.79 with SMTP id k76mr36928137pgc.200.1496912072094; Thu, 08 Jun 2017 01:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496912072; cv=none; d=google.com; s=arc-20160816; b=zUP46GiTCCfRSbevjM3z+/OsVz5v+ged/zHz9wVEZNMhz93qxq9ZDlvy5cBHzi55s9 AYy1+f5QgzjxgueUgok7+lxJyO3c8Ehap339PxogGT2NFHWipeDU1AbeTFBoskirHQrH Iv2Gzoo8eewJYBET5XSo/qYcuIqEcugCECk7lvWLrEu2UUPuM6o0Z/8aZ3veXsxh8eYH 05pLRWvUsQCYBPvWtwu1pnbcvSe2MIS8UAnpi/MwmnZMNAuj2koH9OJAXEBniDH3lBsF /Fy7ARlWbjnpuOoLlVEIfZX464E7WfHZDtWu9AR6jAcRzFaBkvAwuWm2CwDSNGKWYgZ/ SwJQ== 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=gjCGPF2LnKz1vtMKgbQBizjdW6J3uZD/DChcdIeq4vM=; b=Nq++D8y7aQPF9BakU6Mj0JegqEAh0fnGcAWyIuR5DDHcqUDSpY7XADqPr8d/NxayBC yHT7T+xAQCP0C7yhdN2p3yFa1DgSeF5gUqqxmYgH+W4lycY4ky+l5DRXLAJo7aY2wr1L 5J9nO3QNIFEkkHJpB5MGMIJh61AjCE2FKm+F6icvbgXfqvuYsU2oevKeipmWtC7GjBie XUUsmVVuWxFTgKKB8HZmeVJp6DH8zKk0t6ehjEo9VeNX0L+xHlEN34pfUZrnHpB3LxwR 7pWZXo1zOj/ZxJYc9aaCIyjv172UF29e9gWYmwjirgch0IsLWh1MeSTjlTMAHqg57L0F M4rQ== 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 x196si4121624pgx.147.2017.06.08.01.54.31; Thu, 08 Jun 2017 01:54:32 -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 S1751864AbdFHIyb (ORCPT + 6 others); Thu, 8 Jun 2017 04:54:31 -0400 Received: from mail-lf0-f50.google.com ([209.85.215.50]:33850 "EHLO mail-lf0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751850AbdFHIya (ORCPT ); Thu, 8 Jun 2017 04:54:30 -0400 Received: by mail-lf0-f50.google.com with SMTP id v20so15274532lfa.1 for ; Thu, 08 Jun 2017 01:54:29 -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=dGWf9FIOKNCsYSGBOSsUxkq0GcwU+G9uzKiEhgXclf4=; b=VCnsZh504TvjPMB23LNXxRi2z/vczNTkA2gf09DLgxy/BVca9cL8nHil96fcalt/ye 5mlBbotMlmGlnrivBojtTx+QWXss7M8UsSgy+T+f8GlVovD+rBoYYEQcsvCrWtKqyejH MF300Hx91mBBentQDEc7fAWb3jhBwAvRJsbKs= 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=dGWf9FIOKNCsYSGBOSsUxkq0GcwU+G9uzKiEhgXclf4=; b=ScFsirQEMCpU5VyKG2C6WAKVhsRi9sdA92o/ly8WlS8PJG17noWC/JV8d7c7FIz7Pz VlqCGdOeIan5m/ZLXJEEA96GAikg94z43uJkHhdENkD+hS+1pEb7jfnpPRzIn3su1Rls gV4uDKIHlOTP8A9sQk8jG1QrSTbquq/gZQZC+Znp/71YJQ/PIqPuPe+KQo1BIvb7duEv 0PjN6Ci/NytdSlSxwdgmODawaIL+kLVnKzJzAnMzoumWQ16EsETWhVuvBUAh9KwMjNQx 9NB+ptiVd0pMFuecfy3sYLF+glZPYgRhit6Y6J+2s5/1gvLO9k/K39Vlb8h4MoT00+eL rMlg== X-Gm-Message-State: AODbwcBl6nNF4XtNirZYHxqeu+5Hqb2JAr1tgNvyNCBi3IO2rYInwoVe AYe/Vx4ZUCPPjByP0DxUoQ== X-Received: by 10.25.161.200 with SMTP id k191mr3783177lfe.40.1496912068357; Thu, 08 Jun 2017 01:54:28 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id n71sm878356lje.14.2017.06.08.01.54.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Jun 2017 01:54:27 -0700 (PDT) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij Subject: [PATCH 6/6 v3] mmc: debugfs: Move block debugfs into block module Date: Thu, 8 Jun 2017 10:54:03 +0200 Message-Id: <20170608085403.11795-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170608085403.11795-1-linus.walleij@linaro.org> References: <20170608085403.11795-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 if #IS_ENABLED() clauses inside the debugfs code isn't very nice. And alternative is to move the block layer debugfs file handling into the block module, so they live and die with the block initialization of the card. This makes the code smaller since we do not need cross-calls between debugfs.c and block.c. On the other hand it moves some debugfs code from debugfs.c and into block.c. So both approaches have their merits. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - New patch after discussion with Ulf, numbering v3 to keep the series together. Ulf: I leave it to you to decide if you prefer to centralize debugfs code in debugfs.c or to localize the block debugfs code inside block.c. --- drivers/mmc/core/block.c | 170 +++++++++++++++++++++++++++++++++++---------- drivers/mmc/core/block.h | 2 - drivers/mmc/core/debugfs.c | 96 ------------------------- 3 files changed, 132 insertions(+), 136 deletions(-) -- 2.9.4 -- 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 4708f95ebdd0..1ce6012ce3c1 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -1965,44 +1966,6 @@ 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); - -/* Called from debugfs for MMC cards */ -int mmc_blk_get_ext_csd(struct mmc_card *card, u8 **ext_csd) -{ - struct mmc_blk_data *md = dev_get_drvdata(&card->dev); - struct mmc_queue *mq = &md->queue; - struct request *req; - - /* Ask the block layer about 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); - return req_to_mmc_queue_req(req)->drv_op_result; -} -EXPORT_SYMBOL(mmc_blk_get_ext_csd); - static inline int mmc_blk_readonly(struct mmc_card *card) { return mmc_card_readonly(card) || @@ -2275,6 +2238,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; @@ -2311,6 +2402,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/block.h b/drivers/mmc/core/block.h index 377ebbf6a978..860ca7c8df86 100644 --- a/drivers/mmc/core/block.h +++ b/drivers/mmc/core/block.h @@ -5,7 +5,5 @@ struct mmc_queue; struct request; void mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req); -int mmc_blk_card_status_get(struct mmc_card *card, u64 *val); -int mmc_blk_get_ext_csd(struct mmc_card *card, u8 **ext_csd); #endif diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c index cc1f7085111c..8583c2dc879e 100644 --- a/drivers/mmc/core/debugfs.c +++ b/drivers/mmc/core/debugfs.c @@ -282,99 +282,6 @@ void mmc_remove_host_debugfs(struct mmc_host *host) debugfs_remove_recursive(host->debugfs_root); } -#if IS_ENABLED(CONFIG_MMC_BLOCK) - -static int mmc_dbg_card_status_get(void *data, u64 *val) -{ - return mmc_blk_card_status_get(data, val); -} -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; - - err = mmc_blk_get_ext_csd(card, &ext_csd); - 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, -}; - -static int mmc_add_block_debugfs(struct mmc_card *card, struct dentry *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 /* !IS_ENABLED(CONFIG_MMC_BLOCK) */ - -static int mmc_add_block_debugfs(struct mmc_card *card, struct dentry *root) -{ - return 0; -} - -#endif - void mmc_add_card_debugfs(struct mmc_card *card) { struct mmc_host *host = card->host; @@ -397,9 +304,6 @@ void mmc_add_card_debugfs(struct mmc_card *card) if (!debugfs_create_x32("state", S_IRUSR, root, &card->state)) goto err; - if (mmc_add_block_debugfs(card, root)) - goto err; - return; err: