2 * IDE ATAPI streaming tape driver.
4 * Copyright (C) 1995-1999 Gadi Oxman <gadio@netvision.net.il>
5 * Copyright (C) 2003-2005 Bartlomiej Zolnierkiewicz
7 * This driver was constructed as a student project in the software laboratory
8 * of the faculty of electrical engineering in the Technion - Israel's
9 * Institute Of Technology, with the guide of Avner Lottem and Dr. Ilana David.
11 * It is hereby placed under the terms of the GNU general public license.
12 * (See linux/COPYING).
14 * For a historical changelog see
15 * Documentation/ide/ChangeLog.ide-tape.1995-2002
18 #define DRV_NAME "ide-tape"
20 #define IDETAPE_VERSION "1.20"
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/string.h>
25 #include <linux/kernel.h>
26 #include <linux/delay.h>
27 #include <linux/timer.h>
29 #include <linux/interrupt.h>
30 #include <linux/jiffies.h>
31 #include <linux/major.h>
32 #include <linux/errno.h>
33 #include <linux/genhd.h>
34 #include <linux/slab.h>
35 #include <linux/pci.h>
36 #include <linux/ide.h>
37 #include <linux/smp_lock.h>
38 #include <linux/completion.h>
39 #include <linux/bitops.h>
40 #include <linux/mutex.h>
41 #include <scsi/scsi.h>
43 #include <asm/byteorder.h>
44 #include <linux/irq.h>
45 #include <linux/uaccess.h>
47 #include <asm/unaligned.h>
48 #include <linux/mtio.h>
51 /* output errors only */
53 /* output all sense key/asc */
55 /* info regarding all chrdev-related procedures */
56 DBG_CHRDEV = (1 << 2),
57 /* all remaining procedures */
61 /* define to see debug info */
62 #define IDETAPE_DEBUG_LOG 0
65 #define debug_log(lvl, fmt, args...) \
67 if (tape->debug_mask & lvl) \
68 printk(KERN_INFO "ide-tape: " fmt, ## args); \
71 #define debug_log(lvl, fmt, args...) do {} while (0)
74 /**************************** Tunable parameters *****************************/
76 * After each failed packet command we issue a request sense command and retry
77 * the packet command IDETAPE_MAX_PC_RETRIES times.
79 * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries.
81 #define IDETAPE_MAX_PC_RETRIES 3
84 * The following parameter is used to select the point in the internal tape fifo
85 * in which we will start to refill the buffer. Decreasing the following
86 * parameter will improve the system's latency and interactive response, while
87 * using a high value might improve system throughput.
89 #define IDETAPE_FIFO_THRESHOLD 2
92 * DSC polling parameters.
94 * Polling for DSC (a single bit in the status register) is a very important
95 * function in ide-tape. There are two cases in which we poll for DSC:
97 * 1. Before a read/write packet command, to ensure that we can transfer data
98 * from/to the tape's data buffers, without causing an actual media access.
99 * In case the tape is not ready yet, we take out our request from the device
100 * request queue, so that ide.c could service requests from the other device
101 * on the same interface in the meantime.
103 * 2. After the successful initialization of a "media access packet command",
104 * which is a command that can take a long time to complete (the interval can
105 * range from several seconds to even an hour). Again, we postpone our request
106 * in the middle to free the bus for the other device. The polling frequency
107 * here should be lower than the read/write frequency since those media access
108 * commands are slow. We start from a "fast" frequency - IDETAPE_DSC_MA_FAST
109 * (1 second), and if we don't receive DSC after IDETAPE_DSC_MA_THRESHOLD
110 * (5 min), we switch it to a lower frequency - IDETAPE_DSC_MA_SLOW (1 min).
112 * We also set a timeout for the timer, in case something goes wrong. The
113 * timeout should be longer then the maximum execution time of a tape operation.
117 #define IDETAPE_DSC_RW_MIN 5*HZ/100 /* 50 msec */
118 #define IDETAPE_DSC_RW_MAX 40*HZ/100 /* 400 msec */
119 #define IDETAPE_DSC_RW_TIMEOUT 2*60*HZ /* 2 minutes */
120 #define IDETAPE_DSC_MA_FAST 2*HZ /* 2 seconds */
121 #define IDETAPE_DSC_MA_THRESHOLD 5*60*HZ /* 5 minutes */
122 #define IDETAPE_DSC_MA_SLOW 30*HZ /* 30 seconds */
123 #define IDETAPE_DSC_MA_TIMEOUT 2*60*60*HZ /* 2 hours */
125 /*************************** End of tunable parameters ***********************/
127 /* tape directions */
129 IDETAPE_DIR_NONE = (1 << 0),
130 IDETAPE_DIR_READ = (1 << 1),
131 IDETAPE_DIR_WRITE = (1 << 2),
140 /* Tape door status */
141 #define DOOR_UNLOCKED 0
142 #define DOOR_LOCKED 1
143 #define DOOR_EXPLICITLY_LOCKED 2
145 /* Some defines for the SPACE command */
146 #define IDETAPE_SPACE_OVER_FILEMARK 1
147 #define IDETAPE_SPACE_TO_EOD 3
149 /* Some defines for the LOAD UNLOAD command */
150 #define IDETAPE_LU_LOAD_MASK 1
151 #define IDETAPE_LU_RETENSION_MASK 2
152 #define IDETAPE_LU_EOT_MASK 4
154 /* Structures related to the SELECT SENSE / MODE SENSE packet commands. */
155 #define IDETAPE_BLOCK_DESCRIPTOR 0
156 #define IDETAPE_CAPABILITIES_PAGE 0x2a
159 * Most of our global data which we need to save even as we leave the driver due
160 * to an interrupt or a timer event is stored in the struct defined below.
162 typedef struct ide_tape_obj {
164 struct ide_driver *driver;
165 struct gendisk *disk;
168 /* used by REQ_IDETAPE_{READ,WRITE} requests */
169 struct ide_atapi_pc queued_pc;
172 * DSC polling variables.
174 * While polling for DSC we use postponed_rq to postpone the current
175 * request so that ide.c will be able to service pending requests on the
176 * other device. Note that at most we will have only one DSC (usually
177 * data transfer) request in the device request queue.
179 struct request *postponed_rq;
180 /* The time in which we started polling for DSC */
181 unsigned long dsc_polling_start;
182 /* Timer used to poll for dsc */
183 struct timer_list dsc_timer;
184 /* Read/Write dsc polling frequency */
185 unsigned long best_dsc_rw_freq;
186 unsigned long dsc_poll_freq;
187 unsigned long dsc_timeout;
189 /* Read position information */
192 unsigned int first_frame;
194 /* Last error information */
195 u8 sense_key, asc, ascq;
197 /* Character device operation */
201 /* Current character device data transfer direction */
204 /* tape block size, usually 512 or 1024 bytes */
205 unsigned short blk_size;
208 /* Copy of the tape's Capabilities and Mechanical Page */
212 * Active data transfer request parameters.
214 * At most, there is only one ide-tape originated data transfer request
215 * in the device request queue. This allows ide.c to easily service
216 * requests from the other device when we postpone our active request.
219 /* Data buffer size chosen based on the tape's recommendation */
222 struct idetape_bh *merge_bh;
223 /* size of the merge buffer */
225 /* pointer to current buffer head within the merge buffer */
226 struct idetape_bh *bh;
230 /* Measures average tape speed */
231 unsigned long avg_time;
235 /* the door is currently locked */
237 /* the tape hardware is write protected */
239 /* the tape is write protected (hardware or opened as read-only) */
245 static DEFINE_MUTEX(idetape_ref_mutex);
247 static struct class *idetape_sysfs_class;
249 static void ide_tape_release(struct device *);
251 static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
253 struct ide_tape_obj *tape = NULL;
255 mutex_lock(&idetape_ref_mutex);
256 tape = ide_drv_g(disk, ide_tape_obj);
258 if (ide_device_get(tape->drive))
261 get_device(&tape->dev);
263 mutex_unlock(&idetape_ref_mutex);
267 static void ide_tape_put(struct ide_tape_obj *tape)
269 ide_drive_t *drive = tape->drive;
271 mutex_lock(&idetape_ref_mutex);
272 put_device(&tape->dev);
273 ide_device_put(drive);
274 mutex_unlock(&idetape_ref_mutex);
278 * The variables below are used for the character device interface. Additional
279 * state variables are defined in our ide_drive_t structure.
281 static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES];
283 static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
285 struct ide_tape_obj *tape = NULL;
287 mutex_lock(&idetape_ref_mutex);
288 tape = idetape_devs[i];
290 get_device(&tape->dev);
291 mutex_unlock(&idetape_ref_mutex);
295 static int idetape_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
298 struct idetape_bh *bh = pc->bh;
303 (unsigned int)(bh->b_size - atomic_read(&bh->b_count)),
305 drive->hwif->tp_ops->input_data(drive, NULL, bh->b_data +
306 atomic_read(&bh->b_count), count);
308 atomic_add(count, &bh->b_count);
309 if (atomic_read(&bh->b_count) == bh->b_size)
316 static int idetape_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
319 struct idetape_bh *bh = pc->bh;
323 count = min((unsigned int)pc->b_count, (unsigned int)bcount);
324 drive->hwif->tp_ops->output_data(drive, NULL, pc->b_data, count);
327 pc->b_count -= count;
335 static void idetape_update_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc)
337 struct idetape_bh *bh = pc->bh;
338 unsigned int bcount = pc->xferred;
340 if (pc->flags & PC_FLAG_WRITING)
343 if (bh == NULL || bcount > bh->b_size) {
344 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
348 atomic_set(&bh->b_count, bcount);
349 if (atomic_read(&bh->b_count) == bh->b_size)
355 * called on each failed packet command retry to analyze the request sense. We
356 * currently do not utilize this information.
358 static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
360 idetape_tape_t *tape = drive->driver_data;
361 struct ide_atapi_pc *pc = drive->failed_pc;
363 tape->sense_key = sense[2] & 0xF;
364 tape->asc = sense[12];
365 tape->ascq = sense[13];
367 debug_log(DBG_ERR, "pc = %x, sense key = %x, asc = %x, ascq = %x\n",
368 pc->c[0], tape->sense_key, tape->asc, tape->ascq);
370 /* Correct pc->xferred by asking the tape. */
371 if (pc->flags & PC_FLAG_DMA_ERROR) {
372 pc->xferred = pc->req_xfer -
374 get_unaligned_be32(&sense[3]);
375 idetape_update_buffers(drive, pc);
379 * If error was the result of a zero-length read or write command,
380 * with sense key=5, asc=0x22, ascq=0, let it slide. Some drives
381 * (i.e. Seagate STT3401A Travan) don't support 0-length read/writes.
383 if ((pc->c[0] == READ_6 || pc->c[0] == WRITE_6)
385 && pc->c[4] == 0 && pc->c[3] == 0 && pc->c[2] == 0) {
386 if (tape->sense_key == 5) {
387 /* don't report an error, everything's ok */
389 /* don't retry read/write */
390 pc->flags |= PC_FLAG_ABORT;
393 if (pc->c[0] == READ_6 && (sense[2] & 0x80)) {
394 pc->error = IDE_DRV_ERROR_FILEMARK;
395 pc->flags |= PC_FLAG_ABORT;
397 if (pc->c[0] == WRITE_6) {
398 if ((sense[2] & 0x40) || (tape->sense_key == 0xd
399 && tape->asc == 0x0 && tape->ascq == 0x2)) {
400 pc->error = IDE_DRV_ERROR_EOD;
401 pc->flags |= PC_FLAG_ABORT;
404 if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
405 if (tape->sense_key == 8) {
406 pc->error = IDE_DRV_ERROR_EOD;
407 pc->flags |= PC_FLAG_ABORT;
409 if (!(pc->flags & PC_FLAG_ABORT) &&
411 pc->retries = IDETAPE_MAX_PC_RETRIES + 1;
415 /* Free data buffers completely. */
416 static void ide_tape_kfree_buffer(idetape_tape_t *tape)
418 struct idetape_bh *bh = tape->merge_bh;
424 static void ide_tape_handle_dsc(ide_drive_t *);
426 static int ide_tape_callback(ide_drive_t *drive, int dsc)
428 idetape_tape_t *tape = drive->driver_data;
429 struct ide_atapi_pc *pc = drive->pc;
430 struct request *rq = drive->hwif->rq;
431 int uptodate = pc->error ? 0 : 1;
432 int err = uptodate ? 0 : IDE_DRV_ERROR_GENERAL;
434 debug_log(DBG_PROCS, "Enter %s\n", __func__);
437 ide_tape_handle_dsc(drive);
439 if (drive->failed_pc == pc)
440 drive->failed_pc = NULL;
442 if (pc->c[0] == REQUEST_SENSE) {
444 idetape_analyze_error(drive, pc->buf);
446 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE "
447 "itself - Aborting request!\n");
448 } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
449 int blocks = pc->xferred / tape->blk_size;
451 tape->avg_size += blocks * tape->blk_size;
453 if (time_after_eq(jiffies, tape->avg_time + HZ)) {
454 tape->avg_speed = tape->avg_size * HZ /
455 (jiffies - tape->avg_time) / 1024;
457 tape->avg_time = jiffies;
460 tape->first_frame += blocks;
461 rq->current_nr_sectors -= blocks;
467 } else if (pc->c[0] == READ_POSITION && uptodate) {
468 u8 *readpos = pc->buf;
470 debug_log(DBG_SENSE, "BOP - %s\n",
471 (readpos[0] & 0x80) ? "Yes" : "No");
472 debug_log(DBG_SENSE, "EOP - %s\n",
473 (readpos[0] & 0x40) ? "Yes" : "No");
475 if (readpos[0] & 0x4) {
476 printk(KERN_INFO "ide-tape: Block location is unknown"
478 clear_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags);
480 err = IDE_DRV_ERROR_GENERAL;
482 debug_log(DBG_SENSE, "Block Location - %u\n",
483 be32_to_cpup((__be32 *)&readpos[4]));
485 tape->partition = readpos[1];
486 tape->first_frame = be32_to_cpup((__be32 *)&readpos[4]);
487 set_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags);
497 * Postpone the current request so that ide.c will be able to service requests
498 * from another device on the same port while we are polling for DSC.
500 static void idetape_postpone_request(ide_drive_t *drive)
502 idetape_tape_t *tape = drive->driver_data;
504 debug_log(DBG_PROCS, "Enter %s\n", __func__);
506 tape->postponed_rq = drive->hwif->rq;
508 ide_stall_queue(drive, tape->dsc_poll_freq);
511 static void ide_tape_handle_dsc(ide_drive_t *drive)
513 idetape_tape_t *tape = drive->driver_data;
515 /* Media access command */
516 tape->dsc_polling_start = jiffies;
517 tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST;
518 tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT;
519 /* Allow ide.c to handle other requests */
520 idetape_postpone_request(drive);
523 static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
524 unsigned int bcount, int write)
529 bleft = idetape_output_buffers(drive, pc, bcount);
531 bleft = idetape_input_buffers(drive, pc, bcount);
533 return bcount - bleft;
537 * Packet Command Interface
539 * The current Packet Command is available in drive->pc, and will not change
540 * until we finish handling it. Each packet command is associated with a
541 * callback function that will be called when the command is finished.
543 * The handling will be done in three stages:
545 * 1. ide_tape_issue_pc will send the packet command to the drive, and will set
546 * the interrupt handler to ide_pc_intr.
548 * 2. On each interrupt, ide_pc_intr will be called. This step will be
549 * repeated until the device signals us that no more interrupts will be issued.
551 * 3. ATAPI Tape media access commands have immediate status with a delayed
552 * process. In case of a successful initiation of a media access packet command,
553 * the DSC bit will be set when the actual execution of the command is finished.
554 * Since the tape drive will not issue an interrupt, we have to poll for this
555 * event. In this case, we define the request as "low priority request" by
556 * setting rq_status to IDETAPE_RQ_POSTPONED, set a timer to poll for DSC and
559 * ide.c will then give higher priority to requests which originate from the
560 * other device, until will change rq_status to RQ_ACTIVE.
562 * 4. When the packet command is finished, it will be checked for errors.
564 * 5. In case an error was found, we queue a request sense packet command in
565 * front of the request queue and retry the operation up to
566 * IDETAPE_MAX_PC_RETRIES times.
568 * 6. In case no error was found, or we decided to give up and not to retry
569 * again, the callback function will be called and then we will handle the next
573 static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
575 struct ide_atapi_pc *pc)
577 idetape_tape_t *tape = drive->driver_data;
579 if (drive->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
580 drive->failed_pc = pc;
582 /* Set the current packet command */
585 if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
586 (pc->flags & PC_FLAG_ABORT)) {
587 unsigned int done = blk_rq_bytes(drive->hwif->rq);
590 * We will "abort" retrying a packet command in case legitimate
591 * error code was received (crossing a filemark, or end of the
592 * media, for example).
594 if (!(pc->flags & PC_FLAG_ABORT)) {
595 if (!(pc->c[0] == TEST_UNIT_READY &&
596 tape->sense_key == 2 && tape->asc == 4 &&
597 (tape->ascq == 1 || tape->ascq == 8))) {
598 printk(KERN_ERR "ide-tape: %s: I/O error, "
599 "pc = %2x, key = %2x, "
600 "asc = %2x, ascq = %2x\n",
601 tape->name, pc->c[0],
602 tape->sense_key, tape->asc,
606 pc->error = IDE_DRV_ERROR_GENERAL;
609 drive->failed_pc = NULL;
610 drive->pc_callback(drive, 0);
611 ide_complete_rq(drive, -EIO, done);
614 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
618 return ide_issue_pc(drive, cmd);
621 /* A mode sense command is used to "sense" tape parameters. */
622 static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
625 pc->c[0] = MODE_SENSE;
626 if (page_code != IDETAPE_BLOCK_DESCRIPTOR)
627 /* DBD = 1 - Don't return block descriptors */
629 pc->c[2] = page_code;
631 * Changed pc->c[3] to 0 (255 will at best return unused info).
633 * For SCSI this byte is defined as subpage instead of high byte
634 * of length and some IDE drives seem to interpret it this way
635 * and return an error when 255 is used.
638 /* We will just discard data in that case */
640 if (page_code == IDETAPE_BLOCK_DESCRIPTOR)
642 else if (page_code == IDETAPE_CAPABILITIES_PAGE)
648 static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
650 ide_hwif_t *hwif = drive->hwif;
651 idetape_tape_t *tape = drive->driver_data;
652 struct ide_atapi_pc *pc = drive->pc;
655 stat = hwif->tp_ops->read_status(hwif);
657 if (stat & ATA_DSC) {
658 if (stat & ATA_ERR) {
660 if (pc->c[0] != TEST_UNIT_READY)
661 printk(KERN_ERR "ide-tape: %s: I/O error, ",
663 /* Retry operation */
669 pc->error = IDE_DRV_ERROR_GENERAL;
670 drive->failed_pc = NULL;
672 drive->pc_callback(drive, 0);
676 static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
677 struct ide_atapi_pc *pc, struct request *rq,
680 struct idetape_bh *bh = (struct idetape_bh *)rq->special;
681 unsigned int length = rq->current_nr_sectors;
684 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
688 pc->buf_size = length * tape->blk_size;
689 pc->req_xfer = pc->buf_size;
690 if (pc->req_xfer == tape->buffer_size)
691 pc->flags |= PC_FLAG_DMA_OK;
693 if (opcode == READ_6) {
695 atomic_set(&bh->b_count, 0);
696 } else if (opcode == WRITE_6) {
698 pc->flags |= PC_FLAG_WRITING;
699 pc->b_data = bh->b_data;
700 pc->b_count = atomic_read(&bh->b_count);
703 memcpy(rq->cmd, pc->c, 12);
706 static ide_startstop_t idetape_do_request(ide_drive_t *drive,
707 struct request *rq, sector_t block)
709 ide_hwif_t *hwif = drive->hwif;
710 idetape_tape_t *tape = drive->driver_data;
711 struct ide_atapi_pc *pc = NULL;
712 struct request *postponed_rq = tape->postponed_rq;
716 debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %lu,"
717 " current_nr_sectors: %u\n",
718 (unsigned long long)rq->sector, rq->nr_sectors,
719 rq->current_nr_sectors);
721 if (!(blk_special_request(rq) || blk_sense_request(rq))) {
722 /* We do not support buffer cache originated requests. */
723 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in "
724 "request queue (%d)\n", drive->name, rq->cmd_type);
725 if (blk_fs_request(rq) == 0 && rq->errors == 0)
727 ide_complete_rq(drive, -EIO, ide_rq_bytes(rq));
731 /* Retry a failed packet command */
732 if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) {
733 pc = drive->failed_pc;
737 if (postponed_rq != NULL)
738 if (rq != postponed_rq) {
739 printk(KERN_ERR "ide-tape: ide-tape.c bug - "
740 "Two DSC requests were queued\n");
741 drive->failed_pc = NULL;
743 ide_complete_rq(drive, 0, blk_rq_bytes(rq));
747 tape->postponed_rq = NULL;
750 * If the tape is still busy, postpone our request and service
751 * the other device meanwhile.
753 stat = hwif->tp_ops->read_status(hwif);
755 if ((drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) == 0 &&
756 (rq->cmd[13] & REQ_IDETAPE_PC2) == 0)
757 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
759 if (drive->dev_flags & IDE_DFLAG_POST_RESET) {
760 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
761 drive->dev_flags &= ~IDE_DFLAG_POST_RESET;
764 if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) &&
765 (stat & ATA_DSC) == 0) {
766 if (postponed_rq == NULL) {
767 tape->dsc_polling_start = jiffies;
768 tape->dsc_poll_freq = tape->best_dsc_rw_freq;
769 tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT;
770 } else if (time_after(jiffies, tape->dsc_timeout)) {
771 printk(KERN_ERR "ide-tape: %s: DSC timeout\n",
773 if (rq->cmd[13] & REQ_IDETAPE_PC2) {
774 idetape_media_access_finished(drive);
777 return ide_do_reset(drive);
779 } else if (time_after(jiffies,
780 tape->dsc_polling_start +
781 IDETAPE_DSC_MA_THRESHOLD))
782 tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW;
783 idetape_postpone_request(drive);
786 if (rq->cmd[13] & REQ_IDETAPE_READ) {
787 pc = &tape->queued_pc;
788 ide_tape_create_rw_cmd(tape, pc, rq, READ_6);
791 if (rq->cmd[13] & REQ_IDETAPE_WRITE) {
792 pc = &tape->queued_pc;
793 ide_tape_create_rw_cmd(tape, pc, rq, WRITE_6);
796 if (rq->cmd[13] & REQ_IDETAPE_PC1) {
797 pc = (struct ide_atapi_pc *)rq->special;
798 rq->cmd[13] &= ~(REQ_IDETAPE_PC1);
799 rq->cmd[13] |= REQ_IDETAPE_PC2;
802 if (rq->cmd[13] & REQ_IDETAPE_PC2) {
803 idetape_media_access_finished(drive);
809 /* prepare sense request for this command */
810 ide_prep_sense(drive, rq);
812 memset(&cmd, 0, sizeof(cmd));
815 cmd.tf_flags |= IDE_TFLAG_WRITE;
819 ide_init_sg_cmd(&cmd, pc->req_xfer);
820 ide_map_sg(drive, &cmd);
822 return ide_tape_issue_pc(drive, &cmd, pc);
826 * It returns a pointer to the newly allocated buffer, or NULL in case
829 static struct idetape_bh *ide_tape_kmalloc_buffer(idetape_tape_t *tape,
832 struct idetape_bh *bh;
834 bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL);
838 bh->b_data = kmalloc(tape->buffer_size, GFP_KERNEL);
844 bh->b_size = tape->buffer_size;
845 atomic_set(&bh->b_count, full ? bh->b_size : 0);
850 static int idetape_copy_stage_from_user(idetape_tape_t *tape,
851 const char __user *buf, int n)
853 struct idetape_bh *bh = tape->bh;
857 if (bh == NULL || n > bh->b_size - atomic_read(&bh->b_count)) {
858 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
862 if (copy_from_user(bh->b_data + atomic_read(&bh->b_count), buf,
865 atomic_add(n, &bh->b_count);
866 if (atomic_read(&bh->b_count) == bh->b_size)
873 static int idetape_copy_stage_to_user(idetape_tape_t *tape, char __user *buf,
876 struct idetape_bh *bh = tape->bh;
880 if (bh == NULL || n > tape->b_count) {
881 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
885 if (copy_to_user(buf, tape->b_data, n))
895 static void idetape_init_merge_buffer(idetape_tape_t *tape)
897 struct idetape_bh *bh = tape->merge_bh;
898 tape->bh = tape->merge_bh;
900 if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
901 atomic_set(&bh->b_count, 0);
903 tape->b_data = bh->b_data;
904 tape->b_count = atomic_read(&bh->b_count);
909 * Write a filemark if write_filemark=1. Flush the device buffers without
910 * writing a filemark otherwise.
912 static void idetape_create_write_filemark_cmd(ide_drive_t *drive,
913 struct ide_atapi_pc *pc, int write_filemark)
916 pc->c[0] = WRITE_FILEMARKS;
917 pc->c[4] = write_filemark;
918 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
921 static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
923 idetape_tape_t *tape = drive->driver_data;
924 struct gendisk *disk = tape->disk;
925 int load_attempted = 0;
927 /* Wait for the tape to become ready */
928 set_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags);
930 while (time_before(jiffies, timeout)) {
931 if (ide_do_test_unit_ready(drive, disk) == 0)
933 if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2)
934 || (tape->asc == 0x3A)) {
938 ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK);
940 /* not about to be ready */
941 } else if (!(tape->sense_key == 2 && tape->asc == 4 &&
942 (tape->ascq == 1 || tape->ascq == 8)))
949 static int idetape_flush_tape_buffers(ide_drive_t *drive)
951 struct ide_tape_obj *tape = drive->driver_data;
952 struct ide_atapi_pc pc;
955 idetape_create_write_filemark_cmd(drive, &pc, 0);
956 rc = ide_queue_pc_tail(drive, tape->disk, &pc);
959 idetape_wait_ready(drive, 60 * 5 * HZ);
963 static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc)
966 pc->c[0] = READ_POSITION;
970 static int idetape_read_position(ide_drive_t *drive)
972 idetape_tape_t *tape = drive->driver_data;
973 struct ide_atapi_pc pc;
976 debug_log(DBG_PROCS, "Enter %s\n", __func__);
978 idetape_create_read_position_cmd(&pc);
979 if (ide_queue_pc_tail(drive, tape->disk, &pc))
981 position = tape->first_frame;
985 static void idetape_create_locate_cmd(ide_drive_t *drive,
986 struct ide_atapi_pc *pc,
987 unsigned int block, u8 partition, int skip)
990 pc->c[0] = POSITION_TO_ELEMENT;
992 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]);
993 pc->c[8] = partition;
994 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
997 static void __ide_tape_discard_merge_buffer(ide_drive_t *drive)
999 idetape_tape_t *tape = drive->driver_data;
1001 if (tape->chrdev_dir != IDETAPE_DIR_READ)
1004 clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags);
1005 tape->merge_bh_size = 0;
1006 if (tape->merge_bh != NULL) {
1007 ide_tape_kfree_buffer(tape);
1008 tape->merge_bh = NULL;
1011 tape->chrdev_dir = IDETAPE_DIR_NONE;
1015 * Position the tape to the requested block using the LOCATE packet command.
1016 * A READ POSITION command is then issued to check where we are positioned. Like
1017 * all higher level operations, we queue the commands at the tail of the request
1018 * queue and wait for their completion.
1020 static int idetape_position_tape(ide_drive_t *drive, unsigned int block,
1021 u8 partition, int skip)
1023 idetape_tape_t *tape = drive->driver_data;
1024 struct gendisk *disk = tape->disk;
1026 struct ide_atapi_pc pc;
1028 if (tape->chrdev_dir == IDETAPE_DIR_READ)
1029 __ide_tape_discard_merge_buffer(drive);
1030 idetape_wait_ready(drive, 60 * 5 * HZ);
1031 idetape_create_locate_cmd(drive, &pc, block, partition, skip);
1032 retval = ide_queue_pc_tail(drive, disk, &pc);
1036 idetape_create_read_position_cmd(&pc);
1037 return ide_queue_pc_tail(drive, disk, &pc);
1040 static void ide_tape_discard_merge_buffer(ide_drive_t *drive,
1041 int restore_position)
1043 idetape_tape_t *tape = drive->driver_data;
1046 __ide_tape_discard_merge_buffer(drive);
1047 if (restore_position) {
1048 position = idetape_read_position(drive);
1049 seek = position > 0 ? position : 0;
1050 if (idetape_position_tape(drive, seek, 0, 0)) {
1051 printk(KERN_INFO "ide-tape: %s: position_tape failed in"
1052 " %s\n", tape->name, __func__);
1059 * Generate a read/write request for the block device interface and wait for it
1062 static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks,
1063 struct idetape_bh *bh)
1065 idetape_tape_t *tape = drive->driver_data;
1069 debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd);
1071 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
1072 rq->cmd_type = REQ_TYPE_SPECIAL;
1074 rq->rq_disk = tape->disk;
1075 rq->special = (void *)bh;
1076 rq->sector = tape->first_frame;
1077 rq->nr_sectors = blocks;
1078 rq->current_nr_sectors = blocks;
1079 blk_execute_rq(drive->queue, tape->disk, rq, 0);
1081 errors = rq->errors;
1082 ret = tape->blk_size * (blocks - rq->current_nr_sectors);
1083 blk_put_request(rq);
1085 if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0)
1089 idetape_init_merge_buffer(tape);
1090 if (errors == IDE_DRV_ERROR_GENERAL)
1095 static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
1103 static void idetape_create_rewind_cmd(ide_drive_t *drive,
1104 struct ide_atapi_pc *pc)
1107 pc->c[0] = REZERO_UNIT;
1108 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1111 static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
1116 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1119 static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
1123 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]);
1125 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1128 /* Queue up a character device originated write request. */
1129 static int idetape_add_chrdev_write_request(ide_drive_t *drive, int blocks)
1131 idetape_tape_t *tape = drive->driver_data;
1133 debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
1135 return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE,
1136 blocks, tape->merge_bh);
1139 static void ide_tape_flush_merge_buffer(ide_drive_t *drive)
1141 idetape_tape_t *tape = drive->driver_data;
1143 struct idetape_bh *bh;
1145 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) {
1146 printk(KERN_ERR "ide-tape: bug: Trying to empty merge buffer"
1147 " but we are not writing.\n");
1150 if (tape->merge_bh_size > tape->buffer_size) {
1151 printk(KERN_ERR "ide-tape: bug: merge_buffer too big\n");
1152 tape->merge_bh_size = tape->buffer_size;
1154 if (tape->merge_bh_size) {
1155 blocks = tape->merge_bh_size / tape->blk_size;
1156 if (tape->merge_bh_size % tape->blk_size) {
1157 unsigned int i = tape->blk_size -
1158 tape->merge_bh_size % tape->blk_size;
1162 memset(bh->b_data + atomic_read(&bh->b_count),
1164 atomic_add(i, &bh->b_count);
1166 printk(KERN_INFO "ide-tape: bug, bh NULL\n");
1168 (void) idetape_add_chrdev_write_request(drive, blocks);
1169 tape->merge_bh_size = 0;
1171 if (tape->merge_bh != NULL) {
1172 ide_tape_kfree_buffer(tape);
1173 tape->merge_bh = NULL;
1175 tape->chrdev_dir = IDETAPE_DIR_NONE;
1178 static int idetape_init_read(ide_drive_t *drive)
1180 idetape_tape_t *tape = drive->driver_data;
1183 /* Initialize read operation */
1184 if (tape->chrdev_dir != IDETAPE_DIR_READ) {
1185 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
1186 ide_tape_flush_merge_buffer(drive);
1187 idetape_flush_tape_buffers(drive);
1189 if (tape->merge_bh || tape->merge_bh_size) {
1190 printk(KERN_ERR "ide-tape: merge_bh_size should be"
1192 tape->merge_bh_size = 0;
1194 tape->merge_bh = ide_tape_kmalloc_buffer(tape, 0);
1195 if (!tape->merge_bh)
1197 tape->chrdev_dir = IDETAPE_DIR_READ;
1200 * Issue a read 0 command to ensure that DSC handshake is
1201 * switched from completion mode to buffer available mode.
1202 * No point in issuing this if DSC overlap isn't supported, some
1203 * drives (Seagate STT3401A) will return an error.
1205 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
1206 bytes_read = idetape_queue_rw_tail(drive,
1207 REQ_IDETAPE_READ, 0,
1209 if (bytes_read < 0) {
1210 ide_tape_kfree_buffer(tape);
1211 tape->merge_bh = NULL;
1212 tape->chrdev_dir = IDETAPE_DIR_NONE;
1221 /* called from idetape_chrdev_read() to service a chrdev read request. */
1222 static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks)
1224 idetape_tape_t *tape = drive->driver_data;
1226 debug_log(DBG_PROCS, "Enter %s, %d blocks\n", __func__, blocks);
1228 /* If we are at a filemark, return a read length of 0 */
1229 if (test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
1232 idetape_init_read(drive);
1234 return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks,
1238 static void idetape_pad_zeros(ide_drive_t *drive, int bcount)
1240 idetape_tape_t *tape = drive->driver_data;
1241 struct idetape_bh *bh = tape->merge_bh;
1247 count = min(tape->buffer_size, bcount);
1249 blocks = count / tape->blk_size;
1250 atomic_set(&bh->b_count, count);
1251 memset(bh->b_data, 0, atomic_read(&bh->b_count));
1253 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks,
1259 * Rewinds the tape to the Beginning Of the current Partition (BOP). We
1260 * currently support only one partition.
1262 static int idetape_rewind_tape(ide_drive_t *drive)
1264 struct ide_tape_obj *tape = drive->driver_data;
1265 struct gendisk *disk = tape->disk;
1267 struct ide_atapi_pc pc;
1269 debug_log(DBG_SENSE, "Enter %s\n", __func__);
1271 idetape_create_rewind_cmd(drive, &pc);
1272 retval = ide_queue_pc_tail(drive, disk, &pc);
1276 idetape_create_read_position_cmd(&pc);
1277 retval = ide_queue_pc_tail(drive, disk, &pc);
1283 /* mtio.h compatible commands should be issued to the chrdev interface. */
1284 static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd,
1287 idetape_tape_t *tape = drive->driver_data;
1288 void __user *argp = (void __user *)arg;
1290 struct idetape_config {
1291 int dsc_rw_frequency;
1292 int dsc_media_access_frequency;
1296 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1300 if (copy_from_user(&config, argp, sizeof(config)))
1302 tape->best_dsc_rw_freq = config.dsc_rw_frequency;
1305 config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq;
1306 config.nr_stages = 1;
1307 if (copy_to_user(argp, &config, sizeof(config)))
1316 static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1319 idetape_tape_t *tape = drive->driver_data;
1320 struct gendisk *disk = tape->disk;
1321 struct ide_atapi_pc pc;
1322 int retval, count = 0;
1323 int sprev = !!(tape->caps[4] & 0x20);
1327 if (MTBSF == mt_op || MTBSFM == mt_op) {
1330 mt_count = -mt_count;
1333 if (tape->chrdev_dir == IDETAPE_DIR_READ) {
1334 tape->merge_bh_size = 0;
1335 if (test_and_clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
1337 ide_tape_discard_merge_buffer(drive, 0);
1343 idetape_create_space_cmd(&pc, mt_count - count,
1344 IDETAPE_SPACE_OVER_FILEMARK);
1345 return ide_queue_pc_tail(drive, disk, &pc);
1350 retval = idetape_space_over_filemarks(drive, MTFSF,
1354 count = (MTBSFM == mt_op ? 1 : -1);
1355 return idetape_space_over_filemarks(drive, MTFSF, count);
1357 printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",
1364 * Our character device read / write functions.
1366 * The tape is optimized to maximize throughput when it is transferring an
1367 * integral number of the "continuous transfer limit", which is a parameter of
1368 * the specific tape (26kB on my particular tape, 32kB for Onstream).
1370 * As of version 1.3 of the driver, the character device provides an abstract
1371 * continuous view of the media - any mix of block sizes (even 1 byte) on the
1372 * same backup/restore procedure is supported. The driver will internally
1373 * convert the requests to the recommended transfer unit, so that an unmatch
1374 * between the user's block size to the recommended size will only result in a
1375 * (slightly) increased driver overhead, but will no longer hit performance.
1376 * This is not applicable to Onstream.
1378 static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
1379 size_t count, loff_t *ppos)
1381 struct ide_tape_obj *tape = file->private_data;
1382 ide_drive_t *drive = tape->drive;
1383 ssize_t bytes_read, temp, actually_read = 0, rc;
1385 u16 ctl = *(u16 *)&tape->caps[12];
1387 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
1389 if (tape->chrdev_dir != IDETAPE_DIR_READ) {
1390 if (test_bit(IDE_AFLAG_DETECT_BS, &drive->atapi_flags))
1391 if (count > tape->blk_size &&
1392 (count % tape->blk_size) == 0)
1393 tape->user_bs_factor = count / tape->blk_size;
1395 rc = idetape_init_read(drive);
1400 if (tape->merge_bh_size) {
1401 actually_read = min((unsigned int)(tape->merge_bh_size),
1402 (unsigned int)count);
1403 if (idetape_copy_stage_to_user(tape, buf, actually_read))
1405 buf += actually_read;
1406 tape->merge_bh_size -= actually_read;
1407 count -= actually_read;
1409 while (count >= tape->buffer_size) {
1410 bytes_read = idetape_add_chrdev_read_request(drive, ctl);
1411 if (bytes_read <= 0)
1413 if (idetape_copy_stage_to_user(tape, buf, bytes_read))
1416 count -= bytes_read;
1417 actually_read += bytes_read;
1420 bytes_read = idetape_add_chrdev_read_request(drive, ctl);
1421 if (bytes_read <= 0)
1423 temp = min((unsigned long)count, (unsigned long)bytes_read);
1424 if (idetape_copy_stage_to_user(tape, buf, temp))
1426 actually_read += temp;
1427 tape->merge_bh_size = bytes_read-temp;
1430 if (!actually_read && test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) {
1431 debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name);
1433 idetape_space_over_filemarks(drive, MTFSF, 1);
1437 return ret ? ret : actually_read;
1440 static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1441 size_t count, loff_t *ppos)
1443 struct ide_tape_obj *tape = file->private_data;
1444 ide_drive_t *drive = tape->drive;
1445 ssize_t actually_written = 0;
1447 u16 ctl = *(u16 *)&tape->caps[12];
1449 /* The drive is write protected. */
1450 if (tape->write_prot)
1453 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
1455 /* Initialize write operation */
1456 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) {
1457 if (tape->chrdev_dir == IDETAPE_DIR_READ)
1458 ide_tape_discard_merge_buffer(drive, 1);
1459 if (tape->merge_bh || tape->merge_bh_size) {
1460 printk(KERN_ERR "ide-tape: merge_bh_size "
1461 "should be 0 now\n");
1462 tape->merge_bh_size = 0;
1464 tape->merge_bh = ide_tape_kmalloc_buffer(tape, 0);
1465 if (!tape->merge_bh)
1467 tape->chrdev_dir = IDETAPE_DIR_WRITE;
1468 idetape_init_merge_buffer(tape);
1471 * Issue a write 0 command to ensure that DSC handshake is
1472 * switched from completion mode to buffer available mode. No
1473 * point in issuing this if DSC overlap isn't supported, some
1474 * drives (Seagate STT3401A) will return an error.
1476 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
1477 ssize_t retval = idetape_queue_rw_tail(drive,
1478 REQ_IDETAPE_WRITE, 0,
1481 ide_tape_kfree_buffer(tape);
1482 tape->merge_bh = NULL;
1483 tape->chrdev_dir = IDETAPE_DIR_NONE;
1490 if (tape->merge_bh_size) {
1491 if (tape->merge_bh_size >= tape->buffer_size) {
1492 printk(KERN_ERR "ide-tape: bug: merge buf too big\n");
1493 tape->merge_bh_size = 0;
1495 actually_written = min((unsigned int)
1496 (tape->buffer_size - tape->merge_bh_size),
1497 (unsigned int)count);
1498 if (idetape_copy_stage_from_user(tape, buf, actually_written))
1500 buf += actually_written;
1501 tape->merge_bh_size += actually_written;
1502 count -= actually_written;
1504 if (tape->merge_bh_size == tape->buffer_size) {
1506 tape->merge_bh_size = 0;
1507 retval = idetape_add_chrdev_write_request(drive, ctl);
1512 while (count >= tape->buffer_size) {
1514 if (idetape_copy_stage_from_user(tape, buf, tape->buffer_size))
1516 buf += tape->buffer_size;
1517 count -= tape->buffer_size;
1518 retval = idetape_add_chrdev_write_request(drive, ctl);
1519 actually_written += tape->buffer_size;
1524 actually_written += count;
1525 if (idetape_copy_stage_from_user(tape, buf, count))
1527 tape->merge_bh_size += count;
1529 return ret ? ret : actually_written;
1532 static int idetape_write_filemark(ide_drive_t *drive)
1534 struct ide_tape_obj *tape = drive->driver_data;
1535 struct ide_atapi_pc pc;
1537 /* Write a filemark */
1538 idetape_create_write_filemark_cmd(drive, &pc, 1);
1539 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
1540 printk(KERN_ERR "ide-tape: Couldn't write a filemark\n");
1547 * Called from idetape_chrdev_ioctl when the general mtio MTIOCTOP ioctl is
1550 * Note: MTBSF and MTBSFM are not supported when the tape doesn't support
1551 * spacing over filemarks in the reverse direction. In this case, MTFSFM is also
1552 * usually not supported.
1554 * The following commands are currently not supported:
1556 * MTFSS, MTBSS, MTWSM, MTSETDENSITY, MTSETDRVBUFFER, MT_ST_BOOLEANS,
1557 * MT_ST_WRITE_THRESHOLD.
1559 static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
1561 idetape_tape_t *tape = drive->driver_data;
1562 struct gendisk *disk = tape->disk;
1563 struct ide_atapi_pc pc;
1566 debug_log(DBG_ERR, "Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n",
1576 return idetape_space_over_filemarks(drive, mt_op, mt_count);
1583 if (tape->write_prot)
1585 ide_tape_discard_merge_buffer(drive, 1);
1586 for (i = 0; i < mt_count; i++) {
1587 retval = idetape_write_filemark(drive);
1593 ide_tape_discard_merge_buffer(drive, 0);
1594 if (idetape_rewind_tape(drive))
1598 ide_tape_discard_merge_buffer(drive, 0);
1599 return ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK);
1603 * If door is locked, attempt to unlock before
1604 * attempting to eject.
1606 if (tape->door_locked) {
1607 if (!ide_set_media_lock(drive, disk, 0))
1608 tape->door_locked = DOOR_UNLOCKED;
1610 ide_tape_discard_merge_buffer(drive, 0);
1611 retval = ide_do_start_stop(drive, disk, !IDETAPE_LU_LOAD_MASK);
1613 clear_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags);
1616 ide_tape_discard_merge_buffer(drive, 0);
1617 return idetape_flush_tape_buffers(drive);
1619 ide_tape_discard_merge_buffer(drive, 0);
1620 return ide_do_start_stop(drive, disk,
1621 IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
1623 idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD);
1624 return ide_queue_pc_tail(drive, disk, &pc);
1626 (void)idetape_rewind_tape(drive);
1627 idetape_create_erase_cmd(&pc);
1628 return ide_queue_pc_tail(drive, disk, &pc);
1631 if (mt_count < tape->blk_size ||
1632 mt_count % tape->blk_size)
1634 tape->user_bs_factor = mt_count / tape->blk_size;
1635 clear_bit(IDE_AFLAG_DETECT_BS, &drive->atapi_flags);
1637 set_bit(IDE_AFLAG_DETECT_BS, &drive->atapi_flags);
1640 ide_tape_discard_merge_buffer(drive, 0);
1641 return idetape_position_tape(drive,
1642 mt_count * tape->user_bs_factor, tape->partition, 0);
1644 ide_tape_discard_merge_buffer(drive, 0);
1645 return idetape_position_tape(drive, 0, mt_count, 0);
1649 retval = ide_set_media_lock(drive, disk, 1);
1652 tape->door_locked = DOOR_EXPLICITLY_LOCKED;
1655 retval = ide_set_media_lock(drive, disk, 0);
1658 tape->door_locked = DOOR_UNLOCKED;
1661 printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",
1668 * Our character device ioctls. General mtio.h magnetic io commands are
1669 * supported here, and not in the corresponding block interface. Our own
1670 * ide-tape ioctls are supported on both interfaces.
1672 static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
1673 unsigned int cmd, unsigned long arg)
1675 struct ide_tape_obj *tape = file->private_data;
1676 ide_drive_t *drive = tape->drive;
1680 int block_offset = 0, position = tape->first_frame;
1681 void __user *argp = (void __user *)arg;
1683 debug_log(DBG_CHRDEV, "Enter %s, cmd=%u\n", __func__, cmd);
1685 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
1686 ide_tape_flush_merge_buffer(drive);
1687 idetape_flush_tape_buffers(drive);
1689 if (cmd == MTIOCGET || cmd == MTIOCPOS) {
1690 block_offset = tape->merge_bh_size /
1691 (tape->blk_size * tape->user_bs_factor);
1692 position = idetape_read_position(drive);
1698 if (copy_from_user(&mtop, argp, sizeof(struct mtop)))
1700 return idetape_mtioctop(drive, mtop.mt_op, mtop.mt_count);
1702 memset(&mtget, 0, sizeof(struct mtget));
1703 mtget.mt_type = MT_ISSCSI2;
1704 mtget.mt_blkno = position / tape->user_bs_factor - block_offset;
1706 ((tape->blk_size * tape->user_bs_factor)
1707 << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK;
1709 if (tape->drv_write_prot)
1710 mtget.mt_gstat |= GMT_WR_PROT(0xffffffff);
1712 if (copy_to_user(argp, &mtget, sizeof(struct mtget)))
1716 mtpos.mt_blkno = position / tape->user_bs_factor - block_offset;
1717 if (copy_to_user(argp, &mtpos, sizeof(struct mtpos)))
1721 if (tape->chrdev_dir == IDETAPE_DIR_READ)
1722 ide_tape_discard_merge_buffer(drive, 1);
1723 return idetape_blkdev_ioctl(drive, cmd, arg);
1728 * Do a mode sense page 0 with block descriptor and if it succeeds set the tape
1729 * block size with the reported value.
1731 static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
1733 idetape_tape_t *tape = drive->driver_data;
1734 struct ide_atapi_pc pc;
1736 idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR);
1737 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
1738 printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
1739 if (tape->blk_size == 0) {
1740 printk(KERN_WARNING "ide-tape: Cannot deal with zero "
1741 "block size, assuming 32k\n");
1742 tape->blk_size = 32768;
1746 tape->blk_size = (pc.buf[4 + 5] << 16) +
1747 (pc.buf[4 + 6] << 8) +
1749 tape->drv_write_prot = (pc.buf[2] & 0x80) >> 7;
1752 static int idetape_chrdev_open(struct inode *inode, struct file *filp)
1754 unsigned int minor = iminor(inode), i = minor & ~0xc0;
1756 idetape_tape_t *tape;
1759 if (i >= MAX_HWIFS * MAX_DRIVES)
1763 tape = ide_tape_chrdev_get(i);
1769 debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
1772 * We really want to do nonseekable_open(inode, filp); here, but some
1773 * versions of tar incorrectly call lseek on tapes and bail out if that
1774 * fails. So we disallow pread() and pwrite(), but permit lseeks.
1776 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE);
1778 drive = tape->drive;
1780 filp->private_data = tape;
1782 if (test_and_set_bit(IDE_AFLAG_BUSY, &drive->atapi_flags)) {
1787 retval = idetape_wait_ready(drive, 60 * HZ);
1789 clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
1790 printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name);
1794 idetape_read_position(drive);
1795 if (!test_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags))
1796 (void)idetape_rewind_tape(drive);
1798 /* Read block size and write protect status from drive. */
1799 ide_tape_get_bsize_from_bdesc(drive);
1801 /* Set write protect flag if device is opened as read-only. */
1802 if ((filp->f_flags & O_ACCMODE) == O_RDONLY)
1803 tape->write_prot = 1;
1805 tape->write_prot = tape->drv_write_prot;
1807 /* Make sure drive isn't write protected if user wants to write. */
1808 if (tape->write_prot) {
1809 if ((filp->f_flags & O_ACCMODE) == O_WRONLY ||
1810 (filp->f_flags & O_ACCMODE) == O_RDWR) {
1811 clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
1817 /* Lock the tape drive door so user can't eject. */
1818 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
1819 if (!ide_set_media_lock(drive, tape->disk, 1)) {
1820 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED)
1821 tape->door_locked = DOOR_LOCKED;
1833 static void idetape_write_release(ide_drive_t *drive, unsigned int minor)
1835 idetape_tape_t *tape = drive->driver_data;
1837 ide_tape_flush_merge_buffer(drive);
1838 tape->merge_bh = ide_tape_kmalloc_buffer(tape, 1);
1839 if (tape->merge_bh != NULL) {
1840 idetape_pad_zeros(drive, tape->blk_size *
1841 (tape->user_bs_factor - 1));
1842 ide_tape_kfree_buffer(tape);
1843 tape->merge_bh = NULL;
1845 idetape_write_filemark(drive);
1846 idetape_flush_tape_buffers(drive);
1847 idetape_flush_tape_buffers(drive);
1850 static int idetape_chrdev_release(struct inode *inode, struct file *filp)
1852 struct ide_tape_obj *tape = filp->private_data;
1853 ide_drive_t *drive = tape->drive;
1854 unsigned int minor = iminor(inode);
1857 tape = drive->driver_data;
1859 debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
1861 if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
1862 idetape_write_release(drive, minor);
1863 if (tape->chrdev_dir == IDETAPE_DIR_READ) {
1865 ide_tape_discard_merge_buffer(drive, 1);
1868 if (minor < 128 && test_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags))
1869 (void) idetape_rewind_tape(drive);
1870 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
1871 if (tape->door_locked == DOOR_LOCKED) {
1872 if (!ide_set_media_lock(drive, tape->disk, 0))
1873 tape->door_locked = DOOR_UNLOCKED;
1876 clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
1882 static void idetape_get_inquiry_results(ide_drive_t *drive)
1884 idetape_tape_t *tape = drive->driver_data;
1885 struct ide_atapi_pc pc;
1887 char fw_rev[4], vendor_id[8], product_id[16];
1889 idetape_create_inquiry_cmd(&pc);
1890 pc.buf = &pc_buf[0];
1891 pc.buf_size = sizeof(pc_buf);
1893 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
1894 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n",
1898 memcpy(vendor_id, &pc.buf[8], 8);
1899 memcpy(product_id, &pc.buf[16], 16);
1900 memcpy(fw_rev, &pc.buf[32], 4);
1902 ide_fixstring(vendor_id, 8, 0);
1903 ide_fixstring(product_id, 16, 0);
1904 ide_fixstring(fw_rev, 4, 0);
1906 printk(KERN_INFO "ide-tape: %s <-> %s: %.8s %.16s rev %.4s\n",
1907 drive->name, tape->name, vendor_id, product_id, fw_rev);
1911 * Ask the tape about its various parameters. In particular, we will adjust our
1912 * data transfer buffer size to the recommended value as returned by the tape.
1914 static void idetape_get_mode_sense_results(ide_drive_t *drive)
1916 idetape_tape_t *tape = drive->driver_data;
1917 struct ide_atapi_pc pc;
1919 u8 speed, max_speed;
1921 idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE);
1922 if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
1923 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming"
1924 " some default values\n");
1925 tape->blk_size = 512;
1926 put_unaligned(52, (u16 *)&tape->caps[12]);
1927 put_unaligned(540, (u16 *)&tape->caps[14]);
1928 put_unaligned(6*52, (u16 *)&tape->caps[16]);
1931 caps = pc.buf + 4 + pc.buf[3];
1933 /* convert to host order and save for later use */
1934 speed = be16_to_cpup((__be16 *)&caps[14]);
1935 max_speed = be16_to_cpup((__be16 *)&caps[8]);
1937 *(u16 *)&caps[8] = max_speed;
1938 *(u16 *)&caps[12] = be16_to_cpup((__be16 *)&caps[12]);
1939 *(u16 *)&caps[14] = speed;
1940 *(u16 *)&caps[16] = be16_to_cpup((__be16 *)&caps[16]);
1943 printk(KERN_INFO "ide-tape: %s: invalid tape speed "
1944 "(assuming 650KB/sec)\n", drive->name);
1945 *(u16 *)&caps[14] = 650;
1948 printk(KERN_INFO "ide-tape: %s: invalid max_speed "
1949 "(assuming 650KB/sec)\n", drive->name);
1950 *(u16 *)&caps[8] = 650;
1953 memcpy(&tape->caps, caps, 20);
1955 /* device lacks locking support according to capabilities page */
1956 if ((caps[6] & 1) == 0)
1957 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
1960 tape->blk_size = 512;
1961 else if (caps[7] & 0x04)
1962 tape->blk_size = 1024;
1965 #ifdef CONFIG_IDE_PROC_FS
1966 #define ide_tape_devset_get(name, field) \
1967 static int get_##name(ide_drive_t *drive) \
1969 idetape_tape_t *tape = drive->driver_data; \
1970 return tape->field; \
1973 #define ide_tape_devset_set(name, field) \
1974 static int set_##name(ide_drive_t *drive, int arg) \
1976 idetape_tape_t *tape = drive->driver_data; \
1977 tape->field = arg; \
1981 #define ide_tape_devset_rw_field(_name, _field) \
1982 ide_tape_devset_get(_name, _field) \
1983 ide_tape_devset_set(_name, _field) \
1984 IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name)
1986 #define ide_tape_devset_r_field(_name, _field) \
1987 ide_tape_devset_get(_name, _field) \
1988 IDE_DEVSET(_name, 0, get_##_name, NULL)
1990 static int mulf_tdsc(ide_drive_t *drive) { return 1000; }
1991 static int divf_tdsc(ide_drive_t *drive) { return HZ; }
1992 static int divf_buffer(ide_drive_t *drive) { return 2; }
1993 static int divf_buffer_size(ide_drive_t *drive) { return 1024; }
1995 ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
1997 ide_tape_devset_rw_field(debug_mask, debug_mask);
1998 ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq);
2000 ide_tape_devset_r_field(avg_speed, avg_speed);
2001 ide_tape_devset_r_field(speed, caps[14]);
2002 ide_tape_devset_r_field(buffer, caps[16]);
2003 ide_tape_devset_r_field(buffer_size, buffer_size);
2005 static const struct ide_proc_devset idetape_settings[] = {
2006 __IDE_PROC_DEVSET(avg_speed, 0, 0xffff, NULL, NULL),
2007 __IDE_PROC_DEVSET(buffer, 0, 0xffff, NULL, divf_buffer),
2008 __IDE_PROC_DEVSET(buffer_size, 0, 0xffff, NULL, divf_buffer_size),
2009 __IDE_PROC_DEVSET(debug_mask, 0, 0xffff, NULL, NULL),
2010 __IDE_PROC_DEVSET(dsc_overlap, 0, 1, NULL, NULL),
2011 __IDE_PROC_DEVSET(speed, 0, 0xffff, NULL, NULL),
2012 __IDE_PROC_DEVSET(tdsc, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX,
2013 mulf_tdsc, divf_tdsc),
2019 * The function below is called to:
2021 * 1. Initialize our various state variables.
2022 * 2. Ask the tape for its capabilities.
2023 * 3. Allocate a buffer which will be used for data transfer. The buffer size
2024 * is chosen based on the recommendation which we received in step 2.
2026 * Note that at this point ide.c already assigned us an irq, so that we can
2027 * queue requests here and wait for their completion.
2029 static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2034 u16 *ctl = (u16 *)&tape->caps[12];
2036 drive->pc_callback = ide_tape_callback;
2037 drive->pc_update_buffers = idetape_update_buffers;
2038 drive->pc_io_buffers = ide_tape_io_buffers;
2040 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
2042 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) {
2043 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n",
2045 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2048 /* Seagate Travan drives do not support DSC overlap. */
2049 if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401"))
2050 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2052 tape->minor = minor;
2053 tape->name[0] = 'h';
2054 tape->name[1] = 't';
2055 tape->name[2] = '0' + minor;
2056 tape->chrdev_dir = IDETAPE_DIR_NONE;
2058 idetape_get_inquiry_results(drive);
2059 idetape_get_mode_sense_results(drive);
2060 ide_tape_get_bsize_from_bdesc(drive);
2061 tape->user_bs_factor = 1;
2062 tape->buffer_size = *ctl * tape->blk_size;
2063 while (tape->buffer_size > 0xffff) {
2064 printk(KERN_NOTICE "ide-tape: decreasing stage size\n");
2066 tape->buffer_size = *ctl * tape->blk_size;
2068 buffer_size = tape->buffer_size;
2070 /* select the "best" DSC read/write polling freq */
2071 speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]);
2073 t = (IDETAPE_FIFO_THRESHOLD * tape->buffer_size * HZ) / (speed * 1000);
2076 * Ensure that the number we got makes sense; limit it within
2077 * IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX.
2079 tape->best_dsc_rw_freq = clamp_t(unsigned long, t, IDETAPE_DSC_RW_MIN,
2080 IDETAPE_DSC_RW_MAX);
2081 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, "
2083 drive->name, tape->name, *(u16 *)&tape->caps[14],
2084 (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size,
2085 tape->buffer_size / 1024,
2086 tape->best_dsc_rw_freq * 1000 / HZ,
2087 (drive->dev_flags & IDE_DFLAG_USING_DMA) ? ", DMA" : "");
2089 ide_proc_register_driver(drive, tape->driver);
2092 static void ide_tape_remove(ide_drive_t *drive)
2094 idetape_tape_t *tape = drive->driver_data;
2096 ide_proc_unregister_driver(drive, tape->driver);
2097 device_del(&tape->dev);
2098 ide_unregister_region(tape->disk);
2100 mutex_lock(&idetape_ref_mutex);
2101 put_device(&tape->dev);
2102 mutex_unlock(&idetape_ref_mutex);
2105 static void ide_tape_release(struct device *dev)
2107 struct ide_tape_obj *tape = to_ide_drv(dev, ide_tape_obj);
2108 ide_drive_t *drive = tape->drive;
2109 struct gendisk *g = tape->disk;
2111 BUG_ON(tape->merge_bh_size);
2113 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2114 drive->driver_data = NULL;
2115 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor));
2116 device_destroy(idetape_sysfs_class,
2117 MKDEV(IDETAPE_MAJOR, tape->minor + 128));
2118 idetape_devs[tape->minor] = NULL;
2119 g->private_data = NULL;
2124 #ifdef CONFIG_IDE_PROC_FS
2125 static int proc_idetape_read_name
2126 (char *page, char **start, off_t off, int count, int *eof, void *data)
2128 ide_drive_t *drive = (ide_drive_t *) data;
2129 idetape_tape_t *tape = drive->driver_data;
2133 len = sprintf(out, "%s\n", tape->name);
2134 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
2137 static ide_proc_entry_t idetape_proc[] = {
2138 { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL },
2139 { "name", S_IFREG|S_IRUGO, proc_idetape_read_name, NULL },
2140 { NULL, 0, NULL, NULL }
2143 static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive)
2145 return idetape_proc;
2148 static const struct ide_proc_devset *ide_tape_proc_devsets(ide_drive_t *drive)
2150 return idetape_settings;
2154 static int ide_tape_probe(ide_drive_t *);
2156 static struct ide_driver idetape_driver = {
2158 .owner = THIS_MODULE,
2160 .bus = &ide_bus_type,
2162 .probe = ide_tape_probe,
2163 .remove = ide_tape_remove,
2164 .version = IDETAPE_VERSION,
2165 .do_request = idetape_do_request,
2166 #ifdef CONFIG_IDE_PROC_FS
2167 .proc_entries = ide_tape_proc_entries,
2168 .proc_devsets = ide_tape_proc_devsets,
2172 /* Our character device supporting functions, passed to register_chrdev. */
2173 static const struct file_operations idetape_fops = {
2174 .owner = THIS_MODULE,
2175 .read = idetape_chrdev_read,
2176 .write = idetape_chrdev_write,
2177 .ioctl = idetape_chrdev_ioctl,
2178 .open = idetape_chrdev_open,
2179 .release = idetape_chrdev_release,
2182 static int idetape_open(struct block_device *bdev, fmode_t mode)
2184 struct ide_tape_obj *tape = ide_tape_get(bdev->bd_disk);
2192 static int idetape_release(struct gendisk *disk, fmode_t mode)
2194 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
2200 static int idetape_ioctl(struct block_device *bdev, fmode_t mode,
2201 unsigned int cmd, unsigned long arg)
2203 struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj);
2204 ide_drive_t *drive = tape->drive;
2205 int err = generic_ide_ioctl(drive, bdev, cmd, arg);
2207 err = idetape_blkdev_ioctl(drive, cmd, arg);
2211 static struct block_device_operations idetape_block_ops = {
2212 .owner = THIS_MODULE,
2213 .open = idetape_open,
2214 .release = idetape_release,
2215 .locked_ioctl = idetape_ioctl,
2218 static int ide_tape_probe(ide_drive_t *drive)
2220 idetape_tape_t *tape;
2224 if (!strstr("ide-tape", drive->driver_req))
2227 if (drive->media != ide_tape)
2230 if ((drive->dev_flags & IDE_DFLAG_ID_READ) &&
2231 ide_check_atapi_device(drive, DRV_NAME) == 0) {
2232 printk(KERN_ERR "ide-tape: %s: not supported by this version of"
2233 " the driver\n", drive->name);
2236 tape = kzalloc(sizeof(idetape_tape_t), GFP_KERNEL);
2238 printk(KERN_ERR "ide-tape: %s: Can't allocate a tape struct\n",
2243 g = alloc_disk(1 << PARTN_BITS);
2247 ide_init_disk(g, drive);
2249 tape->dev.parent = &drive->gendev;
2250 tape->dev.release = ide_tape_release;
2251 dev_set_name(&tape->dev, dev_name(&drive->gendev));
2253 if (device_register(&tape->dev))
2256 tape->drive = drive;
2257 tape->driver = &idetape_driver;
2260 g->private_data = &tape->driver;
2262 drive->driver_data = tape;
2264 mutex_lock(&idetape_ref_mutex);
2265 for (minor = 0; idetape_devs[minor]; minor++)
2267 idetape_devs[minor] = tape;
2268 mutex_unlock(&idetape_ref_mutex);
2270 idetape_setup(drive, tape, minor);
2272 device_create(idetape_sysfs_class, &drive->gendev,
2273 MKDEV(IDETAPE_MAJOR, minor), NULL, "%s", tape->name);
2274 device_create(idetape_sysfs_class, &drive->gendev,
2275 MKDEV(IDETAPE_MAJOR, minor + 128), NULL,
2278 g->fops = &idetape_block_ops;
2279 ide_register_region(g);
2291 static void __exit idetape_exit(void)
2293 driver_unregister(&idetape_driver.gen_driver);
2294 class_destroy(idetape_sysfs_class);
2295 unregister_chrdev(IDETAPE_MAJOR, "ht");
2298 static int __init idetape_init(void)
2301 idetape_sysfs_class = class_create(THIS_MODULE, "ide_tape");
2302 if (IS_ERR(idetape_sysfs_class)) {
2303 idetape_sysfs_class = NULL;
2304 printk(KERN_ERR "Unable to create sysfs class for ide tapes\n");
2309 if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) {
2310 printk(KERN_ERR "ide-tape: Failed to register chrdev"
2313 goto out_free_class;
2316 error = driver_register(&idetape_driver.gen_driver);
2318 goto out_free_driver;
2323 driver_unregister(&idetape_driver.gen_driver);
2325 class_destroy(idetape_sysfs_class);
2330 MODULE_ALIAS("ide:*m-tape*");
2331 module_init(idetape_init);
2332 module_exit(idetape_exit);
2333 MODULE_ALIAS_CHARDEV_MAJOR(IDETAPE_MAJOR);
2334 MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver");
2335 MODULE_LICENSE("GPL");