From: Bin Meng <bmeng.cn@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/8] nvme: Add show routine to print detailed information
Date: Thu, 3 Aug 2017 02:30:58 -0700 [thread overview]
Message-ID: <1501752663-25088-4-git-send-email-bmeng.cn@gmail.com> (raw)
In-Reply-To: <1501752663-25088-1-git-send-email-bmeng.cn@gmail.com>
From: Zhikang Zhang <zhikang.zhang@nxp.com>
This adds nvme_print_info() to show detailed NVMe controller and
namespace information.
Signed-off-by: Zhikang Zhang <zhikang.zhang@nxp.com>
Signed-off-by: Wenbin Song <wenbin.song@nxp.com>
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---
drivers/nvme/Makefile | 2 +-
drivers/nvme/nvme_show.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++
include/nvme.h | 11 ++++
3 files changed, 139 insertions(+), 1 deletion(-)
create mode 100644 drivers/nvme/nvme_show.c
diff --git a/drivers/nvme/Makefile b/drivers/nvme/Makefile
index 7bd9fa4..1f3010a 100644
--- a/drivers/nvme/Makefile
+++ b/drivers/nvme/Makefile
@@ -4,4 +4,4 @@
# SPDX-License-Identifier: GPL-2.0+
#
-obj-y += nvme-uclass.o nvme.o
+obj-y += nvme-uclass.o nvme.o nvme_show.o
diff --git a/drivers/nvme/nvme_show.c b/drivers/nvme/nvme_show.c
new file mode 100644
index 0000000..5577e5d
--- /dev/null
+++ b/drivers/nvme/nvme_show.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2017 NXP Semiconductors
+ * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <nvme.h>
+#include "nvme.h"
+
+static void print_optional_admin_cmd(u16 oacs, int devnum)
+{
+ printf("Blk device %d: Optional Admin Command Support:\n",
+ devnum);
+ printf("\tNamespace Management/Attachment: %s\n",
+ oacs & 0x08 ? "yes" : "no");
+ printf("\tFirmware Commit/Image download: %s\n",
+ oacs & 0x04 ? "yes" : "no");
+ printf("\tFormat NVM: %s\n",
+ oacs & 0x02 ? "yes" : "no");
+ printf("\tSecurity Send/Receive: %s\n",
+ oacs & 0x01 ? "yes" : "no");
+}
+
+static void print_optional_nvm_cmd(u16 oncs, int devnum)
+{
+ printf("Blk device %d: Optional NVM Command Support:\n",
+ devnum);
+ printf("\tReservation: %s\n",
+ oncs & 0x10 ? "yes" : "no");
+ printf("\tSave/Select field in the Set/Get features: %s\n",
+ oncs & 0x08 ? "yes" : "no");
+ printf("\tWrite Zeroes: %s\n",
+ oncs & 0x04 ? "yes" : "no");
+ printf("\tDataset Management: %s\n",
+ oncs & 0x02 ? "yes" : "no");
+ printf("\tWrite Uncorrectable: %s\n",
+ oncs & 0x01 ? "yes" : "no");
+}
+
+static void print_format_nvme_attributes(u8 fna, int devnum)
+{
+ printf("Blk device %d: Format NVM Attributes:\n", devnum);
+ printf("\tSupport Cryptographic Erase: %s\n",
+ fna & 0x04 ? "yes" : "No");
+ printf("\tSupport erase a particular namespace: %s\n",
+ fna & 0x02 ? "No" : "Yes");
+ printf("\tSupport format a particular namespace: %s\n",
+ fna & 0x01 ? "No" : "Yes");
+}
+
+static void print_format(struct nvme_lbaf *lbaf)
+{
+ u8 str[][10] = {"Best", "Better", "Good", "Degraded"};
+
+ printf("\t\tMetadata Size: %d\n", le16_to_cpu(lbaf->ms));
+ printf("\t\tLBA Data Size: %d\n", 1 << lbaf->ds);
+ printf("\t\tRelative Performance: %s\n", str[lbaf->rp & 0x03]);
+}
+
+static void print_formats(struct nvme_id_ns *id, struct nvme_ns *ns)
+{
+ int i;
+
+ printf("Blk device %d: LBA Format Support:\n", ns->devnum);
+
+ for (i = 0; i < id->nlbaf; i++) {
+ printf("\tLBA Foramt %d Support: ", i);
+ if (i == ns->flbas)
+ printf("(current)\n");
+ else
+ printf("\n");
+ print_format(id->lbaf + i);
+ }
+}
+
+static void print_data_protect_cap(u8 dpc, int devnum)
+{
+ printf("Blk device %d: End-to-End Data", devnum);
+ printf("Protect Capabilities:\n");
+ printf("\tAs last eight bytes: %s\n",
+ dpc & 0x10 ? "yes" : "No");
+ printf("\tAs first eight bytes: %s\n",
+ dpc & 0x08 ? "yes" : "No");
+ printf("\tSupport Type3: %s\n",
+ dpc & 0x04 ? "yes" : "No");
+ printf("\tSupport Type2: %s\n",
+ dpc & 0x02 ? "yes" : "No");
+ printf("\tSupport Type1: %s\n",
+ dpc & 0x01 ? "yes" : "No");
+}
+
+static void print_metadata_cap(u8 mc, int devnum)
+{
+ printf("Blk device %d: Metadata capabilities:\n", devnum);
+ printf("\tAs part of a separate buffer: %s\n",
+ mc & 0x02 ? "yes" : "No");
+ printf("\tAs part of an extended data LBA: %s\n",
+ mc & 0x01 ? "yes" : "No");
+}
+
+int nvme_print_info(struct udevice *udev)
+{
+ struct nvme_ns *ns = dev_get_priv(udev);
+ struct nvme_dev *dev = ns->dev;
+ struct nvme_id_ns buf_ns, *id = &buf_ns;
+ struct nvme_id_ctrl buf_ctrl, *ctrl = &buf_ctrl;
+
+ if (nvme_identify(dev, 0, 1, (dma_addr_t)ctrl))
+ return -EIO;
+
+ print_optional_admin_cmd(le16_to_cpu(ctrl->oacs), ns->devnum);
+ print_optional_nvm_cmd(le16_to_cpu(ctrl->oncs), ns->devnum);
+ print_format_nvme_attributes(ctrl->fna, ns->devnum);
+
+ if (nvme_identify(dev, ns->ns_id, 0, (dma_addr_t)id))
+ return -EIO;
+
+ print_formats(id, ns);
+ print_data_protect_cap(id->dpc, ns->devnum);
+ print_metadata_cap(id->mc, ns->devnum);
+
+ return 0;
+}
diff --git a/include/nvme.h b/include/nvme.h
index 3624408..8375d61 100644
--- a/include/nvme.h
+++ b/include/nvme.h
@@ -68,4 +68,15 @@ int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11,
*/
int nvme_scan_namespace(void);
+/**
+ * nvme_print_info - print detailed NVMe controller and namespace information
+ *
+ * This prints out detailed human readable NVMe controller and namespace
+ * information which is very useful for debugging.
+ *
+ * @udev: NVMe controller device
+ * @return: 0 on success, -EIO if NVMe identify command fails
+ */
+int nvme_print_info(struct udevice *udev);
+
#endif /* __NVME_H__ */
--
2.9.2
next prev parent reply other threads:[~2017-08-03 9:30 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-03 9:30 [U-Boot] [PATCH 0/8] nvme: Add NVM Express driver support Bin Meng
2017-08-03 9:30 ` [U-Boot] [PATCH 1/8] dm: blk: part: Add UCLASS_NVME and IF_TYPE_NVME Bin Meng
2017-08-10 1:30 ` Tom Rini
2017-08-14 0:07 ` [U-Boot] [U-Boot, " Tom Rini
2017-08-03 9:30 ` [U-Boot] [PATCH 2/8] nvme: Add NVM Express driver support Bin Meng
2017-08-10 1:30 ` Tom Rini
2017-08-14 0:07 ` [U-Boot] [U-Boot,2/8] " Tom Rini
2017-08-03 9:30 ` Bin Meng [this message]
2017-08-10 1:31 ` [U-Boot] [PATCH 3/8] nvme: Add show routine to print detailed information Tom Rini
2017-08-14 0:07 ` [U-Boot] [U-Boot, " Tom Rini
2017-08-03 9:30 ` [U-Boot] [PATCH 4/8] nvme: Add nvme commands Bin Meng
2017-08-10 1:31 ` Tom Rini
2017-08-14 0:08 ` [U-Boot] [U-Boot,4/8] " Tom Rini
2017-08-03 9:31 ` [U-Boot] [PATCH 5/8] nvme: Detect devices that are class Storage Express Bin Meng
2017-08-10 1:31 ` Tom Rini
2017-08-14 0:08 ` [U-Boot] [U-Boot, " Tom Rini
2017-08-03 9:31 ` [U-Boot] [PATCH 6/8] nvme: Fix number of blocks detection Bin Meng
2017-08-10 1:31 ` Tom Rini
2017-08-14 0:08 ` [U-Boot] [U-Boot,6/8] " Tom Rini
2017-08-03 9:31 ` [U-Boot] [PATCH 7/8] nvme: Handle zero Maximum Data Transfer Size (MDTS) Bin Meng
2017-08-10 1:31 ` Tom Rini
2017-08-14 0:08 ` [U-Boot] [U-Boot, " Tom Rini
2017-08-03 9:31 ` [U-Boot] [PATCH 8/8] x86: qemu: Enable NVMe driver Bin Meng
2017-08-10 1:31 ` Tom Rini
2017-08-14 0:08 ` [U-Boot] [U-Boot,8/8] " Tom Rini
2017-08-09 22:40 ` [U-Boot] [PATCH 0/8] nvme: Add NVM Express driver support Bin Meng
2017-08-10 1:31 ` Tom Rini
2017-08-10 1:49 ` Bin Meng
2017-08-10 1:56 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1501752663-25088-4-git-send-email-bmeng.cn@gmail.com \
--to=bmeng.cn@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox