git: d5472cd4b3a3 - main - ata_kauai: Fix support for "shasta" controllers.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Mon, 18 Apr 2022 19:08:57 UTC
The branch main has been updated by jhb:

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

commit d5472cd4b3a3fedd56589a16a96f997d1d8fa1dc
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-04-18 19:06:52 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-04-18 19:06:52 +0000

    ata_kauai: Fix support for "shasta" controllers.
    
    The probe routine was setting a value in the softc, but since the
    probe routine was not returning zero, this value was lost since the
    softc was reallocated (and re-zeroed) when the device was attached.
    This is similar in nature to the fixes from
    965205eb66cae3fd5de75a70a3aef2f014f98020.
    
    To fix, move the code to set the 'shasta' flag to the start of attach
    along with related code to set an IRQ resource on some non-shasta
    devices.  The IRQ resource still "worked" being in the probe routine
    as the IRQ resource persisted after probe returned, but it is cleaner
    to go ahead and move it to attach after setting the 'shasta' flag.
    
    I have no way to test this, but noticed this while reading the code.
    
    Reviewed by:    jhibbits
    Differential Revision:  https://reviews.freebsd.org/D34888
---
 sys/powerpc/powermac/ata_kauai.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/sys/powerpc/powermac/ata_kauai.c b/sys/powerpc/powermac/ata_kauai.c
index f1aea059057f..75e676eadd81 100644
--- a/sys/powerpc/powermac/ata_kauai.c
+++ b/sys/powerpc/powermac/ata_kauai.c
@@ -196,9 +196,7 @@ static const u_int udma_timing_shasta[] = {
 static int
 ata_kauai_probe(device_t dev)
 {
-	struct ata_kauai_softc *sc;
 	u_int32_t devid;
-	const char *compatstring = NULL;
 	int i, found;
 
 	found = 0;
@@ -213,18 +211,6 @@ ata_kauai_probe(device_t dev)
 	if (!found)
 		return (ENXIO);
 
-	sc = device_get_softc(dev);
-	bzero(sc, sizeof(struct ata_kauai_softc));
-
-	compatstring = ofw_bus_get_compat(dev);
-	if (compatstring != NULL && strcmp(compatstring,"shasta-ata") == 0)
-		sc->shasta = 1;
-
-	/* Pre-K2 controllers apparently need this hack */
-	if (!sc->shasta &&
-	    (compatstring == NULL || strcmp(compatstring, "K2-UATA") != 0))
-		bus_set_resource(dev, SYS_RES_IRQ, 0, 39, 1);
-
         return (ata_probe(dev));
 }
 
@@ -245,6 +231,7 @@ ata_kauai_attach(device_t dev)
 {
 	struct ata_kauai_softc *sc = device_get_softc(dev);
 	struct ata_channel *ch;
+	const char *compatstring;
 	int i, rid;
 #if USE_DBDMA_IRQ
 	int dbdma_irq_rid = 1;
@@ -252,6 +239,15 @@ ata_kauai_attach(device_t dev)
 	void *cookie;
 #endif
 
+	compatstring = ofw_bus_get_compat(dev);
+	if (compatstring != NULL && strcmp(compatstring,"shasta-ata") == 0)
+		sc->shasta = 1;
+
+	/* Pre-K2 controllers apparently need this hack */
+	if (!sc->shasta &&
+	    (compatstring == NULL || strcmp(compatstring, "K2-UATA") != 0))
+		bus_set_resource(dev, SYS_RES_IRQ, 0, 39, 1);
+
 	ch = &sc->sc_ch.sc_ch;
 
         rid = PCIR_BARS;