1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 NXP Semiconductors
4 * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
14 static void print_optional_admin_cmd(u16 oacs, int devnum)
16 printf("Blk device %d: Optional Admin Command Support:\n",
18 printf("\tNamespace Management/Attachment: %s\n",
19 oacs & 0x08 ? "yes" : "no");
20 printf("\tFirmware Commit/Image download: %s\n",
21 oacs & 0x04 ? "yes" : "no");
22 printf("\tFormat NVM: %s\n",
23 oacs & 0x02 ? "yes" : "no");
24 printf("\tSecurity Send/Receive: %s\n",
25 oacs & 0x01 ? "yes" : "no");
28 static void print_optional_nvm_cmd(u16 oncs, int devnum)
30 printf("Blk device %d: Optional NVM Command Support:\n",
32 printf("\tReservation: %s\n",
33 oncs & 0x10 ? "yes" : "no");
34 printf("\tSave/Select field in the Set/Get features: %s\n",
35 oncs & 0x08 ? "yes" : "no");
36 printf("\tWrite Zeroes: %s\n",
37 oncs & 0x04 ? "yes" : "no");
38 printf("\tDataset Management: %s\n",
39 oncs & 0x02 ? "yes" : "no");
40 printf("\tWrite Uncorrectable: %s\n",
41 oncs & 0x01 ? "yes" : "no");
44 static void print_format_nvme_attributes(u8 fna, int devnum)
46 printf("Blk device %d: Format NVM Attributes:\n", devnum);
47 printf("\tSupport Cryptographic Erase: %s\n",
48 fna & 0x04 ? "yes" : "No");
49 printf("\tSupport erase a particular namespace: %s\n",
50 fna & 0x02 ? "No" : "Yes");
51 printf("\tSupport format a particular namespace: %s\n",
52 fna & 0x01 ? "No" : "Yes");
55 static void print_format(struct nvme_lbaf *lbaf)
57 u8 str[][10] = {"Best", "Better", "Good", "Degraded"};
59 printf("\t\tMetadata Size: %d\n", le16_to_cpu(lbaf->ms));
60 printf("\t\tLBA Data Size: %d\n", 1 << lbaf->ds);
61 printf("\t\tRelative Performance: %s\n", str[lbaf->rp & 0x03]);
64 static void print_formats(struct nvme_id_ns *id, struct nvme_ns *ns)
68 printf("Blk device %d: LBA Format Support:\n", ns->devnum);
70 for (i = 0; i < id->nlbaf; i++) {
71 printf("\tLBA Foramt %d Support: ", i);
73 printf("(current)\n");
76 print_format(id->lbaf + i);
80 static void print_data_protect_cap(u8 dpc, int devnum)
82 printf("Blk device %d: End-to-End Data", devnum);
83 printf("Protect Capabilities:\n");
84 printf("\tAs last eight bytes: %s\n",
85 dpc & 0x10 ? "yes" : "No");
86 printf("\tAs first eight bytes: %s\n",
87 dpc & 0x08 ? "yes" : "No");
88 printf("\tSupport Type3: %s\n",
89 dpc & 0x04 ? "yes" : "No");
90 printf("\tSupport Type2: %s\n",
91 dpc & 0x02 ? "yes" : "No");
92 printf("\tSupport Type1: %s\n",
93 dpc & 0x01 ? "yes" : "No");
96 static void print_metadata_cap(u8 mc, int devnum)
98 printf("Blk device %d: Metadata capabilities:\n", devnum);
99 printf("\tAs part of a separate buffer: %s\n",
100 mc & 0x02 ? "yes" : "No");
101 printf("\tAs part of an extended data LBA: %s\n",
102 mc & 0x01 ? "yes" : "No");
105 int nvme_print_info(struct udevice *udev)
107 struct nvme_ns *ns = dev_get_priv(udev);
108 struct nvme_dev *dev = ns->dev;
109 ALLOC_CACHE_ALIGN_BUFFER(char, buf_ns, sizeof(struct nvme_id_ns));
110 struct nvme_id_ns *id = (struct nvme_id_ns *)buf_ns;
111 ALLOC_CACHE_ALIGN_BUFFER(char, buf_ctrl, sizeof(struct nvme_id_ctrl));
112 struct nvme_id_ctrl *ctrl = (struct nvme_id_ctrl *)buf_ctrl;
114 if (nvme_identify(dev, 0, 1, (dma_addr_t)(long)ctrl))
117 print_optional_admin_cmd(le16_to_cpu(ctrl->oacs), ns->devnum);
118 print_optional_nvm_cmd(le16_to_cpu(ctrl->oncs), ns->devnum);
119 print_format_nvme_attributes(ctrl->fna, ns->devnum);
121 if (nvme_identify(dev, ns->ns_id, 0, (dma_addr_t)(long)id))
124 print_formats(id, ns);
125 print_data_protect_cap(id->dpc, ns->devnum);
126 print_metadata_cap(id->mc, ns->devnum);