diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2006-11-26 09:29:08 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2006-11-26 09:29:08 +0000 |
commit | 5b939a9b4143c6b99cb8a032f88e992b8440ae73 (patch) | |
tree | 57bdf9cdd84dd2518c22845d1b035cca6e006e6c /sys/scsi/scsiconf.c | |
parent | 676b2357c8679c7d7461d8e862dd507e664a345a (diff) |
provide scsi_detach_bus, _target, and _lun to wrap up config_detach for
scsi devices. the midlayer keeps some state for each device that is
attached which needs to be cleaned up on detach, hence this wrapper.
Diffstat (limited to 'sys/scsi/scsiconf.c')
-rw-r--r-- | sys/scsi/scsiconf.c | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/sys/scsi/scsiconf.c b/sys/scsi/scsiconf.c index 3028dbe54bf..0725b902ad0 100644 --- a/sys/scsi/scsiconf.c +++ b/sys/scsi/scsiconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scsiconf.c,v 1.117 2006/10/21 07:36:15 dlg Exp $ */ +/* $OpenBSD: scsiconf.c,v 1.118 2006/11/26 09:29:07 dlg Exp $ */ /* $NetBSD: scsiconf.c,v 1.57 1996/05/02 01:09:01 neil Exp $ */ /* @@ -297,6 +297,82 @@ scsi_probe_lun(struct scsibus_softc *sc, int target, int lun) return (scsi_probedev(sc, target, lun)); } +int +scsi_detach_bus(struct scsibus_softc *sc, int flags) +{ + struct scsi_link *alink = sc->adapter_link; + int i, err, rv; + + for (i = 0; i < alink->adapter_buswidth; i++) { + if (sc->sc_link[i] == NULL) + continue; + + err = scsi_detach_target(sc, i, flags); + if (err != 0) + rv = err; + } + + return (rv); +} + +int +scsi_detach_target(struct scsibus_softc *sc, int target, int flags) +{ + struct scsi_link *alink = sc->adapter_link; + int i, err, rv; + + if (target < 0 || target >= alink->adapter_buswidth || + target == alink->adapter_target) + return (ENXIO); + + for (i = 0; i < alink->luns; i++) { /* nicer backwards? */ + if (sc->sc_link[target][i] == NULL) + continue; + + err = scsi_detach_lun(sc, target, i, flags); + if (err != 0) + rv = err; + } + + return (rv); +} + +int +scsi_detach_lun(struct scsibus_softc *sc, int target, int lun, int flags) +{ + struct scsi_link *alink = sc->adapter_link; + struct scsi_link *link; + int rv; + + if (target < 0 || target >= alink->adapter_buswidth || + target == alink->adapter_target || + lun < 0 || lun >= alink->luns) + return (ENXIO); + + if (sc->sc_link[target] == NULL) + return (ENXIO); + + link = sc->sc_link[target][lun]; + if (link == NULL) + return (ENXIO); + + if (((flags & DETACH_FORCE) == 0) && link->flags & SDEV_OPEN) + return (EBUSY); + + /* detaching a device from scsibus is a two step process... */ + + /* 1. detach the device */ + rv = config_detach(link->device_softc, flags); + if (rv != 0) + return (rv); + + /* 2. free up its state in the midlayer */ + free(link, M_DEVBUF); + sc->sc_link[target][lun] = NULL; + + return (0); +} + void scsi_strvis(u_char *dst, u_char *src, int len) { |