From nobody Mon Nov 16 21:01:00 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jT0dS4jFgz70wjK for ; Mon, 16 Nov 2026 21:01:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jT0dS3DLnz4D9s for ; Mon, 16 Nov 2026 21:01:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794862860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dptThT0X24gxQoFpeAA1VNYg/mfCbXZZRjiCzk7h4/Y=; b=tLEcCJ0l7HwzAhXMttGhmCGOAl2cFimJ7ww81YKLjHKF9pPbaIoZA6JcOGzAnN4GIu/WzB qKVyDUAZT/1tfA++S8b3mLWLqrhUoENhkgD99aZfK0PvL8Ulcp5TMapDDCLDehadeJEnv6 HiVmTNuwOARogLyHD8HIHDC2fhz3+rvPomSG8p+piV64w5XWcCD2xiAZZuDzs19P2RbLDY oqFfXuaWvC2wMQm+RssbyveYCY2eIj4zgzWTrssME5/yYayagqRFsNuZG4SbU5oZJ85+Ih HaPNz+rw/bpDB4SBHYNcJALnGiFKJY57IfFM370TX6GcoFDfSQSLVHQz29IR9w== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794862860; b=i4rTpG6tfja0fUBXOyibrptrUUgETByg6m+pjUEoVcUfbc0rK4Uu5ExGigZRyTPf9j7s7l atXVKpLDtaHy3sIZtqOhL4EZtzKtUqyOeInpV5T+k2ZA4aOWVJBuhLFs54IaFss+Q2fsmZ fd+zu2vfKXyb5g8gcMBJmhz1PqrAzRm5HbfSzulj1awz42FP+fPNLWOkrtjdGMw/FT8wki OxwKDSwoSk7CDfKoUIOYfzh1dIxkd0wg/qelb/W8tHJ9LVVxCne8AoM3gzSe/zEUw3u5kU r+CPPgU6Qdhg3HibDmFXGaNNn9cwatajsDEMSl4GDd77+oQeoOP9Yfvihd6kqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794862860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dptThT0X24gxQoFpeAA1VNYg/mfCbXZZRjiCzk7h4/Y=; b=H1PFkumkeZ03c5iTQOeNglFLQBd/Yfi2YpYlO7y3hWuMVhpGBTHFODmhf79721U0G1sO0W FptvvsJruwp+yeWCnQDz7b2uH0tDdg9UYjmFoyE5ZhHQYMivsMO4VzD+oG0grmOEl4l4xa KJkto8gBuXjzKY8xRvhW4evggPQNqBmisNih6S5FDVEC5UmIWy1wDCspBHZxobY04vdFeD OsBXJ477+KyiT9FJp4lnwYlSy4Dl65XSMcyVMedhTSWjJtWS+mLLpn2VZCJ0g2UUtwEzsK Kz4D/M/8LtvIaZqTqz3zLzb8AHLLP10Lr9IkAaSoRDbRg7xJdn/S03bvMfLZNg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jT0dS2q3Pz191Q for ; Mon, 16 Nov 2026 21:01:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 8036 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 16 Nov 2026 21:01:00 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kenneth D. Merry Subject: git: 2ebb10da6a83 - stable/14 - nvme: Add reservation, format and features command building support List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ken X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 2ebb10da6a83ac596468e2feb44aea956dd77a7f Auto-Submitted: auto-generated Date: Mon, 16 Nov 2026 21:01:00 +0000 Message-Id: <6afb6f0c.8036.3b869108@gitrepo.freebsd.org> The branch stable/14 has been updated by ken: URL: https://cgit.FreeBSD.org/src/commit/?id=2ebb10da6a83ac596468e2feb44aea956dd77a7f commit 2ebb10da6a83ac596468e2feb44aea956dd77a7f Author: Kenneth D. Merry AuthorDate: 2026-11-07 01:05:54 +0000 Commit: Kenneth D. Merry CommitDate: 2026-11-16 21:00:05 +0000 nvme: Add reservation, format and features command building support Add command (struct nvme_command) building functions for the four NVMe reservation opcodes (Report, Register, Acquire and Release), Format NVM, and Get Features / Set Features, along with the enumerations and data structures that go with them. These are shared between the kernel and userland, and are the underpinnings for new camcontrol(8) subcommands (nvres, nvformat, nvfeature) that will be added separately. The reservation type names are intentionally similar to the SCSI names for the same reservation types. sys/dev/nvme/nvme.h: Add NVMe command building functions for the four NVMe reservation opcodes: nvme_ns_resv_report_cmd(), nvme_ns_resv_register_cmd(), nvme_ns_resv_acquire_cmd() and nvme_ns_resv_release_cmd(). Add enumerated types for the various NVMe reservation subcommand actions (acquire, register, release), reservation types, and Change Persist Through Power Loss State values. Add struct nvme_resv_acq_data and struct nvme_resv_reg_data, the data payloads for reservation Acquire and Register. Add a new NVMe Format NVM command building function, nvme_admin_format_cmd(), and an enumeration for the Secure Erase Setting parameter for format. Add nvme_admin_get_feature_cmd() and nvme_admin_set_feature_cmd() functions to fill a struct nvme_command for Get Features / Set Features. Add macros for bitfields in the ctratt and mic dwords of the NVMe Identify Controller data structure. Add a prototype for nvme_hostid_sbuf(). Stop byte swapping the hostid fields in nvme_resv_status_swapbytes() and nvme_resv_status_ext_swapbytes(), and document the fields as little endian. The hostid is an opaque 8 or 16 byte value; keep it in the byte order the device returns it in instead of interpreting it at this level. Widen the nvme_ctrlr_cmd_get_feature() and nvme_ctrlr_cmd_set_feature() prototypes as described below. While here, fix the entry count clamp in the reservation status swapbytes functions to use sizeof(*s) rather than sizeof(s); using the pointer size made the clamp one entry too permissive. sys/dev/nvme/nvme_util.c: Add nvme_hostid_sbuf(), which formats an 8 or 16 byte hostid (from the Get Features hostid feature, in the little-endian byte order the device returns it in) into an sbuf as an integer value in base 16, most significant byte first. sbin/nvmecontrol/resv.c: Decode the now little-endian hostid fields explicitly when printing, and zero pad the printed 64-bit values. Previously the extended hostid printed in a different byte order on big and little endian machines, and without zero padding between the two halves. sys/dev/nvme/nvme_ctrlr_cmd.c: Refactor nvme_ctrlr_cmd_get_feature() and nvme_ctrlr_cmd_set_feature() to use the new command building functions from nvme.h and accept a namespace ID parameter. Refactor nvme_ctrlr_cmd_set_feature() to also accept the sv (save) parameter to persist a feature value across reset. sys/dev/nvme/nvme_ctrlr.c: Update the temperature threshold, autonomous power state transition and host memory buffer callers for the new nvme_ctrlr_cmd_get_feature() and nvme_ctrlr_cmd_set_feature() arguments. Co-authored-by: Reid Linnemann Co-authored-by: Dave Baukus Co-authored-by: Claude Fable 5 Reviewed by: imp MFC after: 1 week Sponsored by: Spectra Logic Differential Revision: https://reviews.freebsd.org/D59531 (cherry picked from commit 7a9e4375316b82ca3426820e24ee69101562611a) --- sbin/nvmecontrol/Makefile | 2 +- sbin/nvmecontrol/resv.c | 9 +- sys/dev/nvme/nvme.h | 190 +++++++++++++++++++++++++++++++++++++++--- sys/dev/nvme/nvme_ctrlr.c | 9 +- sys/dev/nvme/nvme_ctrlr_cmd.c | 33 +++----- sys/dev/nvme/nvme_util.c | 16 ++++ 6 files changed, 219 insertions(+), 40 deletions(-) diff --git a/sbin/nvmecontrol/Makefile b/sbin/nvmecontrol/Makefile index f534093b1332..6eac2931a9e0 100644 --- a/sbin/nvmecontrol/Makefile +++ b/sbin/nvmecontrol/Makefile @@ -23,7 +23,7 @@ SRCS+= sanitize.c SRCS+= selftest.c MAN= nvmecontrol.8 LDFLAGS+= -rdynamic -LIBADD+= util +LIBADD+= sbuf util SUBDIR= modules HAS_TESTS= SUBDIR.${MK_TESTS}+= tests diff --git a/sbin/nvmecontrol/resv.c b/sbin/nvmecontrol/resv.c index 835ad47a924c..0e5e7f5d0b83 100644 --- a/sbin/nvmecontrol/resv.c +++ b/sbin/nvmecontrol/resv.c @@ -418,8 +418,9 @@ resvreport(const struct cmd *f, int argc, char *argv[]) e->ctrlr[i].rcsts); printf(" Reservation Key: 0x%08jx\n", e->ctrlr[i].rkey); - printf(" Host Identifier: 0x%08jx%08jx\n", - e->ctrlr[i].hostid[0], e->ctrlr[i].hostid[1]); + printf(" Host Identifier: 0x%016jx%016jx\n", + le64toh(e->ctrlr[i].hostid[1]), + le64toh(e->ctrlr[i].hostid[0])); } } else { n = MIN(n, (sizeof(data) - sizeof(s)) / sizeof(s->ctrlr[0])); @@ -428,8 +429,8 @@ resvreport(const struct cmd *f, int argc, char *argv[]) s->ctrlr[i].ctrlr_id); printf(" Reservation Status: %u\n", s->ctrlr[i].rcsts); - printf(" Host Identifier: 0x%08jx\n", - s->ctrlr[i].hostid); + printf(" Host Identifier: 0x%016jx\n", + le64toh(s->ctrlr[i].hostid)); printf(" Reservation Key: 0x%08jx\n", s->ctrlr[i].rkey); } diff --git a/sys/dev/nvme/nvme.h b/sys/dev/nvme/nvme.h index 64b48da191e7..b052da3cd374 100644 --- a/sys/dev/nvme/nvme.h +++ b/sys/dev/nvme/nvme.h @@ -31,11 +31,15 @@ #ifdef _KERNEL #include +#else +#include #endif #include #include +struct sbuf; + #define NVME_PASSTHROUGH_CMD _IOWR('n', 0, struct nvme_pt_command) #define NVME_RESET_CONTROLLER _IO('n', 1) #define NVME_GET_NSID _IOR('n', 2, struct nvme_get_nsid) @@ -1096,6 +1100,68 @@ enum nvme_activate_action { NVME_AA_ACTIVATE = 0x2, }; +enum nvme_format_ses { + NVME_FORMAT_SES_NONE = 0x00, + NVME_FORMAT_SES_USER = 0x01, + NVME_FORMAT_SES_CRYPTO = 0x02 +}; + +/* + * Ignore Existing Key + */ +#define NVME_RESV_IEKEY_MASK 0x01 + +/* + * Actions for Reservation Acquire + */ +#define NVME_RESV_ACQUIRE_MASK 0x07 +enum nvme_resv_acquire_action { + NVME_RESV_ACQUIRE_ACQUIRE = 0x00, + NVME_RESV_ACQUIRE_PREEMPT = 0x01, + NVME_RESV_ACQUIRE_PREEMPT_ABT = 0x02 +}; + +/* + * Reservation types for Reservation Acquire. + */ +enum nvme_resv_type { + NVME_RESV_TYPE_WR_EX = 0x01, + NVME_RESV_TYPE_EX_AC = 0x02, + NVME_RESV_TYPE_WR_EX_RO = 0x03, + NVME_RESV_TYPE_EX_AC_RO = 0x04, + NVME_RESV_TYPE_WR_EX_AR = 0x05, + NVME_RESV_TYPE_EX_AC_AR = 0x06 +}; + + +/* + * Values for Reservation Register Change Persist Through Power Loss State + */ +#define NVME_RESV_CPTPL_MASK 0x03 +enum nvme_resv_cptpl { + NVME_RESV_CPTPL_NOCHANGE = 0x00, + NVME_RESV_CPTPL_0 = 0x02, + NVME_RESV_CPTPL_1 = 0x03 +}; + +/* + * Actions for Reservation Register + */ +#define NVME_RESV_REG_MASK 0x07 +enum nvme_resv_register_action { + NVME_RESV_REG_REGISTER = 0x00, + NVME_RESV_REG_UNREGISTER = 0x01, + NVME_RESV_REG_REPLACE = 0x02 +}; + +/* + * Actions for Reservation Release + */ +enum nvme_resv_release_action { + NVME_RESV_REL_RELEASE = 0x00, + NVME_RESV_REL_CLEAR = 0x01 +}; + struct nvme_power_state { /** Maximum Power */ uint16_t mp; /* Maximum Power */ @@ -1150,6 +1216,10 @@ struct nvme_controller_data { uint8_t ieee[3]; /** multi-interface capabilities */ +#define NVME_CD_MIC_MPORT 0x01 +#define NVME_CD_MIC_MCTRL 0x02 +#define NVME_CD_MIC_SRIOV 0x04 +#define NVME_CD_MIC_ANAR 0x08 uint8_t mic; /** maximum data transfer size */ @@ -1171,7 +1241,17 @@ struct nvme_controller_data { uint32_t oaes; /* bitfield really */ /** Controller Attributes */ - uint32_t ctratt; /* bitfield really */ +#define NVME_CD_CTRATT_EXHID 0x001 +#define NVME_CD_CTRATT_NOPSPM 0x002 +#define NVME_CD_CTRATT_NVMSETS 0x004 +#define NVME_CD_CTRATT_RRLVLS 0x008 +#define NVME_CD_CTRATT_ENDGRPS 0x010 +#define NVME_CD_CTRATT_PREDLM 0x020 +#define NVME_CD_CTRATT_TBKAS 0x040 +#define NVME_CD_CTRATT_NSGRAN 0x080 +#define NVME_CD_CTRATT_SQASSOC 0x100 +#define NVME_CD_CTRATT_UUIDLIST 0x200 + uint32_t ctratt; /** Read Recovery Levels Supported */ uint16_t rrls; @@ -1723,11 +1803,25 @@ struct intel_log_temp_stats { _Static_assert(sizeof(struct intel_log_temp_stats) == 13 * 8, "bad size for intel_log_temp_stats"); +struct nvme_resv_acq_data { + uint64_t crkey; + uint64_t prkey; +} __packed __aligned(4); + +_Static_assert(sizeof(struct nvme_resv_acq_data) == 2 * 8, "bad size for nvme_resv_acq_data"); + +struct nvme_resv_reg_data { + uint64_t crkey; + uint64_t nrkey; +} __packed __aligned(4); + +_Static_assert(sizeof(struct nvme_resv_reg_data) == 2 * 8, "bad size for nvme_resv_reg_data"); + struct nvme_resv_reg_ctrlr { uint16_t ctrlr_id; /* Controller ID */ uint8_t rcsts; /* Reservation Status */ uint8_t reserved3[5]; - uint64_t hostid; /* Host Identifier */ + uint64_t hostid; /* Host Identifier (little endian) */ uint64_t rkey; /* Reservation Key */ } __packed __aligned(4); @@ -1738,7 +1832,7 @@ struct nvme_resv_reg_ctrlr_ext { uint8_t rcsts; /* Reservation Status */ uint8_t reserved3[5]; uint64_t rkey; /* Reservation Key */ - uint64_t hostid[2]; /* Host Identifier */ + uint64_t hostid[2]; /* Host Identifier (little endian) */ uint8_t reserved32[32]; } __packed __aligned(4); @@ -1855,6 +1949,7 @@ struct nvme_hmb_desc { #define nvme_completion_is_error(cpl) \ (NVME_STATUS_GET_SC((cpl)->status) != 0 || NVME_STATUS_GET_SCT((cpl)->status) != 0) +void nvme_hostid_sbuf(struct sbuf *sb, const uint8_t *hostid, bool exhid); void nvme_strvis(uint8_t *dst, const uint8_t *src, int dstlen, int srclen); #ifdef _KERNEL @@ -1885,13 +1980,13 @@ int nvme_ctrlr_passthrough_cmd(struct nvme_controller *ctrlr, int is_admin_cmd); /* Admin functions */ -void nvme_ctrlr_cmd_set_feature(struct nvme_controller *ctrlr, - uint8_t feature, uint32_t cdw11, +void nvme_ctrlr_cmd_set_feature(struct nvme_controller *ctrlr, uint32_t nsid, + int sv, uint8_t feature, uint32_t cdw11, uint32_t cdw12, uint32_t cdw13, uint32_t cdw14, uint32_t cdw15, void *payload, uint32_t payload_size, nvme_cb_fn_t cb_fn, void *cb_arg); -void nvme_ctrlr_cmd_get_feature(struct nvme_controller *ctrlr, +void nvme_ctrlr_cmd_get_feature(struct nvme_controller *ctrlr, uint32_t nsid, uint8_t feature, uint32_t cdw11, void *payload, uint32_t payload_size, nvme_cb_fn_t cb_fn, void *cb_arg); @@ -2020,6 +2115,83 @@ nvme_ns_data_format_index(const struct nvme_namespace_data *nsdata) return (fmt); } +static inline +void nvme_ns_resv_report_cmd(struct nvme_command *cmd, uint32_t nsid, + uint32_t length, uint32_t report_type) +{ + cmd->opc = NVME_OPC_RESERVATION_REPORT; + cmd->nsid = htole32(nsid); + cmd->cdw10 = htole32(length); + cmd->cdw11 = htole32(report_type); +} + +static inline +void nvme_ns_resv_register_cmd(struct nvme_command *cmd, uint32_t nsid, + int cptpl, int iekey, int rrega) +{ + cmd->opc = NVME_OPC_RESERVATION_REGISTER; + cmd->nsid = htole32(nsid); + cmd->cdw10 = htole32((rrega & NVME_RESV_REG_MASK) | ((iekey & NVME_RESV_IEKEY_MASK) << 3) | + ((cptpl & NVME_RESV_CPTPL_MASK) << 30)); +} + +static inline +void nvme_ns_resv_acquire_cmd(struct nvme_command *cmd, uint32_t nsid, + int rtype, int iekey, int racqa) +{ + cmd->opc = NVME_OPC_RESERVATION_ACQUIRE; + cmd->nsid = htole32(nsid); + cmd->cdw10 = htole32(((rtype & 0x0f) << 8) | ((iekey & NVME_RESV_IEKEY_MASK) << 3) | + (racqa & NVME_RESV_ACQUIRE_MASK)); +} + +static inline +void nvme_ns_resv_release_cmd(struct nvme_command *cmd, uint32_t nsid, + int rtype, int iekey, int rrela) +{ + cmd->opc = NVME_OPC_RESERVATION_RELEASE; + cmd->nsid = htole32(nsid); + cmd->cdw10 = htole32(((rtype & 0x0f) << 8) | ((iekey & NVME_RESV_IEKEY_MASK) << 3) | + (rrela & 0x07)); +} + + +static inline +void nvme_admin_format_cmd(struct nvme_command *cmd, uint32_t nsid, + int ses, int pil, int pi, int mset, int lbaf) +{ + cmd->opc = NVME_OPC_FORMAT_NVM; + cmd->nsid = htole32(nsid); + cmd->cdw10 = htole32((ses << 9) | (pil << 8) | (pi << 5) | (mset << 4) | + lbaf); +} + +static inline +void nvme_admin_get_feature_cmd(struct nvme_command *cmd, uint32_t nsid, + int sel, uint8_t feature, uint32_t cdw11, int uuid_idx) { + cmd->opc = NVME_OPC_GET_FEATURES; + cmd->nsid = nsid; + cmd->cdw10 = htole32(((sel & 0x7) << 8) | feature); + cmd->cdw11 = htole32(cdw11); + cmd->cdw14 = htole32(uuid_idx & 0x7f); +} + + +static inline +void nvme_admin_set_feature_cmd(struct nvme_command *cmd, uint32_t nsid, + int sv, uint8_t feature, uint32_t cdw11, uint32_t cdw12, + uint32_t cdw13, uint32_t cdw14, uint32_t cdw15) +{ + cmd->opc = NVME_OPC_SET_FEATURES; + cmd->nsid = nsid; + cmd->cdw10 = htole32(((sv & 0x1) << 31) | feature); + cmd->cdw11 = htole32(cdw11); + cmd->cdw12 = htole32(cdw12); + cmd->cdw13 = htole32(cdw13); + cmd->cdw14 = htole32(cdw14); + cmd->cdw15 = htole32(cdw15); +} + /* Endianess conversion functions for NVMe structs */ static inline void nvme_completion_swapbytes(struct nvme_completion *s __unused) @@ -2257,10 +2429,9 @@ void nvme_resv_status_swapbytes(struct nvme_resv_status *s __unused, s->gen = le32toh(s->gen); n = (s->regctl[1] << 8) | s->regctl[0]; - n = MIN(n, (size - sizeof(s)) / sizeof(s->ctrlr[0])); + n = MIN(n, (size - sizeof(*s)) / sizeof(s->ctrlr[0])); for (i = 0; i < n; i++) { s->ctrlr[i].ctrlr_id = le16toh(s->ctrlr[i].ctrlr_id); - s->ctrlr[i].hostid = le64toh(s->ctrlr[i].hostid); s->ctrlr[i].rkey = le64toh(s->ctrlr[i].rkey); } #endif @@ -2275,11 +2446,10 @@ void nvme_resv_status_ext_swapbytes(struct nvme_resv_status_ext *s __unused, s->gen = le32toh(s->gen); n = (s->regctl[1] << 8) | s->regctl[0]; - n = MIN(n, (size - sizeof(s)) / sizeof(s->ctrlr[0])); + n = MIN(n, (size - sizeof(*s)) / sizeof(s->ctrlr[0])); for (i = 0; i < n; i++) { s->ctrlr[i].ctrlr_id = le16toh(s->ctrlr[i].ctrlr_id); s->ctrlr[i].rkey = le64toh(s->ctrlr[i].rkey); - nvme_le128toh((void *)s->ctrlr[i].hostid); } #endif } diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c index 19fd4e70666e..2f593ed7abaf 100644 --- a/sys/dev/nvme/nvme_ctrlr.c +++ b/sys/dev/nvme/nvme_ctrlr.c @@ -854,7 +854,7 @@ nvme_ctrlr_configure_aer(struct nvme_controller *ctrlr) NVME_ASYNC_EVENT_FW_ACTIVATE; status.done = 0; - nvme_ctrlr_cmd_get_feature(ctrlr, NVME_FEAT_TEMPERATURE_THRESHOLD, + nvme_ctrlr_cmd_get_feature(ctrlr, 0, NVME_FEAT_TEMPERATURE_THRESHOLD, 0, NULL, 0, nvme_completion_poll_cb, &status); nvme_completion_poll(&status); if (nvme_completion_is_error(&status.cpl) || @@ -1056,11 +1056,10 @@ nvme_ctrlr_hmb_enable(struct nvme_controller *ctrlr, bool enable, bool memret) if (memret) cdw11 |= 2; status.done = 0; - nvme_ctrlr_cmd_set_feature(ctrlr, NVME_FEAT_HOST_MEMORY_BUFFER, cdw11, - ctrlr->hmb_nchunks * ctrlr->hmb_chunk / ctrlr->page_size, + nvme_ctrlr_cmd_set_feature(ctrlr, 0, 0, NVME_FEAT_HOST_MEMORY_BUFFER, + cdw11, ctrlr->hmb_nchunks * ctrlr->hmb_chunk / 4096, ctrlr->hmb_desc_paddr, ctrlr->hmb_desc_paddr >> 32, - ctrlr->hmb_nchunks, NULL, 0, - nvme_completion_poll_cb, &status); + ctrlr->hmb_nchunks, NULL, 0, nvme_completion_poll_cb, &status); nvme_completion_poll(&status); if (nvme_completion_is_error(&status.cpl)) nvme_printf(ctrlr, "nvme_ctrlr_hmb_enable failed!\n"); diff --git a/sys/dev/nvme/nvme_ctrlr_cmd.c b/sys/dev/nvme/nvme_ctrlr_cmd.c index 68934b9b3947..9b57ae7d970a 100644 --- a/sys/dev/nvme/nvme_ctrlr_cmd.c +++ b/sys/dev/nvme/nvme_ctrlr_cmd.c @@ -163,9 +163,9 @@ nvme_ctrlr_cmd_delete_io_sq(struct nvme_controller *ctrlr, } void -nvme_ctrlr_cmd_set_feature(struct nvme_controller *ctrlr, uint8_t feature, - uint32_t cdw11, uint32_t cdw12, uint32_t cdw13, uint32_t cdw14, - uint32_t cdw15, void *payload, uint32_t payload_size, +nvme_ctrlr_cmd_set_feature(struct nvme_controller *ctrlr, uint32_t nsid, int sv, + uint8_t feature, uint32_t cdw11, uint32_t cdw12, uint32_t cdw13, + uint32_t cdw14, uint32_t cdw15, void *payload, uint32_t payload_size, nvme_cb_fn_t cb_fn, void *cb_arg) { struct nvme_request *req; @@ -174,20 +174,15 @@ nvme_ctrlr_cmd_set_feature(struct nvme_controller *ctrlr, uint8_t feature, req = nvme_allocate_request_null(cb_fn, cb_arg); cmd = &req->cmd; - cmd->opc = NVME_OPC_SET_FEATURES; - cmd->cdw10 = htole32(feature); - cmd->cdw11 = htole32(cdw11); - cmd->cdw12 = htole32(cdw12); - cmd->cdw13 = htole32(cdw13); - cmd->cdw14 = htole32(cdw14); - cmd->cdw15 = htole32(cdw15); + nvme_admin_set_feature_cmd(cmd, nsid, sv, feature, cdw11, cdw12, cdw13, + cdw14, cdw15); nvme_ctrlr_submit_admin_request(ctrlr, req); } void -nvme_ctrlr_cmd_get_feature(struct nvme_controller *ctrlr, uint8_t feature, - uint32_t cdw11, void *payload, uint32_t payload_size, +nvme_ctrlr_cmd_get_feature(struct nvme_controller *ctrlr, uint32_t nsid, + uint8_t feature, uint32_t cdw11, void *payload, uint32_t payload_size, nvme_cb_fn_t cb_fn, void *cb_arg) { struct nvme_request *req; @@ -196,9 +191,7 @@ nvme_ctrlr_cmd_get_feature(struct nvme_controller *ctrlr, uint8_t feature, req = nvme_allocate_request_null(cb_fn, cb_arg); cmd = &req->cmd; - cmd->opc = NVME_OPC_GET_FEATURES; - cmd->cdw10 = htole32(feature); - cmd->cdw11 = htole32(cdw11); + nvme_admin_get_feature_cmd(cmd, nsid, 0, feature, cdw11, 0); nvme_ctrlr_submit_admin_request(ctrlr, req); } @@ -210,8 +203,8 @@ nvme_ctrlr_cmd_set_num_queues(struct nvme_controller *ctrlr, uint32_t cdw11; cdw11 = ((num_queues - 1) << 16) | (num_queues - 1); - nvme_ctrlr_cmd_set_feature(ctrlr, NVME_FEAT_NUMBER_OF_QUEUES, cdw11, - 0, 0, 0, 0, NULL, 0, cb_fn, cb_arg); + nvme_ctrlr_cmd_set_feature(ctrlr, 0, 0, NVME_FEAT_NUMBER_OF_QUEUES, + cdw11, 0, 0, 0, 0, NULL, 0, cb_fn, cb_arg); } void @@ -221,7 +214,7 @@ nvme_ctrlr_cmd_set_async_event_config(struct nvme_controller *ctrlr, uint32_t cdw11; cdw11 = state; - nvme_ctrlr_cmd_set_feature(ctrlr, + nvme_ctrlr_cmd_set_feature(ctrlr, 0, 0, NVME_FEAT_ASYNC_EVENT_CONFIGURATION, cdw11, 0, 0, 0, 0, NULL, 0, cb_fn, cb_arg); } @@ -247,8 +240,8 @@ nvme_ctrlr_cmd_set_interrupt_coalescing(struct nvme_controller *ctrlr, } cdw11 = ((microseconds/100) << 8) | threshold; - nvme_ctrlr_cmd_set_feature(ctrlr, NVME_FEAT_INTERRUPT_COALESCING, cdw11, - 0, 0, 0, 0, NULL, 0, cb_fn, cb_arg); + nvme_ctrlr_cmd_set_feature(ctrlr, 0, 0, NVME_FEAT_INTERRUPT_COALESCING, + cdw11, 0, 0, 0, 0, NULL, 0, cb_fn, cb_arg); } void diff --git a/sys/dev/nvme/nvme_util.c b/sys/dev/nvme/nvme_util.c index f54f3cf0a873..7e493cdf810c 100644 --- a/sys/dev/nvme/nvme_util.c +++ b/sys/dev/nvme/nvme_util.c @@ -29,8 +29,24 @@ #include #include +#include #include +/* + * Append an 8 or 16 byte hostid as an integer value in base 16 to an sbuf. + * The hostid is in the little-endian byte order the device returns it in, + * so print it most significant byte first. + */ +void +nvme_hostid_sbuf(struct sbuf *sb, const uint8_t *hostid, bool exhid) +{ + int i; + + sbuf_cat(sb, "0x"); + for (i = (exhid ? 16 : 8) - 1; i >= 0; i--) + sbuf_printf(sb, "%02x", hostid[i]); +} + void nvme_strvis(uint8_t *dst, const uint8_t *src, int dstlen, int srclen) {