mmc: core: Capture eMMC and SD card errors
authorShaik Sajida Bhanu <quic_c_sbhanu@quicinc.com>
Fri, 27 May 2022 17:53:52 +0000 (23:23 +0530)
committerUlf Hansson <ulf.hansson@linaro.org>
Tue, 12 Jul 2022 10:25:34 +0000 (12:25 +0200)
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>
Link: https://lore.kernel.org/r/1653674036-21829-2-git-send-email-quic_c_sbhanu@quicinc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/core/core.c
include/linux/mmc/host.h

index 4b70cbfc6d5de0cb81d13d16a879f80b0d617a2b..ef53a25788248ed6d57472f7a9cf26ee979f254e 100644 (file)
@@ -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;
 }
@@ -2244,6 +2246,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:
index c193c50ccd785e4cf064311352728f8a60664b42..eb8bc5b9b0b74d4a4ccfc3efb77e9ec217c7d513 100644 (file)
@@ -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
@@ -501,6 +520,7 @@ struct mmc_host {
        /* Host Software Queue support */
        bool                    hsq_enabled;
 
+       u32                     err_stats[MMC_ERR_MAX];
        unsigned long           private[] ____cacheline_aligned;
 };
 
@@ -635,6 +655,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);
 int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd);