2 * drivers/s390/char/tape_34xx.c
3 * tape device discipline for 3480/3490 tapes.
5 * S390 and zSeries version
6 * Copyright (C) 2001,2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Carsten Otte <cotte@de.ibm.com>
8 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
9 * Martin Schwidefsky <schwidefsky@de.ibm.com>
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/bio.h>
16 #include <linux/workqueue.h>
18 #define TAPE_DBF_AREA tape_34xx_dbf
23 #define PRINTK_HEADER "TAPE_34XX: "
26 * Pointer to debug area.
28 debug_info_t
*TAPE_DBF_AREA
= NULL
;
29 EXPORT_SYMBOL(TAPE_DBF_AREA
);
36 #define TAPE34XX_FMT_3480 0
37 #define TAPE34XX_FMT_3480_2_XF 1
38 #define TAPE34XX_FMT_3480_XF 2
40 struct tape_34xx_block_id
{
41 unsigned int wrap
: 1;
42 unsigned int segment
: 7;
43 unsigned int format
: 2;
44 unsigned int block
: 22;
48 * A list of block ID's is used to faster seek blocks.
50 struct tape_34xx_sbid
{
51 struct list_head list
;
52 struct tape_34xx_block_id bid
;
55 static void tape_34xx_delete_sbid_from(struct tape_device
*, int);
58 * Medium sense for 34xx tapes. There is no 'real' medium sense call.
59 * So we just do a normal sense.
62 tape_34xx_medium_sense(struct tape_device
*device
)
64 struct tape_request
*request
;
68 request
= tape_alloc_request(1, 32);
69 if (IS_ERR(request
)) {
70 DBF_EXCEPTION(6, "MSEN fail\n");
71 return PTR_ERR(request
);
74 request
->op
= TO_MSEN
;
75 tape_ccw_end(request
->cpaddr
, SENSE
, 32, request
->cpdata
);
77 rc
= tape_do_io_interruptible(device
, request
);
78 if (request
->rc
== 0) {
79 sense
= request
->cpdata
;
82 * This isn't quite correct. But since INTERVENTION_REQUIRED
83 * means that the drive is 'neither ready nor on-line' it is
84 * only slightly inaccurate to say there is no tape loaded if
85 * the drive isn't online...
87 if (sense
[0] & SENSE_INTERVENTION_REQUIRED
)
88 tape_med_state_set(device
, MS_UNLOADED
);
90 tape_med_state_set(device
, MS_LOADED
);
92 if (sense
[1] & SENSE_WRITE_PROTECT
)
93 device
->tape_generic_status
|= GMT_WR_PROT(~0);
95 device
->tape_generic_status
&= ~GMT_WR_PROT(~0);
97 DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
100 tape_free_request(request
);
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
113 tape_34xx_work_handler(void *data
)
116 struct tape_device
*device
;
118 struct work_struct work
;
123 tape_34xx_medium_sense(p
->device
);
126 DBF_EVENT(3, "T34XX: internal error: unknown work\n");
129 p
->device
= tape_put_device(p
->device
);
134 tape_34xx_schedule_work(struct tape_device
*device
, enum tape_op op
)
137 struct tape_device
*device
;
139 struct work_struct work
;
142 if ((p
= kmalloc(sizeof(*p
), GFP_ATOMIC
)) == NULL
)
145 memset(p
, 0, sizeof(*p
));
146 INIT_WORK(&p
->work
, tape_34xx_work_handler
, p
);
148 p
->device
= tape_get_device_reference(device
);
151 schedule_work(&p
->work
);
156 * Done Handler is called when dev stat = DEVICE-END (successful operation)
159 tape_34xx_done(struct tape_request
*request
)
161 DBF_EVENT(6, "%s done\n", tape_op_verbose
[request
->op
]);
163 switch (request
->op
) {
170 tape_34xx_delete_sbid_from(request
->device
, 0);
175 return TAPE_IO_SUCCESS
;
179 tape_34xx_erp_failed(struct tape_request
*request
, int rc
)
181 DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
182 tape_op_verbose
[request
->op
], rc
);
187 tape_34xx_erp_succeeded(struct tape_request
*request
)
189 DBF_EVENT(3, "Error Recovery successful for %s\n",
190 tape_op_verbose
[request
->op
]);
191 return tape_34xx_done(request
);
195 tape_34xx_erp_retry(struct tape_request
*request
)
197 DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose
[request
->op
]);
198 return TAPE_IO_RETRY
;
202 * This function is called, when no request is outstanding and we get an
206 tape_34xx_unsolicited_irq(struct tape_device
*device
, struct irb
*irb
)
208 if (irb
->scsw
.dstat
== 0x85 /* READY */) {
209 /* A medium was inserted in the drive. */
210 DBF_EVENT(6, "xuud med\n");
211 tape_34xx_delete_sbid_from(device
, 0);
212 tape_34xx_schedule_work(device
, TO_MSEN
);
214 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device
->cdev_id
);
215 PRINT_WARN("Unsolicited IRQ (Device End) caught.\n");
216 tape_dump_sense(device
, NULL
, irb
);
218 return TAPE_IO_SUCCESS
;
222 * Read Opposite Error Recovery Function:
223 * Used, when Read Forward does not work
226 tape_34xx_erp_read_opposite(struct tape_device
*device
,
227 struct tape_request
*request
)
229 if (request
->op
== TO_RFO
) {
231 * We did read forward, but the data could not be read
232 * *correctly*. We transform the request to a read backward
235 tape_std_read_backward(device
, request
);
236 return tape_34xx_erp_retry(request
);
238 if (request
->op
!= TO_RBA
)
239 PRINT_ERR("read_opposite called with state:%s\n",
240 tape_op_verbose
[request
->op
]);
242 * We tried to read forward and backward, but hat no
245 return tape_34xx_erp_failed(request
, -EIO
);
249 tape_34xx_erp_bug(struct tape_device
*device
, struct tape_request
*request
,
250 struct irb
*irb
, int no
)
252 if (request
->op
!= TO_ASSIGN
) {
253 PRINT_WARN("An unexpected condition #%d was caught in "
254 "tape error recovery.\n", no
);
255 PRINT_WARN("Please report this incident.\n");
257 PRINT_WARN("Operation of tape:%s\n",
258 tape_op_verbose
[request
->op
]);
259 tape_dump_sense(device
, request
, irb
);
261 return tape_34xx_erp_failed(request
, -EIO
);
265 * Handle data overrun between cu and drive. The channel speed might
269 tape_34xx_erp_overrun(struct tape_device
*device
, struct tape_request
*request
,
272 if (irb
->ecw
[3] == 0x40) {
273 PRINT_WARN ("Data overrun error between control-unit "
274 "and drive. Use a faster channel connection, "
276 return tape_34xx_erp_failed(request
, -EIO
);
278 return tape_34xx_erp_bug(device
, request
, irb
, -1);
282 * Handle record sequence error.
285 tape_34xx_erp_sequence(struct tape_device
*device
,
286 struct tape_request
*request
, struct irb
*irb
)
288 if (irb
->ecw
[3] == 0x41) {
290 * cu detected incorrect block-id sequence on tape.
292 PRINT_WARN("Illegal block-id sequence found!\n");
293 return tape_34xx_erp_failed(request
, -EIO
);
296 * Record sequence error bit is set, but erpa does not
297 * show record sequence error.
299 return tape_34xx_erp_bug(device
, request
, irb
, -2);
303 * This function analyses the tape's sense-data in case of a unit-check.
304 * If possible, it tries to recover from the error. Else the user is
305 * informed about the problem.
308 tape_34xx_unit_check(struct tape_device
*device
, struct tape_request
*request
,
311 int inhibit_cu_recovery
;
314 inhibit_cu_recovery
= (*device
->modeset_byte
& 0x80) ? 1 : 0;
317 #ifdef CONFIG_S390_TAPE_BLOCK
318 if (request
->op
== TO_BLOCK
) {
320 * Recovery for block device requests. Set the block_position
321 * to something invalid and retry.
323 device
->blk_data
.block_position
= -1;
324 if (request
->retries
-- <= 0)
325 return tape_34xx_erp_failed(request
, -EIO
);
327 return tape_34xx_erp_retry(request
);
332 sense
[0] & SENSE_COMMAND_REJECT
&&
333 sense
[1] & SENSE_WRITE_PROTECT
336 request
->op
== TO_DSE
||
337 request
->op
== TO_WRI
||
338 request
->op
== TO_WTM
340 /* medium is write protected */
341 return tape_34xx_erp_failed(request
, -EACCES
);
343 return tape_34xx_erp_bug(device
, request
, irb
, -3);
348 * Special cases for various tape-states when reaching
349 * end of recorded area
351 * FIXME: Maybe a special case of the special case:
352 * sense[0] == SENSE_EQUIPMENT_CHECK &&
353 * sense[1] == SENSE_DRIVE_ONLINE &&
354 * sense[3] == 0x47 (Volume Fenced)
356 * This was caused by continued FSF or FSR after an
360 sense
[0] == SENSE_DATA_CHECK
||
361 sense
[0] == SENSE_EQUIPMENT_CHECK
||
362 sense
[0] == SENSE_EQUIPMENT_CHECK
+ SENSE_DEFERRED_UNIT_CHECK
364 sense
[1] == SENSE_DRIVE_ONLINE
||
365 sense
[1] == SENSE_BEGINNING_OF_TAPE
+ SENSE_WRITE_MODE
367 switch (request
->op
) {
369 * sense[0] == SENSE_DATA_CHECK &&
370 * sense[1] == SENSE_DRIVE_ONLINE
371 * sense[3] == 0x36 (End Of Data)
373 * Further seeks might return a 'Volume Fenced'.
377 /* Trying to seek beyond end of recorded area */
378 return tape_34xx_erp_failed(request
, -ENOSPC
);
380 return tape_34xx_erp_retry(request
);
383 * sense[0] == SENSE_DATA_CHECK &&
384 * sense[1] == SENSE_DRIVE_ONLINE &&
385 * sense[3] == 0x36 (End Of Data)
388 /* Block could not be located. */
389 tape_34xx_delete_sbid_from(device
, 0);
390 return tape_34xx_erp_failed(request
, -EIO
);
393 /* Read beyond end of recorded area -> 0 bytes read */
394 return tape_34xx_erp_failed(request
, 0);
397 * sense[0] == SENSE_EQUIPMENT_CHECK &&
398 * sense[1] == SENSE_DRIVE_ONLINE &&
399 * sense[3] == 0x38 (Physical End Of Volume)
402 /* Writing at physical end of volume */
403 return tape_34xx_erp_failed(request
, -ENOSPC
);
405 PRINT_ERR("Invalid op in %s:%i\n",
406 __FUNCTION__
, __LINE__
);
407 return tape_34xx_erp_failed(request
, 0);
411 /* Sensing special bits */
412 if (sense
[0] & SENSE_BUS_OUT_CHECK
)
413 return tape_34xx_erp_retry(request
);
415 if (sense
[0] & SENSE_DATA_CHECK
) {
417 * hardware failure, damaged tape or improper
418 * operating conditions
422 /* a read data check occurred */
423 if ((sense
[2] & SENSE_TAPE_SYNC_MODE
) ||
425 // data check is not permanent, may be
426 // recovered. We always use async-mode with
427 // cu-recovery, so this should *never* happen.
428 return tape_34xx_erp_bug(device
, request
,
431 /* data check is permanent, CU recovery has failed */
432 PRINT_WARN("Permanent read error\n");
433 return tape_34xx_erp_failed(request
, -EIO
);
435 // a write data check occurred
436 if ((sense
[2] & SENSE_TAPE_SYNC_MODE
) ||
438 // data check is not permanent, may be
439 // recovered. We always use async-mode with
440 // cu-recovery, so this should *never* happen.
441 return tape_34xx_erp_bug(device
, request
,
444 // data check is permanent, cu-recovery has failed
445 PRINT_WARN("Permanent write error\n");
446 return tape_34xx_erp_failed(request
, -EIO
);
448 /* Data Check (read opposite) occurred. */
449 return tape_34xx_erp_read_opposite(device
, request
);
451 /* ID-Mark at tape start couldn't be written */
452 PRINT_WARN("ID-Mark could not be written.\n");
453 return tape_34xx_erp_failed(request
, -EIO
);
455 /* Tape void. Tried to read beyond end of device. */
456 PRINT_WARN("Read beyond end of recorded area.\n");
457 return tape_34xx_erp_failed(request
, -ENOSPC
);
459 /* Record sequence error. */
460 PRINT_WARN("Invalid block-id sequence found.\n");
461 return tape_34xx_erp_failed(request
, -EIO
);
463 /* all data checks for 3480 should result in one of
464 * the above erpa-codes. For 3490, other data-check
465 * conditions do exist. */
466 if (device
->cdev
->id
.driver_info
== tape_3480
)
467 return tape_34xx_erp_bug(device
, request
,
472 if (sense
[0] & SENSE_OVERRUN
)
473 return tape_34xx_erp_overrun(device
, request
, irb
);
475 if (sense
[1] & SENSE_RECORD_SEQUENCE_ERR
)
476 return tape_34xx_erp_sequence(device
, request
, irb
);
478 /* Sensing erpa codes */
481 /* Unit check with erpa code 0. Report and ignore. */
482 PRINT_WARN("Non-error sense was found. "
483 "Unit-check will be ignored.\n");
484 return TAPE_IO_SUCCESS
;
487 * Data streaming not operational. CU will switch to
488 * interlock mode. Reissue the command.
490 PRINT_WARN("Data streaming not operational. "
491 "Switching to interlock-mode.\n");
492 return tape_34xx_erp_retry(request
);
495 * Path equipment check. Might be drive adapter error, buffer
496 * error on the lower interface, internal path not usable,
497 * or error during cartridge load.
499 PRINT_WARN("A path equipment check occurred. One of the "
500 "following conditions occurred:\n");
501 PRINT_WARN("drive adapter error, buffer error on the lower "
502 "interface, internal path not usable, error "
503 "during cartridge load.\n");
504 return tape_34xx_erp_failed(request
, -EIO
);
507 * Load display check. Load display was command was issued,
508 * but the drive is displaying a drive check message. Can
509 * be threated as "device end".
511 return tape_34xx_erp_succeeded(request
);
514 * Command reject. May indicate illegal channel program or
515 * buffer over/underrun. Since all channel programs are
516 * issued by this driver and ought be correct, we assume a
517 * over/underrun situation and retry the channel program.
519 return tape_34xx_erp_retry(request
);
522 * Function incompatible. Either the tape is idrc compressed
523 * but the hardware isn't capable to do idrc, or a perform
524 * subsystem func is issued and the CU is not on-line.
526 PRINT_WARN ("Function incompatible. Try to switch off idrc\n");
527 return tape_34xx_erp_failed(request
, -EIO
);
530 * Unsolicited environmental data. An internal counter
531 * overflows, we can ignore this and reissue the cmd.
533 return tape_34xx_erp_retry(request
);
536 * Environmental data present. Indicates either unload
537 * completed ok or read buffered log command completed ok.
539 if (request
->op
== TO_RUN
) {
540 /* Rewind unload completed ok. */
541 tape_med_state_set(device
, MS_UNLOADED
);
542 return tape_34xx_erp_succeeded(request
);
544 /* tape_34xx doesn't use read buffered log commands. */
545 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
548 * Permanent equipment check. CU has tried recovery, but
551 return tape_34xx_erp_failed(request
, -EIO
);
553 /* Data security erase failure. */
554 if (request
->op
== TO_DSE
)
555 return tape_34xx_erp_failed(request
, -EIO
);
556 /* Data security erase failure, but no such command issued. */
557 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
560 * Not capable. This indicates either that the drive fails
561 * reading the format id mark or that that format specified
562 * is not supported by the drive.
564 PRINT_WARN("Drive not capable processing the tape format!\n");
565 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
567 /* The medium is write protected. */
568 PRINT_WARN("Medium is write protected!\n");
569 return tape_34xx_erp_failed(request
, -EACCES
);
571 // Tension loss. We cannot recover this, it's an I/O error.
572 PRINT_WARN("The drive lost tape tension.\n");
573 return tape_34xx_erp_failed(request
, -EIO
);
576 * Load Failure. The cartridge was not inserted correctly or
577 * the tape is not threaded correctly.
579 PRINT_WARN("Cartridge load failure. Reload the cartridge "
581 tape_34xx_delete_sbid_from(device
, 0);
582 return tape_34xx_erp_failed(request
, -EIO
);
585 * Unload failure. The drive cannot maintain tape tension
586 * and control tape movement during an unload operation.
588 PRINT_WARN("Failure during cartridge unload. "
589 "Please try manually.\n");
590 if (request
->op
== TO_RUN
)
591 return tape_34xx_erp_failed(request
, -EIO
);
592 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
595 * Drive equipment check. One of the following:
596 * - cu cannot recover from a drive detected error
597 * - a check code message is shown on drive display
598 * - the cartridge loader does not respond correctly
599 * - a failure occurs during an index, load, or unload cycle
601 PRINT_WARN("Equipment check! Please check the drive and "
602 "the cartridge loader.\n");
603 return tape_34xx_erp_failed(request
, -EIO
);
605 if (device
->cdev
->id
.driver_info
== tape_3490
)
607 return tape_34xx_erp_failed(request
, -EIO
);
608 /* This erpa is reserved for 3480 */
609 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
612 * Tape length error. The tape is shorter than reported in
613 * the beginning-of-tape data.
615 PRINT_WARN("Tape length error.\n");
616 return tape_34xx_erp_failed(request
, -EIO
);
619 * Physical end of tape. A read/write operation reached
620 * the physical end of tape.
622 if (request
->op
==TO_WRI
||
623 request
->op
==TO_DSE
||
625 return tape_34xx_erp_failed(request
, -ENOSPC
);
626 return tape_34xx_erp_failed(request
, -EIO
);
628 /* Backward at Beginning of tape. */
629 return tape_34xx_erp_failed(request
, -EIO
);
631 /* Drive switched to not ready. */
632 PRINT_WARN("Drive not ready. Turn the ready/not ready switch "
633 "to ready position and try again.\n");
634 return tape_34xx_erp_failed(request
, -EIO
);
636 /* Manual rewind or unload. This causes an I/O error. */
637 PRINT_WARN("Medium was rewound or unloaded manually.\n");
638 tape_34xx_delete_sbid_from(device
, 0);
639 return tape_34xx_erp_failed(request
, -EIO
);
642 * Degraded mode. A condition that can cause degraded
643 * performance is detected.
645 PRINT_WARN("Subsystem is running in degraded mode.\n");
646 return tape_34xx_erp_retry(request
);
648 /* Drive not ready. */
649 tape_34xx_delete_sbid_from(device
, 0);
650 tape_med_state_set(device
, MS_UNLOADED
);
651 /* Some commands commands are successful even in this case */
652 if (sense
[1] & SENSE_DRIVE_ONLINE
) {
653 switch(request
->op
) {
658 return tape_34xx_done(request
);
664 PRINT_WARN("The drive is not ready.\n");
665 return tape_34xx_erp_failed(request
, -ENOMEDIUM
);
667 /* Locate Block unsuccessful. */
668 if (request
->op
!= TO_BLOCK
&& request
->op
!= TO_LBL
)
669 /* No locate block was issued. */
670 return tape_34xx_erp_bug(device
, request
,
672 return tape_34xx_erp_failed(request
, -EIO
);
674 /* The drive is assigned to a different channel path. */
675 PRINT_WARN("The drive is assigned elsewhere.\n");
676 return tape_34xx_erp_failed(request
, -EIO
);
679 * Drive not on-line. Drive may be switched offline,
680 * the power supply may be switched off or
681 * the drive address may not be set correctly.
683 PRINT_WARN("The drive is not on-line.");
684 return tape_34xx_erp_failed(request
, -EIO
);
686 /* Volume fenced. CU reports volume integrity is lost. */
687 PRINT_WARN("Volume fenced. The volume integrity is lost.\n");
688 tape_34xx_delete_sbid_from(device
, 0);
689 return tape_34xx_erp_failed(request
, -EIO
);
691 /* Log sense data and retry request. */
692 return tape_34xx_erp_retry(request
);
694 /* Bus out check. A parity check error on the bus was found. */
695 PRINT_WARN("Bus out check. A data transfer over the bus "
696 "has been corrupted.\n");
697 return tape_34xx_erp_failed(request
, -EIO
);
699 /* Control unit erp failed. */
700 PRINT_WARN("The control unit I/O error recovery failed.\n");
701 return tape_34xx_erp_failed(request
, -EIO
);
704 * CU and drive incompatible. The drive requests micro-program
705 * patches, which are not available on the CU.
707 PRINT_WARN("The drive needs microprogram patches from the "
708 "control unit, which are not available.\n");
709 return tape_34xx_erp_failed(request
, -EIO
);
712 * Recovered Check-One failure. Cu develops a hardware error,
713 * but is able to recover.
715 return tape_34xx_erp_retry(request
);
717 if (device
->cdev
->id
.driver_info
== tape_3490
)
719 * Resetting event received. Since the driver does
720 * not support resetting event recovery (which has to
721 * be handled by the I/O Layer), retry our command.
723 return tape_34xx_erp_retry(request
);
724 /* This erpa is reserved for 3480. */
725 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
727 if (device
->cdev
->id
.driver_info
== tape_3490
) {
729 * Maximum block size exceeded. This indicates, that
730 * the block to be written is larger than allowed for
733 PRINT_WARN("Maximum block size for buffered "
735 return tape_34xx_erp_failed(request
, -ENOBUFS
);
737 /* This erpa is reserved for 3480. */
738 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
741 * Read buffered log (Overflow). CU is running in extended
742 * buffered log mode, and a counter overflows. This should
743 * never happen, since we're never running in extended
746 return tape_34xx_erp_retry(request
);
749 * Read buffered log (EOV). EOF processing occurs while the
750 * CU is in extended buffered log mode. This should never
751 * happen, since we're never running in extended buffered
754 return tape_34xx_erp_retry(request
);
756 /* End of Volume complete. Rewind unload completed ok. */
757 if (request
->op
== TO_RUN
) {
758 tape_med_state_set(device
, MS_UNLOADED
);
759 tape_34xx_delete_sbid_from(device
, 0);
760 return tape_34xx_erp_succeeded(request
);
762 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
764 /* Global command intercept. */
765 return tape_34xx_erp_retry(request
);
767 /* Channel interface recovery (temporary). */
768 return tape_34xx_erp_retry(request
);
770 /* Channel interface recovery (permanent). */
771 PRINT_WARN("A permanent channel interface error occurred.\n");
772 return tape_34xx_erp_failed(request
, -EIO
);
774 /* Channel protocol error. */
775 PRINT_WARN("A channel protocol error occurred.\n");
776 return tape_34xx_erp_failed(request
, -EIO
);
778 if (device
->cdev
->id
.driver_info
== tape_3480
) {
779 /* Attention intercept. */
780 PRINT_WARN("An attention intercept occurred, "
781 "which will be recovered.\n");
782 return tape_34xx_erp_retry(request
);
784 /* Global status intercept. */
785 PRINT_WARN("An global status intercept was received, "
786 "which will be recovered.\n");
787 return tape_34xx_erp_retry(request
);
791 * Tape length incompatible. The tape inserted is too long,
792 * which could cause damage to the tape or the drive.
794 PRINT_WARN("Tape Length Incompatible\n");
795 PRINT_WARN("Tape length exceeds IBM enhanced capacity "
796 "cartdridge length or a medium\n");
797 PRINT_WARN("with EC-CST identification mark has been mounted "
798 "in a device that writes\n");
799 PRINT_WARN("3480 or 3480 XF format.\n");
800 return tape_34xx_erp_failed(request
, -EIO
);
802 /* Format 3480 XF incompatible */
803 if (sense
[1] & SENSE_BEGINNING_OF_TAPE
)
804 /* The tape will get overwritten. */
805 return tape_34xx_erp_retry(request
);
806 PRINT_WARN("Format 3480 XF Incompatible\n");
807 PRINT_WARN("Medium has been created in 3480 format. "
808 "To change the format writes\n");
809 PRINT_WARN("must be issued at BOT.\n");
810 return tape_34xx_erp_failed(request
, -EIO
);
812 /* Format 3480-2 XF incompatible */
813 PRINT_WARN("Format 3480-2 XF Incompatible\n");
814 PRINT_WARN("Device can only read 3480 or 3480 XF format.\n");
815 return tape_34xx_erp_failed(request
, -EIO
);
817 /* Tape length violation. */
818 PRINT_WARN("Tape Length Violation\n");
819 PRINT_WARN("The mounted tape exceeds IBM Enhanced Capacity "
820 "Cartdridge System Tape length.\n");
821 PRINT_WARN("This may cause damage to the drive or tape when "
822 "processing to the EOV\n");
823 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
825 /* Compaction algorithm incompatible. */
826 PRINT_WARN("Compaction Algorithm Incompatible\n");
827 PRINT_WARN("The volume is recorded using an incompatible "
828 "compaction algorithm,\n");
829 PRINT_WARN("which is not supported by the device.\n");
830 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
832 /* The following erpas should have been covered earlier. */
833 case 0x23: /* Read data check. */
834 case 0x25: /* Write data check. */
835 case 0x26: /* Data check (read opposite). */
836 case 0x28: /* Write id mark check. */
837 case 0x31: /* Tape void. */
838 case 0x40: /* Overrun error. */
839 case 0x41: /* Record sequence error. */
840 /* All other erpas are reserved for future use. */
842 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
847 * 3480/3490 interrupt handler
850 tape_34xx_irq(struct tape_device
*device
, struct tape_request
*request
,
854 return tape_34xx_unsolicited_irq(device
, irb
);
856 if ((irb
->scsw
.dstat
& DEV_STAT_UNIT_EXCEP
) &&
857 (irb
->scsw
.dstat
& DEV_STAT_DEV_END
) &&
858 (request
->op
== TO_WRI
)) {
859 /* Write at end of volume */
860 PRINT_INFO("End of volume\n"); /* XXX */
861 return tape_34xx_erp_failed(request
, -ENOSPC
);
864 if (irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
)
865 return tape_34xx_unit_check(device
, request
, irb
);
867 if (irb
->scsw
.dstat
& DEV_STAT_DEV_END
) {
869 * A unit exception occurs on skipping over a tapemark block.
871 if (irb
->scsw
.dstat
& DEV_STAT_UNIT_EXCEP
) {
872 if (request
->op
== TO_BSB
|| request
->op
== TO_FSB
)
875 DBF_EVENT(5, "Unit Exception!\n");
877 return tape_34xx_done(request
);
880 DBF_EVENT(6, "xunknownirq\n");
881 PRINT_ERR("Unexpected interrupt.\n");
882 PRINT_ERR("Current op is: %s", tape_op_verbose
[request
->op
]);
883 tape_dump_sense(device
, request
, irb
);
891 tape_34xx_ioctl(struct tape_device
*device
, unsigned int cmd
, unsigned long arg
)
893 if (cmd
== TAPE390_DISPLAY
) {
894 struct display_struct disp
;
896 if (copy_from_user(&disp
, (char __user
*) arg
, sizeof(disp
)) != 0)
899 return tape_std_display(device
, &disp
);
905 tape_34xx_append_new_sbid(struct tape_34xx_block_id bid
, struct list_head
*l
)
907 struct tape_34xx_sbid
* new_sbid
;
909 new_sbid
= kmalloc(sizeof(*new_sbid
), GFP_ATOMIC
);
914 list_add(&new_sbid
->list
, l
);
918 * Build up the search block ID list. The block ID consists of a logical
919 * block number and a hardware specific part. The hardware specific part
920 * helps the tape drive to speed up searching for a specific block.
923 tape_34xx_add_sbid(struct tape_device
*device
, struct tape_34xx_block_id bid
)
925 struct list_head
* sbid_list
;
926 struct tape_34xx_sbid
* sbid
;
927 struct list_head
* l
;
930 * immediately return if there is no list at all or the block to add
931 * is located in segment 1 of wrap 0 because this position is used
932 * if no hardware position data is supplied.
934 sbid_list
= (struct list_head
*) device
->discdata
;
935 if (!sbid_list
|| (bid
.segment
< 2 && bid
.wrap
== 0))
939 * Search the position where to insert the new entry. Hardware
940 * acceleration uses only the segment and wrap number. So we
941 * need only one entry for a specific wrap/segment combination.
942 * If there is a block with a lower number but the same hard-
943 * ware position data we just update the block number in the
946 list_for_each(l
, sbid_list
) {
947 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
950 (sbid
->bid
.segment
== bid
.segment
) &&
951 (sbid
->bid
.wrap
== bid
.wrap
)
953 if (bid
.block
< sbid
->bid
.block
)
959 /* Sort in according to logical block number. */
960 if (bid
.block
< sbid
->bid
.block
) {
961 tape_34xx_append_new_sbid(bid
, l
->prev
);
965 /* List empty or new block bigger than last entry. */
967 tape_34xx_append_new_sbid(bid
, l
->prev
);
969 DBF_LH(4, "Current list is:\n");
970 list_for_each(l
, sbid_list
) {
971 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
972 DBF_LH(4, "%d:%03d@%05d\n",
981 * Delete all entries from the search block ID list that belong to tape blocks
982 * equal or higher than the given number.
985 tape_34xx_delete_sbid_from(struct tape_device
*device
, int from
)
987 struct list_head
* sbid_list
;
988 struct tape_34xx_sbid
* sbid
;
989 struct list_head
* l
;
990 struct list_head
* n
;
992 sbid_list
= (struct list_head
*) device
->discdata
;
996 list_for_each_safe(l
, n
, sbid_list
) {
997 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
998 if (sbid
->bid
.block
>= from
) {
999 DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
1011 * Merge hardware position data into a block id.
1014 tape_34xx_merge_sbid(
1015 struct tape_device
* device
,
1016 struct tape_34xx_block_id
* bid
1018 struct tape_34xx_sbid
* sbid
;
1019 struct tape_34xx_sbid
* sbid_to_use
;
1020 struct list_head
* sbid_list
;
1021 struct list_head
* l
;
1023 sbid_list
= (struct list_head
*) device
->discdata
;
1027 if (!sbid_list
|| list_empty(sbid_list
))
1031 list_for_each(l
, sbid_list
) {
1032 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
1034 if (sbid
->bid
.block
>= bid
->block
)
1039 bid
->wrap
= sbid_to_use
->bid
.wrap
;
1040 bid
->segment
= sbid_to_use
->bid
.segment
;
1041 DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
1042 sbid_to_use
->bid
.wrap
,
1043 sbid_to_use
->bid
.segment
,
1044 sbid_to_use
->bid
.block
,
1051 tape_34xx_setup_device(struct tape_device
* device
)
1054 struct list_head
* discdata
;
1056 DBF_EVENT(6, "34xx device setup\n");
1057 if ((rc
= tape_std_assign(device
)) == 0) {
1058 if ((rc
= tape_34xx_medium_sense(device
)) != 0) {
1059 DBF_LH(3, "34xx medium sense returned %d\n", rc
);
1062 discdata
= kmalloc(sizeof(struct list_head
), GFP_KERNEL
);
1064 INIT_LIST_HEAD(discdata
);
1065 device
->discdata
= discdata
;
1072 tape_34xx_cleanup_device(struct tape_device
*device
)
1074 tape_std_unassign(device
);
1076 if (device
->discdata
) {
1077 tape_34xx_delete_sbid_from(device
, 0);
1078 kfree(device
->discdata
);
1079 device
->discdata
= NULL
;
1085 * MTTELL: Tell block. Return the number of block relative to current file.
1088 tape_34xx_mttell(struct tape_device
*device
, int mt_count
)
1091 struct tape_34xx_block_id cbid
;
1092 struct tape_34xx_block_id dbid
;
1093 } __attribute__ ((packed
)) block_id
;
1096 rc
= tape_std_read_block_id(device
, (__u64
*) &block_id
);
1100 tape_34xx_add_sbid(device
, block_id
.cbid
);
1101 return block_id
.cbid
.block
;
1105 * MTSEEK: seek to the specified block.
1108 tape_34xx_mtseek(struct tape_device
*device
, int mt_count
)
1110 struct tape_request
*request
;
1111 struct tape_34xx_block_id
* bid
;
1113 if (mt_count
> 0x3fffff) {
1114 DBF_EXCEPTION(6, "xsee parm\n");
1117 request
= tape_alloc_request(3, 4);
1118 if (IS_ERR(request
))
1119 return PTR_ERR(request
);
1122 request
->op
= TO_LBL
;
1123 bid
= (struct tape_34xx_block_id
*) request
->cpdata
;
1124 bid
->format
= (*device
->modeset_byte
& 0x08) ?
1125 TAPE34XX_FMT_3480_XF
: TAPE34XX_FMT_3480
;
1126 bid
->block
= mt_count
;
1127 tape_34xx_merge_sbid(device
, bid
);
1129 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
1130 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
1131 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
1134 return tape_do_io_free(device
, request
);
1137 #ifdef CONFIG_S390_TAPE_BLOCK
1139 * Tape block read for 34xx.
1141 static struct tape_request
*
1142 tape_34xx_bread(struct tape_device
*device
, struct request
*req
)
1144 struct tape_request
*request
;
1151 struct tape_34xx_block_id
* start_block
;
1153 DBF_EVENT(6, "xBREDid:");
1155 /* Count the number of blocks for the request. */
1156 rq_for_each_bio(bio
, req
) {
1157 bio_for_each_segment(bv
, bio
, i
) {
1158 count
+= bv
->bv_len
>> (TAPEBLOCK_HSEC_S2B
+ 9);
1162 /* Allocate the ccw request. */
1163 request
= tape_alloc_request(3+count
+1, 8);
1164 if (IS_ERR(request
))
1168 request
->op
= TO_BLOCK
;
1169 start_block
= (struct tape_34xx_block_id
*) request
->cpdata
;
1170 start_block
->block
= req
->sector
>> TAPEBLOCK_HSEC_S2B
;
1171 DBF_EVENT(6, "start_block = %i\n", start_block
->block
);
1173 ccw
= request
->cpaddr
;
1174 ccw
= tape_ccw_cc(ccw
, MODE_SET_DB
, 1, device
->modeset_byte
);
1177 * We always setup a nop after the mode set ccw. This slot is
1178 * used in tape_std_check_locate to insert a locate ccw if the
1179 * current tape position doesn't match the start block to be read.
1180 * The second nop will be filled with a read block id which is in
1181 * turn used by tape_34xx_free_bread to populate the segment bid
1184 ccw
= tape_ccw_cc(ccw
, NOP
, 0, NULL
);
1185 ccw
= tape_ccw_cc(ccw
, NOP
, 0, NULL
);
1187 rq_for_each_bio(bio
, req
) {
1188 bio_for_each_segment(bv
, bio
, i
) {
1189 dst
= kmap(bv
->bv_page
) + bv
->bv_offset
;
1190 for (off
= 0; off
< bv
->bv_len
;
1191 off
+= TAPEBLOCK_HSEC_SIZE
) {
1192 ccw
->flags
= CCW_FLAG_CC
;
1193 ccw
->cmd_code
= READ_FORWARD
;
1194 ccw
->count
= TAPEBLOCK_HSEC_SIZE
;
1195 set_normalized_cda(ccw
, (void*) __pa(dst
));
1197 dst
+= TAPEBLOCK_HSEC_SIZE
;
1202 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
1203 DBF_EVENT(6, "xBREDccwg\n");
1208 tape_34xx_free_bread (struct tape_request
*request
)
1212 ccw
= request
->cpaddr
;
1213 if ((ccw
+ 2)->cmd_code
== READ_BLOCK_ID
) {
1215 struct tape_34xx_block_id cbid
;
1216 struct tape_34xx_block_id dbid
;
1217 } __attribute__ ((packed
)) *rbi_data
;
1219 rbi_data
= request
->cpdata
;
1221 if (request
->device
)
1222 tape_34xx_add_sbid(request
->device
, rbi_data
->cbid
);
1225 /* Last ccw is a nop and doesn't need clear_normalized_cda */
1226 for (; ccw
->flags
& CCW_FLAG_CC
; ccw
++)
1227 if (ccw
->cmd_code
== READ_FORWARD
)
1228 clear_normalized_cda(ccw
);
1229 tape_free_request(request
);
1233 * check_locate is called just before the tape request is passed to
1234 * the common io layer for execution. It has to check the current
1235 * tape position and insert a locate ccw if it doesn't match the
1236 * start block for the request.
1239 tape_34xx_check_locate(struct tape_device
*device
, struct tape_request
*request
)
1241 struct tape_34xx_block_id
* start_block
;
1243 start_block
= (struct tape_34xx_block_id
*) request
->cpdata
;
1244 if (start_block
->block
== device
->blk_data
.block_position
)
1247 DBF_LH(4, "Block seek(%06d+%06d)\n", start_block
->block
, device
->bof
);
1248 start_block
->wrap
= 0;
1249 start_block
->segment
= 1;
1250 start_block
->format
= (*device
->modeset_byte
& 0x08) ?
1251 TAPE34XX_FMT_3480_XF
:
1253 start_block
->block
= start_block
->block
+ device
->bof
;
1254 tape_34xx_merge_sbid(device
, start_block
);
1255 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
1256 tape_ccw_cc(request
->cpaddr
+ 2, READ_BLOCK_ID
, 8, request
->cpdata
);
1261 * List of 3480/3490 magnetic tape commands.
1263 static tape_mtop_fn tape_34xx_mtop
[TAPE_NR_MTOPS
] = {
1264 [MTRESET
] = tape_std_mtreset
,
1265 [MTFSF
] = tape_std_mtfsf
,
1266 [MTBSF
] = tape_std_mtbsf
,
1267 [MTFSR
] = tape_std_mtfsr
,
1268 [MTBSR
] = tape_std_mtbsr
,
1269 [MTWEOF
] = tape_std_mtweof
,
1270 [MTREW
] = tape_std_mtrew
,
1271 [MTOFFL
] = tape_std_mtoffl
,
1272 [MTNOP
] = tape_std_mtnop
,
1273 [MTRETEN
] = tape_std_mtreten
,
1274 [MTBSFM
] = tape_std_mtbsfm
,
1275 [MTFSFM
] = tape_std_mtfsfm
,
1276 [MTEOM
] = tape_std_mteom
,
1277 [MTERASE
] = tape_std_mterase
,
1281 [MTSETBLK
] = tape_std_mtsetblk
,
1282 [MTSETDENSITY
] = NULL
,
1283 [MTSEEK
] = tape_34xx_mtseek
,
1284 [MTTELL
] = tape_34xx_mttell
,
1285 [MTSETDRVBUFFER
] = NULL
,
1291 [MTLOAD
] = tape_std_mtload
,
1292 [MTUNLOAD
] = tape_std_mtunload
,
1293 [MTCOMPRESSION
] = tape_std_mtcompression
,
1299 * Tape discipline structure for 3480 and 3490.
1301 static struct tape_discipline tape_discipline_34xx
= {
1302 .owner
= THIS_MODULE
,
1303 .setup_device
= tape_34xx_setup_device
,
1304 .cleanup_device
= tape_34xx_cleanup_device
,
1305 .process_eov
= tape_std_process_eov
,
1306 .irq
= tape_34xx_irq
,
1307 .read_block
= tape_std_read_block
,
1308 .write_block
= tape_std_write_block
,
1309 #ifdef CONFIG_S390_TAPE_BLOCK
1310 .bread
= tape_34xx_bread
,
1311 .free_bread
= tape_34xx_free_bread
,
1312 .check_locate
= tape_34xx_check_locate
,
1314 .ioctl_fn
= tape_34xx_ioctl
,
1315 .mtop_array
= tape_34xx_mtop
1318 static struct ccw_device_id tape_34xx_ids
[] = {
1319 { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), driver_info
: tape_3480
},
1320 { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), driver_info
: tape_3490
},
1321 { /* end of list */ }
1325 tape_34xx_online(struct ccw_device
*cdev
)
1327 return tape_generic_online(
1328 cdev
->dev
.driver_data
,
1329 &tape_discipline_34xx
1334 tape_34xx_offline(struct ccw_device
*cdev
)
1336 return tape_generic_offline(cdev
->dev
.driver_data
);
1339 static struct ccw_driver tape_34xx_driver
= {
1340 .name
= "tape_34xx",
1341 .owner
= THIS_MODULE
,
1342 .ids
= tape_34xx_ids
,
1343 .probe
= tape_generic_probe
,
1344 .remove
= tape_generic_remove
,
1345 .set_online
= tape_34xx_online
,
1346 .set_offline
= tape_34xx_offline
,
1350 tape_34xx_init (void)
1354 TAPE_DBF_AREA
= debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
1355 debug_register_view(TAPE_DBF_AREA
, &debug_sprintf_view
);
1356 #ifdef DBF_LIKE_HELL
1357 debug_set_level(TAPE_DBF_AREA
, 6);
1360 DBF_EVENT(3, "34xx init: $Revision: 1.23 $\n");
1361 /* Register driver for 3480/3490 tapes. */
1362 rc
= ccw_driver_register(&tape_34xx_driver
);
1364 DBF_EVENT(3, "34xx init failed\n");
1366 DBF_EVENT(3, "34xx registered\n");
1371 tape_34xx_exit(void)
1373 ccw_driver_unregister(&tape_34xx_driver
);
1375 debug_unregister(TAPE_DBF_AREA
);
1378 MODULE_DEVICE_TABLE(ccw
, tape_34xx_ids
);
1379 MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
1380 MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape "
1381 "device driver ($Revision: 1.23 $)");
1382 MODULE_LICENSE("GPL");
1384 module_init(tape_34xx_init
);
1385 module_exit(tape_34xx_exit
);