blob: 8b7e0bdda0bab3004c8ce60aa44a65ab1f2fa125 [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
179 mmc_claim_host(host);
180 mmc_set_clock(host, (unsigned int) val);
181 mmc_release_host(host);
182
183 return 0;
184}
185
186DEFINE_SIMPLE_ATTRIBUTE(mmc_clock_fops, mmc_clock_opt_get, mmc_clock_opt_set,
187 "%llu\n");
188
Sujit Reddy Thumma2743a512012-11-09 18:32:32 +0530189static int mmc_max_clock_get(void *data, u64 *val)
190{
191 struct mmc_host *host = data;
192
193 if (!host)
194 return -EINVAL;
195
196 *val = host->f_max;
197
198 return 0;
199}
200
201static int mmc_max_clock_set(void *data, u64 val)
202{
203 struct mmc_host *host = data;
204 int err = -EINVAL;
205 unsigned long freq = val;
206 unsigned int old_freq;
207
208 if (!host || (val < host->f_min))
209 goto out;
210
211 mmc_claim_host(host);
212 if (host->bus_ops && host->bus_ops->change_bus_speed) {
213 old_freq = host->f_max;
214 host->f_max = freq;
215
216 err = host->bus_ops->change_bus_speed(host, &freq);
217
218 if (err)
219 host->f_max = old_freq;
220 }
221 mmc_release_host(host);
222out:
223 return err;
224}
225
226DEFINE_SIMPLE_ATTRIBUTE(mmc_max_clock_fops, mmc_max_clock_get,
227 mmc_max_clock_set, "%llu\n");
228
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +0200229void mmc_add_host_debugfs(struct mmc_host *host)
230{
231 struct dentry *root;
232
233 root = debugfs_create_dir(mmc_hostname(host), NULL);
234 if (IS_ERR(root))
235 /* Don't complain -- debugfs just isn't enabled */
236 return;
237 if (!root)
238 /* Complain -- debugfs is enabled, but it failed to
239 * create the directory. */
240 goto err_root;
241
242 host->debugfs_root = root;
243
244 if (!debugfs_create_file("ios", S_IRUSR, root, host, &mmc_ios_fops))
Andy Shevchenko703aae32010-10-13 11:22:22 +0300245 goto err_node;
246
247 if (!debugfs_create_file("clock", S_IRUSR | S_IWUSR, root, host,
248 &mmc_clock_fops))
249 goto err_node;
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +0200250
Sujit Reddy Thumma2743a512012-11-09 18:32:32 +0530251 if (!debugfs_create_file("max_clock", S_IRUSR | S_IWUSR, root, host,
252 &mmc_max_clock_fops))
253 goto err_node;
254
Linus Walleij04566832010-11-08 21:36:50 -0500255#ifdef CONFIG_MMC_CLKGATE
256 if (!debugfs_create_u32("clk_delay", (S_IRUSR | S_IWUSR),
257 root, &host->clk_delay))
258 goto err_node;
259#endif
Per Forlin1b676f72011-08-19 14:52:37 +0200260#ifdef CONFIG_FAIL_MMC_REQUEST
Per Forlin34f50502011-09-13 23:03:29 +0200261 if (fail_request)
262 setup_fault_attr(&fail_default_attr, fail_request);
263 host->fail_mmc_request = fail_default_attr;
Per Forlin1b676f72011-08-19 14:52:37 +0200264 if (IS_ERR(fault_create_debugfs_attr("fail_mmc_request",
265 root,
266 &host->fail_mmc_request)))
267 goto err_node;
268#endif
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +0200269 return;
270
Andy Shevchenko703aae32010-10-13 11:22:22 +0300271err_node:
Haavard Skinnemoen6edd8ee2008-07-24 14:18:57 +0200272 debugfs_remove_recursive(root);
273 host->debugfs_root = NULL;
274err_root:
275 dev_err(&host->class_dev, "failed to initialize debugfs\n");
276}
277
278void mmc_remove_host_debugfs(struct mmc_host *host)
279{
280 debugfs_remove_recursive(host->debugfs_root);
281}
Haavard Skinnemoenf4b7f922008-07-24 14:18:58 +0200282
283static int mmc_dbg_card_status_get(void *data, u64 *val)
284{
285 struct mmc_card *card = data;
286 u32 status;
287 int ret;
288
289 mmc_claim_host(card->host);
290
291 ret = mmc_send_status(data, &status);
292 if (!ret)
293 *val = status;
294
295 mmc_release_host(card->host);
296
297 return ret;
298}
299DEFINE_SIMPLE_ATTRIBUTE(mmc_dbg_card_status_fops, mmc_dbg_card_status_get,
300 NULL, "%08llx\n");
301
Adrian Hunter736bb6b2009-02-11 14:52:20 +0200302#define EXT_CSD_STR_LEN 1025
303
304static int mmc_ext_csd_open(struct inode *inode, struct file *filp)
305{
306 struct mmc_card *card = inode->i_private;
307 char *buf;
308 ssize_t n = 0;
309 u8 *ext_csd;
310 int err, i;
311
312 buf = kmalloc(EXT_CSD_STR_LEN + 1, GFP_KERNEL);
313 if (!buf)
314 return -ENOMEM;
315
316 ext_csd = kmalloc(512, GFP_KERNEL);
317 if (!ext_csd) {
318 err = -ENOMEM;
319 goto out_free;
320 }
321
322 mmc_claim_host(card->host);
323 err = mmc_send_ext_csd(card, ext_csd);
324 mmc_release_host(card->host);
325 if (err)
326 goto out_free;
327
328 for (i = 511; i >= 0; i--)
329 n += sprintf(buf + n, "%02x", ext_csd[i]);
330 n += sprintf(buf + n, "\n");
331 BUG_ON(n != EXT_CSD_STR_LEN);
332
333 filp->private_data = buf;
334 kfree(ext_csd);
335 return 0;
336
337out_free:
338 kfree(buf);
339 kfree(ext_csd);
340 return err;
341}
342
343static ssize_t mmc_ext_csd_read(struct file *filp, char __user *ubuf,
344 size_t cnt, loff_t *ppos)
345{
346 char *buf = filp->private_data;
347
348 return simple_read_from_buffer(ubuf, cnt, ppos,
349 buf, EXT_CSD_STR_LEN);
350}
351
352static int mmc_ext_csd_release(struct inode *inode, struct file *file)
353{
354 kfree(file->private_data);
355 return 0;
356}
357
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700358static const struct file_operations mmc_dbg_ext_csd_fops = {
Adrian Hunter736bb6b2009-02-11 14:52:20 +0200359 .open = mmc_ext_csd_open,
360 .read = mmc_ext_csd_read,
361 .release = mmc_ext_csd_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200362 .llseek = default_llseek,
Adrian Hunter736bb6b2009-02-11 14:52:20 +0200363};
364
Tatyana Brokhman464fbe12012-10-07 10:33:13 +0200365static int mmc_wr_pack_stats_open(struct inode *inode, struct file *filp)
366{
367 struct mmc_card *card = inode->i_private;
368
369 filp->private_data = card;
370 card->wr_pack_stats.print_in_read = 1;
371 return 0;
372}
373
374#define TEMP_BUF_SIZE 256
375static ssize_t mmc_wr_pack_stats_read(struct file *filp, char __user *ubuf,
376 size_t cnt, loff_t *ppos)
377{
378 struct mmc_card *card = filp->private_data;
379 struct mmc_wr_pack_stats *pack_stats;
380 int i;
381 int max_num_of_packed_reqs = 0;
382 char *temp_buf;
383
384 if (!card)
385 return cnt;
386
387 if (!card->wr_pack_stats.print_in_read)
388 return 0;
389
390 if (!card->wr_pack_stats.enabled) {
391 pr_info("%s: write packing statistics are disabled\n",
392 mmc_hostname(card->host));
393 goto exit;
394 }
395
396 pack_stats = &card->wr_pack_stats;
397
398 if (!pack_stats->packing_events) {
399 pr_info("%s: NULL packing_events\n", mmc_hostname(card->host));
400 goto exit;
401 }
402
403 max_num_of_packed_reqs = card->ext_csd.max_packed_writes;
404
405 temp_buf = kmalloc(TEMP_BUF_SIZE, GFP_KERNEL);
406 if (!temp_buf)
407 goto exit;
408
409 spin_lock(&pack_stats->lock);
410
411 snprintf(temp_buf, TEMP_BUF_SIZE, "%s: write packing statistics:\n",
412 mmc_hostname(card->host));
413 strlcat(ubuf, temp_buf, cnt);
414
415 for (i = 1 ; i <= max_num_of_packed_reqs ; ++i) {
416 if (pack_stats->packing_events[i]) {
417 snprintf(temp_buf, TEMP_BUF_SIZE,
418 "%s: Packed %d reqs - %d times\n",
419 mmc_hostname(card->host), i,
420 pack_stats->packing_events[i]);
421 strlcat(ubuf, temp_buf, cnt);
422 }
423 }
424
425 snprintf(temp_buf, TEMP_BUF_SIZE,
426 "%s: stopped packing due to the following reasons:\n",
427 mmc_hostname(card->host));
428 strlcat(ubuf, temp_buf, cnt);
429
430 if (pack_stats->pack_stop_reason[EXCEEDS_SEGMENTS]) {
431 snprintf(temp_buf, TEMP_BUF_SIZE,
432 "%s: %d times: exceed max num of segments\n",
433 mmc_hostname(card->host),
434 pack_stats->pack_stop_reason[EXCEEDS_SEGMENTS]);
435 strlcat(ubuf, temp_buf, cnt);
436 }
437 if (pack_stats->pack_stop_reason[EXCEEDS_SECTORS]) {
438 snprintf(temp_buf, TEMP_BUF_SIZE,
439 "%s: %d times: exceed max num of sectors\n",
440 mmc_hostname(card->host),
441 pack_stats->pack_stop_reason[EXCEEDS_SECTORS]);
442 strlcat(ubuf, temp_buf, cnt);
443 }
444 if (pack_stats->pack_stop_reason[WRONG_DATA_DIR]) {
445 snprintf(temp_buf, TEMP_BUF_SIZE,
446 "%s: %d times: wrong data direction\n",
447 mmc_hostname(card->host),
448 pack_stats->pack_stop_reason[WRONG_DATA_DIR]);
449 strlcat(ubuf, temp_buf, cnt);
450 }
451 if (pack_stats->pack_stop_reason[FLUSH_OR_DISCARD]) {
452 snprintf(temp_buf, TEMP_BUF_SIZE,
453 "%s: %d times: flush or discard\n",
454 mmc_hostname(card->host),
455 pack_stats->pack_stop_reason[FLUSH_OR_DISCARD]);
456 strlcat(ubuf, temp_buf, cnt);
457 }
458 if (pack_stats->pack_stop_reason[EMPTY_QUEUE]) {
459 snprintf(temp_buf, TEMP_BUF_SIZE,
460 "%s: %d times: empty queue\n",
461 mmc_hostname(card->host),
462 pack_stats->pack_stop_reason[EMPTY_QUEUE]);
463 strlcat(ubuf, temp_buf, cnt);
464 }
465 if (pack_stats->pack_stop_reason[REL_WRITE]) {
466 snprintf(temp_buf, TEMP_BUF_SIZE,
467 "%s: %d times: rel write\n",
468 mmc_hostname(card->host),
469 pack_stats->pack_stop_reason[REL_WRITE]);
470 strlcat(ubuf, temp_buf, cnt);
471 }
472 if (pack_stats->pack_stop_reason[THRESHOLD]) {
473 snprintf(temp_buf, TEMP_BUF_SIZE,
474 "%s: %d times: Threshold\n",
475 mmc_hostname(card->host),
476 pack_stats->pack_stop_reason[THRESHOLD]);
477 strlcat(ubuf, temp_buf, cnt);
478 }
479
Tatyana Brokhman1718ef22012-10-04 11:11:08 +0200480 if (pack_stats->pack_stop_reason[LARGE_SEC_ALIGN]) {
481 snprintf(temp_buf, TEMP_BUF_SIZE,
482 "%s: %d times: Large sector alignment\n",
483 mmc_hostname(card->host),
484 pack_stats->pack_stop_reason[LARGE_SEC_ALIGN]);
485 strlcat(ubuf, temp_buf, cnt);
486 }
Maya Erez64d12462013-01-06 10:19:38 +0200487 if (pack_stats->pack_stop_reason[RANDOM]) {
488 snprintf(temp_buf, TEMP_BUF_SIZE,
489 "%s: %d times: random request\n",
490 mmc_hostname(card->host),
491 pack_stats->pack_stop_reason[RANDOM]);
492 strlcat(ubuf, temp_buf, cnt);
493 }
Konstantin Dorfmanb0832972013-02-05 16:26:19 +0200494 if (pack_stats->pack_stop_reason[FUA]) {
495 snprintf(temp_buf, TEMP_BUF_SIZE,
496 "%s: %d times: fua request\n",
497 mmc_hostname(card->host),
498 pack_stats->pack_stop_reason[FUA]);
499 strlcat(ubuf, temp_buf, cnt);
500 }
Tatyana Brokhman1718ef22012-10-04 11:11:08 +0200501
Tatyana Brokhman464fbe12012-10-07 10:33:13 +0200502 spin_unlock(&pack_stats->lock);
503
504 kfree(temp_buf);
505
506 pr_info("%s", ubuf);
507
508exit:
509 if (card->wr_pack_stats.print_in_read == 1) {
510 card->wr_pack_stats.print_in_read = 0;
511 return strnlen(ubuf, cnt);
512 }
513
514 return 0;
515}
516
517static ssize_t mmc_wr_pack_stats_write(struct file *filp,
518 const char __user *ubuf, size_t cnt,
519 loff_t *ppos)
520{
521 struct mmc_card *card = filp->private_data;
522 int value;
523
524 if (!card)
525 return cnt;
526
527 sscanf(ubuf, "%d", &value);
528 if (value) {
529 mmc_blk_init_packed_statistics(card);
530 } else {
531 spin_lock(&card->wr_pack_stats.lock);
532 card->wr_pack_stats.enabled = false;
533 spin_unlock(&card->wr_pack_stats.lock);
534 }
535
536 return cnt;
537}
538
539static const struct file_operations mmc_dbg_wr_pack_stats_fops = {
540 .open = mmc_wr_pack_stats_open,
541 .read = mmc_wr_pack_stats_read,
542 .write = mmc_wr_pack_stats_write,
543};
544
Yaniv Gardi4c4383f2012-10-11 18:29:28 +0200545static int mmc_bkops_stats_open(struct inode *inode, struct file *filp)
546{
547 struct mmc_card *card = inode->i_private;
548
549 filp->private_data = card;
550
551 card->bkops_info.bkops_stats.print_stats = 1;
552 return 0;
553}
554
555static ssize_t mmc_bkops_stats_read(struct file *filp, char __user *ubuf,
556 size_t cnt, loff_t *ppos)
557{
558 struct mmc_card *card = filp->private_data;
559 struct mmc_bkops_stats *bkops_stats;
560 int i;
561 char *temp_buf;
562
563 if (!card)
564 return cnt;
565
566 bkops_stats = &card->bkops_info.bkops_stats;
567
568 if (!bkops_stats->print_stats)
569 return 0;
570
571 if (!bkops_stats->enabled) {
572 pr_info("%s: bkops statistics are disabled\n",
573 mmc_hostname(card->host));
574 goto exit;
575 }
576
577 temp_buf = kmalloc(TEMP_BUF_SIZE, GFP_KERNEL);
578 if (!temp_buf)
579 goto exit;
580
581 spin_lock(&bkops_stats->lock);
582
583 memset(ubuf, 0, cnt);
584
585 snprintf(temp_buf, TEMP_BUF_SIZE, "%s: bkops statistics:\n",
586 mmc_hostname(card->host));
587 strlcat(ubuf, temp_buf, cnt);
588
589 for (i = 0 ; i < BKOPS_NUM_OF_SEVERITY_LEVELS ; ++i) {
590 snprintf(temp_buf, TEMP_BUF_SIZE,
591 "%s: BKOPS: due to level %d: %u\n",
592 mmc_hostname(card->host), i, bkops_stats->bkops_level[i]);
593 strlcat(ubuf, temp_buf, cnt);
594 }
595
596 snprintf(temp_buf, TEMP_BUF_SIZE,
597 "%s: BKOPS: stopped due to HPI: %u\n",
598 mmc_hostname(card->host), bkops_stats->hpi);
599 strlcat(ubuf, temp_buf, cnt);
600
601 snprintf(temp_buf, TEMP_BUF_SIZE,
602 "%s: BKOPS: how many time host was suspended: %u\n",
603 mmc_hostname(card->host), bkops_stats->suspend);
604 strlcat(ubuf, temp_buf, cnt);
605
606 spin_unlock(&bkops_stats->lock);
607
608 kfree(temp_buf);
609
610 pr_info("%s", ubuf);
611
612exit:
613 if (bkops_stats->print_stats == 1) {
614 bkops_stats->print_stats = 0;
615 return strnlen(ubuf, cnt);
616 }
617
618 return 0;
619}
620
621static ssize_t mmc_bkops_stats_write(struct file *filp,
622 const char __user *ubuf, size_t cnt,
623 loff_t *ppos)
624{
625 struct mmc_card *card = filp->private_data;
626 int value;
627 struct mmc_bkops_stats *bkops_stats;
628
629 if (!card)
630 return cnt;
631
632 bkops_stats = &card->bkops_info.bkops_stats;
633
634 sscanf(ubuf, "%d", &value);
635 if (value) {
636 mmc_blk_init_bkops_statistics(card);
637 } else {
638 spin_lock(&bkops_stats->lock);
639 bkops_stats->enabled = false;
640 spin_unlock(&bkops_stats->lock);
641 }
642
643 return cnt;
644}
645
646static const struct file_operations mmc_dbg_bkops_stats_fops = {
647 .open = mmc_bkops_stats_open,
648 .read = mmc_bkops_stats_read,
649 .write = mmc_bkops_stats_write,
650};
651
Haavard Skinnemoenf4b7f922008-07-24 14:18:58 +0200652void mmc_add_card_debugfs(struct mmc_card *card)
653{
654 struct mmc_host *host = card->host;
655 struct dentry *root;
656
657 if (!host->debugfs_root)
658 return;
659
660 root = debugfs_create_dir(mmc_card_id(card), host->debugfs_root);
661 if (IS_ERR(root))
662 /* Don't complain -- debugfs just isn't enabled */
663 return;
664 if (!root)
665 /* Complain -- debugfs is enabled, but it failed to
666 * create the directory. */
667 goto err;
668
669 card->debugfs_root = root;
670
671 if (!debugfs_create_x32("state", S_IRUSR, root, &card->state))
672 goto err;
673
674 if (mmc_card_mmc(card) || mmc_card_sd(card))
675 if (!debugfs_create_file("status", S_IRUSR, root, card,
676 &mmc_dbg_card_status_fops))
677 goto err;
678
Adrian Hunter736bb6b2009-02-11 14:52:20 +0200679 if (mmc_card_mmc(card))
680 if (!debugfs_create_file("ext_csd", S_IRUSR, root, card,
681 &mmc_dbg_ext_csd_fops))
682 goto err;
683
Tatyana Brokhman464fbe12012-10-07 10:33:13 +0200684 if (mmc_card_mmc(card) && (card->ext_csd.rev >= 6) &&
685 (card->host->caps2 & MMC_CAP2_PACKED_WR))
686 if (!debugfs_create_file("wr_pack_stats", S_IRUSR, root, card,
687 &mmc_dbg_wr_pack_stats_fops))
688 goto err;
689
Maya Erez8a89b152012-12-19 08:44:42 +0200690 if (mmc_card_mmc(card) && (card->ext_csd.rev >= 5) &&
Yaniv Gardi4c4383f2012-10-11 18:29:28 +0200691 card->ext_csd.bkops_en)
692 if (!debugfs_create_file("bkops_stats", S_IRUSR, root, card,
693 &mmc_dbg_bkops_stats_fops))
694 goto err;
695
Haavard Skinnemoenf4b7f922008-07-24 14:18:58 +0200696 return;
697
698err:
699 debugfs_remove_recursive(root);
700 card->debugfs_root = NULL;
701 dev_err(&card->dev, "failed to initialize debugfs\n");
702}
703
704void mmc_remove_card_debugfs(struct mmc_card *card)
705{
706 debugfs_remove_recursive(card->debugfs_root);
707}