nvme_show.c 3.8 KB

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