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