git: cc20d7570563 - stable/13 - nvme_ahci: Mark AHCI devices as such in the controller

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Fri, 21 Jan 2022 02:27:07 UTC
The branch stable/13 has been updated by mav:

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

commit cc20d7570563d5b7e2f91b07a9f2c8a0241cd061
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2021-12-06 17:23:06 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-01-21 02:07:31 +0000

    nvme_ahci: Mark AHCI devices as such in the controller
    
    Add a quirk to flag AHCI attachment to the controller. This is for any
    of the strategies for attaching nvme devices as children of the AHCI
    device for Intel's RAID devices. This also has a side effect of cleaning
    up resource allocation from failed nvme_attach calls now.
    
    Sponsored by:           Netflix
    Reviewed by:            mav
    Differential Revision:  https://reviews.freebsd.org/D33285
    
    (cherry picked from commit 7cf8d63c884c484fee9b287f792549ee15270ae7)
---
 sys/dev/nvme/nvme_ahci.c    | 9 ++++++++-
 sys/dev/nvme/nvme_private.h | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/sys/dev/nvme/nvme_ahci.c b/sys/dev/nvme/nvme_ahci.c
index 8542f6f55246..b2d5813537c3 100644
--- a/sys/dev/nvme/nvme_ahci.c
+++ b/sys/dev/nvme/nvme_ahci.c
@@ -104,7 +104,14 @@ nvme_ahci_attach(device_t dev)
 	}
 	ctrlr->tag = (void *)0x1;
 
-	return nvme_attach(dev);
+	/*
+	 * We're attached via this funky mechanism. Flag the controller so that
+	 * it avoids things that can't work when we do that, like asking for
+	 * PCI config space entries.
+	 */
+	ctrlr->quirks |= QUIRK_AHCI;
+
+	return (nvme_attach(dev));	/* Note: failure frees resources */
 bad:
 	if (ctrlr->resource != NULL) {
 		bus_release_resource(dev, SYS_RES_MEMORY,
diff --git a/sys/dev/nvme/nvme_private.h b/sys/dev/nvme/nvme_private.h
index 3f89f12cf8fd..c889246f9350 100644
--- a/sys/dev/nvme/nvme_private.h
+++ b/sys/dev/nvme/nvme_private.h
@@ -241,6 +241,7 @@ struct nvme_controller {
 #define	QUIRK_DELAY_B4_CHK_RDY	1		/* Can't touch MMIO on disable */
 #define	QUIRK_DISABLE_TIMEOUT	2		/* Disable broken completion timeout feature */
 #define	QUIRK_INTEL_ALIGNMENT	4		/* Pre NVMe 1.3 performance alignment */
+#define QUIRK_AHCI		8		/* Attached via AHCI redirect */
 
 	bus_space_tag_t		bus_tag;
 	bus_space_handle_t	bus_handle;