diff options
Diffstat (limited to 'drivers/scsi/st.c')
-rw-r--r-- | drivers/scsi/st.c | 170 |
1 files changed, 124 insertions, 46 deletions
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index 71952703125..a860c3a9ae9 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -17,7 +17,7 @@ Last modified: 18-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Devfs support */ -static const char *verstr = "20080117"; +static const char *verstr = "20080224"; #include <linux/module.h> @@ -183,6 +183,7 @@ static int modes_defined; static struct st_buffer *new_tape_buffer(int, int, int); static int enlarge_buffer(struct st_buffer *, int, int); +static void clear_buffer(struct st_buffer *); 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); @@ -442,6 +443,7 @@ static void st_sleep_done(void *data, char *sense, int result, int resid) memcpy(SRpnt->sense, sense, SCSI_SENSE_BUFFERSIZE); (STp->buffer)->cmdstat.midlevel_result = SRpnt->result = result; + (STp->buffer)->cmdstat.residual = resid; DEB( STp->write_pending = 0; ) if (SRpnt->waiting) @@ -626,7 +628,7 @@ static int cross_eof(struct scsi_tape * STp, int forward) /* Flush the write buffer (never need to write if variable blocksize). */ -static int flush_write_buffer(struct scsi_tape * STp) +static int st_flush_write_buffer(struct scsi_tape * STp) { int offset, transfer, blks; int result; @@ -717,7 +719,7 @@ static int flush_buffer(struct scsi_tape *STp, int seek_next) return 0; STps = &(STp->ps[STp->partition]); if (STps->rw == ST_WRITING) /* Writing */ - return flush_write_buffer(STp); + return st_flush_write_buffer(STp); if (STp->block_size == 0) return 0; @@ -1159,6 +1161,7 @@ static int st_open(struct inode *inode, struct file *filp) goto err_out; } + (STp->buffer)->cleared = 0; (STp->buffer)->writing = 0; (STp->buffer)->syscall_result = 0; @@ -1172,7 +1175,7 @@ static int st_open(struct inode *inode, struct file *filp) STp->try_dio_now = STp->try_dio; STp->recover_count = 0; DEB( STp->nbr_waits = STp->nbr_finished = 0; - STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = STp->nbr_combinable = 0; ) + STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = 0; ) retval = check_tape(STp, filp); if (retval < 0) @@ -1211,7 +1214,7 @@ static int st_flush(struct file *filp, fl_owner_t id) return 0; if (STps->rw == ST_WRITING && !STp->pos_unknown) { - result = flush_write_buffer(STp); + result = st_flush_write_buffer(STp); if (result != 0 && result != (-ENOSPC)) goto out; } @@ -1226,8 +1229,8 @@ static int st_flush(struct file *filp, fl_owner_t id) } DEBC( if (STp->nbr_requests) - printk(KERN_DEBUG "%s: Number of r/w requests %d, dio used in %d, pages %d (%d).\n", - name, STp->nbr_requests, STp->nbr_dio, STp->nbr_pages, STp->nbr_combinable)); + printk(KERN_DEBUG "%s: Number of r/w requests %d, dio used in %d, pages %d.\n", + name, STp->nbr_requests, STp->nbr_dio, STp->nbr_pages)); if (STps->rw == ST_WRITING && !STp->pos_unknown) { struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat; @@ -1422,9 +1425,6 @@ static int setup_buffering(struct scsi_tape *STp, const char __user *buf, if (STbp->do_dio) { STp->nbr_dio++; STp->nbr_pages += STbp->do_dio; - for (i=1; i < STbp->do_dio; i++) - if (page_to_pfn(STbp->sg[i].page) == page_to_pfn(STbp->sg[i-1].page) + 1) - STp->nbr_combinable++; } ) } else @@ -1435,8 +1435,14 @@ static int setup_buffering(struct scsi_tape *STp, const char __user *buf, if (STp->block_size) bufsize = STp->block_size > st_fixed_buffer_size ? STp->block_size : st_fixed_buffer_size; - else + else { bufsize = count; + /* Make sure that data from previous user is not leaked even if + HBA does not return correct residual */ + if (is_read && STp->sili && !STbp->cleared) + clear_buffer(STbp); + } + if (bufsize > STbp->buffer_size && !enlarge_buffer(STbp, bufsize, STp->restr_dma)) { printk(KERN_WARNING "%s: Can't allocate %d byte tape buffer.\n", @@ -1786,6 +1792,8 @@ static long read_tape(struct scsi_tape *STp, long count, memset(cmd, 0, MAX_COMMAND_SIZE); cmd[0] = READ_6; cmd[1] = (STp->block_size != 0); + if (!cmd[1] && STp->sili) + cmd[1] |= 2; cmd[2] = blks >> 16; cmd[3] = blks >> 8; cmd[4] = blks; @@ -1914,8 +1922,11 @@ static long read_tape(struct scsi_tape *STp, long count, } /* End of error handling */ - else /* Read successful */ + else { /* Read successful */ STbp->buffer_bytes = bytes; + if (STp->sili) /* In fixed block mode residual is always zero here */ + STbp->buffer_bytes -= STp->buffer->cmdstat.residual; + } if (STps->drv_block >= 0) { if (STp->block_size == 0) @@ -2093,7 +2104,8 @@ static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm, char name, STm->defaults_for_writes, STp->omit_blklims, STp->can_partitions, STp->scsi2_logical); printk(KERN_INFO - "%s: sysv: %d nowait: %d\n", name, STm->sysv, STp->immediate); + "%s: sysv: %d nowait: %d sili: %d\n", name, STm->sysv, STp->immediate, + STp->sili); printk(KERN_INFO "%s: debugging: %d\n", name, debugging); } @@ -2136,6 +2148,7 @@ static int st_set_options(struct scsi_tape *STp, long options) STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0; STp->immediate = (options & MT_ST_NOWAIT) != 0; STm->sysv = (options & MT_ST_SYSV) != 0; + STp->sili = (options & MT_ST_SILI) != 0; DEB( debugging = (options & MT_ST_DEBUGGING) != 0; st_log_options(STp, STm, name); ) } else if (code == MT_ST_SETBOOLEANS || code == MT_ST_CLEARBOOLEANS) { @@ -2167,6 +2180,8 @@ static int st_set_options(struct scsi_tape *STp, long options) STp->immediate = value; if ((options & MT_ST_SYSV) != 0) STm->sysv = value; + if ((options & MT_ST_SILI) != 0) + STp->sili = value; DEB( if ((options & MT_ST_DEBUGGING) != 0) debugging = value; @@ -3658,6 +3673,8 @@ static int enlarge_buffer(struct st_buffer * STbuffer, int new_size, int need_dm STbuffer->frp_segs += 1; got += b_size; STbuffer->buffer_size = got; + if (STbuffer->cleared) + memset(page_address(STbuffer->frp[segs].page), 0, b_size); segs++; } STbuffer->b_data = page_address(STbuffer->frp[0].page); @@ -3666,6 +3683,17 @@ static int enlarge_buffer(struct st_buffer * STbuffer, int new_size, int need_dm } +/* Make sure that no data from previous user is in the internal buffer */ +static void clear_buffer(struct st_buffer * st_bp) +{ + int i; + + for (i=0; i < st_bp->frp_segs; i++) + memset(page_address(st_bp->frp[i].page), 0, st_bp->frp[i].length); + st_bp->cleared = 1; +} + + /* Release the extra buffer */ static void normalize_buffer(struct st_buffer * STbuffer) { @@ -3990,6 +4018,7 @@ static int st_probe(struct device *dev) tpnt->two_fm = ST_TWO_FM; tpnt->fast_mteom = ST_FAST_MTEOM; tpnt->scsi2_logical = ST_SCSI2LOGICAL; + tpnt->sili = ST_SILI; tpnt->immediate = ST_NOWAIT; tpnt->default_drvbuffer = 0xff; /* No forced buffering */ tpnt->partition = 0; @@ -4079,9 +4108,9 @@ out_free_tape: if (STm->cdevs[j]) { if (cdev == STm->cdevs[j]) cdev = NULL; - class_device_destroy(st_sysfs_class, - MKDEV(SCSI_TAPE_MAJOR, - TAPE_MINOR(i, mode, j))); + device_destroy(st_sysfs_class, + MKDEV(SCSI_TAPE_MAJOR, + TAPE_MINOR(i, mode, j))); cdev_del(STm->cdevs[j]); } } @@ -4119,9 +4148,9 @@ static int st_remove(struct device *dev) "tape"); for (mode = 0; mode < ST_NBR_MODES; ++mode) { for (j=0; j < 2; j++) { - class_device_destroy(st_sysfs_class, - MKDEV(SCSI_TAPE_MAJOR, - TAPE_MINOR(i, mode, j))); + device_destroy(st_sysfs_class, + MKDEV(SCSI_TAPE_MAJOR, + TAPE_MINOR(i, mode, j))); cdev_del(tpnt->modes[mode].cdevs[j]); tpnt->modes[mode].cdevs[j] = NULL; } @@ -4290,31 +4319,34 @@ static void do_remove_sysfs_files(void) /* The sysfs simple class interface */ -static ssize_t st_defined_show(struct class_device *class_dev, char *buf) +static ssize_t +st_defined_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct st_modedef *STm = (struct st_modedef *)class_get_devdata(class_dev); + struct st_modedef *STm = (struct st_modedef *)dev_get_drvdata(dev); ssize_t l = 0; l = snprintf(buf, PAGE_SIZE, "%d\n", STm->defined); return l; } -CLASS_DEVICE_ATTR(defined, S_IRUGO, st_defined_show, NULL); +DEVICE_ATTR(defined, S_IRUGO, st_defined_show, NULL); -static ssize_t st_defblk_show(struct class_device *class_dev, char *buf) +static ssize_t +st_defblk_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct st_modedef *STm = (struct st_modedef *)class_get_devdata(class_dev); + struct st_modedef *STm = (struct st_modedef *)dev_get_drvdata(dev); ssize_t l = 0; l = snprintf(buf, PAGE_SIZE, "%d\n", STm->default_blksize); return l; } -CLASS_DEVICE_ATTR(default_blksize, S_IRUGO, st_defblk_show, NULL); +DEVICE_ATTR(default_blksize, S_IRUGO, st_defblk_show, NULL); -static ssize_t st_defdensity_show(struct class_device *class_dev, char *buf) +static ssize_t +st_defdensity_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct st_modedef *STm = (struct st_modedef *)class_get_devdata(class_dev); + struct st_modedef *STm = (struct st_modedef *)dev_get_drvdata(dev); ssize_t l = 0; char *fmt; @@ -4323,24 +4355,67 @@ static ssize_t st_defdensity_show(struct class_device *class_dev, char *buf) return l; } -CLASS_DEVICE_ATTR(default_density, S_IRUGO, st_defdensity_show, NULL); +DEVICE_ATTR(default_density, S_IRUGO, st_defdensity_show, NULL); -static ssize_t st_defcompression_show(struct class_device *class_dev, char *buf) +static ssize_t +st_defcompression_show(struct device *dev, struct device_attribute *attr, + char *buf) { - struct st_modedef *STm = (struct st_modedef *)class_get_devdata(class_dev); + struct st_modedef *STm = (struct st_modedef *)dev_get_drvdata(dev); ssize_t l = 0; l = snprintf(buf, PAGE_SIZE, "%d\n", STm->default_compression - 1); return l; } -CLASS_DEVICE_ATTR(default_compression, S_IRUGO, st_defcompression_show, NULL); +DEVICE_ATTR(default_compression, S_IRUGO, st_defcompression_show, NULL); + +static ssize_t +st_options_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct st_modedef *STm = (struct st_modedef *)dev_get_drvdata(dev); + struct scsi_tape *STp; + int i, j, options; + ssize_t l = 0; + + for (i=0; i < st_dev_max; i++) { + for (j=0; j < ST_NBR_MODES; j++) + if (&scsi_tapes[i]->modes[j] == STm) + break; + if (j < ST_NBR_MODES) + break; + } + if (i == st_dev_max) + return 0; /* should never happen */ + + STp = scsi_tapes[i]; + + options = STm->do_buffer_writes ? MT_ST_BUFFER_WRITES : 0; + options |= STm->do_async_writes ? MT_ST_ASYNC_WRITES : 0; + options |= STm->do_read_ahead ? MT_ST_READ_AHEAD : 0; + DEB( options |= debugging ? MT_ST_DEBUGGING : 0 ); + options |= STp->two_fm ? MT_ST_TWO_FM : 0; + options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0; + options |= STm->defaults_for_writes ? MT_ST_DEF_WRITES : 0; + options |= STp->can_bsr ? MT_ST_CAN_BSR : 0; + options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0; + options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0; + options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0; + options |= STm->sysv ? MT_ST_SYSV : 0; + options |= STp->immediate ? MT_ST_NOWAIT : 0; + options |= STp->sili ? MT_ST_SILI : 0; + + l = snprintf(buf, PAGE_SIZE, "0x%08x\n", options); + return l; +} + +DEVICE_ATTR(options, S_IRUGO, st_options_show, NULL); static int do_create_class_files(struct scsi_tape *STp, int dev_num, int mode) { int i, rew, error; char name[10]; - struct class_device *st_class_member; + struct device *st_class_member; for (rew=0; rew < 2; rew++) { /* Make sure that the minor numbers corresponding to the four @@ -4349,29 +4424,32 @@ static int do_create_class_files(struct scsi_tape *STp, int dev_num, int mode) snprintf(name, 10, "%s%s%s", rew ? "n" : "", STp->disk->disk_name, st_formats[i]); st_class_member = - class_device_create(st_sysfs_class, NULL, - MKDEV(SCSI_TAPE_MAJOR, - TAPE_MINOR(dev_num, mode, rew)), - &STp->device->sdev_gendev, "%s", name); + device_create(st_sysfs_class, &STp->device->sdev_gendev, + MKDEV(SCSI_TAPE_MAJOR, + TAPE_MINOR(dev_num, mode, rew)), + "%s", name); if (IS_ERR(st_class_member)) { - printk(KERN_WARNING "st%d: class_device_create failed\n", + printk(KERN_WARNING "st%d: device_create failed\n", dev_num); error = PTR_ERR(st_class_member); goto out; } - class_set_devdata(st_class_member, &STp->modes[mode]); + dev_set_drvdata(st_class_member, &STp->modes[mode]); - error = class_device_create_file(st_class_member, - &class_device_attr_defined); + error = device_create_file(st_class_member, + &dev_attr_defined); + if (error) goto out; + error = device_create_file(st_class_member, + &dev_attr_default_blksize); if (error) goto out; - error = class_device_create_file(st_class_member, - &class_device_attr_default_blksize); + error = device_create_file(st_class_member, + &dev_attr_default_density); if (error) goto out; - error = class_device_create_file(st_class_member, - &class_device_attr_default_density); + error = device_create_file(st_class_member, + &dev_attr_default_compression); if (error) goto out; - error = class_device_create_file(st_class_member, - &class_device_attr_default_compression); + error = device_create_file(st_class_member, + &dev_attr_options); if (error) goto out; if (mode == 0 && rew == 0) { |