blob: 903decf30d6be361e238841752cd80c1c3c346d0 [file] [log] [blame]
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +02001/*
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 Rothwell3f102ae2011-10-09 10:35:16 -040010#include <linux/moduleparam.h>
Paul Gortmaker3ef77af2011-07-10 12:42:00 -040011#include <linux/export.h>
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +020012#include <linux/debugfs.h>
13#include <linux/fs.h>
14#include <linux/seq_file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +020016#include <linux/stat.h>
Per Forlin1b676f72011-08-19 14:52:37 +020017#include <linux/fault-inject.h>
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +020018
Haavard Skinnemoenf4b7f922008-07-24 14:18:58 +020019#include <linux/mmc/card.h>
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +020020#include <linux/mmc/host.h>
21
22#include "core.h"
Haavard Skinnemoenf4b7f922008-07-24 14:18:58 +020023#include "mmc_ops.h"
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +020024
Per Forlin34f50502011-09-13 23:03:29 +020025#ifdef CONFIG_FAIL_MMC_REQUEST
26
27static DECLARE_FAULT_ATTR(fail_default_attr);
28static char *fail_request;
29module_param(fail_request, charp, 0);
30
31#endif /* CONFIG_FAIL_MMC_REQUEST */
32
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +020033/* The debugfs functions are optimized away when CONFIG_DEBUG_FS isn't set. */
34static 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 CAVALLAROdf162192011-11-04 13:53:19 +010060 if (host->actual_clock)
61 seq_printf(s, "actual clock:\t%u Hz\n", host->actual_clock);
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +020062 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 Lucd8a3662011-09-02 16:06:08 +0800129 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 Sa4924c72012-01-11 14:04:52 -0500138 case MMC_TIMING_MMC_HS200:
139 str = "mmc high-speed SDR200";
140 break;
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +0200141 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
150static int mmc_ios_open(struct inode *inode, struct file *file)
151{
152 return single_open(file, mmc_ios_show, inode->i_private);
153}
154
155static 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 Shevchenko703aae32010-10-13 11:22:22 +0300162static 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
171static 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 Tummala22459132013-05-01 11:14:51 +0530179 mmc_rpm_hold(host, &host->class_dev);
Andy Shevchenko703aae32010-10-13 11:22:22 +0300180 mmc_claim_host(host);
181 mmc_set_clock(host, (unsigned int) val);
182 mmc_release_host(host);
Sahitya Tummala22459132013-05-01 11:14:51 +0530183 mmc_rpm_release(host, &host->class_dev);
Andy Shevchenko703aae32010-10-13 11:22:22 +0300184
185 return 0;
186}
187
188DEFINE_SIMPLE_ATTRIBUTE(mmc_clock_fops, mmc_clock_opt_get, mmc_clock_opt_set,
189 "%llu\n");
190
Sujit Reddy Thumma2743a512012-11-09 18:32:32 +0530191static 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
203static 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 Tummala22459132013-05-01 11:14:51 +0530213 mmc_rpm_hold(host, &host->class_dev);
Sujit Reddy Thumma2743a512012-11-09 18:32:32 +0530214 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 Tummala22459132013-05-01 11:14:51 +0530225 mmc_rpm_release(host, &host->class_dev);
Sujit Reddy Thumma2743a512012-11-09 18:32:32 +0530226out:
227 return err;
228}
229
230DEFINE_SIMPLE_ATTRIBUTE(mmc_max_clock_fops, mmc_max_clock_get,
231 mmc_max_clock_set, "%llu\n");
232
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +0200233void 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 Shevchenko703aae32010-10-13 11:22:22 +0300249 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 Skinnemoen6edd8ee2008-07-24 14:18:57 +0200254
Sujit Reddy Thumma2743a512012-11-09 18:32:32 +0530255 if (!debugfs_create_file("max_clock", S_IRUSR | S_IWUSR, root, host,
256 &mmc_max_clock_fops))
257 goto err_node;
258
Linus Walleij04566832010-11-08 21:36:50 -0500259#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 Forlin1b676f72011-08-19 14:52:37 +0200264#ifdef CONFIG_FAIL_MMC_REQUEST
Per Forlin34f50502011-09-13 23:03:29 +0200265 if (fail_request)
266 setup_fault_attr(&fail_default_attr, fail_request);
267 host->fail_mmc_request = fail_default_attr;
Per Forlin1b676f72011-08-19 14:52:37 +0200268 if (IS_ERR(fault_create_debugfs_attr("fail_mmc_request",
269 root,
270 &host->fail_mmc_request)))
271 goto err_node;
272#endif
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +0200273 return;
274
Andy Shevchenko703aae32010-10-13 11:22:22 +0300275err_node:
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +0200276 debugfs_remove_recursive(root);
277 host->debugfs_root = NULL;
278err_root:
279 dev_err(&host->class_dev, "failed to initialize debugfs\n");
280}
281
282void mmc_remove_host_debugfs(struct mmc_host *host)
283{
284 debugfs_remove_recursive(host->debugfs_root);
285}
Haavard Skinnemoenf4b7f922008-07-24 14:18:58 +0200286
287static 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 Tummala22459132013-05-01 11:14:51 +0530293 mmc_rpm_hold(card->host, &card->dev);
Haavard Skinnemoenf4b7f922008-07-24 14:18:58 +0200294 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 Tummala22459132013-05-01 11:14:51 +0530301 mmc_rpm_release(card->host, &card->dev);
Haavard Skinnemoenf4b7f922008-07-24 14:18:58 +0200302
303 return ret;
304}
305DEFINE_SIMPLE_ATTRIBUTE(mmc_dbg_card_status_fops, mmc_dbg_card_status_get,
306 NULL, "%08llx\n");
307
Adrian Hunter736bb6b2009-02-11 14:52:20 +0200308#define EXT_CSD_STR_LEN 1025
309
310static 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 Tummala22459132013-05-01 11:14:51 +0530328 mmc_rpm_hold(card->host, &card->dev);
Adrian Hunter736bb6b2009-02-11 14:52:20 +0200329 mmc_claim_host(card->host);
330 err = mmc_send_ext_csd(card, ext_csd);
331 mmc_release_host(card->host);
Sahitya Tummala22459132013-05-01 11:14:51 +0530332 mmc_rpm_release(card->host, &card->dev);
Adrian Hunter736bb6b2009-02-11 14:52:20 +0200333 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
345out_free:
346 kfree(buf);
347 kfree(ext_csd);
348 return err;
349}
350
351static 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
360static int mmc_ext_csd_release(struct inode *inode, struct file *file)
361{
362 kfree(file->private_data);
363 return 0;
364}
365
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700366static const struct file_operations mmc_dbg_ext_csd_fops = {
Adrian Hunter736bb6b2009-02-11 14:52:20 +0200367 .open = mmc_ext_csd_open,
368 .read = mmc_ext_csd_read,
369 .release = mmc_ext_csd_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200370 .llseek = default_llseek,
Adrian Hunter736bb6b2009-02-11 14:52:20 +0200371};
372
Tatyana Brokhman464fbe12012-10-07 10:33:13 +0200373static 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
383static 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 Brokhman1718ef22012-10-04 11:11:08 +0200488 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 Erez64d12462013-01-06 10:19:38 +0200495 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 Dorfmanb0832972013-02-05 16:26:19 +0200502 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 Brokhman1718ef22012-10-04 11:11:08 +0200509
Tatyana Brokhman464fbe12012-10-07 10:33:13 +0200510 spin_unlock(&pack_stats->lock);
511
512 kfree(temp_buf);
513
514 pr_info("%s", ubuf);
515
516exit:
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
525static 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
547static 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 Gardi4c4383f2012-10-11 18:29:28 +0200553static 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
563static 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
620exit:
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
629static 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
654static 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 Skinnemoenf4b7f922008-07-24 14:18:58 +0200660void 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 Hunter736bb6b2009-02-11 14:52:20 +0200687 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 Brokhman464fbe12012-10-07 10:33:13 +0200692 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 Erez8a89b152012-12-19 08:44:42 +0200698 if (mmc_card_mmc(card) && (card->ext_csd.rev >= 5) &&
Yaniv Gardi4c4383f2012-10-11 18:29:28 +0200699 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 Skinnemoenf4b7f922008-07-24 14:18:58 +0200704 return;
705
706err:
707 debugfs_remove_recursive(root);
708 card->debugfs_root = NULL;
709 dev_err(&card->dev, "failed to initialize debugfs\n");
710}
711
712void mmc_remove_card_debugfs(struct mmc_card *card)
713{
714 debugfs_remove_recursive(card->debugfs_root);
715}