0001
0002
0003
0004
0005
0006
0007 #include <linux/moduleparam.h>
0008 #include <linux/export.h>
0009 #include <linux/debugfs.h>
0010 #include <linux/fs.h>
0011 #include <linux/seq_file.h>
0012 #include <linux/slab.h>
0013 #include <linux/stat.h>
0014 #include <linux/fault-inject.h>
0015
0016 #include <linux/mmc/card.h>
0017 #include <linux/mmc/host.h>
0018
0019 #include "core.h"
0020 #include "card.h"
0021 #include "host.h"
0022 #include "mmc_ops.h"
0023
0024 #ifdef CONFIG_FAIL_MMC_REQUEST
0025
0026 static DECLARE_FAULT_ATTR(fail_default_attr);
0027 static char *fail_request;
0028 module_param(fail_request, charp, 0);
0029 MODULE_PARM_DESC(fail_request, "default fault injection attributes");
0030
0031 #endif
0032
0033
0034 static int mmc_ios_show(struct seq_file *s, void *data)
0035 {
0036 static const char *vdd_str[] = {
0037 [8] = "2.0",
0038 [9] = "2.1",
0039 [10] = "2.2",
0040 [11] = "2.3",
0041 [12] = "2.4",
0042 [13] = "2.5",
0043 [14] = "2.6",
0044 [15] = "2.7",
0045 [16] = "2.8",
0046 [17] = "2.9",
0047 [18] = "3.0",
0048 [19] = "3.1",
0049 [20] = "3.2",
0050 [21] = "3.3",
0051 [22] = "3.4",
0052 [23] = "3.5",
0053 [24] = "3.6",
0054 };
0055 struct mmc_host *host = s->private;
0056 struct mmc_ios *ios = &host->ios;
0057 const char *str;
0058
0059 seq_printf(s, "clock:\t\t%u Hz\n", ios->clock);
0060 if (host->actual_clock)
0061 seq_printf(s, "actual clock:\t%u Hz\n", host->actual_clock);
0062 seq_printf(s, "vdd:\t\t%u ", ios->vdd);
0063 if ((1 << ios->vdd) & MMC_VDD_165_195)
0064 seq_printf(s, "(1.65 - 1.95 V)\n");
0065 else if (ios->vdd < (ARRAY_SIZE(vdd_str) - 1)
0066 && vdd_str[ios->vdd] && vdd_str[ios->vdd + 1])
0067 seq_printf(s, "(%s ~ %s V)\n", vdd_str[ios->vdd],
0068 vdd_str[ios->vdd + 1]);
0069 else
0070 seq_printf(s, "(invalid)\n");
0071
0072 switch (ios->bus_mode) {
0073 case MMC_BUSMODE_OPENDRAIN:
0074 str = "open drain";
0075 break;
0076 case MMC_BUSMODE_PUSHPULL:
0077 str = "push-pull";
0078 break;
0079 default:
0080 str = "invalid";
0081 break;
0082 }
0083 seq_printf(s, "bus mode:\t%u (%s)\n", ios->bus_mode, str);
0084
0085 switch (ios->chip_select) {
0086 case MMC_CS_DONTCARE:
0087 str = "don't care";
0088 break;
0089 case MMC_CS_HIGH:
0090 str = "active high";
0091 break;
0092 case MMC_CS_LOW:
0093 str = "active low";
0094 break;
0095 default:
0096 str = "invalid";
0097 break;
0098 }
0099 seq_printf(s, "chip select:\t%u (%s)\n", ios->chip_select, str);
0100
0101 switch (ios->power_mode) {
0102 case MMC_POWER_OFF:
0103 str = "off";
0104 break;
0105 case MMC_POWER_UP:
0106 str = "up";
0107 break;
0108 case MMC_POWER_ON:
0109 str = "on";
0110 break;
0111 default:
0112 str = "invalid";
0113 break;
0114 }
0115 seq_printf(s, "power mode:\t%u (%s)\n", ios->power_mode, str);
0116 seq_printf(s, "bus width:\t%u (%u bits)\n",
0117 ios->bus_width, 1 << ios->bus_width);
0118
0119 switch (ios->timing) {
0120 case MMC_TIMING_LEGACY:
0121 str = "legacy";
0122 break;
0123 case MMC_TIMING_MMC_HS:
0124 str = "mmc high-speed";
0125 break;
0126 case MMC_TIMING_SD_HS:
0127 str = "sd high-speed";
0128 break;
0129 case MMC_TIMING_UHS_SDR12:
0130 str = "sd uhs SDR12";
0131 break;
0132 case MMC_TIMING_UHS_SDR25:
0133 str = "sd uhs SDR25";
0134 break;
0135 case MMC_TIMING_UHS_SDR50:
0136 str = "sd uhs SDR50";
0137 break;
0138 case MMC_TIMING_UHS_SDR104:
0139 str = "sd uhs SDR104";
0140 break;
0141 case MMC_TIMING_UHS_DDR50:
0142 str = "sd uhs DDR50";
0143 break;
0144 case MMC_TIMING_MMC_DDR52:
0145 str = "mmc DDR52";
0146 break;
0147 case MMC_TIMING_MMC_HS200:
0148 str = "mmc HS200";
0149 break;
0150 case MMC_TIMING_MMC_HS400:
0151 str = mmc_card_hs400es(host->card) ?
0152 "mmc HS400 enhanced strobe" : "mmc HS400";
0153 break;
0154 default:
0155 str = "invalid";
0156 break;
0157 }
0158 seq_printf(s, "timing spec:\t%u (%s)\n", ios->timing, str);
0159
0160 switch (ios->signal_voltage) {
0161 case MMC_SIGNAL_VOLTAGE_330:
0162 str = "3.30 V";
0163 break;
0164 case MMC_SIGNAL_VOLTAGE_180:
0165 str = "1.80 V";
0166 break;
0167 case MMC_SIGNAL_VOLTAGE_120:
0168 str = "1.20 V";
0169 break;
0170 default:
0171 str = "invalid";
0172 break;
0173 }
0174 seq_printf(s, "signal voltage:\t%u (%s)\n", ios->signal_voltage, str);
0175
0176 switch (ios->drv_type) {
0177 case MMC_SET_DRIVER_TYPE_A:
0178 str = "driver type A";
0179 break;
0180 case MMC_SET_DRIVER_TYPE_B:
0181 str = "driver type B";
0182 break;
0183 case MMC_SET_DRIVER_TYPE_C:
0184 str = "driver type C";
0185 break;
0186 case MMC_SET_DRIVER_TYPE_D:
0187 str = "driver type D";
0188 break;
0189 default:
0190 str = "invalid";
0191 break;
0192 }
0193 seq_printf(s, "driver type:\t%u (%s)\n", ios->drv_type, str);
0194
0195 return 0;
0196 }
0197 DEFINE_SHOW_ATTRIBUTE(mmc_ios);
0198
0199 static int mmc_clock_opt_get(void *data, u64 *val)
0200 {
0201 struct mmc_host *host = data;
0202
0203 *val = host->ios.clock;
0204
0205 return 0;
0206 }
0207
0208 static int mmc_clock_opt_set(void *data, u64 val)
0209 {
0210 struct mmc_host *host = data;
0211
0212
0213 if (val != 0 && (val > host->f_max || val < host->f_min))
0214 return -EINVAL;
0215
0216 mmc_claim_host(host);
0217 mmc_set_clock(host, (unsigned int) val);
0218 mmc_release_host(host);
0219
0220 return 0;
0221 }
0222
0223 DEFINE_DEBUGFS_ATTRIBUTE(mmc_clock_fops, mmc_clock_opt_get, mmc_clock_opt_set,
0224 "%llu\n");
0225
0226 static int mmc_err_state_get(void *data, u64 *val)
0227 {
0228 struct mmc_host *host = data;
0229 int i;
0230
0231 if (!host)
0232 return -EINVAL;
0233
0234 *val = 0;
0235 for (i = 0; i < MMC_ERR_MAX; i++) {
0236 if (host->err_stats[i]) {
0237 *val = 1;
0238 break;
0239 }
0240 }
0241
0242 return 0;
0243 }
0244
0245 DEFINE_DEBUGFS_ATTRIBUTE(mmc_err_state, mmc_err_state_get, NULL, "%llu\n");
0246
0247 static int mmc_err_stats_show(struct seq_file *file, void *data)
0248 {
0249 struct mmc_host *host = (struct mmc_host *)file->private;
0250 const char *desc[MMC_ERR_MAX] = {
0251 [MMC_ERR_CMD_TIMEOUT] = "Command Timeout Occurred",
0252 [MMC_ERR_CMD_CRC] = "Command CRC Errors Occurred",
0253 [MMC_ERR_DAT_TIMEOUT] = "Data Timeout Occurred",
0254 [MMC_ERR_DAT_CRC] = "Data CRC Errors Occurred",
0255 [MMC_ERR_AUTO_CMD] = "Auto-Cmd Error Occurred",
0256 [MMC_ERR_ADMA] = "ADMA Error Occurred",
0257 [MMC_ERR_TUNING] = "Tuning Error Occurred",
0258 [MMC_ERR_CMDQ_RED] = "CMDQ RED Errors",
0259 [MMC_ERR_CMDQ_GCE] = "CMDQ GCE Errors",
0260 [MMC_ERR_CMDQ_ICCE] = "CMDQ ICCE Errors",
0261 [MMC_ERR_REQ_TIMEOUT] = "Request Timedout",
0262 [MMC_ERR_CMDQ_REQ_TIMEOUT] = "CMDQ Request Timedout",
0263 [MMC_ERR_ICE_CFG] = "ICE Config Errors",
0264 [MMC_ERR_CTRL_TIMEOUT] = "Controller Timedout errors",
0265 [MMC_ERR_UNEXPECTED_IRQ] = "Unexpected IRQ errors",
0266 };
0267 int i;
0268
0269 for (i = 0; i < MMC_ERR_MAX; i++) {
0270 if (desc[i])
0271 seq_printf(file, "# %s:\t %d\n",
0272 desc[i], host->err_stats[i]);
0273 }
0274
0275 return 0;
0276 }
0277
0278 static int mmc_err_stats_open(struct inode *inode, struct file *file)
0279 {
0280 return single_open(file, mmc_err_stats_show, inode->i_private);
0281 }
0282
0283 static ssize_t mmc_err_stats_write(struct file *filp, const char __user *ubuf,
0284 size_t cnt, loff_t *ppos)
0285 {
0286 struct mmc_host *host = filp->f_mapping->host->i_private;
0287
0288 pr_debug("%s: Resetting MMC error statistics\n", __func__);
0289 memset(host->err_stats, 0, sizeof(host->err_stats));
0290
0291 return cnt;
0292 }
0293
0294 static const struct file_operations mmc_err_stats_fops = {
0295 .open = mmc_err_stats_open,
0296 .read = seq_read,
0297 .write = mmc_err_stats_write,
0298 .release = single_release,
0299 };
0300
0301 void mmc_add_host_debugfs(struct mmc_host *host)
0302 {
0303 struct dentry *root;
0304
0305 root = debugfs_create_dir(mmc_hostname(host), NULL);
0306 host->debugfs_root = root;
0307
0308 debugfs_create_file("ios", S_IRUSR, root, host, &mmc_ios_fops);
0309 debugfs_create_x32("caps", S_IRUSR, root, &host->caps);
0310 debugfs_create_x32("caps2", S_IRUSR, root, &host->caps2);
0311 debugfs_create_file_unsafe("clock", S_IRUSR | S_IWUSR, root, host,
0312 &mmc_clock_fops);
0313
0314 debugfs_create_file_unsafe("err_state", 0600, root, host,
0315 &mmc_err_state);
0316 debugfs_create_file("err_stats", 0600, root, host,
0317 &mmc_err_stats_fops);
0318
0319 #ifdef CONFIG_FAIL_MMC_REQUEST
0320 if (fail_request)
0321 setup_fault_attr(&fail_default_attr, fail_request);
0322 host->fail_mmc_request = fail_default_attr;
0323 fault_create_debugfs_attr("fail_mmc_request", root,
0324 &host->fail_mmc_request);
0325 #endif
0326 }
0327
0328 void mmc_remove_host_debugfs(struct mmc_host *host)
0329 {
0330 debugfs_remove_recursive(host->debugfs_root);
0331 }
0332
0333 void mmc_add_card_debugfs(struct mmc_card *card)
0334 {
0335 struct mmc_host *host = card->host;
0336 struct dentry *root;
0337
0338 if (!host->debugfs_root)
0339 return;
0340
0341 root = debugfs_create_dir(mmc_card_id(card), host->debugfs_root);
0342 card->debugfs_root = root;
0343
0344 debugfs_create_x32("state", S_IRUSR, root, &card->state);
0345 }
0346
0347 void mmc_remove_card_debugfs(struct mmc_card *card)
0348 {
0349 debugfs_remove_recursive(card->debugfs_root);
0350 card->debugfs_root = NULL;
0351 }