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