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