Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1289136pxb; Fri, 21 Jan 2022 14:28:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJzB5ZiPma0vQUIGx/uxAB1KjP+Cw3aemP4XJKUdeuiali54KPrJtJ3Luqc4zSBgN02W5q8b X-Received: by 2002:a63:34c4:: with SMTP id b187mr4354840pga.439.1642804105387; Fri, 21 Jan 2022 14:28:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642804105; cv=none; d=google.com; s=arc-20160816; b=bLwmearlSXSe1jC3+HAtxGh1c76G8X/1LflZ2e91aqLdH3qI7HJc0HZGcnmsdeo0VV okFpYuSmk5KNxLe3OlCcV9Tip+F/BvT5JmfAooirfwNGjpO2sZwFgL6yrZ2leRzjUtqQ XlYXakxFubFqxDXx7DF2ZE4HaooCQ0qu/OSUw4wAiTVCEn33/TtlQPhJ320CImBe4lyu vDH9F+hJUU4U095LVhFcxVysKxVrm8tZtZYZ/Ndk3tafDY+12GvfVmQGHQtwiTYuWUUs ifY0aFj+WP/qcPy6C1dCXd65gdiI/ayuUXXltXXGI4DgrwwHYQDD6AjvYw69aJhlmIBl M8qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=2FIjShg5baSboHk5Y596ymu0qrv2AoIjmxzwRiyXO74=; b=T2vb1u8q/RdsQrJcjNhA+NbZCYMWbMwgAA6xevAIltuKxAS2MOMsEUOSouzfnGYi6y 3Mivn2IOzhpA2EP5xXyZ0nTQyFQJSmfoCwjsmj8oae+Hjtwozy/+epwYjZuMAheM0TcF f0oc4So459MayEjCHSIcJwICZPafTZEEUysUB6/KTXiEU0Y76ViaDYZGxEWRhfjPRLSj WHmeGeaAo+LzvR4PZyQZ6yFBuivcgv/m9iUe2W+d3yRBlConIM5YoHX1Gq0PoqucBIbq b1+cRJ388FVDHSgk+hvAvBICCEgFG7CmWEBSpGkQrRRXsdzIQZvIfEKNHqUGxCMA6B61 0NQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=rVis5IPd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z14si7292715pgo.442.2022.01.21.14.28.12; Fri, 21 Jan 2022 14:28:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=rVis5IPd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230058AbiATR2U (ORCPT + 99 others); Thu, 20 Jan 2022 12:28:20 -0500 Received: from alexa-out.qualcomm.com ([129.46.98.28]:38887 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346833AbiATR05 (ORCPT ); Thu, 20 Jan 2022 12:26:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1642699617; x=1674235617; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=2FIjShg5baSboHk5Y596ymu0qrv2AoIjmxzwRiyXO74=; b=rVis5IPdzyu6Q5vtTGNkx5tHaYnyEjsFzv3OOV1co4BOYbAxK4bjLdIN aIPdfvx+OxVwJo0uHWyKc5SefJqVzCKWJhrrmvQxH4qWuK5NKGgBEilOQ +embhBIE2kFKhKJ2t0O1Te8xYBM9CX+6G7+MNkLNJhlFuR2qHAxlvh5S+ 0=; Received: from ironmsg-lv-alpha.qualcomm.com ([10.47.202.13]) by alexa-out.qualcomm.com with ESMTP; 20 Jan 2022 09:26:57 -0800 X-QCInternal: smtphost Received: from ironmsg01-blr.qualcomm.com ([10.86.208.130]) by ironmsg-lv-alpha.qualcomm.com with ESMTP/TLS/AES256-SHA; 20 Jan 2022 09:26:55 -0800 X-QCInternal: smtphost Received: from c-sbhanu-linux.qualcomm.com ([10.242.50.201]) by ironmsg01-blr.qualcomm.com with ESMTP; 20 Jan 2022 22:56:35 +0530 Received: by c-sbhanu-linux.qualcomm.com (Postfix, from userid 2344807) id 4EEE6538E; Thu, 20 Jan 2022 22:56:34 +0530 (IST) From: Shaik Sajida Bhanu To: adrian.hunter@intel.com, quic_asutoshd@quicinc.com, ulf.hansson@linaro.org, agross@kernel.org, bjorn.andersson@linaro.org, linux-mmc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stummala@codeaurora.org, vbadigan@codeaurora.org, quic_rampraka@quicinc.com, quic_pragalla@quicinc.com, sartgarg@codeaurora.org, nitirawa@codeaurora.org, sayalil@codeaurora.org, Shaik Sajida Bhanu , Liangliang Lu , "Bao D . Nguyen" Subject: [PATCH V3 2/4] mmc: debugfs: Add debug fs entry for mmc driver Date: Thu, 20 Jan 2022 22:56:20 +0530 Message-Id: <1642699582-14785-3-git-send-email-quic_c_sbhanu@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1642699582-14785-1-git-send-email-quic_c_sbhanu@quicinc.com> References: <1642699582-14785-1-git-send-email-quic_c_sbhanu@quicinc.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add debug fs entry to query eMMC and SD card errors statistics Signed-off-by: Shaik Sajida Bhanu Signed-off-by: Liangliang Lu Signed-off-by: Sayali Lokhande Signed-off-by: Bao D. Nguyen --- drivers/mmc/core/debugfs.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c index 3fdbc80..f4cb594 100644 --- a/drivers/mmc/core/debugfs.c +++ b/drivers/mmc/core/debugfs.c @@ -223,6 +223,82 @@ static int mmc_clock_opt_set(void *data, u64 val) DEFINE_DEBUGFS_ATTRIBUTE(mmc_clock_fops, mmc_clock_opt_get, mmc_clock_opt_set, "%llu\n"); +static int mmc_err_state_get(void *data, u64 *val) +{ + struct mmc_host *host = data; + + if (!host) + return -EINVAL; + + *val = host->err_state ? 1 : 0; + + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(mmc_err_state, mmc_err_state_get, NULL, "%llu\n"); + +static int mmc_err_stats_show(struct seq_file *file, void *data) +{ + struct mmc_host *host = (struct mmc_host *)file->private; + const char *desc[MMC_ERR_MAX] = { + [MMC_ERR_CMD_TIMEOUT] = "Command Timeout Occurred", + [MMC_ERR_CMD_CRC] = "Command CRC Errors Occurred", + [MMC_ERR_DAT_TIMEOUT] = "Data Timeout Occurred", + [MMC_ERR_DAT_CRC] = "Data CRC Errors Occurred", + [MMC_ERR_AUTO_CMD] = "Auto-Cmd Error Occurred", + [MMC_ERR_ADMA] = "ADMA Error Occurred", + [MMC_ERR_TUNING] = "Tuning Error Occurred", + [MMC_ERR_CMDQ_RED] = "CMDQ RED Errors", + [MMC_ERR_CMDQ_GCE] = "CMDQ GCE Errors", + [MMC_ERR_CMDQ_ICCE] = "CMDQ ICCE Errors", + [MMC_ERR_REQ_TIMEOUT] = "Request Timedout", + [MMC_ERR_CMDQ_REQ_TIMEOUT] = "CMDQ Request Timedout", + [MMC_ERR_ICE_CFG] = "ICE Config Errors", + }; + int i; + + if (!host) + return -EINVAL; + + if (!host->err_stats_enabled) { + seq_printf(file, "Not supported by driver\n"); + return 0; + } + + for (i = 0; i < MMC_ERR_MAX; i++) { + if (desc[i]) + seq_printf(file, "# %s:\t %d\n", + desc[i], host->err_stats[i]); + } + + return 0; +} + +static int mmc_err_stats_open(struct inode *inode, struct file *file) +{ + return single_open(file, mmc_err_stats_show, inode->i_private); +} + +static ssize_t mmc_err_stats_write(struct file *filp, const char __user *ubuf, + size_t cnt, loff_t *ppos) +{ + struct mmc_host *host = filp->f_mapping->host->i_private; + + if (!host) + return -EINVAL; + + pr_debug("%s: Resetting MMC error statistics\n", __func__); + memset(host->err_stats, 0, sizeof(host->err_stats)); + + return cnt; +} + +static const struct file_operations mmc_err_stats_fops = { + .open = mmc_err_stats_open, + .read = seq_read, + .write = mmc_err_stats_write, +}; + void mmc_add_host_debugfs(struct mmc_host *host) { struct dentry *root; @@ -236,6 +312,11 @@ void mmc_add_host_debugfs(struct mmc_host *host) debugfs_create_file_unsafe("clock", S_IRUSR | S_IWUSR, root, host, &mmc_clock_fops); + debugfs_create_file("err_state", 0600, root, host, + &mmc_err_state); + debugfs_create_file("err_stats", 0600, root, host, + &mmc_err_stats_fops); + #ifdef CONFIG_FAIL_MMC_REQUEST if (fail_request) setup_fault_attr(&fail_default_attr, fail_request); -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation