int ftape_init_drive(int *formatted) { TRACE_FUN(5, "ftape_init_drive"); int result = 0; int status; result = ftape_report_raw_drive_status(&status); if (result >= 0 && (status & QIC_STATUS_CARTRIDGE_PRESENT)) { if (!(status & QIC_STATUS_AT_BOT)) { /* Antique drives will get here after a soft reset, * modern ones only if the driver is loaded when the * tape wasn't rewound properly. */ ftape_seek_to_bot(); } if (!(status & QIC_STATUS_REFERENCED)) { TRACE(5, "starting seek_load_point"); result = ftape_command_wait(QIC_SEEK_LOAD_POINT, timeout.reset, &status); if (result < 0) { TRACE(1, "seek_load_point failed (command)"); } } } if (result >= 0) { int rate; *formatted = (status & QIC_STATUS_REFERENCED); if (!*formatted) { TRACE(1, "Warning: tape is not formatted !"); } /* Select highest rate supported by both fdc and drive. * Start with highest rate supported by the fdc. */ if (fdc.type >= i82078_1) rate = 0; else if (fdc.type >= i82077) rate = 1; else rate = 2; do { result = ftape_set_data_rate(rate); if (result >= 0) { ftape_calc_timeouts(); break; } ++rate; } while (rate < 4); if (result < 0) { result = -EIO; } } if (result >= 0) { /* Tape should be at bot if new cartridge ! */ ftape_new_cartridge(); } init_drive_needed = 0; TRACE_EXIT; return result; }
int ftape_init_drive(void) { int status; qic_model model; unsigned int qic_std; unsigned int data_rate; TRACE_FUN(ft_t_flow); ftape_init_drive_needed = 0; /* don't retry if this fails ? */ TRACE_CATCH(ftape_report_raw_drive_status(&status),); if (status & QIC_STATUS_CARTRIDGE_PRESENT) { if (!(status & QIC_STATUS_AT_BOT)) { /* Antique drives will get here after a soft reset, * modern ones only if the driver is loaded when the * tape wasn't rewound properly. */ /* Tape should be at bot if new cartridge ! */ ftape_seek_to_bot(); } if (!(status & QIC_STATUS_REFERENCED)) { TRACE(ft_t_flow, "starting seek_load_point"); TRACE_CATCH(ftape_command_wait(QIC_SEEK_LOAD_POINT, ftape_timeout.reset, &status),); } }
int ftape_update_header_segments(byte * buffer, int update) { TRACE_FUN(5, "ftape_update_header_segments"); int result = 0; int dummy; int header_changed = 1; if (ftape_state == writing) { result = loop_until_writes_done(); } if (read_only) { result = 0; /* exit and fake success */ TRACE(4, "Tape set read-only: no update"); } else if (result >= 0) { result = ftape_abort_operation(); if (result >= 0) { if (buffer == NULL) { if (bad_sector_map_changed || failed_sector_log_changed) { ftape_seek_to_bot(); /* prevents extra rewind */ buffer = deblock_buffer; result = read_segment(used_header_segment, buffer, &dummy, 0); if (result < 0) { TRACE_EXIT; return result; } } header_changed = 0; } if (update) { if (bad_sector_map_changed) { store_bad_sector_map(buffer); header_changed = 1; } if (failed_sector_log_changed) { update_failed_sector_log(buffer); header_changed = 1; } } if (header_changed) { ftape_seek_to_bot(); /* prevents extra rewind */ result = ftape_write_header_segments(buffer); } } } TRACE_EXIT; return result; }
static int mt_reset(int *dummy) { TRACE_FUN(ft_t_flow); (void)ftape_seek_to_bot(); TRACE_CATCH(ftape_reset_drive(), zft_init_driver(); zft_uninit_mem(); zft_offline = 1); /* fake a re-open of the device. This will set all flage and * allocate buffers as appropriate. The new tape condition will * force the open routine to do anything we need. */ TRACE_CATCH(_zft_open(-1 /* fake reopen */, 0 /* dummy */),); TRACE_EXIT 0; }
static int zft_write_header_segments(__u8* buffer) { int header_1_ok = 0; int header_2_ok = 0; unsigned int time_stamp; TRACE_FUN(ft_t_noise); TRACE_CATCH(ftape_abort_operation(),); ftape_seek_to_bot(); /* prevents extra rewind */ if (GET4(buffer, 0) != FT_HSEG_MAGIC) { TRACE_ABORT(-EIO, ft_t_err, "wrong header signature found, aborting"); } /* Be optimistic: */ PUT4(buffer, FT_SEG_CNT, zft_written_segments + GET4(buffer, FT_SEG_CNT) + 2); if ((time_stamp = zft_get_time()) != 0) { PUT4(buffer, FT_WR_DATE, time_stamp); if (zft_label_changed) { PUT4(buffer, FT_LABEL_DATE, time_stamp); } } TRACE(ft_t_noise, "writing first header segment %d", ft_header_segment_1); header_1_ok = zft_verify_write_segments(ft_header_segment_1, buffer, FT_SEGMENT_SIZE, zft_deblock_buf) >= 0; TRACE(ft_t_noise, "writing second header segment %d", ft_header_segment_2); header_2_ok = zft_verify_write_segments(ft_header_segment_2, buffer, FT_SEGMENT_SIZE, zft_deblock_buf) >= 0; if (!header_1_ok) { TRACE(ft_t_warn, "Warning: " "update of first header segment failed"); } if (!header_2_ok) { TRACE(ft_t_warn, "Warning: " "update of second header segment failed"); } if (!header_1_ok && !header_2_ok) { TRACE_ABORT(-EIO, ft_t_err, "Error: " "update of both header segments failed."); } TRACE_EXIT 0; }
void ftape_calc_timeouts(unsigned int qic_std, unsigned int data_rate, unsigned int tape_len) { int speed; /* deci-ips ! */ int ff_speed; int length; TRACE_FUN(ft_t_any); /* tape transport speed * data rate: QIC-40 QIC-80 QIC-3010 QIC-3020 * * 250 Kbps 25 ips n/a n/a n/a * 500 Kbps 50 ips 34 ips 22.6 ips n/a * 1 Mbps n/a 68 ips 45.2 ips 22.6 ips * 2 Mbps n/a n/a n/a 45.2 ips * * fast tape transport speed is at least 68 ips. */ switch (qic_std) { case QIC_TAPE_QIC40: speed = (data_rate == 250) ? 250 : 500; break; case QIC_TAPE_QIC80: speed = (data_rate == 500) ? 340 : 680; break; case QIC_TAPE_QIC3010: speed = (data_rate == 500) ? 226 : 452; break; case QIC_TAPE_QIC3020: speed = (data_rate == 1000) ? 226 : 452; break; default: TRACE(ft_t_bug, "Unknown qic_std (bug) ?"); speed = 500; break; } if (ft_drive_type.speed == 0) { unsigned long t0; static int dt = 0; /* keep gcc from complaining */ static int first_time = 1; /* Measure the time it takes to wind to EOT and back to BOT. * If the tape length is known, calculate the rewind speed. * Else keep the time value for calculation of the rewind * speed later on, when the length _is_ known. * Ask for a report only when length and speed are both known. */ if (first_time) { ftape_seek_to_bot(); t0 = jiffies; ftape_seek_to_eot(); ftape_seek_to_bot(); dt = (int) (((jiffies - t0) * FT_USPT) / 1000); if (dt < 1) { dt = 1; /* prevent div by zero on failures */ } first_time = 0; TRACE(ft_t_info, "trying to determine seek timeout, got %d msec", dt); } if (tape_len != 0) { ft_drive_type.speed = (2 * 12 * tape_len * 1000) / dt; TRACE(ft_t_warn, "\n" KERN_INFO "==========================================\n" KERN_INFO "drive type: %s\n" KERN_INFO "delta time = %d ms, length = %d ft\n" KERN_INFO "has a maximum tape speed of %d ips\n" KERN_INFO "please report this to "THE_FTAPE_MAINTAINER"\n" KERN_INFO "==========================================", ft_drive_type.name, dt, tape_len, ft_drive_type.speed); } } /* Handle unknown length tapes as very long ones. We'll * determine the actual length from a header segment later. * This is normal for all modern (Wide,TR1/2/3) formats. */ if (tape_len <= 0) { TRACE(ft_t_noise, "Unknown tape length, using maximal timeouts"); length = QIC_TOP_TAPE_LEN; /* use worst case values */ } else { length = tape_len; /* use actual values */ } if (ft_drive_type.speed == 0) { ff_speed = speed; } else { ff_speed = ft_drive_type.speed; } /* time to go from bot to eot at normal speed (data rate): * time = (1+delta) * length (ft) * 12 (inch/ft) / speed (ips) * delta = 10 % for seek speed, 20 % for rewind speed. */ ftape_timeout.seek = (length * 132 * FT_SECOND) / speed; ftape_timeout.rewind = (length * 144 * FT_SECOND) / (10 * ff_speed); ftape_timeout.reset = 20 * FT_SECOND + ftape_timeout.rewind; TRACE(ft_t_noise, "timeouts for speed = %d, length = %d\n" KERN_INFO "seek timeout : %d sec\n" KERN_INFO "rewind timeout: %d sec\n" KERN_INFO "reset timeout : %d sec", speed, length, (ftape_timeout.seek + 500) / 1000, (ftape_timeout.rewind + 500) / 1000, (ftape_timeout.reset + 500) / 1000); TRACE_EXIT; }
/* IOCTL routine called by kernel-interface code */ int _ftape_ioctl(unsigned int command, void *arg) { TRACE_FUN(8, "ftape_ioctl"); int result = EINVAL; union { struct mtop mtop; struct mtget mtget; } krnl_arg; int arg_size = (command & IOCSIZE_MASK) >> IOCSIZE_SHIFT; /* This check will only catch arguments that are too large ! */ if ((command & IOC_INOUT) && arg_size > sizeof(krnl_arg)) { TRACEi(1, "bad argument size:", arg_size); TRACE_EXIT; return -EINVAL; } if (command & IOC_IN) { int error = verify_area(VERIFY_READ, arg, arg_size); if (error) { TRACE_EXIT; return error; } memcpy_fromfs(&krnl_arg.mtop, arg, arg_size); } TRACEx1(5, "called with ioctl command: 0x%08x", command); switch (command) { /* cpio compatibility * mtrasx and mtreset are mt extension by Hennus Bergman * mtseek and mttell are mt extension by eddy olk */ case MTIOCTOP: TRACEx1(5, "calling MTIOCTOP command: 0x%08x", krnl_arg.mtop.mt_op); switch (krnl_arg.mtop.mt_op) { case MTNOP: /* gnu mt calls MTNOP before MTIOCGET to set status */ result = 0; break; case MTRESET: result = ftape_reset_drive(); init_drive_needed = 1; if (result < 0 || ftape_offline) { break; } result = ftape_seek_to_bot(); ftape_reset_position(); break; case MTREW: case MTOFFL: if (ftape_offline) { result = -EIO; break; } ftape_flush_buffers(); ftape_update_header_segments(NULL, 1); result = ftape_seek_to_bot(); ftape_reset_position(); if (krnl_arg.mtop.mt_op == MTOFFL) { going_offline = 1; TRACE(4, "Putting tape drive offline"); } result = 0; break; case MTRETEN: if (ftape_offline) { result = -EIO; break; } result = ftape_seek_to_eot(); if (result >= 0) { result = ftape_seek_to_bot(); } ftape_reset_position(); break; case MTERASE: if (ftape_offline) { result = -EIO; break; } result = ftape_erase(); break; case MTEOM: if (ftape_offline) { result = -EIO; break; } result = ftape_seek_eom(); break; case MTFSFM: if (ftape_offline) { result = -EIO; break; } eof_mark = 1; /* position ready to extend */ case MTFSF: if (ftape_offline) { result = -EIO; break; } result = ftape_seek_eof(krnl_arg.mtop.mt_count); break; case MTBSFM: if (ftape_offline) { result = -EIO; break; } eof_mark = 1; /* position ready to extend */ case MTBSF: if (ftape_offline) { result = -EIO; break; } result = ftape_seek_eof(-krnl_arg.mtop.mt_count); break; case MTFSR: if (ftape_offline) { result = -EIO; break; } tracing = krnl_arg.mtop.mt_count; TRACEx1(2, "tracing set to %d", tracing); result = 0; break; case MTBSR: if (ftape_offline) { result = -EIO; break; } #if 0 result = ftape_fix(); #else result = 0; #endif break; case MTWEOF: if (ftape_offline) { result = -EIO; break; } result = ftape_weof(krnl_arg.mtop.mt_count, ftape_seg_pos, 1); if (result >= 0) { ftape_seg_pos += krnl_arg.mtop.mt_count - 1; } break; /* MTRASx and MTRESET are mt extension by Hennus Bergman */ case MTRAS1: case MTRAS2: case MTRAS3: case MTSEEK: case MTTELL: default: TRACEi(1, "MTIOCTOP sub-command not implemented:", krnl_arg.mtop.mt_op); result = -EIO; break; } break; case MTIOCGET: krnl_arg.mtget.mt_type = drive_type.vendor_id + 0x800000; krnl_arg.mtget.mt_resid = 0; /* not implemented */ krnl_arg.mtget.mt_dsreg = 0; /* status register */ krnl_arg.mtget.mt_gstat = /* device independent status */ ((ftape_offline) ? 0 : GMT_ONLINE(-1L)) | ((write_protected) ? GMT_WR_PROT(-1L) : 0) | ((no_tape) ? GMT_DR_OPEN(-1L) : 0); krnl_arg.mtget.mt_erreg = ftape_last_error; /* error register */ result = ftape_file_no(&krnl_arg.mtget.mt_fileno, &krnl_arg.mtget.mt_blkno); break; case MTIOCPOS: TRACE(5, "Mag tape ioctl command: MTIOCPOS"); TRACE(1, "MTIOCPOS command not implemented"); break; default: result = -EINVAL; break; } if (command & IOC_OUT) { int error = verify_area(VERIFY_WRITE, arg, arg_size); if (error) { TRACE_EXIT; return error; } memcpy_tofs(arg, &krnl_arg, arg_size); } TRACE_EXIT; return result; }
/* RELEASE routine called by kernel-interface code */ int _ftape_close(void) { TRACE_FUN(8, "_ftape_close"); int result = 0; int last_segment = 0; if (!ftape_offline) { result = ftape_flush_buffers(); last_segment = ftape_seg_pos - 1; if (!(ftape_unit & FTAPE_NO_REWIND)) { if (result >= 0) { result = ftape_update_header_segments(NULL, 1); if (result < 0) { TRACE(1, "error: update of header segments failed"); } } else { TRACE(1, "error: unable to update header segments"); } } ftape_abort_operation(); if (!(ftape_unit & FTAPE_NO_REWIND)) { if (!no_tape) { TRACE(5, "rewinding tape"); result = ftape_seek_to_bot(); } ftape_reset_position(); ftape_zap_read_buffers(); ftape_zap_write_buffers(); } } ftape_detach_drive(); fdc_uninit(); if (history.used) { TRACE(3, "== Non-fatal errors this run: =="); TRACE(3, "fdc isr statistics:"); TRACEi(3, " id_am_errors :", history.id_am_errors); TRACEi(3, " id_crc_errors :", history.id_crc_errors); TRACEi(3, " data_am_errors :", history.data_am_errors); TRACEi(3, " data_crc_errors :", history.data_crc_errors); TRACEi(3, " overrun_errors :", history.overrun_errors); TRACEi(3, " no_data_errors :", history.no_data_errors); TRACEi(3, " retries :", history.retries); if (history.used & 1) { TRACE(3, "ecc statistics:"); TRACEi(3, " crc_errors :", history.crc_errors); TRACEi(3, " crc_failures :", history.crc_failures); TRACEi(3, " ecc_failures :", history.ecc_failures); TRACEi(3, " sectors corrected:", history.corrected); } TRACEx2(3, "media defects : %d%s", history.defects, history.defects ? " !!!" : ""); TRACEi(3, "repositions :", history.rewinds); TRACEi(3, "last segment :", last_segment); } if (going_offline) { going_offline = 0; ftape_offline = 1; } TRACE_EXIT; return result; }
void ftape_calc_timeouts(void) { TRACE_FUN(8, "ftape_calc_timeouts"); int speed; /* deci-ips ! */ int length; /* tape transport speed * data rate: QIC-40 QIC-80 QIC-3010 QIC-3020 * * 250 Kbps 25 ips n/a n/a n/a * 500 Kbps 50 ips 34 ips 22.6 ips n/a * 1 Mbps n/a 68 ips 45.2 ips 22.6 ips * 2 Mbps n/a n/a n/a 45.2 ips * * fast tape transport speed is at least 68 ips. */ switch (qic_std) { case QIC_TAPE_QIC40: speed = (ftape_data_rate == 3) ? 250 : 500; break; case QIC_TAPE_QIC80: speed = (ftape_data_rate == 2) ? 340 : 680; break; case QIC_TAPE_QIC3010: speed = (ftape_data_rate == 2) ? 226 : 452; break; case QIC_TAPE_QIC3020: speed = (ftape_data_rate == 1) ? 226 : 452; break; default: TRACE(-1, "Unknown qic_std (bug) ?"); speed = 500; break; } if (tape_len <= 0) { /* Handle unknown length tapes as 1100 ft ones (worst case) */ TRACE(1, "Unknown tape length, using worst case timing values!"); length = 1100; } else { length = tape_len; } if (drive_type.speed == 0) { unsigned long t0; int dt; ftape_seek_to_bot(); t0 = jiffies; ftape_seek_to_eot(); ftape_seek_to_bot(); dt = (int) ((jiffies - t0) * MSPT); drive_type.speed = (2 * 12 * length * 1000) / dt; TRACE(-1, "=========================================="); TRACEx1(-1, "drive : %s", drive_type.name); TRACEx2(-1, "delta time = %d, length = %d", dt, length); TRACEx1(-1, "has max tape speed of %d ips", drive_type.speed); TRACE(-1, "please report this to <*****@*****.**>"); TRACE(-1, "=========================================="); } /* time to go from bot to eot at normal speed (data rate): * time = (1+delta) * length (ft) * 12 (inch/ft) / speed (ips) * delta = 10 % for seek speed, 20 % for rewind speed. */ timeout.seek = (length * 132 * SECOND) / speed; timeout.rewind = (length * 144 * SECOND) / (10 * drive_type.speed); timeout.reset = 20 * SECOND + timeout.rewind; TRACEx2(4, "speed = %d, length = %d", speed, length); TRACEx1(4, "seek timeout: %d sec", (timeout.seek + 500) / 1000); TRACEx1(4, "rewind timeout: %d sec", (timeout.rewind + 500) / 1000); TRACE_EXIT; }