ide-tape.c 55.3 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2 3
 * IDE ATAPI streaming tape driver.
 *
4 5
 * Copyright (C) 1995-1999  Gadi Oxman <gadio@netvision.net.il>
 * Copyright (C) 2003-2005  Bartlomiej Zolnierkiewicz
L
Linus Torvalds 已提交
6 7 8 9 10 11 12 13
 *
 * This driver was constructed as a student project in the software laboratory
 * of the faculty of electrical engineering in the Technion - Israel's
 * Institute Of Technology, with the guide of Avner Lottem and Dr. Ilana David.
 *
 * It is hereby placed under the terms of the GNU general public license.
 * (See linux/COPYING).
 *
14 15
 * For a historical changelog see
 * Documentation/ide/ChangeLog.ide-tape.1995-2002
L
Linus Torvalds 已提交
16 17
 */

18 19
#define DRV_NAME "ide-tape"

20
#define IDETAPE_VERSION "1.20"
L
Linus Torvalds 已提交
21 22 23 24 25 26 27 28 29

#include <linux/module.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/timer.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
30
#include <linux/jiffies.h>
L
Linus Torvalds 已提交
31 32 33 34 35 36 37 38 39
#include <linux/major.h>
#include <linux/errno.h>
#include <linux/genhd.h>
#include <linux/slab.h>
#include <linux/pci.h>
#include <linux/ide.h>
#include <linux/smp_lock.h>
#include <linux/completion.h>
#include <linux/bitops.h>
40
#include <linux/mutex.h>
41
#include <scsi/scsi.h>
L
Linus Torvalds 已提交
42 43

#include <asm/byteorder.h>
44 45 46
#include <linux/irq.h>
#include <linux/uaccess.h>
#include <linux/io.h>
L
Linus Torvalds 已提交
47 48 49
#include <asm/unaligned.h>
#include <linux/mtio.h>

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
enum {
	/* output errors only */
	DBG_ERR =		(1 << 0),
	/* output all sense key/asc */
	DBG_SENSE =		(1 << 1),
	/* info regarding all chrdev-related procedures */
	DBG_CHRDEV =		(1 << 2),
	/* all remaining procedures */
	DBG_PROCS =		(1 << 3),
};

/* define to see debug info */
#define IDETAPE_DEBUG_LOG		0

#if IDETAPE_DEBUG_LOG
#define debug_log(lvl, fmt, args...)			\
{							\
	if (tape->debug_mask & lvl)			\
	printk(KERN_INFO "ide-tape: " fmt, ## args);	\
}
#else
#define debug_log(lvl, fmt, args...) do {} while (0)
#endif

L
Linus Torvalds 已提交
74 75
/**************************** Tunable parameters *****************************/
/*
76 77
 * After each failed packet command we issue a request sense command and retry
 * the packet command IDETAPE_MAX_PC_RETRIES times.
L
Linus Torvalds 已提交
78
 *
79
 * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries.
L
Linus Torvalds 已提交
80 81 82 83
 */
#define IDETAPE_MAX_PC_RETRIES		3

/*
84 85 86 87
 * The following parameter is used to select the point in the internal tape fifo
 * in which we will start to refill the buffer. Decreasing the following
 * parameter will improve the system's latency and interactive response, while
 * using a high value might improve system throughput.
L
Linus Torvalds 已提交
88
 */
89
#define IDETAPE_FIFO_THRESHOLD		2
L
Linus Torvalds 已提交
90 91

/*
92
 * DSC polling parameters.
L
Linus Torvalds 已提交
93
 *
94 95
 * Polling for DSC (a single bit in the status register) is a very important
 * function in ide-tape. There are two cases in which we poll for DSC:
L
Linus Torvalds 已提交
96
 *
97 98 99 100 101
 * 1. Before a read/write packet command, to ensure that we can transfer data
 * from/to the tape's data buffers, without causing an actual media access.
 * In case the tape is not ready yet, we take out our request from the device
 * request queue, so that ide.c could service requests from the other device
 * on the same interface in the meantime.
L
Linus Torvalds 已提交
102
 *
103 104 105 106 107 108 109 110
 * 2. After the successful initialization of a "media access packet command",
 * which is a command that can take a long time to complete (the interval can
 * range from several seconds to even an hour). Again, we postpone our request
 * in the middle to free the bus for the other device. The polling frequency
 * here should be lower than the read/write frequency since those media access
 * commands are slow. We start from a "fast" frequency - IDETAPE_DSC_MA_FAST
 * (1 second), and if we don't receive DSC after IDETAPE_DSC_MA_THRESHOLD
 * (5 min), we switch it to a lower frequency - IDETAPE_DSC_MA_SLOW (1 min).
L
Linus Torvalds 已提交
111
 *
112 113
 * We also set a timeout for the timer, in case something goes wrong. The
 * timeout should be longer then the maximum execution time of a tape operation.
L
Linus Torvalds 已提交
114
 */
115 116

/* DSC timings. */
L
Linus Torvalds 已提交
117 118 119 120 121 122 123 124 125 126
#define IDETAPE_DSC_RW_MIN		5*HZ/100	/* 50 msec */
#define IDETAPE_DSC_RW_MAX		40*HZ/100	/* 400 msec */
#define IDETAPE_DSC_RW_TIMEOUT		2*60*HZ		/* 2 minutes */
#define IDETAPE_DSC_MA_FAST		2*HZ		/* 2 seconds */
#define IDETAPE_DSC_MA_THRESHOLD	5*60*HZ		/* 5 minutes */
#define IDETAPE_DSC_MA_SLOW		30*HZ		/* 30 seconds */
#define IDETAPE_DSC_MA_TIMEOUT		2*60*60*HZ	/* 2 hours */

/*************************** End of tunable parameters ***********************/

127 128 129 130 131 132
/* tape directions */
enum {
	IDETAPE_DIR_NONE  = (1 << 0),
	IDETAPE_DIR_READ  = (1 << 1),
	IDETAPE_DIR_WRITE = (1 << 2),
};
L
Linus Torvalds 已提交
133

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
/* Tape door status */
#define DOOR_UNLOCKED			0
#define DOOR_LOCKED			1
#define DOOR_EXPLICITLY_LOCKED		2

/* Some defines for the SPACE command */
#define IDETAPE_SPACE_OVER_FILEMARK	1
#define IDETAPE_SPACE_TO_EOD		3

/* Some defines for the LOAD UNLOAD command */
#define IDETAPE_LU_LOAD_MASK		1
#define IDETAPE_LU_RETENSION_MASK	2
#define IDETAPE_LU_EOT_MASK		4

/* Structures related to the SELECT SENSE / MODE SENSE packet commands. */
#define IDETAPE_BLOCK_DESCRIPTOR	0
#define IDETAPE_CAPABILITIES_PAGE	0x2a

L
Linus Torvalds 已提交
152
/*
153 154
 * Most of our global data which we need to save even as we leave the driver due
 * to an interrupt or a timer event is stored in the struct defined below.
L
Linus Torvalds 已提交
155 156
 */
typedef struct ide_tape_obj {
157 158 159
	ide_drive_t		*drive;
	struct ide_driver	*driver;
	struct gendisk		*disk;
160
	struct device		dev;
L
Linus Torvalds 已提交
161

162 163
	/* used by REQ_IDETAPE_{READ,WRITE} requests */
	struct ide_atapi_pc queued_pc;
164

L
Linus Torvalds 已提交
165
	/*
166
	 * DSC polling variables.
L
Linus Torvalds 已提交
167
	 *
168 169 170
	 * While polling for DSC we use postponed_rq to postpone the current
	 * request so that ide.c will be able to service pending requests on the
	 * other device. Note that at most we will have only one DSC (usually
171
	 * data transfer) request in the device request queue.
L
Linus Torvalds 已提交
172 173 174 175 176 177 178
	 */
	struct request *postponed_rq;
	/* The time in which we started polling for DSC */
	unsigned long dsc_polling_start;
	/* Timer used to poll for dsc */
	struct timer_list dsc_timer;
	/* Read/Write dsc polling frequency */
179 180
	unsigned long best_dsc_rw_freq;
	unsigned long dsc_poll_freq;
L
Linus Torvalds 已提交
181 182
	unsigned long dsc_timeout;

183
	/* Read position information */
L
Linus Torvalds 已提交
184 185
	u8 partition;
	/* Current block */
186
	unsigned int first_frame;
L
Linus Torvalds 已提交
187

188
	/* Last error information */
L
Linus Torvalds 已提交
189 190
	u8 sense_key, asc, ascq;

191
	/* Character device operation */
L
Linus Torvalds 已提交
192 193 194 195
	unsigned int minor;
	/* device name */
	char name[4];
	/* Current character device data transfer direction */
196
	u8 chrdev_dir;
L
Linus Torvalds 已提交
197

198 199
	/* tape block size, usually 512 or 1024 bytes */
	unsigned short blk_size;
L
Linus Torvalds 已提交
200
	int user_bs_factor;
201

L
Linus Torvalds 已提交
202
	/* Copy of the tape's Capabilities and Mechanical Page */
203
	u8 caps[20];
L
Linus Torvalds 已提交
204 205

	/*
206
	 * Active data transfer request parameters.
L
Linus Torvalds 已提交
207
	 *
208 209 210
	 * At most, there is only one ide-tape originated data transfer request
	 * in the device request queue. This allows ide.c to easily service
	 * requests from the other device when we postpone our active request.
L
Linus Torvalds 已提交
211
	 */
212

213
	/* Data buffer size chosen based on the tape's recommendation */
214
	int buffer_size;
T
Tejun Heo 已提交
215 216 217 218 219 220
	/* Staging buffer of buffer_size bytes */
	void *buf;
	/* The read/write cursor */
	void *cur;
	/* The number of valid bytes in buf */
	size_t valid;
221 222

	/* Measures average tape speed */
L
Linus Torvalds 已提交
223 224 225 226 227 228 229 230 231 232 233
	unsigned long avg_time;
	int avg_size;
	int avg_speed;

	/* the door is currently locked */
	int door_locked;
	/* the tape hardware is write protected */
	char drv_write_prot;
	/* the tape is write protected (hardware or opened as read-only) */
	char write_prot;

234
	u32 debug_mask;
L
Linus Torvalds 已提交
235 236
} idetape_tape_t;

237
static DEFINE_MUTEX(idetape_ref_mutex);
L
Linus Torvalds 已提交
238

239 240
static struct class *idetape_sysfs_class;

241
static void ide_tape_release(struct device *);
242

L
Linus Torvalds 已提交
243 244 245 246
static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
{
	struct ide_tape_obj *tape = NULL;

247
	mutex_lock(&idetape_ref_mutex);
B
Borislav Petkov 已提交
248
	tape = ide_drv_g(disk, ide_tape_obj);
249
	if (tape) {
250
		if (ide_device_get(tape->drive))
251
			tape = NULL;
252
		else
253
			get_device(&tape->dev);
254
	}
255
	mutex_unlock(&idetape_ref_mutex);
L
Linus Torvalds 已提交
256 257 258 259 260
	return tape;
}

static void ide_tape_put(struct ide_tape_obj *tape)
{
261 262
	ide_drive_t *drive = tape->drive;

263
	mutex_lock(&idetape_ref_mutex);
264
	put_device(&tape->dev);
265
	ide_device_put(drive);
266
	mutex_unlock(&idetape_ref_mutex);
L
Linus Torvalds 已提交
267 268 269
}

/*
270 271
 * The variables below are used for the character device interface. Additional
 * state variables are defined in our ide_drive_t structure.
L
Linus Torvalds 已提交
272
 */
273
static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES];
L
Linus Torvalds 已提交
274 275 276 277 278

static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
{
	struct ide_tape_obj *tape = NULL;

279
	mutex_lock(&idetape_ref_mutex);
L
Linus Torvalds 已提交
280 281
	tape = idetape_devs[i];
	if (tape)
282
		get_device(&tape->dev);
283
	mutex_unlock(&idetape_ref_mutex);
L
Linus Torvalds 已提交
284 285 286 287
	return tape;
}

/*
288 289
 * called on each failed packet command retry to analyze the request sense. We
 * currently do not utilize this information.
L
Linus Torvalds 已提交
290
 */
291
static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
L
Linus Torvalds 已提交
292 293
{
	idetape_tape_t *tape = drive->driver_data;
294
	struct ide_atapi_pc *pc = drive->failed_pc;
L
Linus Torvalds 已提交
295

296 297 298
	tape->sense_key = sense[2] & 0xF;
	tape->asc       = sense[12];
	tape->ascq      = sense[13];
299 300 301

	debug_log(DBG_ERR, "pc = %x, sense key = %x, asc = %x, ascq = %x\n",
		 pc->c[0], tape->sense_key, tape->asc, tape->ascq);
L
Linus Torvalds 已提交
302

303
	/* Correct pc->xferred by asking the tape.	 */
304
	if (pc->flags & PC_FLAG_DMA_ERROR)
305
		pc->xferred = pc->req_xfer -
306
			tape->blk_size *
307
			get_unaligned_be32(&sense[3]);
L
Linus Torvalds 已提交
308 309 310 311 312 313

	/*
	 * If error was the result of a zero-length read or write command,
	 * with sense key=5, asc=0x22, ascq=0, let it slide.  Some drives
	 * (i.e. Seagate STT3401A Travan) don't support 0-length read/writes.
	 */
314
	if ((pc->c[0] == READ_6 || pc->c[0] == WRITE_6)
315 316 317
	    /* length == 0 */
	    && pc->c[4] == 0 && pc->c[3] == 0 && pc->c[2] == 0) {
		if (tape->sense_key == 5) {
L
Linus Torvalds 已提交
318 319 320
			/* don't report an error, everything's ok */
			pc->error = 0;
			/* don't retry read/write */
321
			pc->flags |= PC_FLAG_ABORT;
L
Linus Torvalds 已提交
322 323
		}
	}
324
	if (pc->c[0] == READ_6 && (sense[2] & 0x80)) {
325
		pc->error = IDE_DRV_ERROR_FILEMARK;
326
		pc->flags |= PC_FLAG_ABORT;
L
Linus Torvalds 已提交
327
	}
328
	if (pc->c[0] == WRITE_6) {
329 330
		if ((sense[2] & 0x40) || (tape->sense_key == 0xd
		     && tape->asc == 0x0 && tape->ascq == 0x2)) {
331
			pc->error = IDE_DRV_ERROR_EOD;
332
			pc->flags |= PC_FLAG_ABORT;
L
Linus Torvalds 已提交
333 334
		}
	}
335
	if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
336
		if (tape->sense_key == 8) {
337
			pc->error = IDE_DRV_ERROR_EOD;
338
			pc->flags |= PC_FLAG_ABORT;
L
Linus Torvalds 已提交
339
		}
340
		if (!(pc->flags & PC_FLAG_ABORT) &&
341
		    pc->xferred)
L
Linus Torvalds 已提交
342 343 344 345
			pc->retries = IDETAPE_MAX_PC_RETRIES + 1;
	}
}

346 347
static void ide_tape_handle_dsc(ide_drive_t *);

348
static int ide_tape_callback(ide_drive_t *drive, int dsc)
L
Linus Torvalds 已提交
349 350
{
	idetape_tape_t *tape = drive->driver_data;
351
	struct ide_atapi_pc *pc = drive->pc;
352
	struct request *rq = drive->hwif->rq;
353
	int uptodate = pc->error ? 0 : 1;
354
	int err = uptodate ? 0 : IDE_DRV_ERROR_GENERAL;
L
Linus Torvalds 已提交
355

356 357
	debug_log(DBG_PROCS, "Enter %s\n", __func__);

358 359 360
	if (dsc)
		ide_tape_handle_dsc(drive);

361 362
	if (drive->failed_pc == pc)
		drive->failed_pc = NULL;
363

364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
	if (pc->c[0] == REQUEST_SENSE) {
		if (uptodate)
			idetape_analyze_error(drive, pc->buf);
		else
			printk(KERN_ERR "ide-tape: Error in REQUEST SENSE "
					"itself - Aborting request!\n");
	} else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
		int blocks = pc->xferred / tape->blk_size;

		tape->avg_size += blocks * tape->blk_size;

		if (time_after_eq(jiffies, tape->avg_time + HZ)) {
			tape->avg_speed = tape->avg_size * HZ /
				(jiffies - tape->avg_time) / 1024;
			tape->avg_size = 0;
			tape->avg_time = jiffies;
		}

		tape->first_frame += blocks;
T
Tejun Heo 已提交
383
		rq->resid_len = rq->data_len - blocks * tape->blk_size;
384

385 386 387 388
		if (pc->error) {
			uptodate = 0;
			err = pc->error;
		}
389
	} else if (pc->c[0] == READ_POSITION && uptodate) {
390
		u8 *readpos = pc->buf;
391 392 393 394 395 396 397 398 399

		debug_log(DBG_SENSE, "BOP - %s\n",
				(readpos[0] & 0x80) ? "Yes" : "No");
		debug_log(DBG_SENSE, "EOP - %s\n",
				(readpos[0] & 0x40) ? "Yes" : "No");

		if (readpos[0] & 0x4) {
			printk(KERN_INFO "ide-tape: Block location is unknown"
					 "to the tape\n");
400
			clear_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags);
401
			uptodate = 0;
402
			err = IDE_DRV_ERROR_GENERAL;
403 404
		} else {
			debug_log(DBG_SENSE, "Block Location - %u\n",
405
					be32_to_cpup((__be32 *)&readpos[4]));
406 407

			tape->partition = readpos[1];
408
			tape->first_frame = be32_to_cpup((__be32 *)&readpos[4]);
409
			set_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags);
410
		}
L
Linus Torvalds 已提交
411
	}
412

413 414
	rq->errors = err;

415
	return uptodate;
L
Linus Torvalds 已提交
416 417 418
}

/*
419
 * Postpone the current request so that ide.c will be able to service requests
420
 * from another device on the same port while we are polling for DSC.
L
Linus Torvalds 已提交
421
 */
422
static void idetape_postpone_request(ide_drive_t *drive)
L
Linus Torvalds 已提交
423 424 425
{
	idetape_tape_t *tape = drive->driver_data;

426 427
	debug_log(DBG_PROCS, "Enter %s\n", __func__);

428 429
	tape->postponed_rq = drive->hwif->rq;

430
	ide_stall_queue(drive, tape->dsc_poll_freq);
L
Linus Torvalds 已提交
431 432
}

433 434 435 436 437 438 439 440 441 442 443 444
static void ide_tape_handle_dsc(ide_drive_t *drive)
{
	idetape_tape_t *tape = drive->driver_data;

	/* Media access command */
	tape->dsc_polling_start = jiffies;
	tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST;
	tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT;
	/* Allow ide.c to handle other requests */
	idetape_postpone_request(drive);
}

L
Linus Torvalds 已提交
445
/*
446
 * Packet Command Interface
L
Linus Torvalds 已提交
447
 *
448
 * The current Packet Command is available in drive->pc, and will not change
449 450
 * until we finish handling it. Each packet command is associated with a
 * callback function that will be called when the command is finished.
L
Linus Torvalds 已提交
451
 *
452
 * The handling will be done in three stages:
L
Linus Torvalds 已提交
453
 *
454
 * 1. ide_tape_issue_pc will send the packet command to the drive, and will set
455
 * the interrupt handler to ide_pc_intr.
L
Linus Torvalds 已提交
456
 *
457
 * 2. On each interrupt, ide_pc_intr will be called. This step will be
458
 * repeated until the device signals us that no more interrupts will be issued.
L
Linus Torvalds 已提交
459
 *
460 461 462 463 464 465 466
 * 3. ATAPI Tape media access commands have immediate status with a delayed
 * process. In case of a successful initiation of a media access packet command,
 * the DSC bit will be set when the actual execution of the command is finished.
 * Since the tape drive will not issue an interrupt, we have to poll for this
 * event. In this case, we define the request as "low priority request" by
 * setting rq_status to IDETAPE_RQ_POSTPONED, set a timer to poll for DSC and
 * exit the driver.
L
Linus Torvalds 已提交
467
 *
468 469
 * ide.c will then give higher priority to requests which originate from the
 * other device, until will change rq_status to RQ_ACTIVE.
L
Linus Torvalds 已提交
470
 *
471
 * 4. When the packet command is finished, it will be checked for errors.
L
Linus Torvalds 已提交
472
 *
473 474 475
 * 5. In case an error was found, we queue a request sense packet command in
 * front of the request queue and retry the operation up to
 * IDETAPE_MAX_PC_RETRIES times.
L
Linus Torvalds 已提交
476
 *
477 478 479
 * 6. In case no error was found, or we decided to give up and not to retry
 * again, the callback function will be called and then we will handle the next
 * request.
L
Linus Torvalds 已提交
480 481
 */

482 483 484
static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
					 struct ide_cmd *cmd,
					 struct ide_atapi_pc *pc)
L
Linus Torvalds 已提交
485 486 487
{
	idetape_tape_t *tape = drive->driver_data;

488 489
	if (drive->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
		drive->failed_pc = pc;
490

L
Linus Torvalds 已提交
491
	/* Set the current packet command */
492
	drive->pc = pc;
L
Linus Torvalds 已提交
493 494

	if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
495
		(pc->flags & PC_FLAG_ABORT)) {
496 497
		unsigned int done = blk_rq_bytes(drive->hwif->rq);

L
Linus Torvalds 已提交
498
		/*
499 500 501
		 * We will "abort" retrying a packet command in case legitimate
		 * error code was received (crossing a filemark, or end of the
		 * media, for example).
L
Linus Torvalds 已提交
502
		 */
503
		if (!(pc->flags & PC_FLAG_ABORT)) {
504
			if (!(pc->c[0] == TEST_UNIT_READY &&
L
Linus Torvalds 已提交
505 506 507 508 509 510 511 512 513 514
			      tape->sense_key == 2 && tape->asc == 4 &&
			     (tape->ascq == 1 || tape->ascq == 8))) {
				printk(KERN_ERR "ide-tape: %s: I/O error, "
						"pc = %2x, key = %2x, "
						"asc = %2x, ascq = %2x\n",
						tape->name, pc->c[0],
						tape->sense_key, tape->asc,
						tape->ascq);
			}
			/* Giving up */
515
			pc->error = IDE_DRV_ERROR_GENERAL;
L
Linus Torvalds 已提交
516
		}
517

518
		drive->failed_pc = NULL;
519
		drive->pc_callback(drive, 0);
520
		ide_complete_rq(drive, -EIO, done);
521
		return ide_stopped;
L
Linus Torvalds 已提交
522
	}
523
	debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
L
Linus Torvalds 已提交
524 525 526

	pc->retries++;

527
	return ide_issue_pc(drive, cmd);
L
Linus Torvalds 已提交
528 529
}

