diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2010-07-01 05:11:19 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2010-07-01 05:11:19 +0000 |
commit | 470720b3f65a90bd25915bbbe67b9fd17a29d38f (patch) | |
tree | 4a651dbe72b4a3e17480d015f9b34b877585e356 /sys/scsi | |
parent | d4b4fc44c12bd5709aa833bc1f4322dcefd077ce (diff) |
Die struct scsi_device! Die! Instead, save a pointer to the routine
to interpret sense errors. This is initialized to the basic
interpretation routine, and specific scsi drivers (sd/st/cd) can
replace this with their own. While here kill EJUSTRETURN dance and
make more specialized interpretation routines directly call the
basic routine if desired.
Fixes by matthew@ to my first diff. Most original work by dlg@.
ok matthew@ marco@ dlg@
Diffstat (limited to 'sys/scsi')
-rw-r--r-- | sys/scsi/cd.c | 20 | ||||
-rw-r--r-- | sys/scsi/ch.c | 18 | ||||
-rw-r--r-- | sys/scsi/scsi_base.c | 66 | ||||
-rw-r--r-- | sys/scsi/scsiconf.c | 11 | ||||
-rw-r--r-- | sys/scsi/scsiconf.h | 27 | ||||
-rw-r--r-- | sys/scsi/sd.c | 20 | ||||
-rw-r--r-- | sys/scsi/ss.c | 13 | ||||
-rw-r--r-- | sys/scsi/ss_mustek.c | 5 | ||||
-rw-r--r-- | sys/scsi/ss_scanjet.c | 5 | ||||
-rw-r--r-- | sys/scsi/st.c | 24 | ||||
-rw-r--r-- | sys/scsi/uk.c | 13 |
11 files changed, 78 insertions, 144 deletions
diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c index 47790550db6..fdcb74671c5 100644 --- a/sys/scsi/cd.c +++ b/sys/scsi/cd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cd.c,v 1.174 2010/07/01 03:01:37 matthew Exp $ */ +/* $OpenBSD: cd.c,v 1.175 2010/07/01 05:11:18 krw Exp $ */ /* $NetBSD: cd.c,v 1.100 1997/04/02 02:29:30 mycroft Exp $ */ /* @@ -163,13 +163,6 @@ struct cfdriver cd_cd = { struct dkdriver cddkdriver = { cdstrategy }; -struct scsi_device cd_switch = { - cd_interpret_sense, - NULL, /* we have a queue, which is started by this */ - NULL, /* we do not have an async handler */ - NULL, /* no per driver cddone */ -}; - const struct scsi_inquiry_pattern cd_patterns[] = { {T_CDROM, T_REMOV, "", "", ""}, @@ -216,7 +209,7 @@ cdattach(struct device *parent, struct device *self, void *aux) * Store information needed to contact our base driver */ sc->sc_link = sc_link; - sc_link->device = &cd_switch; + sc_link->interpret_sense = cd_interpret_sense; sc_link->device_softc = sc; if (sc_link->openings > CDOUTSTANDING) sc_link->openings = CDOUTSTANDING; @@ -701,7 +694,10 @@ cd_buf_done(struct scsi_xfer *xs) case XS_SENSE: case XS_SHORTSENSE: - error = scsi_interpret_sense(xs); +#ifdef SCSIDEBUG + scsi_sense_print_debug(xs); +#endif + error = cd_interpret_sense(xs); if (error == 0) { bp->b_error = 0; bp->b_resid = xs->resid; @@ -1962,7 +1958,7 @@ cd_interpret_sense(struct scsi_xfer *xs) if (((sc_link->flags & SDEV_OPEN) == 0) || (serr != SSD_ERRCODE_CURRENT && serr != SSD_ERRCODE_DEFERRED)) - return (EJUSTRETURN); /* let the generic code handle it */ + return (scsi_interpret_sense(xs)); /* * We do custom processing in cd for the unit becoming ready @@ -1992,7 +1988,7 @@ cd_interpret_sense(struct scsi_xfer *xs) default: break; } - return (EJUSTRETURN); /* use generic handler in scsi_base */ + return (scsi_interpret_sense(xs)); } #if defined(__macppc__) diff --git a/sys/scsi/ch.c b/sys/scsi/ch.c index 47da62265b1..6a9b82ab874 100644 --- a/sys/scsi/ch.c +++ b/sys/scsi/ch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ch.c,v 1.39 2010/06/26 23:24:45 guenther Exp $ */ +/* $OpenBSD: ch.c,v 1.40 2010/07/01 05:11:18 krw Exp $ */ /* $NetBSD: ch.c,v 1.26 1997/02/21 22:06:52 thorpej Exp $ */ /* @@ -119,14 +119,6 @@ int ch_get_params(struct ch_softc *, int); int ch_interpret_sense(struct scsi_xfer *xs); void ch_get_quirks(struct ch_softc *, struct scsi_inquiry_data *); -/* SCSI glue */ -struct scsi_device ch_switch = { - ch_interpret_sense, - NULL, - NULL, - NULL -}; - /* * SCSI changer quirks. */ @@ -167,7 +159,7 @@ chattach(parent, self, aux) /* Glue into the SCSI bus */ sc->sc_link = link; - link->device = &ch_switch; + link->interpret_sense = ch_interpret_sense; link->device_softc = sc; link->openings = 1; @@ -765,7 +757,7 @@ ch_interpret_sense(xs) if (((sc_link->flags & SDEV_OPEN) == 0) || (serr != SSD_ERRCODE_CURRENT && serr != SSD_ERRCODE_DEFERRED)) - return (EJUSTRETURN); /* let the generic code handle it */ + return (scsi_interpret_sense(xs)); switch (skey) { @@ -792,9 +784,9 @@ ch_interpret_sense(xs) xs->retries++; return (scsi_delay(xs, 1)); default: - return (EJUSTRETURN); + return (scsi_interpret_sense(xs)); } default: - return (EJUSTRETURN); + return (scsi_interpret_sense(xs)); } } diff --git a/sys/scsi/scsi_base.c b/sys/scsi/scsi_base.c index 5e3edbfb464..3ddbb2b9dcf 100644 --- a/sys/scsi/scsi_base.c +++ b/sys/scsi/scsi_base.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scsi_base.c,v 1.177 2010/07/01 03:01:37 matthew Exp $ */ +/* $OpenBSD: scsi_base.c,v 1.178 2010/07/01 05:11:18 krw Exp $ */ /* $NetBSD: scsi_base.c,v 1.43 1997/04/02 02:29:36 mycroft Exp $ */ /* @@ -617,9 +617,6 @@ scsi_xs_put(struct scsi_xfer *xs) scsi_io_put(link->pool, io); scsi_link_close(link); - - if (link->device->start) - link->device->start(link->device_softc); } /* @@ -1231,16 +1228,6 @@ scsi_scsi_cmd(struct scsi_link *link, struct scsi_generic *scsi_cmd, biodone(bp); splx(s); } - - if (link->device->done) { - /* - * Tell the device the operation is actually complete. - * No more will happen with this xfer. This for - * notification of the upper-level driver only; they - * won't be returning any meaningful information to us. - */ - link->device->done(xs); - } } scsi_xs_put(xs); @@ -1270,7 +1257,10 @@ scsi_xs_error(struct scsi_xfer *xs) case XS_SENSE: case XS_SHORTSENSE: - error = scsi_interpret_sense(xs); +#ifdef SCSIDEBUG + scsi_sense_print_debug(xs); +#endif + error = xs->sc_link->interpret_sense(xs); SC_DEBUG(xs->sc_link, SDEV_DB3, ("scsi_interpret_sense returned %#x\n", error)); break; @@ -1326,19 +1316,15 @@ scsi_delay(struct scsi_xfer *xs, int seconds) return (ERESTART); } +#ifdef SCSIDEBUG /* - * Look at the returned sense and act on the error, determining - * the unix error number to pass back. (0 = report no error) - * - * THIS IS THE DEFAULT ERROR HANDLER + * Print out sense data details. */ -int -scsi_interpret_sense(struct scsi_xfer *xs) +void +scsi_sense_print_debug(struct scsi_xfer *xs) { - struct scsi_sense_data *sense = &xs->sense; - struct scsi_link *sc_link = xs->sc_link; - u_int8_t serr, skey; - int error; + struct scsi_sense_data *sense = &xs->sense; + struct scsi_link *sc_link = xs->sc_link; SC_DEBUG(sc_link, SDEV_DB1, ("code:%#x valid:%d key:%#x ili:%d eom:%d fmark:%d extra:%d\n", @@ -1350,24 +1336,26 @@ scsi_interpret_sense(struct scsi_xfer *xs) sense->flags & SSD_FILEMARK ? 1 : 0, sense->extra_len)); -#ifdef SCSIDEBUG if (xs->sc_link->flags & SDEV_DB1) scsi_show_mem((u_char *)&xs->sense, sizeof(xs->sense)); + scsi_print_sense(xs); -#endif /* SCSIDEBUG */ +} +#endif - /* - * If the device has its own error handler, call it first. - * If it returns a legit error value, return that, otherwise - * it wants us to continue with normal error processing. - */ - if (sc_link->device->err_handler) { - SC_DEBUG(sc_link, SDEV_DB2, - ("calling private err_handler()\n")); - error = (*sc_link->device->err_handler) (xs); - if (error != EJUSTRETURN) - return (error); /* error >= 0 better ? */ - } +/* + * Look at the returned sense and act on the error, determining + * the unix error number to pass back. (0 = report no error) + * + * THIS IS THE DEFAULT ERROR HANDLER + */ +int +scsi_interpret_sense(struct scsi_xfer *xs) +{ + struct scsi_sense_data *sense = &xs->sense; + struct scsi_link *sc_link = xs->sc_link; + u_int8_t serr, skey; + int error; /* Default sense interpretation. */ serr = sense->error_code & SSD_ERRCODE; diff --git a/sys/scsi/scsiconf.c b/sys/scsi/scsiconf.c index 8c3c53d25a9..d9b7ce40e80 100644 --- a/sys/scsi/scsiconf.c +++ b/sys/scsi/scsiconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scsiconf.c,v 1.160 2010/07/01 03:20:39 matthew Exp $ */ +/* $OpenBSD: scsiconf.c,v 1.161 2010/07/01 05:11:18 krw Exp $ */ /* $NetBSD: scsiconf.c,v 1.57 1996/05/02 01:09:01 neil Exp $ */ /* @@ -75,13 +75,6 @@ int scsi_probedev(struct scsibus_softc *, int, int); void scsi_devid(struct scsi_link *); int scsi_devid_pg83(struct scsi_link *); -struct scsi_device probe_switch = { - NULL, - NULL, - NULL, - NULL, -}; - int scsibusmatch(struct device *, void *, void *); void scsibusattach(struct device *, struct device *, void *); int scsibusactivate(struct device *, int); @@ -865,7 +858,7 @@ scsi_probedev(struct scsibus_softc *scsi, int target, int lun) *sc_link = *scsi->adapter_link; sc_link->target = target; sc_link->lun = lun; - sc_link->device = &probe_switch; + sc_link->interpret_sense = scsi_interpret_sense; TAILQ_INIT(&sc_link->queue); inqbuf = &sc_link->inqdata; diff --git a/sys/scsi/scsiconf.h b/sys/scsi/scsiconf.h index 0a26745ce76..08c8ef0fb40 100644 --- a/sys/scsi/scsiconf.h +++ b/sys/scsi/scsiconf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: scsiconf.h,v 1.129 2010/07/01 03:20:39 matthew Exp $ */ +/* $OpenBSD: scsiconf.h,v 1.130 2010/07/01 05:11:18 krw Exp $ */ /* $NetBSD: scsiconf.h,v 1.35 1997/04/02 02:29:38 mycroft Exp $ */ /* @@ -266,8 +266,6 @@ void devid_free(struct devid *); * * each adapter type has a scsi_adapter struct. This describes the adapter and * identifies routines that can be called to use the adapter. - * each device type has a scsi_device struct. This describes the device and - * identifies routines that can be called to use the device. * each existing device position (scsibus + target + lun) * can be described by a scsi_link struct. * Only scsi positions that actually have devices, have a scsi_link @@ -311,24 +309,6 @@ struct scsi_adapter { int (*ioctl)(struct scsi_link *, u_long, caddr_t, int); }; -/* - * These entry points are called by the low-end drivers to get services from - * whatever high-end drivers they are attached to. Each device type has one - * of these statically allocated. - */ -struct scsi_device { - int (*err_handler)(struct scsi_xfer *); - /* returns -1 to say err processing done */ - void (*start)(void *); - - int (*async)(void); - void (*done)(struct scsi_xfer *); -}; - -/* - * - */ - struct scsi_runq_entry { TAILQ_ENTRY(scsi_runq_entry) e; u_int state; @@ -417,7 +397,7 @@ struct scsi_link { #define ADEV_NOCAPACITY 0x0800 /* no READ CD CAPACITY */ #define ADEV_NODOORLOCK 0x2000 /* can't lock door */ #define SDEV_ONLYBIG 0x4000 /* always use READ_BIG and WRITE_BIG */ - struct scsi_device *device; /* device entry points etc. */ + int (*interpret_sense)(struct scsi_xfer *); void *device_softc; /* needed for call to foo_start */ struct scsi_adapter *adapter; /* adapter entry points etc. */ void *adapter_softc; /* needed for call to foo_scsi_cmd */ @@ -625,6 +605,9 @@ struct scsi_xfer * scsi_xs_get(struct scsi_link *, int); void scsi_xs_exec(struct scsi_xfer *); int scsi_xs_sync(struct scsi_xfer *); void scsi_xs_put(struct scsi_xfer *); +#ifdef SCSIDEBUG +void scsi_sense_print_debug(struct scsi_xfer *); +#endif /* * iopool stuff diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c index 542364e06e0..d085f1b5418 100644 --- a/sys/scsi/sd.c +++ b/sys/scsi/sd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sd.c,v 1.200 2010/07/01 03:01:37 matthew Exp $ */ +/* $OpenBSD: sd.c,v 1.201 2010/07/01 05:11:18 krw Exp $ */ /* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */ /*- @@ -113,13 +113,6 @@ struct cfdriver sd_cd = { struct dkdriver sddkdriver = { sdstrategy }; -struct scsi_device sd_switch = { - sd_interpret_sense, /* check out error handler first */ - NULL, /* have a queue, served by this */ - NULL, /* have no async handler */ - NULL, /* have no done handler */ -}; - const struct scsi_inquiry_pattern sd_patterns[] = { {T_DIRECT, T_FIXED, "", "", ""}, @@ -174,7 +167,7 @@ sdattach(struct device *parent, struct device *self, void *aux) * Store information needed to contact our base driver */ sc->sc_link = sc_link; - sc_link->device = &sd_switch; + sc_link->interpret_sense = sd_interpret_sense; sc_link->device_softc = sc; /* @@ -770,7 +763,10 @@ sd_buf_done(struct scsi_xfer *xs) case XS_SENSE: case XS_SHORTSENSE: - error = scsi_interpret_sense(xs); +#ifdef SCSIDEBUG + scsi_sense_print_debug(xs); +#endif + error = sd_interpret_sense(xs); if (error == 0) { bp->b_error = 0; bp->b_resid = xs->resid; @@ -1209,7 +1205,7 @@ sd_interpret_sense(struct scsi_xfer *xs) (serr != SSD_ERRCODE_CURRENT && serr != SSD_ERRCODE_DEFERRED) || ((sense->flags & SSD_KEY) != SKEY_NOT_READY) || (sense->extra_len < 6)) - return (EJUSTRETURN); + return (scsi_interpret_sense(xs)); switch (ASC_ASCQ(sense)) { case SENSE_NOT_READY_BECOMING_READY: @@ -1229,7 +1225,7 @@ sd_interpret_sense(struct scsi_xfer *xs) break; default: - retval = EJUSTRETURN; + retval = scsi_interpret_sense(xs); break; } diff --git a/sys/scsi/ss.c b/sys/scsi/ss.c index b240f3131ac..9e3c26af616 100644 --- a/sys/scsi/ss.c +++ b/sys/scsi/ss.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ss.c,v 1.78 2010/07/01 03:01:37 matthew Exp $ */ +/* $OpenBSD: ss.c,v 1.79 2010/07/01 05:11:18 krw Exp $ */ /* $NetBSD: ss.c,v 1.10 1996/05/05 19:52:55 christos Exp $ */ /* @@ -252,13 +252,6 @@ struct cfdriver ss_cd = { NULL, "ss", DV_DULL }; -struct scsi_device ss_switch = { - NULL, - NULL, - NULL, - NULL, -}; - const struct scsi_inquiry_pattern ss_patterns[] = { {T_SCANNER, T_FIXED, "", "", ""}, @@ -325,7 +318,6 @@ ssattach(parent, self, aux) * Store information needed to contact our base driver */ ss->sc_link = sc_link; - sc_link->device = &ss_switch; sc_link->device_softc = ss; sc_link->openings = 1; @@ -689,6 +681,9 @@ ssdone(struct scsi_xfer *xs) case XS_SENSE: case XS_SHORTSENSE: +#ifdef SCSIDEBUG + scsi_sense_print_debug(xs); +#endif error = scsi_interpret_sense(xs); if (error == 0) { bp->b_error = 0; diff --git a/sys/scsi/ss_mustek.c b/sys/scsi/ss_mustek.c index 4e51ab8c9c0..4b0aab182b2 100644 --- a/sys/scsi/ss_mustek.c +++ b/sys/scsi/ss_mustek.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ss_mustek.c,v 1.26 2010/07/01 03:01:37 matthew Exp $ */ +/* $OpenBSD: ss_mustek.c,v 1.27 2010/07/01 05:11:18 krw Exp $ */ /* $NetBSD: ss_mustek.c,v 1.4 1996/05/05 19:52:57 christos Exp $ */ /* @@ -494,6 +494,9 @@ mustek_read_done(struct scsi_xfer *xs) case XS_SENSE: case XS_SHORTSENSE: +#ifdef SCSIDEBUG + scsi_sense_print_debug(xs); +#endif error = scsi_interpret_sense(xs); if (error == 0) { ss->sio.scan_lines -= bp->b_bcount / diff --git a/sys/scsi/ss_scanjet.c b/sys/scsi/ss_scanjet.c index 771810ff8b5..277555cdd0a 100644 --- a/sys/scsi/ss_scanjet.c +++ b/sys/scsi/ss_scanjet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ss_scanjet.c,v 1.43 2010/07/01 03:01:37 matthew Exp $ */ +/* $OpenBSD: ss_scanjet.c,v 1.44 2010/07/01 05:11:18 krw Exp $ */ /* $NetBSD: ss_scanjet.c,v 1.6 1996/05/18 22:58:01 christos Exp $ */ /* @@ -332,6 +332,9 @@ scanjet_read_done(struct scsi_xfer *xs) case XS_SENSE: case XS_SHORTSENSE: +#ifdef SCSIDEBUG + scsi_sense_print_debug(xs); +#endif error = scsi_interpret_sense(xs); if (error == 0) { if (bp->b_bcount >= ss->sio.scan_window_size) diff --git a/sys/scsi/st.c b/sys/scsi/st.c index 0d3f4513c30..10102d0a0e7 100644 --- a/sys/scsi/st.c +++ b/sys/scsi/st.c @@ -1,4 +1,4 @@ -/* $OpenBSD: st.c,v 1.103 2010/07/01 03:01:37 matthew Exp $ */ +/* $OpenBSD: st.c,v 1.104 2010/07/01 05:11:18 krw Exp $ */ /* $NetBSD: st.c,v 1.71 1997/02/21 23:03:49 thorpej Exp $ */ /* @@ -256,13 +256,6 @@ struct cfdriver st_cd = { NULL, "st", DV_TAPE }; -struct scsi_device st_switch = { - st_interpret_sense, - NULL, - NULL, - NULL, -}; - #define ST_INFO_VALID 0x0001 #define ST_BLOCK_SET 0x0002 /* block size, mode set by ioctl */ #define ST_WRITTEN 0x0004 /* data have been written, EOD needed */ @@ -323,7 +316,7 @@ stattach(struct device *parent, struct device *self, void *aux) * Store information needed to contact our base driver */ st->sc_link = sc_link; - sc_link->device = &st_switch; + sc_link->interpret_sense = st_interpret_sense; sc_link->device_softc = st; /* @@ -1075,7 +1068,10 @@ st_buf_done(struct scsi_xfer *xs) case XS_SENSE: case XS_SHORTSENSE: - error = scsi_interpret_sense(xs); +#ifdef SCSIDEBUG + scsi_sense_print_debug(xs); +#endif + error = st_interpret_sense(xs); if (error == 0) { bp->b_error = 0; bp->b_resid = xs->resid; @@ -1911,7 +1907,7 @@ st_interpret_sense(struct scsi_xfer *xs) if (((sc_link->flags & SDEV_OPEN) == 0) || (serr != SSD_ERRCODE_CURRENT && serr != SSD_ERRCODE_DEFERRED)) - return (EJUSTRETURN); /* let the generic code handle it */ + return (scsi_interpret_sense(xs)); switch (skey) { @@ -1938,7 +1934,7 @@ st_interpret_sense(struct scsi_xfer *xs) xs->retries++; return (scsi_delay(xs, 1)); default: - return (EJUSTRETURN); + return (scsi_interpret_sense(xs)); } case SKEY_NO_SENSE: case SKEY_RECOVERED_ERROR: @@ -1947,7 +1943,7 @@ st_interpret_sense(struct scsi_xfer *xs) case SKEY_BLANK_CHECK: break; default: - return (EJUSTRETURN); + return (scsi_interpret_sense(xs)); } /* @@ -2051,7 +2047,7 @@ st_interpret_sense(struct scsi_xfer *xs) } } - return (EJUSTRETURN); + return (scsi_interpret_sense(xs)); } /* diff --git a/sys/scsi/uk.c b/sys/scsi/uk.c index 96c9347b387..cc743efe4ec 100644 --- a/sys/scsi/uk.c +++ b/sys/scsi/uk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uk.c,v 1.14 2010/06/15 04:11:34 dlg Exp $ */ +/* $OpenBSD: uk.c,v 1.15 2010/07/01 05:11:18 krw Exp $ */ /* $NetBSD: uk.c,v 1.15 1996/03/17 00:59:57 thorpej Exp $ */ /* @@ -64,16 +64,6 @@ struct cfdriver uk_cd = { NULL, "uk", DV_DULL }; -/* - * This driver is so simple it uses all the default services - */ -struct scsi_device uk_switch = { - NULL, - NULL, - NULL, - NULL, -}; - int ukmatch(struct device *parent, void *match, void *aux) { @@ -95,7 +85,6 @@ ukattach(struct device *parent, struct device *self, void *aux) /* Store information needed to contact our base driver */ uk->sc_link = sc_link; - sc_link->device = &uk_switch; sc_link->device_softc = uk; sc_link->openings = 1; |