aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/nvme/nvme.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/nvme/nvme.h')
-rw-r--r--sys/dev/nvme/nvme.h27
1 files changed, 25 insertions, 2 deletions
diff --git a/sys/dev/nvme/nvme.h b/sys/dev/nvme/nvme.h
index f4ea08f129c0..c8eba3df9c2a 100644
--- a/sys/dev/nvme/nvme.h
+++ b/sys/dev/nvme/nvme.h
@@ -1910,6 +1910,8 @@ void nvme_sc_sbuf(const struct nvme_completion *cpl, struct sbuf *sbuf);
void nvme_strvis(uint8_t *dst, const uint8_t *src, int dstlen, int srclen);
#ifdef _KERNEL
+#include <sys/systm.h>
+#include <sys/disk.h>
struct bio;
struct thread;
@@ -1928,8 +1930,11 @@ typedef void (*nvme_cons_async_fn_t)(void *, const struct nvme_completion *,
typedef void (*nvme_cons_fail_fn_t)(void *);
enum nvme_namespace_flags {
- NVME_NS_DEALLOCATE_SUPPORTED = 0x1,
- NVME_NS_FLUSH_SUPPORTED = 0x2,
+ NVME_NS_DEALLOCATE_SUPPORTED = 0x01,
+ NVME_NS_FLUSH_SUPPORTED = 0x02,
+ NVME_NS_ADDED = 0x04,
+ NVME_NS_CHANGED = 0x08,
+ NVME_NS_GONE = 0x10,
};
int nvme_ctrlr_passthrough_cmd(struct nvme_controller *ctrlr,
@@ -1995,6 +2000,24 @@ nvme_ctrlr_has_dataset_mgmt(const struct nvme_controller_data *cd)
return (NVMEV(NVME_CTRLR_DATA_ONCS_DSM, cd->oncs) != 0);
}
+/*
+ * Copy the NVME device's serial number to the provided buffer, which must be
+ * at least DISK_IDENT_SIZE bytes large.
+ */
+static inline void
+nvme_cdata_get_disk_ident(const struct nvme_controller_data *cdata, uint8_t *sn)
+{
+ _Static_assert(NVME_SERIAL_NUMBER_LENGTH < DISK_IDENT_SIZE,
+ "NVME serial number too big for disk ident");
+
+ memmove(sn, cdata->sn, NVME_SERIAL_NUMBER_LENGTH);
+ sn[NVME_SERIAL_NUMBER_LENGTH] = '\0';
+ for (int i = 0; sn[i] != '\0'; i++) {
+ if (sn[i] < 0x20 || sn[i] >= 0x80)
+ sn[i] = ' ';
+ }
+}
+
/* Namespace helper functions */
uint32_t nvme_ns_get_max_io_xfer_size(struct nvme_namespace *ns);
uint32_t nvme_ns_get_sector_size(struct nvme_namespace *ns);