530
/* A mode sense command is used to "sense" tape parameters. */
531
static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
L
Linus Torvalds 已提交
532
{
533
	ide_init_pc(pc);
534
	pc->c[0] = MODE_SENSE;
L
Linus Torvalds 已提交
535
	if (page_code != IDETAPE_BLOCK_DESCRIPTOR)
536 537
		/* DBD = 1 - Don't return block descriptors */
		pc->c[1] = 8;
L
Linus Torvalds 已提交
538 539 540 541 542 543 544 545 546
	pc->c[2] = page_code;
	/*
	 * Changed pc->c[3] to 0 (255 will at best return unused info).
	 *
	 * For SCSI this byte is defined as subpage instead of high byte
	 * of length and some IDE drives seem to interpret it this way
	 * and return an error when 255 is used.
	 */
	pc->c[3] = 0;
547 548
	/* We will just discard data in that case */
	pc->c[4] = 255;
L
Linus Torvalds 已提交
549
	if (page_code == IDETAPE_BLOCK_DESCRIPTOR)
550
		pc->req_xfer = 12;
L
Linus Torvalds 已提交
551
	else if (page_code == IDETAPE_CAPABILITIES_PAGE)
552
		pc->req_xfer = 24;
L
Linus Torvalds 已提交
553
	else
554
		pc->req_xfer = 50;
L
Linus Torvalds 已提交
555 556
}

557
static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
L
Linus Torvalds 已提交
558
{
559
	ide_hwif_t *hwif = drive->hwif;
L
Linus Torvalds 已提交
560
	idetape_tape_t *tape = drive->driver_data;
561
	struct ide_atapi_pc *pc = drive->pc;
562
	u8 stat;
L
Linus Torvalds 已提交
563

564
	stat = hwif->tp_ops->read_status(hwif);
565

566 567
	if (stat & ATA_DSC) {
		if (stat & ATA_ERR) {
L
Linus Torvalds 已提交
568
			/* Error detected */
569
			if (pc->c[0] != TEST_UNIT_READY)
L
Linus Torvalds 已提交
570 571 572
				printk(KERN_ERR "ide-tape: %s: I/O error, ",
						tape->name);
			/* Retry operation */
573
			ide_retry_pc(drive);
574
			return ide_stopped;
L
Linus Torvalds 已提交
575 576 577
		}
		pc->error = 0;
	} else {
578
		pc->error = IDE_DRV_ERROR_GENERAL;
579
		drive->failed_pc = NULL;
L
Linus Torvalds 已提交
580
	}
581
	drive->pc_callback(drive, 0);
L
Linus Torvalds 已提交
582 583 584
	return ide_stopped;
}

585
static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
586 587
				   struct ide_atapi_pc *pc, struct request *rq,
				   u8 opcode)
L
Linus Torvalds 已提交
588
{
589
	unsigned int length = blk_rq_sectors(rq);
590

591
	ide_init_pc(pc);
592
	put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
L
Linus Torvalds 已提交
593
	pc->c[1] = 1;
594 595 596
	pc->buf = NULL;
	pc->buf_size = length * tape->blk_size;
	pc->req_xfer = pc->buf_size;
597
	if (pc->req_xfer == tape->buffer_size)
598
		pc->flags |= PC_FLAG_DMA_OK;
L
Linus Torvalds 已提交
599

T
Tejun Heo 已提交
600
	if (opcode == READ_6)
601
		pc->c[0] = READ_6;
T
Tejun Heo 已提交
602
	else if (opcode == WRITE_6) {
603 604 605
		pc->c[0] = WRITE_6;
		pc->flags |= PC_FLAG_WRITING;
	}
606 607

	memcpy(rq->cmd, pc->c, 12);
L
Linus Torvalds 已提交
608 609 610 611 612
}

static ide_startstop_t idetape_do_request(ide_drive_t *drive,
					  struct request *rq, sector_t block)
{
613
	ide_hwif_t *hwif = drive->hwif;
L
Linus Torvalds 已提交
614
	idetape_tape_t *tape = drive->driver_data;
615
	struct ide_atapi_pc *pc = NULL;
L
Linus Torvalds 已提交
616
	struct request *postponed_rq = tape->postponed_rq;
617
	struct ide_cmd cmd;
618
	u8 stat;
L
Linus Torvalds 已提交
619

620 621
	debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %u\n"
		  (unsigned long long)blk_rq_pos(rq), blk_rq_sectors(rq));
L
Linus Torvalds 已提交
622

623
	if (!(blk_special_request(rq) || blk_sense_request(rq))) {
624
		/* We do not support buffer cache originated requests. */
L
Linus Torvalds 已提交
625
		printk(KERN_NOTICE "ide-tape: %s: Unsupported request in "
626
			"request queue (%d)\n", drive->name, rq->cmd_type);
627 628
		if (blk_fs_request(rq) == 0 && rq->errors == 0)
			rq->errors = -EIO;
629
		ide_complete_rq(drive, -EIO, ide_rq_bytes(rq));
L
Linus Torvalds 已提交
630 631 632
		return ide_stopped;
	}

633
	/* Retry a failed packet command */
634 635
	if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) {
		pc = drive->failed_pc;
636 637
		goto out;
	}
638

L
Linus Torvalds 已提交
639 640 641 642
	if (postponed_rq != NULL)
		if (rq != postponed_rq) {
			printk(KERN_ERR "ide-tape: ide-tape.c bug - "
					"Two DSC requests were queued\n");
643
			drive->failed_pc = NULL;
644
			rq->errors = 0;
645
			ide_complete_rq(drive, 0, blk_rq_bytes(rq));
L
Linus Torvalds 已提交
646 647 648 649 650 651 652 653 654
			return ide_stopped;
		}

	tape->postponed_rq = NULL;

	/*
	 * If the tape is still busy, postpone our request and service
	 * the other device meanwhile.
	 */
655
	stat = hwif->tp_ops->read_status(hwif);
L
Linus Torvalds 已提交
656

B
Bartlomiej Zolnierkiewicz 已提交
657 658
	if ((drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) == 0 &&
	    (rq->cmd[13] & REQ_IDETAPE_PC2) == 0)
659
		set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
L
Linus Torvalds 已提交
660

B
Bartlomiej Zolnierkiewicz 已提交
661
	if (drive->dev_flags & IDE_DFLAG_POST_RESET) {
662
		set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
B
Bartlomiej Zolnierkiewicz 已提交
663
		drive->dev_flags &= ~IDE_DFLAG_POST_RESET;
L
Linus Torvalds 已提交
664 665
	}

666
	if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) &&
667
	    (stat & ATA_DSC) == 0) {
L
Linus Torvalds 已提交
668 669
		if (postponed_rq == NULL) {
			tape->dsc_polling_start = jiffies;
670
			tape->dsc_poll_freq = tape->best_dsc_rw_freq;
L
Linus Torvalds 已提交
671 672 673 674
			tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT;
		} else if (time_after(jiffies, tape->dsc_timeout)) {
			printk(KERN_ERR "ide-tape: %s: DSC timeout\n",
				tape->name);
675
			if (rq->cmd[13] & REQ_IDETAPE_PC2) {
L
Linus Torvalds 已提交
676 677 678 679 680
				idetape_media_access_finished(drive);
				return ide_stopped;
			} else {
				return ide_do_reset(drive);
			}
681 682 683
		} else if (time_after(jiffies,
					tape->dsc_polling_start +
					IDETAPE_DSC_MA_THRESHOLD))
684
			tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW;
L
Linus Torvalds 已提交
685 686 687
		idetape_postpone_request(drive);
		return ide_stopped;
	}
688
	if (rq->cmd[13] & REQ_IDETAPE_READ) {
689
		pc = &tape->queued_pc;
690
		ide_tape_create_rw_cmd(tape, pc, rq, READ_6);
L
Linus Torvalds 已提交
691 692
		goto out;
	}
693
	if (rq->cmd[13] & REQ_IDETAPE_WRITE) {
694
		pc = &tape->queued_pc;
695
		ide_tape_create_rw_cmd(tape, pc, rq, WRITE_6);
L
Linus Torvalds 已提交
696 697
		goto out;
	}
698
	if (rq->cmd[13] & REQ_IDETAPE_PC1) {
T
Tejun Heo 已提交
699
		pc = (struct ide_atapi_pc *)rq->special;
700 701
		rq->cmd[13] &= ~(REQ_IDETAPE_PC1);
		rq->cmd[13] |= REQ_IDETAPE_PC2;
L
Linus Torvalds 已提交
702 703
		goto out;
	}
704
	if (rq->cmd[13] & REQ_IDETAPE_PC2) {
L
Linus Torvalds 已提交
705 706 707 708
		idetape_media_access_finished(drive);
		return ide_stopped;
	}
	BUG();
709

710
out:
711 712 713
	/* prepare sense request for this command */
	ide_prep_sense(drive, rq);

714 715 716 717 718 719 720
	memset(&cmd, 0, sizeof(cmd));

	if (rq_data_dir(rq))
		cmd.tf_flags |= IDE_TFLAG_WRITE;

	cmd.rq = rq;

721 722 723
	ide_init_sg_cmd(&cmd, pc->req_xfer);
	ide_map_sg(drive, &cmd);

724
	return ide_tape_issue_pc(drive, &cmd, pc);
L
Linus Torvalds 已提交
725 726 727
}

/*
728 729
 * Write a filemark if write_filemark=1. Flush the device buffers without
 * writing a filemark otherwise.
L
Linus Torvalds 已提交
730
 */
731
static void idetape_create_write_filemark_cmd(ide_drive_t *drive,
732
		struct ide_atapi_pc *pc, int write_filemark)
L
Linus Torvalds 已提交
733
{
734
	ide_init_pc(pc);
735
	pc->c[0] = WRITE_FILEMARKS;
L
Linus Torvalds 已提交
736
	pc->c[4] = write_filemark;
737
	pc->flags |= PC_FLAG_WAIT_FOR_DSC;
L
Linus Torvalds 已提交
738 739 740 741 742
}

static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
{
	idetape_tape_t *tape = drive->driver_data;
743
	struct gendisk *disk = tape->disk;
L
Linus Torvalds 已提交
744 745
	int load_attempted = 0;

746
	/* Wait for the tape to become ready */
747
	set_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags);
L
Linus Torvalds 已提交
748 749
	timeout += jiffies;
	while (time_before(jiffies, timeout)) {
750
		if (ide_do_test_unit_ready(drive, disk) == 0)
L
Linus Torvalds 已提交
751 752
			return 0;
		if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2)
753 754
		    || (tape->asc == 0x3A)) {
			/* no media */
L
Linus Torvalds 已提交
755 756
			if (load_attempted)
				return -ENOMEDIUM;
757
			ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK);
L
Linus Torvalds 已提交
758 759 760 761 762
			load_attempted = 1;
		/* not about to be ready */
		} else if (!(tape->sense_key == 2 && tape->asc == 4 &&
			     (tape->ascq == 1 || tape->ascq == 8)))
			return -EIO;
763
		msleep(100);
L
Linus Torvalds 已提交
764 765 766 767
	}
	return -EIO;
}

