Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Debugfs support for hosts and cards |
| 3 | * |
| 4 | * Copyright (C) 2008 Atmel Corporation |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
Stephen Rothwell | 3f102ae | 2011-10-09 10:35:16 -0400 | [diff] [blame] | 10 | #include <linux/moduleparam.h> |
Paul Gortmaker | 3ef77af | 2011-07-10 12:42:00 -0400 | [diff] [blame] | 11 | #include <linux/export.h> |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 12 | #include <linux/debugfs.h> |
| 13 | #include <linux/fs.h> |
| 14 | #include <linux/seq_file.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 16 | #include <linux/stat.h> |
Per Forlin | 1b676f7 | 2011-08-19 14:52:37 +0200 | [diff] [blame] | 17 | #include <linux/fault-inject.h> |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 18 | |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 19 | #include <linux/mmc/card.h> |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 20 | #include <linux/mmc/host.h> |
| 21 | |
| 22 | #include "core.h" |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 23 | #include "mmc_ops.h" |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 24 | |
Per Forlin | 34f5050 | 2011-09-13 23:03:29 +0200 | [diff] [blame] | 25 | #ifdef CONFIG_FAIL_MMC_REQUEST |
| 26 | |
| 27 | static DECLARE_FAULT_ATTR(fail_default_attr); |
| 28 | static char *fail_request; |
| 29 | module_param(fail_request, charp, 0); |
| 30 | |
| 31 | #endif /* CONFIG_FAIL_MMC_REQUEST */ |
| 32 | |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 33 | /* The debugfs functions are optimized away when CONFIG_DEBUG_FS isn't set. */ |
| 34 | static int mmc_ios_show(struct seq_file *s, void *data) |
| 35 | { |
| 36 | static const char *vdd_str[] = { |
| 37 | [8] = "2.0", |
| 38 | [9] = "2.1", |
| 39 | [10] = "2.2", |
| 40 | [11] = "2.3", |
| 41 | [12] = "2.4", |
| 42 | [13] = "2.5", |
| 43 | [14] = "2.6", |
| 44 | [15] = "2.7", |
| 45 | [16] = "2.8", |
| 46 | [17] = "2.9", |
| 47 | [18] = "3.0", |
| 48 | [19] = "3.1", |
| 49 | [20] = "3.2", |
| 50 | [21] = "3.3", |
| 51 | [22] = "3.4", |
| 52 | [23] = "3.5", |
| 53 | [24] = "3.6", |
| 54 | }; |
| 55 | struct mmc_host *host = s->private; |
| 56 | struct mmc_ios *ios = &host->ios; |
| 57 | const char *str; |
| 58 | |
| 59 | seq_printf(s, "clock:\t\t%u Hz\n", ios->clock); |
Giuseppe CAVALLARO | df16219 | 2011-11-04 13:53:19 +0100 | [diff] [blame] | 60 | if (host->actual_clock) |
| 61 | seq_printf(s, "actual clock:\t%u Hz\n", host->actual_clock); |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 62 | seq_printf(s, "vdd:\t\t%u ", ios->vdd); |
| 63 | if ((1 << ios->vdd) & MMC_VDD_165_195) |
| 64 | seq_printf(s, "(1.65 - 1.95 V)\n"); |
| 65 | else if (ios->vdd < (ARRAY_SIZE(vdd_str) - 1) |
| 66 | && vdd_str[ios->vdd] && vdd_str[ios->vdd + 1]) |
| 67 | seq_printf(s, "(%s ~ %s V)\n", vdd_str[ios->vdd], |
| 68 | vdd_str[ios->vdd + 1]); |
| 69 | else |
| 70 | seq_printf(s, "(invalid)\n"); |
| 71 | |
| 72 | switch (ios->bus_mode) { |
| 73 | case MMC_BUSMODE_OPENDRAIN: |
| 74 | str = "open drain"; |
| 75 | break; |
| 76 | case MMC_BUSMODE_PUSHPULL: |
| 77 | str = "push-pull"; |
| 78 | break; |
| 79 | default: |
| 80 | str = "invalid"; |
| 81 | break; |
| 82 | } |
| 83 | seq_printf(s, "bus mode:\t%u (%s)\n", ios->bus_mode, str); |
| 84 | |
| 85 | switch (ios->chip_select) { |
| 86 | case MMC_CS_DONTCARE: |
| 87 | str = "don't care"; |
| 88 | break; |
| 89 | case MMC_CS_HIGH: |
| 90 | str = "active high"; |
| 91 | break; |
| 92 | case MMC_CS_LOW: |
| 93 | str = "active low"; |
| 94 | break; |
| 95 | default: |
| 96 | str = "invalid"; |
| 97 | break; |
| 98 | } |
| 99 | seq_printf(s, "chip select:\t%u (%s)\n", ios->chip_select, str); |
| 100 | |
| 101 | switch (ios->power_mode) { |
| 102 | case MMC_POWER_OFF: |
| 103 | str = "off"; |
| 104 | break; |
| 105 | case MMC_POWER_UP: |
| 106 | str = "up"; |
| 107 | break; |
| 108 | case MMC_POWER_ON: |
| 109 | str = "on"; |
| 110 | break; |
| 111 | default: |
| 112 | str = "invalid"; |
| 113 | break; |
| 114 | } |
| 115 | seq_printf(s, "power mode:\t%u (%s)\n", ios->power_mode, str); |
| 116 | seq_printf(s, "bus width:\t%u (%u bits)\n", |
| 117 | ios->bus_width, 1 << ios->bus_width); |
| 118 | |
| 119 | switch (ios->timing) { |
| 120 | case MMC_TIMING_LEGACY: |
| 121 | str = "legacy"; |
| 122 | break; |
| 123 | case MMC_TIMING_MMC_HS: |
| 124 | str = "mmc high-speed"; |
| 125 | break; |
| 126 | case MMC_TIMING_SD_HS: |
| 127 | str = "sd high-speed"; |
| 128 | break; |
Aaron Lu | cd8a366 | 2011-09-02 16:06:08 +0800 | [diff] [blame] | 129 | case MMC_TIMING_UHS_SDR50: |
| 130 | str = "sd uhs SDR50"; |
| 131 | break; |
| 132 | case MMC_TIMING_UHS_SDR104: |
| 133 | str = "sd uhs SDR104"; |
| 134 | break; |
| 135 | case MMC_TIMING_UHS_DDR50: |
| 136 | str = "sd uhs DDR50"; |
| 137 | break; |
Girish K S | a4924c7 | 2012-01-11 14:04:52 -0500 | [diff] [blame] | 138 | case MMC_TIMING_MMC_HS200: |
| 139 | str = "mmc high-speed SDR200"; |
| 140 | break; |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 141 | default: |
| 142 | str = "invalid"; |
| 143 | break; |
| 144 | } |
| 145 | seq_printf(s, "timing spec:\t%u (%s)\n", ios->timing, str); |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | static int mmc_ios_open(struct inode *inode, struct file *file) |
| 151 | { |
| 152 | return single_open(file, mmc_ios_show, inode->i_private); |
| 153 | } |
| 154 | |
| 155 | static const struct file_operations mmc_ios_fops = { |
| 156 | .open = mmc_ios_open, |
| 157 | .read = seq_read, |
| 158 | .llseek = seq_lseek, |
| 159 | .release = single_release, |
| 160 | }; |
| 161 | |
Andy Shevchenko | 703aae3 | 2010-10-13 11:22:22 +0300 | [diff] [blame] | 162 | static int mmc_clock_opt_get(void *data, u64 *val) |
| 163 | { |
| 164 | struct mmc_host *host = data; |
| 165 | |
| 166 | *val = host->ios.clock; |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | static int mmc_clock_opt_set(void *data, u64 val) |
| 172 | { |
| 173 | struct mmc_host *host = data; |
| 174 | |
| 175 | /* We need this check due to input value is u64 */ |
| 176 | if (val > host->f_max) |
| 177 | return -EINVAL; |
| 178 | |
Sahitya Tummala | 2245913 | 2013-05-01 11:14:51 +0530 | [diff] [blame] | 179 | mmc_rpm_hold(host, &host->class_dev); |
Andy Shevchenko | 703aae3 | 2010-10-13 11:22:22 +0300 | [diff] [blame] | 180 | mmc_claim_host(host); |
| 181 | mmc_set_clock(host, (unsigned int) val); |
| 182 | mmc_release_host(host); |
Sahitya Tummala | 2245913 | 2013-05-01 11:14:51 +0530 | [diff] [blame] | 183 | mmc_rpm_release(host, &host->class_dev); |
Andy Shevchenko | 703aae3 | 2010-10-13 11:22:22 +0300 | [diff] [blame] | 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | DEFINE_SIMPLE_ATTRIBUTE(mmc_clock_fops, mmc_clock_opt_get, mmc_clock_opt_set, |
| 189 | "%llu\n"); |
| 190 | |
Sujit Reddy Thumma | 2743a51 | 2012-11-09 18:32:32 +0530 | [diff] [blame] | 191 | static int mmc_max_clock_get(void *data, u64 *val) |
| 192 | { |
| 193 | struct mmc_host *host = data; |
| 194 | |
| 195 | if (!host) |
| 196 | return -EINVAL; |
| 197 | |
| 198 | *val = host->f_max; |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static int mmc_max_clock_set(void *data, u64 val) |
| 204 | { |
| 205 | struct mmc_host *host = data; |
| 206 | int err = -EINVAL; |
| 207 | unsigned long freq = val; |
| 208 | unsigned int old_freq; |
| 209 | |
| 210 | if (!host || (val < host->f_min)) |
| 211 | goto out; |
| 212 | |
Sahitya Tummala | 2245913 | 2013-05-01 11:14:51 +0530 | [diff] [blame] | 213 | mmc_rpm_hold(host, &host->class_dev); |
Sujit Reddy Thumma | 2743a51 | 2012-11-09 18:32:32 +0530 | [diff] [blame] | 214 | mmc_claim_host(host); |
| 215 | if (host->bus_ops && host->bus_ops->change_bus_speed) { |
| 216 | old_freq = host->f_max; |
| 217 | host->f_max = freq; |
| 218 | |
| 219 | err = host->bus_ops->change_bus_speed(host, &freq); |
| 220 | |
| 221 | if (err) |
| 222 | host->f_max = old_freq; |
| 223 | } |
| 224 | mmc_release_host(host); |
Sahitya Tummala | 2245913 | 2013-05-01 11:14:51 +0530 | [diff] [blame] | 225 | mmc_rpm_release(host, &host->class_dev); |
Sujit Reddy Thumma | 2743a51 | 2012-11-09 18:32:32 +0530 | [diff] [blame] | 226 | out: |
| 227 | return err; |
| 228 | } |
| 229 | |
| 230 | DEFINE_SIMPLE_ATTRIBUTE(mmc_max_clock_fops, mmc_max_clock_get, |
| 231 | mmc_max_clock_set, "%llu\n"); |
| 232 | |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 233 | void mmc_add_host_debugfs(struct mmc_host *host) |
| 234 | { |
| 235 | struct dentry *root; |
| 236 | |
| 237 | root = debugfs_create_dir(mmc_hostname(host), NULL); |
| 238 | if (IS_ERR(root)) |
| 239 | /* Don't complain -- debugfs just isn't enabled */ |
| 240 | return; |
| 241 | if (!root) |
| 242 | /* Complain -- debugfs is enabled, but it failed to |
| 243 | * create the directory. */ |
| 244 | goto err_root; |
| 245 | |
| 246 | host->debugfs_root = root; |
| 247 | |
| 248 | if (!debugfs_create_file("ios", S_IRUSR, root, host, &mmc_ios_fops)) |
Andy Shevchenko | 703aae3 | 2010-10-13 11:22:22 +0300 | [diff] [blame] | 249 | goto err_node; |
| 250 | |
| 251 | if (!debugfs_create_file("clock", S_IRUSR | S_IWUSR, root, host, |
| 252 | &mmc_clock_fops)) |
| 253 | goto err_node; |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 254 | |
Sujit Reddy Thumma | 2743a51 | 2012-11-09 18:32:32 +0530 | [diff] [blame] | 255 | if (!debugfs_create_file("max_clock", S_IRUSR | S_IWUSR, root, host, |
| 256 | &mmc_max_clock_fops)) |
| 257 | goto err_node; |
| 258 | |
Linus Walleij | 0456683 | 2010-11-08 21:36:50 -0500 | [diff] [blame] | 259 | #ifdef CONFIG_MMC_CLKGATE |
| 260 | if (!debugfs_create_u32("clk_delay", (S_IRUSR | S_IWUSR), |
| 261 | root, &host->clk_delay)) |
| 262 | goto err_node; |
| 263 | #endif |
Per Forlin | 1b676f7 | 2011-08-19 14:52:37 +0200 | [diff] [blame] | 264 | #ifdef CONFIG_FAIL_MMC_REQUEST |
Per Forlin | 34f5050 | 2011-09-13 23:03:29 +0200 | [diff] [blame] | 265 | if (fail_request) |
| 266 | setup_fault_attr(&fail_default_attr, fail_request); |
| 267 | host->fail_mmc_request = fail_default_attr; |
Per Forlin | 1b676f7 | 2011-08-19 14:52:37 +0200 | [diff] [blame] | 268 | if (IS_ERR(fault_create_debugfs_attr("fail_mmc_request", |
| 269 | root, |
| 270 | &host->fail_mmc_request))) |
| 271 | goto err_node; |
| 272 | #endif |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 273 | return; |
| 274 | |
Andy Shevchenko | 703aae3 | 2010-10-13 11:22:22 +0300 | [diff] [blame] | 275 | err_node: |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 276 | debugfs_remove_recursive(root); |
| 277 | host->debugfs_root = NULL; |
| 278 | err_root: |
| 279 | dev_err(&host->class_dev, "failed to initialize debugfs\n"); |
| 280 | } |
| 281 | |
| 282 | void mmc_remove_host_debugfs(struct mmc_host *host) |
| 283 | { |
| 284 | debugfs_remove_recursive(host->debugfs_root); |
| 285 | } |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 286 | |
| 287 | static int mmc_dbg_card_status_get(void *data, u64 *val) |
| 288 | { |
| 289 | struct mmc_card *card = data; |
| 290 | u32 status; |
| 291 | int ret; |
| 292 | |
Sahitya Tummala | 2245913 | 2013-05-01 11:14:51 +0530 | [diff] [blame] | 293 | mmc_rpm_hold(card->host, &card->dev); |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 294 | mmc_claim_host(card->host); |
| 295 | |
| 296 | ret = mmc_send_status(data, &status); |
| 297 | if (!ret) |
| 298 | *val = status; |
| 299 | |
| 300 | mmc_release_host(card->host); |
Sahitya Tummala | 2245913 | 2013-05-01 11:14:51 +0530 | [diff] [blame] | 301 | mmc_rpm_release(card->host, &card->dev); |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 302 | |
| 303 | return ret; |
| 304 | } |
| 305 | DEFINE_SIMPLE_ATTRIBUTE(mmc_dbg_card_status_fops, mmc_dbg_card_status_get, |
| 306 | NULL, "%08llx\n"); |
| 307 | |
Adrian Hunter | 736bb6b | 2009-02-11 14:52:20 +0200 | [diff] [blame] | 308 | #define EXT_CSD_STR_LEN 1025 |
| 309 | |
| 310 | static int mmc_ext_csd_open(struct inode *inode, struct file *filp) |
| 311 | { |
| 312 | struct mmc_card *card = inode->i_private; |
| 313 | char *buf; |
| 314 | ssize_t n = 0; |
| 315 | u8 *ext_csd; |
| 316 | int err, i; |
| 317 | |
| 318 | buf = kmalloc(EXT_CSD_STR_LEN + 1, GFP_KERNEL); |
| 319 | if (!buf) |
| 320 | return -ENOMEM; |
| 321 | |
| 322 | ext_csd = kmalloc(512, GFP_KERNEL); |
| 323 | if (!ext_csd) { |
| 324 | err = -ENOMEM; |
| 325 | goto out_free; |
| 326 | } |
| 327 | |
Sahitya Tummala | 2245913 | 2013-05-01 11:14:51 +0530 | [diff] [blame] | 328 | mmc_rpm_hold(card->host, &card->dev); |
Adrian Hunter | 736bb6b | 2009-02-11 14:52:20 +0200 | [diff] [blame] | 329 | mmc_claim_host(card->host); |
| 330 | err = mmc_send_ext_csd(card, ext_csd); |
| 331 | mmc_release_host(card->host); |
Sahitya Tummala | 2245913 | 2013-05-01 11:14:51 +0530 | [diff] [blame] | 332 | mmc_rpm_release(card->host, &card->dev); |
Adrian Hunter | 736bb6b | 2009-02-11 14:52:20 +0200 | [diff] [blame] | 333 | if (err) |
| 334 | goto out_free; |
| 335 | |
| 336 | for (i = 511; i >= 0; i--) |
| 337 | n += sprintf(buf + n, "%02x", ext_csd[i]); |
| 338 | n += sprintf(buf + n, "\n"); |
| 339 | BUG_ON(n != EXT_CSD_STR_LEN); |
| 340 | |
| 341 | filp->private_data = buf; |
| 342 | kfree(ext_csd); |
| 343 | return 0; |
| 344 | |
| 345 | out_free: |
| 346 | kfree(buf); |
| 347 | kfree(ext_csd); |
| 348 | return err; |
| 349 | } |
| 350 | |
| 351 | static ssize_t mmc_ext_csd_read(struct file *filp, char __user *ubuf, |
| 352 | size_t cnt, loff_t *ppos) |
| 353 | { |
| 354 | char *buf = filp->private_data; |
| 355 | |
| 356 | return simple_read_from_buffer(ubuf, cnt, ppos, |
| 357 | buf, EXT_CSD_STR_LEN); |
| 358 | } |
| 359 | |
| 360 | static int mmc_ext_csd_release(struct inode *inode, struct file *file) |
| 361 | { |
| 362 | kfree(file->private_data); |
| 363 | return 0; |
| 364 | } |
| 365 | |
Alexey Dobriyan | 828c095 | 2009-10-01 15:43:56 -0700 | [diff] [blame] | 366 | static const struct file_operations mmc_dbg_ext_csd_fops = { |
Adrian Hunter | 736bb6b | 2009-02-11 14:52:20 +0200 | [diff] [blame] | 367 | .open = mmc_ext_csd_open, |
| 368 | .read = mmc_ext_csd_read, |
| 369 | .release = mmc_ext_csd_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 370 | .llseek = default_llseek, |
Adrian Hunter | 736bb6b | 2009-02-11 14:52:20 +0200 | [diff] [blame] | 371 | }; |
| 372 | |
Tatyana Brokhman | 464fbe1 | 2012-10-07 10:33:13 +0200 | [diff] [blame] | 373 | static int mmc_wr_pack_stats_open(struct inode *inode, struct file *filp) |
| 374 | { |
| 375 | struct mmc_card *card = inode->i_private; |
| 376 | |
| 377 | filp->private_data = card; |
| 378 | card->wr_pack_stats.print_in_read = 1; |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | #define TEMP_BUF_SIZE 256 |
| 383 | static ssize_t mmc_wr_pack_stats_read(struct file *filp, char __user *ubuf, |
| 384 | size_t cnt, loff_t *ppos) |
| 385 | { |
| 386 | struct mmc_card *card = filp->private_data; |
| 387 | struct mmc_wr_pack_stats *pack_stats; |
| 388 | int i; |
| 389 | int max_num_of_packed_reqs = 0; |
| 390 | char *temp_buf; |
| 391 | |
| 392 | if (!card) |
| 393 | return cnt; |
| 394 | |
| 395 | if (!card->wr_pack_stats.print_in_read) |
| 396 | return 0; |
| 397 | |
| 398 | if (!card->wr_pack_stats.enabled) { |
| 399 | pr_info("%s: write packing statistics are disabled\n", |
| 400 | mmc_hostname(card->host)); |
| 401 | goto exit; |
| 402 | } |
| 403 | |
| 404 | pack_stats = &card->wr_pack_stats; |
| 405 | |
| 406 | if (!pack_stats->packing_events) { |
| 407 | pr_info("%s: NULL packing_events\n", mmc_hostname(card->host)); |
| 408 | goto exit; |
| 409 | } |
| 410 | |
| 411 | max_num_of_packed_reqs = card->ext_csd.max_packed_writes; |
| 412 | |
| 413 | temp_buf = kmalloc(TEMP_BUF_SIZE, GFP_KERNEL); |
| 414 | if (!temp_buf) |
| 415 | goto exit; |
| 416 | |
| 417 | spin_lock(&pack_stats->lock); |
| 418 | |
| 419 | snprintf(temp_buf, TEMP_BUF_SIZE, "%s: write packing statistics:\n", |
| 420 | mmc_hostname(card->host)); |
| 421 | strlcat(ubuf, temp_buf, cnt); |
| 422 | |
| 423 | for (i = 1 ; i <= max_num_of_packed_reqs ; ++i) { |
| 424 | if (pack_stats->packing_events[i]) { |
| 425 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 426 | "%s: Packed %d reqs - %d times\n", |
| 427 | mmc_hostname(card->host), i, |
| 428 | pack_stats->packing_events[i]); |
| 429 | strlcat(ubuf, temp_buf, cnt); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 434 | "%s: stopped packing due to the following reasons:\n", |
| 435 | mmc_hostname(card->host)); |
| 436 | strlcat(ubuf, temp_buf, cnt); |
| 437 | |
| 438 | if (pack_stats->pack_stop_reason[EXCEEDS_SEGMENTS]) { |
| 439 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 440 | "%s: %d times: exceed max num of segments\n", |
| 441 | mmc_hostname(card->host), |
| 442 | pack_stats->pack_stop_reason[EXCEEDS_SEGMENTS]); |
| 443 | strlcat(ubuf, temp_buf, cnt); |
| 444 | } |
| 445 | if (pack_stats->pack_stop_reason[EXCEEDS_SECTORS]) { |
| 446 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 447 | "%s: %d times: exceed max num of sectors\n", |
| 448 | mmc_hostname(card->host), |
| 449 | pack_stats->pack_stop_reason[EXCEEDS_SECTORS]); |
| 450 | strlcat(ubuf, temp_buf, cnt); |
| 451 | } |
| 452 | if (pack_stats->pack_stop_reason[WRONG_DATA_DIR]) { |
| 453 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 454 | "%s: %d times: wrong data direction\n", |
| 455 | mmc_hostname(card->host), |
| 456 | pack_stats->pack_stop_reason[WRONG_DATA_DIR]); |
| 457 | strlcat(ubuf, temp_buf, cnt); |
| 458 | } |
| 459 | if (pack_stats->pack_stop_reason[FLUSH_OR_DISCARD]) { |
| 460 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 461 | "%s: %d times: flush or discard\n", |
| 462 | mmc_hostname(card->host), |
| 463 | pack_stats->pack_stop_reason[FLUSH_OR_DISCARD]); |
| 464 | strlcat(ubuf, temp_buf, cnt); |
| 465 | } |
| 466 | if (pack_stats->pack_stop_reason[EMPTY_QUEUE]) { |
| 467 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 468 | "%s: %d times: empty queue\n", |
| 469 | mmc_hostname(card->host), |
| 470 | pack_stats->pack_stop_reason[EMPTY_QUEUE]); |
| 471 | strlcat(ubuf, temp_buf, cnt); |
| 472 | } |
| 473 | if (pack_stats->pack_stop_reason[REL_WRITE]) { |
| 474 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 475 | "%s: %d times: rel write\n", |
| 476 | mmc_hostname(card->host), |
| 477 | pack_stats->pack_stop_reason[REL_WRITE]); |
| 478 | strlcat(ubuf, temp_buf, cnt); |
| 479 | } |
| 480 | if (pack_stats->pack_stop_reason[THRESHOLD]) { |
| 481 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 482 | "%s: %d times: Threshold\n", |
| 483 | mmc_hostname(card->host), |
| 484 | pack_stats->pack_stop_reason[THRESHOLD]); |
| 485 | strlcat(ubuf, temp_buf, cnt); |
| 486 | } |
| 487 | |
Tatyana Brokhman | 1718ef2 | 2012-10-04 11:11:08 +0200 | [diff] [blame] | 488 | if (pack_stats->pack_stop_reason[LARGE_SEC_ALIGN]) { |
| 489 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 490 | "%s: %d times: Large sector alignment\n", |
| 491 | mmc_hostname(card->host), |
| 492 | pack_stats->pack_stop_reason[LARGE_SEC_ALIGN]); |
| 493 | strlcat(ubuf, temp_buf, cnt); |
| 494 | } |
Maya Erez | 64d1246 | 2013-01-06 10:19:38 +0200 | [diff] [blame] | 495 | if (pack_stats->pack_stop_reason[RANDOM]) { |
| 496 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 497 | "%s: %d times: random request\n", |
| 498 | mmc_hostname(card->host), |
| 499 | pack_stats->pack_stop_reason[RANDOM]); |
| 500 | strlcat(ubuf, temp_buf, cnt); |
| 501 | } |
Konstantin Dorfman | b083297 | 2013-02-05 16:26:19 +0200 | [diff] [blame] | 502 | if (pack_stats->pack_stop_reason[FUA]) { |
| 503 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 504 | "%s: %d times: fua request\n", |
| 505 | mmc_hostname(card->host), |
| 506 | pack_stats->pack_stop_reason[FUA]); |
| 507 | strlcat(ubuf, temp_buf, cnt); |
| 508 | } |
Tatyana Brokhman | 1718ef2 | 2012-10-04 11:11:08 +0200 | [diff] [blame] | 509 | |
Tatyana Brokhman | 464fbe1 | 2012-10-07 10:33:13 +0200 | [diff] [blame] | 510 | spin_unlock(&pack_stats->lock); |
| 511 | |
| 512 | kfree(temp_buf); |
| 513 | |
| 514 | pr_info("%s", ubuf); |
| 515 | |
| 516 | exit: |
| 517 | if (card->wr_pack_stats.print_in_read == 1) { |
| 518 | card->wr_pack_stats.print_in_read = 0; |
| 519 | return strnlen(ubuf, cnt); |
| 520 | } |
| 521 | |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | static ssize_t mmc_wr_pack_stats_write(struct file *filp, |
| 526 | const char __user *ubuf, size_t cnt, |
| 527 | loff_t *ppos) |
| 528 | { |
| 529 | struct mmc_card *card = filp->private_data; |
| 530 | int value; |
| 531 | |
| 532 | if (!card) |
| 533 | return cnt; |
| 534 | |
| 535 | sscanf(ubuf, "%d", &value); |
| 536 | if (value) { |
| 537 | mmc_blk_init_packed_statistics(card); |
| 538 | } else { |
| 539 | spin_lock(&card->wr_pack_stats.lock); |
| 540 | card->wr_pack_stats.enabled = false; |
| 541 | spin_unlock(&card->wr_pack_stats.lock); |
| 542 | } |
| 543 | |
| 544 | return cnt; |
| 545 | } |
| 546 | |
| 547 | static const struct file_operations mmc_dbg_wr_pack_stats_fops = { |
| 548 | .open = mmc_wr_pack_stats_open, |
| 549 | .read = mmc_wr_pack_stats_read, |
| 550 | .write = mmc_wr_pack_stats_write, |
| 551 | }; |
| 552 | |
Yaniv Gardi | 4c4383f | 2012-10-11 18:29:28 +0200 | [diff] [blame] | 553 | static int mmc_bkops_stats_open(struct inode *inode, struct file *filp) |
| 554 | { |
| 555 | struct mmc_card *card = inode->i_private; |
| 556 | |
| 557 | filp->private_data = card; |
| 558 | |
| 559 | card->bkops_info.bkops_stats.print_stats = 1; |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | static ssize_t mmc_bkops_stats_read(struct file *filp, char __user *ubuf, |
| 564 | size_t cnt, loff_t *ppos) |
| 565 | { |
| 566 | struct mmc_card *card = filp->private_data; |
| 567 | struct mmc_bkops_stats *bkops_stats; |
| 568 | int i; |
| 569 | char *temp_buf; |
| 570 | |
| 571 | if (!card) |
| 572 | return cnt; |
| 573 | |
| 574 | bkops_stats = &card->bkops_info.bkops_stats; |
| 575 | |
| 576 | if (!bkops_stats->print_stats) |
| 577 | return 0; |
| 578 | |
| 579 | if (!bkops_stats->enabled) { |
| 580 | pr_info("%s: bkops statistics are disabled\n", |
| 581 | mmc_hostname(card->host)); |
| 582 | goto exit; |
| 583 | } |
| 584 | |
| 585 | temp_buf = kmalloc(TEMP_BUF_SIZE, GFP_KERNEL); |
| 586 | if (!temp_buf) |
| 587 | goto exit; |
| 588 | |
| 589 | spin_lock(&bkops_stats->lock); |
| 590 | |
| 591 | memset(ubuf, 0, cnt); |
| 592 | |
| 593 | snprintf(temp_buf, TEMP_BUF_SIZE, "%s: bkops statistics:\n", |
| 594 | mmc_hostname(card->host)); |
| 595 | strlcat(ubuf, temp_buf, cnt); |
| 596 | |
| 597 | for (i = 0 ; i < BKOPS_NUM_OF_SEVERITY_LEVELS ; ++i) { |
| 598 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 599 | "%s: BKOPS: due to level %d: %u\n", |
| 600 | mmc_hostname(card->host), i, bkops_stats->bkops_level[i]); |
| 601 | strlcat(ubuf, temp_buf, cnt); |
| 602 | } |
| 603 | |
| 604 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 605 | "%s: BKOPS: stopped due to HPI: %u\n", |
| 606 | mmc_hostname(card->host), bkops_stats->hpi); |
| 607 | strlcat(ubuf, temp_buf, cnt); |
| 608 | |
| 609 | snprintf(temp_buf, TEMP_BUF_SIZE, |
| 610 | "%s: BKOPS: how many time host was suspended: %u\n", |
| 611 | mmc_hostname(card->host), bkops_stats->suspend); |
| 612 | strlcat(ubuf, temp_buf, cnt); |
| 613 | |
| 614 | spin_unlock(&bkops_stats->lock); |
| 615 | |
| 616 | kfree(temp_buf); |
| 617 | |
| 618 | pr_info("%s", ubuf); |
| 619 | |
| 620 | exit: |
| 621 | if (bkops_stats->print_stats == 1) { |
| 622 | bkops_stats->print_stats = 0; |
| 623 | return strnlen(ubuf, cnt); |
| 624 | } |
| 625 | |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | static ssize_t mmc_bkops_stats_write(struct file *filp, |
| 630 | const char __user *ubuf, size_t cnt, |
| 631 | loff_t *ppos) |
| 632 | { |
| 633 | struct mmc_card *card = filp->private_data; |
| 634 | int value; |
| 635 | struct mmc_bkops_stats *bkops_stats; |
| 636 | |
| 637 | if (!card) |
| 638 | return cnt; |
| 639 | |
| 640 | bkops_stats = &card->bkops_info.bkops_stats; |
| 641 | |
| 642 | sscanf(ubuf, "%d", &value); |
| 643 | if (value) { |
| 644 | mmc_blk_init_bkops_statistics(card); |
| 645 | } else { |
| 646 | spin_lock(&bkops_stats->lock); |
| 647 | bkops_stats->enabled = false; |
| 648 | spin_unlock(&bkops_stats->lock); |
| 649 | } |
| 650 | |
| 651 | return cnt; |
| 652 | } |
| 653 | |
| 654 | static const struct file_operations mmc_dbg_bkops_stats_fops = { |
| 655 | .open = mmc_bkops_stats_open, |
| 656 | .read = mmc_bkops_stats_read, |
| 657 | .write = mmc_bkops_stats_write, |
| 658 | }; |
| 659 | |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 660 | void mmc_add_card_debugfs(struct mmc_card *card) |
| 661 | { |
| 662 | struct mmc_host *host = card->host; |
| 663 | struct dentry *root; |
| 664 | |
| 665 | if (!host->debugfs_root) |
| 666 | return; |
| 667 | |
| 668 | root = debugfs_create_dir(mmc_card_id(card), host->debugfs_root); |
| 669 | if (IS_ERR(root)) |
| 670 | /* Don't complain -- debugfs just isn't enabled */ |
| 671 | return; |
| 672 | if (!root) |
| 673 | /* Complain -- debugfs is enabled, but it failed to |
| 674 | * create the directory. */ |
| 675 | goto err; |
| 676 | |
| 677 | card->debugfs_root = root; |
| 678 | |
| 679 | if (!debugfs_create_x32("state", S_IRUSR, root, &card->state)) |
| 680 | goto err; |
| 681 | |
| 682 | if (mmc_card_mmc(card) || mmc_card_sd(card)) |
| 683 | if (!debugfs_create_file("status", S_IRUSR, root, card, |
| 684 | &mmc_dbg_card_status_fops)) |
| 685 | goto err; |
| 686 | |
Adrian Hunter | 736bb6b | 2009-02-11 14:52:20 +0200 | [diff] [blame] | 687 | if (mmc_card_mmc(card)) |
| 688 | if (!debugfs_create_file("ext_csd", S_IRUSR, root, card, |
| 689 | &mmc_dbg_ext_csd_fops)) |
| 690 | goto err; |
| 691 | |
Tatyana Brokhman | 464fbe1 | 2012-10-07 10:33:13 +0200 | [diff] [blame] | 692 | if (mmc_card_mmc(card) && (card->ext_csd.rev >= 6) && |
| 693 | (card->host->caps2 & MMC_CAP2_PACKED_WR)) |
| 694 | if (!debugfs_create_file("wr_pack_stats", S_IRUSR, root, card, |
| 695 | &mmc_dbg_wr_pack_stats_fops)) |
| 696 | goto err; |
| 697 | |
Maya Erez | 8a89b15 | 2012-12-19 08:44:42 +0200 | [diff] [blame] | 698 | if (mmc_card_mmc(card) && (card->ext_csd.rev >= 5) && |
Yaniv Gardi | 4c4383f | 2012-10-11 18:29:28 +0200 | [diff] [blame] | 699 | card->ext_csd.bkops_en) |
| 700 | if (!debugfs_create_file("bkops_stats", S_IRUSR, root, card, |
| 701 | &mmc_dbg_bkops_stats_fops)) |
| 702 | goto err; |
| 703 | |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 704 | return; |
| 705 | |
| 706 | err: |
| 707 | debugfs_remove_recursive(root); |
| 708 | card->debugfs_root = NULL; |
| 709 | dev_err(&card->dev, "failed to initialize debugfs\n"); |
| 710 | } |
| 711 | |
| 712 | void mmc_remove_card_debugfs(struct mmc_card *card) |
| 713 | { |
| 714 | debugfs_remove_recursive(card->debugfs_root); |
| 715 | } |