ide-tape: convert to ide_debug_log macro
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / ide / ide-tape.c
CommitLineData
1da177e4 1/*
5ce78af4
BP
2 * IDE ATAPI streaming tape driver.
3 *
59bca8cc
BZ
4 * Copyright (C) 1995-1999 Gadi Oxman <gadio@netvision.net.il>
5 * Copyright (C) 2003-2005 Bartlomiej Zolnierkiewicz
1da177e4 6 *
1da177e4
LT
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.
10 *
11 * It is hereby placed under the terms of the GNU general public license.
12 * (See linux/COPYING).
1da177e4 13 *
5ce78af4
BP
14 * For a historical changelog see
15 * Documentation/ide/ChangeLog.ide-tape.1995-2002
1da177e4
LT
16 */
17
51509eec
BZ
18#define DRV_NAME "ide-tape"
19
dfe79936 20#define IDETAPE_VERSION "1.20"
1da177e4 21
1da177e4
LT
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>
28#include <linux/mm.h>
29#include <linux/interrupt.h>
9bae1ff3 30#include <linux/jiffies.h>
1da177e4 31#include <linux/major.h>
1da177e4
LT
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>
cf8b8975 40#include <linux/mutex.h>
90699ce2 41#include <scsi/scsi.h>
1da177e4
LT
42
43#include <asm/byteorder.h>
c837cfa5
BP
44#include <linux/irq.h>
45#include <linux/uaccess.h>
46#include <linux/io.h>
1da177e4 47#include <asm/unaligned.h>
1da177e4
LT
48#include <linux/mtio.h>
49
8004a8c9 50/* define to see debug info */
e972d702 51#undef IDETAPE_DEBUG_LOG
8004a8c9 52
e972d702
BP
53#ifdef IDETAPE_DEBUG_LOG
54#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, ## args)
8004a8c9 55#else
e972d702 56#define ide_debug_log(lvl, fmt, args...) do {} while (0)
8004a8c9
BP
57#endif
58
1da177e4 59/**************************** Tunable parameters *****************************/
1da177e4 60/*
3c98bf34
BP
61 * After each failed packet command we issue a request sense command and retry
62 * the packet command IDETAPE_MAX_PC_RETRIES times.
1da177e4 63 *
3c98bf34 64 * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries.
1da177e4
LT
65 */
66#define IDETAPE_MAX_PC_RETRIES 3
67
1da177e4 68/*
3c98bf34
BP
69 * The following parameter is used to select the point in the internal tape fifo
70 * in which we will start to refill the buffer. Decreasing the following
71 * parameter will improve the system's latency and interactive response, while
72 * using a high value might improve system throughput.
1da177e4 73 */
3c98bf34 74#define IDETAPE_FIFO_THRESHOLD 2
1da177e4
LT
75
76/*
3c98bf34 77 * DSC polling parameters.
1da177e4 78 *
3c98bf34
BP
79 * Polling for DSC (a single bit in the status register) is a very important
80 * function in ide-tape. There are two cases in which we poll for DSC:
1da177e4 81 *
3c98bf34
BP
82 * 1. Before a read/write packet command, to ensure that we can transfer data
83 * from/to the tape's data buffers, without causing an actual media access.
84 * In case the tape is not ready yet, we take out our request from the device
85 * request queue, so that ide.c could service requests from the other device
86 * on the same interface in the meantime.
1da177e4 87 *
3c98bf34
BP
88 * 2. After the successful initialization of a "media access packet command",
89 * which is a command that can take a long time to complete (the interval can
90 * range from several seconds to even an hour). Again, we postpone our request
91 * in the middle to free the bus for the other device. The polling frequency
92 * here should be lower than the read/write frequency since those media access
93 * commands are slow. We start from a "fast" frequency - IDETAPE_DSC_MA_FAST
94 * (1 second), and if we don't receive DSC after IDETAPE_DSC_MA_THRESHOLD
95 * (5 min), we switch it to a lower frequency - IDETAPE_DSC_MA_SLOW (1 min).
1da177e4 96 *
3c98bf34
BP
97 * We also set a timeout for the timer, in case something goes wrong. The
98 * timeout should be longer then the maximum execution time of a tape operation.
1da177e4 99 */
3c98bf34
BP
100
101/* DSC timings. */
1da177e4
LT
102#define IDETAPE_DSC_RW_MIN 5*HZ/100 /* 50 msec */
103#define IDETAPE_DSC_RW_MAX 40*HZ/100 /* 400 msec */
104#define IDETAPE_DSC_RW_TIMEOUT 2*60*HZ /* 2 minutes */
105#define IDETAPE_DSC_MA_FAST 2*HZ /* 2 seconds */
106#define IDETAPE_DSC_MA_THRESHOLD 5*60*HZ /* 5 minutes */
107#define IDETAPE_DSC_MA_SLOW 30*HZ /* 30 seconds */
108#define IDETAPE_DSC_MA_TIMEOUT 2*60*60*HZ /* 2 hours */
109
110/*************************** End of tunable parameters ***********************/
111
54abf37e
BP
112/* tape directions */
113enum {
114 IDETAPE_DIR_NONE = (1 << 0),
115 IDETAPE_DIR_READ = (1 << 1),
116 IDETAPE_DIR_WRITE = (1 << 2),
117};
1da177e4 118
03056b90
BP
119/* Tape door status */
120#define DOOR_UNLOCKED 0
121#define DOOR_LOCKED 1
122#define DOOR_EXPLICITLY_LOCKED 2
123
124/* Some defines for the SPACE command */
125#define IDETAPE_SPACE_OVER_FILEMARK 1
126#define IDETAPE_SPACE_TO_EOD 3
127
128/* Some defines for the LOAD UNLOAD command */
129#define IDETAPE_LU_LOAD_MASK 1
130#define IDETAPE_LU_RETENSION_MASK 2
131#define IDETAPE_LU_EOT_MASK 4
132
03056b90
BP
133/* Structures related to the SELECT SENSE / MODE SENSE packet commands. */
134#define IDETAPE_BLOCK_DESCRIPTOR 0
135#define IDETAPE_CAPABILITIES_PAGE 0x2a
136
1da177e4 137/*
3c98bf34
BP
138 * Most of our global data which we need to save even as we leave the driver due
139 * to an interrupt or a timer event is stored in the struct defined below.
1da177e4
LT
140 */
141typedef struct ide_tape_obj {
7f3c868b
BZ
142 ide_drive_t *drive;
143 struct ide_driver *driver;
144 struct gendisk *disk;
8fed4368 145 struct device dev;
1da177e4 146
2e8a6f89
BZ
147 /* used by REQ_IDETAPE_{READ,WRITE} requests */
148 struct ide_atapi_pc queued_pc;
394a4c21 149
1da177e4 150 /*
3c98bf34 151 * DSC polling variables.
1da177e4 152 *
3c98bf34
BP
153 * While polling for DSC we use postponed_rq to postpone the current
154 * request so that ide.c will be able to service pending requests on the
155 * other device. Note that at most we will have only one DSC (usually
5bd50dc6 156 * data transfer) request in the device request queue.
1da177e4
LT
157 */
158 struct request *postponed_rq;
159 /* The time in which we started polling for DSC */
160 unsigned long dsc_polling_start;
161 /* Timer used to poll for dsc */
162 struct timer_list dsc_timer;
163 /* Read/Write dsc polling frequency */
54bb2074
BP
164 unsigned long best_dsc_rw_freq;
165 unsigned long dsc_poll_freq;
1da177e4
LT
166 unsigned long dsc_timeout;
167
3c98bf34 168 /* Read position information */
1da177e4
LT
169 u8 partition;
170 /* Current block */
54bb2074 171 unsigned int first_frame;
1da177e4 172
3c98bf34 173 /* Last error information */
1da177e4
LT
174 u8 sense_key, asc, ascq;
175
3c98bf34 176 /* Character device operation */
1da177e4
LT
177 unsigned int minor;
178 /* device name */
179 char name[4];
180 /* Current character device data transfer direction */
54abf37e 181 u8 chrdev_dir;
1da177e4 182
54bb2074
BP
183 /* tape block size, usually 512 or 1024 bytes */
184 unsigned short blk_size;
1da177e4 185 int user_bs_factor;
b6422013 186
1da177e4 187 /* Copy of the tape's Capabilities and Mechanical Page */
b6422013 188 u8 caps[20];
1da177e4
LT
189
190 /*
3c98bf34 191 * Active data transfer request parameters.
1da177e4 192 *
3c98bf34
BP
193 * At most, there is only one ide-tape originated data transfer request
194 * in the device request queue. This allows ide.c to easily service
195 * requests from the other device when we postpone our active request.
1da177e4 196 */
83042b24 197
3c98bf34 198 /* Data buffer size chosen based on the tape's recommendation */
f73850a3 199 int buffer_size;
963da55c
TH
200 /* Staging buffer of buffer_size bytes */
201 void *buf;
202 /* The read/write cursor */
203 void *cur;
204 /* The number of valid bytes in buf */
205 size_t valid;
3c98bf34 206
3c98bf34 207 /* Measures average tape speed */
1da177e4
LT
208 unsigned long avg_time;
209 int avg_size;
210 int avg_speed;
211
1da177e4
LT
212 /* the door is currently locked */
213 int door_locked;
214 /* the tape hardware is write protected */
215 char drv_write_prot;
216 /* the tape is write protected (hardware or opened as read-only) */
217 char write_prot;
1da177e4
LT
218} idetape_tape_t;
219
cf8b8975 220static DEFINE_MUTEX(idetape_ref_mutex);
1da177e4 221
d5dee80a
WD
222static struct class *idetape_sysfs_class;
223
8fed4368 224static void ide_tape_release(struct device *);
08da591e 225
9d01e4cd
BP
226static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES];
227
228static struct ide_tape_obj *ide_tape_get(struct gendisk *disk, bool cdev,
229 unsigned int i)
1da177e4
LT
230{
231 struct ide_tape_obj *tape = NULL;
232
cf8b8975 233 mutex_lock(&idetape_ref_mutex);
9d01e4cd
BP
234
235 if (cdev)
236 tape = idetape_devs[i];
237 else
238 tape = ide_drv_g(disk, ide_tape_obj);
239
08da591e 240 if (tape) {
d3e33ff5 241 if (ide_device_get(tape->drive))
08da591e 242 tape = NULL;
d3e33ff5 243 else
8fed4368 244 get_device(&tape->dev);
08da591e 245 }
9d01e4cd 246
cf8b8975 247 mutex_unlock(&idetape_ref_mutex);
1da177e4
LT
248 return tape;
249}
250
1da177e4
LT
251static void ide_tape_put(struct ide_tape_obj *tape)
252{
d3e33ff5
BZ
253 ide_drive_t *drive = tape->drive;
254
cf8b8975 255 mutex_lock(&idetape_ref_mutex);
8fed4368 256 put_device(&tape->dev);
d3e33ff5 257 ide_device_put(drive);
cf8b8975 258 mutex_unlock(&idetape_ref_mutex);
1da177e4
LT
259}
260
1da177e4 261/*
1b5db434
BP
262 * called on each failed packet command retry to analyze the request sense. We
263 * currently do not utilize this information.
1da177e4 264 */
ae3a8387 265static void idetape_analyze_error(ide_drive_t *drive)
1da177e4
LT
266{
267 idetape_tape_t *tape = drive->driver_data;
5e2040fd 268 struct ide_atapi_pc *pc = drive->failed_pc;
dfb7e621 269 struct request *rq = drive->hwif->rq;
ae3a8387 270 u8 *sense = bio_data(rq->bio);
1da177e4 271
1b5db434
BP
272 tape->sense_key = sense[2] & 0xF;
273 tape->asc = sense[12];
274 tape->ascq = sense[13];
8004a8c9 275
e972d702
BP
276 ide_debug_log(IDE_DBG_FUNC,
277 "cmd: 0x%x, sense key = %x, asc = %x, ascq = %x",
278 rq->cmd[0], tape->sense_key, tape->asc, tape->ascq);
1da177e4 279
077e6dba 280 /* correct remaining bytes to transfer */
21d9c5d2 281 if (pc->flags & PC_FLAG_DMA_ERROR)
077e6dba 282 rq->resid_len = tape->blk_size * get_unaligned_be32(&sense[3]);
1da177e4
LT
283
284 /*
285 * If error was the result of a zero-length read or write command,
286 * with sense key=5, asc=0x22, ascq=0, let it slide. Some drives
287 * (i.e. Seagate STT3401A Travan) don't support 0-length read/writes.
288 */
90699ce2 289 if ((pc->c[0] == READ_6 || pc->c[0] == WRITE_6)
1b5db434
BP
290 /* length == 0 */
291 && pc->c[4] == 0 && pc->c[3] == 0 && pc->c[2] == 0) {
292 if (tape->sense_key == 5) {
1da177e4
LT
293 /* don't report an error, everything's ok */
294 pc->error = 0;
295 /* don't retry read/write */
346331f8 296 pc->flags |= PC_FLAG_ABORT;
1da177e4
LT
297 }
298 }
90699ce2 299 if (pc->c[0] == READ_6 && (sense[2] & 0x80)) {
c152cc1a 300 pc->error = IDE_DRV_ERROR_FILEMARK;
346331f8 301 pc->flags |= PC_FLAG_ABORT;
1da177e4 302 }
90699ce2 303 if (pc->c[0] == WRITE_6) {
1b5db434
BP
304 if ((sense[2] & 0x40) || (tape->sense_key == 0xd
305 && tape->asc == 0x0 && tape->ascq == 0x2)) {
c152cc1a 306 pc->error = IDE_DRV_ERROR_EOD;
346331f8 307 pc->flags |= PC_FLAG_ABORT;
1da177e4
LT
308 }
309 }
90699ce2 310 if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
1b5db434 311 if (tape->sense_key == 8) {
c152cc1a 312 pc->error = IDE_DRV_ERROR_EOD;
346331f8 313 pc->flags |= PC_FLAG_ABORT;
1da177e4 314 }
346331f8 315 if (!(pc->flags & PC_FLAG_ABORT) &&
077e6dba 316 (blk_rq_bytes(rq) - rq->resid_len))
1da177e4
LT
317 pc->retries = IDETAPE_MAX_PC_RETRIES + 1;
318 }
319}
320
b14c7212
BZ
321static void ide_tape_handle_dsc(ide_drive_t *);
322
03a2faae 323static int ide_tape_callback(ide_drive_t *drive, int dsc)
1da177e4
LT
324{
325 idetape_tape_t *tape = drive->driver_data;
2b9efba4 326 struct ide_atapi_pc *pc = drive->pc;
313afea7 327 struct request *rq = drive->hwif->rq;
5985e6ab 328 int uptodate = pc->error ? 0 : 1;
313afea7 329 int err = uptodate ? 0 : IDE_DRV_ERROR_GENERAL;
1da177e4 330
e972d702
BP
331 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, dsc: %d, err: %d", rq->cmd[0],
332 dsc, err);
8004a8c9 333
b14c7212
BZ
334 if (dsc)
335 ide_tape_handle_dsc(drive);
336
5e2040fd
BZ
337 if (drive->failed_pc == pc)
338 drive->failed_pc = NULL;
dd2e9a03 339
5985e6ab
BZ
340 if (pc->c[0] == REQUEST_SENSE) {
341 if (uptodate)
ae3a8387 342 idetape_analyze_error(drive);
5985e6ab
BZ
343 else
344 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE "
345 "itself - Aborting request!\n");
346 } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
077e6dba
BP
347 unsigned int blocks =
348 (blk_rq_bytes(rq) - rq->resid_len) / tape->blk_size;
5985e6ab
BZ
349
350 tape->avg_size += blocks * tape->blk_size;
351
352 if (time_after_eq(jiffies, tape->avg_time + HZ)) {
353 tape->avg_speed = tape->avg_size * HZ /
354 (jiffies - tape->avg_time) / 1024;
355 tape->avg_size = 0;
356 tape->avg_time = jiffies;
357 }
358
359 tape->first_frame += blocks;
5985e6ab 360
313afea7
BZ
361 if (pc->error) {
362 uptodate = 0;
363 err = pc->error;
364 }
1da177e4 365 }
313afea7
BZ
366 rq->errors = err;
367
03a2faae 368 return uptodate;
1da177e4
LT
369}
370
1da177e4 371/*
3c98bf34 372 * Postpone the current request so that ide.c will be able to service requests
b65fac32 373 * from another device on the same port while we are polling for DSC.
1da177e4 374 */
5a04cfa9 375static void idetape_postpone_request(ide_drive_t *drive)
1da177e4
LT
376{
377 idetape_tape_t *tape = drive->driver_data;
e972d702 378 struct request *rq = drive->hwif->rq;
1da177e4 379
e972d702
BP
380 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, dsc_poll_freq: %lu",
381 rq->cmd[0], tape->dsc_poll_freq);
8004a8c9 382
e972d702 383 tape->postponed_rq = rq;
b65fac32 384
54bb2074 385 ide_stall_queue(drive, tape->dsc_poll_freq);
1da177e4
LT
386}
387
74e63e74
BZ
388static void ide_tape_handle_dsc(ide_drive_t *drive)
389{
390 idetape_tape_t *tape = drive->driver_data;
391
392 /* Media access command */
393 tape->dsc_polling_start = jiffies;
394 tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST;
395 tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT;
396 /* Allow ide.c to handle other requests */
397 idetape_postpone_request(drive);
398}
399
1da177e4 400/*
3c98bf34 401 * Packet Command Interface
1da177e4 402 *
2b9efba4 403 * The current Packet Command is available in drive->pc, and will not change
3c98bf34
BP
404 * until we finish handling it. Each packet command is associated with a
405 * callback function that will be called when the command is finished.
1da177e4 406 *
3c98bf34 407 * The handling will be done in three stages:
1da177e4 408 *
b788ee9c 409 * 1. ide_tape_issue_pc will send the packet command to the drive, and will set
aa5d2de7 410 * the interrupt handler to ide_pc_intr.
1da177e4 411 *
aa5d2de7 412 * 2. On each interrupt, ide_pc_intr will be called. This step will be
3c98bf34 413 * repeated until the device signals us that no more interrupts will be issued.
1da177e4 414 *
3c98bf34
BP
415 * 3. ATAPI Tape media access commands have immediate status with a delayed
416 * process. In case of a successful initiation of a media access packet command,
417 * the DSC bit will be set when the actual execution of the command is finished.
418 * Since the tape drive will not issue an interrupt, we have to poll for this
419 * event. In this case, we define the request as "low priority request" by
420 * setting rq_status to IDETAPE_RQ_POSTPONED, set a timer to poll for DSC and
421 * exit the driver.
1da177e4 422 *
3c98bf34
BP
423 * ide.c will then give higher priority to requests which originate from the
424 * other device, until will change rq_status to RQ_ACTIVE.
1da177e4 425 *
3c98bf34 426 * 4. When the packet command is finished, it will be checked for errors.
1da177e4 427 *
3c98bf34
BP
428 * 5. In case an error was found, we queue a request sense packet command in
429 * front of the request queue and retry the operation up to
430 * IDETAPE_MAX_PC_RETRIES times.
1da177e4 431 *
3c98bf34
BP
432 * 6. In case no error was found, or we decided to give up and not to retry
433 * again, the callback function will be called and then we will handle the next
434 * request.
1da177e4 435 */
1da177e4 436
b788ee9c
BZ
437static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
438 struct ide_cmd *cmd,
439 struct ide_atapi_pc *pc)
1da177e4 440{
1da177e4 441 idetape_tape_t *tape = drive->driver_data;
dfb7e621 442 struct request *rq = drive->hwif->rq;
1da177e4 443
5e2040fd
BZ
444 if (drive->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
445 drive->failed_pc = pc;
2b9efba4 446
1da177e4 447 /* Set the current packet command */
2b9efba4 448 drive->pc = pc;
1da177e4
LT
449
450 if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
346331f8 451 (pc->flags & PC_FLAG_ABORT)) {
b3071d19 452
1da177e4 453 /*
3c98bf34
BP
454 * We will "abort" retrying a packet command in case legitimate
455 * error code was received (crossing a filemark, or end of the
456 * media, for example).
1da177e4 457 */
346331f8 458 if (!(pc->flags & PC_FLAG_ABORT)) {
90699ce2 459 if (!(pc->c[0] == TEST_UNIT_READY &&
1da177e4
LT
460 tape->sense_key == 2 && tape->asc == 4 &&
461 (tape->ascq == 1 || tape->ascq == 8))) {
462 printk(KERN_ERR "ide-tape: %s: I/O error, "
463 "pc = %2x, key = %2x, "
464 "asc = %2x, ascq = %2x\n",
465 tape->name, pc->c[0],
466 tape->sense_key, tape->asc,
467 tape->ascq);
468 }
469 /* Giving up */
c152cc1a 470 pc->error = IDE_DRV_ERROR_GENERAL;
1da177e4 471 }
b3071d19 472
5e2040fd 473 drive->failed_pc = NULL;
b14c7212 474 drive->pc_callback(drive, 0);
dfb7e621 475 ide_complete_rq(drive, -EIO, blk_rq_bytes(rq));
92f5daff 476 return ide_stopped;
1da177e4 477 }
e972d702
BP
478 ide_debug_log(IDE_DBG_SENSE, "retry #%d, cmd: 0x%02x", pc->retries,
479 pc->c[0]);
1da177e4
LT
480
481 pc->retries++;
1da177e4 482
b788ee9c 483 return ide_issue_pc(drive, cmd);
1da177e4
LT
484}
485
3c98bf34 486/* A mode sense command is used to "sense" tape parameters. */
d236d74c 487static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
1da177e4 488{
7bf7420a 489 ide_init_pc(pc);
90699ce2 490 pc->c[0] = MODE_SENSE;
1da177e4 491 if (page_code != IDETAPE_BLOCK_DESCRIPTOR)
3c98bf34
BP
492 /* DBD = 1 - Don't return block descriptors */
493 pc->c[1] = 8;
1da177e4
LT
494 pc->c[2] = page_code;
495 /*
496 * Changed pc->c[3] to 0 (255 will at best return unused info).
497 *
498 * For SCSI this byte is defined as subpage instead of high byte
499 * of length and some IDE drives seem to interpret it this way
500 * and return an error when 255 is used.
501 */
502 pc->c[3] = 0;
3c98bf34
BP
503 /* We will just discard data in that case */
504 pc->c[4] = 255;
1da177e4 505 if (page_code == IDETAPE_BLOCK_DESCRIPTOR)
d236d74c 506 pc->req_xfer = 12;
1da177e4 507 else if (page_code == IDETAPE_CAPABILITIES_PAGE)
d236d74c 508 pc->req_xfer = 24;
1da177e4 509 else
d236d74c 510 pc->req_xfer = 50;
1da177e4
LT
511}
512
5a04cfa9 513static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
1da177e4 514{
b73c7ee2 515 ide_hwif_t *hwif = drive->hwif;
1da177e4 516 idetape_tape_t *tape = drive->driver_data;
2b9efba4 517 struct ide_atapi_pc *pc = drive->pc;
22c525b9 518 u8 stat;
1da177e4 519
374e042c 520 stat = hwif->tp_ops->read_status(hwif);
c47137a9 521
3a7d2484
BZ
522 if (stat & ATA_DSC) {
523 if (stat & ATA_ERR) {
1da177e4 524 /* Error detected */
90699ce2 525 if (pc->c[0] != TEST_UNIT_READY)
1da177e4
LT
526 printk(KERN_ERR "ide-tape: %s: I/O error, ",
527 tape->name);
528 /* Retry operation */
6b544fcc 529 ide_retry_pc(drive);
258ec411 530 return ide_stopped;
1da177e4
LT
531 }
532 pc->error = 0;
1da177e4 533 } else {
c152cc1a 534 pc->error = IDE_DRV_ERROR_GENERAL;
5e2040fd 535 drive->failed_pc = NULL;
1da177e4 536 }
b14c7212 537 drive->pc_callback(drive, 0);
1da177e4
LT
538 return ide_stopped;
539}
540
cd2abbfe 541static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
0014c75b
BP
542 struct ide_atapi_pc *pc, struct request *rq,
543 u8 opcode)
1da177e4 544{
10c0b343 545 unsigned int length = blk_rq_sectors(rq) / (tape->blk_size >> 9);
0014c75b 546
7bf7420a 547 ide_init_pc(pc);
860ff5ec 548 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
1da177e4 549 pc->c[1] = 1;
19f52a78
BP
550
551 if (blk_rq_bytes(rq) == tape->buffer_size)
5e331095 552 pc->flags |= PC_FLAG_DMA_OK;
1da177e4 553
963da55c 554 if (opcode == READ_6)
cd2abbfe 555 pc->c[0] = READ_6;
963da55c 556 else if (opcode == WRITE_6) {
cd2abbfe
BP
557 pc->c[0] = WRITE_6;
558 pc->flags |= PC_FLAG_WRITING;
cd2abbfe 559 }
0014c75b
BP
560
561 memcpy(rq->cmd, pc->c, 12);
1da177e4
LT
562}
563
1da177e4
LT
564static ide_startstop_t idetape_do_request(ide_drive_t *drive,
565 struct request *rq, sector_t block)
566{
b73c7ee2 567 ide_hwif_t *hwif = drive->hwif;
1da177e4 568 idetape_tape_t *tape = drive->driver_data;
d236d74c 569 struct ide_atapi_pc *pc = NULL;
1da177e4 570 struct request *postponed_rq = tape->postponed_rq;
b788ee9c 571 struct ide_cmd cmd;
22c525b9 572 u8 stat;
1da177e4 573
e972d702
BP
574 ide_debug_log(IDE_DBG_RQ, "cmd: 0x%x, sector: %llu, nr_sectors: %u",
575 rq->cmd[0], (unsigned long long)blk_rq_pos(rq),
576 blk_rq_sectors(rq));
1da177e4 577
2c7eaa43 578 BUG_ON(!(blk_special_request(rq) || blk_sense_request(rq)));
1da177e4 579
3c98bf34 580 /* Retry a failed packet command */
5e2040fd
BZ
581 if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) {
582 pc = drive->failed_pc;
28c7214b
BZ
583 goto out;
584 }
5a04cfa9 585
1da177e4
LT
586 if (postponed_rq != NULL)
587 if (rq != postponed_rq) {
588 printk(KERN_ERR "ide-tape: ide-tape.c bug - "
589 "Two DSC requests were queued\n");
313afea7 590 drive->failed_pc = NULL;
6902a533 591 rq->errors = 0;
f974b196 592 ide_complete_rq(drive, 0, blk_rq_bytes(rq));
1da177e4
LT
593 return ide_stopped;
594 }
1da177e4
LT
595
596 tape->postponed_rq = NULL;
597
598 /*
599 * If the tape is still busy, postpone our request and service
600 * the other device meanwhile.
601 */
374e042c 602 stat = hwif->tp_ops->read_status(hwif);
1da177e4 603
97100fc8
BZ
604 if ((drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) == 0 &&
605 (rq->cmd[13] & REQ_IDETAPE_PC2) == 0)
626542ca 606 drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC;
1da177e4 607
97100fc8 608 if (drive->dev_flags & IDE_DFLAG_POST_RESET) {
626542ca 609 drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC;
97100fc8 610 drive->dev_flags &= ~IDE_DFLAG_POST_RESET;
1da177e4
LT
611 }
612
626542ca
BP
613 if (!(drive->atapi_flags & IDE_AFLAG_IGNORE_DSC) &&
614 !(stat & ATA_DSC)) {
1da177e4
LT
615 if (postponed_rq == NULL) {
616 tape->dsc_polling_start = jiffies;
54bb2074 617 tape->dsc_poll_freq = tape->best_dsc_rw_freq;
1da177e4
LT
618 tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT;
619 } else if (time_after(jiffies, tape->dsc_timeout)) {
620 printk(KERN_ERR "ide-tape: %s: DSC timeout\n",
621 tape->name);
83dd5735 622 if (rq->cmd[13] & REQ_IDETAPE_PC2) {
1da177e4
LT
623 idetape_media_access_finished(drive);
624 return ide_stopped;
625 } else {
626 return ide_do_reset(drive);
627 }
5a04cfa9
BP
628 } else if (time_after(jiffies,
629 tape->dsc_polling_start +
630 IDETAPE_DSC_MA_THRESHOLD))
54bb2074 631 tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW;
1da177e4
LT
632 idetape_postpone_request(drive);
633 return ide_stopped;
626542ca
BP
634 } else
635 drive->atapi_flags &= ~IDE_AFLAG_IGNORE_DSC;
636
83dd5735 637 if (rq->cmd[13] & REQ_IDETAPE_READ) {
2e8a6f89 638 pc = &tape->queued_pc;
0014c75b 639 ide_tape_create_rw_cmd(tape, pc, rq, READ_6);
1da177e4
LT
640 goto out;
641 }
83dd5735 642 if (rq->cmd[13] & REQ_IDETAPE_WRITE) {
2e8a6f89 643 pc = &tape->queued_pc;
0014c75b 644 ide_tape_create_rw_cmd(tape, pc, rq, WRITE_6);
1da177e4
LT
645 goto out;
646 }
83dd5735 647 if (rq->cmd[13] & REQ_IDETAPE_PC1) {
c267cc1c 648 pc = (struct ide_atapi_pc *)rq->special;
83dd5735
BP
649 rq->cmd[13] &= ~(REQ_IDETAPE_PC1);
650 rq->cmd[13] |= REQ_IDETAPE_PC2;
1da177e4
LT
651 goto out;
652 }
83dd5735 653 if (rq->cmd[13] & REQ_IDETAPE_PC2) {
1da177e4
LT
654 idetape_media_access_finished(drive);
655 return ide_stopped;
656 }
657 BUG();
28c7214b 658
f2e3ab52 659out:
6b544fcc
BP
660 /* prepare sense request for this command */
661 ide_prep_sense(drive, rq);
662
b788ee9c
BZ
663 memset(&cmd, 0, sizeof(cmd));
664
665 if (rq_data_dir(rq))
666 cmd.tf_flags |= IDE_TFLAG_WRITE;
667
668 cmd.rq = rq;
669
dfb7e621 670 ide_init_sg_cmd(&cmd, blk_rq_bytes(rq));
5c4be572
TH
671 ide_map_sg(drive, &cmd);
672
b788ee9c 673 return ide_tape_issue_pc(drive, &cmd, pc);
1da177e4
LT
674}
675
1da177e4 676/*
3c98bf34
BP
677 * Write a filemark if write_filemark=1. Flush the device buffers without
678 * writing a filemark otherwise.
1da177e4 679 */
5a04cfa9 680static void idetape_create_write_filemark_cmd(ide_drive_t *drive,
d236d74c 681 struct ide_atapi_pc *pc, int write_filemark)
1da177e4 682{
7bf7420a 683 ide_init_pc(pc);
90699ce2 684 pc->c[0] = WRITE_FILEMARKS;
1da177e4 685 pc->c[4] = write_filemark;
346331f8 686 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1da177e4
LT
687}
688
1da177e4
LT
689static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
690{
691 idetape_tape_t *tape = drive->driver_data;
2ac07d92 692 struct gendisk *disk = tape->disk;
1da177e4
LT
693 int load_attempted = 0;
694
3c98bf34 695 /* Wait for the tape to become ready */
49d8078a 696 set_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT), &drive->atapi_flags);
1da177e4
LT
697 timeout += jiffies;
698 while (time_before(jiffies, timeout)) {
de699ad5 699 if (ide_do_test_unit_ready(drive, disk) == 0)
1da177e4
LT
700 return 0;
701 if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2)
3c98bf34
BP
702 || (tape->asc == 0x3A)) {
703 /* no media */
1da177e4
LT
704 if (load_attempted)
705 return -ENOMEDIUM;
0c8a6c7a 706 ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK);
1da177e4
LT
707 load_attempted = 1;
708 /* not about to be ready */
709 } else if (!(tape->sense_key == 2 && tape->asc == 4 &&
710 (tape->ascq == 1 || tape->ascq == 8)))
711 return -EIO;
80ce45fd 712 msleep(100);
1da177e4
LT
713 }
714 return -EIO;
715}
716
5a04cfa9 717static int idetape_flush_tape_buffers(ide_drive_t *drive)
1da177e4 718{
2ac07d92 719 struct ide_tape_obj *tape = drive->driver_data;
d236d74c 720 struct ide_atapi_pc pc;
1da177e4
LT
721 int rc;
722
723 idetape_create_write_filemark_cmd(drive, &pc, 0);
b13345f3 724 rc = ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0);
5a04cfa9 725 if (rc)
1da177e4
LT
726 return rc;
727 idetape_wait_ready(drive, 60 * 5 * HZ);
728 return 0;
729}
730
55ce3a12 731static int ide_tape_read_position(ide_drive_t *drive)
1da177e4
LT
732{
733 idetape_tape_t *tape = drive->driver_data;
d236d74c 734 struct ide_atapi_pc pc;
55ce3a12 735 u8 buf[20];
1da177e4 736
e972d702 737 ide_debug_log(IDE_DBG_FUNC, "enter");
1da177e4 738
55ce3a12
BP
739 /* prep cmd */
740 ide_init_pc(&pc);
741 pc.c[0] = READ_POSITION;
742 pc.req_xfer = 20;
743
744 if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer))
1da177e4 745 return -1;
55ce3a12
BP
746
747 if (!pc.error) {
e972d702 748 ide_debug_log(IDE_DBG_FUNC, "BOP - %s",
55ce3a12 749 (buf[0] & 0x80) ? "Yes" : "No");
e972d702 750 ide_debug_log(IDE_DBG_FUNC, "EOP - %s",
55ce3a12
BP
751 (buf[0] & 0x40) ? "Yes" : "No");
752
753 if (buf[0] & 0x4) {
754 printk(KERN_INFO "ide-tape: Block location is unknown"
755 "to the tape\n");
8dcce408
BZ
756 clear_bit(ilog2(IDE_AFLAG_ADDRESS_VALID),
757 &drive->atapi_flags);
55ce3a12
BP
758 return -1;
759 } else {
e972d702
BP
760 ide_debug_log(IDE_DBG_FUNC, "Block Location: %u",
761 be32_to_cpup((__be32 *)&buf[4]));
55ce3a12
BP
762
763 tape->partition = buf[1];
764 tape->first_frame = be32_to_cpup((__be32 *)&buf[4]);
8dcce408
BZ
765 set_bit(ilog2(IDE_AFLAG_ADDRESS_VALID),
766 &drive->atapi_flags);
55ce3a12
BP
767 }
768 }
769
770 return tape->first_frame;
1da177e4
LT
771}
772
d236d74c
BP
773static void idetape_create_locate_cmd(ide_drive_t *drive,
774 struct ide_atapi_pc *pc,
5a04cfa9 775 unsigned int block, u8 partition, int skip)
1da177e4 776{
7bf7420a 777 ide_init_pc(pc);
90699ce2 778 pc->c[0] = POSITION_TO_ELEMENT;
1da177e4 779 pc->c[1] = 2;
860ff5ec 780 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]);
1da177e4 781 pc->c[8] = partition;
346331f8 782 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1da177e4
LT
783}
784
ec0fdb01 785static void __ide_tape_discard_merge_buffer(ide_drive_t *drive)
1da177e4
LT
786{
787 idetape_tape_t *tape = drive->driver_data;
1da177e4 788
54abf37e 789 if (tape->chrdev_dir != IDETAPE_DIR_READ)
9798630a 790 return;
1da177e4 791
49d8078a 792 clear_bit(ilog2(IDE_AFLAG_FILEMARK), &drive->atapi_flags);
963da55c
TH
793 tape->valid = 0;
794 if (tape->buf != NULL) {
795 kfree(tape->buf);
796 tape->buf = NULL;
1da177e4
LT
797 }
798
54abf37e 799 tape->chrdev_dir = IDETAPE_DIR_NONE;
1da177e4
LT
800}
801
802/*
3c98bf34
BP
803 * Position the tape to the requested block using the LOCATE packet command.
804 * A READ POSITION command is then issued to check where we are positioned. Like
805 * all higher level operations, we queue the commands at the tail of the request
806 * queue and wait for their completion.
1da177e4 807 */
5a04cfa9
BP
808static int idetape_position_tape(ide_drive_t *drive, unsigned int block,
809 u8 partition, int skip)
1da177e4
LT
810{
811 idetape_tape_t *tape = drive->driver_data;
2ac07d92 812 struct gendisk *disk = tape->disk;
55ce3a12 813 int ret;
d236d74c 814 struct ide_atapi_pc pc;
1da177e4 815
54abf37e 816 if (tape->chrdev_dir == IDETAPE_DIR_READ)
ec0fdb01 817 __ide_tape_discard_merge_buffer(drive);
1da177e4
LT
818 idetape_wait_ready(drive, 60 * 5 * HZ);
819 idetape_create_locate_cmd(drive, &pc, block, partition, skip);
55ce3a12
BP
820 ret = ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
821 if (ret)
822 return ret;
1da177e4 823
55ce3a12
BP
824 ret = ide_tape_read_position(drive);
825 if (ret < 0)
826 return ret;
827 return 0;
1da177e4
LT
828}
829
ec0fdb01 830static void ide_tape_discard_merge_buffer(ide_drive_t *drive,
5a04cfa9 831 int restore_position)
1da177e4
LT
832{
833 idetape_tape_t *tape = drive->driver_data;
1da177e4
LT
834 int seek, position;
835
ec0fdb01 836 __ide_tape_discard_merge_buffer(drive);
1da177e4 837 if (restore_position) {
55ce3a12 838 position = ide_tape_read_position(drive);
9798630a 839 seek = position > 0 ? position : 0;
1da177e4 840 if (idetape_position_tape(drive, seek, 0, 0)) {
5a04cfa9 841 printk(KERN_INFO "ide-tape: %s: position_tape failed in"
ec0fdb01 842 " %s\n", tape->name, __func__);
1da177e4
LT
843 return;
844 }
845 }
846}
847
848/*
3c98bf34
BP
849 * Generate a read/write request for the block device interface and wait for it
850 * to be serviced.
1da177e4 851 */
6bb11dd1 852static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size)
1da177e4
LT
853{
854 idetape_tape_t *tape = drive->driver_data;
64ea1b4a 855 struct request *rq;
21d9c5d2 856 int ret;
1da177e4 857
e972d702
BP
858 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, size: %d", cmd, size);
859
21d9c5d2 860 BUG_ON(cmd != REQ_IDETAPE_READ && cmd != REQ_IDETAPE_WRITE);
6bb11dd1 861 BUG_ON(size < 0 || size % tape->blk_size);
8004a8c9 862
64ea1b4a
FT
863 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
864 rq->cmd_type = REQ_TYPE_SPECIAL;
83dd5735 865 rq->cmd[13] = cmd;
64ea1b4a 866 rq->rq_disk = tape->disk;
c9059598 867 rq->__sector = tape->first_frame;
21d9c5d2
TH
868
869 if (size) {
963da55c 870 ret = blk_rq_map_kern(drive->queue, rq, tape->buf, size,
21d9c5d2
TH
871 __GFP_WAIT);
872 if (ret)
873 goto out_put;
874 }
875
64ea1b4a
FT
876 blk_execute_rq(drive->queue, tape->disk, rq, 0);
877
963da55c 878 /* calculate the number of transferred bytes and update buffer state */
c3a4d78c 879 size -= rq->resid_len;
963da55c 880 tape->cur = tape->buf;
21d9c5d2 881 if (cmd == REQ_IDETAPE_READ)
963da55c
TH
882 tape->valid = size;
883 else
884 tape->valid = 0;
1da177e4 885
21d9c5d2
TH
886 ret = size;
887 if (rq->errors == IDE_DRV_ERROR_GENERAL)
888 ret = -EIO;
21d9c5d2
TH
889out_put:
890 blk_put_request(rq);
64ea1b4a 891 return ret;
1da177e4
LT
892}
893
d236d74c 894static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
1da177e4 895{
7bf7420a 896 ide_init_pc(pc);
90699ce2 897 pc->c[0] = INQUIRY;
5a04cfa9 898 pc->c[4] = 254;
d236d74c 899 pc->req_xfer = 254;
1da177e4
LT
900}
901
d236d74c
BP
902static void idetape_create_rewind_cmd(ide_drive_t *drive,
903 struct ide_atapi_pc *pc)
1da177e4 904{
7bf7420a 905 ide_init_pc(pc);
90699ce2 906 pc->c[0] = REZERO_UNIT;
346331f8 907 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1da177e4
LT
908}
909
d236d74c 910static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
1da177e4 911{
7bf7420a 912 ide_init_pc(pc);
90699ce2 913 pc->c[0] = ERASE;
1da177e4 914 pc->c[1] = 1;
346331f8 915 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1da177e4
LT
916}
917
d236d74c 918static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
1da177e4 919{
7bf7420a 920 ide_init_pc(pc);
90699ce2 921 pc->c[0] = SPACE;
860ff5ec 922 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]);
1da177e4 923 pc->c[1] = cmd;
346331f8 924 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1da177e4
LT
925}
926
d9df937a 927static void ide_tape_flush_merge_buffer(ide_drive_t *drive)
1da177e4
LT
928{
929 idetape_tape_t *tape = drive->driver_data;
55a5d291 930
54abf37e 931 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) {
077e3bdb 932 printk(KERN_ERR "ide-tape: bug: Trying to empty merge buffer"
5a04cfa9 933 " but we are not writing.\n");
1da177e4
LT
934 return;
935 }
963da55c 936 if (tape->buf) {
6bb11dd1
TH
937 size_t aligned = roundup(tape->valid, tape->blk_size);
938
939 memset(tape->cur, 0, aligned - tape->valid);
07bd9686 940 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, aligned);
963da55c
TH
941 kfree(tape->buf);
942 tape->buf = NULL;
1da177e4 943 }
54abf37e 944 tape->chrdev_dir = IDETAPE_DIR_NONE;
1da177e4
LT
945}
946
88f1b941 947static int idetape_init_rw(ide_drive_t *drive, int dir)
1da177e4
LT
948{
949 idetape_tape_t *tape = drive->driver_data;
88f1b941 950 int rc;
1da177e4 951
88f1b941 952 BUG_ON(dir != IDETAPE_DIR_READ && dir != IDETAPE_DIR_WRITE);
1da177e4 953
88f1b941
TH
954 if (tape->chrdev_dir == dir)
955 return 0;
956
957 if (tape->chrdev_dir == IDETAPE_DIR_READ)
958 ide_tape_discard_merge_buffer(drive, 1);
959 else if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
960 ide_tape_flush_merge_buffer(drive);
961 idetape_flush_tape_buffers(drive);
962 }
963
964 if (tape->buf || tape->valid) {
965 printk(KERN_ERR "ide-tape: valid should be 0 now\n");
966 tape->valid = 0;
967 }
968
969 tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
970 if (!tape->buf)
971 return -ENOMEM;
972 tape->chrdev_dir = dir;
973 tape->cur = tape->buf;
974
975 /*
976 * Issue a 0 rw command to ensure that DSC handshake is
977 * switched from completion mode to buffer available mode. No
978 * point in issuing this if DSC overlap isn't supported, some
979 * drives (Seagate STT3401A) will return an error.
980 */
981 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
982 int cmd = dir == IDETAPE_DIR_READ ? REQ_IDETAPE_READ
983 : REQ_IDETAPE_WRITE;
984
985 rc = idetape_queue_rw_tail(drive, cmd, 0);
986 if (rc < 0) {
987 kfree(tape->buf);
988 tape->buf = NULL;
989 tape->chrdev_dir = IDETAPE_DIR_NONE;
990 return rc;
1da177e4
LT
991 }
992 }
5e69bd95 993
1da177e4
LT
994 return 0;
995}
996
5a04cfa9 997static void idetape_pad_zeros(ide_drive_t *drive, int bcount)
1da177e4
LT
998{
999 idetape_tape_t *tape = drive->driver_data;
963da55c
TH
1000
1001 memset(tape->buf, 0, tape->buffer_size);
3c98bf34 1002
1da177e4 1003 while (bcount) {
963da55c 1004 unsigned int count = min(tape->buffer_size, bcount);
1da177e4 1005
6bb11dd1 1006 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, count);
1da177e4 1007 bcount -= count;
1da177e4
LT
1008 }
1009}
1010
1da177e4 1011/*
3c98bf34
BP
1012 * Rewinds the tape to the Beginning Of the current Partition (BOP). We
1013 * currently support only one partition.
1014 */
5a04cfa9 1015static int idetape_rewind_tape(ide_drive_t *drive)
1da177e4 1016{
2ac07d92
BZ
1017 struct ide_tape_obj *tape = drive->driver_data;
1018 struct gendisk *disk = tape->disk;
d236d74c 1019 struct ide_atapi_pc pc;
55ce3a12 1020 int ret;
8004a8c9 1021
e972d702 1022 ide_debug_log(IDE_DBG_FUNC, "enter");
8004a8c9 1023
1da177e4 1024 idetape_create_rewind_cmd(drive, &pc);
55ce3a12
BP
1025 ret = ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
1026 if (ret)
1027 return ret;
1da177e4 1028
55ce3a12
BP
1029 ret = ide_tape_read_position(drive);
1030 if (ret < 0)
1031 return ret;
1da177e4
LT
1032 return 0;
1033}
1034
3c98bf34 1035/* mtio.h compatible commands should be issued to the chrdev interface. */
5a04cfa9
BP
1036static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd,
1037 unsigned long arg)
1da177e4
LT
1038{
1039 idetape_tape_t *tape = drive->driver_data;
1da177e4
LT
1040 void __user *argp = (void __user *)arg;
1041
d59823fa
BP
1042 struct idetape_config {
1043 int dsc_rw_frequency;
1044 int dsc_media_access_frequency;
1045 int nr_stages;
1046 } config;
1047
e972d702 1048 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%04x", cmd);
8004a8c9 1049
1da177e4 1050 switch (cmd) {
5a04cfa9
BP
1051 case 0x0340:
1052 if (copy_from_user(&config, argp, sizeof(config)))
1053 return -EFAULT;
1054 tape->best_dsc_rw_freq = config.dsc_rw_frequency;
5a04cfa9
BP
1055 break;
1056 case 0x0350:
2fc2111c 1057 memset(&config, 0, sizeof(config));
5a04cfa9 1058 config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq;
83042b24 1059 config.nr_stages = 1;
5a04cfa9
BP
1060 if (copy_to_user(argp, &config, sizeof(config)))
1061 return -EFAULT;
1062 break;
1063 default:
1064 return -EIO;
1da177e4
LT
1065 }
1066 return 0;
1067}
1068
5a04cfa9
BP
1069static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1070 int mt_count)
1da177e4
LT
1071{
1072 idetape_tape_t *tape = drive->driver_data;
2ac07d92 1073 struct gendisk *disk = tape->disk;
d236d74c 1074 struct ide_atapi_pc pc;
5a04cfa9 1075 int retval, count = 0;
b6422013 1076 int sprev = !!(tape->caps[4] & 0x20);
1da177e4 1077
e972d702
BP
1078
1079 ide_debug_log(IDE_DBG_FUNC, "mt_op: %d, mt_count: %d", mt_op, mt_count);
1080
1da177e4
LT
1081 if (mt_count == 0)
1082 return 0;
1083 if (MTBSF == mt_op || MTBSFM == mt_op) {
b6422013 1084 if (!sprev)
1da177e4 1085 return -EIO;
5a04cfa9 1086 mt_count = -mt_count;
1da177e4
LT
1087 }
1088
54abf37e 1089 if (tape->chrdev_dir == IDETAPE_DIR_READ) {
963da55c 1090 tape->valid = 0;
49d8078a
BP
1091 if (test_and_clear_bit(ilog2(IDE_AFLAG_FILEMARK),
1092 &drive->atapi_flags))
1da177e4 1093 ++count;
ec0fdb01 1094 ide_tape_discard_merge_buffer(drive, 0);
1da177e4
LT
1095 }
1096
1da177e4 1097 switch (mt_op) {
5a04cfa9
BP
1098 case MTFSF:
1099 case MTBSF:
1100 idetape_create_space_cmd(&pc, mt_count - count,
1101 IDETAPE_SPACE_OVER_FILEMARK);
b13345f3 1102 return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
5a04cfa9
BP
1103 case MTFSFM:
1104 case MTBSFM:
1105 if (!sprev)
1106 return -EIO;
1107 retval = idetape_space_over_filemarks(drive, MTFSF,
1108 mt_count - count);
1109 if (retval)
1110 return retval;
1111 count = (MTBSFM == mt_op ? 1 : -1);
1112 return idetape_space_over_filemarks(drive, MTFSF, count);
1113 default:
1114 printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",
1115 mt_op);
1116 return -EIO;
1da177e4
LT
1117 }
1118}
1119
1da177e4 1120/*
3c98bf34 1121 * Our character device read / write functions.
1da177e4 1122 *
3c98bf34
BP
1123 * The tape is optimized to maximize throughput when it is transferring an
1124 * integral number of the "continuous transfer limit", which is a parameter of
1125 * the specific tape (26kB on my particular tape, 32kB for Onstream).
1da177e4 1126 *
3c98bf34
BP
1127 * As of version 1.3 of the driver, the character device provides an abstract
1128 * continuous view of the media - any mix of block sizes (even 1 byte) on the
1129 * same backup/restore procedure is supported. The driver will internally
1130 * convert the requests to the recommended transfer unit, so that an unmatch
1131 * between the user's block size to the recommended size will only result in a
1132 * (slightly) increased driver overhead, but will no longer hit performance.
1133 * This is not applicable to Onstream.
1da177e4 1134 */
5a04cfa9
BP
1135static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
1136 size_t count, loff_t *ppos)
1da177e4 1137{
5aeddf90 1138 struct ide_tape_obj *tape = file->private_data;
1da177e4 1139 ide_drive_t *drive = tape->drive;
07bd9686 1140 size_t done = 0;
dcd96379 1141 ssize_t ret = 0;
07bd9686 1142 int rc;
1da177e4 1143
e972d702 1144 ide_debug_log(IDE_DBG_FUNC, "count %Zd", count);
1da177e4 1145
54abf37e 1146 if (tape->chrdev_dir != IDETAPE_DIR_READ) {
49d8078a 1147 if (test_bit(ilog2(IDE_AFLAG_DETECT_BS), &drive->atapi_flags))
54bb2074
BP
1148 if (count > tape->blk_size &&
1149 (count % tape->blk_size) == 0)
1150 tape->user_bs_factor = count / tape->blk_size;
1da177e4 1151 }
07bd9686 1152
88f1b941 1153 rc = idetape_init_rw(drive, IDETAPE_DIR_READ);
8d06bfad 1154 if (rc < 0)
1da177e4 1155 return rc;
07bd9686
TH
1156
1157 while (done < count) {
1158 size_t todo;
1159
1160 /* refill if staging buffer is empty */
1161 if (!tape->valid) {
1162 /* If we are at a filemark, nothing more to read */
49d8078a
BP
1163 if (test_bit(ilog2(IDE_AFLAG_FILEMARK),
1164 &drive->atapi_flags))
07bd9686
TH
1165 break;
1166 /* read */
1167 if (idetape_queue_rw_tail(drive, REQ_IDETAPE_READ,
1168 tape->buffer_size) <= 0)
1169 break;
1170 }
1171
1172 /* copy out */
1173 todo = min_t(size_t, count - done, tape->valid);
1174 if (copy_to_user(buf + done, tape->cur, todo))
dcd96379 1175 ret = -EFAULT;
07bd9686
TH
1176
1177 tape->cur += todo;
1178 tape->valid -= todo;
1179 done += todo;
1da177e4 1180 }
07bd9686 1181
49d8078a 1182 if (!done && test_bit(ilog2(IDE_AFLAG_FILEMARK), &drive->atapi_flags)) {
1da177e4
LT
1183 idetape_space_over_filemarks(drive, MTFSF, 1);
1184 return 0;
1185 }
dcd96379 1186
07bd9686 1187 return ret ? ret : done;
1da177e4
LT
1188}
1189
5a04cfa9 1190static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1da177e4
LT
1191 size_t count, loff_t *ppos)
1192{
5aeddf90 1193 struct ide_tape_obj *tape = file->private_data;
1da177e4 1194 ide_drive_t *drive = tape->drive;
07bd9686 1195 size_t done = 0;
dcd96379 1196 ssize_t ret = 0;
88f1b941 1197 int rc;
1da177e4
LT
1198
1199 /* The drive is write protected. */
1200 if (tape->write_prot)
1201 return -EACCES;
1202
e972d702 1203 ide_debug_log(IDE_DBG_FUNC, "count %Zd", count);
1da177e4
LT
1204
1205 /* Initialize write operation */
88f1b941
TH
1206 rc = idetape_init_rw(drive, IDETAPE_DIR_WRITE);
1207 if (rc < 0)
1208 return rc;
07bd9686
TH
1209
1210 while (done < count) {
1211 size_t todo;
1212
1213 /* flush if staging buffer is full */
1214 if (tape->valid == tape->buffer_size &&
1215 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE,
1216 tape->buffer_size) <= 0)
1217 return rc;
1218
1219 /* copy in */
1220 todo = min_t(size_t, count - done,
1221 tape->buffer_size - tape->valid);
1222 if (copy_from_user(tape->cur, buf + done, todo))
dcd96379 1223 ret = -EFAULT;
07bd9686
TH
1224
1225 tape->cur += todo;
1226 tape->valid += todo;
1227 done += todo;
1da177e4 1228 }
07bd9686
TH
1229
1230 return ret ? ret : done;
1da177e4
LT
1231}
1232
5a04cfa9 1233static int idetape_write_filemark(ide_drive_t *drive)
1da177e4 1234{
2ac07d92 1235 struct ide_tape_obj *tape = drive->driver_data;
d236d74c 1236 struct ide_atapi_pc pc;
1da177e4
LT
1237
1238 /* Write a filemark */
1239 idetape_create_write_filemark_cmd(drive, &pc, 1);
b13345f3 1240 if (ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0)) {
1da177e4
LT
1241 printk(KERN_ERR "ide-tape: Couldn't write a filemark\n");
1242 return -EIO;
1243 }
1244 return 0;
1245}
1246
1247/*
d99c9da2
BP
1248 * Called from idetape_chrdev_ioctl when the general mtio MTIOCTOP ioctl is
1249 * requested.
1da177e4 1250 *
d99c9da2
BP
1251 * Note: MTBSF and MTBSFM are not supported when the tape doesn't support
1252 * spacing over filemarks in the reverse direction. In this case, MTFSFM is also
5bd50dc6 1253 * usually not supported.
1da177e4 1254 *
d99c9da2 1255 * The following commands are currently not supported:
1da177e4 1256 *
d99c9da2
BP
1257 * MTFSS, MTBSS, MTWSM, MTSETDENSITY, MTSETDRVBUFFER, MT_ST_BOOLEANS,
1258 * MT_ST_WRITE_THRESHOLD.
1da177e4 1259 */
d99c9da2 1260static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
1da177e4
LT
1261{
1262 idetape_tape_t *tape = drive->driver_data;
2ac07d92 1263 struct gendisk *disk = tape->disk;
d236d74c 1264 struct ide_atapi_pc pc;
5a04cfa9 1265 int i, retval;
1da177e4 1266
e972d702
BP
1267 ide_debug_log(IDE_DBG_FUNC, "MTIOCTOP ioctl: mt_op: %d, mt_count: %d",
1268 mt_op, mt_count);
5a04cfa9 1269
1da177e4 1270 switch (mt_op) {
5a04cfa9
BP
1271 case MTFSF:
1272 case MTFSFM:
1273 case MTBSF:
1274 case MTBSFM:
1275 if (!mt_count)
1276 return 0;
1277 return idetape_space_over_filemarks(drive, mt_op, mt_count);
1278 default:
1279 break;
1da177e4 1280 }
5a04cfa9 1281
1da177e4 1282 switch (mt_op) {
5a04cfa9
BP
1283 case MTWEOF:
1284 if (tape->write_prot)
1285 return -EACCES;
ec0fdb01 1286 ide_tape_discard_merge_buffer(drive, 1);
5a04cfa9
BP
1287 for (i = 0; i < mt_count; i++) {
1288 retval = idetape_write_filemark(drive);
1289 if (retval)
1290 return retval;
1291 }
1292 return 0;
1293 case MTREW:
ec0fdb01 1294 ide_tape_discard_merge_buffer(drive, 0);
5a04cfa9
BP
1295 if (idetape_rewind_tape(drive))
1296 return -EIO;
1297 return 0;
1298 case MTLOAD:
ec0fdb01 1299 ide_tape_discard_merge_buffer(drive, 0);
0c8a6c7a 1300 return ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK);
5a04cfa9
BP
1301 case MTUNLOAD:
1302 case MTOFFL:
1303 /*
1304 * If door is locked, attempt to unlock before
1305 * attempting to eject.
1306 */
1307 if (tape->door_locked) {
0578042d 1308 if (!ide_set_media_lock(drive, disk, 0))
385a4b87 1309 tape->door_locked = DOOR_UNLOCKED;
5a04cfa9 1310 }
ec0fdb01 1311 ide_tape_discard_merge_buffer(drive, 0);
0c8a6c7a 1312 retval = ide_do_start_stop(drive, disk, !IDETAPE_LU_LOAD_MASK);
5a04cfa9 1313 if (!retval)
49d8078a
BP
1314 clear_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT),
1315 &drive->atapi_flags);
5a04cfa9
BP
1316 return retval;
1317 case MTNOP:
ec0fdb01 1318 ide_tape_discard_merge_buffer(drive, 0);
5a04cfa9
BP
1319 return idetape_flush_tape_buffers(drive);
1320 case MTRETEN:
ec0fdb01 1321 ide_tape_discard_merge_buffer(drive, 0);
0c8a6c7a 1322 return ide_do_start_stop(drive, disk,
5a04cfa9 1323 IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
5a04cfa9
BP
1324 case MTEOM:
1325 idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD);
b13345f3 1326 return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
5a04cfa9
BP
1327 case MTERASE:
1328 (void)idetape_rewind_tape(drive);
1329 idetape_create_erase_cmd(&pc);
b13345f3 1330 return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
5a04cfa9
BP
1331 case MTSETBLK:
1332 if (mt_count) {
1333 if (mt_count < tape->blk_size ||
1334 mt_count % tape->blk_size)
1da177e4 1335 return -EIO;
5a04cfa9 1336 tape->user_bs_factor = mt_count / tape->blk_size;
49d8078a
BP
1337 clear_bit(ilog2(IDE_AFLAG_DETECT_BS),
1338 &drive->atapi_flags);
5a04cfa9 1339 } else
49d8078a
BP
1340 set_bit(ilog2(IDE_AFLAG_DETECT_BS),
1341 &drive->atapi_flags);
5a04cfa9
BP
1342 return 0;
1343 case MTSEEK:
ec0fdb01 1344 ide_tape_discard_merge_buffer(drive, 0);
5a04cfa9
BP
1345 return idetape_position_tape(drive,
1346 mt_count * tape->user_bs_factor, tape->partition, 0);
1347 case MTSETPART:
ec0fdb01 1348 ide_tape_discard_merge_buffer(drive, 0);
5a04cfa9
BP
1349 return idetape_position_tape(drive, 0, mt_count, 0);
1350 case MTFSR:
1351 case MTBSR:
1352 case MTLOCK:
0578042d 1353 retval = ide_set_media_lock(drive, disk, 1);
5a04cfa9 1354 if (retval)
1da177e4 1355 return retval;
5a04cfa9
BP
1356 tape->door_locked = DOOR_EXPLICITLY_LOCKED;
1357 return 0;
1358 case MTUNLOCK:
0578042d 1359 retval = ide_set_media_lock(drive, disk, 0);
5a04cfa9
BP
1360 if (retval)
1361 return retval;
1362 tape->door_locked = DOOR_UNLOCKED;
1363 return 0;
1364 default:
1365 printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",
1366 mt_op);
1367 return -EIO;
1da177e4
LT
1368 }
1369}
1370
1371/*
d99c9da2
BP
1372 * Our character device ioctls. General mtio.h magnetic io commands are
1373 * supported here, and not in the corresponding block interface. Our own
1374 * ide-tape ioctls are supported on both interfaces.
1da177e4 1375 */
d99c9da2
BP
1376static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
1377 unsigned int cmd, unsigned long arg)
1da177e4 1378{
5aeddf90 1379 struct ide_tape_obj *tape = file->private_data;
1da177e4
LT
1380 ide_drive_t *drive = tape->drive;
1381 struct mtop mtop;
1382 struct mtget mtget;
1383 struct mtpos mtpos;
54bb2074 1384 int block_offset = 0, position = tape->first_frame;
1da177e4
LT
1385 void __user *argp = (void __user *)arg;
1386
e972d702 1387 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x", cmd);
1da177e4 1388
54abf37e 1389 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
d9df937a 1390 ide_tape_flush_merge_buffer(drive);
1da177e4
LT
1391 idetape_flush_tape_buffers(drive);
1392 }
1393 if (cmd == MTIOCGET || cmd == MTIOCPOS) {
963da55c 1394 block_offset = tape->valid /
54bb2074 1395 (tape->blk_size * tape->user_bs_factor);
55ce3a12 1396 position = ide_tape_read_position(drive);
5a04cfa9 1397 if (position < 0)
1da177e4
LT
1398 return -EIO;
1399 }
1400 switch (cmd) {
5a04cfa9
BP
1401 case MTIOCTOP:
1402 if (copy_from_user(&mtop, argp, sizeof(struct mtop)))
1403 return -EFAULT;
1404 return idetape_mtioctop(drive, mtop.mt_op, mtop.mt_count);
1405 case MTIOCGET:
1406 memset(&mtget, 0, sizeof(struct mtget));
1407 mtget.mt_type = MT_ISSCSI2;
1408 mtget.mt_blkno = position / tape->user_bs_factor - block_offset;
1409 mtget.mt_dsreg =
1410 ((tape->blk_size * tape->user_bs_factor)
1411 << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK;
1412
1413 if (tape->drv_write_prot)
1414 mtget.mt_gstat |= GMT_WR_PROT(0xffffffff);
1415
1416 if (copy_to_user(argp, &mtget, sizeof(struct mtget)))
1417 return -EFAULT;
1418 return 0;
1419 case MTIOCPOS:
1420 mtpos.mt_blkno = position / tape->user_bs_factor - block_offset;
1421 if (copy_to_user(argp, &mtpos, sizeof(struct mtpos)))
1422 return -EFAULT;
1423 return 0;
1424 default:
1425 if (tape->chrdev_dir == IDETAPE_DIR_READ)
ec0fdb01 1426 ide_tape_discard_merge_buffer(drive, 1);
5a04cfa9 1427 return idetape_blkdev_ioctl(drive, cmd, arg);
1da177e4
LT
1428 }
1429}
1430
3cffb9ce
BP
1431/*
1432 * Do a mode sense page 0 with block descriptor and if it succeeds set the tape
1433 * block size with the reported value.
1434 */
1435static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
1436{
1437 idetape_tape_t *tape = drive->driver_data;
d236d74c 1438 struct ide_atapi_pc pc;
837272b4 1439 u8 buf[12];
3cffb9ce
BP
1440
1441 idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR);
837272b4 1442 if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) {
3cffb9ce 1443 printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
54bb2074 1444 if (tape->blk_size == 0) {
3cffb9ce
BP
1445 printk(KERN_WARNING "ide-tape: Cannot deal with zero "
1446 "block size, assuming 32k\n");
54bb2074 1447 tape->blk_size = 32768;
3cffb9ce
BP
1448 }
1449 return;
1450 }
837272b4
BP
1451 tape->blk_size = (buf[4 + 5] << 16) +
1452 (buf[4 + 6] << 8) +
1453 buf[4 + 7];
1454 tape->drv_write_prot = (buf[2] & 0x80) >> 7;
e972d702
BP
1455
1456 ide_debug_log(IDE_DBG_FUNC, "blk_size: %d, write_prot: %d",
1457 tape->blk_size, tape->drv_write_prot);
3cffb9ce 1458}
1da177e4 1459
5a04cfa9 1460static int idetape_chrdev_open(struct inode *inode, struct file *filp)
1da177e4
LT
1461{
1462 unsigned int minor = iminor(inode), i = minor & ~0xc0;
1463 ide_drive_t *drive;
1464 idetape_tape_t *tape;
1da177e4
LT
1465 int retval;
1466
8004a8c9
BP
1467 if (i >= MAX_HWIFS * MAX_DRIVES)
1468 return -ENXIO;
1469
04f4ac9d 1470 lock_kernel();
9d01e4cd 1471 tape = ide_tape_get(NULL, true, i);
04f4ac9d
JC
1472 if (!tape) {
1473 unlock_kernel();
8004a8c9 1474 return -ENXIO;
04f4ac9d 1475 }
8004a8c9 1476
e972d702
BP
1477 drive = tape->drive;
1478 filp->private_data = tape;
1479
1480 ide_debug_log(IDE_DBG_FUNC, "enter");
8004a8c9 1481
1da177e4
LT
1482 /*
1483 * We really want to do nonseekable_open(inode, filp); here, but some
1484 * versions of tar incorrectly call lseek on tapes and bail out if that
1485 * fails. So we disallow pread() and pwrite(), but permit lseeks.
1486 */
1487 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE);
1488
1da177e4 1489
49d8078a 1490 if (test_and_set_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags)) {
1da177e4
LT
1491 retval = -EBUSY;
1492 goto out_put_tape;
1493 }
1494
1495 retval = idetape_wait_ready(drive, 60 * HZ);
1496 if (retval) {
49d8078a 1497 clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags);
1da177e4
LT
1498 printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name);
1499 goto out_put_tape;
1500 }
1501
79ca743f 1502 ide_tape_read_position(drive);
49d8078a 1503 if (!test_bit(ilog2(IDE_AFLAG_ADDRESS_VALID), &drive->atapi_flags))
1da177e4
LT
1504 (void)idetape_rewind_tape(drive);
1505
1da177e4 1506 /* Read block size and write protect status from drive. */
3cffb9ce 1507 ide_tape_get_bsize_from_bdesc(drive);
1da177e4
LT
1508
1509 /* Set write protect flag if device is opened as read-only. */
1510 if ((filp->f_flags & O_ACCMODE) == O_RDONLY)
1511 tape->write_prot = 1;
1512 else
1513 tape->write_prot = tape->drv_write_prot;
1514
1515 /* Make sure drive isn't write protected if user wants to write. */
1516 if (tape->write_prot) {
1517 if ((filp->f_flags & O_ACCMODE) == O_WRONLY ||
1518 (filp->f_flags & O_ACCMODE) == O_RDWR) {
49d8078a 1519 clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags);
1da177e4
LT
1520 retval = -EROFS;
1521 goto out_put_tape;
1522 }
1523 }
1524
3c98bf34 1525 /* Lock the tape drive door so user can't eject. */
54abf37e 1526 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
0578042d 1527 if (!ide_set_media_lock(drive, tape->disk, 1)) {
385a4b87
BZ
1528 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED)
1529 tape->door_locked = DOOR_LOCKED;
1da177e4
LT
1530 }
1531 }
04f4ac9d 1532 unlock_kernel();
1da177e4
LT
1533 return 0;
1534
1535out_put_tape:
1536 ide_tape_put(tape);
04f4ac9d 1537 unlock_kernel();
1da177e4
LT
1538 return retval;
1539}
1540
5a04cfa9 1541static void idetape_write_release(ide_drive_t *drive, unsigned int minor)
1da177e4
LT
1542{
1543 idetape_tape_t *tape = drive->driver_data;
1544
d9df937a 1545 ide_tape_flush_merge_buffer(drive);
963da55c
TH
1546 tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
1547 if (tape->buf != NULL) {
54bb2074
BP
1548 idetape_pad_zeros(drive, tape->blk_size *
1549 (tape->user_bs_factor - 1));
963da55c
TH
1550 kfree(tape->buf);
1551 tape->buf = NULL;
1da177e4
LT
1552 }
1553 idetape_write_filemark(drive);
1554 idetape_flush_tape_buffers(drive);
1555 idetape_flush_tape_buffers(drive);
1556}
1557
5a04cfa9 1558static int idetape_chrdev_release(struct inode *inode, struct file *filp)
1da177e4 1559{
5aeddf90 1560 struct ide_tape_obj *tape = filp->private_data;
1da177e4 1561 ide_drive_t *drive = tape->drive;
1da177e4
LT
1562 unsigned int minor = iminor(inode);
1563
1564 lock_kernel();
1565 tape = drive->driver_data;
8004a8c9 1566
e972d702 1567 ide_debug_log(IDE_DBG_FUNC, "enter");
1da177e4 1568
54abf37e 1569 if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
1da177e4 1570 idetape_write_release(drive, minor);
54abf37e 1571 if (tape->chrdev_dir == IDETAPE_DIR_READ) {
1da177e4 1572 if (minor < 128)
ec0fdb01 1573 ide_tape_discard_merge_buffer(drive, 1);
1da177e4 1574 }
f64eee7b 1575
49d8078a
BP
1576 if (minor < 128 && test_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT),
1577 &drive->atapi_flags))
1da177e4 1578 (void) idetape_rewind_tape(drive);
49d8078a 1579
54abf37e 1580 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
1da177e4 1581 if (tape->door_locked == DOOR_LOCKED) {
0578042d 1582 if (!ide_set_media_lock(drive, tape->disk, 0))
385a4b87 1583 tape->door_locked = DOOR_UNLOCKED;
1da177e4
LT
1584 }
1585 }
49d8078a 1586 clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags);
1da177e4
LT
1587 ide_tape_put(tape);
1588 unlock_kernel();
1589 return 0;
1590}
1591
6d29c8f0 1592static void idetape_get_inquiry_results(ide_drive_t *drive)
1da177e4 1593{
1da177e4 1594 idetape_tape_t *tape = drive->driver_data;
d236d74c 1595 struct ide_atapi_pc pc;
41fa9f86 1596 u8 pc_buf[256];
801bd32e 1597 char fw_rev[4], vendor_id[8], product_id[16];
6d29c8f0 1598
1da177e4 1599 idetape_create_inquiry_cmd(&pc);
b13345f3 1600 if (ide_queue_pc_tail(drive, tape->disk, &pc, pc_buf, pc.req_xfer)) {
6d29c8f0
BP
1601 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n",
1602 tape->name);
1da177e4
LT
1603 return;
1604 }
b13345f3
BP
1605 memcpy(vendor_id, &pc_buf[8], 8);
1606 memcpy(product_id, &pc_buf[16], 16);
1607 memcpy(fw_rev, &pc_buf[32], 4);
41f81d54 1608
801bd32e
BP
1609 ide_fixstring(vendor_id, 8, 0);
1610 ide_fixstring(product_id, 16, 0);
1611 ide_fixstring(fw_rev, 4, 0);
41f81d54 1612
801bd32e 1613 printk(KERN_INFO "ide-tape: %s <-> %s: %.8s %.16s rev %.4s\n",
41f81d54 1614 drive->name, tape->name, vendor_id, product_id, fw_rev);
1da177e4
LT
1615}
1616
1617/*
b6422013
BP
1618 * Ask the tape about its various parameters. In particular, we will adjust our
1619 * data transfer buffer size to the recommended value as returned by the tape.
1da177e4 1620 */
5a04cfa9 1621static void idetape_get_mode_sense_results(ide_drive_t *drive)
1da177e4
LT
1622{
1623 idetape_tape_t *tape = drive->driver_data;
d236d74c 1624 struct ide_atapi_pc pc;
b13345f3 1625 u8 buf[24], *caps;
b6422013 1626 u8 speed, max_speed;
47314fa4 1627
1da177e4 1628 idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE);
b13345f3 1629 if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) {
b6422013
BP
1630 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming"
1631 " some default values\n");
54bb2074 1632 tape->blk_size = 512;
b6422013
BP
1633 put_unaligned(52, (u16 *)&tape->caps[12]);
1634 put_unaligned(540, (u16 *)&tape->caps[14]);
1635 put_unaligned(6*52, (u16 *)&tape->caps[16]);
1da177e4
LT
1636 return;
1637 }
b13345f3 1638 caps = buf + 4 + buf[3];
b6422013
BP
1639
1640 /* convert to host order and save for later use */
cd740ab0
HH
1641 speed = be16_to_cpup((__be16 *)&caps[14]);
1642 max_speed = be16_to_cpup((__be16 *)&caps[8]);
1da177e4 1643
cd740ab0
HH
1644 *(u16 *)&caps[8] = max_speed;
1645 *(u16 *)&caps[12] = be16_to_cpup((__be16 *)&caps[12]);
1646 *(u16 *)&caps[14] = speed;
1647 *(u16 *)&caps[16] = be16_to_cpup((__be16 *)&caps[16]);
1da177e4 1648
b6422013
BP
1649 if (!speed) {
1650 printk(KERN_INFO "ide-tape: %s: invalid tape speed "
1651 "(assuming 650KB/sec)\n", drive->name);
cd740ab0 1652 *(u16 *)&caps[14] = 650;
1da177e4 1653 }
b6422013
BP
1654 if (!max_speed) {
1655 printk(KERN_INFO "ide-tape: %s: invalid max_speed "
1656 "(assuming 650KB/sec)\n", drive->name);
cd740ab0 1657 *(u16 *)&caps[8] = 650;
1da177e4
LT
1658 }
1659
b6422013 1660 memcpy(&tape->caps, caps, 20);
0578042d
BZ
1661
1662 /* device lacks locking support according to capabilities page */
1663 if ((caps[6] & 1) == 0)
42619d35 1664 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
0578042d 1665
b6422013 1666 if (caps[7] & 0x02)
54bb2074 1667 tape->blk_size = 512;
b6422013 1668 else if (caps[7] & 0x04)
54bb2074 1669 tape->blk_size = 1024;
1da177e4
LT
1670}
1671
7662d046 1672#ifdef CONFIG_IDE_PROC_FS
8185d5aa
BZ
1673#define ide_tape_devset_get(name, field) \
1674static int get_##name(ide_drive_t *drive) \
1675{ \
1676 idetape_tape_t *tape = drive->driver_data; \
1677 return tape->field; \
1678}
1679
1680#define ide_tape_devset_set(name, field) \
1681static int set_##name(ide_drive_t *drive, int arg) \
1682{ \
1683 idetape_tape_t *tape = drive->driver_data; \
1684 tape->field = arg; \
1685 return 0; \
1686}
1687
92f1f8fd 1688#define ide_tape_devset_rw_field(_name, _field) \
8185d5aa
BZ
1689ide_tape_devset_get(_name, _field) \
1690ide_tape_devset_set(_name, _field) \
92f1f8fd 1691IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name)
8185d5aa 1692
92f1f8fd 1693#define ide_tape_devset_r_field(_name, _field) \
8185d5aa 1694ide_tape_devset_get(_name, _field) \
92f1f8fd 1695IDE_DEVSET(_name, 0, get_##_name, NULL)
8185d5aa
BZ
1696
1697static int mulf_tdsc(ide_drive_t *drive) { return 1000; }
1698static int divf_tdsc(ide_drive_t *drive) { return HZ; }
1699static int divf_buffer(ide_drive_t *drive) { return 2; }
1700static int divf_buffer_size(ide_drive_t *drive) { return 1024; }
1701
97100fc8 1702ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
92f1f8fd 1703
92f1f8fd
EO
1704ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq);
1705
1706ide_tape_devset_r_field(avg_speed, avg_speed);
1707ide_tape_devset_r_field(speed, caps[14]);
1708ide_tape_devset_r_field(buffer, caps[16]);
1709ide_tape_devset_r_field(buffer_size, buffer_size);
1710
1711static const struct ide_proc_devset idetape_settings[] = {
1712 __IDE_PROC_DEVSET(avg_speed, 0, 0xffff, NULL, NULL),
1713 __IDE_PROC_DEVSET(buffer, 0, 0xffff, NULL, divf_buffer),
1714 __IDE_PROC_DEVSET(buffer_size, 0, 0xffff, NULL, divf_buffer_size),
92f1f8fd
EO
1715 __IDE_PROC_DEVSET(dsc_overlap, 0, 1, NULL, NULL),
1716 __IDE_PROC_DEVSET(speed, 0, 0xffff, NULL, NULL),
1717 __IDE_PROC_DEVSET(tdsc, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX,
1718 mulf_tdsc, divf_tdsc),
71bfc7a7 1719 { NULL },
8185d5aa 1720};
7662d046 1721#endif
1da177e4
LT
1722
1723/*
3c98bf34 1724 * The function below is called to:
1da177e4 1725 *
3c98bf34
BP
1726 * 1. Initialize our various state variables.
1727 * 2. Ask the tape for its capabilities.
1728 * 3. Allocate a buffer which will be used for data transfer. The buffer size
1729 * is chosen based on the recommendation which we received in step 2.
1da177e4 1730 *
3c98bf34
BP
1731 * Note that at this point ide.c already assigned us an irq, so that we can
1732 * queue requests here and wait for their completion.
1da177e4 1733 */
5a04cfa9 1734static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
1da177e4 1735{
83042b24 1736 unsigned long t;
1da177e4 1737 int speed;
f73850a3 1738 int buffer_size;
b6422013 1739 u16 *ctl = (u16 *)&tape->caps[12];
1da177e4 1740
e972d702
BP
1741 ide_debug_log(IDE_DBG_FUNC, "minor: %d", minor);
1742
1743 drive->pc_callback = ide_tape_callback;
776bb027 1744
97100fc8
BZ
1745 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
1746
4166c199
BZ
1747 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) {
1748 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n",
1749 tape->name);
97100fc8 1750 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
1da177e4 1751 }
97100fc8 1752
1da177e4 1753 /* Seagate Travan drives do not support DSC overlap. */
4dde4492 1754 if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401"))
97100fc8
BZ
1755 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
1756
1da177e4
LT
1757 tape->minor = minor;
1758 tape->name[0] = 'h';
1759 tape->name[1] = 't';
1760 tape->name[2] = '0' + minor;
54abf37e 1761 tape->chrdev_dir = IDETAPE_DIR_NONE;
4dde4492 1762
1da177e4
LT
1763 idetape_get_inquiry_results(drive);
1764 idetape_get_mode_sense_results(drive);
3cffb9ce 1765 ide_tape_get_bsize_from_bdesc(drive);
1da177e4 1766 tape->user_bs_factor = 1;
f73850a3
BP
1767 tape->buffer_size = *ctl * tape->blk_size;
1768 while (tape->buffer_size > 0xffff) {
1da177e4 1769 printk(KERN_NOTICE "ide-tape: decreasing stage size\n");
b6422013 1770 *ctl /= 2;
f73850a3 1771 tape->buffer_size = *ctl * tape->blk_size;
1da177e4 1772 }
f73850a3 1773 buffer_size = tape->buffer_size;
1da177e4 1774
83042b24 1775 /* select the "best" DSC read/write polling freq */
b6422013 1776 speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]);
1da177e4 1777
f73850a3 1778 t = (IDETAPE_FIFO_THRESHOLD * tape->buffer_size * HZ) / (speed * 1000);
1da177e4
LT
1779
1780 /*
3c98bf34
BP
1781 * Ensure that the number we got makes sense; limit it within
1782 * IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX.
1da177e4 1783 */
a792bd5a
HH
1784 tape->best_dsc_rw_freq = clamp_t(unsigned long, t, IDETAPE_DSC_RW_MIN,
1785 IDETAPE_DSC_RW_MAX);
1da177e4 1786 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, "
83042b24 1787 "%lums tDSC%s\n",
b6422013 1788 drive->name, tape->name, *(u16 *)&tape->caps[14],
f73850a3
BP
1789 (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size,
1790 tape->buffer_size / 1024,
54bb2074 1791 tape->best_dsc_rw_freq * 1000 / HZ,
97100fc8 1792 (drive->dev_flags & IDE_DFLAG_USING_DMA) ? ", DMA" : "");
1da177e4 1793
1e874f44 1794 ide_proc_register_driver(drive, tape->driver);
1da177e4
LT
1795}
1796
4031bbe4 1797static void ide_tape_remove(ide_drive_t *drive)
1da177e4
LT
1798{
1799 idetape_tape_t *tape = drive->driver_data;
1da177e4 1800
7662d046 1801 ide_proc_unregister_driver(drive, tape->driver);
8fed4368 1802 device_del(&tape->dev);
1da177e4
LT
1803 ide_unregister_region(tape->disk);
1804
8fed4368
BZ
1805 mutex_lock(&idetape_ref_mutex);
1806 put_device(&tape->dev);
1807 mutex_unlock(&idetape_ref_mutex);
1da177e4
LT
1808}
1809
8fed4368 1810static void ide_tape_release(struct device *dev)
1da177e4 1811{
8fed4368 1812 struct ide_tape_obj *tape = to_ide_drv(dev, ide_tape_obj);
1da177e4
LT
1813 ide_drive_t *drive = tape->drive;
1814 struct gendisk *g = tape->disk;
1815
963da55c 1816 BUG_ON(tape->valid);
8604affd 1817
97100fc8 1818 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
1da177e4 1819 drive->driver_data = NULL;
dbc1272e 1820 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor));
5a04cfa9
BP
1821 device_destroy(idetape_sysfs_class,
1822 MKDEV(IDETAPE_MAJOR, tape->minor + 128));
1da177e4
LT
1823 idetape_devs[tape->minor] = NULL;
1824 g->private_data = NULL;
1825 put_disk(g);
1826 kfree(tape);
1827}
1828
ecfd80e4 1829#ifdef CONFIG_IDE_PROC_FS
1da177e4
LT
1830static int proc_idetape_read_name
1831 (char *page, char **start, off_t off, int count, int *eof, void *data)
1832{
1833 ide_drive_t *drive = (ide_drive_t *) data;
1834 idetape_tape_t *tape = drive->driver_data;
1835 char *out = page;
1836 int len;
1837
1838 len = sprintf(out, "%s\n", tape->name);
1839 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
1840}
1841
1842static ide_proc_entry_t idetape_proc[] = {
1843 { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL },
1844 { "name", S_IFREG|S_IRUGO, proc_idetape_read_name, NULL },
1845 { NULL, 0, NULL, NULL }
1846};
79cb3803
BZ
1847
1848static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive)
1849{
1850 return idetape_proc;
1851}
1852
1853static const struct ide_proc_devset *ide_tape_proc_devsets(ide_drive_t *drive)
1854{
1855 return idetape_settings;
1856}
1da177e4
LT
1857#endif
1858
4031bbe4 1859static int ide_tape_probe(ide_drive_t *);
1da177e4 1860
7f3c868b 1861static struct ide_driver idetape_driver = {
8604affd 1862 .gen_driver = {
4ef3b8f4 1863 .owner = THIS_MODULE,
8604affd
BZ
1864 .name = "ide-tape",
1865 .bus = &ide_bus_type,
8604affd 1866 },
4031bbe4
RK
1867 .probe = ide_tape_probe,
1868 .remove = ide_tape_remove,
1da177e4 1869 .version = IDETAPE_VERSION,
1da177e4 1870 .do_request = idetape_do_request,
7662d046 1871#ifdef CONFIG_IDE_PROC_FS
79cb3803
BZ
1872 .proc_entries = ide_tape_proc_entries,
1873 .proc_devsets = ide_tape_proc_devsets,
7662d046 1874#endif
1da177e4
LT
1875};
1876
3c98bf34 1877/* Our character device supporting functions, passed to register_chrdev. */
2b8693c0 1878static const struct file_operations idetape_fops = {
1da177e4
LT
1879 .owner = THIS_MODULE,
1880 .read = idetape_chrdev_read,
1881 .write = idetape_chrdev_write,
1882 .ioctl = idetape_chrdev_ioctl,
1883 .open = idetape_chrdev_open,
1884 .release = idetape_chrdev_release,
1885};
1886
a4600f81 1887static int idetape_open(struct block_device *bdev, fmode_t mode)
1da177e4 1888{
9d01e4cd 1889 struct ide_tape_obj *tape = ide_tape_get(bdev->bd_disk, false, 0);
1da177e4 1890
5a04cfa9 1891 if (!tape)
1da177e4
LT
1892 return -ENXIO;
1893
1da177e4
LT
1894 return 0;
1895}
1896
a4600f81 1897static int idetape_release(struct gendisk *disk, fmode_t mode)
1da177e4 1898{
5aeddf90 1899 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
1da177e4
LT
1900
1901 ide_tape_put(tape);
1da177e4
LT
1902 return 0;
1903}
1904
a4600f81 1905static int idetape_ioctl(struct block_device *bdev, fmode_t mode,
1da177e4
LT
1906 unsigned int cmd, unsigned long arg)
1907{
5aeddf90 1908 struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj);
1da177e4 1909 ide_drive_t *drive = tape->drive;
1bddd9e6 1910 int err = generic_ide_ioctl(drive, bdev, cmd, arg);
1da177e4
LT
1911 if (err == -EINVAL)
1912 err = idetape_blkdev_ioctl(drive, cmd, arg);
1913 return err;
1914}
1915
1916static struct block_device_operations idetape_block_ops = {
1917 .owner = THIS_MODULE,
a4600f81
AV
1918 .open = idetape_open,
1919 .release = idetape_release,
1920 .locked_ioctl = idetape_ioctl,
1da177e4
LT
1921};
1922
4031bbe4 1923static int ide_tape_probe(ide_drive_t *drive)
1da177e4
LT
1924{
1925 idetape_tape_t *tape;
1926 struct gendisk *g;
1927 int minor;
1928
e972d702
BP
1929 ide_debug_log(IDE_DBG_FUNC, "enter");
1930
1931 if (!strstr(DRV_NAME, drive->driver_req))
1da177e4 1932 goto failed;
2a924662 1933
1da177e4
LT
1934 if (drive->media != ide_tape)
1935 goto failed;
2a924662 1936
97100fc8
BZ
1937 if ((drive->dev_flags & IDE_DFLAG_ID_READ) &&
1938 ide_check_atapi_device(drive, DRV_NAME) == 0) {
5a04cfa9
BP
1939 printk(KERN_ERR "ide-tape: %s: not supported by this version of"
1940 " the driver\n", drive->name);
1da177e4
LT
1941 goto failed;
1942 }
5a04cfa9 1943 tape = kzalloc(sizeof(idetape_tape_t), GFP_KERNEL);
1da177e4 1944 if (tape == NULL) {
5a04cfa9
BP
1945 printk(KERN_ERR "ide-tape: %s: Can't allocate a tape struct\n",
1946 drive->name);
1da177e4
LT
1947 goto failed;
1948 }
1949
1950 g = alloc_disk(1 << PARTN_BITS);
1951 if (!g)
1952 goto out_free_tape;
1953
1954 ide_init_disk(g, drive);
1955
8fed4368
BZ
1956 tape->dev.parent = &drive->gendev;
1957 tape->dev.release = ide_tape_release;
1958 dev_set_name(&tape->dev, dev_name(&drive->gendev));
1959
1960 if (device_register(&tape->dev))
1961 goto out_free_disk;
1da177e4
LT
1962
1963 tape->drive = drive;
1964 tape->driver = &idetape_driver;
1965 tape->disk = g;
1966
1967 g->private_data = &tape->driver;
1968
1969 drive->driver_data = tape;
1970
cf8b8975 1971 mutex_lock(&idetape_ref_mutex);
1da177e4
LT
1972 for (minor = 0; idetape_devs[minor]; minor++)
1973 ;
1974 idetape_devs[minor] = tape;
cf8b8975 1975 mutex_unlock(&idetape_ref_mutex);
1da177e4
LT
1976
1977 idetape_setup(drive, tape, minor);
1978
3ee074bf
GKH
1979 device_create(idetape_sysfs_class, &drive->gendev,
1980 MKDEV(IDETAPE_MAJOR, minor), NULL, "%s", tape->name);
1981 device_create(idetape_sysfs_class, &drive->gendev,
1982 MKDEV(IDETAPE_MAJOR, minor + 128), NULL,
1983 "n%s", tape->name);
d5dee80a 1984
1da177e4
LT
1985 g->fops = &idetape_block_ops;
1986 ide_register_region(g);
1987
1988 return 0;
8604affd 1989
8fed4368
BZ
1990out_free_disk:
1991 put_disk(g);
1da177e4
LT
1992out_free_tape:
1993 kfree(tape);
1994failed:
8604affd 1995 return -ENODEV;
1da177e4
LT
1996}
1997
5a04cfa9 1998static void __exit idetape_exit(void)
1da177e4 1999{
8604affd 2000 driver_unregister(&idetape_driver.gen_driver);
d5dee80a 2001 class_destroy(idetape_sysfs_class);
1da177e4
LT
2002 unregister_chrdev(IDETAPE_MAJOR, "ht");
2003}
2004
17514e8a 2005static int __init idetape_init(void)
1da177e4 2006{
d5dee80a
WD
2007 int error = 1;
2008 idetape_sysfs_class = class_create(THIS_MODULE, "ide_tape");
2009 if (IS_ERR(idetape_sysfs_class)) {
2010 idetape_sysfs_class = NULL;
2011 printk(KERN_ERR "Unable to create sysfs class for ide tapes\n");
2012 error = -EBUSY;
2013 goto out;
2014 }
2015
1da177e4 2016 if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) {
5a04cfa9
BP
2017 printk(KERN_ERR "ide-tape: Failed to register chrdev"
2018 " interface\n");
d5dee80a
WD
2019 error = -EBUSY;
2020 goto out_free_class;
1da177e4 2021 }
d5dee80a
WD
2022
2023 error = driver_register(&idetape_driver.gen_driver);
2024 if (error)
2025 goto out_free_driver;
2026
2027 return 0;
2028
2029out_free_driver:
2030 driver_unregister(&idetape_driver.gen_driver);
2031out_free_class:
2032 class_destroy(idetape_sysfs_class);
2033out:
2034 return error;
1da177e4
LT
2035}
2036
263756ec 2037MODULE_ALIAS("ide:*m-tape*");
1da177e4
LT
2038module_init(idetape_init);
2039module_exit(idetape_exit);
2040MODULE_ALIAS_CHARDEV_MAJOR(IDETAPE_MAJOR);
9c145768
BP
2041MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver");
2042MODULE_LICENSE("GPL");