From 71c6d11d65a48949a4c41fe3d0534386a5140f9a Mon Sep 17 00:00:00 2001 From: Michael Shalayeff Date: Wed, 7 Sep 2005 04:00:17 +0000 Subject: sync on shutdown --- sys/dev/ic/ciss.c | 72 ++++++++++++++++++++++++++++++++++------------------ sys/dev/ic/cissreg.h | 9 ++++++- sys/dev/ic/cissvar.h | 7 +++-- 3 files changed, 61 insertions(+), 27 deletions(-) (limited to 'sys') diff --git a/sys/dev/ic/ciss.c b/sys/dev/ic/ciss.c index 565452b910f..3bae70fd335 100644 --- a/sys/dev/ic/ciss.c +++ b/sys/dev/ic/ciss.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ciss.c,v 1.6 2005/08/20 18:01:35 mickey Exp $ */ +/* $OpenBSD: ciss.c,v 1.7 2005/09/07 04:00:16 mickey Exp $ */ /* * Copyright (c) 2005 Michael Shalayeff @@ -131,6 +131,7 @@ ciss_attach(struct ciss_softc *sc) struct ciss_inquiry *inq; bus_dma_segment_t seg[1]; int error, i, total, rseg, maxfer; + ciss_lock_t lock; paddr_t pa; bus_space_read_region_4(sc->iot, sc->cfg_ioh, sc->cfgoff, @@ -297,9 +298,11 @@ ciss_attach(struct ciss_softc *sc) } bzero(sc->scratch, PAGE_SIZE); + lock = CISS_LOCK_SCRATCH(sc); inq = sc->scratch; if (ciss_inq(sc, inq)) { printf(": adapter inquiry failed\n"); + CISS_UNLOCK_SCRATCH(sc, lock); bus_dmamem_free(sc->dmat, sc->cmdseg, 1); bus_dmamap_destroy(sc->dmat, sc->cmdmap); return -1; @@ -308,6 +311,7 @@ ciss_attach(struct ciss_softc *sc) if (!(inq->flags & CISS_INQ_BIGMAP)) { printf(": big map is not supported, flags=%b\n", inq->flags, CISS_INQ_BITS); + CISS_UNLOCK_SCRATCH(sc, lock); bus_dmamem_free(sc->dmat, sc->cmdseg, 1); bus_dmamap_destroy(sc->dmat, sc->cmdmap); return -1; @@ -320,6 +324,11 @@ ciss_attach(struct ciss_softc *sc) inq->numld, inq->numld == 1? "" : "s", inq->hw_rev, inq->fw_running, inq->fw_stored); + CISS_UNLOCK_SCRATCH(sc, lock); + + timeout_set(&sc->sc_hb, ciss_heartbeat, sc); + timeout_add(&sc->sc_hb, hz * 3); + /* map LDs */ if (ciss_ldmap(sc)) { printf("%s: adapter LD map failed\n", sc->sc_dev.dv_xname); @@ -331,7 +340,7 @@ ciss_attach(struct ciss_softc *sc) /* TODO scan all physdev */ /* TODO scan all logdev */ -#if 0 + sc->sc_flush = CISS_FLUSH_ENABLE; if (!(sc->sc_sh = shutdownhook_establish(ciss_shutdown, sc))) { printf(": unable to establish shutdown hook\n"); bus_dmamem_free(sc->dmat, sc->cmdseg, 1); @@ -339,6 +348,7 @@ ciss_attach(struct ciss_softc *sc) return -1; } +#if 0 if (kthread_create(ciss_kthread, sc, NULL, "%s", sc->sc_dev.dv_xname)) { printf(": unable to create kernel thread\n"); shutdownhook_disestablish(sc->sc_sh); @@ -348,9 +358,6 @@ ciss_attach(struct ciss_softc *sc) } #endif - timeout_set(&sc->sc_hb, ciss_heartbeat, sc); - timeout_add(&sc->sc_hb, hz * 3); - sc->sc_link.device = &ciss_dev; sc->sc_link.adapter_softc = sc; sc->sc_link.openings = sc->maxcmd / sc->maxunits; /* XXX */ @@ -382,8 +389,9 @@ ciss_shutdown(void *v) { struct ciss_softc *sc = v; - ciss_sync(sc); + sc->sc_flush = CISS_FLUSH_DISABLE; timeout_del(&sc->sc_hb); + ciss_sync(sc); } void @@ -539,7 +547,7 @@ ciss_cmd(struct ciss_ccb *ccb, int flags, int wait) } int -ciss_done(struct ciss_ccb *ccb) /* TODO */ +ciss_done(struct ciss_ccb *ccb) { struct ciss_softc *sc = ccb->ccb_sc; struct scsi_xfer *xs = ccb->ccb_xs; @@ -669,11 +677,14 @@ ciss_ldmap(struct ciss_softc *sc) struct ciss_ccb *ccb; struct ciss_cmd *cmd; struct ciss_ldmap *lmap; - int total, error; + ciss_lock_t lock; + int total, rv; + lock = CISS_LOCK_SCRATCH(sc); lmap = sc->scratch; lmap->size = htobe32(sc->maxunits * sizeof(lmap->map)); total = sizeof(*lmap) + (sc->maxunits - 1) * sizeof(lmap->map); + ccb = ciss_get_ccb(sc); ccb->ccb_len = total; ccb->ccb_data = lmap; @@ -688,41 +699,49 @@ ciss_ldmap(struct ciss_softc *sc) cmd->cdb[8] = total >> 8; /* biiiig endian */ cmd->cdb[9] = total & 0xff; - if ((error = ciss_cmd(ccb, BUS_DMA_NOWAIT, SCSI_POLL|SCSI_NOSLEEP))) - return error; + rv = ciss_cmd(ccb, BUS_DMA_NOWAIT, SCSI_POLL|SCSI_NOSLEEP); + CISS_UNLOCK_SCRATCH(sc, lock); + if (rv) + return rv; printf("lmap %x:%x ", lmap->map[0].tgt, lmap->map[0].tgt2); return 0; } int -ciss_sync(struct ciss_softc *sc) /* TODO */ +ciss_sync(struct ciss_softc *sc) { -#if 0 struct ciss_ccb *ccb; struct ciss_cmd *cmd; + struct ciss_flush *flush; + ciss_lock_t lock; + int rv; + + lock = CISS_LOCK_SCRATCH(sc); + flush = sc->scratch; + bzero(flush, sizeof(*flush)); + flush->flush = sc->sc_flush; - inq = sc->scratch; ccb = ciss_get_ccb(sc); - ccb->ccb_len = sizeof(*inq); - ccb->ccb_data = inq; + ccb->ccb_len = sizeof(*flush); + ccb->ccb_data = flush; cmd = &ccb->ccb_cmd; cmd->tgt = CISS_CMD_MODE_PERIPH; cmd->tgt2 = 0; cmd->cdblen = 10; - cmd->flags = CISS_CDB_CMD | CISS_CDB_SIMPL | CISS_CDB_IN; + cmd->flags = CISS_CDB_CMD | CISS_CDB_SIMPL | CISS_CDB_OUT; cmd->tmo = 0; bzero(&cmd->cdb[0], sizeof(cmd->cdb)); - cmd->cdb[0] = CISS_CMD_CTRL_GET; - cmd->cdb[6] = CISS_CMS_CTRL_CTRL; - cmd->cdb[7] = sizeof(*inq) >> 8; /* biiiig endian */ - cmd->cdb[8] = sizeof(*inq) & 0xff; + cmd->cdb[0] = CISS_CMD_CTRL_SET; + cmd->cdb[6] = CISS_CMS_CTRL_FLUSH; + cmd->cdb[7] = sizeof(*flush) >> 8; /* biiiig endian */ + cmd->cdb[8] = sizeof(*flush) & 0xff; - return ciss_cmd(ccb, BUS_DMA_NOWAIT, SCSI_POLL|SCSI_NOSLEEP); -#else - return 0; -#endif + rv = ciss_cmd(ccb, BUS_DMA_NOWAIT, SCSI_POLL|SCSI_NOSLEEP); + CISS_UNLOCK_SCRATCH(sc, lock); + + return rv; } int @@ -762,6 +781,7 @@ ciss_scsi_raw_cmd(struct scsi_xfer *xs) /* TODO */ ccb->ccb_xs = xs; + cmd->cdblen = xs->cmdlen; cmd->flags = CISS_CDB_CMD | CISS_CDB_SIMPL; if (xs->flags & SCSI_DATA_IN) @@ -812,6 +832,8 @@ ciss_scsi_cmd(struct scsi_xfer *xs) error = 0; xs->error = XS_NOERROR; + /* XXX emulate SYNCHRONIZE_CACHE ??? */ + ccb = ciss_get_ccb(sc); cmd = &ccb->ccb_cmd; ccb->ccb_len = xs->datalen; @@ -933,6 +955,8 @@ ciss_ioctl(struct device *dev, u_long cmd, caddr_t addr) /* TODO */ case BIOCVOL: case BIOCDISK: case BIOCALARM: + case BIOCBLINK: + case BIOCSETSTATE: default: CISS_DPRINTF(CISS_D_IOCTL, ("%s: invalid ioctl\n", sc->sc_dev.dv_xname)); diff --git a/sys/dev/ic/cissreg.h b/sys/dev/ic/cissreg.h index 81516ac9b0c..5fe09a4a14e 100644 --- a/sys/dev/ic/cissreg.h +++ b/sys/dev/ic/cissreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cissreg.h,v 1.1 2005/07/06 01:52:13 mickey Exp $ */ +/* $OpenBSD: cissreg.h,v 1.2 2005/09/07 04:00:16 mickey Exp $ */ /* * Copyright (c) 2005 Michael Shalayeff @@ -118,6 +118,13 @@ struct ciss_ldmap { } map[1]; } __packed; +struct ciss_flush { + u_int16_t flush; +#define CISS_FLUSH_ENABLE 0 +#define CISS_FLUSH_DISABLE 1 + u_int16_t resv[255]; +} __packed; + struct ciss_cmd { u_int8_t resv0; /* 00 */ u_int8_t sgin; /* 01: #sg in the cmd */ diff --git a/sys/dev/ic/cissvar.h b/sys/dev/ic/cissvar.h index 85ba61730a8..c2299e8aabc 100644 --- a/sys/dev/ic/cissvar.h +++ b/sys/dev/ic/cissvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cissvar.h,v 1.1 2005/07/06 01:52:13 mickey Exp $ */ +/* $OpenBSD: cissvar.h,v 1.2 2005/09/07 04:00:16 mickey Exp $ */ /* * Copyright (c) 2005 Michael Shalayeff @@ -25,6 +25,7 @@ struct ciss_softc { void *sc_ih; void *sc_sh; struct proc *sc_thread; + int sc_flush; u_int sc_flags; int ccblen, maxcmd, maxsg, nbus, ndrives, maxunits; @@ -50,9 +51,11 @@ struct ciss_rawsoftc { u_int8_t sc_channel; }; -/* XXX These have to become spinlocks in case of SMP */ +/* XXX These have to become spinlocks in case of fine SMP */ #define CISS_LOCK(sc) splbio() #define CISS_UNLOCK(sc, lock) splx(lock) +#define CISS_LOCK_SCRATCH(sc) splbio() +#define CISS_UNLOCK_SCRATCH(sc, lock) splx(lock) typedef int ciss_lock_t; int ciss_attach(struct ciss_softc *sc); -- cgit v1.2.3