Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev detach the controller itself on shutdown; adjust to ...
details: https://anonhg.NetBSD.org/src/rev/8c1151e395d9
branches: trunk
changeset: 445355:8c1151e395d9
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Wed Oct 24 19:38:00 2018 +0000
description:
detach the controller itself on shutdown; adjust to not detach already
detached atabus/channel
diffstat:
sys/dev/ata/TODO.ncq | 3 ---
sys/dev/ata/ata.c | 6 ++++--
sys/dev/ata/atavar.h | 11 ++++++-----
sys/dev/ic/ahcisata_core.c | 35 ++++++++++++++++++++++++++++-------
sys/dev/ic/ahcisatavar.h | 3 ++-
sys/dev/ic/siisata.c | 36 ++++++++++++++++++++++++++----------
sys/dev/ic/siisatavar.h | 3 ++-
sys/dev/pci/ahcisata_pci.c | 19 +++++++++++++++----
sys/dev/pci/siisata_pci.c | 19 +++++++++++++++----
9 files changed, 98 insertions(+), 37 deletions(-)
diffs (truncated from 350 to 300 lines):
diff -r 8d4928dbf1bb -r 8c1151e395d9 sys/dev/ata/TODO.ncq
--- a/sys/dev/ata/TODO.ncq Wed Oct 24 18:27:15 2018 +0000
+++ b/sys/dev/ata/TODO.ncq Wed Oct 24 19:38:00 2018 +0000
@@ -14,6 +14,3 @@
- old bug - kern/16789
add support for the NCQ TRIM if supported by device?
-
-ahcisata(4)/siisata(4) - enable detach on shutdown, and fix the issue
-with atabus being detached several times
diff -r 8d4928dbf1bb -r 8c1151e395d9 sys/dev/ata/ata.c
--- a/sys/dev/ata/ata.c Wed Oct 24 18:27:15 2018 +0000
+++ b/sys/dev/ata/ata.c Wed Oct 24 19:38:00 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ata.c,v 1.142 2018/10/22 20:13:47 jdolecek Exp $ */
+/* $NetBSD: ata.c,v 1.143 2018/10/24 19:38:00 jdolecek Exp $ */
/*
* Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved.
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.142 2018/10/22 20:13:47 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.143 2018/10/24 19:38:00 jdolecek Exp $");
#include "opt_ata.h"
@@ -216,6 +216,8 @@
return;
ata_channel_destroy(chp);
+
+ chp->ch_flags |= ATACH_DETACHED;
}
static void
diff -r 8d4928dbf1bb -r 8c1151e395d9 sys/dev/ata/atavar.h
--- a/sys/dev/ata/atavar.h Wed Oct 24 18:27:15 2018 +0000
+++ b/sys/dev/ata/atavar.h Wed Oct 24 19:38:00 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atavar.h,v 1.100 2018/10/22 20:13:47 jdolecek Exp $ */
+/* $NetBSD: atavar.h,v 1.101 2018/10/24 19:38:00 jdolecek Exp $ */
/*
* Copyright (c) 1998, 2001 Manuel Bouyer.
@@ -410,10 +410,11 @@
#define ATACH_TH_RESET 0x200 /* someone ask the thread to reset */
#define ATACH_TH_RESCAN 0x400 /* rescan requested */
#define ATACH_NCQ 0x800 /* channel executing NCQ commands */
-#define ATACH_DMA_BEFORE_CMD 0x1000 /* start DMA first */
-#define ATACH_TH_DRIVE_RESET 0x2000 /* asked thread to drive(s) reset */
-#define ATACH_RECOVERING 0x4000 /* channel is recovering */
-#define ATACH_TH_RECOVERY 0x8000 /* asked thread to run recovery */
+#define ATACH_DMA_BEFORE_CMD 0x01000 /* start DMA first */
+#define ATACH_TH_DRIVE_RESET 0x02000 /* asked thread to drive(s) reset */
+#define ATACH_RECOVERING 0x04000 /* channel is recovering */
+#define ATACH_TH_RECOVERY 0x08000 /* asked thread to run recovery */
+#define ATACH_DETACHED 0x10000 /* channel was destroyed */
#define ATACH_NODRIVE 0xff /* no drive selected for reset */
diff -r 8d4928dbf1bb -r 8c1151e395d9 sys/dev/ic/ahcisata_core.c
--- a/sys/dev/ic/ahcisata_core.c Wed Oct 24 18:27:15 2018 +0000
+++ b/sys/dev/ic/ahcisata_core.c Wed Oct 24 19:38:00 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ahcisata_core.c,v 1.64 2018/10/22 20:13:47 jdolecek Exp $ */
+/* $NetBSD: ahcisata_core.c,v 1.65 2018/10/24 19:38:00 jdolecek Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.64 2018/10/22 20:13:47 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.65 2018/10/24 19:38:00 jdolecek Exp $");
#include <sys/types.h>
#include <sys/malloc.h>
@@ -477,6 +477,24 @@
}
}
+void
+ahci_childdetached(struct ahci_softc *sc, device_t child)
+{
+ struct ahci_channel *achp;
+ struct ata_channel *chp;
+
+ for (int i = 0; i < AHCI_MAX_PORTS; i++) {
+ achp = &sc->sc_channels[i];
+ chp = &achp->ata_channel;
+
+ if ((sc->sc_ahci_ports & (1U << i)) == 0)
+ continue;
+
+ if (child == chp->atabus)
+ chp->atabus = NULL;
+ }
+}
+
int
ahci_detach(struct ahci_softc *sc, int flags)
{
@@ -502,10 +520,15 @@
break;
}
- if (chp->atabus == NULL)
+ if (chp->atabus != NULL) {
+ if ((error = config_detach(chp->atabus, flags)) != 0)
+ return error;
+
+ KASSERT(chp->atabus == NULL);
+ }
+
+ if (chp->ch_flags & ATACH_DETACHED)
continue;
- if ((error = config_detach(chp->atabus, flags)) != 0)
- return error;
for (j = 0; j < sc->sc_ncmds; j++)
bus_dmamap_destroy(sc->sc_dmat, achp->ahcic_datad[j]);
@@ -517,8 +540,6 @@
bus_dmamem_free(sc->sc_dmat, &achp->ahcic_cmd_tbl_seg,
achp->ahcic_cmd_tbl_nseg);
- chp->atabus = NULL;
-
ata_channel_detach(chp);
}
diff -r 8d4928dbf1bb -r 8c1151e395d9 sys/dev/ic/ahcisatavar.h
--- a/sys/dev/ic/ahcisatavar.h Wed Oct 24 18:27:15 2018 +0000
+++ b/sys/dev/ic/ahcisatavar.h Wed Oct 24 19:38:00 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ahcisatavar.h,v 1.19 2018/10/22 20:13:47 jdolecek Exp $ */
+/* $NetBSD: ahcisatavar.h,v 1.20 2018/10/24 19:38:00 jdolecek Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -117,6 +117,7 @@
void ahci_attach(struct ahci_softc *);
int ahci_detach(struct ahci_softc *, int);
+void ahci_childdetached(struct ahci_softc *, device_t);
void ahci_resume(struct ahci_softc *);
int ahci_intr(void *);
diff -r 8d4928dbf1bb -r 8c1151e395d9 sys/dev/ic/siisata.c
--- a/sys/dev/ic/siisata.c Wed Oct 24 18:27:15 2018 +0000
+++ b/sys/dev/ic/siisata.c Wed Oct 24 19:38:00 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.36 2018/10/22 20:13:47 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.37 2018/10/24 19:38:00 jdolecek Exp $ */
/* from ahcisata_core.c */
@@ -79,7 +79,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.36 2018/10/22 20:13:47 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.37 2018/10/24 19:38:00 jdolecek Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -408,6 +408,19 @@
return;
}
+void
+siisata_childdetached(struct siisata_softc *sc, device_t child)
+{
+ struct ata_channel *chp;
+
+ for (int i = 0; i < sc->sc_atac.atac_nchannels; i++) {
+ chp = sc->sc_chanarray[i];
+
+ if (child == chp->atabus)
+ chp->atabus = NULL;
+ }
+}
+
int
siisata_detach(struct siisata_softc *sc, int flags)
{
@@ -417,14 +430,22 @@
struct ata_channel *chp;
int i, j, error;
+ if (adapt->adapt_refcnt != 0)
+ return EBUSY;
+
for (i = 0; i < sc->sc_atac.atac_nchannels; i++) {
schp = &sc->sc_channels[i];
chp = sc->sc_chanarray[i];
- if (chp->atabus == NULL)
+ if (chp->atabus != NULL) {
+ if ((error = config_detach(chp->atabus, flags)) != 0)
+ return error;
+
+ KASSERT(chp->atabus == NULL);
+ }
+
+ if (chp->ch_flags & ATACH_DETACHED)
continue;
- if ((error = config_detach(chp->atabus, flags)) != 0)
- return error;
for (j = 0; j < SIISATA_MAX_SLOTS; j++)
bus_dmamap_destroy(sc->sc_dmat, schp->sch_datad[j]);
@@ -436,14 +457,9 @@
bus_dmamem_free(sc->sc_dmat,
&schp->sch_prb_seg, schp->sch_prb_nseg);
- chp->atabus = NULL;
-
ata_channel_detach(chp);
}
- if (adapt->adapt_refcnt != 0)
- return EBUSY;
-
/* leave the chip in reset */
GRWRITE(sc, GR_GC, GR_GC_GLBLRST);
diff -r 8d4928dbf1bb -r 8c1151e395d9 sys/dev/ic/siisatavar.h
--- a/sys/dev/ic/siisatavar.h Wed Oct 24 18:27:15 2018 +0000
+++ b/sys/dev/ic/siisatavar.h Wed Oct 24 19:38:00 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: siisatavar.h,v 1.8 2018/10/22 20:13:47 jdolecek Exp $ */
+/* $NetBSD: siisatavar.h,v 1.9 2018/10/24 19:38:00 jdolecek Exp $ */
/* from ahcisatavar.h */
@@ -114,6 +114,7 @@
void siisata_attach(struct siisata_softc *);
int siisata_detach(struct siisata_softc *, int);
+void siisata_childdetached(struct siisata_softc *, device_t);
void siisata_resume(struct siisata_softc *);
int siisata_intr(void *);
diff -r 8d4928dbf1bb -r 8c1151e395d9 sys/dev/pci/ahcisata_pci.c
--- a/sys/dev/pci/ahcisata_pci.c Wed Oct 24 18:27:15 2018 +0000
+++ b/sys/dev/pci/ahcisata_pci.c Wed Oct 24 19:38:00 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ahcisata_pci.c,v 1.40 2018/10/22 21:40:45 jdolecek Exp $ */
+/* $NetBSD: ahcisata_pci.c,v 1.41 2018/10/24 19:38:00 jdolecek Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_pci.c,v 1.40 2018/10/22 21:40:45 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_pci.c,v 1.41 2018/10/24 19:38:00 jdolecek Exp $");
#include <sys/types.h>
#include <sys/malloc.h>
@@ -208,11 +208,13 @@
static int ahci_pci_match(device_t, cfdata_t, void *);
static void ahci_pci_attach(device_t, device_t, void *);
static int ahci_pci_detach(device_t, int);
+static void ahci_pci_childdetached(device_t, device_t);
static bool ahci_pci_resume(device_t, const pmf_qual_t *);
-CFATTACH_DECL_NEW(ahcisata_pci, sizeof(struct ahci_pci_softc),
- ahci_pci_match, ahci_pci_attach, ahci_pci_detach, NULL);
+CFATTACH_DECL3_NEW(ahcisata_pci, sizeof(struct ahci_pci_softc),
+ ahci_pci_match, ahci_pci_attach, ahci_pci_detach, NULL,
+ NULL, ahci_pci_childdetached, DVF_DETACH_SHUTDOWN);
static int
ahci_pci_has_quirk(pci_vendor_id_t vendor, pci_product_id_t product)
@@ -328,6 +330,15 @@
aprint_error_dev(self, "couldn't establish power handler\n");
}
+static void
+ahci_pci_childdetached(device_t dv, device_t child)
+{
+ struct ahci_pci_softc *psc = device_private(dv);
+ struct ahci_softc *sc = &psc->ah_sc;
+
+ ahci_childdetached(sc, child);
+}
+
static int
ahci_pci_detach(device_t dv, int flags)
{
diff -r 8d4928dbf1bb -r 8c1151e395d9 sys/dev/pci/siisata_pci.c
--- a/sys/dev/pci/siisata_pci.c Wed Oct 24 18:27:15 2018 +0000
+++ b/sys/dev/pci/siisata_pci.c Wed Oct 24 19:38:00 2018 +0000
@@ -1,4 +1,4 @@
Home |
Main Index |
Thread Index |
Old Index