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>
35 #include <linux/delay.h>
37 #include <linux/ftape.h>
38 #include <linux/qic117.h>
39 #include "../lowlevel/ftape-tracing.h"
40 #include "../lowlevel/fdc-io.h"
41 #include "../lowlevel/ftape-io.h"
42 #include "../lowlevel/ftape-ctl.h"
43 #include "../lowlevel/ftape-rw.h"
44 #include "../lowlevel/ftape-write.h"
45 #include "../lowlevel/ftape-read.h"
46 #include "../lowlevel/ftape-init.h"
47 #include "../lowlevel/ftape-calibr.h"
51 /* NOTE: sectors start numbering at 1, all others at 0 ! */
52 ft_timeout_table ftape_timeout;
53 unsigned int ftape_tape_len;
54 volatile qic117_cmd_t ftape_current_command;
55 const struct qic117_command_table qic117_cmds[] = QIC117_COMMANDS;
56 int ftape_might_be_off_track;
60 static int diagnostic_mode;
61 static unsigned int ftape_udelay_count;
62 static unsigned int ftape_udelay_time;
64 void ftape_udelay(unsigned int usecs)
66 volatile int count = (ftape_udelay_count * usecs +
67 ftape_udelay_count - 1) / ftape_udelay_time;
71 for (i = 0; i < 20; ++i);
75 void ftape_udelay_calibrate(void)
77 ftape_calibrate("ftape_udelay",
78 ftape_udelay, &ftape_udelay_count, &ftape_udelay_time);
81 /* Delay (msec) routine.
83 void ftape_sleep(unsigned int time)
87 time *= 1000; /* msecs -> usecs */
89 /* Time too small for scheduler, do a busy wait ! */
94 unsigned int ticks = (time + FT_USPT - 1) / FT_USPT;
96 TRACE(ft_t_any, "%d msec, %d ticks", time/1000, ticks);
100 msleep_interruptible(jiffies_to_msecs(timeout));
101 /* Mmm. Isn't current->blocked == 0xffffffff ?
103 if (signal_pending(current)) {
104 TRACE(ft_t_err, "awoken by non-blocked signal :-(");
106 restore_flags(flags);
111 /* send a command or parameter to the drive
112 * Generates # of step pulses.
114 static inline int ft_send_to_drive(int arg)
116 /* Always wait for a command_timeout period to separate
117 * individuals commands and/or parameters.
119 ftape_sleep(3 * FT_MILLISECOND);
120 /* Keep cylinder nr within range, step towards home if possible.
122 if (ftape_current_cylinder >= arg) {
123 return fdc_seek(ftape_current_cylinder - arg);
125 return fdc_seek(ftape_current_cylinder + arg);
129 /* forward */ int ftape_report_raw_drive_status(int *status);
131 static int ft_check_cmd_restrictions(qic117_cmd_t command)
136 TRACE(ft_t_flow, "%s", qic117_cmds[command].name);
137 /* A new motion command during an uninterruptible (motion)
138 * command requires a ready status before the new command can
139 * be issued. Otherwise a new motion command needs to be
140 * checked against required status.
142 if (qic117_cmds[command].cmd_type == motion &&
143 qic117_cmds[ftape_current_command].non_intr) {
144 ftape_report_raw_drive_status(&status);
145 if ((status & QIC_STATUS_READY) == 0) {
147 "motion cmd (%d) during non-intr cmd (%d)",
148 command, ftape_current_command);
149 TRACE(ft_t_noise, "waiting until drive gets ready");
150 ftape_ready_wait(ftape_timeout.seek,
154 if (qic117_cmds[command].mask != 0) {
156 /* Some commands do require a certain status:
158 if (status == -1) { /* not yet set */
159 ftape_report_raw_drive_status(&status);
161 difference = ((status ^ qic117_cmds[command].state) &
162 qic117_cmds[command].mask);
163 /* Wait until the drive gets
164 * ready. This may last forever if
165 * the drive never gets ready...
167 while ((difference & QIC_STATUS_READY) != 0) {
168 TRACE(ft_t_noise, "command %d issued while not ready",
170 TRACE(ft_t_noise, "waiting until drive gets ready");
171 if (ftape_ready_wait(ftape_timeout.seek,
172 &status) == -EINTR) {
173 /* Bail out on signal !
175 TRACE_ABORT(-EINTR, ft_t_warn,
176 "interrupted by non-blockable signal");
178 difference = ((status ^ qic117_cmds[command].state) &
179 qic117_cmds[command].mask);
181 while ((difference & QIC_STATUS_ERROR) != 0) {
186 "command %d issued while error pending",
188 TRACE(ft_t_noise, "clearing error status");
189 ftape_report_error(&err, &cmd, 1);
190 ftape_report_raw_drive_status(&status);
191 difference = ((status ^ qic117_cmds[command].state) &
192 qic117_cmds[command].mask);
193 if ((difference & QIC_STATUS_ERROR) != 0) {
194 /* Bail out on fatal signal !
196 FT_SIGNAL_EXIT(_NEVER_BLOCK);
200 /* Any remaining difference can't be solved
203 if (difference & (QIC_STATUS_CARTRIDGE_PRESENT |
204 QIC_STATUS_NEW_CARTRIDGE |
205 QIC_STATUS_REFERENCED)) {
207 "Fatal: tape removed or reinserted !");
210 TRACE(ft_t_err, "wrong state: 0x%02x should be: 0x%02x",
211 status & qic117_cmds[command].mask,
212 qic117_cmds[command].state);
216 if (~status & QIC_STATUS_READY & qic117_cmds[command].mask) {
217 TRACE_ABORT(-EBUSY, ft_t_err, "Bad: still busy!");
223 /* Issue a tape command:
225 int ftape_command(qic117_cmd_t command)
231 if ((unsigned int)command > NR_ITEMS(qic117_cmds)) {
232 /* This is a bug we'll want to know about too.
234 TRACE_ABORT(-EIO, ft_t_bug, "bug - bad command: %d", command);
236 if (++level > 5) { /* This is a bug we'll want to know about. */
238 TRACE_ABORT(-EIO, ft_t_bug, "bug - recursion for command: %d",
241 /* disable logging and restriction check for some commands,
242 * check all other commands that have a prescribed starting
245 if (diagnostic_mode) {
246 TRACE(ft_t_flow, "diagnostic command %d", command);
247 } else if (command == QIC_REPORT_DRIVE_STATUS ||
248 command == QIC_REPORT_NEXT_BIT) {
249 TRACE(ft_t_any, "%s", qic117_cmds[command].name);
251 TRACE_CATCH(ft_check_cmd_restrictions(command), --level);
253 /* Now all conditions are met or result was < 0.
255 result = ft_send_to_drive((unsigned int)command);
256 if (qic117_cmds[command].cmd_type == motion &&
257 command != QIC_LOGICAL_FORWARD && command != QIC_STOP_TAPE) {
258 ft_location.known = 0;
260 ftape_current_command = command;
265 /* Send a tape command parameter:
266 * Generates command # of step pulses.
267 * Skips tape-status call !
269 int ftape_parameter(unsigned int parameter)
273 TRACE(ft_t_flow, "called with parameter = %d", parameter);
274 TRACE_EXIT ft_send_to_drive(parameter + 2);
277 /* Wait for the drive to get ready.
278 * timeout time in milli-seconds
279 * Returned status is valid if result != -EIO
281 * Should we allow to be killed by SIGINT? (^C)
282 * Would be nice at least for large timeouts.
284 int ftape_ready_wait(unsigned int timeout, int *status)
287 unsigned int poll_delay;
291 /* the following ** REALLY ** reduces the system load when
292 * e.g. one simply rewinds or retensions. The tape is slow
293 * anyway. It is really not necessary to detect error
294 * conditions with 1/10 seconds granularity
296 * On my AMD 133MHZ 486: 100 ms: 23% system load
300 if (timeout <= FT_SECOND) {
301 poll_delay = 100 * FT_MILLISECOND;
302 signal_retries = 20; /* two seconds */
303 } else if (timeout < 20 * FT_SECOND) {
304 TRACE(ft_t_flow, "setting poll delay to 1 second");
305 poll_delay = FT_SECOND;
306 signal_retries = 2; /* two seconds */
308 TRACE(ft_t_flow, "setting poll delay to 5 seconds");
309 poll_delay = 5 * FT_SECOND;
310 signal_retries = 1; /* five seconds */
314 TRACE_CATCH(ftape_report_raw_drive_status(status),);
315 if (*status & QIC_STATUS_READY) {
318 if (!signal_retries--) {
319 FT_SIGNAL_EXIT(_NEVER_BLOCK);
321 if ((int)timeout >= 0) {
322 /* this will fail when jiffies wraps around about
323 * once every year :-)
325 timeout -= ((jiffies - t0) * FT_SECOND) / HZ;
327 TRACE_ABORT(-ETIME, ft_t_err, "timeout");
329 ftape_sleep(poll_delay);
330 timeout -= poll_delay;
332 ftape_sleep(poll_delay);
338 /* Issue command and wait up to timeout milli seconds for drive ready
340 int ftape_command_wait(qic117_cmd_t command, unsigned int timeout, int *status)
344 /* Drive should be ready, issue command
346 result = ftape_command(command);
348 result = ftape_ready_wait(timeout, status);
353 static int ftape_parameter_wait(unsigned int parm, unsigned int timeout, int *status)
357 /* Drive should be ready, issue command
359 result = ftape_parameter(parm);
361 result = ftape_ready_wait(timeout, status);
366 /*--------------------------------------------------------------------------
370 /* Query the drive about its status. The command is sent and
371 result_length bits of status are returned (2 extra bits are read
372 for start and stop). */
374 int ftape_report_operation(int *status,
375 qic117_cmd_t command,
383 TRACE_CATCH(ftape_command(command),);
384 t0 = ftape_timestamp();
388 ftape_sleep(3 * FT_MILLISECOND); /* see remark below */
389 TRACE_CATCH(fdc_sense_drive_status(&st3),);
390 dt = ftape_timediff(t0, ftape_timestamp());
391 /* Ack should be asserted within Ttimout + Tack = 6 msec.
392 * Looks like some drives fail to do this so extend this
393 * period to 300 msec.
395 } while (!(st3 & ST3_TRACK_0) && dt < 300000);
396 if (!(st3 & ST3_TRACK_0)) {
398 "No acknowledge after %u msec. (%i iter)", dt / 1000, i);
399 TRACE_ABORT(-EIO, ft_t_err, "timeout on Acknowledge");
401 /* dt may be larger than expected because of other tasks
402 * scheduled while we were sleeping.
404 if (i > 1 && dt > 6000) {
405 TRACE(ft_t_err, "Acknowledge after %u msec. (%i iter)",
409 for (i = 0; i < result_length + 1; i++) {
410 TRACE_CATCH(ftape_command(QIC_REPORT_NEXT_BIT),);
411 TRACE_CATCH(fdc_sense_drive_status(&st3),);
412 if (i < result_length) {
413 *status |= ((st3 & ST3_TRACK_0) ? 1 : 0) << i;
414 } else if ((st3 & ST3_TRACK_0) == 0) {
415 TRACE_ABORT(-EIO, ft_t_err, "missing status stop bit");
418 /* this command will put track zero and index back into normal state */
419 (void)ftape_command(QIC_REPORT_NEXT_BIT);
423 /* Report the current drive status. */
425 int ftape_report_raw_drive_status(int *status)
432 result = ftape_report_operation(status,
433 QIC_REPORT_DRIVE_STATUS, 8);
434 } while (result < 0 && ++count <= 3);
436 TRACE_ABORT(-EIO, ft_t_err,
437 "report_operation failed after %d trials", count);
439 if ((*status & 0xff) == 0xff) {
440 TRACE_ABORT(-EIO, ft_t_err,
441 "impossible drive status 0xff");
443 if (*status & QIC_STATUS_READY) {
444 ftape_current_command = QIC_NO_COMMAND; /* completed */
446 ft_last_status.status.drive_status = (__u8)(*status & 0xff);
450 int ftape_report_drive_status(int *status)
454 TRACE_CATCH(ftape_report_raw_drive_status(status),);
455 if (*status & QIC_STATUS_NEW_CARTRIDGE ||
456 !(*status & QIC_STATUS_CARTRIDGE_PRESENT)) {
457 ft_failure = 1; /* will inhibit further operations */
460 if (*status & QIC_STATUS_READY && *status & QIC_STATUS_ERROR) {
461 /* Let caller handle all errors */
462 TRACE_ABORT(1, ft_t_warn, "warning: error status set!");
467 int ftape_report_error(unsigned int *error,
468 qic117_cmd_t *command, int report)
470 static const ftape_error ftape_errors[] = QIC117_ERRORS;
474 TRACE_CATCH(ftape_report_operation(&code, QIC_REPORT_ERROR_CODE, 16),);
475 *error = (unsigned int)(code & 0xff);
476 *command = (qic117_cmd_t)((code>>8)&0xff);
477 /* remember hardware status, maybe useful for status ioctls
479 ft_last_error.error.command = (__u8)*command;
480 ft_last_error.error.error = (__u8)*error;
485 TRACE_ABORT(0, ft_t_info, "No error");
487 TRACE(ft_t_info, "errorcode: %d", *error);
488 if (*error < NR_ITEMS(ftape_errors)) {
489 TRACE(ft_t_noise, "%sFatal ERROR:",
490 (ftape_errors[*error].fatal ? "" : "Non-"));
491 TRACE(ft_t_noise, "%s ...", ftape_errors[*error].message);
493 TRACE(ft_t_noise, "Unknown ERROR !");
495 if ((unsigned int)*command < NR_ITEMS(qic117_cmds) &&
496 qic117_cmds[*command].name != NULL) {
497 TRACE(ft_t_noise, "... caused by command \'%s\'",
498 qic117_cmds[*command].name);
500 TRACE(ft_t_noise, "... caused by unknown command %d",
506 int ftape_report_configuration(qic_model *model,
514 static const unsigned int qic_rates[ 4] = { 250, 2000, 500, 1000 };
517 result = ftape_report_operation(&config,
518 QIC_REPORT_DRIVE_CONFIGURATION, 8);
520 ft_last_status.status.drive_config = (__u8)0x00;
521 *model = prehistoric;
523 *qic_std = QIC_TAPE_QIC40;
527 ft_last_status.status.drive_config = (__u8)(config & 0xff);
529 *rate = qic_rates[(config & QIC_CONFIG_RATE_MASK) >> QIC_CONFIG_RATE_SHIFT];
530 result = ftape_report_operation(&status, QIC_REPORT_TAPE_STATUS, 8);
532 ft_last_status.status.tape_status = (__u8)0x00;
533 /* pre- QIC117 rev C spec. drive, QIC_CONFIG_80 bit is valid.
535 *qic_std = (config & QIC_CONFIG_80) ?
536 QIC_TAPE_QIC80 : QIC_TAPE_QIC40;
537 /* ?? how's about 425ft tapes? */
538 *tape_len = (config & QIC_CONFIG_LONG) ? 307 : 0;
539 *model = pre_qic117c;
542 ft_last_status.status.tape_status = (__u8)(status & 0xff);
543 *model = post_qic117b;
544 TRACE(ft_t_any, "report tape status result = %02x", status);
545 /* post- QIC117 rev C spec. drive, QIC_CONFIG_80 bit is
548 switch (status & QIC_TAPE_STD_MASK) {
551 case QIC_TAPE_QIC3020:
552 case QIC_TAPE_QIC3010:
553 *qic_std = status & QIC_TAPE_STD_MASK;
559 switch (status & QIC_TAPE_LEN_MASK) {
561 /* 205 or 425+ ft 550 Oe tape */
565 /* 307.5 ft 550 Oe Extended Length (XL) tape */
568 case QIC_TAPE_VARIABLE:
569 /* Variable length 550 Oe tape */
572 case QIC_TAPE_1100FT:
573 /* 1100 ft 550 Oe tape */
577 /* Variable length 900 Oe tape */
584 if (*qic_std == -1 || *tape_len == -1) {
586 "post qic-117b spec drive with unknown tape");
588 result = *tape_len == -1 ? -EIO : 0;
589 if (status & QIC_TAPE_WIDE) {
592 TRACE(ft_t_info, "TR-1 tape detected");
594 case QIC_TAPE_QIC3010:
595 TRACE(ft_t_info, "TR-2 tape detected");
597 case QIC_TAPE_QIC3020:
598 TRACE(ft_t_info, "TR-3 tape detected");
602 "Unknown Travan tape type detected");
607 TRACE_EXIT (result < 0) ? -EIO : 0;
610 static int ftape_report_rom_version(int *version)
613 if (ftape_report_operation(version, QIC_REPORT_ROM_VERSION, 8) < 0) {
620 void ftape_report_vendor_id(unsigned int *id)
625 /* We'll try to get a vendor id from the drive. First
626 * according to the QIC-117 spec, a 16-bit id is requested.
627 * If that fails we'll try an 8-bit version, otherwise we'll
628 * try an undocumented query.
630 result = ftape_report_operation((int *) id, QIC_REPORT_VENDOR_ID, 16);
632 result = ftape_report_operation((int *) id,
633 QIC_REPORT_VENDOR_ID, 8);
635 /* The following is an undocumented call found
638 result = ftape_report_operation((int *) id, 24, 8);
640 *id = UNKNOWN_VENDOR;
642 TRACE(ft_t_noise, "got old 8 bit id: %04x",
647 TRACE(ft_t_noise, "got 8 bit id: %04x", *id);
651 TRACE(ft_t_noise, "got 16 bit id: %04x", *id);
657 if (ftape_report_rom_version(&version) < 0) {
658 TRACE(ft_t_bug, "report rom version failed");
661 TRACE(ft_t_noise, "CMS rom version: %d", version);
662 ftape_command(QIC_ENTER_DIAGNOSTIC_1);
663 ftape_command(QIC_ENTER_DIAGNOSTIC_1);
665 if (ftape_report_operation(&sign, 9, 8) < 0) {
667 qic117_cmd_t command;
669 ftape_report_error(&error, &command, 1);
670 ftape_command(QIC_ENTER_PRIMARY_MODE);
672 TRACE_EXIT; /* failure ! */
674 TRACE(ft_t_noise, "CMS signature: %02x", sign);
677 result = ftape_report_operation(&sign, 37, 8);
682 "This is an Iomega drive !");
686 "This is a real CMS drive !");
690 TRACE(ft_t_noise, "CMS status: %d", sign);
693 *id = UNKNOWN_VENDOR;
695 ftape_command(QIC_ENTER_PRIMARY_MODE);
701 static int qic_rate_code(unsigned int rate)
705 return QIC_CONFIG_RATE_250;
707 return QIC_CONFIG_RATE_500;
709 return QIC_CONFIG_RATE_1000;
711 return QIC_CONFIG_RATE_2000;
713 return QIC_CONFIG_RATE_500;
717 static int ftape_set_rate_test(unsigned int *max_rate)
720 qic117_cmd_t command;
725 /* Check if the drive does support the select rate command
726 * by testing all different settings. If any one is accepted
727 * we assume the command is supported, else not.
729 for (*max_rate = 2000; *max_rate >= 250; *max_rate /= 2) {
730 if (ftape_command(QIC_SELECT_RATE) < 0) {
733 if (ftape_parameter_wait(qic_rate_code(*max_rate),
734 1 * FT_SECOND, &status) < 0) {
737 if (status & QIC_STATUS_ERROR) {
738 ftape_report_error(&error, &command, 0);
741 supported = 1; /* did accept a request */
744 TRACE(ft_t_noise, "Select Rate command is%s supported",
745 supported ? "" : " not");
746 TRACE_EXIT supported;
749 int ftape_set_data_rate(unsigned int new_rate /* Kbps */, unsigned int qic_std)
753 unsigned int data_rate = new_rate;
754 static int supported;
755 int rate_changed = 0;
756 qic_model dummy_model;
757 unsigned int dummy_qic_std, dummy_tape_len;
760 if (ft_drive_max_rate == 0) { /* first time */
761 supported = ftape_set_rate_test(&ft_drive_max_rate);
764 ftape_command(QIC_SELECT_RATE);
765 result = ftape_parameter_wait(qic_rate_code(new_rate),
766 1 * FT_SECOND, &status);
767 if (result >= 0 && !(status & QIC_STATUS_ERROR)) {
771 TRACE_CATCH(result = ftape_report_configuration(&dummy_model,
775 if (data_rate != new_rate) {
777 TRACE(ft_t_warn, "Rate change not supported!");
778 } else if (rate_changed) {
779 TRACE(ft_t_warn, "Requested: %d, got %d",
780 new_rate, data_rate);
782 TRACE(ft_t_warn, "Rate change failed!");
787 * Set data rate and write precompensation as specified:
789 * | QIC-40/80 | QIC-3010/3020
790 * rate | precomp | precomp
791 * ----------+-------------+--------------
792 * 250 Kbps. | 250 ns. | 0 ns.
793 * 500 Kbps. | 125 ns. | 0 ns.
794 * 1 Mbps. | 42 ns. | 0 ns.
795 * 2 Mbps | N/A | 0 ns.
797 if ((qic_std == QIC_TAPE_QIC40 && data_rate > 500) ||
798 (qic_std == QIC_TAPE_QIC80 && data_rate > 1000)) {
800 ft_t_warn, "Datarate too high for QIC-mode");
802 TRACE_CATCH(fdc_set_data_rate(data_rate),_res = -EINVAL);
803 ft_data_rate = data_rate;
804 if (qic_std == QIC_TAPE_QIC40 || qic_std == QIC_TAPE_QIC80) {
807 fdc_set_write_precomp(250);
811 fdc_set_write_precomp(125);
814 fdc_set_write_precomp(42);
818 fdc_set_write_precomp(0);
823 /* The next two functions are used to cope with excessive overrun errors
825 int ftape_increase_threshold(void)
827 TRACE_FUN(ft_t_flow);
829 if (fdc.type < i82077 || ft_fdc_threshold >= 12) {
830 TRACE_ABORT(-EIO, ft_t_err, "cannot increase fifo threshold");
832 if (fdc_fifo_threshold(++ft_fdc_threshold, NULL, NULL, NULL) < 0) {
833 TRACE(ft_t_err, "cannot increase fifo threshold");
837 TRACE(ft_t_info, "New FIFO threshold: %d", ft_fdc_threshold);
841 int ftape_half_data_rate(void)
843 if (ft_data_rate < 500) {
846 if (ftape_set_data_rate(ft_data_rate / 2, ft_qic_std) < 0) {
849 ftape_calc_timeouts(ft_qic_std, ft_data_rate, ftape_tape_len);
853 /* Seek the head to the specified track.
855 int ftape_seek_head_to_track(unsigned int track)
860 ft_location.track = -1; /* remains set in case of error */
861 if (track >= ft_tracks_per_tape) {
862 TRACE_ABORT(-EINVAL, ft_t_bug, "track out of bounds");
864 TRACE(ft_t_flow, "seeking track %d", track);
865 TRACE_CATCH(ftape_command(QIC_SEEK_HEAD_TO_TRACK),);
866 TRACE_CATCH(ftape_parameter_wait(track, ftape_timeout.head_seek,
868 ft_location.track = track;
869 ftape_might_be_off_track = 0;
873 int ftape_wakeup_drive(wake_up_types method)
880 case wake_up_colorado:
881 TRACE_CATCH(ftape_command(QIC_PHANTOM_SELECT),);
882 TRACE_CATCH(ftape_parameter(0 /* ft_drive_sel ?? */),);
884 case wake_up_mountain:
885 TRACE_CATCH(ftape_command(QIC_SOFT_SELECT),);
886 ftape_sleep(FT_MILLISECOND); /* NEEDED */
887 TRACE_CATCH(ftape_parameter(18),);
889 case wake_up_insight:
890 ftape_sleep(100 * FT_MILLISECOND);
892 fdc_motor(motor_on); /* enable is done by motor-on */
896 TRACE_EXIT -ENODEV; /* unknown wakeup method */
899 /* If wakeup succeeded we shouldn't get an error here..
901 TRACE_CATCH(ftape_report_raw_drive_status(&status),
908 int ftape_put_drive_to_sleep(wake_up_types method)
913 case wake_up_colorado:
914 TRACE_CATCH(ftape_command(QIC_PHANTOM_DESELECT),);
916 case wake_up_mountain:
917 TRACE_CATCH(ftape_command(QIC_SOFT_DESELECT),);
919 case wake_up_insight:
920 fdc_motor(0); /* enable is done by motor-on */
921 case no_wake_up: /* no wakeup / no sleep ! */
924 TRACE_EXIT -ENODEV; /* unknown wakeup method */
929 int ftape_reset_drive(void)
933 unsigned int err_code;
934 qic117_cmd_t err_command;
938 /* We want to re-establish contact with our drive. Fire a
939 * number of reset commands (single step pulses) and pray for
942 for (i = 0; i < 2; ++i) {
943 TRACE(ft_t_flow, "Resetting fdc");
945 ftape_sleep(10 * FT_MILLISECOND);
946 TRACE(ft_t_flow, "Reset command to drive");
947 result = ftape_command(QIC_RESET);
949 ftape_sleep(1 * FT_SECOND); /* drive not
953 TRACE(ft_t_flow, "Re-selecting drive");
955 /* Strange, the QIC-117 specs don't mention
956 * this but the drive gets deselected after a
957 * soft reset ! So we need to enable it
960 if (ftape_wakeup_drive(ft_drive_type.wake_up) < 0) {
961 TRACE(ft_t_err, "Wakeup failed !");
963 TRACE(ft_t_flow, "Waiting until drive gets ready");
964 result= ftape_ready_wait(ftape_timeout.reset, &status);
965 if (result == 0 && (status & QIC_STATUS_ERROR)) {
966 result = ftape_report_error(&err_code,
968 if (result == 0 && err_code == 27) {
969 /* Okay, drive saw reset
970 * command and responded as it
981 FT_SIGNAL_EXIT(_DONT_BLOCK);
984 TRACE(ft_t_err, "General failure to reset tape drive");
986 /* Restore correct settings: keep original rate
988 ftape_set_data_rate(ft_data_rate, ft_qic_std);
990 ftape_init_drive_needed = 1;