1995-05-30 08:16:23 +00:00
|
|
|
/*
|
1995-11-29 10:49:16 +00:00
|
|
|
* Written by grefen@convex.com (probably moved by now)
|
1993-11-18 05:03:27 +00:00
|
|
|
* Based on scsi drivers by Julian Elischer (julian@tfs.com)
|
1993-08-20 09:23:30 +00:00
|
|
|
*
|
1997-01-14 07:20:47 +00:00
|
|
|
* $FreeBSD$
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <ch.h>
|
1996-07-14 10:46:56 +00:00
|
|
|
#include "opt_scsi.h"
|
1993-06-12 14:58:17 +00: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/chio.h>
|
1994-10-21 01:19:28 +00:00
|
|
|
#include <sys/malloc.h>
|
1995-11-29 10:49:16 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#ifdef DEVFS
|
|
|
|
#include <sys/devfsext.h>
|
|
|
|
#endif /*DEVFS*/
|
1995-12-08 11:19:42 +00:00
|
|
|
|
|
|
|
#include <scsi/scsi_all.h>
|
|
|
|
#include <scsi/scsi_changer.h>
|
|
|
|
#include <scsi/scsiconf.h>
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
#define CHRETRIES 2
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-05-03 18:09:20 +00:00
|
|
|
#define CHUNIT(DEV) ((minor(DEV)&0xF0) >> 4) /* 4 bit unit. */
|
|
|
|
#define CHSETUNIT(DEV, U) makedev(major(DEV), ((U) << 4))
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
#define MODE(z) ( (minor(z) & 0x0F) )
|
|
|
|
|
|
|
|
#define ESUCCESS 0
|
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data {
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t flags;
|
|
|
|
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 opertaions */
|
|
|
|
u_int16_t lsterr; /* details of lasterror */
|
|
|
|
u_char stor; /* posible Storage locations */
|
1995-12-08 11:19:42 +00:00
|
|
|
#ifdef DEVFS
|
1996-03-27 18:50:10 +00:00
|
|
|
void *c_devfs_token;
|
|
|
|
void *ctl_devfs_token;
|
1995-12-08 11:19:42 +00:00
|
|
|
#endif
|
1995-03-01 22:24:47 +00:00
|
|
|
};
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1996-03-10 07:13:15 +00:00
|
|
|
static errval ch_getelem __P((u_int32_t unit, short *stat, int type, u_int32_t from,
|
|
|
|
void *data, u_int32_t flags));
|
|
|
|
static errval ch_move __P((u_int32_t unit, short *stat, u_int32_t chm, u_int32_t from,
|
|
|
|
u_int32_t to, u_int32_t flags));
|
|
|
|
static errval ch_mode_sense __P((u_int32_t unit, u_int32_t flags));
|
|
|
|
static errval ch_position __P((u_int32_t unit, short *stat, u_int32_t chm,
|
|
|
|
u_int32_t to, u_int32_t flags));
|
1995-12-14 19:51:15 +00:00
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
static int chunit(dev_t dev) { return CHUNIT(dev); }
|
|
|
|
static dev_t chsetunit(dev_t dev, int unit) { return CHSETUNIT(dev, unit); }
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-12-14 09:55:16 +00:00
|
|
|
static errval ch_open(dev_t dev, int flags, int fmt, struct proc *p,
|
1995-12-14 19:51:15 +00:00
|
|
|
struct scsi_link *sc_link);
|
1995-12-14 09:55:16 +00:00
|
|
|
static errval ch_ioctl(dev_t dev, int cmd, caddr_t addr, int flag,
|
1995-12-14 19:51:15 +00:00
|
|
|
struct proc *p, struct scsi_link *sc_link);
|
1995-12-14 09:55:16 +00:00
|
|
|
static errval ch_close(dev_t dev, int flag, int fmt, struct proc *p,
|
1995-12-14 19:51:15 +00:00
|
|
|
struct scsi_link *sc_link);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static d_open_t chopen;
|
|
|
|
static d_close_t chclose;
|
|
|
|
static d_ioctl_t chioctl;
|
|
|
|
|
|
|
|
#define CDEV_MAJOR 17
|
1995-12-08 23:23:00 +00:00
|
|
|
static struct cdevsw ch_cdevsw =
|
1995-12-08 11:19:42 +00:00
|
|
|
{ chopen, chclose, noread, nowrite, /*17*/
|
|
|
|
chioctl, nostop, nullreset, nodevtotty,/* ch */
|
|
|
|
noselect, nommap, nostrat, "ch", NULL, -1 };
|
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
SCSI_DEVICE_ENTRIES(ch)
|
|
|
|
|
1995-12-14 09:55:16 +00:00
|
|
|
static struct scsi_device ch_switch =
|
1994-10-19 00:09:47 +00:00
|
|
|
{
|
1995-03-01 22:24:47 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
"ch",
|
|
|
|
0,
|
|
|
|
{0, 0},
|
|
|
|
0, /* Link flags */
|
|
|
|
chattach,
|
1995-03-04 20:51:10 +00:00
|
|
|
"Medium-Changer",
|
1995-03-01 22:24:47 +00:00
|
|
|
chopen,
|
|
|
|
sizeof(struct scsi_data),
|
|
|
|
T_CHANGER,
|
|
|
|
chunit,
|
|
|
|
chsetunit,
|
|
|
|
ch_open,
|
|
|
|
ch_ioctl,
|
|
|
|
ch_close,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CH_OPEN 0x01
|
1994-10-19 00:09:47 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* The routine called by the low level scsi routine when it discovers
|
|
|
|
* a device suitable for this driver.
|
|
|
|
*/
|
1995-12-14 19:51:15 +00:00
|
|
|
static errval
|
1995-03-01 22:24:47 +00:00
|
|
|
chattach(struct scsi_link *sc_link)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *ch = sc_link->sd;
|
|
|
|
|
|
|
|
unit = sc_link->dev_unit;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use the subdriver to request information regarding
|
|
|
|
* the drive. We cannot use interrupts yet, so the
|
|
|
|
* request must specify this.
|
|
|
|
*/
|
|
|
|
if ((ch_mode_sense(unit, SCSI_NOSLEEP | SCSI_NOMASK /*| SCSI_SILENT */ ))) {
|
1995-03-15 14:22:12 +00:00
|
|
|
printf("offline");
|
1993-11-18 05:03:27 +00:00
|
|
|
} else {
|
1995-03-15 14:22:12 +00:00
|
|
|
printf("%d slot(s) %d drive(s) %d arm(s) %d i/e-slot(s)",
|
1995-03-01 22:24:47 +00:00
|
|
|
ch->slots, ch->drives, ch->chms, ch->imexs);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
#ifdef DEVFS
|
1996-03-27 18:50:10 +00:00
|
|
|
ch->c_devfs_token = devfs_add_devswf(&ch_cdevsw, unit << 4, DV_CHR,
|
|
|
|
UID_ROOT, GID_OPERATOR, 0600,
|
|
|
|
"ch%d", unit);
|
|
|
|
ch->ctl_devfs_token = devfs_add_devswf(&ch_cdevsw,
|
|
|
|
(unit << 4) | SCSI_CONTROL_MASK,
|
|
|
|
DV_CHR,
|
|
|
|
UID_ROOT, GID_OPERATOR, 0600,
|
|
|
|
"ch%d.ctl", unit);
|
1995-12-08 11:19:42 +00:00
|
|
|
#endif
|
1995-03-01 22:24:47 +00:00
|
|
|
return 0;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* open the device.
|
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
static errval
|
1995-03-04 20:51:10 +00:00
|
|
|
ch_open(dev_t dev, int flags, int fmt, struct proc *p,
|
1995-12-14 19:51:15 +00:00
|
|
|
struct scsi_link *sc_link)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
errval errcode = 0;
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, mode;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *cd;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-01-08 13:38:38 +00:00
|
|
|
unit = CHUNIT(dev);
|
1993-06-12 14:58:17 +00:00
|
|
|
mode = MODE(dev);
|
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
cd = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Only allow one at a time
|
|
|
|
*/
|
1995-03-01 22:24:47 +00:00
|
|
|
if (cd->flags & CH_OPEN) {
|
1995-04-14 15:10:44 +00:00
|
|
|
printf("ch%ld: already open\n", unit);
|
1994-01-29 10:30:41 +00:00
|
|
|
return EBUSY;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Catch any unit attention errors.
|
|
|
|
*/
|
|
|
|
scsi_test_unit_ready(sc_link, SCSI_SILENT);
|
|
|
|
|
|
|
|
sc_link->flags |= SDEV_OPEN;
|
|
|
|
/*
|
|
|
|
* Check that it is still responding and ok.
|
|
|
|
*/
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errcode = (scsi_test_unit_ready(sc_link, 0))) ) {
|
|
|
|
printf("ch%ld: not ready\n", unit);
|
1993-11-18 05:03:27 +00:00
|
|
|
sc_link->flags &= ~SDEV_OPEN;
|
|
|
|
return errcode;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Make sure data is loaded
|
|
|
|
*/
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errcode = (ch_mode_sense(unit, SCSI_NOSLEEP | SCSI_NOMASK))) ) {
|
1995-05-11 19:26:53 +00:00
|
|
|
printf("ch%ld: scsi changer :- offline\n", unit);
|
1993-11-18 05:03:27 +00:00
|
|
|
sc_link->flags &= ~SDEV_OPEN;
|
|
|
|
return (errcode);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1995-03-01 22:24:47 +00:00
|
|
|
cd->flags = CH_OPEN;
|
1993-11-18 05:03:27 +00:00
|
|
|
return 0;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* close the device.. only called if we are the LAST
|
|
|
|
* occurence of an open device
|
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
static errval
|
1995-03-04 20:51:10 +00:00
|
|
|
ch_close(dev_t dev, int flag, int fmt, struct proc *p,
|
|
|
|
struct scsi_link *sc_link)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1995-03-01 22:24:47 +00:00
|
|
|
sc_link->sd->flags = 0;
|
1993-11-18 05:03:27 +00:00
|
|
|
sc_link->flags &= ~SDEV_OPEN;
|
|
|
|
return (0);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Perform special action on behalf of the user
|
|
|
|
* Knows about the internals of this device
|
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
static errval
|
1995-12-14 19:51:15 +00:00
|
|
|
ch_ioctl(dev_t dev, int cmd, caddr_t arg, int mode, struct proc *p,
|
|
|
|
struct scsi_link *sc_link)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
/* struct ch_cmd_buf *args; */
|
1993-06-12 14:58:17 +00:00
|
|
|
unsigned char unit;
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t flags;
|
1993-11-18 05:03:27 +00:00
|
|
|
errval ret;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *cd;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the device that the user is talking about
|
|
|
|
*/
|
|
|
|
flags = 0; /* give error messages, act on errors etc. */
|
1995-01-08 13:38:38 +00:00
|
|
|
unit = CHUNIT(dev);
|
1995-03-01 22:24:47 +00:00
|
|
|
cd = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
1993-12-19 00:55:01 +00:00
|
|
|
switch ((int)cmd) {
|
1993-11-18 05:03:27 +00:00
|
|
|
case CHIOOP:{
|
|
|
|
struct chop *ch = (struct chop *) arg;
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB2,
|
|
|
|
("[chtape_chop: %x]\n", ch->ch_op));
|
|
|
|
|
|
|
|
switch ((short) (ch->ch_op)) {
|
|
|
|
case CHGETPARAM:
|
1995-03-01 22:24:47 +00:00
|
|
|
ch->u.getparam.chmo = cd->chmo;
|
|
|
|
ch->u.getparam.chms = cd->chms;
|
|
|
|
ch->u.getparam.sloto = cd->sloto;
|
|
|
|
ch->u.getparam.slots = cd->slots;
|
|
|
|
ch->u.getparam.imexo = cd->imexo;
|
|
|
|
ch->u.getparam.imexs = cd->imexs;
|
|
|
|
ch->u.getparam.driveo = cd->driveo;
|
|
|
|
ch->u.getparam.drives = cd->drives;
|
|
|
|
ch->u.getparam.rot = cd->rot;
|
1993-11-18 05:03:27 +00:00
|
|
|
ch->result = 0;
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case CHPOSITION:
|
|
|
|
return ch_position(unit, &ch->result, ch->u.position.chm,
|
|
|
|
ch->u.position.to,
|
|
|
|
flags);
|
|
|
|
case CHMOVE:
|
|
|
|
return ch_move(unit, &ch->result, ch->u.position.chm,
|
|
|
|
ch->u.move.from, ch->u.move.to,
|
|
|
|
flags);
|
|
|
|
case CHGETELEM:
|
|
|
|
return ch_getelem(unit, &ch->result, ch->u.get_elem_stat.type,
|
|
|
|
ch->u.get_elem_stat.from, &ch->u.get_elem_stat.elem_data,
|
|
|
|
flags);
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
default:
|
1995-03-04 20:51:10 +00:00
|
|
|
return scsi_do_ioctl(dev, cmd, arg, mode, p, sc_link);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
return (ret ? ESUCCESS : EIO);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
1995-12-14 09:55:16 +00:00
|
|
|
static errval
|
1993-11-18 05:03:27 +00:00
|
|
|
ch_getelem(unit, stat, type, from, data, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, from, flags;
|
1993-11-25 01:38:01 +00:00
|
|
|
int type;
|
1993-11-18 05:03:27 +00:00
|
|
|
short *stat;
|
1995-03-28 07:58:53 +00:00
|
|
|
void *data; /* XXX `struct untagged *' - see chio.h */
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
struct scsi_read_element_status scsi_cmd;
|
1993-11-18 05:03:27 +00:00
|
|
|
char elbuf[32];
|
|
|
|
errval ret;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link;
|
|
|
|
|
|
|
|
if ((sc_link = SCSI_LINK(&ch_switch, unit)) == 0)
|
|
|
|
return ENXIO;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
|
|
|
scsi_cmd.op_code = READ_ELEMENT_STATUS;
|
1993-08-20 09:23:30 +00:00
|
|
|
scsi_cmd.byte2 = type;
|
1993-11-18 05:03:27 +00:00
|
|
|
scsi_cmd.starting_element_addr[0] = (from >> 8) & 0xff;
|
|
|
|
scsi_cmd.starting_element_addr[1] = from & 0xff;
|
|
|
|
scsi_cmd.number_of_elements[1] = 1;
|
|
|
|
scsi_cmd.allocation_length[2] = 32;
|
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
if ((ret = scsi_scsi_cmd(sc_link,
|
1993-11-18 05:03:27 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd),
|
|
|
|
(u_char *) elbuf,
|
|
|
|
32,
|
|
|
|
CHRETRIES,
|
|
|
|
100000,
|
|
|
|
NULL,
|
|
|
|
SCSI_DATA_IN | flags) != ESUCCESS)) {
|
1995-03-01 22:24:47 +00:00
|
|
|
*stat = sc_link->sd->lsterr;
|
1993-11-18 05:03:27 +00:00
|
|
|
bcopy(elbuf + 16, data, 16);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
bcopy(elbuf + 16, data, 16); /*Just a hack sh */
|
1993-06-12 14:58:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1995-12-14 09:55:16 +00:00
|
|
|
static errval
|
1993-11-18 05:03:27 +00:00
|
|
|
ch_move(unit, stat, chm, from, to, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, chm, from, to, flags;
|
1993-11-18 05:03:27 +00:00
|
|
|
short *stat;
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
struct scsi_move_medium scsi_cmd;
|
1993-11-18 05:03:27 +00:00
|
|
|
errval ret;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link;
|
|
|
|
|
|
|
|
if ((sc_link = SCSI_LINK(&ch_switch, unit)) == 0)
|
|
|
|
return ENXIO;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
|
|
|
scsi_cmd.op_code = MOVE_MEDIUM;
|
1993-11-18 05:03:27 +00:00
|
|
|
scsi_cmd.transport_element_address[0] = (chm >> 8) & 0xff;
|
|
|
|
scsi_cmd.transport_element_address[1] = chm & 0xff;
|
|
|
|
scsi_cmd.source_address[0] = (from >> 8) & 0xff;
|
|
|
|
scsi_cmd.source_address[1] = from & 0xff;
|
|
|
|
scsi_cmd.destination_address[0] = (to >> 8) & 0xff;
|
|
|
|
scsi_cmd.destination_address[1] = to & 0xff;
|
|
|
|
scsi_cmd.invert = (chm & CH_INVERT) ? 1 : 0;
|
1995-03-01 22:24:47 +00:00
|
|
|
if ((ret = scsi_scsi_cmd(sc_link,
|
1993-11-18 05:03:27 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd),
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
CHRETRIES,
|
|
|
|
100000,
|
|
|
|
NULL,
|
|
|
|
flags) != ESUCCESS)) {
|
1995-03-01 22:24:47 +00:00
|
|
|
*stat = sc_link->sd->lsterr;
|
1993-11-18 05:03:27 +00:00
|
|
|
return ret;
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1995-12-14 09:55:16 +00:00
|
|
|
static errval
|
1993-11-18 05:03:27 +00:00
|
|
|
ch_position(unit, stat, chm, to, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, chm, to, flags;
|
1993-11-18 05:03:27 +00:00
|
|
|
short *stat;
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
struct scsi_position_to_element scsi_cmd;
|
1993-11-18 05:03:27 +00:00
|
|
|
errval ret;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link;
|
|
|
|
|
|
|
|
if ((sc_link = SCSI_LINK(&ch_switch, unit)) == 0)
|
|
|
|
return ENXIO;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
|
|
|
scsi_cmd.op_code = POSITION_TO_ELEMENT;
|
1993-11-18 05:03:27 +00:00
|
|
|
scsi_cmd.transport_element_address[0] = (chm >> 8) & 0xff;
|
|
|
|
scsi_cmd.transport_element_address[1] = chm & 0xff;
|
|
|
|
scsi_cmd.source_address[0] = (to >> 8) & 0xff;
|
|
|
|
scsi_cmd.source_address[1] = to & 0xff;
|
|
|
|
scsi_cmd.invert = (chm & CH_INVERT) ? 1 : 0;
|
1995-03-01 22:24:47 +00:00
|
|
|
if ((ret = scsi_scsi_cmd(sc_link,
|
1993-11-18 05:03:27 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd),
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
CHRETRIES,
|
|
|
|
100000,
|
|
|
|
NULL,
|
|
|
|
flags) != ESUCCESS)) {
|
1995-03-01 22:24:47 +00:00
|
|
|
*stat = sc_link->sd->lsterr;
|
1993-11-18 05:03:27 +00:00
|
|
|
return ret;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
return ret;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __STDC__
|
|
|
|
#define b2tol(a) (((unsigned)(a##_1) << 8) + (unsigned)a##_0 )
|
|
|
|
#else
|
|
|
|
#define b2tol(a) (((unsigned)(a/**/_1) << 8) + (unsigned)a/**/_0 )
|
|
|
|
#endif
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Get the scsi driver to send a full inquiry to the
|
1995-05-30 08:16:23 +00:00
|
|
|
* device and use the results to fill out the global
|
1993-11-18 05:03:27 +00:00
|
|
|
* parameter structure.
|
|
|
|
*/
|
1995-05-30 08:16:23 +00:00
|
|
|
static errval
|
1993-06-12 14:58:17 +00:00
|
|
|
ch_mode_sense(unit, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, flags;
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
struct scsi_mode_sense scsi_cmd;
|
1993-11-18 05:03:27 +00:00
|
|
|
u_char scsi_sense[128]; /* Can't use scsi_mode_sense_data because of
|
|
|
|
* missing block descriptor
|
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
u_char *b;
|
1996-03-10 18:17:54 +00:00
|
|
|
int32_t i, l;
|
1993-11-18 05:03:27 +00:00
|
|
|
errval errcode;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *cd;
|
|
|
|
struct scsi_link *sc_link;
|
|
|
|
|
|
|
|
if ((sc_link = SCSI_LINK(&ch_switch, unit)) == 0)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
cd = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First check if we have it all loaded
|
|
|
|
*/
|
|
|
|
if (sc_link->flags & SDEV_MEDIA_LOADED)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
1995-05-30 08:16:23 +00:00
|
|
|
* First do a mode sense
|
1993-11-18 05:03:27 +00:00
|
|
|
*/
|
|
|
|
/* sc_link->flags &= ~SDEV_MEDIA_LOADED; *//*XXX */
|
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
|
|
|
scsi_cmd.op_code = MODE_SENSE;
|
|
|
|
scsi_cmd.byte2 = SMS_DBD;
|
|
|
|
scsi_cmd.page = 0x3f; /* All Pages */
|
|
|
|
scsi_cmd.length = sizeof(scsi_sense);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read in the pages
|
|
|
|
*/
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errcode = scsi_scsi_cmd(sc_link,
|
1993-11-18 05:03:27 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(struct scsi_mode_sense),
|
|
|
|
(u_char *) & scsi_sense,
|
|
|
|
sizeof (scsi_sense),
|
|
|
|
CHRETRIES,
|
|
|
|
5000,
|
|
|
|
NULL,
|
1995-04-14 15:10:44 +00:00
|
|
|
flags | SCSI_DATA_IN) != 0) ) {
|
1993-11-18 05:03:27 +00:00
|
|
|
if (!(flags & SCSI_SILENT))
|
1995-04-14 15:10:44 +00:00
|
|
|
printf("ch%ld: could not mode sense\n", unit);
|
1993-11-18 05:03:27 +00:00
|
|
|
return (errcode);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
sc_link->flags |= SDEV_MEDIA_LOADED;
|
|
|
|
l = scsi_sense[0] - 3;
|
|
|
|
b = &scsi_sense[4];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To avoid alignment problems
|
|
|
|
*/
|
|
|
|
/* XXX - FIX THIS FOR MSB */
|
1993-06-12 14:58:17 +00:00
|
|
|
#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
|
|
|
|
#if 0
|
1993-11-18 05:03:27 +00:00
|
|
|
printf("\nmode_sense %d\n", l);
|
|
|
|
for (i = 0; i < l + 4; i++) {
|
|
|
|
printf("%x%c", scsi_sense[i], i % 8 == 7 ? '\n' : ':');
|
|
|
|
} printf("\n");
|
1993-06-12 14:58:17 +00:00
|
|
|
#endif
|
1993-11-18 05:03:27 +00:00
|
|
|
for (i = 0; i < l;) {
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t pc = (*b++) & 0x3f;
|
|
|
|
u_int32_t pl = *b++;
|
1993-11-18 05:03:27 +00:00
|
|
|
u_char *bb = b;
|
1993-12-19 00:55:01 +00:00
|
|
|
switch ((int)pc) {
|
1993-11-18 05:03:27 +00:00
|
|
|
case 0x1d:
|
1995-03-01 22:24:47 +00:00
|
|
|
cd->chmo = p2copy(bb);
|
|
|
|
cd->chms = p2copy(bb);
|
|
|
|
cd->sloto = p2copy(bb);
|
|
|
|
cd->slots = p2copy(bb);
|
|
|
|
cd->imexo = p2copy(bb);
|
|
|
|
cd->imexs = p2copy(bb);
|
|
|
|
cd->driveo = p2copy(bb);
|
|
|
|
cd->drives = p2copy(bb);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
case 0x1e:
|
1995-03-01 22:24:47 +00:00
|
|
|
cd->rot = (*b) & 1;
|
1993-11-18 05:03:27 +00:00
|
|
|
break;
|
|
|
|
case 0x1f:
|
1995-03-01 22:24:47 +00:00
|
|
|
cd->stor = *b & 0xf;
|
1993-11-18 05:03:27 +00:00
|
|
|
bb += 2;
|
1995-03-01 22:24:47 +00:00
|
|
|
cd->stor = p4copy(bb);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
1993-11-18 05:03:27 +00:00
|
|
|
break;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
b += pl;
|
|
|
|
i += pl + 2;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB2,
|
|
|
|
(" cht(%d-%d)slot(%d-%d)imex(%d-%d)cts(%d-%d) %s rotate\n",
|
1995-03-01 22:24:47 +00:00
|
|
|
cd->chmo, cd->chms,
|
|
|
|
cd->sloto, cd->slots,
|
|
|
|
cd->imexo, cd->imexs,
|
|
|
|
cd->driveo, cd->drives,
|
|
|
|
cd->rot ? "can" : "can't"));
|
1993-11-18 05:03:27 +00:00
|
|
|
return (0);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
static ch_devsw_installed = 0;
|
|
|
|
|
|
|
|
static void ch_drvinit(void *unused)
|
|
|
|
{
|
|
|
|
dev_t dev;
|
|
|
|
|
|
|
|
if( ! ch_devsw_installed ) {
|
1995-12-08 11:19:42 +00:00
|
|
|
dev = makedev(CDEV_MAJOR, 0);
|
|
|
|
cdevsw_add(&dev,&ch_cdevsw, NULL);
|
1995-11-29 10:49:16 +00:00
|
|
|
ch_devsw_installed = 1;
|
1995-11-29 14:41:20 +00:00
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(chdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,ch_drvinit,NULL)
|
|
|
|
|
|
|
|
|