768
static int idetape_flush_tape_buffers(ide_drive_t *drive)
L
Linus Torvalds 已提交
769
{
770
	struct ide_tape_obj *tape = drive->driver_data;
771
	struct ide_atapi_pc pc;
L
Linus Torvalds 已提交
772 773 774
	int rc;

	idetape_create_write_filemark_cmd(drive, &pc, 0);
775
	rc = ide_queue_pc_tail(drive, tape->disk, &pc);
776
	if (rc)
L
Linus Torvalds 已提交
777 778 779 780 781
		return rc;
	idetape_wait_ready(drive, 60 * 5 * HZ);
	return 0;
}

782
static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc)
L
Linus Torvalds 已提交
783
{
784
	ide_init_pc(pc);
785
	pc->c[0] = READ_POSITION;
786
	pc->req_xfer = 20;
L
Linus Torvalds 已提交
787 788
}

789
static int idetape_read_position(ide_drive_t *drive)
L
Linus Torvalds 已提交
790 791
{
	idetape_tape_t *tape = drive->driver_data;
792
	struct ide_atapi_pc pc;
L
Linus Torvalds 已提交
793 794
	int position;

795
	debug_log(DBG_PROCS, "Enter %s\n", __func__);
L
Linus Torvalds 已提交
796 797

	idetape_create_read_position_cmd(&pc);
798
	if (ide_queue_pc_tail(drive, tape->disk, &pc))
L
Linus Torvalds 已提交
799
		return -1;
800
	position = tape->first_frame;
L
Linus Torvalds 已提交
801 802 803
	return position;
}

804 805
static void idetape_create_locate_cmd(ide_drive_t *drive,
		struct ide_atapi_pc *pc,
806
		unsigned int block, u8 partition, int skip)
L
Linus Torvalds 已提交
807
{
808
	ide_init_pc(pc);
809
	pc->c[0] = POSITION_TO_ELEMENT;
L
Linus Torvalds 已提交
810
	pc->c[1] = 2;
811
	put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]);
L
Linus Torvalds 已提交
812
	pc->c[8] = partition;
813
	pc->flags |= PC_FLAG_WAIT_FOR_DSC;
L
Linus Torvalds 已提交
814 815
}

816
static void __ide_tape_discard_merge_buffer(ide_drive_t *drive)
L
Linus Torvalds 已提交
817 818 819
{
	idetape_tape_t *tape = drive->driver_data;

820
	if (tape->chrdev_dir != IDETAPE_DIR_READ)
821
		return;
L
Linus Torvalds 已提交
822

823
	clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags);
T
Tejun Heo 已提交
824 825 826 827
	tape->valid = 0;
	if (tape->buf != NULL) {
		kfree(tape->buf);
		tape->buf = NULL;
L
Linus Torvalds 已提交
828 829
	}

830
	tape->chrdev_dir = IDETAPE_DIR_NONE;
L
Linus Torvalds 已提交
831 832 833
}

/*
834 835 836 837
 * Position the tape to the requested block using the LOCATE packet command.
 * A READ POSITION command is then issued to check where we are positioned. Like
 * all higher level operations, we queue the commands at the tail of the request
 * queue and wait for their completion.
L
Linus Torvalds 已提交
838
 */
839 840
static int idetape_position_tape(ide_drive_t *drive, unsigned int block,
		u8 partition, int skip)
L
Linus Torvalds 已提交
841 842
{
	idetape_tape_t *tape = drive->driver_data;
843
	struct gendisk *disk = tape->disk;
L
Linus Torvalds 已提交
844
	int retval;
845
	struct ide_atapi_pc pc;
L
Linus Torvalds 已提交
846

847
	if (tape->chrdev_dir == IDETAPE_DIR_READ)
848
		__ide_tape_discard_merge_buffer(drive);
L
Linus Torvalds 已提交
849 850
	idetape_wait_ready(drive, 60 * 5 * HZ);
	idetape_create_locate_cmd(drive, &pc, block, partition, skip);
851
	retval = ide_queue_pc_tail(drive, disk, &pc);
L
Linus Torvalds 已提交
852 853 854 855
	if (retval)
		return (retval);

	idetape_create_read_position_cmd(&pc);
856
	return ide_queue_pc_tail(drive, disk, &pc);
L
Linus Torvalds 已提交
857 858
}

859
static void ide_tape_discard_merge_buffer(ide_drive_t *drive,
860
					  int restore_position)
L
Linus Torvalds 已提交
861 862 863 864
{
	idetape_tape_t *tape = drive->driver_data;
	int seek, position;

865
	__ide_tape_discard_merge_buffer(drive);
L
Linus Torvalds 已提交
866 867
	if (restore_position) {
		position = idetape_read_position(drive);
868
		seek = position > 0 ? position : 0;
L
Linus Torvalds 已提交
869
		if (idetape_position_tape(drive, seek, 0, 0)) {
870
			printk(KERN_INFO "ide-tape: %s: position_tape failed in"
871
					 " %s\n", tape->name, __func__);
L
Linus Torvalds 已提交
872 873 874 875 876 877
			return;
		}
	}
}

/*
878 879
 * Generate a read/write request for the block device interface and wait for it
 * to be serviced.
L
Linus Torvalds 已提交
880
 */
881
static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size)
L
Linus Torvalds 已提交
882 883
{
	idetape_tape_t *tape = drive->driver_data;
884
	struct request *rq;
885
	int ret;
L
Linus Torvalds 已提交
886

887
	debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd);
888
	BUG_ON(cmd != REQ_IDETAPE_READ && cmd != REQ_IDETAPE_WRITE);
889
	BUG_ON(size < 0 || size % tape->blk_size);
890

891 892
	rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
	rq->cmd_type = REQ_TYPE_SPECIAL;
893
	rq->cmd[13] = cmd;
894
	rq->rq_disk = tape->disk;
895 896

	if (size) {
T
Tejun Heo 已提交
897
		ret = blk_rq_map_kern(drive->queue, rq, tape->buf, size,
898 899 900 901 902
				      __GFP_WAIT);
		if (ret)
			goto out_put;
	}

903 904
	blk_execute_rq(drive->queue, tape->disk, rq, 0);

T
Tejun Heo 已提交
905
	/* calculate the number of transferred bytes and update buffer state */
T
Tejun Heo 已提交
906
	size -= rq->resid_len;
T
Tejun Heo 已提交
907
	tape->cur = tape->buf;
908
	if (cmd == REQ_IDETAPE_READ)
T
Tejun Heo 已提交
909 910 911
		tape->valid = size;
	else
		tape->valid = 0;
L
Linus Torvalds 已提交
912

913 914 915 916 917
	ret = size;
	if (rq->errors == IDE_DRV_ERROR_GENERAL)
		ret = -EIO;
out_put:
	blk_put_request(rq);
918
	return ret;
L
Linus Torvalds 已提交
919 920
}

921
static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
L
Linus Torvalds 已提交
922
{
923
	ide_init_pc(pc);
924
	pc->c[0] = INQUIRY;
925
	pc->c[4] = 254;
926
	pc->req_xfer = 254;
L
Linus Torvalds 已提交
927 928
}

929 930
static void idetape_create_rewind_cmd(ide_drive_t *drive,
		struct ide_atapi_pc *pc)
L
Linus Torvalds 已提交
931
{
932
	ide_init_pc(pc);
933
	pc->c[0] = REZERO_UNIT;
934
	pc->flags |= PC_FLAG_WAIT_FOR_DSC;
L
Linus Torvalds 已提交
935 936
}

937
static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
L
Linus Torvalds 已提交
938
{
939
	ide_init_pc(pc);
940
	pc->c[0] = ERASE;
L
Linus Torvalds 已提交
941
	pc->c[1] = 1;
942
	pc->flags |= PC_FLAG_WAIT_FOR_DSC;
L
Linus Torvalds 已提交
943 944
}

945
static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
L
Linus Torvalds 已提交
946
{
947
	ide_init_pc(pc);
948
	pc->c[0] = SPACE;
949
	put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]);
L
Linus Torvalds 已提交
950
	pc->c[1] = cmd;
951
	pc->flags |= PC_FLAG_WAIT_FOR_DSC;
L
Linus Torvalds 已提交
952 953
}

954
static void ide_tape_flush_merge_buffer(ide_drive_t *drive)
L
Linus Torvalds 已提交
955 956
{
	idetape_tape_t *tape = drive->driver_data;
957

958
	if (tape->chrdev_dir != IDETAPE_DIR_WRITE) {
959
		printk(KERN_ERR "ide-tape: bug: Trying to empty merge buffer"
960
				" but we are not writing.\n");
L
Linus Torvalds 已提交
961 962
		return;
	}
T
Tejun Heo 已提交
963
	if (tape->buf) {
964 965 966
		size_t aligned = roundup(tape->valid, tape->blk_size);

		memset(tape->cur, 0, aligned - tape->valid);
967
		idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, aligned);
T
Tejun Heo 已提交
968 969
		kfree(tape->buf);
		tape->buf = NULL;
L
Linus Torvalds 已提交
970
	}
971
	tape->chrdev_dir = IDETAPE_DIR_NONE;
L
Linus Torvalds 已提交
972 973
}

T
Tejun Heo 已提交
974
static int idetape_init_rw(ide_drive_t *drive, int dir)
L
Linus Torvalds 已提交
975 976
{
	idetape_tape_t *tape = drive->driver_data;
T
Tejun Heo 已提交
977
	int rc;
L
Linus Torvalds 已提交
978

T
Tejun Heo 已提交
979
	BUG_ON(dir != IDETAPE_DIR_READ && dir != IDETAPE_DIR_WRITE);
L
Linus Torvalds 已提交
980

T
Tejun Heo 已提交
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
	if (tape->chrdev_dir == dir)
		return 0;

	if (tape->chrdev_dir == IDETAPE_DIR_READ)
		ide_tape_discard_merge_buffer(drive, 1);
	else if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
		ide_tape_flush_merge_buffer(drive);
		idetape_flush_tape_buffers(drive);
	}

	if (tape->buf || tape->valid) {
		printk(KERN_ERR "ide-tape: valid should be 0 now\n");
		tape->valid = 0;
	}

	tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
	if (!tape->buf)
		return -ENOMEM;
	tape->chrdev_dir = dir;
	tape->cur = tape->buf;

	/*
	 * Issue a 0 rw command to ensure that DSC handshake is
	 * switched from completion mode to buffer available mode.  No
	 * point in issuing this if DSC overlap isn't supported, some
	 * drives (Seagate STT3401A) will return an error.
	 */
	if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
		int cmd = dir == IDETAPE_DIR_READ ? REQ_IDETAPE_READ
						  : REQ_IDETAPE_WRITE;

		rc = idetape_queue_rw_tail(drive, cmd, 0);
		if (rc < 0) {
			kfree(tape->buf);
			tape->buf = NULL;
			tape->chrdev_dir = IDETAPE_DIR_NONE;
			return rc;
L
Linus Torvalds 已提交
1018 1019
		}
	}
1020

L
Linus Torvalds 已提交
1021 1022 1023
	return 0;
}

