All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V6 0/5] mmc: add error statistics for eMMC and SD card
@ 2022-05-18  7:02 Shaik Sajida Bhanu
  2022-05-18  7:02 ` [PATCH V6 1/5] mmc: core: Capture eMMC and SD card errors Shaik Sajida Bhanu
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Shaik Sajida Bhanu @ 2022-05-18  7:02 UTC (permalink / raw)
  To: adrian.hunter, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Rajeshwari Ravindra Kamble

From: Rajeshwari Ravindra Kamble <c_rkambl@qti.qualcomm.com>

Changes since V5:
	- Considered all error stats enums to set error state.
	- Added missed tuning error related code changes which was
	  missed in patch set V5 as Adrain Hunter pointed.
	- Replaced DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE
	  as suggested by Adrain Hunter.
	  
Changes since V4:
	- Defined new macro to increment err_stats members when error occured
	  as suggested by Adrain Hunter.
	- Called err_stats members increment function after printing the error
	  as suggested by Adrain Hunter.
	- Considered INDEX and END_BIT errors same as CRC errors as suggested
	  by Adrain Hunter.
	- Removed Null check for host in debug fs functions and Reordered
	  err_stats declarationas suggested by Adrain Hunter.
	- Removed err_state variable stuff and updated err_state debug fs entry
	  based on the err_stats members state as suggested by Adrain Hunter.

Changes since V3:
	- Dropped error stats feature flag as suggested by Adrain Hunter.
	- Separated error state related changes in separate patches as
	  suggested by Adrain Hunter.
	  [PATCH V4 4/7] : error state debug fs
	  [PATCH V4 5/7] : error state enable function
	  [PATCH V4 6/7] : error state enable in error case
	- Note: we are enabling error state before calling sdhci_dumpregs
	  we couldn't add the err state in error stats array as err state
	  is not error type.
	- Corrected Signed-off-by order as suggested by Bjron Andersson.
	- Moved error state enable code from sdhci_dumpregs to error
	  conditions as suggested by Adrain Hunter

Changes since V2:
	- Removed userspace error stats clear debug fs entry as suggested
	  by Adrain Hunter.
	- Split patch into 4 patches
	  [PATCH V3 1/4] : sdhci driver
	  [PATCH V3 2/4] : debug fs entries
	  [PATCH V3 3/4] : core driver
	  [PATCH V3 4/4] : cqhci driver
	- Used for loop to print error messages instead of using printf
	  statements for all error messages as suggested by Adrain Hunter.
	- Introduced one flag to enable error stats feature, if any other
	  client wants to use this feature, they need to enable that flag.
	- Moved reset command timeout error statement to card init flow
	  as suggested by Adrain Hunter.

Changes since V1:
	- Removed sysfs entry for eMMC and SD card error statistics and added
	  debugfs entry as suggested by Adrian Hunter and Ulf Hansson.

Shaik Sajida Bhanu (5):
  mmc: core: Capture eMMC and SD card errors
  mmc: sdhci: Capture eMMC and SD card errors
  mmc: debugfs: Add debug fs entry for mmc driver
  mmc: debugfs: Add debug fs error state entry for mmc driver
  mmc: cqhci: Capture eMMC and SD card errors

 drivers/mmc/core/core.c       | 10 +++++-
 drivers/mmc/core/debugfs.c    | 79 +++++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/host/cqhci-core.c |  9 ++++-
 drivers/mmc/host/sdhci.c      | 59 ++++++++++++++++++++++++--------
 drivers/mmc/host/sdhci.h      |  3 ++
 include/linux/mmc/host.h      | 26 ++++++++++++++
 include/linux/mmc/mmc.h       |  6 ++++
 7 files changed, 175 insertions(+), 17 deletions(-)

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH V6 1/5] mmc: core: Capture eMMC and SD card errors
  2022-05-18  7:02 [PATCH V6 0/5] mmc: add error statistics for eMMC and SD card Shaik Sajida Bhanu
@ 2022-05-18  7:02 ` Shaik Sajida Bhanu
  2022-05-23  7:14   ` Adrian Hunter
  2022-05-18  7:02 ` [PATCH V6 2/5] mmc: sdhci: " Shaik Sajida Bhanu
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Shaik Sajida Bhanu @ 2022-05-18  7:02 UTC (permalink / raw)
  To: adrian.hunter, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Shaik Sajida Bhanu, Liangliang Lu, Bao D . Nguyen

Add changes to capture eMMC and SD card errors.
This is useful for debug and testing.

Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
Signed-off-by: Ram Prakash Gupta <quic_rampraka@quicinc.com>
Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>
---
 drivers/mmc/core/core.c  | 10 +++++++++-
 include/linux/mmc/host.h | 26 ++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 368f104..5db5adf 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -943,9 +943,11 @@ int mmc_execute_tuning(struct mmc_card *card)
 	}
 
 	/* Only print error when we don't check for card removal */
-	if (!host->detect_change)
+	if (!host->detect_change) {
 		pr_err("%s: tuning execution failed: %d\n",
 			mmc_hostname(host), err);
+		mmc_debugfs_err_stats_inc(host, MMC_ERR_TUNING);
+	}
 
 	return err;
 }
@@ -2242,6 +2244,12 @@ void mmc_rescan(struct work_struct *work)
 		if (freqs[i] <= host->f_min)
 			break;
 	}
+
+	/*
+	 * Ignore the command timeout errors observed during
+	 * the card init as those are excepted.
+	 */
+	host->err_stats[MMC_ERR_CMD_TIMEOUT] = 0;
 	mmc_release_host(host);
 
  out:
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 0c0c9a0..0d7c0f7 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -93,6 +93,25 @@ struct mmc_clk_phase_map {
 
 struct mmc_host;
 
+enum mmc_err_stat {
+	MMC_ERR_CMD_TIMEOUT,
+	MMC_ERR_CMD_CRC,
+	MMC_ERR_DAT_TIMEOUT,
+	MMC_ERR_DAT_CRC,
+	MMC_ERR_AUTO_CMD,
+	MMC_ERR_ADMA,
+	MMC_ERR_TUNING,
+	MMC_ERR_CMDQ_RED,
+	MMC_ERR_CMDQ_GCE,
+	MMC_ERR_CMDQ_ICCE,
+	MMC_ERR_REQ_TIMEOUT,
+	MMC_ERR_CMDQ_REQ_TIMEOUT,
+	MMC_ERR_ICE_CFG,
+	MMC_ERR_CTRL_TIMEOUT,
+	MMC_ERR_UNEXPECTED_IRQ,
+	MMC_ERR_MAX,
+};
+
 struct mmc_host_ops {
 	/*
 	 * It is optional for the host to implement pre_req and post_req in
@@ -498,6 +517,7 @@ struct mmc_host {
 	/* Host Software Queue support */
 	bool			hsq_enabled;
 
+	u32			err_stats[MMC_ERR_MAX];
 	unsigned long		private[] ____cacheline_aligned;
 };
 
@@ -632,6 +652,12 @@ static inline enum dma_data_direction mmc_get_dma_dir(struct mmc_data *data)
 	return data->flags & MMC_DATA_WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
 }
 
+static inline void mmc_debugfs_err_stats_inc(struct mmc_host *host,
+					     enum mmc_err_stat stat)
+{
+	host->err_stats[stat] += 1;
+}
+
 int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error);
 int mmc_send_abort_tuning(struct mmc_host *host, u32 opcode);
 
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH V6 2/5] mmc: sdhci: Capture eMMC and SD card errors
  2022-05-18  7:02 [PATCH V6 0/5] mmc: add error statistics for eMMC and SD card Shaik Sajida Bhanu
  2022-05-18  7:02 ` [PATCH V6 1/5] mmc: core: Capture eMMC and SD card errors Shaik Sajida Bhanu
@ 2022-05-18  7:02 ` Shaik Sajida Bhanu
  2022-05-23  7:14   ` Adrian Hunter
  2022-05-18  7:02 ` [PATCH V6 3/5] mmc: debugfs: Add debug fs entry for mmc driver Shaik Sajida Bhanu
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Shaik Sajida Bhanu @ 2022-05-18  7:02 UTC (permalink / raw)
  To: adrian.hunter, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Shaik Sajida Bhanu, Liangliang Lu, Bao D . Nguyen

