1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2f6aa61d5SZhikang Zhang /*
3f6aa61d5SZhikang Zhang * Copyright (C) 2017 NXP Semiconductors
4f6aa61d5SZhikang Zhang * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
5f6aa61d5SZhikang Zhang */
6f6aa61d5SZhikang Zhang
7f6aa61d5SZhikang Zhang #include <common.h>
8f6aa61d5SZhikang Zhang #include <dm.h>
9f6aa61d5SZhikang Zhang #include <errno.h>
10704e040aSBin Meng #include <memalign.h>
11f6aa61d5SZhikang Zhang #include <nvme.h>
12f6aa61d5SZhikang Zhang #include "nvme.h"
13f6aa61d5SZhikang Zhang
print_optional_admin_cmd(u16 oacs,int devnum)14f6aa61d5SZhikang Zhang static void print_optional_admin_cmd(u16 oacs, int devnum)
15f6aa61d5SZhikang Zhang {
16f6aa61d5SZhikang Zhang printf("Blk device %d: Optional Admin Command Support:\n",
17f6aa61d5SZhikang Zhang devnum);
18f6aa61d5SZhikang Zhang printf("\tNamespace Management/Attachment: %s\n",
19f6aa61d5SZhikang Zhang oacs & 0x08 ? "yes" : "no");
20f6aa61d5SZhikang Zhang printf("\tFirmware Commit/Image download: %s\n",
21f6aa61d5SZhikang Zhang oacs & 0x04 ? "yes" : "no");
22f6aa61d5SZhikang Zhang printf("\tFormat NVM: %s\n",
23f6aa61d5SZhikang Zhang oacs & 0x02 ? "yes" : "no");
24f6aa61d5SZhikang Zhang printf("\tSecurity Send/Receive: %s\n",
25f6aa61d5SZhikang Zhang oacs & 0x01 ? "yes" : "no");
26f6aa61d5SZhikang Zhang }
27f6aa61d5SZhikang Zhang
print_optional_nvm_cmd(u16 oncs,int devnum)28f6aa61d5SZhikang Zhang static void print_optional_nvm_cmd(u16 oncs, int devnum)
29f6aa61d5SZhikang Zhang {
30f6aa61d5SZhikang Zhang printf("Blk device %d: Optional NVM Command Support:\n",
31f6aa61d5SZhikang Zhang devnum);
32f6aa61d5SZhikang Zhang printf("\tReservation: %s\n",
33f6aa61d5SZhikang Zhang oncs & 0x10 ? "yes" : "no");
34f6aa61d5SZhikang Zhang printf("\tSave/Select field in the Set/Get features: %s\n",
35f6aa61d5SZhikang Zhang oncs & 0x08 ? "yes" : "no");
36f6aa61d5SZhikang Zhang printf("\tWrite Zeroes: %s\n",
37f6aa61d5SZhikang Zhang oncs & 0x04 ? "yes" : "no");
38f6aa61d5SZhikang Zhang printf("\tDataset Management: %s\n",
39f6aa61d5SZhikang Zhang oncs & 0x02 ? "yes" : "no");
40f6aa61d5SZhikang Zhang printf("\tWrite Uncorrectable: %s\n",
41f6aa61d5SZhikang Zhang oncs & 0x01 ? "yes" : "no");
42f6aa61d5SZhikang Zhang }
43f6aa61d5SZhikang Zhang
print_format_nvme_attributes(u8 fna,int devnum)44f6aa61d5SZhikang Zhang static void print_format_nvme_attributes(u8 fna, int devnum)
45f6aa61d5SZhikang Zhang {
46f6aa61d5SZhikang Zhang printf("Blk device %d: Format NVM Attributes:\n", devnum);
47f6aa61d5SZhikang Zhang printf("\tSupport Cryptographic Erase: %s\n",
48f6aa61d5SZhikang Zhang fna & 0x04 ? "yes" : "No");
49f6aa61d5SZhikang Zhang printf("\tSupport erase a particular namespace: %s\n",
50f6aa61d5SZhikang Zhang fna & 0x02 ? "No" : "Yes");
51f6aa61d5SZhikang Zhang printf("\tSupport format a particular namespace: %s\n",
52f6aa61d5SZhikang Zhang fna & 0x01 ? "No" : "Yes");
53f6aa61d5SZhikang Zhang }
54f6aa61d5SZhikang Zhang
print_format(struct nvme_lbaf * lbaf)55f6aa61d5SZhikang Zhang static void print_format(struct nvme_lbaf *lbaf)
56f6aa61d5SZhikang Zhang {
57f6aa61d5SZhikang Zhang u8 str[][10] = {"Best", "Better", "Good", "Degraded"};
58f6aa61d5SZhikang Zhang
59f6aa61d5SZhikang Zhang printf("\t\tMetadata Size: %d\n", le16_to_cpu(lbaf->ms));
60f6aa61d5SZhikang Zhang printf("\t\tLBA Data Size: %d\n", 1 << lbaf->ds);
61f6aa61d5SZhikang Zhang printf("\t\tRelative Performance: %s\n", str[lbaf->rp & 0x03]);
62f6aa61d5SZhikang Zhang }
63f6aa61d5SZhikang Zhang
print_formats(struct nvme_id_ns * id,struct nvme_ns * ns)64f6aa61d5SZhikang Zhang static void print_formats(struct nvme_id_ns *id, struct nvme_ns *ns)
65f6aa61d5SZhikang Zhang {
66f6aa61d5SZhikang Zhang int i;
67f6aa61d5SZhikang Zhang
68f6aa61d5SZhikang Zhang printf("Blk device %d: LBA Format Support:\n", ns->devnum);
69f6aa61d5SZhikang Zhang
70f6aa61d5SZhikang Zhang for (i = 0; i < id->nlbaf; i++) {
71f6aa61d5SZhikang Zhang printf("\tLBA Foramt %d Support: ", i);
72f6aa61d5SZhikang Zhang if (i == ns->flbas)
73f6aa61d5SZhikang Zhang printf("(current)\n");
74f6aa61d5SZhikang Zhang else
75f6aa61d5SZhikang Zhang printf("\n");
76f6aa61d5SZhikang Zhang print_format(id->lbaf + i);
77f6aa61d5SZhikang Zhang }
78f6aa61d5SZhikang Zhang }
79f6aa61d5SZhikang Zhang
print_data_protect_cap(u8 dpc,int devnum)80f6aa61d5SZhikang Zhang static void print_data_protect_cap(u8 dpc, int devnum)
81f6aa61d5SZhikang Zhang {
82f6aa61d5SZhikang Zhang printf("Blk device %d: End-to-End Data", devnum);
83f6aa61d5SZhikang Zhang printf("Protect Capabilities:\n");
84f6aa61d5SZhikang Zhang printf("\tAs last eight bytes: %s\n",
85f6aa61d5SZhikang Zhang dpc & 0x10 ? "yes" : "No");
86f6aa61d5SZhikang Zhang printf("\tAs first eight bytes: %s\n",
87f6aa61d5SZhikang Zhang dpc & 0x08 ? "yes" : "No");
88f6aa61d5SZhikang Zhang printf("\tSupport Type3: %s\n",
89f6aa61d5SZhikang Zhang dpc & 0x04 ? "yes" : "No");
90f6aa61d5SZhikang Zhang printf("\tSupport Type2: %s\n",
91f6aa61d5SZhikang Zhang dpc & 0x02 ? "yes" : "No");
92f6aa61d5SZhikang Zhang printf("\tSupport Type1: %s\n",
93f6aa61d5SZhikang Zhang dpc & 0x01 ? "yes" : "No");
94f6aa61d5SZhikang Zhang }
95f6aa61d5SZhikang Zhang
print_metadata_cap(u8 mc,int devnum)96f6aa61d5SZhikang Zhang static void print_metadata_cap(u8 mc, int devnum)
97f6aa61d5SZhikang Zhang {
98f6aa61d5SZhikang Zhang printf("Blk device %d: Metadata capabilities:\n", devnum);
99f6aa61d5SZhikang Zhang printf("\tAs part of a separate buffer: %s\n",
100f6aa61d5SZhikang Zhang mc & 0x02 ? "yes" : "No");
101f6aa61d5SZhikang Zhang printf("\tAs part of an extended data LBA: %s\n",
102f6aa61d5SZhikang Zhang mc & 0x01 ? "yes" : "No");
103f6aa61d5SZhikang Zhang }
104f6aa61d5SZhikang Zhang
nvme_print_info(struct udevice * udev)105f6aa61d5SZhikang Zhang int nvme_print_info(struct udevice *udev)
106f6aa61d5SZhikang Zhang {
107f6aa61d5SZhikang Zhang struct nvme_ns *ns = dev_get_priv(udev);
108f6aa61d5SZhikang Zhang struct nvme_dev *dev = ns->dev;
109704e040aSBin Meng ALLOC_CACHE_ALIGN_BUFFER(char, buf_ns, sizeof(struct nvme_id_ns));
110704e040aSBin Meng struct nvme_id_ns *id = (struct nvme_id_ns *)buf_ns;
111704e040aSBin Meng ALLOC_CACHE_ALIGN_BUFFER(char, buf_ctrl, sizeof(struct nvme_id_ctrl));
112704e040aSBin Meng struct nvme_id_ctrl *ctrl = (struct nvme_id_ctrl *)buf_ctrl;
113f6aa61d5SZhikang Zhang
114f6aa61d5SZhikang Zhang if (nvme_identify(dev, 0, 1, (dma_addr_t)ctrl))
115f6aa61d5SZhikang Zhang return -EIO;
116f6aa61d5SZhikang Zhang
117f6aa61d5SZhikang Zhang print_optional_admin_cmd(le16_to_cpu(ctrl->oacs), ns->devnum);
118f6aa61d5SZhikang Zhang print_optional_nvm_cmd(le16_to_cpu(ctrl->oncs), ns->devnum);
119f6aa61d5SZhikang Zhang print_format_nvme_attributes(ctrl->fna, ns->devnum);
120f6aa61d5SZhikang Zhang
121f6aa61d5SZhikang Zhang if (nvme_identify(dev, ns->ns_id, 0, (dma_addr_t)id))
122f6aa61d5SZhikang Zhang return -EIO;
123f6aa61d5SZhikang Zhang
124f6aa61d5SZhikang Zhang print_formats(id, ns);
125f6aa61d5SZhikang Zhang print_data_protect_cap(id->dpc, ns->devnum);
126f6aa61d5SZhikang Zhang print_metadata_cap(id->mc, ns->devnum);
127f6aa61d5SZhikang Zhang
128f6aa61d5SZhikang Zhang return 0;
129f6aa61d5SZhikang Zhang }
130