debugfs.c 17 KB

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