Add changes to capture eMMC and SD card errors.
This is useful for debug and testing.

Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>
---
 drivers/mmc/host/sdhci.c | 59 ++++++++++++++++++++++++++++++++++++------------
 drivers/mmc/host/sdhci.h |  3 +++
 include/linux/mmc/mmc.h  |  6 +++++
 3 files changed, 53 insertions(+), 15 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 7728f26..bd4372c 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -224,6 +224,7 @@ void sdhci_reset(struct sdhci_host *host, u8 mask)
 		if (timedout) {
 			pr_err("%s: Reset 0x%x never completed.\n",
 				mmc_hostname(host->mmc), (int)mask);
+			sdhci_err_stats_inc(host, CTRL_TIMEOUT);
 			sdhci_dumpregs(host);
 			return;
 		}
@@ -1719,6 +1720,7 @@ static bool sdhci_send_command_retry(struct sdhci_host *host,
 		if (!timeout--) {
 			pr_err("%s: Controller never released inhibit bit(s).\n",
 			       mmc_hostname(host->mmc));
+			sdhci_err_stats_inc(host, CTRL_TIMEOUT);
 			sdhci_dumpregs(host);
 			cmd->error = -EIO;
 			return false;
@@ -1968,6 +1970,7 @@ void sdhci_enable_clk(struct sdhci_host *host, u16 clk)
 		if (timedout) {
 			pr_err("%s: Internal clock never stabilised.\n",
 			       mmc_hostname(host->mmc));
+			sdhci_err_stats_inc(host, CTRL_TIMEOUT);
 			sdhci_dumpregs(host);
 			return;
 		}
@@ -1990,6 +1993,7 @@ void sdhci_enable_clk(struct sdhci_host *host, u16 clk)
 			if (timedout) {
 				pr_err("%s: PLL clock never stabilised.\n",
 				       mmc_hostname(host->mmc));
+				sdhci_err_stats_inc(host, CTRL_TIMEOUT);
 				sdhci_dumpregs(host);
 				return;
 			}
@@ -3145,6 +3149,7 @@ static void sdhci_timeout_timer(struct timer_list *t)
 	if (host->cmd && !sdhci_data_line_cmd(host->cmd)) {
 		pr_err("%s: Timeout waiting for hardware cmd interrupt.\n",
 		       mmc_hostname(host->mmc));
+		sdhci_err_stats_inc(host, REQ_TIMEOUT);
 		sdhci_dumpregs(host);
 
 		host->cmd->error = -ETIMEDOUT;
@@ -3167,6 +3172,7 @@ static void sdhci_timeout_data_timer(struct timer_list *t)
 	    (host->cmd && sdhci_data_line_cmd(host->cmd))) {
 		pr_err("%s: Timeout waiting for hardware interrupt.\n",
 		       mmc_hostname(host->mmc));
+		sdhci_err_stats_inc(host, REQ_TIMEOUT);
 		sdhci_dumpregs(host);
 
 		if (host->data) {
@@ -3218,17 +3224,21 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *intmask_p)
 			return;
 		pr_err("%s: Got command interrupt 0x%08x even though no command operation was in progress.\n",
 		       mmc_hostname(host->mmc), (unsigned)intmask);
+		sdhci_err_stats_inc(host, UNEXPECTED_IRQ);
 		sdhci_dumpregs(host);
 		return;
 	}
 
 	if (intmask & (SDHCI_INT_TIMEOUT | SDHCI_INT_CRC |
 		       SDHCI_INT_END_BIT | SDHCI_INT_INDEX)) {
-		if (intmask & SDHCI_INT_TIMEOUT)
+		if (intmask & SDHCI_INT_TIMEOUT) {
 			host->cmd->error = -ETIMEDOUT;
-		else
+			sdhci_err_stats_inc(host, CMD_TIMEOUT);
+		} else {
 			host->cmd->error = -EILSEQ;
-
+			if (!mmc_op_tuning(host->cmd->opcode))
+				sdhci_err_stats_inc(host, CMD_CRC);
+		}
 		/* Treat data command CRC error the same as data CRC error */
 		if (host->cmd->data &&
 		    (intmask & (SDHCI_INT_CRC | SDHCI_INT_TIMEOUT)) ==
@@ -3249,6 +3259,8 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *intmask_p)
 		int err = (auto_cmd_status & SDHCI_AUTO_CMD_TIMEOUT) ?
 			  -ETIMEDOUT :
 			  -EILSEQ;
+		sdhci_err_stats_inc(host, AUTO_CMD);
+
 
 		if (mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) {
 			mrq->sbc->error = err;
@@ -3326,6 +3338,7 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
 			if (intmask & SDHCI_INT_DATA_TIMEOUT) {
 				host->data_cmd = NULL;
 				data_cmd->error = -ETIMEDOUT;
+				sdhci_err_stats_inc(host, CMD_TIMEOUT);
 				__sdhci_finish_mrq(host, data_cmd->mrq);
 				return;
 			}
@@ -3354,23 +3367,30 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
 
 		pr_err("%s: Got data interrupt 0x%08x even though no data operation was in progress.\n",
 		       mmc_hostname(host->mmc), (unsigned)intmask);
+		sdhci_err_stats_inc(host, UNEXPECTED_IRQ);
 		sdhci_dumpregs(host);
 
 		return;
 	}
 
-	if (intmask & SDHCI_INT_DATA_TIMEOUT)
+	if (intmask & SDHCI_INT_DATA_TIMEOUT) {
 		host->data->error = -ETIMEDOUT;
-	else if (intmask & SDHCI_INT_DATA_END_BIT)
+		sdhci_err_stats_inc(host, DAT_TIMEOUT);
+	} else if (intmask & SDHCI_INT_DATA_END_BIT) {
 		host->data->error = -EILSEQ;
-	else if ((intmask & SDHCI_INT_DATA_CRC) &&
+		if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))))
+			sdhci_err_stats_inc(host, DAT_CRC);
+	} else if ((intmask & SDHCI_INT_DATA_CRC) &&
 		SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
-			!= MMC_BUS_TEST_R)
+			!= MMC_BUS_TEST_R) {
 		host->data->error = -EILSEQ;
-	else if (intmask & SDHCI_INT_ADMA_ERROR) {
+		if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))))
+			sdhci_err_stats_inc(host, DAT_CRC);
+	} else if (intmask & SDHCI_INT_ADMA_ERROR) {
 		pr_err("%s: ADMA error: 0x%08x\n", mmc_hostname(host->mmc),
 		       intmask);
 		sdhci_adma_show_error(host);
+		sdhci_err_stats_inc(host, ADMA);
 		host->data->error = -EIO;
 		if (host->ops->adma_workaround)
 			host->ops->adma_workaround(host, intmask);
@@ -3568,6 +3588,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 	if (unexpected) {
 		pr_err("%s: Unexpected interrupt 0x%08x.\n",
 			   mmc_hostname(host->mmc), unexpected);
+		sdhci_err_stats_inc(host, UNEXPECTED_IRQ);
 		sdhci_dumpregs(host);
 	}
 
@@ -3889,20 +3910,27 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
 	if (!host->cqe_on)
 		return false;
 
-	if (intmask & (SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC))
+	if (intmask & (SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC)) {
 		*cmd_error = -EILSEQ;
-	else if (intmask & SDHCI_INT_TIMEOUT)
+		if (!mmc_op_tuning(host->cmd->opcode))
+			sdhci_err_stats_inc(host, CMD_CRC);
+	} else if (intmask & SDHCI_INT_TIMEOUT) {
 		*cmd_error = -ETIMEDOUT;
-	else
+		sdhci_err_stats_inc(host, CMD_TIMEOUT);
+	} else
 		*cmd_error = 0;
 
-	if (intmask & (SDHCI_INT_DATA_END_BIT | SDHCI_INT_DATA_CRC))
+	if (intmask & (SDHCI_INT_DATA_END_BIT | SDHCI_INT_DATA_CRC)) {
 		*data_error = -EILSEQ;
-	else if (intmask & SDHCI_INT_DATA_TIMEOUT)
+		if (!mmc_op_tuning(host->cmd->opcode))
+			sdhci_err_stats_inc(host, DAT_CRC);
+	} else if (intmask & SDHCI_INT_DATA_TIMEOUT) {
 		*data_error = -ETIMEDOUT;
-	else if (intmask & SDHCI_INT_ADMA_ERROR)
+		sdhci_err_stats_inc(host, DAT_TIMEOUT);
+	} else if (intmask & SDHCI_INT_ADMA_ERROR) {
 		*data_error = -EIO;
-	else
+		sdhci_err_stats_inc(host, ADMA);
+	} else
 		*data_error = 0;
 
 	/* Clear selected interrupts. */
@@ -3918,6 +3946,7 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
 		sdhci_writel(host, intmask, SDHCI_INT_STATUS);
 		pr_err("%s: CQE: Unexpected interrupt 0x%08x.\n",
 		       mmc_hostname(host->mmc), intmask);
+		sdhci_err_stats_inc(host, UNEXPECTED_IRQ);
 		sdhci_dumpregs(host);
 	}
 
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index 6c689be..2c02ded 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -356,6 +356,9 @@ struct sdhci_adma2_64_desc {
  */
 #define MMC_CMD_TRANSFER_TIME	(10 * NSEC_PER_MSEC) /* max 10 ms */
 
+#define sdhci_err_stats_inc(host, err_name) \
+	mmc_debugfs_err_stats_inc((host)->mmc, MMC_ERR_##err_name)
+
 enum sdhci_cookie {
 	COOKIE_UNMAPPED,
 	COOKIE_PRE_MAPPED,	/* mapped by sdhci_pre_req() */
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index d9a65c6..9c50bc4 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -99,6 +99,12 @@ static inline bool mmc_op_multi(u32 opcode)
 	       opcode == MMC_READ_MULTIPLE_BLOCK;
 }
 
+static inline bool mmc_op_tuning(u32 opcode)
+{
+	return opcode == MMC_SEND_TUNING_BLOCK ||
+			opcode == MMC_SEND_TUNING_BLOCK_HS200;
+}
+
 /*
  * MMC_SWITCH argument format:
  *
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH V6 3/5] mmc: debugfs: Add debug fs entry for mmc driver
  2022-05-18  7:02 [PATCH V6 0/5] mmc: add error statistics for eMMC and SD card Shaik Sajida Bhanu
  2022-05-18  7:02 ` [PATCH V6 1/5] mmc: core: Capture eMMC and SD card errors Shaik Sajida Bhanu
  2022-05-18  7:02 ` [PATCH V6 2/5] mmc: sdhci: " Shaik Sajida Bhanu
@ 2022-05-18  7:02 ` Shaik Sajida Bhanu
  2022-05-23  7:15   ` Adrian Hunter
  2022-05-18  7:02 ` [PATCH V6 4/5] mmc: debugfs: Add debug fs error state " Shaik Sajida Bhanu
  2022-05-18  7:02 ` [PATCH V6 5/5] mmc: cqhci: Capture eMMC and SD card errors Shaik Sajida Bhanu
  4 siblings, 1 reply; 14+ messages in thread
From: Shaik Sajida Bhanu @ 2022-05-18  7:02 UTC (permalink / raw)
  To: adrian.hunter, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Shaik Sajida Bhanu, Liangliang Lu, Bao D . Nguyen

Add debug fs entry to query eMMC and SD card errors statistics

Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>
---
 drivers/mmc/core/debugfs.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
index 3fdbc80..6aa5a60 100644
--- a/drivers/mmc/core/debugfs.c
+++ b/drivers/mmc/core/debugfs.c
@@ -223,6 +223,59 @@ 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_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",
+		[MMC_ERR_CTRL_TIMEOUT] = "Controller Timedout errors",
+		[MMC_ERR_UNEXPECTED_IRQ] = "Unexpected IRQ errors",
+	};
+	int i;
+
+	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;
+
+	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 +289,9 @@ 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_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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH V6 4/5] mmc: debugfs: Add debug fs error state entry for mmc driver
  2022-05-18  7:02 [PATCH V6 0/5] mmc: add error statistics for eMMC and SD card Shaik Sajida Bhanu
                   ` (2 preceding siblings ...)
  2022-05-18  7:02 ` [PATCH V6 3/5] mmc: debugfs: Add debug fs entry for mmc driver Shaik Sajida Bhanu
@ 2022-05-18  7:02 ` Shaik Sajida Bhanu
  2022-05-23  7:15   ` Adrian Hunter
  2022-05-18  7:02 ` [PATCH V6 5/5] mmc: cqhci: Capture eMMC and SD card errors Shaik Sajida Bhanu
  4 siblings, 1 reply; 14+ messages in thread
From: Shaik Sajida Bhanu @ 2022-05-18  7:02 UTC (permalink / raw)
  To: adrian.hunter, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Shaik Sajida Bhanu, Liangliang Lu, Bao D . Nguyen

Add debug fs entry error state to query eMMC and SD card errors statistics.
If any errors occurred in eMMC and SD card driver level then
err_state value will be set to 1.

Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>
---
 drivers/mmc/core/debugfs.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
index 6aa5a60..3c7908d 100644
--- a/drivers/mmc/core/debugfs.c
+++ b/drivers/mmc/core/debugfs.c
@@ -223,6 +223,27 @@ 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;
+	int i;
+
+	if (!host)
+		return -EINVAL;
+
+	*val = 0;
+	for (i = 0; i < MMC_ERR_MAX; i++) {
+		if (host->err_stats[i]) {
+			*val = 1;
+			break;
+		}
+	}
+
+	return 0;
+}
+
+DEFINE_DEBUGFS_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;
@@ -289,6 +310,8 @@ 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);
 
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH V6 5/5] mmc: cqhci: Capture eMMC and SD card errors
  2022-05-18  7:02 [PATCH V6 0/5] mmc: add error statistics for eMMC and SD card Shaik Sajida Bhanu
                   ` (3 preceding siblings ...)
  2022-05-18  7:02 ` [PATCH V6 4/5] mmc: debugfs: Add debug fs error state " Shaik Sajida Bhanu
@ 2022-05-18  7:02 ` Shaik Sajida Bhanu
  2022-05-23  7:15   ` Adrian Hunter
  4 siblings, 1 reply; 14+ messages in thread
From: Shaik Sajida Bhanu @ 2022-05-18  7:02 UTC (permalink / raw)
  To: adrian.hunter, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Shaik Sajida Bhanu, Liangliang Lu, Bao D . Nguyen

Add changes to capture eMMC and SD card errors.
This is useful for debug and testing.

Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
Signed-off-by: Ram Prakash Gupta <quic_rampraka@quicinc.com>
Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>
---
 drivers/mmc/host/cqhci-core.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/cqhci-core.c b/drivers/mmc/host/cqhci-core.c
index 31f8412..7f25cca 100644
--- a/drivers/mmc/host/cqhci-core.c
+++ b/drivers/mmc/host/cqhci-core.c
@@ -822,8 +822,15 @@ irqreturn_t cqhci_irq(struct mmc_host *mmc, u32 intmask, int cmd_error,
 	pr_debug("%s: cqhci: IRQ status: 0x%08x\n", mmc_hostname(mmc), status);
 
 	if ((status & (CQHCI_IS_RED | CQHCI_IS_GCE | CQHCI_IS_ICCE)) ||
-	    cmd_error || data_error)
+	    cmd_error || data_error) {
+		if (status & CQHCI_IS_RED)
+			mmc_debugfs_err_stats_inc(mmc, MMC_ERR_CMDQ_RED);
+		if (status & CQHCI_IS_GCE)
+			mmc_debugfs_err_stats_inc(mmc, MMC_ERR_CMDQ_GCE);
+		if (status & CQHCI_IS_ICCE)
+			mmc_debugfs_err_stats_inc(mmc, MMC_ERR_CMDQ_ICCE);
 		cqhci_error_irq(mmc, status, cmd_error, data_error);
+	}
 
 	if (status & CQHCI_IS_TCC) {
 		/* read TCN and complete the request */
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH V6 1/5] mmc: core: Capture eMMC and SD card errors
  2022-05-18  7:02 ` [PATCH V6 1/5] mmc: core: Capture eMMC and SD card errors Shaik Sajida Bhanu
@ 2022-05-23  7:14   ` Adrian Hunter
  2022-05-24  5:56     ` Sajida Bhanu (Temp)
  0 siblings, 1 reply; 14+ messages in thread
From: Adrian Hunter @ 2022-05-23  7:14 UTC (permalink / raw)
  To: Shaik Sajida Bhanu, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Liangliang Lu, Bao D . Nguyen

On 18/05/22 10:02, Shaik Sajida Bhanu wrote:
> Add changes to capture eMMC and SD card errors.
> This is useful for debug and testing.
> 
> Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
> Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
> Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
> Signed-off-by: Ram Prakash Gupta <quic_rampraka@quicinc.com>
> Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>

Seems to need to be re-based on Ulf's next branch:

	git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git next

Otherwise:

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/mmc/core/core.c  | 10 +++++++++-
>  include/linux/mmc/host.h | 26 ++++++++++++++++++++++++++
>  2 files changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 368f104..5db5adf 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -943,9 +943,11 @@ int mmc_execute_tuning(struct mmc_card *card)
>  	}
>  
>  	/* Only print error when we don't check for card removal */
> -	if (!host->detect_change)
> +	if (!host->detect_change) {
>  		pr_err("%s: tuning execution failed: %d\n",
>  			mmc_hostname(host), err);
> +		mmc_debugfs_err_stats_inc(host, MMC_ERR_TUNING);
> +	}
>  
>  	return err;
>  }
> @@ -2242,6 +2244,12 @@ void mmc_rescan(struct work_struct *work)
>  		if (freqs[i] <= host->f_min)
>  			break;
>  	}
> +
> +	/*
> +	 * Ignore the command timeout errors observed during
> +	 * the card init as those are excepted.
> +	 */
> +	host->err_stats[MMC_ERR_CMD_TIMEOUT] = 0;
>  	mmc_release_host(host);
>  
>   out:
> diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
> index 0c0c9a0..0d7c0f7 100644
> --- a/include/linux/mmc/host.h
> +++ b/include/linux/mmc/host.h
> @@ -93,6 +93,25 @@ struct mmc_clk_phase_map {
>  
>  struct mmc_host;
>  
> +enum mmc_err_stat {
> +	MMC_ERR_CMD_TIMEOUT,
> +	MMC_ERR_CMD_CRC,
> +	MMC_ERR_DAT_TIMEOUT,
> +	MMC_ERR_DAT_CRC,
> +	MMC_ERR_AUTO_CMD,
> +	MMC_ERR_ADMA,
> +	MMC_ERR_TUNING,
> +	MMC_ERR_CMDQ_RED,
> +	MMC_ERR_CMDQ_GCE,
> +	MMC_ERR_CMDQ_ICCE,
> +	MMC_ERR_REQ_TIMEOUT,
> +	MMC_ERR_CMDQ_REQ_TIMEOUT,
> +	MMC_ERR_ICE_CFG,
> +	MMC_ERR_CTRL_TIMEOUT,
> +	MMC_ERR_UNEXPECTED_IRQ,
> +	MMC_ERR_MAX,
> +};
> +
>  struct mmc_host_ops {
>  	/*
>  	 * It is optional for the host to implement pre_req and post_req in
> @@ -498,6 +517,7 @@ struct mmc_host {
>  	/* Host Software Queue support */
>  	bool			hsq_enabled;
>  
> +	u32			err_stats[MMC_ERR_MAX];
>  	unsigned long		private[] ____cacheline_aligned;
>  };
>  
> @@ -632,6 +652,12 @@ static inline enum dma_data_direction mmc_get_dma_dir(struct mmc_data *data)
>  	return data->flags & MMC_DATA_WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
>  }
>  
> +static inline void mmc_debugfs_err_stats_inc(struct mmc_host *host,
> +					     enum mmc_err_stat stat)
> +{
> +	host->err_stats[stat] += 1;
> +}
> +
>  int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error);
>  int mmc_send_abort_tuning(struct mmc_host *host, u32 opcode);
>  


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH V6 2/5] mmc: sdhci: Capture eMMC and SD card errors
  2022-05-18  7:02 ` [PATCH V6 2/5] mmc: sdhci: " Shaik Sajida Bhanu
@ 2022-05-23  7:14   ` Adrian Hunter
  2022-05-24  5:48     ` Sajida Bhanu (Temp)
  0 siblings, 1 reply; 14+ messages in thread
From: Adrian Hunter @ 2022-05-23  7:14 UTC (permalink / raw)
  To: Shaik Sajida Bhanu, adrian.hunter, ulf.hansson, wsa+renesas,
	shawn.lin, yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Liangliang Lu, Bao D . Nguyen

On 18/05/22 10:02, Shaik Sajida Bhanu wrote:
> Add changes to capture eMMC and SD card errors.
> This is useful for debug and testing.
> 
> Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
> Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
> Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
> Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>

Misplaced blank line (see below) and seems to need to be
re-based on Ulf's next branch:

	git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git next

Otherwise:

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/mmc/host/sdhci.c | 59 ++++++++++++++++++++++++++++++++++++------------
>  drivers/mmc/host/sdhci.h |  3 +++
>  include/linux/mmc/mmc.h  |  6 +++++
>  3 files changed, 53 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index 7728f26..bd4372c 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -224,6 +224,7 @@ void sdhci_reset(struct sdhci_host *host, u8 mask)
>  		if (timedout) {
>  			pr_err("%s: Reset 0x%x never completed.\n",
>  				mmc_hostname(host->mmc), (int)mask);
> +			sdhci_err_stats_inc(host, CTRL_TIMEOUT);
>  			sdhci_dumpregs(host);
>  			return;
>  		}
> @@ -1719,6 +1720,7 @@ static bool sdhci_send_command_retry(struct sdhci_host *host,
>  		if (!timeout--) {
>  			pr_err("%s: Controller never released inhibit bit(s).\n",
>  			       mmc_hostname(host->mmc));
> +			sdhci_err_stats_inc(host, CTRL_TIMEOUT);
>  			sdhci_dumpregs(host);
>  			cmd->error = -EIO;
>  			return false;
> @@ -1968,6 +1970,7 @@ void sdhci_enable_clk(struct sdhci_host *host, u16 clk)
>  		if (timedout) {
>  			pr_err("%s: Internal clock never stabilised.\n",
>  			       mmc_hostname(host->mmc));
> +			sdhci_err_stats_inc(host, CTRL_TIMEOUT);
>  			sdhci_dumpregs(host);
>  			return;
>  		}
> @@ -1990,6 +1993,7 @@ void sdhci_enable_clk(struct sdhci_host *host, u16 clk)
>  			if (timedout) {
>  				pr_err("%s: PLL clock never stabilised.\n",
>  				       mmc_hostname(host->mmc));
> +				sdhci_err_stats_inc(host, CTRL_TIMEOUT);
>  				sdhci_dumpregs(host);
>  				return;
>  			}
> @@ -3145,6 +3149,7 @@ static void sdhci_timeout_timer(struct timer_list *t)
>  	if (host->cmd && !sdhci_data_line_cmd(host->cmd)) {
>  		pr_err("%s: Timeout waiting for hardware cmd interrupt.\n",
>  		       mmc_hostname(host->mmc));
> +		sdhci_err_stats_inc(host, REQ_TIMEOUT);
>  		sdhci_dumpregs(host);
>  
>  		host->cmd->error = -ETIMEDOUT;
> @@ -3167,6 +3172,7 @@ static void sdhci_timeout_data_timer(struct timer_list *t)
>  	    (host->cmd && sdhci_data_line_cmd(host->cmd))) {
>  		pr_err("%s: Timeout waiting for hardware interrupt.\n",
>  		       mmc_hostname(host->mmc));
> +		sdhci_err_stats_inc(host, REQ_TIMEOUT);
>  		sdhci_dumpregs(host);
>  
>  		if (host->data) {
> @@ -3218,17 +3224,21 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *intmask_p)
>  			return;
>  		pr_err("%s: Got command interrupt 0x%08x even though no command operation was in progress.\n",
>  		       mmc_hostname(host->mmc), (unsigned)intmask);
> +		sdhci_err_stats_inc(host, UNEXPECTED_IRQ);
>  		sdhci_dumpregs(host);
>  		return;
>  	}
>  
>  	if (intmask & (SDHCI_INT_TIMEOUT | SDHCI_INT_CRC |
>  		       SDHCI_INT_END_BIT | SDHCI_INT_INDEX)) {
> -		if (intmask & SDHCI_INT_TIMEOUT)
> +		if (intmask & SDHCI_INT_TIMEOUT) {
>  			host->cmd->error = -ETIMEDOUT;
> -		else
> +			sdhci_err_stats_inc(host, CMD_TIMEOUT);
> +		} else {
>  			host->cmd->error = -EILSEQ;
> -
> +			if (!mmc_op_tuning(host->cmd->opcode))
> +				sdhci_err_stats_inc(host, CMD_CRC);
> +		}
>  		/* Treat data command CRC error the same as data CRC error */
>  		if (host->cmd->data &&
>  		    (intmask & (SDHCI_INT_CRC | SDHCI_INT_TIMEOUT)) ==
> @@ -3249,6 +3259,8 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *intmask_p)
>  		int err = (auto_cmd_status & SDHCI_AUTO_CMD_TIMEOUT) ?
>  			  -ETIMEDOUT :
>  			  -EILSEQ;

Blank line better here

> +		sdhci_err_stats_inc(host, AUTO_CMD);
> +

This makes double blank line

>  
>  		if (mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) {
>  			mrq->sbc->error = err;
> @@ -3326,6 +3338,7 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
>  			if (intmask & SDHCI_INT_DATA_TIMEOUT) {
>  				host->data_cmd = NULL;
>  				data_cmd->error = -ETIMEDOUT;
> +				sdhci_err_stats_inc(host, CMD_TIMEOUT);
>  				__sdhci_finish_mrq(host, data_cmd->mrq);
>  				return;
>  			}
> @@ -3354,23 +3367,30 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
>  
>  		pr_err("%s: Got data interrupt 0x%08x even though no data operation was in progress.\n",
>  		       mmc_hostname(host->mmc), (unsigned)intmask);
> +		sdhci_err_stats_inc(host, UNEXPECTED_IRQ);
>  		sdhci_dumpregs(host);
>  
>  		return;
>  	}
>  
> -	if (intmask & SDHCI_INT_DATA_TIMEOUT)
> +	if (intmask & SDHCI_INT_DATA_TIMEOUT) {
>  		host->data->error = -ETIMEDOUT;
> -	else if (intmask & SDHCI_INT_DATA_END_BIT)
> +		sdhci_err_stats_inc(host, DAT_TIMEOUT);
> +	} else if (intmask & SDHCI_INT_DATA_END_BIT) {
>  		host->data->error = -EILSEQ;
> -	else if ((intmask & SDHCI_INT_DATA_CRC) &&
> +		if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))))
> +			sdhci_err_stats_inc(host, DAT_CRC);
> +	} else if ((intmask & SDHCI_INT_DATA_CRC) &&
>  		SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
> -			!= MMC_BUS_TEST_R)
> +			!= MMC_BUS_TEST_R) {
>  		host->data->error = -EILSEQ;
> -	else if (intmask & SDHCI_INT_ADMA_ERROR) {
> +		if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))))
> +			sdhci_err_stats_inc(host, DAT_CRC);
> +	} else if (intmask & SDHCI_INT_ADMA_ERROR) {
>  		pr_err("%s: ADMA error: 0x%08x\n", mmc_hostname(host->mmc),
>  		       intmask);
>  		sdhci_adma_show_error(host);
> +		sdhci_err_stats_inc(host, ADMA);
>  		host->data->error = -EIO;
>  		if (host->ops->adma_workaround)
>  			host->ops->adma_workaround(host, intmask);
> @@ -3568,6 +3588,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
>  	if (unexpected) {
>  		pr_err("%s: Unexpected interrupt 0x%08x.\n",
>  			   mmc_hostname(host->mmc), unexpected);
> +		sdhci_err_stats_inc(host, UNEXPECTED_IRQ);
>  		sdhci_dumpregs(host);
>  	}
>  
> @@ -3889,20 +3910,27 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
>  	if (!host->cqe_on)
>  		return false;
>  
> -	if (intmask & (SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC))
> +	if (intmask & (SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC)) {
>  		*cmd_error = -EILSEQ;
> -	else if (intmask & SDHCI_INT_TIMEOUT)
> +		if (!mmc_op_tuning(host->cmd->opcode))
> +			sdhci_err_stats_inc(host, CMD_CRC);
> +	} else if (intmask & SDHCI_INT_TIMEOUT) {
>  		*cmd_error = -ETIMEDOUT;
> -	else
> +		sdhci_err_stats_inc(host, CMD_TIMEOUT);
> +	} else
>  		*cmd_error = 0;
>  
> -	if (intmask & (SDHCI_INT_DATA_END_BIT | SDHCI_INT_DATA_CRC))
> +	if (intmask & (SDHCI_INT_DATA_END_BIT | SDHCI_INT_DATA_CRC)) {
>  		*data_error = -EILSEQ;
> -	else if (intmask & SDHCI_INT_DATA_TIMEOUT)
> +		if (!mmc_op_tuning(host->cmd->opcode))
> +			sdhci_err_stats_inc(host, DAT_CRC);
> +	} else if (intmask & SDHCI_INT_DATA_TIMEOUT) {
>  		*data_error = -ETIMEDOUT;
> -	else if (intmask & SDHCI_INT_ADMA_ERROR)
> +		sdhci_err_stats_inc(host, DAT_TIMEOUT);
> +	} else if (intmask & SDHCI_INT_ADMA_ERROR) {
>  		*data_error = -EIO;
> -	else
> +		sdhci_err_stats_inc(host, ADMA);
> +	} else
>  		*data_error = 0;
>  
>  	/* Clear selected interrupts. */
> @@ -3918,6 +3946,7 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
>  		sdhci_writel(host, intmask, SDHCI_INT_STATUS);
>  		pr_err("%s: CQE: Unexpected interrupt 0x%08x.\n",
>  		       mmc_hostname(host->mmc), intmask);
> +		sdhci_err_stats_inc(host, UNEXPECTED_IRQ);
>  		sdhci_dumpregs(host);
>  	}
>  
> diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
> index 6c689be..2c02ded 100644
> --- a/drivers/mmc/host/sdhci.h
> +++ b/drivers/mmc/host/sdhci.h
> @@ -356,6 +356,9 @@ struct sdhci_adma2_64_desc {
>   */
>  #define MMC_CMD_TRANSFER_TIME	(10 * NSEC_PER_MSEC) /* max 10 ms */
>  
> +#define sdhci_err_stats_inc(host, err_name) \
> +	mmc_debugfs_err_stats_inc((host)->mmc, MMC_ERR_##err_name)
> +
>  enum sdhci_cookie {
>  	COOKIE_UNMAPPED,
>  	COOKIE_PRE_MAPPED,	/* mapped by sdhci_pre_req() */
> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
> index d9a65c6..9c50bc4 100644
> --- a/include/linux/mmc/mmc.h
> +++ b/include/linux/mmc/mmc.h
> @@ -99,6 +99,12 @@ static inline bool mmc_op_multi(u32 opcode)
>  	       opcode == MMC_READ_MULTIPLE_BLOCK;
>  }
>  
> +static inline bool mmc_op_tuning(u32 opcode)
> +{
> +	return opcode == MMC_SEND_TUNING_BLOCK ||
> +			opcode == MMC_SEND_TUNING_BLOCK_HS200;
> +}
> +
>  /*
>   * MMC_SWITCH argument format:
>   *


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH V6 3/5] mmc: debugfs: Add debug fs entry for mmc driver
  2022-05-18  7:02 ` [PATCH V6 3/5] mmc: debugfs: Add debug fs entry for mmc driver Shaik Sajida Bhanu
@ 2022-05-23  7:15   ` Adrian Hunter
  0 siblings, 0 replies; 14+ messages in thread
From: Adrian Hunter @ 2022-05-23  7:15 UTC (permalink / raw)
  To: Shaik Sajida Bhanu, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Liangliang Lu, Bao D . Nguyen

On 18/05/22 10:02, Shaik Sajida Bhanu wrote:
> Add debug fs entry to query eMMC and SD card errors statistics
> 
> Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
> Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
> Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
> Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/mmc/core/debugfs.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
> 
> diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
> index 3fdbc80..6aa5a60 100644
> --- a/drivers/mmc/core/debugfs.c
> +++ b/drivers/mmc/core/debugfs.c
> @@ -223,6 +223,59 @@ 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_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",
> +		[MMC_ERR_CTRL_TIMEOUT] = "Controller Timedout errors",
> +		[MMC_ERR_UNEXPECTED_IRQ] = "Unexpected IRQ errors",
> +	};
> +	int i;
> +
> +	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;
> +
> +	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 +289,9 @@ 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_stats", 0600, root, host,
> +			    &mmc_err_stats_fops);
> +
>  #ifdef CONFIG_FAIL_MMC_REQUEST
>  	if (fail_request)
>  		setup_fault_attr(&fail_default_attr, fail_request);


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH V6 4/5] mmc: debugfs: Add debug fs error state entry for mmc driver
  2022-05-18  7:02 ` [PATCH V6 4/5] mmc: debugfs: Add debug fs error state " Shaik Sajida Bhanu
@ 2022-05-23  7:15   ` Adrian Hunter
  2022-05-24  5:19     ` Sajida Bhanu (Temp)
  0 siblings, 1 reply; 14+ messages in thread
From: Adrian Hunter @ 2022-05-23  7:15 UTC (permalink / raw)
  To: Shaik Sajida Bhanu, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Liangliang Lu, Bao D . Nguyen

On 18/05/22 10:02, Shaik Sajida Bhanu wrote:
> Add debug fs entry error state to query eMMC and SD card errors statistics.
> If any errors occurred in eMMC and SD card driver level then
> err_state value will be set to 1.
> 
> Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
> Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
> Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
> Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>

Could use debugfs_create_file_unsafe() (see below)

Otherwise:

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/mmc/core/debugfs.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
> index 6aa5a60..3c7908d 100644
> --- a/drivers/mmc/core/debugfs.c
> +++ b/drivers/mmc/core/debugfs.c
> @@ -223,6 +223,27 @@ 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;
> +	int i;
> +
> +	if (!host)
> +		return -EINVAL;
> +
> +	*val = 0;
> +	for (i = 0; i < MMC_ERR_MAX; i++) {
> +		if (host->err_stats[i]) {
> +			*val = 1;
> +			break;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +DEFINE_DEBUGFS_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;
> @@ -289,6 +310,8 @@ 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);

This could use debugfs_create_file_unsafe()

>  	debugfs_create_file("err_stats", 0600, root, host,
>  			    &mmc_err_stats_fops);
>  


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH V6 5/5] mmc: cqhci: Capture eMMC and SD card errors
  2022-05-18  7:02 ` [PATCH V6 5/5] mmc: cqhci: Capture eMMC and SD card errors Shaik Sajida Bhanu
@ 2022-05-23  7:15   ` Adrian Hunter
  0 siblings, 0 replies; 14+ messages in thread
From: Adrian Hunter @ 2022-05-23  7:15 UTC (permalink / raw)
  To: Shaik Sajida Bhanu, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Liangliang Lu, Bao D . Nguyen

On 18/05/22 10:02, Shaik Sajida Bhanu wrote:
> Add changes to capture eMMC and SD card errors.
> This is useful for debug and testing.
> 
> Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
> Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
> Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
> Signed-off-by: Ram Prakash Gupta <quic_rampraka@quicinc.com>
> Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/mmc/host/cqhci-core.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mmc/host/cqhci-core.c b/drivers/mmc/host/cqhci-core.c
> index 31f8412..7f25cca 100644
> --- a/drivers/mmc/host/cqhci-core.c
> +++ b/drivers/mmc/host/cqhci-core.c
> @@ -822,8 +822,15 @@ irqreturn_t cqhci_irq(struct mmc_host *mmc, u32 intmask, int cmd_error,
>  	pr_debug("%s: cqhci: IRQ status: 0x%08x\n", mmc_hostname(mmc), status);
>  
>  	if ((status & (CQHCI_IS_RED | CQHCI_IS_GCE | CQHCI_IS_ICCE)) ||
> -	    cmd_error || data_error)
> +	    cmd_error || data_error) {
> +		if (status & CQHCI_IS_RED)
> +			mmc_debugfs_err_stats_inc(mmc, MMC_ERR_CMDQ_RED);
> +		if (status & CQHCI_IS_GCE)
> +			mmc_debugfs_err_stats_inc(mmc, MMC_ERR_CMDQ_GCE);
> +		if (status & CQHCI_IS_ICCE)
> +			mmc_debugfs_err_stats_inc(mmc, MMC_ERR_CMDQ_ICCE);
>  		cqhci_error_irq(mmc, status, cmd_error, data_error);
> +	}
>  
>  	if (status & CQHCI_IS_TCC) {
>  		/* read TCN and complete the request */


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH V6 4/5] mmc: debugfs: Add debug fs error state entry for mmc driver
  2022-05-23  7:15   ` Adrian Hunter
@ 2022-05-24  5:19     ` Sajida Bhanu (Temp)
  0 siblings, 0 replies; 14+ messages in thread
From: Sajida Bhanu (Temp) @ 2022-05-24  5:19 UTC (permalink / raw)
  To: Adrian Hunter, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Liangliang Lu, Bao D . Nguyen

Hi Adrian,

Thanks for the review.

Please find the inline comments.

Thanks,

Sajida

On 5/23/2022 12:45 PM, Adrian Hunter wrote:
> On 18/05/22 10:02, Shaik Sajida Bhanu wrote:
>> Add debug fs entry error state to query eMMC and SD card errors statistics.
>> If any errors occurred in eMMC and SD card driver level then
>> err_state value will be set to 1.
>>
>> Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
>> Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
>> Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
>> Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>
> Could use debugfs_create_file_unsafe() (see below)
>
> Otherwise:
>
> Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Sure Thank you
>
>> ---
>>   drivers/mmc/core/debugfs.c | 23 +++++++++++++++++++++++
>>   1 file changed, 23 insertions(+)
>>
>> diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
>> index 6aa5a60..3c7908d 100644
>> --- a/drivers/mmc/core/debugfs.c
>> +++ b/drivers/mmc/core/debugfs.c
>> @@ -223,6 +223,27 @@ 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;
>> +	int i;
>> +
>> +	if (!host)
>> +		return -EINVAL;
>> +
>> +	*val = 0;
>> +	for (i = 0; i < MMC_ERR_MAX; i++) {
>> +		if (host->err_stats[i]) {
>> +			*val = 1;
>> +			break;
>> +		}
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +DEFINE_DEBUGFS_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;
>> @@ -289,6 +310,8 @@ 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);
> This could use debugfs_create_file_unsafe()
Sure
>
>>   	debugfs_create_file("err_stats", 0600, root, host,
>>   			    &mmc_err_stats_fops);
>>   

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH V6 2/5] mmc: sdhci: Capture eMMC and SD card errors
  2022-05-23  7:14   ` Adrian Hunter
@ 2022-05-24  5:48     ` Sajida Bhanu (Temp)
  0 siblings, 0 replies; 14+ messages in thread
