📄 ftape-io.c
字号:
qic117_cmds[*command].name); } else { TRACE(ft_t_noise, "... caused by unknown command %d", *command); } TRACE_EXIT 0;}int ftape_report_configuration(qic_model *model, unsigned int *rate, int *qic_std, int *tape_len){ int result; int config; int status; static const unsigned int qic_rates[ 4] = { 250, 2000, 500, 1000 }; TRACE_FUN(ft_t_any); result = ftape_report_operation(&config, QIC_REPORT_DRIVE_CONFIGURATION, 8); if (result < 0) { ft_last_status.status.drive_config = (__u8)0x00; *model = prehistoric; *rate = 500; *qic_std = QIC_TAPE_QIC40; *tape_len = 205; TRACE_EXIT 0; } else { ft_last_status.status.drive_config = (__u8)(config & 0xff); } *rate = qic_rates[(config & QIC_CONFIG_RATE_MASK) >> QIC_CONFIG_RATE_SHIFT]; result = ftape_report_operation(&status, QIC_REPORT_TAPE_STATUS, 8); if (result < 0) { ft_last_status.status.tape_status = (__u8)0x00; /* pre- QIC117 rev C spec. drive, QIC_CONFIG_80 bit is valid. */ *qic_std = (config & QIC_CONFIG_80) ? QIC_TAPE_QIC80 : QIC_TAPE_QIC40; /* ?? how's about 425ft tapes? */ *tape_len = (config & QIC_CONFIG_LONG) ? 307 : 0; *model = pre_qic117c; result = 0; } else { ft_last_status.status.tape_status = (__u8)(status & 0xff); *model = post_qic117b; TRACE(ft_t_any, "report tape status result = %02x", status); /* post- QIC117 rev C spec. drive, QIC_CONFIG_80 bit is * invalid. */ switch (status & QIC_TAPE_STD_MASK) { case QIC_TAPE_QIC40: case QIC_TAPE_QIC80: case QIC_TAPE_QIC3020: case QIC_TAPE_QIC3010: *qic_std = status & QIC_TAPE_STD_MASK; break; default: *qic_std = -1; break; } switch (status & QIC_TAPE_LEN_MASK) { case QIC_TAPE_205FT: /* 205 or 425+ ft 550 Oe tape */ *tape_len = 0; break; case QIC_TAPE_307FT: /* 307.5 ft 550 Oe Extended Length (XL) tape */ *tape_len = 307; break; case QIC_TAPE_VARIABLE: /* Variable length 550 Oe tape */ *tape_len = 0; break; case QIC_TAPE_1100FT: /* 1100 ft 550 Oe tape */ *tape_len = 1100; break; case QIC_TAPE_FLEX: /* Variable length 900 Oe tape */ *tape_len = 0; break; default: *tape_len = -1; break; } if (*qic_std == -1 || *tape_len == -1) { TRACE(ft_t_any, "post qic-117b spec drive with unknown tape"); } result = *tape_len == -1 ? -EIO : 0; if (status & QIC_TAPE_WIDE) { switch (*qic_std) { case QIC_TAPE_QIC80: TRACE(ft_t_info, "TR-1 tape detected"); break; case QIC_TAPE_QIC3010: TRACE(ft_t_info, "TR-2 tape detected"); break; case QIC_TAPE_QIC3020: TRACE(ft_t_info, "TR-3 tape detected"); break; default: TRACE(ft_t_warn, "Unknown Travan tape type detected"); break; } } } TRACE_EXIT (result < 0) ? -EIO : 0;}static int ftape_report_rom_version(int *version){ if (ftape_report_operation(version, QIC_REPORT_ROM_VERSION, 8) < 0) { return -EIO; } else { return 0; }}void ftape_report_vendor_id(unsigned int *id){ int result; TRACE_FUN(ft_t_any); /* We'll try to get a vendor id from the drive. First * according to the QIC-117 spec, a 16-bit id is requested. * If that fails we'll try an 8-bit version, otherwise we'll * try an undocumented query. */ result = ftape_report_operation((int *) id, QIC_REPORT_VENDOR_ID, 16); if (result < 0) { result = ftape_report_operation((int *) id, QIC_REPORT_VENDOR_ID, 8); if (result < 0) { /* The following is an undocumented call found * in the CMS code. */ result = ftape_report_operation((int *) id, 24, 8); if (result < 0) { *id = UNKNOWN_VENDOR; } else { TRACE(ft_t_noise, "got old 8 bit id: %04x", *id); *id |= 0x20000; } } else { TRACE(ft_t_noise, "got 8 bit id: %04x", *id); *id |= 0x10000; } } else { TRACE(ft_t_noise, "got 16 bit id: %04x", *id); } if (*id == 0x0047) { int version; int sign; if (ftape_report_rom_version(&version) < 0) { TRACE(ft_t_bug, "report rom version failed"); TRACE_EXIT; } TRACE(ft_t_noise, "CMS rom version: %d", version); ftape_command(QIC_ENTER_DIAGNOSTIC_1); ftape_command(QIC_ENTER_DIAGNOSTIC_1); diagnostic_mode = 1; if (ftape_report_operation(&sign, 9, 8) < 0) { unsigned int error; qic117_cmd_t command; ftape_report_error(&error, &command, 1); ftape_command(QIC_ENTER_PRIMARY_MODE); diagnostic_mode = 0; TRACE_EXIT; /* failure ! */ } else { TRACE(ft_t_noise, "CMS signature: %02x", sign); } if (sign == 0xa5) { result = ftape_report_operation(&sign, 37, 8); if (result < 0) { if (version >= 63) { *id = 0x8880; TRACE(ft_t_noise, "This is an Iomega drive !"); } else { *id = 0x0047; TRACE(ft_t_noise, "This is a real CMS drive !"); } } else { *id = 0x0047; TRACE(ft_t_noise, "CMS status: %d", sign); } } else { *id = UNKNOWN_VENDOR; } ftape_command(QIC_ENTER_PRIMARY_MODE); diagnostic_mode = 0; } TRACE_EXIT;}static int qic_rate_code(unsigned int rate){ switch (rate) { case 250: return QIC_CONFIG_RATE_250; case 500: return QIC_CONFIG_RATE_500; case 1000: return QIC_CONFIG_RATE_1000; case 2000: return QIC_CONFIG_RATE_2000; default: return QIC_CONFIG_RATE_500; }}static int ftape_set_rate_test(unsigned int *max_rate){ unsigned int error; qic117_cmd_t command; int status; int supported = 0; TRACE_FUN(ft_t_any); /* Check if the drive does support the select rate command * by testing all different settings. If any one is accepted * we assume the command is supported, else not. */ for (*max_rate = 2000; *max_rate >= 250; *max_rate /= 2) { if (ftape_command(QIC_SELECT_RATE) < 0) { continue; } if (ftape_parameter_wait(qic_rate_code(*max_rate), 1 * FT_SECOND, &status) < 0) { continue; } if (status & QIC_STATUS_ERROR) { ftape_report_error(&error, &command, 0); continue; } supported = 1; /* did accept a request */ break; } TRACE(ft_t_noise, "Select Rate command is%s supported", supported ? "" : " not"); TRACE_EXIT supported;}int ftape_set_data_rate(unsigned int new_rate /* Kbps */, unsigned int qic_std){ int status; int result = 0; unsigned int data_rate = new_rate; static int supported; int rate_changed = 0; qic_model dummy_model; unsigned int dummy_qic_std, dummy_tape_len; TRACE_FUN(ft_t_any); if (ft_drive_max_rate == 0) { /* first time */ supported = ftape_set_rate_test(&ft_drive_max_rate); } if (supported) { ftape_command(QIC_SELECT_RATE); result = ftape_parameter_wait(qic_rate_code(new_rate), 1 * FT_SECOND, &status); if (result >= 0 && !(status & QIC_STATUS_ERROR)) { rate_changed = 1; } } TRACE_CATCH(result = ftape_report_configuration(&dummy_model, &data_rate, &dummy_qic_std, &dummy_tape_len),); if (data_rate != new_rate) { if (!supported) { TRACE(ft_t_warn, "Rate change not supported!"); } else if (rate_changed) { TRACE(ft_t_warn, "Requested: %d, got %d", new_rate, data_rate); } else { TRACE(ft_t_warn, "Rate change failed!"); } result = -EINVAL; } /* * Set data rate and write precompensation as specified: * * | QIC-40/80 | QIC-3010/3020 * rate | precomp | precomp * ----------+-------------+-------------- * 250 Kbps. | 250 ns. | 0 ns. * 500 Kbps. | 125 ns. | 0 ns. * 1 Mbps. | 42 ns. | 0 ns. * 2 Mbps | N/A | 0 ns. */ if ((qic_std == QIC_TAPE_QIC40 && data_rate > 500) || (qic_std == QIC_TAPE_QIC80 && data_rate > 1000)) { TRACE_ABORT(-EINVAL, ft_t_warn, "Datarate too high for QIC-mode"); } TRACE_CATCH(fdc_set_data_rate(data_rate),_res = -EINVAL); ft_data_rate = data_rate; if (qic_std == QIC_TAPE_QIC40 || qic_std == QIC_TAPE_QIC80) { switch (data_rate) { case 250: fdc_set_write_precomp(250); break; default: case 500: fdc_set_write_precomp(125); break; case 1000: fdc_set_write_precomp(42); break; } } else { fdc_set_write_precomp(0); } TRACE_EXIT result;}/* The next two functions are used to cope with excessive overrun errors */int ftape_increase_threshold(void){ TRACE_FUN(ft_t_flow); if (fdc.type < i82077 || ft_fdc_threshold >= 12) { TRACE_ABORT(-EIO, ft_t_err, "cannot increase fifo threshold"); } if (fdc_fifo_threshold(++ft_fdc_threshold, NULL, NULL, NULL) < 0) { TRACE(ft_t_err, "cannot increase fifo threshold"); ft_fdc_threshold --; fdc_reset(); } TRACE(ft_t_info, "New FIFO threshold: %d", ft_fdc_threshold); TRACE_EXIT 0;}int ftape_half_data_rate(void){ if (ft_data_rate < 500) { return -1; } if (ftape_set_data_rate(ft_data_rate / 2, ft_qic_std) < 0) { return -EIO; } ftape_calc_timeouts(ft_qic_std, ft_data_rate, ftape_tape_len); return 0;}/* Seek the head to the specified track. */int ftape_seek_head_to_track(unsigned int track){ int status; TRACE_FUN(ft_t_any); ft_location.track = -1; /* remains set in case of error */ if (track >= ft_tracks_per_tape) { TRACE_ABORT(-EINVAL, ft_t_bug, "track out of bounds"); } TRACE(ft_t_flow, "seeking track %d", track); TRACE_CATCH(ftape_command(QIC_SEEK_HEAD_TO_TRACK),); TRACE_CATCH(ftape_parameter_wait(track, ftape_timeout.head_seek, &status),); ft_location.track = track; ftape_might_be_off_track = 0; TRACE_EXIT 0;}int ftape_wakeup_drive(wake_up_types method){ int status; int motor_on = 0; TRACE_FUN(ft_t_any); switch (method) { case wake_up_colorado: TRACE_CATCH(ftape_command(QIC_PHANTOM_SELECT),); TRACE_CATCH(ftape_parameter(0 /* ft_drive_sel ?? */),); break; case wake_up_mountain: TRACE_CATCH(ftape_command(QIC_SOFT_SELECT),); ftape_sleep(FT_MILLISECOND); /* NEEDED */ TRACE_CATCH(ftape_parameter(18),); break; case wake_up_insight: ftape_sleep(100 * FT_MILLISECOND); motor_on = 1; fdc_motor(motor_on); /* enable is done by motor-on */ case no_wake_up: break; default: TRACE_EXIT -ENODEV; /* unknown wakeup method */ break; } /* If wakeup succeeded we shouldn't get an error here.. */ TRACE_CATCH(ftape_report_raw_drive_status(&status), if (motor_on) { fdc_motor(0); }); TRACE_EXIT 0;}int ftape_put_drive_to_sleep(wake_up_types method){ TRACE_FUN(ft_t_any); switch (method) { case wake_up_colorado: TRACE_CATCH(ftape_command(QIC_PHANTOM_DESELECT),); break; case wake_up_mountain: TRACE_CATCH(ftape_command(QIC_SOFT_DESELECT),); break; case wake_up_insight: fdc_motor(0); /* enable is done by motor-on */ case no_wake_up: /* no wakeup / no sleep ! */ break; default: TRACE_EXIT -ENODEV; /* unknown wakeup method */ } TRACE_EXIT 0;}int ftape_reset_drive(void){ int result = 0; int status; unsigned int err_code; qic117_cmd_t err_command; int i; TRACE_FUN(ft_t_any); /* We want to re-establish contact with our drive. Fire a * number of reset commands (single step pulses) and pray for * success. */ for (i = 0; i < 2; ++i) { TRACE(ft_t_flow, "Resetting fdc"); fdc_reset(); ftape_sleep(10 * FT_MILLISECOND); TRACE(ft_t_flow, "Reset command to drive"); result = ftape_command(QIC_RESET); if (result == 0) { ftape_sleep(1 * FT_SECOND); /* drive not * accessible * during 1 second */ TRACE(ft_t_flow, "Re-selecting drive"); /* Strange, the QIC-117 specs don't mention * this but the drive gets deselected after a * soft reset ! So we need to enable it * again. */ if (ftape_wakeup_drive(ft_drive_type.wake_up) < 0) { TRACE(ft_t_err, "Wakeup failed !"); } TRACE(ft_t_flow, "Waiting until drive gets ready"); result= ftape_ready_wait(ftape_timeout.reset, &status); if (result == 0 && (status & QIC_STATUS_ERROR)) { result = ftape_report_error(&err_code, &err_command, 1); if (result == 0 && err_code == 27) { /* Okay, drive saw reset * command and responded as it * should */ break; } else { result = -EIO; } } else { result = -EIO; } } FT_SIGNAL_EXIT(_DONT_BLOCK); } if (result != 0) { TRACE(ft_t_err, "General failure to reset tape drive"); } else { /* Restore correct settings: keep original rate */ ftape_set_data_rate(ft_data_rate, ft_qic_std); } ftape_init_drive_needed = 1; TRACE_EXIT result;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -