Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Rework the changer driver a bit:
details: https://anonhg.NetBSD.org/src/rev/0146589bd4f1
branches: trunk
changeset: 476217:0146589bd4f1
user: thorpej <thorpej%NetBSD.org@localhost>
date: Thu Sep 09 23:24:11 1999 +0000
description:
Rework the changer driver a bit:
- Take note of magazine changes, and enqueue "Element Status Changed" events
that user processes can read or select on.
- Normalize some structure names.
- Report back more status about changer elements:
* Volume tags (e.g. barcode labels on the backs of your tapes)
* External device names (for drive units in a changer)
* Last element a unit of media was moved from
* Sense information for SCSI changer elements in EXCEPT condition
* Vendor-specific data if the user requests it.
- Add support for setting volume tags.
diffstat:
sys/dev/scsipi/ch.c | 730 ++++++++++++++++++++++++++++++++++++-----
sys/dev/scsipi/scsi_changer.h | 52 ++-
sys/sys/chio.h | 223 ++++++++++--
sys/sys/conf.h | 4 +-
4 files changed, 860 insertions(+), 149 deletions(-)
diffs (truncated from 1370 to 300 lines):
diff -r a4dd3e441888 -r 0146589bd4f1 sys/dev/scsipi/ch.c
--- a/sys/dev/scsipi/ch.c Thu Sep 09 21:52:11 1999 +0000
+++ b/sys/dev/scsipi/ch.c Thu Sep 09 23:24:11 1999 +0000
@@ -1,12 +1,12 @@
-/* $NetBSD: ch.c,v 1.38 1999/04/04 12:20:48 bouyer Exp $ */
+/* $NetBSD: ch.c,v 1.39 1999/09/09 23:24:12 thorpej Exp $ */
-/*
- * Copyright (c) 1996, 1997, 1998 Jason R. Thorpe <thorpej%and.com@localhost>
+/*-
+ * Copyright (c) 1996, 1997, 1998, 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
- * Partially based on an autochanger driver written by Stefan Grefen
- * and on an autochanger driver written by the Systems Programming Group
- * at the University of Utah Computer Science Department.
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -17,27 +17,29 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgements:
- * This product includes software developed by Jason R. Thorpe
- * for And Communications, http://www.and.com/
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/kernel.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/buf.h>
@@ -48,6 +50,10 @@
#include <sys/malloc.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
+#include <sys/vnode.h>
+#include <sys/time.h>
+#include <sys/select.h>
+#include <sys/poll.h>
#include <dev/scsipi/scsipi_all.h>
#include <dev/scsipi/scsi_all.h>
@@ -61,6 +67,11 @@
struct device sc_dev; /* generic device info */
struct scsipi_link *sc_link; /* link in the SCSI bus */
+ u_int sc_events; /* event bitmask */
+ struct selinfo sc_selq; /* select/poll queue for events */
+
+ int sc_flags; /* misc. info */
+
int sc_picker; /* current picker */
/*
@@ -81,8 +92,6 @@
*/
u_int8_t sc_exchangemask[4];
- int flags; /* misc. info */
-
/*
* Quirks; see below.
*/
@@ -91,7 +100,7 @@
};
/* sc_flags */
-#define CHF_ROTATE 0x01 /* picker can rotate */
+#define CHF_ROTATE 0x01 /* picker can rotate */
/* Autoconfiguration glue */
int chmatch __P((struct device *, struct cfdata *, void *));
@@ -109,19 +118,36 @@
};
/* SCSI glue */
+int ch_interpret_sense __P((struct scsipi_xfer *));
+
struct scsipi_device ch_switch = {
- NULL, NULL, NULL, NULL
+ ch_interpret_sense, /* check our error handler first */
+ NULL, /* no queue; our commands are synchronous */
+ NULL, /* have no async handler */
+ NULL, /* nothing to be done when xfer is done */
};
-int ch_move __P((struct ch_softc *, struct changer_move *));
-int ch_exchange __P((struct ch_softc *, struct changer_exchange *));
-int ch_position __P((struct ch_softc *, struct changer_position *));
+int ch_move __P((struct ch_softc *, struct changer_move_request *));
+int ch_exchange __P((struct ch_softc *, struct changer_exchange_request *));
+int ch_position __P((struct ch_softc *, struct changer_position_request *));
int ch_ielem __P((struct ch_softc *));
-int ch_usergetelemstatus __P((struct ch_softc *, int, u_int8_t *));
-int ch_getelemstatus __P((struct ch_softc *, int, int, caddr_t, size_t));
+int ch_ousergetelemstatus __P((struct ch_softc *, int, u_int8_t *));
+int ch_usergetelemstatus __P((struct ch_softc *,
+ struct changer_element_status_request *));
+int ch_getelemstatus __P((struct ch_softc *, int, int, void *,
+ size_t, int));
+int ch_setvoltag __P((struct ch_softc *,
+ struct changer_set_voltag_request *));
int ch_get_params __P((struct ch_softc *, int));
void ch_get_quirks __P((struct ch_softc *,
struct scsipi_inquiry_pattern *));
+void ch_event __P((struct ch_softc *, u_int));
+int ch_map_element __P((struct ch_softc *, u_int16_t, int *, int *));
+
+void ch_voltag_convert_in __P((const struct changer_volume_tag *,
+ struct changer_voltag *));
+int ch_voltag_convert_out __P((const struct changer_voltag *,
+ struct changer_volume_tag *));
/*
* SCSI changer quirks.
@@ -189,7 +215,7 @@
* Get information about the device. Note we can't use
* interrupts yet.
*/
- if (ch_get_params(sc, SCSI_AUTOCONF))
+ if (ch_get_params(sc, SCSI_AUTOCONF|SCSI_IGNORE_MEDIA_CHANGE))
printf("%s: offline\n", sc->sc_dev.dv_xname);
else {
#define PLURAL(c) (c) == 1 ? "" : "s"
@@ -242,12 +268,14 @@
sc->sc_link->flags |= SDEV_OPEN;
/*
- * Absorb any unit attention errors. Ignore "not ready"
- * since this might occur if e.g. a tape isn't actually
- * loaded in the drive.
+ * Make sure the unit is on-line. If a UNIT ATTENTION
+ * occurs, we will mark that an Init-Element-Status is
+ * needed in ch_get_params().
+ *
+ * We ignore NOT READY in case e.g a magazine isn't actually
+ * loaded into the changer or a tape isn't in the drive.
*/
- error = scsipi_test_unit_ready(sc->sc_link,
- SCSI_IGNORE_NOT_READY|SCSI_IGNORE_MEDIA_CHANGE);
+ error = scsipi_test_unit_ready(sc->sc_link, SCSI_IGNORE_NOT_READY);
if (error)
goto bad;
@@ -276,11 +304,36 @@
scsipi_wait_drain(sc->sc_link);
scsipi_adapter_delref(sc->sc_link);
+
+ sc->sc_events = 0;
+
sc->sc_link->flags &= ~SDEV_OPEN;
return (0);
}
int
+chread(dev, uio, flags)
+ dev_t dev;
+ struct uio *uio;
+ int flags;
+{
+ struct ch_softc *sc = ch_cd.cd_devs[CHUNIT(dev)];
+ int error;
+
+ if (uio->uio_resid != CHANGER_EVENT_SIZE)
+ return (EINVAL);
+
+ /*
+ * Read never blocks; if there are no events pending, we just
+ * return an all-clear bitmask.
+ */
+ error = uiomove(&sc->sc_events, CHANGER_EVENT_SIZE, uio);
+ if (error == 0)
+ sc->sc_events = 0;
+ return (error);
+}
+
+int
chioctl(dev, cmd, data, flags, p)
dev_t dev;
u_long cmd;
@@ -298,7 +351,7 @@
switch (cmd) {
case CHIOGPICKER:
case CHIOGPARAMS:
- case CHIOGSTATUS:
+ case OCHIOGSTATUS:
break;
default:
@@ -308,30 +361,35 @@
switch (cmd) {
case CHIOMOVE:
- error = ch_move(sc, (struct changer_move *)data);
+ error = ch_move(sc, (struct changer_move_request *)data);
break;
case CHIOEXCHANGE:
- error = ch_exchange(sc, (struct changer_exchange *)data);
+ error = ch_exchange(sc,
+ (struct changer_exchange_request *)data);
break;
case CHIOPOSITION:
- error = ch_position(sc, (struct changer_position *)data);
+ error = ch_position(sc,
+ (struct changer_position_request *)data);
break;
case CHIOGPICKER:
*(int *)data = sc->sc_picker - sc->sc_firsts[CHET_MT];
break;
- case CHIOSPICKER: {
+ case CHIOSPICKER:
+ {
int new_picker = *(int *)data;
if (new_picker > (sc->sc_counts[CHET_MT] - 1))
return (EINVAL);
sc->sc_picker = sc->sc_firsts[CHET_MT] + new_picker;
- break; }
+ break;
+ }
- case CHIOGPARAMS: {
+ case CHIOGPARAMS:
+ {
struct changer_params *cp = (struct changer_params *)data;
cp->cp_curpicker = sc->sc_picker - sc->sc_firsts[CHET_MT];
@@ -339,18 +397,32 @@
cp->cp_nslots = sc->sc_counts[CHET_ST];
cp->cp_nportals = sc->sc_counts[CHET_IE];
cp->cp_ndrives = sc->sc_counts[CHET_DT];
- break; }
+ break;
+ }
case CHIOIELEM:
error = ch_ielem(sc);
break;
- case CHIOGSTATUS: {
- struct changer_element_status *ces =
- (struct changer_element_status *)data;
+ case OCHIOGSTATUS:
+ {
+ struct ochanger_element_status_request *cesr =
+ (struct ochanger_element_status_request *)data;
+
+ error = ch_ousergetelemstatus(sc, cesr->cesr_type,
+ cesr->cesr_data);
+ break;
+ }
- error = ch_usergetelemstatus(sc, ces->ces_type, ces->ces_data);
- break; }
+ case CHIOGSTATUS:
+ error = ch_usergetelemstatus(sc,
+ (struct changer_element_status_request *)data);
+ break;
Home |
Main Index |
Thread Index |
Old Index