diff --git a/sys/dev/usb/umass.c b/sys/dev/usb/umass.c index c9203b571ab6..63ff2b52778f 100644 --- a/sys/dev/usb/umass.c +++ b/sys/dev/usb/umass.c @@ -1,4 +1,4 @@ -/* $NetBSD: umass.c,v 1.94 2003/01/06 12:46:11 wiz Exp $ */ +/* $NetBSD: umass.c,v 1.95 2003/02/16 23:14:06 augustss Exp $ */ /*- * Copyright (c) 1999 MAEKAWA Masahide , * Nick Hibma @@ -94,7 +94,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.94 2003/01/06 12:46:11 wiz Exp $"); +__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.95 2003/02/16 23:14:06 augustss Exp $"); #include "atapibus.h" #include "scsibus.h" @@ -107,7 +107,6 @@ __KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.94 2003/01/06 12:46:11 wiz Exp $"); #if defined(__NetBSD__) || defined(__OpenBSD__) #include #include -#include #include #undef KASSERT #define KASSERT(cond, msg) @@ -603,7 +602,7 @@ USB_DETACH(umass) { USB_DETACH_START(umass, sc); struct umassbus_softc *scbus = sc->bus; - int rv = 0, i; + int rv = 0, i, s; DPRINTF(UDMASS_USB, ("%s: detached\n", USBDEVNAME(sc->sc_dev))); @@ -613,15 +612,16 @@ USB_DETACH(umass) usbd_abort_pipe(sc->sc_pipe[i]); } -#if 0 /* Do we really need reference counting? Perhaps in ioctl() */ s = splusb(); if (--sc->sc_refcnt >= 0) { +#ifdef DIAGNOSTIC + printf("%s: waiting for refcnt\n", USBDEVNAME(sc->sc_dev)); +#endif /* Wait for processes to go away. */ usb_detach_wait(USBDEV(sc->sc_dev)); } splx(s); -#endif if (scbus != NULL) { if (scbus->sc_child != NULL) diff --git a/sys/dev/usb/umass_scsipi.c b/sys/dev/usb/umass_scsipi.c index 4c9a4725b755..9ea03006286b 100644 --- a/sys/dev/usb/umass_scsipi.c +++ b/sys/dev/usb/umass_scsipi.c @@ -1,4 +1,4 @@ -/* $NetBSD: umass_scsipi.c,v 1.8 2003/01/21 20:56:57 augustss Exp $ */ +/* $NetBSD: umass_scsipi.c,v 1.9 2003/02/16 23:14:08 augustss Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.8 2003/01/21 20:56:57 augustss Exp $"); +__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.9 2003/02/16 23:14:08 augustss Exp $"); #include "atapibus.h" #include "scsibus.h" @@ -140,8 +140,12 @@ umass_scsi_attach(struct umass_softc *sc) scbus->sc_channel.chan_id = UMASS_SCSIID_HOST; DPRINTF(UDMASS_USB, ("%s: umass_attach_bus: SCSI\n", USBDEVNAME(sc->sc_dev))); + + sc->sc_refcnt++; scbus->base.sc_child = config_found(&sc->sc_dev, &scbus->sc_channel, scsipiprint); + if (--sc->sc_refcnt < 0) + usb_detach_wakeup(USBDEV(sc->sc_dev)); return (0); } @@ -163,8 +167,12 @@ umass_atapi_attach(struct umass_softc *sc) scbus->sc_channel.chan_defquirks |= sc->sc_busquirks; DPRINTF(UDMASS_USB, ("%s: umass_attach_bus: ATAPI\n", USBDEVNAME(sc->sc_dev))); + + sc->sc_refcnt++; scbus->base.sc_child = config_found(&sc->sc_dev, &scbus->sc_channel, scsipiprint); + if (--sc->sc_refcnt < 0) + usb_detach_wakeup(USBDEV(sc->sc_dev)); return (0); } diff --git a/sys/dev/usb/umassvar.h b/sys/dev/usb/umassvar.h index 3b8c59009b4e..bce20e13ae11 100644 --- a/sys/dev/usb/umassvar.h +++ b/sys/dev/usb/umassvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: umassvar.h,v 1.17 2002/12/06 03:57:51 erh Exp $ */ +/* $NetBSD: umassvar.h,v 1.18 2003/02/16 23:14:08 augustss Exp $ */ /*- * Copyright (c) 1999 MAEKAWA Masahide , * Nick Hibma @@ -265,6 +265,7 @@ struct umass_softc { int sc_xfer_flags; char sc_dying; + int sc_refcnt; struct umassbus_softc *bus; /* bus dependent data */ };