git: 3444d620b2a4 - stable/13 - bhyve nvme: Add Select support to Get Features

From: Chuck Tuffli <chuck_at_FreeBSD.org>
Date: Mon, 21 Feb 2022 21:58:01 UTC
The branch stable/13 has been updated by chuck:

URL: https://cgit.FreeBSD.org/src/commit/?id=3444d620b2a4c7c6eccd5f67b4e7cc2b48a73af9

commit 3444d620b2a4c7c6eccd5f67b4e7cc2b48a73af9
Author:     Chuck Tuffli <chuck@FreeBSD.org>
AuthorDate: 2022-01-30 07:09:35 +0000
Commit:     Chuck Tuffli <chuck@FreeBSD.org>
CommitDate: 2022-02-22 03:27:14 +0000

    bhyve nvme: Add Select support to Get Features
    
    Implement basic support for the SEL field of Get Features. This returns
    information about Namespace Specific features.
    
    Fixes UNH IOL 16.0 Test 1.2, Case 13
    
    (cherry picked from commit 073f2076fea4748b457b15dbd1d6e11b802b76f3)
---
 usr.sbin/bhyve/pci_nvme.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/usr.sbin/bhyve/pci_nvme.c b/usr.sbin/bhyve/pci_nvme.c
index 29c5aec4f44c..aff881bd5056 100644
--- a/usr.sbin/bhyve/pci_nvme.c
+++ b/usr.sbin/bhyve/pci_nvme.c
@@ -1798,12 +1798,16 @@ nvme_opc_set_features(struct pci_nvme_softc *sc, struct nvme_command *command,
 	return (0);
 }
 
+#define NVME_FEATURES_SEL_SUPPORTED	0x3
+#define NVME_FEATURES_NS_SPECIFIC	(1 << 1)
+
 static int
 nvme_opc_get_features(struct pci_nvme_softc* sc, struct nvme_command* command,
 	struct nvme_completion* compl)
 {
 	struct nvme_feature_obj *feat;
 	uint8_t fid = command->cdw10 & 0xFF;
+	uint8_t sel = (command->cdw10 >> 8) & 0x7;
 
 	DPRINTF("%s: Feature ID 0x%x (%s)", __func__, fid, nvme_fid_to_name(fid));
 
@@ -1822,7 +1826,10 @@ nvme_opc_get_features(struct pci_nvme_softc* sc, struct nvme_command* command,
 	}
 
 	if (compl->status == NVME_SC_SUCCESS) {
-		compl->cdw0 = feat->cdw11;
+		if ((sel == NVME_FEATURES_SEL_SUPPORTED) && feat->namespace_specific)
+			compl->cdw0 = NVME_FEATURES_NS_SPECIFIC;
+		else
+			compl->cdw0 = feat->cdw11;
 	}
 
 	return (0);