1994-12-30 08:23:49 +03:00
|
|
|
/* $NetBSD: st.c,v 1.46 1994/12/30 05:23:49 mycroft Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* Copyright (c) 1994 Charles Hannum. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Charles Hannum.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Originally written by Julian Elischer (julian@tfs.com)
|
1993-03-21 21:04:42 +03: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.
|
1993-05-20 07:46:09 +04:00
|
|
|
*
|
1994-03-29 08:29:20 +04:00
|
|
|
* Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
|
|
|
|
* major changes by Julian Elischer (julian@jules.dialix.oz.au) May 1993
|
1993-03-21 21:04:42 +03: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.
|
|
|
|
*/
|
|
|
|
|
1993-12-17 10:56:32 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1994-03-29 08:29:20 +04:00
|
|
|
#include <sys/fcntl.h>
|
1993-12-17 10:56:32 +03:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
1994-03-29 08:29:20 +04:00
|
|
|
#include <sys/malloc.h>
|
1993-12-17 10:56:32 +03:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/mtio.h>
|
1994-03-29 08:29:20 +04:00
|
|
|
#include <sys/device.h>
|
1993-12-17 10:56:32 +03:00
|
|
|
|
|
|
|
#include <scsi/scsi_all.h>
|
|
|
|
#include <scsi/scsi_tape.h>
|
|
|
|
#include <scsi/scsiconf.h>
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/* Defines for device specific stuff */
|
|
|
|
#define DEF_FIXED_BSIZE 512
|
|
|
|
#define ST_RETRIES 4 /* only on non IO commands */
|
1993-06-16 07:39:30 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
#define STMODE(z) ( minor(z) & 0x03)
|
|
|
|
#define STDSTY(z) ((minor(z) >> 2) & 0x03)
|
|
|
|
#define STUNIT(z) ((minor(z) >> 4) )
|
|
|
|
#define CTLMODE 3
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
#define SCSI_2_MAX_DENSITY_CODE 0x17 /* maximum density code specified
|
|
|
|
* in SCSI II spec. */
|
|
|
|
/*
|
|
|
|
* Define various devices that we know mis-behave in some way,
|
|
|
|
* and note how they are bad, so we can correct for them
|
|
|
|
*/
|
|
|
|
struct modes {
|
1994-12-28 22:42:47 +03:00
|
|
|
u_int quirks; /* same definitions as in quirkdata */
|
|
|
|
int blksize;
|
|
|
|
u_int8_t density;
|
1994-03-29 08:29:20 +04:00
|
|
|
};
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
struct quirkdata {
|
|
|
|
u_int quirks;
|
|
|
|
#define ST_Q_FORCE_BLKSIZE 0x0001
|
|
|
|
#define ST_Q_SENSE_HELP 0x0002 /* must do READ for good MODE SENSE */
|
|
|
|
#define ST_Q_IGNORE_LOADS 0x0004
|
|
|
|
#define ST_Q_BLKSIZE 0x0008 /* variable-block media_blksize > 0 */
|
1994-08-09 22:50:17 +04:00
|
|
|
u_int page_0_size;
|
|
|
|
#define MAX_PAGE_0_SIZE 64
|
1994-03-29 08:29:20 +04:00
|
|
|
struct modes modes[4];
|
|
|
|
};
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_quirk_inquiry_pattern {
|
|
|
|
struct scsi_inquiry_pattern pattern;
|
|
|
|
struct quirkdata quirkdata;
|
|
|
|
};
|
1994-03-29 08:29:20 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_quirk_inquiry_pattern st_quirk_patterns[] = {
|
|
|
|
{T_SEQUENTIAL, T_REMOV,
|
1994-12-30 08:23:49 +03:00
|
|
|
" ", " ", " ", 0, 0, {
|
1994-12-28 22:42:47 +03:00
|
|
|
ST_Q_FORCE_BLKSIZE, 512, 0, /* minor 0-3 */
|
|
|
|
ST_Q_FORCE_BLKSIZE, 512, QIC_24, /* minor 4-7 */
|
|
|
|
ST_Q_FORCE_BLKSIZE, 0, HALFINCH_1600, /* minor 8-11 */
|
|
|
|
ST_Q_FORCE_BLKSIZE, 0, HALFINCH_6250 /* minor 12-15 */
|
|
|
|
}},
|
|
|
|
{T_SEQUENTIAL, T_REMOV,
|
|
|
|
"TANDBERG", " TDC 3600 ", "", 0, 12, {
|
|
|
|
0, 0, 0, /* minor 0-3 */
|
|
|
|
ST_Q_FORCE_BLKSIZE, 0, QIC_525, /* minor 4-7 */
|
|
|
|
0, 0, QIC_150, /* minor 8-11 */
|
|
|
|
0, 0, QIC_120 /* minor 12-15 */
|
|
|
|
}},
|
|
|
|
/*
|
|
|
|
* At least -005 and -007 need this. I'll assume they all do unless I
|
|
|
|
* hear otherwise. - mycroft, 31MAR1994
|
|
|
|
*/
|
|
|
|
{T_SEQUENTIAL, T_REMOV,
|
|
|
|
"ARCHIVE ", "VIPER 2525 25462", "", 0, 0, {
|
|
|
|
ST_Q_SENSE_HELP, 0, 0, /* minor 0-3 */
|
|
|
|
ST_Q_SENSE_HELP, 0, QIC_525, /* minor 4-7 */
|
|
|
|
0, 0, QIC_150, /* minor 8-11 */
|
|
|
|
0, 0, QIC_120 /* minor 12-15 */
|
|
|
|
}},
|
|
|
|
/*
|
|
|
|
* One user reports that this works for his tape drive. It probably
|
|
|
|
* needs more work. - mycroft, 09APR1994
|
|
|
|
*/
|
|
|
|
{T_SEQUENTIAL, T_REMOV,
|
|
|
|
"SANKYO ", "CP525 ", "", 0, 0, {
|
|
|
|
ST_Q_FORCE_BLKSIZE, 512, 0, /* minor 0-3 */
|
|
|
|
ST_Q_FORCE_BLKSIZE, 512, QIC_525, /* minor 4-7 */
|
|
|
|
0, 0, QIC_150, /* minor 8-11 */
|
|
|
|
0, 0, QIC_120 /* minor 12-15 */
|
|
|
|
}},
|
|
|
|
{T_SEQUENTIAL, T_REMOV,
|
|
|
|
"ARCHIVE ", "VIPER 150 21247", "", 0, 12, {
|
|
|
|
0, 0, 0, /* minor 0-3 */
|
|
|
|
0, 0, QIC_150, /* minor 4-7 */
|
|
|
|
0, 0, QIC_120, /* minor 8-11 */
|
|
|
|
0, 0, QIC_24 /* minor 12-15 */
|
|
|
|
}},
|
|
|
|
{T_SEQUENTIAL, T_REMOV,
|
|
|
|
"WANGTEK ", "5525ES SCSI REV7", "", 0, 0, {
|
|
|
|
0, 0, 0, /* minor 0-3 */
|
|
|
|
ST_Q_BLKSIZE, 0, QIC_525, /* minor 4-7 */
|
|
|
|
0, 0, QIC_150, /* minor 8-11 */
|
|
|
|
0, 0, QIC_120 /* minor 12-15 */
|
|
|
|
}},
|
|
|
|
{T_SEQUENTIAL, T_REMOV,
|
|
|
|
"WangDAT ", "Model 1300 ", "", 0, 0, {
|
|
|
|
0, 0, 0, /* minor 0-3 */
|
|
|
|
ST_Q_FORCE_BLKSIZE, 512, DDS, /* minor 4-7 */
|
|
|
|
ST_Q_FORCE_BLKSIZE, 1024, DDS, /* minor 8-11 */
|
|
|
|
ST_Q_FORCE_BLKSIZE, 0, DDS /* minor 12-15 */
|
|
|
|
}},
|
1994-08-09 22:50:17 +04:00
|
|
|
#if 0
|
1994-12-28 22:42:47 +03:00
|
|
|
{T_SEQUENTIAL, T_REMOV,
|
|
|
|
"EXABYTE ", "EXB-8200 ", "", 0, 12, {
|
|
|
|
0, 0, 0, /* minor 0-3 */
|
|
|
|
0, 0, 0, /* minor 4-7 */
|
|
|
|
0, 0, 0, /* minor 8-11 */
|
|
|
|
0, 0, 0 /* minor 12-15 */
|
|
|
|
}},
|
1994-08-09 22:50:17 +04:00
|
|
|
#endif
|
1994-03-29 08:29:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NOEJECT 0
|
|
|
|
#define EJECT 1
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc {
|
1994-03-29 08:29:20 +04:00
|
|
|
struct device sc_dev;
|
|
|
|
/*--------------------present operating parameters, flags etc.----------------*/
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags; /* see below */
|
1994-03-29 08:29:20 +04:00
|
|
|
u_int quirks; /* quirks for the open mode */
|
1994-12-28 22:42:47 +03:00
|
|
|
int blksize; /* blksize we are using */
|
|
|
|
u_int8_t density; /* present density */
|
1994-08-09 22:50:17 +04:00
|
|
|
u_int page_0_size; /* size of page 0 data */
|
1994-12-28 22:42:47 +03:00
|
|
|
u_int last_dsty; /* last density opened */
|
1994-03-29 08:29:20 +04:00
|
|
|
/*--------------------device/scsi parameters----------------------------------*/
|
|
|
|
struct scsi_link *sc_link; /* our link to the adpter etc. */
|
|
|
|
/*--------------------parameters reported by the device ----------------------*/
|
1994-12-28 22:42:47 +03:00
|
|
|
int blkmin; /* min blk size */
|
|
|
|
int blkmax; /* max blk size */
|
|
|
|
struct quirkdata *quirkdata; /* if we have a rogue entry */
|
1994-03-29 08:29:20 +04:00
|
|
|
/*--------------------parameters reported by the device for this media--------*/
|
1994-12-28 22:42:47 +03:00
|
|
|
u_long numblks; /* nominal blocks capacity */
|
|
|
|
int media_blksize; /* 0 if not ST_FIXEDBLOCKS */
|
|
|
|
u_int8_t media_density; /* this is what it said when asked */
|
1994-03-29 08:29:20 +04:00
|
|
|
/*--------------------quirks for the whole drive------------------------------*/
|
|
|
|
u_int drive_quirks; /* quirks of this drive */
|
1994-12-28 22:42:47 +03:00
|
|
|
/*--------------------How we should set up when opening each minor device----*/
|
1994-03-29 08:29:20 +04:00
|
|
|
struct modes modes[4]; /* plus more for each mode */
|
1994-12-28 22:42:47 +03:00
|
|
|
u_int8_t modeflags[4]; /* flags for the modes */
|
1994-03-29 08:29:20 +04: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
|
|
|
|
/*--------------------storage for sense data returned by the drive------------*/
|
1994-08-09 22:50:17 +04:00
|
|
|
u_char sense_data[MAX_PAGE_0_SIZE]; /*
|
|
|
|
* additional sense data needed
|
|
|
|
* for mode sense/select.
|
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
struct buf buf_queue; /* the queue of pending IO operations */
|
|
|
|
};
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
int stmatch __P((struct device *, void *, void *));
|
1994-03-29 08:29:20 +04:00
|
|
|
void stattach __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
struct cfdriver stcd = {
|
1994-12-28 22:42:47 +03:00
|
|
|
NULL, "st", stmatch, stattach, DV_TAPE, sizeof(struct st_softc)
|
1994-03-29 08:29:20 +04:00
|
|
|
};
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
int st_space __P((struct st_softc *, int number, u_int what, int flags));
|
|
|
|
int st_rewind __P((struct st_softc *, u_int immediate, int flags));
|
|
|
|
int st_mode_sense __P((struct st_softc *, int flags));
|
|
|
|
int st_decide_mode __P((struct st_softc *, boolean first_read));
|
|
|
|
int st_read_block_limits __P((struct st_softc *, int flags));
|
|
|
|
int st_touch_tape __P((struct st_softc *));
|
|
|
|
int st_write_filemarks __P((struct st_softc *, int number, int flags));
|
|
|
|
int st_load __P((struct st_softc *, u_int type, int flags));
|
|
|
|
int st_mode_select __P((struct st_softc *, int flags));
|
1994-03-29 08:29:20 +04:00
|
|
|
void ststrategy();
|
|
|
|
void stminphys();
|
1994-04-13 09:43:19 +04:00
|
|
|
int st_check_eod();
|
1994-03-29 08:29:20 +04:00
|
|
|
void ststart();
|
|
|
|
void st_unmount();
|
|
|
|
int st_mount_tape();
|
|
|
|
void st_loadquirks();
|
|
|
|
void st_identify_drive();
|
|
|
|
int st_interpret_sense();
|
|
|
|
|
|
|
|
struct scsi_device st_switch = {
|
|
|
|
st_interpret_sense,
|
|
|
|
ststart,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
1994-11-21 14:28:47 +03:00
|
|
|
#define ST_INFO_VALID 0x0001
|
|
|
|
#define ST_BLOCK_SET 0x0002 /* block size, mode set by ioctl */
|
|
|
|
#define ST_WRITTEN 0x0004 /* data have been written, EOD needed */
|
|
|
|
#define ST_FIXEDBLOCKS 0x0008
|
|
|
|
#define ST_AT_FILEMARK 0x0010
|
|
|
|
#define ST_EIO_PENDING 0x0020 /* we couldn't report it then (had data) */
|
|
|
|
#define ST_NEW_MOUNT 0x0040 /* still need to decide mode */
|
|
|
|
#define ST_READONLY 0x0080 /* st_mode_sense says write protected */
|
|
|
|
#define ST_FM_WRITTEN 0x0100 /*
|
1994-03-29 08:29:20 +04:00
|
|
|
* EOF file mark written -- used with
|
|
|
|
* ~ST_WRITTEN to indicate that multiple file
|
|
|
|
* marks have been written
|
|
|
|
*/
|
1994-11-21 14:28:47 +03:00
|
|
|
#define ST_BLANK_READ 0x0200 /* BLANK CHECK encountered already */
|
|
|
|
#define ST_2FM_AT_EOD 0x0400 /* write 2 file marks at EOD */
|
|
|
|
#define ST_MOUNTED 0x0800 /* Device is presently mounted */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
#define ST_PER_ACTION (ST_AT_FILEMARK | ST_EIO_PENDING | ST_BLANK_READ)
|
|
|
|
#define ST_PER_MOUNT (ST_INFO_VALID | ST_BLOCK_SET | ST_WRITTEN | \
|
1994-12-28 22:42:47 +03:00
|
|
|
ST_FIXEDBLOCKS | ST_READONLY | ST_FM_WRITTEN | \
|
|
|
|
ST_2FM_AT_EOD | ST_PER_ACTION)
|
|
|
|
|
|
|
|
struct scsi_inquiry_pattern st_patterns[] = {
|
|
|
|
{T_SEQUENTIAL, T_REMOV,
|
|
|
|
"", "", ""},
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
stmatch(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
void *match, *aux;
|
|
|
|
{
|
|
|
|
struct cfdata *cf = match;
|
|
|
|
struct scsibus_attach_args *sa = aux;
|
|
|
|
int priority;
|
|
|
|
|
|
|
|
(void)scsi_inqmatch(sa->sa_inqbuf,
|
|
|
|
(caddr_t)st_patterns, sizeof(st_patterns)/sizeof(st_patterns[0]),
|
|
|
|
sizeof(st_patterns[0]), &priority);
|
|
|
|
return (priority);
|
|
|
|
}
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The routine called by the low level scsi routine when it discovers
|
|
|
|
* A device suitable for this driver
|
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
void
|
|
|
|
stattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st = (void *)self;
|
|
|
|
struct scsibus_attach_args *sa = aux;
|
|
|
|
struct scsi_link *sc_link = sa->sa_sc_link;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB2, ("stattach: "));
|
1993-04-12 12:19:28 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* Store information needed to contact our base driver
|
|
|
|
*/
|
|
|
|
st->sc_link = sc_link;
|
1994-12-28 22:42:47 +03:00
|
|
|
sc_link->device = &st_switch;
|
|
|
|
sc_link->device_softc = st;
|
|
|
|
sc_link->openings = 1;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* Check if the drive is a known criminal and take
|
|
|
|
* Any steps needed to bring it into line
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
st_identify_drive(st, sa->sa_inqbuf);
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use the subdriver to request information regarding
|
|
|
|
* the drive. We cannot use interrupts yet, so the
|
|
|
|
* request must specify this.
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
printf(": %s", st->quirkdata ? "rogue, " : "");
|
|
|
|
if (scsi_test_unit_ready(sc_link,
|
|
|
|
SCSI_AUTOCONF | SCSI_SILENT | SCSI_IGNORE_MEDIA_CHANGE) ||
|
|
|
|
st_mode_sense(st,
|
|
|
|
SCSI_AUTOCONF | SCSI_SILENT | SCSI_IGNORE_MEDIA_CHANGE))
|
1994-03-29 08:29:20 +04:00
|
|
|
printf("drive empty\n");
|
|
|
|
else {
|
|
|
|
printf("density code 0x%x, ", st->media_density);
|
1994-12-28 22:42:47 +03:00
|
|
|
if (st->media_blksize > 0)
|
|
|
|
printf("%d-byte", st->media_blksize);
|
1994-03-29 08:29:20 +04:00
|
|
|
else
|
|
|
|
printf("variable");
|
|
|
|
printf(" blocks, write-%s\n",
|
|
|
|
(st->flags & ST_READONLY) ? "protected" : "enabled");
|
|
|
|
}
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* Set up the buf queue for this device
|
1993-04-12 12:19:28 +04:00
|
|
|
*/
|
|
|
|
st->buf_queue.b_active = 0;
|
|
|
|
st->buf_queue.b_actf = 0;
|
1994-02-06 11:01:45 +03:00
|
|
|
st->buf_queue.b_actb = &st->buf_queue.b_actf;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* Use the inquiry routine in 'scsi_base' to get drive info so we can
|
|
|
|
* Further tailor our behaviour.
|
|
|
|
*/
|
|
|
|
void
|
1994-12-28 22:42:47 +03:00
|
|
|
st_identify_drive(st, inqbuf)
|
|
|
|
struct st_softc *st;
|
|
|
|
struct scsi_inquiry_data *inqbuf;
|
1994-03-29 08:29:20 +04:00
|
|
|
{
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_quirk_inquiry_pattern *finger;
|
|
|
|
int priority;
|
|
|
|
|
|
|
|
finger = (struct st_quirk_inquiry_pattern *)scsi_inqmatch(inqbuf,
|
|
|
|
(caddr_t)st_quirk_patterns,
|
|
|
|
sizeof(st_quirk_patterns)/sizeof(st_quirk_patterns[0]),
|
|
|
|
sizeof(st_quirk_patterns[0]), &priority);
|
|
|
|
if (priority != 0) {
|
|
|
|
st->quirkdata = &finger->quirkdata;
|
|
|
|
st->drive_quirks = finger->quirkdata.quirks;
|
|
|
|
st->quirks = finger->quirkdata.quirks; /* start value */
|
|
|
|
st->page_0_size = finger->quirkdata.page_0_size;
|
|
|
|
st_loadquirks(st);
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialise the subdevices to the default (QUIRK) state.
|
|
|
|
* this will remove any setting made by the system operator or previous
|
|
|
|
* operations.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
st_loadquirks(st)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-03-29 08:29:20 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct modes *mode;
|
|
|
|
struct modes *mode2;
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
mode = st->quirkdata->modes;
|
1994-03-29 08:29:20 +04:00
|
|
|
mode2 = st->modes;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
bzero(mode2, sizeof(struct modes));
|
|
|
|
st->modeflags[i] &= ~(BLKSIZE_SET_BY_QUIRK |
|
|
|
|
DENSITY_SET_BY_QUIRK | BLKSIZE_SET_BY_USER |
|
|
|
|
DENSITY_SET_BY_USER);
|
1994-12-28 22:42:47 +03:00
|
|
|
if ((mode->quirks | st->drive_quirks) & ST_Q_FORCE_BLKSIZE) {
|
|
|
|
mode2->blksize = mode->blksize;
|
1994-03-29 08:29:20 +04:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
stopen(dev, flags)
|
|
|
|
dev_t dev;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1994-03-29 08:29:20 +04:00
|
|
|
{
|
|
|
|
int unit;
|
|
|
|
u_int mode, dsty;
|
|
|
|
int error = 0;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_link *sc_link;
|
|
|
|
|
|
|
|
unit = STUNIT(dev);
|
|
|
|
if (unit >= stcd.cd_ndevs)
|
1993-04-12 16:10:28 +04:00
|
|
|
return ENXIO;
|
1994-03-29 08:29:20 +04:00
|
|
|
st = stcd.cd_devs[unit];
|
1994-04-11 07:53:58 +04:00
|
|
|
if (!st)
|
1993-04-12 16:10:28 +04:00
|
|
|
return ENXIO;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
1994-11-21 14:28:47 +03:00
|
|
|
mode = STMODE(dev);
|
|
|
|
dsty = STDSTY(dev);
|
1994-03-29 08:29:20 +04:00
|
|
|
sc_link = st->sc_link;
|
1994-11-21 14:28:47 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB1, ("open: dev=0x%x (unit %d (of %d))\n", dev,
|
|
|
|
unit, stcd.cd_ndevs));
|
|
|
|
|
1994-11-21 14:28:47 +03:00
|
|
|
/*
|
|
|
|
* Only allow one at a time
|
|
|
|
*/
|
|
|
|
if (sc_link->flags & SDEV_OPEN) {
|
|
|
|
printf("%s: already open\n", st->sc_dev.dv_xname);
|
1994-03-29 08:29:20 +04:00
|
|
|
return EBUSY;
|
1994-11-21 14:28:47 +03:00
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
1994-11-21 14:28:47 +03:00
|
|
|
* Catch any unit attention errors.
|
1993-04-12 12:19:28 +04:00
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
if (error = scsi_test_unit_ready(sc_link,
|
|
|
|
SCSI_IGNORE_MEDIA_CHANGE | (mode == CTLMODE ? SCSI_IGNORE_NOT_READY : 0)))
|
|
|
|
goto bad;
|
1994-03-29 08:29:20 +04:00
|
|
|
|
|
|
|
sc_link->flags |= SDEV_OPEN; /* unit attn are now errors */
|
1994-11-21 14:28:47 +03:00
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* If the mode is 3 (e.g. minor = 3,7,11,15)
|
1994-12-28 22:42:47 +03:00
|
|
|
* then the device has been opened to set defaults
|
1994-03-29 08:29:20 +04:00
|
|
|
* This mode does NOT ALLOW I/O, only ioctls
|
1993-04-12 12:19:28 +04:00
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
if (mode == CTLMODE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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(st, NOEJECT);
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* If we are not mounted, then we should start a new
|
|
|
|
* mount session.
|
1993-04-12 12:19:28 +04:00
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
if (!(st->flags & ST_MOUNTED)) {
|
|
|
|
st_mount_tape(dev, flags);
|
|
|
|
st->last_dsty = dsty;
|
1993-04-12 12:19:28 +04:00
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
1994-03-29 08:29:20 +04: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-04-12 12:19:28 +04:00
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
if ((flags & O_ACCMODE) == FWRITE)
|
|
|
|
st->flags |= ST_WRITTEN;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-11-21 14:28:47 +03:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB2, ("open complete\n"));
|
1994-03-29 08:29:20 +04:00
|
|
|
return 0;
|
1994-11-21 14:28:47 +03:00
|
|
|
|
|
|
|
bad:
|
1994-12-28 22:42:47 +03:00
|
|
|
st_unmount(st, NOEJECT);
|
1994-11-21 14:28:47 +03:00
|
|
|
sc_link->flags &= ~SDEV_OPEN;
|
|
|
|
return error;
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* close the device.. only called if we are the LAST
|
|
|
|
* occurence of an open device
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
stclose(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st = stcd.cd_devs[STUNIT(dev)];
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-11-21 14:28:47 +03:00
|
|
|
SC_DEBUG(st->sc_link, SDEV_DB1, ("closing\n"));
|
1994-03-29 08:29:20 +04:00
|
|
|
if ((st->flags & (ST_WRITTEN | ST_FM_WRITTEN)) == ST_WRITTEN)
|
|
|
|
st_write_filemarks(st, 1, 0);
|
1994-11-21 14:28:47 +03:00
|
|
|
switch (STMODE(dev)) {
|
1994-03-29 08:29:20 +04:00
|
|
|
case 0:
|
|
|
|
case 3: /* for now */
|
|
|
|
st_unmount(st, NOEJECT);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* leave mounted unless media seems to have been removed */
|
1994-11-21 14:28:47 +03:00
|
|
|
if (!(st->sc_link->flags & SDEV_MEDIA_LOADED))
|
1994-03-29 08:29:20 +04:00
|
|
|
st_unmount(st, NOEJECT);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
st_unmount(st, EJECT);
|
|
|
|
break;
|
|
|
|
}
|
1994-11-21 14:28:47 +03:00
|
|
|
st->sc_link->flags &= ~SDEV_OPEN;
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
return 0;
|
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
st_mount_tape(dev, flags)
|
|
|
|
dev_t dev;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1994-03-29 08:29:20 +04:00
|
|
|
{
|
|
|
|
int unit;
|
|
|
|
u_int mode, dsty;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_link *sc_link;
|
|
|
|
int error = 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
unit = STUNIT(dev);
|
|
|
|
mode = STMODE(dev);
|
|
|
|
dsty = STDSTY(dev);
|
|
|
|
st = stcd.cd_devs[unit];
|
|
|
|
sc_link = st->sc_link;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
if (st->flags & ST_MOUNTED)
|
|
|
|
return 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
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.)
|
|
|
|
*/
|
|
|
|
if (error = st_load(st, LD_LOAD, 0))
|
|
|
|
return error;
|
|
|
|
/*
|
|
|
|
* Throw another dummy instruction to catch
|
|
|
|
* 'Unit attention' errors. Some drives appear to give
|
|
|
|
* these after doing a Load instruction.
|
|
|
|
* (noteably some DAT drives)
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
scsi_test_unit_ready(sc_link, SCSI_SILENT); /* XXX */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* Some devices can't tell you much until they have been
|
|
|
|
* asked to look at the media. This quirk does this.
|
|
|
|
*/
|
1994-04-13 09:43:19 +04:00
|
|
|
if (st->quirks & ST_Q_SENSE_HELP)
|
1994-03-29 08:29:20 +04:00
|
|
|
if (error = st_touch_tape(st))
|
|
|
|
return error;
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
|
|
|
* Load the physical device parameters
|
1994-03-29 08:29:20 +04:00
|
|
|
* loads: blkmin, blkmax
|
1993-04-12 12:19:28 +04:00
|
|
|
*/
|
1994-04-13 09:43:19 +04:00
|
|
|
if (error = st_read_block_limits(st, 0))
|
1994-03-29 08:29:20 +04:00
|
|
|
return error;
|
|
|
|
/*
|
|
|
|
* Load the media dependent parameters
|
1994-12-28 22:42:47 +03:00
|
|
|
* includes: media_blksize,media_density,numblks
|
1994-03-29 08:29:20 +04:00
|
|
|
* As we have a tape in, it should be reflected here.
|
|
|
|
* If not you may need the "quirk" above.
|
|
|
|
*/
|
|
|
|
if (error = st_mode_sense(st, 0))
|
|
|
|
return error;
|
|
|
|
/*
|
|
|
|
* 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)) {
|
1994-12-28 22:42:47 +03:00
|
|
|
st->blksize = st->modes[dsty].blksize;
|
|
|
|
if (st->blksize)
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
|
|
|
} else {
|
|
|
|
if (error = st_decide_mode(st, FALSE))
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if (error = st_mode_select(st, 0)) {
|
|
|
|
printf("%s: cannot set selected mode\n", st->sc_dev.dv_xname);
|
|
|
|
return error;
|
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
scsi_prevent(sc_link, PR_PREVENT,
|
|
|
|
SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_NOT_READY);
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags &= ~ST_NEW_MOUNT;
|
|
|
|
st->flags |= ST_MOUNTED;
|
|
|
|
sc_link->flags |= SDEV_MEDIA_LOADED; /* move earlier? */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
return 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* 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(st, eject)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-03-29 08:29:20 +04:00
|
|
|
boolean eject;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_link *sc_link = st->sc_link;
|
|
|
|
int nmarks;
|
|
|
|
|
|
|
|
if (!(st->flags & ST_MOUNTED))
|
|
|
|
return;
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB1, ("unmounting\n"));
|
1994-12-28 22:42:47 +03:00
|
|
|
st_check_eod(st, FALSE, &nmarks, SCSI_IGNORE_NOT_READY);
|
|
|
|
st_rewind(st, 0, SCSI_IGNORE_NOT_READY);
|
|
|
|
scsi_prevent(sc_link, PR_ALLOW,
|
|
|
|
SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_NOT_READY);
|
1994-03-29 08:29:20 +04:00
|
|
|
if (eject)
|
1994-12-28 22:42:47 +03:00
|
|
|
st_load(st, LD_UNLOAD, SCSI_IGNORE_NOT_READY);
|
1994-03-29 08:29:20 +04:00
|
|
|
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)
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
st_decide_mode(st, first_read)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-03-29 08:29:20 +04:00
|
|
|
boolean first_read;
|
|
|
|
{
|
|
|
|
#ifdef SCSIDEBUG
|
|
|
|
struct scsi_link *sc_link = st->sc_link;
|
|
|
|
#endif
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB2, ("starting block mode decision\n"));
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04: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)) {
|
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
1994-12-28 22:42:47 +03:00
|
|
|
st->blksize = st->blkmin;
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3,
|
|
|
|
("blkmin == blkmax of %d\n", st->blkmin));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the tape density mandates (or even suggests) use of fixed
|
|
|
|
* or variable-length blocks, comply.
|
|
|
|
*/
|
|
|
|
switch (st->density) {
|
|
|
|
case HALFINCH_800:
|
|
|
|
case HALFINCH_1600:
|
|
|
|
case HALFINCH_6250:
|
|
|
|
case DDS:
|
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
1994-12-28 22:42:47 +03:00
|
|
|
st->blksize = 0;
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3, ("density specified variable\n"));
|
|
|
|
goto done;
|
|
|
|
case QIC_11:
|
|
|
|
case QIC_24:
|
|
|
|
case QIC_120:
|
|
|
|
case QIC_150:
|
|
|
|
case QIC_525:
|
|
|
|
case QIC_1320:
|
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
1994-12-28 22:42:47 +03:00
|
|
|
if (st->media_blksize > 0)
|
|
|
|
st->blksize = st->media_blksize;
|
1994-03-29 08:29:20 +04:00
|
|
|
else
|
1994-12-28 22:42:47 +03:00
|
|
|
st->blksize = DEF_FIXED_BSIZE;
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3, ("density specified fixed\n"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 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 &&
|
1994-12-28 22:42:47 +03:00
|
|
|
(!(st->quirks & ST_Q_BLKSIZE) || (st->media_blksize == 0) ||
|
|
|
|
(st->media_blksize == DEF_FIXED_BSIZE) ||
|
|
|
|
(st->media_blksize == 1024))) {
|
|
|
|
if (st->media_blksize > 0)
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
1994-12-28 22:42:47 +03:00
|
|
|
else
|
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
|
|
|
st->blksize = st->media_blksize;
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3,
|
1994-12-28 22:42:47 +03:00
|
|
|
("Used media_blksize of %d\n", st->media_blksize));
|
1994-03-29 08:29:20 +04:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We're getting no hints from any direction. Choose variable-
|
|
|
|
* length blocks arbitrarily.
|
|
|
|
*/
|
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
1994-12-28 22:42:47 +03:00
|
|
|
st->blksize = 0;
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3,
|
|
|
|
("Give up and default to variable mode\n"));
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
done:
|
1994-03-29 08:29:20 +04: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)
|
|
|
|
*/
|
|
|
|
switch (st->density) {
|
|
|
|
/* 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:
|
|
|
|
st->flags &= ~ST_2FM_AT_EOD;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
default:
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags |= ST_2FM_AT_EOD;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1993-04-12 12:19:28 +04:00
|
|
|
return 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
|
|
|
* trim the size of the transfer if needed,
|
|
|
|
* called by physio
|
1994-03-29 08:29:20 +04:00
|
|
|
* basically the smaller of our min and the scsi driver's
|
1993-04-12 12:19:28 +04:00
|
|
|
* minphys
|
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
void
|
|
|
|
stminphys(bp)
|
|
|
|
struct buf *bp;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-12-28 22:42:47 +03:00
|
|
|
register struct st_softc *st = stcd.cd_devs[STUNIT(bp->b_dev)];
|
1994-03-29 08:29:20 +04:00
|
|
|
|
|
|
|
(st->sc_link->adapter->scsi_minphys) (bp);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:19:28 +04: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.
|
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
void
|
|
|
|
ststrategy(bp)
|
|
|
|
struct buf *bp;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st = stcd.cd_devs[STUNIT(bp->b_dev)];
|
1994-03-29 08:29:20 +04:00
|
|
|
struct buf *dp;
|
|
|
|
int opri;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(st->sc_link, SDEV_DB1,
|
|
|
|
("ststrategy %d bytes @ blk %d\n", bp->b_bcount, bp->b_blkno));
|
|
|
|
/*
|
|
|
|
* If it's a null transfer, return immediatly
|
|
|
|
*/
|
1994-11-21 13:39:09 +03:00
|
|
|
if (bp->b_bcount == 0)
|
1993-03-21 21:04:42 +03:00
|
|
|
goto done;
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
|
|
|
* Odd sized request on fixed drives are verboten
|
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
if (st->flags & ST_FIXEDBLOCKS) {
|
1994-12-28 22:42:47 +03:00
|
|
|
if (bp->b_bcount % st->blksize) {
|
1994-03-29 08:29:20 +04:00
|
|
|
printf("%s: bad request, must be multiple of %d\n",
|
1994-12-28 22:42:47 +03:00
|
|
|
st->sc_dev.dv_xname, st->blksize);
|
1994-03-29 08:29:20 +04:00
|
|
|
bp->b_error = EIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* as are out-of-range requests on variable drives.
|
|
|
|
*/
|
1994-04-24 09:40:05 +04:00
|
|
|
else if (bp->b_bcount < st->blkmin ||
|
|
|
|
(st->blkmax && bp->b_bcount > st->blkmax)) {
|
1994-03-29 08:29:20 +04:00
|
|
|
printf("%s: bad request, must be between %d and %d\n",
|
|
|
|
st->sc_dev.dv_xname, st->blkmin, st->blkmax);
|
1993-03-21 21:04:42 +03:00
|
|
|
bp->b_error = EIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
stminphys(bp);
|
|
|
|
opri = splbio();
|
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
1994-03-29 08:29:20 +04: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()))
|
1993-04-12 12:19:28 +04:00
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
dp = &st->buf_queue;
|
1993-03-21 21:04:42 +03:00
|
|
|
bp->b_actf = NULL;
|
1994-02-06 11:01:45 +03:00
|
|
|
bp->b_actb = dp->b_actb;
|
|
|
|
*dp->b_actb = bp;
|
|
|
|
dp->b_actb = &bp->b_actf;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
|
|
|
* Tell the device to get going on the transfer if it's
|
1994-03-29 08:29:20 +04:00
|
|
|
* not doing anything, otherwise just wait for completion
|
|
|
|
* (All a bit silly if we're only allowing 1 open but..)
|
1993-04-12 12:19:28 +04:00
|
|
|
*/
|
1994-11-21 13:39:09 +03:00
|
|
|
ststart(st);
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
splx(opri);
|
|
|
|
return;
|
|
|
|
bad:
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
done:
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
|
|
|
* Correctly set the buf to indicate a completed xfer
|
|
|
|
*/
|
1993-03-21 21:04:42 +03:00
|
|
|
iodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1993-04-12 12:19:28 +04: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,
|
1994-03-29 08:29:20 +04:00
|
|
|
* It dequeues the buf and creates a scsi command to perform the
|
|
|
|
* transfer required. The transfer request will call scsi_done
|
1993-04-12 12:19:28 +04:00
|
|
|
* 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.
|
1994-03-29 08:29:20 +04:00
|
|
|
* ststart() is called at splbio
|
|
|
|
*/
|
|
|
|
void
|
1994-11-21 13:39:09 +03:00
|
|
|
ststart(st)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_link *sc_link = st->sc_link;
|
|
|
|
register struct buf *bp, *dp;
|
1993-04-12 12:19:28 +04:00
|
|
|
struct scsi_rw_tape cmd;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB2, ("ststart "));
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
|
|
|
* See if there is a buf to do and we are not already
|
|
|
|
* doing one
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
while (sc_link->openings > 0) {
|
1994-03-29 08:29:20 +04:00
|
|
|
/* if a special awaits, let it proceed first */
|
|
|
|
if (sc_link->flags & SDEV_WAITING) {
|
|
|
|
sc_link->flags &= ~SDEV_WAITING;
|
|
|
|
wakeup((caddr_t)sc_link);
|
|
|
|
return;
|
|
|
|
}
|
1993-04-12 12:19:28 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
bp = st->buf_queue.b_actf;
|
|
|
|
if (!bp)
|
|
|
|
return; /* no work to bother with */
|
|
|
|
if (dp = bp->b_actf)
|
|
|
|
dp->b_actb = bp->b_actb;
|
|
|
|
else
|
|
|
|
st->buf_queue.b_actb = bp->b_actb;
|
|
|
|
*bp->b_actb = dp;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* if the device has been unmounted byt the user
|
|
|
|
* 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;
|
1994-06-16 19:57:39 +04:00
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = EIO;
|
|
|
|
biodone(bp);
|
|
|
|
continue;
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
1994-06-16 19:57:39 +04:00
|
|
|
if (st_space(st, 0, SP_FILEMARKS, 0)) {
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = EIO;
|
|
|
|
biodone(bp);
|
|
|
|
continue;
|
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
} else {
|
|
|
|
bp->b_resid = bp->b_bcount;
|
1993-03-21 21:04:42 +03:00
|
|
|
bp->b_error = 0;
|
1994-03-29 08:29:20 +04:00
|
|
|
bp->b_flags &= ~B_ERROR;
|
|
|
|
st->flags &= ~ST_AT_FILEMARK;
|
|
|
|
biodone(bp);
|
|
|
|
continue; /* seek more work */
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
}
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* If we are at EIO (e.g. EOM) but have not reported it
|
|
|
|
* yet then we should report it now
|
1993-04-12 12:19:28 +04:00
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
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 */
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
1994-04-13 09:43:19 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* Fill out the scsi command
|
|
|
|
*/
|
|
|
|
bzero(&cmd, sizeof(cmd));
|
|
|
|
if ((bp->b_flags & B_READ) == B_WRITE) {
|
1994-12-28 22:42:47 +03:00
|
|
|
cmd.opcode = WRITE;
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags &= ~ST_FM_WRITTEN;
|
|
|
|
st->flags |= ST_WRITTEN;
|
|
|
|
flags = SCSI_DATA_OUT;
|
|
|
|
} else {
|
1994-12-28 22:42:47 +03:00
|
|
|
cmd.opcode = READ;
|
1994-03-29 08:29:20 +04:00
|
|
|
flags = SCSI_DATA_IN;
|
|
|
|
}
|
1994-04-13 09:43:19 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* Handle "fixed-block-mode" tape drives by using the
|
|
|
|
* block count instead of the length.
|
|
|
|
*/
|
|
|
|
if (st->flags & ST_FIXEDBLOCKS) {
|
1994-04-13 09:43:19 +04:00
|
|
|
cmd.byte2 |= SRW_FIXED;
|
1994-12-28 22:42:47 +03:00
|
|
|
lto3b(bp->b_bcount / st->blksize, cmd.len);
|
1994-04-13 09:43:19 +04:00
|
|
|
} else
|
1994-03-29 08:29:20 +04:00
|
|
|
lto3b(bp->b_bcount, cmd.len);
|
1994-04-13 09:43:19 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* go ask the adapter to do all this for us
|
|
|
|
*/
|
|
|
|
if (scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd,
|
1994-06-16 05:07:30 +04:00
|
|
|
sizeof(cmd), (u_char *) bp->b_data, bp->b_bcount, 0,
|
1994-12-28 22:42:47 +03:00
|
|
|
100000, bp, flags | SCSI_NOSLEEP))
|
1994-03-29 08:29:20 +04:00
|
|
|
printf("%s: not queued\n", st->sc_dev.dv_xname);
|
|
|
|
} /* go back and see if we can cram more work in.. */
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* Perform special action on behalf of the user;
|
|
|
|
* knows about the internals of this device
|
|
|
|
*/
|
|
|
|
int
|
1994-12-28 22:42:47 +03:00
|
|
|
stioctl(dev, cmd, arg, flag, p)
|
1994-03-29 08:29:20 +04:00
|
|
|
dev_t dev;
|
1994-10-31 00:43:03 +03:00
|
|
|
u_long cmd;
|
1994-03-29 08:29:20 +04:00
|
|
|
caddr_t arg;
|
|
|
|
int flag;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct proc *p;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:29:20 +04:00
|
|
|
int error = 0;
|
|
|
|
int unit;
|
|
|
|
int number, nmarks, dsty;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
|
|
|
int hold_blksize;
|
|
|
|
u_int8_t hold_density;
|
1994-03-29 08:29:20 +04:00
|
|
|
struct mtop *mt = (struct mtop *) arg;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
|
|
|
* Find the device that the user is talking about
|
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
flags = 0; /* give error messages, act on errors etc. */
|
|
|
|
unit = STUNIT(dev);
|
|
|
|
dsty = STDSTY(dev);
|
|
|
|
st = stcd.cd_devs[unit];
|
1994-12-28 22:42:47 +03:00
|
|
|
hold_blksize = st->blksize;
|
1994-03-29 08:29:20 +04:00
|
|
|
hold_density = st->density;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case MTIOCGET: {
|
|
|
|
struct mtget *g = (struct mtget *) arg;
|
|
|
|
|
|
|
|
SC_DEBUG(st->sc_link, SDEV_DB1, ("[ioctl: get status]\n"));
|
|
|
|
bzero(g, sizeof(struct mtget));
|
|
|
|
g->mt_type = 0x7; /* Ultrix compat *//*? */
|
1994-12-28 22:42:47 +03:00
|
|
|
g->mt_blksiz = st->blksize;
|
1994-03-29 08:29:20 +04:00
|
|
|
g->mt_density = st->density;
|
1994-12-28 22:42:47 +03:00
|
|
|
g->mt_mblksiz[0] = st->modes[0].blksize;
|
|
|
|
g->mt_mblksiz[1] = st->modes[1].blksize;
|
|
|
|
g->mt_mblksiz[2] = st->modes[2].blksize;
|
|
|
|
g->mt_mblksiz[3] = st->modes[3].blksize;
|
1994-03-29 08:29:20 +04:00
|
|
|
g->mt_mdensity[0] = st->modes[0].density;
|
|
|
|
g->mt_mdensity[1] = st->modes[1].density;
|
|
|
|
g->mt_mdensity[2] = st->modes[2].density;
|
|
|
|
g->mt_mdensity[3] = st->modes[3].density;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
|
|
|
case MTIOCTOP: {
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(st->sc_link, SDEV_DB1,
|
|
|
|
("[ioctl: op=0x%x count=0x%x]\n", mt->mt_op, mt->mt_count));
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
/* compat: in U*x it is a short */
|
|
|
|
number = mt->mt_count;
|
1994-03-29 08:29:20 +04:00
|
|
|
switch ((short) (mt->mt_op)) {
|
1993-03-21 21:04:42 +03:00
|
|
|
case MTWEOF: /* write an end-of-file record */
|
1994-03-29 08:29:20 +04:00
|
|
|
error = st_write_filemarks(st, number, flags);
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
case MTBSF: /* backward space file */
|
1994-03-29 08:29:20 +04:00
|
|
|
number = -number;
|
|
|
|
case MTFSF: /* forward space file */
|
1994-04-13 09:43:19 +04:00
|
|
|
error = st_check_eod(st, FALSE, &nmarks, flags);
|
1994-03-29 08:29:20 +04:00
|
|
|
if (!error)
|
|
|
|
error = st_space(st, number - nmarks,
|
|
|
|
SP_FILEMARKS, flags);
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
case MTBSR: /* backward space record */
|
1994-03-29 08:29:20 +04:00
|
|
|
number = -number;
|
|
|
|
case MTFSR: /* forward space record */
|
1994-04-13 09:43:19 +04:00
|
|
|
error = st_check_eod(st, TRUE, &nmarks, flags);
|
1994-03-29 08:29:20 +04:00
|
|
|
if (!error)
|
|
|
|
error = st_space(st, number, SP_BLKS, flags);
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
case MTREW: /* rewind */
|
1994-04-13 09:43:19 +04:00
|
|
|
error = st_rewind(st, 0, flags);
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
case MTOFFL: /* rewind and put the drive offline */
|
1994-03-29 08:29:20 +04:00
|
|
|
st_unmount(st, EJECT);
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
case MTNOP: /* no operation, sets status only */
|
1994-04-06 01:59:49 +04:00
|
|
|
break;
|
1994-04-06 02:08:09 +04:00
|
|
|
case MTRETEN: /* retension the tape */
|
1994-04-13 09:43:19 +04:00
|
|
|
error = st_load(st, LD_RETENSION, flags);
|
1994-04-06 02:18:00 +04:00
|
|
|
if (!error)
|
|
|
|
error = st_load(st, LD_LOAD, flags);
|
1994-04-06 02:08:09 +04:00
|
|
|
break;
|
1994-04-06 01:59:49 +04:00
|
|
|
case MTEOM: /* forward space to end of media */
|
1994-04-13 09:43:19 +04:00
|
|
|
error = st_check_eod(st, FALSE, &nmarks, flags);
|
1994-04-06 01:59:49 +04:00
|
|
|
if (!error)
|
|
|
|
error = st_space(st, 1, SP_EOM, flags);
|
|
|
|
break;
|
1993-03-21 21:04:42 +03:00
|
|
|
case MTCACHE: /* enable controller cache */
|
|
|
|
case MTNOCACHE: /* disable controller cache */
|
|
|
|
break;
|
1994-03-29 08:29:20 +04:00
|
|
|
case MTSETBSIZ: /* Set block size for device */
|
|
|
|
#ifdef NOTYET
|
|
|
|
if (!(st->flags & ST_NEW_MOUNT)) {
|
|
|
|
uprintf("re-mount tape before changing blocksize");
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (number == 0) {
|
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
|
|
|
} else {
|
|
|
|
if ((st->blkmin || st->blkmax) &&
|
|
|
|
(number < st->blkmin ||
|
|
|
|
number > st->blkmax)) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
st->blksize = number;
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags |= ST_BLOCK_SET; /*XXX */
|
|
|
|
goto try_new_value;
|
|
|
|
|
|
|
|
case MTSETDNSTY: /* Set density for device and mode */
|
|
|
|
if (number > SCSI_2_MAX_DENSITY_CODE)
|
|
|
|
error = EINVAL;
|
|
|
|
else
|
|
|
|
st->density = number;
|
|
|
|
goto try_new_value;
|
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
default:
|
1994-03-29 08:29:20 +04:00
|
|
|
error = EINVAL;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
break;
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
case MTIOCIEOT:
|
|
|
|
case MTIOCEEOT:
|
1994-03-29 08:29:20 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (STMODE(dev) == CTLMODE)
|
1994-12-28 22:42:47 +03:00
|
|
|
error = scsi_do_ioctl(st->sc_link, dev, cmd, arg, flag, p);
|
1994-03-29 08:29:20 +04:00
|
|
|
else
|
|
|
|
error = ENOTTY;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
return error;
|
|
|
|
/*-----------------------------*/
|
|
|
|
try_new_value:
|
|
|
|
/*
|
|
|
|
* Check that the mode being asked for is aggreeable to the
|
|
|
|
* drive. If not, put it back the way it was.
|
|
|
|
*/
|
|
|
|
if (error = st_mode_select(st, 0)) { /* put it back as it was */
|
|
|
|
printf("%s: cannot set selected mode\n", st->sc_dev.dv_xname);
|
|
|
|
st->density = hold_density;
|
1994-12-28 22:42:47 +03:00
|
|
|
st->blksize = hold_blksize;
|
|
|
|
if (st->blksize)
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
|
|
|
else
|
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* As the drive liked it, if we are setting a new default,
|
|
|
|
* set it into the structures as such.
|
|
|
|
*
|
|
|
|
* The means for deciding this are not finalised yet
|
|
|
|
*/
|
|
|
|
if (STMODE(dev) == 0x03) {
|
|
|
|
/* special mode */
|
|
|
|
/* XXX */
|
|
|
|
switch ((short) (mt->mt_op)) {
|
|
|
|
case MTSETBSIZ:
|
1994-12-28 22:42:47 +03:00
|
|
|
st->modes[dsty].blksize = st->blksize;
|
1994-03-29 08:29:20 +04:00
|
|
|
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-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* Do a synchronous read.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
st_read(st, buf, size, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
|
|
|
int size;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1994-03-29 08:29:20 +04:00
|
|
|
char *buf;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-04-13 09:43:19 +04:00
|
|
|
struct scsi_rw_tape cmd;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* If it's a null transfer, return immediatly
|
|
|
|
*/
|
|
|
|
if (size == 0)
|
|
|
|
return 0;
|
1994-04-13 09:43:19 +04:00
|
|
|
bzero(&cmd, sizeof(cmd));
|
1994-12-28 22:42:47 +03:00
|
|
|
cmd.opcode = READ;
|
1994-03-29 08:29:20 +04:00
|
|
|
if (st->flags & ST_FIXEDBLOCKS) {
|
1994-04-13 09:43:19 +04:00
|
|
|
cmd.byte2 |= SRW_FIXED;
|
1994-12-28 22:42:47 +03:00
|
|
|
lto3b(size / (st->blksize ? st->blksize : DEF_FIXED_BSIZE),
|
1994-04-13 09:43:19 +04:00
|
|
|
cmd.len);
|
1994-03-29 08:29:20 +04:00
|
|
|
} else
|
1994-04-13 09:43:19 +04:00
|
|
|
lto3b(size, cmd.len);
|
|
|
|
return scsi_scsi_cmd(st->sc_link, (struct scsi_generic *) &cmd,
|
|
|
|
sizeof(cmd), (u_char *) buf, size, 0, 100000, NULL,
|
1994-03-29 08:29:20 +04:00
|
|
|
flags | SCSI_DATA_IN);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __STDC__
|
1994-03-29 08:29:20 +04:00
|
|
|
#define b2tol(a) (((unsigned)(a##_1) << 8) + (unsigned)a##_0)
|
1993-03-21 21:04:42 +03:00
|
|
|
#else
|
1994-03-29 08:29:20 +04:00
|
|
|
#define b2tol(a) (((unsigned)(a/**/_1) << 8) + (unsigned)a/**/_0)
|
1993-03-21 21:04:42 +03:00
|
|
|
#endif
|
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
|
|
|
* Ask the drive what it's min and max blk sizes are.
|
1994-03-29 08:29:20 +04:00
|
|
|
*/
|
|
|
|
int
|
1994-04-13 09:43:19 +04:00
|
|
|
st_read_block_limits(st, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-04-13 09:43:19 +04:00
|
|
|
struct scsi_block_limits cmd;
|
|
|
|
struct scsi_block_limits_data block_limits;
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_link *sc_link = st->sc_link;
|
1994-04-13 09:43:19 +04:00
|
|
|
int error;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First check if we have it all loaded
|
|
|
|
*/
|
1994-03-29 08:29:20 +04:00
|
|
|
if ((sc_link->flags & SDEV_MEDIA_LOADED))
|
|
|
|
return 0;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* do a 'Read Block Limits'
|
|
|
|
*/
|
1994-04-13 09:43:19 +04:00
|
|
|
bzero(&cmd, sizeof(cmd));
|
1994-12-28 22:42:47 +03:00
|
|
|
cmd.opcode = READ_BLOCK_LIMITS;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* do the command, update the global values
|
1993-04-12 12:19:28 +04:00
|
|
|
*/
|
1994-04-13 09:43:19 +04:00
|
|
|
if (error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd,
|
|
|
|
sizeof(cmd), (u_char *) &block_limits, sizeof(block_limits),
|
1994-03-29 08:29:20 +04:00
|
|
|
ST_RETRIES, 5000, NULL, flags | SCSI_DATA_IN))
|
|
|
|
return error;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
1994-04-13 09:43:19 +04:00
|
|
|
st->blkmin = b2tol(block_limits.min_length);
|
|
|
|
st->blkmax = _3btol(&block_limits.max_length_2);
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
SC_DEBUG(sc_link, SDEV_DB3,
|
1994-12-28 22:42:47 +03:00
|
|
|
("(%d <= blksize <= %d)\n", st->blkmin, st->blkmax));
|
1994-03-29 08:29:20 +04:00
|
|
|
return 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the scsi driver to send a full inquiry to the
|
|
|
|
* device and use the results to fill out the global
|
|
|
|
* parameter structure.
|
1994-03-29 08:29:20 +04:00
|
|
|
*
|
|
|
|
* called from:
|
|
|
|
* attach
|
|
|
|
* open
|
|
|
|
* ioctl (to reset original blksize)
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
st_mode_sense(st, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:29:20 +04:00
|
|
|
u_int scsi_sense_len;
|
|
|
|
int error;
|
1994-04-13 09:43:19 +04:00
|
|
|
struct scsi_mode_sense cmd;
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_sense {
|
|
|
|
struct scsi_mode_header header;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct scsi_blk_desc blk_desc;
|
1994-08-09 22:50:17 +04:00
|
|
|
u_char sense_data[MAX_PAGE_0_SIZE];
|
1994-03-29 08:29:20 +04:00
|
|
|
} scsi_sense;
|
|
|
|
struct scsi_link *sc_link = st->sc_link;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
1994-08-09 22:50:17 +04:00
|
|
|
scsi_sense_len = 12 + st->page_0_size;
|
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* Set up a mode sense
|
1993-04-12 12:19:28 +04:00
|
|
|
*/
|
1994-04-13 09:43:19 +04:00
|
|
|
bzero(&cmd, sizeof(cmd));
|
1994-12-28 22:42:47 +03:00
|
|
|
cmd.opcode = MODE_SENSE;
|
1994-04-13 09:43:19 +04:00
|
|
|
cmd.length = scsi_sense_len;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* do the command, but we don't need the results
|
1994-03-29 08:29:20 +04:00
|
|
|
* just print them for our interest's sake, if asked,
|
|
|
|
* or if we need it as a template for the mode select
|
|
|
|
* store it away.
|
1993-04-12 12:19:28 +04:00
|
|
|
*/
|
1994-04-13 09:43:19 +04:00
|
|
|
if (error = scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd,
|
1994-08-09 22:50:17 +04:00
|
|
|
sizeof(cmd), (u_char *) &scsi_sense, scsi_sense_len,
|
1994-03-29 08:29:20 +04:00
|
|
|
ST_RETRIES, 5000, NULL, flags | SCSI_DATA_IN))
|
|
|
|
return error;
|
|
|
|
|
1994-08-09 22:50:17 +04:00
|
|
|
st->numblks = _3btol(scsi_sense.blk_desc.nblocks);
|
1994-12-28 22:42:47 +03:00
|
|
|
st->media_blksize = _3btol(scsi_sense.blk_desc.blklen);
|
1994-08-09 22:50:17 +04:00
|
|
|
st->media_density = scsi_sense.blk_desc.density;
|
|
|
|
if (scsi_sense.header.dev_spec & SMH_DSP_WRITE_PROT)
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags |= ST_READONLY;
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB3,
|
|
|
|
("density code 0x%x, %d-byte blocks, write-%s, ",
|
1994-12-28 22:42:47 +03:00
|
|
|
st->media_density, st->media_blksize,
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags & ST_READONLY ? "protected" : "enabled"));
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB3,
|
|
|
|
("%sbuffered\n",
|
1994-08-09 22:50:17 +04:00
|
|
|
scsi_sense.header.dev_spec & SMH_DSP_BUFF_MODE ? "" : "un"));
|
|
|
|
if (st->page_0_size)
|
|
|
|
bcopy(scsi_sense.sense_data, st->sense_data, st->page_0_size);
|
1994-03-29 08:29:20 +04:00
|
|
|
sc_link->flags |= SDEV_MEDIA_LOADED;
|
|
|
|
return 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* Send a filled out parameter structure to the drive to
|
|
|
|
* set it into the desire modes etc.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
st_mode_select(st, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-08-09 22:50:17 +04:00
|
|
|
u_int scsi_select_len;
|
|
|
|
int error;
|
1994-04-13 09:43:19 +04:00
|
|
|
struct scsi_mode_select cmd;
|
1994-08-09 22:50:17 +04:00
|
|
|
struct scsi_select {
|
1994-03-29 08:29:20 +04:00
|
|
|
struct scsi_mode_header header;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct scsi_blk_desc blk_desc;
|
1994-08-09 22:50:17 +04:00
|
|
|
u_char sense_data[MAX_PAGE_0_SIZE];
|
|
|
|
} scsi_select;
|
|
|
|
struct scsi_link *sc_link = st->sc_link;
|
|
|
|
|
|
|
|
scsi_select_len = 12 + st->page_0_size;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up for a mode select
|
|
|
|
*/
|
1994-04-13 09:43:19 +04:00
|
|
|
bzero(&cmd, sizeof(cmd));
|
1994-12-28 22:42:47 +03:00
|
|
|
cmd.opcode = MODE_SELECT;
|
1994-08-09 22:50:17 +04:00
|
|
|
cmd.length = scsi_select_len;
|
1994-04-13 09:43:19 +04:00
|
|
|
|
1994-08-09 22:50:17 +04:00
|
|
|
bzero(&scsi_select, scsi_select_len);
|
1994-12-28 22:42:47 +03:00
|
|
|
scsi_select.header.blk_desc_len = sizeof(struct scsi_blk_desc);
|
1994-08-09 22:50:17 +04:00
|
|
|
scsi_select.header.dev_spec |= SMH_DSP_BUFF_MODE_ON;
|
|
|
|
scsi_select.blk_desc.density = st->density;
|
1994-03-29 08:29:20 +04:00
|
|
|
if (st->flags & ST_FIXEDBLOCKS)
|
1994-12-28 22:42:47 +03:00
|
|
|
lto3b(st->blksize, scsi_select.blk_desc.blklen);
|
1994-08-09 22:50:17 +04:00
|
|
|
if (st->page_0_size)
|
|
|
|
bcopy(st->sense_data, scsi_select.sense_data, st->page_0_size);
|
1994-04-13 09:43:19 +04:00
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
|
|
|
* do the command
|
|
|
|
*/
|
1994-08-09 22:50:17 +04:00
|
|
|
return scsi_scsi_cmd(sc_link, (struct scsi_generic *) &cmd,
|
|
|
|
sizeof(cmd), (u_char *) &scsi_select, scsi_select_len,
|
|
|
|
ST_RETRIES, 5000, NULL, flags | SCSI_DATA_OUT);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
|
|
|
* skip N blocks/filemarks/seq filemarks/eom
|
1994-03-29 08:29:20 +04:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
st_space(st, number, what, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-03-29 08:29:20 +04:00
|
|
|
u_int what;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1994-03-29 08:29:20 +04:00
|
|
|
int number;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-04-13 09:43:19 +04:00
|
|
|
struct scsi_space cmd;
|
1994-03-29 08:29:20 +04:00
|
|
|
int error;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
switch (what) {
|
|
|
|
case SP_BLKS:
|
|
|
|
if (st->flags & ST_PER_ACTION) {
|
|
|
|
if (number > 0) {
|
|
|
|
st->flags &= ~ST_PER_ACTION;
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
error = st_space(st, 0, SP_FILEMARKS,
|
|
|
|
flags);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if (st->flags & ST_BLANK_READ) {
|
|
|
|
st->flags &= ~ST_BLANK_READ;
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
st->flags &= ~ST_EIO_PENDING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SP_FILEMARKS:
|
|
|
|
if (st->flags & ST_EIO_PENDING) {
|
|
|
|
if (number > 0) {
|
1994-04-06 01:59:49 +04:00
|
|
|
/* pretend we just discovered the error */
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags &= ~ST_EIO_PENDING;
|
|
|
|
return EIO;
|
|
|
|
} else if (number < 0) {
|
|
|
|
/* back away from the error */
|
|
|
|
st->flags &= ~ST_EIO_PENDING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (st->flags & ST_AT_FILEMARK) {
|
|
|
|
st->flags &= ~ST_AT_FILEMARK;
|
|
|
|
number--;
|
|
|
|
}
|
|
|
|
if ((st->flags & ST_BLANK_READ) && (number < 0)) {
|
|
|
|
/* back away from unwritten tape */
|
|
|
|
st->flags &= ~ST_BLANK_READ;
|
|
|
|
number++; /* XXX dubious */
|
|
|
|
}
|
1994-04-06 01:59:49 +04:00
|
|
|
break;
|
|
|
|
case SP_EOM:
|
|
|
|
if (st->flags & ST_EIO_PENDING) {
|
|
|
|
/* pretend we just discovered the error */
|
|
|
|
st->flags &= ~ST_EIO_PENDING;
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
if (st->flags & ST_AT_FILEMARK)
|
|
|
|
st->flags &= ~ST_AT_FILEMARK;
|
|
|
|
break;
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
|
|
|
if (number == 0)
|
|
|
|
return 0;
|
1994-04-13 09:43:19 +04:00
|
|
|
|
|
|
|
bzero(&cmd, sizeof(cmd));
|
1994-12-28 22:42:47 +03:00
|
|
|
cmd.opcode = SPACE;
|
1994-04-13 09:43:19 +04:00
|
|
|
cmd.byte2 = what;
|
|
|
|
lto3b(number, cmd.number);
|
|
|
|
|
|
|
|
return scsi_scsi_cmd(st->sc_link, (struct scsi_generic *) &cmd,
|
1994-12-28 22:55:50 +03:00
|
|
|
sizeof(cmd), 0, 0, 0, 900000, NULL, flags);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* write N filemarks
|
1994-03-29 08:29:20 +04:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
st_write_filemarks(st, number, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1994-03-29 08:29:20 +04:00
|
|
|
int number;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-04-13 09:43:19 +04:00
|
|
|
struct scsi_write_filemarks cmd;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
/*
|
|
|
|
* It's hard to write a negative number of file marks.
|
|
|
|
* Don't try.
|
|
|
|
*/
|
|
|
|
if (number < 0)
|
|
|
|
return EINVAL;
|
|
|
|
switch (number) {
|
|
|
|
case 0: /* really a command to sync the drive's buffers */
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (st->flags & ST_FM_WRITTEN) /* already have one down */
|
|
|
|
st->flags &= ~ST_WRITTEN;
|
|
|
|
else
|
|
|
|
st->flags |= ST_FM_WRITTEN;
|
|
|
|
st->flags &= ~ST_PER_ACTION;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
st->flags &= ~(ST_PER_ACTION | ST_WRITTEN);
|
|
|
|
}
|
1994-04-13 09:43:19 +04:00
|
|
|
|
|
|
|
bzero(&cmd, sizeof(cmd));
|
1994-12-28 22:42:47 +03:00
|
|
|
cmd.opcode = WRITE_FILEMARKS;
|
1994-04-13 09:43:19 +04:00
|
|
|
lto3b(number, cmd.number);
|
|
|
|
|
|
|
|
return scsi_scsi_cmd(st->sc_link, (struct scsi_generic *) &cmd,
|
|
|
|
sizeof(cmd), 0, 0, 0, 100000, NULL, flags);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
1994-03-29 08:29:20 +04: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.
|
|
|
|
*/
|
|
|
|
int
|
1994-04-13 09:43:19 +04:00
|
|
|
st_check_eod(st, position, nmarks, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-03-29 08:29:20 +04:00
|
|
|
boolean position;
|
|
|
|
int *nmarks;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:29:20 +04:00
|
|
|
int error;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
switch (st->flags & (ST_WRITTEN | ST_FM_WRITTEN | ST_2FM_AT_EOD)) {
|
|
|
|
default:
|
|
|
|
*nmarks = 0;
|
|
|
|
return 0;
|
|
|
|
case ST_WRITTEN:
|
|
|
|
case ST_WRITTEN | ST_FM_WRITTEN | ST_2FM_AT_EOD:
|
|
|
|
*nmarks = 1;
|
|
|
|
break;
|
|
|
|
case ST_WRITTEN | ST_2FM_AT_EOD:
|
|
|
|
*nmarks = 2;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
error = st_write_filemarks(st, *nmarks, flags);
|
|
|
|
if (position && !error)
|
|
|
|
error = st_space(st, -*nmarks, SP_FILEMARKS, flags);
|
|
|
|
return error;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
1994-04-06 02:08:09 +04:00
|
|
|
* load/unload/retension
|
1994-03-29 08:29:20 +04:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
st_load(st, type, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-03-29 08:29:20 +04:00
|
|
|
u_int type;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-04-13 09:43:19 +04:00
|
|
|
struct scsi_load cmd;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
if (type != LD_LOAD) {
|
|
|
|
int error;
|
|
|
|
int nmarks;
|
|
|
|
|
1994-04-13 09:43:19 +04:00
|
|
|
error = st_check_eod(st, FALSE, &nmarks, flags);
|
1994-03-29 08:29:20 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
if (st->quirks & ST_Q_IGNORE_LOADS)
|
|
|
|
return 0;
|
1994-04-13 09:43:19 +04:00
|
|
|
|
|
|
|
bzero(&cmd, sizeof(cmd));
|
1994-12-28 22:42:47 +03:00
|
|
|
cmd.opcode = LOAD;
|
1994-04-13 09:43:19 +04:00
|
|
|
cmd.how = type;
|
|
|
|
|
|
|
|
return scsi_scsi_cmd(st->sc_link, (struct scsi_generic *) &cmd,
|
|
|
|
sizeof(cmd), 0, 0, ST_RETRIES, 300000, NULL, flags);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Rewind the device
|
1994-03-29 08:29:20 +04:00
|
|
|
*/
|
|
|
|
int
|
1994-04-13 09:43:19 +04:00
|
|
|
st_rewind(st, immediate, flags)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1994-04-13 09:43:19 +04:00
|
|
|
u_int immediate;
|
1994-04-11 07:53:58 +04:00
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-04-13 09:43:19 +04:00
|
|
|
struct scsi_rewind cmd;
|
1994-03-29 08:29:20 +04:00
|
|
|
int error;
|
|
|
|
int nmarks;
|
|
|
|
|
1994-04-13 09:43:19 +04:00
|
|
|
error = st_check_eod(st, FALSE, &nmarks, flags);
|
1994-03-29 08:29:20 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
st->flags &= ~ST_PER_ACTION;
|
1994-04-13 09:43:19 +04:00
|
|
|
|
|
|
|
bzero(&cmd, sizeof(cmd));
|
1994-12-28 22:42:47 +03:00
|
|
|
cmd.opcode = REWIND;
|
1994-04-13 09:43:19 +04:00
|
|
|
cmd.byte2 = immediate;
|
|
|
|
|
|
|
|
return scsi_scsi_cmd(st->sc_link, (struct scsi_generic *) &cmd,
|
|
|
|
sizeof(cmd), 0, 0, ST_RETRIES, immediate ? 5000 : 300000, NULL,
|
1994-03-29 08:29:20 +04:00
|
|
|
flags);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:19:28 +04:00
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* Look at the returned sense and act on the error and detirmine
|
|
|
|
* The unix error number to pass back... (0 = report no error)
|
|
|
|
* (-1 = continue processing)
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
st_interpret_sense(xs)
|
1993-04-12 12:19:28 +04:00
|
|
|
struct scsi_xfer *xs;
|
1994-03-29 08:29:20 +04:00
|
|
|
{
|
|
|
|
struct scsi_link *sc_link = xs->sc_link;
|
|
|
|
struct scsi_sense_data *sense = &xs->sense;
|
|
|
|
struct buf *bp = xs->bp;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st = sc_link->device_softc;
|
|
|
|
u_int8_t key;
|
|
|
|
u_int32_t info;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
1994-03-29 08:29:20 +04:00
|
|
|
* Get the sense fields and work out what code
|
1993-04-12 12:19:28 +04:00
|
|
|
*/
|
1994-08-12 12:57:18 +04:00
|
|
|
if (sense->error_code & SSD_ERRCODE_VALID) {
|
1994-11-22 03:14:24 +03:00
|
|
|
bcopy(sense->extended_info, &info, sizeof info);
|
1994-08-12 12:57:18 +04:00
|
|
|
info = ntohl(info);
|
|
|
|
} else
|
1994-03-29 08:29:20 +04:00
|
|
|
info = xs->datalen; /* bad choice if fixed blocks */
|
|
|
|
if ((sense->error_code & SSD_ERRCODE) != 0x70)
|
|
|
|
return -1; /* let the generic code handle it */
|
|
|
|
if (st->flags & ST_FIXEDBLOCKS) {
|
1994-12-28 22:42:47 +03:00
|
|
|
xs->resid = info * st->blksize;
|
1994-05-09 11:40:47 +04:00
|
|
|
if (sense->extended_flags & SSD_EOM) {
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags |= ST_EIO_PENDING;
|
|
|
|
if (bp)
|
|
|
|
bp->b_resid = xs->resid;
|
|
|
|
}
|
1994-05-09 11:40:47 +04:00
|
|
|
if (sense->extended_flags & SSD_FILEMARK) {
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags |= ST_AT_FILEMARK;
|
|
|
|
if (bp)
|
|
|
|
bp->b_resid = xs->resid;
|
|
|
|
}
|
1994-05-09 11:40:47 +04:00
|
|
|
if (sense->extended_flags & SSD_ILI) {
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags |= ST_EIO_PENDING;
|
|
|
|
if (bp)
|
|
|
|
bp->b_resid = xs->resid;
|
1994-12-28 22:42:47 +03:00
|
|
|
if (sense->error_code & SSD_ERRCODE_VALID &&
|
|
|
|
(xs->flags & SCSI_SILENT) == 0)
|
1994-03-29 08:29:20 +04:00
|
|
|
printf("%s: block wrong size, %d blocks residual\n",
|
|
|
|
st->sc_dev.dv_xname, info);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
1994-04-13 09:43:19 +04:00
|
|
|
if ((st->quirks & ST_Q_SENSE_HELP) &&
|
1994-03-29 08:29:20 +04:00
|
|
|
!(sc_link->flags & SDEV_MEDIA_LOADED))
|
1994-12-28 22:42:47 +03:00
|
|
|
st->blksize -= 512;
|
1994-03-29 08:29:20 +04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If no data was tranfered, do it immediatly
|
|
|
|
*/
|
|
|
|
if (xs->resid >= xs->datalen) {
|
|
|
|
if (st->flags & ST_EIO_PENDING)
|
|
|
|
return EIO;
|
|
|
|
if (st->flags & ST_AT_FILEMARK) {
|
|
|
|
if (bp)
|
|
|
|
bp->b_resid = xs->resid;
|
|
|
|
return 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
} else { /* must be variable mode */
|
|
|
|
xs->resid = xs->datalen; /* to be sure */
|
1994-05-09 11:40:47 +04:00
|
|
|
if (sense->extended_flags & SSD_EOM)
|
1994-03-29 08:29:20 +04:00
|
|
|
return EIO;
|
1994-05-09 11:40:47 +04:00
|
|
|
if (sense->extended_flags & SSD_FILEMARK) {
|
1994-03-29 08:29:20 +04:00
|
|
|
if (bp)
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
return 0;
|
|
|
|
}
|
1994-05-09 11:40:47 +04:00
|
|
|
if (sense->extended_flags & SSD_ILI) {
|
1994-03-29 08:29:20 +04:00
|
|
|
if (info < 0) {
|
|
|
|
/*
|
|
|
|
* the record was bigger than the read
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
if ((xs->flags & SCSI_SILENT) == 0)
|
1994-03-29 08:29:20 +04:00
|
|
|
printf("%s: %d-byte record too big\n",
|
|
|
|
st->sc_dev.dv_xname,
|
|
|
|
xs->datalen - info);
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
xs->resid = info;
|
|
|
|
if (bp)
|
|
|
|
bp->b_resid = info;
|
1993-04-12 12:19:28 +04:00
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-05-09 11:40:47 +04:00
|
|
|
key = sense->extended_flags & SSD_KEY;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
if (key == 0x8) {
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
1994-04-13 09:43:19 +04:00
|
|
|
if ((st->quirks & ST_Q_SENSE_HELP) &&
|
1994-03-29 08:29:20 +04:00
|
|
|
!(sc_link->flags & SDEV_MEDIA_LOADED)) {
|
|
|
|
/* still starting */
|
1994-12-28 22:42:47 +03:00
|
|
|
st->blksize -= 512;
|
1994-03-29 08:29:20 +04:00
|
|
|
} else if (!(st->flags & (ST_2FM_AT_EOD | ST_BLANK_READ))) {
|
|
|
|
st->flags |= ST_BLANK_READ;
|
|
|
|
xs->resid = xs->datalen;
|
|
|
|
if (bp) {
|
|
|
|
bp->b_resid = xs->resid;
|
|
|
|
/* return an EOF */
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1; /* let the default/generic handler handle it */
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1993-04-12 12:19:28 +04:00
|
|
|
|
|
|
|
/*
|
1994-03-29 08:29:20 +04: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.
|
|
|
|
*/
|
1993-04-12 12:19:28 +04:00
|
|
|
int
|
1994-03-29 08:29:20 +04:00
|
|
|
st_touch_tape(st)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct st_softc *st;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-12-28 22:42:47 +03:00
|
|
|
char *buf;
|
|
|
|
int readsize;
|
1994-03-29 08:29:20 +04:00
|
|
|
int error;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
buf = malloc(1024, M_TEMP, M_NOWAIT);
|
|
|
|
if (!buf)
|
|
|
|
return ENOMEM;
|
1993-04-12 12:19:28 +04:00
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
if (error = st_mode_sense(st, 0))
|
|
|
|
goto bad;
|
1994-12-28 22:42:47 +03:00
|
|
|
st->blksize = 1024;
|
1994-03-29 08:29:20 +04:00
|
|
|
do {
|
1994-12-28 22:42:47 +03:00
|
|
|
switch (st->blksize) {
|
1994-03-29 08:29:20 +04:00
|
|
|
case 512:
|
|
|
|
case 1024:
|
1994-12-28 22:42:47 +03:00
|
|
|
readsize = st->blksize;
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags |= ST_FIXEDBLOCKS;
|
|
|
|
break;
|
|
|
|
default:
|
1994-12-28 22:42:47 +03:00
|
|
|
readsize = 1;
|
1994-03-29 08:29:20 +04:00
|
|
|
st->flags &= ~ST_FIXEDBLOCKS;
|
1993-04-12 12:19:28 +04:00
|
|
|
}
|
1994-03-29 08:29:20 +04:00
|
|
|
if (error = st_mode_select(st, 0))
|
|
|
|
goto bad;
|
1994-12-28 22:42:47 +03:00
|
|
|
st_read(st, buf, readsize, SCSI_SILENT); /* XXX */
|
1994-04-13 09:43:19 +04:00
|
|
|
if (error = st_rewind(st, 0, 0)) {
|
1994-03-29 08:29:20 +04:00
|
|
|
bad: free(buf, M_TEMP);
|
|
|
|
return error;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
} while (readsize != 1 && readsize > st->blksize);
|
|
|
|
|
1994-03-29 08:29:20 +04:00
|
|
|
free(buf, M_TEMP);
|
1993-04-12 12:19:28 +04:00
|
|
|
return 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-05-11 13:49:17 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
stdump()
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Not implemented. */
|
|
|
|
return EINVAL;
|
|
|
|
}
|