1024
static void idetape_pad_zeros(ide_drive_t *drive, int bcount)
L
Linus Torvalds 已提交
1025 1026
{
	idetape_tape_t *tape = drive->driver_data;
T
Tejun Heo 已提交
1027 1028

	memset(tape->buf, 0, tape->buffer_size);
1029

L
Linus Torvalds 已提交
1030
	while (bcount) {
T
Tejun Heo 已提交
1031
		unsigned int count = min(tape->buffer_size, bcount);
L
Linus Torvalds 已提交
1032

1033
		idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, count);
L
Linus Torvalds 已提交
1034 1035 1036 1037 1038
		bcount -= count;
	}
}

/*
1039 1040 1041
 * Rewinds the tape to the Beginning Of the current Partition (BOP). We
 * currently support only one partition.
 */
1042
static int idetape_rewind_tape(ide_drive_t *drive)
L
Linus Torvalds 已提交
1043
{
1044 1045
	struct ide_tape_obj *tape = drive->driver_data;
	struct gendisk *disk = tape->disk;
L
Linus Torvalds 已提交
1046
	int retval;
1047
	struct ide_atapi_pc pc;
1048 1049 1050

	debug_log(DBG_SENSE, "Enter %s\n", __func__);

L
Linus Torvalds 已提交
1051
	idetape_create_rewind_cmd(drive, &pc);
1052
	retval = ide_queue_pc_tail(drive, disk, &pc);
L
Linus Torvalds 已提交
1053 1054 1055 1056
	if (retval)
		return retval;

	idetape_create_read_position_cmd(&pc);
1057
	retval = ide_queue_pc_tail(drive, disk, &pc);
L
Linus Torvalds 已提交
1058 1059 1060 1061 1062
	if (retval)
		return retval;
	return 0;
}

1063
/* mtio.h compatible commands should be issued to the chrdev interface. */
1064 1065
static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd,
				unsigned long arg)
L
Linus Torvalds 已提交
1066 1067 1068 1069
{
	idetape_tape_t *tape = drive->driver_data;
	void __user *argp = (void __user *)arg;

1070 1071 1072 1073 1074 1075
	struct idetape_config {
		int dsc_rw_frequency;
		int dsc_media_access_frequency;
		int nr_stages;
	} config;

1076 1077
	debug_log(DBG_PROCS, "Enter %s\n", __func__);

L
Linus Torvalds 已提交
1078
	switch (cmd) {
1079 1080 1081 1082 1083 1084 1085
	case 0x0340:
		if (copy_from_user(&config, argp, sizeof(config)))
			return -EFAULT;
		tape->best_dsc_rw_freq = config.dsc_rw_frequency;
		break;
	case 0x0350:
		config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq;
1086
		config.nr_stages = 1;
1087 1088 1089 1090 1091
		if (copy_to_user(argp, &config, sizeof(config)))
			return -EFAULT;
		break;
	default:
		return -EIO;
L
Linus Torvalds 已提交
1092 1093 1094 1095
	}
	return 0;
}

1096 1097
static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
					int mt_count)
L
Linus Torvalds 已提交
1098 1099
{
	idetape_tape_t *tape = drive->driver_data;
1100
	struct gendisk *disk = tape->disk;
1101
	struct ide_atapi_pc pc;
1102
	int retval, count = 0;
1103
	int sprev = !!(tape->caps[4] & 0x20);
L
Linus Torvalds 已提交
1104 1105 1106 1107

	if (mt_count == 0)
		return 0;
	if (MTBSF == mt_op || MTBSFM == mt_op) {
1108
		if (!sprev)
L
Linus Torvalds 已提交
1109
			return -EIO;
1110
		mt_count = -mt_count;
L
Linus Torvalds 已提交
1111 1112
	}

1113
	if (tape->chrdev_dir == IDETAPE_DIR_READ) {
T
Tejun Heo 已提交
1114
		tape->valid = 0;
1115
		if (test_and_clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
L
Linus Torvalds 已提交
1116
			++count;
1117
		ide_tape_discard_merge_buffer(drive, 0);
L
Linus Torvalds 已提交
1118 1119 1120
	}

	switch (mt_op) {
1121 1122 1123 1124
	case MTFSF:
	case MTBSF:
		idetape_create_space_cmd(&pc, mt_count - count,
					 IDETAPE_SPACE_OVER_FILEMARK);
1125
		return ide_queue_pc_tail(drive, disk, &pc);
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
	case MTFSFM:
	case MTBSFM:
		if (!sprev)
			return -EIO;
		retval = idetape_space_over_filemarks(drive, MTFSF,
						      mt_count - count);
		if (retval)
			return retval;
		count = (MTBSFM == mt_op ? 1 : -1);
		return idetape_space_over_filemarks(drive, MTFSF, count);
	default:
		printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",
				mt_op);
		return -EIO;
L
Linus Torvalds 已提交
1140 1141 1142 1143
	}
}

/*
1144
 * Our character device read / write functions.
L
Linus Torvalds 已提交
1145
 *
1146 1147 1148
 * The tape is optimized to maximize throughput when it is transferring an
 * integral number of the "continuous transfer limit", which is a parameter of
 * the specific tape (26kB on my particular tape, 32kB for Onstream).
L
Linus Torvalds 已提交
1149
 *
1150 1151 1152 1153 1154 1155 1156
 * As of version 1.3 of the driver, the character device provides an abstract
 * continuous view of the media - any mix of block sizes (even 1 byte) on the
 * same backup/restore procedure is supported. The driver will internally
 * convert the requests to the recommended transfer unit, so that an unmatch
 * between the user's block size to the recommended size will only result in a
 * (slightly) increased driver overhead, but will no longer hit performance.
 * This is not applicable to Onstream.
L
Linus Torvalds 已提交
1157
 */
1158 1159
static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
				   size_t count, loff_t *ppos)
L
Linus Torvalds 已提交
1160
{
B
Borislav Petkov 已提交
1161
	struct ide_tape_obj *tape = file->private_data;
L
Linus Torvalds 已提交
1162
	ide_drive_t *drive = tape->drive;
1163
	size_t done = 0;
1164
	ssize_t ret = 0;
1165
	int rc;
L
Linus Torvalds 已提交
1166

1167
	debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
L
Linus Torvalds 已提交
1168

1169
	if (tape->chrdev_dir != IDETAPE_DIR_READ) {
1170
		if (test_bit(IDE_AFLAG_DETECT_BS, &drive->atapi_flags))
1171 1172 1173
			if (count > tape->blk_size &&
			    (count % tape->blk_size) == 0)
				tape->user_bs_factor = count / tape->blk_size;
L
Linus Torvalds 已提交
1174
	}
1175

T
Tejun Heo 已提交
1176
	rc = idetape_init_rw(drive, IDETAPE_DIR_READ);
1177
	if (rc < 0)
L
Linus Torvalds 已提交
1178
		return rc;
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196

	while (done < count) {
		size_t todo;

		/* refill if staging buffer is empty */
		if (!tape->valid) {
			/* If we are at a filemark, nothing more to read */
			if (test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
				break;
			/* read */
			if (idetape_queue_rw_tail(drive, REQ_IDETAPE_READ,
						  tape->buffer_size) <= 0)
				break;
		}

		/* copy out */
		todo = min_t(size_t, count - done, tape->valid);
		if (copy_to_user(buf + done, tape->cur, todo))
1197
			ret = -EFAULT;
1198 1199 1200 1201

		tape->cur += todo;
		tape->valid -= todo;
		done += todo;
L
Linus Torvalds 已提交
1202
	}
1203 1204

	if (!done && test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) {
1205 1206
		debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name);

L
Linus Torvalds 已提交
1207 1208 1209
		idetape_space_over_filemarks(drive, MTFSF, 1);
		return 0;
	}
1210

1211
	return ret ? ret : done;
L
Linus Torvalds 已提交
1212 1213
}

1214
static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
L
Linus Torvalds 已提交
1215 1216
				     size_t count, loff_t *ppos)
{
B
Borislav Petkov 已提交
1217
	struct ide_tape_obj *tape = file->private_data;
L
Linus Torvalds 已提交
1218
	ide_drive_t *drive = tape->drive;
1219
	size_t done = 0;
1220
	ssize_t ret = 0;
T
Tejun Heo 已提交
1221
	int rc;
L
Linus Torvalds 已提交
1222 1223 1224 1225 1226

	/* The drive is write protected. */
	if (tape->write_prot)
		return -EACCES;

1227
	debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
L
Linus Torvalds 已提交
1228 1229

	/* Initialize write operation */
T
Tejun Heo 已提交
1230 1231 1232
	rc = idetape_init_rw(drive, IDETAPE_DIR_WRITE);
	if (rc < 0)
		return rc;
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246

	while (done < count) {
		size_t todo;

		/* flush if staging buffer is full */
		if (tape->valid == tape->buffer_size &&
		    idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE,
					  tape->buffer_size) <= 0)
			return rc;

		/* copy in */
		todo = min_t(size_t, count - done,
			     tape->buffer_size - tape->valid);
		if (copy_from_user(tape->cur, buf + done, todo))
1247
			ret = -EFAULT;
1248 1249 1250 1251

		tape->cur += todo;
		tape->valid += todo;
		done += todo;
L
Linus Torvalds 已提交
1252
	}
1253 1254

	return ret ? ret : done;
L
Linus Torvalds 已提交
1255 1256
}

1257
static int idetape_write_filemark(ide_drive_t *drive)
L
Linus Torvalds 已提交
1258
{
1259
	struct ide_tape_obj *tape = drive->driver_data;
1260
	struct ide_atapi_pc pc;
L
Linus Torvalds 已提交
1261 1262 1263

	/* Write a filemark */
	idetape_create_write_filemark_cmd(drive, &pc, 1);
1264
	if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
L
Linus Torvalds 已提交
1265 1266 1267 1268 1269 1270 1271
		printk(KERN_ERR "ide-tape: Couldn't write a filemark\n");
		return -EIO;
	}
	return 0;
}

/*
1272 1273
 * Called from idetape_chrdev_ioctl when the general mtio MTIOCTOP ioctl is
 * requested.
L
Linus Torvalds 已提交
1274
 *
1275 1276
 * Note: MTBSF and MTBSFM are not supported when the tape doesn't support
 * spacing over filemarks in the reverse direction. In this case, MTFSFM is also
1277
 * usually not supported.
L
Linus Torvalds 已提交
1278
 *
1279
 * The following commands are currently not supported:
L
Linus Torvalds 已提交
1280
 *
1281 1282
 * MTFSS, MTBSS, MTWSM, MTSETDENSITY, MTSETDRVBUFFER, MT_ST_BOOLEANS,
 * MT_ST_WRITE_THRESHOLD.
L
Linus Torvalds 已提交
1283
 */
