• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/drivers/scsi/

Lines Matching refs:STp

183 static int osst_int_ioctl(struct osst_tape *STp, struct osst_request ** aSRpnt,
186 static int osst_set_frame_position(struct osst_tape *STp, struct osst_request ** aSRpnt, int frame, int skip);
188 static int osst_get_frame_position(struct osst_tape *STp, struct osst_request ** aSRpnt);
190 static int osst_flush_write_buffer(struct osst_tape *STp, struct osst_request ** aSRpnt);
192 static int osst_write_error_recovery(struct osst_tape * STp, struct osst_request ** aSRpnt, int pending);
236 static int osst_chk_result(struct osst_tape * STp, struct osst_request * SRpnt)
238 char *name = tape_name(STp);
249 cmdstatp = &STp->buffer->cmdstat;
253 scode = STp->buffer->cmdstat.sense_hdr.sense_key;
297 STp->pos_unknown |= STp->device->was_reset;
300 STp->recover_count++;
301 STp->recover_erreg++;
311 STp->recover_count);
325 struct osst_tape *STp = SRpnt->stp;
328 STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors;
330 STp->write_pending = 0;
425 static struct osst_request * osst_do_scsi(struct osst_request *SRpnt, struct osst_tape *STp,
437 if (!do_wait && ((STp->buffer)->last_SRpnt)) {
439 tape_name(STp));
441 (STp->buffer)->syscall_result = (-EINTR);
443 (STp->buffer)->syscall_result = (-EBUSY);
451 tape_name(STp));
453 (STp->buffer)->syscall_result = (-EINTR);
455 (STp->buffer)->syscall_result = (-EBUSY);
458 SRpnt->stp = STp;
464 (STp->buffer)->last_SRpnt = SRpnt;
466 waiting = &STp->wait;
470 use_sg = (bytes > STp->buffer->sg[0].length) ? STp->buffer->use_sg : 0;
472 bp = (char *)&(STp->buffer->sg[0]);
473 if (STp->buffer->sg_segs < use_sg)
474 use_sg = STp->buffer->sg_segs;
477 bp = (STp->buffer)->b_data;
480 STp->buffer->cmdstat.have_sense = 0;
481 STp->buffer->syscall_result = 0;
486 (STp->buffer)->syscall_result = (-EBUSY);
490 STp->buffer->syscall_result = osst_chk_result(STp, SRpnt);
492 if (STp->buffer->syscall_result == 0 &&
496 (STp->first_frame_position == 240
497 /* or STp->read_error_frame to fail again on the block calculated above */ &&
499 printk(OSST_DEB_MSG "%s:D: Injecting read error\n", tape_name(STp));
500 STp->buffer->last_result_fatal = 1;
509 static void osst_write_behind_check(struct osst_tape *STp)
513 STbuffer = STp->buffer;
516 if (STp->write_pending)
517 STp->nbr_waits++;
519 STp->nbr_finished++;
521 wait_for_completion(&(STp->wait));
522 STp->buffer->last_SRpnt->waiting = NULL;
524 STp->buffer->syscall_result = osst_chk_result(STp, STp->buffer->last_SRpnt);
526 if (STp->buffer->syscall_result)
527 STp->buffer->syscall_result =
528 osst_write_error_recovery(STp, &(STp->buffer->last_SRpnt), 1);
530 STp->first_frame_position++;
532 osst_release_request(STp->buffer->last_SRpnt);
551 static void osst_init_aux(struct osst_tape * STp, int frame_type, int frame_seq_number,
554 os_aux_t *aux = STp->buffer->aux;
558 if (STp->raw) return;
568 aux->update_frame_cntr = htonl(STp->update_frame_cntr);
578 aux->next_mark_ppos = htonl(STp->first_mark_ppos);
595 par->wrt_pass_cntr = htons(STp->wrt_pass_cntr);
596 par->first_frame_ppos = htonl(STp->first_data_ppos);
597 par->last_frame_ppos = htonl(STp->capacity);
604 aux->filemark_cnt = htonl(STp->filemark_cnt);
606 aux->last_mark_ppos = htonl(STp->last_mark_ppos);
607 aux->last_mark_lbn = htonl(STp->last_mark_lbn);
613 static int osst_verify_frame(struct osst_tape * STp, int frame_seq_number, int quiet)
615 char * name = tape_name(STp);
616 os_aux_t * aux = STp->buffer->aux;
618 struct st_partstat * STps = &(STp->ps[STp->partition]);
621 if (STp->raw) {
622 if (STp->buffer->syscall_result) {
623 for (i=0; i < STp->buffer->sg_segs; i++)
624 memset(page_address(sg_page(&STp->buffer->sg[i])),
625 0, STp->buffer->sg[i].length);
626 strcpy(STp->buffer->b_data, "READ ERROR ON FRAME");
628 STp->buffer->buffer_bytes = OS_FRAME_SIZE;
631 if (STp->buffer->syscall_result) {
643 if (memcmp(aux->application_sig, STp->application_sig, 4) != 0 &&
644 (memcmp(aux->application_sig, "LIN3", 4) != 0 || STp->linux_media_version != 4)) {
651 if (!STp->linux_media || STp->linux_media_version != 2) {
665 if (ntohs(par->wrt_pass_cntr) != STp->wrt_pass_cntr) {
668 name, ntohs(par->wrt_pass_cntr), STp->wrt_pass_cntr);
683 STp->first_frame_position < STp->eod_frame_ppos) {
685 STp->first_frame_position);
701 if (STp->header_cache != NULL && i < OS_FM_TAB_MAX && (i > STp->filemark_cnt ||
702 STp->first_frame_position - 1 != ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[i]))) {
705 STp->header_cache->dat_fm_tab.fm_tab_ent[i] == 0?"Learned":"Corrected",
706 i, STp->first_frame_position - 1);
708 STp->header_cache->dat_fm_tab.fm_tab_ent[i] = htonl(STp->first_frame_position - 1);
709 if (i >= STp->filemark_cnt)
710 STp->filemark_cnt = i+1;
715 STp->frame_in_buffer = 1;
720 STp->buffer->buffer_bytes = blk_cnt * blk_sz;
721 STp->buffer->read_pointer = 0;
722 STp->frame_in_buffer = 1;
725 if (STp->block_size != blk_sz && blk_sz > 0) {
729 STp->block_size<1024?STp->block_size:STp->block_size/1024,
730 STp->block_size<1024?'b':'k');
731 STp->block_size = blk_sz;
732 STp->buffer->buffer_blocks = OS_DATA_SIZE / blk_sz;
736 STp->frame_seq_number = ntohl(aux->frame_seq_num);
737 STp->logical_blk_num = ntohl(aux->logical_blk_num);
741 if (STp->read_error_frame == 0)
742 STp->read_error_frame = STp->first_frame_position - 1;
749 static int osst_wait_ready(struct osst_tape * STp, struct osst_request ** aSRpnt,
757 char * name = tape_name(STp);
768 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, DMA_NONE, STp->timeout, MAX_RETRIES, 1);
772 while ( STp->buffer->syscall_result && time_before(jiffies, startwait + timeout*HZ) &&
789 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE, STp->timeout, MAX_RETRIES, 1);
795 if ( STp->buffer->syscall_result &&
796 osst_write_error_recovery(STp, aSRpnt, 0) ) {
800 STp->buffer->syscall_result, SRpnt->sense[0], SRpnt->sense[2],
814 static int osst_wait_for_medium(struct osst_tape * STp, struct osst_request ** aSRpnt, unsigned timeout)
821 char * name = tape_name(STp);
829 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, DMA_NONE, STp->timeout, MAX_RETRIES, 1);
833 while ( STp->buffer->syscall_result && time_before(jiffies, startwait + timeout*HZ) &&
847 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE, STp->timeout, MAX_RETRIES, 1);
853 if ( STp->buffer->syscall_result && SRpnt->sense[2] != 2 &&
858 STp->buffer->syscall_result, SRpnt->sense[0], SRpnt->sense[2],
869 static int osst_position_tape_and_confirm(struct osst_tape * STp, struct osst_request ** aSRpnt, int frame)
873 osst_wait_ready(STp, aSRpnt, 15 * 60, 0); /* TODO - can this catch a write error? */
874 retval = osst_set_frame_position(STp, aSRpnt, frame, 0);
876 osst_wait_ready(STp, aSRpnt, 15 * 60, OSST_WAIT_POSITION_COMPLETE);
877 return (osst_get_frame_position(STp, aSRpnt));
883 static int osst_flush_drive_buffer(struct osst_tape * STp, struct osst_request ** aSRpnt)
890 char * name = tape_name(STp);
899 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, DMA_NONE, STp->timeout, MAX_RETRIES, 1);
902 if (STp->buffer->syscall_result) {
908 result = osst_write_error_recovery(STp, aSRpnt, 0);
910 result |= osst_wait_ready(STp, aSRpnt, 5 * 60, delay);
911 STp->ps[STp->partition].rw = OS_WRITING_COMPLETE;
917 static int osst_wait_frame(struct osst_tape * STp, struct osst_request ** aSRpnt, int curr, int minlast, int to)
920 char * name = tape_name(STp);
924 if (minlast >= 0 && STp->ps[STp->partition].rw != ST_READING)
930 result = osst_get_frame_position(STp, aSRpnt);
932 if ((result = osst_write_error_recovery(STp, aSRpnt, 0)) == 0)
935 if (STp->first_frame_position == curr &&
937 (signed)STp->last_frame_position > (signed)curr + minlast) ||
938 (minlast >= 0 && STp->cur_frames > minlast)
945 name, curr, curr+minlast, STp->first_frame_position,
946 STp->last_frame_position, STp->cur_frames,
956 name, curr, curr+minlast, STp->first_frame_position,
957 STp->last_frame_position, STp->cur_frames, result);
965 name, curr, curr+minlast, STp->first_frame_position,
966 STp->last_frame_position, STp->cur_frames,
972 static int osst_recover_wait_frame(struct osst_tape * STp, struct osst_request ** aSRpnt, int writing)
978 char * name = tape_name(STp);
982 char * olddata = STp->buffer->b_data;
983 int oldsize = STp->buffer->buffer_size;
990 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, DMA_NONE, STp->timeout,
995 if (STp->buffer->syscall_result && (SRpnt->sense[2] & 0x0f) != 2) {
998 retval = osst_write_error_recovery(STp, aSRpnt, 0);
1003 STp->buffer->b_data = mybuf; STp->buffer->buffer_size = 24;
1007 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 20, DMA_FROM_DEVICE, STp->timeout,
1010 retval = ( STp->buffer->syscall_result || (STp->buffer)->b_data[15] > 25 );
1011 STp->buffer->b_data = olddata; STp->buffer->buffer_size = oldsize;
1017 if (STp->buffer->syscall_result)
1030 static int osst_read_frame(struct osst_tape * STp, struct osst_request ** aSRpnt, int timeout)
1036 os_aux_t * aux = STp->buffer->aux;
1037 char * name = tape_name(STp);
1040 if (STp->poll)
1041 if (osst_wait_frame (STp, aSRpnt, STp->first_frame_position, 0, timeout))
1042 retval = osst_recover_wait_frame(STp, aSRpnt, 0);
1053 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, OS_FRAME_SIZE, DMA_FROM_DEVICE,
1054 STp->timeout, MAX_RETRIES, 1);
1059 if ((STp->buffer)->syscall_result) {
1061 if (STp->read_error_frame == 0) {
1062 STp->read_error_frame = STp->first_frame_position;
1064 printk(OSST_DEB_MSG "%s:D: Recording read error at %d\n", name, STp->read_error_frame);
1078 STp->first_frame_position++;
1101 static int osst_initiate_read(struct osst_tape * STp, struct osst_request ** aSRpnt)
1103 struct st_partstat * STps = &(STp->ps[STp->partition]);
1107 char * name = tape_name(STp);
1110 if (STps->rw == ST_WRITING || STp->dirty) {
1111 STp->write_type = OS_WRITE_DATA;
1112 osst_flush_write_buffer(STp, aSRpnt);
1113 osst_flush_drive_buffer(STp, aSRpnt);
1116 STp->frame_in_buffer = 0;
1129 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, DMA_NONE, STp->timeout, MAX_RETRIES, 1);
1131 if ((retval = STp->buffer->syscall_result))
1138 static int osst_get_logical_frame(struct osst_tape * STp, struct osst_request ** aSRpnt,
1141 struct st_partstat * STps = &(STp->ps[STp->partition]);
1142 char * name = tape_name(STp);
1152 if (frame_seq_number == -1 && STp->frame_in_buffer) {
1154 printk(OSST_DEB_MSG "%s:D: Frame %d still in buffer\n", name, STp->frame_seq_number);
1165 if (STp->read_error_frame) {
1166 osst_set_frame_position(STp, aSRpnt, STp->read_error_frame, 0);
1169 name, STp->read_error_frame);
1171 STp->read_error_frame = 0;
1172 STp->abort_count++;
1181 if ( osst_initiate_read(STp, aSRpnt)
1182 || ( (!STp->frame_in_buffer) && osst_read_frame(STp, aSRpnt, 30) ) ) {
1183 if (STp->raw)
1185 position = osst_get_frame_position(STp, aSRpnt);
1188 else if (position > STp->eod_frame_ppos || ++bad == 10) {
1189 position = STp->read_error_frame - 1;
1200 osst_set_frame_position(STp, aSRpnt, position, 0);
1203 if (osst_verify_frame(STp, frame_seq_number, quiet))
1205 if (osst_verify_frame(STp, -1, quiet)) {
1206 x = ntohl(STp->buffer->aux->frame_seq_num);
1207 if (STp->fast_open) {
1211 STp->header_ok = 0;
1212 STp->read_error_frame = 0;
1218 position = STp->read_error_frame - 1;
1221 position = osst_get_frame_position(STp, aSRpnt)
1224 if (STp->first_frame_position >= 3000 && position < 3000)
1231 STp->first_frame_position - position);
1233 osst_set_frame_position(STp, aSRpnt, position, 0);
1239 if (osst_get_frame_position(STp, aSRpnt) == 0xbaf) {
1243 osst_set_frame_position(STp, aSRpnt, 0xbb8, 0);
1246 STp->frame_in_buffer = 0;
1249 STp->recover_count++;
1250 STp->recover_erreg++;
1252 name, STp->read_error_frame);
1254 STp->read_count++;
1260 name, frame_seq_number, STp->frame_seq_number, STps->eof);
1262 STp->fast_open = 0;
1263 STp->read_error_frame = 0;
1267 static int osst_seek_logical_blk(struct osst_tape * STp, struct osst_request ** aSRpnt, int logical_blk_num)
1269 struct st_partstat * STps = &(STp->ps[STp->partition]);
1270 char * name = tape_name(STp);
1277 name, logical_blk_num, STp->logical_blk_num,
1278 STp->block_size<1024?STp->block_size:STp->block_size/1024,
1279 STp->block_size<1024?'b':'k');
1283 move = logical_blk_num - STp->logical_blk_num;
1284 if (move < 0) move -= (OS_DATA_SIZE / STp->block_size) - 1;
1285 move /= (OS_DATA_SIZE / STp->block_size);
1286 frame_seq_estimate = STp->frame_seq_number + move;
1288 frame_seq_estimate = logical_blk_num * STp->block_size / OS_DATA_SIZE;
1293 if (ppos_estimate > STp->eod_frame_ppos-2) {
1294 frame_seq_estimate += STp->eod_frame_ppos - 2 - ppos_estimate;
1295 ppos_estimate = STp->eod_frame_ppos - 2;
1301 osst_set_frame_position(STp, aSRpnt, ppos_estimate, 0);
1302 if (osst_get_logical_frame(STp, aSRpnt, frame_seq_estimate, 1) >= 0) {
1304 if (logical_blk_num < STp->logical_blk_num ||
1305 logical_blk_num >= STp->logical_blk_num + ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt)) {
1307 move = logical_blk_num < STp->logical_blk_num? -2 : 1;
1309 move = logical_blk_num - STp->logical_blk_num;
1310 if (move < 0) move -= (OS_DATA_SIZE / STp->block_size) - 1;
1311 move /= (OS_DATA_SIZE / STp->block_size);
1313 if (!move) move = logical_blk_num > STp->logical_blk_num ? 1 : -1;
1317 name, retries, ppos_estimate, STp->frame_seq_number, frame_seq_estimate,
1318 STp->logical_blk_num, logical_blk_num, move);
1324 STp->buffer->read_pointer = (logical_blk_num - STp->logical_blk_num) * STp->block_size;
1325 STp->buffer->buffer_bytes -= STp->buffer->read_pointer;
1326 STp->logical_blk_num = logical_blk_num;
1330 name, ppos_estimate, STp->frame_seq_number, STp->frame_in_buffer,
1331 STp->buffer->buffer_bytes, STp->buffer->read_pointer / STp->block_size,
1332 STp->block_size);
1334 STps->drv_file = ntohl(STp->buffer->aux->filemark_cnt);
1339 STps->drv_block = ntohl(STp->buffer->aux->last_mark_lbn)?
1340 STp->logical_blk_num -
1341 (STps->drv_file ? ntohl(STp->buffer->aux->last_mark_lbn) + 1 : 0):
1344 STps->eof = (STp->first_frame_position >= STp->eod_frame_ppos)?ST_EOD:ST_NOEOF;
1348 if (osst_get_logical_frame(STp, aSRpnt, -1, 1) < 0)
1353 name, retries, ppos_estimate, STp->frame_seq_number, frame_seq_estimate,
1354 STp->logical_blk_num, logical_blk_num);
1356 if (frame_seq_estimate != STp->frame_seq_number)
1357 ppos_estimate += frame_seq_estimate - STp->frame_seq_number;
1363 name, logical_blk_num, STp->logical_blk_num, retries);
1376 static int osst_get_sector(struct osst_tape * STp, struct osst_request ** aSRpnt)
1380 char * name = tape_name(STp);
1384 name, STp->first_frame_position, STp->frame_seq_number, STp->logical_blk_num,
1385 STp->ps[STp->partition].drv_file, STp->ps[STp->partition].drv_block,
1386 STp->ps[STp->partition].rw == ST_WRITING?'w':'r',
1387 STp->ps[STp->partition].rw == ST_WRITING?STp->buffer->buffer_bytes:
1388 STp->buffer->read_pointer, STp->ps[STp->partition].eof);
1391 if (STp->ps[STp->partition].drv_block >= 0) {
1392 sector = (STp->frame_in_buffer ? STp->first_frame_position-1 :
1393 STp->first_frame_position) << OSST_FRAME_SHIFT;
1394 if (STp->ps[STp->partition].rw == ST_WRITING)
1395 sector |= (STp->buffer->buffer_bytes >> OSST_SECTOR_SHIFT) & OSST_SECTOR_MASK;
1397 sector |= (STp->buffer->read_pointer >> OSST_SECTOR_SHIFT) & OSST_SECTOR_MASK;
1399 sector = osst_get_frame_position(STp, aSRpnt);
1406 static int osst_seek_sector(struct osst_tape * STp, struct osst_request ** aSRpnt, int sector)
1408 struct st_partstat * STps = &(STp->ps[STp->partition]);
1413 char * name = tape_name(STp);
1418 if (frame < 0 || frame >= STp->capacity) return (-ENXIO);
1420 if (frame <= STp->first_data_ppos) {
1421 STp->frame_seq_number = STp->logical_blk_num = STps->drv_file = STps->drv_block = 0;
1422 return (osst_set_frame_position(STp, aSRpnt, frame, 0));
1424 r = osst_set_frame_position(STp, aSRpnt, offset?frame:frame-1, 0);
1427 r = osst_get_logical_frame(STp, aSRpnt, -1, 1);
1430 if (osst_get_frame_position(STp, aSRpnt) != (offset?frame+1:frame)) return (-EIO);
1433 STp->logical_blk_num += offset / STp->block_size;
1434 STp->buffer->read_pointer = offset;
1435 STp->buffer->buffer_bytes -= offset;
1437 STp->frame_seq_number++;
1438 STp->frame_in_buffer = 0;
1439 STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
1440 STp->buffer->buffer_bytes = STp->buffer->read_pointer = 0;
1442 STps->drv_file = ntohl(STp->buffer->aux->filemark_cnt);
1447 STps->drv_block = ntohl(STp->buffer->aux->last_mark_lbn)?
1448 STp->logical_blk_num -
1449 (STps->drv_file ? ntohl(STp->buffer->aux->last_mark_lbn) + 1 : 0):
1452 STps->eof = (STp->first_frame_position >= STp->eod_frame_ppos)?ST_EOD:ST_NOEOF;
1456 name, STp->first_frame_position, STp->frame_seq_number, STp->logical_blk_num,
1457 STps->drv_file, STps->drv_block, STp->buffer->read_pointer, STps->eof);
1469 static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct osst_request ** aSRpnt,
1476 int nframes = STp->cur_frames;
1477 int blks_per_frame = ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
1478 int frame_seq_number = ntohl(STp->buffer->aux->frame_seq_num)
1480 int logical_blk_num = ntohl(STp->buffer->aux->logical_blk_num)
1482 char * name = tape_name(STp);
1494 osst_copy_from_buffer(STp->buffer, (p = &buffer[nframes * OS_DATA_SIZE]));
1510 SRpnt = osst_do_scsi(SRpnt, STp, cmd, OS_FRAME_SIZE, DMA_FROM_DEVICE,
1511 STp->timeout, MAX_RETRIES, 1);
1513 if ((STp->buffer)->syscall_result || !SRpnt) {
1519 osst_copy_from_buffer(STp->buffer, p);
1527 osst_get_frame_position(STp, aSRpnt);
1530 printk(OSST_DEB_MSG "%s:D: Frames left in buffer: %d\n", name, STp->cur_frames);
1538 if (STp->write_type == OS_WRITE_HEADER) {
1550 osst_set_frame_position(STp, aSRpnt, new_frame + i, 0);
1551 osst_wait_ready(STp, aSRpnt, 60, OSST_WAIT_POSITION_COMPLETE);
1552 osst_get_frame_position(STp, aSRpnt);
1563 osst_copy_to_buffer(STp->buffer, p);
1567 osst_init_aux(STp, STp->buffer->aux->frame_type, frame_seq_number+i,
1569 ntohl(STp->buffer->aux->dat.dat_list[0].blk_sz), blks_per_frame);
1582 SRpnt = osst_do_scsi(SRpnt, STp, cmd, OS_FRAME_SIZE, DMA_TO_DEVICE,
1583 STp->timeout, MAX_RETRIES, 1);
1585 if (STp->buffer->syscall_result)
1598 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
1599 STp->timeout, MAX_RETRIES, 1);
1607 flag = STp->buffer->syscall_result;
1613 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE, STp->timeout,
1622 if (STp->buffer->syscall_result)
1649 osst_get_frame_position(STp, aSRpnt);
1652 name, STp->first_frame_position, STp->last_frame_position, STp->cur_frames);
1659 STp->write_type == OS_WRITE_HEADER?"header":"body");
1662 osst_copy_to_buffer(STp->buffer, p); /* so buffer content == at entry in all cases */
1667 static int osst_reposition_and_retry(struct osst_tape * STp, struct osst_request ** aSRpnt,
1672 char * name = tape_name(STp);
1686 if (frame < 2990 && frame+skip+STp->cur_frames+pending >= 2990)
1688 expected = frame+skip+STp->cur_frames+pending;
1691 name, frame+skip, STp->frame_seq_number-STp->cur_frames-pending);
1693 osst_set_frame_position(STp, aSRpnt, frame + skip, 1);
1698 if (osst_get_frame_position(STp, aSRpnt) < 0) { /* additional write error */
1701 name, STp->first_frame_position,
1702 STp->last_frame_position, STp->cur_frames);
1704 frame = STp->last_frame_position;
1708 if (pending && STp->cur_frames < 50) {
1716 name, STp->frame_seq_number-1, STp->first_frame_position);
1718 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, OS_FRAME_SIZE, DMA_TO_DEVICE,
1719 STp->timeout, MAX_RETRIES, 1);
1722 if (STp->buffer->syscall_result) { /* additional write error */
1738 if (STp->cur_frames == 0) {
1743 if (STp->first_frame_position != expected) {
1745 name, STp->first_frame_position, expected);
1770 static int osst_write_error_recovery(struct osst_tape * STp, struct osst_request ** aSRpnt, int pending)
1773 struct st_partstat * STps = & STp->ps[STp->partition];
1774 char * name = tape_name(STp);
1799 osst_get_frame_position(STp, aSRpnt);
1802 name, STp->first_frame_position, STp->last_frame_position);
1804 switch (STp->write_type) {
1810 name, STp->cur_frames, frame, (frame + skip > 3000 && frame < 3000)?3000:frame + skip);
1811 if (STp->os_fw_rev >= 10600)
1812 retval = osst_reposition_and_retry(STp, aSRpnt, frame, skip, pending);
1814 retval = osst_read_back_buffer_and_rewrite(STp, aSRpnt, frame, skip, pending);
1822 osst_set_frame_position(STp, aSRpnt, frame + STp->cur_frames + pending, 0);
1827 retval = osst_read_back_buffer_and_rewrite(STp, aSRpnt, frame, 1, pending);
1831 osst_set_frame_position(STp, aSRpnt, frame + STp->cur_frames + pending, 0);
1833 osst_get_frame_position(STp, aSRpnt);
1836 name, STp->cur_frames, STp->first_frame_position, STp->last_frame_position);
1837 printk(OSST_DEB_MSG "%s:D: next logical frame to write: %d\n", name, STp->logical_blk_num);
1840 STp->recover_count++;
1841 STp->recover_erreg++;
1843 STp->abort_count++;
1849 static int osst_space_over_filemarks_backward(struct osst_tape * STp, struct osst_request ** aSRpnt,
1852 char * name = tape_name(STp);
1859 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
1865 if (STp->linux_media_version >= 4) {
1869 cnt = ntohl(STp->buffer->aux->filemark_cnt);
1870 if (STp->header_ok &&
1871 STp->header_cache != NULL &&
1874 (cnt - mt_count) < STp->filemark_cnt &&
1875 STp->header_cache->dat_fm_tab.fm_tab_ent[cnt-1] == STp->buffer->aux->last_mark_ppos)
1877 last_mark_ppos = ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[cnt - mt_count]);
1879 if (STp->header_cache == NULL || (cnt - mt_count) < 0 || (cnt - mt_count) >= OS_FM_TAB_MAX)
1881 STp->header_cache == NULL?"lack of header cache":"count out of range");
1885 ((cnt == -1 && ntohl(STp->buffer->aux->last_mark_ppos) == -1) ||
1886 (STp->header_cache->dat_fm_tab.fm_tab_ent[cnt-1] ==
1887 STp->buffer->aux->last_mark_ppos))?"match":"error",
1890 if (last_mark_ppos > 10 && last_mark_ppos < STp->eod_frame_ppos) {
1891 osst_position_tape_and_confirm(STp, aSRpnt, last_mark_ppos);
1892 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
1899 if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) {
1912 last_mark_ppos = ntohl(STp->buffer->aux->last_mark_ppos);
1918 osst_position_tape_and_confirm(STp, aSRpnt, last_mark_ppos);
1920 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
1926 if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) {
1934 STp->frame_seq_number++;
1935 STp->frame_in_buffer = 0;
1936 STp->buffer->buffer_bytes = 0;
1937 STp->buffer->read_pointer = 0;
1938 STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
1948 static int osst_space_over_filemarks_forward_slow(struct osst_tape * STp, struct osst_request ** aSRpnt,
1953 char * name = tape_name(STp);
1957 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
1964 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
1970 if (STp->buffer->aux->frame_type == OS_FRAME_TYPE_MARKER)
1972 if (STp->buffer->aux->frame_type == OS_FRAME_TYPE_EOD) {
1976 if (STp->first_frame_position > STp->eod_frame_ppos+1) {
1979 name, STp->eod_frame_ppos, STp->first_frame_position-1);
1981 STp->eod_frame_ppos = STp->first_frame_position-1;
1987 STp->frame_in_buffer = 0;
1990 STp->frame_seq_number++;
1991 STp->frame_in_buffer = 0;
1992 STp->buffer->buffer_bytes = 0;
1993 STp->buffer->read_pointer = 0;
1994 STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
2002 static int osst_space_over_filemarks_forward_fast(struct osst_tape * STp, struct osst_request ** aSRpnt,
2005 char * name = tape_name(STp);
2012 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
2019 if (STp->linux_media_version >= 4) {
2023 cnt = ntohl(STp->buffer->aux->filemark_cnt) - 1;
2024 if (STp->header_ok &&
2025 STp->header_cache != NULL &&
2027 (cnt + mt_count) < STp->filemark_cnt &&
2028 ((cnt == -1 && ntohl(STp->buffer->aux->last_mark_ppos) == -1) ||
2029 (STp->header_cache->dat_fm_tab.fm_tab_ent[cnt] == STp->buffer->aux->last_mark_ppos)))
2031 next_mark_ppos = ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[cnt + mt_count]);
2033 if (STp->header_cache == NULL || (cnt + mt_count) >= OS_FM_TAB_MAX)
2035 STp->header_cache == NULL?"lack of header cache":"count out of range");
2039 ((cnt == -1 && ntohl(STp->buffer->aux->last_mark_ppos) == -1) ||
2040 (STp->header_cache->dat_fm_tab.fm_tab_ent[cnt] ==
2041 STp->buffer->aux->last_mark_ppos))?"match":"error",
2044 if (next_mark_ppos <= 10 || next_mark_ppos > STp->eod_frame_ppos) {
2048 return osst_space_over_filemarks_forward_slow(STp, aSRpnt, mt_op, mt_count);
2050 osst_position_tape_and_confirm(STp, aSRpnt, next_mark_ppos);
2051 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
2058 if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) {
2063 if (ntohl(STp->buffer->aux->filemark_cnt) != cnt + mt_count) {
2066 ntohl(STp->buffer->aux->filemark_cnt));
2075 if (STp->buffer->aux->frame_type == OS_FRAME_TYPE_MARKER)
2077 if (STp->buffer->aux->frame_type == OS_FRAME_TYPE_EOD) {
2083 if (ntohl(STp->buffer->aux->filemark_cnt) == 0) {
2084 if (STp->first_mark_ppos == -1) {
2088 return osst_space_over_filemarks_forward_slow(STp, aSRpnt, mt_op, mt_count);
2090 osst_position_tape_and_confirm(STp, aSRpnt, STp->first_mark_ppos);
2091 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
2099 if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) {
2101 name, STp->first_mark_ppos);
2105 if (osst_space_over_filemarks_backward(STp, aSRpnt, MTBSF, 1) < 0)
2112 next_mark_ppos = ntohl(STp->buffer->aux->next_mark_ppos);
2113 if (!next_mark_ppos || next_mark_ppos > STp->eod_frame_ppos) {
2117 return osst_space_over_filemarks_forward_slow(STp, aSRpnt, mt_op, mt_count - cnt);
2122 osst_position_tape_and_confirm(STp, aSRpnt, next_mark_ppos);
2124 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
2131 if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_MARKER) {
2139 STp->frame_seq_number++;
2140 STp->frame_in_buffer = 0;
2141 STp->buffer->buffer_bytes = 0;
2142 STp->buffer->read_pointer = 0;
2143 STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
2153 static void osst_set_retries(struct osst_tape * STp, struct osst_request ** aSRpnt, int retries)
2157 char * name = tape_name(STp);
2164 (STp->buffer)->b_data[0] = cmd[4] - 1;
2165 (STp->buffer)->b_data[1] = 0; /* Medium Type - ignoring */
2166 (STp->buffer)->b_data[2] = 0; /* Reserved */
2167 (STp->buffer)->b_data[3] = 0; /* Block Descriptor Length */
2168 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 0] = NUMBER_RETRIES_PAGE | (1 << 7);
2169 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 1] = 2;
2170 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 2] = 4;
2171 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 3] = retries;
2176 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], DMA_TO_DEVICE, STp->timeout, 0, 1);
2179 if ((STp->buffer)->syscall_result)
2185 static int osst_write_filemark(struct osst_tape * STp, struct osst_request ** aSRpnt)
2188 int this_mark_ppos = STp->first_frame_position;
2189 int this_mark_lbn = STp->logical_blk_num;
2191 char * name = tape_name(STp);
2194 if (STp->raw) return 0;
2196 STp->write_type = OS_WRITE_NEW_MARK;
2199 name, STp->filemark_cnt, this_mark_ppos, STp->frame_seq_number, this_mark_lbn);
2201 STp->dirty = 1;
2202 result = osst_flush_write_buffer(STp, aSRpnt);
2203 result |= osst_flush_drive_buffer(STp, aSRpnt);
2204 STp->last_mark_ppos = this_mark_ppos;
2205 STp->last_mark_lbn = this_mark_lbn;
2206 if (STp->header_cache != NULL && STp->filemark_cnt < OS_FM_TAB_MAX)
2207 STp->header_cache->dat_fm_tab.fm_tab_ent[STp->filemark_cnt] = htonl(this_mark_ppos);
2208 if (STp->filemark_cnt++ == 0)
2209 STp->first_mark_ppos = this_mark_ppos;
2213 static int osst_write_eod(struct osst_tape * STp, struct osst_request ** aSRpnt)
2217 char * name = tape_name(STp);
2220 if (STp->raw) return 0;
2222 STp->write_type = OS_WRITE_EOD;
2223 STp->eod_frame_ppos = STp->first_frame_position;
2226 STp->eod_frame_ppos, STp->frame_seq_number, STp->logical_blk_num);
2228 STp->dirty = 1;
2230 result = osst_flush_write_buffer(STp, aSRpnt);
2231 result |= osst_flush_drive_buffer(STp, aSRpnt);
2232 STp->eod_frame_lfa = --(STp->frame_seq_number);
2236 static int osst_write_filler(struct osst_tape * STp, struct osst_request ** aSRpnt, int where, int count)
2238 char * name = tape_name(STp);
2243 osst_wait_ready(STp, aSRpnt, 60 * 5, 0);
2244 osst_set_frame_position(STp, aSRpnt, where, 0);
2245 STp->write_type = OS_WRITE_FILLER;
2247 memcpy(STp->buffer->b_data, "Filler", 6);
2248 STp->buffer->buffer_bytes = 6;
2249 STp->dirty = 1;
2250 if (osst_flush_write_buffer(STp, aSRpnt)) {
2258 return osst_flush_drive_buffer(STp, aSRpnt);
2261 static int __osst_write_header(struct osst_tape * STp, struct osst_request ** aSRpnt, int where, int count)
2263 char * name = tape_name(STp);
2269 osst_wait_ready(STp, aSRpnt, 60 * 5, 0);
2270 osst_set_frame_position(STp, aSRpnt, where, 0);
2271 STp->write_type = OS_WRITE_HEADER;
2273 osst_copy_to_buffer(STp->buffer, (unsigned char *)STp->header_cache);
2274 STp->buffer->buffer_bytes = sizeof(os_header_t);
2275 STp->dirty = 1;
2276 if (osst_flush_write_buffer(STp, aSRpnt)) {
2281 result = osst_flush_drive_buffer(STp, aSRpnt);
2288 static int osst_write_header(struct osst_tape * STp, struct osst_request ** aSRpnt, int locate_eod)
2292 char * name = tape_name(STp);
2297 if (STp->raw) return 0;
2299 if (STp->header_cache == NULL) {
2300 if ((STp->header_cache = (os_header_t *)vmalloc(sizeof(os_header_t))) == NULL) {
2304 memset(STp->header_cache, 0, sizeof(os_header_t));
2309 if (STp->header_ok) STp->update_frame_cntr++;
2310 else STp->update_frame_cntr = 0;
2312 header = STp->header_cache;
2320 header->partition[0].wrt_pass_cntr = htons(STp->wrt_pass_cntr);
2321 header->partition[0].first_frame_ppos = htonl(STp->first_data_ppos);
2322 header->partition[0].last_frame_ppos = htonl(STp->capacity);
2323 header->partition[0].eod_frame_ppos = htonl(STp->eod_frame_ppos);
2333 header->ext_track_tb.dat_ext_trk_ey.last_hlb = htonl(STp->eod_frame_lfa);
2334 header->ext_track_tb.dat_ext_trk_ey.last_pp = htonl(STp->eod_frame_ppos);
2337 header->dat_fm_tab.fm_tab_ent_cnt = htons(STp->filemark_cnt<OS_FM_TAB_MAX?
2338 STp->filemark_cnt:OS_FM_TAB_MAX);
2340 result = __osst_write_header(STp, aSRpnt, 0xbae, 5);
2341 if (STp->update_frame_cntr == 0)
2342 osst_write_filler(STp, aSRpnt, 0xbb3, 5);
2343 result &= __osst_write_header(STp, aSRpnt, 5, 5);
2347 printk(OSST_DEB_MSG "%s:D: Locating back to eod frame addr %d\n", name, STp->eod_frame_ppos);
2349 osst_set_frame_position(STp, aSRpnt, STp->eod_frame_ppos, 0);
2354 memcpy(STp->application_sig, "LIN4", 4);
2355 STp->linux_media = 1;
2356 STp->linux_media_version = 4;
2357 STp->header_ok = 1;
2362 static int osst_reset_header(struct osst_tape * STp, struct osst_request ** aSRpnt)
2364 if (STp->header_cache != NULL)
2365 memset(STp->header_cache, 0, sizeof(os_header_t));
2367 STp->logical_blk_num = STp->frame_seq_number = 0;
2368 STp->frame_in_buffer = 0;
2369 STp->eod_frame_ppos = STp->first_data_ppos = 0x0000000A;
2370 STp->filemark_cnt = 0;
2371 STp->first_mark_ppos = STp->last_mark_ppos = STp->last_mark_lbn = -1;
2372 return osst_write_header(STp, aSRpnt, 1);
2375 static int __osst_analyze_headers(struct osst_tape * STp, struct osst_request ** aSRpnt, int ppos)
2377 char * name = tape_name(STp);
2384 if (STp->raw)
2387 if (ppos == 5 || ppos == 0xbae || STp->buffer->syscall_result) {
2388 if (osst_set_frame_position(STp, aSRpnt, ppos, 0))
2390 osst_wait_ready(STp, aSRpnt, 60 * 15, 0);
2391 if (osst_initiate_read (STp, aSRpnt)) {
2396 if (osst_read_frame(STp, aSRpnt, 180)) {
2402 header = (os_header_t *) STp->buffer->b_data; /* warning: only first segment addressable */
2403 aux = STp->buffer->aux;
2432 if (update_frame_cntr < STp->update_frame_cntr) {
2435 name, ppos, update_frame_cntr, STp->update_frame_cntr);
2457 STp->linux_media = 1;
2466 if (linux_media_version < STp->linux_media_version) {
2473 if (linux_media_version > STp->linux_media_version) {
2478 memcpy(STp->application_sig, id_string, 5);
2479 STp->linux_media_version = linux_media_version;
2480 STp->update_frame_cntr = -1;
2482 if (update_frame_cntr > STp->update_frame_cntr) {
2487 if (STp->header_cache == NULL) {
2488 if ((STp->header_cache = (os_header_t *)vmalloc(sizeof(os_header_t))) == NULL) {
2496 osst_copy_from_buffer(STp->buffer, (unsigned char *)STp->header_cache);
2497 header = STp->header_cache; /* further accesses from cached (full) copy */
2499 STp->wrt_pass_cntr = ntohs(header->partition[0].wrt_pass_cntr);
2500 STp->first_data_ppos = ntohl(header->partition[0].first_frame_ppos);
2501 STp->eod_frame_ppos = ntohl(header->partition[0].eod_frame_ppos);
2502 STp->eod_frame_lfa = ntohl(header->ext_track_tb.dat_ext_trk_ey.last_hlb);
2503 STp->filemark_cnt = ntohl(aux->filemark_cnt);
2504 STp->first_mark_ppos = ntohl(aux->next_mark_ppos);
2505 STp->last_mark_ppos = ntohl(aux->last_mark_ppos);
2506 STp->last_mark_lbn = ntohl(aux->last_mark_lbn);
2507 STp->update_frame_cntr = update_frame_cntr;
2510 name, STp->wrt_pass_cntr, STp->update_frame_cntr, STp->filemark_cnt);
2512 STp->first_data_ppos,
2516 name, STp->first_mark_ppos, STp->last_mark_ppos, STp->eod_frame_ppos);
2518 if (header->minor_rev < 4 && STp->linux_media_version == 4) {
2530 header->partition[0].last_frame_ppos != htonl(STp->capacity) ||
2540 header->ext_track_tb.dat_ext_trk_ey.last_pp != htonl(STp->eod_frame_ppos) ||
2544 htons(STp->filemark_cnt<OS_FM_TAB_MAX?STp->filemark_cnt:OS_FM_TAB_MAX)))
2552 static int osst_analyze_headers(struct osst_tape * STp, struct osst_request ** aSRpnt)
2557 char * name = tape_name(STp);
2559 position = osst_get_frame_position(STp, aSRpnt);
2561 if (STp->raw) {
2562 STp->header_ok = STp->linux_media = 1;
2563 STp->linux_media_version = 0;
2566 STp->header_ok = STp->linux_media = STp->linux_media_version = 0;
2567 STp->wrt_pass_cntr = STp->update_frame_cntr = -1;
2568 STp->eod_frame_ppos = STp->first_data_ppos = -1;
2569 STp->first_mark_ppos = STp->last_mark_ppos = STp->last_mark_lbn = -1;
2581 if (__osst_analyze_headers(STp, aSRpnt, ppos))
2588 if (__osst_analyze_headers(STp, aSRpnt, ppos))
2593 STp->eod_frame_ppos = STp->first_data_ppos = 0;
2594 osst_set_frame_position(STp, aSRpnt, 10, 0);
2597 if (position <= STp->first_data_ppos) {
2598 position = STp->first_data_ppos;
2599 STp->ps[0].drv_file = STp->ps[0].drv_block = STp->frame_seq_number = STp->logical_blk_num = 0;
2601 osst_set_frame_position(STp, aSRpnt, position, 0);
2602 STp->header_ok = 1;
2607 static int osst_verify_position(struct osst_tape * STp, struct osst_request ** aSRpnt)
2609 int frame_position = STp->first_frame_position;
2610 int frame_seq_numbr = STp->frame_seq_number;
2611 int logical_blk_num = STp->logical_blk_num;
2612 int halfway_frame = STp->frame_in_buffer;
2613 int read_pointer = STp->buffer->read_pointer;
2617 char * name = tape_name(STp);
2621 osst_set_frame_position(STp, aSRpnt, frame_position - 1, 0);
2622 if (osst_get_logical_frame(STp, aSRpnt, -1, 0) < 0) {
2628 if (STp->linux_media_version >= 4) {
2629 for (i=0; i<STp->filemark_cnt; i++)
2630 if ((n=ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[i])) < frame_position)
2634 actual_mark_ppos = STp->buffer->aux->frame_type == OS_FRAME_TYPE_MARKER ?
2635 frame_position - 1 : ntohl(STp->buffer->aux->last_mark_ppos);
2636 if (frame_position != STp->first_frame_position ||
2637 frame_seq_numbr != STp->frame_seq_number + (halfway_frame?0:1) ||
2641 STp->first_frame_position, frame_position,
2642 STp->frame_seq_number + (halfway_frame?0:1),
2649 osst_set_frame_position(STp, aSRpnt, frame_position - 1, 0);
2650 STp->buffer->buffer_bytes = read_pointer;
2651 STp->ps[STp->partition].rw = ST_WRITING;
2652 STp->dirty = 1;
2654 STp->frame_in_buffer = halfway_frame;
2655 STp->frame_seq_number = frame_seq_numbr;
2656 STp->logical_blk_num = logical_blk_num;
2683 static int osst_configure_onstream(struct osst_tape *STp, struct osst_request ** aSRpnt)
2686 char * name = tape_name(STp);
2694 if (STp->ready != ST_READY) {
2701 if (STp->os_fw_rev < 10600) {
2702 printk(KERN_INFO "%s:I: Old OnStream firmware revision detected (%s),\n", name, STp->device->rev);
2716 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], DMA_FROM_DEVICE, STp->timeout, 0, 1);
2724 if ((STp->buffer)->syscall_result != 0) {
2729 header = (osst_mode_parameter_header_t *) (STp->buffer)->b_data;
2730 bs = (osst_block_size_page_t *) ((STp->buffer)->b_data + sizeof(osst_mode_parameter_header_t) + header->bdl);
2753 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], DMA_TO_DEVICE, STp->timeout, 0, 1);
2755 if ((STp->buffer)->syscall_result != 0) {
2766 osst_set_retries(STp, aSRpnt, 0);
2784 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 0] = VENDOR_IDENT_PAGE | (1 << 7);
2785 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 1] = 6;
2786 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 2] = 'L';
2787 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 3] = 'I';
2788 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 4] = 'N';
2789 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 5] = '4';
2790 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 6] = 0;
2791 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 7] = 0;
2793 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], DMA_TO_DEVICE, STp->timeout, 0, 1);
2796 if ((STp->buffer)->syscall_result != 0) {
2798 (char *) ((STp->buffer)->b_data + MODE_HEADER_LENGTH + 2));
2808 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], DMA_FROM_DEVICE, STp->timeout, 0, 1);
2811 if ((STp->buffer)->syscall_result != 0) {
2816 header = (osst_mode_parameter_header_t *) (STp->buffer)->b_data;
2817 cp = (osst_capabilities_page_t *) ((STp->buffer)->b_data +
2828 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], DMA_FROM_DEVICE, STp->timeout, 0, 1);
2831 if ((STp->buffer)->syscall_result != 0) {
2836 header = (osst_mode_parameter_header_t *) (STp->buffer)->b_data;
2837 prm = (osst_tape_paramtr_page_t *) ((STp->buffer)->b_data +
2840 STp->density = prm->density;
2841 STp->capacity = ntohs(prm->segtrk) * ntohs(prm->trks);
2844 name, STp->density, STp->capacity / 32, drive_buffer_size);
2854 static int cross_eof(struct osst_tape *STp, struct osst_request ** aSRpnt, int forward)
2857 char * name = tape_name(STp);
2867 result = osst_space_over_filemarks_forward_slow(STp, aSRpnt, MTFSF, 1);
2871 result = osst_seek_logical_blk(STp, aSRpnt, STp->logical_blk_num - 1);
2883 static int osst_get_frame_position(struct osst_tape *STp, struct osst_request ** aSRpnt)
2888 char * name = tape_name(STp);
2893 char * olddata = STp->buffer->b_data;
2894 int oldsize = STp->buffer->buffer_size;
2896 if (STp->ready != ST_READY) return (-EIO);
2901 STp->buffer->b_data = mybuf; STp->buffer->buffer_size = 24;
2902 SRpnt = osst_do_scsi(*aSRpnt, STp, scmd, 20, DMA_FROM_DEVICE,
2903 STp->timeout, MAX_RETRIES, 1);
2905 STp->buffer->b_data = olddata; STp->buffer->buffer_size = oldsize;
2910 if (STp->buffer->syscall_result)
2921 STp->buffer->b_data = mybuf; STp->buffer->buffer_size = 24;
2922 SRpnt = osst_do_scsi(SRpnt, STp, scmd, 20, DMA_FROM_DEVICE,
2923 STp->timeout, MAX_RETRIES, 1);
2926 name, mysense[2], mysense[12], mysense[13], STp->buffer->syscall_result?"":"ok:",
2929 if (!STp->buffer->syscall_result)
2934 STp->first_frame_position = ((STp->buffer)->b_data[4] << 24)
2935 + ((STp->buffer)->b_data[5] << 16)
2936 + ((STp->buffer)->b_data[6] << 8)
2937 + (STp->buffer)->b_data[7];
2938 STp->last_frame_position = ((STp->buffer)->b_data[ 8] << 24)
2939 + ((STp->buffer)->b_data[ 9] << 16)
2940 + ((STp->buffer)->b_data[10] << 8)
2941 + (STp->buffer)->b_data[11];
2942 STp->cur_frames = (STp->buffer)->b_data[15];
2946 STp->first_frame_position, STp->last_frame_position,
2947 ((STp->buffer)->b_data[0]&0x80)?" (BOP)":
2948 ((STp->buffer)->b_data[0]&0x40)?" (EOP)":"",
2949 STp->cur_frames);
2952 if (STp->cur_frames == 0 && STp->first_frame_position != STp->last_frame_position) {
2955 STp->first_frame_position, STp->last_frame_position, STp->cur_frames);
2957 STp->first_frame_position = STp->last_frame_position;
2960 STp->buffer->b_data = olddata; STp->buffer->buffer_size = oldsize;
2962 return (result == 0 ? STp->first_frame_position : result);
2967 static int osst_set_frame_position(struct osst_tape *STp, struct osst_request ** aSRpnt, int ppos, int skip)
2974 char * name = tape_name(STp);
2976 if (STp->ready != ST_READY) return (-EIO);
2978 STps = &(STp->ps[STp->partition]);
2980 if (ppos < 0 || ppos > STp->capacity) {
2982 pp = ppos = ppos < 0 ? 0 : (STp->capacity - 1);
3001 SRpnt = osst_do_scsi(*aSRpnt, STp, scmd, 0, DMA_NONE, STp->long_timeout,
3007 if ((STp->buffer)->syscall_result != 0) {
3010 name, STp->first_frame_position, pp);
3015 osst_wait_ready(STp, aSRpnt, 5 * 60, OSST_WAIT_POSITION_COMPLETE);
3017 STp->first_frame_position = STp->last_frame_position = ppos;
3021 STp->frame_in_buffer = 0;
3025 static int osst_write_trailer(struct osst_tape *STp, struct osst_request ** aSRpnt, int leave_at_EOT)
3027 struct st_partstat * STps = &(STp->ps[STp->partition]);
3030 if (STp->write_type != OS_WRITE_NEW_MARK) {
3032 result = osst_flush_drive_buffer(STp, aSRpnt);
3034 result = osst_write_filemark(STp, aSRpnt);
3041 result = osst_write_eod(STp, aSRpnt);
3042 osst_write_header(STp, aSRpnt, leave_at_EOT);
3053 static int osst_flush_write_buffer(struct osst_tape *STp, struct osst_request ** aSRpnt)
3060 char * name = tape_name(STp);
3062 if ((STp->buffer)->writing) {
3063 if (SRpnt == (STp->buffer)->last_SRpnt)
3074 osst_write_behind_check(STp);
3075 if ((STp->buffer)->syscall_result) {
3079 name, (STp->buffer)->midlevel_result);
3081 if ((STp->buffer)->midlevel_result == INT_MAX)
3088 if (STp->dirty == 1) {
3090 STp->write_count++;
3091 STps = &(STp->ps[STp->partition]);
3093 offset = STp->buffer->buffer_bytes;
3094 blks = (offset + STp->block_size - 1) / STp->block_size;
3098 osst_zero_buffer_tail(STp->buffer);
3100 if (STp->poll)
3101 if (osst_wait_frame (STp, aSRpnt, STp->first_frame_position, -50, 120))
3102 result = osst_recover_wait_frame(STp, aSRpnt, 1);
3109 switch (STp->write_type) {
3114 name, blks, STp->frame_seq_number,
3115 STp->logical_blk_num - blks, STp->logical_blk_num - 1);
3117 osst_init_aux(STp, OS_FRAME_TYPE_DATA, STp->frame_seq_number++,
3118 STp->logical_blk_num - blks, STp->block_size, blks);
3121 osst_init_aux(STp, OS_FRAME_TYPE_EOD, STp->frame_seq_number++,
3122 STp->logical_blk_num, 0, 0);
3125 osst_init_aux(STp, OS_FRAME_TYPE_MARKER, STp->frame_seq_number++,
3126 STp->logical_blk_num++, 0, blks=1);
3129 osst_init_aux(STp, OS_FRAME_TYPE_HEADER, 0, 0, 0, blks=0);
3132 osst_init_aux(STp, OS_FRAME_TYPE_FILL, 0, 0, 0, 0);
3140 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, transfer, DMA_TO_DEVICE,
3141 STp->timeout, MAX_RETRIES, 1);
3146 if ((STp->buffer)->syscall_result != 0) {
3156 STp->dirty = 0;
3157 (STp->buffer)->buffer_bytes = 0;
3161 if (osst_write_error_recovery(STp, aSRpnt, 1)) {
3169 STp->first_frame_position++;
3170 STp->dirty = 0;
3171 (STp->buffer)->buffer_bytes = 0;
3183 static int osst_flush_buffer(struct osst_tape * STp, struct osst_request ** aSRpnt, int seek_next)
3188 char * name = tape_name(STp);
3195 if( STp->pos_unknown)
3198 if (STp->ready != ST_READY)
3201 STps = &(STp->ps[STp->partition]);
3202 if (STps->rw == ST_WRITING || STp->dirty) { /* Writing */
3203 STp->write_type = OS_WRITE_DATA;
3204 return osst_flush_write_buffer(STp, aSRpnt);
3206 if (STp->block_size == 0)
3213 if (!STp->can_bsr) {
3214 backspace = ((STp->buffer)->buffer_bytes + (STp->buffer)->read_pointer) / STp->block_size -
3215 ((STp->buffer)->read_pointer + STp->block_size - 1 ) / STp->block_size ;
3216 (STp->buffer)->buffer_bytes = 0;
3217 (STp->buffer)->read_pointer = 0;
3218 STp->frame_in_buffer = 0;
3223 result = cross_eof(STp, aSRpnt, 0); /* Back over the EOF hit */
3233 result = osst_seek_logical_blk(STp, aSRpnt, STp->logical_blk_num - backspace);
3245 static int osst_write_frame(struct osst_tape * STp, struct osst_request ** aSRpnt, int synchronous)
3251 char * name = tape_name(STp);
3254 if ((!STp-> raw) && (STp->first_frame_position == 0xbae)) { /* _must_ preserve buffer! */
3258 if (osst_flush_drive_buffer(STp, aSRpnt) < 0) {
3262 if (osst_get_frame_position(STp, aSRpnt) < 0xbb8) {
3266 osst_position_tape_and_confirm(STp, aSRpnt, 0xbb8);
3270 if (STp->poll)
3271 if (osst_wait_frame (STp, aSRpnt, STp->first_frame_position, -48, 120))
3272 if (osst_recover_wait_frame(STp, aSRpnt, 1))
3275 // osst_build_stats(STp, &SRpnt);
3277 STp->ps[STp->partition].rw = ST_WRITING;
3278 STp->write_type = OS_WRITE_DATA;
3284 blks = STp->buffer->buffer_bytes / STp->block_size;
3288 STp->frame_seq_number, STp->logical_blk_num - blks, STp->logical_blk_num - 1);
3290 osst_init_aux(STp, OS_FRAME_TYPE_DATA, STp->frame_seq_number++,
3291 STp->logical_blk_num - blks, STp->block_size, blks);
3295 STp->write_pending = 1;
3297 SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, OS_FRAME_SIZE, DMA_TO_DEVICE, STp->timeout,
3304 if (STp->buffer->syscall_result != 0) {
3315 if (osst_write_error_recovery(STp, aSRpnt, 1))
3320 STp->first_frame_position++;
3323 STp->write_count++;
3329 static int do_door_lock(struct osst_tape * STp, int do_lock)
3335 printk(OSST_DEB_MSG "%s:D: %socking drive door.\n", tape_name(STp), do_lock ? "L" : "Unl");
3337 retval = scsi_ioctl(STp->device, cmd, NULL);
3339 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED;
3342 STp->door_locked = ST_LOCK_FAILS;
3348 static void reset_state(struct osst_tape *STp)
3353 STp->pos_unknown = 0;
3355 STps = &(STp->ps[i]);
3380 struct osst_tape * STp = filp->private_data;
3381 char * name = tape_name(STp);
3384 if (mutex_lock_interruptible(&STp->lock))
3393 if( !scsi_block_when_processing_errors(STp->device) ) {
3398 if (STp->ready != ST_READY) {
3399 if (STp->ready == ST_NO_TAPE)
3405 STm = &(STp->modes[STp->current_mode]);
3417 if (STp->pos_unknown) {
3423 if (!STp->in_use) {
3430 if (STp->write_prot) {
3436 if (STp->block_size != 0 && (count % STp->block_size) != 0) {
3438 name, count, STp->block_size<1024?
3439 STp->block_size:STp->block_size/1024, STp->block_size<1024?'b':'k');
3444 if (STp->first_frame_position >= STp->capacity - OSST_EOM_RESERVE) {
3446 name, STp->first_frame_position);
3451 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && !do_door_lock(STp, 1))
3452 STp->door_locked = ST_LOCKED_AUTO;
3454 STps = &(STp->ps[STp->partition]);
3461 retval = osst_flush_buffer(STp, &SRpnt, 0);
3468 if (!STp->header_ok ||
3469 (STp->first_frame_position == STp->first_data_ppos && STps->drv_block < 0) ||
3471 STp->wrt_pass_cntr++;
3474 name, STp->wrt_pass_cntr);
3476 osst_reset_header(STp, &SRpnt);
3481 if ((STp->fast_open && osst_verify_position(STp, &SRpnt)) ||
3483 if (STp->first_frame_position == STp->eod_frame_ppos) { /* at EOD */
3484 STps->drv_file = STp->filemark_cnt;
3497 if ((STps->drv_file + STps->drv_block) > 0 && STps->drv_file < STp->filemark_cnt) {
3498 STp->filemark_cnt = STps->drv_file;
3499 STp->last_mark_ppos =
3500 ntohl(STp->header_cache->dat_fm_tab.fm_tab_ent[STp->filemark_cnt-1]);
3503 name, STps->drv_file, STp->wrt_pass_cntr);
3510 name, STp->filemark_cnt, STp->last_mark_ppos, STp->last_mark_lbn);
3514 STp->fast_open = 0;
3516 if (!STp->header_ok) {
3524 if ((STp->buffer)->writing) {
3526 osst_write_behind_check(STp);
3527 if ((STp->buffer)->syscall_result) {
3531 (STp->buffer)->midlevel_result);
3533 if ((STp->buffer)->midlevel_result == INT_MAX)
3560 write_threshold = (STp->buffer)->buffer_blocks * STp->block_size;
3569 STp->logical_blk_num, STp->frame_seq_number, STp->first_frame_position);
3572 while ((STp->buffer)->buffer_bytes + count > write_threshold)
3575 do_count = (STp->buffer)->buffer_blocks * STp->block_size -
3576 (STp->buffer)->buffer_bytes;
3580 i = append_to_buffer(b_point, STp->buffer, do_count);
3586 blks = do_count / STp->block_size;
3587 STp->logical_blk_num += blks; /* logical_blk_num is incremented as data is moved from user */
3589 i = osst_write_frame(STp, &SRpnt, 1);
3592 transfer = STp->buffer->writing;
3597 STps->drv_block += (do_count - transfer) / STp->block_size;
3625 STp->buffer->buffer_bytes = 0;
3626 STp->dirty = 0;
3638 STp->buffer->buffer_bytes = 0;
3639 STp->dirty = 0;
3643 STp->dirty = 1;
3644 i = append_to_buffer(b_point, STp->buffer, count);
3649 blks = count / STp->block_size;
3650 STp->logical_blk_num += blks;
3658 if (doing_write && (STp->buffer)->syscall_result != 0) {
3659 retval = (STp->buffer)->syscall_result;
3663 if (STm->do_async_writes && ((STp->buffer)->buffer_bytes >= STp->write_threshold)) {
3665 (STp->buffer)->writing = ((STp->buffer)->buffer_bytes /
3666 STp->block_size) * STp->block_size;
3667 STp->dirty = !((STp->buffer)->writing ==
3668 (STp->buffer)->buffer_bytes);
3670 i = osst_write_frame(STp, &SRpnt, 0);
3686 mutex_unlock(&STp->lock);
3701 struct osst_tape * STp = filp->private_data;
3702 char * name = tape_name(STp);
3705 if (mutex_lock_interruptible(&STp->lock))
3714 if( !scsi_block_when_processing_errors(STp->device) ) {
3719 if (STp->ready != ST_READY) {
3720 if (STp->ready == ST_NO_TAPE)
3726 STm = &(STp->modes[STp->current_mode]);
3732 if (!STp->in_use) {
3739 if (!STp->header_ok) {
3744 if (STp->do_auto_lock && STp->door_locked == ST_UNLOCKED && !do_door_lock(STp, 1))
3745 STp->door_locked = ST_LOCKED_AUTO;
3747 STps = &(STp->ps[STp->partition]);
3749 retval = osst_flush_buffer(STp, &SRpnt, 0);
3755 if ((count % STp->block_size) != 0) {
3758 STp->block_size<1024?STp->block_size:STp->block_size/1024, STp->block_size<1024?'b':'k');
3764 STps->eof, (STp->buffer)->buffer_bytes);
3766 if ((STp->buffer)->buffer_bytes == 0 &&
3788 for (total = 0, special = 0; total < count - STp->block_size + 1 && !special; ) {
3791 if ((STp->buffer)->buffer_bytes == 0) {
3794 special = osst_get_logical_frame(STp, &SRpnt, STp->frame_seq_number, 0);
3796 STp->frame_in_buffer = 0;
3803 if ((STp->buffer)->buffer_bytes > 0) {
3807 STps->eof, (STp->buffer)->buffer_bytes, (int) (count - total));
3810 transfer = (((STp->buffer)->buffer_bytes < count - total ?
3811 (STp->buffer)->buffer_bytes : count - total)/
3812 STp->block_size) * STp->block_size;
3817 name, count, STp->block_size < 1024?
3818 STp->block_size:STp->block_size/1024,
3819 STp->block_size<1024?'b':'k');
3822 i = from_buffer(STp->buffer, buf, transfer);
3827 STp->logical_blk_num += transfer / STp->block_size;
3828 STps->drv_block += transfer / STp->block_size;
3834 if ((STp->buffer)->buffer_bytes == 0) {
3838 name, STp->frame_seq_number);
3840 STp->frame_in_buffer = 0;
3841 STp->frame_seq_number++; /* frame to look for next time */
3848 STps->eof = (STp->first_frame_position >= STp->eod_frame_ppos)?ST_EOD_2:ST_FM;
3870 mutex_unlock(&STp->lock);
3877 static void osst_log_options(struct osst_tape *STp, struct st_modedef *STm, char *name)
3881 name, STp->current_mode, STm->do_buffer_writes, STm->do_async_writes,
3885 name, STp->can_bsr, STp->two_fm, STp->fast_mteom, STp->do_auto_lock);
3888 name, STm->defaults_for_writes, STp->omit_blklims, STp->can_partitions,
3889 STp->scsi2_logical);
3900 static int osst_set_options(struct osst_tape *STp, long options)
3905 char * name = tape_name(STp);
3907 STm = &(STp->modes[STp->current_mode]);
3909 memcpy(STm, &(STp->modes[0]), sizeof(*STm));
3914 name, STp->current_mode);
3924 STp->two_fm = (options & MT_ST_TWO_FM) != 0;
3925 STp->fast_mteom = (options & MT_ST_FAST_MTEOM) != 0;
3926 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
3927 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
3928 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
3929 if ((STp->device)->scsi_level >= SCSI_2)
3930 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
3931 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
3936 osst_log_options(STp, STm, name);
3949 STp->two_fm = value;
3951 STp->fast_mteom = value;
3953 STp->do_auto_lock = value;
3955 STp->can_bsr = value;
3957 STp->omit_blklims = value;
3958 if ((STp->device)->scsi_level >= SCSI_2 &&
3960 STp->can_partitions = value;
3962 STp->scsi2_logical = value;
3969 osst_log_options(STp, STm, name);
3978 STp->write_threshold = value;
4002 STp->long_timeout = (value & ~MT_ST_SET_LONG_TIMEOUT) * HZ;
4007 STp->timeout = value * HZ;
4027 STp->default_drvbuffer = 0xff;
4031 STp->default_drvbuffer = value & 7;
4033 name, STp->default_drvbuffer);
4056 static int osst_int_ioctl(struct osst_tape * STp, struct osst_request ** aSRpnt,
4068 char * name = tape_name(STp);
4070 if (STp->ready != ST_READY && cmd_in != MTLOAD) {
4071 if (STp->ready == ST_NO_TAPE)
4076 timeout = STp->long_timeout;
4077 STps = &(STp->ps[STp->partition]);
4081 frame_seq_numbr = STp->frame_seq_number;
4082 logical_blk_num = STp->logical_blk_num;
4089 if (STp->raw)
4091 if (STp->linux_media)
4092 ioctl_result = osst_space_over_filemarks_forward_fast(STp, &SRpnt, cmd_in, arg);
4094 ioctl_result = osst_space_over_filemarks_forward_slow(STp, &SRpnt, cmd_in, arg);
4104 if (STp->raw)
4106 ioctl_result = osst_space_over_filemarks_backward(STp, &SRpnt, cmd_in, arg);
4128 ioctl_result = osst_seek_logical_blk(STp, &SRpnt, logical_blk_num);
4172 if ((STps->rw == ST_WRITING || STp->dirty) && !STp->pos_unknown) {
4173 STp->write_type = OS_WRITE_DATA;
4174 ioctl_result = osst_flush_write_buffer(STp, &SRpnt);
4182 ioctl_result |= osst_write_filemark(STp, &SRpnt);
4188 if (STp->write_prot)
4190 if (!STp->raw)
4198 timeout = STp->timeout;
4216 if (STp->ready == ST_NO_TAPE)
4225 timeout = STp->timeout;
4258 if ((osst_position_tape_and_confirm(STp, &SRpnt, STp->eod_frame_ppos) < 0) ||
4259 (osst_get_logical_frame(STp, &SRpnt, -1, 0) < 0)) {
4263 if (STp->buffer->aux->frame_type != OS_FRAME_TYPE_EOD) {
4270 ioctl_result = osst_set_frame_position(STp, &SRpnt, STp->eod_frame_ppos, 0);
4271 fileno = STp->filemark_cnt;
4276 if (STp->write_prot)
4278 ioctl_result = osst_reset_header(STp, &SRpnt);
4279 i = osst_write_eod(STp, &SRpnt);
4281 i = osst_position_tape_and_confirm(STp, &SRpnt, STp->eod_frame_ppos);
4298 !STp->dirty &&
4299 ((STp->buffer)->buffer_bytes == 0) &&
4309 STp->block_size = (arg & MT_ST_BLKSIZE_MASK);
4311 name, STp->block_size);
4318 if (STp->dirty || (STp->buffer)->buffer_bytes != 0)
4322 (arg & MT_ST_BLKSIZE_MASK) != STp->block_size ) {
4334 SRpnt = osst_do_scsi(SRpnt, STp, cmd, datalen, direction, timeout, MAX_RETRIES, 1);
4336 ioctl_result = (STp->buffer)->syscall_result;
4346 STp->frame_seq_number = frame_seq_numbr;
4347 STp->logical_blk_num = logical_blk_num;
4373 ioctl_result = osst_seek_logical_blk(STp, &SRpnt, STp->logical_blk_num-1);
4375 STp->logical_blk_num++;
4376 STp->frame_seq_number++;
4377 STp->frame_in_buffer = 0;
4378 STp->buffer->read_pointer = 0;
4381 STps->eof = (STp->first_frame_position >= STp->eod_frame_ppos)?ST_EOD:ST_FM;
4386 STp->rew_at_close = 0;
4389 STp->ps[i].rw = ST_IDLE;
4390 STp->ps[i].last_block_valid = 0;
4392 STp->partition = 0;
4396 ioctl_result = osst_position_tape_and_confirm(STp, &SRpnt, STp->first_data_ppos);
4402 if (osst_position_tape_and_confirm(STp, &SRpnt, STp->first_data_ppos) < 0)
4408 if (osst_position_tape_and_confirm(STp, &SRpnt, STp->eod_frame_ppos) < 0)
4411 STps->drv_file = STp->filemark_cnt;
4418 STp->header_ok = 0;
4420 STp->header_ok = 0;
4432 if (cmd_in == MTLOAD && osst_wait_for_medium(STp, &SRpnt, 60))
4433 ioctl_result = osst_wait_ready(STp, &SRpnt, 5 * 60, OSST_WAIT_POSITION_COMPLETE);
4448 struct osst_tape * STp;
4464 (STp = os_scsi_tapes[dev]) == NULL || !STp->device) {
4469 name = tape_name(STp);
4471 if (STp->in_use) {
4478 if (scsi_device_get(STp->device)) {
4485 filp->private_data = STp;
4486 STp->in_use = 1;
4488 STp->rew_at_close = TAPE_REWIND(inode);
4490 if( !scsi_block_when_processing_errors(STp->device) ) {
4494 if (mode != STp->current_mode) {
4498 name, STp->current_mode, mode);
4501 STp->current_mode = mode;
4503 STm = &(STp->modes[STp->current_mode]);
4506 STp->write_prot = ((flags & O_ACCMODE) == O_RDONLY);
4508 STp->raw = TAPE_IS_RAW(inode);
4509 if (STp->raw)
4510 STp->header_ok = 0;
4513 if (!enlarge_buffer(STp->buffer, STp->restr_dma)) {
4518 if (STp->buffer->buffer_size >= OS_FRAME_SIZE) {
4520 (i < STp->buffer->sg_segs) && ((b_size + STp->buffer->sg[i].length) <= OS_DATA_SIZE);
4521 b_size += STp->buffer->sg[i++].length);
4522 STp->buffer->aux = (os_aux_t *) (page_address(sg_page(&STp->buffer->sg[i])) + OS_DATA_SIZE - b_size);
4525 STp->buffer->b_data, page_address(STp->buffer->sg[0].page));
4527 STp->buffer->aux, i, page_address(STp->buffer->sg[i].page));
4530 STp->buffer->aux = NULL; /* this had better never happen! */
4535 STp->buffer->writing = 0;
4536 STp->buffer->syscall_result = 0;
4537 STp->dirty = 0;
4539 STps = &(STp->ps[i]);
4542 STp->ready = ST_READY;
4544 STp->nbr_waits = STp->nbr_finished = 0;
4550 SRpnt = osst_do_scsi(NULL, STp, cmd, 0, DMA_NONE, STp->timeout, MAX_RETRIES, 1);
4552 retval = (STp->buffer)->syscall_result;
4570 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
4571 STp->timeout, MAX_RETRIES, 1);
4573 osst_wait_ready(STp, &SRpnt, (SRpnt->sense[13]==1?15:3) * 60, 0);
4580 STp->header_ok = 0;
4587 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
4588 STp->timeout, MAX_RETRIES, 1);
4594 STp->pos_unknown = 0;
4595 STp->partition = STp->new_partition = 0;
4596 if (STp->can_partitions)
4597 STp->nbr_partitions = 1; /* This guess will be updated later if necessary */
4599 STps = &(STp->ps[i]);
4608 STp->recover_count = 0;
4609 STp->abort_count = 0;
4615 if (!STp->buffer->syscall_result && STp->header_ok &&
4624 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], DMA_FROM_DEVICE, STp->timeout, 0, 1);
4626 if (STp->buffer->syscall_result ||
4627 STp->buffer->b_data[MODE_HEADER_LENGTH + 2] != 'L' ||
4628 STp->buffer->b_data[MODE_HEADER_LENGTH + 3] != 'I' ||
4629 STp->buffer->b_data[MODE_HEADER_LENGTH + 4] != 'N' ||
4630 STp->buffer->b_data[MODE_HEADER_LENGTH + 5] != '4' ) {
4633 STp->buffer->b_data[MODE_HEADER_LENGTH + 2],
4634 STp->buffer->b_data[MODE_HEADER_LENGTH + 3],
4635 STp->buffer->b_data[MODE_HEADER_LENGTH + 4],
4636 STp->buffer->b_data[MODE_HEADER_LENGTH + 5]);
4638 STp->header_ok = 0;
4640 i = STp->first_frame_position;
4641 if (STp->header_ok && i == osst_get_frame_position(STp, &SRpnt)) {
4642 if (STp->door_locked == ST_UNLOCKED) {
4643 if (do_door_lock(STp, 1))
4646 STp->door_locked = ST_LOCKED_AUTO;
4648 if (!STp->frame_in_buffer) {
4649 STp->block_size = (STm->default_blksize > 0) ?
4651 STp->buffer->buffer_bytes = STp->buffer->read_pointer = 0;
4653 STp->buffer->buffer_blocks = OS_DATA_SIZE / STp->block_size;
4654 STp->fast_open = 1;
4659 if (i != STp->first_frame_position)
4661 name, i, STp->first_frame_position);
4663 STp->header_ok = 0;
4665 STp->fast_open = 0;
4667 if ((STp->buffer)->syscall_result != 0 && /* in all error conditions except no medium */
4675 (STp->buffer)->b_data[0] = cmd[4] - 1;
4676 (STp->buffer)->b_data[1] = 0; /* Medium Type - ignoring */
4677 (STp->buffer)->b_data[2] = 0; /* Reserved */
4678 (STp->buffer)->b_data[3] = 0; /* Block Descriptor Length */
4679 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 0] = 0x3f;
4680 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 1] = 1;
4681 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 2] = 2;
4682 (STp->buffer)->b_data[MODE_HEADER_LENGTH + 3] = 3;
4687 SRpnt = osst_do_scsi(SRpnt, STp, cmd, cmd[4], DMA_TO_DEVICE, STp->timeout, 0, 1);
4689 STp->header_ok = 0;
4696 SRpnt = osst_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
4697 STp->timeout, MAX_RETRIES, 1);
4703 STp->pos_unknown = 0;
4704 STp->partition = STp->new_partition = 0;
4705 if (STp->can_partitions)
4706 STp->nbr_partitions = 1; /* This guess will be updated later if necessary */
4708 STps = &(STp->ps[i]);
4721 if (osst_wait_ready(STp, &SRpnt, 15 * 60, 0))
4724 if ((STp->buffer)->syscall_result != 0) {
4725 if ((STp->device)->scsi_level >= SCSI_2 &&
4729 STp->ready = ST_NO_TAPE;
4731 STp->ready = ST_NOT_READY;
4734 STp->density = 0; /* Clear the erroneous "residue" */
4735 STp->write_prot = 0;
4736 STp->block_size = 0;
4737 STp->ps[0].drv_file = STp->ps[0].drv_block = (-1);
4738 STp->partition = STp->new_partition = 0;
4739 STp->door_locked = ST_UNLOCKED;
4743 osst_configure_onstream(STp, &SRpnt);
4745 STp->block_size = STp->raw ? OS_FRAME_SIZE : (
4747 STp->buffer->buffer_blocks = STp->raw ? 1 : OS_DATA_SIZE / STp->block_size;
4748 STp->buffer->buffer_bytes =
4749 STp->buffer->read_pointer =
4750 STp->frame_in_buffer = 0;
4755 name, STp->block_size, OS_FRAME_SIZE, (STp->buffer)->buffer_size,
4756 (STp->buffer)->buffer_blocks);
4759 if (STp->drv_write_prot) {
4760 STp->write_prot = 1;
4776 STp->density_changed = STp->blksize_changed = 0;
4777 STp->compression_changed = 0;
4783 if (STp->door_locked == ST_UNLOCKED) {
4784 if (do_door_lock(STp, 1))
4787 STp->door_locked = ST_LOCKED_AUTO;
4790 osst_analyze_headers(STp, &SRpnt);
4800 normalize_buffer(STp->buffer);
4801 STp->header_ok = 0;
4802 STp->in_use = 0;
4803 scsi_device_put(STp->device);
4825 struct osst_tape * STp = filp->private_data;
4826 struct st_modedef * STm = &(STp->modes[STp->current_mode]);
4827 struct st_partstat * STps = &(STp->ps[STp->partition]);
4829 char * name = tape_name(STp);
4834 if ((STps->rw == ST_WRITING || STp->dirty) && !STp->pos_unknown) {
4835 STp->write_type = OS_WRITE_DATA;
4836 result = osst_flush_write_buffer(STp, &SRpnt);
4840 if ( STps->rw >= ST_WRITING && !STp->pos_unknown) {
4847 name, STp->nbr_waits, STp->nbr_finished);
4850 result = osst_write_trailer(STp, &SRpnt, !(STp->rew_at_close));
4854 name, 1+STp->two_fm);
4857 else if (!STp->rew_at_close) {
4858 STps = &(STp->ps[STp->partition]);
4860 if (STp->can_bsr)
4861 result = osst_flush_buffer(STp, &SRpnt, 0); /* this is the default path */
4863 result = cross_eof(STp, &SRpnt, 0);
4875 !(result = cross_eof(STp, &SRpnt, 1))) ||
4885 if (STp->rew_at_close) {
4886 result2 = osst_position_tape_and_confirm(STp, &SRpnt, STp->first_data_ppos);
4887 STps->drv_file = STps->drv_block = STp->frame_seq_number = STp->logical_blk_num = 0;
4893 if (STp->abort_count || STp->recover_count) {
4895 if (STp->abort_count)
4896 printk(" %d unrecovered errors", STp->abort_count);
4897 if (STp->recover_count)
4898 printk(" %d recovered errors", STp->recover_count);
4899 if (STp->write_count)
4900 printk(" in %d frames written", STp->write_count);
4901 if (STp->read_count)
4902 printk(" in %d frames read", STp->read_count);
4904 STp->recover_count = 0;
4905 STp->abort_count = 0;
4907 STp->write_count = 0;
4908 STp->read_count = 0;
4918 struct osst_tape * STp = filp->private_data;
4920 if (STp->door_locked == ST_LOCKED_AUTO)
4921 do_door_lock(STp, 0);
4923 if (STp->raw)
4924 STp->header_ok = 0;
4926 normalize_buffer(STp->buffer);
4928 STp->in_use = 0;
4931 scsi_device_put(STp->device);
4945 struct osst_tape * STp = file->private_data;
4946 char * name = tape_name(STp);
4950 if (mutex_lock_interruptible(&STp->lock)) {
4956 if (debugging && !STp->in_use) {
4962 STm = &(STp->modes[STp->current_mode]);
4963 STps = &(STp->ps[STp->partition]);
4971 if( !scsi_block_when_processing_errors(STp->device) ) {
4980 cmd_type, cmd_nr, STp->raw?"raw":"normal");
5008 if (!STp->pos_unknown) {
5025 i = !STp->can_partitions || (STp->new_partition != STp->partition);
5035 i = osst_flush_buffer(STp, &SRpnt, i);
5056 reset_state(STp);
5058 STp->device->was_reset = 0;
5076 STp->first_frame_position, STp->eod_frame_ppos, STp->frame_seq_number,
5077 STp->logical_blk_num, STps->drv_file, STps->drv_block );
5079 if (STps->rw >= ST_WRITING && STp->first_frame_position >= STp->eod_frame_ppos) {
5080 auto_weof = ((STp->write_type != OS_WRITE_NEW_MARK) &&
5082 i = osst_write_trailer(STp, &SRpnt,
5086 name, auto_weof, STp->first_frame_position, STp->eod_frame_ppos,
5087 STp->frame_seq_number, STp->logical_blk_num, STps->drv_file, STps->drv_block );
5097 if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED)
5098 do_door_lock(STp, 0); /* Ignore result! */
5102 retval = osst_set_options(STp, mtc.mt_count);
5107 if (mtc.mt_count >= STp->nbr_partitions)
5110 STp->new_partition = mtc.mt_count;
5117 if (!STp->can_partitions) {
5121 if ((i = osst_int_ioctl(STp, &SRpnt, MTREW, 0)) < 0 /*||
5127 STp->ps[i].rw = ST_IDLE;
5128 STp->ps[i].at_sm = 0;
5129 STp->ps[i].last_block_valid = 0;
5131 STp->partition = STp->new_partition = 0;
5132 STp->nbr_partitions = 1; /* Bad guess ?-) */
5139 if (STp->raw)
5140 i = osst_set_frame_position(STp, &SRpnt, mtc.mt_count, 0);
5142 i = osst_seek_sector(STp, &SRpnt, mtc.mt_count);
5143 if (!STp->can_partitions)
5144 STp->ps[0].rw = ST_IDLE;
5150 retval = do_door_lock(STp, (mtc.mt_op == MTLOCK));
5155 cross_eof(STp, &SRpnt, 0);
5162 retval = osst_int_ioctl(STp, &SRpnt, mtc.mt_op, mtc.mt_count);
5171 if ((i = osst_flush_buffer(STp, &SRpnt, 0)) < 0) {
5185 mt_status.mt_erreg = STp->recover_erreg << MT_ST_SOFTERR_SHIFT;
5187 ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) |
5188 ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK);
5191 if (STp->block_size != 0) {
5193 mt_status.mt_blkno += (STp->buffer)->buffer_bytes / STp->block_size;
5195 mt_status.mt_blkno -= ((STp->buffer)->buffer_bytes +
5196 STp->block_size - 1) / STp->block_size;
5200 if (STp->drv_write_prot)
5208 mt_status.mt_resid = STp->partition;
5213 if (STp->density == 1)
5215 else if (STp->density == 2)
5217 else if (STp->density == 3)
5219 if (STp->ready == ST_READY)
5221 if (STp->ready == ST_NO_TAPE)
5225 if (STm->do_async_writes || (STm->do_buffer_writes && STp->block_size != 0) ||
5226 STp->drv_buffer != 0)
5235 STp->recover_erreg = 0; /* Clear after read */
5247 if (STp->raw)
5248 blk = osst_get_frame_position(STp, &SRpnt);
5250 blk = osst_get_sector(STp, &SRpnt);
5263 mutex_unlock(&STp->lock);
5265 retval = scsi_ioctl(STp->device, cmd_in, p);
5272 mutex_unlock(&STp->lock);
5281 struct osst_tape *STp = file->private_data;
5282 struct scsi_device *sdev = STp->device;
5689 struct osst_tape * STp = (struct osst_tape *) dev_get_drvdata (dev);
5692 if (STp && STp->header_ok && STp->linux_media)
5693 l = snprintf(buf, PAGE_SIZE, "%d.%d\n", STp->header_cache->major_rev, STp->header_cache->minor_rev);
5703 struct osst_tape * STp = (struct osst_tape *) dev_get_drvdata (dev);
5706 if (STp && STp->header_ok && STp->linux_media)
5707 l = snprintf(buf, PAGE_SIZE, "LIN%d\n", STp->linux_media_version);
5716 struct osst_tape * STp = (struct osst_tape *) dev_get_drvdata (dev);
5719 if (STp && STp->header_ok && STp->linux_media)
5720 l = snprintf(buf, PAGE_SIZE, "%d\n", STp->capacity);
5730 struct osst_tape * STp = (struct osst_tape *) dev_get_drvdata (dev);
5733 if (STp && STp->header_ok && STp->linux_media)
5734 l = snprintf(buf, PAGE_SIZE, "%d\n", STp->first_data_ppos);
5744 struct osst_tape * STp = (struct osst_tape *) dev_get_drvdata (dev);
5747 if (STp && STp->header_ok && STp->linux_media)
5748 l = snprintf(buf, PAGE_SIZE, "%d\n", STp->eod_frame_ppos);
5757 struct osst_tape * STp = (struct osst_tape *) dev_get_drvdata (dev);
5760 if (STp && STp->header_ok && STp->linux_media)
5761 l = snprintf(buf, PAGE_SIZE, "%d\n", STp->filemark_cnt);
5785 static int osst_sysfs_add(dev_t dev, struct device *device, struct osst_tape * STp, char * name)
5790 osst_member = device_create(osst_sysfs_class, device, dev, STp,
6071 struct osst_tape * STp;
6080 if (!(STp = os_scsi_tapes[i])) continue;
6082 vfree(STp->header_cache);
6083 if (STp->buffer) {
6084 normalize_buffer(STp->buffer);
6085 kfree(STp->buffer);
6087 put_disk(STp->drive);
6088 kfree(STp);