1998-01-12 21:30:41 +03:00
|
|
|
/* $NetBSD: ac.c,v 1.11 1998/01/12 18:30:41 thorpej Exp $ */
|
1997-10-04 13:59:35 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* 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 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 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.
|
|
|
|
*/
|
1994-10-26 10:22:45 +03:00
|
|
|
|
1994-05-23 09:58:16 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1991 University of Utah.
|
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* the Systems Programming Group of the University of Utah Computer
|
|
|
|
* Science Department.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* 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 acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
|
|
|
*
|
|
|
|
* from: Utah $Hdr: ac.c 1.5 92/01/21$
|
|
|
|
*
|
1994-10-26 10:22:45 +03:00
|
|
|
* @(#)ac.c 8.2 (Berkeley) 1/12/94
|
1994-05-23 09:58:16 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SCSI driver for MO autochanger.
|
|
|
|
*
|
|
|
|
* Very crude. Because of the lack of connect/disconnect support in the
|
|
|
|
* scsi driver, this driver can tie up the SCSI bus for a long time. It
|
|
|
|
* also grabs a DMA channel and holds it for the duration even though it
|
|
|
|
* never uses it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1997-03-31 11:32:14 +04:00
|
|
|
#include <sys/systm.h>
|
1994-05-23 09:58:16 +04:00
|
|
|
#include <sys/buf.h>
|
1997-03-31 11:32:14 +04:00
|
|
|
#include <sys/device.h>
|
1994-05-23 09:58:16 +04:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <hp300/dev/scsireg.h>
|
1997-01-30 12:14:10 +03:00
|
|
|
#include <hp300/dev/scsivar.h>
|
1994-05-23 09:58:16 +04:00
|
|
|
#include <hp300/dev/acioctl.h>
|
|
|
|
#include <hp300/dev/acvar.h>
|
|
|
|
|
1997-03-31 11:32:14 +04:00
|
|
|
/* cdev_decl(ac); */
|
|
|
|
/* XXX we should use macros to do these... */
|
|
|
|
int acopen __P((dev_t, int, int, struct proc *));
|
|
|
|
int acclose __P((dev_t, int, int, struct proc *));
|
|
|
|
int acioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
|
|
|
|
|
|
|
|
static int acmatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
static void acattach __P((struct device *, struct device *, void *));
|
1994-05-23 09:58:16 +04:00
|
|
|
|
1997-01-30 12:14:10 +03:00
|
|
|
struct cfattach ac_ca = {
|
|
|
|
sizeof(struct ac_softc), acmatch, acattach
|
|
|
|
};
|
1994-05-23 09:58:16 +04:00
|
|
|
|
1998-01-12 21:30:41 +03:00
|
|
|
extern struct cfdriver ac_cd;
|
1994-05-23 09:58:16 +04:00
|
|
|
|
1997-01-30 12:14:10 +03:00
|
|
|
void acstart __P((void *));
|
|
|
|
void acgo __P((void *));
|
|
|
|
void acintr __P((void *, int));
|
1994-05-23 09:58:16 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
int ac_debug = 0x0000;
|
|
|
|
#define ACD_FOLLOW 0x0001
|
|
|
|
#define ACD_OPEN 0x0002
|
|
|
|
#endif
|
|
|
|
|
1997-03-31 11:32:14 +04:00
|
|
|
static int
|
1997-01-30 12:14:10 +03:00
|
|
|
acmatch(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
1994-05-23 09:58:16 +04:00
|
|
|
{
|
1997-01-30 12:14:10 +03:00
|
|
|
struct oscsi_attach_args *osa = aux;
|
1994-05-23 09:58:16 +04:00
|
|
|
|
1997-01-30 12:14:10 +03:00
|
|
|
if (osa->osa_inqbuf->type != 8 || osa->osa_inqbuf->qual != 0x80 ||
|
|
|
|
osa->osa_inqbuf->version != 2)
|
1995-12-02 21:21:49 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1997-03-31 11:32:14 +04:00
|
|
|
static void
|
1997-01-30 12:14:10 +03:00
|
|
|
acattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1994-05-23 09:58:16 +04:00
|
|
|
{
|
1997-01-30 12:14:10 +03:00
|
|
|
struct ac_softc *sc = (struct ac_softc *)self;
|
|
|
|
struct oscsi_attach_args *osa = aux;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
sc->sc_target = osa->osa_target;
|
|
|
|
sc->sc_lun = osa->osa_lun;
|
|
|
|
|
|
|
|
/* Initialize SCSI queue entry. */
|
|
|
|
sc->sc_sq.sq_softc = sc;
|
|
|
|
sc->sc_sq.sq_target = sc->sc_target;
|
|
|
|
sc->sc_sq.sq_lun = sc->sc_lun;
|
|
|
|
sc->sc_sq.sq_start = acstart;
|
|
|
|
sc->sc_sq.sq_go = acgo;
|
|
|
|
sc->sc_sq.sq_intr = acintr;
|
|
|
|
|
|
|
|
sc->sc_bp = (struct buf *)malloc(sizeof(struct buf),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
sc->sc_cmd = (struct scsi_fmt_cdb *)malloc(sizeof(struct scsi_fmt_cdb),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
|
|
|
|
if (sc->sc_bp == NULL || sc->sc_cmd == NULL) {
|
|
|
|
printf("%s: memory allocation failed\n", sc->sc_dev.dv_xname);
|
|
|
|
return;
|
1994-05-23 09:58:16 +04:00
|
|
|
}
|
|
|
|
|
1997-01-30 12:14:10 +03:00
|
|
|
sc->sc_flags = ACF_ALIVE;
|
1994-05-23 09:58:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1997-03-31 11:32:14 +04:00
|
|
|
int
|
1994-05-23 09:58:16 +04:00
|
|
|
acopen(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1997-03-31 11:32:14 +04:00
|
|
|
int unit = minor(dev);
|
1997-01-30 12:14:10 +03:00
|
|
|
struct ac_softc *sc;
|
1994-05-23 09:58:16 +04:00
|
|
|
|
1997-01-30 12:14:10 +03:00
|
|
|
if (unit >= ac_cd.cd_ndevs ||
|
|
|
|
(sc = ac_cd.cd_devs[unit]) == NULL ||
|
|
|
|
(sc->sc_flags & ACF_ALIVE) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
1994-05-23 09:58:16 +04:00
|
|
|
if (sc->sc_flags & ACF_OPEN)
|
1997-01-30 12:14:10 +03:00
|
|
|
return (EBUSY);
|
|
|
|
|
1994-05-23 09:58:16 +04:00
|
|
|
/*
|
|
|
|
* Since acgeteinfo can block we mark the changer open now.
|
|
|
|
*/
|
|
|
|
sc->sc_flags |= ACF_OPEN;
|
|
|
|
if (acgeteinfo(dev)) {
|
|
|
|
sc->sc_flags &= ~ACF_OPEN;
|
|
|
|
return(EIO);
|
|
|
|
}
|
1997-01-30 12:14:10 +03:00
|
|
|
return (0);
|
1994-05-23 09:58:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1997-03-31 11:32:14 +04:00
|
|
|
int
|
1994-05-23 09:58:16 +04:00
|
|
|
acclose(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1997-01-30 12:14:10 +03:00
|
|
|
struct ac_softc *sc = ac_cd.cd_devs[minor(dev)];
|
1994-05-23 09:58:16 +04:00
|
|
|
|
|
|
|
sc->sc_flags &= ~ACF_OPEN;
|
1997-01-30 12:14:10 +03:00
|
|
|
return (0);
|
1994-05-23 09:58:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ACRESLEN(ep) \
|
|
|
|
(8 + (ep)->nmte*12 + (ep)->nse*12 + (ep)->niee*12 + (ep)->ndte*20)
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1997-03-31 11:32:14 +04:00
|
|
|
int
|
1994-05-23 09:58:16 +04:00
|
|
|
acioctl(dev, cmd, data, flag, p)
|
|
|
|
dev_t dev;
|
1997-03-31 11:32:14 +04:00
|
|
|
u_long cmd;
|
1994-05-23 09:58:16 +04:00
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1997-01-30 12:14:10 +03:00
|
|
|
struct ac_softc *sc = ac_cd.cd_devs[minor(dev)];
|
1994-05-23 09:58:16 +04:00
|
|
|
char *dp;
|
|
|
|
int dlen, error = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* perform an init element status and mode sense to reset state */
|
|
|
|
case ACIOCINIT:
|
|
|
|
error = accommand(dev, ACCMD_INITES, (caddr_t)0, 0);
|
|
|
|
if (!error)
|
|
|
|
error = acgeteinfo(dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* copy internal element information */
|
|
|
|
case ACIOCGINFO:
|
|
|
|
*(struct acinfo *)data = sc->sc_einfo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACIOCRAWES:
|
|
|
|
{
|
|
|
|
struct acbuffer *acbp = (struct acbuffer *)data;
|
|
|
|
|
|
|
|
dlen = ACRESLEN(&sc->sc_einfo);
|
|
|
|
dp = (char *) malloc(dlen, M_DEVBUF, M_WAITOK);
|
|
|
|
error = accommand(dev, ACCMD_READES, dp, dlen);
|
|
|
|
if (!error) {
|
|
|
|
dlen = *(int *)&dp[4] + 8;
|
|
|
|
if (dlen > acbp->buflen)
|
|
|
|
dlen = acbp->buflen;
|
|
|
|
error = copyout(dp, acbp->bufptr, dlen);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ACIOCGSTAT:
|
|
|
|
{
|
|
|
|
struct acbuffer *acbp = (struct acbuffer *)data;
|
|
|
|
|
|
|
|
dlen = ACRESLEN(&sc->sc_einfo);
|
|
|
|
dp = (char *) malloc(dlen, M_DEVBUF, M_WAITOK);
|
|
|
|
error = accommand(dev, ACCMD_READES, dp, dlen);
|
|
|
|
if (!error) {
|
|
|
|
int ne;
|
|
|
|
char *tbuf;
|
|
|
|
|
|
|
|
ne = sc->sc_einfo.nmte + sc->sc_einfo.nse +
|
|
|
|
sc->sc_einfo.niee + sc->sc_einfo.ndte;
|
|
|
|
dlen = ne * sizeof(struct aceltstat);
|
|
|
|
tbuf = (char *) malloc(dlen, M_DEVBUF, M_WAITOK);
|
|
|
|
acconvert(dp, tbuf, ne);
|
|
|
|
if (dlen > acbp->buflen)
|
|
|
|
dlen = acbp->buflen;
|
|
|
|
error = copyout(tbuf, acbp->bufptr, dlen);
|
|
|
|
free(tbuf, M_DEVBUF);
|
|
|
|
}
|
|
|
|
free(dp, M_DEVBUF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ACIOCMOVE:
|
|
|
|
error = accommand(dev, ACCMD_MOVEM, data,
|
|
|
|
sizeof(struct acmove));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
1997-03-31 11:32:14 +04:00
|
|
|
int
|
1994-05-23 09:58:16 +04:00
|
|
|
accommand(dev, command, bufp, buflen)
|
|
|
|
dev_t dev;
|
|
|
|
int command;
|
|
|
|
char *bufp;
|
|
|
|
int buflen;
|
|
|
|
{
|
|
|
|
int unit = minor(dev);
|
1997-01-30 12:14:10 +03:00
|
|
|
struct ac_softc *sc = ac_cd.cd_devs[unit];
|
1997-03-31 11:32:14 +04:00
|
|
|
struct buf *bp = sc->sc_bp;
|
|
|
|
struct scsi_fmt_cdb *cmd = sc->sc_cmd;
|
1994-05-23 09:58:16 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ac_debug & ACD_FOLLOW)
|
1997-04-03 02:37:21 +04:00
|
|
|
printf("accommand(dev=%x, cmd=%x, buf=%p, buflen=%x)\n",
|
1994-05-23 09:58:16 +04:00
|
|
|
dev, command, bufp, buflen);
|
|
|
|
#endif
|
|
|
|
if (sc->sc_flags & ACF_ACTIVE)
|
|
|
|
panic("accommand: active!");
|
|
|
|
|
|
|
|
sc->sc_flags |= ACF_ACTIVE;
|
|
|
|
bzero((caddr_t)cmd->cdb, sizeof(cmd->cdb));
|
|
|
|
cmd->cdb[0] = command;
|
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
case ACCMD_INITES:
|
|
|
|
cmd->len = 6;
|
|
|
|
break;
|
|
|
|
case ACCMD_READES:
|
|
|
|
cmd->len = 12;
|
|
|
|
*(short *)&cmd->cdb[2] = 0;
|
|
|
|
*(short *)&cmd->cdb[4] =
|
|
|
|
sc->sc_einfo.nmte + sc->sc_einfo.nse +
|
|
|
|
sc->sc_einfo.niee + sc->sc_einfo.ndte;
|
|
|
|
cmd->cdb[7] = buflen >> 16;
|
|
|
|
cmd->cdb[8] = buflen >> 8;
|
|
|
|
cmd->cdb[9] = buflen;
|
|
|
|
break;
|
|
|
|
case ACCMD_MODESENSE:
|
|
|
|
cmd->len = 6;
|
|
|
|
cmd->cdb[2] = 0x3F; /* all pages */
|
|
|
|
cmd->cdb[4] = buflen;
|
|
|
|
break;
|
|
|
|
case ACCMD_MOVEM:
|
|
|
|
cmd->len = 12;
|
|
|
|
*(short *)&cmd->cdb[2] = sc->sc_picker;
|
|
|
|
*(short *)&cmd->cdb[4] = *(short *)&bufp[0];
|
|
|
|
*(short *)&cmd->cdb[6] = *(short *)&bufp[2];
|
|
|
|
if (*(short *)&bufp[4] & AC_INVERT)
|
|
|
|
cmd->cdb[10] = 1;
|
|
|
|
bufp = 0;
|
|
|
|
buflen = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("accommand: bad command");
|
|
|
|
}
|
|
|
|
bp->b_flags = B_BUSY|B_READ;
|
|
|
|
bp->b_dev = dev;
|
|
|
|
bp->b_un.b_addr = bufp;
|
|
|
|
bp->b_bcount = buflen;
|
|
|
|
bp->b_resid = 0;
|
|
|
|
bp->b_blkno = 0;
|
|
|
|
bp->b_error = 0;
|
1997-01-30 12:14:10 +03:00
|
|
|
if (scsireq(sc->sc_dev.dv_parent, &sc->sc_sq))
|
|
|
|
acstart(sc);
|
1994-05-23 09:58:16 +04:00
|
|
|
error = biowait(bp);
|
|
|
|
sc->sc_flags &= ~ACF_ACTIVE;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1997-01-30 12:14:10 +03:00
|
|
|
void
|
|
|
|
acstart(arg)
|
|
|
|
void *arg;
|
1994-05-23 09:58:16 +04:00
|
|
|
{
|
1997-01-30 12:14:10 +03:00
|
|
|
struct ac_softc *sc = arg;
|
|
|
|
|
1994-05-23 09:58:16 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (ac_debug & ACD_FOLLOW)
|
1997-04-03 02:37:21 +04:00
|
|
|
printf("acstart(unit=%x)\n", sc->sc_dev.dv_unit);
|
1994-05-23 09:58:16 +04:00
|
|
|
#endif
|
1997-01-30 12:14:10 +03:00
|
|
|
if (scsiustart(sc->sc_dev.dv_parent->dv_unit))
|
|
|
|
acgo(arg);
|
1994-05-23 09:58:16 +04:00
|
|
|
}
|
|
|
|
|
1997-01-30 12:14:10 +03:00
|
|
|
void
|
|
|
|
acgo(arg)
|
|
|
|
void *arg;
|
1994-05-23 09:58:16 +04:00
|
|
|
{
|
1997-01-30 12:14:10 +03:00
|
|
|
struct ac_softc *sc = arg;
|
1997-03-31 11:32:14 +04:00
|
|
|
struct buf *bp = sc->sc_bp;
|
1994-05-23 09:58:16 +04:00
|
|
|
int stat;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ac_debug & ACD_FOLLOW)
|
1997-04-03 02:37:21 +04:00
|
|
|
printf("acgo(unit=%x): ", sc->sc_dev.dv_unit);
|
1994-05-23 09:58:16 +04:00
|
|
|
#endif
|
1997-01-30 12:14:10 +03:00
|
|
|
stat = scsigo(sc->sc_dev.dv_parent->dv_unit, sc->sc_target,
|
|
|
|
sc->sc_lun, bp, sc->sc_cmd, 0);
|
1994-05-23 09:58:16 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (ac_debug & ACD_FOLLOW)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("scsigo returns %x\n", stat);
|
1994-05-23 09:58:16 +04:00
|
|
|
#endif
|
|
|
|
if (stat) {
|
|
|
|
bp->b_error = EIO;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
(void) biodone(bp);
|
1997-01-30 12:14:10 +03:00
|
|
|
scsifree(sc->sc_dev.dv_parent, &sc->sc_sq);
|
1994-05-23 09:58:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-01-30 12:14:10 +03:00
|
|
|
void
|
1996-02-14 05:43:54 +03:00
|
|
|
acintr(arg, stat)
|
|
|
|
void *arg;
|
|
|
|
int stat;
|
1994-05-23 09:58:16 +04:00
|
|
|
{
|
1997-03-31 11:32:14 +04:00
|
|
|
struct ac_softc *sc = arg;
|
|
|
|
struct buf *bp = sc->sc_bp;
|
1994-05-23 09:58:16 +04:00
|
|
|
u_char sensebuf[78];
|
|
|
|
struct scsi_xsense *sp;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ac_debug & ACD_FOLLOW)
|
1997-03-31 11:32:14 +04:00
|
|
|
printf("acintr(unit=%x, stat=%x)\n", sc->sc_dev.dv_unit, stat);
|
1994-05-23 09:58:16 +04:00
|
|
|
#endif
|
|
|
|
switch (stat) {
|
|
|
|
case 0:
|
|
|
|
bp->b_resid = 0;
|
|
|
|
break;
|
|
|
|
case STS_CHECKCOND:
|
1997-01-30 12:14:10 +03:00
|
|
|
scsi_request_sense(sc->sc_dev.dv_parent->dv_unit,
|
|
|
|
sc->sc_target, sc->sc_lun, sensebuf, sizeof sensebuf);
|
1994-05-23 09:58:16 +04:00
|
|
|
sp = (struct scsi_xsense *)sensebuf;
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("%s: acintr sense key=%x, ac=%x, acq=%x\n",
|
1997-01-30 12:14:10 +03:00
|
|
|
sc->sc_dev.dv_xname, sp->key, sp->info4, sp->len);
|
1994-05-23 09:58:16 +04:00
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = EIO;
|
|
|
|
break;
|
|
|
|
default:
|
1997-01-30 12:14:10 +03:00
|
|
|
printf("%s: acintr unknown status 0x%x\n", sc->sc_dev.dv_xname,
|
1995-12-02 21:21:49 +03:00
|
|
|
stat);
|
1994-05-23 09:58:16 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
(void) biodone(sc->sc_bp);
|
1997-01-30 12:14:10 +03:00
|
|
|
scsifree(sc->sc_dev.dv_parent, &sc->sc_sq);
|
1994-05-23 09:58:16 +04:00
|
|
|
}
|
|
|
|
|
1997-03-31 11:32:14 +04:00
|
|
|
int
|
1994-05-23 09:58:16 +04:00
|
|
|
acgeteinfo(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
1997-01-30 12:14:10 +03:00
|
|
|
struct ac_softc *sc = ac_cd.cd_devs[minor(dev)];
|
1997-03-31 11:32:14 +04:00
|
|
|
char *bp;
|
1994-05-23 09:58:16 +04:00
|
|
|
char msbuf[48];
|
|
|
|
int error;
|
|
|
|
|
|
|
|
bzero(msbuf, sizeof msbuf);
|
|
|
|
error = accommand(dev, ACCMD_MODESENSE, msbuf, sizeof msbuf);
|
|
|
|
if (error)
|
|
|
|
return(error);
|
|
|
|
bp = &msbuf[4];
|
|
|
|
while (bp < &msbuf[48]) {
|
|
|
|
switch (bp[0] & 0x3F) {
|
|
|
|
case 0x1D:
|
|
|
|
sc->sc_einfo = *(struct acinfo *)&bp[2];
|
|
|
|
sc->sc_picker = sc->sc_einfo.fmte; /* XXX */
|
|
|
|
return(0);
|
|
|
|
case 0x1E:
|
|
|
|
bp += 4;
|
|
|
|
break;
|
|
|
|
case 0x1F:
|
|
|
|
bp += 20;
|
|
|
|
break;
|
|
|
|
default:
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("acgeteinfo: bad page type %x\n", bp[0]);
|
1994-05-23 09:58:16 +04:00
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
1997-03-31 11:32:14 +04:00
|
|
|
void
|
1994-05-23 09:58:16 +04:00
|
|
|
acconvert(sbuf, dbuf, ne)
|
|
|
|
char *sbuf, *dbuf;
|
|
|
|
int ne;
|
|
|
|
{
|
1997-03-31 11:32:14 +04:00
|
|
|
struct aceltstat *ep = (struct aceltstat *)dbuf;
|
|
|
|
struct ac_restatphdr *phdr;
|
|
|
|
struct ac_restatdb *dbp;
|
1994-05-23 09:58:16 +04:00
|
|
|
struct ac_restathdr *hdr;
|
|
|
|
#ifdef DEBUG
|
1997-03-31 11:32:14 +04:00
|
|
|
int bcount;
|
1994-05-23 09:58:16 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
hdr = (struct ac_restathdr *)&sbuf[0];
|
|
|
|
sbuf += sizeof *hdr;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ac_debug & ACD_FOLLOW)
|
1997-04-03 02:37:21 +04:00
|
|
|
printf("element status: first=%d, num=%d, len=%ld\n",
|
1994-05-23 09:58:16 +04:00
|
|
|
hdr->ac_felt, hdr->ac_nelt, hdr->ac_bcount);
|
|
|
|
if (hdr->ac_nelt != ne) {
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("acconvert: # of elements, %d != %d\n",
|
1994-05-23 09:58:16 +04:00
|
|
|
hdr->ac_nelt, ne);
|
|
|
|
if (hdr->ac_nelt < ne)
|
|
|
|
ne = hdr->ac_nelt;
|
|
|
|
}
|
|
|
|
bcount = hdr->ac_bcount;
|
|
|
|
#endif
|
|
|
|
while (ne) {
|
|
|
|
phdr = (struct ac_restatphdr *)sbuf;
|
|
|
|
sbuf += sizeof *phdr;
|
|
|
|
#ifdef DEBUG
|
|
|
|
bcount -= sizeof *phdr;
|
|
|
|
#endif
|
|
|
|
dbp = (struct ac_restatdb *)sbuf;
|
|
|
|
sbuf += phdr->ac_bcount;
|
|
|
|
#ifdef DEBUG
|
|
|
|
bcount -= phdr->ac_bcount;
|
|
|
|
#endif
|
|
|
|
while (dbp < (struct ac_restatdb *)sbuf) {
|
|
|
|
ep->type = phdr->ac_type;
|
|
|
|
ep->eaddr = dbp->ac_eaddr;
|
|
|
|
ep->flags = 0;
|
|
|
|
if (dbp->ac_full)
|
|
|
|
ep->flags |= AC_FULL;
|
|
|
|
if (dbp->ac_exc)
|
|
|
|
ep->flags |= AC_ERROR;
|
|
|
|
if (dbp->ac_acc)
|
|
|
|
ep->flags |= AC_ACCESS;
|
|
|
|
dbp = (struct ac_restatdb *)
|
|
|
|
((char *)dbp + phdr->ac_dlen);
|
|
|
|
ep++;
|
|
|
|
ne--;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ne < 0 || bcount < 0)
|
|
|
|
panic("acconvert: inconsistant");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|