1284
static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
L
Linus Torvalds 已提交
1285 1286
{
	idetape_tape_t *tape = drive->driver_data;
1287
	struct gendisk *disk = tape->disk;
1288
	struct ide_atapi_pc pc;
1289
	int i, retval;
L
Linus Torvalds 已提交
1290

1291 1292
	debug_log(DBG_ERR, "Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n",
			mt_op, mt_count);
1293

L
Linus Torvalds 已提交
1294
	switch (mt_op) {
1295 1296 1297 1298 1299 1300 1301 1302 1303
	case MTFSF:
	case MTFSFM:
	case MTBSF:
	case MTBSFM:
		if (!mt_count)
			return 0;
		return idetape_space_over_filemarks(drive, mt_op, mt_count);
	default:
		break;
L
Linus Torvalds 已提交
1304
	}
1305

L
Linus Torvalds 已提交
1306
	switch (mt_op) {
1307 1308 1309
	case MTWEOF:
		if (tape->write_prot)
			return -EACCES;
1310
		ide_tape_discard_merge_buffer(drive, 1);
1311 1312 1313 1314 1315 1316 1317
		for (i = 0; i < mt_count; i++) {
			retval = idetape_write_filemark(drive);
			if (retval)
				return retval;
		}
		return 0;
	case MTREW:
1318
		ide_tape_discard_merge_buffer(drive, 0);
1319 1320 1321 1322
		if (idetape_rewind_tape(drive))
			return -EIO;
		return 0;
	case MTLOAD:
1323
		ide_tape_discard_merge_buffer(drive, 0);
1324
		return ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK);
1325 1326 1327 1328 1329 1330 1331
	case MTUNLOAD:
	case MTOFFL:
		/*
		 * If door is locked, attempt to unlock before
		 * attempting to eject.
		 */
		if (tape->door_locked) {
1332
			if (!ide_set_media_lock(drive, disk, 0))
1333
				tape->door_locked = DOOR_UNLOCKED;
1334
		}
1335
		ide_tape_discard_merge_buffer(drive, 0);
1336
		retval = ide_do_start_stop(drive, disk, !IDETAPE_LU_LOAD_MASK);
1337
		if (!retval)
1338
			clear_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags);
1339 1340
		return retval;
	case MTNOP:
1341
		ide_tape_discard_merge_buffer(drive, 0);
1342 1343
		return idetape_flush_tape_buffers(drive);
	case MTRETEN:
1344
		ide_tape_discard_merge_buffer(drive, 0);
1345
		return ide_do_start_stop(drive, disk,
1346 1347 1348
			IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
	case MTEOM:
		idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD);
1349
		return ide_queue_pc_tail(drive, disk, &pc);
1350 1351 1352
	case MTERASE:
		(void)idetape_rewind_tape(drive);
		idetape_create_erase_cmd(&pc);
1353
		return ide_queue_pc_tail(drive, disk, &pc);
1354 1355 1356 1357
	case MTSETBLK:
		if (mt_count) {
			if (mt_count < tape->blk_size ||
			    mt_count % tape->blk_size)
L
Linus Torvalds 已提交
1358
				return -EIO;
1359
			tape->user_bs_factor = mt_count / tape->blk_size;
1360
			clear_bit(IDE_AFLAG_DETECT_BS, &drive->atapi_flags);
1361
		} else
1362
			set_bit(IDE_AFLAG_DETECT_BS, &drive->atapi_flags);
1363 1364
		return 0;
	case MTSEEK:
1365
		ide_tape_discard_merge_buffer(drive, 0);
1366 1367 1368
		return idetape_position_tape(drive,
			mt_count * tape->user_bs_factor, tape->partition, 0);
	case MTSETPART:
1369
		ide_tape_discard_merge_buffer(drive, 0);
1370 1371 1372 1373
		return idetape_position_tape(drive, 0, mt_count, 0);
	case MTFSR:
	case MTBSR:
	case MTLOCK:
1374
		retval = ide_set_media_lock(drive, disk, 1);
1375
		if (retval)
L
Linus Torvalds 已提交
1376
			return retval;
1377 1378 1379
		tape->door_locked = DOOR_EXPLICITLY_LOCKED;
		return 0;
	case MTUNLOCK:
1380
		retval = ide_set_media_lock(drive, disk, 0);
1381 1382 1383 1384 1385 1386 1387 1388
		if (retval)
			return retval;
		tape->door_locked = DOOR_UNLOCKED;
		return 0;
	default:
		printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",
				mt_op);
		return -EIO;
L
Linus Torvalds 已提交
1389 1390 1391 1392
	}
}

/*
1393 1394 1395
 * Our character device ioctls. General mtio.h magnetic io commands are
 * supported here, and not in the corresponding block interface. Our own
 * ide-tape ioctls are supported on both interfaces.
L
Linus Torvalds 已提交
1396
 */
1397 1398
static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
				unsigned int cmd, unsigned long arg)
L
Linus Torvalds 已提交
1399
{
B
Borislav Petkov 已提交
1400
	struct ide_tape_obj *tape = file->private_data;
L
Linus Torvalds 已提交
1401 1402 1403 1404
	ide_drive_t *drive = tape->drive;
	struct mtop mtop;
	struct mtget mtget;
	struct mtpos mtpos;
1405
	int block_offset = 0, position = tape->first_frame;
L
Linus Torvalds 已提交
1406 1407
	void __user *argp = (void __user *)arg;

1408
	debug_log(DBG_CHRDEV, "Enter %s, cmd=%u\n", __func__, cmd);
L
Linus Torvalds 已提交
1409

1410
	if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
1411
		ide_tape_flush_merge_buffer(drive);
L
Linus Torvalds 已提交
1412 1413 1414
		idetape_flush_tape_buffers(drive);
	}
	if (cmd == MTIOCGET || cmd == MTIOCPOS) {
T
Tejun Heo 已提交
1415
		block_offset = tape->valid /
1416
			(tape->blk_size * tape->user_bs_factor);
1417 1418
		position = idetape_read_position(drive);
		if (position < 0)
L
Linus Torvalds 已提交
1419 1420 1421
			return -EIO;
	}
	switch (cmd) {
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
	case MTIOCTOP:
		if (copy_from_user(&mtop, argp, sizeof(struct mtop)))
			return -EFAULT;
		return idetape_mtioctop(drive, mtop.mt_op, mtop.mt_count);
	case MTIOCGET:
		memset(&mtget, 0, sizeof(struct mtget));
		mtget.mt_type = MT_ISSCSI2;
		mtget.mt_blkno = position / tape->user_bs_factor - block_offset;
		mtget.mt_dsreg =
			((tape->blk_size * tape->user_bs_factor)
			 << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK;

		if (tape->drv_write_prot)
			mtget.mt_gstat |= GMT_WR_PROT(0xffffffff);

		if (copy_to_user(argp, &mtget, sizeof(struct mtget)))
			return -EFAULT;
		return 0;
	case MTIOCPOS:
		mtpos.mt_blkno = position / tape->user_bs_factor - block_offset;
		if (copy_to_user(argp, &mtpos, sizeof(struct mtpos)))
			return -EFAULT;
		return 0;
	default:
		if (tape->chrdev_dir == IDETAPE_DIR_READ)
1447
			ide_tape_discard_merge_buffer(drive, 1);
1448
		return idetape_blkdev_ioctl(drive, cmd, arg);
L
Linus Torvalds 已提交
1449 1450 1451
	}
}

1452 1453 1454 1455 1456 1457 1458
/*
 * Do a mode sense page 0 with block descriptor and if it succeeds set the tape
 * block size with the reported value.
 */
static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
{
	idetape_tape_t *tape = drive->driver_data;
1459
	struct ide_atapi_pc pc;
1460 1461

	idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR);
1462
	if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
1463
		printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
1464
		if (tape->blk_size == 0) {
1465 1466
			printk(KERN_WARNING "ide-tape: Cannot deal with zero "
					    "block size, assuming 32k\n");
1467
			tape->blk_size = 32768;
1468 1469 1470
		}
		return;
	}
1471 1472 1473 1474
	tape->blk_size = (pc.buf[4 + 5] << 16) +
				(pc.buf[4 + 6] << 8)  +
				 pc.buf[4 + 7];
	tape->drv_write_prot = (pc.buf[2] & 0x80) >> 7;
1475
}
L
Linus Torvalds 已提交
1476

1477
static int idetape_chrdev_open(struct inode *inode, struct file *filp)
L
Linus Torvalds 已提交
1478 1479 1480 1481 1482 1483
{
	unsigned int minor = iminor(inode), i = minor & ~0xc0;
	ide_drive_t *drive;
	idetape_tape_t *tape;
	int retval;

1484 1485 1486
	if (i >= MAX_HWIFS * MAX_DRIVES)
		return -ENXIO;

1487
	lock_kernel();
1488
	tape = ide_tape_chrdev_get(i);
1489 1490
	if (!tape) {
		unlock_kernel();
1491
		return -ENXIO;
1492
	}
1493 1494 1495

	debug_log(DBG_CHRDEV, "Enter %s\n", __func__);

L
Linus Torvalds 已提交
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506
	/*
	 * We really want to do nonseekable_open(inode, filp); here, but some
	 * versions of tar incorrectly call lseek on tapes and bail out if that
	 * fails.  So we disallow pread() and pwrite(), but permit lseeks.
	 */
	filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE);

	drive = tape->drive;

	filp->private_data = tape;

1507
	if (test_and_set_bit(IDE_AFLAG_BUSY, &drive->atapi_flags)) {
L
Linus Torvalds 已提交
1508 1509 1510 1511 1512 1513
		retval = -EBUSY;
		goto out_put_tape;
	}

	retval = idetape_wait_ready(drive, 60 * HZ);
	if (retval) {
1514
		clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
L
Linus Torvalds 已提交
1515 1516 1517 1518 1519
		printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name);
		goto out_put_tape;
	}

	idetape_read_position(drive);
1520
	if (!test_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags))
L
Linus Torvalds 已提交
1521 1522 1523
		(void)idetape_rewind_tape(drive);

	/* Read block size and write protect status from drive. */
1524
	ide_tape_get_bsize_from_bdesc(drive);
L
Linus Torvalds 已提交
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535

	/* Set write protect flag if device is opened as read-only. */
	if ((filp->f_flags & O_ACCMODE) == O_RDONLY)
		tape->write_prot = 1;
	else
		tape->write_prot = tape->drv_write_prot;

	/* Make sure drive isn't write protected if user wants to write. */
	if (tape->write_prot) {
		if ((filp->f_flags & O_ACCMODE) == O_WRONLY ||
		    (filp->f_flags & O_ACCMODE) == O_RDWR) {
1536
			clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
L
Linus Torvalds 已提交
1537 1538 1539 1540 1541
			retval = -EROFS;
			goto out_put_tape;
		}
	}

1542
	/* Lock the tape drive door so user can't eject. */
1543
	if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
1544
		if (!ide_set_media_lock(drive, tape->disk, 1)) {
1545 1546
			if (tape->door_locked != DOOR_EXPLICITLY_LOCKED)
				tape->door_locked = DOOR_LOCKED;
L
Linus Torvalds 已提交
1547 1548
		}
	}
1549
	unlock_kernel();
L
Linus Torvalds 已提交
1550 1551 1552 1553
	return 0;

out_put_tape:
	ide_tape_put(tape);
1554
	unlock_kernel();
L
Linus Torvalds 已提交
1555 1556 1557
	return retval;
}

1558
static void idetape_write_release(ide_drive_t *drive, unsigned int minor)
L
Linus Torvalds 已提交
1559 1560 1561
{
	idetape_tape_t *tape = drive->driver_data;

1562
	ide_tape_flush_merge_buffer(drive);
T
Tejun Heo 已提交
1563 1564
	tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
	if (tape->buf != NULL) {
1565 1566
		idetape_pad_zeros(drive, tape->blk_size *
				(tape->user_bs_factor - 1));
T
Tejun Heo 已提交
1567 1568
		kfree(tape->buf);
		tape->buf = NULL;
L
Linus Torvalds 已提交
1569 1570 1571 1572 1573 1574
	}
	idetape_write_filemark(drive);
	idetape_flush_tape_buffers(drive);
	idetape_flush_tape_buffers(drive);
}

