Lines Matching defs:STp
240 struct scsi_tape *STp = NULL;
246 STp = scsi_tapes[dev];
247 if (!STp) goto out;
249 kref_get(&STp->kref);
251 if (!STp->device)
254 if (scsi_device_get(STp->device))
260 kref_put(&STp->kref, scsi_tape_release);
261 STp = NULL;
265 return STp;
268 static void scsi_tape_put(struct scsi_tape *STp)
270 struct scsi_device *sdev = STp->device;
273 kref_put(&STp->kref, scsi_tape_release);
348 static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
353 char *name = tape_name(STp);
359 cmdstatp = &STp->buffer->cmdstat;
363 scode = STp->buffer->cmdstat.sense_hdr.sense_key;
396 STp->cln_mode >= EXTENDED_SENSE_START) { /* Only fixed format sense */
397 if (STp->cln_sense_value)
398 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] &
399 STp->cln_sense_mask) == STp->cln_sense_value);
401 STp->cleaning_req |= ((SRpnt->sense[STp->cln_mode] &
402 STp->cln_sense_mask) != 0);
406 STp->cleaning_req = 1; /* ASC and ASCQ => cleaning requested */
408 STp->pos_unknown |= STp->device->was_reset;
417 STp->recover_count++;
418 STp->recover_reg++;
429 STp->recover_count);
465 struct scsi_tape *STp = SRpnt->stp;
467 STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors;
468 STp->buffer->cmdstat.residual = req->resid_len;
523 st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd,
527 struct rq_map_data *mdata = &STp->buffer->map_data;
531 if (!do_wait && ((STp->buffer)->last_SRpnt)) {
533 tape_name(STp));
535 (STp->buffer)->syscall_result = (-EINTR);
537 (STp->buffer)->syscall_result = (-EBUSY);
542 SRpnt = st_allocate_request(STp);
550 (STp->buffer)->last_SRpnt = SRpnt;
552 waiting = &STp->wait;
556 if (STp->buffer->do_dio) {
558 mdata->nr_entries = STp->buffer->sg_segs;
559 mdata->pages = STp->buffer->mapped_pages;
561 mdata->page_order = STp->buffer->reserved_page_order;
564 mdata->pages = STp->buffer->reserved_pages;
569 STp->buffer->cmdstat.have_sense = 0;
570 STp->buffer->syscall_result = 0;
576 (STp->buffer)->syscall_result = (-EBUSY);
577 (STp->buffer)->last_SRpnt = NULL;
581 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt);
592 static int write_behind_check(struct scsi_tape * STp)
600 STbuffer = STp->buffer;
605 if (STp->write_pending)
606 STp->nbr_waits++;
608 STp->nbr_finished++;
611 wait_for_completion(&(STp->wait));
616 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt);
620 STps = &(STp->ps[STp->partition]);
622 if (STp->block_size == 0)
625 STps->drv_block += STbuffer->writing / STp->block_size;
647 tape_name(STp), STbuffer->cmdstat.midlevel_result, retval);) /* end DEB */
655 static int cross_eof(struct scsi_tape * STp, int forward)
670 tape_name(STp), forward ? "forward" : "backward"));
672 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
673 STp->device->request_queue->rq_timeout,
676 return (STp->buffer)->syscall_result;
681 if ((STp->buffer)->cmdstat.midlevel_result != 0)
683 tape_name(STp), forward ? "forward" : "backward");
685 return (STp->buffer)->syscall_result;
690 static int st_flush_write_buffer(struct scsi_tape * STp)
698 result = write_behind_check(STp);
703 if (STp->dirty == 1) {
705 transfer = STp->buffer->buffer_bytes;
707 tape_name(STp), transfer));
712 blks = transfer / STp->block_size;
717 SRpnt = st_do_scsi(NULL, STp, cmd, transfer, DMA_TO_DEVICE,
718 STp->device->request_queue->rq_timeout,
721 return (STp->buffer)->syscall_result;
723 STps = &(STp->ps[STp->partition]);
724 if ((STp->buffer)->syscall_result != 0) {
725 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
733 STp->dirty = 0;
734 (STp->buffer)->buffer_bytes = 0;
740 tape_name(STp));
747 STp->dirty = 0;
748 (STp->buffer)->buffer_bytes = 0;
759 static int flush_buffer(struct scsi_tape *STp, int seek_next)
765 STbuffer = STp->buffer;
771 if (STp->pos_unknown)
774 if (STp->ready != ST_READY)
776 STps = &(STp->ps[STp->partition]);
778 return st_flush_write_buffer(STp);
780 if (STp->block_size == 0)
783 backspace = ((STp->buffer)->buffer_bytes +
784 (STp->buffer)->read_pointer) / STp->block_size -
785 ((STp->buffer)->read_pointer + STp->block_size - 1) /
786 STp->block_size;
787 (STp->buffer)->buffer_bytes = 0;
788 (STp->buffer)->read_pointer = 0;
792 result = cross_eof(STp, 0); /* Back over the EOF hit */
802 result = st_int_ioctl(STp, MTBSR, backspace);
815 static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm)
819 char *name = tape_name(STp);
821 if (!STp->density_changed &&
823 STm->default_density != STp->density) {
827 arg = STp->density;
829 if (!STp->blksize_changed &&
831 STm->default_blksize != STp->block_size) {
835 arg |= STp->block_size;
837 st_int_ioctl(STp, SET_DENS_AND_BLK, arg)) {
849 static int do_door_lock(struct scsi_tape * STp, int do_lock)
852 DEB(char *name = tape_name(STp);)
858 retval = scsi_ioctl(STp->device, cmd, NULL);
860 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED;
863 STp->door_locked = ST_LOCK_FAILS;
870 static void reset_state(struct scsi_tape *STp)
875 STp->pos_unknown = 0;
877 STps = &(STp->ps[i]);
885 if (STp->can_partitions) {
886 STp->partition = find_partition(STp);
887 if (STp->partition < 0)
888 STp->partition = 0;
889 STp->new_partition = STp->partition;
903 static int test_ready(struct scsi_tape *STp, int do_wait)
909 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
916 SRpnt = st_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
917 STp->long_timeout, MAX_READY_RETRIES, 1);
920 retval = (STp->buffer)->syscall_result;
950 if ((STp->device)->scsi_level >= SCSI_2 &&
960 retval = (STp->buffer)->syscall_result;
977 static int check_tape(struct scsi_tape *STp, struct file *filp)
985 char *name = tape_name(STp);
989 STp->ready = ST_READY;
991 if (mode != STp->current_mode) {
993 name, STp->current_mode, mode));
995 STp->current_mode = mode;
997 STm = &(STp->modes[STp->current_mode]);
999 saved_cleaning = STp->cleaning_req;
1000 STp->cleaning_req = 0;
1003 retval = test_ready(STp, do_wait);
1009 STp->pos_unknown = 0;
1010 STp->partition = STp->new_partition = 0;
1011 if (STp->can_partitions)
1012 STp->nbr_partitions = 1; /* This guess will be updated later
1015 STps = &(STp->ps[i]);
1026 STp->cleaning_req |= saved_cleaning;
1030 STp->ready = ST_NO_TAPE;
1032 STp->ready = ST_NOT_READY;
1034 STp->density = 0; /* Clear the erroneous "residue" */
1035 STp->write_prot = 0;
1036 STp->block_size = 0;
1037 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1);
1038 STp->partition = STp->new_partition = 0;
1039 STp->door_locked = ST_UNLOCKED;
1044 if (STp->omit_blklims)
1045 STp->min_block = STp->max_block = (-1);
1050 SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, DMA_FROM_DEVICE,
1051 STp->device->request_queue->rq_timeout,
1054 retval = (STp->buffer)->syscall_result;
1058 if (!SRpnt->result && !STp->buffer->cmdstat.have_sense) {
1059 STp->max_block = ((STp->buffer)->b_data[1] << 16) |
1060 ((STp->buffer)->b_data[2] << 8) | (STp->buffer)->b_data[3];
1061 STp->min_block = ((STp->buffer)->b_data[4] << 8) |
1062 (STp->buffer)->b_data[5];
1063 if ( DEB( debugging || ) !STp->inited)
1066 STp->min_block, STp->max_block);
1068 STp->min_block = STp->max_block = (-1);
1078 SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, DMA_FROM_DEVICE,
1079 STp->device->request_queue->rq_timeout,
1082 retval = (STp->buffer)->syscall_result;
1086 if ((STp->buffer)->syscall_result != 0) {
1088 STp->block_size = ST_DEFAULT_BLOCK; /* Educated guess (?) */
1089 (STp->buffer)->syscall_result = 0; /* Prevent error propagation */
1090 STp->drv_write_prot = 0;
1095 (STp->buffer)->b_data[0], (STp->buffer)->b_data[1],
1096 (STp->buffer)->b_data[2], (STp->buffer)->b_data[3]));
1098 if ((STp->buffer)->b_data[3] >= 8) {
1099 STp->drv_buffer = ((STp->buffer)->b_data[2] >> 4) & 7;
1100 STp->density = (STp->buffer)->b_data[4];
1101 STp->block_size = (STp->buffer)->b_data[9] * 65536 +
1102 (STp->buffer)->b_data[10] * 256 + (STp->buffer)->b_data[11];
1105 name, STp->density, (STp->buffer)->b_data[5] * 65536 +
1106 (STp->buffer)->b_data[6] * 256 + (STp->buffer)->b_data[7],
1107 STp->drv_buffer));
1109 STp->drv_write_prot = ((STp->buffer)->b_data[2] & 0x80) != 0;
1113 STp->inited = 1;
1115 if (STp->block_size > 0)
1116 (STp->buffer)->buffer_blocks =
1117 (STp->buffer)->buffer_size / STp->block_size;
1119 (STp->buffer)->buffer_blocks = 1;
1120 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0;
1124 STp->block_size, (STp->buffer)->buffer_size,
1125 (STp->buffer)->buffer_blocks));
1127 if (STp->drv_write_prot) {
1128 STp->write_prot = 1;
1140 if (STp->can_partitions && STp->nbr_partitions < 1) {
1146 if ((STp->partition = find_partition(STp)) < 0) {
1147 retval = STp->partition;
1150 STp->new_partition = STp->partition;
1151 STp->nbr_partitions = 1; /* This guess will be updated when necessary */
1155 STp->density_changed = STp->blksize_changed = 0;
1156 STp->compression_changed = 0;
1158 (retval = set_mode_densblk(STp, STm)) < 0)
1161 if (STp->default_drvbuffer != 0xff) {
1162 if (st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer))
1165 name, STp->default_drvbuffer);
1182 struct scsi_tape *STp;
1195 if (!(STp = scsi_tape_get(dev))) {
1201 filp->private_data = STp;
1202 name = tape_name(STp);
1204 if (STp->in_use) {
1206 scsi_tape_put(STp);
1212 STp->in_use = 1;
1214 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0;
1216 if (!scsi_block_when_processing_errors(STp->device)) {
1222 if (!enlarge_buffer(STp->buffer, PAGE_SIZE, STp->restr_dma)) {
1229 (STp->buffer)->cleared = 0;
1230 (STp->buffer)->writing = 0;
1231 (STp->buffer)->syscall_result = 0;
1233 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY);
1235 STp->dirty = 0;
1237 STps = &(STp->ps[i]);
1240 STp->try_dio_now = STp->try_dio;
1241 STp->recover_count = 0;
1242 DEB( STp->nbr_waits = STp->nbr_finished = 0;
1243 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = 0; )
1245 retval = check_tape(STp, filp);
1250 if (STp->ready == NO_TAPE)
1260 normalize_buffer(STp->buffer);
1261 STp->in_use = 0;
1262 scsi_tape_put(STp);
1276 struct scsi_tape *STp = filp->private_data;
1277 struct st_modedef *STm = &(STp->modes[STp->current_mode]);
1278 struct st_partstat *STps = &(STp->ps[STp->partition]);
1279 char *name = tape_name(STp);
1284 if (STps->rw == ST_WRITING && !STp->pos_unknown) {
1285 result = st_flush_write_buffer(STp);
1290 if (STp->can_partitions &&
1291 (result2 = switch_partition(STp)) < 0) {
1299 DEBC( if (STp->nbr_requests)
1301 name, STp->nbr_requests, STp->nbr_dio, STp->nbr_pages));
1303 if (STps->rw == ST_WRITING && !STp->pos_unknown) {
1304 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
1307 name, STp->nbr_waits, STp->nbr_finished);
1312 cmd[4] = 1 + STp->two_fm;
1314 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
1315 STp->device->request_queue->rq_timeout,
1318 result = (STp->buffer)->syscall_result;
1322 if (STp->buffer->syscall_result == 0 ||
1334 if (STp->two_fm)
1335 cross_eof(STp, 0);
1348 } else if (!STp->rew_at_close) {
1349 STps = &(STp->ps[STp->partition]);
1351 if (STp->can_bsr)
1352 result = flush_buffer(STp, 0);
1354 result = cross_eof(STp, 0);
1364 !(result = cross_eof(STp, 1))) ||
1374 if (STp->rew_at_close) {
1375 result2 = st_int_ioctl(STp, MTREW, 1);
1388 struct scsi_tape *STp = filp->private_data;
1390 if (STp->door_locked == ST_LOCKED_AUTO)
1391 do_door_lock(STp, 0);
1393 normalize_buffer(STp->buffer);
1395 STp->in_use = 0;
1397 scsi_tape_put(STp);
1404 static ssize_t rw_checks(struct scsi_tape *STp, struct file *filp, size_t count)
1414 if (!scsi_block_when_processing_errors(STp->device)) {
1419 if (STp->ready != ST_READY) {
1420 if (STp->ready == ST_NO_TAPE)
1427 if (! STp->modes[STp->current_mode].defined) {
1437 if (STp->pos_unknown) {
1446 if (!STp->in_use) {
1447 printk(ST_DEB_MSG "%s: Incorrect device.\n", tape_name(STp));
1452 if (STp->can_partitions &&
1453 (retval = switch_partition(STp)) < 0)
1456 if (STp->block_size == 0 && STp->max_block > 0 &&
1457 (count < STp->min_block || count > STp->max_block)) {
1462 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED &&
1463 !do_door_lock(STp, 1))
1464 STp->door_locked = ST_LOCKED_AUTO;
1471 static int setup_buffering(struct scsi_tape *STp, const char __user *buf,
1475 struct st_buffer *STbp = STp->buffer;
1478 i = STp->try_dio_now && try_rdio;
1480 i = STp->try_dio_now && try_wdio;
1483 STp->device->request_queue)) == 0) {
1495 STp->nbr_dio++;
1496 STp->nbr_pages += STbp->do_dio;
1501 DEB( STp->nbr_requests++; )
1504 if (STp->block_size)
1505 bufsize = STp->block_size > st_fixed_buffer_size ?
1506 STp->block_size : st_fixed_buffer_size;
1511 if (is_read && STp->sili && !STbp->cleared)
1516 !enlarge_buffer(STbp, bufsize, STp->restr_dma)) {
1518 tape_name(STp), bufsize);
1522 if (STp->block_size)
1523 STbp->buffer_blocks = bufsize / STp->block_size;
1532 static void release_buffering(struct scsi_tape *STp, int is_read)
1536 STbp = STp->buffer;
1557 struct scsi_tape *STp = filp->private_data;
1561 char *name = tape_name(STp);
1563 if (mutex_lock_interruptible(&STp->lock))
1566 retval = rw_checks(STp, filp, count);
1571 if (STp->block_size != 0 && (count % STp->block_size) != 0) {
1578 STm = &(STp->modes[STp->current_mode]);
1579 STps = &(STp->ps[STp->partition]);
1581 if (STp->write_prot) {
1588 retval = flush_buffer(STp, 0);
1594 if ((retval = set_mode_densblk(STp, STm)) < 0)
1597 !(STp->compression_changed)) {
1598 if (st_compression(STp, (STm->default_compression == ST_YES))) {
1609 STbp = STp->buffer;
1610 i = write_behind_check(STp);
1630 if (STp->block_size != 0 &&
1638 retval = setup_buffering(STp, buf, count, 0);
1646 cmd[1] = (STp->block_size != 0);
1657 if (STp->block_size == 0)
1660 do_count = STbp->buffer_blocks * STp->block_size -
1675 async_write = STp->block_size == 0 && !STbp->do_dio &&
1678 if (STp->block_size != 0 && STm->do_buffer_writes &&
1679 !(STp->try_dio_now && try_wdio) && STps->eof < ST_EOM_OK &&
1681 STp->dirty = 1;
1688 if (STp->block_size == 0)
1695 blks /= STp->block_size;
1696 transfer = blks * STp->block_size;
1702 SRpnt = st_do_scsi(SRpnt, STp, cmd, transfer, DMA_TO_DEVICE,
1703 STp->device->request_queue->rq_timeout,
1711 STp->dirty = !(STbp->writing ==
1714 DEB( STp->write_pending = 1; )
1719 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
1726 else if (STp->block_size == 0 &&
1731 if (STp->block_size != 0)
1732 undone *= STp->block_size;
1738 if (STp->block_size)
1739 blks = (transfer - undone) / STp->block_size;
1745 if (STp->block_size == 0 ||
1756 move_buffer_data(STp->buffer, transfer - undone);
1760 STp->block_size;
1765 name, STp->buffer->buffer_bytes));
1790 if (STp->block_size == 0)
1797 STp->dirty = 0;
1815 release_buffering(STp, 0);
1816 mutex_unlock(&STp->lock);
1828 static long read_tape(struct scsi_tape *STp, long count,
1838 char *name = tape_name(STp);
1843 STm = &(STp->modes[STp->current_mode]);
1844 STps = &(STp->ps[STp->partition]);
1847 STbp = STp->buffer;
1849 if (STp->block_size == 0)
1852 if (!(STp->try_dio_now && try_rdio) && STm->do_read_ahead) {
1853 blks = (STp->buffer)->buffer_blocks;
1854 bytes = blks * STp->block_size;
1857 if (!STbp->do_dio && bytes > (STp->buffer)->buffer_size)
1858 bytes = (STp->buffer)->buffer_size;
1859 blks = bytes / STp->block_size;
1860 bytes = blks * STp->block_size;
1866 cmd[1] = (STp->block_size != 0);
1867 if (!cmd[1] && STp->sili)
1874 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE,
1875 STp->device->request_queue->rq_timeout,
1877 release_buffering(STp, 1);
1887 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
1907 if (STp->block_size == 0 &&
1912 if (STp->block_size == 0) {
1931 st_int_ioctl(STp, MTBSR, 1);
1936 STp->block_size;
1942 if (st_int_ioctl(STp, MTBSR, 1))
1950 if (STp->block_size == 0)
1954 bytes - transfer * STp->block_size;
1963 if (STp->block_size == 0)
1967 bytes - transfer * STp->block_size;
2000 if (STp->sili) /* In fixed block mode residual is always zero here */
2001 STbp->buffer_bytes -= STp->buffer->cmdstat.residual;
2005 if (STp->block_size == 0)
2008 STps->drv_block += STbp->buffer_bytes / STp->block_size;
2024 struct scsi_tape *STp = filp->private_data;
2027 struct st_buffer *STbp = STp->buffer;
2028 DEB( char *name = tape_name(STp); )
2030 if (mutex_lock_interruptible(&STp->lock))
2033 retval = rw_checks(STp, filp, count);
2037 STm = &(STp->modes[STp->current_mode]);
2038 if (STp->block_size != 0 && (count % STp->block_size) != 0) {
2043 STp->try_dio_now = 0; /* Direct i/o can't handle split blocks */
2046 STps = &(STp->ps[STp->partition]);
2048 retval = flush_buffer(STp, 0);
2059 retval = setup_buffering(STp, buf, count, 1);
2095 special = read_tape(STp, count - total, &SRpnt);
2124 if (STp->block_size == 0)
2154 release_buffering(STp, 1);
2157 mutex_unlock(&STp->lock);
2167 static void st_log_options(struct scsi_tape * STp, struct st_modedef * STm, char *name)
2172 name, STp->current_mode, STm->do_buffer_writes, STm->do_async_writes,
2176 name, STp->can_bsr, STp->two_fm, STp->fast_mteom, STp->do_auto_lock);
2179 name, STm->defaults_for_writes, STp->omit_blklims, STp->can_partitions,
2180 STp->scsi2_logical);
2182 "%s: sysv: %d nowait: %d sili: %d\n", name, STm->sysv, STp->immediate,
2183 STp->sili);
2191 static int st_set_options(struct scsi_tape *STp, long options)
2196 char *name = tape_name(STp);
2199 STm = &(STp->modes[STp->current_mode]);
2202 memcpy(STm, &(STp->modes[0]), sizeof(struct st_modedef));
2207 name, STp->current_mode));
2216 STp->two_fm = (options & MT_ST_TWO_FM) != 0;
2217 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0;
2218 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2219 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2220 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2221 if ((STp->device)->scsi_level >= SCSI_2)
2222 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2223 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2224 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2226 STp->sili = (options & MT_ST_SILI) != 0;
2228 st_log_options(STp, STm, name); )
2240 STp->two_fm = value;
2242 STp->fast_mteom = value;
2244 STp->do_auto_lock = value;
2246 STp->can_bsr = value;
2248 STp->omit_blklims = value;
2249 if ((STp->device)->scsi_level >= SCSI_2 &&
2251 STp->can_partitions = value;
2253 STp->scsi2_logical = value;
2255 STp->immediate = value;
2259 STp->sili = value;
2263 st_log_options(STp, STm, name); )
2275 if (STp->ready == ST_READY) {
2276 STp->blksize_changed = 0;
2277 set_mode_densblk(STp, STm);
2283 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
2287 blk_queue_rq_timeout(STp->device->request_queue,
2298 STp->cln_mode = value;
2299 STp->cln_sense_mask = (options >> 8) & 0xff;
2300 STp->cln_sense_value = (options >> 16) & 0xff;
2303 name, value, STp->cln_sense_mask, STp->cln_sense_value);
2316 if (STp->ready == ST_READY) {
2317 STp->density_changed = 0;
2318 set_mode_densblk(STp, STm);
2323 STp->default_drvbuffer = 0xff;
2327 STp->default_drvbuffer = value & 7;
2330 name, STp->default_drvbuffer));
2331 if (STp->ready == ST_READY)
2332 st_int_ioctl(STp, MTSETDRVBUFFER, STp->default_drvbuffer);
2341 STp->c_algo = (value & 0xff00) >> 8;
2343 name, STp->c_algo));
2349 if (STp->ready == ST_READY) {
2350 STp->compression_changed = 0;
2351 st_compression(STp, (STm->default_compression == ST_YES));
2385 static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs)
2397 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_FROM_DEVICE,
2398 STp->device->request_queue->rq_timeout, 0, 1);
2400 return (STp->buffer)->syscall_result;
2404 return STp->buffer->syscall_result;
2410 static int write_mode_page(struct scsi_tape *STp, int page, int slow)
2420 pgo = MODE_HEADER_LENGTH + (STp->buffer)->b_data[MH_OFF_BDESCS_LENGTH];
2421 cmd[4] = pgo + (STp->buffer)->b_data[pgo + MP_OFF_PAGE_LENGTH] + 2;
2424 (STp->buffer)->b_data[MH_OFF_DATA_LENGTH] = 0;
2425 (STp->buffer)->b_data[MH_OFF_MEDIUM_TYPE] = 0;
2426 (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP;
2427 (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR;
2430 STp->long_timeout : STp->device->request_queue->rq_timeout;
2431 SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_TO_DEVICE,
2434 return (STp->buffer)->syscall_result;
2438 return STp->buffer->syscall_result;
2459 static int st_compression(struct scsi_tape * STp, int state)
2463 unsigned char *b_data = (STp->buffer)->b_data;
2464 DEB( char *name = tape_name(STp); )
2466 if (STp->ready != ST_READY)
2470 retval = read_mode_page(STp, COMPRESSION_PAGE, 0);
2490 if (STp->c_algo != 0)
2491 b_data[mpoffs + CP_OFF_C_ALGO] = STp->c_algo;
2495 if (STp->c_algo != 0)
2499 retval = write_mode_page(STp, COMPRESSION_PAGE, 0);
2507 STp->compression_changed = 1;
2513 static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_code)
2516 DEB( char *name = tape_name(STp); )
2521 if (STp->ready != ST_READY && !load_code) {
2522 if (STp->ready == ST_NO_TAPE)
2542 if (STp->immediate) {
2544 timeout = STp->device->request_queue->rq_timeout;
2547 timeout = STp->long_timeout;
2556 SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
2559 return (STp->buffer)->syscall_result;
2561 retval = (STp->buffer)->syscall_result;
2567 STp->rew_at_close = 0;
2568 STp->ready = ST_NO_TAPE;
2571 STp->rew_at_close = STp->autorew_dev;
2572 retval = check_tape(STp, filp);
2578 STps = &(STp->ps[STp->partition]);
2604 static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned long arg)
2615 char *name = tape_name(STp);
2617 WARN_ON(STp->buffer->do_dio != 0);
2618 if (STp->ready != ST_READY) {
2619 if (STp->ready == ST_NO_TAPE)
2624 timeout = STp->long_timeout;
2625 STps = &(STp->ps[STp->partition]);
2711 if (STp->write_prot)
2719 timeout = STp->device->request_queue->rq_timeout;
2735 if (STp->immediate) {
2737 timeout = STp->device->request_queue->rq_timeout;
2748 if (STp->immediate) {
2750 timeout = STp->device->request_queue->rq_timeout;
2757 if (!STp->fast_mteom) {
2759 ioctl_result = st_int_ioctl(STp, MTFSF, 0x7fffff);
2777 if (STp->write_prot)
2781 if (STp->immediate) {
2783 timeout = STp->device->request_queue->rq_timeout;
2786 timeout = STp->long_timeout * 8;
2796 if (STp->dirty || (STp->buffer)->buffer_bytes != 0)
2800 STp->max_block > 0 &&
2801 ((arg & MT_ST_BLKSIZE_MASK) < STp->min_block ||
2802 (arg & MT_ST_BLKSIZE_MASK) > STp->max_block)) {
2807 if ((STp->use_pf & USE_PF))
2812 memset((STp->buffer)->b_data, 0, 12);
2814 (STp->buffer)->b_data[2] = (arg & 7) << 4;
2816 (STp->buffer)->b_data[2] =
2817 STp->drv_buffer << 4;
2818 (STp->buffer)->b_data[3] = 8; /* block descriptor length */
2820 (STp->buffer)->b_data[4] = arg;
2821 STp->density_changed = 1; /* At least we tried ;-) */
2823 (STp->buffer)->b_data[4] = arg >> 24;
2825 (STp->buffer)->b_data[4] = STp->density;
2829 STp->blksize_changed = 1; /* At least we tried ;-) */
2831 ltmp = STp->block_size;
2832 (STp->buffer)->b_data[9] = (ltmp >> 16);
2833 (STp->buffer)->b_data[10] = (ltmp >> 8);
2834 (STp->buffer)->b_data[11] = ltmp;
2835 timeout = STp->device->request_queue->rq_timeout;
2840 (STp->buffer)->b_data[9] * 65536 +
2841 (STp->buffer)->b_data[10] * 256 +
2842 (STp->buffer)->b_data[11]);
2846 (STp->buffer)->b_data[4]);
2850 ((STp->buffer)->b_data[2] >> 4) & 7);
2857 SRpnt = st_do_scsi(NULL, STp, cmd, datalen, direction,
2860 return (STp->buffer)->syscall_result;
2862 ioctl_result = (STp->buffer)->syscall_result;
2872 ioctl_result = st_int_ioctl(STp, MTFSF, 1);
2874 ioctl_result = st_int_ioctl(STp, MTBSF, 1);
2877 STp->block_size = arg & MT_ST_BLKSIZE_MASK;
2878 if (STp->block_size != 0) {
2879 (STp->buffer)->buffer_blocks =
2880 (STp->buffer)->buffer_size / STp->block_size;
2882 (STp->buffer)->buffer_bytes = (STp->buffer)->read_pointer = 0;
2884 STp->density = arg >> MT_ST_DENSITY_SHIFT;
2886 STp->drv_buffer = (arg & 7);
2888 STp->density = arg;
2901 struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
2976 !(STp->use_pf & PF_TESTED)) {
2979 STp->use_pf = (STp->use_pf ^ USE_PF) | PF_TESTED;
2982 return st_int_ioctl(STp, cmd_in, arg);
3002 static int get_location(struct scsi_tape *STp, unsigned int *block, int *partition,
3008 DEB( char *name = tape_name(STp); )
3010 if (STp->ready != ST_READY)
3014 if ((STp->device)->scsi_level < SCSI_2) {
3019 if (!logical && !STp->scsi2_logical)
3022 SRpnt = st_do_scsi(NULL, STp, scmd, 20, DMA_FROM_DEVICE,
3023 STp->device->request_queue->rq_timeout,
3026 return (STp->buffer)->syscall_result;
3028 if ((STp->buffer)->syscall_result != 0 ||
3029 (STp->device->scsi_level >= SCSI_2 &&
3030 ((STp->buffer)->b_data[0] & 4) != 0)) {
3036 if ((STp->device)->scsi_level < SCSI_2) {
3037 *block = ((STp->buffer)->b_data[0] << 16)
3038 + ((STp->buffer)->b_data[1] << 8)
3039 + (STp->buffer)->b_data[2];
3042 *block = ((STp->buffer)->b_data[4] << 24)
3043 + ((STp->buffer)->b_data[5] << 16)
3044 + ((STp->buffer)->b_data[6] << 8)
3045 + (STp->buffer)->b_data[7];
3046 *partition = (STp->buffer)->b_data[1];
3047 if (((STp->buffer)->b_data[0] & 0x80) &&
3048 (STp->buffer)->b_data[1] == 0) /* BOP of partition 0 */
3049 STp->ps[0].drv_block = STp->ps[0].drv_file = 0;
3063 static int set_location(struct scsi_tape *STp, unsigned int block, int partition,
3072 DEB( char *name = tape_name(STp); )
3074 if (STp->ready != ST_READY)
3076 timeout = STp->long_timeout;
3077 STps = &(STp->ps[STp->partition]);
3085 if ((!STp->can_partitions && partition != 0) ||
3088 if (partition != STp->partition) {
3089 if (get_location(STp, &blk, &p, 1))
3096 name, blk, STp->partition));
3101 if ((STp->device)->scsi_level < SCSI_2) {
3113 if (!logical && !STp->scsi2_logical)
3115 if (STp->partition != partition) {
3120 name, STp->partition, partition));
3123 if (STp->immediate) {
3125 timeout = STp->device->request_queue->rq_timeout;
3128 SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE,
3131 return (STp->buffer)->syscall_result;
3135 if ((STp->buffer)->syscall_result != 0) {
3137 if (STp->can_partitions &&
3138 (STp->device)->scsi_level >= SCSI_2 &&
3139 (p = find_partition(STp)) >= 0)
3140 STp->partition = p;
3142 if (STp->can_partitions) {
3143 STp->partition = partition;
3144 STps = &(STp->ps[partition]);
3166 static int find_partition(struct scsi_tape *STp)
3171 if ((i = get_location(STp, &block, &partition, 1)) < 0)
3180 static int switch_partition(struct scsi_tape *STp)
3184 if (STp->partition == STp->new_partition)
3186 STps = &(STp->ps[STp->new_partition]);
3189 return set_location(STp, STps->last_block_visited, STp->new_partition, 1);
3209 static int nbr_partitions(struct scsi_tape *STp)
3212 DEB( char *name = tape_name(STp); )
3214 if (STp->ready != ST_READY)
3217 result = read_mode_page(STp, PART_PAGE, 1);
3224 result = (STp->buffer)->b_data[MODE_HEADER_LENGTH +
3252 static int partition_tape(struct scsi_tape *STp, int size)
3254 char *name = tape_name(STp);
3259 result = read_mode_page(STp, PART_PAGE, 0);
3265 bp = (STp->buffer)->b_data;
3302 result = write_mode_page(STp, PART_PAGE, 1);
3320 struct scsi_tape *STp = file->private_data;
3323 char *name = tape_name(STp);
3326 if (mutex_lock_interruptible(&STp->lock))
3330 if (debugging && !STp->in_use) {
3336 STm = &(STp->modes[STp->current_mode]);
3337 STps = &(STp->ps[STp->partition]);
3345 retval = scsi_nonblockable_ioctl(STp->device, cmd_in, p,
3347 if (!scsi_block_when_processing_errors(STp->device) || retval != -ENODEV)
3381 if (!STp->pos_unknown) {
3399 i = !STp->can_partitions ||
3400 (STp->new_partition != STp->partition);
3409 i = flush_buffer(STp, i);
3418 i = st_int_ioctl(STp, MTWEOF, 1);
3443 reset_state(STp);
3445 STp->device->was_reset = 0;
3453 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED)
3454 do_door_lock(STp, 0); /* Ignore result! */
3458 retval = st_set_options(STp, mtc.mt_count);
3463 if (!STp->can_partitions ||
3468 if (mtc.mt_count >= STp->nbr_partitions &&
3469 (STp->nbr_partitions = nbr_partitions(STp)) < 0) {
3473 if (mtc.mt_count >= STp->nbr_partitions) {
3477 STp->new_partition = mtc.mt_count;
3483 if (!STp->can_partitions) {
3487 if ((i = st_int_ioctl(STp, MTREW, 0)) < 0 ||
3488 (i = partition_tape(STp, mtc.mt_count)) < 0) {
3493 STp->ps[i].rw = ST_IDLE;
3494 STp->ps[i].at_sm = 0;
3495 STp->ps[i].last_block_valid = 0;
3497 STp->partition = STp->new_partition = 0;
3498 STp->nbr_partitions = 1; /* Bad guess ?-) */
3505 i = set_location(STp, mtc.mt_count, STp->new_partition, 0);
3506 if (!STp->can_partitions)
3507 STp->ps[0].rw = ST_IDLE;
3513 retval = do_load_unload(STp, file, 0);
3518 retval = do_load_unload(STp, file, max(1, mtc.mt_count));
3523 retval = do_door_lock(STp, (mtc.mt_op == MTLOCK));
3527 if (STp->can_partitions && STp->ready == ST_READY &&
3528 (i = switch_partition(STp)) < 0) {
3534 retval = st_compression(STp, (mtc.mt_count & 1));
3536 retval = st_int_ioctl(STp, mtc.mt_op, mtc.mt_count);
3544 if ((i = flush_buffer(STp, 0)) < 0) {
3548 if (STp->can_partitions &&
3549 (i = switch_partition(STp)) < 0) {
3562 mt_status.mt_type = STp->tape_type;
3564 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) |
3565 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK);
3568 if (STp->block_size != 0) {
3571 (STp->buffer)->buffer_bytes / STp->block_size;
3574 ((STp->buffer)->buffer_bytes +
3575 STp->block_size - 1) / STp->block_size;
3579 if (STp->drv_write_prot)
3587 mt_status.mt_erreg = (STp->recover_reg << MT_ST_SOFTERR_SHIFT);
3588 mt_status.mt_resid = STp->partition;
3593 if (STp->density == 1)
3595 else if (STp->density == 2)
3597 else if (STp->density == 3)
3599 if (STp->ready == ST_READY)
3601 if (STp->ready == ST_NO_TAPE)
3606 (STm->do_buffer_writes && STp->block_size != 0) ||
3607 STp->drv_buffer != 0)
3609 if (STp->cleaning_req)
3618 STp->recover_reg = 0; /* Clear after read */
3628 if ((i = get_location(STp, &blk, &bt, 0)) < 0) {
3638 mutex_unlock(&STp->lock);
3650 i = scsi_cmd_ioctl(STp->disk->queue, STp->disk,
3656 retval = scsi_ioctl(STp->device, cmd_in, p);
3658 STp->rew_at_close = 0;
3659 STp->ready = ST_NO_TAPE;
3664 mutex_unlock(&STp->lock);
3671 struct scsi_tape *STp = file->private_data;
3672 struct scsi_device *sdev = STp->device;
4450 struct scsi_tape *STp;
4464 STp = scsi_tapes[i];
4470 options |= STp->two_fm ? MT_ST_TWO_FM : 0;
4471 options |= STp->fast_mteom ? MT_ST_FAST_MTEOM : 0;
4473 options |= STp->can_bsr ? MT_ST_CAN_BSR : 0;
4474 options |= STp->omit_blklims ? MT_ST_NO_BLKLIMS : 0;
4475 options |= STp->can_partitions ? MT_ST_CAN_PARTITIONS : 0;
4476 options |= STp->scsi2_logical ? MT_ST_SCSI2LOGICAL : 0;
4478 options |= STp->immediate ? MT_ST_NOWAIT : 0;
4479 options |= STp->sili ? MT_ST_SILI : 0;
4487 static int do_create_class_files(struct scsi_tape *STp, int dev_num, int mode)
4498 STp->disk->disk_name, st_formats[i]);
4500 device_create(st_sysfs_class, &STp->device->sdev_gendev,
4503 &STp->modes[mode], "%s", name);
4528 error = sysfs_create_link(&STp->device->sdev_gendev.kobj,