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 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_in_error_state(int status)
510 if ((status & QIC_STATUS_READY) && (status & QIC_STATUS_ERROR)) {
511 TRACE_ABORT(1, ft_t_warn, "warning: error status set!");
516 int ftape_report_configuration(qic_model *model,
524 static const unsigned int qic_rates[ 4] = { 250, 2000, 500, 1000 };
527 result = ftape_report_operation(&config,
528 QIC_REPORT_DRIVE_CONFIGURATION, 8);
530 ft_last_status.status.drive_config = (__u8)0x00;
531 *model = prehistoric;
533 *qic_std = QIC_TAPE_QIC40;
537 ft_last_status.status.drive_config = (__u8)(config & 0xff);
539 *rate = qic_rates[(config & QIC_CONFIG_RATE_MASK) >> QIC_CONFIG_RATE_SHIFT];
540 result = ftape_report_operation(&status, QIC_REPORT_TAPE_STATUS, 8);
542 ft_last_status.status.tape_status = (__u8)0x00;
543 /* pre- QIC117 rev C spec. drive, QIC_CONFIG_80 bit is valid.
545 *qic_std = (config & QIC_CONFIG_80) ?
546 QIC_TAPE_QIC80 : QIC_TAPE_QIC40;
547 /* ?? how's about 425ft tapes? */
548 *tape_len = (config & QIC_CONFIG_LONG) ? 307 : 0;
549 *model = pre_qic117c;
552 ft_last_status.status.tape_status = (__u8)(status & 0xff);
553 *model = post_qic117b;
554 TRACE(ft_t_any, "report tape status result = %02x", status);
555 /* post- QIC117 rev C spec. drive, QIC_CONFIG_80 bit is
558 switch (status & QIC_TAPE_STD_MASK) {
561 case QIC_TAPE_QIC3020:
562 case QIC_TAPE_QIC3010:
563 *qic_std = status & QIC_TAPE_STD_MASK;
569 switch (status & QIC_TAPE_LEN_MASK) {
571 /* 205 or 425+ ft 550 Oe tape */
575 /* 307.5 ft 550 Oe Extended Length (XL) tape */
578 case QIC_TAPE_VARIABLE:
579 /* Variable length 550 Oe tape */
582 case QIC_TAPE_1100FT:
583 /* 1100 ft 550 Oe tape */
587 /* Variable length 900 Oe tape */
594 if (*qic_std == -1 || *tape_len == -1) {
596 "post qic-117b spec drive with unknown tape");
598 result = *tape_len == -1 ? -EIO : 0;
599 if (status & QIC_TAPE_WIDE) {
602 TRACE(ft_t_info, "TR-1 tape detected");
604 case QIC_TAPE_QIC3010:
605 TRACE(ft_t_info, "TR-2 tape detected");
607 case QIC_TAPE_QIC3020:
608 TRACE(ft_t_info, "TR-3 tape detected");
612 "Unknown Travan tape type detected");
617 TRACE_EXIT (result < 0) ? -EIO : 0;
620 int ftape_report_rom_version(int *version)
623 if (ftape_report_operation(version, QIC_REPORT_ROM_VERSION, 8) < 0) {
630 int ftape_report_signature(int *signature)
634 result = ftape_command(28);
635 result = ftape_report_operation(signature, 9, 8);
636 result = ftape_command(30);
637 return (result < 0) ? -EIO : 0;
640 void ftape_report_vendor_id(unsigned int *id)
645 /* We'll try to get a vendor id from the drive. First
646 * according to the QIC-117 spec, a 16-bit id is requested.
647 * If that fails we'll try an 8-bit version, otherwise we'll
648 * try an undocumented query.
650 result = ftape_report_operation((int *) id, QIC_REPORT_VENDOR_ID, 16);
652 result = ftape_report_operation((int *) id,
653 QIC_REPORT_VENDOR_ID, 8);
655 /* The following is an undocumented call found
658 result = ftape_report_operation((int *) id, 24, 8);
660 *id = UNKNOWN_VENDOR;
662 TRACE(ft_t_noise, "got old 8 bit id: %04x",
667 TRACE(ft_t_noise, "got 8 bit id: %04x", *id);
671 TRACE(ft_t_noise, "got 16 bit id: %04x", *id);
677 if (ftape_report_rom_version(&version) < 0) {
678 TRACE(ft_t_bug, "report rom version failed");
681 TRACE(ft_t_noise, "CMS rom version: %d", version);
682 ftape_command(QIC_ENTER_DIAGNOSTIC_1);
683 ftape_command(QIC_ENTER_DIAGNOSTIC_1);
685 if (ftape_report_operation(&sign, 9, 8) < 0) {
687 qic117_cmd_t command;
689 ftape_report_error(&error, &command, 1);
690 ftape_command(QIC_ENTER_PRIMARY_MODE);
692 TRACE_EXIT; /* failure ! */
694 TRACE(ft_t_noise, "CMS signature: %02x", sign);
697 result = ftape_report_operation(&sign, 37, 8);
702 "This is an Iomega drive !");
706 "This is a real CMS drive !");
710 TRACE(ft_t_noise, "CMS status: %d", sign);
713 *id = UNKNOWN_VENDOR;
715 ftape_command(QIC_ENTER_PRIMARY_MODE);
721 static int qic_rate_code(unsigned int rate)
725 return QIC_CONFIG_RATE_250;
727 return QIC_CONFIG_RATE_500;
729 return QIC_CONFIG_RATE_1000;
731 return QIC_CONFIG_RATE_2000;
733 return QIC_CONFIG_RATE_500;
737 static int ftape_set_rate_test(unsigned int *max_rate)
740 qic117_cmd_t command;
745 /* Check if the drive does support the select rate command
746 * by testing all different settings. If any one is accepted
747 * we assume the command is supported, else not.
749 for (*max_rate = 2000; *max_rate >= 250; *max_rate /= 2) {
750 if (ftape_command(QIC_SELECT_RATE) < 0) {
753 if (ftape_parameter_wait(qic_rate_code(*max_rate),
754 1 * FT_SECOND, &status) < 0) {
757 if (status & QIC_STATUS_ERROR) {
758 ftape_report_error(&error, &command, 0);
761 supported = 1; /* did accept a request */
764 TRACE(ft_t_noise, "Select Rate command is%s supported",
765 supported ? "" : " not");
766 TRACE_EXIT supported;
769 int ftape_set_data_rate(unsigned int new_rate /* Kbps */, unsigned int qic_std)
773 unsigned int data_rate = new_rate;
774 static int supported;
775 int rate_changed = 0;
776 qic_model dummy_model;
777 unsigned int dummy_qic_std, dummy_tape_len;
780 if (ft_drive_max_rate == 0) { /* first time */
781 supported = ftape_set_rate_test(&ft_drive_max_rate);
784 ftape_command(QIC_SELECT_RATE);
785 result = ftape_parameter_wait(qic_rate_code(new_rate),
786 1 * FT_SECOND, &status);
787 if (result >= 0 && !(status & QIC_STATUS_ERROR)) {
791 TRACE_CATCH(result = ftape_report_configuration(&dummy_model,
795 if (data_rate != new_rate) {
797 TRACE(ft_t_warn, "Rate change not supported!");
798 } else if (rate_changed) {
799 TRACE(ft_t_warn, "Requested: %d, got %d",
800 new_rate, data_rate);
802 TRACE(ft_t_warn, "Rate change failed!");
807 * Set data rate and write precompensation as specified:
809 * | QIC-40/80 | QIC-3010/3020
810 * rate | precomp | precomp
811 * ----------+-------------+--------------
812 * 250 Kbps. | 250 ns. | 0 ns.
813 * 500 Kbps. | 125 ns. | 0 ns.
814 * 1 Mbps. | 42 ns. | 0 ns.
815 * 2 Mbps | N/A | 0 ns.
817 if ((qic_std == QIC_TAPE_QIC40 && data_rate > 500) ||
818 (qic_std == QIC_TAPE_QIC80 && data_rate > 1000)) {
820 ft_t_warn, "Datarate too high for QIC-mode");
822 TRACE_CATCH(fdc_set_data_rate(data_rate),_res = -EINVAL);
823 ft_data_rate = data_rate;
824 if (qic_std == QIC_TAPE_QIC40 || qic_std == QIC_TAPE_QIC80) {
827 fdc_set_write_precomp(250);
831 fdc_set_write_precomp(125);
834 fdc_set_write_precomp(42);
838 fdc_set_write_precomp(0);
843 /* The next two functions are used to cope with excessive overrun errors
845 int ftape_increase_threshold(void)
847 TRACE_FUN(ft_t_flow);
849 if (fdc.type < i82077 || ft_fdc_threshold >= 12) {
850 TRACE_ABORT(-EIO, ft_t_err, "cannot increase fifo threshold");
852 if (fdc_fifo_threshold(++ft_fdc_threshold, NULL, NULL, NULL) < 0) {
853 TRACE(ft_t_err, "cannot increase fifo threshold");
857 TRACE(ft_t_info, "New FIFO threshold: %d", ft_fdc_threshold);
861 int ftape_half_data_rate(void)
863 if (ft_data_rate < 500) {
866 if (ftape_set_data_rate(ft_data_rate / 2, ft_qic_std) < 0) {
869 ftape_calc_timeouts(ft_qic_std, ft_data_rate, ftape_tape_len);
873 /* Seek the head to the specified track.
875 int ftape_seek_head_to_track(unsigned int track)
880 ft_location.track = -1; /* remains set in case of error */
881 if (track >= ft_tracks_per_tape) {
882 TRACE_ABORT(-EINVAL, ft_t_bug, "track out of bounds");
884 TRACE(ft_t_flow, "seeking track %d", track);
885 TRACE_CATCH(ftape_command(QIC_SEEK_HEAD_TO_TRACK),);
886 TRACE_CATCH(ftape_parameter_wait(track, ftape_timeout.head_seek,
888 ft_location.track = track;
889 ftape_might_be_off_track = 0;
893 int ftape_wakeup_drive(wake_up_types method)
900 case wake_up_colorado:
901 TRACE_CATCH(ftape_command(QIC_PHANTOM_SELECT),);
902 TRACE_CATCH(ftape_parameter(0 /* ft_drive_sel ?? */),);
904 case wake_up_mountain:
905 TRACE_CATCH(ftape_command(QIC_SOFT_SELECT),);
906 ftape_sleep(FT_MILLISECOND); /* NEEDED */
907 TRACE_CATCH(ftape_parameter(18),);
909 case wake_up_insight:
910 ftape_sleep(100 * FT_MILLISECOND);
912 fdc_motor(motor_on); /* enable is done by motor-on */
916 TRACE_EXIT -ENODEV; /* unknown wakeup method */
919 /* If wakeup succeeded we shouldn't get an error here..
921 TRACE_CATCH(ftape_report_raw_drive_status(&status),
928 int ftape_put_drive_to_sleep(wake_up_types method)
933 case wake_up_colorado:
934 TRACE_CATCH(ftape_command(QIC_PHANTOM_DESELECT),);
936 case wake_up_mountain:
937 TRACE_CATCH(ftape_command(QIC_SOFT_DESELECT),);
939 case wake_up_insight:
940 fdc_motor(0); /* enable is done by motor-on */
941 case no_wake_up: /* no wakeup / no sleep ! */
944 TRACE_EXIT -ENODEV; /* unknown wakeup method */
949 int ftape_reset_drive(void)
953 unsigned int err_code;
954 qic117_cmd_t err_command;
958 /* We want to re-establish contact with our drive. Fire a
959 * number of reset commands (single step pulses) and pray for
962 for (i = 0; i < 2; ++i) {
963 TRACE(ft_t_flow, "Resetting fdc");
965 ftape_sleep(10 * FT_MILLISECOND);
966 TRACE(ft_t_flow, "Reset command to drive");
967 result = ftape_command(QIC_RESET);
969 ftape_sleep(1 * FT_SECOND); /* drive not
973 TRACE(ft_t_flow, "Re-selecting drive");
975 /* Strange, the QIC-117 specs don't mention
976 * this but the drive gets deselected after a
977 * soft reset ! So we need to enable it
980 if (ftape_wakeup_drive(ft_drive_type.wake_up) < 0) {
981 TRACE(ft_t_err, "Wakeup failed !");
983 TRACE(ft_t_flow, "Waiting until drive gets ready");
984 result= ftape_ready_wait(ftape_timeout.reset, &status);
985 if (result == 0 && (status & QIC_STATUS_ERROR)) {
986 result = ftape_report_error(&err_code,
988 if (result == 0 && err_code == 27) {
989 /* Okay, drive saw reset
990 * command and responded as it
1001 FT_SIGNAL_EXIT(_DONT_BLOCK);
1004 TRACE(ft_t_err, "General failure to reset tape drive");
1006 /* Restore correct settings: keep original rate
1008 ftape_set_data_rate(ft_data_rate, ft_qic_std);
1010 ftape_init_drive_needed = 1;