1575
static int idetape_chrdev_release(struct inode *inode, struct file *filp)
L
Linus Torvalds 已提交
1576
{
B
Borislav Petkov 已提交
1577
	struct ide_tape_obj *tape = filp->private_data;
L
Linus Torvalds 已提交
1578 1579 1580 1581 1582
	ide_drive_t *drive = tape->drive;
	unsigned int minor = iminor(inode);

	lock_kernel();
	tape = drive->driver_data;
1583 1584

	debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
L
Linus Torvalds 已提交
1585

1586
	if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
L
Linus Torvalds 已提交
1587
		idetape_write_release(drive, minor);
1588
	if (tape->chrdev_dir == IDETAPE_DIR_READ) {
L
Linus Torvalds 已提交
1589
		if (minor < 128)
1590
			ide_tape_discard_merge_buffer(drive, 1);
L
Linus Torvalds 已提交
1591
	}
1592

1593
	if (minor < 128 && test_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags))
L
Linus Torvalds 已提交
1594
		(void) idetape_rewind_tape(drive);
1595
	if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
L
Linus Torvalds 已提交
1596
		if (tape->door_locked == DOOR_LOCKED) {
1597
			if (!ide_set_media_lock(drive, tape->disk, 0))
1598
				tape->door_locked = DOOR_UNLOCKED;
L
Linus Torvalds 已提交
1599 1600
		}
	}
1601
	clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
L
Linus Torvalds 已提交
1602 1603 1604 1605 1606
	ide_tape_put(tape);
	unlock_kernel();
	return 0;
}

1607
static void idetape_get_inquiry_results(ide_drive_t *drive)
L
Linus Torvalds 已提交
1608 1609
{
	idetape_tape_t *tape = drive->driver_data;
1610
	struct ide_atapi_pc pc;
1611
	u8 pc_buf[256];
B
Borislav Petkov 已提交
1612
	char fw_rev[4], vendor_id[8], product_id[16];
1613

L
Linus Torvalds 已提交
1614
	idetape_create_inquiry_cmd(&pc);
1615 1616 1617
	pc.buf = &pc_buf[0];
	pc.buf_size = sizeof(pc_buf);

1618
	if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
1619 1620
		printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n",
				tape->name);
L
Linus Torvalds 已提交
1621 1622
		return;
	}
1623 1624 1625
	memcpy(vendor_id, &pc.buf[8], 8);
	memcpy(product_id, &pc.buf[16], 16);
	memcpy(fw_rev, &pc.buf[32], 4);
1626

B
Borislav Petkov 已提交
1627 1628 1629
	ide_fixstring(vendor_id, 8, 0);
	ide_fixstring(product_id, 16, 0);
	ide_fixstring(fw_rev, 4, 0);
1630

B
Borislav Petkov 已提交
1631
	printk(KERN_INFO "ide-tape: %s <-> %s: %.8s %.16s rev %.4s\n",
1632
			drive->name, tape->name, vendor_id, product_id, fw_rev);
L
Linus Torvalds 已提交
1633 1634 1635
}

/*
1636 1637
 * Ask the tape about its various parameters. In particular, we will adjust our
 * data transfer buffer	size to the recommended value as returned by the tape.
L
Linus Torvalds 已提交
1638
 */
1639
static void idetape_get_mode_sense_results(ide_drive_t *drive)
L
Linus Torvalds 已提交
1640 1641
{
	idetape_tape_t *tape = drive->driver_data;
1642
	struct ide_atapi_pc pc;
1643 1644
	u8 *caps;
	u8 speed, max_speed;
1645

L
Linus Torvalds 已提交
1646
	idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE);
1647
	if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
1648 1649
		printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming"
				" some default values\n");
1650
		tape->blk_size = 512;
1651 1652 1653
		put_unaligned(52,   (u16 *)&tape->caps[12]);
		put_unaligned(540,  (u16 *)&tape->caps[14]);
		put_unaligned(6*52, (u16 *)&tape->caps[16]);
L
Linus Torvalds 已提交
1654 1655
		return;
	}
1656
	caps = pc.buf + 4 + pc.buf[3];
1657 1658

	/* convert to host order and save for later use */
1659 1660
	speed = be16_to_cpup((__be16 *)&caps[14]);
	max_speed = be16_to_cpup((__be16 *)&caps[8]);
L
Linus Torvalds 已提交
1661

1662 1663 1664 1665
	*(u16 *)&caps[8] = max_speed;
	*(u16 *)&caps[12] = be16_to_cpup((__be16 *)&caps[12]);
	*(u16 *)&caps[14] = speed;
	*(u16 *)&caps[16] = be16_to_cpup((__be16 *)&caps[16]);
L
Linus Torvalds 已提交
1666

1667 1668 1669
	if (!speed) {
		printk(KERN_INFO "ide-tape: %s: invalid tape speed "
				"(assuming 650KB/sec)\n", drive->name);
1670
		*(u16 *)&caps[14] = 650;
L
Linus Torvalds 已提交
1671
	}
1672 1673 1674
	if (!max_speed) {
		printk(KERN_INFO "ide-tape: %s: invalid max_speed "
				"(assuming 650KB/sec)\n", drive->name);
1675
		*(u16 *)&caps[8] = 650;
L
Linus Torvalds 已提交
1676 1677
	}

1678
	memcpy(&tape->caps, caps, 20);
1679 1680 1681

	/* device lacks locking support according to capabilities page */
	if ((caps[6] & 1) == 0)
1682
		drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
1683

1684
	if (caps[7] & 0x02)
1685
		tape->blk_size = 512;
1686
	else if (caps[7] & 0x04)
1687
		tape->blk_size = 1024;
L
Linus Torvalds 已提交
1688 1689
}

1690
#ifdef CONFIG_IDE_PROC_FS
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
#define ide_tape_devset_get(name, field) \
static int get_##name(ide_drive_t *drive) \
{ \
	idetape_tape_t *tape = drive->driver_data; \
	return tape->field; \
}

#define ide_tape_devset_set(name, field) \
static int set_##name(ide_drive_t *drive, int arg) \
{ \
	idetape_tape_t *tape = drive->driver_data; \
	tape->field = arg; \
	return 0; \
}

1706
#define ide_tape_devset_rw_field(_name, _field) \
1707 1708
ide_tape_devset_get(_name, _field) \
ide_tape_devset_set(_name, _field) \
1709
IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name)
1710

1711
#define ide_tape_devset_r_field(_name, _field) \
1712
ide_tape_devset_get(_name, _field) \
1713
IDE_DEVSET(_name, 0, get_##_name, NULL)
1714 1715 1716 1717 1718 1719

static int mulf_tdsc(ide_drive_t *drive)	{ return 1000; }
static int divf_tdsc(ide_drive_t *drive)	{ return   HZ; }
static int divf_buffer(ide_drive_t *drive)	{ return    2; }
static int divf_buffer_size(ide_drive_t *drive)	{ return 1024; }

B
Bartlomiej Zolnierkiewicz 已提交
1720
ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738

ide_tape_devset_rw_field(debug_mask, debug_mask);
ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq);

ide_tape_devset_r_field(avg_speed, avg_speed);
ide_tape_devset_r_field(speed, caps[14]);
ide_tape_devset_r_field(buffer, caps[16]);
ide_tape_devset_r_field(buffer_size, buffer_size);

static const struct ide_proc_devset idetape_settings[] = {
	__IDE_PROC_DEVSET(avg_speed,	0, 0xffff, NULL, NULL),
	__IDE_PROC_DEVSET(buffer,	0, 0xffff, NULL, divf_buffer),
	__IDE_PROC_DEVSET(buffer_size,	0, 0xffff, NULL, divf_buffer_size),
	__IDE_PROC_DEVSET(debug_mask,	0, 0xffff, NULL, NULL),
	__IDE_PROC_DEVSET(dsc_overlap,	0,      1, NULL, NULL),
	__IDE_PROC_DEVSET(speed,	0, 0xffff, NULL, NULL),
	__IDE_PROC_DEVSET(tdsc,		IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX,
					mulf_tdsc, divf_tdsc),
1739
	{ NULL },
1740
};
1741
#endif
L
Linus Torvalds 已提交
1742 1743

/*
1744
 * The function below is called to:
L
Linus Torvalds 已提交
1745
 *
1746 1747 1748 1749
 * 1. Initialize our various state variables.
 * 2. Ask the tape for its capabilities.
 * 3. Allocate a buffer which will be used for data transfer. The buffer size
 * is chosen based on the recommendation which we received in step 2.
L
Linus Torvalds 已提交
1750
 *
1751 1752
 * Note that at this point ide.c already assigned us an irq, so that we can
 * queue requests here and wait for their completion.
L
Linus Torvalds 已提交
1753
 */
1754
static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
L
Linus Torvalds 已提交
1755
{
1756
	unsigned long t;
L
Linus Torvalds 已提交
1757
	int speed;
1758
	int buffer_size;
1759
	u16 *ctl = (u16 *)&tape->caps[12];
L
Linus Torvalds 已提交
1760

1761
	drive->pc_callback	 = ide_tape_callback;
1762

B
Bartlomiej Zolnierkiewicz 已提交
1763 1764
	drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;

1765 1766 1767
	if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) {
		printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n",
				 tape->name);
B
Bartlomiej Zolnierkiewicz 已提交
1768
		drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
L
Linus Torvalds 已提交
1769
	}
B
Bartlomiej Zolnierkiewicz 已提交
1770

L
Linus Torvalds 已提交
1771
	/* Seagate Travan drives do not support DSC overlap. */
1772
	if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401"))
B
Bartlomiej Zolnierkiewicz 已提交
1773 1774
		drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;

L
Linus Torvalds 已提交
1775 1776 1777 1778
	tape->minor = minor;
	tape->name[0] = 'h';
	tape->name[1] = 't';
	tape->name[2] = '0' + minor;
1779
	tape->chrdev_dir = IDETAPE_DIR_NONE;
1780

L
Linus Torvalds 已提交
1781 1782
	idetape_get_inquiry_results(drive);
	idetape_get_mode_sense_results(drive);
1783
	ide_tape_get_bsize_from_bdesc(drive);
L
Linus Torvalds 已提交
1784
	tape->user_bs_factor = 1;
1785 1786
	tape->buffer_size = *ctl * tape->blk_size;
	while (tape->buffer_size > 0xffff) {
L
Linus Torvalds 已提交
1787
		printk(KERN_NOTICE "ide-tape: decreasing stage size\n");
1788
		*ctl /= 2;
1789
		tape->buffer_size = *ctl * tape->blk_size;
L
Linus Torvalds 已提交
1790
	}
1791
	buffer_size = tape->buffer_size;
L
Linus Torvalds 已提交
1792

1793
	/* select the "best" DSC read/write polling freq */
1794
	speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]);
L
Linus Torvalds 已提交
1795

1796
	t = (IDETAPE_FIFO_THRESHOLD * tape->buffer_size * HZ) / (speed * 1000);
L
Linus Torvalds 已提交
1797 1798

	/*
1799 1800
	 * Ensure that the number we got makes sense; limit it within
	 * IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX.
L
Linus Torvalds 已提交
1801
	 */
1802 1803
	tape->best_dsc_rw_freq = clamp_t(unsigned long, t, IDETAPE_DSC_RW_MIN,
					 IDETAPE_DSC_RW_MAX);
