Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 NXP Semiconductors |
| 4 | * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com> |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 7 | #include <blk.h> |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 8 | #include <command.h> |
| 9 | #include <dm.h> |
| 10 | #include <nvme.h> |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 11 | |
Bin Meng | 326c5fd | 2017-08-22 08:15:17 -0700 | [diff] [blame] | 12 | static int nvme_curr_dev; |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 13 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 14 | static int do_nvme(struct cmd_tbl *cmdtp, int flag, int argc, |
| 15 | char *const argv[]) |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 16 | { |
| 17 | int ret; |
| 18 | |
Bin Meng | 326c5fd | 2017-08-22 08:15:17 -0700 | [diff] [blame] | 19 | if (argc == 2) { |
| 20 | if (strncmp(argv[1], "scan", 4) == 0) { |
| 21 | ret = nvme_scan_namespace(); |
| 22 | if (ret) |
| 23 | return CMD_RET_FAILURE; |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 24 | |
Bin Meng | 326c5fd | 2017-08-22 08:15:17 -0700 | [diff] [blame] | 25 | return ret; |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 26 | } |
Bin Meng | 326c5fd | 2017-08-22 08:15:17 -0700 | [diff] [blame] | 27 | if (strncmp(argv[1], "deta", 4) == 0) { |
| 28 | struct udevice *udev; |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 29 | |
Simon Glass | dbfa32c | 2022-08-11 19:34:59 -0600 | [diff] [blame] | 30 | ret = blk_get_device(UCLASS_NVME, nvme_curr_dev, |
Bin Meng | 326c5fd | 2017-08-22 08:15:17 -0700 | [diff] [blame] | 31 | &udev); |
| 32 | if (ret < 0) |
| 33 | return CMD_RET_FAILURE; |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 34 | |
Bin Meng | 326c5fd | 2017-08-22 08:15:17 -0700 | [diff] [blame] | 35 | nvme_print_info(udev); |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 36 | |
Bin Meng | 326c5fd | 2017-08-22 08:15:17 -0700 | [diff] [blame] | 37 | return ret; |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 38 | } |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 39 | } |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 40 | |
Simon Glass | dbfa32c | 2022-08-11 19:34:59 -0600 | [diff] [blame] | 41 | return blk_common_cmd(argc, argv, UCLASS_NVME, &nvme_curr_dev); |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | U_BOOT_CMD( |
Bin Meng | 326c5fd | 2017-08-22 08:15:17 -0700 | [diff] [blame] | 45 | nvme, 8, 1, do_nvme, |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 46 | "NVM Express sub-system", |
Bin Meng | 326c5fd | 2017-08-22 08:15:17 -0700 | [diff] [blame] | 47 | "scan - scan NVMe devices\n" |
| 48 | "nvme detail - show details of current NVMe device\n" |
| 49 | "nvme info - show all available NVMe devices\n" |
| 50 | "nvme device [dev] - show or set current NVMe device\n" |
| 51 | "nvme part [dev] - print partition table of one or all NVMe devices\n" |
| 52 | "nvme read addr blk# cnt - read `cnt' blocks starting at block\n" |
| 53 | " `blk#' to memory address `addr'\n" |
| 54 | "nvme write addr blk# cnt - write `cnt' blocks starting at block\n" |
| 55 | " `blk#' from memory address `addr'" |
Zhikang Zhang | 4945565 | 2017-08-03 02:30:59 -0700 | [diff] [blame] | 56 | ); |