diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2005-04-05 12:13:17 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2005-04-05 12:13:17 +0000 |
commit | 6925dcc5a6aeebcfd28fd678a39f45cd5e642fc4 (patch) | |
tree | edff0ec67ee1aff67ce310d4cb4f112eb8f2621e /sys | |
parent | b4e7d5833ec209b9297616ebee0f72301a626151 (diff) |
Factor out scsi_mode_sense() and scsi_mode_select() like NetBSD does.
Eliminate some duplicate structures and defines along the way. SCSI CD
drives will now pay attention to the 'flags' parameter for MODE SENSE
and MODE SELECT commands. No other functional change.
ok tdeval@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/scsi/cd_scsi.c | 44 | ||||
-rw-r--r-- | sys/scsi/ch.c | 33 | ||||
-rw-r--r-- | sys/scsi/scsi_base.c | 59 | ||||
-rw-r--r-- | sys/scsi/scsiconf.h | 6 | ||||
-rw-r--r-- | sys/scsi/sd_scsi.c | 41 | ||||
-rw-r--r-- | sys/scsi/ss_mustek.c | 12 | ||||
-rw-r--r-- | sys/scsi/ss_mustek.h | 10 | ||||
-rw-r--r-- | sys/scsi/st.c | 32 |
8 files changed, 95 insertions, 142 deletions
diff --git a/sys/scsi/cd_scsi.c b/sys/scsi/cd_scsi.c index a423823d0b6..b148d4b15d8 100644 --- a/sys/scsi/cd_scsi.c +++ b/sys/scsi/cd_scsi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cd_scsi.c,v 1.5 2004/05/09 14:08:11 krw Exp $ */ +/* $OpenBSD: cd_scsi.c,v 1.6 2005/04/05 12:13:16 krw Exp $ */ /* $NetBSD: cd_scsi.c,v 1.14 1998/08/31 22:28:06 cgd Exp $ */ /*- @@ -104,25 +104,8 @@ cd_scsibus_get_mode(cd, data, page, len, flags) struct scsi_cd_mode_data *data; int page, len, flags; { - struct scsi_mode_sense scsi_cmd; - -#ifdef DIAGNOSTIC - if (len == 0 || len > 256) { - printf ("cd_scsibus_get_mode: Mode page %02x request " - "bad size: %d bytes\n", page, len); - return (EINVAL); - } -#endif - - bzero(&scsi_cmd, sizeof(scsi_cmd)); - bzero(data, sizeof(*data)); - scsi_cmd.opcode = MODE_SENSE; - scsi_cmd.page = page; - scsi_cmd.length = len & 0xff; - return (scsi_scsi_cmd(cd->sc_link, - (struct scsi_generic *)&scsi_cmd, sizeof(scsi_cmd), - (u_char *)data, len, CDRETRIES, 20000, NULL, - SCSI_DATA_IN)); + return scsi_mode_sense(cd->sc_link, 0, page, (u_char *)data, + len, flags, 20000); } /* @@ -134,30 +117,13 @@ cd_scsibus_set_mode(cd, data, len, flags) struct scsi_cd_mode_data *data; int len, flags; { - struct scsi_mode_select scsi_cmd; - -#ifdef DIAGNOSTIC - if (len == 0 || len > 256) { - printf ("cd_scsibus_set_mode: Set mode request " - "bad size: %d bytes\n", len); - return (EINVAL); - } -#endif - - bzero(&scsi_cmd, sizeof(scsi_cmd)); - scsi_cmd.opcode = MODE_SELECT; - scsi_cmd.byte2 |= SMS_PF; - scsi_cmd.length = len & 0xff; - /* SPC-2 revision 16, section 8.3: Mode parameters When used with the [MODE SELECT command], the data length field is reserved. */ data->header.data_length = 0; - return (scsi_scsi_cmd(cd->sc_link, - (struct scsi_generic *)&scsi_cmd, sizeof(scsi_cmd), - (u_char *)data, len, CDRETRIES, 20000, NULL, - SCSI_DATA_OUT)); + return scsi_mode_select(cd->sc_link, SMS_PF, (u_char *)data, len, flags, + 20000); } int diff --git a/sys/scsi/ch.c b/sys/scsi/ch.c index 024c690160b..45e8bcf0324 100644 --- a/sys/scsi/ch.c +++ b/sys/scsi/ch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ch.c,v 1.17 2004/11/30 19:28:36 krw Exp $ */ +/* $OpenBSD: ch.c,v 1.18 2005/04/05 12:13:16 krw Exp $ */ /* $NetBSD: ch.c,v 1.26 1997/02/21 22:06:52 thorpej Exp $ */ /* @@ -609,11 +609,10 @@ ch_getelemstatus(sc, first, count, data, datalen) * softc. */ int -ch_get_params(sc, scsiflags) +ch_get_params(sc, flags) struct ch_softc *sc; - int scsiflags; + int flags; { - struct scsi_mode_sense cmd; struct scsi_mode_sense_data { struct scsi_mode_header header; union { @@ -626,17 +625,10 @@ ch_get_params(sc, scsiflags) u_int8_t *moves, *exchanges; /* - * Grab info from the element address assignment page. + * Grab info from the element address assignment page (0x1d). */ - bzero(&cmd, sizeof(cmd)); - bzero(&sense_data, sizeof(sense_data)); - cmd.opcode = MODE_SENSE; - cmd.byte2 |= 0x08; /* disable block descriptors */ - cmd.page = 0x1d; - cmd.length = (sizeof(sense_data) & 0xff); - error = scsi_scsi_cmd(sc->sc_link, (struct scsi_generic *)&cmd, - sizeof(cmd), (u_char *)&sense_data, sizeof(sense_data), CHRETRIES, - 6000, NULL, scsiflags | SCSI_DATA_IN); + error = scsi_mode_sense(sc->sc_link, SMS_DBD, 0x1d, + (u_char *)&sense_data, sizeof(sense_data), flags, 6000); if (error) { printf("%s: could not sense element address page\n", sc->sc_dev.dv_xname); @@ -655,17 +647,10 @@ ch_get_params(sc, scsiflags) /* XXX ask for page trasport geom */ /* - * Grab info from the capabilities page. + * Grab info from the capabilities page (0x1f). */ - bzero(&cmd, sizeof(cmd)); - bzero(&sense_data, sizeof(sense_data)); - cmd.opcode = MODE_SENSE; - cmd.byte2 |= 0x08; /* disable block descriptors */ - cmd.page = 0x1f; - cmd.length = (sizeof(sense_data) & 0xff); - error = scsi_scsi_cmd(sc->sc_link, (struct scsi_generic *)&cmd, - sizeof(cmd), (u_char *)&sense_data, sizeof(sense_data), CHRETRIES, - 6000, NULL, scsiflags | SCSI_DATA_IN); + error = scsi_mode_sense(sc->sc_link, SMS_DBD, 0x1f, + (u_char *)&sense_data, sizeof(sense_data), flags, 6000); if (error) { printf("%s: could not sense capabilities page\n", sc->sc_dev.dv_xname); diff --git a/sys/scsi/scsi_base.c b/sys/scsi/scsi_base.c index 734303ac95d..84b81b6bf5e 100644 --- a/sys/scsi/scsi_base.c +++ b/sys/scsi/scsi_base.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scsi_base.c,v 1.64 2005/04/01 23:34:39 krw Exp $ */ +/* $OpenBSD: scsi_base.c,v 1.65 2005/04/05 12:13:16 krw Exp $ */ /* $NetBSD: scsi_base.c,v 1.43 1997/04/02 02:29:36 mycroft Exp $ */ /* @@ -356,6 +356,63 @@ scsi_start(sc_link, type, flags) type == SSS_START ? 30000 : 10000, NULL, flags); } +int +scsi_mode_sense(sc_link, byte2, page, data, len, flags, timeout) + struct scsi_link *sc_link; + int byte2, page, flags, timeout; + size_t len; + u_char *data; +{ + struct scsi_mode_sense scsi_cmd; + int error; + + /* + * Make sure the sense buffer is clean before we do the mode sense, so + * that checks for bogus values of 0 will work in case the mode sense + * fails. + */ + bzero(data, len); + + bzero(&scsi_cmd, sizeof(scsi_cmd)); + scsi_cmd.opcode = MODE_SENSE; + scsi_cmd.byte2 = byte2; + scsi_cmd.page = page; + scsi_cmd.length = len & 0xff; + + error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&scsi_cmd, + sizeof(scsi_cmd), data, len, 4, timeout, NULL, + flags | SCSI_DATA_IN); + + SC_DEBUG(sc_link, SDEV_DB2, ("scsi_mode_sense: page %#x, error = %d\n", + page, error)); + + return (error); +} + +int +scsi_mode_select(sc_link, byte2, data, len, flags, timeout) + struct scsi_link *sc_link; + int byte2, flags, timeout; + size_t len; + u_char *data; +{ + struct scsi_mode_select scsi_cmd; + int error; + + bzero(&scsi_cmd, sizeof(scsi_cmd)); + scsi_cmd.opcode = MODE_SELECT; + scsi_cmd.byte2 = byte2; + scsi_cmd.length = len & 0xff; + + error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&scsi_cmd, + sizeof(scsi_cmd), data, len, 4, timeout, NULL, + flags | SCSI_DATA_OUT); + + SC_DEBUG(sc_link, SDEV_DB2, ("scsi_mode_select: error = %d\n", error)); + + return (error); +} + /* * This routine is called by the scsi interrupt when the transfer is complete. */ diff --git a/sys/scsi/scsiconf.h b/sys/scsi/scsiconf.h index 644fd76eec8..2fcf7e253e5 100644 --- a/sys/scsi/scsiconf.h +++ b/sys/scsi/scsiconf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: scsiconf.h,v 1.48 2004/11/30 19:28:37 krw Exp $ */ +/* $OpenBSD: scsiconf.h,v 1.49 2005/04/05 12:13:16 krw Exp $ */ /* $NetBSD: scsiconf.h,v 1.35 1997/04/02 02:29:38 mycroft Exp $ */ /* @@ -330,6 +330,10 @@ int scsi_test_unit_ready(struct scsi_link *, int, int); int scsi_inquire(struct scsi_link *, struct scsi_inquiry_data *, int); int scsi_prevent(struct scsi_link *, int, int); int scsi_start(struct scsi_link *, int, int); +int scsi_mode_sense(struct scsi_link *, int, int, u_char *, size_t, + int, int); +int scsi_mode_select(struct scsi_link *, int, u_char *, size_t, int, + int); void scsi_done(struct scsi_xfer *); void scsi_user_done(struct scsi_xfer *); int scsi_scsi_cmd(struct scsi_link *, struct scsi_generic *, diff --git a/sys/scsi/sd_scsi.c b/sys/scsi/sd_scsi.c index e6ea2d2e9dc..4dd4b9e7203 100644 --- a/sys/scsi/sd_scsi.c +++ b/sys/scsi/sd_scsi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sd_scsi.c,v 1.6 2003/06/25 02:18:35 krw Exp $ */ +/* $OpenBSD: sd_scsi.c,v 1.7 2005/04/05 12:13:16 krw Exp $ */ /* $NetBSD: sd_scsi.c,v 1.8 1998/10/08 20:21:13 thorpej Exp $ */ /*- @@ -95,27 +95,8 @@ sd_scsibus_mode_sense(sd, scsi_sense, page, flags) struct sd_scsibus_mode_sense_data *scsi_sense; int page, flags; { - struct scsi_mode_sense scsi_cmd; - - /* - * Make sure the sense buffer is clean before we do - * the mode sense, so that checks for bogus values of - * 0 will work in case the mode sense fails. - */ - bzero(scsi_sense, sizeof(*scsi_sense)); - - bzero(&scsi_cmd, sizeof(scsi_cmd)); - scsi_cmd.opcode = MODE_SENSE; - scsi_cmd.page = page; - scsi_cmd.length = sizeof(*scsi_sense); - /* - * If the command worked, use the results to fill out - * the parameter structure - */ - return (scsi_scsi_cmd(sd->sc_link, - (struct scsi_generic *)&scsi_cmd, sizeof(scsi_cmd), - (u_char *)scsi_sense, sizeof(*scsi_sense), - SDRETRIES, 6000, NULL, flags | SCSI_DATA_IN | SCSI_SILENT)); + return scsi_mode_sense(sd->sc_link, 0, page, (u_char *)scsi_sense, + sizeof(*scsi_sense), flags | SCSI_SILENT, 6000); } int @@ -124,7 +105,6 @@ sd_scsibus_get_optparms(sd, dp, flags) struct disk_parms *dp; int flags; { - struct scsi_mode_sense scsi_cmd; struct sd_scsibus_mode_sense_data scsi_sense; int error; @@ -137,18 +117,11 @@ sd_scsibus_get_optparms(sd, dp, flags) * It is better to get the following params from the * mode sense page 6 only (optical device parameter page). * However, there are stupid optical devices which does NOT - * support the page 6. Ghaa.... + * support the page 6. Ask for all (0x3f) pages. Ghaa.... */ - bzero(&scsi_cmd, sizeof(scsi_cmd)); - scsi_cmd.opcode = MODE_SENSE; - scsi_cmd.page = 0x3f; /* all pages */ - scsi_cmd.length = sizeof(struct scsi_mode_header) + - sizeof(struct scsi_blk_desc); - - if ((error = scsi_scsi_cmd(sd->sc_link, - (struct scsi_generic *)&scsi_cmd, sizeof(scsi_cmd), - (u_char *)&scsi_sense, sizeof(scsi_sense), SDRETRIES, - 6000, NULL, flags | SCSI_DATA_IN)) != 0) + error = scsi_mode_sense(sd->sc_link, 0, 0x3f, (u_char *)&scsi_sense, + sizeof(scsi_sense), flags, 6000); + if (error != 0) return (SDGP_RESULT_OFFLINE); /* XXX? */ dp->blksize = _3btol(scsi_sense.blk_desc.blklen); diff --git a/sys/scsi/ss_mustek.c b/sys/scsi/ss_mustek.c index b258b452416..aa37da6151e 100644 --- a/sys/scsi/ss_mustek.c +++ b/sys/scsi/ss_mustek.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ss_mustek.c,v 1.9 2002/03/14 01:27:13 millert Exp $ */ +/* $OpenBSD: ss_mustek.c,v 1.10 2005/04/05 12:13:16 krw Exp $ */ /* $NetBSD: ss_mustek.c,v 1.4 1996/05/05 19:52:57 christos Exp $ */ /* @@ -254,7 +254,6 @@ int mustek_trigger_scanner(ss) struct ss_softc *ss; { - struct mustek_mode_select_cmd mode_cmd; struct mustek_mode_select_data mode_data; struct mustek_set_window_cmd window_cmd; struct mustek_set_window_data window_data; @@ -311,10 +310,6 @@ mustek_trigger_scanner(ss) /* * do what it takes to actualize the mode */ - bzero(&mode_cmd, sizeof(mode_cmd)); - mode_cmd.opcode = MUSTEK_MODE_SELECT; - _lto2b(sizeof(mode_data), mode_cmd.length); - bzero(&mode_data, sizeof(mode_data)); mode_data.mode = MUSTEK_MODE_MASK | MUSTEK_HT_PATTERN_BUILTIN | MUSTEK_UNIT_SPEC; @@ -341,9 +336,8 @@ mustek_trigger_scanner(ss) SC_DEBUG(sc_link, SDEV_DB1, ("mustek_trigger_scanner: mode_select\n")); /* send the command to the scanner */ - error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &mode_cmd, - sizeof(mode_cmd), (u_char *) &mode_data, sizeof(mode_data), - MUSTEK_RETRIES, 5000, NULL, SCSI_DATA_OUT); + error = scsi_mode_select(sc_link, 0, (u_char *)&mode_data, + sizeof(mode_data), 0, 5000); if (error) return (error); diff --git a/sys/scsi/ss_mustek.h b/sys/scsi/ss_mustek.h index ff5dcc7b40a..95dbc4b3107 100644 --- a/sys/scsi/ss_mustek.h +++ b/sys/scsi/ss_mustek.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ss_mustek.h,v 1.4 1996/05/07 09:34:33 niklas Exp $ */ +/* $OpenBSD: ss_mustek.h,v 1.5 2005/04/05 12:13:16 krw Exp $ */ /* $NetBSD: ss_mustek.h,v 1.2 1996/03/19 03:08:37 mycroft Exp $ */ /* @@ -52,7 +52,6 @@ #define MUSTEK_SET_WINDOW 0x04 /* set image area and windows */ #define MUSTEK_READ 0x08 /* read command */ #define MUSTEK_GET_STATUS 0x0f /* image status */ -#define MUSTEK_MODE_SELECT 0x15 /* set resolution, paper length, .. */ #define MUSTEK_ADF 0x10 /* ADF and backtracking selection */ #define MUSTEK_START_STOP 0x1b /* start/stop scan */ #define MUSTEK_LUT 0x55 /* look up table download */ @@ -126,13 +125,6 @@ struct mustek_get_status_data { u_int8_t lines[3]; /* LSB */ }; -struct mustek_mode_select_cmd { - u_int8_t opcode; /* 0x15 */ - u_int8_t reserved[2]; - u_int8_t length[2]; - u_int8_t control; -}; - /* * resolution settings: * MFS06000CX: diff --git a/sys/scsi/st.c b/sys/scsi/st.c index 84efb0ca844..c7a45fa4779 100644 --- a/sys/scsi/st.c +++ b/sys/scsi/st.c @@ -1,4 +1,4 @@ -/* $OpenBSD: st.c,v 1.43 2004/11/30 19:28:37 krw Exp $ */ +/* $OpenBSD: st.c,v 1.44 2005/04/05 12:13:16 krw Exp $ */ /* $NetBSD: st.c,v 1.71 1997/02/21 23:03:49 thorpej Exp $ */ /* @@ -1429,9 +1429,8 @@ st_mode_sense(st, flags) struct st_softc *st; int flags; { - u_int scsi_sense_len; + size_t scsi_sense_len; int error; - struct scsi_mode_sense cmd; struct scsi_sense { struct scsi_mode_header header; struct scsi_blk_desc blk_desc; @@ -1442,21 +1441,10 @@ st_mode_sense(st, flags) scsi_sense_len = 12 + st->page_0_size; /* - * Set up a mode sense + * Ask for page 0 mode sense data. */ - bzero(&cmd, sizeof(cmd)); - cmd.opcode = MODE_SENSE; - cmd.length = scsi_sense_len; - - /* - * do the command, but we don't need the results - * just print them for our interest's sake, if asked, - * or if we need it as a template for the mode select - * store it away. - */ - error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd, - sizeof(cmd), (u_char *) &scsi_sense, scsi_sense_len, - ST_RETRIES, ST_CTL_TIME, NULL, flags | SCSI_DATA_IN); + error = scsi_mode_sense(sc_link, 0, 0, (u_char *)&scsi_sense, + scsi_sense_len, flags, ST_CTL_TIME); if (error) return error; @@ -1490,7 +1478,6 @@ st_mode_select(st, flags) int flags; { u_int scsi_select_len; - struct scsi_mode_select cmd; struct scsi_select { struct scsi_mode_header header; struct scsi_blk_desc blk_desc; @@ -1518,10 +1505,6 @@ st_mode_select(st, flags) /* * Set up for a mode select */ - bzero(&cmd, sizeof(cmd)); - cmd.opcode = MODE_SELECT; - cmd.length = scsi_select_len; - bzero(&scsi_select, scsi_select_len); scsi_select.header.blk_desc_len = sizeof(struct scsi_blk_desc); scsi_select.header.dev_spec &= ~SMH_DSP_BUFF_MODE; @@ -1538,9 +1521,8 @@ st_mode_select(st, flags) /* * do the command */ - return scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd, - sizeof(cmd), (u_char *) &scsi_select, scsi_select_len, - ST_RETRIES, ST_CTL_TIME, NULL, flags | SCSI_DATA_OUT); + return scsi_mode_select(st->sc_link, 0, (u_char *)&scsi_select, + scsi_select_len, flags, ST_CTL_TIME); } /* |