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