From: Sajida Bhanu (Temp) @ 2022-05-24  5:48 UTC (permalink / raw)
  To: Adrian Hunter, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Liangliang Lu, Bao D . Nguyen

Hi Adrain,

Thank You for the review.

Please find the inline comments.

Thanks,

Sajida

On 5/23/2022 12:44 PM, Adrian Hunter wrote:
> On 18/05/22 10:02, Shaik Sajida Bhanu wrote:
>> Add changes to capture eMMC and SD card errors.
>> This is useful for debug and testing.
>>
>> Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
>> Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
>> Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
>> Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>
> Misplaced blank line (see below) and seems to need to be
Sure will address
> re-based on Ulf's next branch:
>
> 	git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git next
>
> Otherwise:
>
> Acked-by: Adrian Hunter <adrian.hunter@intel.com>
>
>> ---
>>   drivers/mmc/host/sdhci.c | 59 ++++++++++++++++++++++++++++++++++++------------
>>   drivers/mmc/host/sdhci.h |  3 +++
>>   include/linux/mmc/mmc.h  |  6 +++++
>>   3 files changed, 53 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
>> index 7728f26..bd4372c 100644
>> --- a/drivers/mmc/host/sdhci.c
>> +++ b/drivers/mmc/host/sdhci.c
>> @@ -224,6 +224,7 @@ void sdhci_reset(struct sdhci_host *host, u8 mask)
>>   		if (timedout) {
>>   			pr_err("%s: Reset 0x%x never completed.\n",
>>   				mmc_hostname(host->mmc), (int)mask);
>> +			sdhci_err_stats_inc(host, CTRL_TIMEOUT);
>>   			sdhci_dumpregs(host);
>>   			return;
>>   		}
>> @@ -1719,6 +1720,7 @@ static bool sdhci_send_command_retry(struct sdhci_host *host,
>>   		if (!timeout--) {
>>   			pr_err("%s: Controller never released inhibit bit(s).\n",
>>   			       mmc_hostname(host->mmc));
>> +			sdhci_err_stats_inc(host, CTRL_TIMEOUT);
>>   			sdhci_dumpregs(host);
>>   			cmd->error = -EIO;
>>   			return false;
>> @@ -1968,6 +1970,7 @@ void sdhci_enable_clk(struct sdhci_host *host, u16 clk)
>>   		if (timedout) {
>>   			pr_err("%s: Internal clock never stabilised.\n",
>>   			       mmc_hostname(host->mmc));
>> +			sdhci_err_stats_inc(host, CTRL_TIMEOUT);
>>   			sdhci_dumpregs(host);
>>   			return;
>>   		}
>> @@ -1990,6 +1993,7 @@ void sdhci_enable_clk(struct sdhci_host *host, u16 clk)
>>   			if (timedout) {
>>   				pr_err("%s: PLL clock never stabilised.\n",
>>   				       mmc_hostname(host->mmc));
>> +				sdhci_err_stats_inc(host, CTRL_TIMEOUT);
>>   				sdhci_dumpregs(host);
>>   				return;
>>   			}
>> @@ -3145,6 +3149,7 @@ static void sdhci_timeout_timer(struct timer_list *t)
>>   	if (host->cmd && !sdhci_data_line_cmd(host->cmd)) {
>>   		pr_err("%s: Timeout waiting for hardware cmd interrupt.\n",
>>   		       mmc_hostname(host->mmc));
>> +		sdhci_err_stats_inc(host, REQ_TIMEOUT);
>>   		sdhci_dumpregs(host);
>>   
>>   		host->cmd->error = -ETIMEDOUT;
>> @@ -3167,6 +3172,7 @@ static void sdhci_timeout_data_timer(struct timer_list *t)
>>   	    (host->cmd && sdhci_data_line_cmd(host->cmd))) {
>>   		pr_err("%s: Timeout waiting for hardware interrupt.\n",
>>   		       mmc_hostname(host->mmc));
>> +		sdhci_err_stats_inc(host, REQ_TIMEOUT);
>>   		sdhci_dumpregs(host);
>>   
>>   		if (host->data) {
>> @@ -3218,17 +3224,21 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *intmask_p)
>>   			return;
>>   		pr_err("%s: Got command interrupt 0x%08x even though no command operation was in progress.\n",
>>   		       mmc_hostname(host->mmc), (unsigned)intmask);
>> +		sdhci_err_stats_inc(host, UNEXPECTED_IRQ);
>>   		sdhci_dumpregs(host);
>>   		return;
>>   	}
>>   
>>   	if (intmask & (SDHCI_INT_TIMEOUT | SDHCI_INT_CRC |
>>   		       SDHCI_INT_END_BIT | SDHCI_INT_INDEX)) {
>> -		if (intmask & SDHCI_INT_TIMEOUT)
>> +		if (intmask & SDHCI_INT_TIMEOUT) {
>>   			host->cmd->error = -ETIMEDOUT;
>> -		else
>> +			sdhci_err_stats_inc(host, CMD_TIMEOUT);
>> +		} else {
>>   			host->cmd->error = -EILSEQ;
>> -
>> +			if (!mmc_op_tuning(host->cmd->opcode))
>> +				sdhci_err_stats_inc(host, CMD_CRC);
>> +		}
>>   		/* Treat data command CRC error the same as data CRC error */
>>   		if (host->cmd->data &&
>>   		    (intmask & (SDHCI_INT_CRC | SDHCI_INT_TIMEOUT)) ==
>> @@ -3249,6 +3259,8 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *intmask_p)
>>   		int err = (auto_cmd_status & SDHCI_AUTO_CMD_TIMEOUT) ?
>>   			  -ETIMEDOUT :
>>   			  -EILSEQ;
> Blank line better here
>
>> +		sdhci_err_stats_inc(host, AUTO_CMD);
>> +
> This makes double blank line
>
>>   
>>   		if (mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) {
>>   			mrq->sbc->error = err;
>> @@ -3326,6 +3338,7 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
>>   			if (intmask & SDHCI_INT_DATA_TIMEOUT) {
>>   				host->data_cmd = NULL;
>>   				data_cmd->error = -ETIMEDOUT;
>> +				sdhci_err_stats_inc(host, CMD_TIMEOUT);
>>   				__sdhci_finish_mrq(host, data_cmd->mrq);
>>   				return;
>>   			}
>> @@ -3354,23 +3367,30 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
>>   
>>   		pr_err("%s: Got data interrupt 0x%08x even though no data operation was in progress.\n",
>>   		       mmc_hostname(host->mmc), (unsigned)intmask);
>> +		sdhci_err_stats_inc(host, UNEXPECTED_IRQ);
>>   		sdhci_dumpregs(host);
>>   
>>   		return;
>>   	}
>>   
>> -	if (intmask & SDHCI_INT_DATA_TIMEOUT)
>> +	if (intmask & SDHCI_INT_DATA_TIMEOUT) {
>>   		host->data->error = -ETIMEDOUT;
>> -	else if (intmask & SDHCI_INT_DATA_END_BIT)
>> +		sdhci_err_stats_inc(host, DAT_TIMEOUT);
>> +	} else if (intmask & SDHCI_INT_DATA_END_BIT) {
>>   		host->data->error = -EILSEQ;
>> -	else if ((intmask & SDHCI_INT_DATA_CRC) &&
>> +		if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))))
>> +			sdhci_err_stats_inc(host, DAT_CRC);
>> +	} else if ((intmask & SDHCI_INT_DATA_CRC) &&
>>   		SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
>> -			!= MMC_BUS_TEST_R)
>> +			!= MMC_BUS_TEST_R) {
>>   		host->data->error = -EILSEQ;
>> -	else if (intmask & SDHCI_INT_ADMA_ERROR) {
>> +		if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))))
>> +			sdhci_err_stats_inc(host, DAT_CRC);
>> +	} else if (intmask & SDHCI_INT_ADMA_ERROR) {
>>   		pr_err("%s: ADMA error: 0x%08x\n", mmc_hostname(host->mmc),
>>   		       intmask);
>>   		sdhci_adma_show_error(host);
>> +		sdhci_err_stats_inc(host, ADMA);
>>   		host->data->error = -EIO;
>>   		if (host->ops->adma_workaround)
>>   			host->ops->adma_workaround(host, intmask);
>> @@ -3568,6 +3588,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
>>   	if (unexpected) {
>>   		pr_err("%s: Unexpected interrupt 0x%08x.\n",
>>   			   mmc_hostname(host->mmc), unexpected);
>> +		sdhci_err_stats_inc(host, UNEXPECTED_IRQ);
>>   		sdhci_dumpregs(host);
>>   	}
>>   
>> @@ -3889,20 +3910,27 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
>>   	if (!host->cqe_on)
>>   		return false;
>>   
>> -	if (intmask & (SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC))
>> +	if (intmask & (SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC)) {
>>   		*cmd_error = -EILSEQ;
>> -	else if (intmask & SDHCI_INT_TIMEOUT)
>> +		if (!mmc_op_tuning(host->cmd->opcode))
>> +			sdhci_err_stats_inc(host, CMD_CRC);
>> +	} else if (intmask & SDHCI_INT_TIMEOUT) {
>>   		*cmd_error = -ETIMEDOUT;
>> -	else
>> +		sdhci_err_stats_inc(host, CMD_TIMEOUT);
>> +	} else
>>   		*cmd_error = 0;
>>   
>> -	if (intmask & (SDHCI_INT_DATA_END_BIT | SDHCI_INT_DATA_CRC))
>> +	if (intmask & (SDHCI_INT_DATA_END_BIT | SDHCI_INT_DATA_CRC)) {
>>   		*data_error = -EILSEQ;
>> -	else if (intmask & SDHCI_INT_DATA_TIMEOUT)
>> +		if (!mmc_op_tuning(host->cmd->opcode))
>> +			sdhci_err_stats_inc(host, DAT_CRC);
>> +	} else if (intmask & SDHCI_INT_DATA_TIMEOUT) {
>>   		*data_error = -ETIMEDOUT;
>> -	else if (intmask & SDHCI_INT_ADMA_ERROR)
>> +		sdhci_err_stats_inc(host, DAT_TIMEOUT);
>> +	} else if (intmask & SDHCI_INT_ADMA_ERROR) {
>>   		*data_error = -EIO;
>> -	else
>> +		sdhci_err_stats_inc(host, ADMA);
>> +	} else
>>   		*data_error = 0;
>>   
>>   	/* Clear selected interrupts. */
>> @@ -3918,6 +3946,7 @@ bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error,
>>   		sdhci_writel(host, intmask, SDHCI_INT_STATUS);
>>   		pr_err("%s: CQE: Unexpected interrupt 0x%08x.\n",
>>   		       mmc_hostname(host->mmc), intmask);
>> +		sdhci_err_stats_inc(host, UNEXPECTED_IRQ);
>>   		sdhci_dumpregs(host);
>>   	}
>>   
>> diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
>> index 6c689be..2c02ded 100644
>> --- a/drivers/mmc/host/sdhci.h
>> +++ b/drivers/mmc/host/sdhci.h
>> @@ -356,6 +356,9 @@ struct sdhci_adma2_64_desc {
>>    */
>>   #define MMC_CMD_TRANSFER_TIME	(10 * NSEC_PER_MSEC) /* max 10 ms */
>>   
>> +#define sdhci_err_stats_inc(host, err_name) \
>> +	mmc_debugfs_err_stats_inc((host)->mmc, MMC_ERR_##err_name)
>> +
>>   enum sdhci_cookie {
>>   	COOKIE_UNMAPPED,
>>   	COOKIE_PRE_MAPPED,	/* mapped by sdhci_pre_req() */
>> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
>> index d9a65c6..9c50bc4 100644
>> --- a/include/linux/mmc/mmc.h
>> +++ b/include/linux/mmc/mmc.h
>> @@ -99,6 +99,12 @@ static inline bool mmc_op_multi(u32 opcode)
>>   	       opcode == MMC_READ_MULTIPLE_BLOCK;
>>   }
>>   
>> +static inline bool mmc_op_tuning(u32 opcode)
>> +{
>> +	return opcode == MMC_SEND_TUNING_BLOCK ||
>> +			opcode == MMC_SEND_TUNING_BLOCK_HS200;
>> +}
>> +
>>   /*
>>    * MMC_SWITCH argument format:
>>    *

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH V6 1/5] mmc: core: Capture eMMC and SD card errors
  2022-05-23  7:14   ` Adrian Hunter
@ 2022-05-24  5:56     ` Sajida Bhanu (Temp)
  0 siblings, 0 replies; 14+ messages in thread
From: Sajida Bhanu (Temp) @ 2022-05-24  5:56 UTC (permalink / raw)
  To: Adrian Hunter, ulf.hansson, wsa+renesas, shawn.lin,
	yoshihiro.shimoda.uh, digetx, quic_asutoshd
  Cc: linux-arm-msm, linux-mmc, linux-kernel, quic_rampraka,
	quic_pragalla, quic_sartgarg, quic_nitirawa, quic_sayalil,
	Liangliang Lu, Bao D . Nguyen

On 5/23/2022 12:44 PM, Adrian Hunter wrote:
> On 18/05/22 10:02, Shaik Sajida Bhanu wrote:
>> Add changes to capture eMMC and SD card errors.
>> This is useful for debug and testing.
>>
>> Signed-off-by: Liangliang Lu <quic_luliang@quicinc.com>
>> Signed-off-by: Sayali Lokhande <quic_sayalil@quicinc.com>
>> Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
>> Signed-off-by: Ram Prakash Gupta <quic_rampraka@quicinc.com>
>> Signed-off-by: Shaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>
> Seems to need to be re-based on Ulf's next branch:
>
> 	git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git next
Sure Thank You for the review.
>
> Otherwise:
>
> Acked-by: Adrian Hunter <adrian.hunter@intel.com>
>
>> ---
>>   drivers/mmc/core/core.c  | 10 +++++++++-
>>   include/linux/mmc/host.h | 26 ++++++++++++++++++++++++++
>>   2 files changed, 35 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
>> index 368f104..5db5adf 100644
>> --- a/drivers/mmc/core/core.c
>> +++ b/drivers/mmc/core/core.c
>> @@ -943,9 +943,11 @@ int mmc_execute_tuning(struct mmc_card *card)
>>   	}
>>   
>>   	/* Only print error when we don't check for card removal */
>> -	if (!host->detect_change)
>> +	if (!host->detect_change) {
>>   		pr_err("%s: tuning execution failed: %d\n",
>>   			mmc_hostname(host), err);
>> +		mmc_debugfs_err_stats_inc(host, MMC_ERR_TUNING);
>> +	}
>>   
>>   	return err;
>>   }
>> @@ -2242,6 +2244,12 @@ void mmc_rescan(struct work_struct *work)
>>   		if (freqs[i] <= host->f_min)
>>   			break;
>>   	}
>> +
>> +	/*
>> +	 * Ignore the command timeout errors observed during
>> +	 * the card init as those are excepted.
>> +	 */
>> +	host->err_stats[MMC_ERR_CMD_TIMEOUT] = 0;
>>   	mmc_release_host(host);
>>   
>>    out:
>> diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
>> index 0c0c9a0..0d7c0f7 100644
>> --- a/include/linux/mmc/host.h
>> +++ b/include/linux/mmc/host.h
>> @@ -93,6 +93,25 @@ struct mmc_clk_phase_map {
>>   
>>   struct mmc_host;
>>   
>> +enum mmc_err_stat {
>> +	MMC_ERR_CMD_TIMEOUT,
>> +	MMC_ERR_CMD_CRC,
>> +	MMC_ERR_DAT_TIMEOUT,
>> +	MMC_ERR_DAT_CRC,
>> +	MMC_ERR_AUTO_CMD,
>> +	MMC_ERR_ADMA,
>> +	MMC_ERR_TUNING,
>> +	MMC_ERR_CMDQ_RED,
>> +	MMC_ERR_CMDQ_GCE,
>> +	MMC_ERR_CMDQ_ICCE,
>> +	MMC_ERR_REQ_TIMEOUT,
>> +	MMC_ERR_CMDQ_REQ_TIMEOUT,
>> +	MMC_ERR_ICE_CFG,
>> +	MMC_ERR_CTRL_TIMEOUT,
>> +	MMC_ERR_UNEXPECTED_IRQ,
>> +	MMC_ERR_MAX,
>> +};
>> +
>>   struct mmc_host_ops {
>>   	/*
>>   	 * It is optional for the host to implement pre_req and post_req in
>> @@ -498,6 +517,7 @@ struct mmc_host {
>>   	/* Host Software Queue support */
>>   	bool			hsq_enabled;
>>   
>> +	u32			err_stats[MMC_ERR_MAX];
>>   	unsigned long		private[] ____cacheline_aligned;
>>   };
>>   
>> @@ -632,6 +652,12 @@ static inline enum dma_data_direction mmc_get_dma_dir(struct mmc_data *data)
>>   	return data->flags & MMC_DATA_WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
>>   }
>>   
>> +static inline void mmc_debugfs_err_stats_inc(struct mmc_host *host,
>> +					     enum mmc_err_stat stat)
>> +{
>> +	host->err_stats[stat] += 1;
>> +}
>> +
>>   int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error);
>>   int mmc_send_abort_tuning(struct mmc_host *host, u32 opcode);
>>   

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-05-24  5:57 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-18  7:02 [PATCH V6 0/5] mmc: add error statistics for eMMC and SD card Shaik Sajida Bhanu
2022-05-18  7:02 ` [PATCH V6 1/5] mmc: core: Capture eMMC and SD card errors Shaik Sajida Bhanu
2022-05-23  7:14   ` Adrian Hunter
2022-05-24  5:56     ` Sajida Bhanu (Temp)
2022-05-18  7:02 ` [PATCH V6 2/5] mmc: sdhci: " Shaik Sajida Bhanu
2022-05-23  7:14   ` Adrian Hunter
2022-05-24  5:48     ` Sajida Bhanu (Temp)
2022-05-18  7:02 ` [PATCH V6 3/5] mmc: debugfs: Add debug fs entry for mmc driver Shaik Sajida Bhanu
2022-05-23  7:15   ` Adrian Hunter
2022-05-18  7:02 ` [PATCH V6 4/5] mmc: debugfs: Add debug fs error state " Shaik Sajida Bhanu
2022-05-23  7:15   ` Adrian Hunter
2022-05-24  5:19     ` Sajida Bhanu (Temp)
2022-05-18  7:02 ` [PATCH V6 5/5] mmc: cqhci: Capture eMMC and SD card errors Shaik Sajida Bhanu
2022-05-23  7:15   ` Adrian Hunter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.