📄 ftape-ctl.c
字号:
/* * Copyright (C) 1993-1995 Bas Laarhoven. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * * This file contains the non-read/write ftape functions * for the QIC-40/80 floppy-tape driver for Linux. */#include <linux/errno.h>#include <linux/mm.h>#include <linux/ftape.h>#include <asm/segment.h>#include "tracing.h"#include "ftape-eof.h"#include "ftape-io.h"#include "ftape-ctl.h"#include "ftape-write.h"#include "ftape-read.h"#include "ftape-rw.h"#include "qic117.h"#include "ftape-bsm.h"/* Global vars. */int segments_per_track = 102;int segments_per_head = 1020;int segments_per_cylinder = 4;int tracks_per_tape = 20;int ftape_failure = 1;int ftape_seg_pos = 0;int first_data_segment = -1;int ftape_state = idle; /* use buffer_state_enum */history_record history;int write_protected;int ftape_offline = 0;int no_tape = 1;int formatted = 0;int ftape_data_rate = 0;int going_offline = 0;int read_only = 0;/* Local vars. */static int ftape_last_error = 0;static const vendor_struct vendors[] = QIC117_VENDORS;static const wakeup_method methods[] = WAKEUP_METHODS;static int init_drive_needed = 1;static int ftape_not_operational(int status){ /* return true if status indicates tape can not be used. */ return ((status ^ QIC_STATUS_CARTRIDGE_PRESENT) & (QIC_STATUS_ERROR | QIC_STATUS_CARTRIDGE_PRESENT | QIC_STATUS_NEW_CARTRIDGE));}int ftape_seek_to_eot(void){ TRACE_FUN(8, "ftape_seek_to_eot"); int result; int status; result = ftape_ready_wait(timeout.pause, &status); while ((status & QIC_STATUS_AT_EOT) == 0) { if (result < 0) { TRACE(1, "failed"); TRACE_EXIT; return result; } if (ftape_not_operational(status)) { TRACE_EXIT; return -EIO; } result = ftape_command_wait(QIC_PHYSICAL_FORWARD, timeout.rewind, &status); } TRACE_EXIT; return 0;}int ftape_seek_to_bot(void){ TRACE_FUN(8, "ftape_seek_to_bot"); int result; int status; result = ftape_ready_wait(timeout.pause, &status); while ((status & QIC_STATUS_AT_BOT) == 0) { if (result < 0) { TRACE(1, "failed"); TRACE_EXIT; return result; } if (ftape_not_operational(status)) { TRACE_EXIT; return -EIO; } result = ftape_command_wait(QIC_PHYSICAL_REVERSE, timeout.rewind, &status); } TRACE_EXIT; return 0;}void ftape_reset_position(void){ ftape_seg_pos = first_data_segment; reset_eof_list();}int ftape_new_cartridge(void){ location.track = -1; /* force seek on first access */ first_data_segment = -1; /* unknown */ ftape_zap_read_buffers(); ftape_zap_write_buffers(); ftape_reset_position(); return 0;}int ftape_abort_operation(void){ TRACE_FUN(5, "ftape_abort_operation"); int result = 0; int i; int status; if (runner_status == running) { TRACE(5, "aborting runner, waiting"); runner_status = do_abort; /* set timeout so that the tape will run to logical EOT * if we missed the last sector and there are no queue pulses. */ result = ftape_dumb_stop(); if (result == 0) { runner_status = idle; } } if (runner_status != idle) { if (runner_status == do_abort) { TRACE(5, "forcing runner abort"); } TRACE(5, "stopping tape"); result = ftape_command_wait(QIC_STOP_TAPE, timeout.stop, &status); location.known = 0; runner_status = idle; } for (i = 0; i < NR_BUFFERS; ++i) { buffer[i].status = waiting; } head = tail = 0; TRACE_EXIT; return result;}int lookup_vendor_id(int vendor_id){ int i = 0; while (vendors[i].vendor_id != vendor_id) { if (++i >= NR_ITEMS(vendors)) { return -1; } } return i;}void ftape_detach_drive(void){ TRACE_FUN(8, "ftape_detach_drive"); TRACE(5, "disabling tape drive and fdc"); ftape_put_drive_to_sleep(drive_type); fdc_catch_stray_interrupts(1); /* one always comes */ fdc_disable(); fdc_release_irq_and_dma(); TRACE_EXIT;}static void clear_history(void){ history.used = 0; history.id_am_errors = history.id_crc_errors = history.data_am_errors = history.data_crc_errors = history.overrun_errors = history.no_data_errors = history.retries = history.crc_errors = history.crc_failures = history.ecc_failures = history.corrected = history.defects = history.rewinds = 0;}int ftape_activate_drive(vendor_struct * drive_type){ TRACE_FUN(5, "ftape_activate_drive"); int result = 0; /* If we already know the drive type, wake it up. * Else try to find out what kind of drive is attached. */ if (drive_type->wake_up != unknown_wake_up) { TRACE(5, "enabling tape drive and fdc"); result = ftape_wakeup_drive(drive_type->wake_up); if (result < 0) { TRACE(1, "known wakeup method failed"); } } else { int old_tracing = tracing; wake_up_types method; /* Try to awaken the drive using all known methods. * Lower tracing for a while. */ if (tracing <= 4) { tracing = 0; } for (method = no_wake_up; method < NR_ITEMS(methods); ++method) { drive_type->wake_up = method;#if 0 /* Test setup for dual drive configuration in dodo. * /dev/rft2 uses mountain wakeup only -> Archive QIC-80 * /dev/rft3 uses colorado wakeup only -> Jumbo QIC-40 * Other systems will use the normal scheme. */ if ((FTAPE_UNIT < 2) || (FTAPE_UNIT == 2 && method == wake_up_mountain) || (FTAPE_UNIT == 3 && method == wake_up_colorado)) { result = ftape_wakeup_drive(drive_type->wake_up); } else { result = -EIO; }#else result = ftape_wakeup_drive(drive_type->wake_up);#endif if (result >= 0) { int tracing = old_tracing; /* fool TRACE */ TRACEx1(2, "drive wakeup method: %s", methods[drive_type->wake_up].name); break; } } tracing = old_tracing; if (method >= NR_ITEMS(methods)) { /* no response at all, cannot open this drive */ drive_type->wake_up = unknown_wake_up; TRACE(1, "no tape drive found !"); tracing = old_tracing; result = -ENODEV; } } TRACE_EXIT; return result;}int ftape_get_drive_status(int *new_tape, int *no_tape, int *wp_tape){ TRACE_FUN(5, "ftape_get_drive_status"); int result; int status; *no_tape = *wp_tape = 0; /* Tape drive is activated now. * First clear error status if present. */ do { result = ftape_ready_wait(timeout.reset, &status); if (result < 0) { if (result == -ETIME) { TRACE(1, "ftape_ready_wait timeout"); } else if (result == -EINTR) { TRACE(1, "ftape_ready_wait aborted"); } else { TRACE(1, "ftape_ready_wait failed"); } result = -EIO; break; } /* Clear error condition (drive is ready !) */ if (status & QIC_STATUS_ERROR) { int error; int command; TRACE(1, "error status set"); result = ftape_report_error(&error, &command, 1); if (result < 0) { TRACEi(1, "report_error_code failed:", result); ftape_reset_drive(); /* hope it's working next time */ init_drive_needed = 1; result = -EIO; break; } else if (error != 0) { TRACEi(4, "error code :", error); TRACEi(4, "error command:", command); } } if (status & QIC_STATUS_NEW_CARTRIDGE) { int error; int command; int old_tracing = tracing; /* Undocumented feature: Must clear (not present!) error * here or we'll fail later. */ tracing = 0; ftape_report_error(&error, &command, 1); tracing = old_tracing; TRACE(3, "status: new cartridge"); *new_tape = 1; } } while (status & QIC_STATUS_ERROR); *no_tape = !(status & QIC_STATUS_CARTRIDGE_PRESENT); *wp_tape = (status & QIC_STATUS_WRITE_PROTECT); if (*no_tape) { TRACE(1, "no cartridge present"); } else { if (*wp_tape) { TRACE(2, "Write protected cartridge"); } } TRACE_EXIT; return result;}void ftape_log_vendor_id(void){ TRACE_FUN(5, "ftape_log_vendor_id"); int vendor_index; ftape_report_vendor_id(&drive_type.vendor_id); vendor_index = lookup_vendor_id(drive_type.vendor_id); if (drive_type.vendor_id == UNKNOWN_VENDOR && drive_type.wake_up == wake_up_colorado) { vendor_index = 0; drive_type.vendor_id = 0; /* hack to get rid of all this mail */ } if (vendor_index < 0) { /* Unknown vendor id, first time opening device. * The drive_type remains set to type found at wakeup time, this * will probably keep the driver operating for this new vendor. */ TRACE(-1, "============ unknown vendor id ==========="); TRACE(-1, "A new, yet unsupported tape drive is found"); TRACE(-1, "Please report the following values:"); TRACEx1(-1, " Vendor id : 0x%04x", drive_type.vendor_id); TRACEx1(-1, " Wakeup method : %s", methods[drive_type.wake_up].name); TRACE(-1, "And a description of your tape drive to:"); TRACE(-1, "Claus Heine <claus@momo.math.rwth-aachen.de>"); TRACE(-1, "=========================================="); drive_type.speed = 500; /* deci-ips: very safe value */ } else { drive_type.name = vendors[vendor_index].name; drive_type.speed = vendors[vendor_index].speed; TRACEx1(3, "tape drive type: %s", drive_type.name); /* scan all methods for this vendor_id in table */ while (drive_type.wake_up != vendors[vendor_index].wake_up) { if (vendor_index < NR_ITEMS(vendors) - 1 && vendors[vendor_index + 1].vendor_id == drive_type.vendor_id) { ++vendor_index; } else { break; } } if (drive_type.wake_up != vendors[vendor_index].wake_up) { TRACE(-1, "=========================================="); TRACE(-1, "wakeup type mismatch:"); TRACEx2(-1, "found: %s, expected: %s", methods[drive_type.wake_up].name, methods[vendors[vendor_index].wake_up].name); TRACE(-1, "please report this to <claus@momo.math.rwth-aachen.de>"); TRACE(-1, "=========================================="); } } 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 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -