/* 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; }
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; }
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; }