blob: f2c9acba5c3272a17a93a27acef6cb77632ddf29 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Zhikang Zhang49455652017-08-03 02:30:59 -07002/*
3 * Copyright (C) 2017 NXP Semiconductors
4 * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
Zhikang Zhang49455652017-08-03 02:30:59 -07005 */
6
Simon Glass655306c2020-05-10 11:39:58 -06007#include <blk.h>
Zhikang Zhang49455652017-08-03 02:30:59 -07008#include <command.h>
9#include <dm.h>
10#include <nvme.h>
Zhikang Zhang49455652017-08-03 02:30:59 -070011
Bin Meng326c5fd2017-08-22 08:15:17 -070012static int nvme_curr_dev;
Zhikang Zhang49455652017-08-03 02:30:59 -070013
Simon Glassed38aef2020-05-10 11:40:03 -060014static int do_nvme(struct cmd_tbl *cmdtp, int flag, int argc,
15 char *const argv[])
Zhikang Zhang49455652017-08-03 02:30:59 -070016{
17 int ret;
18
Bin Meng326c5fd2017-08-22 08:15:17 -070019 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 Zhang49455652017-08-03 02:30:59 -070024
Bin Meng326c5fd2017-08-22 08:15:17 -070025 return ret;
Zhikang Zhang49455652017-08-03 02:30:59 -070026 }
Bin Meng326c5fd2017-08-22 08:15:17 -070027 if (strncmp(argv[1], "deta", 4) == 0) {
28 struct udevice *udev;
Zhikang Zhang49455652017-08-03 02:30:59 -070029
Simon Glassdbfa32c2022-08-11 19:34:59 -060030 ret = blk_get_device(UCLASS_NVME, nvme_curr_dev,
Bin Meng326c5fd2017-08-22 08:15:17 -070031 &udev);
32 if (ret < 0)
33 return CMD_RET_FAILURE;
Zhikang Zhang49455652017-08-03 02:30:59 -070034
Bin Meng326c5fd2017-08-22 08:15:17 -070035 nvme_print_info(udev);
Zhikang Zhang49455652017-08-03 02:30:59 -070036
Bin Meng326c5fd2017-08-22 08:15:17 -070037 return ret;
Zhikang Zhang49455652017-08-03 02:30:59 -070038 }
Zhikang Zhang49455652017-08-03 02:30:59 -070039 }
Zhikang Zhang49455652017-08-03 02:30:59 -070040
Simon Glassdbfa32c2022-08-11 19:34:59 -060041 return blk_common_cmd(argc, argv, UCLASS_NVME, &nvme_curr_dev);
Zhikang Zhang49455652017-08-03 02:30:59 -070042}
43
44U_BOOT_CMD(
Bin Meng326c5fd2017-08-22 08:15:17 -070045 nvme, 8, 1, do_nvme,
Zhikang Zhang49455652017-08-03 02:30:59 -070046 "NVM Express sub-system",
Bin Meng326c5fd2017-08-22 08:15:17 -070047 "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 Zhang49455652017-08-03 02:30:59 -070056);