1996-03-31 00:44:50 +03:00
|
|
|
/* $NetBSD: ch.c,v 1.19 1996/03/30 21:44:58 christos Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* Copyright (c) 1994 Charles Hannum. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 Charles Hannum.
|
|
|
|
* 4. The name of the author may not 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.
|
1993-03-21 21:04:42 +03:00
|
|
|
*/
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* Originally written by grefen@?????
|
|
|
|
* Based on scsi drivers by Julian Elischer (julian@tfs.com)
|
|
|
|
*/
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1993-12-17 10:56:32 +03:00
|
|
|
#include <sys/types.h>
|
1993-03-21 21:04:42 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/chio.h>
|
1994-03-29 08:29:20 +04:00
|
|
|
#include <sys/device.h>
|
1996-03-31 00:44:50 +03:00
|
|
|
#include <sys/conf.h>
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
#include <scsi/scsi_all.h>
|
|
|
|
#include <scsi/scsi_changer.h>
|
|
|
|
#include <scsi/scsiconf.h>
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
#define CHRETRIES 2
|
|
|
|
|
|
|
|
#define CHMODE(z) (minor(z) & 0x0f)
|
|
|
|
#define CHUNIT(z) (minor(z) >> 4)
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ch_softc {
|
1994-03-29 08:29:20 +04:00
|
|
|
struct device sc_dev;
|
|
|
|
|
|
|
|
struct scsi_link *sc_link; /* all the inter level info */
|
1994-12-28 22:42:47 +03:00
|
|
|
u_int16_t chmo; /* Offset of first CHM */
|
|
|
|
u_int16_t chms; /* No. of CHM */
|
|
|
|
u_int16_t slots; /* No. of Storage Elements */
|
|
|
|
u_int16_t sloto; /* Offset of first SE */
|
|
|
|
u_int16_t imexs; /* No. of Import/Export Slots */
|
|
|
|
u_int16_t imexo; /* Offset of first IM/EX */
|
|
|
|
u_int16_t drives; /* No. of CTS */
|
|
|
|
u_int16_t driveo; /* Offset of first CTS */
|
|
|
|
u_int16_t rot; /* CHM can rotate */
|
|
|
|
u_long op_matrix; /* possible operations */
|
|
|
|
u_int16_t lsterr; /* details of lasterror */
|
1994-03-29 08:29:20 +04:00
|
|
|
u_char stor; /* posible Storage locations */
|
|
|
|
};
|
|
|
|
|
1996-02-15 00:46:52 +03:00
|
|
|
int chmatch __P((struct device *, void *, void *));
|
|
|
|
void chattach __P((struct device *, struct device *, void *));
|
|
|
|
int ch_getelem __P((struct ch_softc *, short *, int, int , char *, int));
|
|
|
|
int ch_move __P((struct ch_softc *, short *, int, int , int , int ));
|
|
|
|
int ch_position __P((struct ch_softc *, short *, int, int , int ));
|
|
|
|
int ch_mode_sense __P((struct ch_softc *, int));
|
1994-03-29 08:29:20 +04:00
|
|
|
|
1996-03-17 03:57:14 +03:00
|
|
|
struct cfattach ch_ca = {
|
|
|
|
sizeof(struct ch_softc), chmatch, chattach
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cfdriver ch_cd = {
|
|
|
|
NULL, "ch", DV_DULL
|
1994-03-29 08:29:20 +04:00
|
|
|
};
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* This driver is so simple it uses all the default services
|
|
|
|
*/
|
|
|
|
struct scsi_device ch_switch = {
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
struct scsi_inquiry_pattern ch_patterns[] = {
|
|
|
|
{T_CHANGER, T_REMOV,
|
|
|
|
"", "", ""},
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
chmatch(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
void *match, *aux;
|
|
|
|
{
|
|
|
|
struct scsibus_attach_args *sa = aux;
|
|
|
|
int priority;
|
|
|
|
|
|
|
|
(void)scsi_inqmatch(sa->sa_inqbuf,
|
|
|
|
(caddr_t)ch_patterns, sizeof(ch_patterns)/sizeof(ch_patterns[0]),
|
|
|
|
sizeof(ch_patterns[0]), &priority);
|
|
|
|
return (priority);
|
|
|
|
}
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* The routine called by the low level scsi routine when it discovers
|
|
|
|
* a device suitable for this driver.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
chattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ch_softc *ch = (void *)self;
|
|
|
|
struct scsibus_attach_args *sa = aux;
|
|
|
|
struct scsi_link *sc_link = sa->sa_sc_link;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB2, ("chattach: "));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store information needed to contact our base driver
|
|
|
|
*/
|
|
|
|
ch->sc_link = sc_link;
|
|
|
|
sc_link->device = &ch_switch;
|
1994-11-21 13:39:09 +03:00
|
|
|
sc_link->device_softc = ch;
|
1994-12-28 22:42:47 +03:00
|
|
|
sc_link->openings = 1;
|
1994-03-29 08:29:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use the subdriver to request information regarding
|
|
|
|
* the drive. We cannot use interrupts yet, so the
|
|
|
|
* request must specify this.
|
|
|
|
*/
|
1996-03-05 03:15:09 +03:00
|
|
|
printf("\n");
|
|
|
|
printf("%s: ", ch->sc_dev.dv_xname);
|
1994-12-28 22:42:47 +03:00
|
|
|
if (ch_mode_sense(ch, SCSI_AUTOCONF) != 0)
|
1996-03-05 03:15:09 +03:00
|
|
|
printf("offline\n");
|
1994-04-11 07:53:58 +04:00
|
|
|
else
|
1996-03-05 03:15:09 +03:00
|
|
|
printf("%d slot(s), %d drive(s), %d arm(s), %d i/e-slot(s)\n",
|
1994-03-29 08:29:20 +04:00
|
|
|
ch->slots, ch->drives, ch->chms, ch->imexs);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* open the device.
|
|
|
|
*/
|
|
|
|
int
|
1996-02-15 00:46:52 +03:00
|
|
|
chopen(dev, flags, mode, p)
|
1994-03-29 08:29:20 +04:00
|
|
|
dev_t dev;
|
1996-02-15 00:46:52 +03:00
|
|
|
int flags;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:29:20 +04:00
|
|
|
int error = 0;
|
1996-02-15 00:46:52 +03:00
|
|
|
int unit;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ch_softc *ch;
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_link *sc_link;
|
|
|
|
|
|
|
|
unit = CHUNIT(dev);
|
1996-03-17 03:57:14 +03:00
|
|
|
if (unit >= ch_cd.cd_ndevs)
|
1994-03-29 08:29:20 +04:00
|
|
|
return ENXIO;
|
1996-03-17 03:57:14 +03:00
|
|
|
ch = ch_cd.cd_devs[unit];
|
1994-04-11 07:53:58 +04:00
|
|
|
if (!ch)
|
1994-03-29 08:29:20 +04:00
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
sc_link = ch->sc_link;
|
|
|
|
|
1994-11-21 14:28:47 +03:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB1,
|
1996-03-17 03:57:14 +03:00
|
|
|
("chopen: dev=0x%x (unit %d (of %d))\n", dev, unit, ch_cd.cd_ndevs));
|
1994-11-21 14:28:47 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Only allow one at a time
|
|
|
|
*/
|
|
|
|
if (sc_link->flags & SDEV_OPEN) {
|
|
|
|
printf("%s: already open\n", ch->sc_dev.dv_xname);
|
1994-03-29 08:29:20 +04:00
|
|
|
return EBUSY;
|
1994-11-21 14:28:47 +03:00
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Catch any unit attention errors.
|
|
|
|
*/
|
1996-02-15 00:46:52 +03:00
|
|
|
error = scsi_test_unit_ready(sc_link, SCSI_IGNORE_MEDIA_CHANGE);
|
|
|
|
if (error)
|
1994-11-21 14:28:47 +03:00
|
|
|
goto bad;
|
1994-12-28 22:42:47 +03:00
|
|
|
|
|
|
|
sc_link->flags |= SDEV_OPEN; /* unit attn are now errors */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* Make sure data is loaded
|
|
|
|
*/
|
1996-02-15 00:46:52 +03:00
|
|
|
if ((error = ch_mode_sense(ch, 0)) != 0) {
|
1994-03-29 08:29:20 +04:00
|
|
|
printf("%s: offline\n", ch->sc_dev.dv_xname);
|
1994-11-21 14:28:47 +03:00
|
|
|
goto bad;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-11-21 14:28:47 +03:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3, ("open complete\n"));
|
1994-03-29 08:29:20 +04:00
|
|
|
return 0;
|
1994-11-21 14:28:47 +03:00
|
|
|
|
|
|
|
bad:
|
|
|
|
sc_link->flags &= ~SDEV_OPEN;
|
|
|
|
return error;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* close the device.. only called if we are the LAST
|
|
|
|
* occurence of an open device
|
|
|
|
*/
|
|
|
|
int
|
1996-02-15 00:46:52 +03:00
|
|
|
chclose(dev, flags, mode, p)
|
1994-03-29 08:29:20 +04:00
|
|
|
dev_t dev;
|
1996-02-15 00:46:52 +03:00
|
|
|
int flags;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1996-03-17 03:57:14 +03:00
|
|
|
struct ch_softc *ch = ch_cd.cd_devs[CHUNIT(dev)];
|
1994-03-29 08:29:20 +04:00
|
|
|
|
1994-11-21 14:28:47 +03:00
|
|
|
SC_DEBUG(ch->sc_link, SDEV_DB1, ("closing\n"));
|
|
|
|
ch->sc_link->flags &= ~SDEV_OPEN;
|
1994-03-29 08:29:20 +04:00
|
|
|
|
|
|
|
return 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* Perform special action on behalf of the user
|
|
|
|
* Knows about the internals of this device
|
|
|
|
*/
|
|
|
|
int
|
1994-12-28 22:42:47 +03:00
|
|
|
chioctl(dev, cmd, arg, mode, p)
|
1994-03-29 08:29:20 +04:00
|
|
|
dev_t dev;
|
1994-10-31 00:43:03 +03:00
|
|
|
u_long cmd;
|
1994-03-29 08:29:20 +04:00
|
|
|
caddr_t arg;
|
|
|
|
int mode;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct proc *p;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1996-03-17 03:57:14 +03:00
|
|
|
struct ch_softc *ch = ch_cd.cd_devs[CHUNIT(dev)];
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_link *sc_link = ch->sc_link;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1994-03-29 08:29:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the device that the user is talking about
|
|
|
|
*/
|
|
|
|
flags = 0; /* give error messages, act on errors etc. */
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case CHIOOP: {
|
|
|
|
struct chop *chop = (struct chop *) arg;
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB2, ("[chtape_chop: %x]\n",
|
|
|
|
chop->ch_op));
|
|
|
|
|
|
|
|
switch (chop->ch_op) {
|
|
|
|
case CHGETPARAM:
|
|
|
|
chop->u.getparam.chmo = ch->chmo;
|
|
|
|
chop->u.getparam.chms = ch->chms;
|
|
|
|
chop->u.getparam.sloto = ch->sloto;
|
|
|
|
chop->u.getparam.slots = ch->slots;
|
|
|
|
chop->u.getparam.imexo = ch->imexo;
|
|
|
|
chop->u.getparam.imexs = ch->imexs;
|
|
|
|
chop->u.getparam.driveo = ch->driveo;
|
|
|
|
chop->u.getparam.drives = ch->drives;
|
|
|
|
chop->u.getparam.rot = ch->rot;
|
|
|
|
chop->result = 0;
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case CHPOSITION:
|
|
|
|
return ch_position(ch, &chop->result,
|
|
|
|
chop->u.position.chm, chop->u.position.to, flags);
|
|
|
|
case CHMOVE:
|
|
|
|
return ch_move(ch, &chop->result, chop->u.position.chm,
|
|
|
|
chop->u.move.from, chop->u.move.to, flags);
|
|
|
|
case CHGETELEM:
|
|
|
|
return ch_getelem(ch, &chop->result,
|
|
|
|
chop->u.get_elem_stat.type,
|
|
|
|
chop->u.get_elem_stat.from,
|
1996-02-15 00:46:52 +03:00
|
|
|
(char *) &chop->u.get_elem_stat.elem_data, flags);
|
1994-03-29 08:29:20 +04:00
|
|
|
default:
|
|
|
|
return EINVAL;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
default:
|
1994-12-28 22:42:47 +03:00
|
|
|
return scsi_do_ioctl(sc_link, dev, cmd, arg, mode, p);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("chioctl: impossible");
|
|
|
|
#endif
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
int
|
|
|
|
ch_getelem(ch, stat, type, from, data, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ch_softc *ch;
|
1994-03-29 08:29:20 +04:00
|
|
|
short *stat;
|
|
|
|
int type, from;
|
|
|
|
char *data;
|
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
|
|
|
struct scsi_read_element_status scsi_cmd;
|
|
|
|
char elbuf[32];
|
1994-03-29 08:29:20 +04:00
|
|
|
int error;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
1994-12-28 22:42:47 +03:00
|
|
|
scsi_cmd.opcode = READ_ELEMENT_STATUS;
|
1994-03-29 08:29:20 +04:00
|
|
|
scsi_cmd.byte2 = type;
|
1996-03-19 06:05:15 +03:00
|
|
|
_lto2b(from, scsi_cmd.starting_element_addr);
|
1994-03-29 08:29:20 +04:00
|
|
|
scsi_cmd.number_of_elements[1] = 1;
|
|
|
|
scsi_cmd.allocation_length[2] = 32;
|
|
|
|
|
|
|
|
error = scsi_scsi_cmd(ch->sc_link, (struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd), (u_char *) elbuf, 32, CHRETRIES, 100000, NULL,
|
|
|
|
SCSI_DATA_IN | flags);
|
|
|
|
if (error)
|
|
|
|
*stat = ch->lsterr;
|
|
|
|
else
|
|
|
|
*stat = 0;
|
|
|
|
bcopy(elbuf + 16, data, 16);
|
|
|
|
return error;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
int
|
|
|
|
ch_move(ch, stat, chm, from, to, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ch_softc *ch;
|
1994-03-29 08:29:20 +04:00
|
|
|
short *stat;
|
|
|
|
int chm, from, to, flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
|
|
|
struct scsi_move_medium scsi_cmd;
|
1994-03-29 08:29:20 +04:00
|
|
|
int error;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
1994-12-28 22:42:47 +03:00
|
|
|
scsi_cmd.opcode = MOVE_MEDIUM;
|
1996-03-19 06:05:15 +03:00
|
|
|
_lto2b(chm, scsi_cmd.transport_element_address);
|
|
|
|
_lto2b(from, scsi_cmd.source_address);
|
|
|
|
_lto2b(to, scsi_cmd.destination_address);
|
1994-03-29 08:29:20 +04:00
|
|
|
scsi_cmd.invert = (chm & CH_INVERT) ? 1 : 0;
|
|
|
|
error = scsi_scsi_cmd(ch->sc_link, (struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd), NULL, 0, CHRETRIES, 100000, NULL, flags);
|
|
|
|
if (error)
|
|
|
|
*stat = ch->lsterr;
|
|
|
|
else
|
|
|
|
*stat = 0;
|
|
|
|
return error;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
int
|
|
|
|
ch_position(ch, stat, chm, to, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ch_softc *ch;
|
1994-03-29 08:29:20 +04:00
|
|
|
short *stat;
|
|
|
|
int chm, to, flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
|
|
|
struct scsi_position_to_element scsi_cmd;
|
1994-03-29 08:29:20 +04:00
|
|
|
int error;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
1994-12-28 22:42:47 +03:00
|
|
|
scsi_cmd.opcode = POSITION_TO_ELEMENT;
|
1996-03-19 06:05:15 +03:00
|
|
|
_lto2b(chm, scsi_cmd.transport_element_address);
|
|
|
|
_lto2b(to, scsi_cmd.source_address);
|
1994-03-29 08:29:20 +04:00
|
|
|
scsi_cmd.invert = (chm & CH_INVERT) ? 1 : 0;
|
|
|
|
error = scsi_scsi_cmd(ch->sc_link, (struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd), NULL, 0, CHRETRIES, 100000, NULL, flags);
|
|
|
|
if (error)
|
|
|
|
*stat = ch->lsterr;
|
|
|
|
else
|
|
|
|
*stat = 0;
|
|
|
|
return error;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* Get the scsi driver to send a full inquiry to the
|
|
|
|
* device and use the results to fill out the global
|
|
|
|
* parameter structure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ch_mode_sense(ch, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ch_softc *ch;
|
1994-03-29 08:29:20 +04:00
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
|
|
|
struct scsi_mode_sense scsi_cmd;
|
1994-03-29 08:29:20 +04:00
|
|
|
u_char scsi_sense[128]; /* Can't use scsi_mode_sense_data because of
|
|
|
|
* missing block descriptor.
|
|
|
|
*/
|
1993-03-21 21:04:42 +03:00
|
|
|
u_char *b;
|
1994-03-29 08:29:20 +04:00
|
|
|
int i, l;
|
|
|
|
int error;
|
|
|
|
struct scsi_link *sc_link = ch->sc_link;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First check if we have it all loaded
|
|
|
|
*/
|
|
|
|
if (sc_link->flags & SDEV_MEDIA_LOADED)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First do a mode sense
|
|
|
|
*/
|
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
1994-12-28 22:42:47 +03:00
|
|
|
scsi_cmd.opcode = MODE_SENSE;
|
1994-03-29 08:29:20 +04:00
|
|
|
scsi_cmd.byte2 = SMS_DBD;
|
|
|
|
scsi_cmd.page = 0x3f; /* All Pages */
|
|
|
|
scsi_cmd.length = sizeof(scsi_sense);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read in the pages
|
|
|
|
*/
|
1996-02-15 00:46:52 +03:00
|
|
|
error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd), (u_char *) &scsi_sense,
|
|
|
|
sizeof(scsi_sense), CHRETRIES, 5000, NULL,
|
|
|
|
flags | SCSI_DATA_IN);
|
|
|
|
if (error) {
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("%s: could not mode sense\n", ch->sc_dev.dv_xname);
|
1994-03-29 08:29:20 +04:00
|
|
|
return error;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
|
|
|
|
sc_link->flags |= SDEV_MEDIA_LOADED;
|
|
|
|
l = scsi_sense[0] - 3;
|
|
|
|
b = &scsi_sense[4];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To avoid alignment problems
|
|
|
|
*/
|
|
|
|
/* XXXX - FIX THIS FOR MSB */
|
|
|
|
#define p2copy(valp) (valp[1] | (valp[0]<<8)); valp+=2
|
|
|
|
#define p4copy(valp) (valp[3] | (valp[2]<<8) | (valp[1]<<16) | (valp[0]<<24)); valp+=4
|
1993-03-21 21:04:42 +03:00
|
|
|
#if 0
|
1994-03-29 08:29:20 +04:00
|
|
|
printf("\nmode_sense %d\n", l);
|
|
|
|
for (i = 0; i < l + 4; i++)
|
|
|
|
printf("%x%c", scsi_sense[i], i % 8 == 7 ? '\n' : ':');
|
1993-03-21 21:04:42 +03:00
|
|
|
printf("\n");
|
|
|
|
#endif
|
1994-03-29 08:29:20 +04:00
|
|
|
for (i = 0; i < l;) {
|
|
|
|
u_char pc = (*b++) & 0x3f;
|
|
|
|
u_char pl = *b++;
|
|
|
|
u_char *bb = b;
|
|
|
|
switch (pc) {
|
|
|
|
case 0x1d:
|
|
|
|
ch->chmo = p2copy(bb);
|
|
|
|
ch->chms = p2copy(bb);
|
|
|
|
ch->sloto = p2copy(bb);
|
|
|
|
ch->slots = p2copy(bb);
|
|
|
|
ch->imexo = p2copy(bb);
|
|
|
|
ch->imexs = p2copy(bb);
|
|
|
|
ch->driveo = p2copy(bb);
|
|
|
|
ch->drives = p2copy(bb);
|
|
|
|
break;
|
|
|
|
case 0x1e:
|
|
|
|
ch->rot = *b & 0x1;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1994-03-29 08:29:20 +04:00
|
|
|
case 0x1f:
|
|
|
|
ch->stor = *b & 0xf;
|
|
|
|
bb += 2;
|
|
|
|
ch->stor = p4copy(bb);
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
default:
|
1994-03-29 08:29:20 +04:00
|
|
|
break;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
b += pl;
|
|
|
|
i += pl + 2;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB2,
|
|
|
|
(" cht(%d-%d)slot(%d-%d)imex(%d-%d)cts(%d-%d) %s rotate\n",
|
|
|
|
ch->chmo, ch->chms, ch->sloto, ch->slots, ch->imexo, ch->imexs,
|
|
|
|
ch->driveo, ch->drives, ch->rot ? "can" : "can't"));
|
|
|
|
return 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|