1/*
2 *  drivers/s390/char/tape_34xx.c
3 *    tape device discipline for 3480/3490 tapes.
4 *
5 *    Copyright (C) IBM Corp. 2001,2006
6 *    Author(s): Carsten Otte <cotte@de.ibm.com>
7 *		 Tuan Ngo-Anh <ngoanh@de.ibm.com>
8 *		 Martin Schwidefsky <schwidefsky@de.ibm.com>
9 */
10
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/bio.h>
14#include <linux/workqueue.h>
15
16#define TAPE_DBF_AREA	tape_34xx_dbf
17
18#include "tape.h"
19#include "tape_std.h"
20
21#define PRINTK_HEADER "TAPE_34XX: "
22
23/*
24 * Pointer to debug area.
25 */
26debug_info_t *TAPE_DBF_AREA = NULL;
27EXPORT_SYMBOL(TAPE_DBF_AREA);
28
29#define TAPE34XX_FMT_3480	0
30#define TAPE34XX_FMT_3480_2_XF	1
31#define TAPE34XX_FMT_3480_XF	2
32
33struct tape_34xx_block_id {
34	unsigned int	wrap		: 1;
35	unsigned int	segment		: 7;
36	unsigned int	format		: 2;
37	unsigned int	block		: 22;
38};
39
40/*
41 * A list of block ID's is used to faster seek blocks.
42 */
43struct tape_34xx_sbid {
44	struct list_head		list;
45	struct tape_34xx_block_id	bid;
46};
47
48static void tape_34xx_delete_sbid_from(struct tape_device *, int);
49
50/*
51 * Medium sense for 34xx tapes. There is no 'real' medium sense call.
52 * So we just do a normal sense.
53 */
54static int
55tape_34xx_medium_sense(struct tape_device *device)
56{
57	struct tape_request *request;
58	unsigned char       *sense;
59	int                  rc;
60
61	request = tape_alloc_request(1, 32);
62	if (IS_ERR(request)) {
63		DBF_EXCEPTION(6, "MSEN fail\n");
64		return PTR_ERR(request);
65	}
66
67	request->op = TO_MSEN;
68	tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata);
69
70	rc = tape_do_io_interruptible(device, request);
71	if (request->rc == 0) {
72		sense = request->cpdata;
73
74		/*
75		 * This isn't quite correct. But since INTERVENTION_REQUIRED
76		 * means that the drive is 'neither ready nor on-line' it is
77		 * only slightly inaccurate to say there is no tape loaded if
78		 * the drive isn't online...
79		 */
80		if (sense[0] & SENSE_INTERVENTION_REQUIRED)
81			tape_med_state_set(device, MS_UNLOADED);
82		else
83			tape_med_state_set(device, MS_LOADED);
84
85		if (sense[1] & SENSE_WRITE_PROTECT)
86			device->tape_generic_status |= GMT_WR_PROT(~0);
87		else
88			device->tape_generic_status &= ~GMT_WR_PROT(~0);
89	} else {
90		DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
91			request->rc);
92	}
93	tape_free_request(request);
94
95	return rc;
96}
97
98struct tape_34xx_work {
99	struct tape_device	*device;
100	enum tape_op		 op;
101	struct work_struct	 work;
102};
103
104/*
105 * These functions are currently used only to schedule a medium_sense for
106 * later execution. This is because we get an interrupt whenever a medium
107 * is inserted but cannot call tape_do_io* from an interrupt context.
108 * Maybe that's useful for other actions we want to start from the
109 * interrupt handler.
110 */
111static void
112tape_34xx_work_handler(struct work_struct *work)
113{
114	struct tape_34xx_work *p =
115		container_of(work, struct tape_34xx_work, work);
116
117	switch(p->op) {
118		case TO_MSEN:
119			tape_34xx_medium_sense(p->device);
120			break;
121		default:
122			DBF_EVENT(3, "T34XX: internal error: unknown work\n");
123	}
124
125	p->device = tape_put_device(p->device);
126	kfree(p);
127}
128
129static int
130tape_34xx_schedule_work(struct tape_device *device, enum tape_op op)
131{
132	struct tape_34xx_work *p;
133
134	if ((p = kmalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
135		return -ENOMEM;
136
137	memset(p, 0, sizeof(*p));
138	INIT_WORK(&p->work, tape_34xx_work_handler);
139
140	p->device = tape_get_device_reference(device);
141	p->op     = op;
142
143	schedule_work(&p->work);
144	return 0;
145}
146
147/*
148 * Done Handler is called when dev stat = DEVICE-END (successful operation)
149 */
150static inline int
151tape_34xx_done(struct tape_request *request)
152{
153	DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
154
155	switch (request->op) {
156		case TO_DSE:
157		case TO_RUN:
158		case TO_WRI:
159		case TO_WTM:
160		case TO_ASSIGN:
161		case TO_UNASSIGN:
162			tape_34xx_delete_sbid_from(request->device, 0);
163			break;
164		default:
165			;
166	}
167	return TAPE_IO_SUCCESS;
168}
169
170static inline int
171tape_34xx_erp_failed(struct tape_request *request, int rc)
172{
173	DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
174		  tape_op_verbose[request->op], rc);
175	return rc;
176}
177
178static inline int
179tape_34xx_erp_succeeded(struct tape_request *request)
180{
181	DBF_EVENT(3, "Error Recovery successful for %s\n",
182		  tape_op_verbose[request->op]);
183	return tape_34xx_done(request);
184}
185
186static inline int
187tape_34xx_erp_retry(struct tape_request *request)
188{
189	DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose[request->op]);
190	return TAPE_IO_RETRY;
191}
192
193/*
194 * This function is called, when no request is outstanding and we get an
195 * interrupt
196 */
197static int
198tape_34xx_unsolicited_irq(struct tape_device *device, struct irb *irb)
199{
200	if (irb->scsw.dstat == 0x85 /* READY */) {
201		/* A medium was inserted in the drive. */
202		DBF_EVENT(6, "xuud med\n");
203		tape_34xx_delete_sbid_from(device, 0);
204		tape_34xx_schedule_work(device, TO_MSEN);
205	} else {
206		DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
207		PRINT_WARN("Unsolicited IRQ (Device End) caught.\n");
208		tape_dump_sense(device, NULL, irb);
209	}
210	return TAPE_IO_SUCCESS;
211}
212
213/*
214 * Read Opposite Error Recovery Function:
215 * Used, when Read Forward does not work
216 */
217static int
218tape_34xx_erp_read_opposite(struct tape_device *device,
219			    struct tape_request *request)
220{
221	if (request->op == TO_RFO) {
222		/*
223		 * We did read forward, but the data could not be read
224		 * *correctly*. We transform the request to a read backward
225		 * and try again.
226		 */
227		tape_std_read_backward(device, request);
228		return tape_34xx_erp_retry(request);
229	}
230	if (request->op != TO_RBA)
231		PRINT_ERR("read_opposite called with state:%s\n",
232			  tape_op_verbose[request->op]);
233	/*
234	 * We tried to read forward and backward, but hat no
235	 * success -> failed.
236	 */
237	return tape_34xx_erp_failed(request, -EIO);
238}
239
240static int
241tape_34xx_erp_bug(struct tape_device *device, struct tape_request *request,
242		  struct irb *irb, int no)
243{
244	if (request->op != TO_ASSIGN) {
245		PRINT_WARN("An unexpected condition #%d was caught in "
246			   "tape error recovery.\n", no);
247		PRINT_WARN("Please report this incident.\n");
248		if (request)
249			PRINT_WARN("Operation of tape:%s\n",
250				   tape_op_verbose[request->op]);
251		tape_dump_sense(device, request, irb);
252	}
253	return tape_34xx_erp_failed(request, -EIO);
254}
255
256/*
257 * Handle data overrun between cu and drive. The channel speed might
258 * be too slow.
259 */
260static int
261tape_34xx_erp_overrun(struct tape_device *device, struct tape_request *request,
262		      struct irb *irb)
263{
264	if (irb->ecw[3] == 0x40) {
265		PRINT_WARN ("Data overrun error between control-unit "
266			    "and drive. Use a faster channel connection, "
267			    "if possible! \n");
268		return tape_34xx_erp_failed(request, -EIO);
269	}
270	return tape_34xx_erp_bug(device, request, irb, -1);
271}
272
273/*
274 * Handle record sequence error.
275 */
276static int
277tape_34xx_erp_sequence(struct tape_device *device,
278		       struct tape_request *request, struct irb *irb)
279{
280	if (irb->ecw[3] == 0x41) {
281		/*
282		 * cu detected incorrect block-id sequence on tape.
283		 */
284		PRINT_WARN("Illegal block-id sequence found!\n");
285		return tape_34xx_erp_failed(request, -EIO);
286	}
287	/*
288	 * Record sequence error bit is set, but erpa does not
289	 * show record sequence error.
290	 */
291	return tape_34xx_erp_bug(device, request, irb, -2);
292}
293
294/*
295 * This function analyses the tape's sense-data in case of a unit-check.
296 * If possible, it tries to recover from the error. Else the user is
297 * informed about the problem.
298 */
299static int
300tape_34xx_unit_check(struct tape_device *device, struct tape_request *request,
301		     struct irb *irb)
302{
303	int inhibit_cu_recovery;
304	__u8* sense;
305
306	inhibit_cu_recovery = (*device->modeset_byte & 0x80) ? 1 : 0;
307	sense = irb->ecw;
308
309#ifdef CONFIG_S390_TAPE_BLOCK
310	if (request->op == TO_BLOCK) {
311		/*
312		 * Recovery for block device requests. Set the block_position
313		 * to something invalid and retry.
314		 */
315		device->blk_data.block_position = -1;
316		if (request->retries-- <= 0)
317			return tape_34xx_erp_failed(request, -EIO);
318		else
319			return tape_34xx_erp_retry(request);
320	}
321#endif
322
323	if (
324		sense[0] & SENSE_COMMAND_REJECT &&
325		sense[1] & SENSE_WRITE_PROTECT
326	) {
327		if (
328			request->op == TO_DSE ||
329			request->op == TO_WRI ||
330			request->op == TO_WTM
331		) {
332			/* medium is write protected */
333			return tape_34xx_erp_failed(request, -EACCES);
334		} else {
335			return tape_34xx_erp_bug(device, request, irb, -3);
336		}
337	}
338
339	if ((
340		sense[0] == SENSE_DATA_CHECK      ||
341		sense[0] == SENSE_EQUIPMENT_CHECK ||
342		sense[0] == SENSE_EQUIPMENT_CHECK + SENSE_DEFERRED_UNIT_CHECK
343	) && (
344		sense[1] == SENSE_DRIVE_ONLINE ||
345		sense[1] == SENSE_BEGINNING_OF_TAPE + SENSE_WRITE_MODE
346	)) {
347		switch (request->op) {
348		/*
349		 * sense[0] == SENSE_DATA_CHECK   &&
350		 * sense[1] == SENSE_DRIVE_ONLINE
351		 * sense[3] == 0x36 (End Of Data)
352		 *
353		 * Further seeks might return a 'Volume Fenced'.
354		 */
355		case TO_FSF:
356		case TO_FSB:
357			/* Trying to seek beyond end of recorded area */
358			return tape_34xx_erp_failed(request, -ENOSPC);
359		case TO_BSB:
360			return tape_34xx_erp_retry(request);
361
362		/*
363		 * sense[0] == SENSE_DATA_CHECK   &&
364		 * sense[1] == SENSE_DRIVE_ONLINE &&
365		 * sense[3] == 0x36 (End Of Data)
366		 */
367		case TO_LBL:
368			/* Block could not be located. */
369			tape_34xx_delete_sbid_from(device, 0);
370			return tape_34xx_erp_failed(request, -EIO);
371
372		case TO_RFO:
373			/* Read beyond end of recorded area -> 0 bytes read */
374			return tape_34xx_erp_failed(request, 0);
375
376		/*
377		 * sense[0] == SENSE_EQUIPMENT_CHECK &&
378		 * sense[1] == SENSE_DRIVE_ONLINE    &&
379		 * sense[3] == 0x38 (Physical End Of Volume)
380		 */
381		case TO_WRI:
382			/* Writing at physical end of volume */
383			return tape_34xx_erp_failed(request, -ENOSPC);
384		default:
385			PRINT_ERR("Invalid op in %s:%i\n",
386				  __FUNCTION__, __LINE__);
387			return tape_34xx_erp_failed(request, 0);
388		}
389	}
390
391	/* Sensing special bits */
392	if (sense[0] & SENSE_BUS_OUT_CHECK)
393		return tape_34xx_erp_retry(request);
394
395	if (sense[0] & SENSE_DATA_CHECK) {
396		/*
397		 * hardware failure, damaged tape or improper
398		 * operating conditions
399		 */
400		switch (sense[3]) {
401		case 0x23:
402			/* a read data check occurred */
403			if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
404			    inhibit_cu_recovery)
405				// data check is not permanent, may be
406				// recovered. We always use async-mode with
407				// cu-recovery, so this should *never* happen.
408				return tape_34xx_erp_bug(device, request,
409							 irb, -4);
410
411			/* data check is permanent, CU recovery has failed */
412			PRINT_WARN("Permanent read error\n");
413			return tape_34xx_erp_failed(request, -EIO);
414		case 0x25:
415			// a write data check occurred
416			if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
417			    inhibit_cu_recovery)
418				// data check is not permanent, may be
419				// recovered. We always use async-mode with
420				// cu-recovery, so this should *never* happen.
421				return tape_34xx_erp_bug(device, request,
422							 irb, -5);
423
424			// data check is permanent, cu-recovery has failed
425			PRINT_WARN("Permanent write error\n");
426			return tape_34xx_erp_failed(request, -EIO);
427		case 0x26:
428			/* Data Check (read opposite) occurred. */
429			return tape_34xx_erp_read_opposite(device, request);
430		case 0x28:
431			/* ID-Mark at tape start couldn't be written */
432			PRINT_WARN("ID-Mark could not be written.\n");
433			return tape_34xx_erp_failed(request, -EIO);
434		case 0x31:
435			/* Tape void. Tried to read beyond end of device. */
436			PRINT_WARN("Read beyond end of recorded area.\n");
437			return tape_34xx_erp_failed(request, -ENOSPC);
438		case 0x41:
439			/* Record sequence error. */
440			PRINT_WARN("Invalid block-id sequence found.\n");
441			return tape_34xx_erp_failed(request, -EIO);
442		default:
443			/* all data checks for 3480 should result in one of
444			 * the above erpa-codes. For 3490, other data-check
445			 * conditions do exist. */
446			if (device->cdev->id.driver_info == tape_3480)
447				return tape_34xx_erp_bug(device, request,
448							 irb, -6);
449		}
450	}
451
452	if (sense[0] & SENSE_OVERRUN)
453		return tape_34xx_erp_overrun(device, request, irb);
454
455	if (sense[1] & SENSE_RECORD_SEQUENCE_ERR)
456		return tape_34xx_erp_sequence(device, request, irb);
457
458	/* Sensing erpa codes */
459	switch (sense[3]) {
460	case 0x00:
461		/* Unit check with erpa code 0. Report and ignore. */
462		PRINT_WARN("Non-error sense was found. "
463			   "Unit-check will be ignored.\n");
464		return TAPE_IO_SUCCESS;
465	case 0x21:
466		/*
467		 * Data streaming not operational. CU will switch to
468		 * interlock mode. Reissue the command.
469		 */
470		PRINT_WARN("Data streaming not operational. "
471			   "Switching to interlock-mode.\n");
472		return tape_34xx_erp_retry(request);
473	case 0x22:
474		/*
475		 * Path equipment check. Might be drive adapter error, buffer
476		 * error on the lower interface, internal path not usable,
477		 * or error during cartridge load.
478		 */
479		PRINT_WARN("A path equipment check occurred. One of the "
480			   "following conditions occurred:\n");
481		PRINT_WARN("drive adapter error, buffer error on the lower "
482			   "interface, internal path not usable, error "
483			   "during cartridge load.\n");
484		return tape_34xx_erp_failed(request, -EIO);
485	case 0x24:
486		/*
487		 * Load display check. Load display was command was issued,
488		 * but the drive is displaying a drive check message. Can
489		 * be threated as "device end".
490		 */
491		return tape_34xx_erp_succeeded(request);
492	case 0x27:
493		/*
494		 * Command reject. May indicate illegal channel program or
495		 * buffer over/underrun. Since all channel programs are
496		 * issued by this driver and ought be correct, we assume a
497		 * over/underrun situation and retry the channel program.
498		 */
499		return tape_34xx_erp_retry(request);
500	case 0x29:
501		/*
502		 * Function incompatible. Either the tape is idrc compressed
503		 * but the hardware isn't capable to do idrc, or a perform
504		 * subsystem func is issued and the CU is not on-line.
505		 */
506		PRINT_WARN ("Function incompatible. Try to switch off idrc\n");
507		return tape_34xx_erp_failed(request, -EIO);
508	case 0x2a:
509		/*
510		 * Unsolicited environmental data. An internal counter
511		 * overflows, we can ignore this and reissue the cmd.
512		 */
513		return tape_34xx_erp_retry(request);
514	case 0x2b:
515		/*
516		 * Environmental data present. Indicates either unload
517		 * completed ok or read buffered log command completed ok.
518		 */
519		if (request->op == TO_RUN) {
520			/* Rewind unload completed ok. */
521			tape_med_state_set(device, MS_UNLOADED);
522			return tape_34xx_erp_succeeded(request);
523		}
524		/* tape_34xx doesn't use read buffered log commands. */
525		return tape_34xx_erp_bug(device, request, irb, sense[3]);
526	case 0x2c:
527		/*
528		 * Permanent equipment check. CU has tried recovery, but
529		 * did not succeed.
530		 */
531		return tape_34xx_erp_failed(request, -EIO);
532	case 0x2d:
533		/* Data security erase failure. */
534		if (request->op == TO_DSE)
535			return tape_34xx_erp_failed(request, -EIO);
536		/* Data security erase failure, but no such command issued. */
537		return tape_34xx_erp_bug(device, request, irb, sense[3]);
538	case 0x2e:
539		/*
540		 * Not capable. This indicates either that the drive fails
541		 * reading the format id mark or that that format specified
542		 * is not supported by the drive.
543		 */
544		PRINT_WARN("Drive not capable processing the tape format!\n");
545		return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
546	case 0x30:
547		/* The medium is write protected. */
548		PRINT_WARN("Medium is write protected!\n");
549		return tape_34xx_erp_failed(request, -EACCES);
550	case 0x32:
551		// Tension loss. We cannot recover this, it's an I/O error.
552		PRINT_WARN("The drive lost tape tension.\n");
553		return tape_34xx_erp_failed(request, -EIO);
554	case 0x33:
555		/*
556		 * Load Failure. The cartridge was not inserted correctly or
557		 * the tape is not threaded correctly.
558		 */
559		PRINT_WARN("Cartridge load failure. Reload the cartridge "
560			   "and try again.\n");
561		tape_34xx_delete_sbid_from(device, 0);
562		return tape_34xx_erp_failed(request, -EIO);
563	case 0x34:
564		/*
565		 * Unload failure. The drive cannot maintain tape tension
566		 * and control tape movement during an unload operation.
567		 */
568		PRINT_WARN("Failure during cartridge unload. "
569			   "Please try manually.\n");
570		if (request->op == TO_RUN)
571			return tape_34xx_erp_failed(request, -EIO);
572		return tape_34xx_erp_bug(device, request, irb, sense[3]);
573	case 0x35:
574		/*
575		 * Drive equipment check. One of the following:
576		 * - cu cannot recover from a drive detected error
577		 * - a check code message is shown on drive display
578		 * - the cartridge loader does not respond correctly
579		 * - a failure occurs during an index, load, or unload cycle
580		 */
581		PRINT_WARN("Equipment check! Please check the drive and "
582			   "the cartridge loader.\n");
583		return tape_34xx_erp_failed(request, -EIO);
584	case 0x36:
585		if (device->cdev->id.driver_info == tape_3490)
586			/* End of data. */
587			return tape_34xx_erp_failed(request, -EIO);
588		/* This erpa is reserved for 3480 */
589		return tape_34xx_erp_bug(device, request, irb, sense[3]);
590	case 0x37:
591		/*
592		 * Tape length error. The tape is shorter than reported in
593		 * the beginning-of-tape data.
594		 */
595		PRINT_WARN("Tape length error.\n");
596		return tape_34xx_erp_failed(request, -EIO);
597	case 0x38:
598		/*
599		 * Physical end of tape. A read/write operation reached
600		 * the physical end of tape.
601		 */
602		if (request->op==TO_WRI ||
603		    request->op==TO_DSE ||
604		    request->op==TO_WTM)
605			return tape_34xx_erp_failed(request, -ENOSPC);
606		return tape_34xx_erp_failed(request, -EIO);
607	case 0x39:
608		/* Backward at Beginning of tape. */
609		return tape_34xx_erp_failed(request, -EIO);
610	case 0x3a:
611		/* Drive switched to not ready. */
612		PRINT_WARN("Drive not ready. Turn the ready/not ready switch "
613			   "to ready position and try again.\n");
614		return tape_34xx_erp_failed(request, -EIO);
615	case 0x3b:
616		/* Manual rewind or unload. This causes an I/O error. */
617		PRINT_WARN("Medium was rewound or unloaded manually.\n");
618		tape_34xx_delete_sbid_from(device, 0);
619		return tape_34xx_erp_failed(request, -EIO);
620	case 0x42:
621		/*
622		 * Degraded mode. A condition that can cause degraded
623		 * performance is detected.
624		 */
625		PRINT_WARN("Subsystem is running in degraded mode.\n");
626		return tape_34xx_erp_retry(request);
627	case 0x43:
628		/* Drive not ready. */
629		tape_34xx_delete_sbid_from(device, 0);
630		tape_med_state_set(device, MS_UNLOADED);
631		/* Some commands commands are successful even in this case */
632		if (sense[1] & SENSE_DRIVE_ONLINE) {
633			switch(request->op) {
634				case TO_ASSIGN:
635				case TO_UNASSIGN:
636				case TO_DIS:
637				case TO_NOP:
638					return tape_34xx_done(request);
639					break;
640				default:
641					break;
642			}
643		}
644		PRINT_WARN("The drive is not ready.\n");
645		return tape_34xx_erp_failed(request, -ENOMEDIUM);
646	case 0x44:
647		/* Locate Block unsuccessful. */
648		if (request->op != TO_BLOCK && request->op != TO_LBL)
649			/* No locate block was issued. */
650			return tape_34xx_erp_bug(device, request,
651						 irb, sense[3]);
652		return tape_34xx_erp_failed(request, -EIO);
653	case 0x45:
654		/* The drive is assigned to a different channel path. */
655		PRINT_WARN("The drive is assigned elsewhere.\n");
656		return tape_34xx_erp_failed(request, -EIO);
657	case 0x46:
658		/*
659		 * Drive not on-line. Drive may be switched offline,
660		 * the power supply may be switched off or
661		 * the drive address may not be set correctly.
662		 */
663		PRINT_WARN("The drive is not on-line.");
664		return tape_34xx_erp_failed(request, -EIO);
665	case 0x47:
666		/* Volume fenced. CU reports volume integrity is lost. */
667		PRINT_WARN("Volume fenced. The volume integrity is lost.\n");
668		tape_34xx_delete_sbid_from(device, 0);
669		return tape_34xx_erp_failed(request, -EIO);
670	case 0x48:
671		/* Log sense data and retry request. */
672		return tape_34xx_erp_retry(request);
673	case 0x49:
674		/* Bus out check. A parity check error on the bus was found. */
675		PRINT_WARN("Bus out check. A data transfer over the bus "
676			   "has been corrupted.\n");
677		return tape_34xx_erp_failed(request, -EIO);
678	case 0x4a:
679		/* Control unit erp failed. */
680		PRINT_WARN("The control unit I/O error recovery failed.\n");
681		return tape_34xx_erp_failed(request, -EIO);
682	case 0x4b:
683		/*
684		 * CU and drive incompatible. The drive requests micro-program
685		 * patches, which are not available on the CU.
686		 */
687		PRINT_WARN("The drive needs microprogram patches from the "
688			   "control unit, which are not available.\n");
689		return tape_34xx_erp_failed(request, -EIO);
690	case 0x4c:
691		/*
692		 * Recovered Check-One failure. Cu develops a hardware error,
693		 * but is able to recover.
694		 */
695		return tape_34xx_erp_retry(request);
696	case 0x4d:
697		if (device->cdev->id.driver_info == tape_3490)
698			/*
699			 * Resetting event received. Since the driver does
700			 * not support resetting event recovery (which has to
701			 * be handled by the I/O Layer), retry our command.
702			 */
703			return tape_34xx_erp_retry(request);
704		/* This erpa is reserved for 3480. */
705		return tape_34xx_erp_bug(device, request, irb, sense[3]);
706	case 0x4e:
707		if (device->cdev->id.driver_info == tape_3490) {
708			/*
709			 * Maximum block size exceeded. This indicates, that
710			 * the block to be written is larger than allowed for
711			 * buffered mode.
712			 */
713			PRINT_WARN("Maximum block size for buffered "
714				   "mode exceeded.\n");
715			return tape_34xx_erp_failed(request, -ENOBUFS);
716		}
717		/* This erpa is reserved for 3480. */
718		return tape_34xx_erp_bug(device, request, irb, sense[3]);
719	case 0x50:
720		/*
721		 * Read buffered log (Overflow). CU is running in extended
722		 * buffered log mode, and a counter overflows. This should
723		 * never happen, since we're never running in extended
724		 * buffered log mode.
725		 */
726		return tape_34xx_erp_retry(request);
727	case 0x51:
728		/*
729		 * Read buffered log (EOV). EOF processing occurs while the
730		 * CU is in extended buffered log mode. This should never
731		 * happen, since we're never running in extended buffered
732		 * log mode.
733		 */
734		return tape_34xx_erp_retry(request);
735	case 0x52:
736		/* End of Volume complete. Rewind unload completed ok. */
737		if (request->op == TO_RUN) {
738			tape_med_state_set(device, MS_UNLOADED);
739			tape_34xx_delete_sbid_from(device, 0);
740			return tape_34xx_erp_succeeded(request);
741		}
742		return tape_34xx_erp_bug(device, request, irb, sense[3]);
743	case 0x53:
744		/* Global command intercept. */
745		return tape_34xx_erp_retry(request);
746	case 0x54:
747		/* Channel interface recovery (temporary). */
748		return tape_34xx_erp_retry(request);
749	case 0x55:
750		/* Channel interface recovery (permanent). */
751		PRINT_WARN("A permanent channel interface error occurred.\n");
752		return tape_34xx_erp_failed(request, -EIO);
753	case 0x56:
754		/* Channel protocol error. */
755		PRINT_WARN("A channel protocol error occurred.\n");
756		return tape_34xx_erp_failed(request, -EIO);
757	case 0x57:
758		if (device->cdev->id.driver_info == tape_3480) {
759			/* Attention intercept. */
760			PRINT_WARN("An attention intercept occurred, "
761				   "which will be recovered.\n");
762			return tape_34xx_erp_retry(request);
763		} else {
764			/* Global status intercept. */
765			PRINT_WARN("An global status intercept was received, "
766				   "which will be recovered.\n");
767			return tape_34xx_erp_retry(request);
768		}
769	case 0x5a:
770		/*
771		 * Tape length incompatible. The tape inserted is too long,
772		 * which could cause damage to the tape or the drive.
773		 */
774		PRINT_WARN("Tape Length Incompatible\n");
775		PRINT_WARN("Tape length exceeds IBM enhanced capacity "
776			"cartdridge length or a medium\n");
777		PRINT_WARN("with EC-CST identification mark has been mounted "
778			"in a device that writes\n");
779		PRINT_WARN("3480 or 3480 XF format.\n");
780		return tape_34xx_erp_failed(request, -EIO);
781	case 0x5b:
782		/* Format 3480 XF incompatible */
783		if (sense[1] & SENSE_BEGINNING_OF_TAPE)
784			/* The tape will get overwritten. */
785			return tape_34xx_erp_retry(request);
786		PRINT_WARN("Format 3480 XF Incompatible\n");
787		PRINT_WARN("Medium has been created in 3480 format. "
788			"To change the format writes\n");
789		PRINT_WARN("must be issued at BOT.\n");
790		return tape_34xx_erp_failed(request, -EIO);
791	case 0x5c:
792		/* Format 3480-2 XF incompatible */
793		PRINT_WARN("Format 3480-2 XF Incompatible\n");
794		PRINT_WARN("Device can only read 3480 or 3480 XF format.\n");
795		return tape_34xx_erp_failed(request, -EIO);
796	case 0x5d:
797		/* Tape length violation. */
798		PRINT_WARN("Tape Length Violation\n");
799		PRINT_WARN("The mounted tape exceeds IBM Enhanced Capacity "
800			"Cartdridge System Tape length.\n");
801		PRINT_WARN("This may cause damage to the drive or tape when "
802			"processing to the EOV\n");
803		return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
804	case 0x5e:
805		/* Compaction algorithm incompatible. */
806		PRINT_WARN("Compaction Algorithm Incompatible\n");
807		PRINT_WARN("The volume is recorded using an incompatible "
808			"compaction algorithm,\n");
809		PRINT_WARN("which is not supported by the device.\n");
810		return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
811
812		/* The following erpas should have been covered earlier. */
813	case 0x23: /* Read data check. */
814	case 0x25: /* Write data check. */
815	case 0x26: /* Data check (read opposite). */
816	case 0x28: /* Write id mark check. */
817	case 0x31: /* Tape void. */
818	case 0x40: /* Overrun error. */
819	case 0x41: /* Record sequence error. */
820		/* All other erpas are reserved for future use. */
821	default:
822		return tape_34xx_erp_bug(device, request, irb, sense[3]);
823	}
824}
825
826/*
827 * 3480/3490 interrupt handler
828 */
829static int
830tape_34xx_irq(struct tape_device *device, struct tape_request *request,
831	      struct irb *irb)
832{
833	if (request == NULL)
834		return tape_34xx_unsolicited_irq(device, irb);
835
836	if ((irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) &&
837	    (irb->scsw.dstat & DEV_STAT_DEV_END) &&
838	    (request->op == TO_WRI)) {
839		/* Write at end of volume */
840		PRINT_INFO("End of volume\n");
841		return tape_34xx_erp_failed(request, -ENOSPC);
842	}
843
844	if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
845		return tape_34xx_unit_check(device, request, irb);
846
847	if (irb->scsw.dstat & DEV_STAT_DEV_END) {
848		/*
849		 * A unit exception occurs on skipping over a tapemark block.
850		 */
851		if (irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) {
852			if (request->op == TO_BSB || request->op == TO_FSB)
853				request->rescnt++;
854			else
855				DBF_EVENT(5, "Unit Exception!\n");
856		}
857		return tape_34xx_done(request);
858	}
859
860	DBF_EVENT(6, "xunknownirq\n");
861	PRINT_ERR("Unexpected interrupt.\n");
862	PRINT_ERR("Current op is: %s", tape_op_verbose[request->op]);
863	tape_dump_sense(device, request, irb);
864	return TAPE_IO_STOP;
865}
866
867/*
868 * ioctl_overload
869 */
870static int
871tape_34xx_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
872{
873	if (cmd == TAPE390_DISPLAY) {
874		struct display_struct disp;
875
876		if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)) != 0)
877			return -EFAULT;
878
879		return tape_std_display(device, &disp);
880	} else
881		return -EINVAL;
882}
883
884static inline void
885tape_34xx_append_new_sbid(struct tape_34xx_block_id bid, struct list_head *l)
886{
887	struct tape_34xx_sbid *	new_sbid;
888
889	new_sbid = kmalloc(sizeof(*new_sbid), GFP_ATOMIC);
890	if (!new_sbid)
891		return;
892
893	new_sbid->bid = bid;
894	list_add(&new_sbid->list, l);
895}
896
897/*
898 * Build up the search block ID list. The block ID consists of a logical
899 * block number and a hardware specific part. The hardware specific part
900 * helps the tape drive to speed up searching for a specific block.
901 */
902static void
903tape_34xx_add_sbid(struct tape_device *device, struct tape_34xx_block_id bid)
904{
905	struct list_head *	sbid_list;
906	struct tape_34xx_sbid *	sbid;
907	struct list_head *	l;
908
909	/*
910	 * immediately return if there is no list at all or the block to add
911	 * is located in segment 1 of wrap 0 because this position is used
912	 * if no hardware position data is supplied.
913	 */
914	sbid_list = (struct list_head *) device->discdata;
915	if (!sbid_list || (bid.segment < 2 && bid.wrap == 0))
916		return;
917
918	/*
919	 * Search the position where to insert the new entry. Hardware
920	 * acceleration uses only the segment and wrap number. So we
921	 * need only one entry for a specific wrap/segment combination.
922	 * If there is a block with a lower number but the same hard-
923	 * ware position data we just update the block number in the
924	 * existing entry.
925	 */
926	list_for_each(l, sbid_list) {
927		sbid = list_entry(l, struct tape_34xx_sbid, list);
928
929		if (
930			(sbid->bid.segment == bid.segment) &&
931			(sbid->bid.wrap    == bid.wrap)
932		) {
933			if (bid.block < sbid->bid.block)
934				sbid->bid = bid;
935			else return;
936			break;
937		}
938
939		/* Sort in according to logical block number. */
940		if (bid.block < sbid->bid.block) {
941			tape_34xx_append_new_sbid(bid, l->prev);
942			break;
943		}
944	}
945	/* List empty or new block bigger than last entry. */
946	if (l == sbid_list)
947		tape_34xx_append_new_sbid(bid, l->prev);
948
949	DBF_LH(4, "Current list is:\n");
950	list_for_each(l, sbid_list) {
951		sbid = list_entry(l, struct tape_34xx_sbid, list);
952		DBF_LH(4, "%d:%03d@%05d\n",
953			sbid->bid.wrap,
954			sbid->bid.segment,
955			sbid->bid.block
956		);
957	}
958}
959
960/*
961 * Delete all entries from the search block ID list that belong to tape blocks
962 * equal or higher than the given number.
963 */
964static void
965tape_34xx_delete_sbid_from(struct tape_device *device, int from)
966{
967	struct list_head *	sbid_list;
968	struct tape_34xx_sbid *	sbid;
969	struct list_head *	l;
970	struct list_head *	n;
971
972	sbid_list = (struct list_head *) device->discdata;
973	if (!sbid_list)
974		return;
975
976	list_for_each_safe(l, n, sbid_list) {
977		sbid = list_entry(l, struct tape_34xx_sbid, list);
978		if (sbid->bid.block >= from) {
979			DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
980				sbid->bid.wrap,
981				sbid->bid.segment,
982				sbid->bid.block
983			);
984			list_del(l);
985			kfree(sbid);
986		}
987	}
988}
989
990/*
991 * Merge hardware position data into a block id.
992 */
993static void
994tape_34xx_merge_sbid(
995	struct tape_device *		device,
996	struct tape_34xx_block_id *	bid
997) {
998	struct tape_34xx_sbid *	sbid;
999	struct tape_34xx_sbid *	sbid_to_use;
1000	struct list_head *	sbid_list;
1001	struct list_head *	l;
1002
1003	sbid_list = (struct list_head *) device->discdata;
1004	bid->wrap    = 0;
1005	bid->segment = 1;
1006
1007	if (!sbid_list || list_empty(sbid_list))
1008		return;
1009
1010	sbid_to_use = NULL;
1011	list_for_each(l, sbid_list) {
1012		sbid = list_entry(l, struct tape_34xx_sbid, list);
1013
1014		if (sbid->bid.block >= bid->block)
1015			break;
1016		sbid_to_use = sbid;
1017	}
1018	if (sbid_to_use) {
1019		bid->wrap    = sbid_to_use->bid.wrap;
1020		bid->segment = sbid_to_use->bid.segment;
1021		DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
1022			sbid_to_use->bid.wrap,
1023			sbid_to_use->bid.segment,
1024			sbid_to_use->bid.block,
1025			bid->block
1026		);
1027	}
1028}
1029
1030static int
1031tape_34xx_setup_device(struct tape_device * device)
1032{
1033	int			rc;
1034	struct list_head *	discdata;
1035
1036	DBF_EVENT(6, "34xx device setup\n");
1037	if ((rc = tape_std_assign(device)) == 0) {
1038		if ((rc = tape_34xx_medium_sense(device)) != 0) {
1039			DBF_LH(3, "34xx medium sense returned %d\n", rc);
1040		}
1041	}
1042	discdata = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1043	if (discdata) {
1044			INIT_LIST_HEAD(discdata);
1045			device->discdata = discdata;
1046	}
1047
1048	return rc;
1049}
1050
1051static void
1052tape_34xx_cleanup_device(struct tape_device *device)
1053{
1054	tape_std_unassign(device);
1055
1056	if (device->discdata) {
1057		tape_34xx_delete_sbid_from(device, 0);
1058		kfree(device->discdata);
1059		device->discdata = NULL;
1060	}
1061}
1062
1063
1064/*
1065 * MTTELL: Tell block. Return the number of block relative to current file.
1066 */
1067static int
1068tape_34xx_mttell(struct tape_device *device, int mt_count)
1069{
1070	struct {
1071		struct tape_34xx_block_id	cbid;
1072		struct tape_34xx_block_id	dbid;
1073	} __attribute__ ((packed)) block_id;
1074	int rc;
1075
1076	rc = tape_std_read_block_id(device, (__u64 *) &block_id);
1077	if (rc)
1078		return rc;
1079
1080	tape_34xx_add_sbid(device, block_id.cbid);
1081	return block_id.cbid.block;
1082}
1083
1084/*
1085 * MTSEEK: seek to the specified block.
1086 */
1087static int
1088tape_34xx_mtseek(struct tape_device *device, int mt_count)
1089{
1090	struct tape_request *request;
1091	struct tape_34xx_block_id *	bid;
1092
1093	if (mt_count > 0x3fffff) {
1094		DBF_EXCEPTION(6, "xsee parm\n");
1095		return -EINVAL;
1096	}
1097	request = tape_alloc_request(3, 4);
1098	if (IS_ERR(request))
1099		return PTR_ERR(request);
1100
1101	/* setup ccws */
1102	request->op = TO_LBL;
1103	bid         = (struct tape_34xx_block_id *) request->cpdata;
1104	bid->format = (*device->modeset_byte & 0x08) ?
1105			TAPE34XX_FMT_3480_XF : TAPE34XX_FMT_3480;
1106	bid->block  = mt_count;
1107	tape_34xx_merge_sbid(device, bid);
1108
1109	tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
1110	tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1111	tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
1112
1113	/* execute it */
1114	return tape_do_io_free(device, request);
1115}
1116
1117#ifdef CONFIG_S390_TAPE_BLOCK
1118/*
1119 * Tape block read for 34xx.
1120 */
1121static struct tape_request *
1122tape_34xx_bread(struct tape_device *device, struct request *req)
1123{
1124	struct tape_request *request;
1125	struct ccw1 *ccw;
1126	int count = 0, i;
1127	unsigned off;
1128	char *dst;
1129	struct bio_vec *bv;
1130	struct bio *bio;
1131	struct tape_34xx_block_id *	start_block;
1132
1133	DBF_EVENT(6, "xBREDid:");
1134
1135	/* Count the number of blocks for the request. */
1136	rq_for_each_bio(bio, req) {
1137		bio_for_each_segment(bv, bio, i) {
1138			count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
1139		}
1140	}
1141
1142	/* Allocate the ccw request. */
1143	request = tape_alloc_request(3+count+1, 8);
1144	if (IS_ERR(request))
1145		return request;
1146
1147	/* Setup ccws. */
1148	request->op = TO_BLOCK;
1149	start_block = (struct tape_34xx_block_id *) request->cpdata;
1150	start_block->block = req->sector >> TAPEBLOCK_HSEC_S2B;
1151	DBF_EVENT(6, "start_block = %i\n", start_block->block);
1152
1153	ccw = request->cpaddr;
1154	ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);
1155
1156	/*
1157	 * We always setup a nop after the mode set ccw. This slot is
1158	 * used in tape_std_check_locate to insert a locate ccw if the
1159	 * current tape position doesn't match the start block to be read.
1160	 * The second nop will be filled with a read block id which is in
1161	 * turn used by tape_34xx_free_bread to populate the segment bid
1162	 * table.
1163	 */
1164	ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
1165	ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
1166
1167	rq_for_each_bio(bio, req) {
1168		bio_for_each_segment(bv, bio, i) {
1169			dst = kmap(bv->bv_page) + bv->bv_offset;
1170			for (off = 0; off < bv->bv_len;
1171			     off += TAPEBLOCK_HSEC_SIZE) {
1172				ccw->flags = CCW_FLAG_CC;
1173				ccw->cmd_code = READ_FORWARD;
1174				ccw->count = TAPEBLOCK_HSEC_SIZE;
1175				set_normalized_cda(ccw, (void*) __pa(dst));
1176				ccw++;
1177				dst += TAPEBLOCK_HSEC_SIZE;
1178			}
1179		}
1180	}
1181
1182	ccw = tape_ccw_end(ccw, NOP, 0, NULL);
1183	DBF_EVENT(6, "xBREDccwg\n");
1184	return request;
1185}
1186
1187static void
1188tape_34xx_free_bread (struct tape_request *request)
1189{
1190	struct ccw1* ccw;
1191
1192	ccw = request->cpaddr;
1193	if ((ccw + 2)->cmd_code == READ_BLOCK_ID) {
1194		struct {
1195			struct tape_34xx_block_id	cbid;
1196			struct tape_34xx_block_id	dbid;
1197		} __attribute__ ((packed)) *rbi_data;
1198
1199		rbi_data = request->cpdata;
1200
1201		if (request->device)
1202			tape_34xx_add_sbid(request->device, rbi_data->cbid);
1203	}
1204
1205	/* Last ccw is a nop and doesn't need clear_normalized_cda */
1206	for (; ccw->flags & CCW_FLAG_CC; ccw++)
1207		if (ccw->cmd_code == READ_FORWARD)
1208			clear_normalized_cda(ccw);
1209	tape_free_request(request);
1210}
1211
1212/*
1213 * check_locate is called just before the tape request is passed to
1214 * the common io layer for execution. It has to check the current
1215 * tape position and insert a locate ccw if it doesn't match the
1216 * start block for the request.
1217 */
1218static void
1219tape_34xx_check_locate(struct tape_device *device, struct tape_request *request)
1220{
1221	struct tape_34xx_block_id *	start_block;
1222
1223	start_block = (struct tape_34xx_block_id *) request->cpdata;
1224	if (start_block->block == device->blk_data.block_position)
1225		return;
1226
1227	DBF_LH(4, "Block seek(%06d+%06d)\n", start_block->block, device->bof);
1228	start_block->wrap    = 0;
1229	start_block->segment = 1;
1230	start_block->format  = (*device->modeset_byte & 0x08) ?
1231				TAPE34XX_FMT_3480_XF :
1232				TAPE34XX_FMT_3480;
1233	start_block->block   = start_block->block + device->bof;
1234	tape_34xx_merge_sbid(device, start_block);
1235	tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1236	tape_ccw_cc(request->cpaddr + 2, READ_BLOCK_ID, 8, request->cpdata);
1237}
1238#endif
1239
1240/*
1241 * List of 3480/3490 magnetic tape commands.
1242 */
1243static tape_mtop_fn tape_34xx_mtop[TAPE_NR_MTOPS] = {
1244	[MTRESET]	 = tape_std_mtreset,
1245	[MTFSF]		 = tape_std_mtfsf,
1246	[MTBSF]		 = tape_std_mtbsf,
1247	[MTFSR]		 = tape_std_mtfsr,
1248	[MTBSR]		 = tape_std_mtbsr,
1249	[MTWEOF]	 = tape_std_mtweof,
1250	[MTREW]		 = tape_std_mtrew,
1251	[MTOFFL]	 = tape_std_mtoffl,
1252	[MTNOP]		 = tape_std_mtnop,
1253	[MTRETEN]	 = tape_std_mtreten,
1254	[MTBSFM]	 = tape_std_mtbsfm,
1255	[MTFSFM]	 = tape_std_mtfsfm,
1256	[MTEOM]		 = tape_std_mteom,
1257	[MTERASE]	 = tape_std_mterase,
1258	[MTRAS1]	 = NULL,
1259	[MTRAS2]	 = NULL,
1260	[MTRAS3]	 = NULL,
1261	[MTSETBLK]	 = tape_std_mtsetblk,
1262	[MTSETDENSITY]	 = NULL,
1263	[MTSEEK]	 = tape_34xx_mtseek,
1264	[MTTELL]	 = tape_34xx_mttell,
1265	[MTSETDRVBUFFER] = NULL,
1266	[MTFSS]		 = NULL,
1267	[MTBSS]		 = NULL,
1268	[MTWSM]		 = NULL,
1269	[MTLOCK]	 = NULL,
1270	[MTUNLOCK]	 = NULL,
1271	[MTLOAD]	 = tape_std_mtload,
1272	[MTUNLOAD]	 = tape_std_mtunload,
1273	[MTCOMPRESSION]	 = tape_std_mtcompression,
1274	[MTSETPART]	 = NULL,
1275	[MTMKPART]	 = NULL
1276};
1277
1278/*
1279 * Tape discipline structure for 3480 and 3490.
1280 */
1281static struct tape_discipline tape_discipline_34xx = {
1282	.owner = THIS_MODULE,
1283	.setup_device = tape_34xx_setup_device,
1284	.cleanup_device = tape_34xx_cleanup_device,
1285	.process_eov = tape_std_process_eov,
1286	.irq = tape_34xx_irq,
1287	.read_block = tape_std_read_block,
1288	.write_block = tape_std_write_block,
1289#ifdef CONFIG_S390_TAPE_BLOCK
1290	.bread = tape_34xx_bread,
1291	.free_bread = tape_34xx_free_bread,
1292	.check_locate = tape_34xx_check_locate,
1293#endif
1294	.ioctl_fn = tape_34xx_ioctl,
1295	.mtop_array = tape_34xx_mtop
1296};
1297
1298static struct ccw_device_id tape_34xx_ids[] = {
1299	{ CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), .driver_info = tape_3480},
1300	{ CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), .driver_info = tape_3490},
1301	{ /* end of list */ },
1302};
1303
1304static int
1305tape_34xx_online(struct ccw_device *cdev)
1306{
1307	return tape_generic_online(
1308		cdev->dev.driver_data,
1309		&tape_discipline_34xx
1310	);
1311}
1312
1313static int
1314tape_34xx_offline(struct ccw_device *cdev)
1315{
1316	return tape_generic_offline(cdev->dev.driver_data);
1317}
1318
1319static struct ccw_driver tape_34xx_driver = {
1320	.name = "tape_34xx",
1321	.owner = THIS_MODULE,
1322	.ids = tape_34xx_ids,
1323	.probe = tape_generic_probe,
1324	.remove = tape_generic_remove,
1325	.set_online = tape_34xx_online,
1326	.set_offline = tape_34xx_offline,
1327};
1328
1329static int
1330tape_34xx_init (void)
1331{
1332	int rc;
1333
1334	TAPE_DBF_AREA = debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
1335	debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1336#ifdef DBF_LIKE_HELL
1337	debug_set_level(TAPE_DBF_AREA, 6);
1338#endif
1339
1340	DBF_EVENT(3, "34xx init\n");
1341	/* Register driver for 3480/3490 tapes. */
1342	rc = ccw_driver_register(&tape_34xx_driver);
1343	if (rc)
1344		DBF_EVENT(3, "34xx init failed\n");
1345	else
1346		DBF_EVENT(3, "34xx registered\n");
1347	return rc;
1348}
1349
1350static void
1351tape_34xx_exit(void)
1352{
1353	ccw_driver_unregister(&tape_34xx_driver);
1354
1355	debug_unregister(TAPE_DBF_AREA);
1356}
1357
1358MODULE_DEVICE_TABLE(ccw, tape_34xx_ids);
1359MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
1360MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape device driver");
1361MODULE_LICENSE("GPL");
1362
1363module_init(tape_34xx_init);
1364module_exit(tape_34xx_exit);
1365