2 * linux/drivers/ide/ide-tape.c Version 1.16f Dec 15, 1999
4 * Copyright (C) 1995 - 1999 Gadi Oxman <gadio@netvision.net.il>
6 * This driver was constructed as a student project in the software laboratory
7 * of the faculty of electrical engineering in the Technion - Israel's
8 * Institute Of Technology, with the guide of Avner Lottem and Dr. Ilana David.
10 * It is hereby placed under the terms of the GNU general public license.
11 * (See linux/COPYING).
15 * IDE ATAPI streaming tape driver.
17 * This driver is a part of the Linux ide driver and works in co-operation
18 * with linux/drivers/block/ide.c.
20 * The driver, in co-operation with ide.c, basically traverses the
21 * request-list for the block device interface. The character device
22 * interface, on the other hand, creates new requests, adds them
23 * to the request-list of the block device, and waits for their completion.
25 * Pipelined operation mode is now supported on both reads and writes.
27 * The block device major and minor numbers are determined from the
28 * tape's relative position in the ide interfaces, as explained in ide.c.
30 * The character device interface consists of the following devices:
32 * ht0 major 37, minor 0 first IDE tape, rewind on close.
33 * ht1 major 37, minor 1 second IDE tape, rewind on close.
35 * nht0 major 37, minor 128 first IDE tape, no rewind on close.
36 * nht1 major 37, minor 129 second IDE tape, no rewind on close.
39 * Run linux/scripts/MAKEDEV.ide to create the above entries.
41 * The general magnetic tape commands compatible interface, as defined by
42 * include/linux/mtio.h, is accessible through the character device.
44 * General ide driver configuration options, such as the interrupt-unmask
45 * flag, can be configured by issuing an ioctl to the block device interface,
46 * as any other ide device.
48 * Our own ide-tape ioctl's can be issued to either the block device or
49 * the character device interface.
51 * Maximal throughput with minimal bus load will usually be achieved in the
54 * 1. ide-tape is operating in the pipelined operation mode.
55 * 2. No buffering is performed by the user backup program.
57 * Testing was done with a 2 GB CONNER CTMA 4000 IDE ATAPI Streaming Tape Drive.
59 * Ver 0.1 Nov 1 95 Pre-working code :-)
60 * Ver 0.2 Nov 23 95 A short backup (few megabytes) and restore procedure
61 * was successful ! (Using tar cvf ... on the block
63 * A longer backup resulted in major swapping, bad
64 * overall Linux performance and eventually failed as
65 * we received non serial read-ahead requests from the
67 * Ver 0.3 Nov 28 95 Long backups are now possible, thanks to the
68 * character device interface. Linux's responsiveness
69 * and performance doesn't seem to be much affected
70 * from the background backup procedure.
71 * Some general mtio.h magnetic tape operations are
72 * now supported by our character device. As a result,
73 * popular tape utilities are starting to work with
75 * The following configurations were tested:
76 * 1. An IDE ATAPI TAPE shares the same interface
77 * and irq with an IDE ATAPI CDROM.
78 * 2. An IDE ATAPI TAPE shares the same interface
79 * and irq with a normal IDE disk.
80 * Both configurations seemed to work just fine !
81 * However, to be on the safe side, it is meanwhile
82 * recommended to give the IDE TAPE its own interface
84 * The one thing which needs to be done here is to
85 * add a "request postpone" feature to ide.c,
86 * so that we won't have to wait for the tape to finish
87 * performing a long media access (DSC) request (such
88 * as a rewind) before we can access the other device
89 * on the same interface. This effect doesn't disturb
90 * normal operation most of the time because read/write
91 * requests are relatively fast, and once we are
92 * performing one tape r/w request, a lot of requests
93 * from the other device can be queued and ide.c will
94 * service all of them after this single tape request.
95 * Ver 1.0 Dec 11 95 Integrated into Linux 1.3.46 development tree.
96 * On each read / write request, we now ask the drive
97 * if we can transfer a constant number of bytes
98 * (a parameter of the drive) only to its buffers,
99 * without causing actual media access. If we can't,
100 * we just wait until we can by polling the DSC bit.
101 * This ensures that while we are not transferring
102 * more bytes than the constant referred to above, the
103 * interrupt latency will not become too high and
104 * we won't cause an interrupt timeout, as happened
105 * occasionally in the previous version.
106 * While polling for DSC, the current request is
107 * postponed and ide.c is free to handle requests from
108 * the other device. This is handled transparently to
109 * ide.c. The hwgroup locking method which was used
110 * in the previous version was removed.
111 * Use of new general features which are provided by
112 * ide.c for use with atapi devices.
113 * (Programming done by Mark Lord)
114 * Few potential bug fixes (Again, suggested by Mark)
115 * Single character device data transfers are now
116 * not limited in size, as they were before.
117 * We are asking the tape about its recommended
118 * transfer unit and send a larger data transfer
119 * as several transfers of the above size.
120 * For best results, use an integral number of this
121 * basic unit (which is shown during driver
122 * initialization). I will soon add an ioctl to get
123 * this important parameter.
124 * Our data transfer buffer is allocated on startup,
125 * rather than before each data transfer. This should
126 * ensure that we will indeed have a data buffer.
127 * Ver 1.1 Dec 14 95 Fixed random problems which occurred when the tape
128 * shared an interface with another device.
129 * (poll_for_dsc was a complete mess).
130 * Removed some old (non-active) code which had
131 * to do with supporting buffer cache originated
133 * The block device interface can now be opened, so
134 * that general ide driver features like the unmask
135 * interrupts flag can be selected with an ioctl.
136 * This is the only use of the block device interface.
137 * New fast pipelined operation mode (currently only on
138 * writes). When using the pipelined mode, the
139 * throughput can potentially reach the maximum
140 * tape supported throughput, regardless of the
141 * user backup program. On my tape drive, it sometimes
142 * boosted performance by a factor of 2. Pipelined
143 * mode is enabled by default, but since it has a few
144 * downfalls as well, you may want to disable it.
145 * A short explanation of the pipelined operation mode
146 * is available below.
147 * Ver 1.2 Jan 1 96 Eliminated pipelined mode race condition.
148 * Added pipeline read mode. As a result, restores
149 * are now as fast as backups.
150 * Optimized shared interface behavior. The new behavior
151 * typically results in better IDE bus efficiency and
152 * higher tape throughput.
153 * Pre-calculation of the expected read/write request
154 * service time, based on the tape's parameters. In
155 * the pipelined operation mode, this allows us to
156 * adjust our polling frequency to a much lower value,
157 * and thus to dramatically reduce our load on Linux,
158 * without any decrease in performance.
159 * Implemented additional mtio.h operations.
160 * The recommended user block size is returned by
161 * the MTIOCGET ioctl.
162 * Additional minor changes.
163 * Ver 1.3 Feb 9 96 Fixed pipelined read mode bug which prevented the
164 * use of some block sizes during a restore procedure.
165 * The character device interface will now present a
166 * continuous view of the media - any mix of block sizes
167 * during a backup/restore procedure is supported. The
168 * driver will buffer the requests internally and
169 * convert them to the tape's recommended transfer
170 * unit, making performance almost independent of the
171 * chosen user block size.
172 * Some improvements in error recovery.
173 * By cooperating with ide-dma.c, bus mastering DMA can
174 * now sometimes be used with IDE tape drives as well.
175 * Bus mastering DMA has the potential to dramatically
176 * reduce the CPU's overhead when accessing the device,
177 * and can be enabled by using hdparm -d1 on the tape's
178 * block device interface. For more info, read the
179 * comments in ide-dma.c.
180 * Ver 1.4 Mar 13 96 Fixed serialize support.
181 * Ver 1.5 Apr 12 96 Fixed shared interface operation, broken in 1.3.85.
182 * Fixed pipelined read mode inefficiency.
183 * Fixed nasty null dereferencing bug.
184 * Ver 1.6 Aug 16 96 Fixed FPU usage in the driver.
185 * Fixed end of media bug.
186 * Ver 1.7 Sep 10 96 Minor changes for the CONNER CTT8000-A model.
187 * Ver 1.8 Sep 26 96 Attempt to find a better balance between good
188 * interactive response and high system throughput.
189 * Ver 1.9 Nov 5 96 Automatically cross encountered filemarks rather
190 * than requiring an explicit FSF command.
191 * Abort pending requests at end of media.
192 * MTTELL was sometimes returning incorrect results.
193 * Return the real block size in the MTIOCGET ioctl.
194 * Some error recovery bug fixes.
195 * Ver 1.10 Nov 5 96 Major reorganization.
196 * Reduced CPU overhead a bit by eliminating internal
198 * Added module support.
199 * Added multiple tape drives support.
200 * Added partition support.
201 * Rewrote DSC handling.
202 * Some portability fixes.
203 * Removed ide-tape.h.
204 * Additional minor changes.
205 * Ver 1.11 Dec 2 96 Bug fix in previous DSC timeout handling.
206 * Use ide_stall_queue() for DSC overlap.
207 * Use the maximum speed rather than the current speed
208 * to compute the request service time.
209 * Ver 1.12 Dec 7 97 Fix random memory overwriting and/or last block data
210 * corruption, which could occur if the total number
211 * of bytes written to the tape was not an integral
212 * number of tape blocks.
213 * Add support for INTERRUPT DRQ devices.
214 * Ver 1.13 Jan 2 98 Add "speed == 0" work-around for HP COLORADO 5GB
215 * Ver 1.14 Dec 30 98 Partial fixes for the Sony/AIWA tape drives.
216 * Replace cli()/sti() with hwgroup spinlocks.
217 * Ver 1.15 Mar 25 99 Fix SMP race condition by replacing hwgroup
218 * spinlock with private per-tape spinlock.
219 * Ver 1.16 Sep 1 99 Add OnStream tape support.
220 * Abort read pipeline on EOD.
221 * Wait for the tape to become ready in case it returns
222 * "in the process of becoming ready" on open().
223 * Fix zero padding of the last written block in
224 * case the tape block size is larger than PAGE_SIZE.
225 * Decrease the default disconnection time to tn.
226 * Ver 1.16e Oct 3 99 Minor fixes.
227 * Ver 1.16e1 Oct 13 99 Patches by Arnold Niessen,
228 * niessen@iae.nl / arnold.niessen@philips.com
229 * GO-1) Undefined code in idetape_read_position
230 * according to Gadi's email
231 * AJN-1) Minor fix asc == 11 should be asc == 0x11
232 * in idetape_issue_packet_command (did effect
233 * debugging output only)
234 * AJN-2) Added more debugging output, and
235 * added ide-tape: where missing. I would also
236 * like to add tape->name where possible
237 * AJN-3) Added different debug_level's
238 * via /proc/ide/hdc/settings
239 * "debug_level" determines amount of debugging output;
240 * can be changed using /proc/ide/hdx/settings
241 * 0 : almost no debugging output
242 * 1 : 0+output errors only
243 * 2 : 1+output all sensekey/asc
244 * 3 : 2+follow all chrdev related procedures
245 * 4 : 3+follow all procedures
246 * 5 : 4+include pc_stack rq_stack info
247 * 6 : 5+USE_COUNT updates
248 * AJN-4) Fixed timeout for retension in idetape_queue_pc_tail
249 * from 5 to 10 minutes
250 * AJN-5) Changed maximum number of blocks to skip when
251 * reading tapes with multiple consecutive write
252 * errors from 100 to 1000 in idetape_get_logical_blk
253 * Proposed changes to code:
254 * 1) output "logical_blk_num" via /proc
255 * 2) output "current_operation" via /proc
256 * 3) Either solve or document the fact that `mt rewind' is
257 * required after reading from /dev/nhtx to be
258 * able to rmmod the idetape module;
259 * Also, sometimes an application finishes but the
260 * device remains `busy' for some time. Same cause ?
261 * Proposed changes to release-notes:
262 * 4) write a simple `quickstart' section in the
263 * release notes; I volunteer if you don't want to
264 * 5) include a pointer to video4linux in the doc
265 * to stimulate video applications
266 * 6) release notes lines 331 and 362: explain what happens
267 * if the application data rate is higher than 1100 KB/s;
268 * similar approach to lower-than-500 kB/s ?
269 * 7) 6.6 Comparison; wouldn't it be better to allow different
270 * strategies for read and write ?
271 * Wouldn't it be better to control the tape buffer
272 * contents instead of the bandwidth ?
273 * 8) line 536: replace will by would (if I understand
274 * this section correctly, a hypothetical and unwanted situation
275 * is being described)
276 * Ver 1.16f Dec 15 99 Change place of the secondary OnStream header frames.
279 * Here are some words from the first releases of hd.c, which are quoted
280 * in ide.c and apply here as well:
282 * | Special care is recommended. Have Fun!
287 * An overview of the pipelined operation mode.
289 * In the pipelined write mode, we will usually just add requests to our
290 * pipeline and return immediately, before we even start to service them. The
291 * user program will then have enough time to prepare the next request while
292 * we are still busy servicing previous requests. In the pipelined read mode,
293 * the situation is similar - we add read-ahead requests into the pipeline,
294 * before the user even requested them.
296 * The pipeline can be viewed as a "safety net" which will be activated when
297 * the system load is high and prevents the user backup program from keeping up
298 * with the current tape speed. At this point, the pipeline will get
299 * shorter and shorter but the tape will still be streaming at the same speed.
300 * Assuming we have enough pipeline stages, the system load will hopefully
301 * decrease before the pipeline is completely empty, and the backup program
302 * will be able to "catch up" and refill the pipeline again.
304 * When using the pipelined mode, it would be best to disable any type of
305 * buffering done by the user program, as ide-tape already provides all the
306 * benefits in the kernel, where it can be done in a more efficient way.
307 * As we will usually not block the user program on a request, the most
308 * efficient user code will then be a simple read-write-read-... cycle.
309 * Any additional logic will usually just slow down the backup process.
311 * Using the pipelined mode, I get a constant over 400 KBps throughput,
312 * which seems to be the maximum throughput supported by my tape.
314 * However, there are some downfalls:
316 * 1. We use memory (for data buffers) in proportional to the number
317 * of pipeline stages (each stage is about 26 KB with my tape).
318 * 2. In the pipelined write mode, we cheat and postpone error codes
319 * to the user task. In read mode, the actual tape position
320 * will be a bit further than the last requested block.
324 * 1. We allocate stages dynamically only when we need them. When
325 * we don't need them, we don't consume additional memory. In
326 * case we can't allocate stages, we just manage without them
327 * (at the expense of decreased throughput) so when Linux is
328 * tight in memory, we will not pose additional difficulties.
330 * 2. The maximum number of stages (which is, in fact, the maximum
331 * amount of memory) which we allocate is limited by the compile
332 * time parameter IDETAPE_MAX_PIPELINE_STAGES.
334 * 3. The maximum number of stages is a controlled parameter - We
335 * don't start from the user defined maximum number of stages
336 * but from the lower IDETAPE_MIN_PIPELINE_STAGES (again, we
337 * will not even allocate this amount of stages if the user
338 * program can't handle the speed). We then implement a feedback
339 * loop which checks if the pipeline is empty, and if it is, we
340 * increase the maximum number of stages as necessary until we
341 * reach the optimum value which just manages to keep the tape
342 * busy with minimum allocated memory or until we reach
343 * IDETAPE_MAX_PIPELINE_STAGES.
347 * In pipelined write mode, ide-tape can not return accurate error codes
348 * to the user program since we usually just add the request to the
349 * pipeline without waiting for it to be serviced. In case an error
350 * occurs, I will report it on the next user request.
352 * In the pipelined read mode, subsequent read requests or forward
353 * filemark spacing will perform correctly, as we preserve all blocks
354 * and filemarks which we encountered during our excess read-ahead.
356 * For accurate tape positioning and error reporting, disabling
357 * pipelined mode might be the best option.
359 * You can enable/disable/tune the pipelined operation mode by adjusting
360 * the compile time parameters below.
364 * Possible improvements.
366 * 1. Support for the ATAPI overlap protocol.
368 * In order to maximize bus throughput, we currently use the DSC
369 * overlap method which enables ide.c to service requests from the
370 * other device while the tape is busy executing a command. The
371 * DSC overlap method involves polling the tape's status register
372 * for the DSC bit, and servicing the other device while the tape
375 * In the current QIC development standard (December 1995),
376 * it is recommended that new tape drives will *in addition*
377 * implement the ATAPI overlap protocol, which is used for the
378 * same purpose - efficient use of the IDE bus, but is interrupt
379 * driven and thus has much less CPU overhead.
381 * ATAPI overlap is likely to be supported in most new ATAPI
382 * devices, including new ATAPI cdroms, and thus provides us
383 * a method by which we can achieve higher throughput when
384 * sharing a (fast) ATA-2 disk with any (slow) new ATAPI device.
387 #define IDETAPE_VERSION "1.16f"
389 #include <linux/config.h>
390 #include <linux/module.h>
391 #include <linux/types.h>
392 #include <linux/string.h>
393 #include <linux/kernel.h>
394 #include <linux/delay.h>
395 #include <linux/timer.h>
396 #include <linux/mm.h>
397 #include <linux/interrupt.h>
398 #include <linux/major.h>
399 #include <linux/devfs_fs_kernel.h>
400 #include <linux/errno.h>
401 #include <linux/genhd.h>
402 #include <linux/malloc.h>
403 #include <linux/pci.h>
404 #include <linux/ide.h>
406 #include <asm/byteorder.h>
408 #include <asm/uaccess.h>
410 #include <asm/unaligned.h>
411 #include <asm/bitops.h>
414 #define NO_LONGER_REQUIRED (1)
419 #define ONSTREAM_DEBUG (0)
420 #define OS_CONFIG_PARTITION (0xff)
421 #define OS_DATA_PARTITION (0)
422 #define OS_PARTITION_VERSION (1)
427 typedef struct os_partition_s
{
431 __u32 first_frame_addr
;
432 __u32 last_frame_addr
;
433 __u32 eod_frame_addr
;
439 typedef struct os_dat_entry_s
{
449 #define OS_DAT_FLAGS_DATA (0xc)
450 #define OS_DAT_FLAGS_MARK (0x1)
452 typedef struct os_dat_s
{
457 os_dat_entry_t dat_list
[16];
463 #define OS_FRAME_TYPE_FILL (0)
464 #define OS_FRAME_TYPE_EOD (1 << 0)
465 #define OS_FRAME_TYPE_MARKER (1 << 1)
466 #define OS_FRAME_TYPE_HEADER (1 << 3)
467 #define OS_FRAME_TYPE_DATA (1 << 7)
472 typedef struct os_aux_s
{
473 __u32 format_id
; /* hardware compability AUX is based on */
474 char application_sig
[4]; /* driver used to write this media */
475 __u32 hdwr
; /* reserved */
476 __u32 update_frame_cntr
; /* for configuration frame */
478 __u8 frame_type_reserved
;
479 __u8 reserved_18_19
[2];
480 os_partition_t partition
;
481 __u8 reserved_36_43
[8];
483 __u32 logical_blk_num_high
;
484 __u32 logical_blk_num
;
486 __u8 reserved188_191
[4];
489 __u32 last_mark_addr
;
490 __u8 reserved204_223
[20];
493 * __u8 app_specific[32];
495 * Linux specific fields:
497 __u32 next_mark_addr
; /* when known, points to next marker */
498 __u8 linux_specific
[28];
500 __u8 reserved_256_511
[256];
503 typedef struct os_header_s
{
507 __u8 reserved10_15
[6];
510 os_partition_t partition
;
514 * OnStream ADRL frame
516 #define OS_FRAME_SIZE (32 * 1024 + 512)
517 #define OS_DATA_SIZE (32 * 1024)
518 #define OS_AUX_SIZE (512)
520 #include <linux/mtio.h>
522 /**************************** Tunable parameters *****************************/
526 * Pipelined mode parameters.
528 * We try to use the minimum number of stages which is enough to
529 * keep the tape constantly streaming. To accomplish that, we implement
530 * a feedback loop around the maximum number of stages:
532 * We start from MIN maximum stages (we will not even use MIN stages
533 * if we don't need them), increment it by RATE*(MAX-MIN)
534 * whenever we sense that the pipeline is empty, until we reach
535 * the optimum value or until we reach MAX.
537 * Setting the following parameter to 0 will disable the pipelined mode.
539 #define IDETAPE_MIN_PIPELINE_STAGES 200
540 #define IDETAPE_MAX_PIPELINE_STAGES 400
541 #define IDETAPE_INCREASE_STAGES_RATE 20
544 * The following are used to debug the driver:
546 * Setting IDETAPE_DEBUG_INFO to 1 will report device capabilities.
547 * Setting IDETAPE_DEBUG_LOG to 1 will log driver flow control.
548 * Setting IDETAPE_DEBUG_BUGS to 1 will enable self-sanity checks in
551 * Setting them to 0 will restore normal operation mode:
553 * 1. Disable logging normal successful operations.
554 * 2. Disable self-sanity checks.
555 * 3. Errors will still be logged, of course.
557 * All the #if DEBUG code will be removed some day, when the driver
558 * is verified to be stable enough. This will make it much more
561 #define IDETAPE_DEBUG_INFO 0
562 #define IDETAPE_DEBUG_LOG 1
563 #define IDETAPE_DEBUG_LOG_VERBOSE 0
564 #define IDETAPE_DEBUG_BUGS 1
567 * After each failed packet command we issue a request sense command
568 * and retry the packet command IDETAPE_MAX_PC_RETRIES times.
570 * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries.
572 #define IDETAPE_MAX_PC_RETRIES 3
575 * With each packet command, we allocate a buffer of
576 * IDETAPE_PC_BUFFER_SIZE bytes. This is used for several packet
577 * commands (Not for READ/WRITE commands).
579 #define IDETAPE_PC_BUFFER_SIZE 256
582 * In various places in the driver, we need to allocate storage
583 * for packet commands and requests, which will remain valid while
584 * we leave the driver to wait for an interrupt or a timeout event.
586 #define IDETAPE_PC_STACK (10 + IDETAPE_MAX_PC_RETRIES)
589 * Some tape drives require a long irq timeout
591 #define IDETAPE_WAIT_CMD (60*HZ)
594 * The following parameter is used to select the point in the internal
595 * tape fifo in which we will start to refill the buffer. Decreasing
596 * the following parameter will improve the system's latency and
597 * interactive response, while using a high value might improve sytem
600 #define IDETAPE_FIFO_THRESHOLD 2
603 * DSC polling parameters.
605 * Polling for DSC (a single bit in the status register) is a very
606 * important function in ide-tape. There are two cases in which we
609 * 1. Before a read/write packet command, to ensure that we
610 * can transfer data from/to the tape's data buffers, without
611 * causing an actual media access. In case the tape is not
612 * ready yet, we take out our request from the device
613 * request queue, so that ide.c will service requests from
614 * the other device on the same interface meanwhile.
616 * 2. After the successful initialization of a "media access
617 * packet command", which is a command which can take a long
618 * time to complete (it can be several seconds or even an hour).
620 * Again, we postpone our request in the middle to free the bus
621 * for the other device. The polling frequency here should be
622 * lower than the read/write frequency since those media access
623 * commands are slow. We start from a "fast" frequency -
624 * IDETAPE_DSC_MA_FAST (one second), and if we don't receive DSC
625 * after IDETAPE_DSC_MA_THRESHOLD (5 minutes), we switch it to a
626 * lower frequency - IDETAPE_DSC_MA_SLOW (1 minute).
628 * We also set a timeout for the timer, in case something goes wrong.
629 * The timeout should be longer then the maximum execution time of a
636 #define IDETAPE_DSC_RW_MIN 5*HZ/100 /* 50 msec */
637 #define IDETAPE_DSC_RW_MAX 40*HZ/100 /* 400 msec */
638 #define IDETAPE_DSC_RW_TIMEOUT 2*60*HZ /* 2 minutes */
639 #define IDETAPE_DSC_MA_FAST 2*HZ /* 2 seconds */
640 #define IDETAPE_DSC_MA_THRESHOLD 5*60*HZ /* 5 minutes */
641 #define IDETAPE_DSC_MA_SLOW 30*HZ /* 30 seconds */
642 #define IDETAPE_DSC_MA_TIMEOUT 2*60*60*HZ /* 2 hours */
644 /*************************** End of tunable parameters ***********************/
647 * Debugging/Performance analysis
651 #define USE_IOTRACE 0
653 #include <linux/io_trace.h>
654 #define IO_IDETAPE_FIFO 500
658 * Read/Write error simulation
660 #define SIMULATE_ERRORS 0
663 * For general magnetic tape device compatibility.
666 idetape_direction_none
,
667 idetape_direction_read
,
668 idetape_direction_write
669 } idetape_chrdev_direction_t
;
672 * Our view of a packet command.
674 typedef struct idetape_packet_command_s
{
675 u8 c
[12]; /* Actual packet bytes */
676 int retries
; /* On each retry, we increment retries */
677 int error
; /* Error code */
678 int request_transfer
; /* Bytes to transfer */
679 int actually_transferred
; /* Bytes actually transferred */
680 int buffer_size
; /* Size of our data buffer */
681 struct buffer_head
*bh
;
684 byte
*buffer
; /* Data buffer */
685 byte
*current_position
; /* Pointer into the above buffer */
686 ide_startstop_t (*callback
) (ide_drive_t
*); /* Called when this packet command is completed */
687 byte pc_buffer
[IDETAPE_PC_BUFFER_SIZE
]; /* Temporary buffer */
688 unsigned int flags
; /* Status/Action bit flags */
692 * Packet command flag bits.
694 #define PC_ABORT 0 /* Set when an error is considered normal - We won't retry */
695 #define PC_WAIT_FOR_DSC 1 /* 1 When polling for DSC on a media access command */
696 #define PC_DMA_RECOMMENDED 2 /* 1 when we prefer to use DMA if possible */
697 #define PC_DMA_IN_PROGRESS 3 /* 1 while DMA in progress */
698 #define PC_DMA_ERROR 4 /* 1 when encountered problem during DMA */
699 #define PC_WRITING 5 /* Data direction */
702 * Capabilities and Mechanical Status Page
705 unsigned page_code
:6; /* Page code - Should be 0x2a */
707 __u8 ps
:1; /* parameters saveable */
708 __u8 page_length
; /* Page Length - Should be 0x12 */
709 __u8 reserved2
, reserved3
;
710 unsigned ro
:1; /* Read Only Mode */
711 unsigned reserved4_1234
:4;
712 unsigned sprev
:1; /* Supports SPACE in the reverse direction */
713 unsigned reserved4_67
:2;
714 unsigned reserved5_012
:3;
715 unsigned efmt
:1; /* Supports ERASE command initiated formatting */
716 unsigned reserved5_4
:1;
717 unsigned qfa
:1; /* Supports the QFA two partition formats */
718 unsigned reserved5_67
:2;
719 unsigned lock
:1; /* Supports locking the volume */
720 unsigned locked
:1; /* The volume is locked */
721 unsigned prevent
:1; /* The device defaults in the prevent state after power up */
722 unsigned eject
:1; /* The device can eject the volume */
723 __u8 disconnect
:1; /* The device can break request > ctl */
725 unsigned ecc
:1; /* Supports error correction */
726 unsigned cmprs
:1; /* Supports data compression */
727 unsigned reserved7_0
:1;
728 unsigned blk512
:1; /* Supports 512 bytes block size */
729 unsigned blk1024
:1; /* Supports 1024 bytes block size */
730 unsigned reserved7_3_6
:4;
731 unsigned blk32768
:1; /* slowb - the device restricts the byte count for PIO */
732 /* transfers for slow buffer memory ??? */
733 /* Also 32768 block size in some cases */
734 __u16 max_speed
; /* Maximum speed supported in KBps */
735 __u8 reserved10
, reserved11
;
736 __u16 ctl
; /* Continuous Transfer Limit in blocks */
737 __u16 speed
; /* Current Speed, in KBps */
738 __u16 buffer_size
; /* Buffer Size, in 512 bytes */
739 __u8 reserved18
, reserved19
;
740 } idetape_capabilities_page_t
;
746 unsigned page_code
:6; /* Page code - Should be 0x30 */
747 unsigned reserved1_6
:1;
749 __u8 page_length
; /* Page Length - Should be 2 */
752 unsigned play32_5
:1;
753 unsigned reserved2_23
:2;
754 unsigned record32
:1;
755 unsigned record32_5
:1;
756 unsigned reserved2_6
:1;
758 } idetape_block_size_page_t
;
763 typedef struct idetape_stage_s
{
764 struct request rq
; /* The corresponding request */
765 struct buffer_head
*bh
; /* The data buffers */
766 struct idetape_stage_s
*next
; /* Pointer to the next stage */
767 os_aux_t
*aux
; /* OnStream aux ptr */
771 * REQUEST SENSE packet command result - Data Format.
774 unsigned error_code
:7; /* Current of deferred errors */
775 unsigned valid
:1; /* The information field conforms to QIC-157C */
776 __u8 reserved1
:8; /* Segment Number - Reserved */
777 unsigned sense_key
:4; /* Sense Key */
778 unsigned reserved2_4
:1; /* Reserved */
779 unsigned ili
:1; /* Incorrect Length Indicator */
780 unsigned eom
:1; /* End Of Medium */
781 unsigned filemark
:1; /* Filemark */
782 __u32 information
__attribute__ ((packed
));
783 __u8 asl
; /* Additional sense length (n-7) */
784 __u32 command_specific
; /* Additional command specific information */
785 __u8 asc
; /* Additional Sense Code */
786 __u8 ascq
; /* Additional Sense Code Qualifier */
787 __u8 replaceable_unit_code
; /* Field Replaceable Unit Code */
788 unsigned sk_specific1
:7; /* Sense Key Specific */
789 unsigned sksv
:1; /* Sense Key Specific information is valid */
790 __u8 sk_specific2
; /* Sense Key Specific */
791 __u8 sk_specific3
; /* Sense Key Specific */
792 __u8 pad
[2]; /* Padding to 20 bytes */
793 } idetape_request_sense_result_t
;
797 * Most of our global data which we need to save even as we leave the
798 * driver due to an interrupt or a timer event is stored in a variable
799 * of type idetape_tape_t, defined below.
803 devfs_handle_t de_r
, de_n
;
806 * Since a typical character device operation requires more
807 * than one packet command, we provide here enough memory
808 * for the maximum of interconnected packet commands.
809 * The packet commands are stored in the circular array pc_stack.
810 * pc_stack_index points to the last used entry, and warps around
811 * to the start when we get to the last array entry.
813 * pc points to the current processed packet command.
815 * failed_pc points to the last failed packet command, or contains
816 * NULL if we do not need to retry any packet command. This is
817 * required since an additional packet command is needed before the
818 * retry, to get detailed information on what went wrong.
820 idetape_pc_t
*pc
; /* Current packet command */
821 idetape_pc_t
*failed_pc
; /* Last failed packet command */
822 idetape_pc_t pc_stack
[IDETAPE_PC_STACK
];/* Packet command stack */
823 int pc_stack_index
; /* Next free packet command storage space */
824 struct request rq_stack
[IDETAPE_PC_STACK
];
825 int rq_stack_index
; /* We implement a circular array */
828 * DSC polling variables.
830 * While polling for DSC we use postponed_rq to postpone the
831 * current request so that ide.c will be able to service
832 * pending requests on the other device. Note that at most
833 * we will have only one DSC (usually data transfer) request
834 * in the device request queue. Additional requests can be
835 * queued in our internal pipeline, but they will be visible
836 * to ide.c only one at a time.
838 struct request
*postponed_rq
;
839 unsigned long dsc_polling_start
; /* The time in which we started polling for DSC */
840 struct timer_list dsc_timer
; /* Timer used to poll for dsc */
841 unsigned long best_dsc_rw_frequency
; /* Read/Write dsc polling frequency */
842 unsigned long dsc_polling_frequency
; /* The current polling frequency */
843 unsigned long dsc_timeout
; /* Maximum waiting time */
846 * Read position information
849 unsigned int first_frame_position
; /* Current block */
850 unsigned int last_frame_position
;
851 unsigned int blocks_in_buffer
;
854 * Last error information
856 byte sense_key
, asc
, ascq
;
859 * Character device operation
862 char name
[4]; /* device name */
863 idetape_chrdev_direction_t chrdev_direction
; /* Current character device data transfer direction */
868 unsigned short tape_block_size
; /* Usually 512 or 1024 bytes */
870 idetape_capabilities_page_t capabilities
; /* Copy of the tape's Capabilities and Mechanical Page */
873 * Active data transfer request parameters.
875 * At most, there is only one ide-tape originated data transfer
876 * request in the device request queue. This allows ide.c to
877 * easily service requests from the other device when we
878 * postpone our active request. In the pipelined operation
879 * mode, we use our internal pipeline structure to hold
880 * more data requests.
882 * The data buffer size is chosen based on the tape's
885 struct request
*active_data_request
; /* Pointer to the request which is waiting in the device request queue */
886 int stage_size
; /* Data buffer size (chosen based on the tape's recommendation */
887 idetape_stage_t
*merge_stage
;
888 int merge_stage_size
;
889 struct buffer_head
*bh
;
894 * Pipeline parameters.
896 * To accomplish non-pipelined mode, we simply set the following
897 * variables to zero (or NULL, where appropriate).
899 int nr_stages
; /* Number of currently used stages */
900 int nr_pending_stages
; /* Number of pending stages */
901 int max_stages
, min_pipeline
, max_pipeline
; /* We will not allocate more than this number of stages */
902 idetape_stage_t
*first_stage
; /* The first stage which will be removed from the pipeline */
903 idetape_stage_t
*active_stage
; /* The currently active stage */
904 idetape_stage_t
*next_stage
; /* Will be serviced after the currently active request */
905 idetape_stage_t
*last_stage
; /* New requests will be added to the pipeline here */
906 idetape_stage_t
*cache_stage
; /* Optional free stage which we can use */
908 int excess_bh_size
; /* Wasted space in each stage */
910 unsigned int flags
; /* Status/Action flags */
911 spinlock_t spinlock
; /* protects the ide-tape queue */
914 * Measures average tape speed
916 unsigned long avg_time
;
920 idetape_request_sense_result_t sense
; /* last sense information */
924 char firmware_revision
[6];
925 int firmware_revision_num
;
927 int door_locked
; /* the door is currently locked */
932 int onstream
; /* the tape is an OnStream tape */
933 int raw
; /* OnStream raw access (32.5KB block size) */
934 int cur_frames
; /* current number of frames in internal buffer */
935 int max_frames
; /* max number of frames in internal buffer */
936 int logical_blk_num
; /* logical block number */
937 __u16 wrt_pass_cntr
; /* write pass counter */
938 __u32 update_frame_cntr
; /* update frame counter */
939 struct semaphore
*sem
;
940 int onstream_write_error
; /* write error recovery active */
941 int header_ok
; /* header frame verified ok */
942 int linux_media
; /* reading linux-specifc media */
943 int linux_media_version
;
944 char application_sig
[5]; /* application signature */
949 unsigned long cmd_start_time
;
950 unsigned long max_cmd_time
;
953 * Optimize the number of "buffer filling"
954 * mode sense commands.
956 unsigned long last_buffer_fill
; /* last time in which we issued fill cmd */
957 int req_buffer_fill
; /* buffer fill command requested */
958 int writes_since_buffer_fill
;
959 int reads_since_buffer_fill
;
962 * Limit the number of times a request can
963 * be postponed, to avoid an infinite postpone
966 int postpone_cnt
; /* request postpone count limit */
969 * Measures number of frames:
971 * 1. written/read to/from the driver pipeline (pipeline_head).
972 * 2. written/read to/from the tape buffers (buffer_head).
973 * 3. written/read by the tape to/from the media (tape_head).
981 * Speed control at the tape buffers input/output
983 unsigned long insert_time
;
986 int max_insert_speed
;
987 int measure_insert_time
;
990 * Measure tape still time, in milliseconds
992 unsigned long tape_still_time_begin
;
996 * Speed regulation negative feedback loop
999 int pipeline_head_speed
, controlled_pipeline_head_speed
, uncontrolled_pipeline_head_speed
;
1000 int controlled_last_pipeline_head
, uncontrolled_last_pipeline_head
;
1001 unsigned long uncontrolled_pipeline_head_time
, controlled_pipeline_head_time
;
1002 int controlled_previous_pipeline_head
, uncontrolled_previous_pipeline_head
;
1003 unsigned long controlled_previous_head_time
, uncontrolled_previous_head_time
;
1004 int restart_speed_control_req
;
1007 * Debug_level determines amount of debugging output;
1008 * can be changed using /proc/ide/hdx/settings
1009 * 0 : almost no debugging output
1010 * 1 : 0+output errors only
1011 * 2 : 1+output all sensekey/asc
1012 * 3 : 2+follow all chrdev related procedures
1013 * 4 : 3+follow all procedures
1014 * 5 : 4+include pc_stack rq_stack info
1015 * 6 : 5+USE_COUNT updates
1023 #define DOOR_UNLOCKED 0
1024 #define DOOR_LOCKED 1
1025 #define DOOR_EXPLICITLY_LOCKED 2
1028 * Tape flag bits values.
1030 #define IDETAPE_IGNORE_DSC 0
1031 #define IDETAPE_ADDRESS_VALID 1 /* 0 When the tape position is unknown */
1032 #define IDETAPE_BUSY 2 /* Device already opened */
1033 #define IDETAPE_PIPELINE_ERROR 3 /* Error detected in a pipeline stage */
1034 #define IDETAPE_DETECT_BS 4 /* Attempt to auto-detect the current user block size */
1035 #define IDETAPE_FILEMARK 5 /* Currently on a filemark */
1036 #define IDETAPE_DRQ_INTERRUPT 6 /* DRQ interrupt device */
1037 #define IDETAPE_READ_ERROR 7
1038 #define IDETAPE_PIPELINE_ACTIVE 8 /* pipeline active */
1041 * Supported ATAPI tape drives packet commands
1043 #define IDETAPE_TEST_UNIT_READY_CMD 0x00
1044 #define IDETAPE_REWIND_CMD 0x01
1045 #define IDETAPE_REQUEST_SENSE_CMD 0x03
1046 #define IDETAPE_READ_CMD 0x08
1047 #define IDETAPE_WRITE_CMD 0x0a
1048 #define IDETAPE_WRITE_FILEMARK_CMD 0x10
1049 #define IDETAPE_SPACE_CMD 0x11
1050 #define IDETAPE_INQUIRY_CMD 0x12
1051 #define IDETAPE_ERASE_CMD 0x19
1052 #define IDETAPE_MODE_SENSE_CMD 0x1a
1053 #define IDETAPE_MODE_SELECT_CMD 0x15
1054 #define IDETAPE_LOAD_UNLOAD_CMD 0x1b
1055 #define IDETAPE_PREVENT_CMD 0x1e
1056 #define IDETAPE_LOCATE_CMD 0x2b
1057 #define IDETAPE_READ_POSITION_CMD 0x34
1058 #define IDETAPE_READ_BUFFER_CMD 0x3c
1059 #define IDETAPE_SET_SPEED_CMD 0xbb
1062 * Some defines for the READ BUFFER command
1064 #define IDETAPE_RETRIEVE_FAULTY_BLOCK 6
1067 * Some defines for the SPACE command
1069 #define IDETAPE_SPACE_OVER_FILEMARK 1
1070 #define IDETAPE_SPACE_TO_EOD 3
1073 * Some defines for the LOAD UNLOAD command
1075 #define IDETAPE_LU_LOAD_MASK 1
1076 #define IDETAPE_LU_RETENSION_MASK 2
1077 #define IDETAPE_LU_EOT_MASK 4
1080 * Special requests for our block device strategy routine.
1082 * In order to service a character device command, we add special
1083 * requests to the tail of our block device request queue and wait
1084 * for their completion.
1087 #define IDETAPE_FIRST_RQ 90
1090 * IDETAPE_PC_RQ is used to queue a packet command in the request queue.
1092 #define IDETAPE_PC_RQ1 90
1093 #define IDETAPE_PC_RQ2 91
1096 * IDETAPE_READ_RQ and IDETAPE_WRITE_RQ are used by our
1097 * character device interface to request read/write operations from
1098 * our block device interface.
1100 #define IDETAPE_READ_RQ 92
1101 #define IDETAPE_WRITE_RQ 93
1102 #define IDETAPE_ABORTED_WRITE_RQ 94
1103 #define IDETAPE_ABORTED_READ_RQ 95
1104 #define IDETAPE_READ_BUFFER_RQ 96
1106 #define IDETAPE_LAST_RQ 96
1109 * A macro which can be used to check if a we support a given
1112 #define IDETAPE_RQ_CMD(cmd) ((cmd >= IDETAPE_FIRST_RQ) && (cmd <= IDETAPE_LAST_RQ))
1115 * Error codes which are returned in rq->errors to the higher part
1118 #define IDETAPE_ERROR_GENERAL 101
1119 #define IDETAPE_ERROR_FILEMARK 102
1120 #define IDETAPE_ERROR_EOD 103
1123 * The ATAPI Status Register.
1128 unsigned check
:1; /* Error occurred */
1129 unsigned idx
:1; /* Reserved */
1130 unsigned corr
:1; /* Correctable error occurred */
1131 unsigned drq
:1; /* Data is request by the device */
1132 unsigned dsc
:1; /* Buffer availability / Media access command finished */
1133 unsigned reserved5
:1; /* Reserved */
1134 unsigned drdy
:1; /* Ignored for ATAPI commands (ready to accept ATA command) */
1135 unsigned bsy
:1; /* The device has access to the command block */
1137 } idetape_status_reg_t
;
1140 * The ATAPI error register.
1145 unsigned ili
:1; /* Illegal Length Indication */
1146 unsigned eom
:1; /* End Of Media Detected */
1147 unsigned abrt
:1; /* Aborted command - As defined by ATA */
1148 unsigned mcr
:1; /* Media Change Requested - As defined by ATA */
1149 unsigned sense_key
:4; /* Sense key of the last failed packet command */
1151 } idetape_error_reg_t
;
1154 * ATAPI Feature Register
1159 unsigned dma
:1; /* Using DMA of PIO */
1160 unsigned reserved321
:3; /* Reserved */
1161 unsigned reserved654
:3; /* Reserved (Tag Type) */
1162 unsigned reserved7
:1; /* Reserved */
1164 } idetape_feature_reg_t
;
1167 * ATAPI Byte Count Register.
1172 unsigned low
:8; /* LSB */
1173 unsigned high
:8; /* MSB */
1175 } idetape_bcount_reg_t
;
1178 * ATAPI Interrupt Reason Register.
1183 unsigned cod
:1; /* Information transferred is command (1) or data (0) */
1184 unsigned io
:1; /* The device requests us to read (1) or write (0) */
1185 unsigned reserved
:6; /* Reserved */
1187 } idetape_ireason_reg_t
;
1190 * ATAPI Drive Select Register
1195 unsigned sam_lun
:4; /* Should be zero with ATAPI (not used) */
1196 unsigned drv
:1; /* The responding drive will be drive 0 (0) or drive 1 (1) */
1197 unsigned one5
:1; /* Should be set to 1 */
1198 unsigned reserved6
:1; /* Reserved */
1199 unsigned one7
:1; /* Should be set to 1 */
1201 } idetape_drivesel_reg_t
;
1204 * ATAPI Device Control Register
1209 unsigned zero0
:1; /* Should be set to zero */
1210 unsigned nien
:1; /* Device interrupt is disabled (1) or enabled (0) */
1211 unsigned srst
:1; /* ATA software reset. ATAPI devices should use the new ATAPI srst. */
1212 unsigned one3
:1; /* Should be set to 1 */
1213 unsigned reserved4567
:4; /* Reserved */
1215 } idetape_control_reg_t
;
1218 * idetape_chrdev_t provides the link between out character device
1219 * interface and our block device interface and the corresponding
1220 * ide_drive_t structure.
1227 * The following is used to format the general configuration word of
1228 * the ATAPI IDENTIFY DEVICE command.
1230 struct idetape_id_gcw
{
1231 unsigned packet_size
:2; /* Packet Size */
1232 unsigned reserved234
:3; /* Reserved */
1233 unsigned drq_type
:2; /* Command packet DRQ type */
1234 unsigned removable
:1; /* Removable media */
1235 unsigned device_type
:5; /* Device type */
1236 unsigned reserved13
:1; /* Reserved */
1237 unsigned protocol
:2; /* Protocol type */
1241 * INQUIRY packet command - Data Format (From Table 6-8 of QIC-157C)
1244 unsigned device_type
:5; /* Peripheral Device Type */
1245 unsigned reserved0_765
:3; /* Peripheral Qualifier - Reserved */
1246 unsigned reserved1_6t0
:7; /* Reserved */
1247 unsigned rmb
:1; /* Removable Medium Bit */
1248 unsigned ansi_version
:3; /* ANSI Version */
1249 unsigned ecma_version
:3; /* ECMA Version */
1250 unsigned iso_version
:2; /* ISO Version */
1251 unsigned response_format
:4; /* Response Data Format */
1252 unsigned reserved3_45
:2; /* Reserved */
1253 unsigned reserved3_6
:1; /* TrmIOP - Reserved */
1254 unsigned reserved3_7
:1; /* AENC - Reserved */
1255 __u8 additional_length
; /* Additional Length (total_length-4) */
1256 __u8 rsv5
, rsv6
, rsv7
; /* Reserved */
1257 __u8 vendor_id
[8]; /* Vendor Identification */
1258 __u8 product_id
[16]; /* Product Identification */
1259 __u8 revision_level
[4]; /* Revision Level */
1260 __u8 vendor_specific
[20]; /* Vendor Specific - Optional */
1261 __u8 reserved56t95
[40]; /* Reserved - Optional */
1262 /* Additional information may be returned */
1263 } idetape_inquiry_result_t
;
1266 * READ POSITION packet command - Data Format (From Table 6-57)
1269 unsigned reserved0_10
:2; /* Reserved */
1270 unsigned bpu
:1; /* Block Position Unknown */
1271 unsigned reserved0_543
:3; /* Reserved */
1272 unsigned eop
:1; /* End Of Partition */
1273 unsigned bop
:1; /* Beginning Of Partition */
1274 u8 partition
; /* Partition Number */
1275 u8 reserved2
, reserved3
; /* Reserved */
1276 u32 first_block
; /* First Block Location */
1277 u32 last_block
; /* Last Block Location (Optional) */
1278 u8 reserved12
; /* Reserved */
1279 u8 blocks_in_buffer
[3]; /* Blocks In Buffer - (Optional) */
1280 u32 bytes_in_buffer
; /* Bytes In Buffer (Optional) */
1281 } idetape_read_position_result_t
;
1284 * Follows structures which are related to the SELECT SENSE / MODE SENSE
1285 * packet commands. Those packet commands are still not supported
1288 #define IDETAPE_CAPABILITIES_PAGE 0x2a
1289 #define IDETAPE_BLOCK_SIZE_PAGE 0x30
1292 * Mode Parameter Header for the MODE SENSE packet command
1295 __u8 mode_data_length
; /* Length of the following data transfer */
1296 __u8 medium_type
; /* Medium Type */
1297 __u8 dsp
; /* Device Specific Parameter */
1298 __u8 bdl
; /* Block Descriptor Length */
1300 /* data transfer page */
1302 __u8 reserved0_6
:1;
1303 __u8 ps
:1; /* parameters saveable */
1304 __u8 page_length
; /* page Length == 0x02 */
1306 __u8 read32k
:1; /* 32k blk size (data only) */
1307 __u8 read32k5
:1; /* 32.5k blk size (data&AUX) */
1308 __u8 reserved3_23
:2;
1309 __u8 write32k
:1; /* 32k blk size (data only) */
1310 __u8 write32k5
:1; /* 32.5k blk size (data&AUX) */
1311 __u8 reserved3_6
:1;
1312 __u8 streaming
:1; /* streaming mode enable */
1314 } idetape_mode_parameter_header_t
;
1317 * Mode Parameter Block Descriptor the MODE SENSE packet command
1319 * Support for block descriptors is optional.
1322 __u8 density_code
; /* Medium density code */
1323 __u8 blocks
[3]; /* Number of blocks */
1324 __u8 reserved4
; /* Reserved */
1325 __u8 length
[3]; /* Block Length */
1326 } idetape_parameter_block_descriptor_t
;
1329 * The Data Compression Page, as returned by the MODE SENSE packet command.
1332 unsigned page_code
:6; /* Page Code - Should be 0xf */
1333 unsigned reserved0
:1; /* Reserved */
1335 __u8 page_length
; /* Page Length - Should be 14 */
1336 unsigned reserved2
:6; /* Reserved */
1337 unsigned dcc
:1; /* Data Compression Capable */
1338 unsigned dce
:1; /* Data Compression Enable */
1339 unsigned reserved3
:5; /* Reserved */
1340 unsigned red
:2; /* Report Exception on Decompression */
1341 unsigned dde
:1; /* Data Decompression Enable */
1342 __u32 ca
; /* Compression Algorithm */
1343 __u32 da
; /* Decompression Algorithm */
1344 __u8 reserved
[4]; /* Reserved */
1345 } idetape_data_compression_page_t
;
1348 * The Medium Partition Page, as returned by the MODE SENSE packet command.
1351 unsigned page_code
:6; /* Page Code - Should be 0x11 */
1352 unsigned reserved1_6
:1; /* Reserved */
1354 __u8 page_length
; /* Page Length - Should be 6 */
1355 __u8 map
; /* Maximum Additional Partitions - Should be 0 */
1356 __u8 apd
; /* Additional Partitions Defined - Should be 0 */
1357 unsigned reserved4_012
:3; /* Reserved */
1358 unsigned psum
:2; /* Should be 0 */
1359 unsigned idp
:1; /* Should be 0 */
1360 unsigned sdp
:1; /* Should be 0 */
1361 unsigned fdp
:1; /* Fixed Data Partitions */
1362 __u8 mfr
; /* Medium Format Recognition */
1363 __u8 reserved
[2]; /* Reserved */
1364 } idetape_medium_partition_page_t
;
1367 * Run time configurable parameters.
1370 int dsc_rw_frequency
;
1371 int dsc_media_access_frequency
;
1376 * The variables below are used for the character device interface.
1377 * Additional state variables are defined in our ide_drive_t structure.
1379 static idetape_chrdev_t idetape_chrdevs
[MAX_HWIFS
* MAX_DRIVES
];
1380 static int idetape_chrdev_present
= 0;
1382 #if IDETAPE_DEBUG_LOG_VERBOSE
1385 * DO NOT REMOVE, BUILDING A VERBOSE DEBUG SCHEME FOR ATAPI
1388 char *idetape_sense_key_verbose (byte idetape_sense_key
)
1390 switch (idetape_sense_key
) {
1393 sprintf(buf
, "IDETAPE_SENSE (0x%02x)", idetape_sense_key
);
1400 char *idetape_command_key_verbose (byte idetape_command_key
)
1402 switch (idetape_command_key
) {
1403 case IDETAPE_TEST_UNIT_READY_CMD
: return("TEST_UNIT_READY_CMD");
1404 case IDETAPE_REWIND_CMD
: return("REWIND_CMD");
1405 case IDETAPE_REQUEST_SENSE_CMD
: return("REQUEST_SENSE_CMD");
1406 case IDETAPE_READ_CMD
: return("READ_CMD");
1407 case IDETAPE_WRITE_CMD
: return("WRITE_CMD");
1408 case IDETAPE_WRITE_FILEMARK_CMD
: return("WRITE_FILEMARK_CMD");
1409 case IDETAPE_SPACE_CMD
: return("SPACE_CMD");
1410 case IDETAPE_INQUIRY_CMD
: return("INQUIRY_CMD");
1411 case IDETAPE_ERASE_CMD
: return("ERASE_CMD")
1412 case IDETAPE_MODE_SENSE_CMD
: return("MODE_SENSE_CMD");
1413 case IDETAPE_MODE_SELECT_CMD
: return("MODE_SELECT_CMD");
1414 case IDETAPE_LOAD_UNLOAD_CMD
: return("LOAD_UNLOAD_CMD");
1415 case IDETAPE_PREVENT_CMD
: return("PREVENT_CMD");
1416 case IDETAPE_LOCATE_CMD
: return("LOCATE_CMD");
1417 case IDETAPE_READ_POSITION_CMD
: return("READ_POSITION_CMD");
1418 case IDETAPE_READ_BUFFER_CMD
: return("READ_BUFFER_CMD");
1419 case IDETAPE_SET_SPEED_CMD
: return("SET_SPEED_CMD");
1422 sprintf(buf
, "CMD (0x%02x)", idetape_command_key
);
1427 #endif /* IDETAPE_DEBUG_LOG_VERBOSE */
1430 * Too bad. The drive wants to send us data which we are not ready to accept.
1431 * Just throw it away.
1433 static void idetape_discard_data (ide_drive_t
*drive
, unsigned int bcount
)
1436 IN_BYTE (IDE_DATA_REG
);
1439 static void idetape_input_buffers (ide_drive_t
*drive
, idetape_pc_t
*pc
, unsigned int bcount
)
1441 struct buffer_head
*bh
= pc
->bh
;
1445 #if IDETAPE_DEBUG_BUGS
1447 printk (KERN_ERR
"ide-tape: bh == NULL in idetape_input_buffers\n");
1448 idetape_discard_data (drive
, bcount
);
1451 #endif /* IDETAPE_DEBUG_BUGS */
1452 count
= IDE_MIN (bh
->b_size
- atomic_read(&bh
->b_count
), bcount
);
1453 atapi_input_bytes (drive
, bh
->b_data
+ atomic_read(&bh
->b_count
), count
);
1454 bcount
-= count
; atomic_add(count
, &bh
->b_count
);
1455 if (atomic_read(&bh
->b_count
) == bh
->b_size
) {
1458 atomic_set(&bh
->b_count
, 0);
1464 static void idetape_output_buffers (ide_drive_t
*drive
, idetape_pc_t
*pc
, unsigned int bcount
)
1466 struct buffer_head
*bh
= pc
->bh
;
1470 #if IDETAPE_DEBUG_BUGS
1472 printk (KERN_ERR
"ide-tape: bh == NULL in idetape_output_buffers\n");
1475 #endif /* IDETAPE_DEBUG_BUGS */
1476 count
= IDE_MIN (pc
->b_count
, bcount
);
1477 atapi_output_bytes (drive
, pc
->b_data
, count
);
1478 bcount
-= count
; pc
->b_data
+= count
; pc
->b_count
-= count
;
1480 pc
->bh
= bh
= bh
->b_reqnext
;
1482 pc
->b_data
= bh
->b_data
;
1483 pc
->b_count
= atomic_read(&bh
->b_count
);
1489 #ifdef CONFIG_BLK_DEV_IDEDMA
1490 static void idetape_update_buffers (idetape_pc_t
*pc
)
1492 struct buffer_head
*bh
= pc
->bh
;
1493 int count
, bcount
= pc
->actually_transferred
;
1495 if (test_bit (PC_WRITING
, &pc
->flags
))
1498 #if IDETAPE_DEBUG_BUGS
1500 printk (KERN_ERR
"ide-tape: bh == NULL in idetape_update_buffers\n");
1503 #endif /* IDETAPE_DEBUG_BUGS */
1504 count
= IDE_MIN (bh
->b_size
, bcount
);
1505 atomic_set(&bh
->b_count
, count
);
1506 if (atomic_read(&bh
->b_count
) == bh
->b_size
)
1512 #endif /* CONFIG_BLK_DEV_IDEDMA */
1515 * idetape_next_pc_storage returns a pointer to a place in which we can
1516 * safely store a packet command, even though we intend to leave the
1517 * driver. A storage space for a maximum of IDETAPE_PC_STACK packet
1518 * commands is allocated at initialization time.
1520 static idetape_pc_t
*idetape_next_pc_storage (ide_drive_t
*drive
)
1522 idetape_tape_t
*tape
= drive
->driver_data
;
1524 #if IDETAPE_DEBUG_LOG
1525 if (tape
->debug_level
>= 5)
1526 printk (KERN_INFO
"ide-tape: pc_stack_index=%d\n",tape
->pc_stack_index
);
1527 #endif /* IDETAPE_DEBUG_LOG */
1528 if (tape
->pc_stack_index
==IDETAPE_PC_STACK
)
1529 tape
->pc_stack_index
=0;
1530 return (&tape
->pc_stack
[tape
->pc_stack_index
++]);
1534 * idetape_next_rq_storage is used along with idetape_next_pc_storage.
1535 * Since we queue packet commands in the request queue, we need to
1536 * allocate a request, along with the allocation of a packet command.
1539 /**************************************************************
1541 * This should get fixed to use kmalloc(GFP_ATOMIC, ..) *
1542 * followed later on by kfree(). -ml *
1544 **************************************************************/
1546 static struct request
*idetape_next_rq_storage (ide_drive_t
*drive
)
1548 idetape_tape_t
*tape
= drive
->driver_data
;
1550 #if IDETAPE_DEBUG_LOG
1551 if (tape
->debug_level
>= 5)
1552 printk (KERN_INFO
"ide-tape: rq_stack_index=%d\n",tape
->rq_stack_index
);
1553 #endif /* IDETAPE_DEBUG_LOG */
1554 if (tape
->rq_stack_index
==IDETAPE_PC_STACK
)
1555 tape
->rq_stack_index
=0;
1556 return (&tape
->rq_stack
[tape
->rq_stack_index
++]);
1560 * idetape_init_pc initializes a packet command.
1562 static void idetape_init_pc (idetape_pc_t
*pc
)
1564 memset (pc
->c
, 0, 12);
1567 pc
->request_transfer
= 0;
1568 pc
->buffer
= pc
->pc_buffer
;
1569 pc
->buffer_size
= IDETAPE_PC_BUFFER_SIZE
;
1575 * idetape_analyze_error is called on each failed packet command retry
1576 * to analyze the request sense. We currently do not utilize this
1579 static void idetape_analyze_error (ide_drive_t
*drive
,idetape_request_sense_result_t
*result
)
1581 idetape_tape_t
*tape
= drive
->driver_data
;
1582 idetape_pc_t
*pc
= tape
->failed_pc
;
1584 tape
->sense
= *result
;
1585 tape
->sense_key
= result
->sense_key
; tape
->asc
= result
->asc
; tape
->ascq
= result
->ascq
;
1586 #if IDETAPE_DEBUG_LOG
1588 * Without debugging, we only log an error if we decided to
1591 if (tape
->debug_level
>= 1)
1592 printk (KERN_INFO
"ide-tape: pc = %x, sense key = %x, asc = %x, ascq = %x\n",pc
->c
[0],result
->sense_key
,result
->asc
,result
->ascq
);
1593 #if IDETAPE_DEBUG_LOG_VERBOSE
1594 if (tape
->debug_level
>= 1)
1595 printk (KERN_INFO
"ide-tape: pc = %s, sense key = %x, asc = %x, ascq = %x\n",
1596 idetape_command_key_verbose((byte
) pc
->c
[0]),
1600 #endif /* IDETAPE_DEBUG_LOG_VERBOSE */
1601 #endif /* IDETAPE_DEBUG_LOG */
1603 if (tape
->onstream
&& result
->sense_key
== 2 && result
->asc
== 0x53 && result
->ascq
== 2) {
1604 clear_bit(PC_DMA_ERROR
, &pc
->flags
);
1605 ide_stall_queue(drive
, HZ
/ 2);
1608 #ifdef CONFIG_BLK_DEV_IDEDMA
1611 * Correct pc->actually_transferred by asking the tape.
1613 if (test_bit (PC_DMA_ERROR
, &pc
->flags
)) {
1614 pc
->actually_transferred
= pc
->request_transfer
- tape
->tape_block_size
* ntohl (get_unaligned (&result
->information
));
1615 idetape_update_buffers (pc
);
1617 #endif /* CONFIG_BLK_DEV_IDEDMA */
1618 if (pc
->c
[0] == IDETAPE_READ_CMD
&& result
->filemark
) {
1619 pc
->error
= IDETAPE_ERROR_FILEMARK
;
1620 set_bit (PC_ABORT
, &pc
->flags
);
1622 if (pc
->c
[0] == IDETAPE_WRITE_CMD
) {
1623 if (result
->eom
|| (result
->sense_key
== 0xd && result
->asc
== 0x0 && result
->ascq
== 0x2)) {
1624 pc
->error
= IDETAPE_ERROR_EOD
;
1625 set_bit (PC_ABORT
, &pc
->flags
);
1628 if (pc
->c
[0] == IDETAPE_READ_CMD
|| pc
->c
[0] == IDETAPE_WRITE_CMD
) {
1629 if (result
->sense_key
== 8) {
1630 pc
->error
= IDETAPE_ERROR_EOD
;
1631 set_bit (PC_ABORT
, &pc
->flags
);
1633 if (!test_bit (PC_ABORT
, &pc
->flags
) && (tape
->onstream
|| pc
->actually_transferred
))
1634 pc
->retries
= IDETAPE_MAX_PC_RETRIES
+ 1;
1638 static void idetape_abort_pipeline (ide_drive_t
*drive
)
1640 idetape_tape_t
*tape
= drive
->driver_data
;
1641 idetape_stage_t
*stage
= tape
->next_stage
;
1643 #if IDETAPE_DEBUG_LOG
1644 if (tape
->debug_level
>= 4)
1645 printk(KERN_INFO
"ide-tape: %s: idetape_abort_pipeline called\n", tape
->name
);
1648 if (stage
->rq
.cmd
== IDETAPE_WRITE_RQ
)
1649 stage
->rq
.cmd
= IDETAPE_ABORTED_WRITE_RQ
;
1650 else if (stage
->rq
.cmd
== IDETAPE_READ_RQ
)
1651 stage
->rq
.cmd
= IDETAPE_ABORTED_READ_RQ
;
1652 stage
= stage
->next
;
1657 * idetape_active_next_stage will declare the next stage as "active".
1659 static void idetape_active_next_stage (ide_drive_t
*drive
)
1661 idetape_tape_t
*tape
= drive
->driver_data
;
1662 idetape_stage_t
*stage
=tape
->next_stage
;
1663 struct request
*rq
= &stage
->rq
;
1665 #if IDETAPE_DEBUG_LOG
1666 if (tape
->debug_level
>= 4)
1667 printk (KERN_INFO
"ide-tape: Reached idetape_active_next_stage\n");
1668 #endif /* IDETAPE_DEBUG_LOG */
1669 #if IDETAPE_DEBUG_BUGS
1670 if (stage
== NULL
) {
1671 printk (KERN_ERR
"ide-tape: bug: Trying to activate a non existing stage\n");
1674 #endif /* IDETAPE_DEBUG_BUGS */
1678 tape
->active_data_request
=rq
;
1679 tape
->active_stage
=stage
;
1680 tape
->next_stage
=stage
->next
;
1684 * idetape_increase_max_pipeline_stages is a part of the feedback
1685 * loop which tries to find the optimum number of stages. In the
1686 * feedback loop, we are starting from a minimum maximum number of
1687 * stages, and if we sense that the pipeline is empty, we try to
1688 * increase it, until we reach the user compile time memory limit.
1690 static void idetape_increase_max_pipeline_stages (ide_drive_t
*drive
)
1692 idetape_tape_t
*tape
= drive
->driver_data
;
1693 int increase
= (tape
->max_pipeline
- tape
->min_pipeline
) / 10;
1695 #if IDETAPE_DEBUG_LOG
1696 if (tape
->debug_level
>= 4)
1697 printk (KERN_INFO
"ide-tape: Reached idetape_increase_max_pipeline_stages\n");
1698 #endif /* IDETAPE_DEBUG_LOG */
1700 tape
->max_stages
+= increase
;
1701 tape
->max_stages
= IDE_MAX(tape
->max_stages
, tape
->min_pipeline
);
1702 tape
->max_stages
= IDE_MIN(tape
->max_stages
, tape
->max_pipeline
);
1706 * idetape_kfree_stage calls kfree to completely free a stage, along with
1707 * its related buffers.
1709 static void __idetape_kfree_stage (idetape_stage_t
*stage
)
1711 struct buffer_head
*prev_bh
, *bh
= stage
->bh
;
1714 while (bh
!= NULL
) {
1715 if (bh
->b_data
!= NULL
) {
1716 size
= (int) bh
->b_size
;
1718 free_page ((unsigned long) bh
->b_data
);
1720 bh
->b_data
+= PAGE_SIZE
;
1730 static void idetape_kfree_stage (idetape_tape_t
*tape
, idetape_stage_t
*stage
)
1732 __idetape_kfree_stage (stage
);
1736 * idetape_remove_stage_head removes tape->first_stage from the pipeline.
1737 * The caller should avoid race conditions.
1739 static void idetape_remove_stage_head (ide_drive_t
*drive
)
1741 idetape_tape_t
*tape
= drive
->driver_data
;
1742 idetape_stage_t
*stage
;
1744 #if IDETAPE_DEBUG_LOG
1745 if (tape
->debug_level
>= 4)
1746 printk (KERN_INFO
"ide-tape: Reached idetape_remove_stage_head\n");
1747 #endif /* IDETAPE_DEBUG_LOG */
1748 #if IDETAPE_DEBUG_BUGS
1749 if (tape
->first_stage
== NULL
) {
1750 printk (KERN_ERR
"ide-tape: bug: tape->first_stage is NULL\n");
1753 if (tape
->active_stage
== tape
->first_stage
) {
1754 printk (KERN_ERR
"ide-tape: bug: Trying to free our active pipeline stage\n");
1757 #endif /* IDETAPE_DEBUG_BUGS */
1758 stage
=tape
->first_stage
;
1759 tape
->first_stage
=stage
->next
;
1760 idetape_kfree_stage (tape
, stage
);
1762 if (tape
->first_stage
== NULL
) {
1763 tape
->last_stage
=NULL
;
1764 #if IDETAPE_DEBUG_BUGS
1765 if (tape
->next_stage
!= NULL
)
1766 printk (KERN_ERR
"ide-tape: bug: tape->next_stage != NULL\n");
1767 if (tape
->nr_stages
)
1768 printk (KERN_ERR
"ide-tape: bug: nr_stages should be 0 now\n");
1769 #endif /* IDETAPE_DEBUG_BUGS */
1774 * idetape_end_request is used to finish servicing a request, and to
1775 * insert a pending pipeline request into the main device queue.
1777 static void idetape_end_request (byte uptodate
, ide_hwgroup_t
*hwgroup
)
1779 ide_drive_t
*drive
= hwgroup
->drive
;
1780 struct request
*rq
= hwgroup
->rq
;
1781 idetape_tape_t
*tape
= drive
->driver_data
;
1782 unsigned long flags
;
1784 int remove_stage
= 0;
1786 idetape_stage_t
*stage
;
1791 #if IDETAPE_DEBUG_LOG
1792 if (tape
->debug_level
>= 4)
1793 printk (KERN_INFO
"ide-tape: Reached idetape_end_request\n");
1794 #endif /* IDETAPE_DEBUG_LOG */
1797 case 0: error
= IDETAPE_ERROR_GENERAL
; break;
1798 case 1: error
= 0; break;
1799 default: error
= uptodate
;
1803 tape
->failed_pc
= NULL
;
1805 spin_lock_irqsave(&tape
->spinlock
, flags
);
1806 if (tape
->active_data_request
== rq
) { /* The request was a pipelined data transfer request */
1807 tape
->active_stage
= NULL
;
1808 tape
->active_data_request
= NULL
;
1809 tape
->nr_pending_stages
--;
1810 if (rq
->cmd
== IDETAPE_WRITE_RQ
) {
1812 if (tape
->debug_level
>= 2) {
1813 if (tape
->onstream
) {
1814 stage
= tape
->first_stage
;
1816 p
= stage
->bh
->b_data
;
1817 if (ntohl(aux
->logical_blk_num
) < 11300 && ntohl(aux
->logical_blk_num
) > 11100)
1818 printk(KERN_INFO
"ide-tape: finished writing logical blk %u (data %x %x %x %x)\n", ntohl(aux
->logical_blk_num
), *p
++, *p
++, *p
++, *p
++);
1822 if (tape
->onstream
&& !tape
->raw
) {
1823 if (tape
->first_frame_position
== 0xba4) {
1825 if (tape
->debug_level
>= 2)
1826 printk("ide-tape: %s: skipping over config parition..\n", tape
->name
);
1828 tape
->onstream_write_error
= 2;
1835 set_bit (IDETAPE_PIPELINE_ERROR
, &tape
->flags
);
1836 if (error
== IDETAPE_ERROR_EOD
)
1837 idetape_abort_pipeline (drive
);
1838 if (tape
->onstream
&& !tape
->raw
&& error
== IDETAPE_ERROR_GENERAL
&& tape
->sense
.sense_key
== 3) {
1839 clear_bit (IDETAPE_PIPELINE_ERROR
, &tape
->flags
);
1840 printk(KERN_ERR
"ide-tape: %s: write error, enabling error recovery\n", tape
->name
);
1841 tape
->onstream_write_error
= 1;
1843 tape
->nr_pending_stages
++;
1844 tape
->next_stage
= tape
->first_stage
;
1845 rq
->current_nr_sectors
= rq
->nr_sectors
;
1850 } else if (rq
->cmd
== IDETAPE_READ_RQ
) {
1851 if (error
== IDETAPE_ERROR_EOD
) {
1852 set_bit (IDETAPE_PIPELINE_ERROR
, &tape
->flags
);
1853 idetape_abort_pipeline(drive
);
1856 if (tape
->next_stage
!= NULL
&& !tape
->onstream_write_error
) {
1857 idetape_active_next_stage (drive
);
1860 * Insert the next request into the request queue.
1862 (void) ide_do_drive_cmd (drive
, tape
->active_data_request
, ide_end
);
1863 } else if (!error
) {
1864 if (!tape
->onstream
)
1865 idetape_increase_max_pipeline_stages (drive
);
1868 ide_end_drive_cmd (drive
, 0, 0);
1870 idetape_remove_stage_head (drive
);
1871 if (tape
->active_data_request
== NULL
)
1872 clear_bit(IDETAPE_PIPELINE_ACTIVE
, &tape
->flags
);
1873 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
1876 static ide_startstop_t
idetape_request_sense_callback (ide_drive_t
*drive
)
1878 idetape_tape_t
*tape
= drive
->driver_data
;
1880 #if IDETAPE_DEBUG_LOG
1881 if (tape
->debug_level
>= 4)
1882 printk (KERN_INFO
"ide-tape: Reached idetape_request_sense_callback\n");
1883 #endif /* IDETAPE_DEBUG_LOG */
1884 if (!tape
->pc
->error
) {
1885 idetape_analyze_error (drive
,(idetape_request_sense_result_t
*) tape
->pc
->buffer
);
1886 idetape_end_request (1,HWGROUP (drive
));
1888 printk (KERN_ERR
"ide-tape: Error in REQUEST SENSE itself - Aborting request!\n");
1889 idetape_end_request (0,HWGROUP (drive
));
1894 static void idetape_create_request_sense_cmd (idetape_pc_t
*pc
)
1896 idetape_init_pc (pc
);
1897 pc
->c
[0] = IDETAPE_REQUEST_SENSE_CMD
;
1899 pc
->request_transfer
= 18;
1900 pc
->callback
= &idetape_request_sense_callback
;
1904 * idetape_queue_pc_head generates a new packet command request in front
1905 * of the request queue, before the current request, so that it will be
1906 * processed immediately, on the next pass through the driver.
1908 * idetape_queue_pc_head is called from the request handling part of
1909 * the driver (the "bottom" part). Safe storage for the request should
1910 * be allocated with idetape_next_pc_storage and idetape_next_rq_storage
1911 * before calling idetape_queue_pc_head.
1913 * Memory for those requests is pre-allocated at initialization time, and
1914 * is limited to IDETAPE_PC_STACK requests. We assume that we have enough
1915 * space for the maximum possible number of inter-dependent packet commands.
1917 * The higher level of the driver - The ioctl handler and the character
1918 * device handling functions should queue request to the lower level part
1919 * and wait for their completion using idetape_queue_pc_tail or
1920 * idetape_queue_rw_tail.
1922 static void idetape_queue_pc_head (ide_drive_t
*drive
,idetape_pc_t
*pc
,struct request
*rq
)
1924 ide_init_drive_cmd (rq
);
1925 rq
->buffer
= (char *) pc
;
1926 rq
->cmd
= IDETAPE_PC_RQ1
;
1927 (void) ide_do_drive_cmd (drive
, rq
, ide_preempt
);
1931 * idetape_retry_pc is called when an error was detected during the
1932 * last packet command. We queue a request sense packet command in
1933 * the head of the request list.
1935 static ide_startstop_t
idetape_retry_pc (ide_drive_t
*drive
)
1937 idetape_tape_t
*tape
= drive
->driver_data
;
1940 idetape_error_reg_t error
;
1942 error
.all
= IN_BYTE (IDE_ERROR_REG
);
1943 pc
= idetape_next_pc_storage (drive
);
1944 rq
= idetape_next_rq_storage (drive
);
1945 idetape_create_request_sense_cmd (pc
);
1946 set_bit (IDETAPE_IGNORE_DSC
, &tape
->flags
);
1947 idetape_queue_pc_head (drive
, pc
, rq
);
1952 * idetape_postpone_request postpones the current request so that
1953 * ide.c will be able to service requests from another device on
1954 * the same hwgroup while we are polling for DSC.
1956 static void idetape_postpone_request (ide_drive_t
*drive
)
1958 idetape_tape_t
*tape
= drive
->driver_data
;
1960 #if IDETAPE_DEBUG_LOG
1961 if (tape
->debug_level
>= 4)
1962 printk(KERN_INFO
"ide-tape: idetape_postpone_request\n");
1964 tape
->postponed_rq
= HWGROUP(drive
)->rq
;
1965 ide_stall_queue(drive
, tape
->dsc_polling_frequency
);
1969 * idetape_pc_intr is the usual interrupt handler which will be called
1970 * during a packet command. We will transfer some of the data (as
1971 * requested by the drive) and will re-point interrupt handler to us.
1972 * When data transfer is finished, we will act according to the
1973 * algorithm described before idetape_issue_packet_command.
1976 static ide_startstop_t
idetape_pc_intr (ide_drive_t
*drive
)
1978 idetape_tape_t
*tape
= drive
->driver_data
;
1979 idetape_status_reg_t status
;
1980 idetape_bcount_reg_t bcount
;
1981 idetape_ireason_reg_t ireason
;
1982 idetape_pc_t
*pc
=tape
->pc
;
1985 unsigned long cmd_time
;
1987 static int error_sim_count
= 0;
1990 #if IDETAPE_DEBUG_LOG
1991 if (tape
->debug_level
>= 4)
1992 printk (KERN_INFO
"ide-tape: Reached idetape_pc_intr interrupt handler\n");
1993 #endif /* IDETAPE_DEBUG_LOG */
1995 status
.all
= GET_STAT(); /* Clear the interrupt */
1997 #ifdef CONFIG_BLK_DEV_IDEDMA
1998 if (test_bit (PC_DMA_IN_PROGRESS
, &pc
->flags
)) {
1999 if (HWIF(drive
)->dmaproc(ide_dma_end
, drive
)) {
2001 * A DMA error is sometimes expected. For example,
2002 * if the tape is crossing a filemark during a
2003 * READ command, it will issue an irq and position
2004 * itself before the filemark, so that only a partial
2005 * data transfer will occur (which causes the DMA
2006 * error). In that case, we will later ask the tape
2007 * how much bytes of the original request were
2008 * actually transferred (we can't receive that
2009 * information from the DMA engine on most chipsets).
2011 set_bit (PC_DMA_ERROR
, &pc
->flags
);
2012 } else if (!status
.b
.check
) {
2013 pc
->actually_transferred
=pc
->request_transfer
;
2014 idetape_update_buffers (pc
);
2016 #if IDETAPE_DEBUG_LOG
2017 if (tape
->debug_level
>= 4)
2018 printk (KERN_INFO
"ide-tape: DMA finished\n");
2019 #endif /* IDETAPE_DEBUG_LOG */
2021 #endif /* CONFIG_BLK_DEV_IDEDMA */
2023 if (!status
.b
.drq
) { /* No more interrupts */
2024 cmd_time
= (jiffies
- tape
->cmd_start_time
) * 1000 / HZ
;
2025 tape
->max_cmd_time
= IDE_MAX(cmd_time
, tape
->max_cmd_time
);
2026 #if IDETAPE_DEBUG_LOG
2027 if (tape
->debug_level
>= 2)
2028 printk (KERN_INFO
"ide-tape: Packet command completed, %d bytes transferred\n", pc
->actually_transferred
);
2029 #endif /* IDETAPE_DEBUG_LOG */
2030 clear_bit (PC_DMA_IN_PROGRESS
, &pc
->flags
);
2032 ide__sti(); /* local CPU only */
2035 if ((pc
->c
[0] == IDETAPE_WRITE_CMD
|| pc
->c
[0] == IDETAPE_READ_CMD
) && (++error_sim_count
% 100) == 0) {
2036 printk(KERN_INFO
"ide-tape: %s: simulating error\n", tape
->name
);
2040 if (status
.b
.check
&& pc
->c
[0] == IDETAPE_REQUEST_SENSE_CMD
)
2042 if (status
.b
.check
|| test_bit (PC_DMA_ERROR
, &pc
->flags
)) { /* Error detected */
2043 #if IDETAPE_DEBUG_LOG
2044 if (tape
->debug_level
>= 1)
2045 printk (KERN_INFO
"ide-tape: %s: I/O error, ",tape
->name
);
2046 #endif /* IDETAPE_DEBUG_LOG */
2047 if (pc
->c
[0] == IDETAPE_REQUEST_SENSE_CMD
) {
2048 printk (KERN_ERR
"ide-tape: I/O error in request sense command\n");
2049 return ide_do_reset (drive
);
2051 #if IDETAPE_DEBUG_LOG
2052 if (tape
->debug_level
>= 1)
2053 printk(KERN_INFO
"ide-tape: [cmd %x]: check condition\n", pc
->c
[0]);
2055 return idetape_retry_pc (drive
); /* Retry operation */
2058 if (!tape
->onstream
&& test_bit (PC_WAIT_FOR_DSC
, &pc
->flags
) && !status
.b
.dsc
) { /* Media access command */
2059 tape
->dsc_polling_start
= jiffies
;
2060 tape
->dsc_polling_frequency
= IDETAPE_DSC_MA_FAST
;
2061 tape
->dsc_timeout
= jiffies
+ IDETAPE_DSC_MA_TIMEOUT
;
2062 idetape_postpone_request (drive
); /* Allow ide.c to handle other requests */
2065 if (tape
->failed_pc
== pc
)
2066 tape
->failed_pc
=NULL
;
2067 return pc
->callback(drive
); /* Command finished - Call the callback function */
2069 #ifdef CONFIG_BLK_DEV_IDEDMA
2070 if (test_and_clear_bit (PC_DMA_IN_PROGRESS
, &pc
->flags
)) {
2071 printk (KERN_ERR
"ide-tape: The tape wants to issue more interrupts in DMA mode\n");
2072 printk (KERN_ERR
"ide-tape: DMA disabled, reverting to PIO\n");
2073 (void) HWIF(drive
)->dmaproc(ide_dma_off
, drive
);
2074 return ide_do_reset (drive
);
2076 #endif /* CONFIG_BLK_DEV_IDEDMA */
2077 bcount
.b
.high
=IN_BYTE (IDE_BCOUNTH_REG
); /* Get the number of bytes to transfer */
2078 bcount
.b
.low
=IN_BYTE (IDE_BCOUNTL_REG
); /* on this interrupt */
2079 ireason
.all
=IN_BYTE (IDE_IREASON_REG
);
2081 if (ireason
.b
.cod
) {
2082 printk (KERN_ERR
"ide-tape: CoD != 0 in idetape_pc_intr\n");
2083 return ide_do_reset (drive
);
2085 if (ireason
.b
.io
== test_bit (PC_WRITING
, &pc
->flags
)) { /* Hopefully, we will never get here */
2086 printk (KERN_ERR
"ide-tape: We wanted to %s, ", ireason
.b
.io
? "Write":"Read");
2087 printk (KERN_ERR
"ide-tape: but the tape wants us to %s !\n",ireason
.b
.io
? "Read":"Write");
2088 return ide_do_reset (drive
);
2090 if (!test_bit (PC_WRITING
, &pc
->flags
)) { /* Reading - Check that we have enough space */
2091 temp
= pc
->actually_transferred
+ bcount
.all
;
2092 if ( temp
> pc
->request_transfer
) {
2093 if (temp
> pc
->buffer_size
) {
2094 printk (KERN_ERR
"ide-tape: The tape wants to send us more data than expected - discarding data\n");
2095 idetape_discard_data (drive
,bcount
.all
);
2096 ide_set_handler (drive
,&idetape_pc_intr
,IDETAPE_WAIT_CMD
,NULL
);
2099 #if IDETAPE_DEBUG_LOG
2100 if (tape
->debug_level
>= 2)
2101 printk (KERN_NOTICE
"ide-tape: The tape wants to send us more data than expected - allowing transfer\n");
2102 #endif /* IDETAPE_DEBUG_LOG */
2105 if (test_bit (PC_WRITING
, &pc
->flags
)) {
2107 idetape_output_buffers (drive
, pc
, bcount
.all
);
2109 atapi_output_bytes (drive
,pc
->current_position
,bcount
.all
); /* Write the current buffer */
2112 idetape_input_buffers (drive
, pc
, bcount
.all
);
2114 atapi_input_bytes (drive
,pc
->current_position
,bcount
.all
); /* Read the current buffer */
2116 pc
->actually_transferred
+=bcount
.all
; /* Update the current position */
2117 pc
->current_position
+=bcount
.all
;
2118 #if IDETAPE_DEBUG_LOG
2119 if (tape
->debug_level
>= 2)
2120 printk(KERN_INFO
"ide-tape: [cmd %x] transferred %d bytes on that interrupt\n", pc
->c
[0], bcount
.all
);
2122 ide_set_handler (drive
,&idetape_pc_intr
,IDETAPE_WAIT_CMD
,NULL
); /* And set the interrupt handler again */
2127 * Packet Command Interface
2129 * The current Packet Command is available in tape->pc, and will not
2130 * change until we finish handling it. Each packet command is associated
2131 * with a callback function that will be called when the command is
2134 * The handling will be done in three stages:
2136 * 1. idetape_issue_packet_command will send the packet command to the
2137 * drive, and will set the interrupt handler to idetape_pc_intr.
2139 * 2. On each interrupt, idetape_pc_intr will be called. This step
2140 * will be repeated until the device signals us that no more
2141 * interrupts will be issued.
2143 * 3. ATAPI Tape media access commands have immediate status with a
2144 * delayed process. In case of a successful initiation of a
2145 * media access packet command, the DSC bit will be set when the
2146 * actual execution of the command is finished.
2147 * Since the tape drive will not issue an interrupt, we have to
2148 * poll for this event. In this case, we define the request as
2149 * "low priority request" by setting rq_status to
2150 * IDETAPE_RQ_POSTPONED, set a timer to poll for DSC and exit
2153 * ide.c will then give higher priority to requests which
2154 * originate from the other device, until will change rq_status
2157 * 4. When the packet command is finished, it will be checked for errors.
2159 * 5. In case an error was found, we queue a request sense packet command
2160 * in front of the request queue and retry the operation up to
2161 * IDETAPE_MAX_PC_RETRIES times.
2163 * 6. In case no error was found, or we decided to give up and not
2164 * to retry again, the callback function will be called and then
2165 * we will handle the next request.
2168 static ide_startstop_t
idetape_transfer_pc(ide_drive_t
*drive
)
2170 idetape_tape_t
*tape
= drive
->driver_data
;
2171 idetape_pc_t
*pc
= tape
->pc
;
2172 idetape_ireason_reg_t ireason
;
2174 ide_startstop_t startstop
;
2176 if (ide_wait_stat (&startstop
,drive
,DRQ_STAT
,BUSY_STAT
,WAIT_READY
)) {
2177 printk (KERN_ERR
"ide-tape: Strange, packet command initiated yet DRQ isn't asserted\n");
2180 ireason
.all
=IN_BYTE (IDE_IREASON_REG
);
2181 while (retries
-- && (!ireason
.b
.cod
|| ireason
.b
.io
)) {
2182 printk(KERN_ERR
"ide-tape: (IO,CoD != (0,1) while issuing a packet command, retrying\n");
2184 ireason
.all
= IN_BYTE(IDE_IREASON_REG
);
2186 printk(KERN_ERR
"ide-tape: (IO,CoD != (0,1) while issuing a packet command, ignoring\n");
2191 if (!ireason
.b
.cod
|| ireason
.b
.io
) {
2192 printk (KERN_ERR
"ide-tape: (IO,CoD) != (0,1) while issuing a packet command\n");
2193 return ide_do_reset (drive
);
2195 tape
->cmd_start_time
= jiffies
;
2196 ide_set_handler(drive
, &idetape_pc_intr
, IDETAPE_WAIT_CMD
, NULL
); /* Set the interrupt routine */
2197 atapi_output_bytes (drive
,pc
->c
,12); /* Send the actual packet */
2201 static ide_startstop_t
idetape_issue_packet_command (ide_drive_t
*drive
, idetape_pc_t
*pc
)
2203 idetape_tape_t
*tape
= drive
->driver_data
;
2204 idetape_bcount_reg_t bcount
;
2207 #if IDETAPE_DEBUG_BUGS
2208 if (tape
->pc
->c
[0] == IDETAPE_REQUEST_SENSE_CMD
&& pc
->c
[0] == IDETAPE_REQUEST_SENSE_CMD
) {
2209 printk (KERN_ERR
"ide-tape: possible ide-tape.c bug - Two request sense in serial were issued\n");
2211 #endif /* IDETAPE_DEBUG_BUGS */
2213 if (tape
->failed_pc
== NULL
&& pc
->c
[0] != IDETAPE_REQUEST_SENSE_CMD
)
2215 tape
->pc
=pc
; /* Set the current packet command */
2217 if (pc
->retries
> IDETAPE_MAX_PC_RETRIES
|| test_bit (PC_ABORT
, &pc
->flags
)) {
2219 * We will "abort" retrying a packet command in case
2220 * a legitimate error code was received (crossing a
2221 * filemark, or DMA error in the end of media, for
2224 if (!test_bit (PC_ABORT
, &pc
->flags
)) {
2225 if (!(pc
->c
[0] == 0 && tape
->sense_key
== 2 && tape
->asc
== 4 && (tape
->ascq
== 1 || tape
->ascq
== 8))) {
2226 printk (KERN_ERR
"ide-tape: %s: I/O error, pc = %2x, key = %2x, asc = %2x, ascq = %2x\n",
2227 tape
->name
, pc
->c
[0], tape
->sense_key
, tape
->asc
, tape
->ascq
);
2228 if (tape
->onstream
&& pc
->c
[0] == 8 && tape
->sense_key
== 3 && tape
->asc
== 0x11) /* AJN-1: 11 should be 0x11 */
2229 printk(KERN_ERR
"ide-tape: %s: enabling read error recovery\n", tape
->name
);
2231 pc
->error
= IDETAPE_ERROR_GENERAL
; /* Giving up */
2233 tape
->failed_pc
=NULL
;
2234 return pc
->callback(drive
);
2236 #if IDETAPE_DEBUG_LOG
2237 if (tape
->debug_level
>= 2)
2238 printk (KERN_INFO
"ide-tape: Retry number - %d\n",pc
->retries
);
2239 #endif /* IDETAPE_DEBUG_LOG */
2242 pc
->actually_transferred
=0; /* We haven't transferred any data yet */
2243 pc
->current_position
=pc
->buffer
;
2244 bcount
.all
=pc
->request_transfer
; /* Request to transfer the entire buffer at once */
2246 #ifdef CONFIG_BLK_DEV_IDEDMA
2247 if (test_and_clear_bit (PC_DMA_ERROR
, &pc
->flags
)) {
2248 printk (KERN_WARNING
"ide-tape: DMA disabled, reverting to PIO\n");
2249 (void) HWIF(drive
)->dmaproc(ide_dma_off
, drive
);
2251 if (test_bit (PC_DMA_RECOMMENDED
, &pc
->flags
) && drive
->using_dma
)
2252 dma_ok
=!HWIF(drive
)->dmaproc(test_bit (PC_WRITING
, &pc
->flags
) ? ide_dma_write
: ide_dma_read
, drive
);
2253 #endif /* CONFIG_BLK_DEV_IDEDMA */
2255 if (IDE_CONTROL_REG
)
2256 OUT_BYTE (drive
->ctl
,IDE_CONTROL_REG
);
2257 OUT_BYTE (dma_ok
? 1:0,IDE_FEATURE_REG
); /* Use PIO/DMA */
2258 OUT_BYTE (bcount
.b
.high
,IDE_BCOUNTH_REG
);
2259 OUT_BYTE (bcount
.b
.low
,IDE_BCOUNTL_REG
);
2260 OUT_BYTE (drive
->select
.all
,IDE_SELECT_REG
);
2261 #ifdef CONFIG_BLK_DEV_IDEDMA
2262 if (dma_ok
) { /* Begin DMA, if necessary */
2263 set_bit (PC_DMA_IN_PROGRESS
, &pc
->flags
);
2264 (void) (HWIF(drive
)->dmaproc(ide_dma_begin
, drive
));
2266 #endif /* CONFIG_BLK_DEV_IDEDMA */
2267 if (test_bit(IDETAPE_DRQ_INTERRUPT
, &tape
->flags
)) {
2268 ide_set_handler(drive
, &idetape_transfer_pc
, IDETAPE_WAIT_CMD
, NULL
);
2269 OUT_BYTE(WIN_PACKETCMD
, IDE_COMMAND_REG
);
2272 OUT_BYTE(WIN_PACKETCMD
, IDE_COMMAND_REG
);
2273 return idetape_transfer_pc(drive
);
2278 * General packet command callback function.
2280 static ide_startstop_t
idetape_pc_callback (ide_drive_t
*drive
)
2282 idetape_tape_t
*tape
= drive
->driver_data
;
2284 #if IDETAPE_DEBUG_LOG
2285 if (tape
->debug_level
>= 4)
2286 printk (KERN_INFO
"ide-tape: Reached idetape_pc_callback\n");
2287 #endif /* IDETAPE_DEBUG_LOG */
2289 idetape_end_request (tape
->pc
->error
? 0:1, HWGROUP(drive
));
2294 * A mode sense command is used to "sense" tape parameters.
2296 static void idetape_create_mode_sense_cmd (idetape_pc_t
*pc
, byte page_code
)
2298 idetape_init_pc (pc
);
2299 pc
->c
[0] = IDETAPE_MODE_SENSE_CMD
;
2300 pc
->c
[1] = 8; /* DBD = 1 - Don't return block descriptors for now */
2301 pc
->c
[2] = page_code
;
2302 pc
->c
[3] = 255; /* Don't limit the returned information */
2303 pc
->c
[4] = 255; /* (We will just discard data in that case) */
2304 if (page_code
== IDETAPE_CAPABILITIES_PAGE
)
2305 pc
->request_transfer
= 24;
2307 pc
->request_transfer
= 50;
2308 pc
->callback
= &idetape_pc_callback
;
2311 static ide_startstop_t
idetape_onstream_buffer_fill_callback (ide_drive_t
*drive
)
2313 idetape_tape_t
*tape
= drive
->driver_data
;
2315 tape
->max_frames
= tape
->pc
->buffer
[4 + 2];
2316 tape
->cur_frames
= tape
->pc
->buffer
[4 + 3];
2317 if (tape
->chrdev_direction
== idetape_direction_write
)
2318 tape
->tape_head
= tape
->buffer_head
- tape
->cur_frames
;
2320 tape
->tape_head
= tape
->buffer_head
+ tape
->cur_frames
;
2321 if (tape
->tape_head
!= tape
->last_tape_head
) {
2322 tape
->last_tape_head
= tape
->tape_head
;
2323 tape
->tape_still_time_begin
= jiffies
;
2324 if (tape
->tape_still_time
> 200)
2325 tape
->measure_insert_time
= 1;
2327 tape
->tape_still_time
= (jiffies
- tape
->tape_still_time_begin
) * 1000 / HZ
;
2329 IO_trace(IO_IDETAPE_FIFO
, tape
->pipeline_head
, tape
->buffer_head
, tape
->tape_head
, tape
->minor
);
2331 #if IDETAPE_DEBUG_LOG
2332 if (tape
->debug_level
>= 1)
2333 printk(KERN_INFO
"ide-tape: buffer fill callback, %d/%d\n", tape
->cur_frames
, tape
->max_frames
);
2335 idetape_end_request (tape
->pc
->error
? 0:1, HWGROUP(drive
));
2339 static void idetape_queue_onstream_buffer_fill (ide_drive_t
*drive
)
2344 pc
= idetape_next_pc_storage (drive
);
2345 rq
= idetape_next_rq_storage (drive
);
2346 idetape_create_mode_sense_cmd (pc
, 0x33);
2347 pc
->callback
= idetape_onstream_buffer_fill_callback
;
2348 idetape_queue_pc_head (drive
, pc
, rq
);
2351 static void calculate_speeds(ide_drive_t
*drive
)
2353 idetape_tape_t
*tape
= drive
->driver_data
;
2354 int full
= 125, empty
= 75;
2356 if (jiffies
> tape
->controlled_pipeline_head_time
+ 120 * HZ
) {
2357 tape
->controlled_previous_pipeline_head
= tape
->controlled_last_pipeline_head
;
2358 tape
->controlled_previous_head_time
= tape
->controlled_pipeline_head_time
;
2359 tape
->controlled_last_pipeline_head
= tape
->pipeline_head
;
2360 tape
->controlled_pipeline_head_time
= jiffies
;
2362 if (jiffies
> tape
->controlled_pipeline_head_time
+ 60 * HZ
)
2363 tape
->controlled_pipeline_head_speed
= (tape
->pipeline_head
- tape
->controlled_last_pipeline_head
) * 32 * HZ
/ (jiffies
- tape
->controlled_pipeline_head_time
);
2364 else if (jiffies
> tape
->controlled_previous_head_time
)
2365 tape
->controlled_pipeline_head_speed
= (tape
->pipeline_head
- tape
->controlled_previous_pipeline_head
) * 32 * HZ
/ (jiffies
- tape
->controlled_previous_head_time
);
2367 if (tape
->nr_pending_stages
< tape
->max_stages
/*- 1 */) { /* -1 for read mode error recovery */
2368 if (jiffies
> tape
->uncontrolled_previous_head_time
+ 10 * HZ
) {
2369 tape
->uncontrolled_pipeline_head_time
= jiffies
;
2370 tape
->uncontrolled_pipeline_head_speed
= (tape
->pipeline_head
- tape
->uncontrolled_previous_pipeline_head
) * 32 * HZ
/ (jiffies
- tape
->uncontrolled_previous_head_time
);
2373 tape
->uncontrolled_previous_head_time
= jiffies
;
2374 tape
->uncontrolled_previous_pipeline_head
= tape
->pipeline_head
;
2375 if (jiffies
> tape
->uncontrolled_pipeline_head_time
+ 30 * HZ
) {
2376 tape
->uncontrolled_pipeline_head_time
= jiffies
;
2379 tape
->pipeline_head_speed
= IDE_MAX(tape
->uncontrolled_pipeline_head_speed
, tape
->controlled_pipeline_head_speed
);
2380 if (tape
->speed_control
== 0) {
2381 tape
->max_insert_speed
= 5000;
2382 } else if (tape
->speed_control
== 1) {
2383 if (tape
->nr_pending_stages
>= tape
->max_stages
/ 2)
2384 tape
->max_insert_speed
= tape
->pipeline_head_speed
+
2385 (1100 - tape
->pipeline_head_speed
) * 2 * (tape
->nr_pending_stages
- tape
->max_stages
/ 2) / tape
->max_stages
;
2387 tape
->max_insert_speed
= 500 +
2388 (tape
->pipeline_head_speed
- 500) * 2 * tape
->nr_pending_stages
/ tape
->max_stages
;
2389 if (tape
->nr_pending_stages
>= tape
->max_stages
* 99 / 100)
2390 tape
->max_insert_speed
= 5000;
2391 } else if (tape
->speed_control
== 2) {
2392 tape
->max_insert_speed
= tape
->pipeline_head_speed
* empty
/ 100 +
2393 (tape
->pipeline_head_speed
* full
/ 100 - tape
->pipeline_head_speed
* empty
/ 100) * tape
->nr_pending_stages
/ tape
->max_stages
;
2395 tape
->max_insert_speed
= tape
->speed_control
;
2396 tape
->max_insert_speed
= IDE_MAX(tape
->max_insert_speed
, 500);
2399 static ide_startstop_t
idetape_media_access_finished (ide_drive_t
*drive
)
2401 idetape_tape_t
*tape
= drive
->driver_data
;
2402 idetape_pc_t
*pc
= tape
->pc
;
2403 idetape_status_reg_t status
;
2406 printk(KERN_INFO
"ide-tape: bug: onstream, media_access_finished\n");
2407 status
.all
= GET_STAT();
2409 if (status
.b
.check
) { /* Error detected */
2410 printk (KERN_ERR
"ide-tape: %s: I/O error, ",tape
->name
);
2411 return idetape_retry_pc (drive
); /* Retry operation */
2414 if (tape
->failed_pc
== pc
)
2415 tape
->failed_pc
= NULL
;
2417 pc
->error
= IDETAPE_ERROR_GENERAL
;
2418 tape
->failed_pc
= NULL
;
2420 return pc
->callback (drive
);
2423 static ide_startstop_t
idetape_rw_callback (ide_drive_t
*drive
)
2425 idetape_tape_t
*tape
= drive
->driver_data
;
2426 struct request
*rq
= HWGROUP(drive
)->rq
;
2427 int blocks
= tape
->pc
->actually_transferred
/ tape
->tape_block_size
;
2429 tape
->avg_size
+= blocks
* tape
->tape_block_size
;
2430 tape
->insert_size
+= blocks
* tape
->tape_block_size
;
2431 if (tape
->insert_size
> 1024 * 1024)
2432 tape
->measure_insert_time
= 1;
2433 if (tape
->measure_insert_time
) {
2434 tape
->measure_insert_time
= 0;
2435 tape
->insert_time
= jiffies
;
2436 tape
->insert_size
= 0;
2438 if (jiffies
> tape
->insert_time
)
2439 tape
->insert_speed
= tape
->insert_size
/ 1024 * HZ
/ (jiffies
- tape
->insert_time
);
2440 if (jiffies
- tape
->avg_time
>= HZ
) {
2441 tape
->avg_speed
= tape
->avg_size
* HZ
/ (jiffies
- tape
->avg_time
) / 1024;
2443 tape
->avg_time
= jiffies
;
2446 #if IDETAPE_DEBUG_LOG
2447 if (tape
->debug_level
>= 4)
2448 printk (KERN_INFO
"ide-tape: Reached idetape_rw_callback\n");
2449 #endif /* IDETAPE_DEBUG_LOG */
2451 tape
->first_frame_position
+= blocks
;
2452 rq
->current_nr_sectors
-= blocks
;
2454 if (!tape
->pc
->error
)
2455 idetape_end_request (1, HWGROUP (drive
));
2457 idetape_end_request (tape
->pc
->error
, HWGROUP (drive
));
2461 static void idetape_create_read_cmd (idetape_tape_t
*tape
, idetape_pc_t
*pc
, unsigned int length
, struct buffer_head
*bh
)
2463 struct buffer_head
*p
= bh
;
2464 idetape_init_pc (pc
);
2465 pc
->c
[0] = IDETAPE_READ_CMD
;
2466 put_unaligned (htonl (length
), (unsigned int *) &pc
->c
[1]);
2468 pc
->callback
= &idetape_rw_callback
;
2470 atomic_set(&bh
->b_count
, 0);
2472 if (tape
->onstream
) {
2474 atomic_set(&p
->b_count
, 0);
2478 if (!tape
->onstream
) {
2479 pc
->request_transfer
= pc
->buffer_size
= length
* tape
->tape_block_size
;
2480 if (pc
->request_transfer
== tape
->stage_size
)
2481 set_bit (PC_DMA_RECOMMENDED
, &pc
->flags
);
2484 pc
->request_transfer
= pc
->buffer_size
= 32768 + 512;
2485 set_bit (PC_DMA_RECOMMENDED
, &pc
->flags
);
2487 pc
->request_transfer
= 0;
2491 static void idetape_create_read_buffer_cmd(idetape_tape_t
*tape
, idetape_pc_t
*pc
, unsigned int length
, struct buffer_head
*bh
)
2495 struct buffer_head
*p
= bh
;
2496 idetape_init_pc (pc
);
2497 pc
->c
[0] = IDETAPE_READ_BUFFER_CMD
;
2498 pc
->c
[1] = IDETAPE_RETRIEVE_FAULTY_BLOCK
;
2499 pc
->c
[7] = size
>> 8;
2500 pc
->c
[8] = size
& 0xff;
2501 pc
->callback
= &idetape_pc_callback
;
2503 atomic_set(&bh
->b_count
, 0);
2506 atomic_set(&p
->b_count
, 0);
2509 pc
->request_transfer
= pc
->buffer_size
= size
;
2512 static void idetape_create_write_cmd (idetape_tape_t
*tape
, idetape_pc_t
*pc
, unsigned int length
, struct buffer_head
*bh
)
2514 struct buffer_head
*p
= bh
;
2515 idetape_init_pc (pc
);
2516 pc
->c
[0] = IDETAPE_WRITE_CMD
;
2517 put_unaligned (htonl (length
), (unsigned int *) &pc
->c
[1]);
2519 pc
->callback
= &idetape_rw_callback
;
2520 set_bit (PC_WRITING
, &pc
->flags
);
2521 if (tape
->onstream
) {
2523 atomic_set(&p
->b_count
, p
->b_size
);
2528 pc
->b_data
= bh
->b_data
;
2529 pc
->b_count
= atomic_read(&bh
->b_count
);
2531 if (!tape
->onstream
) {
2532 pc
->request_transfer
= pc
->buffer_size
= length
* tape
->tape_block_size
;
2533 if (pc
->request_transfer
== tape
->stage_size
)
2534 set_bit (PC_DMA_RECOMMENDED
, &pc
->flags
);
2537 pc
->request_transfer
= pc
->buffer_size
= 32768 + 512;
2538 set_bit (PC_DMA_RECOMMENDED
, &pc
->flags
);
2540 pc
->request_transfer
= 0;
2545 * idetape_do_request is our request handling function.
2547 static ide_startstop_t
idetape_do_request (ide_drive_t
*drive
, struct request
*rq
, unsigned long block
)
2549 idetape_tape_t
*tape
= drive
->driver_data
;
2551 struct request
*postponed_rq
= tape
->postponed_rq
;
2552 idetape_status_reg_t status
;
2554 #if IDETAPE_DEBUG_LOG
2555 if (tape
->debug_level
>= 5)
2556 printk (KERN_INFO
"ide-tape: rq_status: %d, rq_dev: %u, cmd: %d, errors: %d\n",rq
->rq_status
,(unsigned int) rq
->rq_dev
,rq
->cmd
,rq
->errors
);
2557 if (tape
->debug_level
>= 2)
2558 printk (KERN_INFO
"ide-tape: sector: %ld, nr_sectors: %ld, current_nr_sectors: %ld\n",rq
->sector
,rq
->nr_sectors
,rq
->current_nr_sectors
);
2559 #endif /* IDETAPE_DEBUG_LOG */
2561 if (!IDETAPE_RQ_CMD (rq
->cmd
)) {
2563 * We do not support buffer cache originated requests.
2565 printk (KERN_NOTICE
"ide-tape: %s: Unsupported command in request queue (%d)\n", drive
->name
, rq
->cmd
);
2566 ide_end_request (0,HWGROUP (drive
)); /* Let the common code handle it */
2571 * Retry a failed packet command
2573 if (tape
->failed_pc
!= NULL
&& tape
->pc
->c
[0] == IDETAPE_REQUEST_SENSE_CMD
) {
2574 return idetape_issue_packet_command (drive
, tape
->failed_pc
);
2576 #if IDETAPE_DEBUG_BUGS
2577 if (postponed_rq
!= NULL
)
2578 if (rq
!= postponed_rq
) {
2579 printk (KERN_ERR
"ide-tape: ide-tape.c bug - Two DSC requests were queued\n");
2580 idetape_end_request (0,HWGROUP (drive
));
2583 #endif /* IDETAPE_DEBUG_BUGS */
2585 tape
->postponed_rq
= NULL
;
2588 * If the tape is still busy, postpone our request and service
2589 * the other device meanwhile.
2591 status
.all
= GET_STAT();
2594 * The OnStream tape drive doesn't support DSC. Assume
2595 * that DSC is always set.
2599 if (!drive
->dsc_overlap
&& rq
->cmd
!= IDETAPE_PC_RQ2
)
2600 set_bit (IDETAPE_IGNORE_DSC
, &tape
->flags
);
2603 * For the OnStream tape, check the current status of the tape
2604 * internal buffer using data gathered from the buffer fill
2605 * mode page, and postpone our request, effectively "disconnecting"
2606 * from the IDE bus, in case the buffer is full (writing) or
2607 * empty (reading), and there is a danger that our request will
2608 * hold the IDE bus during actual media access.
2610 if (tape
->tape_still_time
> 100 && tape
->tape_still_time
< 200)
2611 tape
->measure_insert_time
= 1;
2612 if (tape
->req_buffer_fill
&& (rq
->cmd
== IDETAPE_WRITE_RQ
|| rq
->cmd
== IDETAPE_READ_RQ
)) {
2613 tape
->req_buffer_fill
= 0;
2614 tape
->writes_since_buffer_fill
= 0;
2615 tape
->reads_since_buffer_fill
= 0;
2616 tape
->last_buffer_fill
= jiffies
;
2617 idetape_queue_onstream_buffer_fill(drive
);
2618 if (jiffies
> tape
->insert_time
)
2619 tape
->insert_speed
= tape
->insert_size
/ 1024 * HZ
/ (jiffies
- tape
->insert_time
);
2622 if (jiffies
> tape
->insert_time
)
2623 tape
->insert_speed
= tape
->insert_size
/ 1024 * HZ
/ (jiffies
- tape
->insert_time
);
2624 calculate_speeds(drive
);
2625 if (tape
->onstream
&& tape
->max_frames
&&
2626 ((rq
->cmd
== IDETAPE_WRITE_RQ
&& (tape
->cur_frames
== tape
->max_frames
|| (tape
->speed_control
&& tape
->cur_frames
> 5 && (tape
->insert_speed
> tape
->max_insert_speed
|| (0 /* tape->cur_frames > 30 && tape->tape_still_time > 200 */))))) ||
2627 (rq
->cmd
== IDETAPE_READ_RQ
&& (tape
->cur_frames
== 0 || (tape
->speed_control
&& (tape
->cur_frames
< tape
->max_frames
- 5) && tape
->insert_speed
> tape
->max_insert_speed
)) && rq
->nr_sectors
))) {
2628 #if IDETAPE_DEBUG_LOG
2629 if (tape
->debug_level
>= 4)
2630 printk(KERN_INFO
"ide-tape: postponing request, cmd %d, cur %d, max %d\n",
2631 rq
->cmd
, tape
->cur_frames
, tape
->max_frames
);
2633 if (tape
->postpone_cnt
++ < 500) {
2635 tape
->req_buffer_fill
= 1;
2638 else if (tape
->debug_level
>= 4)
2639 printk(KERN_INFO
"ide-tape: %s: postpone_cnt %d\n", tape
->name
, tape
->postpone_cnt
);
2642 if (!test_and_clear_bit (IDETAPE_IGNORE_DSC
, &tape
->flags
) && !status
.b
.dsc
) {
2643 if (postponed_rq
== NULL
) {
2644 tape
->dsc_polling_start
= jiffies
;
2645 tape
->dsc_polling_frequency
= tape
->best_dsc_rw_frequency
;
2646 tape
->dsc_timeout
= jiffies
+ IDETAPE_DSC_RW_TIMEOUT
;
2647 } else if ((signed long) (jiffies
- tape
->dsc_timeout
) > 0) {
2648 printk (KERN_ERR
"ide-tape: %s: DSC timeout\n", tape
->name
);
2649 if (rq
->cmd
== IDETAPE_PC_RQ2
) {
2650 idetape_media_access_finished (drive
);
2653 return ide_do_reset (drive
);
2655 } else if (jiffies
- tape
->dsc_polling_start
> IDETAPE_DSC_MA_THRESHOLD
)
2656 tape
->dsc_polling_frequency
= IDETAPE_DSC_MA_SLOW
;
2657 idetape_postpone_request (drive
);
2661 case IDETAPE_READ_RQ
:
2662 tape
->buffer_head
++;
2664 IO_trace(IO_IDETAPE_FIFO
, tape
->pipeline_head
, tape
->buffer_head
, tape
->tape_head
, tape
->minor
);
2666 tape
->postpone_cnt
= 0;
2667 tape
->reads_since_buffer_fill
++;
2668 if (tape
->onstream
) {
2669 if (tape
->cur_frames
- tape
->reads_since_buffer_fill
<= 0)
2670 tape
->req_buffer_fill
= 1;
2671 if (jiffies
> tape
->last_buffer_fill
+ 5 * HZ
/ 100)
2672 tape
->req_buffer_fill
= 1;
2674 pc
=idetape_next_pc_storage (drive
);
2675 idetape_create_read_cmd (tape
, pc
, rq
->current_nr_sectors
, rq
->bh
);
2677 case IDETAPE_WRITE_RQ
:
2678 tape
->buffer_head
++;
2680 IO_trace(IO_IDETAPE_FIFO
, tape
->pipeline_head
, tape
->buffer_head
, tape
->tape_head
, tape
->minor
);
2682 tape
->postpone_cnt
= 0;
2683 tape
->writes_since_buffer_fill
++;
2684 if (tape
->onstream
) {
2685 if (tape
->cur_frames
+ tape
->writes_since_buffer_fill
>= tape
->max_frames
)
2686 tape
->req_buffer_fill
= 1;
2687 if (jiffies
> tape
->last_buffer_fill
+ 5 * HZ
/ 100)
2688 tape
->req_buffer_fill
= 1;
2689 calculate_speeds(drive
);
2691 pc
=idetape_next_pc_storage (drive
);
2692 idetape_create_write_cmd (tape
, pc
, rq
->current_nr_sectors
, rq
->bh
);
2694 case IDETAPE_READ_BUFFER_RQ
:
2695 tape
->postpone_cnt
= 0;
2696 pc
=idetape_next_pc_storage (drive
);
2697 idetape_create_read_buffer_cmd (tape
, pc
, rq
->current_nr_sectors
, rq
->bh
);
2699 case IDETAPE_ABORTED_WRITE_RQ
:
2700 rq
->cmd
= IDETAPE_WRITE_RQ
;
2701 idetape_end_request (IDETAPE_ERROR_EOD
, HWGROUP(drive
));
2703 case IDETAPE_ABORTED_READ_RQ
:
2704 #if IDETAPE_DEBUG_LOG
2705 if (tape
->debug_level
>= 2)
2706 printk(KERN_INFO
"ide-tape: %s: detected aborted read rq\n", tape
->name
);
2708 rq
->cmd
= IDETAPE_READ_RQ
;
2709 idetape_end_request (IDETAPE_ERROR_EOD
, HWGROUP(drive
));
2711 case IDETAPE_PC_RQ1
:
2712 pc
=(idetape_pc_t
*) rq
->buffer
;
2713 rq
->cmd
= IDETAPE_PC_RQ2
;
2715 case IDETAPE_PC_RQ2
:
2716 idetape_media_access_finished (drive
);
2719 printk (KERN_ERR
"ide-tape: bug in IDETAPE_RQ_CMD macro\n");
2720 idetape_end_request (0,HWGROUP (drive
));
2723 return idetape_issue_packet_command (drive
, pc
);
2727 * Pipeline related functions
2729 static inline int idetape_pipeline_active (idetape_tape_t
*tape
)
2733 rc1
= test_bit(IDETAPE_PIPELINE_ACTIVE
, &tape
->flags
);
2734 rc2
= (tape
->active_data_request
!= NULL
);
2739 * idetape_kmalloc_stage uses __get_free_page to allocate a pipeline
2740 * stage, along with all the necessary small buffers which together make
2741 * a buffer of size tape->stage_size (or a bit more). We attempt to
2742 * combine sequential pages as much as possible.
2744 * Returns a pointer to the new allocated stage, or NULL if we
2745 * can't (or don't want to) allocate a stage.
2747 * Pipeline stages are optional and are used to increase performance.
2748 * If we can't allocate them, we'll manage without them.
2750 static idetape_stage_t
*__idetape_kmalloc_stage (idetape_tape_t
*tape
, int full
, int clear
)
2752 idetape_stage_t
*stage
;
2753 struct buffer_head
*prev_bh
, *bh
;
2754 int pages
= tape
->pages_per_stage
;
2757 if ((stage
= (idetape_stage_t
*) kmalloc (sizeof (idetape_stage_t
),GFP_KERNEL
)) == NULL
)
2761 bh
= stage
->bh
= (struct buffer_head
*) kmalloc (sizeof (struct buffer_head
), GFP_KERNEL
);
2764 bh
->b_reqnext
= NULL
;
2765 if ((bh
->b_data
= (char *) __get_free_page (GFP_KERNEL
)) == NULL
)
2768 memset(bh
->b_data
, 0, PAGE_SIZE
);
2769 bh
->b_size
= PAGE_SIZE
;
2770 atomic_set(&bh
->b_count
, full
? bh
->b_size
: 0);
2771 set_bit (BH_Lock
, &bh
->b_state
);
2774 if ((b_data
= (char *) __get_free_page (GFP_KERNEL
)) == NULL
)
2777 memset(b_data
, 0, PAGE_SIZE
);
2778 if (bh
->b_data
== b_data
+ PAGE_SIZE
) {
2779 bh
->b_size
+= PAGE_SIZE
;
2780 bh
->b_data
-= PAGE_SIZE
;
2782 atomic_add(PAGE_SIZE
, &bh
->b_count
);
2785 if (b_data
== bh
->b_data
+ bh
->b_size
) {
2786 bh
->b_size
+= PAGE_SIZE
;
2788 atomic_add(PAGE_SIZE
, &bh
->b_count
);
2792 if ((bh
= (struct buffer_head
*) kmalloc (sizeof (struct buffer_head
), GFP_KERNEL
)) == NULL
) {
2793 free_page ((unsigned long) b_data
);
2796 bh
->b_reqnext
= NULL
;
2797 bh
->b_data
= b_data
;
2798 bh
->b_size
= PAGE_SIZE
;
2799 atomic_set(&bh
->b_count
, full
? bh
->b_size
: 0);
2800 set_bit (BH_Lock
, &bh
->b_state
);
2801 prev_bh
->b_reqnext
= bh
;
2803 bh
->b_size
-= tape
->excess_bh_size
;
2805 atomic_sub(tape
->excess_bh_size
, &bh
->b_count
);
2807 stage
->aux
= (os_aux_t
*) (bh
->b_data
+ bh
->b_size
- OS_AUX_SIZE
);
2810 __idetape_kfree_stage (stage
);
2814 static idetape_stage_t
*idetape_kmalloc_stage (idetape_tape_t
*tape
)
2816 idetape_stage_t
*cache_stage
= tape
->cache_stage
;
2818 #if IDETAPE_DEBUG_LOG
2819 if (tape
->debug_level
>= 4)
2820 printk (KERN_INFO
"ide-tape: Reached idetape_kmalloc_stage\n");
2821 #endif /* IDETAPE_DEBUG_LOG */
2823 if (tape
->nr_stages
>= tape
->max_stages
)
2825 if (cache_stage
!= NULL
) {
2826 tape
->cache_stage
= NULL
;
2829 return __idetape_kmalloc_stage (tape
, 0, 0);
2832 static void idetape_copy_stage_from_user (idetape_tape_t
*tape
, idetape_stage_t
*stage
, const char *buf
, int n
)
2834 struct buffer_head
*bh
= tape
->bh
;
2838 #if IDETAPE_DEBUG_BUGS
2840 printk (KERN_ERR
"ide-tape: bh == NULL in idetape_copy_stage_from_user\n");
2843 #endif /* IDETAPE_DEBUG_BUGS */
2844 count
= IDE_MIN (bh
->b_size
- atomic_read(&bh
->b_count
), n
);
2845 copy_from_user (bh
->b_data
+ atomic_read(&bh
->b_count
), buf
, count
);
2846 n
-= count
; atomic_add(count
, &bh
->b_count
); buf
+= count
;
2847 if (atomic_read(&bh
->b_count
) == bh
->b_size
) {
2850 atomic_set(&bh
->b_count
, 0);
2856 static void idetape_copy_stage_to_user (idetape_tape_t
*tape
, char *buf
, idetape_stage_t
*stage
, int n
)
2858 struct buffer_head
*bh
= tape
->bh
;
2862 #if IDETAPE_DEBUG_BUGS
2864 printk (KERN_ERR
"ide-tape: bh == NULL in idetape_copy_stage_to_user\n");
2867 #endif /* IDETAPE_DEBUG_BUGS */
2868 count
= IDE_MIN (tape
->b_count
, n
);
2869 copy_to_user (buf
, tape
->b_data
, count
);
2870 n
-= count
; tape
->b_data
+= count
; tape
->b_count
-= count
; buf
+= count
;
2871 if (!tape
->b_count
) {
2872 tape
->bh
= bh
= bh
->b_reqnext
;
2874 tape
->b_data
= bh
->b_data
;
2875 tape
->b_count
= atomic_read(&bh
->b_count
);
2881 static void idetape_init_merge_stage (idetape_tape_t
*tape
)
2883 struct buffer_head
*bh
= tape
->merge_stage
->bh
;
2886 if (tape
->chrdev_direction
== idetape_direction_write
)
2887 atomic_set(&bh
->b_count
, 0);
2889 tape
->b_data
= bh
->b_data
;
2890 tape
->b_count
= atomic_read(&bh
->b_count
);
2894 static void idetape_switch_buffers (idetape_tape_t
*tape
, idetape_stage_t
*stage
)
2896 struct buffer_head
*tmp
;
2899 tmp
= stage
->bh
; tmp_aux
= stage
->aux
;
2900 stage
->bh
= tape
->merge_stage
->bh
; stage
->aux
= tape
->merge_stage
->aux
;
2901 tape
->merge_stage
->bh
= tmp
; tape
->merge_stage
->aux
= tmp_aux
;
2902 idetape_init_merge_stage (tape
);
2906 * idetape_add_stage_tail adds a new stage at the end of the pipeline.
2908 static void idetape_add_stage_tail (ide_drive_t
*drive
,idetape_stage_t
*stage
)
2910 idetape_tape_t
*tape
= drive
->driver_data
;
2911 unsigned long flags
;
2913 #if IDETAPE_DEBUG_LOG
2914 if (tape
->debug_level
>= 4)
2915 printk (KERN_INFO
"ide-tape: Reached idetape_add_stage_tail\n");
2916 #endif /* IDETAPE_DEBUG_LOG */
2917 spin_lock_irqsave(&tape
->spinlock
, flags
);
2919 if (tape
->last_stage
!= NULL
)
2920 tape
->last_stage
->next
=stage
;
2922 tape
->first_stage
=tape
->next_stage
=stage
;
2923 tape
->last_stage
=stage
;
2924 if (tape
->next_stage
== NULL
)
2925 tape
->next_stage
=tape
->last_stage
;
2927 tape
->nr_pending_stages
++;
2928 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
2932 * Initialize the OnStream AUX
2934 static void idetape_init_stage (ide_drive_t
*drive
, idetape_stage_t
*stage
, int frame_type
, int logical_blk_num
)
2936 idetape_tape_t
*tape
= drive
->driver_data
;
2937 os_aux_t
*aux
= stage
->aux
;
2938 os_partition_t
*par
= &aux
->partition
;
2939 os_dat_t
*dat
= &aux
->dat
;
2941 if (!tape
->onstream
|| tape
->raw
)
2943 memset(aux
, 0, sizeof(*aux
));
2944 aux
->format_id
= htonl(0);
2945 memcpy(aux
->application_sig
, "LIN3", 4);
2946 aux
->hdwr
= htonl(0);
2947 aux
->frame_type
= frame_type
;
2949 if (frame_type
== OS_FRAME_TYPE_HEADER
) {
2950 aux
->update_frame_cntr
= htonl(tape
->update_frame_cntr
);
2951 par
->partition_num
= OS_CONFIG_PARTITION
;
2952 par
->par_desc_ver
= OS_PARTITION_VERSION
;
2953 par
->wrt_pass_cntr
= htons(0xffff);
2954 par
->first_frame_addr
= htonl(0);
2955 par
->last_frame_addr
= htonl(0xbb7);
2957 aux
->update_frame_cntr
= htonl(0);
2958 par
->partition_num
= OS_DATA_PARTITION
;
2959 par
->par_desc_ver
= OS_PARTITION_VERSION
;
2960 par
->wrt_pass_cntr
= htons(tape
->wrt_pass_cntr
);
2961 par
->first_frame_addr
= htonl(0x14);
2962 par
->last_frame_addr
= htonl(19239 * 24);
2964 if (frame_type
!= OS_FRAME_TYPE_HEADER
) {
2965 aux
->frame_seq_num
= htonl(logical_blk_num
);
2966 aux
->logical_blk_num_high
= htonl(0);
2967 aux
->logical_blk_num
= htonl(logical_blk_num
);
2969 aux
->frame_seq_num
= htonl(0);
2970 aux
->logical_blk_num_high
= htonl(0);
2971 aux
->logical_blk_num
= htonl(0);
2974 if (frame_type
!= OS_FRAME_TYPE_HEADER
) {
2979 if (frame_type
== OS_FRAME_TYPE_DATA
)
2980 dat
->dat_list
[0].blk_sz
= htonl(32 * 1024);
2982 dat
->dat_list
[0].blk_sz
= 0;
2983 dat
->dat_list
[0].blk_cnt
= htons(1);
2984 if (frame_type
== OS_FRAME_TYPE_MARKER
)
2985 dat
->dat_list
[0].flags
= OS_DAT_FLAGS_MARK
;
2987 dat
->dat_list
[0].flags
= OS_DAT_FLAGS_DATA
;
2988 dat
->dat_list
[0].reserved
= 0;
2990 aux
->next_mark_addr
= htonl(tape
->first_mark_addr
);
2991 aux
->filemark_cnt
= ntohl(tape
->filemark_cnt
);
2992 aux
->phys_fm
= ntohl(0xffffffff);
2993 aux
->last_mark_addr
= ntohl(tape
->last_mark_addr
);
2997 * idetape_wait_for_request installs a semaphore in a pending request
2998 * and sleeps until it is serviced.
3000 * The caller should ensure that the request will not be serviced
3001 * before we install the semaphore (usually by disabling interrupts).
3003 static void idetape_wait_for_request (ide_drive_t
*drive
, struct request
*rq
)
3005 DECLARE_MUTEX_LOCKED(sem
);
3006 idetape_tape_t
*tape
= drive
->driver_data
;
3008 #if IDETAPE_DEBUG_BUGS
3009 if (rq
== NULL
|| !IDETAPE_RQ_CMD (rq
->cmd
)) {
3010 printk (KERN_ERR
"ide-tape: bug: Trying to sleep on non-valid request\n");
3013 #endif /* IDETAPE_DEBUG_BUGS */
3016 spin_unlock(&tape
->spinlock
);
3020 spin_lock_irq(&tape
->spinlock
);
3023 static ide_startstop_t
idetape_read_position_callback (ide_drive_t
*drive
)
3025 idetape_tape_t
*tape
= drive
->driver_data
;
3026 idetape_read_position_result_t
*result
;
3028 #if IDETAPE_DEBUG_LOG
3029 if (tape
->debug_level
>= 4)
3030 printk (KERN_INFO
"ide-tape: Reached idetape_read_position_callback\n");
3031 #endif /* IDETAPE_DEBUG_LOG */
3033 if (!tape
->pc
->error
) {
3034 result
= (idetape_read_position_result_t
*) tape
->pc
->buffer
;
3035 #if IDETAPE_DEBUG_LOG
3036 if (tape
->debug_level
>= 2)
3037 printk (KERN_INFO
"ide-tape: BOP - %s\n",result
->bop
? "Yes":"No");
3038 if (tape
->debug_level
>= 2)
3039 printk (KERN_INFO
"ide-tape: EOP - %s\n",result
->eop
? "Yes":"No");
3040 #endif /* IDETAPE_DEBUG_LOG */
3042 printk (KERN_INFO
"ide-tape: Block location is unknown to the tape\n");
3043 clear_bit (IDETAPE_ADDRESS_VALID
, &tape
->flags
);
3044 idetape_end_request (0,HWGROUP (drive
));
3046 #if IDETAPE_DEBUG_LOG
3047 if (tape
->debug_level
>= 2)
3048 printk (KERN_INFO
"ide-tape: Block Location - %u\n", ntohl (result
->first_block
));
3049 #endif /* IDETAPE_DEBUG_LOG */
3050 tape
->partition
= result
->partition
;
3051 tape
->first_frame_position
= ntohl (result
->first_block
);
3052 tape
->last_frame_position
= ntohl (result
->last_block
);
3053 tape
->blocks_in_buffer
= result
->blocks_in_buffer
[2];
3054 set_bit (IDETAPE_ADDRESS_VALID
, &tape
->flags
);
3055 idetape_end_request (1,HWGROUP (drive
));
3058 idetape_end_request (0,HWGROUP (drive
));
3064 * idetape_create_write_filemark_cmd will:
3066 * 1. Write a filemark if write_filemark=1.
3067 * 2. Flush the device buffers without writing a filemark
3068 * if write_filemark=0.
3071 static void idetape_create_write_filemark_cmd (ide_drive_t
*drive
, idetape_pc_t
*pc
,int write_filemark
)
3073 idetape_tape_t
*tape
= drive
->driver_data
;
3075 idetape_init_pc (pc
);
3076 pc
->c
[0] = IDETAPE_WRITE_FILEMARK_CMD
;
3079 pc
->c
[4] = write_filemark
;
3080 set_bit (PC_WAIT_FOR_DSC
, &pc
->flags
);
3081 pc
->callback
= &idetape_pc_callback
;
3084 static void idetape_create_test_unit_ready_cmd(idetape_pc_t
*pc
)
3086 idetape_init_pc(pc
);
3087 pc
->c
[0] = IDETAPE_TEST_UNIT_READY_CMD
;
3088 pc
->callback
= &idetape_pc_callback
;
3092 * idetape_queue_pc_tail is based on the following functions:
3094 * ide_do_drive_cmd from ide.c
3095 * cdrom_queue_request and cdrom_queue_packet_command from ide-cd.c
3097 * We add a special packet command request to the tail of the request queue,
3098 * and wait for it to be serviced.
3100 * This is not to be called from within the request handling part
3101 * of the driver ! We allocate here data in the stack, and it is valid
3102 * until the request is finished. This is not the case for the bottom
3103 * part of the driver, where we are always leaving the functions to wait
3104 * for an interrupt or a timer event.
3106 * From the bottom part of the driver, we should allocate safe memory
3107 * using idetape_next_pc_storage and idetape_next_rq_storage, and add
3108 * the request to the request list without waiting for it to be serviced !
3109 * In that case, we usually use idetape_queue_pc_head.
3111 static int __idetape_queue_pc_tail (ide_drive_t
*drive
,idetape_pc_t
*pc
)
3115 ide_init_drive_cmd (&rq
);
3116 rq
.buffer
= (char *) pc
;
3117 rq
.cmd
= IDETAPE_PC_RQ1
;
3118 return ide_do_drive_cmd (drive
, &rq
, ide_wait
);
3121 static void idetape_create_load_unload_cmd (ide_drive_t
*drive
, idetape_pc_t
*pc
,int cmd
)
3123 idetape_tape_t
*tape
= drive
->driver_data
;
3125 idetape_init_pc (pc
);
3126 pc
->c
[0] = IDETAPE_LOAD_UNLOAD_CMD
;
3130 set_bit (PC_WAIT_FOR_DSC
, &pc
->flags
);
3131 pc
->callback
= &idetape_pc_callback
;
3134 static int idetape_wait_ready (ide_drive_t
*drive
, unsigned long long timeout
)
3136 idetape_tape_t
*tape
= drive
->driver_data
;
3140 * Wait for the tape to become ready
3143 while (jiffies
< timeout
) {
3144 idetape_create_test_unit_ready_cmd(&pc
);
3145 if (!__idetape_queue_pc_tail(drive
, &pc
))
3147 if (tape
->sense_key
== 2 && tape
->asc
== 4 && tape
->ascq
== 2) {
3148 idetape_create_load_unload_cmd (drive
, &pc
, IDETAPE_LU_LOAD_MASK
);
3149 __idetape_queue_pc_tail(drive
,&pc
);
3150 idetape_create_test_unit_ready_cmd(&pc
);
3151 if (!__idetape_queue_pc_tail(drive
, &pc
))
3154 if (!(tape
->sense_key
== 2 && tape
->asc
== 4 && (tape
->ascq
== 1 || tape
->ascq
== 8)))
3156 current
->state
= TASK_INTERRUPTIBLE
;
3157 schedule_timeout(HZ
/ 10);
3162 static int idetape_queue_pc_tail (ide_drive_t
*drive
,idetape_pc_t
*pc
)
3164 idetape_tape_t
*tape
= drive
->driver_data
;
3167 rc
= __idetape_queue_pc_tail(drive
, pc
);
3169 if (tape
->onstream
&& test_bit(PC_WAIT_FOR_DSC
, &pc
->flags
))
3170 rc
= idetape_wait_ready(drive
, 60 * 10 * HZ
); /* AJN-4: Changed from 5 to 10 minutes;
3171 because retension takes approx. 8:20 with Onstream 30GB tape */
3175 static int idetape_flush_tape_buffers (ide_drive_t
*drive
)
3180 idetape_create_write_filemark_cmd(drive
, &pc
, 0);
3181 if ((rc
= idetape_queue_pc_tail (drive
,&pc
)))
3183 idetape_wait_ready(drive
, 60 * 5 * HZ
);
3187 static void idetape_create_read_position_cmd (idetape_pc_t
*pc
)
3189 idetape_init_pc (pc
);
3190 pc
->c
[0] = IDETAPE_READ_POSITION_CMD
;
3191 pc
->request_transfer
= 20;
3192 pc
->callback
= &idetape_read_position_callback
;
3195 static int idetape_read_position (ide_drive_t
*drive
)
3197 idetape_tape_t
*tape
= drive
->driver_data
;
3201 #ifdef NO_LONGER_REQUIRED
3202 idetape_flush_tape_buffers(drive
);
3204 idetape_create_read_position_cmd(&pc
);
3205 if (idetape_queue_pc_tail (drive
,&pc
))
3207 position
= tape
->first_frame_position
;
3208 #ifdef NO_LONGER_REQUIRED
3209 if (tape
->onstream
) {
3210 if ((position
!= tape
->last_frame_position
- tape
->blocks_in_buffer
) &&
3211 (position
!= tape
->last_frame_position
+ tape
->blocks_in_buffer
)) {
3212 if (tape
->blocks_in_buffer
== 0) {
3213 printk("ide-tape: %s: correcting read position %d, %d, %d\n", tape
->name
, position
, tape
->last_frame_position
, tape
->blocks_in_buffer
);
3214 position
= tape
->last_frame_position
;
3215 tape
->first_frame_position
= position
;
3223 static void idetape_create_locate_cmd (ide_drive_t
*drive
, idetape_pc_t
*pc
, unsigned int block
, byte partition
, int skip
)
3225 idetape_tape_t
*tape
= drive
->driver_data
;
3227 idetape_init_pc (pc
);
3228 pc
->c
[0] = IDETAPE_LOCATE_CMD
;
3233 put_unaligned (htonl (block
), (unsigned int *) &pc
->c
[3]);
3234 pc
->c
[8] = partition
;
3236 pc
->c
[9] = skip
<< 7;
3237 set_bit (PC_WAIT_FOR_DSC
, &pc
->flags
);
3238 pc
->callback
= &idetape_pc_callback
;
3241 static void idetape_create_prevent_cmd (ide_drive_t
*drive
, idetape_pc_t
*pc
, int prevent
)
3243 idetape_init_pc(pc
);
3244 pc
->c
[0] = IDETAPE_PREVENT_CMD
;
3246 pc
->callback
= &idetape_pc_callback
;
3249 static int __idetape_discard_read_pipeline (ide_drive_t
*drive
)
3251 idetape_tape_t
*tape
= drive
->driver_data
;
3252 unsigned long flags
;
3255 if (tape
->chrdev_direction
!= idetape_direction_read
)
3257 tape
->merge_stage_size
= 0;
3258 if (tape
->merge_stage
!= NULL
) {
3259 __idetape_kfree_stage (tape
->merge_stage
);
3260 tape
->merge_stage
= NULL
;
3262 tape
->chrdev_direction
= idetape_direction_none
;
3264 if (tape
->first_stage
== NULL
)
3267 spin_lock_irqsave(&tape
->spinlock
, flags
);
3268 tape
->next_stage
= NULL
;
3269 if (idetape_pipeline_active (tape
))
3270 idetape_wait_for_request(drive
, tape
->active_data_request
);
3271 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
3273 cnt
= tape
->nr_stages
- tape
->nr_pending_stages
;
3274 while (tape
->first_stage
!= NULL
)
3275 idetape_remove_stage_head (drive
);
3276 tape
->nr_pending_stages
= 0;
3277 tape
->max_stages
= tape
->min_pipeline
;
3282 * idetape_position_tape positions the tape to the requested block
3283 * using the LOCATE packet command. A READ POSITION command is then
3284 * issued to check where we are positioned.
3286 * Like all higher level operations, we queue the commands at the tail
3287 * of the request queue and wait for their completion.
3290 static int idetape_position_tape (ide_drive_t
*drive
, unsigned int block
, byte partition
, int skip
)
3292 idetape_tape_t
*tape
= drive
->driver_data
;
3296 if (tape
->chrdev_direction
== idetape_direction_read
)
3297 __idetape_discard_read_pipeline(drive
);
3298 idetape_wait_ready(drive
, 60 * 5 * HZ
);
3299 idetape_create_locate_cmd (drive
, &pc
, block
, partition
, skip
);
3300 retval
=idetape_queue_pc_tail (drive
,&pc
);
3301 if (retval
) return (retval
);
3303 idetape_create_read_position_cmd (&pc
);
3304 return (idetape_queue_pc_tail (drive
,&pc
));
3307 static void idetape_discard_read_pipeline (ide_drive_t
*drive
, int restore_position
)
3309 idetape_tape_t
*tape
= drive
->driver_data
;
3313 cnt
= __idetape_discard_read_pipeline(drive
);
3314 if (restore_position
) {
3315 position
= idetape_read_position(drive
);
3317 if (tape
->debug_level
>= 2)
3318 printk(KERN_INFO
"ide-tape: address %u, nr_stages %d\n", position
, cnt
);
3320 seek
= position
> cnt
? position
- cnt
: 0;
3321 if (idetape_position_tape(drive
, seek
, 0, 0)) {
3322 printk(KERN_INFO
"ide-tape: %s: position_tape failed in discard_pipeline()\n", tape
->name
);
3328 static void idetape_update_stats (ide_drive_t
*drive
)
3332 idetape_create_mode_sense_cmd (&pc
, 0x33);
3333 pc
.callback
= idetape_onstream_buffer_fill_callback
;
3334 (void) idetape_queue_pc_tail(drive
, &pc
);
3338 * idetape_queue_rw_tail generates a read/write request for the block
3339 * device interface and wait for it to be serviced.
3341 static int idetape_queue_rw_tail (ide_drive_t
*drive
, int cmd
, int blocks
, struct buffer_head
*bh
)
3343 idetape_tape_t
*tape
= drive
->driver_data
;
3346 #if IDETAPE_DEBUG_LOG
3347 if (tape
->debug_level
>= 2)
3348 printk (KERN_INFO
"ide-tape: idetape_queue_rw_tail: cmd=%d\n",cmd
);
3349 #endif /* IDETAPE_DEBUG_LOG */
3350 #if IDETAPE_DEBUG_BUGS
3351 if (idetape_pipeline_active (tape
)) {
3352 printk (KERN_ERR
"ide-tape: bug: the pipeline is active in idetape_queue_rw_tail\n");
3355 #endif /* IDETAPE_DEBUG_BUGS */
3357 ide_init_drive_cmd (&rq
);
3360 rq
.sector
= tape
->first_frame_position
;
3361 rq
.nr_sectors
= rq
.current_nr_sectors
= blocks
;
3363 tape
->postpone_cnt
= 600;
3364 (void) ide_do_drive_cmd (drive
, &rq
, ide_wait
);
3366 if (cmd
!= IDETAPE_READ_RQ
&& cmd
!= IDETAPE_WRITE_RQ
)
3369 if (tape
->merge_stage
)
3370 idetape_init_merge_stage (tape
);
3371 if (rq
.errors
== IDETAPE_ERROR_GENERAL
)
3373 return (tape
->tape_block_size
* (blocks
-rq
.current_nr_sectors
));
3377 * Read back the drive's internal buffer contents, as a part
3378 * of the write error recovery mechanism for old OnStream
3379 * firmware revisions.
3381 static void idetape_onstream_read_back_buffer (ide_drive_t
*drive
)
3383 idetape_tape_t
*tape
= drive
->driver_data
;
3384 int frames
, i
, logical_blk_num
;
3385 idetape_stage_t
*stage
, *first
= NULL
, *last
= NULL
;
3389 unsigned long flags
;
3391 idetape_update_stats(drive
);
3392 frames
= tape
->cur_frames
;
3393 logical_blk_num
= ntohl(tape
->first_stage
->aux
->logical_blk_num
) - frames
;
3394 printk(KERN_INFO
"ide-tape: %s: reading back %d frames from the drive's internal buffer\n", tape
->name
, frames
);
3395 for (i
= 0; i
< frames
; i
++) {
3396 stage
= __idetape_kmalloc_stage(tape
, 0, 0);
3400 p
= stage
->bh
->b_data
;
3401 idetape_queue_rw_tail(drive
, IDETAPE_READ_BUFFER_RQ
, tape
->capabilities
.ctl
, stage
->bh
);
3403 if (tape
->debug_level
>= 2)
3404 printk(KERN_INFO
"ide-tape: %s: read back logical block %d, data %x %x %x %x\n", tape
->name
, logical_blk_num
, *p
++, *p
++, *p
++, *p
++);
3407 ide_init_drive_cmd (rq
);
3408 rq
->cmd
= IDETAPE_WRITE_RQ
;
3409 rq
->sector
= tape
->first_frame_position
;
3410 rq
->nr_sectors
= rq
->current_nr_sectors
= tape
->capabilities
.ctl
;
3411 idetape_init_stage(drive
, stage
, OS_FRAME_TYPE_DATA
, logical_blk_num
++);
3418 spin_lock_irqsave(&tape
->spinlock
, flags
);
3419 last
->next
= tape
->first_stage
;
3420 tape
->next_stage
= tape
->first_stage
= first
;
3421 tape
->nr_stages
+= frames
;
3422 tape
->nr_pending_stages
+= frames
;
3423 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
3425 idetape_update_stats(drive
);
3427 if (tape
->debug_level
>= 2)
3428 printk(KERN_INFO
"ide-tape: %s: frames left in buffer: %d\n", tape
->name
, tape
->cur_frames
);
3433 * Error recovery algorithm for the OnStream tape.
3435 static void idetape_onstream_write_error_recovery (ide_drive_t
*drive
)
3437 idetape_tape_t
*tape
= drive
->driver_data
;
3440 if (tape
->onstream_write_error
== 1) {
3441 printk(KERN_ERR
"ide-tape: %s: detected physical bad block at %u\n", tape
->name
, ntohl(tape
->sense
.information
));
3442 block
= ntohl(tape
->sense
.information
) + 80;
3443 idetape_update_stats(drive
);
3444 printk(KERN_ERR
"ide-tape: %s: relocating %d buffered logical blocks to physical block %u\n", tape
->name
, tape
->cur_frames
, block
);
3445 idetape_update_stats(drive
);
3446 if (tape
->firmware_revision_num
>= 106)
3447 idetape_position_tape(drive
, block
, 0, 1);
3449 idetape_onstream_read_back_buffer(drive
);
3450 idetape_position_tape(drive
, block
, 0, 0);
3452 idetape_read_position(drive
);
3454 if (tape
->debug_level
>= 1)
3455 printk(KERN_ERR
"ide-tape: %s: positioning complete, cur_frames %d, pos %d, tape pos %d\n", tape
->name
, tape
->cur_frames
, tape
->first_frame_position
, tape
->last_frame_position
);
3457 } else if (tape
->onstream_write_error
== 2) {
3459 if (tape
->debug_level
>= 1)
3460 printk(KERN_INFO
"ide-tape: %s: skipping over config partition\n", tape
->name
);
3462 idetape_flush_tape_buffers(drive
);
3463 block
= idetape_read_position(drive
);
3465 printk(KERN_ERR
"ide-tape: warning, current position %d, expected %d\n", block
, 0xba4);
3466 idetape_position_tape(drive
, 0xbb8, 0, 0);
3468 tape
->onstream_write_error
= 0;
3472 * idetape_insert_pipeline_into_queue is used to start servicing the
3473 * pipeline stages, starting from tape->next_stage.
3475 static void idetape_insert_pipeline_into_queue (ide_drive_t
*drive
)
3477 idetape_tape_t
*tape
= drive
->driver_data
;
3479 if (tape
->next_stage
== NULL
)
3481 if (!idetape_pipeline_active (tape
)) {
3482 if (tape
->onstream_write_error
)
3483 idetape_onstream_write_error_recovery(drive
);
3484 set_bit(IDETAPE_PIPELINE_ACTIVE
, &tape
->flags
);
3485 idetape_active_next_stage (drive
);
3486 (void) ide_do_drive_cmd (drive
, tape
->active_data_request
, ide_end
);
3490 static void idetape_create_inquiry_cmd (idetape_pc_t
*pc
)
3492 idetape_init_pc(pc
);
3493 pc
->c
[0] = IDETAPE_INQUIRY_CMD
;
3494 pc
->c
[4] = pc
->request_transfer
= 254;
3495 pc
->callback
= &idetape_pc_callback
;
3498 static void idetape_create_rewind_cmd (ide_drive_t
*drive
, idetape_pc_t
*pc
)
3500 idetape_tape_t
*tape
= drive
->driver_data
;
3502 idetape_init_pc (pc
);
3503 pc
->c
[0] = IDETAPE_REWIND_CMD
;
3506 set_bit (PC_WAIT_FOR_DSC
, &pc
->flags
);
3507 pc
->callback
= &idetape_pc_callback
;
3510 static void idetape_create_mode_select_cmd (idetape_pc_t
*pc
, int length
)
3512 idetape_init_pc (pc
);
3513 set_bit (PC_WRITING
, &pc
->flags
);
3514 pc
->c
[0] = IDETAPE_MODE_SELECT_CMD
;
3516 put_unaligned (htons(length
), (unsigned short *) &pc
->c
[3]);
3517 pc
->request_transfer
= 255;
3518 pc
->callback
= &idetape_pc_callback
;
3521 static void idetape_create_erase_cmd (idetape_pc_t
*pc
)
3523 idetape_init_pc (pc
);
3524 pc
->c
[0] = IDETAPE_ERASE_CMD
;
3526 set_bit (PC_WAIT_FOR_DSC
, &pc
->flags
);
3527 pc
->callback
= &idetape_pc_callback
;
3530 static void idetape_create_space_cmd (idetape_pc_t
*pc
,int count
,byte cmd
)
3532 idetape_init_pc (pc
);
3533 pc
->c
[0] = IDETAPE_SPACE_CMD
;
3534 put_unaligned (htonl (count
), (unsigned int *) &pc
->c
[1]);
3536 set_bit (PC_WAIT_FOR_DSC
, &pc
->flags
);
3537 pc
->callback
= &idetape_pc_callback
;
3541 * Verify that we have the correct tape frame
3543 static int idetape_verify_stage (ide_drive_t
*drive
, idetape_stage_t
*stage
, int logical_blk_num
, int quiet
)
3545 idetape_tape_t
*tape
= drive
->driver_data
;
3546 os_aux_t
*aux
= stage
->aux
;
3547 os_partition_t
*par
= &aux
->partition
;
3548 struct request
*rq
= &stage
->rq
;
3549 struct buffer_head
*bh
;
3551 if (!tape
->onstream
)
3557 memset(bh
->b_data
, 0, bh
->b_size
);
3560 strcpy(stage
->bh
->b_data
, "READ ERROR ON FRAME");
3564 if (rq
->errors
== IDETAPE_ERROR_GENERAL
) {
3565 printk(KERN_INFO
"ide-tape: %s: skipping frame, read error\n", tape
->name
);
3568 if (rq
->errors
== IDETAPE_ERROR_EOD
) {
3569 printk(KERN_INFO
"ide-tape: %s: skipping frame, eod\n", tape
->name
);
3572 if (ntohl(aux
->format_id
) != 0) {
3573 printk(KERN_INFO
"ide-tape: %s: skipping frame, format_id %u\n", tape
->name
, ntohl(aux
->format_id
));
3576 if (memcmp(aux
->application_sig
, tape
->application_sig
, 4) != 0) {
3577 printk(KERN_INFO
"ide-tape: %s: skipping frame, incorrect application signature\n", tape
->name
);
3580 if (aux
->frame_type
!= OS_FRAME_TYPE_DATA
&&
3581 aux
->frame_type
!= OS_FRAME_TYPE_EOD
&&
3582 aux
->frame_type
!= OS_FRAME_TYPE_MARKER
) {
3583 printk(KERN_INFO
"ide-tape: %s: skipping frame, frame type %x\n", tape
->name
, aux
->frame_type
);
3586 if (par
->partition_num
!= OS_DATA_PARTITION
) {
3587 if (!tape
->linux_media
|| tape
->linux_media_version
!= 2) {
3588 printk(KERN_INFO
"ide-tape: %s: skipping frame, partition num %d\n", tape
->name
, par
->partition_num
);
3592 if (par
->par_desc_ver
!= OS_PARTITION_VERSION
) {
3593 printk(KERN_INFO
"ide-tape: %s: skipping frame, partition version %d\n", tape
->name
, par
->par_desc_ver
);
3596 if (ntohs(par
->wrt_pass_cntr
) != tape
->wrt_pass_cntr
) {
3597 printk(KERN_INFO
"ide-tape: %s: skipping frame, wrt_pass_cntr %d (expected %d)(logical_blk_num %u)\n", tape
->name
, ntohs(par
->wrt_pass_cntr
), tape
->wrt_pass_cntr
, ntohl(aux
->logical_blk_num
));
3600 if (aux
->frame_seq_num
!= aux
->logical_blk_num
) {
3601 printk(KERN_INFO
"ide-tape: %s: skipping frame, seq != logical\n", tape
->name
);
3604 if (logical_blk_num
!= -1 && ntohl(aux
->logical_blk_num
) != logical_blk_num
) {
3606 printk(KERN_INFO
"ide-tape: %s: skipping frame, logical_blk_num %u (expected %d)\n", tape
->name
, ntohl(aux
->logical_blk_num
), logical_blk_num
);
3609 if (aux
->frame_type
== OS_FRAME_TYPE_MARKER
) {
3610 rq
->errors
= IDETAPE_ERROR_FILEMARK
;
3611 rq
->current_nr_sectors
= rq
->nr_sectors
;
3616 static void idetape_wait_first_stage (ide_drive_t
*drive
)
3618 idetape_tape_t
*tape
= drive
->driver_data
;
3619 unsigned long flags
;
3621 if (tape
->first_stage
== NULL
)
3623 spin_lock_irqsave(&tape
->spinlock
, flags
);
3624 if (tape
->active_stage
== tape
->first_stage
)
3625 idetape_wait_for_request(drive
, tape
->active_data_request
);
3626 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
3630 * idetape_add_chrdev_write_request tries to add a character device
3631 * originated write request to our pipeline. In case we don't succeed,
3632 * we revert to non-pipelined operation mode for this request.
3634 * 1. Try to allocate a new pipeline stage.
3635 * 2. If we can't, wait for more and more requests to be serviced
3636 * and try again each time.
3637 * 3. If we still can't allocate a stage, fallback to
3638 * non-pipelined operation mode for this request.
3640 static int idetape_add_chrdev_write_request (ide_drive_t
*drive
, int blocks
)
3642 idetape_tape_t
*tape
= drive
->driver_data
;
3643 idetape_stage_t
*new_stage
;
3644 unsigned long flags
;
3647 #if IDETAPE_DEBUG_LOG
3648 if (tape
->debug_level
>= 3)
3649 printk (KERN_INFO
"ide-tape: Reached idetape_add_chrdev_write_request\n");
3650 #endif /* IDETAPE_DEBUG_LOG */
3653 * Attempt to allocate a new stage.
3654 * Pay special attention to possible race conditions.
3656 while ((new_stage
= idetape_kmalloc_stage (tape
)) == NULL
) {
3657 spin_lock_irqsave(&tape
->spinlock
, flags
);
3658 if (idetape_pipeline_active (tape
)) {
3659 idetape_wait_for_request(drive
, tape
->active_data_request
);
3660 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
3662 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
3663 idetape_insert_pipeline_into_queue (drive
);
3664 if (idetape_pipeline_active (tape
))
3667 * Linux is short on memory. Fallback to
3668 * non-pipelined operation mode for this request.
3670 return idetape_queue_rw_tail (drive
, IDETAPE_WRITE_RQ
, blocks
, tape
->merge_stage
->bh
);
3673 rq
= &new_stage
->rq
;
3674 ide_init_drive_cmd (rq
);
3675 rq
->cmd
= IDETAPE_WRITE_RQ
;
3676 rq
->sector
= tape
->first_frame_position
; /* Doesn't actually matter - We always assume sequential access */
3677 rq
->nr_sectors
= rq
->current_nr_sectors
= blocks
;
3679 idetape_switch_buffers (tape
, new_stage
);
3680 idetape_init_stage(drive
, new_stage
, OS_FRAME_TYPE_DATA
, tape
->logical_blk_num
);
3681 tape
->logical_blk_num
++;
3682 idetape_add_stage_tail (drive
,new_stage
);
3683 tape
->pipeline_head
++;
3685 IO_trace(IO_IDETAPE_FIFO
, tape
->pipeline_head
, tape
->buffer_head
, tape
->tape_head
, tape
->minor
);
3687 calculate_speeds(drive
);
3690 * Estimate whether the tape has stopped writing by checking
3691 * if our write pipeline is currently empty. If we are not
3692 * writing anymore, wait for the pipeline to be full enough
3693 * (90%) before starting to service requests, so that we will
3694 * be able to keep up with the higher speeds of the tape.
3696 * For the OnStream drive, we can query the number of pending
3697 * frames in the drive's internal buffer. As long as the tape
3698 * is still writing, it is better to write frames immediately
3699 * rather than gather them in the pipeline. This will give the
3700 * tape's firmware the ability to sense the current incoming
3701 * data rate more accurately, and since the OnStream tape
3702 * supports variable speeds, it can try to adjust itself to the
3703 * incoming data rate.
3705 if (!idetape_pipeline_active(tape
)) {
3706 if (tape
->nr_stages
>= tape
->max_stages
* 9 / 10 ||
3707 tape
->nr_stages
>= tape
->max_stages
- tape
->uncontrolled_pipeline_head_speed
* 3 * 1024 / tape
->tape_block_size
) {
3708 tape
->measure_insert_time
= 1;
3709 tape
->insert_time
= jiffies
;
3710 tape
->insert_size
= 0;
3711 tape
->insert_speed
= 0;
3712 idetape_insert_pipeline_into_queue (drive
);
3713 } else if (tape
->onstream
) {
3714 idetape_update_stats(drive
);
3715 if (tape
->cur_frames
> 5)
3716 idetape_insert_pipeline_into_queue (drive
);
3719 if (test_and_clear_bit (IDETAPE_PIPELINE_ERROR
, &tape
->flags
)) /* Return a deferred error */
3725 * idetape_wait_for_pipeline will wait until all pending pipeline
3726 * requests are serviced. Typically called on device close.
3728 static void idetape_wait_for_pipeline (ide_drive_t
*drive
)
3730 idetape_tape_t
*tape
= drive
->driver_data
;
3731 unsigned long flags
;
3733 while (tape
->next_stage
|| idetape_pipeline_active(tape
)) {
3734 idetape_insert_pipeline_into_queue (drive
);
3735 spin_lock_irqsave(&tape
->spinlock
, flags
);
3736 if (idetape_pipeline_active(tape
))
3737 idetape_wait_for_request(drive
, tape
->active_data_request
);
3738 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
3742 static void idetape_empty_write_pipeline (ide_drive_t
*drive
)
3744 idetape_tape_t
*tape
= drive
->driver_data
;
3746 struct buffer_head
*bh
;
3748 #if IDETAPE_DEBUG_BUGS
3749 if (tape
->chrdev_direction
!= idetape_direction_write
) {
3750 printk (KERN_ERR
"ide-tape: bug: Trying to empty write pipeline, but we are not writing.\n");
3753 if (tape
->merge_stage_size
> tape
->stage_size
) {
3754 printk (KERN_ERR
"ide-tape: bug: merge_buffer too big\n");
3755 tape
->merge_stage_size
= tape
->stage_size
;
3757 #endif /* IDETAPE_DEBUG_BUGS */
3758 if (tape
->merge_stage_size
) {
3759 blocks
=tape
->merge_stage_size
/tape
->tape_block_size
;
3760 if (tape
->merge_stage_size
% tape
->tape_block_size
) {
3762 i
= tape
->tape_block_size
- tape
->merge_stage_size
% tape
->tape_block_size
;
3763 bh
= tape
->bh
->b_reqnext
;
3765 atomic_set(&bh
->b_count
, 0);
3771 printk(KERN_INFO
"ide-tape: bug, bh NULL\n");
3774 min
= IDE_MIN(i
, bh
->b_size
- atomic_read(&bh
->b_count
));
3775 memset(bh
->b_data
+ atomic_read(&bh
->b_count
), 0, min
);
3776 atomic_add(min
, &bh
->b_count
);
3781 (void) idetape_add_chrdev_write_request (drive
, blocks
);
3782 tape
->merge_stage_size
= 0;
3784 idetape_wait_for_pipeline (drive
);
3785 if (tape
->merge_stage
!= NULL
) {
3786 __idetape_kfree_stage (tape
->merge_stage
);
3787 tape
->merge_stage
= NULL
;
3789 clear_bit (IDETAPE_PIPELINE_ERROR
, &tape
->flags
);
3790 tape
->chrdev_direction
=idetape_direction_none
;
3793 * On the next backup, perform the feedback loop again.
3794 * (I don't want to keep sense information between backups,
3795 * as some systems are constantly on, and the system load
3796 * can be totally different on the next backup).
3798 tape
->max_stages
= tape
->min_pipeline
;
3799 #if IDETAPE_DEBUG_BUGS
3800 if (tape
->first_stage
!= NULL
|| tape
->next_stage
!= NULL
|| tape
->last_stage
!= NULL
|| tape
->nr_stages
!= 0) {
3801 printk (KERN_ERR
"ide-tape: ide-tape pipeline bug, "
3802 "first_stage %p, next_stage %p, last_stage %p, nr_stages %d\n",
3803 tape
->first_stage
, tape
->next_stage
, tape
->last_stage
, tape
->nr_stages
);
3805 #endif /* IDETAPE_DEBUG_BUGS */
3808 static void idetape_restart_speed_control (ide_drive_t
*drive
)
3810 idetape_tape_t
*tape
= drive
->driver_data
;
3812 tape
->restart_speed_control_req
= 0;
3813 tape
->pipeline_head
= 0;
3814 tape
->buffer_head
= tape
->tape_head
= tape
->cur_frames
;
3815 tape
->controlled_last_pipeline_head
= tape
->uncontrolled_last_pipeline_head
= 0;
3816 tape
->controlled_previous_pipeline_head
= tape
->uncontrolled_previous_pipeline_head
= 0;
3817 tape
->pipeline_head_speed
= tape
->controlled_pipeline_head_speed
= 5000;
3818 tape
->uncontrolled_pipeline_head_speed
= 0;
3819 tape
->controlled_pipeline_head_time
= tape
->uncontrolled_pipeline_head_time
= jiffies
;
3820 tape
->controlled_previous_head_time
= tape
->uncontrolled_previous_head_time
= jiffies
;
3823 static int idetape_initiate_read (ide_drive_t
*drive
, int max_stages
)
3825 idetape_tape_t
*tape
= drive
->driver_data
;
3826 idetape_stage_t
*new_stage
;
3829 int blocks
= tape
->capabilities
.ctl
;
3831 if (tape
->chrdev_direction
!= idetape_direction_read
) { /* Initialize read operation */
3832 if (tape
->chrdev_direction
== idetape_direction_write
) {
3833 idetape_empty_write_pipeline (drive
);
3834 idetape_flush_tape_buffers (drive
);
3836 #if IDETAPE_DEBUG_BUGS
3837 if (tape
->merge_stage
|| tape
->merge_stage_size
) {
3838 printk (KERN_ERR
"ide-tape: merge_stage_size should be 0 now\n");
3839 tape
->merge_stage_size
= 0;
3841 #endif /* IDETAPE_DEBUG_BUGS */
3842 if ((tape
->merge_stage
= __idetape_kmalloc_stage (tape
, 0, 0)) == NULL
)
3844 tape
->chrdev_direction
= idetape_direction_read
;
3845 tape
->logical_blk_num
= 0;
3848 * Issue a read 0 command to ensure that DSC handshake
3849 * is switched from completion mode to buffer available
3852 bytes_read
= idetape_queue_rw_tail (drive
, IDETAPE_READ_RQ
, 0, tape
->merge_stage
->bh
);
3853 if (bytes_read
< 0) {
3854 kfree (tape
->merge_stage
);
3855 tape
->merge_stage
= NULL
;
3856 tape
->chrdev_direction
= idetape_direction_none
;
3860 if (tape
->restart_speed_control_req
)
3861 idetape_restart_speed_control(drive
);
3862 ide_init_drive_cmd (&rq
);
3863 rq
.cmd
= IDETAPE_READ_RQ
;
3864 rq
.sector
= tape
->first_frame_position
;
3865 rq
.nr_sectors
= rq
.current_nr_sectors
= blocks
;
3866 if (!test_bit(IDETAPE_PIPELINE_ERROR
, &tape
->flags
) && tape
->nr_stages
<= max_stages
) {
3867 new_stage
=idetape_kmalloc_stage (tape
);
3868 while (new_stage
!= NULL
) {
3870 idetape_add_stage_tail (drive
,new_stage
);
3871 if (tape
->nr_stages
>= max_stages
)
3873 new_stage
=idetape_kmalloc_stage (tape
);
3876 if (!idetape_pipeline_active(tape
)) {
3877 if (tape
->nr_pending_stages
>= 3 * max_stages
/ 4) {
3878 tape
->measure_insert_time
= 1;
3879 tape
->insert_time
= jiffies
;
3880 tape
->insert_size
= 0;
3881 tape
->insert_speed
= 0;
3882 idetape_insert_pipeline_into_queue (drive
);
3883 } else if (tape
->onstream
) {
3884 idetape_update_stats(drive
);
3885 if (tape
->cur_frames
< tape
->max_frames
- 5)
3886 idetape_insert_pipeline_into_queue (drive
);
3892 static int idetape_get_logical_blk (ide_drive_t
*drive
, int logical_blk_num
, int max_stages
, int quiet
)
3894 idetape_tape_t
*tape
= drive
->driver_data
;
3895 unsigned long flags
;
3896 int cnt
= 0, x
, position
;
3899 * Search and wait for the next logical tape block
3902 if (cnt
++ > 1000) { /* AJN: was 100 */
3903 printk(KERN_INFO
"ide-tape: %s: couldn't find logical block %d, aborting\n", tape
->name
, logical_blk_num
);
3906 idetape_initiate_read(drive
, max_stages
);
3907 if (tape
->first_stage
== NULL
) {
3908 if (tape
->onstream
) {
3910 if (tape
->debug_level
>= 1)
3911 printk(KERN_INFO
"ide-tape: %s: first_stage == NULL, pipeline error %ld\n", tape
->name
, (long)test_bit(IDETAPE_PIPELINE_ERROR
, &tape
->flags
));
3913 clear_bit(IDETAPE_PIPELINE_ERROR
, &tape
->flags
);
3914 position
= idetape_read_position(drive
);
3915 if (position
>= 2980 && position
< 3000)
3919 printk(KERN_INFO
"ide-tape: %s: blank block detected, positioning tape to block %d\n", tape
->name
, position
);
3920 idetape_position_tape(drive
, position
, 0, 1);
3926 idetape_wait_first_stage(drive
);
3927 if (idetape_verify_stage(drive
, tape
->first_stage
, logical_blk_num
, quiet
))
3929 if (tape
->first_stage
->rq
.errors
== IDETAPE_ERROR_EOD
)
3931 if (idetape_verify_stage(drive
, tape
->first_stage
, -1, quiet
)) {
3932 x
= ntohl(tape
->first_stage
->aux
->logical_blk_num
);
3933 if (x
> logical_blk_num
) {
3934 printk(KERN_ERR
"ide-tape: %s: couldn't find logical block %d, aborting (block %d found)\n", tape
->name
, logical_blk_num
, x
);
3938 spin_lock_irqsave(&tape
->spinlock
, flags
);
3939 idetape_remove_stage_head(drive
);
3940 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
3943 tape
->logical_blk_num
= ntohl(tape
->first_stage
->aux
->logical_blk_num
);
3948 * idetape_add_chrdev_read_request is called from idetape_chrdev_read
3949 * to service a character device read request and add read-ahead
3950 * requests to our pipeline.
3952 static int idetape_add_chrdev_read_request (ide_drive_t
*drive
,int blocks
)
3954 idetape_tape_t
*tape
= drive
->driver_data
;
3955 unsigned long flags
;
3956 struct request
*rq_ptr
;
3959 #if IDETAPE_DEBUG_LOG
3960 if (tape
->debug_level
>= 4)
3961 printk (KERN_INFO
"ide-tape: Reached idetape_add_chrdev_read_request, %d blocks\n", blocks
);
3962 #endif /* IDETAPE_DEBUG_LOG */
3965 * Wait for the next logical block to be available at the head
3968 if (!idetape_get_logical_blk(drive
, tape
->logical_blk_num
, tape
->max_stages
, 0)) {
3969 if (tape
->onstream
) {
3970 set_bit(IDETAPE_READ_ERROR
, &tape
->flags
);
3973 if (test_bit(IDETAPE_PIPELINE_ERROR
, &tape
->flags
))
3975 return idetape_queue_rw_tail (drive
, IDETAPE_READ_RQ
, blocks
, tape
->merge_stage
->bh
);
3977 rq_ptr
= &tape
->first_stage
->rq
;
3978 bytes_read
= tape
->tape_block_size
* (rq_ptr
->nr_sectors
- rq_ptr
->current_nr_sectors
);
3979 rq_ptr
->nr_sectors
= rq_ptr
->current_nr_sectors
= 0;
3982 if (tape
->onstream
&& !tape
->raw
&& tape
->first_stage
->aux
->frame_type
== OS_FRAME_TYPE_EOD
) {
3984 if (tape
->debug_level
>= 2)
3985 printk(KERN_INFO
"ide-tape: %s: EOD reached\n", tape
->name
);
3989 if (rq_ptr
->errors
== IDETAPE_ERROR_EOD
)
3991 else if (rq_ptr
->errors
== IDETAPE_ERROR_FILEMARK
)
3992 set_bit (IDETAPE_FILEMARK
, &tape
->flags
);
3994 idetape_switch_buffers (tape
, tape
->first_stage
);
3995 if (rq_ptr
->errors
== IDETAPE_ERROR_GENERAL
) {
3997 if (tape
->debug_level
>= 1)
3998 printk(KERN_INFO
"ide-tape: error detected, bytes_read %d\n", bytes_read
);
4001 clear_bit (IDETAPE_FILEMARK
, &tape
->flags
);
4002 spin_lock_irqsave(&tape
->spinlock
, flags
);
4003 idetape_remove_stage_head (drive
);
4004 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
4005 tape
->logical_blk_num
++;
4006 tape
->pipeline_head
++;
4008 IO_trace(IO_IDETAPE_FIFO
, tape
->pipeline_head
, tape
->buffer_head
, tape
->tape_head
, tape
->minor
);
4010 calculate_speeds(drive
);
4012 #if IDETAPE_DEBUG_BUGS
4013 if (bytes_read
> blocks
*tape
->tape_block_size
) {
4014 printk (KERN_ERR
"ide-tape: bug: trying to return more bytes than requested\n");
4015 bytes_read
=blocks
*tape
->tape_block_size
;
4017 #endif /* IDETAPE_DEBUG_BUGS */
4018 return (bytes_read
);
4021 static void idetape_pad_zeros (ide_drive_t
*drive
, int bcount
)
4023 idetape_tape_t
*tape
= drive
->driver_data
;
4024 struct buffer_head
*bh
;
4028 bh
= tape
->merge_stage
->bh
;
4029 count
= IDE_MIN (tape
->stage_size
, bcount
);
4031 blocks
= count
/ tape
->tape_block_size
;
4033 atomic_set(&bh
->b_count
, IDE_MIN (count
, bh
->b_size
));
4034 memset (bh
->b_data
, 0, atomic_read(&bh
->b_count
));
4035 count
-= atomic_read(&bh
->b_count
);
4038 idetape_queue_rw_tail (drive
, IDETAPE_WRITE_RQ
, blocks
, tape
->merge_stage
->bh
);
4042 static int idetape_pipeline_size (ide_drive_t
*drive
)
4044 idetape_tape_t
*tape
= drive
->driver_data
;
4045 idetape_stage_t
*stage
;
4049 idetape_wait_for_pipeline (drive
);
4050 stage
= tape
->first_stage
;
4051 while (stage
!= NULL
) {
4053 size
+= tape
->tape_block_size
* (rq
->nr_sectors
-rq
->current_nr_sectors
);
4054 if (rq
->errors
== IDETAPE_ERROR_FILEMARK
)
4055 size
+= tape
->tape_block_size
;
4056 stage
= stage
->next
;
4058 size
+= tape
->merge_stage_size
;
4063 * Rewinds the tape to the Beginning Of the current Partition (BOP).
4065 * We currently support only one partition.
4067 static int idetape_rewind_tape (ide_drive_t
*drive
)
4071 idetape_tape_t
*tape
= drive
->driver_data
;
4072 #if IDETAPE_DEBUG_LOG
4073 if (tape
->debug_level
>= 2)
4074 printk (KERN_INFO
"ide-tape: Reached idetape_rewind_tape\n");
4075 #endif /* IDETAPE_DEBUG_LOG */
4077 idetape_create_rewind_cmd (drive
, &pc
);
4078 retval
=idetape_queue_pc_tail (drive
,&pc
);
4079 if (retval
) return retval
;
4081 idetape_create_read_position_cmd (&pc
);
4082 retval
= idetape_queue_pc_tail (drive
,&pc
);
4083 if (retval
) return retval
;
4084 tape
->logical_blk_num
= 0;
4089 * Our special ide-tape ioctl's.
4091 * Currently there aren't any ioctl's.
4092 * mtio.h compatible commands should be issued to the character device
4095 static int idetape_blkdev_ioctl (ide_drive_t
*drive
, struct inode
*inode
, struct file
*file
,
4096 unsigned int cmd
, unsigned long arg
)
4098 idetape_tape_t
*tape
= drive
->driver_data
;
4099 idetape_config_t config
;
4101 #if IDETAPE_DEBUG_LOG
4102 if (tape
->debug_level
>= 4)
4103 printk (KERN_INFO
"ide-tape: Reached idetape_blkdev_ioctl\n");
4104 #endif /* IDETAPE_DEBUG_LOG */
4107 if (copy_from_user ((char *) &config
, (char *) arg
, sizeof (idetape_config_t
)))
4109 tape
->best_dsc_rw_frequency
= config
.dsc_rw_frequency
;
4110 tape
->max_stages
= config
.nr_stages
;
4113 config
.dsc_rw_frequency
= (int) tape
->best_dsc_rw_frequency
;
4114 config
.nr_stages
= tape
->max_stages
;
4115 if (copy_to_user ((char *) arg
, (char *) &config
, sizeof (idetape_config_t
)))
4125 * The block device interface should not be used for data transfers.
4126 * However, we still allow opening it so that we can issue general
4127 * ide driver configuration ioctl's, such as the interrupt unmask feature.
4129 static int idetape_blkdev_open (struct inode
*inode
, struct file
*filp
, ide_drive_t
*drive
)
4133 printk(KERN_INFO
"ide-tape: MOD_INC_USE_COUNT in idetape_blkdev_open\n");
4138 static void idetape_blkdev_release (struct inode
*inode
, struct file
*filp
, ide_drive_t
*drive
)
4142 printk(KERN_INFO
"ide-tape: MOD_DEC_USE_COUNT in idetape_blkdev_release\n");
4147 * idetape_pre_reset is called before an ATAPI/ATA software reset.
4149 static void idetape_pre_reset (ide_drive_t
*drive
)
4151 idetape_tape_t
*tape
= drive
->driver_data
;
4153 set_bit (IDETAPE_IGNORE_DSC
, &tape
->flags
);
4157 * Character device interface functions
4159 static ide_drive_t
*get_drive_ptr (kdev_t i_rdev
)
4161 unsigned int i
= MINOR(i_rdev
) & ~0xc0;
4163 if (i
>= MAX_HWIFS
* MAX_DRIVES
)
4165 return (idetape_chrdevs
[i
].drive
);
4168 static int idetape_onstream_space_over_filemarks_backward (ide_drive_t
*drive
,short mt_op
,int mt_count
)
4170 idetape_tape_t
*tape
= drive
->driver_data
;
4173 unsigned long flags
;
4175 if (!idetape_get_logical_blk(drive
, -1, 10, 0)) {
4176 printk(KERN_INFO
"ide-tape: %s: couldn't get logical blk num in space_filemarks_bwd\n", tape
->name
);
4179 while (cnt
!= mt_count
) {
4180 last_mark_addr
= ntohl(tape
->first_stage
->aux
->last_mark_addr
);
4181 if (last_mark_addr
== -1)
4184 if (tape
->debug_level
>= 2)
4185 printk(KERN_INFO
"ide-tape: positioning to last mark at %d\n", last_mark_addr
);
4187 idetape_position_tape(drive
, last_mark_addr
, 0, 0);
4189 if (!idetape_get_logical_blk(drive
, -1, 10, 0)) {
4190 printk(KERN_INFO
"ide-tape: %s: couldn't get logical blk num in space_filemarks\n", tape
->name
);
4193 if (tape
->first_stage
->aux
->frame_type
!= OS_FRAME_TYPE_MARKER
) {
4194 printk(KERN_INFO
"ide-tape: %s: expected to find marker at block %d, not found\n", tape
->name
, last_mark_addr
);
4198 if (mt_op
== MTBSFM
) {
4199 spin_lock_irqsave(&tape
->spinlock
, flags
);
4200 idetape_remove_stage_head (drive
);
4201 tape
->logical_blk_num
++;
4202 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
4208 * ADRL 1.1 compatible "slow" space filemarks fwd version
4210 * Just scans for the filemark sequentially.
4212 static int idetape_onstream_space_over_filemarks_forward_slow (ide_drive_t
*drive
,short mt_op
,int mt_count
)
4214 idetape_tape_t
*tape
= drive
->driver_data
;
4216 unsigned long flags
;
4218 if (!idetape_get_logical_blk(drive
, -1, 10, 0)) {
4219 printk(KERN_INFO
"ide-tape: %s: couldn't get logical blk num in space_filemarks_fwd\n", tape
->name
);
4223 if (!idetape_get_logical_blk(drive
, -1, 10, 0)) {
4224 printk(KERN_INFO
"ide-tape: %s: couldn't get logical blk num in space_filemarks\n", tape
->name
);
4227 if (tape
->first_stage
->aux
->frame_type
== OS_FRAME_TYPE_MARKER
)
4229 if (tape
->first_stage
->aux
->frame_type
== OS_FRAME_TYPE_EOD
) {
4231 if (tape
->debug_level
>= 2)
4232 printk(KERN_INFO
"ide-tape: %s: space_fwd: EOD reached\n", tape
->name
);
4236 if (cnt
== mt_count
)
4238 spin_lock_irqsave(&tape
->spinlock
, flags
);
4239 idetape_remove_stage_head (drive
);
4240 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
4242 if (mt_op
== MTFSF
) {
4243 spin_lock_irqsave(&tape
->spinlock
, flags
);
4244 idetape_remove_stage_head (drive
);
4245 tape
->logical_blk_num
++;
4246 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
4253 * Fast linux specific version of OnStream FSF
4255 static int idetape_onstream_space_over_filemarks_forward_fast (ide_drive_t
*drive
,short mt_op
,int mt_count
)
4257 idetape_tape_t
*tape
= drive
->driver_data
;
4258 int cnt
= 0, next_mark_addr
;
4259 unsigned long flags
;
4261 if (!idetape_get_logical_blk(drive
, -1, 10, 0)) {
4262 printk(KERN_INFO
"ide-tape: %s: couldn't get logical blk num in space_filemarks_fwd\n", tape
->name
);
4267 * Find nearest (usually previous) marker
4270 if (tape
->first_stage
->aux
->frame_type
== OS_FRAME_TYPE_MARKER
)
4272 if (tape
->first_stage
->aux
->frame_type
== OS_FRAME_TYPE_EOD
) {
4274 if (tape
->debug_level
>= 2)
4275 printk(KERN_INFO
"ide-tape: %s: space_fwd: EOD reached\n", tape
->name
);
4279 if (ntohl(tape
->first_stage
->aux
->filemark_cnt
) == 0) {
4280 if (tape
->first_mark_addr
== -1) {
4281 printk(KERN_INFO
"ide-tape: %s: reverting to slow filemark space\n", tape
->name
);
4282 return idetape_onstream_space_over_filemarks_forward_slow(drive
, mt_op
, mt_count
);
4284 idetape_position_tape(drive
, tape
->first_mark_addr
, 0, 0);
4285 if (!idetape_get_logical_blk(drive
, -1, 10, 0)) {
4286 printk(KERN_INFO
"ide-tape: %s: couldn't get logical blk num in space_filemarks_fwd_fast\n", tape
->name
);
4289 if (tape
->first_stage
->aux
->frame_type
!= OS_FRAME_TYPE_MARKER
) {
4290 printk(KERN_INFO
"ide-tape: %s: expected to find filemark at %d\n", tape
->name
, tape
->first_mark_addr
);
4294 if (idetape_onstream_space_over_filemarks_backward(drive
, MTBSF
, 1) < 0)
4300 while (cnt
!= mt_count
) {
4301 next_mark_addr
= ntohl(tape
->first_stage
->aux
->next_mark_addr
);
4302 if (!next_mark_addr
|| next_mark_addr
> tape
->eod_frame_addr
) {
4303 printk(KERN_INFO
"ide-tape: %s: reverting to slow filemark space\n", tape
->name
);
4304 return idetape_onstream_space_over_filemarks_forward_slow(drive
, mt_op
, mt_count
- cnt
);
4306 } else if (tape
->debug_level
>= 2) {
4307 printk(KERN_INFO
"ide-tape: positioning to next mark at %d\n", next_mark_addr
);
4310 idetape_position_tape(drive
, next_mark_addr
, 0, 0);
4312 if (!idetape_get_logical_blk(drive
, -1, 10, 0)) {
4313 printk(KERN_INFO
"ide-tape: %s: couldn't get logical blk num in space_filemarks\n", tape
->name
);
4316 if (tape
->first_stage
->aux
->frame_type
!= OS_FRAME_TYPE_MARKER
) {
4317 printk(KERN_INFO
"ide-tape: %s: expected to find marker at block %d, not found\n", tape
->name
, next_mark_addr
);
4321 if (mt_op
== MTFSF
) {
4322 spin_lock_irqsave(&tape
->spinlock
, flags
);
4323 idetape_remove_stage_head (drive
);
4324 tape
->logical_blk_num
++;
4325 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
4331 * idetape_space_over_filemarks is now a bit more complicated than just
4332 * passing the command to the tape since we may have crossed some
4333 * filemarks during our pipelined read-ahead mode.
4335 * As a minor side effect, the pipeline enables us to support MTFSFM when
4336 * the filemark is in our internal pipeline even if the tape doesn't
4337 * support spacing over filemarks in the reverse direction.
4339 static int idetape_space_over_filemarks (ide_drive_t
*drive
,short mt_op
,int mt_count
)
4341 idetape_tape_t
*tape
= drive
->driver_data
;
4343 unsigned long flags
;
4347 if (tape
->onstream
) {
4350 speed_control
= tape
->speed_control
;
4351 tape
->speed_control
= 0;
4352 if (mt_op
== MTFSF
|| mt_op
== MTFSFM
) {
4353 if (tape
->linux_media
)
4354 retval
= idetape_onstream_space_over_filemarks_forward_fast(drive
, mt_op
, mt_count
);
4356 retval
= idetape_onstream_space_over_filemarks_forward_slow(drive
, mt_op
, mt_count
);
4358 retval
= idetape_onstream_space_over_filemarks_backward(drive
, mt_op
, mt_count
);
4359 tape
->speed_control
= speed_control
;
4360 tape
->restart_speed_control_req
= 1;
4364 if (tape
->chrdev_direction
== idetape_direction_read
) {
4366 * We have a read-ahead buffer. Scan it for crossed
4369 tape
->merge_stage_size
= 0;
4370 clear_bit (IDETAPE_FILEMARK
, &tape
->flags
);
4371 while (tape
->first_stage
!= NULL
) {
4372 idetape_wait_first_stage(drive
);
4373 if (tape
->first_stage
->rq
.errors
== IDETAPE_ERROR_FILEMARK
)
4375 if (count
== mt_count
) {
4378 spin_lock_irqsave(&tape
->spinlock
, flags
);
4379 idetape_remove_stage_head (drive
);
4380 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
4387 spin_lock_irqsave(&tape
->spinlock
, flags
);
4388 idetape_remove_stage_head (drive
);
4389 spin_unlock_irqrestore(&tape
->spinlock
, flags
);
4391 idetape_discard_read_pipeline (drive
, 1);
4395 * The filemark was not found in our internal pipeline.
4396 * Now we can issue the space command.
4400 idetape_create_space_cmd (&pc
,mt_count
-count
,IDETAPE_SPACE_OVER_FILEMARK
);
4401 return (idetape_queue_pc_tail (drive
,&pc
));
4403 if (!tape
->capabilities
.sprev
)
4405 retval
= idetape_space_over_filemarks (drive
, MTFSF
, mt_count
-count
);
4406 if (retval
) return (retval
);
4407 return (idetape_space_over_filemarks (drive
, MTBSF
, 1));
4409 if (!tape
->capabilities
.sprev
)
4411 idetape_create_space_cmd (&pc
,-(mt_count
+count
),IDETAPE_SPACE_OVER_FILEMARK
);
4412 return (idetape_queue_pc_tail (drive
,&pc
));
4414 if (!tape
->capabilities
.sprev
)
4416 retval
= idetape_space_over_filemarks (drive
, MTBSF
, mt_count
+count
);
4417 if (retval
) return (retval
);
4418 return (idetape_space_over_filemarks (drive
, MTFSF
, 1));
4420 printk (KERN_ERR
"ide-tape: MTIO operation %d not supported\n",mt_op
);
4427 * Our character device read / write functions.
4429 * The tape is optimized to maximize throughput when it is transferring
4430 * an integral number of the "continuous transfer limit", which is
4431 * a parameter of the specific tape (26 KB on my particular tape).
4432 * (32 kB for Onstream)
4434 * As of version 1.3 of the driver, the character device provides an
4435 * abstract continuous view of the media - any mix of block sizes (even 1
4436 * byte) on the same backup/restore procedure is supported. The driver
4437 * will internally convert the requests to the recommended transfer unit,
4438 * so that an unmatch between the user's block size to the recommended
4439 * size will only result in a (slightly) increased driver overhead, but
4440 * will no longer hit performance.
4441 * This is not applicable to Onstream.
4443 static ssize_t
idetape_chrdev_read (struct file
*file
, char *buf
,
4444 size_t count
, loff_t
*ppos
)
4446 struct inode
*inode
= file
->f_dentry
->d_inode
;
4447 ide_drive_t
*drive
= get_drive_ptr (inode
->i_rdev
);
4448 idetape_tape_t
*tape
= drive
->driver_data
;
4449 ssize_t bytes_read
,temp
,actually_read
=0, rc
;
4451 if (ppos
!= &file
->f_pos
) {
4452 /* "A request was outside the capabilities of the device." */
4455 if (tape
->onstream
&& (count
!= tape
->tape_block_size
)) {
4456 printk(KERN_ERR
"ide-tape: %s: use %d bytes as block size (%Zd used)\n", tape
->name
, tape
->tape_block_size
, count
);
4459 #if IDETAPE_DEBUG_LOG
4460 if (tape
->debug_level
>= 3)
4461 printk (KERN_INFO
"ide-tape: Reached idetape_chrdev_read, count %Zd\n", count
);
4462 #endif /* IDETAPE_DEBUG_LOG */
4464 if (tape
->chrdev_direction
!= idetape_direction_read
) {
4465 if (test_bit (IDETAPE_DETECT_BS
, &tape
->flags
))
4466 if (count
> tape
->tape_block_size
&& (count
% tape
->tape_block_size
) == 0)
4467 tape
->user_bs_factor
= count
/ tape
->tape_block_size
;
4469 if ((rc
= idetape_initiate_read(drive
, tape
->max_stages
)) < 0)
4473 if (tape
->merge_stage_size
) {
4474 actually_read
=IDE_MIN (tape
->merge_stage_size
,count
);
4475 idetape_copy_stage_to_user (tape
, buf
, tape
->merge_stage
, actually_read
);
4476 buf
+= actually_read
; tape
->merge_stage_size
-= actually_read
; count
-=actually_read
;
4478 while (count
>= tape
->stage_size
) {
4479 bytes_read
=idetape_add_chrdev_read_request (drive
, tape
->capabilities
.ctl
);
4480 if (bytes_read
<= 0)
4482 idetape_copy_stage_to_user (tape
, buf
, tape
->merge_stage
, bytes_read
);
4483 buf
+= bytes_read
; count
-= bytes_read
; actually_read
+= bytes_read
;
4486 bytes_read
=idetape_add_chrdev_read_request (drive
, tape
->capabilities
.ctl
);
4487 if (bytes_read
<= 0)
4489 temp
=IDE_MIN (count
,bytes_read
);
4490 idetape_copy_stage_to_user (tape
, buf
, tape
->merge_stage
, temp
);
4491 actually_read
+=temp
;
4492 tape
->merge_stage_size
=bytes_read
-temp
;
4495 if (!actually_read
&& test_bit (IDETAPE_FILEMARK
, &tape
->flags
)) {
4496 #if IDETAPE_DEBUG_LOG
4497 if (tape
->debug_level
>= 2)
4498 printk(KERN_INFO
"ide-tape: %s: spacing over filemark\n", tape
->name
);
4500 idetape_space_over_filemarks (drive
, MTFSF
, 1);
4503 if (tape
->onstream
&& !actually_read
&& test_and_clear_bit(IDETAPE_READ_ERROR
, &tape
->flags
)) {
4504 printk(KERN_ERR
"ide-tape: %s: unrecovered read error on logical block number %d, skipping\n", tape
->name
, tape
->logical_blk_num
);
4505 tape
->logical_blk_num
++;
4508 return actually_read
;
4511 static void idetape_update_last_marker (ide_drive_t
*drive
, int last_mark_addr
, int next_mark_addr
)
4513 idetape_tape_t
*tape
= drive
->driver_data
;
4514 idetape_stage_t
*stage
;
4518 if (!tape
->onstream
|| tape
->raw
)
4520 if (last_mark_addr
== -1)
4522 stage
= __idetape_kmalloc_stage(tape
, 0, 0);
4525 idetape_flush_tape_buffers(drive
);
4526 position
= idetape_read_position(drive
);
4528 if (tape
->debug_level
>= 2)
4529 printk(KERN_INFO
"ide-tape: current position (2) %d, lblk %d\n", position
, tape
->logical_blk_num
);
4530 if (tape
->debug_level
>= 2)
4531 printk(KERN_INFO
"ide-tape: current position (2) tape block %d\n", tape
->last_frame_position
);
4533 idetape_position_tape(drive
, last_mark_addr
, 0, 0);
4534 if (!idetape_queue_rw_tail (drive
, IDETAPE_READ_RQ
, 1, stage
->bh
)) {
4535 printk(KERN_INFO
"ide-tape: %s: couldn't read last marker\n", tape
->name
);
4536 __idetape_kfree_stage (stage
);
4537 idetape_position_tape(drive
, position
, 0, 0);
4541 if (aux
->frame_type
!= OS_FRAME_TYPE_MARKER
) {
4542 printk(KERN_INFO
"ide-tape: %s: expected to find marker at addr %d\n", tape
->name
, last_mark_addr
);
4543 __idetape_kfree_stage (stage
);
4544 idetape_position_tape(drive
, position
, 0, 0);
4548 if (tape
->debug_level
>= 2)
4549 printk(KERN_INFO
"ide-tape: writing back marker\n");
4551 aux
->next_mark_addr
= htonl(next_mark_addr
);
4552 idetape_position_tape(drive
, last_mark_addr
, 0, 0);
4553 if (!idetape_queue_rw_tail (drive
, IDETAPE_WRITE_RQ
, 1, stage
->bh
)) {
4554 printk(KERN_INFO
"ide-tape: %s: couldn't write back marker frame at %d\n", tape
->name
, last_mark_addr
);
4555 __idetape_kfree_stage (stage
);
4556 idetape_position_tape(drive
, position
, 0, 0);
4559 __idetape_kfree_stage (stage
);
4560 idetape_flush_tape_buffers (drive
);
4561 idetape_position_tape(drive
, position
, 0, 0);
4565 static void __idetape_write_header (ide_drive_t
*drive
, int block
, int cnt
)
4567 idetape_tape_t
*tape
= drive
->driver_data
;
4568 idetape_stage_t
*stage
;
4571 stage
= __idetape_kmalloc_stage(tape
, 1, 1);
4574 idetape_init_stage(drive
, stage
, OS_FRAME_TYPE_HEADER
, tape
->logical_blk_num
);
4575 idetape_wait_ready(drive
, 60 * 5 * HZ
);
4576 idetape_position_tape(drive
, block
, 0, 0);
4577 memset(&header
, 0, sizeof(header
));
4578 strcpy(header
.ident_str
, "ADR_SEQ");
4579 header
.major_rev
= 1;
4580 header
.minor_rev
= 2;
4582 header
.partition
.partition_num
= OS_DATA_PARTITION
;
4583 header
.partition
.par_desc_ver
= OS_PARTITION_VERSION
;
4584 header
.partition
.first_frame_addr
= htonl(0x14);
4585 header
.partition
.last_frame_addr
= htonl(19239 * 24);
4586 header
.partition
.wrt_pass_cntr
= htons(tape
->wrt_pass_cntr
);
4587 header
.partition
.eod_frame_addr
= htonl(tape
->eod_frame_addr
);
4588 memcpy(stage
->bh
->b_data
, &header
, sizeof(header
));
4590 if (!idetape_queue_rw_tail (drive
, IDETAPE_WRITE_RQ
, 1, stage
->bh
)) {
4591 printk(KERN_INFO
"ide-tape: %s: couldn't write header frame\n", tape
->name
);
4592 __idetape_kfree_stage (stage
);
4596 __idetape_kfree_stage (stage
);
4597 idetape_flush_tape_buffers (drive
);
4600 static void idetape_write_header (ide_drive_t
*drive
, int locate_eod
)
4602 idetape_tape_t
*tape
= drive
->driver_data
;
4605 if (tape
->debug_level
>= 2)
4606 printk(KERN_INFO
"ide-tape: %s: writing tape header\n", tape
->name
);
4608 if (!tape
->onstream
|| tape
->raw
)
4610 tape
->update_frame_cntr
++;
4611 __idetape_write_header(drive
, 5, 5);
4612 __idetape_write_header(drive
, 0xbae, 5);
4615 if (tape
->debug_level
>= 2)
4616 printk(KERN_INFO
"ide-tape: %s: locating back to eod frame addr %d\n", tape
->name
, tape
->eod_frame_addr
);
4618 idetape_position_tape(drive
, tape
->eod_frame_addr
, 0, 0);
4622 static ssize_t
idetape_chrdev_write (struct file
*file
, const char *buf
,
4623 size_t count
, loff_t
*ppos
)
4625 struct inode
*inode
= file
->f_dentry
->d_inode
;
4626 ide_drive_t
*drive
= get_drive_ptr (inode
->i_rdev
);
4627 idetape_tape_t
*tape
= drive
->driver_data
;
4628 ssize_t retval
,actually_written
=0;
4631 if (ppos
!= &file
->f_pos
) {
4632 /* "A request was outside the capabilities of the device." */
4635 if (tape
->onstream
&& (count
!= tape
->tape_block_size
)) {
4636 printk(KERN_ERR
"ide-tape: %s: use %d bytes as block size (%Zd used)\n", tape
->name
, tape
->tape_block_size
, count
);
4639 #if IDETAPE_DEBUG_LOG
4640 if (tape
->debug_level
>= 3)
4641 printk (KERN_INFO
"ide-tape: Reached idetape_chrdev_write, count %Zd\n", count
);
4642 #endif /* IDETAPE_DEBUG_LOG */
4644 if (tape
->chrdev_direction
!= idetape_direction_write
) { /* Initialize write operation */
4645 if (tape
->chrdev_direction
== idetape_direction_read
)
4646 idetape_discard_read_pipeline (drive
, 1);
4647 #if IDETAPE_DEBUG_BUGS
4648 if (tape
->merge_stage
|| tape
->merge_stage_size
) {
4649 printk (KERN_ERR
"ide-tape: merge_stage_size should be 0 now\n");
4650 tape
->merge_stage_size
= 0;
4652 #endif /* IDETAPE_DEBUG_BUGS */
4653 if ((tape
->merge_stage
= __idetape_kmalloc_stage (tape
, 0, 0)) == NULL
)
4655 tape
->chrdev_direction
= idetape_direction_write
;
4656 idetape_init_merge_stage (tape
);
4658 if (tape
->onstream
) {
4659 position
= idetape_read_position(drive
);
4660 if (position
<= 20) {
4661 tape
->logical_blk_num
= 0;
4662 tape
->wrt_pass_cntr
++;
4664 if (tape
->debug_level
>= 2)
4665 printk(KERN_INFO
"ide-tape: %s: logical block num 0, setting eod to 20\n", tape
->name
);
4666 if (tape
->debug_level
>= 2)
4667 printk(KERN_INFO
"ide-tape: %s: allocating new write pass counter %d\n", tape
->name
, tape
->wrt_pass_cntr
);
4669 tape
->filemark_cnt
= 0;
4670 tape
->eod_frame_addr
= 20;
4671 tape
->first_mark_addr
= tape
->last_mark_addr
= -1;
4672 idetape_write_header(drive
, 1);
4675 if (tape
->debug_level
>= 2)
4676 printk(KERN_INFO
"ide-tape: %s: positioning tape to eod at %d\n", tape
->name
, tape
->eod_frame_addr
);
4678 position
= idetape_read_position(drive
);
4679 if (position
!= tape
->eod_frame_addr
)
4680 idetape_position_tape(drive
, tape
->eod_frame_addr
, 0, 0);
4682 if (tape
->debug_level
>= 2)
4683 printk(KERN_INFO
"ide-tape: %s: first_frame_position %d\n", tape
->name
, tape
->first_frame_position
);
4688 * Issue a write 0 command to ensure that DSC handshake
4689 * is switched from completion mode to buffer available
4692 retval
= idetape_queue_rw_tail (drive
, IDETAPE_WRITE_RQ
, 0, tape
->merge_stage
->bh
);
4694 kfree (tape
->merge_stage
);
4695 tape
->merge_stage
= NULL
;
4696 tape
->chrdev_direction
= idetape_direction_none
;
4700 if (tape
->debug_level
>= 2)
4701 printk("ide-tape: first_frame_position %d\n", tape
->first_frame_position
);
4706 if (tape
->restart_speed_control_req
)
4707 idetape_restart_speed_control(drive
);
4708 if (tape
->merge_stage_size
) {
4709 #if IDETAPE_DEBUG_BUGS
4710 if (tape
->merge_stage_size
>= tape
->stage_size
) {
4711 printk (KERN_ERR
"ide-tape: bug: merge buffer too big\n");
4712 tape
->merge_stage_size
=0;
4714 #endif /* IDETAPE_DEBUG_BUGS */
4715 actually_written
=IDE_MIN (tape
->stage_size
-tape
->merge_stage_size
,count
);
4716 idetape_copy_stage_from_user (tape
, tape
->merge_stage
, buf
, actually_written
);
4717 buf
+=actually_written
;tape
->merge_stage_size
+=actually_written
;count
-=actually_written
;
4719 if (tape
->merge_stage_size
== tape
->stage_size
) {
4720 tape
->merge_stage_size
= 0;
4721 retval
=idetape_add_chrdev_write_request (drive
, tape
->capabilities
.ctl
);
4726 while (count
>= tape
->stage_size
) {
4727 idetape_copy_stage_from_user (tape
, tape
->merge_stage
, buf
, tape
->stage_size
);
4728 buf
+=tape
->stage_size
;count
-=tape
->stage_size
;
4729 retval
=idetape_add_chrdev_write_request (drive
, tape
->capabilities
.ctl
);
4730 actually_written
+=tape
->stage_size
;
4735 actually_written
+=count
;
4736 idetape_copy_stage_from_user (tape
, tape
->merge_stage
, buf
, count
);
4737 tape
->merge_stage_size
+=count
;
4739 return (actually_written
);
4742 static int idetape_write_filemark (ide_drive_t
*drive
)
4744 idetape_tape_t
*tape
= drive
->driver_data
;
4748 if (!tape
->onstream
) {
4749 idetape_create_write_filemark_cmd(drive
, &pc
,1); /* Write a filemark */
4750 if (idetape_queue_pc_tail (drive
,&pc
)) {
4751 printk (KERN_ERR
"ide-tape: Couldn't write a filemark\n");
4754 } else if (!tape
->raw
) {
4755 last_mark_addr
= idetape_read_position(drive
);
4756 tape
->merge_stage
= __idetape_kmalloc_stage (tape
, 1, 0);
4757 if (tape
->merge_stage
!= NULL
) {
4758 idetape_init_stage(drive
, tape
->merge_stage
, OS_FRAME_TYPE_MARKER
, tape
->logical_blk_num
);
4759 idetape_pad_zeros (drive
, tape
->stage_size
);
4760 tape
->logical_blk_num
++;
4761 __idetape_kfree_stage (tape
->merge_stage
);
4762 tape
->merge_stage
= NULL
;
4764 if (tape
->filemark_cnt
)
4765 idetape_update_last_marker(drive
, tape
->last_mark_addr
, last_mark_addr
);
4766 tape
->last_mark_addr
= last_mark_addr
;
4767 if (tape
->filemark_cnt
++ == 0)
4768 tape
->first_mark_addr
= last_mark_addr
;
4773 static void idetape_write_eod (ide_drive_t
*drive
)
4775 idetape_tape_t
*tape
= drive
->driver_data
;
4777 if (!tape
->onstream
|| tape
->raw
)
4779 tape
->merge_stage
= __idetape_kmalloc_stage (tape
, 1, 0);
4780 if (tape
->merge_stage
!= NULL
) {
4781 tape
->eod_frame_addr
= idetape_read_position(drive
);
4782 idetape_init_stage(drive
, tape
->merge_stage
, OS_FRAME_TYPE_EOD
, tape
->logical_blk_num
);
4783 idetape_pad_zeros (drive
, tape
->stage_size
);
4784 __idetape_kfree_stage (tape
->merge_stage
);
4785 tape
->merge_stage
= NULL
;
4790 int idetape_seek_logical_blk (ide_drive_t
*drive
, int logical_blk_num
)
4792 idetape_tape_t
*tape
= drive
->driver_data
;
4793 int estimated_address
= logical_blk_num
+ 20;
4797 speed_control
= tape
->speed_control
;
4798 tape
->speed_control
= 0;
4799 if (logical_blk_num
< 0)
4800 logical_blk_num
= 0;
4801 if (idetape_get_logical_blk(drive
, logical_blk_num
, 10, 1))
4803 while (++retries
< 10) {
4804 idetape_discard_read_pipeline(drive
, 0);
4805 idetape_position_tape(drive
, estimated_address
, 0, 0);
4806 if (idetape_get_logical_blk(drive
, logical_blk_num
, 10, 1))
4808 if (!idetape_get_logical_blk(drive
, -1, 10, 1))
4810 if (tape
->logical_blk_num
< logical_blk_num
)
4811 estimated_address
+= logical_blk_num
- tape
->logical_blk_num
;
4816 tape
->speed_control
= speed_control
;
4817 tape
->restart_speed_control_req
= 1;
4818 printk(KERN_INFO
"ide-tape: %s: couldn't seek to logical block %d (at %d), %d retries\n", tape
->name
, logical_blk_num
, tape
->logical_blk_num
, retries
);
4821 tape
->speed_control
= speed_control
;
4822 tape
->restart_speed_control_req
= 1;
4827 * idetape_mtioctop is called from idetape_chrdev_ioctl when
4828 * the general mtio MTIOCTOP ioctl is requested.
4830 * We currently support the following mtio.h operations:
4832 * MTFSF - Space over mt_count filemarks in the positive direction.
4833 * The tape is positioned after the last spaced filemark.
4835 * MTFSFM - Same as MTFSF, but the tape is positioned before the
4838 * MTBSF - Steps background over mt_count filemarks, tape is
4839 * positioned before the last filemark.
4841 * MTBSFM - Like MTBSF, only tape is positioned after the last filemark.
4845 * MTBSF and MTBSFM are not supported when the tape doesn't
4846 * supports spacing over filemarks in the reverse direction.
4847 * In this case, MTFSFM is also usually not supported (it is
4848 * supported in the rare case in which we crossed the filemark
4849 * during our read-ahead pipelined operation mode).
4851 * MTWEOF - Writes mt_count filemarks. Tape is positioned after
4852 * the last written filemark.
4854 * MTREW - Rewinds tape.
4856 * MTLOAD - Loads the tape.
4858 * MTOFFL - Puts the tape drive "Offline": Rewinds the tape and
4859 * MTUNLOAD prevents further access until the media is replaced.
4861 * MTNOP - Flushes tape buffers.
4863 * MTRETEN - Retension media. This typically consists of one end
4864 * to end pass on the media.
4866 * MTEOM - Moves to the end of recorded data.
4868 * MTERASE - Erases tape.
4870 * MTSETBLK - Sets the user block size to mt_count bytes. If
4871 * mt_count is 0, we will attempt to autodetect
4874 * MTSEEK - Positions the tape in a specific block number, where
4875 * each block is assumed to contain which user_block_size
4878 * MTSETPART - Switches to another tape partition.
4880 * MTLOCK - Locks the tape door.
4882 * MTUNLOCK - Unlocks the tape door.
4884 * The following commands are currently not supported:
4886 * MTFSS, MTBSS, MTWSM, MTSETDENSITY,
4887 * MTSETDRVBUFFER, MT_ST_BOOLEANS, MT_ST_WRITE_THRESHOLD.
4889 static int idetape_mtioctop (ide_drive_t
*drive
,short mt_op
,int mt_count
)
4891 idetape_tape_t
*tape
= drive
->driver_data
;
4895 #if IDETAPE_DEBUG_LOG
4896 if (tape
->debug_level
>= 1)
4897 printk (KERN_INFO
"ide-tape: Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n",mt_op
,mt_count
);
4898 #endif /* IDETAPE_DEBUG_LOG */
4900 * Commands which need our pipelined read-ahead stages.
4909 return (idetape_space_over_filemarks (drive
,mt_op
,mt_count
));
4915 idetape_discard_read_pipeline (drive
, 1);
4916 for (i
= 0; i
< mt_count
; i
++) {
4917 retval
= idetape_write_filemark(drive
);
4918 if (retval
) return retval
;
4922 idetape_discard_read_pipeline (drive
, 0);
4923 if (idetape_rewind_tape(drive
))
4925 if (tape
->onstream
&& !tape
->raw
)
4926 return idetape_position_tape(drive
, 20, 0, 0);
4929 idetape_discard_read_pipeline (drive
, 0);
4930 idetape_create_load_unload_cmd (drive
, &pc
, IDETAPE_LU_LOAD_MASK
);
4931 return (idetape_queue_pc_tail (drive
,&pc
));
4934 idetape_discard_read_pipeline (drive
, 0);
4935 idetape_create_load_unload_cmd (drive
, &pc
,!IDETAPE_LU_LOAD_MASK
);
4936 return (idetape_queue_pc_tail (drive
,&pc
));
4938 idetape_discard_read_pipeline (drive
, 0);
4939 return (idetape_flush_tape_buffers (drive
));
4941 idetape_discard_read_pipeline (drive
, 0);
4942 idetape_create_load_unload_cmd (drive
, &pc
,IDETAPE_LU_RETENSION_MASK
| IDETAPE_LU_LOAD_MASK
);
4943 return (idetape_queue_pc_tail (drive
,&pc
));
4945 if (tape
->onstream
) {
4947 if (tape
->debug_level
>= 2)
4948 printk(KERN_INFO
"ide-tape: %s: positioning tape to eod at %d\n", tape
->name
, tape
->eod_frame_addr
);
4950 idetape_position_tape(drive
, tape
->eod_frame_addr
, 0, 0);
4951 if (!idetape_get_logical_blk(drive
, -1, 10, 0))
4953 if (tape
->first_stage
->aux
->frame_type
!= OS_FRAME_TYPE_EOD
)
4957 idetape_create_space_cmd (&pc
,0,IDETAPE_SPACE_TO_EOD
);
4958 return (idetape_queue_pc_tail (drive
,&pc
));
4960 if (tape
->onstream
) {
4961 tape
->eod_frame_addr
= 20;
4962 tape
->logical_blk_num
= 0;
4963 tape
->first_mark_addr
= tape
->last_mark_addr
= -1;
4964 idetape_position_tape(drive
, tape
->eod_frame_addr
, 0, 0);
4965 idetape_write_eod(drive
);
4966 idetape_flush_tape_buffers (drive
);
4967 idetape_write_header(drive
, 0);
4968 idetape_flush_tape_buffers (drive
);
4969 (void) idetape_rewind_tape (drive
);
4972 (void) idetape_rewind_tape (drive
);
4973 idetape_create_erase_cmd (&pc
);
4974 return (idetape_queue_pc_tail (drive
,&pc
));
4976 if (tape
->onstream
) {
4977 if (mt_count
!= tape
->tape_block_size
) {
4978 printk(KERN_INFO
"ide-tape: %s: MTSETBLK %d -- only %d bytes block size supported\n", tape
->name
, mt_count
, tape
->tape_block_size
);
4984 if (mt_count
< tape
->tape_block_size
|| mt_count
% tape
->tape_block_size
)
4986 tape
->user_bs_factor
= mt_count
/ tape
->tape_block_size
;
4987 clear_bit (IDETAPE_DETECT_BS
, &tape
->flags
);
4989 set_bit (IDETAPE_DETECT_BS
, &tape
->flags
);
4992 if (!tape
->onstream
|| tape
->raw
) {
4993 idetape_discard_read_pipeline (drive
, 0);
4994 return idetape_position_tape (drive
, mt_count
* tape
->user_bs_factor
, tape
->partition
, 0);
4996 return idetape_seek_logical_blk(drive
, mt_count
);
4998 idetape_discard_read_pipeline (drive
, 0);
5001 return (idetape_position_tape (drive
, 0, mt_count
, 0));
5004 if (tape
->onstream
) {
5005 if (!idetape_get_logical_blk(drive
, -1, 10, 0))
5008 return idetape_seek_logical_blk(drive
, tape
->logical_blk_num
+ mt_count
);
5010 idetape_discard_read_pipeline (drive
, 0);
5011 return idetape_seek_logical_blk(drive
, tape
->logical_blk_num
- mt_count
);
5015 idetape_create_prevent_cmd(drive
, &pc
, 1);
5016 retval
= idetape_queue_pc_tail (drive
,&pc
);
5017 if (retval
) return retval
;
5018 tape
->door_locked
= DOOR_EXPLICITLY_LOCKED
;
5021 idetape_create_prevent_cmd(drive
, &pc
, 0);
5022 retval
= idetape_queue_pc_tail (drive
,&pc
);
5023 if (retval
) return retval
;
5024 tape
->door_locked
= DOOR_UNLOCKED
;
5027 printk (KERN_ERR
"ide-tape: MTIO operation %d not supported\n",mt_op
);
5033 * Our character device ioctls.
5035 * General mtio.h magnetic io commands are supported here, and not in
5036 * the corresponding block interface.
5038 * The following ioctls are supported:
5040 * MTIOCTOP - Refer to idetape_mtioctop for detailed description.
5042 * MTIOCGET - The mt_dsreg field in the returned mtget structure
5043 * will be set to (user block size in bytes <<
5044 * MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK.
5046 * The mt_blkno is set to the current user block number.
5047 * The other mtget fields are not supported.
5049 * MTIOCPOS - The current tape "block position" is returned. We
5050 * assume that each block contains user_block_size
5053 * Our own ide-tape ioctls are supported on both interfaces.
5055 static int idetape_chrdev_ioctl (struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
5057 ide_drive_t
*drive
= get_drive_ptr (inode
->i_rdev
);
5058 idetape_tape_t
*tape
= drive
->driver_data
;
5062 int block_offset
= 0, position
= tape
->first_frame_position
;
5064 #if IDETAPE_DEBUG_LOG
5065 if (tape
->debug_level
>= 3)
5066 printk (KERN_INFO
"ide-tape: Reached idetape_chrdev_ioctl, cmd=%u\n",cmd
);
5067 #endif /* IDETAPE_DEBUG_LOG */
5069 tape
->restart_speed_control_req
= 1;
5070 if (tape
->chrdev_direction
== idetape_direction_write
) {
5071 idetape_empty_write_pipeline (drive
);
5072 idetape_flush_tape_buffers (drive
);
5074 if (cmd
== MTIOCGET
|| cmd
== MTIOCPOS
) {
5075 block_offset
= idetape_pipeline_size (drive
) / (tape
->tape_block_size
* tape
->user_bs_factor
);
5076 if ((position
= idetape_read_position(drive
)) < 0)
5081 if (copy_from_user ((char *) &mtop
, (char *) arg
, sizeof (struct mtop
)))
5083 return (idetape_mtioctop (drive
,mtop
.mt_op
,mtop
.mt_count
));
5085 memset (&mtget
, 0, sizeof (struct mtget
));
5086 mtget
.mt_type
= MT_ISSCSI2
;
5087 if (!tape
->onstream
|| tape
->raw
)
5088 mtget
.mt_blkno
= position
/ tape
->user_bs_factor
- block_offset
;
5090 if (!idetape_get_logical_blk(drive
, -1, 10, 0))
5091 mtget
.mt_blkno
= -1;
5093 mtget
.mt_blkno
= tape
->logical_blk_num
;
5095 mtget
.mt_dsreg
= ((tape
->tape_block_size
* tape
->user_bs_factor
) << MT_ST_BLKSIZE_SHIFT
) & MT_ST_BLKSIZE_MASK
;
5096 if (tape
->onstream
) {
5097 mtget
.mt_gstat
|= GMT_ONLINE(0xffffffff);
5098 if (tape
->first_stage
&& tape
->first_stage
->aux
->frame_type
== OS_FRAME_TYPE_EOD
)
5099 mtget
.mt_gstat
|= GMT_EOD(0xffffffff);
5101 mtget
.mt_gstat
|= GMT_BOT(0xffffffff);
5103 if (copy_to_user ((char *) arg
,(char *) &mtget
, sizeof (struct mtget
)))
5107 if (tape
->onstream
&& !tape
->raw
) {
5108 if (!idetape_get_logical_blk(drive
, -1, 10, 0))
5110 mtpos
.mt_blkno
= tape
->logical_blk_num
;
5112 mtpos
.mt_blkno
= position
/ tape
->user_bs_factor
- block_offset
;
5113 if (copy_to_user ((char *) arg
,(char *) &mtpos
, sizeof (struct mtpos
)))
5117 if (tape
->chrdev_direction
== idetape_direction_read
)
5118 idetape_discard_read_pipeline (drive
, 1);
5119 return (idetape_blkdev_ioctl (drive
,inode
,file
,cmd
,arg
));
5123 static int __idetape_analyze_headers (ide_drive_t
*drive
, int block
)
5125 idetape_tape_t
*tape
= drive
->driver_data
;
5126 idetape_stage_t
*stage
;
5127 os_header_t
*header
;
5130 if (!tape
->onstream
|| tape
->raw
) {
5131 tape
->header_ok
= tape
->linux_media
= 1;
5134 tape
->header_ok
= tape
->linux_media
= 0;
5135 tape
->update_frame_cntr
= 0;
5136 tape
->wrt_pass_cntr
= 0;
5137 tape
->eod_frame_addr
= 20;
5138 tape
->first_mark_addr
= tape
->last_mark_addr
= -1;
5139 stage
= __idetape_kmalloc_stage (tape
, 0, 0);
5143 if (tape
->debug_level
>= 2)
5144 printk(KERN_INFO
"ide-tape: %s: reading header\n", tape
->name
);
5146 idetape_position_tape(drive
, block
, 0, 0);
5147 if (!idetape_queue_rw_tail (drive
, IDETAPE_READ_RQ
, 1, stage
->bh
)) {
5148 printk(KERN_INFO
"ide-tape: %s: couldn't read header frame\n", tape
->name
);
5149 __idetape_kfree_stage (stage
);
5152 header
= (os_header_t
*) stage
->bh
->b_data
;
5154 if (strncmp(header
->ident_str
, "ADR_SEQ", 7) != 0) {
5155 printk(KERN_INFO
"ide-tape: %s: invalid header identification string\n", tape
->name
);
5156 __idetape_kfree_stage (stage
);
5159 if (header
->major_rev
!= 1 || (header
->minor_rev
!= 1 && header
->minor_rev
!= 2))
5160 printk(KERN_INFO
"ide-tape: warning: revision %d.%d detected (1.1/1.2 supported)\n", header
->major_rev
, header
->minor_rev
);
5161 if (header
->par_num
!= 1)
5162 printk(KERN_INFO
"ide-tape: warning: %d partitions defined, only one supported\n", header
->par_num
);
5163 tape
->wrt_pass_cntr
= ntohs(header
->partition
.wrt_pass_cntr
);
5164 tape
->eod_frame_addr
= ntohl(header
->partition
.eod_frame_addr
);
5165 tape
->filemark_cnt
= ntohl(aux
->filemark_cnt
);
5166 tape
->first_mark_addr
= ntohl(aux
->next_mark_addr
);
5167 tape
->last_mark_addr
= ntohl(aux
->last_mark_addr
);
5168 tape
->update_frame_cntr
= ntohl(aux
->update_frame_cntr
);
5169 memcpy(tape
->application_sig
, aux
->application_sig
, 4); tape
->application_sig
[4] = 0;
5170 if (memcmp(tape
->application_sig
, "LIN", 3) == 0) {
5171 tape
->linux_media
= 1;
5172 tape
->linux_media_version
= tape
->application_sig
[3] - '0';
5173 if (tape
->linux_media_version
!= 3)
5174 printk(KERN_INFO
"ide-tape: %s: Linux media version %d detected (current 3)\n", tape
->name
, tape
->linux_media_version
);
5176 printk(KERN_INFO
"ide-tape: %s: non Linux media detected (%s)\n", tape
->name
, tape
->application_sig
);
5177 tape
->linux_media
= 0;
5180 if (tape
->debug_level
>= 2)
5181 printk(KERN_INFO
"ide-tape: %s: detected write pass counter %d, eod frame addr %d\n", tape
->name
, tape
->wrt_pass_cntr
, tape
->eod_frame_addr
);
5183 __idetape_kfree_stage (stage
);
5187 static int idetape_analyze_headers (ide_drive_t
*drive
)
5189 idetape_tape_t
*tape
= drive
->driver_data
;
5190 int position
, block
;
5192 if (!tape
->onstream
|| tape
->raw
) {
5193 tape
->header_ok
= tape
->linux_media
= 1;
5196 tape
->header_ok
= tape
->linux_media
= 0;
5197 position
= idetape_read_position(drive
);
5198 for (block
= 5; block
< 10; block
++)
5199 if (__idetape_analyze_headers(drive
, block
))
5202 for (block
= 0xbae; block
< 0xbb8; block
++)
5204 for (block
= 0xbae; block
< 0xbb3; block
++)
5206 if (__idetape_analyze_headers(drive
, block
))
5208 printk(KERN_ERR
"ide-tape: %s: failed to find valid ADRL header\n", tape
->name
);
5213 idetape_position_tape(drive
, position
, 0, 0);
5214 tape
->header_ok
= 1;
5219 * Our character device open function.
5221 static int idetape_chrdev_open (struct inode
*inode
, struct file
*filp
)
5224 idetape_tape_t
*tape
;
5226 unsigned int minor
=MINOR (inode
->i_rdev
);
5228 #if IDETAPE_DEBUG_LOG
5229 printk (KERN_INFO
"ide-tape: Reached idetape_chrdev_open\n");
5230 #endif /* IDETAPE_DEBUG_LOG */
5232 if ((drive
= get_drive_ptr (inode
->i_rdev
)) == NULL
)
5234 tape
= drive
->driver_data
;
5236 if (test_and_set_bit (IDETAPE_BUSY
, &tape
->flags
))
5240 if (tape
->debug_level
>= 6)
5241 printk(KERN_INFO
"ide-tape: MOD_INC_USE_COUNT in idetape_chrdev_open-1\n");
5243 if (!tape
->onstream
) {
5244 idetape_read_position(drive
);
5245 if (!test_bit (IDETAPE_ADDRESS_VALID
, &tape
->flags
))
5246 (void) idetape_rewind_tape (drive
);
5249 tape
->tape_block_size
= tape
->stage_size
= 32768 + 512;
5252 tape
->tape_block_size
= tape
->stage_size
= 32768;
5256 if (idetape_wait_ready(drive
, 60 * HZ
)) {
5257 clear_bit(IDETAPE_BUSY
, &tape
->flags
);
5260 if (tape
->debug_level
>= 6)
5261 printk(KERN_INFO
"ide-tape: MOD_DEC_USE_COUNT in idetape_chrdev_open-1\n");
5263 printk(KERN_ERR
"ide-tape: %s: drive not ready\n", tape
->name
);
5266 idetape_read_position(drive
);
5269 if (tape
->debug_level
>= 6)
5270 printk(KERN_INFO
"ide-tape: MOD_DEC_USE_COUNT in idetape_chrdev_open-2\n");
5272 clear_bit (IDETAPE_PIPELINE_ERROR
, &tape
->flags
);
5274 if (tape
->chrdev_direction
== idetape_direction_none
) {
5277 if (tape
->debug_level
>= 6)
5278 printk(KERN_INFO
"ide-tape: MOD_INC_USE_COUNT in idetape_chrdev_open-2\n");
5280 idetape_create_prevent_cmd(drive
, &pc
, 1);
5281 if (!idetape_queue_pc_tail (drive
,&pc
)) {
5282 if (tape
->door_locked
!= DOOR_EXPLICITLY_LOCKED
)
5283 tape
->door_locked
= DOOR_LOCKED
;
5285 idetape_analyze_headers(drive
);
5287 tape
->max_frames
= tape
->cur_frames
= tape
->req_buffer_fill
= 0;
5288 idetape_restart_speed_control(drive
);
5289 tape
->restart_speed_control_req
= 0;
5294 * Our character device release function.
5296 static int idetape_chrdev_release (struct inode
*inode
, struct file
*filp
)
5298 ide_drive_t
*drive
= get_drive_ptr (inode
->i_rdev
);
5299 idetape_tape_t
*tape
= drive
->driver_data
;
5301 unsigned int minor
=MINOR (inode
->i_rdev
);
5303 #if IDETAPE_DEBUG_LOG
5304 if (tape
->debug_level
>= 3)
5305 printk (KERN_INFO
"ide-tape: Reached idetape_chrdev_release\n");
5306 #endif /* IDETAPE_DEBUG_LOG */
5308 if (tape
->chrdev_direction
== idetape_direction_write
) {
5309 idetape_empty_write_pipeline (drive
);
5310 tape
->merge_stage
= __idetape_kmalloc_stage (tape
, 1, 0);
5311 if (tape
->merge_stage
!= NULL
) {
5312 idetape_pad_zeros (drive
, tape
->tape_block_size
* (tape
->user_bs_factor
- 1));
5313 __idetape_kfree_stage (tape
->merge_stage
);
5314 tape
->merge_stage
= NULL
;
5316 idetape_write_filemark(drive
);
5317 idetape_write_eod(drive
);
5318 idetape_flush_tape_buffers (drive
);
5319 idetape_write_header(drive
, minor
>= 128);
5320 idetape_flush_tape_buffers (drive
);
5322 if (tape
->chrdev_direction
== idetape_direction_read
) {
5324 idetape_discard_read_pipeline (drive
, 1);
5326 idetape_wait_for_pipeline (drive
);
5328 if (tape
->cache_stage
!= NULL
) {
5329 __idetape_kfree_stage (tape
->cache_stage
);
5330 tape
->cache_stage
= NULL
;
5333 (void) idetape_rewind_tape (drive
);
5334 if (tape
->chrdev_direction
== idetape_direction_none
) {
5335 if (tape
->door_locked
!= DOOR_EXPLICITLY_LOCKED
) {
5336 idetape_create_prevent_cmd(drive
, &pc
, 0);
5337 if (!idetape_queue_pc_tail (drive
,&pc
))
5338 tape
->door_locked
= DOOR_UNLOCKED
;
5342 if (tape
->debug_level
>= 6)
5343 printk(KERN_INFO
"ide-tape: MOD_DEC_USE_COUNT in idetape_chrdev_release\n");
5346 clear_bit (IDETAPE_BUSY
, &tape
->flags
);
5351 * idetape_identify_device is called to check the contents of the
5352 * ATAPI IDENTIFY command results. We return:
5354 * 1 If the tape can be supported by us, based on the information
5357 * 0 If this tape driver is not currently supported by us.
5359 static int idetape_identify_device (ide_drive_t
*drive
,struct hd_driveid
*id
)
5361 struct idetape_id_gcw gcw
;
5362 #if IDETAPE_DEBUG_INFO
5363 unsigned short mask
,i
;
5364 #endif /* IDETAPE_DEBUG_INFO */
5369 *((unsigned short *) &gcw
) = id
->config
;
5371 #if IDETAPE_DEBUG_INFO
5372 printk (KERN_INFO
"ide-tape: Dumping ATAPI Identify Device tape parameters\n");
5373 printk (KERN_INFO
"ide-tape: Protocol Type: ");
5374 switch (gcw
.protocol
) {
5375 case 0: case 1: printk (KERN_INFO
"ATA\n");break;
5376 case 2: printk (KERN_INFO
"ATAPI\n");break;
5377 case 3: printk (KERN_INFO
"Reserved (Unknown to ide-tape)\n");break;
5379 printk (KERN_INFO
"ide-tape: Device Type: %x - ",gcw
.device_type
);
5380 switch (gcw
.device_type
) {
5381 case 0: printk (KERN_INFO
"Direct-access Device\n");break;
5382 case 1: printk (KERN_INFO
"Streaming Tape Device\n");break;
5383 case 2: case 3: case 4: printk (KERN_INFO
"Reserved\n");break;
5384 case 5: printk (KERN_INFO
"CD-ROM Device\n");break;
5385 case 6: printk (KERN_INFO
"Reserved\n");
5386 case 7: printk (KERN_INFO
"Optical memory Device\n");break;
5387 case 0x1f: printk (KERN_INFO
"Unknown or no Device type\n");break;
5388 default: printk (KERN_INFO
"Reserved\n");
5390 printk (KERN_INFO
"ide-tape: Removable: %s",gcw
.removable
? "Yes\n":"No\n");
5391 printk (KERN_INFO
"ide-tape: Command Packet DRQ Type: ");
5392 switch (gcw
.drq_type
) {
5393 case 0: printk (KERN_INFO
"Microprocessor DRQ\n");break;
5394 case 1: printk (KERN_INFO
"Interrupt DRQ\n");break;
5395 case 2: printk (KERN_INFO
"Accelerated DRQ\n");break;
5396 case 3: printk (KERN_INFO
"Reserved\n");break;
5398 printk (KERN_INFO
"ide-tape: Command Packet Size: ");
5399 switch (gcw
.packet_size
) {
5400 case 0: printk (KERN_INFO
"12 bytes\n");break;
5401 case 1: printk (KERN_INFO
"16 bytes\n");break;
5402 default: printk (KERN_INFO
"Reserved\n");break;
5404 printk (KERN_INFO
"ide-tape: Model: %.40s\n",id
->model
);
5405 printk (KERN_INFO
"ide-tape: Firmware Revision: %.8s\n",id
->fw_rev
);
5406 printk (KERN_INFO
"ide-tape: Serial Number: %.20s\n",id
->serial_no
);
5407 printk (KERN_INFO
"ide-tape: Write buffer size: %d bytes\n",id
->buf_size
*512);
5408 printk (KERN_INFO
"ide-tape: DMA: %s",id
->capability
& 0x01 ? "Yes\n":"No\n");
5409 printk (KERN_INFO
"ide-tape: LBA: %s",id
->capability
& 0x02 ? "Yes\n":"No\n");
5410 printk (KERN_INFO
"ide-tape: IORDY can be disabled: %s",id
->capability
& 0x04 ? "Yes\n":"No\n");
5411 printk (KERN_INFO
"ide-tape: IORDY supported: %s",id
->capability
& 0x08 ? "Yes\n":"Unknown\n");
5412 printk (KERN_INFO
"ide-tape: ATAPI overlap supported: %s",id
->capability
& 0x20 ? "Yes\n":"No\n");
5413 printk (KERN_INFO
"ide-tape: PIO Cycle Timing Category: %d\n",id
->tPIO
);
5414 printk (KERN_INFO
"ide-tape: DMA Cycle Timing Category: %d\n",id
->tDMA
);
5415 printk (KERN_INFO
"ide-tape: Single Word DMA supported modes: ");
5416 for (i
=0,mask
=1;i
<8;i
++,mask
=mask
<< 1) {
5417 if (id
->dma_1word
& mask
)
5418 printk (KERN_INFO
"%d ",i
);
5419 if (id
->dma_1word
& (mask
<< 8))
5420 printk (KERN_INFO
"(active) ");
5422 printk (KERN_INFO
"\n");
5423 printk (KERN_INFO
"ide-tape: Multi Word DMA supported modes: ");
5424 for (i
=0,mask
=1;i
<8;i
++,mask
=mask
<< 1) {
5425 if (id
->dma_mword
& mask
)
5426 printk (KERN_INFO
"%d ",i
);
5427 if (id
->dma_mword
& (mask
<< 8))
5428 printk (KERN_INFO
"(active) ");
5430 printk (KERN_INFO
"\n");
5431 if (id
->field_valid
& 0x0002) {
5432 printk (KERN_INFO
"ide-tape: Enhanced PIO Modes: %s\n",id
->eide_pio_modes
& 1 ? "Mode 3":"None");
5433 printk (KERN_INFO
"ide-tape: Minimum Multi-word DMA cycle per word: ");
5434 if (id
->eide_dma_min
== 0)
5435 printk (KERN_INFO
"Not supported\n");
5437 printk (KERN_INFO
"%d ns\n",id
->eide_dma_min
);
5439 printk (KERN_INFO
"ide-tape: Manufacturer\'s Recommended Multi-word cycle: ");
5440 if (id
->eide_dma_time
== 0)
5441 printk (KERN_INFO
"Not supported\n");
5443 printk (KERN_INFO
"%d ns\n",id
->eide_dma_time
);
5445 printk (KERN_INFO
"ide-tape: Minimum PIO cycle without IORDY: ");
5446 if (id
->eide_pio
== 0)
5447 printk (KERN_INFO
"Not supported\n");
5449 printk (KERN_INFO
"%d ns\n",id
->eide_pio
);
5451 printk (KERN_INFO
"ide-tape: Minimum PIO cycle with IORDY: ");
5452 if (id
->eide_pio_iordy
== 0)
5453 printk (KERN_INFO
"Not supported\n");
5455 printk (KERN_INFO
"%d ns\n",id
->eide_pio_iordy
);
5458 printk (KERN_INFO
"ide-tape: According to the device, fields 64-70 are not valid.\n");
5459 #endif /* IDETAPE_DEBUG_INFO */
5461 /* Check that we can support this device */
5463 if (gcw
.protocol
!=2 )
5464 printk (KERN_ERR
"ide-tape: Protocol is not ATAPI\n");
5465 else if (gcw
.device_type
!= 1)
5466 printk (KERN_ERR
"ide-tape: Device type is not set to tape\n");
5467 else if (!gcw
.removable
)
5468 printk (KERN_ERR
"ide-tape: The removable flag is not set\n");
5469 else if (gcw
.packet_size
!= 0) {
5470 printk (KERN_ERR
"ide-tape: Packet size is not 12 bytes long\n");
5471 if (gcw
.packet_size
== 1)
5472 printk (KERN_ERR
"ide-tape: Sorry, padding to 16 bytes is still not supported\n");
5479 * Notify vendor ID to the OnStream tape drive
5481 static void idetape_onstream_set_vendor (ide_drive_t
*drive
, char *vendor
)
5484 idetape_mode_parameter_header_t
*header
;
5486 idetape_create_mode_select_cmd(&pc
, sizeof(*header
) + 8);
5487 pc
.buffer
[0] = 3 + 8; /* Mode Data Length */
5488 pc
.buffer
[1] = 0; /* Medium Type - ignoring */
5489 pc
.buffer
[2] = 0; /* Reserved */
5490 pc
.buffer
[3] = 0; /* Block Descriptor Length */
5491 pc
.buffer
[4 + 0] = 0x36 | (1 << 7);
5492 pc
.buffer
[4 + 1] = 6;
5493 pc
.buffer
[4 + 2] = vendor
[0];
5494 pc
.buffer
[4 + 3] = vendor
[1];
5495 pc
.buffer
[4 + 4] = vendor
[2];
5496 pc
.buffer
[4 + 5] = vendor
[3];
5497 pc
.buffer
[4 + 6] = 0;
5498 pc
.buffer
[4 + 7] = 0;
5499 if (idetape_queue_pc_tail (drive
,&pc
))
5500 printk (KERN_ERR
"ide-tape: Couldn't set vendor name to %s\n", vendor
);
5505 * Various unused OnStream commands
5508 static void idetape_onstream_set_retries (ide_drive_t
*drive
, int retries
)
5512 idetape_create_mode_select_cmd(&pc
, sizeof(idetape_mode_parameter_header_t
) + 4);
5513 pc
.buffer
[0] = 3 + 4;
5514 pc
.buffer
[1] = 0; /* Medium Type - ignoring */
5515 pc
.buffer
[2] = 0; /* Reserved */
5516 pc
.buffer
[3] = 0; /* Block Descriptor Length */
5517 pc
.buffer
[4 + 0] = 0x2f | (1 << 7);
5518 pc
.buffer
[4 + 1] = 2;
5519 pc
.buffer
[4 + 2] = 4;
5520 pc
.buffer
[4 + 3] = retries
;
5521 if (idetape_queue_pc_tail (drive
,&pc
))
5522 printk (KERN_ERR
"ide-tape: Couldn't set retries to %d\n", retries
);
5527 * Configure 32.5KB block size.
5529 static void idetape_onstream_configure_block_size (ide_drive_t
*drive
)
5532 idetape_mode_parameter_header_t
*header
;
5533 idetape_block_size_page_t
*bs
;
5536 * Get the current block size from the block size mode page
5538 idetape_create_mode_sense_cmd (&pc
,IDETAPE_BLOCK_SIZE_PAGE
);
5539 if (idetape_queue_pc_tail (drive
,&pc
))
5540 printk (KERN_ERR
"ide-tape: can't get tape block size mode page\n");
5541 header
= (idetape_mode_parameter_header_t
*) pc
.buffer
;
5542 bs
= (idetape_block_size_page_t
*) (pc
.buffer
+ sizeof(idetape_mode_parameter_header_t
) + header
->bdl
);
5544 #if IDETAPE_DEBUG_INFO
5545 printk(KERN_INFO
"ide-tape: 32KB play back: %s\n", bs
->play32
? "Yes" : "No");
5546 printk(KERN_INFO
"ide-tape: 32.5KB play back: %s\n", bs
->play32_5
? "Yes" : "No");
5547 printk(KERN_INFO
"ide-tape: 32KB record: %s\n", bs
->record32
? "Yes" : "No");
5548 printk(KERN_INFO
"ide-tape: 32.5KB record: %s\n", bs
->record32_5
? "Yes" : "No");
5549 #endif /* IDETAPE_DEBUG_INFO */
5552 * Configure default auto columns mode, 32.5KB block size
5559 idetape_create_mode_select_cmd(&pc
, sizeof(*header
) + sizeof(*bs
));
5560 if (idetape_queue_pc_tail (drive
,&pc
))
5561 printk (KERN_ERR
"ide-tape: Couldn't set tape block size mode page\n");
5565 * In debug mode, we want to see as many errors as possible
5566 * to test the error recovery mechanism.
5568 idetape_onstream_set_retries(drive
, 0);
5573 * Use INQUIRY to get the firmware revision
5575 static void idetape_get_inquiry_results (ide_drive_t
*drive
)
5578 idetape_tape_t
*tape
= drive
->driver_data
;
5580 idetape_inquiry_result_t
*inquiry
;
5582 idetape_create_inquiry_cmd(&pc
);
5583 if (idetape_queue_pc_tail (drive
,&pc
)) {
5584 printk (KERN_ERR
"ide-tape: %s: can't get INQUIRY results\n", tape
->name
);
5587 inquiry
= (idetape_inquiry_result_t
*) pc
.buffer
;
5588 memcpy(tape
->vendor_id
, inquiry
->vendor_id
, 8);
5589 memcpy(tape
->product_id
, inquiry
->product_id
, 16);
5590 memcpy(tape
->firmware_revision
, inquiry
->revision_level
, 4);
5591 ide_fixstring(tape
->vendor_id
, 10, 0);
5592 ide_fixstring(tape
->product_id
, 18, 0);
5593 ide_fixstring(tape
->firmware_revision
, 6, 0);
5594 r
= tape
->firmware_revision
;
5595 if (*(r
+ 1) == '.')
5596 tape
->firmware_revision_num
= (*r
- '0') * 100 + (*(r
+ 2) - '0') * 10 + *(r
+ 3) - '0';
5597 else if (tape
->onstream
)
5598 tape
->firmware_revision_num
= (*r
- '0') * 100 + (*(r
+ 1) - '0') * 10 + *(r
+ 2) - '0';
5599 printk(KERN_INFO
"ide-tape: %s <-> %s: %s %s rev %s\n", drive
->name
, tape
->name
, tape
->vendor_id
, tape
->product_id
, tape
->firmware_revision
);
5603 * Configure the OnStream ATAPI tape drive for default operation
5605 static void idetape_configure_onstream (ide_drive_t
*drive
)
5607 idetape_tape_t
*tape
= drive
->driver_data
;
5609 if (tape
->firmware_revision_num
< 105) {
5610 printk(KERN_INFO
"ide-tape: %s: Old OnStream firmware revision detected (%s)\n", tape
->name
, tape
->firmware_revision
);
5611 printk(KERN_INFO
"ide-tape: %s: An upgrade to version 1.05 or above is recommended\n", tape
->name
);
5615 * Configure 32.5KB (data+aux) block size.
5617 idetape_onstream_configure_block_size(drive
);
5620 * Set vendor name to 'LIN3' for "Linux support version 3".
5622 idetape_onstream_set_vendor(drive
, "LIN3");
5626 * idetape_get_mode_sense_results asks the tape about its various
5627 * parameters. In particular, we will adjust our data transfer buffer
5628 * size to the recommended value as returned by the tape.
5630 static void idetape_get_mode_sense_results (ide_drive_t
*drive
)
5632 idetape_tape_t
*tape
= drive
->driver_data
;
5634 idetape_mode_parameter_header_t
*header
;
5635 idetape_capabilities_page_t
*capabilities
;
5637 idetape_create_mode_sense_cmd (&pc
,IDETAPE_CAPABILITIES_PAGE
);
5638 if (idetape_queue_pc_tail (drive
,&pc
)) {
5639 printk (KERN_ERR
"ide-tape: Can't get tape parameters - assuming some default values\n");
5640 tape
->tape_block_size
= 512; tape
->capabilities
.ctl
= 52;
5641 tape
->capabilities
.speed
= 450; tape
->capabilities
.buffer_size
= 6 * 52;
5644 header
= (idetape_mode_parameter_header_t
*) pc
.buffer
;
5645 capabilities
= (idetape_capabilities_page_t
*) (pc
.buffer
+ sizeof(idetape_mode_parameter_header_t
) + header
->bdl
);
5647 capabilities
->max_speed
= ntohs (capabilities
->max_speed
);
5648 capabilities
->ctl
= ntohs (capabilities
->ctl
);
5649 capabilities
->speed
= ntohs (capabilities
->speed
);
5650 capabilities
->buffer_size
= ntohs (capabilities
->buffer_size
);
5652 if (!capabilities
->speed
) {
5653 printk(KERN_INFO
"ide-tape: %s: overriding capabilities->speed (assuming 650KB/sec)\n", drive
->name
);
5654 capabilities
->speed
= 650;
5656 if (!capabilities
->max_speed
) {
5657 printk(KERN_INFO
"ide-tape: %s: overriding capabilities->max_speed (assuming 650KB/sec)\n", drive
->name
);
5658 capabilities
->max_speed
= 650;
5661 tape
->capabilities
= *capabilities
; /* Save us a copy */
5662 if (capabilities
->blk512
)
5663 tape
->tape_block_size
= 512;
5664 else if (capabilities
->blk1024
)
5665 tape
->tape_block_size
= 1024;
5666 else if (tape
->onstream
&& capabilities
->blk32768
)
5667 tape
->tape_block_size
= 32768;
5669 #if IDETAPE_DEBUG_INFO
5670 printk (KERN_INFO
"ide-tape: Dumping the results of the MODE SENSE packet command\n");
5671 printk (KERN_INFO
"ide-tape: Mode Parameter Header:\n");
5672 printk (KERN_INFO
"ide-tape: Mode Data Length - %d\n",header
->mode_data_length
);
5673 printk (KERN_INFO
"ide-tape: Medium Type - %d\n",header
->medium_type
);
5674 printk (KERN_INFO
"ide-tape: Device Specific Parameter - %d\n",header
->dsp
);
5675 printk (KERN_INFO
"ide-tape: Block Descriptor Length - %d\n",header
->bdl
);
5677 printk (KERN_INFO
"ide-tape: Capabilities and Mechanical Status Page:\n");
5678 printk (KERN_INFO
"ide-tape: Page code - %d\n",capabilities
->page_code
);
5679 printk (KERN_INFO
"ide-tape: Page length - %d\n",capabilities
->page_length
);
5680 printk (KERN_INFO
"ide-tape: Read only - %s\n",capabilities
->ro
? "Yes":"No");
5681 printk (KERN_INFO
"ide-tape: Supports reverse space - %s\n",capabilities
->sprev
? "Yes":"No");
5682 printk (KERN_INFO
"ide-tape: Supports erase initiated formatting - %s\n",capabilities
->efmt
? "Yes":"No");
5683 printk (KERN_INFO
"ide-tape: Supports QFA two Partition format - %s\n",capabilities
->qfa
? "Yes":"No");
5684 printk (KERN_INFO
"ide-tape: Supports locking the medium - %s\n",capabilities
->lock
? "Yes":"No");
5685 printk (KERN_INFO
"ide-tape: The volume is currently locked - %s\n",capabilities
->locked
? "Yes":"No");
5686 printk (KERN_INFO
"ide-tape: The device defaults in the prevent state - %s\n",capabilities
->prevent
? "Yes":"No");
5687 printk (KERN_INFO
"ide-tape: Supports ejecting the medium - %s\n",capabilities
->eject
? "Yes":"No");
5688 printk (KERN_INFO
"ide-tape: Supports error correction - %s\n",capabilities
->ecc
? "Yes":"No");
5689 printk (KERN_INFO
"ide-tape: Supports data compression - %s\n",capabilities
->cmprs
? "Yes":"No");
5690 printk (KERN_INFO
"ide-tape: Supports 512 bytes block size - %s\n",capabilities
->blk512
? "Yes":"No");
5691 printk (KERN_INFO
"ide-tape: Supports 1024 bytes block size - %s\n",capabilities
->blk1024
? "Yes":"No");
5692 printk (KERN_INFO
"ide-tape: Supports 32768 bytes block size / Restricted byte count for PIO transfers - %s\n",capabilities
->blk32768
? "Yes":"No");
5693 printk (KERN_INFO
"ide-tape: Maximum supported speed in KBps - %d\n",capabilities
->max_speed
);
5694 printk (KERN_INFO
"ide-tape: Continuous transfer limits in blocks - %d\n",capabilities
->ctl
);
5695 printk (KERN_INFO
"ide-tape: Current speed in KBps - %d\n",capabilities
->speed
);
5696 printk (KERN_INFO
"ide-tape: Buffer size - %d\n",capabilities
->buffer_size
*512);
5697 #endif /* IDETAPE_DEBUG_INFO */
5700 static void idetape_add_settings (ide_drive_t
*drive
)
5702 idetape_tape_t
*tape
= drive
->driver_data
;
5705 * drive setting name read/write ioctl ioctl data type min max mul_factor div_factor data pointer set function
5707 ide_add_setting(drive
, "buffer", SETTING_READ
, -1, -1, TYPE_SHORT
, 0, 0xffff, 1, 2, &tape
->capabilities
.buffer_size
, NULL
);
5708 ide_add_setting(drive
, "pipeline_min", SETTING_RW
, -1, -1, TYPE_INT
, 2, 0xffff, tape
->stage_size
/ 1024, 1, &tape
->min_pipeline
, NULL
);
5709 ide_add_setting(drive
, "pipeline", SETTING_RW
, -1, -1, TYPE_INT
, 2, 0xffff, tape
->stage_size
/ 1024, 1, &tape
->max_stages
, NULL
);
5710 ide_add_setting(drive
, "pipeline_max", SETTING_RW
, -1, -1, TYPE_INT
, 2, 0xffff, tape
->stage_size
/ 1024, 1, &tape
->max_pipeline
, NULL
);
5711 ide_add_setting(drive
, "pipeline_used",SETTING_READ
, -1, -1, TYPE_INT
, 0, 0xffff, tape
->stage_size
/ 1024, 1, &tape
->nr_stages
, NULL
);
5712 ide_add_setting(drive
, "pipeline_pending",SETTING_READ
,-1, -1, TYPE_INT
, 0, 0xffff, tape
->stage_size
/ 1024, 1, &tape
->nr_pending_stages
, NULL
);
5713 ide_add_setting(drive
, "speed", SETTING_READ
, -1, -1, TYPE_SHORT
, 0, 0xffff, 1, 1, &tape
->capabilities
.speed
, NULL
);
5714 ide_add_setting(drive
, "stage", SETTING_READ
, -1, -1, TYPE_INT
, 0, 0xffff, 1, 1024, &tape
->stage_size
, NULL
);
5715 ide_add_setting(drive
, "tdsc", SETTING_RW
, -1, -1, TYPE_INT
, IDETAPE_DSC_RW_MIN
, IDETAPE_DSC_RW_MAX
, 1000, HZ
, &tape
->best_dsc_rw_frequency
, NULL
);
5716 ide_add_setting(drive
, "dsc_overlap", SETTING_RW
, -1, -1, TYPE_BYTE
, 0, 1, 1, 1, &drive
->dsc_overlap
, NULL
);
5717 ide_add_setting(drive
, "pipeline_head_speed_c",SETTING_READ
, -1, -1, TYPE_INT
, 0, 0xffff, 1, 1, &tape
->controlled_pipeline_head_speed
, NULL
);
5718 ide_add_setting(drive
, "pipeline_head_speed_u",SETTING_READ
, -1, -1, TYPE_INT
, 0, 0xffff, 1, 1, &tape
->uncontrolled_pipeline_head_speed
, NULL
);
5719 ide_add_setting(drive
, "avg_speed", SETTING_READ
, -1, -1, TYPE_INT
, 0, 0xffff, 1, 1, &tape
->avg_speed
, NULL
);
5720 if (tape
->onstream
) {
5721 ide_add_setting(drive
, "cur_frames", SETTING_READ
, -1, -1, TYPE_SHORT
, 0, 0xffff, 1, 1, &tape
->cur_frames
, NULL
);
5722 ide_add_setting(drive
, "max_frames", SETTING_READ
, -1, -1, TYPE_SHORT
, 0, 0xffff, 1, 1, &tape
->max_frames
, NULL
);
5723 ide_add_setting(drive
, "insert_speed", SETTING_READ
, -1, -1, TYPE_INT
, 0, 0xffff, 1, 1, &tape
->insert_speed
, NULL
);
5724 ide_add_setting(drive
, "speed_control",SETTING_RW
, -1, -1, TYPE_INT
, 0, 0xffff, 1, 1, &tape
->speed_control
, NULL
);
5725 ide_add_setting(drive
, "debug_level",SETTING_RW
, -1, -1, TYPE_INT
, 0, 0xffff, 1, 1, &tape
->debug_level
, NULL
);
5726 ide_add_setting(drive
, "tape_still_time",SETTING_READ
, -1, -1, TYPE_INT
, 0, 0xffff, 1, 1, &tape
->tape_still_time
, NULL
);
5727 ide_add_setting(drive
, "max_insert_speed",SETTING_RW
, -1, -1, TYPE_INT
, 0, 0xffff, 1, 1, &tape
->max_insert_speed
, NULL
);
5728 ide_add_setting(drive
, "insert_size", SETTING_READ
, -1, -1, TYPE_INT
, 0, 0xffff, 1, 1, &tape
->insert_size
, NULL
);
5733 * ide_setup is called to:
5735 * 1. Initialize our various state variables.
5736 * 2. Ask the tape for its capabilities.
5737 * 3. Allocate a buffer which will be used for data
5738 * transfer. The buffer size is chosen based on
5739 * the recommendation which we received in step (2).
5741 * Note that at this point ide.c already assigned us an irq, so that
5742 * we can queue requests here and wait for their completion.
5744 static void idetape_setup (ide_drive_t
*drive
, idetape_tape_t
*tape
, int minor
)
5746 unsigned long t1
, tmid
, tn
, t
;
5748 struct idetape_id_gcw gcw
;
5751 memset (tape
, 0, sizeof (idetape_tape_t
));
5752 spin_lock_init(&tape
->spinlock
);
5753 drive
->driver_data
= tape
;
5754 drive
->ready_stat
= 0; /* An ATAPI device ignores DRDY */
5755 if (strstr(drive
->id
->model
, "OnStream DI-30"))
5757 drive
->dsc_overlap
= 1;
5758 #ifdef CONFIG_BLK_DEV_IDEPCI
5759 if (!tape
->onstream
&& HWIF(drive
)->pci_dev
!= NULL
) {
5761 * These two ide-pci host adapters appear to need DSC overlap disabled.
5762 * This probably needs further analysis.
5764 if ((HWIF(drive
)->pci_dev
->device
== PCI_DEVICE_ID_ARTOP_ATP850UF
) ||
5765 (HWIF(drive
)->pci_dev
->device
== PCI_DEVICE_ID_TTI_HPT343
)) {
5766 printk(KERN_INFO
"ide-tape: %s: disabling DSC overlap\n", tape
->name
);
5767 drive
->dsc_overlap
= 0;
5770 #endif /* CONFIG_BLK_DEV_IDEPCI */
5771 tape
->drive
= drive
;
5772 tape
->minor
= minor
;
5773 tape
->name
[0] = 'h'; tape
->name
[1] = 't'; tape
->name
[2] = '0' + minor
;
5774 tape
->chrdev_direction
= idetape_direction_none
;
5775 tape
->pc
= tape
->pc_stack
;
5776 tape
->max_insert_speed
= 10000;
5777 tape
->speed_control
= 1;
5778 *((unsigned short *) &gcw
) = drive
->id
->config
;
5779 if (gcw
.drq_type
== 1)
5780 set_bit(IDETAPE_DRQ_INTERRUPT
, &tape
->flags
);
5782 tape
->min_pipeline
= tape
->max_pipeline
= tape
->max_stages
= 10;
5784 idetape_get_inquiry_results(drive
);
5785 idetape_get_mode_sense_results(drive
);
5787 idetape_configure_onstream(drive
);
5789 tape
->user_bs_factor
= 1;
5790 tape
->stage_size
= tape
->capabilities
.ctl
* tape
->tape_block_size
;
5791 while (tape
->stage_size
> 0xffff) {
5792 printk (KERN_NOTICE
"ide-tape: decreasing stage size\n");
5793 tape
->capabilities
.ctl
/= 2;
5794 tape
->stage_size
= tape
->capabilities
.ctl
* tape
->tape_block_size
;
5796 stage_size
= tape
->stage_size
;
5798 stage_size
= 32768 + 512;
5799 tape
->pages_per_stage
= stage_size
/ PAGE_SIZE
;
5800 if (stage_size
% PAGE_SIZE
) {
5801 tape
->pages_per_stage
++;
5802 tape
->excess_bh_size
= PAGE_SIZE
- stage_size
% PAGE_SIZE
;
5806 * Select the "best" DSC read/write polling frequency
5807 * and pipeline size.
5809 speed
= IDE_MAX (tape
->capabilities
.speed
, tape
->capabilities
.max_speed
);
5811 tape
->max_stages
= speed
* 1000 * 10 / tape
->stage_size
;
5812 tape
->min_pipeline
= tape
->max_stages
;
5813 tape
->max_pipeline
= tape
->max_stages
* 2;
5815 t1
= (tape
->stage_size
* HZ
) / (speed
* 1000);
5816 tmid
= (tape
->capabilities
.buffer_size
* 32 * HZ
) / (speed
* 125);
5817 tn
= (IDETAPE_FIFO_THRESHOLD
* tape
->stage_size
* HZ
) / (speed
* 1000);
5819 if (tape
->max_stages
)
5825 * Ensure that the number we got makes sense; limit
5826 * it within IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX.
5828 tape
->best_dsc_rw_frequency
= IDE_MAX (IDE_MIN (t
, IDETAPE_DSC_RW_MAX
), IDETAPE_DSC_RW_MIN
);
5829 printk (KERN_INFO
"ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, %dkB pipeline, %lums tDSC%s\n",
5830 drive
->name
, tape
->name
, tape
->capabilities
.speed
, (tape
->capabilities
.buffer_size
* 512) / tape
->stage_size
,
5831 tape
->stage_size
/ 1024, tape
->max_stages
* tape
->stage_size
/ 1024,
5832 tape
->best_dsc_rw_frequency
* 1000 / HZ
, drive
->using_dma
? ", DMA":"");
5834 idetape_add_settings(drive
);
5837 static int idetape_cleanup (ide_drive_t
*drive
)
5839 idetape_tape_t
*tape
= drive
->driver_data
;
5840 int minor
= tape
->minor
;
5841 unsigned long flags
;
5843 save_flags (flags
); /* all CPUs (overkill?) */
5844 cli(); /* all CPUs (overkill?) */
5845 if (test_bit (IDETAPE_BUSY
, &tape
->flags
) || tape
->first_stage
!= NULL
|| tape
->merge_stage_size
|| drive
->usage
) {
5846 restore_flags(flags
); /* all CPUs (overkill?) */
5849 idetape_chrdevs
[minor
].drive
= NULL
;
5850 restore_flags (flags
); /* all CPUs (overkill?) */
5851 DRIVER(drive
)->busy
= 0;
5852 (void) ide_unregister_subdriver (drive
);
5853 drive
->driver_data
= NULL
;
5854 devfs_unregister (tape
->de_r
);
5855 devfs_unregister (tape
->de_n
);
5857 for (minor
= 0; minor
< MAX_HWIFS
* MAX_DRIVES
; minor
++)
5858 if (idetape_chrdevs
[minor
].drive
!= NULL
)
5860 devfs_unregister_chrdev (IDETAPE_MAJOR
, "ht");
5861 idetape_chrdev_present
= 0;
5865 #ifdef CONFIG_PROC_FS
5867 static int proc_idetape_read_name
5868 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
5870 ide_drive_t
*drive
= (ide_drive_t
*) data
;
5871 idetape_tape_t
*tape
= drive
->driver_data
;
5875 len
= sprintf(out
,"%s\n", tape
->name
);
5876 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
5879 static ide_proc_entry_t idetape_proc
[] = {
5880 { "name", S_IFREG
|S_IRUGO
, proc_idetape_read_name
, NULL
},
5881 { NULL
, 0, NULL
, NULL
}
5886 #define idetape_proc NULL
5891 * IDE subdriver functions, registered with ide.c
5893 static ide_driver_t idetape_driver
= {
5895 version
: IDETAPE_VERSION
,
5899 supports_dsc_overlap
: 1,
5900 cleanup
: idetape_cleanup
,
5901 do_request
: idetape_do_request
,
5902 end_request
: idetape_end_request
,
5903 ioctl
: idetape_blkdev_ioctl
,
5904 open
: idetape_blkdev_open
,
5905 release
: idetape_blkdev_release
,
5906 pre_reset
: idetape_pre_reset
,
5910 int idetape_init (void);
5911 static ide_module_t idetape_module
= {
5919 * Our character device supporting functions, passed to register_chrdev.
5921 static struct file_operations idetape_fops
= {
5922 read
: idetape_chrdev_read
,
5923 write
: idetape_chrdev_write
,
5924 ioctl
: idetape_chrdev_ioctl
,
5925 open
: idetape_chrdev_open
,
5926 release
: idetape_chrdev_release
,
5930 * idetape_init will register the driver for each tape.
5932 int idetape_init (void)
5935 idetape_tape_t
*tape
;
5936 int minor
, failed
= 0, supported
= 0;
5940 printk(KERN_INFO
"ide-tape: MOD_INC_USE_COUNT in idetape_init\n");
5942 if (!idetape_chrdev_present
)
5943 for (minor
= 0; minor
< MAX_HWIFS
* MAX_DRIVES
; minor
++ )
5944 idetape_chrdevs
[minor
].drive
= NULL
;
5946 if ((drive
= ide_scan_devices (ide_tape
, idetape_driver
.name
, NULL
, failed
++)) == NULL
) {
5947 ide_register_module (&idetape_module
);
5950 printk(KERN_INFO
"ide-tape: MOD_DEC_USE_COUNT in idetape_init\n");
5954 if (!idetape_chrdev_present
&&
5955 devfs_register_chrdev (IDETAPE_MAJOR
, "ht", &idetape_fops
)) {
5956 printk (KERN_ERR
"ide-tape: Failed to register character device interface\n");
5959 printk(KERN_INFO
"ide-tape: MOD_DEC_USE_COUNT in idetape_init\n");
5964 if (!idetape_identify_device (drive
, drive
->id
)) {
5965 printk (KERN_ERR
"ide-tape: %s: not supported by this version of ide-tape\n", drive
->name
);
5969 if (strstr(drive
->id
->model
, "OnStream DI-30")) {
5970 printk("ide-tape: ide-scsi emulation is not supported for %s.\n", drive
->id
->model
);
5972 printk("ide-tape: passing drive %s to ide-scsi emulation.\n", drive
->name
);
5976 tape
= (idetape_tape_t
*) kmalloc (sizeof (idetape_tape_t
), GFP_KERNEL
);
5978 printk (KERN_ERR
"ide-tape: %s: Can't allocate a tape structure\n", drive
->name
);
5981 if (ide_register_subdriver (drive
, &idetape_driver
, IDE_SUBDRIVER_VERSION
)) {
5982 printk (KERN_ERR
"ide-tape: %s: Failed to register the driver with ide.c\n", drive
->name
);
5986 for (minor
= 0; idetape_chrdevs
[minor
].drive
!= NULL
; minor
++);
5987 idetape_setup (drive
, tape
, minor
);
5988 idetape_chrdevs
[minor
].drive
= drive
;
5990 devfs_register (drive
->de
, "mt", DEVFS_FL_DEFAULT
,
5991 HWIF(drive
)->major
, minor
,
5992 S_IFCHR
| S_IRUGO
| S_IWUGO
,
5993 &idetape_fops
, NULL
);
5995 devfs_register (drive
->de
, "mtn", DEVFS_FL_DEFAULT
,
5996 HWIF(drive
)->major
, minor
+ 128,
5997 S_IFCHR
| S_IRUGO
| S_IWUGO
,
5998 &idetape_fops
, NULL
);
5999 devfs_register_tape (tape
->de_r
);
6000 supported
++; failed
--;
6001 } while ((drive
= ide_scan_devices (ide_tape
, idetape_driver
.name
, NULL
, failed
++)) != NULL
);
6002 if (!idetape_chrdev_present
&& !supported
) {
6003 devfs_unregister_chrdev (IDETAPE_MAJOR
, "ht");
6005 idetape_chrdev_present
= 1;
6006 ide_register_module (&idetape_module
);
6009 printk(KERN_INFO
"ide-tape: MOD_DEC_USE_COUNT in idetape_init\n");
6015 int init_module (void)
6017 return idetape_init ();
6020 void cleanup_module (void)
6025 for (minor
= 0; minor
< MAX_HWIFS
* MAX_DRIVES
; minor
++) {
6026 drive
= idetape_chrdevs
[minor
].drive
;
6027 if (drive
!= NULL
&& idetape_cleanup (drive
))
6028 printk (KERN_ERR
"ide-tape: %s: cleanup_module() called while still busy\n", drive
->name
);
6030 ide_unregister_module(&idetape_module
);