2 * Copyright (C) 1993-1996 Bas Laarhoven,
3 * (C) 1996 Kai Harrekilde-Petersen,
4 * (C) 1997 Claus-Justus Heine.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-io.c,v $
23 * $Date: 1997/11/11 14:02:36 $
25 * This file contains the general control functions for the
26 * QIC-40/80/3010/3020 floppy-tape driver "ftape" for Linux.
29 #include <linux/errno.h>
30 #include <linux/sched.h>
32 #include <asm/system.h>
33 #include <linux/ioctl.h>
34 #include <linux/mtio.h>
36 #include <linux/ftape.h>
37 #include <linux/qic117.h>
38 #include "../lowlevel/ftape-tracing.h"
39 #include "../lowlevel/fdc-io.h"
40 #include "../lowlevel/ftape-io.h"
41 #include "../lowlevel/ftape-ctl.h"
42 #include "../lowlevel/ftape-rw.h"
43 #include "../lowlevel/ftape-write.h"
44 #include "../lowlevel/ftape-read.h"
45 #include "../lowlevel/ftape-init.h"
46 #include "../lowlevel/ftape-calibr.h"
50 /* NOTE: sectors start numbering at 1, all others at 0 ! */
51 ft_timeout_table ftape_timeout;
52 unsigned int ftape_tape_len;
53 volatile qic117_cmd_t ftape_current_command;
54 const struct qic117_command_table qic117_cmds[] = QIC117_COMMANDS;
55 int ftape_might_be_off_track;
59 static int diagnostic_mode;
60 static unsigned int ftape_udelay_count;
61 static unsigned int ftape_udelay_time;
63 void ftape_udelay(unsigned int usecs)
65 volatile int count = (ftape_udelay_count * usecs +
66 ftape_udelay_count - 1) / ftape_udelay_time;
70 for (i = 0; i < 20; ++i);
74 void ftape_udelay_calibrate(void)
76 ftape_calibrate("ftape_udelay",
77 ftape_udelay, &ftape_udelay_count, &ftape_udelay_time);
80 /* Delay (msec) routine.
82 void ftape_sleep(unsigned int time)
86 time *= 1000; /* msecs -> usecs */
88 /* Time too small for scheduler, do a busy wait ! */
93 unsigned int ticks = (time + FT_USPT - 1) / FT_USPT;
95 TRACE(ft_t_any, "%d msec, %d ticks", time/1000, ticks);
99 set_current_state(TASK_INTERRUPTIBLE);
101 /* Mmm. Isn't current->blocked == 0xffffffff ?
103 if (signal_pending(current)) {
105 "awoken by non-blocked signal :-(");
106 break; /* exit on signal */
108 while (current->state != TASK_RUNNING) {
109 timeout = schedule_timeout(timeout);
112 restore_flags(flags);
117 /* send a command or parameter to the drive
118 * Generates # of step pulses.
120 static inline int ft_send_to_drive(int arg)
122 /* Always wait for a command_timeout period to separate
123 * individuals commands and/or parameters.
125 ftape_sleep(3 * FT_MILLISECOND);
126 /* Keep cylinder nr within range, step towards home if possible.
128 if (ftape_current_cylinder >= arg) {
129 return fdc_seek(ftape_current_cylinder - arg);
131 return fdc_seek(ftape_current_cylinder + arg);
135 /* forward */ int ftape_report_raw_drive_status(int *status);
137 static int ft_check_cmd_restrictions(qic117_cmd_t command)
142 TRACE(ft_t_flow, "%s", qic117_cmds[command].name);
143 /* A new motion command during an uninterruptible (motion)
144 * command requires a ready status before the new command can
145 * be issued. Otherwise a new motion command needs to be
146 * checked against required status.
148 if (qic117_cmds[command].cmd_type == motion &&
149 qic117_cmds[ftape_current_command].non_intr) {
150 ftape_report_raw_drive_status(&status);
151 if ((status & QIC_STATUS_READY) == 0) {
153 "motion cmd (%d) during non-intr cmd (%d)",
154 command, ftape_current_command);
155 TRACE(ft_t_noise, "waiting until drive gets ready");
156 ftape_ready_wait(ftape_timeout.seek,
160 if (qic117_cmds[command].mask != 0) {
162 /* Some commands do require a certain status:
164 if (status == -1) { /* not yet set */
165 ftape_report_raw_drive_status(&status);
167 difference = ((status ^ qic117_cmds[command].state) &
168 qic117_cmds[command].mask);
169 /* Wait until the drive gets
170 * ready. This may last forever if
171 * the drive never gets ready...
173 while ((difference & QIC_STATUS_READY) != 0) {
174 TRACE(ft_t_noise, "command %d issued while not ready",
176 TRACE(ft_t_noise, "waiting until drive gets ready");
177 if (ftape_ready_wait(ftape_timeout.seek,
178 &status) == -EINTR) {
179 /* Bail out on signal !
181 TRACE_ABORT(-EINTR, ft_t_warn,
182 "interrupted by non-blockable signal");
184 difference = ((status ^ qic117_cmds[command].state) &
185 qic117_cmds[command].mask);
187 while ((difference & QIC_STATUS_ERROR) != 0) {
192 "command %d issued while error pending",
194 TRACE(ft_t_noise, "clearing error status");
195 ftape_report_error(&err, &cmd, 1);
196 ftape_report_raw_drive_status(&status);
197 difference = ((status ^ qic117_cmds[command].state) &
198 qic117_cmds[command].mask);
199 if ((difference & QIC_STATUS_ERROR) != 0) {
200 /* Bail out on fatal signal !
202 FT_SIGNAL_EXIT(_NEVER_BLOCK);
206 /* Any remaining difference can't be solved
209 if (difference & (QIC_STATUS_CARTRIDGE_PRESENT |
210 QIC_STATUS_NEW_CARTRIDGE |
211 QIC_STATUS_REFERENCED)) {
213 "Fatal: tape removed or reinserted !");
216 TRACE(ft_t_err, "wrong state: 0x%02x should be: 0x%02x",
217 status & qic117_cmds[command].mask,
218 qic117_cmds[command].state);
222 if (~status & QIC_STATUS_READY & qic117_cmds[command].mask) {
223 TRACE_ABORT(-EBUSY, ft_t_err, "Bad: still busy!");
229 /* Issue a tape command:
231 int ftape_command(qic117_cmd_t command)
237 if ((unsigned int)command > NR_ITEMS(qic117_cmds)) {
238 /* This is a bug we'll want to know about too.
240 TRACE_ABORT(-EIO, ft_t_bug, "bug - bad command: %d", command);
242 if (++level > 5) { /* This is a bug we'll want to know about. */
244 TRACE_ABORT(-EIO, ft_t_bug, "bug - recursion for command: %d",
247 /* disable logging and restriction check for some commands,
248 * check all other commands that have a prescribed starting
251 if (diagnostic_mode) {
252 TRACE(ft_t_flow, "diagnostic command %d", command);
253 } else if (command == QIC_REPORT_DRIVE_STATUS ||
254 command == QIC_REPORT_NEXT_BIT) {
255 TRACE(ft_t_any, "%s", qic117_cmds[command].name);
257 TRACE_CATCH(ft_check_cmd_restrictions(command), --level);
259 /* Now all conditions are met or result was < 0.
261 result = ft_send_to_drive((unsigned int)command);
262 if (qic117_cmds[command].cmd_type == motion &&
263 command != QIC_LOGICAL_FORWARD && command != QIC_STOP_TAPE) {
264 ft_location.known = 0;
266 ftape_current_command = command;
271 /* Send a tape command parameter:
272 * Generates command # of step pulses.
273 * Skips tape-status call !
275 int ftape_parameter(unsigned int parameter)
279 TRACE(ft_t_flow, "called with parameter = %d", parameter);
280 TRACE_EXIT ft_send_to_drive(parameter + 2);
283 /* Wait for the drive to get ready.
284 * timeout time in milli-seconds
285 * Returned status is valid if result != -EIO
287 * Should we allow to be killed by SIGINT? (^C)
288 * Would be nice at least for large timeouts.
290 int ftape_ready_wait(unsigned int timeout, int *status)
293 unsigned int poll_delay;
297 /* the following ** REALLY ** reduces the system load when
298 * e.g. one simply rewinds or retensions. The tape is slow
299 * anyway. It is really not necessary to detect error
300 * conditions with 1/10 seconds granularity
302 * On my AMD 133MHZ 486: 100 ms: 23% system load
306 if (timeout <= FT_SECOND) {
307 poll_delay = 100 * FT_MILLISECOND;
308 signal_retries = 20; /* two seconds */
309 } else if (timeout < 20 * FT_SECOND) {
310 TRACE(ft_t_flow, "setting poll delay to 1 second");
311 poll_delay = FT_SECOND;
312 signal_retries = 2; /* two seconds */
314 TRACE(ft_t_flow, "setting poll delay to 5 seconds");
315 poll_delay = 5 * FT_SECOND;
316 signal_retries = 1; /* five seconds */
320 TRACE_CATCH(ftape_report_raw_drive_status(status),);
321 if (*status & QIC_STATUS_READY) {
324 if (!signal_retries--) {
325 FT_SIGNAL_EXIT(_NEVER_BLOCK);
327 if ((int)timeout >= 0) {
328 /* this will fail when jiffies wraps around about
329 * once every year :-)
331 timeout -= ((jiffies - t0) * FT_SECOND) / HZ;
333 TRACE_ABORT(-ETIME, ft_t_err, "timeout");
335 ftape_sleep(poll_delay);
336 timeout -= poll_delay;
338 ftape_sleep(poll_delay);
344 /* Issue command and wait up to timeout milli seconds for drive ready
346 int ftape_command_wait(qic117_cmd_t command, unsigned int timeout, int *status)
350 /* Drive should be ready, issue command
352 result = ftape_command(command);
354 result = ftape_ready_wait(timeout, status);
359 int ftape_parameter_wait(unsigned int parm, unsigned int timeout, int *status)
363 /* Drive should be ready, issue command
365 result = ftape_parameter(parm);
367 result = ftape_ready_wait(timeout, status);
372 /*--------------------------------------------------------------------------
376 /* Query the drive about its status. The command is sent and
377 result_length bits of status are returned (2 extra bits are read
378 for start and stop). */
380 int ftape_report_operation(int *status,
381 qic117_cmd_t command,
389 TRACE_CATCH(ftape_command(command),);
390 t0 = ftape_timestamp();
394 ftape_sleep(3 * FT_MILLISECOND); /* see remark below */
395 TRACE_CATCH(fdc_sense_drive_status(&st3),);
396 dt = ftape_timediff(t0, ftape_timestamp());
397 /* Ack should be asserted within Ttimout + Tack = 6 msec.
398 * Looks like some drives fail to do this so extend this
399 * period to 300 msec.
401 } while (!(st3 & ST3_TRACK_0) && dt < 300000);
402 if (!(st3 & ST3_TRACK_0)) {
404 "No acknowledge after %u msec. (%i iter)", dt / 1000, i);
405 TRACE_ABORT(-EIO, ft_t_err, "timeout on Acknowledge");
407 /* dt may be larger than expected because of other tasks
408 * scheduled while we were sleeping.
410 if (i > 1 && dt > 6000) {
411 TRACE(ft_t_err, "Acknowledge after %u msec. (%i iter)",
415 for (i = 0; i < result_length + 1; i++) {
416 TRACE_CATCH(ftape_command(QIC_REPORT_NEXT_BIT),);
417 TRACE_CATCH(fdc_sense_drive_status(&st3),);
418 if (i < result_length) {
419 *status |= ((st3 & ST3_TRACK_0) ? 1 : 0) << i;
420 } else if ((st3 & ST3_TRACK_0) == 0) {
421 TRACE_ABORT(-EIO, ft_t_err, "missing status stop bit");
424 /* this command will put track zero and index back into normal state */
425 (void)ftape_command(QIC_REPORT_NEXT_BIT);
429 /* Report the current drive status. */
431 int ftape_report_raw_drive_status(int *status)
438 result = ftape_report_operation(status,
439 QIC_REPORT_DRIVE_STATUS, 8);
440 } while (result < 0 && ++count <= 3);
442 TRACE_ABORT(-EIO, ft_t_err,
443 "report_operation failed after %d trials", count);
445 if ((*status & 0xff) == 0xff) {
446 TRACE_ABORT(-EIO, ft_t_err,
447 "impossible drive status 0xff");
449 if (*status & QIC_STATUS_READY) {
450 ftape_current_command = QIC_NO_COMMAND; /* completed */
452 ft_last_status.status.drive_status = (__u8)(*status & 0xff);
456 int ftape_report_drive_status(int *status)
460 TRACE_CATCH(ftape_report_raw_drive_status(status),);
461 if (*status & QIC_STATUS_NEW_CARTRIDGE ||
462 !(*status & QIC_STATUS_CARTRIDGE_PRESENT)) {
463 ft_failure = 1; /* will inhibit further operations */
466 if (*status & QIC_STATUS_READY && *status & QIC_STATUS_ERROR) {
467 /* Let caller handle all errors */
468 TRACE_ABORT(1, ft_t_warn, "warning: error status set!");
473 int ftape_report_error(unsigned int *error,
474 qic117_cmd_t *command, int report)
476 static const ftape_error ftape_errors[] = QIC117_ERRORS;
480 TRACE_CATCH(ftape_report_operation(&code, QIC_REPORT_ERROR_CODE, 16),);
481 *error = (unsigned int)(code & 0xff);
482 *command = (qic117_cmd_t)((code>>8)&0xff);
483 /* remember hardware status, maybe useful for status ioctls
485 ft_last_error.error.command = (__u8)*command;
486 ft_last_error.error.error = (__u8)*error;
491 TRACE_ABORT(0, ft_t_info, "No error");
493 TRACE(ft_t_info, "errorcode: %d", *error);
494 if (*error < NR_ITEMS(ftape_errors)) {
495 TRACE(ft_t_noise, "%sFatal ERROR:",
496 (ftape_errors[*error].fatal ? "" : "Non-"));
497 TRACE(ft_t_noise, "%s ...", ftape_errors[*error].message);
499 TRACE(ft_t_noise, "Unknown ERROR !");
501 if ((unsigned int)*command < NR_ITEMS(qic117_cmds) &&
502 qic117_cmds[*command].name != NULL) {
503 TRACE(ft_t_noise, "... caused by command \'%s\'",
504 qic117_cmds[*command].name);
506 TRACE(ft_t_noise, "... caused by unknown command %d",
512 int ftape_in_error_state(int status)
516 if ((status & QIC_STATUS_READY) && (status & QIC_STATUS_ERROR)) {
517 TRACE_ABORT(1, ft_t_warn, "warning: error status set!");
522 int ftape_report_configuration(qic_model *model,
530 static const unsigned int qic_rates[ 4] = { 250, 2000, 500, 1000 };
533 result = ftape_report_operation(&config,
534 QIC_REPORT_DRIVE_CONFIGURATION, 8);
536 ft_last_status.status.drive_config = (__u8)0x00;
537 *model = prehistoric;
539 *qic_std = QIC_TAPE_QIC40;
543 ft_last_status.status.drive_config = (__u8)(config & 0xff);
545 *rate = qic_rates[(config & QIC_CONFIG_RATE_MASK) >> QIC_CONFIG_RATE_SHIFT];
546 result = ftape_report_operation(&status, QIC_REPORT_TAPE_STATUS, 8);
548 ft_last_status.status.tape_status = (__u8)0x00;
549 /* pre- QIC117 rev C spec. drive, QIC_CONFIG_80 bit is valid.
551 *qic_std = (config & QIC_CONFIG_80) ?
552 QIC_TAPE_QIC80 : QIC_TAPE_QIC40;
553 /* ?? how's about 425ft tapes? */
554 *tape_len = (config & QIC_CONFIG_LONG) ? 307 : 0;
555 *model = pre_qic117c;
558 ft_last_status.status.tape_status = (__u8)(status & 0xff);
559 *model = post_qic117b;
560 TRACE(ft_t_any, "report tape status result = %02x", status);
561 /* post- QIC117 rev C spec. drive, QIC_CONFIG_80 bit is
564 switch (status & QIC_TAPE_STD_MASK) {
567 case QIC_TAPE_QIC3020:
568 case QIC_TAPE_QIC3010:
569 *qic_std = status & QIC_TAPE_STD_MASK;
575 switch (status & QIC_TAPE_LEN_MASK) {
577 /* 205 or 425+ ft 550 Oe tape */
581 /* 307.5 ft 550 Oe Extended Length (XL) tape */
584 case QIC_TAPE_VARIABLE:
585 /* Variable length 550 Oe tape */
588 case QIC_TAPE_1100FT:
589 /* 1100 ft 550 Oe tape */
593 /* Variable length 900 Oe tape */
600 if (*qic_std == -1 || *tape_len == -1) {
602 "post qic-117b spec drive with unknown tape");
604 result = *tape_len == -1 ? -EIO : 0;
605 if (status & QIC_TAPE_WIDE) {
608 TRACE(ft_t_info, "TR-1 tape detected");
610 case QIC_TAPE_QIC3010:
611 TRACE(ft_t_info, "TR-2 tape detected");
613 case QIC_TAPE_QIC3020:
614 TRACE(ft_t_info, "TR-3 tape detected");
618 "Unknown Travan tape type detected");
623 TRACE_EXIT (result < 0) ? -EIO : 0;
626 int ftape_report_rom_version(int *version)
629 if (ftape_report_operation(version, QIC_REPORT_ROM_VERSION, 8) < 0) {
636 int ftape_report_signature(int *signature)
640 result = ftape_command(28);
641 result = ftape_report_operation(signature, 9, 8);
642 result = ftape_command(30);
643 return (result < 0) ? -EIO : 0;
646 void ftape_report_vendor_id(unsigned int *id)
651 /* We'll try to get a vendor id from the drive. First
652 * according to the QIC-117 spec, a 16-bit id is requested.
653 * If that fails we'll try an 8-bit version, otherwise we'll
654 * try an undocumented query.
656 result = ftape_report_operation((int *) id, QIC_REPORT_VENDOR_ID, 16);
658 result = ftape_report_operation((int *) id,
659 QIC_REPORT_VENDOR_ID, 8);
661 /* The following is an undocumented call found
664 result = ftape_report_operation((int *) id, 24, 8);
666 *id = UNKNOWN_VENDOR;
668 TRACE(ft_t_noise, "got old 8 bit id: %04x",
673 TRACE(ft_t_noise, "got 8 bit id: %04x", *id);
677 TRACE(ft_t_noise, "got 16 bit id: %04x", *id);
683 if (ftape_report_rom_version(&version) < 0) {
684 TRACE(ft_t_bug, "report rom version failed");
687 TRACE(ft_t_noise, "CMS rom version: %d", version);
688 ftape_command(QIC_ENTER_DIAGNOSTIC_1);
689 ftape_command(QIC_ENTER_DIAGNOSTIC_1);
691 if (ftape_report_operation(&sign, 9, 8) < 0) {
693 qic117_cmd_t command;
695 ftape_report_error(&error, &command, 1);
696 ftape_command(QIC_ENTER_PRIMARY_MODE);
698 TRACE_EXIT; /* failure ! */
700 TRACE(ft_t_noise, "CMS signature: %02x", sign);
703 result = ftape_report_operation(&sign, 37, 8);
708 "This is an Iomega drive !");
712 "This is a real CMS drive !");
716 TRACE(ft_t_noise, "CMS status: %d", sign);
719 *id = UNKNOWN_VENDOR;
721 ftape_command(QIC_ENTER_PRIMARY_MODE);
727 static int qic_rate_code(unsigned int rate)
731 return QIC_CONFIG_RATE_250;
733 return QIC_CONFIG_RATE_500;
735 return QIC_CONFIG_RATE_1000;
737 return QIC_CONFIG_RATE_2000;
739 return QIC_CONFIG_RATE_500;
743 static int ftape_set_rate_test(unsigned int *max_rate)
746 qic117_cmd_t command;
751 /* Check if the drive does support the select rate command
752 * by testing all different settings. If any one is accepted
753 * we assume the command is supported, else not.
755 for (*max_rate = 2000; *max_rate >= 250; *max_rate /= 2) {
756 if (ftape_command(QIC_SELECT_RATE) < 0) {
759 if (ftape_parameter_wait(qic_rate_code(*max_rate),
760 1 * FT_SECOND, &status) < 0) {
763 if (status & QIC_STATUS_ERROR) {
764 ftape_report_error(&error, &command, 0);
767 supported = 1; /* did accept a request */
770 TRACE(ft_t_noise, "Select Rate command is%s supported",
771 supported ? "" : " not");
772 TRACE_EXIT supported;
775 int ftape_set_data_rate(unsigned int new_rate /* Kbps */, unsigned int qic_std)
779 unsigned int data_rate = new_rate;
780 static int supported;
781 int rate_changed = 0;
782 qic_model dummy_model;
783 unsigned int dummy_qic_std, dummy_tape_len;
786 if (ft_drive_max_rate == 0) { /* first time */
787 supported = ftape_set_rate_test(&ft_drive_max_rate);
790 ftape_command(QIC_SELECT_RATE);
791 result = ftape_parameter_wait(qic_rate_code(new_rate),
792 1 * FT_SECOND, &status);
793 if (result >= 0 && !(status & QIC_STATUS_ERROR)) {
797 TRACE_CATCH(result = ftape_report_configuration(&dummy_model,
801 if (data_rate != new_rate) {
803 TRACE(ft_t_warn, "Rate change not supported!");
804 } else if (rate_changed) {
805 TRACE(ft_t_warn, "Requested: %d, got %d",
806 new_rate, data_rate);
808 TRACE(ft_t_warn, "Rate change failed!");
813 * Set data rate and write precompensation as specified:
815 * | QIC-40/80 | QIC-3010/3020
816 * rate | precomp | precomp
817 * ----------+-------------+--------------
818 * 250 Kbps. | 250 ns. | 0 ns.
819 * 500 Kbps. | 125 ns. | 0 ns.
820 * 1 Mbps. | 42 ns. | 0 ns.
821 * 2 Mbps | N/A | 0 ns.
823 if ((qic_std == QIC_TAPE_QIC40 && data_rate > 500) ||
824 (qic_std == QIC_TAPE_QIC80 && data_rate > 1000)) {
826 ft_t_warn, "Datarate too high for QIC-mode");
828 TRACE_CATCH(fdc_set_data_rate(data_rate),_res = -EINVAL);
829 ft_data_rate = data_rate;
830 if (qic_std == QIC_TAPE_QIC40 || qic_std == QIC_TAPE_QIC80) {
833 fdc_set_write_precomp(250);
837 fdc_set_write_precomp(125);
840 fdc_set_write_precomp(42);
844 fdc_set_write_precomp(0);
849 /* The next two functions are used to cope with excessive overrun errors
851 int ftape_increase_threshold(void)
853 TRACE_FUN(ft_t_flow);
855 if (fdc.type < i82077 || ft_fdc_threshold >= 12) {
856 TRACE_ABORT(-EIO, ft_t_err, "cannot increase fifo threshold");
858 if (fdc_fifo_threshold(++ft_fdc_threshold, NULL, NULL, NULL) < 0) {
859 TRACE(ft_t_err, "cannot increase fifo threshold");
863 TRACE(ft_t_info, "New FIFO threshold: %d", ft_fdc_threshold);
867 int ftape_half_data_rate(void)
869 if (ft_data_rate < 500) {
872 if (ftape_set_data_rate(ft_data_rate / 2, ft_qic_std) < 0) {
875 ftape_calc_timeouts(ft_qic_std, ft_data_rate, ftape_tape_len);
879 /* Seek the head to the specified track.
881 int ftape_seek_head_to_track(unsigned int track)
886 ft_location.track = -1; /* remains set in case of error */
887 if (track >= ft_tracks_per_tape) {
888 TRACE_ABORT(-EINVAL, ft_t_bug, "track out of bounds");
890 TRACE(ft_t_flow, "seeking track %d", track);
891 TRACE_CATCH(ftape_command(QIC_SEEK_HEAD_TO_TRACK),);
892 TRACE_CATCH(ftape_parameter_wait(track, ftape_timeout.head_seek,
894 ft_location.track = track;
895 ftape_might_be_off_track = 0;
899 int ftape_wakeup_drive(wake_up_types method)
906 case wake_up_colorado:
907 TRACE_CATCH(ftape_command(QIC_PHANTOM_SELECT),);
908 TRACE_CATCH(ftape_parameter(0 /* ft_drive_sel ?? */),);
910 case wake_up_mountain:
911 TRACE_CATCH(ftape_command(QIC_SOFT_SELECT),);
912 ftape_sleep(FT_MILLISECOND); /* NEEDED */
913 TRACE_CATCH(ftape_parameter(18),);
915 case wake_up_insight:
916 ftape_sleep(100 * FT_MILLISECOND);
918 fdc_motor(motor_on); /* enable is done by motor-on */
922 TRACE_EXIT -ENODEV; /* unknown wakeup method */
925 /* If wakeup succeeded we shouldn't get an error here..
927 TRACE_CATCH(ftape_report_raw_drive_status(&status),
934 int ftape_put_drive_to_sleep(wake_up_types method)
939 case wake_up_colorado:
940 TRACE_CATCH(ftape_command(QIC_PHANTOM_DESELECT),);
942 case wake_up_mountain:
943 TRACE_CATCH(ftape_command(QIC_SOFT_DESELECT),);
945 case wake_up_insight:
946 fdc_motor(0); /* enable is done by motor-on */
947 case no_wake_up: /* no wakeup / no sleep ! */
950 TRACE_EXIT -ENODEV; /* unknown wakeup method */
955 int ftape_reset_drive(void)
959 unsigned int err_code;
960 qic117_cmd_t err_command;
964 /* We want to re-establish contact with our drive. Fire a
965 * number of reset commands (single step pulses) and pray for
968 for (i = 0; i < 2; ++i) {
969 TRACE(ft_t_flow, "Resetting fdc");
971 ftape_sleep(10 * FT_MILLISECOND);
972 TRACE(ft_t_flow, "Reset command to drive");
973 result = ftape_command(QIC_RESET);
975 ftape_sleep(1 * FT_SECOND); /* drive not
979 TRACE(ft_t_flow, "Re-selecting drive");
981 /* Strange, the QIC-117 specs don't mention
982 * this but the drive gets deselected after a
983 * soft reset ! So we need to enable it
986 if (ftape_wakeup_drive(ft_drive_type.wake_up) < 0) {
987 TRACE(ft_t_err, "Wakeup failed !");
989 TRACE(ft_t_flow, "Waiting until drive gets ready");
990 result= ftape_ready_wait(ftape_timeout.reset, &status);
991 if (result == 0 && (status & QIC_STATUS_ERROR)) {
992 result = ftape_report_error(&err_code,
994 if (result == 0 && err_code == 27) {
995 /* Okay, drive saw reset
996 * command and responded as it
1007 FT_SIGNAL_EXIT(_DONT_BLOCK);
1010 TRACE(ft_t_err, "General failure to reset tape drive");
1012 /* Restore correct settings: keep original rate
1014 ftape_set_data_rate(ft_data_rate, ft_qic_std);
1016 ftape_init_drive_needed = 1;