blkcache.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) Nelson Integration, LLC 2016
  4. * Author: Eric Nelson<eric@nelint.com>
  5. *
  6. */
  7. #include <command.h>
  8. #include <config.h>
  9. #include <common.h>
  10. #include <malloc.h>
  11. #include <part.h>
  12. static int blkc_show(struct cmd_tbl *cmdtp, int flag,
  13. int argc, char *const argv[])
  14. {
  15. struct block_cache_stats stats;
  16. blkcache_stats(&stats);
  17. printf("hits: %u\n"
  18. "misses: %u\n"
  19. "entries: %u\n"
  20. "max blocks/entry: %u\n"
  21. "max cache entries: %u\n",
  22. stats.hits, stats.misses, stats.entries,
  23. stats.max_blocks_per_entry, stats.max_entries);
  24. return 0;
  25. }
  26. static int blkc_configure(struct cmd_tbl *cmdtp, int flag,
  27. int argc, char *const argv[])
  28. {
  29. unsigned blocks_per_entry, max_entries;
  30. if (argc != 3)
  31. return CMD_RET_USAGE;
  32. blocks_per_entry = simple_strtoul(argv[1], 0, 0);
  33. max_entries = simple_strtoul(argv[2], 0, 0);
  34. blkcache_configure(blocks_per_entry, max_entries);
  35. printf("changed to max of %u entries of %u blocks each\n",
  36. max_entries, blocks_per_entry);
  37. return 0;
  38. }
  39. static struct cmd_tbl cmd_blkc_sub[] = {
  40. U_BOOT_CMD_MKENT(show, 0, 0, blkc_show, "", ""),
  41. U_BOOT_CMD_MKENT(configure, 3, 0, blkc_configure, "", ""),
  42. };
  43. static __maybe_unused void blkc_reloc(void)
  44. {
  45. static int relocated;
  46. if (!relocated) {
  47. fixup_cmdtable(cmd_blkc_sub, ARRAY_SIZE(cmd_blkc_sub));
  48. relocated = 1;
  49. };
  50. }
  51. static int do_blkcache(struct cmd_tbl *cmdtp, int flag,
  52. int argc, char *const argv[])
  53. {
  54. struct cmd_tbl *c;
  55. #ifdef CONFIG_NEEDS_MANUAL_RELOC
  56. blkc_reloc();
  57. #endif
  58. if (argc < 2)
  59. return CMD_RET_USAGE;
  60. /* Strip off leading argument */
  61. argc--;
  62. argv++;
  63. c = find_cmd_tbl(argv[0], &cmd_blkc_sub[0], ARRAY_SIZE(cmd_blkc_sub));
  64. if (!c)
  65. return CMD_RET_USAGE;
  66. return c->cmd(cmdtp, flag, argc, argv);
  67. }
  68. U_BOOT_CMD(
  69. blkcache, 4, 0, do_blkcache,
  70. "block cache diagnostics and control",
  71. "show - show and reset statistics\n"
  72. "blkcache configure <blocks> <entries> "
  73. "- set max blocks per entry and max cache entries\n"
  74. );