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/segment.h>
33 #include <asm/system.h>
34 #include <linux/ioctl.h>
35 #include <linux/mtio.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
= 0;
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
= 0;
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 set_current_state(TASK_INTERRUPTIBLE
);
102 /* Mmm. Isn't current->blocked == 0xffffffff ?
104 if (signal_pending(current
)) {
106 "awoken by non-blocked signal :-(");
107 break; /* exit on signal */
109 while (current
->state
!= TASK_RUNNING
) {
110 timeout
= schedule_timeout(timeout
);
113 restore_flags(flags
);
118 /* send a command or parameter to the drive
119 * Generates # of step pulses.
121 static inline int ft_send_to_drive(int arg
)
123 /* Always wait for a command_timeout period to separate
124 * individuals commands and/or parameters.
126 ftape_sleep(3 * FT_MILLISECOND
);
127 /* Keep cylinder nr within range, step towards home if possible.
129 if (ftape_current_cylinder
>= arg
) {
130 return fdc_seek(ftape_current_cylinder
- arg
);
132 return fdc_seek(ftape_current_cylinder
+ arg
);
136 /* forward */ int ftape_report_raw_drive_status(int *status
);
138 static int ft_check_cmd_restrictions(qic117_cmd_t command
)
143 TRACE(ft_t_flow
, "%s", qic117_cmds
[command
].name
);
144 /* A new motion command during an uninterruptible (motion)
145 * command requires a ready status before the new command can
146 * be issued. Otherwise a new motion command needs to be
147 * checked against required status.
149 if (qic117_cmds
[command
].cmd_type
== motion
&&
150 qic117_cmds
[ftape_current_command
].non_intr
) {
151 ftape_report_raw_drive_status(&status
);
152 if ((status
& QIC_STATUS_READY
) == 0) {
154 "motion cmd (%d) during non-intr cmd (%d)",
155 command
, ftape_current_command
);
156 TRACE(ft_t_noise
, "waiting until drive gets ready");
157 ftape_ready_wait(ftape_timeout
.seek
,
161 if (qic117_cmds
[command
].mask
!= 0) {
163 /* Some commands do require a certain status:
165 if (status
== -1) { /* not yet set */
166 ftape_report_raw_drive_status(&status
);
168 difference
= ((status
^ qic117_cmds
[command
].state
) &
169 qic117_cmds
[command
].mask
);
170 /* Wait until the drive gets
171 * ready. This may last forever if
172 * the drive never gets ready...
174 while ((difference
& QIC_STATUS_READY
) != 0) {
175 TRACE(ft_t_noise
, "command %d issued while not ready",
177 TRACE(ft_t_noise
, "waiting until drive gets ready");
178 if (ftape_ready_wait(ftape_timeout
.seek
,
179 &status
) == -EINTR
) {
180 /* Bail out on signal !
182 TRACE_ABORT(-EINTR
, ft_t_warn
,
183 "interrupted by non-blockable signal");
185 difference
= ((status
^ qic117_cmds
[command
].state
) &
186 qic117_cmds
[command
].mask
);
188 while ((difference
& QIC_STATUS_ERROR
) != 0) {
193 "command %d issued while error pending",
195 TRACE(ft_t_noise
, "clearing error status");
196 ftape_report_error(&err
, &cmd
, 1);
197 ftape_report_raw_drive_status(&status
);
198 difference
= ((status
^ qic117_cmds
[command
].state
) &
199 qic117_cmds
[command
].mask
);
200 if ((difference
& QIC_STATUS_ERROR
) != 0) {
201 /* Bail out on fatal signal !
203 FT_SIGNAL_EXIT(_NEVER_BLOCK
);
207 /* Any remaining difference can't be solved
210 if (difference
& (QIC_STATUS_CARTRIDGE_PRESENT
|
211 QIC_STATUS_NEW_CARTRIDGE
|
212 QIC_STATUS_REFERENCED
)) {
214 "Fatal: tape removed or reinserted !");
217 TRACE(ft_t_err
, "wrong state: 0x%02x should be: 0x%02x",
218 status
& qic117_cmds
[command
].mask
,
219 qic117_cmds
[command
].state
);
223 if (~status
& QIC_STATUS_READY
& qic117_cmds
[command
].mask
) {
224 TRACE_ABORT(-EBUSY
, ft_t_err
, "Bad: still busy!");
230 /* Issue a tape command:
232 int ftape_command(qic117_cmd_t command
)
235 static int level
= 0;
238 if ((unsigned int)command
> NR_ITEMS(qic117_cmds
)) {
239 /* This is a bug we'll want to know about too.
241 TRACE_ABORT(-EIO
, ft_t_bug
, "bug - bad command: %d", command
);
243 if (++level
> 5) { /* This is a bug we'll want to know about. */
245 TRACE_ABORT(-EIO
, ft_t_bug
, "bug - recursion for command: %d",
248 /* disable logging and restriction check for some commands,
249 * check all other commands that have a prescribed starting
252 if (diagnostic_mode
) {
253 TRACE(ft_t_flow
, "diagnostic command %d", command
);
254 } else if (command
== QIC_REPORT_DRIVE_STATUS
||
255 command
== QIC_REPORT_NEXT_BIT
) {
256 TRACE(ft_t_any
, "%s", qic117_cmds
[command
].name
);
258 TRACE_CATCH(ft_check_cmd_restrictions(command
), --level
);
260 /* Now all conditions are met or result was < 0.
262 result
= ft_send_to_drive((unsigned int)command
);
263 if (qic117_cmds
[command
].cmd_type
== motion
&&
264 command
!= QIC_LOGICAL_FORWARD
&& command
!= QIC_STOP_TAPE
) {
265 ft_location
.known
= 0;
267 ftape_current_command
= command
;
272 /* Send a tape command parameter:
273 * Generates command # of step pulses.
274 * Skips tape-status call !
276 int ftape_parameter(unsigned int parameter
)
280 TRACE(ft_t_flow
, "called with parameter = %d", parameter
);
281 TRACE_EXIT
ft_send_to_drive(parameter
+ 2);
284 /* Wait for the drive to get ready.
285 * timeout time in milli-seconds
286 * Returned status is valid if result != -EIO
288 * Should we allow to be killed by SIGINT? (^C)
289 * Would be nice at least for large timeouts.
291 int ftape_ready_wait(unsigned int timeout
, int *status
)
294 unsigned int poll_delay
;
298 /* the following ** REALLY ** reduces the system load when
299 * e.g. one simply rewinds or retensions. The tape is slow
300 * anyway. It is really not necessary to detect error
301 * conditions with 1/10 seconds granularity
303 * On my AMD 133MHZ 486: 100 ms: 23% system load
307 if (timeout
<= FT_SECOND
) {
308 poll_delay
= 100 * FT_MILLISECOND
;
309 signal_retries
= 20; /* two seconds */
310 } else if (timeout
< 20 * FT_SECOND
) {
311 TRACE(ft_t_flow
, "setting poll delay to 1 second");
312 poll_delay
= FT_SECOND
;
313 signal_retries
= 2; /* two seconds */
315 TRACE(ft_t_flow
, "setting poll delay to 5 seconds");
316 poll_delay
= 5 * FT_SECOND
;
317 signal_retries
= 1; /* five seconds */
321 TRACE_CATCH(ftape_report_raw_drive_status(status
),);
322 if (*status
& QIC_STATUS_READY
) {
325 if (!signal_retries
--) {
326 FT_SIGNAL_EXIT(_NEVER_BLOCK
);
328 if ((int)timeout
>= 0) {
329 /* this will fail when jiffies wraps around about
330 * once every year :-)
332 timeout
-= ((jiffies
- t0
) * FT_SECOND
) / HZ
;
334 TRACE_ABORT(-ETIME
, ft_t_err
, "timeout");
336 ftape_sleep(poll_delay
);
337 timeout
-= poll_delay
;
339 ftape_sleep(poll_delay
);
345 /* Issue command and wait up to timeout milli seconds for drive ready
347 int ftape_command_wait(qic117_cmd_t command
, unsigned int timeout
, int *status
)
351 /* Drive should be ready, issue command
353 result
= ftape_command(command
);
355 result
= ftape_ready_wait(timeout
, status
);
360 int ftape_parameter_wait(unsigned int parm
, unsigned int timeout
, int *status
)
364 /* Drive should be ready, issue command
366 result
= ftape_parameter(parm
);
368 result
= ftape_ready_wait(timeout
, status
);
373 /*--------------------------------------------------------------------------
377 /* Query the drive about its status. The command is sent and
378 result_length bits of status are returned (2 extra bits are read
379 for start and stop). */
381 int ftape_report_operation(int *status
,
382 qic117_cmd_t command
,
390 TRACE_CATCH(ftape_command(command
),);
391 t0
= ftape_timestamp();
395 ftape_sleep(3 * FT_MILLISECOND
); /* see remark below */
396 TRACE_CATCH(fdc_sense_drive_status(&st3
),);
397 dt
= ftape_timediff(t0
, ftape_timestamp());
398 /* Ack should be asserted within Ttimout + Tack = 6 msec.
399 * Looks like some drives fail to do this so extend this
400 * period to 300 msec.
402 } while (!(st3
& ST3_TRACK_0
) && dt
< 300000);
403 if (!(st3
& ST3_TRACK_0
)) {
405 "No acknowledge after %u msec. (%i iter)", dt
/ 1000, i
);
406 TRACE_ABORT(-EIO
, ft_t_err
, "timeout on Acknowledge");
408 /* dt may be larger than expected because of other tasks
409 * scheduled while we were sleeping.
411 if (i
> 1 && dt
> 6000) {
412 TRACE(ft_t_err
, "Acknowledge after %u msec. (%i iter)",
416 for (i
= 0; i
< result_length
+ 1; i
++) {
417 TRACE_CATCH(ftape_command(QIC_REPORT_NEXT_BIT
),);
418 TRACE_CATCH(fdc_sense_drive_status(&st3
),);
419 if (i
< result_length
) {
420 *status
|= ((st3
& ST3_TRACK_0
) ? 1 : 0) << i
;
421 } else if ((st3
& ST3_TRACK_0
) == 0) {
422 TRACE_ABORT(-EIO
, ft_t_err
, "missing status stop bit");
425 /* this command will put track zero and index back into normal state */
426 (void)ftape_command(QIC_REPORT_NEXT_BIT
);
430 /* Report the current drive status. */
432 int ftape_report_raw_drive_status(int *status
)
439 result
= ftape_report_operation(status
,
440 QIC_REPORT_DRIVE_STATUS
, 8);
441 } while (result
< 0 && ++count
<= 3);
443 TRACE_ABORT(-EIO
, ft_t_err
,
444 "report_operation failed after %d trials", count
);
446 if ((*status
& 0xff) == 0xff) {
447 TRACE_ABORT(-EIO
, ft_t_err
,
448 "impossible drive status 0xff");
450 if (*status
& QIC_STATUS_READY
) {
451 ftape_current_command
= QIC_NO_COMMAND
; /* completed */
453 ft_last_status
.status
.drive_status
= (__u8
)(*status
& 0xff);
457 int ftape_report_drive_status(int *status
)
461 TRACE_CATCH(ftape_report_raw_drive_status(status
),);
462 if (*status
& QIC_STATUS_NEW_CARTRIDGE
||
463 !(*status
& QIC_STATUS_CARTRIDGE_PRESENT
)) {
464 ft_failure
= 1; /* will inhibit further operations */
467 if (*status
& QIC_STATUS_READY
&& *status
& QIC_STATUS_ERROR
) {
468 /* Let caller handle all errors */
469 TRACE_ABORT(1, ft_t_warn
, "warning: error status set!");
474 int ftape_report_error(unsigned int *error
,
475 qic117_cmd_t
*command
, int report
)
477 static const ftape_error ftape_errors
[] = QIC117_ERRORS
;
481 TRACE_CATCH(ftape_report_operation(&code
, QIC_REPORT_ERROR_CODE
, 16),);
482 *error
= (unsigned int)(code
& 0xff);
483 *command
= (qic117_cmd_t
)((code
>>8)&0xff);
484 /* remember hardware status, maybe useful for status ioctls
486 ft_last_error
.error
.command
= (__u8
)*command
;
487 ft_last_error
.error
.error
= (__u8
)*error
;
492 TRACE_ABORT(0, ft_t_info
, "No error");
494 TRACE(ft_t_info
, "errorcode: %d", *error
);
495 if (*error
< NR_ITEMS(ftape_errors
)) {
496 TRACE(ft_t_noise
, "%sFatal ERROR:",
497 (ftape_errors
[*error
].fatal
? "" : "Non-"));
498 TRACE(ft_t_noise
, "%s ...", ftape_errors
[*error
].message
);
500 TRACE(ft_t_noise
, "Unknown ERROR !");
502 if ((unsigned int)*command
< NR_ITEMS(qic117_cmds
) &&
503 qic117_cmds
[*command
].name
!= NULL
) {
504 TRACE(ft_t_noise
, "... caused by command \'%s\'",
505 qic117_cmds
[*command
].name
);
507 TRACE(ft_t_noise
, "... caused by unknown command %d",
513 int ftape_in_error_state(int status
)
517 if ((status
& QIC_STATUS_READY
) && (status
& QIC_STATUS_ERROR
)) {
518 TRACE_ABORT(1, ft_t_warn
, "warning: error status set!");
523 int ftape_report_configuration(qic_model
*model
,
531 static const unsigned int qic_rates
[ 4] = { 250, 2000, 500, 1000 };
534 result
= ftape_report_operation(&config
,
535 QIC_REPORT_DRIVE_CONFIGURATION
, 8);
537 ft_last_status
.status
.drive_config
= (__u8
)0x00;
538 *model
= prehistoric
;
540 *qic_std
= QIC_TAPE_QIC40
;
544 ft_last_status
.status
.drive_config
= (__u8
)(config
& 0xff);
546 *rate
= qic_rates
[(config
& QIC_CONFIG_RATE_MASK
) >> QIC_CONFIG_RATE_SHIFT
];
547 result
= ftape_report_operation(&status
, QIC_REPORT_TAPE_STATUS
, 8);
549 ft_last_status
.status
.tape_status
= (__u8
)0x00;
550 /* pre- QIC117 rev C spec. drive, QIC_CONFIG_80 bit is valid.
552 *qic_std
= (config
& QIC_CONFIG_80
) ?
553 QIC_TAPE_QIC80
: QIC_TAPE_QIC40
;
554 /* ?? how's about 425ft tapes? */
555 *tape_len
= (config
& QIC_CONFIG_LONG
) ? 307 : 0;
556 *model
= pre_qic117c
;
559 ft_last_status
.status
.tape_status
= (__u8
)(status
& 0xff);
560 *model
= post_qic117b
;
561 TRACE(ft_t_any
, "report tape status result = %02x", status
);
562 /* post- QIC117 rev C spec. drive, QIC_CONFIG_80 bit is
565 switch (status
& QIC_TAPE_STD_MASK
) {
568 case QIC_TAPE_QIC3020
:
569 case QIC_TAPE_QIC3010
:
570 *qic_std
= status
& QIC_TAPE_STD_MASK
;
576 switch (status
& QIC_TAPE_LEN_MASK
) {
578 /* 205 or 425+ ft 550 Oe tape */
582 /* 307.5 ft 550 Oe Extended Length (XL) tape */
585 case QIC_TAPE_VARIABLE
:
586 /* Variable length 550 Oe tape */
589 case QIC_TAPE_1100FT
:
590 /* 1100 ft 550 Oe tape */
594 /* Variable length 900 Oe tape */
601 if (*qic_std
== -1 || *tape_len
== -1) {
603 "post qic-117b spec drive with unknown tape");
605 result
= *tape_len
== -1 ? -EIO
: 0;
606 if (status
& QIC_TAPE_WIDE
) {
609 TRACE(ft_t_info
, "TR-1 tape detected");
611 case QIC_TAPE_QIC3010
:
612 TRACE(ft_t_info
, "TR-2 tape detected");
614 case QIC_TAPE_QIC3020
:
615 TRACE(ft_t_info
, "TR-3 tape detected");
619 "Unknown Travan tape type detected");
624 TRACE_EXIT (result
< 0) ? -EIO
: 0;
627 int ftape_report_rom_version(int *version
)
630 if (ftape_report_operation(version
, QIC_REPORT_ROM_VERSION
, 8) < 0) {
637 int ftape_report_signature(int *signature
)
641 result
= ftape_command(28);
642 result
= ftape_report_operation(signature
, 9, 8);
643 result
= ftape_command(30);
644 return (result
< 0) ? -EIO
: 0;
647 void ftape_report_vendor_id(unsigned int *id
)
652 /* We'll try to get a vendor id from the drive. First
653 * according to the QIC-117 spec, a 16-bit id is requested.
654 * If that fails we'll try an 8-bit version, otherwise we'll
655 * try an undocumented query.
657 result
= ftape_report_operation((int *) id
, QIC_REPORT_VENDOR_ID
, 16);
659 result
= ftape_report_operation((int *) id
,
660 QIC_REPORT_VENDOR_ID
, 8);
662 /* The following is an undocumented call found
665 result
= ftape_report_operation((int *) id
, 24, 8);
667 *id
= UNKNOWN_VENDOR
;
669 TRACE(ft_t_noise
, "got old 8 bit id: %04x",
674 TRACE(ft_t_noise
, "got 8 bit id: %04x", *id
);
678 TRACE(ft_t_noise
, "got 16 bit id: %04x", *id
);
684 if (ftape_report_rom_version(&version
) < 0) {
685 TRACE(ft_t_bug
, "report rom version failed");
688 TRACE(ft_t_noise
, "CMS rom version: %d", version
);
689 ftape_command(QIC_ENTER_DIAGNOSTIC_1
);
690 ftape_command(QIC_ENTER_DIAGNOSTIC_1
);
692 if (ftape_report_operation(&sign
, 9, 8) < 0) {
694 qic117_cmd_t command
;
696 ftape_report_error(&error
, &command
, 1);
697 ftape_command(QIC_ENTER_PRIMARY_MODE
);
699 TRACE_EXIT
; /* failure ! */
701 TRACE(ft_t_noise
, "CMS signature: %02x", sign
);
704 result
= ftape_report_operation(&sign
, 37, 8);
709 "This is an Iomega drive !");
713 "This is a real CMS drive !");
717 TRACE(ft_t_noise
, "CMS status: %d", sign
);
720 *id
= UNKNOWN_VENDOR
;
722 ftape_command(QIC_ENTER_PRIMARY_MODE
);
728 static int qic_rate_code(unsigned int rate
)
732 return QIC_CONFIG_RATE_250
;
734 return QIC_CONFIG_RATE_500
;
736 return QIC_CONFIG_RATE_1000
;
738 return QIC_CONFIG_RATE_2000
;
740 return QIC_CONFIG_RATE_500
;
744 static int ftape_set_rate_test(unsigned int *max_rate
)
747 qic117_cmd_t command
;
752 /* Check if the drive does support the select rate command
753 * by testing all different settings. If any one is accepted
754 * we assume the command is supported, else not.
756 for (*max_rate
= 2000; *max_rate
>= 250; *max_rate
/= 2) {
757 if (ftape_command(QIC_SELECT_RATE
) < 0) {
760 if (ftape_parameter_wait(qic_rate_code(*max_rate
),
761 1 * FT_SECOND
, &status
) < 0) {
764 if (status
& QIC_STATUS_ERROR
) {
765 ftape_report_error(&error
, &command
, 0);
768 supported
= 1; /* did accept a request */
771 TRACE(ft_t_noise
, "Select Rate command is%s supported",
772 supported
? "" : " not");
773 TRACE_EXIT supported
;
776 int ftape_set_data_rate(unsigned int new_rate
/* Kbps */, unsigned int qic_std
)
780 unsigned int data_rate
= new_rate
;
781 static int supported
= 0;
782 int rate_changed
= 0;
783 qic_model dummy_model
;
784 unsigned int dummy_qic_std
, dummy_tape_len
;
787 if (ft_drive_max_rate
== 0) { /* first time */
788 supported
= ftape_set_rate_test(&ft_drive_max_rate
);
791 ftape_command(QIC_SELECT_RATE
);
792 result
= ftape_parameter_wait(qic_rate_code(new_rate
),
793 1 * FT_SECOND
, &status
);
794 if (result
>= 0 && !(status
& QIC_STATUS_ERROR
)) {
798 TRACE_CATCH(result
= ftape_report_configuration(&dummy_model
,
802 if (data_rate
!= new_rate
) {
804 TRACE(ft_t_warn
, "Rate change not supported!");
805 } else if (rate_changed
) {
806 TRACE(ft_t_warn
, "Requested: %d, got %d",
807 new_rate
, data_rate
);
809 TRACE(ft_t_warn
, "Rate change failed!");
814 * Set data rate and write precompensation as specified:
816 * | QIC-40/80 | QIC-3010/3020
817 * rate | precomp | precomp
818 * ----------+-------------+--------------
819 * 250 Kbps. | 250 ns. | 0 ns.
820 * 500 Kbps. | 125 ns. | 0 ns.
821 * 1 Mbps. | 42 ns. | 0 ns.
822 * 2 Mbps | N/A | 0 ns.
824 if ((qic_std
== QIC_TAPE_QIC40
&& data_rate
> 500) ||
825 (qic_std
== QIC_TAPE_QIC80
&& data_rate
> 1000)) {
827 ft_t_warn
, "Datarate too high for QIC-mode");
829 TRACE_CATCH(fdc_set_data_rate(data_rate
),_res
= -EINVAL
);
830 ft_data_rate
= data_rate
;
831 if (qic_std
== QIC_TAPE_QIC40
|| qic_std
== QIC_TAPE_QIC80
) {
834 fdc_set_write_precomp(250);
838 fdc_set_write_precomp(125);
841 fdc_set_write_precomp(42);
845 fdc_set_write_precomp(0);
850 /* The next two functions are used to cope with excessive overrun errors
852 int ftape_increase_threshold(void)
854 TRACE_FUN(ft_t_flow
);
856 if (fdc
.type
< i82077
|| ft_fdc_threshold
>= 12) {
857 TRACE_ABORT(-EIO
, ft_t_err
, "cannot increase fifo threshold");
859 if (fdc_fifo_threshold(++ft_fdc_threshold
, NULL
, NULL
, NULL
) < 0) {
860 TRACE(ft_t_err
, "cannot increase fifo threshold");
864 TRACE(ft_t_info
, "New FIFO threshold: %d", ft_fdc_threshold
);
868 int ftape_half_data_rate(void)
870 if (ft_data_rate
< 500) {
873 if (ftape_set_data_rate(ft_data_rate
/ 2, ft_qic_std
) < 0) {
876 ftape_calc_timeouts(ft_qic_std
, ft_data_rate
, ftape_tape_len
);
880 /* Seek the head to the specified track.
882 int ftape_seek_head_to_track(unsigned int track
)
887 ft_location
.track
= -1; /* remains set in case of error */
888 if (track
>= ft_tracks_per_tape
) {
889 TRACE_ABORT(-EINVAL
, ft_t_bug
, "track out of bounds");
891 TRACE(ft_t_flow
, "seeking track %d", track
);
892 TRACE_CATCH(ftape_command(QIC_SEEK_HEAD_TO_TRACK
),);
893 TRACE_CATCH(ftape_parameter_wait(track
, ftape_timeout
.head_seek
,
895 ft_location
.track
= track
;
896 ftape_might_be_off_track
= 0;
900 int ftape_wakeup_drive(wake_up_types method
)
907 case wake_up_colorado
:
908 TRACE_CATCH(ftape_command(QIC_PHANTOM_SELECT
),);
909 TRACE_CATCH(ftape_parameter(0 /* ft_drive_sel ?? */),);
911 case wake_up_mountain
:
912 TRACE_CATCH(ftape_command(QIC_SOFT_SELECT
),);
913 ftape_sleep(FT_MILLISECOND
); /* NEEDED */
914 TRACE_CATCH(ftape_parameter(18),);
916 case wake_up_insight
:
917 ftape_sleep(100 * FT_MILLISECOND
);
919 fdc_motor(motor_on
); /* enable is done by motor-on */
923 TRACE_EXIT
-ENODEV
; /* unknown wakeup method */
926 /* If wakeup succeeded we shouldn't get an error here..
928 TRACE_CATCH(ftape_report_raw_drive_status(&status
),
935 int ftape_put_drive_to_sleep(wake_up_types method
)
940 case wake_up_colorado
:
941 TRACE_CATCH(ftape_command(QIC_PHANTOM_DESELECT
),);
943 case wake_up_mountain
:
944 TRACE_CATCH(ftape_command(QIC_SOFT_DESELECT
),);
946 case wake_up_insight
:
947 fdc_motor(0); /* enable is done by motor-on */
948 case no_wake_up
: /* no wakeup / no sleep ! */
951 TRACE_EXIT
-ENODEV
; /* unknown wakeup method */
956 int ftape_reset_drive(void)
960 unsigned int err_code
;
961 qic117_cmd_t err_command
;
965 /* We want to re-establish contact with our drive. Fire a
966 * number of reset commands (single step pulses) and pray for
969 for (i
= 0; i
< 2; ++i
) {
970 TRACE(ft_t_flow
, "Resetting fdc");
972 ftape_sleep(10 * FT_MILLISECOND
);
973 TRACE(ft_t_flow
, "Reset command to drive");
974 result
= ftape_command(QIC_RESET
);
976 ftape_sleep(1 * FT_SECOND
); /* drive not
980 TRACE(ft_t_flow
, "Re-selecting drive");
982 /* Strange, the QIC-117 specs don't mention
983 * this but the drive gets deselected after a
984 * soft reset ! So we need to enable it
987 if (ftape_wakeup_drive(ft_drive_type
.wake_up
) < 0) {
988 TRACE(ft_t_err
, "Wakeup failed !");
990 TRACE(ft_t_flow
, "Waiting until drive gets ready");
991 result
= ftape_ready_wait(ftape_timeout
.reset
, &status
);
992 if (result
== 0 && (status
& QIC_STATUS_ERROR
)) {
993 result
= ftape_report_error(&err_code
,
995 if (result
== 0 && err_code
== 27) {
996 /* Okay, drive saw reset
997 * command and responded as it
1008 FT_SIGNAL_EXIT(_DONT_BLOCK
);
1011 TRACE(ft_t_err
, "General failure to reset tape drive");
1013 /* Restore correct settings: keep original rate
1015 ftape_set_data_rate(ft_data_rate
, ft_qic_std
);
1017 ftape_init_drive_needed
= 1;