L
Linus Torvalds 已提交
1804
	printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, "
1805
		"%lums tDSC%s\n",
1806
		drive->name, tape->name, *(u16 *)&tape->caps[14],
1807 1808
		(*(u16 *)&tape->caps[16] * 512) / tape->buffer_size,
		tape->buffer_size / 1024,
1809
		tape->best_dsc_rw_freq * 1000 / HZ,
B
Bartlomiej Zolnierkiewicz 已提交
1810
		(drive->dev_flags & IDE_DFLAG_USING_DMA) ? ", DMA" : "");
L
Linus Torvalds 已提交
1811

1812
	ide_proc_register_driver(drive, tape->driver);
L
Linus Torvalds 已提交
1813 1814
}

1815
static void ide_tape_remove(ide_drive_t *drive)
L
Linus Torvalds 已提交
1816 1817 1818
{
	idetape_tape_t *tape = drive->driver_data;

1819
	ide_proc_unregister_driver(drive, tape->driver);
1820
	device_del(&tape->dev);
L
Linus Torvalds 已提交
1821 1822
	ide_unregister_region(tape->disk);

1823 1824 1825
	mutex_lock(&idetape_ref_mutex);
	put_device(&tape->dev);
	mutex_unlock(&idetape_ref_mutex);
L
Linus Torvalds 已提交
1826 1827
}

1828
static void ide_tape_release(struct device *dev)
L
Linus Torvalds 已提交
1829
{
1830
	struct ide_tape_obj *tape = to_ide_drv(dev, ide_tape_obj);
L
Linus Torvalds 已提交
1831 1832 1833
	ide_drive_t *drive = tape->drive;
	struct gendisk *g = tape->disk;

T
Tejun Heo 已提交
1834
	BUG_ON(tape->valid);
1835

B
Bartlomiej Zolnierkiewicz 已提交
1836
	drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
L
Linus Torvalds 已提交
1837
	drive->driver_data = NULL;
1838
	device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor));
1839 1840
	device_destroy(idetape_sysfs_class,
			MKDEV(IDETAPE_MAJOR, tape->minor + 128));
L
Linus Torvalds 已提交
1841 1842 1843 1844 1845 1846
	idetape_devs[tape->minor] = NULL;
	g->private_data = NULL;
	put_disk(g);
	kfree(tape);
}

1847
#ifdef CONFIG_IDE_PROC_FS
L
Linus Torvalds 已提交
1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
static int proc_idetape_read_name
	(char *page, char **start, off_t off, int count, int *eof, void *data)
{
	ide_drive_t	*drive = (ide_drive_t *) data;
	idetape_tape_t	*tape = drive->driver_data;
	char		*out = page;
	int		len;

	len = sprintf(out, "%s\n", tape->name);
	PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
}

static ide_proc_entry_t idetape_proc[] = {
	{ "capacity",	S_IFREG|S_IRUGO,	proc_ide_read_capacity, NULL },
	{ "name",	S_IFREG|S_IRUGO,	proc_idetape_read_name,	NULL },
	{ NULL, 0, NULL, NULL }
};
1865 1866 1867 1868 1869 1870 1871 1872 1873 1874

static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive)
{
	return idetape_proc;
}

static const struct ide_proc_devset *ide_tape_proc_devsets(ide_drive_t *drive)
{
	return idetape_settings;
}
L
Linus Torvalds 已提交
1875 1876
#endif

1877
static int ide_tape_probe(ide_drive_t *);
L
Linus Torvalds 已提交
1878

1879
static struct ide_driver idetape_driver = {
1880
	.gen_driver = {
1881
		.owner		= THIS_MODULE,
1882 1883 1884
		.name		= "ide-tape",
		.bus		= &ide_bus_type,
	},
1885 1886
	.probe			= ide_tape_probe,
	.remove			= ide_tape_remove,
L
Linus Torvalds 已提交
1887 1888
	.version		= IDETAPE_VERSION,
	.do_request		= idetape_do_request,
1889
#ifdef CONFIG_IDE_PROC_FS
1890 1891
	.proc_entries		= ide_tape_proc_entries,
	.proc_devsets		= ide_tape_proc_devsets,
1892
#endif
L
Linus Torvalds 已提交
1893 1894
};

1895
/* Our character device supporting functions, passed to register_chrdev. */
1896
static const struct file_operations idetape_fops = {
L
Linus Torvalds 已提交
1897 1898 1899 1900 1901 1902 1903 1904
	.owner		= THIS_MODULE,
	.read		= idetape_chrdev_read,
	.write		= idetape_chrdev_write,
	.ioctl		= idetape_chrdev_ioctl,
	.open		= idetape_chrdev_open,
	.release	= idetape_chrdev_release,
};

A
Al Viro 已提交
1905
static int idetape_open(struct block_device *bdev, fmode_t mode)
L
Linus Torvalds 已提交
1906
{
A
Al Viro 已提交
1907
	struct ide_tape_obj *tape = ide_tape_get(bdev->bd_disk);
L
Linus Torvalds 已提交
1908

1909
	if (!tape)
L
Linus Torvalds 已提交
1910 1911 1912 1913 1914
		return -ENXIO;

	return 0;
}

A
Al Viro 已提交
1915
static int idetape_release(struct gendisk *disk, fmode_t mode)
L
Linus Torvalds 已提交
1916
{
B
Borislav Petkov 已提交
1917
	struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
L
Linus Torvalds 已提交
1918 1919 1920 1921 1922

	ide_tape_put(tape);
	return 0;
}

A
Al Viro 已提交
1923
static int idetape_ioctl(struct block_device *bdev, fmode_t mode,
L
Linus Torvalds 已提交
1924 1925
			unsigned int cmd, unsigned long arg)
{
B
Borislav Petkov 已提交
1926
	struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj);
L
Linus Torvalds 已提交
1927
	ide_drive_t *drive = tape->drive;
1928
	int err = generic_ide_ioctl(drive, bdev, cmd, arg);
L
Linus Torvalds 已提交
1929 1930 1931 1932 1933 1934 1935
	if (err == -EINVAL)
		err = idetape_blkdev_ioctl(drive, cmd, arg);
	return err;
}

static struct block_device_operations idetape_block_ops = {
	.owner		= THIS_MODULE,
A
Al Viro 已提交
1936 1937 1938
	.open		= idetape_open,
	.release	= idetape_release,
	.locked_ioctl	= idetape_ioctl,
L
Linus Torvalds 已提交
1939 1940
};

1941
static int ide_tape_probe(ide_drive_t *drive)
L
Linus Torvalds 已提交
1942 1943 1944 1945 1946 1947 1948
{
	idetape_tape_t *tape;
	struct gendisk *g;
	int minor;

	if (!strstr("ide-tape", drive->driver_req))
		goto failed;
1949

L
Linus Torvalds 已提交
1950 1951
	if (drive->media != ide_tape)
		goto failed;
1952

B
Bartlomiej Zolnierkiewicz 已提交
1953 1954
	if ((drive->dev_flags & IDE_DFLAG_ID_READ) &&
	    ide_check_atapi_device(drive, DRV_NAME) == 0) {
1955 1956
		printk(KERN_ERR "ide-tape: %s: not supported by this version of"
				" the driver\n", drive->name);
L
Linus Torvalds 已提交
1957 1958
		goto failed;
	}
1959
	tape = kzalloc(sizeof(idetape_tape_t), GFP_KERNEL);
L
Linus Torvalds 已提交
1960
	if (tape == NULL) {
1961 1962
		printk(KERN_ERR "ide-tape: %s: Can't allocate a tape struct\n",
				drive->name);
L
Linus Torvalds 已提交
1963 1964 1965 1966 1967 1968 1969 1970 1971
		goto failed;
	}

	g = alloc_disk(1 << PARTN_BITS);
	if (!g)
		goto out_free_tape;

	ide_init_disk(g, drive);

1972 1973 1974 1975 1976 1977
	tape->dev.parent = &drive->gendev;
	tape->dev.release = ide_tape_release;
	dev_set_name(&tape->dev, dev_name(&drive->gendev));

	if (device_register(&tape->dev))
		goto out_free_disk;
L
Linus Torvalds 已提交
1978 1979 1980 1981 1982 1983 1984 1985 1986

	tape->drive = drive;
	tape->driver = &idetape_driver;
	tape->disk = g;

	g->private_data = &tape->driver;

	drive->driver_data = tape;

1987
	mutex_lock(&idetape_ref_mutex);
L
Linus Torvalds 已提交
1988 1989 1990
	for (minor = 0; idetape_devs[minor]; minor++)
		;
	idetape_devs[minor] = tape;
1991
	mutex_unlock(&idetape_ref_mutex);
L
Linus Torvalds 已提交
1992 1993 1994

	idetape_setup(drive, tape, minor);

1995 1996 1997 1998 1999
	device_create(idetape_sysfs_class, &drive->gendev,
		      MKDEV(IDETAPE_MAJOR, minor), NULL, "%s", tape->name);
	device_create(idetape_sysfs_class, &drive->gendev,
		      MKDEV(IDETAPE_MAJOR, minor + 128), NULL,
		      "n%s", tape->name);
2000

L
Linus Torvalds 已提交
2001 2002 2003 2004
	g->fops = &idetape_block_ops;
	ide_register_region(g);

	return 0;
2005

2006 2007
out_free_disk:
	put_disk(g);
L
Linus Torvalds 已提交
2008 2009 2010
out_free_tape:
	kfree(tape);
failed:
2011
	return -ENODEV;
L
Linus Torvalds 已提交
2012 2013
}

2014
static void __exit idetape_exit(void)
L
Linus Torvalds 已提交
2015
{
2016
	driver_unregister(&idetape_driver.gen_driver);
2017
	class_destroy(idetape_sysfs_class);
L
Linus Torvalds 已提交
2018 2019 2020
	unregister_chrdev(IDETAPE_MAJOR, "ht");
}

2021
static int __init idetape_init(void)
L
Linus Torvalds 已提交
2022
{
2023 2024 2025 2026 2027 2028 2029 2030 2031
	int error = 1;
	idetape_sysfs_class = class_create(THIS_MODULE, "ide_tape");
	if (IS_ERR(idetape_sysfs_class)) {
		idetape_sysfs_class = NULL;
		printk(KERN_ERR "Unable to create sysfs class for ide tapes\n");
		error = -EBUSY;
		goto out;
	}

L
Linus Torvalds 已提交
2032
	if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) {
2033 2034
		printk(KERN_ERR "ide-tape: Failed to register chrdev"
				" interface\n");
2035 2036
		error = -EBUSY;
		goto out_free_class;
L
Linus Torvalds 已提交
2037
	}
2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050

	error = driver_register(&idetape_driver.gen_driver);
	if (error)
		goto out_free_driver;

	return 0;

out_free_driver:
	driver_unregister(&idetape_driver.gen_driver);
out_free_class:
	class_destroy(idetape_sysfs_class);
out:
	return error;
L
Linus Torvalds 已提交
2051 2052
}

2053
MODULE_ALIAS("ide:*m-tape*");
L
Linus Torvalds 已提交
2054 2055 2056
module_init(idetape_init);
module_exit(idetape_exit);
MODULE_ALIAS_CHARDEV_MAJOR(IDETAPE_MAJOR);
2057 2058
MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver");
MODULE_LICENSE("GPL");