Last modified: 18-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Devfs support
*/
-static char *verstr = "20040403";
+static char *verstr = "20041025";
#include <linux/module.h>
#include <asm/dma.h>
#include <asm/system.h>
+#include <scsi/scsi.h>
+#include <scsi/scsi_dbg.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_driver.h>
+#include <scsi/scsi_eh.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_ioctl.h>
+#include <scsi/scsi_request.h>
+
+
/* The driver prints some debugging information on the console if DEBUG
is defined and non-zero. */
#define DEBUG 0
#define DEBC(a)
#endif
-
-#include "scsi.h"
-#include <scsi/scsi_host.h>
-
-#include <scsi/scsi_driver.h>
-#include <scsi/scsi_ioctl.h>
-
#define ST_KILOBYTE 1024
#include "st_options.h"
static int buffer_kbs;
static int max_sg_segs;
static int try_direct_io = TRY_DIRECT_IO;
-static int try_rdio = TRUE;
-static int try_wdio = TRUE;
+static int try_rdio = 1;
+static int try_wdio = 1;
static int st_dev_max;
static int st_nr_dev;
24 bits) */
#define SET_DENS_AND_BLK 0x10001
-static rwlock_t st_dev_arr_lock = RW_LOCK_UNLOCKED;
+static DEFINE_RWLOCK(st_dev_arr_lock);
static int st_fixed_buffer_size = ST_FIXED_BUFFER_SIZE;
static int st_max_sg_segs = ST_MAX_SG;
-static Scsi_Tape **scsi_tapes = NULL;
+static struct scsi_tape **scsi_tapes = NULL;
static int modes_defined;
-static ST_buffer *new_tape_buffer(int, int, int);
-static int enlarge_buffer(ST_buffer *, int, int);
-static void normalize_buffer(ST_buffer *);
-static int append_to_buffer(const char __user *, ST_buffer *, int);
-static int from_buffer(ST_buffer *, char __user *, int);
-static void move_buffer_data(ST_buffer *, int);
-static void buf_to_sg(ST_buffer *, unsigned int);
+static struct st_buffer *new_tape_buffer(int, int, int);
+static int enlarge_buffer(struct st_buffer *, int, int);
+static void normalize_buffer(struct st_buffer *);
+static int append_to_buffer(const char __user *, struct st_buffer *, int);
+static int from_buffer(struct st_buffer *, char __user *, int);
+static void move_buffer_data(struct st_buffer *, int);
+static void buf_to_sg(struct st_buffer *, unsigned int);
static int st_map_user_pages(struct scatterlist *, const unsigned int,
unsigned long, size_t, int, unsigned long);
static void do_create_driverfs_files(void);
static void do_remove_driverfs_files(void);
-static void do_create_class_files(Scsi_Tape *, int, int);
+static void do_create_class_files(struct scsi_tape *, int, int);
static struct scsi_driver st_template = {
.owner = THIS_MODULE,
.init_command = st_init_command,
};
-static int st_compression(Scsi_Tape *, int);
+static int st_compression(struct scsi_tape *, int);
-static int find_partition(Scsi_Tape *);
-static int switch_partition(Scsi_Tape *);
+static int find_partition(struct scsi_tape *);
+static int switch_partition(struct scsi_tape *);
-static int st_int_ioctl(Scsi_Tape *, unsigned int, unsigned long);
+static int st_int_ioctl(struct scsi_tape *, unsigned int, unsigned long);
\f
#include "osst_detect.h"
/* If the device signature is on the list of incompatible drives, the
function returns a pointer to the name of the correct driver (if known) */
-static char * st_incompatible(Scsi_Device* SDp)
+static char * st_incompatible(struct scsi_device* SDp)
{
struct st_reject_data *rp;
}
\f
-static inline char *tape_name(Scsi_Tape *tape)
+static inline char *tape_name(struct scsi_tape *tape)
{
return tape->disk->disk_name;
}
/* Convert the result to success code */
-static int st_chk_result(Scsi_Tape *STp, Scsi_Request * SRpnt)
+static int st_chk_result(struct scsi_tape *STp, struct scsi_request * SRpnt)
{
int result = SRpnt->sr_result;
unsigned char *sense = SRpnt->sr_sense_buffer, scode;
SRpnt->sr_cmnd[3], SRpnt->sr_cmnd[4], SRpnt->sr_cmnd[5],
SRpnt->sr_bufflen);
if (driver_byte(result) & DRIVER_SENSE)
- print_req_sense("st", SRpnt);
+ scsi_print_req_sense("st", SRpnt);
} else ) /* end DEB */
if (!(driver_byte(result) & DRIVER_SENSE) ||
((sense[0] & 0x70) == 0x70 &&
SRpnt->sr_cmnd[0] != TEST_UNIT_READY)) { /* Abnormal conditions for tape */
if (driver_byte(result) & DRIVER_SENSE) {
printk(KERN_WARNING "%s: Error with sense data: ", name);
- print_req_sense("st", SRpnt);
+ scsi_print_req_sense("st", SRpnt);
} else
printk(KERN_WARNING
"%s: Error %x (sugg. bt 0x%x, driver bt 0x%x, host bt 0x%x).\n",
/* Wakeup from interrupt */
-static void st_sleep_done(Scsi_Cmnd * SCpnt)
+static void st_sleep_done(struct scsi_cmnd * SCpnt)
{
int remainder;
- Scsi_Tape *STp = container_of(SCpnt->request->rq_disk->private_data,
- Scsi_Tape, driver);
+ struct scsi_tape *STp = container_of(SCpnt->request->rq_disk->private_data,
+ struct scsi_tape, driver);
if ((STp->buffer)->writing &&
(SCpnt->sense_buffer[0] & 0x70) == 0x70 &&
/* Do the scsi command. Waits until command performed if do_wait is true.
Otherwise write_behind_check() is used to check that the command
has finished. */
-static Scsi_Request *
- st_do_scsi(Scsi_Request * SRpnt, Scsi_Tape * STp, unsigned char *cmd, int bytes,
- int direction, int timeout, int retries, int do_wait)
+static struct scsi_request *
+st_do_scsi(struct scsi_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd,
+ int bytes, int direction, int timeout, int retries, int do_wait)
{
unsigned char *bp;
/* Handle the write-behind checking (downs the semaphore) */
-static void write_behind_check(Scsi_Tape * STp)
+static void write_behind_check(struct scsi_tape * STp)
{
- ST_buffer *STbuffer;
- ST_partstat *STps;
+ struct st_buffer *STbuffer;
+ struct st_partstat *STps;
STbuffer = STp->buffer;
/* Step over EOF if it has been inadvertently crossed (ioctl not used because
it messes up the block number). */
-static int cross_eof(Scsi_Tape * STp, int forward)
+static int cross_eof(struct scsi_tape * STp, int forward)
{
- Scsi_Request *SRpnt;
+ struct scsi_request *SRpnt;
unsigned char cmd[MAX_COMMAND_SIZE];
cmd[0] = SPACE;
DEBC(printk(ST_DEB_MSG "%s: Stepping over filemark %s.\n",
tape_name(STp), forward ? "forward" : "backward"));
- SRpnt = st_do_scsi(NULL, STp, cmd, 0, SCSI_DATA_NONE,
- STp->device->timeout, MAX_RETRIES, TRUE);
+ SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
+ STp->device->timeout, MAX_RETRIES, 1);
if (!SRpnt)
return (STp->buffer)->syscall_result;
/* Flush the write buffer (never need to write if variable blocksize). */
-static int flush_write_buffer(Scsi_Tape * STp)
+static int flush_write_buffer(struct scsi_tape * STp)
{
int offset, transfer, blks;
int result;
unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request *SRpnt;
- ST_partstat *STps;
+ struct scsi_request *SRpnt;
+ struct st_partstat *STps;
if ((STp->buffer)->writing) {
write_behind_check(STp);
cmd[3] = blks >> 8;
cmd[4] = blks;
- SRpnt = st_do_scsi(NULL, STp, cmd, transfer, SCSI_DATA_WRITE,
- STp->device->timeout, MAX_WRITE_RETRIES, TRUE);
+ SRpnt = st_do_scsi(NULL, STp, cmd, transfer, DMA_TO_DEVICE,
+ STp->device->timeout, MAX_WRITE_RETRIES, 1);
if (!SRpnt)
return (STp->buffer)->syscall_result;
/* Flush the tape buffer. The tape will be positioned correctly unless
seek_next is true. */
-static int flush_buffer(Scsi_Tape *STp, int seek_next)
+static int flush_buffer(struct scsi_tape *STp, int seek_next)
{
int backspace, result;
- ST_buffer *STbuffer;
- ST_partstat *STps;
+ struct st_buffer *STbuffer;
+ struct st_partstat *STps;
STbuffer = STp->buffer;
result = 0;
if (!seek_next) {
if (STps->eof == ST_FM_HIT) {
- result = cross_eof(STp, FALSE); /* Back over the EOF hit */
+ result = cross_eof(STp, 0); /* Back over the EOF hit */
if (!result)
STps->eof = ST_NOEOF;
else {
}
\f
/* Set the mode parameters */
-static int set_mode_densblk(Scsi_Tape * STp, ST_mode * STm)
+static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm)
{
- int set_it = FALSE;
+ int set_it = 0;
unsigned long arg;
char *name = tape_name(STp);
STm->default_density >= 0 &&
STm->default_density != STp->density) {
arg = STm->default_density;
- set_it = TRUE;
+ set_it = 1;
} else
arg = STp->density;
arg <<= MT_ST_DENSITY_SHIFT;
STm->default_blksize >= 0 &&
STm->default_blksize != STp->block_size) {
arg |= STm->default_blksize;
- set_it = TRUE;
+ set_it = 1;
} else
arg |= STp->block_size;
if (set_it &&
}
-/* Lock or unlock the drive door. Don't use when Scsi_Request allocated. */
-static int do_door_lock(Scsi_Tape * STp, int do_lock)
+/* Lock or unlock the drive door. Don't use when scsi_request allocated. */
+static int do_door_lock(struct scsi_tape * STp, int do_lock)
{
int retval, cmd;
DEB(char *name = tape_name(STp);)
/* Set the internal state after reset */
-static void reset_state(Scsi_Tape *STp)
+static void reset_state(struct scsi_tape *STp)
{
int i;
- ST_partstat *STps;
+ struct st_partstat *STps;
STp->pos_unknown = 0;
for (i = 0; i < ST_NBR_PARTITIONS; i++) {
STps->rw = ST_IDLE;
STps->eof = ST_NOEOF;
STps->at_sm = 0;
- STps->last_block_valid = FALSE;
+ STps->last_block_valid = 0;
STps->drv_block = -1;
STps->drv_file = -1;
}
#define MAX_ATTENTIONS 10
-static int test_ready(Scsi_Tape *STp, int do_wait)
+static int test_ready(struct scsi_tape *STp, int do_wait)
{
int attentions, waits, max_wait, scode;
- int retval = CHKRES_READY, new_session = FALSE;
+ int retval = CHKRES_READY, new_session = 0;
unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request *SRpnt = NULL;
+ struct scsi_request *SRpnt = NULL;
max_wait = do_wait ? ST_BLOCK_SECONDS : 0;
for (attentions=waits=0; ; ) {
memset((void *) &cmd[0], 0, MAX_COMMAND_SIZE);
cmd[0] = TEST_UNIT_READY;
- SRpnt = st_do_scsi(SRpnt, STp, cmd, 0, SCSI_DATA_NONE,
- STp->long_timeout, MAX_READY_RETRIES, TRUE);
+ SRpnt = st_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
+ STp->long_timeout, MAX_READY_RETRIES, 1);
if (!SRpnt) {
retval = (STp->buffer)->syscall_result;
scode = (SRpnt->sr_sense_buffer[2] & 0x0f);
if (scode == UNIT_ATTENTION) { /* New media? */
- new_session = TRUE;
+ new_session = 1;
if (attentions < MAX_ATTENTIONS) {
attentions++;
continue;
0 drive ready
1 drive not ready (possibly no tape)
*/
-static int check_tape(Scsi_Tape *STp, struct file *filp)
+static int check_tape(struct scsi_tape *STp, struct file *filp)
{
- int i, retval, new_session = FALSE, do_wait;
+ int i, retval, new_session = 0, do_wait;
unsigned char cmd[MAX_COMMAND_SIZE], saved_cleaning;
unsigned short st_flags = filp->f_flags;
- Scsi_Request *SRpnt = NULL;
- ST_mode *STm;
- ST_partstat *STps;
+ struct scsi_request *SRpnt = NULL;
+ struct st_modedef *STm;
+ struct st_partstat *STps;
char *name = tape_name(STp);
struct inode *inode = filp->f_dentry->d_inode;
int mode = TAPE_MODE(inode);
if (mode != STp->current_mode) {
DEBC(printk(ST_DEB_MSG "%s: Mode change from %d to %d.\n",
name, STp->current_mode, mode));
- new_session = TRUE;
+ new_session = 1;
STp->current_mode = mode;
}
STm = &(STp->modes[STp->current_mode]);
STps->rw = ST_IDLE;
STps->eof = ST_NOEOF;
STps->at_sm = 0;
- STps->last_block_valid = FALSE;
+ STps->last_block_valid = 0;
STps->drv_block = 0;
STps->drv_file = 0;
}
- new_session = TRUE;
+ new_session = 1;
}
else {
STp->cleaning_req |= saved_cleaning;
memset((void *) &cmd[0], 0, MAX_COMMAND_SIZE);
cmd[0] = READ_BLOCK_LIMITS;
- SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, SCSI_DATA_READ, STp->device->timeout,
- MAX_READY_RETRIES, TRUE);
+ SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, DMA_FROM_DEVICE,
+ STp->device->timeout, MAX_READY_RETRIES, 1);
if (!SRpnt) {
retval = (STp->buffer)->syscall_result;
goto err_out;
cmd[0] = MODE_SENSE;
cmd[4] = 12;
- SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, SCSI_DATA_READ, STp->device->timeout,
- MAX_READY_RETRIES, TRUE);
+ SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, DMA_FROM_DEVICE,
+ STp->device->timeout, MAX_READY_RETRIES, 1);
if (!SRpnt) {
retval = (STp->buffer)->syscall_result;
goto err_out;
}
scsi_release_request(SRpnt);
SRpnt = NULL;
- STp->inited = TRUE;
+ STp->inited = 1;
if (STp->block_size > 0)
(STp->buffer)->buffer_blocks =
}
if (new_session) { /* Change the drive parameters for the new mode */
- STp->density_changed = STp->blksize_changed = FALSE;
- STp->compression_changed = FALSE;
+ STp->density_changed = STp->blksize_changed = 0;
+ STp->compression_changed = 0;
if (!(STm->defaults_for_writes) &&
(retval = set_mode_densblk(STp, STm)) < 0)
goto err_out;
static int st_open(struct inode *inode, struct file *filp)
{
int i, retval = (-EIO);
- Scsi_Tape *STp;
- ST_partstat *STps;
+ struct scsi_tape *STp;
+ struct st_partstat *STps;
int dev = TAPE_NR(inode);
char *name;
{
int result = 0, result2;
unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request *SRpnt;
- Scsi_Tape *STp = filp->private_data;
- ST_mode *STm = &(STp->modes[STp->current_mode]);
- ST_partstat *STps = &(STp->ps[STp->partition]);
+ struct scsi_request *SRpnt;
+ struct scsi_tape *STp = filp->private_data;
+ struct st_modedef *STm = &(STp->modes[STp->current_mode]);
+ struct st_partstat *STps = &(STp->ps[STp->partition]);
char *name = tape_name(STp);
if (file_count(filp) > 1)
if (STps->rw == ST_WRITING && !STp->pos_unknown) {
- DEBC(printk(ST_DEB_MSG "%s: File length %ld bytes.\n",
- name, (long) (filp->f_pos));
+ DEBC(printk(ST_DEB_MSG "%s: File length %lld bytes.\n",
+ name, (long long)filp->f_pos);
printk(ST_DEB_MSG "%s: Async write waits %d, finished %d.\n",
name, STp->nbr_waits, STp->nbr_finished);
)
cmd[0] = WRITE_FILEMARKS;
cmd[4] = 1 + STp->two_fm;
- SRpnt = st_do_scsi(NULL, STp, cmd, 0, SCSI_DATA_NONE,
- STp->device->timeout, MAX_WRITE_RETRIES, TRUE);
+ SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
+ STp->device->timeout, MAX_WRITE_RETRIES, 1);
if (!SRpnt) {
result = (STp->buffer)->syscall_result;
goto out;
STps->drv_file++;
STps->drv_block = 0;
if (STp->two_fm)
- cross_eof(STp, FALSE);
+ cross_eof(STp, 0);
STps->eof = ST_FM;
}
if (STp->can_bsr)
result = flush_buffer(STp, 0);
else if (STps->eof == ST_FM_HIT) {
- result = cross_eof(STp, FALSE);
+ result = cross_eof(STp, 0);
if (result) {
if (STps->drv_file >= 0)
STps->drv_file++;
STps->eof = ST_NOEOF;
}
} else if ((STps->eof == ST_NOEOF &&
- !(result = cross_eof(STp, TRUE))) ||
+ !(result = cross_eof(STp, 1))) ||
STps->eof == ST_FM_HIT) {
if (STps->drv_file >= 0)
STps->drv_file++;
static int st_release(struct inode *inode, struct file *filp)
{
int result = 0;
- Scsi_Tape *STp = filp->private_data;
+ struct scsi_tape *STp = filp->private_data;
if (STp->door_locked == ST_LOCKED_AUTO)
do_door_lock(STp, 0);
}
\f
/* The checks common to both reading and writing */
-static ssize_t rw_checks(Scsi_Tape *STp, struct file *filp, size_t count)
+static ssize_t rw_checks(struct scsi_tape *STp, struct file *filp, size_t count)
{
ssize_t retval = 0;
}
-static int setup_buffering(Scsi_Tape *STp, const char __user *buf, size_t count, int is_read)
+static int setup_buffering(struct scsi_tape *STp, const char __user *buf,
+ size_t count, int is_read)
{
int i, bufsize, retval = 0;
- ST_buffer *STbp = STp->buffer;
+ struct st_buffer *STbp = STp->buffer;
if (is_read)
i = STp->try_dio && try_rdio;
STbp->buffer_bytes = 0; /* can be used as transfer counter */
}
else
- STbp->do_dio = FALSE; /* fall back to buffering with any error */
+ STbp->do_dio = 0; /* fall back to buffering with any error */
STbp->sg_segs = STbp->do_dio;
STbp->frp_sg_current = 0;
DEB(
}
)
} else
- STbp->do_dio = FALSE;
+ STbp->do_dio = 0;
DEB( STp->nbr_requests++; )
if (!STbp->do_dio) {
/* Can be called more than once after each setup_buffer() */
-static void release_buffering(Scsi_Tape *STp)
+static void release_buffering(struct scsi_tape *STp)
{
- ST_buffer *STbp;
+ struct st_buffer *STbp;
STbp = STp->buffer;
if (STbp->do_dio) {
- sgl_unmap_user_pages(&(STbp->sg[0]), STbp->do_dio, FALSE);
+ sgl_unmap_user_pages(&(STbp->sg[0]), STbp->do_dio, 0);
STbp->do_dio = 0;
}
}
int async_write;
unsigned char cmd[MAX_COMMAND_SIZE];
const char __user *b_point;
- Scsi_Request *SRpnt = NULL;
- Scsi_Tape *STp = filp->private_data;
- ST_mode *STm;
- ST_partstat *STps;
- ST_buffer *STbp;
+ struct scsi_request *SRpnt = NULL;
+ struct scsi_tape *STp = filp->private_data;
+ struct st_modedef *STm;
+ struct st_partstat *STps;
+ struct st_buffer *STbp;
char *name = tape_name(STp);
if (down_interruptible(&STp->lock))
goto out;
}
- retval = setup_buffering(STp, buf, count, FALSE);
+ retval = setup_buffering(STp, buf, count, 0);
if (retval)
goto out;
if (STp->block_size != 0 && STm->do_buffer_writes &&
!(STp->try_dio && try_wdio) && STps->eof < ST_EOM_OK &&
STbp->buffer_bytes < STbp->buffer_size) {
- STp->dirty = TRUE;
+ STp->dirty = 1;
/* Don't write a buffer that is not full enough. */
if (!async_write && count == 0)
break;
cmd[3] = blks >> 8;
cmd[4] = blks;
- SRpnt = st_do_scsi(SRpnt, STp, cmd, transfer, SCSI_DATA_WRITE,
+ SRpnt = st_do_scsi(SRpnt, STp, cmd, transfer, DMA_TO_DEVICE,
STp->device->timeout, MAX_WRITE_RETRIES, !async_write);
if (!SRpnt) {
retval = STbp->syscall_result;
if (!retry_eot && (SRpnt->sr_sense_buffer[0] & 1) == 0 &&
(scode == NO_SENSE || scode == RECOVERED_ERROR)) {
move_buffer_data(STp->buffer, transfer - undone);
- retry_eot = TRUE;
+ retry_eot = 1;
if (STps->drv_block >= 0) {
STps->drv_block += (transfer - undone) /
STp->block_size;
Does release user buffer mapping if it is set.
*/
-static long read_tape(Scsi_Tape *STp, long count, Scsi_Request ** aSRpnt)
+static long read_tape(struct scsi_tape *STp, long count,
+ struct scsi_request ** aSRpnt)
{
int transfer, blks, bytes;
unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request *SRpnt;
- ST_mode *STm;
- ST_partstat *STps;
- ST_buffer *STbp;
+ struct scsi_request *SRpnt;
+ struct st_modedef *STm;
+ struct st_partstat *STps;
+ struct st_buffer *STbp;
int retval = 0;
char *name = tape_name(STp);
cmd[4] = blks;
SRpnt = *aSRpnt;
- SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, SCSI_DATA_READ,
- STp->device->timeout, MAX_RETRIES, TRUE);
+ SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE,
+ STp->device->timeout, MAX_RETRIES, 1);
release_buffering(STp);
*aSRpnt = SRpnt;
if (!SRpnt)
ssize_t retval = 0;
ssize_t i, transfer;
int special, do_dio = 0;
- Scsi_Request *SRpnt = NULL;
- Scsi_Tape *STp = filp->private_data;
- ST_mode *STm;
- ST_partstat *STps;
- ST_buffer *STbp = STp->buffer;
+ struct scsi_request *SRpnt = NULL;
+ struct scsi_tape *STp = filp->private_data;
+ struct st_modedef *STm;
+ struct st_partstat *STps;
+ struct st_buffer *STbp = STp->buffer;
DEB( char *name = tape_name(STp); )
if (down_interruptible(&STp->lock))
STps->eof, STbp->buffer_bytes);
) /* end DEB */
- retval = setup_buffering(STp, buf, count, TRUE);
+ retval = setup_buffering(STp, buf, count, 1);
if (retval)
goto out;
do_dio = STbp->do_dio;
DEB(
/* Set the driver options */
-static void st_log_options(Scsi_Tape * STp, ST_mode * STm, char *name)
+static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm, char *name)
{
if (debugging) {
printk(KERN_INFO
)
-static int st_set_options(Scsi_Tape *STp, long options)
+static int st_set_options(struct scsi_tape *STp, long options)
{
int value;
long code;
- ST_mode *STm;
+ struct st_modedef *STm;
char *name = tape_name(STp);
struct cdev *cd0, *cd1;
STm = &(STp->modes[STp->current_mode]);
if (!STm->defined) {
cd0 = STm->cdevs[0]; cd1 = STm->cdevs[1];
- memcpy(STm, &(STp->modes[0]), sizeof(ST_mode));
+ memcpy(STm, &(STp->modes[0]), sizeof(struct st_modedef));
STm->cdevs[0] = cd0; STm->cdevs[1] = cd1;
- modes_defined = TRUE;
+ modes_defined = 1;
DEBC(printk(ST_DEB_MSG
"%s: Initialized mode %d definition from mode 0\n",
name, STp->current_mode));
DEBC( printk(KERN_INFO "%s: Default block size set to %d bytes.\n",
name, STm->default_blksize));
if (STp->ready == ST_READY) {
- STp->blksize_changed = FALSE;
+ STp->blksize_changed = 0;
set_mode_densblk(STp, STm);
}
}
DEBC( printk(KERN_INFO "%s: Density default set to %x\n",
name, STm->default_density));
if (STp->ready == ST_READY) {
- STp->density_changed = FALSE;
+ STp->density_changed = 0;
set_mode_densblk(STp, STm);
}
}
DEBC( printk(KERN_INFO "%s: Compression default set to %x\n",
name, (value & 1)));
if (STp->ready == ST_READY) {
- STp->compression_changed = FALSE;
+ STp->compression_changed = 0;
st_compression(STp, (STm->default_compression == ST_YES));
}
}
/* Read a mode page into the tape buffer. The block descriptors are included
if incl_block_descs is true. The page control is ored to the page number
parameter, if necessary. */
-static int read_mode_page(Scsi_Tape *STp, int page, int omit_block_descs)
+static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs)
{
unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request *SRpnt = NULL;
+ struct scsi_request *SRpnt = NULL;
memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = MODE_SENSE;
cmd[2] = page;
cmd[4] = 255;
- SRpnt = st_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_READ,
- STp->device->timeout, 0, TRUE);
+ SRpnt = st_do_scsi(SRpnt, STp, cmd, cmd[4], DMA_FROM_DEVICE,
+ STp->device->timeout, 0, 1);
if (SRpnt == NULL)
return (STp->buffer)->syscall_result;
/* Send the mode page in the tape buffer to the drive. Assumes that the mode data
in the buffer is correctly formatted. The long timeout is used if slow is non-zero. */
-static int write_mode_page(Scsi_Tape *STp, int page, int slow)
+static int write_mode_page(struct scsi_tape *STp, int page, int slow)
{
int pgo;
unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request *SRpnt = NULL;
+ struct scsi_request *SRpnt = NULL;
memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = MODE_SELECT;
(STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP;
(STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR;
- SRpnt = st_do_scsi(SRpnt, STp, cmd, cmd[4], SCSI_DATA_WRITE,
- (slow ? STp->long_timeout : STp->device->timeout), 0, TRUE);
+ SRpnt = st_do_scsi(SRpnt, STp, cmd, cmd[4], DMA_TO_DEVICE,
+ (slow ? STp->long_timeout : STp->device->timeout), 0, 1);
if (SRpnt == NULL)
return (STp->buffer)->syscall_result;
work without this (suggestion from Michael Schaefer <Michael.Schaefer@dlr.de>).
Including block descriptors should not cause any harm to other drives. */
-static int st_compression(Scsi_Tape * STp, int state)
+static int st_compression(struct scsi_tape * STp, int state)
{
int retval;
int mpoffs; /* Offset to mode page start */
return (-EIO);
/* Read the current page contents */
- retval = read_mode_page(STp, COMPRESSION_PAGE, FALSE);
+ retval = read_mode_page(STp, COMPRESSION_PAGE, 0);
if (retval) {
DEBC(printk(ST_DEB_MSG "%s: Compression mode page not supported.\n",
name));
b_data[mpoffs + CP_OFF_C_ALGO] = 0; /* no compression */
}
- retval = write_mode_page(STp, COMPRESSION_PAGE, FALSE);
+ retval = write_mode_page(STp, COMPRESSION_PAGE, 0);
if (retval) {
DEBC(printk(ST_DEB_MSG "%s: Compression change failed.\n", name));
return (-EIO);
DEBC(printk(ST_DEB_MSG "%s: Compression state changed to %d.\n",
name, state));
- STp->compression_changed = TRUE;
+ STp->compression_changed = 1;
return 0;
}
/* Process the load and unload commands (does unload if the load code is zero) */
-static int do_load_unload(Scsi_Tape *STp, struct file *filp, int load_code)
+static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_code)
{
int retval = (-EIO), timeout;
DEB( char *name = tape_name(STp); )
unsigned char cmd[MAX_COMMAND_SIZE];
- ST_partstat *STps;
- Scsi_Request *SRpnt;
+ struct st_partstat *STps;
+ struct scsi_request *SRpnt;
if (STp->ready != ST_READY && !load_code) {
if (STp->ready == ST_NO_TAPE)
printk(ST_DEB_MSG "%s: Loading tape.\n", name);
);
- SRpnt = st_do_scsi(NULL, STp, cmd, 0, SCSI_DATA_NONE,
- timeout, MAX_RETRIES, TRUE);
+ SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
+ timeout, MAX_RETRIES, 1);
if (!SRpnt)
return (STp->buffer)->syscall_result;
\f
/* Internal ioctl function */
-static int st_int_ioctl(Scsi_Tape *STp, unsigned int cmd_in, unsigned long arg)
+static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned long arg)
{
int timeout;
long ltmp;
int ioctl_result;
- int chg_eof = TRUE;
+ int chg_eof = 1;
unsigned char cmd[MAX_COMMAND_SIZE];
- Scsi_Request *SRpnt;
- ST_partstat *STps;
+ struct scsi_request *SRpnt;
+ struct st_partstat *STps;
int fileno, blkno, at_sm, undone;
- int datalen = 0, direction = SCSI_DATA_NONE;
+ int datalen = 0, direction = DMA_NONE;
char *name = tape_name(STp);
WARN_ON(STp->buffer->do_dio != 0);
memset(cmd, 0, MAX_COMMAND_SIZE);
switch (cmd_in) {
case MTFSFM:
- chg_eof = FALSE; /* Changed from the FSF after this */
+ chg_eof = 0; /* Changed from the FSF after this */
case MTFSF:
cmd[0] = SPACE;
cmd[1] = 0x01; /* Space FileMarks */
at_sm &= (arg == 0);
break;
case MTBSFM:
- chg_eof = FALSE; /* Changed from the FSF after this */
+ chg_eof = 0; /* Changed from the FSF after this */
case MTBSF:
cmd[0] = SPACE;
cmd[1] = 0x01; /* Space FileMarks */
case MTSETDENSITY: /* Set tape density */
case MTSETDRVBUFFER: /* Set drive buffering */
case SET_DENS_AND_BLK: /* Set density and block size */
- chg_eof = FALSE;
+ chg_eof = 0;
if (STp->dirty || (STp->buffer)->buffer_bytes != 0)
return (-EIO); /* Not allowed if data in buffer */
if ((cmd_in == MTSETBLK || cmd_in == SET_DENS_AND_BLK) &&
if ((STp->use_pf & USE_PF))
cmd[1] = MODE_SELECT_PAGE_FORMAT;
cmd[4] = datalen = 12;
- direction = SCSI_DATA_WRITE;
+ direction = DMA_TO_DEVICE;
memset((STp->buffer)->b_data, 0, 12);
if (cmd_in == MTSETDRVBUFFER)
(STp->buffer)->b_data[3] = 8; /* block descriptor length */
if (cmd_in == MTSETDENSITY) {
(STp->buffer)->b_data[4] = arg;
- STp->density_changed = TRUE; /* At least we tried ;-) */
+ STp->density_changed = 1; /* At least we tried ;-) */
} else if (cmd_in == SET_DENS_AND_BLK)
(STp->buffer)->b_data[4] = arg >> 24;
else
if (cmd_in == MTSETBLK || cmd_in == SET_DENS_AND_BLK) {
ltmp = arg & MT_ST_BLKSIZE_MASK;
if (cmd_in == MTSETBLK)
- STp->blksize_changed = TRUE; /* At least we tried ;-) */
+ STp->blksize_changed = 1; /* At least we tried ;-) */
} else
ltmp = STp->block_size;
(STp->buffer)->b_data[9] = (ltmp >> 16);
}
SRpnt = st_do_scsi(NULL, STp, cmd, datalen, direction,
- timeout, MAX_RETRIES, TRUE);
+ timeout, MAX_RETRIES, 1);
if (!SRpnt)
return (STp->buffer)->syscall_result;
/* Get the tape position. If bt == 2, arg points into a kernel space mt_loc
structure. */
-static int get_location(Scsi_Tape *STp, unsigned int *block, int *partition,
+static int get_location(struct scsi_tape *STp, unsigned int *block, int *partition,
int logical)
{
int result;
unsigned char scmd[MAX_COMMAND_SIZE];
- Scsi_Request *SRpnt;
+ struct scsi_request *SRpnt;
DEB( char *name = tape_name(STp); )
if (STp->ready != ST_READY)
if (!logical && !STp->scsi2_logical)
scmd[1] = 1;
}
- SRpnt = st_do_scsi(NULL, STp, scmd, 20, SCSI_DATA_READ, STp->device->timeout,
- MAX_READY_RETRIES, TRUE);
+ SRpnt = st_do_scsi(NULL, STp, scmd, 20, DMA_FROM_DEVICE,
+ STp->device->timeout, MAX_READY_RETRIES, 1);
if (!SRpnt)
return (STp->buffer)->syscall_result;
/* Set the tape block and partition. Negative partition means that only the
block should be set in vendor specific way. */
-static int set_location(Scsi_Tape *STp, unsigned int block, int partition,
+static int set_location(struct scsi_tape *STp, unsigned int block, int partition,
int logical)
{
- ST_partstat *STps;
+ struct st_partstat *STps;
int result, p;
unsigned int blk;
int timeout;
unsigned char scmd[MAX_COMMAND_SIZE];
- Scsi_Request *SRpnt;
+ struct scsi_request *SRpnt;
DEB( char *name = tape_name(STp); )
if (STp->ready != ST_READY)
return (-EINVAL);
if (partition != STp->partition) {
if (get_location(STp, &blk, &p, 1))
- STps->last_block_valid = FALSE;
+ STps->last_block_valid = 0;
else {
- STps->last_block_valid = TRUE;
+ STps->last_block_valid = 1;
STps->last_block_visited = blk;
DEBC(printk(ST_DEB_MSG
"%s: Visited block %d for partition %d saved.\n",
timeout = STp->device->timeout;
}
- SRpnt = st_do_scsi(NULL, STp, scmd, 0, SCSI_DATA_NONE,
- timeout, MAX_READY_RETRIES, TRUE);
+ SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE,
+ timeout, MAX_READY_RETRIES, 1);
if (!SRpnt)
return (STp->buffer)->syscall_result;
/* Find the current partition number for the drive status. Called from open and
returns either partition number of negative error code. */
-static int find_partition(Scsi_Tape *STp)
+static int find_partition(struct scsi_tape *STp)
{
int i, partition;
unsigned int block;
/* Change the partition if necessary */
-static int switch_partition(Scsi_Tape *STp)
+static int switch_partition(struct scsi_tape *STp)
{
- ST_partstat *STps;
+ struct st_partstat *STps;
if (STp->partition == STp->new_partition)
return 0;
/* Get the number of partitions on the tape. As a side effect reads the
mode page into the tape buffer. */
-static int nbr_partitions(Scsi_Tape *STp)
+static int nbr_partitions(struct scsi_tape *STp)
{
int result;
DEB( char *name = tape_name(STp); )
if (STp->ready != ST_READY)
return (-EIO);
- result = read_mode_page(STp, PART_PAGE, TRUE);
+ result = read_mode_page(STp, PART_PAGE, 1);
if (result) {
DEBC(printk(ST_DEB_MSG "%s: Can't read medium partition page.\n",
is acceptable also to some other old drives and enforced if the first partition
size field is used for the first additional partition size.
*/
-static int partition_tape(Scsi_Tape *STp, int size)
+static int partition_tape(struct scsi_tape *STp, int size)
{
char *name = tape_name(STp);
int result;
int pgo, psd_cnt, psdo;
unsigned char *bp;
- result = read_mode_page(STp, PART_PAGE, FALSE);
+ result = read_mode_page(STp, PART_PAGE, 0);
if (result) {
DEBC(printk(ST_DEB_MSG "%s: Can't read partition mode page.\n", name));
return result;
bp[pgo + PP_OFF_RESERVED] = 0;
bp[pgo + PP_OFF_FLAGS] = PP_BIT_IDP | PP_MSK_PSUM_MB;
- result = write_mode_page(STp, PART_PAGE, TRUE);
+ result = write_mode_page(STp, PART_PAGE, 1);
if (result) {
printk(KERN_INFO "%s: Partitioning of tape failed.\n", name);
result = (-EIO);
int i, cmd_nr, cmd_type, bt;
int retval = 0;
unsigned int blk;
- Scsi_Tape *STp = file->private_data;
- ST_mode *STm;
- ST_partstat *STps;
+ struct scsi_tape *STp = file->private_data;
+ struct st_modedef *STm;
+ struct st_partstat *STps;
char *name = tape_name(STp);
void __user *p = (void __user *)arg;
* may try and take the device offline, in which case all further
* access to the device is prohibited.
*/
- if (!scsi_block_when_processing_errors(STp->device)) {
- retval = (-ENXIO);
+ retval = scsi_nonblockable_ioctl(STp->device, cmd_in, p, file);
+ if (!scsi_block_when_processing_errors(STp->device) || retval != -ENODEV)
goto out;
- }
+ retval = 0;
+
cmd_type = _IOC_TYPE(cmd_in);
cmd_nr = _IOC_NR(cmd_in);
for (i = 0; i < ST_NBR_PARTITIONS; i++) {
STp->ps[i].rw = ST_IDLE;
STp->ps[i].at_sm = 0;
- STp->ps[i].last_block_valid = FALSE;
+ STp->ps[i].last_block_valid = 0;
}
STp->partition = STp->new_partition = 0;
STp->nbr_partitions = 1; /* Bad guess ?-) */
goto out;
}
- if ((i = flush_buffer(STp, FALSE)) < 0) {
+ if ((i = flush_buffer(STp, 0)) < 0) {
retval = i;
goto out;
}
/* Try to allocate a new tape buffer. Calling function must not hold
dev_arr_lock. */
-static ST_buffer *
+static struct st_buffer *
new_tape_buffer(int from_initialization, int need_dma, int max_sg)
{
int i, priority, got = 0, segs = 0;
- ST_buffer *tb;
+ struct st_buffer *tb;
if (from_initialization)
priority = GFP_ATOMIC;
else
priority = GFP_KERNEL;
- i = sizeof(ST_buffer) + (max_sg - 1) * sizeof(struct scatterlist) +
+ i = sizeof(struct st_buffer) + (max_sg - 1) * sizeof(struct scatterlist) +
max_sg * sizeof(struct st_buf_fragment);
tb = kmalloc(i, priority);
if (!tb) {
tb->b_data = page_address(tb->sg[0].page);
tb->frp = (struct st_buf_fragment *)(&(tb->sg[0]) + max_sg);
- tb->in_use = TRUE;
+ tb->in_use = 1;
tb->dma = need_dma;
tb->buffer_size = got;
/* Try to allocate enough space in the tape buffer */
-static int enlarge_buffer(ST_buffer * STbuffer, int new_size, int need_dma)
+static int enlarge_buffer(struct st_buffer * STbuffer, int new_size, int need_dma)
{
int segs, nbr, max_segs, b_size, priority, order, got;
if (new_size <= STbuffer->buffer_size)
- return TRUE;
+ return 1;
if (STbuffer->buffer_size <= PAGE_SIZE)
normalize_buffer(STbuffer); /* Avoid extra segment */
max_segs = STbuffer->use_sg;
nbr = max_segs - STbuffer->frp_segs;
if (nbr <= 0)
- return FALSE;
+ return 0;
priority = GFP_KERNEL | __GFP_NOWARN;
if (need_dma)
}
DEB(STbuffer->buffer_size = got);
normalize_buffer(STbuffer);
- return FALSE;
+ return 0;
}
STbuffer->frp[segs].length = b_size;
STbuffer->frp_segs += 1;
}
STbuffer->b_data = page_address(STbuffer->frp[0].page);
- return TRUE;
+ return 1;
}
/* Release the extra buffer */
-static void normalize_buffer(ST_buffer * STbuffer)
+static void normalize_buffer(struct st_buffer * STbuffer)
{
int i, order;
/* Move data from the user buffer to the tape buffer. Returns zero (success) or
negative error code. */
-static int append_to_buffer(const char __user *ubp, ST_buffer * st_bp, int do_count)
+static int append_to_buffer(const char __user *ubp, struct st_buffer * st_bp, int do_count)
{
int i, cnt, res, offset;
/* Move data from the tape buffer to the user buffer. Returns zero (success) or
negative error code. */
-static int from_buffer(ST_buffer * st_bp, char __user *ubp, int do_count)
+static int from_buffer(struct st_buffer * st_bp, char __user *ubp, int do_count)
{
int i, cnt, res, offset;
/* Move data towards start of buffer */
-static void move_buffer_data(ST_buffer * st_bp, int offset)
+static void move_buffer_data(struct st_buffer * st_bp, int offset)
{
int src_seg, dst_seg, src_offset = 0, dst_offset;
int count, total;
/* Fill the s/g list up to the length required for this transfer */
-static void buf_to_sg(ST_buffer *STbp, unsigned int length)
+static void buf_to_sg(struct st_buffer *STbp, unsigned int length)
{
int i;
unsigned int count;
struct scsi_device *SDp = to_scsi_device(dev);
struct gendisk *disk = NULL;
struct cdev *cdev = NULL;
- Scsi_Tape *tpnt = NULL;
- ST_mode *STm;
- ST_partstat *STps;
- ST_buffer *buffer;
+ struct scsi_tape *tpnt = NULL;
+ struct st_modedef *STm;
+ struct st_partstat *STps;
+ struct st_buffer *buffer;
int i, j, mode, dev_num, error;
char *stp;
u64 bounce_limit;
i = SDp->host->sg_tablesize;
if (st_max_sg_segs < i)
i = st_max_sg_segs;
- buffer = new_tape_buffer(TRUE, (SDp->host)->unchecked_isa_dma, i);
+ buffer = new_tape_buffer(1, (SDp->host)->unchecked_isa_dma, i);
if (buffer == NULL) {
- printk(KERN_ERR "st: Can't allocate new tape buffer. Device not attached.\n");
+ printk(KERN_ERR
+ "st: Can't allocate new tape buffer. Device not attached.\n");
goto out;
}
write_lock(&st_dev_arr_lock);
if (st_nr_dev >= st_dev_max) {
- Scsi_Tape **tmp_da;
+ struct scsi_tape **tmp_da;
int tmp_dev_max;
tmp_dev_max = max(st_nr_dev * 2, 8);
goto out_put_disk;
}
- tmp_da = kmalloc(tmp_dev_max * sizeof(Scsi_Tape *), GFP_ATOMIC);
+ tmp_da = kmalloc(tmp_dev_max * sizeof(struct scsi_tape *), GFP_ATOMIC);
if (tmp_da == NULL) {
write_unlock(&st_dev_arr_lock);
printk(KERN_ERR "st: Can't extend device array.\n");
goto out_put_disk;
}
- memset(tmp_da, 0, tmp_dev_max * sizeof(Scsi_Tape *));
+ memset(tmp_da, 0, tmp_dev_max * sizeof(struct scsi_tape *));
if (scsi_tapes != NULL) {
memcpy(tmp_da, scsi_tapes,
- st_dev_max * sizeof(Scsi_Tape *));
+ st_dev_max * sizeof(struct scsi_tape *));
kfree(scsi_tapes);
}
scsi_tapes = tmp_da;
if (i >= st_dev_max)
panic("scsi_devices corrupt (st)");
- tpnt = kmalloc(sizeof(Scsi_Tape), GFP_ATOMIC);
+ tpnt = kmalloc(sizeof(struct scsi_tape), GFP_ATOMIC);
if (tpnt == NULL) {
write_unlock(&st_dev_arr_lock);
printk(KERN_ERR "st: Can't allocate device descriptor.\n");
goto out_put_disk;
}
- memset(tpnt, 0, sizeof(Scsi_Tape));
+ memset(tpnt, 0, sizeof(struct scsi_tape));
tpnt->disk = disk;
sprintf(disk->disk_name, "st%d", i);
disk->private_data = &tpnt->driver;
for (i = 0; i < ST_NBR_MODES; i++) {
STm = &(tpnt->modes[i]);
- STm->defined = FALSE;
+ STm->defined = 0;
STm->sysv = ST_SYSV;
STm->defaults_for_writes = 0;
STm->do_async_writes = ST_ASYNC_WRITES;
STps->rw = ST_IDLE;
STps->eof = ST_NOEOF;
STps->at_sm = 0;
- STps->last_block_valid = FALSE;
+ STps->last_block_valid = 0;
STps->drv_block = (-1);
STps->drv_file = (-1);
}
tpnt->current_mode = 0;
- tpnt->modes[0].defined = TRUE;
+ tpnt->modes[0].defined = 1;
tpnt->density_changed = tpnt->compression_changed =
- tpnt->blksize_changed = FALSE;
+ tpnt->blksize_changed = 0;
init_MUTEX(&tpnt->lock);
st_nr_dev++;
static int st_remove(struct device *dev)
{
- Scsi_Device *SDp = to_scsi_device(dev);
- Scsi_Tape *tpnt;
+ struct scsi_device *SDp = to_scsi_device(dev);
+ struct scsi_tape *tpnt;
int i, j, mode;
write_lock(&st_dev_arr_lock);
/* The sysfs simple class interface */
static ssize_t st_defined_show(struct class_device *class_dev, char *buf)
{
- ST_mode *STm = (ST_mode *)class_get_devdata(class_dev);
+ struct st_modedef *STm = (struct st_modedef *)class_get_devdata(class_dev);
ssize_t l = 0;
l = snprintf(buf, PAGE_SIZE, "%d\n", STm->defined);
static ssize_t st_defblk_show(struct class_device *class_dev, char *buf)
{
- ST_mode *STm = (ST_mode *)class_get_devdata(class_dev);
+ struct st_modedef *STm = (struct st_modedef *)class_get_devdata(class_dev);
ssize_t l = 0;
l = snprintf(buf, PAGE_SIZE, "%d\n", STm->default_blksize);
static ssize_t st_defdensity_show(struct class_device *class_dev, char *buf)
{
- ST_mode *STm = (ST_mode *)class_get_devdata(class_dev);
+ struct st_modedef *STm = (struct st_modedef *)class_get_devdata(class_dev);
ssize_t l = 0;
char *fmt;
static ssize_t st_defcompression_show(struct class_device *class_dev, char *buf)
{
- ST_mode *STm = (ST_mode *)class_get_devdata(class_dev);
+ struct st_modedef *STm = (struct st_modedef *)class_get_devdata(class_dev);
ssize_t l = 0;
l = snprintf(buf, PAGE_SIZE, "%d\n", STm->default_compression - 1);
CLASS_DEVICE_ATTR(default_compression, S_IRUGO, st_defcompression_show, NULL);
-static void do_create_class_files(Scsi_Tape *STp, int dev_num, int mode)
+static void do_create_class_files(struct scsi_tape *STp, int dev_num, int mode)
{
int i, rew, error;
char name[10];
return nr_pages;
out_unmap:
- sgl_unmap_user_pages(sgl, nr_pages, FALSE);
+ sgl_unmap_user_pages(sgl, nr_pages, 0);
return 0;
}