1993-06-12 14:58:17 +00:00
|
|
|
/*
|
1993-07-29 11:49:13 +00:00
|
|
|
* Written by Julian Elischer (julian@tfs.com)(now julian@DIALix.oz.au)
|
1993-06-12 14:58:17 +00:00
|
|
|
* for TRW Financial Systems for use under the MACH(2.5) operating system.
|
|
|
|
*
|
|
|
|
* TRW Financial Systems, in accordance with their agreement with Carnegie
|
|
|
|
* Mellon University, makes this software available to CMU to distribute
|
|
|
|
* or use in any manner that they see fit as long as this message is kept with
|
|
|
|
* the software. For this reason TFS also grants any other persons or
|
|
|
|
* organisations permission to use or modify this software.
|
|
|
|
*
|
|
|
|
* TFS supplies this software to be publicly redistributed
|
|
|
|
* on the understanding that TFS is not responsible for the correct
|
|
|
|
* functioning of this software in any circumstances.
|
|
|
|
*
|
1997-02-22 09:48:43 +00:00
|
|
|
* $Id$
|
1993-11-18 05:03:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
|
1993-07-29 11:49:13 +00:00
|
|
|
* major changes by Julian Elischer (julian@jules.dialix.oz.au) May 1993
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To do:
|
|
|
|
* work out some better way of guessing what a good timeout is going
|
|
|
|
* to be depending on whether we expect to retension or not.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1996-01-05 20:12:53 +00:00
|
|
|
#include "opt_bounce.h"
|
1996-07-14 10:46:56 +00:00
|
|
|
#include "opt_scsi.h"
|
1996-01-05 20:12:53 +00:00
|
|
|
|
1994-12-16 06:03:28 +00:00
|
|
|
#include <sys/types.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
|
1994-10-23 21:28:03 +00:00
|
|
|
#include <sys/fcntl.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
1993-08-28 03:08:59 +00:00
|
|
|
#include <sys/malloc.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/mtio.h>
|
1995-12-08 11:19:42 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#ifdef DEVFS
|
|
|
|
#include <sys/devfsext.h>
|
|
|
|
#endif /*DEVFS*/
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
#include <scsi/scsi_all.h>
|
|
|
|
#include <scsi/scsi_tape.h>
|
|
|
|
#include <scsi/scsiconf.h>
|
|
|
|
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1993-07-29 11:49:13 +00:00
|
|
|
/* Defines for device specific stuff */
|
|
|
|
#define PAGE_0_SENSE_DATA_SIZE 12
|
|
|
|
#define DEF_FIXED_BSIZE 512
|
1993-11-18 05:03:27 +00:00
|
|
|
#define ST_RETRIES 4 /* only on non IO commands */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-05-03 18:09:20 +00:00
|
|
|
#define STUNIT(DEV) ((minor(DEV)&0xF0) >> 4) /* 4 bit unit. */
|
|
|
|
#define STSETUNIT(DEV, U) makedev(major(DEV), ((U) << 4))
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
#define MODE(z) ( (minor(z) & 0x03) )
|
|
|
|
#define DSTY(z) ( ((minor(z) >> 2) & 0x03) )
|
1993-11-18 05:03:27 +00:00
|
|
|
#define CTLMODE 3
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-05-03 18:09:20 +00:00
|
|
|
#define IS_CTLMODE(DEV) (MODE(DEV) == CTLMODE)
|
1995-01-08 13:38:38 +00:00
|
|
|
|
1996-03-10 07:13:15 +00:00
|
|
|
static errval st_space __P((u_int32_t unit, int32_t number, u_int32_t what, u_int32_t flags));
|
|
|
|
static errval st_rewind __P((u_int32_t unit, boolean immed, u_int32_t flags));
|
|
|
|
static errval st_erase __P((u_int32_t unit, boolean immed, u_int32_t flags));
|
|
|
|
static errval st_mode_sense __P((u_int32_t unit, u_int32_t flags, \
|
|
|
|
struct tape_pages *page, u_int32_t pagelen, u_int32_t pagecode));
|
|
|
|
static errval st_decide_mode __P((u_int32_t unit, boolean first_read));
|
|
|
|
static errval st_read __P((u_int32_t unit, char *buf, u_int32_t size,
|
|
|
|
u_int32_t flags));
|
|
|
|
static errval st_rd_blk_lim __P((u_int32_t unit, u_int32_t flags));
|
|
|
|
static errval st_touch_tape __P((u_int32_t unit));
|
|
|
|
static errval st_write_filemarks __P((u_int32_t unit, int32_t number, u_int32_t flags));
|
|
|
|
static errval st_load __P((u_int32_t unit, u_int32_t type, u_int32_t flags));
|
|
|
|
static errval st_mode_select __P((u_int32_t unit, u_int32_t flags, \
|
|
|
|
struct tape_pages *page, u_int32_t pagelen));
|
|
|
|
static errval st_comp __P((u_int32_t unit, u_int32_t mode));
|
|
|
|
static int32_t st_chkeod __P((u_int32_t unit, boolean position, int32_t *nmarks,
|
|
|
|
u_int32_t flags));
|
|
|
|
static void ststart(u_int32_t unit, u_int32_t flags);
|
1995-12-10 01:47:34 +00:00
|
|
|
static void st_unmount __P((int unit, boolean eject));
|
1996-03-10 07:13:15 +00:00
|
|
|
static errval st_mount_tape __P((dev_t dev, u_int32_t flags));
|
1995-12-10 01:47:34 +00:00
|
|
|
static void st_loadquirks __P((struct scsi_link *sc_link));
|
|
|
|
static errval st_interpret_sense __P((struct scsi_xfer *xs));
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
#define ESUCCESS 0
|
1993-11-18 05:03:27 +00:00
|
|
|
#define NOEJECT 0
|
|
|
|
#define EJECT 1
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data {
|
1993-07-29 11:49:13 +00:00
|
|
|
/*--------------------present operating parameters, flags etc.----------------*/
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t flags; /* see below */
|
|
|
|
u_int32_t blksiz; /* blksiz we are using */
|
|
|
|
u_int32_t density; /* present density */
|
|
|
|
u_int32_t comp; /* present compression mode */
|
|
|
|
u_int32_t quirks; /* quirks for the open mode */
|
|
|
|
u_int32_t last_dsty; /* last density openned */
|
1993-07-29 11:49:13 +00:00
|
|
|
/*--------------------parameters reported by the device ----------------------*/
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t blkmin; /* min blk size */
|
|
|
|
u_int32_t blkmax; /* max blk size */
|
1993-07-29 11:49:13 +00:00
|
|
|
/*--------------------parameters reported by the device for this media--------*/
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t numblks; /* nominal blocks capacity */
|
|
|
|
u_int32_t media_blksiz; /* 0 if not ST_FIXEDBLOCKS */
|
|
|
|
u_int32_t media_density; /* this is what it said when asked */
|
1993-07-29 11:49:13 +00:00
|
|
|
/*--------------------quirks for the whole drive------------------------------*/
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t drive_quirks; /* quirks of this drive */
|
1993-07-29 11:49:13 +00:00
|
|
|
/*--------------------How we should set up when openning each minor device----*/
|
1994-09-28 20:16:45 +00:00
|
|
|
st_modes modes; /* plus more for each mode */
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int8_t modeflags[4]; /* flags for the modes */
|
1993-11-18 05:03:27 +00:00
|
|
|
#define DENSITY_SET_BY_USER 0x01
|
|
|
|
#define DENSITY_SET_BY_QUIRK 0x02
|
|
|
|
#define BLKSIZE_SET_BY_USER 0x04
|
|
|
|
#define BLKSIZE_SET_BY_QUIRK 0x08
|
1995-03-21 11:21:08 +00:00
|
|
|
#define COMPRES_SET_BY_USER 0x10
|
|
|
|
#define COMPRES_SET_BY_QUIRK 0x20
|
1993-07-29 11:49:13 +00:00
|
|
|
/*--------------------storage for sense data returned by the drive------------*/
|
1995-03-21 11:21:08 +00:00
|
|
|
unsigned char saved_page0[PAGE_0_SENSE_DATA_SIZE]; /*
|
1993-11-18 05:03:27 +00:00
|
|
|
* additional sense data needed
|
|
|
|
* for mode sense/select.
|
|
|
|
*/
|
1995-11-19 22:22:35 +00:00
|
|
|
struct buf_queue_head buf_queue;
|
1993-11-18 05:03:27 +00:00
|
|
|
struct scsi_xfer scsi_xfer; /* scsi xfer struct for this drive */
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t xfer_block_wait; /* is a process waiting? */
|
1995-12-08 11:19:42 +00:00
|
|
|
#ifdef DEVFS
|
|
|
|
struct {
|
|
|
|
void *rst;
|
|
|
|
void *nrst;
|
1996-03-27 18:50:10 +00:00
|
|
|
void *erst;
|
1995-12-08 11:19:42 +00:00
|
|
|
/* end of aliases */
|
1996-04-01 02:12:53 +00:00
|
|
|
void *rst_[4];
|
|
|
|
void *nrst_[4];
|
|
|
|
void *erst_[4];
|
|
|
|
void *ctl_[4];
|
1996-03-27 18:50:10 +00:00
|
|
|
void *ctl;
|
1995-12-08 11:19:42 +00:00
|
|
|
} devfs_token;
|
|
|
|
#endif
|
1994-12-16 06:03:28 +00:00
|
|
|
};
|
1993-11-18 05:03:27 +00:00
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
static int stunit(dev_t dev) { return STUNIT(dev); }
|
|
|
|
static dev_t stsetunit(dev_t dev, int unit) { return STSETUNIT(dev, unit); }
|
|
|
|
|
1995-10-21 23:13:11 +00:00
|
|
|
static errval st_open(dev_t dev, int flags, int fmt, struct proc *p,
|
|
|
|
struct scsi_link *sc_link);
|
|
|
|
static errval st_ioctl(dev_t dev, int cmd, caddr_t addr, int flag,
|
1995-03-04 20:51:10 +00:00
|
|
|
struct proc *p, struct scsi_link *sc_link);
|
1995-10-21 23:13:11 +00:00
|
|
|
static errval st_close(dev_t dev, int flag, int fmt, struct proc *p,
|
1995-03-04 20:51:10 +00:00
|
|
|
struct scsi_link *sc_link);
|
1995-10-21 23:13:11 +00:00
|
|
|
static void st_strategy(struct buf *bp, struct scsi_link *sc_link);
|
1995-03-01 22:24:47 +00:00
|
|
|
|
1995-12-14 09:55:16 +00:00
|
|
|
static d_open_t stopen;
|
|
|
|
static d_close_t stclose;
|
|
|
|
static d_ioctl_t stioctl;
|
|
|
|
static d_strategy_t ststrategy;
|
1995-12-08 11:19:42 +00:00
|
|
|
|
|
|
|
#define CDEV_MAJOR 14
|
|
|
|
#define BDEV_MAJOR 5
|
1996-07-23 21:52:43 +00:00
|
|
|
static struct cdevsw st_cdevsw;
|
1995-12-08 23:23:00 +00:00
|
|
|
static struct bdevsw st_bdevsw =
|
1995-12-08 11:19:42 +00:00
|
|
|
{ stopen, stclose, ststrategy, stioctl, /*5*/
|
1997-02-10 02:22:35 +00:00
|
|
|
nodump, nopsize, D_TAPE, "st", &st_cdevsw, -1 };
|
1995-12-08 11:19:42 +00:00
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
SCSI_DEVICE_ENTRIES(st)
|
|
|
|
|
1995-10-21 23:13:11 +00:00
|
|
|
static struct scsi_device st_switch =
|
1995-03-01 22:24:47 +00:00
|
|
|
{
|
1996-02-19 09:36:23 +00:00
|
|
|
st_interpret_sense, /* check errors with us first */
|
|
|
|
ststart, /* we have a queue, and this is how we service it */
|
|
|
|
NULL,
|
|
|
|
NULL, /* use the default 'done' routine */
|
|
|
|
"st",
|
|
|
|
0,
|
1995-03-01 22:24:47 +00:00
|
|
|
{0, 0},
|
|
|
|
0, /* Link flags */
|
|
|
|
stattach,
|
1995-03-04 20:51:10 +00:00
|
|
|
"Sequential-Access",
|
1995-03-01 22:24:47 +00:00
|
|
|
stopen,
|
1996-02-19 09:36:23 +00:00
|
|
|
sizeof(struct scsi_data),
|
1995-03-01 22:24:47 +00:00
|
|
|
T_SEQUENTIAL,
|
|
|
|
stunit,
|
|
|
|
stsetunit,
|
|
|
|
st_open,
|
|
|
|
st_ioctl,
|
|
|
|
st_close,
|
|
|
|
st_strategy,
|
|
|
|
};
|
|
|
|
|
1993-07-29 11:49:13 +00:00
|
|
|
#define ST_INITIALIZED 0x01
|
|
|
|
#define ST_INFO_VALID 0x02
|
|
|
|
#define ST_OPEN 0x04
|
1993-11-18 05:03:27 +00:00
|
|
|
#define ST_BLOCK_SET 0x08 /* block size, mode set by ioctl */
|
|
|
|
#define ST_WRITTEN 0x10 /* data have been written, EOD needed */
|
1993-07-29 11:49:13 +00:00
|
|
|
#define ST_FIXEDBLOCKS 0x20
|
|
|
|
#define ST_AT_FILEMARK 0x40
|
1993-11-18 05:03:27 +00:00
|
|
|
#define ST_EIO_PENDING 0x80 /* we couldn't report it then (had data) */
|
|
|
|
#define ST_NEW_MOUNT 0x100 /* still need to decide mode */
|
|
|
|
#define ST_READONLY 0x200 /* st_mode_sense says write protected */
|
|
|
|
#define ST_FM_WRITTEN 0x400 /*
|
|
|
|
* EOF file mark written -- used with
|
|
|
|
* ~ST_WRITTEN to indicate that multiple file
|
|
|
|
* marks have been written
|
|
|
|
*/
|
|
|
|
#define ST_BLANK_READ 0x800 /* BLANK CHECK encountered already */
|
|
|
|
#define ST_2FM_AT_EOD 0x1000 /* write 2 file marks at EOD */
|
|
|
|
#define ST_MOUNTED 0x2000 /* Device is presently mounted */
|
1995-07-09 08:14:24 +00:00
|
|
|
#define ST_SENSE_READ 0x4000 /* mode sense read from drive */
|
1993-09-07 15:58:00 +00:00
|
|
|
|
|
|
|
#define ST_PER_ACTION (ST_AT_FILEMARK | ST_EIO_PENDING | ST_BLANK_READ)
|
1993-11-18 05:03:27 +00:00
|
|
|
#define ST_PER_MOUNT (ST_INFO_VALID | ST_BLOCK_SET | ST_WRITTEN | \
|
|
|
|
ST_FIXEDBLOCKS | ST_READONLY | \
|
1993-09-07 15:58:00 +00:00
|
|
|
ST_FM_WRITTEN | ST_2FM_AT_EOD | ST_PER_ACTION)
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* The routine called by the low level scsi routine when it discovers
|
1995-03-01 22:24:47 +00:00
|
|
|
* a device suitable for this driver
|
1993-11-18 05:03:27 +00:00
|
|
|
*/
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1995-03-01 22:24:47 +00:00
|
|
|
stattach(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;
|
1996-03-29 04:35:09 +00:00
|
|
|
#ifdef DEVFS
|
1996-04-01 02:12:53 +00:00
|
|
|
int ii;
|
1996-03-29 04:35:09 +00:00
|
|
|
#endif /*DEVFS*/
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *st = sc_link->sd;
|
1994-12-16 06:03:28 +00:00
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
unit = sc_link->dev_unit;
|
1994-09-28 20:16:45 +00:00
|
|
|
|
1995-11-19 22:22:35 +00:00
|
|
|
TAILQ_INIT(&st->buf_queue);
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Check if the drive is a known criminal and take
|
|
|
|
* Any steps needed to bring it into line
|
|
|
|
*/
|
1995-03-01 22:24:47 +00:00
|
|
|
st_loadquirks(sc_link);
|
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.
|
|
|
|
*/
|
1995-03-21 11:21:08 +00:00
|
|
|
if (st_mode_sense(unit, SCSI_NOSLEEP | SCSI_NOMASK | SCSI_SILENT,
|
|
|
|
NULL, 0, 0)) {
|
1995-03-15 14:22:12 +00:00
|
|
|
printf("drive offline");
|
1993-11-18 05:03:27 +00:00
|
|
|
} else {
|
1995-04-14 15:10:44 +00:00
|
|
|
printf("density code 0x%lx, ", st->media_density);
|
1993-11-18 05:03:27 +00:00
|
|
|
if (!scsi_test_unit_ready(sc_link, SCSI_NOSLEEP | SCSI_NOMASK | SCSI_SILENT)) {
|
|
|
|
if (st->media_blksiz) {
|
1995-04-14 15:10:44 +00:00
|
|
|
printf("%ld-byte", st->media_blksiz);
|
1993-11-18 05:03:27 +00:00
|
|
|
} else {
|
1993-08-28 03:08:59 +00:00
|
|
|
printf("variable");
|
|
|
|
}
|
1995-03-15 14:22:12 +00:00
|
|
|
printf(" blocks, write-%s",
|
1993-11-18 05:03:27 +00:00
|
|
|
(st->flags & ST_READONLY) ? "protected" : "enabled");
|
|
|
|
} else {
|
1995-03-15 14:22:12 +00:00
|
|
|
printf(" drive empty");
|
1993-07-29 11:49:13 +00:00
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Set up the buf queue for this device
|
|
|
|
*/
|
1993-07-29 11:49:13 +00:00
|
|
|
st->flags |= ST_INITIALIZED;
|
1995-12-08 11:19:42 +00:00
|
|
|
#ifdef DEVFS
|
1996-04-01 02:12:53 +00:00
|
|
|
for(ii=0; ii<4; ii++) {
|
|
|
|
st->devfs_token.rst_[ii] =
|
|
|
|
devfs_add_devswf(&st_cdevsw,
|
|
|
|
(unit << 4 ) + (ii * 4), DV_CHR,
|
|
|
|
UID_ROOT, GID_OPERATOR, 0660,
|
|
|
|
"rst%ld.%d", unit, ii);
|
|
|
|
st->devfs_token.nrst_[ii] =
|
|
|
|
devfs_add_devswf(&st_cdevsw,
|
|
|
|
(unit << 4 ) + ((ii * 4) + 1), DV_CHR,
|
|
|
|
UID_ROOT, GID_OPERATOR, 0660,
|
|
|
|
"nrst%ld.%d", unit, ii);
|
|
|
|
st->devfs_token.erst_[ii] =
|
|
|
|
devfs_add_devswf(&st_cdevsw,
|
|
|
|
(unit << 4 ) + ((ii * 4) + 2), DV_CHR,
|
|
|
|
UID_ROOT, GID_OPERATOR, 0660,
|
|
|
|
"erst%ld.%d", unit, ii);
|
|
|
|
st->devfs_token.ctl_[ii] =
|
|
|
|
devfs_add_devswf(&st_cdevsw,
|
|
|
|
(unit << 4 ) + ((ii * 4) + 3), DV_CHR,
|
|
|
|
UID_ROOT, GID_OPERATOR, 0600,
|
|
|
|
"st%ldctl.%d", unit, ii);
|
|
|
|
}
|
|
|
|
|
|
|
|
st->devfs_token.ctl =
|
|
|
|
devfs_add_devswf(&st_cdevsw, (unit << 4 ) | SCSI_CONTROL_MASK,
|
|
|
|
DV_CHR, UID_ROOT, GID_WHEEL, 0600,
|
|
|
|
"rst%d.ctl", unit);
|
1995-12-08 11:19:42 +00:00
|
|
|
/** add links **/
|
1996-04-01 02:12:53 +00:00
|
|
|
st->devfs_token.rst =
|
1996-04-02 04:54:26 +00:00
|
|
|
devfs_link(st->devfs_token.rst_[0], "rst%ld", unit);
|
1996-04-01 02:12:53 +00:00
|
|
|
st->devfs_token.nrst =
|
1996-04-02 04:54:26 +00:00
|
|
|
devfs_link(st->devfs_token.nrst_[0], "nrst%ld", unit);
|
1996-04-01 02:12:53 +00:00
|
|
|
st->devfs_token.erst =
|
1996-04-02 04:54:26 +00:00
|
|
|
devfs_link(st->devfs_token.erst_[0], "erst%ld", unit);
|
1995-12-08 11:19:42 +00:00
|
|
|
#endif
|
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
|
|
|
/*
|
|
|
|
* initialise the subdevices to the default (QUIRK) state.
|
|
|
|
* this will remove any setting made by the system operator or previous
|
|
|
|
* operations.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static void
|
1995-03-01 22:24:47 +00:00
|
|
|
st_loadquirks(sc_link)
|
|
|
|
struct scsi_link *sc_link;
|
1993-11-18 05:03:27 +00:00
|
|
|
{
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *st = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
int i;
|
1994-09-28 20:16:45 +00:00
|
|
|
struct st_mode *mode;
|
|
|
|
struct st_mode *mode2;
|
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
mode = (struct st_mode*) sc_link->devmodes;
|
1994-09-28 20:16:45 +00:00
|
|
|
if (!mode)
|
|
|
|
return;
|
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
st->quirks = st->drive_quirks = sc_link->quirks;
|
1994-09-28 20:16:45 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
mode2 = st->modes;
|
1994-09-28 20:16:45 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
1994-09-28 20:16:45 +00:00
|
|
|
bzero(mode2, sizeof(*mode2));
|
1993-11-18 05:03:27 +00:00
|
|
|
st->modeflags[i] &= ~(BLKSIZE_SET_BY_QUIRK
|
|
|
|
| DENSITY_SET_BY_QUIRK
|
|
|
|
| BLKSIZE_SET_BY_USER
|
|
|
|
| DENSITY_SET_BY_USER);
|
|
|
|
if (mode->blksiz && ((mode->quirks | st->drive_quirks)
|
|
|
|
& (ST_Q_FORCE_FIXED_MODE))) {
|
|
|
|
mode2->blksiz = mode->blksiz;
|
|
|
|
st->modeflags[i] |= BLKSIZE_SET_BY_QUIRK;
|
|
|
|
} else {
|
|
|
|
if ((mode->quirks | st->drive_quirks)
|
|
|
|
& ST_Q_FORCE_VAR_MODE) {
|
|
|
|
mode2->blksiz = 0;
|
|
|
|
st->modeflags[i] |= BLKSIZE_SET_BY_QUIRK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mode->density) {
|
|
|
|
mode2->density = mode->density;
|
|
|
|
st->modeflags[i] |= DENSITY_SET_BY_QUIRK;
|
|
|
|
}
|
|
|
|
mode++;
|
|
|
|
mode2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* open the device.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1995-03-04 20:51:10 +00:00
|
|
|
st_open(dev_t dev, int flags, int fmt, struct proc *p,
|
|
|
|
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, mode, dsty;
|
1993-11-18 05:03:27 +00:00
|
|
|
errval errno = 0;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *st;
|
|
|
|
|
1995-01-08 13:38:38 +00:00
|
|
|
unit = STUNIT(dev);
|
1993-06-12 14:58:17 +00:00
|
|
|
mode = MODE(dev);
|
|
|
|
dsty = DSTY(dev);
|
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
st = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Make sure the device has been initialised
|
|
|
|
*/
|
1993-08-28 03:08:59 +00:00
|
|
|
if ((st == NULL) || (!(st->flags & ST_INITIALIZED)))
|
1993-11-18 05:03:27 +00:00
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only allow one at a time
|
|
|
|
*/
|
|
|
|
if (st->flags & ST_OPEN) {
|
1994-01-29 10:30:41 +00:00
|
|
|
return (EBUSY);
|
1993-07-29 11:49:13 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Throw out a dummy instruction to catch 'Unit attention
|
|
|
|
* errors (the error handling will invalidate all our
|
|
|
|
* device info if we get one, but otherwise, ignore it)
|
|
|
|
*/
|
|
|
|
scsi_test_unit_ready(sc_link, SCSI_SILENT);
|
|
|
|
|
|
|
|
sc_link->flags |= SDEV_OPEN; /* unit attn are now errors */
|
|
|
|
/*
|
|
|
|
* If the mode is 3 (e.g. minor = 3,7,11,15)
|
|
|
|
* then the device has been openned to set defaults
|
1995-01-08 13:38:38 +00:00
|
|
|
* This mode does NOT ALLOW I/O, only ioctls.
|
|
|
|
* XXX: Where do we lock out I/O?
|
1993-11-18 05:03:27 +00:00
|
|
|
*/
|
1995-01-08 13:38:38 +00:00
|
|
|
if (IS_CTLMODE(dev))
|
1993-11-18 05:03:27 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the device is ready to use (media loaded?)
|
|
|
|
* This time take notice of the return result
|
|
|
|
*/
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errno = scsi_test_unit_ready(sc_link, 0)) ) {
|
1995-01-24 12:04:56 +00:00
|
|
|
uprintf("st%d: not ready\n", unit);
|
1993-11-18 05:03:27 +00:00
|
|
|
st_unmount(unit, NOEJECT);
|
|
|
|
return (errno);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* if it's a different mode, or if the media has been
|
|
|
|
* invalidated, unmount the tape from the previous
|
|
|
|
* session but continue with open processing
|
|
|
|
*/
|
|
|
|
if ((st->last_dsty != dsty)
|
|
|
|
|| (!(sc_link->flags & SDEV_MEDIA_LOADED))) {
|
|
|
|
st_unmount(unit, NOEJECT);
|
1993-09-05 15:42:22 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
1995-05-30 08:16:23 +00:00
|
|
|
* If we are not mounted, then we should start a new
|
1993-11-18 05:03:27 +00:00
|
|
|
* mount session.
|
|
|
|
*/
|
|
|
|
if (!(st->flags & ST_MOUNTED)) {
|
|
|
|
st_mount_tape(dev, flags);
|
|
|
|
st->last_dsty = dsty;
|
1993-09-07 15:58:00 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Make sure that a tape opened in write-only mode will have
|
|
|
|
* file marks written on it when closed, even if not written to.
|
|
|
|
* This is for SUN compatibility
|
|
|
|
*/
|
1993-09-07 15:58:00 +00:00
|
|
|
if ((flags & O_ACCMODE) == FWRITE)
|
|
|
|
st->flags |= ST_WRITTEN;
|
|
|
|
|
1996-01-29 03:19:23 +00:00
|
|
|
scsi_prevent(sc_link, PR_PREVENT, 0); /* who cares if it fails? */
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB2, ("Open complete\n"));
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
st->flags |= ST_OPEN;
|
1995-01-08 13:38:38 +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-08 11:19:42 +00:00
|
|
|
static errval
|
1995-03-04 20:51:10 +00:00
|
|
|
st_close(dev_t dev, int flag, int fmt, struct proc *p,
|
|
|
|
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, mode;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *st;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-01-08 13:38:38 +00:00
|
|
|
unit = STUNIT(dev);
|
1993-06-12 14:58:17 +00:00
|
|
|
mode = MODE(dev);
|
1995-03-01 22:24:47 +00:00
|
|
|
st = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
if ((st->flags & (ST_WRITTEN | ST_FM_WRITTEN)) == ST_WRITTEN)
|
|
|
|
st_write_filemarks(unit, 1, 0);
|
1996-06-24 04:54:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Since the device has seen its last close, allow media removal.
|
|
|
|
* Do this before we attempt an eject.
|
|
|
|
*/
|
|
|
|
scsi_prevent(sc_link, PR_ALLOW, SCSI_SILENT);
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
switch (mode & 0x3) {
|
|
|
|
case 0:
|
|
|
|
case 3: /* for now */
|
|
|
|
st_unmount(unit, NOEJECT);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
case 1: /*leave mounted unless media seems to have been removed */
|
|
|
|
if (!(sc_link->flags & SDEV_MEDIA_LOADED)) {
|
|
|
|
st_unmount(unit, NOEJECT);
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
case 2:
|
|
|
|
st_unmount(unit, EJECT);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
}
|
1996-01-29 03:19:23 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
sc_link->flags &= ~SDEV_OPEN;
|
|
|
|
st->flags &= ~ST_OPEN;
|
1996-01-29 03:19:23 +00:00
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Start a new mount session.
|
|
|
|
* Copy in all the default parameters from the selected device mode.
|
|
|
|
* and try guess any that seem to be defaulted.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1993-11-18 05:03:27 +00:00
|
|
|
st_mount_tape(dev, flags)
|
|
|
|
dev_t dev;
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t flags;
|
1993-07-29 11:49:13 +00:00
|
|
|
{
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, mode, dsty;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *st;
|
1993-11-18 05:03:27 +00:00
|
|
|
struct scsi_link *sc_link;
|
|
|
|
errval errno = 0;
|
1993-07-29 11:49:13 +00:00
|
|
|
|
1995-01-08 13:38:38 +00:00
|
|
|
unit = STUNIT(dev);
|
1993-11-18 05:03:27 +00:00
|
|
|
mode = MODE(dev);
|
|
|
|
dsty = DSTY(dev);
|
1995-03-01 22:24:47 +00:00
|
|
|
sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
st = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
if (st->flags & ST_MOUNTED)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB1, ("mounting\n "));
|
|
|
|
st->flags |= ST_NEW_MOUNT;
|
|
|
|
st->quirks = st->drive_quirks | st->modes[dsty].quirks;
|
|
|
|
/*
|
|
|
|
* If the media is new, then make sure we give it a chance to
|
|
|
|
* to do a 'load' instruction. ( We assume it is new)
|
|
|
|
*/
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errno = st_load(unit, LD_LOAD, 0)) ) {
|
1993-11-18 05:03:27 +00:00
|
|
|
return (errno);
|
1993-08-28 03:08:59 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Throw another dummy instruction to catch
|
|
|
|
* 'Unit attention' errors. Some drives appear to give
|
|
|
|
* these after doing a Load instruction.
|
|
|
|
* (noteably some DAT drives)
|
|
|
|
*/
|
|
|
|
scsi_test_unit_ready(sc_link, SCSI_SILENT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some devices can't tell you much until they have been
|
|
|
|
* asked to look at the media. This quirk does this.
|
|
|
|
*/
|
|
|
|
if (st->quirks & ST_Q_SNS_HLP) {
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errno = st_touch_tape(unit)) )
|
1993-11-18 05:03:27 +00:00
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Load the physical device parameters
|
|
|
|
* loads: blkmin, blkmax
|
|
|
|
*/
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errno = st_rd_blk_lim(unit, 0)) ) {
|
1993-11-18 05:03:27 +00:00
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Load the media dependent parameters
|
|
|
|
* includes: media_blksiz,media_density,numblks
|
|
|
|
* As we have a tape in, it should be reflected here.
|
|
|
|
* If not you may need the "quirk" above.
|
|
|
|
*/
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errno = st_mode_sense(unit, 0, NULL, 0, 0)) ) {
|
1993-11-18 05:03:27 +00:00
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we have gained a permanent density from somewhere,
|
|
|
|
* then use it in preference to the one supplied by
|
|
|
|
* default by the driver.
|
|
|
|
*/
|
|
|
|
if (st->modeflags[dsty] & (DENSITY_SET_BY_QUIRK | DENSITY_SET_BY_USER)) {
|
|
|
|
st->density = st->modes[dsty].density;
|
|
|
|
} else {
|
|
|
|
st->density = st->media_density;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we have gained a permanent blocksize
|
|
|
|
* then use it in preference to the one supplied by
|
|
|
|
* default by the driver.
|
|
|
|
*/
|
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
|
|
|
if (st->modeflags[dsty] & (BLKSIZE_SET_BY_QUIRK | BLKSIZE_SET_BY_USER)) {
|
|
|
|
st->blksiz = st->modes[dsty].blksiz;
|
|
|
|
if (st->blksiz) {
|
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
|
|
|
}
|
|
|
|
} else {
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errno = st_decide_mode(unit, FALSE)) ) {
|
1993-11-18 05:03:27 +00:00
|
|
|
return errno;
|
|
|
|
}
|
1993-08-28 03:08:59 +00:00
|
|
|
}
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errno = st_mode_select(unit, 0, NULL, 0)) ) {
|
|
|
|
printf("st%ld: Cannot set selected mode", unit);
|
1993-11-18 05:03:27 +00:00
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
st->flags &= ~ST_NEW_MOUNT;
|
|
|
|
st->flags |= ST_MOUNTED;
|
1995-07-09 08:14:24 +00:00
|
|
|
sc_link->flags |= SDEV_MEDIA_LOADED;
|
1993-07-29 11:49:13 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* End the present mount session.
|
|
|
|
* Rewind, and optionally eject the tape.
|
|
|
|
* Reset various flags to indicate that all new
|
|
|
|
* operations require another mount operation
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
st_unmount(int unit, boolean eject)
|
|
|
|
{
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
1996-03-10 07:13:15 +00:00
|
|
|
int32_t nmarks;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
if (!(st->flags & ST_MOUNTED))
|
|
|
|
return;
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB1, ("unmounting\n"));
|
|
|
|
st_chkeod(unit, FALSE, &nmarks, SCSI_SILENT);
|
|
|
|
st_rewind(unit, FALSE, SCSI_SILENT);
|
|
|
|
if (eject) {
|
|
|
|
st_load(unit, LD_UNLOAD, SCSI_SILENT);
|
|
|
|
}
|
|
|
|
st->flags &= ~(ST_MOUNTED | ST_NEW_MOUNT);
|
|
|
|
sc_link->flags &= ~SDEV_MEDIA_LOADED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given all we know about the device, media, mode, 'quirks' and
|
|
|
|
* initial operation, make a decision as to how we should be set
|
|
|
|
* to run (regarding blocking and EOD marks)
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1993-11-18 05:03:27 +00:00
|
|
|
st_decide_mode(unit, first_read)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit;
|
1993-11-18 05:03:27 +00:00
|
|
|
boolean first_read;
|
|
|
|
{
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB2, ("starting block mode decision\n"));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user hasn't already specified fixed or variable-length
|
|
|
|
* blocks and the block size (zero if variable-length), we'll
|
|
|
|
* have to try to figure them out ourselves.
|
|
|
|
*
|
|
|
|
* Our first shot at a method is, "The quirks made me do it!"
|
|
|
|
*/
|
1993-12-19 00:55:01 +00:00
|
|
|
switch ((int)(st->quirks & (ST_Q_FORCE_FIXED_MODE | ST_Q_FORCE_VAR_MODE))) {
|
1993-11-18 05:03:27 +00:00
|
|
|
case (ST_Q_FORCE_FIXED_MODE | ST_Q_FORCE_VAR_MODE):
|
1995-04-14 15:10:44 +00:00
|
|
|
printf("st%ld: bad quirks\n", unit);
|
1993-08-28 03:08:59 +00:00
|
|
|
return (EINVAL);
|
1993-11-18 05:03:27 +00:00
|
|
|
case ST_Q_FORCE_FIXED_MODE: /*specified fixed, but not what size */
|
1993-07-29 11:49:13 +00:00
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
1993-09-05 15:42:22 +00:00
|
|
|
if (st->blkmin && (st->blkmin == st->blkmax))
|
1993-08-28 03:08:59 +00:00
|
|
|
st->blksiz = st->blkmin;
|
1993-11-18 05:03:27 +00:00
|
|
|
else if (st->media_blksiz > 0)
|
1993-07-29 11:49:13 +00:00
|
|
|
st->blksiz = st->media_blksiz;
|
|
|
|
else
|
1993-08-28 03:08:59 +00:00
|
|
|
st->blksiz = DEF_FIXED_BSIZE;
|
1995-04-14 15:10:44 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3, ("Quirks force fixed mode(%ld)\n",
|
1993-11-18 05:03:27 +00:00
|
|
|
st->blksiz));
|
1993-08-28 03:08:59 +00:00
|
|
|
goto done;
|
1993-11-18 05:03:27 +00:00
|
|
|
case ST_Q_FORCE_VAR_MODE:
|
1993-07-29 11:49:13 +00:00
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
|
|
|
st->blksiz = 0;
|
1993-11-18 05:03:27 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3, ("Quirks force variable mode\n"));
|
1993-08-28 03:08:59 +00:00
|
|
|
goto done;
|
1993-07-29 11:49:13 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* If the drive can only handle fixed-length blocks and only at
|
|
|
|
* one size, perhaps we should just do that.
|
|
|
|
*/
|
|
|
|
if (st->blkmin && (st->blkmin == st->blkmax)) {
|
1993-08-28 03:08:59 +00:00
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
|
|
|
st->blksiz = st->blkmin;
|
1993-11-18 05:03:27 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3,
|
1995-04-14 15:10:44 +00:00
|
|
|
("blkmin == blkmax of %ld\n", st->blkmin));
|
1993-08-28 03:08:59 +00:00
|
|
|
goto done;
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* If the tape density mandates (or even suggests) use of fixed
|
|
|
|
* or variable-length blocks, comply.
|
|
|
|
*/
|
1993-12-19 00:55:01 +00:00
|
|
|
switch ((int)st->density) {
|
1993-11-18 05:03:27 +00:00
|
|
|
case HALFINCH_800:
|
|
|
|
case HALFINCH_1600:
|
|
|
|
case HALFINCH_6250:
|
|
|
|
case DDS:
|
1996-02-03 13:31:13 +00:00
|
|
|
case QIC_525:
|
|
|
|
case QIC_1320:
|
|
|
|
case QIC_3080:
|
1993-08-28 03:08:59 +00:00
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
|
|
|
st->blksiz = 0;
|
1993-11-18 05:03:27 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3, ("density specified variable\n"));
|
1993-08-28 03:08:59 +00:00
|
|
|
goto done;
|
1993-11-18 05:03:27 +00:00
|
|
|
case QIC_11:
|
|
|
|
case QIC_24:
|
|
|
|
case QIC_120:
|
|
|
|
case QIC_150:
|
1993-08-28 03:08:59 +00:00
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
1993-11-18 05:03:27 +00:00
|
|
|
if (st->media_blksiz > 0) {
|
1993-08-28 03:08:59 +00:00
|
|
|
st->blksiz = st->media_blksiz;
|
1993-11-18 05:03:27 +00:00
|
|
|
} else {
|
1993-08-28 03:08:59 +00:00
|
|
|
st->blksiz = DEF_FIXED_BSIZE;
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB3, ("density specified fixed\n"));
|
1993-08-28 03:08:59 +00:00
|
|
|
goto done;
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* If we're about to read the tape, perhaps we should choose
|
|
|
|
* fixed or variable-length blocks and block size according to
|
|
|
|
* what the drive found on the tape.
|
|
|
|
*/
|
|
|
|
if (first_read
|
|
|
|
&& (!(st->quirks & ST_Q_BLKSIZ)
|
|
|
|
|| (st->media_blksiz == 0)
|
|
|
|
|| (st->media_blksiz == DEF_FIXED_BSIZE)
|
|
|
|
|| (st->media_blksiz == 1024))) {
|
|
|
|
if (st->media_blksiz == 0) {
|
1993-08-28 03:08:59 +00:00
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
1993-11-18 05:03:27 +00:00
|
|
|
} else {
|
1993-08-28 03:08:59 +00:00
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
1993-08-28 03:08:59 +00:00
|
|
|
st->blksiz = st->media_blksiz;
|
1993-11-18 05:03:27 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3,
|
1995-04-14 15:10:44 +00:00
|
|
|
("Used media_blksiz of %ld\n", st->media_blksiz));
|
1993-08-28 03:08:59 +00:00
|
|
|
goto done;
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* We're getting no hints from any direction. Choose variable-
|
|
|
|
* length blocks arbitrarily.
|
|
|
|
*/
|
1993-09-05 15:42:22 +00:00
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
|
|
|
st->blksiz = 0;
|
1993-11-18 05:03:27 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3, ("Give up and default to variable mode\n"));
|
1993-08-28 03:08:59 +00:00
|
|
|
done:
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Decide whether or not to write two file marks to signify end-
|
|
|
|
* of-data. Make the decision as a function of density. If
|
|
|
|
* the decision is not to use a second file mark, the SCSI BLANK
|
|
|
|
* CHECK condition code will be recognized as end-of-data when
|
|
|
|
* first read.
|
|
|
|
* (I think this should be a by-product of fixed/variable..julian)
|
|
|
|
*/
|
1993-12-19 00:55:01 +00:00
|
|
|
switch ((int)st->density) {
|
1993-11-18 05:03:27 +00:00
|
|
|
/* case 8 mm: What is the SCSI density code for 8 mm, anyway? */
|
|
|
|
case QIC_11:
|
|
|
|
case QIC_24:
|
|
|
|
case QIC_120:
|
|
|
|
case QIC_150:
|
|
|
|
case QIC_525:
|
|
|
|
case QIC_1320:
|
1995-11-30 07:43:47 +00:00
|
|
|
case QIC_3080:
|
1993-11-18 05:03:27 +00:00
|
|
|
st->flags &= ~ST_2FM_AT_EOD;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
st->flags |= ST_2FM_AT_EOD;
|
|
|
|
}
|
|
|
|
return 0;
|
1993-08-28 03:08:59 +00:00
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Actually translate the requested transfer into
|
|
|
|
* one the physical driver can understand
|
|
|
|
* The transfer is described by a buf and will include
|
|
|
|
* only one physical transfer.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static void
|
1995-03-01 22:24:47 +00:00
|
|
|
st_strategy(struct buf *bp, 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;
|
|
|
|
u_int32_t opri;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *st;
|
1995-10-12 02:02:03 +00:00
|
|
|
int len;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-01-08 13:38:38 +00:00
|
|
|
unit = STUNIT((bp->b_dev));
|
1995-03-01 22:24:47 +00:00
|
|
|
st = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* If it's a null transfer, return immediatly
|
|
|
|
*/
|
1995-10-12 02:02:03 +00:00
|
|
|
if ((len = bp->b_bcount) == 0) {
|
1993-06-12 14:58:17 +00:00
|
|
|
goto done;
|
|
|
|
}
|
1995-10-12 02:02:03 +00:00
|
|
|
/*
|
|
|
|
* Check the adapter can do it
|
|
|
|
*/
|
|
|
|
scsi_minphys(bp,&st_switch);
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Odd sized request on fixed drives are verboten
|
|
|
|
*/
|
|
|
|
if (st->flags & ST_FIXEDBLOCKS) {
|
|
|
|
if (bp->b_bcount % st->blksiz) {
|
1995-12-09 20:42:38 +00:00
|
|
|
printf("st%ld: bad request, must be multiple of %ld\n",
|
1993-11-18 05:03:27 +00:00
|
|
|
unit, st->blksiz);
|
1993-07-29 11:49:13 +00:00
|
|
|
bp->b_error = EIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* as are out-of-range requests on variable drives.
|
1995-10-12 02:02:03 +00:00
|
|
|
* (or if we got chopped by minphys)
|
1993-11-18 05:03:27 +00:00
|
|
|
*/
|
1995-10-12 02:02:03 +00:00
|
|
|
else {
|
|
|
|
if ((bp->b_bcount < st->blkmin || bp->b_bcount > st->blkmax)) {
|
1995-12-09 20:42:38 +00:00
|
|
|
printf("st%ld: bad request, must be between %ld and %ld\n",
|
1995-10-12 02:02:03 +00:00
|
|
|
unit, st->blkmin, st->blkmax);
|
|
|
|
bp->b_error = EIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
if (len != bp->b_bcount) {
|
1995-12-09 20:42:38 +00:00
|
|
|
printf("st%ld: bad request, must be less than %ld bytes\n",
|
1995-10-12 02:05:47 +00:00
|
|
|
unit, bp->b_bcount + 1);
|
1995-10-12 02:02:03 +00:00
|
|
|
bp->b_error = EIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
opri = splbio();
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
/*
|
1994-03-23 09:16:04 +00:00
|
|
|
* Use a bounce buffer if necessary
|
1995-05-30 08:16:23 +00:00
|
|
|
*/
|
1994-08-31 06:17:49 +00:00
|
|
|
#ifdef BOUNCE_BUFFERS
|
1995-03-01 22:24:47 +00:00
|
|
|
if (sc_link->flags & SDEV_BOUNCE)
|
1994-03-23 09:16:04 +00:00
|
|
|
vm_bounce_alloc(bp);
|
|
|
|
#endif
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Place it in the queue of activities for this tape
|
|
|
|
* at the end (a bit silly because we only have on user..
|
|
|
|
* (but it could fork() ))
|
|
|
|
*/
|
1995-11-19 22:22:35 +00:00
|
|
|
TAILQ_INSERT_TAIL(&st->buf_queue, bp, b_act);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Tell the device to get going on the transfer if it's
|
|
|
|
* not doing anything, otherwise just wait for completion
|
|
|
|
* (All a bit silly if we're only allowing 1 open but..)
|
|
|
|
*/
|
1995-04-23 22:07:56 +00:00
|
|
|
ststart(unit, 0);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
splx(opri);
|
|
|
|
return;
|
|
|
|
bad:
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
done:
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Correctly set the buf to indicate a completed xfer
|
|
|
|
*/
|
1995-02-25 19:11:11 +00:00
|
|
|
biodone(bp);
|
1993-06-12 14:58:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* ststart looks to see if there is a buf waiting for the device
|
|
|
|
* and that the device is not already busy. If both are true,
|
|
|
|
* It dequeues the buf and creates a scsi command to perform the
|
|
|
|
* transfer required. The transfer request will call scsi_done
|
|
|
|
* on completion, which will in turn call this routine again
|
|
|
|
* so that the next queued transfer is performed.
|
|
|
|
* The bufs are queued by the strategy routine (ststrategy)
|
|
|
|
*
|
|
|
|
* This routine is also called after other non-queued requests
|
|
|
|
* have been made of the scsi driver, to ensure that the queue
|
|
|
|
* continues to be drained.
|
|
|
|
* ststart() is called at splbio
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static void
|
1995-04-23 22:07:56 +00:00
|
|
|
ststart(unit, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit;
|
|
|
|
u_int32_t flags;
|
1993-11-18 05:03:27 +00:00
|
|
|
{
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
register struct buf *bp = 0;
|
|
|
|
struct scsi_rw_tape cmd;
|
|
|
|
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB2, ("ststart "));
|
|
|
|
/*
|
|
|
|
* See if there is a buf to do and we are not already
|
|
|
|
* doing one
|
|
|
|
*/
|
|
|
|
while (sc_link->opennings != 0) {
|
|
|
|
|
|
|
|
/* if a special awaits, let it proceed first */
|
|
|
|
if (sc_link->flags & SDEV_WAITING) {
|
1994-01-29 10:30:41 +00:00
|
|
|
sc_link->flags &= ~SDEV_WAITING;
|
1993-11-18 05:03:27 +00:00
|
|
|
wakeup((caddr_t)sc_link);
|
|
|
|
return;
|
|
|
|
}
|
1995-11-19 22:22:35 +00:00
|
|
|
|
|
|
|
bp = st->buf_queue.tqh_first;
|
|
|
|
if (bp == NULL) { /* yes, an assign */
|
|
|
|
return;
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
1995-11-19 22:22:35 +00:00
|
|
|
TAILQ_REMOVE( &st->buf_queue, bp, b_act);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
/*
|
1995-07-09 08:14:24 +00:00
|
|
|
* if the device has been unmounted by the user
|
1993-11-18 05:03:27 +00:00
|
|
|
* then throw away all requests until done
|
|
|
|
*/
|
|
|
|
if ((!(st->flags & ST_MOUNTED))
|
|
|
|
|| (!(sc_link->flags & SDEV_MEDIA_LOADED))) {
|
|
|
|
/* make sure that one implies the other.. */
|
|
|
|
sc_link->flags &= ~SDEV_MEDIA_LOADED;
|
|
|
|
goto badnews;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* only FIXEDBLOCK devices have pending operations
|
|
|
|
*/
|
|
|
|
if (st->flags & ST_FIXEDBLOCKS) {
|
|
|
|
/*
|
|
|
|
* If we are at a filemark but have not reported it yet
|
|
|
|
* then we should report it now
|
|
|
|
*/
|
|
|
|
if (st->flags & ST_AT_FILEMARK) {
|
|
|
|
if ((bp->b_flags & B_READ) == B_WRITE) {
|
|
|
|
/*
|
|
|
|
* Handling of ST_AT_FILEMARK in
|
|
|
|
* st_space will fill in the right file
|
|
|
|
* mark count.
|
|
|
|
* Back up over filemark
|
|
|
|
*/
|
|
|
|
if (st_space(unit, 0, SP_FILEMARKS, 0) !=
|
|
|
|
ESUCCESS)
|
|
|
|
goto badnews;
|
|
|
|
} else {
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
bp->b_error = 0;
|
|
|
|
bp->b_flags &= ~B_ERROR;
|
|
|
|
st->flags &= ~ST_AT_FILEMARK;
|
|
|
|
biodone(bp);
|
|
|
|
continue; /* seek more work */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we are at EIO (e.g. EOM) but have not reported it
|
|
|
|
* yet then we should report it now
|
|
|
|
*/
|
|
|
|
if (st->flags & ST_EIO_PENDING) {
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
bp->b_error = EIO;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
st->flags &= ~ST_EIO_PENDING;
|
|
|
|
biodone(bp);
|
|
|
|
continue; /* seek more work */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Fill out the scsi command
|
|
|
|
*/
|
|
|
|
bzero(&cmd, sizeof(cmd));
|
|
|
|
if ((bp->b_flags & B_READ) == B_WRITE) {
|
|
|
|
cmd.op_code = WRITE_COMMAND_TAPE;
|
|
|
|
st->flags &= ~ST_FM_WRITTEN;
|
|
|
|
st->flags |= ST_WRITTEN;
|
1995-04-23 22:07:56 +00:00
|
|
|
flags |= SCSI_DATA_OUT;
|
1993-11-18 05:03:27 +00:00
|
|
|
} else {
|
|
|
|
cmd.op_code = READ_COMMAND_TAPE;
|
1995-04-23 22:07:56 +00:00
|
|
|
flags |= SCSI_DATA_IN;
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Handle "fixed-block-mode" tape drives by using the
|
|
|
|
* block count instead of the length.
|
|
|
|
*/
|
|
|
|
if (st->flags & ST_FIXEDBLOCKS) {
|
|
|
|
cmd.byte2 |= SRWT_FIXED;
|
1995-01-31 11:41:47 +00:00
|
|
|
scsi_uto3b(bp->b_bcount / st->blksiz, cmd.len);
|
1993-11-18 05:03:27 +00:00
|
|
|
} else {
|
1995-01-31 11:41:47 +00:00
|
|
|
scsi_uto3b(bp->b_bcount, cmd.len);
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* go ask the adapter to do all this for us
|
|
|
|
*/
|
|
|
|
if (scsi_scsi_cmd(sc_link,
|
|
|
|
(struct scsi_generic *) &cmd,
|
|
|
|
sizeof(cmd),
|
|
|
|
(u_char *) bp->b_un.b_addr,
|
|
|
|
bp->b_bcount,
|
|
|
|
0, /* can't retry a read on a tape really */
|
|
|
|
100000,
|
|
|
|
bp,
|
1995-07-16 09:13:14 +00:00
|
|
|
flags) == SUCCESSFULLY_QUEUED) {
|
1993-11-18 05:03:27 +00:00
|
|
|
} else {
|
|
|
|
badnews:
|
1995-04-14 15:10:44 +00:00
|
|
|
printf("st%ld: oops not queued\n", unit);
|
1993-11-18 05:03:27 +00:00
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = EIO;
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
} /* go back and see if we can cram more work in.. */
|
|
|
|
}
|
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-08 11:19:42 +00:00
|
|
|
static errval
|
1995-03-01 22:24:47 +00:00
|
|
|
st_ioctl(dev_t dev, int cmd, caddr_t arg, int flag,
|
1995-03-04 20:51:10 +00:00
|
|
|
struct proc *p, struct scsi_link *sc_link)
|
1993-08-28 03:08:59 +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;
|
|
|
|
u_int32_t number, flags, dsty;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *st;
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t hold_blksiz;
|
|
|
|
u_int32_t hold_density;
|
|
|
|
int32_t nmarks;
|
1993-11-18 05:03:27 +00:00
|
|
|
struct mtop *mt = (struct mtop *) arg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 = STUNIT(dev);
|
1993-09-05 15:42:22 +00:00
|
|
|
dsty = DSTY(dev);
|
1995-03-01 22:24:47 +00:00
|
|
|
st = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
hold_blksiz = st->blksiz;
|
|
|
|
hold_density = st->density;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
switch (cmd) {
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
case MTIOCGET:
|
1993-11-18 05:03:27 +00:00
|
|
|
{
|
|
|
|
struct mtget *g = (struct mtget *) arg;
|
|
|
|
|
1995-03-01 22:24:47 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB1, ("[ioctl: get status]\n"));
|
1993-11-18 05:03:27 +00:00
|
|
|
bzero(g, sizeof(struct mtget));
|
|
|
|
g->mt_type = 0x7; /* Ultrix compat *//*? */
|
|
|
|
g->mt_density = st->density;
|
|
|
|
g->mt_blksiz = st->blksiz;
|
1995-03-21 11:21:08 +00:00
|
|
|
g->mt_comp = st->comp;
|
1993-11-18 05:03:27 +00:00
|
|
|
g->mt_density0 = st->modes[0].density;
|
|
|
|
g->mt_density1 = st->modes[1].density;
|
|
|
|
g->mt_density2 = st->modes[2].density;
|
|
|
|
g->mt_density3 = st->modes[3].density;
|
|
|
|
g->mt_blksiz0 = st->modes[0].blksiz;
|
|
|
|
g->mt_blksiz1 = st->modes[1].blksiz;
|
|
|
|
g->mt_blksiz2 = st->modes[2].blksiz;
|
|
|
|
g->mt_blksiz3 = st->modes[3].blksiz;
|
1995-03-21 11:21:08 +00:00
|
|
|
g->mt_comp0 = 0;
|
|
|
|
g->mt_comp1 = 0;
|
|
|
|
g->mt_comp2 = 0;
|
|
|
|
g->mt_comp3 = 0;
|
1993-11-18 05:03:27 +00:00
|
|
|
break;
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
case MTIOCTOP:
|
1993-11-18 05:03:27 +00:00
|
|
|
{
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-04-14 15:10:44 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB1, ("[ioctl: op=0x%x count=0x%lx]\n",
|
1993-11-18 05:03:27 +00:00
|
|
|
mt->mt_op, mt->mt_count));
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/* compat: in U*x it is a short */
|
|
|
|
number = mt->mt_count;
|
|
|
|
switch ((short) (mt->mt_op)) {
|
|
|
|
case MTWEOF: /* write an end-of-file record */
|
|
|
|
errcode = st_write_filemarks(unit, number, flags);
|
1993-08-28 03:08:59 +00:00
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
case MTBSF: /* backward space file */
|
|
|
|
number = -number;
|
|
|
|
case MTFSF: /* forward space file */
|
|
|
|
errcode = st_chkeod(unit, FALSE, &nmarks, flags);
|
|
|
|
if (errcode == ESUCCESS)
|
|
|
|
errcode = st_space(unit, number - nmarks,
|
|
|
|
SP_FILEMARKS, flags);
|
|
|
|
break;
|
|
|
|
case MTBSR: /* backward space record */
|
|
|
|
number = -number;
|
|
|
|
case MTFSR: /* forward space record */
|
|
|
|
errcode = st_chkeod(unit, TRUE, &nmarks, flags);
|
|
|
|
if (errcode == ESUCCESS)
|
|
|
|
errcode = st_space(unit, number, SP_BLKS, flags);
|
|
|
|
break;
|
1995-04-29 21:30:29 +00:00
|
|
|
case MTEOD: /* space to end of recorded medium */
|
|
|
|
errcode = st_chkeod(unit, FALSE, &nmarks, flags);
|
|
|
|
if (errcode == ESUCCESS)
|
|
|
|
errcode = st_space(unit, 0, SP_EOM,
|
|
|
|
flags);
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
case MTREW: /* rewind */
|
|
|
|
errcode = st_rewind(unit, FALSE, flags);
|
|
|
|
break;
|
1995-04-29 21:30:29 +00:00
|
|
|
case MTERASE: /* erase */
|
1994-10-28 13:19:42 +00:00
|
|
|
errcode = st_erase(unit, FALSE, flags);
|
|
|
|
break;
|
1996-01-08 12:26:15 +00:00
|
|
|
case MTRETENS: /* re-tension tape */
|
|
|
|
errcode = st_load(unit, LD_LOAD|LD_RETEN,
|
|
|
|
flags);
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
case MTOFFL: /* rewind and put the drive offline */
|
1996-06-24 04:54:32 +00:00
|
|
|
/*
|
|
|
|
* Be sure to allow media removal before
|
|
|
|
* attempting the eject.
|
|
|
|
*/
|
|
|
|
scsi_prevent(sc_link, PR_ALLOW, SCSI_SILENT);
|
1993-11-18 05:03:27 +00:00
|
|
|
st_unmount(unit, EJECT);
|
|
|
|
break;
|
|
|
|
case MTNOP: /* no operation, sets status only */
|
|
|
|
case MTCACHE: /* enable controller cache */
|
|
|
|
case MTNOCACHE: /* disable controller cache */
|
|
|
|
break;
|
|
|
|
case MTSETBSIZ: /* Set block size for device */
|
|
|
|
#ifdef NOTYET
|
|
|
|
if (!(st->flags & ST_NEW_MOUNT)) {
|
|
|
|
uprintf("re-mount tape before changing blocksize");
|
1993-09-05 15:42:22 +00:00
|
|
|
errcode = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
#endif
|
|
|
|
if (number == 0) {
|
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
|
|
|
} else {
|
|
|
|
if ((st->blkmin || st->blkmax) /* they exist */
|
|
|
|
&&((number < st->blkmin
|
|
|
|
|| number > st->blkmax))) {
|
|
|
|
errcode = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
|
|
|
}
|
|
|
|
st->blksiz = number;
|
|
|
|
st->flags |= ST_BLOCK_SET; /*XXX */
|
|
|
|
goto try_new_value;
|
1993-07-29 11:49:13 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
case MTSETDNSTY: /* Set density for device and mode */
|
1996-06-24 04:54:32 +00:00
|
|
|
if (number > (u_int8_t)0xff) {
|
|
|
|
/* Guard against overflows */
|
1993-11-18 05:03:27 +00:00
|
|
|
errcode = EINVAL;
|
|
|
|
} else {
|
|
|
|
st->density = number;
|
1996-06-24 04:54:32 +00:00
|
|
|
goto try_new_value;
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
1996-06-24 04:54:32 +00:00
|
|
|
break;
|
1995-03-21 11:21:08 +00:00
|
|
|
case MTCOMP: /* enable default compression */
|
|
|
|
errcode = st_comp(unit,number);
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
default:
|
1993-08-20 09:23:30 +00:00
|
|
|
errcode = EINVAL;
|
1993-07-29 11:49:13 +00:00
|
|
|
}
|
|
|
|
break;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
case MTIOCIEOT:
|
|
|
|
case MTIOCEEOT:
|
|
|
|
break;
|
1993-08-20 09:23:30 +00:00
|
|
|
default:
|
1995-01-08 13:38:38 +00:00
|
|
|
if(IS_CTLMODE(dev))
|
1995-03-04 20:51:10 +00:00
|
|
|
errcode = scsi_do_ioctl(dev, cmd, arg, flag, p, sc_link);
|
1993-11-18 05:03:27 +00:00
|
|
|
else
|
|
|
|
errcode = ENOTTY;
|
|
|
|
break;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-08-20 09:23:30 +00:00
|
|
|
return errcode;
|
1993-11-18 05:03:27 +00:00
|
|
|
/*-----------------------------*/
|
|
|
|
try_new_value:
|
|
|
|
/*
|
|
|
|
* Check that the mode being asked for is aggreeable to the
|
|
|
|
* drive. If not, put it back the way it was.
|
|
|
|
*/
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errcode = st_mode_select(unit, 0, NULL, 0)) ) { /* put back as it was */
|
1995-12-09 20:42:38 +00:00
|
|
|
printf("st%ld: Cannot set selected mode", unit);
|
1993-11-18 05:03:27 +00:00
|
|
|
st->density = hold_density;
|
|
|
|
st->blksiz = hold_blksiz;
|
|
|
|
if (st->blksiz) {
|
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
|
|
|
} else {
|
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
|
|
|
}
|
|
|
|
return (errcode);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* As the drive liked it, if we are setting a new default,
|
|
|
|
* set it into the structures as such.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-11-18 05:03:27 +00:00
|
|
|
* The means for deciding this are not finalised yet
|
|
|
|
*/
|
1995-01-08 13:38:38 +00:00
|
|
|
if (IS_CTLMODE(dev)) {
|
1993-11-18 05:03:27 +00:00
|
|
|
/* special mode */
|
|
|
|
/* XXX */
|
|
|
|
switch ((short) (mt->mt_op)) {
|
|
|
|
case MTSETBSIZ:
|
|
|
|
st->modes[dsty].blksiz = st->blksiz;
|
|
|
|
st->modeflags[dsty] |= BLKSIZE_SET_BY_USER;
|
|
|
|
break;
|
|
|
|
case MTSETDNSTY:
|
|
|
|
st->modes[dsty].density = st->density;
|
|
|
|
st->modeflags[dsty] |= DENSITY_SET_BY_USER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Do a synchronous read.
|
|
|
|
*/
|
1995-10-21 23:13:11 +00:00
|
|
|
static errval
|
1993-11-18 05:03:27 +00:00
|
|
|
st_read(unit, buf, size, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, size, flags;
|
1993-11-18 05:03:27 +00:00
|
|
|
char *buf;
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
1993-08-28 03:08:59 +00:00
|
|
|
struct scsi_rw_tape scsi_cmd;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* If it's a null transfer, return immediatly
|
|
|
|
*/
|
|
|
|
if (size == 0) {
|
|
|
|
return (ESUCCESS);
|
1993-08-28 03:08:59 +00:00
|
|
|
}
|
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
|
|
|
scsi_cmd.op_code = READ_COMMAND_TAPE;
|
1993-11-18 05:03:27 +00:00
|
|
|
if (st->flags & ST_FIXEDBLOCKS) {
|
|
|
|
scsi_cmd.byte2 |= SRWT_FIXED;
|
1995-01-31 11:41:47 +00:00
|
|
|
scsi_uto3b(size / (st->blksiz ? st->blksiz : DEF_FIXED_BSIZE),
|
1993-11-18 05:03:27 +00:00
|
|
|
scsi_cmd.len);
|
|
|
|
} else {
|
1995-01-31 11:41:47 +00:00
|
|
|
scsi_uto3b(size, scsi_cmd.len);
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
1995-03-01 22:24:47 +00:00
|
|
|
return (scsi_scsi_cmd(sc_link,
|
1993-11-18 05:03:27 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd),
|
|
|
|
(u_char *) buf,
|
|
|
|
size,
|
|
|
|
0, /* not on io commands */
|
|
|
|
100000,
|
|
|
|
NULL,
|
|
|
|
flags | SCSI_DATA_IN));
|
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
|
|
|
/*
|
|
|
|
* Ask the drive what it's min and max blk sizes are.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1993-06-12 14:58:17 +00:00
|
|
|
st_rd_blk_lim(unit, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, flags;
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
struct scsi_blk_limits scsi_cmd;
|
1993-06-12 14:58:17 +00:00
|
|
|
struct scsi_blk_limits_data scsi_blkl;
|
1993-11-18 05:03:27 +00:00
|
|
|
errval errno;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First check if we have it all loaded
|
|
|
|
*/
|
|
|
|
if ((sc_link->flags & SDEV_MEDIA_LOADED))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* do a 'Read Block Limits'
|
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
|
|
|
scsi_cmd.op_code = READ_BLK_LIMITS;
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* do the command, update the global values
|
|
|
|
*/
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errno = scsi_scsi_cmd(sc_link,
|
1993-11-18 05:03:27 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd),
|
|
|
|
(u_char *) & scsi_blkl,
|
|
|
|
sizeof(scsi_blkl),
|
|
|
|
ST_RETRIES,
|
|
|
|
5000,
|
|
|
|
NULL,
|
1995-04-14 15:10:44 +00:00
|
|
|
flags | SCSI_DATA_IN)) ) {
|
1993-08-28 03:08:59 +00:00
|
|
|
return errno;
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
st->blkmin = b2tol(scsi_blkl.min_length);
|
1995-01-31 11:41:47 +00:00
|
|
|
st->blkmax = scsi_3btou(&scsi_blkl.max_length_2);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3,
|
1995-04-14 15:10:44 +00:00
|
|
|
("(%ld <= blksiz <= %ld)\n", st->blkmin, st->blkmax));
|
1993-08-28 03:08:59 +00:00
|
|
|
return 0;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-07-29 11:49:13 +00:00
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* called from:
|
|
|
|
* attach
|
|
|
|
* open
|
|
|
|
* ioctl (to reset original blksize)
|
|
|
|
*/
|
1995-05-30 08:16:23 +00:00
|
|
|
static errval
|
1995-03-21 11:21:08 +00:00
|
|
|
st_mode_sense(unit, flags, page, pagelen, pagecode)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, flags;
|
1995-03-21 11:21:08 +00:00
|
|
|
struct tape_pages *page;
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t pagelen,pagecode;
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t dat_len;
|
1993-11-18 05:03:27 +00:00
|
|
|
errval errno;
|
|
|
|
struct scsi_mode_sense scsi_cmd;
|
1995-03-21 11:21:08 +00:00
|
|
|
struct {
|
1993-11-18 05:03:27 +00:00
|
|
|
struct scsi_mode_header header;
|
|
|
|
struct blk_desc blk_desc;
|
1995-03-21 11:21:08 +00:00
|
|
|
struct tape_pages page;
|
|
|
|
} dat;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
1995-03-21 11:21:08 +00:00
|
|
|
/* Tandberg tape drives returns page 00
|
|
|
|
* with the sense data, whether or not
|
|
|
|
* you want it( ie the don't like you
|
|
|
|
* saying you want anything less!!!!!
|
|
|
|
* They also expect page 00
|
|
|
|
* back when you issue a mode select
|
|
|
|
*/
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-07-09 08:14:24 +00:00
|
|
|
st->flags &= ~ST_SENSE_READ;
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
1995-03-21 11:21:08 +00:00
|
|
|
* Check if we need to use a default page..
|
1993-11-18 05:03:27 +00:00
|
|
|
*/
|
1995-03-21 11:21:08 +00:00
|
|
|
if ((st->quirks & ST_Q_NEEDS_PAGE_0) && (!page)) {
|
|
|
|
pagelen = PAGE_0_SENSE_DATA_SIZE;
|
|
|
|
page = (struct tape_pages *) st->saved_page0;
|
|
|
|
pagecode = 0;
|
1993-07-29 11:49:13 +00:00
|
|
|
}
|
1995-03-21 11:21:08 +00:00
|
|
|
/*
|
|
|
|
* Now work out the total dat size etc.
|
|
|
|
*/
|
|
|
|
dat_len = sizeof(struct scsi_mode_header)
|
|
|
|
+ sizeof(struct blk_desc)
|
|
|
|
+ (page ? pagelen : 0);
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
1995-05-30 08:16:23 +00:00
|
|
|
* Set up a mode sense
|
1993-11-18 05:03:27 +00:00
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
|
|
|
scsi_cmd.op_code = MODE_SENSE;
|
1995-03-21 11:21:08 +00:00
|
|
|
scsi_cmd.page = (u_char) pagecode;
|
|
|
|
scsi_cmd.length = dat_len;
|
1993-07-29 11:49:13 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
1995-05-30 08:16:23 +00:00
|
|
|
* do the command,
|
1995-03-21 11:21:08 +00:00
|
|
|
* use the results to set blksiz, numblks and density
|
1993-11-18 05:03:27 +00:00
|
|
|
* or if we need it as a template for the mode select
|
|
|
|
* store it away.
|
|
|
|
*/
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errno = scsi_scsi_cmd(sc_link,
|
1993-11-18 05:03:27 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd),
|
1995-03-21 11:21:08 +00:00
|
|
|
(u_char *) &dat,
|
|
|
|
dat_len,
|
1993-11-18 05:03:27 +00:00
|
|
|
ST_RETRIES,
|
|
|
|
5000,
|
|
|
|
NULL,
|
1995-04-14 15:10:44 +00:00
|
|
|
flags | SCSI_DATA_IN)) ) {
|
1993-08-28 03:08:59 +00:00
|
|
|
return errno;
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
1995-03-21 11:21:08 +00:00
|
|
|
st->numblks = scsi_3btou(dat.blk_desc.nblocks);
|
|
|
|
st->media_blksiz = scsi_3btou(dat.blk_desc.blklen);
|
|
|
|
st->media_density = dat.blk_desc.density;
|
|
|
|
if (dat.header.dev_spec & SMH_DSP_WRITE_PROT) {
|
1993-08-28 03:08:59 +00:00
|
|
|
st->flags |= ST_READONLY;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3,
|
1995-04-14 15:10:44 +00:00
|
|
|
("density code 0x%lx, %ld-byte blocks, write-%s, ",
|
1993-11-18 05:03:27 +00:00
|
|
|
st->media_density, st->media_blksiz,
|
|
|
|
st->flags & ST_READONLY ? "protected" : "enabled"));
|
1995-03-21 11:21:08 +00:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3, ("%sbuffered\n",
|
|
|
|
((dat.header.dev_spec & SMH_DSP_BUFF_MODE) ? "" : "un")));
|
|
|
|
if (page) {
|
|
|
|
bcopy(&dat.page, page, pagelen);
|
1993-07-29 11:49:13 +00:00
|
|
|
}
|
1995-07-09 08:14:24 +00:00
|
|
|
st->flags |= ST_SENSE_READ;
|
1993-08-28 03:08:59 +00:00
|
|
|
return 0;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Send a filled out parameter structure to the drive to
|
|
|
|
* set it into the desire modes etc.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1995-03-21 11:21:08 +00:00
|
|
|
st_mode_select(unit, flags, page, pagelen)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, flags;
|
1995-03-21 11:21:08 +00:00
|
|
|
struct tape_pages *page;
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t pagelen;
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t dat_len;
|
1993-06-12 14:58:17 +00:00
|
|
|
struct scsi_mode_select scsi_cmd;
|
1995-03-21 11:21:08 +00:00
|
|
|
struct {
|
1993-11-18 05:03:27 +00:00
|
|
|
struct scsi_mode_header header;
|
|
|
|
struct blk_desc blk_desc;
|
1995-03-21 11:21:08 +00:00
|
|
|
struct tape_pages page;
|
1993-11-18 05:03:27 +00:00
|
|
|
} dat;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
/*
|
1995-03-21 11:21:08 +00:00
|
|
|
* Check if we need to use a default page..
|
|
|
|
* Gee, hope we saved one before now........
|
1993-11-18 05:03:27 +00:00
|
|
|
*/
|
1995-03-21 11:21:08 +00:00
|
|
|
if ((st->quirks & ST_Q_NEEDS_PAGE_0) && (!page)) {
|
|
|
|
pagelen = PAGE_0_SENSE_DATA_SIZE;
|
|
|
|
page = (struct tape_pages *) st->saved_page0;
|
1993-07-29 11:49:13 +00:00
|
|
|
}
|
1995-03-21 11:21:08 +00:00
|
|
|
/*
|
|
|
|
* Now work out the total dat size etc.
|
|
|
|
*/
|
|
|
|
dat_len = sizeof(struct scsi_mode_header)
|
|
|
|
+ sizeof(struct blk_desc)
|
|
|
|
+ (page ? pagelen : 0);
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Set up for a mode select
|
|
|
|
*/
|
1995-03-21 11:21:08 +00:00
|
|
|
bzero(&dat, dat_len);
|
1993-06-12 14:58:17 +00:00
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
|
|
|
scsi_cmd.op_code = MODE_SELECT;
|
1993-07-29 11:49:13 +00:00
|
|
|
scsi_cmd.length = dat_len;
|
1995-03-21 11:21:08 +00:00
|
|
|
dat.header.blk_desc_len = sizeof(struct blk_desc);
|
|
|
|
dat.header.dev_spec |= SMH_DSP_BUFF_MODE_ON;
|
|
|
|
dat.blk_desc.density = st->density;
|
1993-11-18 05:03:27 +00:00
|
|
|
if (st->flags & ST_FIXEDBLOCKS) {
|
1995-03-21 11:21:08 +00:00
|
|
|
scsi_uto3b(st->blksiz, dat.blk_desc.blklen);
|
1993-07-29 11:49:13 +00:00
|
|
|
}
|
1995-03-21 11:21:08 +00:00
|
|
|
if (page) {
|
|
|
|
bcopy(page, &dat.page, pagelen);
|
1993-11-18 05:03:27 +00:00
|
|
|
/* the Tandberg tapes need the block size to */
|
|
|
|
/* be set on each mode sense/select. */
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* do the command
|
|
|
|
*/
|
1995-03-01 22:24:47 +00:00
|
|
|
return (scsi_scsi_cmd(sc_link,
|
1993-11-18 05:03:27 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd),
|
1995-03-21 11:21:08 +00:00
|
|
|
(u_char *) &dat,
|
1993-11-18 05:03:27 +00:00
|
|
|
dat_len,
|
|
|
|
ST_RETRIES,
|
|
|
|
5000,
|
|
|
|
NULL,
|
|
|
|
flags | SCSI_DATA_OUT));
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
1995-10-21 23:13:11 +00:00
|
|
|
static int noisy_st = 0;
|
1995-03-21 11:21:08 +00:00
|
|
|
/***************************************************************\
|
|
|
|
* Set the compression mode of the drive to on (1) or off (0) *
|
|
|
|
still doesn't work! grrr!
|
|
|
|
\***************************************************************/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
|
|
|
st_comp(unit,mode)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit,mode;
|
1995-03-21 11:21:08 +00:00
|
|
|
{
|
|
|
|
struct tape_pages page;
|
|
|
|
int pagesize;
|
|
|
|
int retval;
|
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
|
|
|
|
|
|
|
bzero(&page, sizeof(page));
|
|
|
|
pagesize = sizeof(page.pages.configuration) + PAGE_HEADERLEN;
|
|
|
|
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (retval = st_mode_sense(unit, 0,
|
|
|
|
&page, pagesize, ST_PAGE_CONFIGURATION)) )
|
1995-03-21 11:21:08 +00:00
|
|
|
{
|
|
|
|
printf("sense returned an error of %d\n",retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
if ( noisy_st)
|
1995-04-14 15:10:44 +00:00
|
|
|
printf("drive reports value of %d, setting %ld\n",
|
1995-03-21 11:21:08 +00:00
|
|
|
page.pages.configuration.data_compress_alg,mode);
|
|
|
|
|
|
|
|
page.pg_code &= ST_P_CODE;
|
|
|
|
page.pg_length = sizeof(page.pages.configuration);
|
|
|
|
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
page.pages.configuration.data_compress_alg = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
page.pages.configuration.data_compress_alg = 1;
|
|
|
|
break;
|
|
|
|
default:
|
1995-04-14 15:10:44 +00:00
|
|
|
printf("st%ld: bad value for compression mode\n",unit);
|
1995-03-21 11:21:08 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (retval = st_mode_select(unit, 0, &page, pagesize)) )
|
1995-03-21 11:21:08 +00:00
|
|
|
{
|
|
|
|
printf("select returned an error of %d\n",retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
st->comp = mode;
|
|
|
|
return 0;
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* skip N blocks/filemarks/seq filemarks/eom
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1993-11-18 05:03:27 +00:00
|
|
|
st_space(unit, number, what, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, what, flags;
|
|
|
|
int32_t number;
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
errval error;
|
1993-06-12 14:58:17 +00:00
|
|
|
struct scsi_space scsi_cmd;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1993-12-19 00:55:01 +00:00
|
|
|
switch ((int)what) {
|
1993-11-18 05:03:27 +00:00
|
|
|
case SP_BLKS:
|
|
|
|
if (st->flags & ST_PER_ACTION) {
|
|
|
|
if (number > 0) {
|
1993-09-07 15:58:00 +00:00
|
|
|
st->flags &= ~ST_PER_ACTION;
|
1993-11-18 05:03:27 +00:00
|
|
|
return (EIO);
|
|
|
|
} else if (number < 0) {
|
|
|
|
if (st->flags & ST_AT_FILEMARK) {
|
|
|
|
/*
|
|
|
|
* Handling of ST_AT_FILEMARK
|
|
|
|
* in st_space will fill in the
|
|
|
|
* right file mark count.
|
|
|
|
*/
|
1993-09-07 15:58:00 +00:00
|
|
|
error = st_space(unit, 0, SP_FILEMARKS,
|
|
|
|
flags);
|
1993-11-18 05:03:27 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
1993-09-07 15:58:00 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
if (st->flags & ST_BLANK_READ) {
|
1993-09-07 15:58:00 +00:00
|
|
|
st->flags &= ~ST_BLANK_READ;
|
1993-11-18 05:03:27 +00:00
|
|
|
return (EIO);
|
1993-09-07 15:58:00 +00:00
|
|
|
}
|
|
|
|
st->flags &= ~ST_EIO_PENDING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
case SP_FILEMARKS:
|
|
|
|
if (st->flags & ST_EIO_PENDING) {
|
|
|
|
if (number > 0) { /* pretend we just discover the error */
|
1993-09-07 15:58:00 +00:00
|
|
|
st->flags &= ~ST_EIO_PENDING;
|
1993-11-18 05:03:27 +00:00
|
|
|
return (EIO);
|
|
|
|
} else if (number < 0) { /* back away from the error */
|
1993-09-07 15:58:00 +00:00
|
|
|
st->flags &= ~ST_EIO_PENDING;
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
1993-09-07 15:58:00 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
if (st->flags & ST_AT_FILEMARK) {
|
1993-09-07 15:58:00 +00:00
|
|
|
st->flags &= ~ST_AT_FILEMARK;
|
|
|
|
number--;
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
if ((st->flags & ST_BLANK_READ) && (number < 0)) { /* back away from unwritten tape */
|
1993-09-07 15:58:00 +00:00
|
|
|
st->flags &= ~ST_BLANK_READ;
|
1993-11-18 05:03:27 +00:00
|
|
|
number++; /* dubious */
|
1993-09-07 15:58:00 +00:00
|
|
|
}
|
1995-04-29 21:30:29 +00:00
|
|
|
break;
|
|
|
|
case SP_EOM:
|
|
|
|
if (st->flags & ST_EIO_PENDING)
|
|
|
|
{
|
|
|
|
/* we are already at EOM */
|
|
|
|
st->flags &= ~ST_EIO_PENDING;
|
|
|
|
return(ESUCCESS);
|
|
|
|
}
|
|
|
|
number = 1; /* we have only one end-of-medium */
|
|
|
|
break;
|
1993-09-07 15:58:00 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
if (number == 0) {
|
|
|
|
return (ESUCCESS);
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
|
|
|
scsi_cmd.op_code = SPACE;
|
1993-08-20 09:23:30 +00:00
|
|
|
scsi_cmd.byte2 = what & SS_CODE;
|
1995-01-31 11:41:47 +00:00
|
|
|
scsi_uto3b(number, scsi_cmd.number);
|
1995-03-01 22:24:47 +00:00
|
|
|
return (scsi_scsi_cmd(sc_link,
|
1993-11-18 05:03:27 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0, /* no retries please , just fail */
|
1996-02-08 06:23:49 +00:00
|
|
|
3600000, /* wait up to an hour for completion */
|
1993-11-18 05:03:27 +00:00
|
|
|
NULL,
|
|
|
|
flags));
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* write N filemarks
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1993-11-18 05:03:27 +00:00
|
|
|
st_write_filemarks(unit, number, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, flags;
|
|
|
|
int32_t number;
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
struct scsi_write_filemarks scsi_cmd;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* It's hard to write a negative number of file marks.
|
|
|
|
* Don't try.
|
|
|
|
*/
|
|
|
|
if (number < 0) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
1993-12-19 00:55:01 +00:00
|
|
|
switch ((int)number) {
|
1993-11-18 05:03:27 +00:00
|
|
|
case 0: /* really a command to sync the drive's buffers */
|
1993-09-07 15:58:00 +00:00
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
case 1:
|
|
|
|
if (st->flags & ST_FM_WRITTEN) { /* already have one down */
|
1993-09-07 15:58:00 +00:00
|
|
|
st->flags &= ~ST_WRITTEN;
|
1993-11-18 05:03:27 +00:00
|
|
|
} else {
|
1993-09-07 15:58:00 +00:00
|
|
|
st->flags |= ST_FM_WRITTEN;
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
1993-09-07 15:58:00 +00:00
|
|
|
st->flags &= ~ST_PER_ACTION;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
st->flags &= ~(ST_PER_ACTION | ST_WRITTEN);
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
|
|
|
scsi_cmd.op_code = WRITE_FILEMARKS;
|
1995-01-31 11:41:47 +00:00
|
|
|
scsi_uto3b(number, scsi_cmd.number);
|
1995-03-01 22:24:47 +00:00
|
|
|
return scsi_scsi_cmd(sc_link,
|
1993-11-18 05:03:27 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0, /* no retries, just fail */
|
|
|
|
100000, /* 10 secs.. (may need to repos head ) */
|
|
|
|
NULL,
|
|
|
|
flags);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-09-07 15:58:00 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Make sure the right number of file marks is on tape if the
|
|
|
|
* tape has been written. If the position argument is true,
|
|
|
|
* leave the tape positioned where it was originally.
|
|
|
|
*
|
|
|
|
* nmarks returns the number of marks to skip (or, if position
|
|
|
|
* true, which were skipped) to get back original position.
|
|
|
|
*/
|
1996-03-10 07:13:15 +00:00
|
|
|
static int32_t
|
1993-09-07 15:58:00 +00:00
|
|
|
st_chkeod(unit, position, nmarks, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit;
|
1993-11-18 05:03:27 +00:00
|
|
|
boolean position;
|
1996-03-10 07:13:15 +00:00
|
|
|
int32_t *nmarks;
|
|
|
|
u_int32_t flags;
|
1993-09-07 15:58:00 +00:00
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
errval error;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *st = SCSI_DATA(&st_switch, unit);
|
1993-09-07 15:58:00 +00:00
|
|
|
|
1993-12-19 00:55:01 +00:00
|
|
|
switch ((int)(st->flags & (ST_WRITTEN | ST_FM_WRITTEN | ST_2FM_AT_EOD))) {
|
1993-09-07 15:58:00 +00:00
|
|
|
default:
|
|
|
|
*nmarks = 0;
|
1993-11-18 05:03:27 +00:00
|
|
|
return (ESUCCESS);
|
|
|
|
case ST_WRITTEN:
|
|
|
|
case ST_WRITTEN | ST_FM_WRITTEN | ST_2FM_AT_EOD:
|
1993-09-07 15:58:00 +00:00
|
|
|
*nmarks = 1;
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
case ST_WRITTEN | ST_2FM_AT_EOD:
|
1993-09-07 15:58:00 +00:00
|
|
|
*nmarks = 2;
|
|
|
|
}
|
|
|
|
error = st_write_filemarks(unit, *nmarks, flags);
|
1993-11-18 05:03:27 +00:00
|
|
|
if (position && (error == ESUCCESS))
|
1993-09-07 15:58:00 +00:00
|
|
|
error = st_space(unit, -*nmarks, SP_FILEMARKS, flags);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* load/unload (with retension if true)
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1993-11-18 05:03:27 +00:00
|
|
|
st_load(unit, type, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, type, flags;
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
struct scsi_load scsi_cmd;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
1993-11-18 05:03:27 +00:00
|
|
|
if (type != LD_LOAD) {
|
|
|
|
errval error;
|
1996-03-10 07:13:15 +00:00
|
|
|
int32_t nmarks;
|
1993-09-07 15:58:00 +00:00
|
|
|
|
|
|
|
error = st_chkeod(unit, FALSE, &nmarks, flags);
|
1993-11-18 05:03:27 +00:00
|
|
|
if (error != ESUCCESS)
|
|
|
|
return (error);
|
|
|
|
sc_link->flags &= ~SDEV_MEDIA_LOADED;
|
1993-09-07 15:58:00 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
if (st->quirks & ST_Q_IGNORE_LOADS)
|
|
|
|
return (0);
|
1993-09-07 15:58:00 +00:00
|
|
|
scsi_cmd.op_code = LOAD_UNLOAD;
|
|
|
|
scsi_cmd.how |= type;
|
1995-03-01 22:24:47 +00:00
|
|
|
return (scsi_scsi_cmd(sc_link,
|
1993-11-18 05:03:27 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
ST_RETRIES,
|
1996-01-14 16:29:01 +00:00
|
|
|
900000, /* 15 min */
|
1993-11-18 05:03:27 +00:00
|
|
|
NULL,
|
|
|
|
flags));
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-09-07 15:58:00 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Rewind the device
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1993-11-18 05:03:27 +00:00
|
|
|
st_rewind(unit, immed, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, flags;
|
1993-11-18 05:03:27 +00:00
|
|
|
boolean immed;
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
struct scsi_rewind scsi_cmd;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
1993-11-18 05:03:27 +00:00
|
|
|
errval error;
|
1996-03-10 07:13:15 +00:00
|
|
|
int32_t nmarks;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1993-09-07 15:58:00 +00:00
|
|
|
error = st_chkeod(unit, FALSE, &nmarks, flags);
|
1993-11-18 05:03:27 +00:00
|
|
|
if (error != ESUCCESS)
|
|
|
|
return (error);
|
1993-08-28 03:08:59 +00:00
|
|
|
st->flags &= ~ST_PER_ACTION;
|
1993-06-12 14:58:17 +00:00
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
|
|
|
scsi_cmd.op_code = REWIND;
|
1993-08-28 03:08:59 +00:00
|
|
|
scsi_cmd.byte2 = immed ? SR_IMMED : 0;
|
1995-03-01 22:24:47 +00:00
|
|
|
return (scsi_scsi_cmd(sc_link,
|
1993-11-18 05:03:27 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd),
|
1994-10-28 13:19:42 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
ST_RETRIES,
|
|
|
|
immed ? 5000 : 300000, /* 5 sec or 5 min */
|
|
|
|
NULL,
|
|
|
|
flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-04-29 21:30:29 +00:00
|
|
|
** Erase the device
|
1995-05-30 08:16:23 +00:00
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1994-10-28 13:19:42 +00:00
|
|
|
st_erase(unit, immed, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit, flags;
|
1994-10-28 13:19:42 +00:00
|
|
|
boolean immed;
|
|
|
|
{
|
|
|
|
struct scsi_erase scsi_cmd;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&st_switch, unit);
|
|
|
|
struct scsi_data *st = sc_link->sd;
|
1994-10-28 13:19:42 +00:00
|
|
|
errval error;
|
1996-03-10 07:13:15 +00:00
|
|
|
int32_t nmarks;
|
1994-10-28 13:19:42 +00:00
|
|
|
|
|
|
|
error = st_chkeod(unit, FALSE, &nmarks, flags);
|
|
|
|
if (error != ESUCCESS)
|
|
|
|
return (error);
|
|
|
|
/*
|
1995-04-29 21:30:29 +00:00
|
|
|
** Archive Viper 2525 technical manual 5.7 (ERASE 19h):
|
1994-10-28 13:19:42 +00:00
|
|
|
** tape has to be positioned to BOT first before erase command
|
|
|
|
** is issued or command is rejected. So we rewind the tape first
|
|
|
|
** and exit with an error, if the tape can't be rewinded.
|
|
|
|
*/
|
|
|
|
error = st_rewind(unit, FALSE, SCSI_SILENT);
|
|
|
|
if (error != ESUCCESS)
|
|
|
|
return (error);
|
|
|
|
st->flags &= ~ST_PER_ACTION;
|
|
|
|
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
|
|
|
scsi_cmd.op_code = ERASE;
|
1995-04-29 21:30:29 +00:00
|
|
|
scsi_cmd.byte2 = SE_LONG; /* LONG_ERASE */
|
1994-10-28 13:19:42 +00:00
|
|
|
scsi_cmd.byte2 += immed ? SE_IMMED : 0; /* immed bit is here the 2nd! */
|
1995-03-01 22:24:47 +00:00
|
|
|
return (scsi_scsi_cmd(sc_link,
|
1994-10-28 13:19:42 +00:00
|
|
|
(struct scsi_generic *) &scsi_cmd,
|
|
|
|
sizeof(scsi_cmd),
|
1993-11-18 05:03:27 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
ST_RETRIES,
|
1996-06-22 14:57:55 +00:00
|
|
|
immed ? 5000 : (200 * 60 * 1000), /* 5 sec or 200 min */
|
1993-11-18 05:03:27 +00:00
|
|
|
NULL,
|
|
|
|
flags));
|
1993-08-28 03:08:59 +00:00
|
|
|
}
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* Look at the returned sense and act on the error and detirmine
|
|
|
|
* The unix error number to pass back... (0 = report no error)
|
1995-01-08 13:38:38 +00:00
|
|
|
* (SCSIRET_CONTINUE = continue processing)
|
1993-11-18 05:03:27 +00:00
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1993-11-18 05:03:27 +00:00
|
|
|
st_interpret_sense(xs)
|
|
|
|
struct scsi_xfer *xs;
|
1993-08-28 03:08:59 +00:00
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
struct scsi_link *sc_link = xs->sc_link;
|
|
|
|
struct scsi_sense_data *sense = &(xs->sense);
|
|
|
|
boolean silent = xs->flags & SCSI_SILENT;
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit = sc_link->dev_unit;
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *st = SCSI_DATA(&st_switch, unit);
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t key;
|
|
|
|
int32_t info;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the sense fields and work out what code
|
|
|
|
*/
|
|
|
|
if (sense->error_code & SSD_ERRCODE_VALID) {
|
1996-03-10 07:13:15 +00:00
|
|
|
info = ntohl(*((int32_t *) sense->ext.extended.info));
|
1993-11-18 05:03:27 +00:00
|
|
|
} else {
|
1995-04-14 15:10:44 +00:00
|
|
|
if (st->flags & ST_FIXEDBLOCKS) {
|
|
|
|
info = xs->datalen / st->blksiz;
|
|
|
|
} else {
|
|
|
|
info = xs->datalen;
|
|
|
|
}
|
1993-08-28 03:08:59 +00:00
|
|
|
}
|
1996-06-24 04:54:32 +00:00
|
|
|
|
|
|
|
key = sense->ext.extended.flags & SSD_KEY;
|
|
|
|
|
|
|
|
if (((sense->error_code & SSD_ERRCODE) != 0x70)
|
|
|
|
|| (key == 0x7)) /* Media Write Protected */ {
|
1995-04-14 15:10:44 +00:00
|
|
|
return SCSIRET_CONTINUE;/* let the generic code handle it */
|
1993-08-28 03:08:59 +00:00
|
|
|
}
|
1995-04-14 15:10:44 +00:00
|
|
|
if(sense->ext.extended.flags & (SSD_EOM|SSD_FILEMARK|SSD_ILI)) {
|
|
|
|
if (st->flags & ST_FIXEDBLOCKS) {
|
|
|
|
xs->resid = info * st->blksiz;
|
|
|
|
xs->flags |= SCSI_RESID_VALID;
|
|
|
|
if (sense->ext.extended.flags & SSD_EOM) {
|
|
|
|
st->flags |= ST_EIO_PENDING;
|
1993-08-28 03:08:59 +00:00
|
|
|
}
|
1995-04-14 15:10:44 +00:00
|
|
|
if (sense->ext.extended.flags & SSD_FILEMARK) {
|
|
|
|
st->flags |= ST_AT_FILEMARK;
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
1995-04-14 15:10:44 +00:00
|
|
|
if (sense->ext.extended.flags & SSD_ILI) {
|
|
|
|
st->flags |= ST_EIO_PENDING;
|
|
|
|
if (sense->error_code & SSD_ERRCODE_VALID &&
|
|
|
|
!silent)
|
|
|
|
printf("st%ld: block wrong size"
|
|
|
|
", %ld blocks residual\n", unit
|
|
|
|
,info);
|
|
|
|
/*XXX*/ /* is this how it works ? */
|
|
|
|
/* check def of ILI for fixed blk tapes */
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-04-14 15:10:44 +00:00
|
|
|
/*
|
|
|
|
* This quirk code helps the drive read
|
|
|
|
* the first tape block, regardless of
|
|
|
|
* format. That is required for these
|
|
|
|
* drives to return proper MODE SENSE
|
|
|
|
* information.
|
|
|
|
*/
|
|
|
|
if ((st->quirks & ST_Q_SNS_HLP) &&
|
1995-07-09 08:14:24 +00:00
|
|
|
!(st->flags & ST_SENSE_READ)) {
|
1995-04-14 15:10:44 +00:00
|
|
|
st->blksiz -= 512;
|
|
|
|
}
|
1993-08-28 03:08:59 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
1995-04-14 15:10:44 +00:00
|
|
|
* If no data was tranfered, do it immediatly
|
1993-11-18 05:03:27 +00:00
|
|
|
*/
|
1995-04-14 15:10:44 +00:00
|
|
|
if (xs->resid >= xs->datalen) {
|
|
|
|
xs->flags &= ~SCSI_RESID_VALID;
|
|
|
|
if (st->flags & ST_AT_FILEMARK) {
|
|
|
|
xs->flags |= SCSI_EOF;
|
|
|
|
st->flags &= ~ST_AT_FILEMARK;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (st->flags & ST_EIO_PENDING) {
|
|
|
|
st->flags &= ~ST_EIO_PENDING;
|
|
|
|
return EIO;
|
1993-08-28 03:08:59 +00:00
|
|
|
}
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
return 0;
|
1995-04-14 15:10:44 +00:00
|
|
|
} else { /* must be variable mode */
|
|
|
|
xs->resid = xs->datalen; /* to be sure */
|
|
|
|
if (sense->ext.extended.flags & SSD_EOM) {
|
1993-11-18 05:03:27 +00:00
|
|
|
return (EIO);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1995-04-14 15:10:44 +00:00
|
|
|
if (sense->ext.extended.flags & SSD_FILEMARK) {
|
|
|
|
xs->flags |= SCSI_EOF;
|
|
|
|
}
|
|
|
|
if (sense->ext.extended.flags & SSD_ILI) {
|
|
|
|
if (info < 0) {
|
|
|
|
/*
|
|
|
|
* the record was bigger than the read
|
|
|
|
*/
|
|
|
|
if (!silent)
|
|
|
|
printf("st%ld: %ld-byte record "
|
|
|
|
"too big\n", unit,
|
|
|
|
xs->datalen - info);
|
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
xs->resid = info;
|
|
|
|
xs->flags |= SCSI_RESID_VALID;
|
1993-08-28 03:08:59 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
1995-04-14 15:10:44 +00:00
|
|
|
return 0;
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (key == 0x8) {
|
1995-04-14 15:10:44 +00:00
|
|
|
xs->flags |= SCSI_EOF; /* some drives need this */
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* This quirk code helps the drive read the
|
|
|
|
* first tape block, regardless of format. That
|
|
|
|
* is required for these drives to return proper
|
|
|
|
* MODE SENSE information.
|
|
|
|
*/
|
|
|
|
if ((st->quirks & ST_Q_SNS_HLP) &&
|
1995-07-09 08:14:24 +00:00
|
|
|
!(st->flags & ST_SENSE_READ)) {
|
1995-04-14 15:10:44 +00:00
|
|
|
/* still starting */
|
1993-11-18 05:03:27 +00:00
|
|
|
st->blksiz -= 512;
|
|
|
|
} else if (!(st->flags & (ST_2FM_AT_EOD | ST_BLANK_READ))) {
|
|
|
|
st->flags |= ST_BLANK_READ;
|
1995-04-14 15:10:44 +00:00
|
|
|
xs->flags |= SCSI_EOF;
|
1993-11-18 05:03:27 +00:00
|
|
|
return (ESUCCESS);
|
|
|
|
}
|
|
|
|
}
|
1995-04-14 15:10:44 +00:00
|
|
|
return SCSIRET_CONTINUE; /* Use the the generic handler */
|
1993-11-18 05:03:27 +00:00
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
/*
|
|
|
|
* The quirk here is that the drive returns some value to st_mode_sense
|
|
|
|
* incorrectly until the tape has actually passed by the head.
|
|
|
|
*
|
|
|
|
* The method is to set the drive to large fixed-block state (user-specified
|
|
|
|
* density and 1024-byte blocks), then read and rewind to get it to sense the
|
|
|
|
* tape. If that doesn't work, try 512-byte fixed blocks. If that doesn't
|
|
|
|
* work, as a last resort, try variable- length blocks. The result will be
|
|
|
|
* the ability to do an accurate st_mode_sense.
|
|
|
|
*
|
|
|
|
* We know we can do a rewind because we just did a load, which implies rewind.
|
|
|
|
* Rewind seems preferable to space backward if we have a virgin tape.
|
|
|
|
*
|
|
|
|
* The rest of the code for this quirk is in ILI processing and BLANK CHECK
|
|
|
|
* error processing, both part of st_interpret_sense.
|
|
|
|
*/
|
1995-12-08 11:19:42 +00:00
|
|
|
static errval
|
1993-11-18 05:03:27 +00:00
|
|
|
st_touch_tape(unit)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit;
|
1993-11-18 05:03:27 +00:00
|
|
|
{
|
1995-03-01 22:24:47 +00:00
|
|
|
struct scsi_data *st = SCSI_DATA(&st_switch, unit);
|
1993-11-18 05:03:27 +00:00
|
|
|
char *buf;
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t readsiz;
|
1993-11-18 05:03:27 +00:00
|
|
|
errval errno;
|
1993-09-05 15:42:22 +00:00
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
buf = malloc(1024, M_TEMP, M_NOWAIT);
|
|
|
|
if (!buf)
|
|
|
|
return (ENOMEM);
|
1993-09-05 15:42:22 +00:00
|
|
|
|
1995-04-14 15:10:44 +00:00
|
|
|
if (( errno = st_mode_sense(unit, 0, NULL, 0, 0)) ) {
|
1993-11-18 05:03:27 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
1996-02-03 13:31:13 +00:00
|
|
|
st->blksiz = (st->quirks & ST_Q_NO_1024)? 512: 1024;
|
1993-11-18 05:03:27 +00:00
|
|
|
do {
|
1993-12-19 00:55:01 +00:00
|
|
|
switch ((int)st->blksiz) {
|
1993-11-18 05:03:27 +00:00
|
|
|
case 512:
|
|
|
|
case 1024:
|
|
|
|
readsiz = st->blksiz;
|
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
|
|
|
break;
|
1993-09-05 15:42:22 +00:00
|
|
|
default:
|
1993-11-18 05:03:27 +00:00
|
|
|
readsiz = 1;
|
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
1995-04-14 15:10:44 +00:00
|
|
|
} if ( (errno = st_mode_select(unit, 0, NULL, 0)) ) {
|
1993-11-18 05:03:27 +00:00
|
|
|
goto bad;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
st_read(unit, buf, readsiz, SCSI_SILENT);
|
1995-04-14 15:10:44 +00:00
|
|
|
if ( (errno = st_rewind(unit, FALSE, 0)) ) {
|
1993-11-18 05:03:27 +00:00
|
|
|
bad: free(buf, M_TEMP);
|
|
|
|
return (errno);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
} while (readsiz != 1 && readsiz > st->blksiz);
|
|
|
|
free(buf, M_TEMP);
|
|
|
|
return 0;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
|
|
|
|
static st_devsw_installed = 0;
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static void
|
|
|
|
st_drvinit(void *unused)
|
1995-11-29 10:49:16 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if( ! st_devsw_installed ) {
|
1996-07-23 21:52:43 +00:00
|
|
|
bdevsw_add_generic(BDEV_MAJOR, CDEV_MAJOR, &st_bdevsw);
|
1995-11-29 10:49:16 +00:00
|
|
|
st_devsw_installed = 1;
|
1995-11-29 14:41:20 +00:00
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(stdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,st_drvinit,NULL)
|
|
|
|
|
|
|
|
|