2 * drivers/s390/char/tape_34xx.c
3 * tape device discipline for 3480/3490 tapes.
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>
11 #define KMSG_COMPONENT "tape_34xx"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/bio.h>
17 #include <linux/workqueue.h>
19 #define TAPE_DBF_AREA tape_34xx_dbf
25 * Pointer to debug area.
27 debug_info_t
*TAPE_DBF_AREA
= NULL
;
28 EXPORT_SYMBOL(TAPE_DBF_AREA
);
30 #define TAPE34XX_FMT_3480 0
31 #define TAPE34XX_FMT_3480_2_XF 1
32 #define TAPE34XX_FMT_3480_XF 2
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;
42 * A list of block ID's is used to faster seek blocks.
44 struct tape_34xx_sbid
{
45 struct list_head list
;
46 struct tape_34xx_block_id bid
;
49 static void tape_34xx_delete_sbid_from(struct tape_device
*, int);
52 * Medium sense for 34xx tapes. There is no 'real' medium sense call.
53 * So we just do a normal sense.
56 tape_34xx_medium_sense(struct tape_device
*device
)
58 struct tape_request
*request
;
62 request
= tape_alloc_request(1, 32);
63 if (IS_ERR(request
)) {
64 DBF_EXCEPTION(6, "MSEN fail\n");
65 return PTR_ERR(request
);
68 request
->op
= TO_MSEN
;
69 tape_ccw_end(request
->cpaddr
, SENSE
, 32, request
->cpdata
);
71 rc
= tape_do_io_interruptible(device
, request
);
72 if (request
->rc
== 0) {
73 sense
= request
->cpdata
;
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...
81 if (sense
[0] & SENSE_INTERVENTION_REQUIRED
)
82 tape_med_state_set(device
, MS_UNLOADED
);
84 tape_med_state_set(device
, MS_LOADED
);
86 if (sense
[1] & SENSE_WRITE_PROTECT
)
87 device
->tape_generic_status
|= GMT_WR_PROT(~0);
89 device
->tape_generic_status
&= ~GMT_WR_PROT(~0);
91 DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
94 tape_free_request(request
);
99 struct tape_34xx_work
{
100 struct tape_device
*device
;
102 struct work_struct work
;
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(struct work_struct
*work
)
115 struct tape_34xx_work
*p
=
116 container_of(work
, struct tape_34xx_work
, work
);
117 struct tape_device
*device
= p
->device
;
121 tape_34xx_medium_sense(device
);
124 DBF_EVENT(3, "T34XX: internal error: unknown work\n");
126 tape_put_device(device
);
131 tape_34xx_schedule_work(struct tape_device
*device
, enum tape_op op
)
133 struct tape_34xx_work
*p
;
135 if ((p
= kzalloc(sizeof(*p
), GFP_ATOMIC
)) == NULL
)
138 INIT_WORK(&p
->work
, tape_34xx_work_handler
);
140 p
->device
= tape_get_device(device
);
143 schedule_work(&p
->work
);
148 * Done Handler is called when dev stat = DEVICE-END (successful operation)
151 tape_34xx_done(struct tape_request
*request
)
153 DBF_EVENT(6, "%s done\n", tape_op_verbose
[request
->op
]);
155 switch (request
->op
) {
162 tape_34xx_delete_sbid_from(request
->device
, 0);
167 return TAPE_IO_SUCCESS
;
171 tape_34xx_erp_failed(struct tape_request
*request
, int rc
)
173 DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
174 tape_op_verbose
[request
->op
], rc
);
179 tape_34xx_erp_succeeded(struct tape_request
*request
)
181 DBF_EVENT(3, "Error Recovery successful for %s\n",
182 tape_op_verbose
[request
->op
]);
183 return tape_34xx_done(request
);
187 tape_34xx_erp_retry(struct tape_request
*request
)
189 DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose
[request
->op
]);
190 return TAPE_IO_RETRY
;
194 * This function is called, when no request is outstanding and we get an
198 tape_34xx_unsolicited_irq(struct tape_device
*device
, struct irb
*irb
)
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
);
206 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device
->cdev_id
);
207 tape_dump_sense_dbf(device
, NULL
, irb
);
209 return TAPE_IO_SUCCESS
;
213 * Read Opposite Error Recovery Function:
214 * Used, when Read Forward does not work
217 tape_34xx_erp_read_opposite(struct tape_device
*device
,
218 struct tape_request
*request
)
220 if (request
->op
== TO_RFO
) {
222 * We did read forward, but the data could not be read
223 * *correctly*. We transform the request to a read backward
226 tape_std_read_backward(device
, request
);
227 return tape_34xx_erp_retry(request
);
231 * We tried to read forward and backward, but hat no
234 return tape_34xx_erp_failed(request
, -EIO
);
238 tape_34xx_erp_bug(struct tape_device
*device
, struct tape_request
*request
,
239 struct irb
*irb
, int no
)
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
);
246 return tape_34xx_erp_failed(request
, -EIO
);
250 * Handle data overrun between cu and drive. The channel speed might
254 tape_34xx_erp_overrun(struct tape_device
*device
, struct tape_request
*request
,
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
);
262 return tape_34xx_erp_bug(device
, request
, irb
, -1);
266 * Handle record sequence error.
269 tape_34xx_erp_sequence(struct tape_device
*device
,
270 struct tape_request
*request
, struct irb
*irb
)
272 if (irb
->ecw
[3] == 0x41) {
274 * cu detected incorrect block-id sequence on tape.
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
);
281 * Record sequence error bit is set, but erpa does not
282 * show record sequence error.
284 return tape_34xx_erp_bug(device
, request
, irb
, -2);
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.
293 tape_34xx_unit_check(struct tape_device
*device
, struct tape_request
*request
,
296 int inhibit_cu_recovery
;
299 inhibit_cu_recovery
= (*device
->modeset_byte
& 0x80) ? 1 : 0;
302 #ifdef CONFIG_S390_TAPE_BLOCK
303 if (request
->op
== TO_BLOCK
) {
305 * Recovery for block device requests. Set the block_position
306 * to something invalid and retry.
308 device
->blk_data
.block_position
= -1;
309 if (request
->retries
-- <= 0)
310 return tape_34xx_erp_failed(request
, -EIO
);
312 return tape_34xx_erp_retry(request
);
317 sense
[0] & SENSE_COMMAND_REJECT
&&
318 sense
[1] & SENSE_WRITE_PROTECT
321 request
->op
== TO_DSE
||
322 request
->op
== TO_WRI
||
323 request
->op
== TO_WTM
325 /* medium is write protected */
326 return tape_34xx_erp_failed(request
, -EACCES
);
328 return tape_34xx_erp_bug(device
, request
, irb
, -3);
333 * Special cases for various tape-states when reaching
334 * end of recorded area
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)
341 * This was caused by continued FSF or FSR after an
345 sense
[0] == SENSE_DATA_CHECK
||
346 sense
[0] == SENSE_EQUIPMENT_CHECK
||
347 sense
[0] == SENSE_EQUIPMENT_CHECK
+ SENSE_DEFERRED_UNIT_CHECK
349 sense
[1] == SENSE_DRIVE_ONLINE
||
350 sense
[1] == SENSE_BEGINNING_OF_TAPE
+ SENSE_WRITE_MODE
352 switch (request
->op
) {
354 * sense[0] == SENSE_DATA_CHECK &&
355 * sense[1] == SENSE_DRIVE_ONLINE
356 * sense[3] == 0x36 (End Of Data)
358 * Further seeks might return a 'Volume Fenced'.
362 /* Trying to seek beyond end of recorded area */
363 return tape_34xx_erp_failed(request
, -ENOSPC
);
365 return tape_34xx_erp_retry(request
);
368 * sense[0] == SENSE_DATA_CHECK &&
369 * sense[1] == SENSE_DRIVE_ONLINE &&
370 * sense[3] == 0x36 (End Of Data)
373 /* Block could not be located. */
374 tape_34xx_delete_sbid_from(device
, 0);
375 return tape_34xx_erp_failed(request
, -EIO
);
378 /* Read beyond end of recorded area -> 0 bytes read */
379 return tape_34xx_erp_failed(request
, 0);
382 * sense[0] == SENSE_EQUIPMENT_CHECK &&
383 * sense[1] == SENSE_DRIVE_ONLINE &&
384 * sense[3] == 0x38 (Physical End Of Volume)
387 /* Writing at physical end of volume */
388 return tape_34xx_erp_failed(request
, -ENOSPC
);
390 return tape_34xx_erp_failed(request
, 0);
394 /* Sensing special bits */
395 if (sense
[0] & SENSE_BUS_OUT_CHECK
)
396 return tape_34xx_erp_retry(request
);
398 if (sense
[0] & SENSE_DATA_CHECK
) {
400 * hardware failure, damaged tape or improper
401 * operating conditions
405 /* a read data check occurred */
406 if ((sense
[2] & SENSE_TAPE_SYNC_MODE
) ||
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
,
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
);
419 // a write data check occurred
420 if ((sense
[2] & SENSE_TAPE_SYNC_MODE
) ||
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
,
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
);
433 /* Data Check (read opposite) occurred. */
434 return tape_34xx_erp_read_opposite(device
, request
);
436 /* ID-Mark at tape start couldn't be written */
437 dev_warn (&device
->cdev
->dev
, "Writing the ID-mark "
439 return tape_34xx_erp_failed(request
, -EIO
);
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
);
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
);
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
,
460 if (sense
[0] & SENSE_OVERRUN
)
461 return tape_34xx_erp_overrun(device
, request
, irb
);
463 if (sense
[1] & SENSE_RECORD_SEQUENCE_ERR
)
464 return tape_34xx_erp_sequence(device
, request
, irb
);
466 /* Sensing erpa codes */
469 /* Unit check with erpa code 0. Report and ignore. */
470 return TAPE_IO_SUCCESS
;
473 * Data streaming not operational. CU will switch to
474 * interlock mode. Reissue the command.
476 return tape_34xx_erp_retry(request
);
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.
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
);
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".
492 return tape_34xx_erp_succeeded(request
);
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.
500 return tape_34xx_erp_retry(request
);
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.
507 return tape_34xx_erp_failed(request
, -EIO
);
510 * Unsolicited environmental data. An internal counter
511 * overflows, we can ignore this and reissue the cmd.
513 return tape_34xx_erp_retry(request
);
516 * Environmental data present. Indicates either unload
517 * completed ok or read buffered log command completed ok.
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
);
524 /* tape_34xx doesn't use read buffered log commands. */
525 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
528 * Permanent equipment check. CU has tried recovery, but
531 return tape_34xx_erp_failed(request
, -EIO
);
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]);
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.
544 dev_warn (&device
->cdev
->dev
, "The tape unit cannot process "
545 "the tape format\n");
546 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
548 /* The medium is write protected. */
549 dev_warn (&device
->cdev
->dev
, "The tape medium is write-"
551 return tape_34xx_erp_failed(request
, -EACCES
);
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
);
559 * Load Failure. The cartridge was not inserted correctly or
560 * the tape is not threaded correctly.
562 dev_warn (&device
->cdev
->dev
, "The tape unit failed to load"
564 tape_34xx_delete_sbid_from(device
, 0);
565 return tape_34xx_erp_failed(request
, -EIO
);
568 * Unload failure. The drive cannot maintain tape tension
569 * and control tape movement during an unload operation.
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]);
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
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
);
588 if (device
->cdev
->id
.driver_info
== tape_3490
)
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]);
595 * Tape length error. The tape is shorter than reported in
596 * the beginning-of-tape data.
598 dev_warn (&device
->cdev
->dev
, "The tape information states an"
599 " incorrect length\n");
600 return tape_34xx_erp_failed(request
, -EIO
);
603 * Physical end of tape. A read/write operation reached
604 * the physical end of tape.
606 if (request
->op
==TO_WRI
||
607 request
->op
==TO_DSE
||
609 return tape_34xx_erp_failed(request
, -ENOSPC
);
610 return tape_34xx_erp_failed(request
, -EIO
);
612 /* Backward at Beginning of tape. */
613 return tape_34xx_erp_failed(request
, -EIO
);
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
);
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
);
626 * Degraded mode. A condition that can cause degraded
627 * performance is detected.
629 dev_warn (&device
->cdev
->dev
, "The tape subsystem is running "
630 "in degraded mode\n");
631 return tape_34xx_erp_retry(request
);
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
) {
643 return tape_34xx_done(request
);
649 return tape_34xx_erp_failed(request
, -ENOMEDIUM
);
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
,
656 return tape_34xx_erp_failed(request
, -EIO
);
658 /* The drive is assigned to a different channel path. */
659 dev_warn (&device
->cdev
->dev
, "The tape unit is already "
661 return tape_34xx_erp_failed(request
, -EIO
);
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.
668 dev_warn (&device
->cdev
->dev
, "The tape unit is not online\n");
669 return tape_34xx_erp_failed(request
, -EIO
);
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
);
677 /* Log sense data and retry request. */
678 return tape_34xx_erp_retry(request
);
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 "
683 return tape_34xx_erp_failed(request
, -EIO
);
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
);
691 * CU and drive incompatible. The drive requests micro-program
692 * patches, which are not available on the CU.
694 dev_warn (&device
->cdev
->dev
, "The tape unit requires a "
695 "firmware update\n");
696 return tape_34xx_erp_failed(request
, -EIO
);
699 * Recovered Check-One failure. Cu develops a hardware error,
700 * but is able to recover.
702 return tape_34xx_erp_retry(request
);
704 if (device
->cdev
->id
.driver_info
== tape_3490
)
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.
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]);
714 if (device
->cdev
->id
.driver_info
== tape_3490
) {
716 * Maximum block size exceeded. This indicates, that
717 * the block to be written is larger than allowed for
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
);
724 /* This erpa is reserved for 3480. */
725 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
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
733 return tape_34xx_erp_retry(request
);
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
741 return tape_34xx_erp_retry(request
);
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
);
749 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
751 /* Global command intercept. */
752 return tape_34xx_erp_retry(request
);
754 /* Channel interface recovery (temporary). */
755 return tape_34xx_erp_retry(request
);
757 /* Channel interface recovery (permanent). */
758 dev_warn (&device
->cdev
->dev
, "A channel interface error cannot be"
760 return tape_34xx_erp_failed(request
, -EIO
);
762 /* Channel protocol error. */
763 dev_warn (&device
->cdev
->dev
, "A channel protocol error "
765 return tape_34xx_erp_failed(request
, -EIO
);
767 if (device
->cdev
->id
.driver_info
== tape_3480
) {
768 /* Attention intercept. */
769 return tape_34xx_erp_retry(request
);
771 /* Global status intercept. */
772 return tape_34xx_erp_retry(request
);
776 * Tape length incompatible. The tape inserted is too long,
777 * which could cause damage to the tape or the drive.
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
);
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
);
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
);
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
);
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
);
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. */
816 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
821 * 3480/3490 interrupt handler
824 tape_34xx_irq(struct tape_device
*device
, struct tape_request
*request
,
828 return tape_34xx_unsolicited_irq(device
, irb
);
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
);
837 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
)
838 return tape_34xx_unit_check(device
, request
, irb
);
840 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_DEV_END
) {
842 * A unit exception occurs on skipping over a tapemark block.
844 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_EXCEP
) {
845 if (request
->op
== TO_BSB
|| request
->op
== TO_FSB
)
848 DBF_EVENT(5, "Unit Exception!\n");
850 return tape_34xx_done(request
);
853 DBF_EVENT(6, "xunknownirq\n");
854 tape_dump_sense_dbf(device
, request
, irb
);
862 tape_34xx_ioctl(struct tape_device
*device
, unsigned int cmd
, unsigned long arg
)
864 if (cmd
== TAPE390_DISPLAY
) {
865 struct display_struct disp
;
867 if (copy_from_user(&disp
, (char __user
*) arg
, sizeof(disp
)) != 0)
870 return tape_std_display(device
, &disp
);
876 tape_34xx_append_new_sbid(struct tape_34xx_block_id bid
, struct list_head
*l
)
878 struct tape_34xx_sbid
* new_sbid
;
880 new_sbid
= kmalloc(sizeof(*new_sbid
), GFP_ATOMIC
);
885 list_add(&new_sbid
->list
, l
);
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.
894 tape_34xx_add_sbid(struct tape_device
*device
, struct tape_34xx_block_id bid
)
896 struct list_head
* sbid_list
;
897 struct tape_34xx_sbid
* sbid
;
898 struct list_head
* l
;
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.
905 sbid_list
= (struct list_head
*) device
->discdata
;
906 if (!sbid_list
|| (bid
.segment
< 2 && bid
.wrap
== 0))
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
917 list_for_each(l
, sbid_list
) {
918 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
921 (sbid
->bid
.segment
== bid
.segment
) &&
922 (sbid
->bid
.wrap
== bid
.wrap
)
924 if (bid
.block
< sbid
->bid
.block
)
930 /* Sort in according to logical block number. */
931 if (bid
.block
< sbid
->bid
.block
) {
932 tape_34xx_append_new_sbid(bid
, l
->prev
);
936 /* List empty or new block bigger than last entry. */
938 tape_34xx_append_new_sbid(bid
, l
->prev
);
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",
952 * Delete all entries from the search block ID list that belong to tape blocks
953 * equal or higher than the given number.
956 tape_34xx_delete_sbid_from(struct tape_device
*device
, int from
)
958 struct list_head
* sbid_list
;
959 struct tape_34xx_sbid
* sbid
;
960 struct list_head
* l
;
961 struct list_head
* n
;
963 sbid_list
= (struct list_head
*) device
->discdata
;
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",
982 * Merge hardware position data into a block id.
985 tape_34xx_merge_sbid(
986 struct tape_device
* device
,
987 struct tape_34xx_block_id
* bid
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
;
994 sbid_list
= (struct list_head
*) device
->discdata
;
998 if (!sbid_list
|| list_empty(sbid_list
))
1002 list_for_each(l
, sbid_list
) {
1003 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
1005 if (sbid
->bid
.block
>= bid
->block
)
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
,
1022 tape_34xx_setup_device(struct tape_device
* device
)
1025 struct list_head
* discdata
;
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
);
1033 discdata
= kmalloc(sizeof(struct list_head
), GFP_KERNEL
);
1035 INIT_LIST_HEAD(discdata
);
1036 device
->discdata
= discdata
;
1043 tape_34xx_cleanup_device(struct tape_device
*device
)
1045 tape_std_unassign(device
);
1047 if (device
->discdata
) {
1048 tape_34xx_delete_sbid_from(device
, 0);
1049 kfree(device
->discdata
);
1050 device
->discdata
= NULL
;
1056 * MTTELL: Tell block. Return the number of block relative to current file.
1059 tape_34xx_mttell(struct tape_device
*device
, int mt_count
)
1062 struct tape_34xx_block_id cbid
;
1063 struct tape_34xx_block_id dbid
;
1064 } __attribute__ ((packed
)) block_id
;
1067 rc
= tape_std_read_block_id(device
, (__u64
*) &block_id
);
1071 tape_34xx_add_sbid(device
, block_id
.cbid
);
1072 return block_id
.cbid
.block
;
1076 * MTSEEK: seek to the specified block.
1079 tape_34xx_mtseek(struct tape_device
*device
, int mt_count
)
1081 struct tape_request
*request
;
1082 struct tape_34xx_block_id
* bid
;
1084 if (mt_count
> 0x3fffff) {
1085 DBF_EXCEPTION(6, "xsee parm\n");
1088 request
= tape_alloc_request(3, 4);
1089 if (IS_ERR(request
))
1090 return PTR_ERR(request
);
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
);
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
);
1105 return tape_do_io_free(device
, request
);
1108 #ifdef CONFIG_S390_TAPE_BLOCK
1110 * Tape block read for 34xx.
1112 static struct tape_request
*
1113 tape_34xx_bread(struct tape_device
*device
, struct request
*req
)
1115 struct tape_request
*request
;
1121 struct req_iterator iter
;
1122 struct tape_34xx_block_id
* start_block
;
1124 DBF_EVENT(6, "xBREDid:");
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);
1130 /* Allocate the ccw request. */
1131 request
= tape_alloc_request(3+count
+1, 8);
1132 if (IS_ERR(request
))
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
);
1141 ccw
= request
->cpaddr
;
1142 ccw
= tape_ccw_cc(ccw
, MODE_SET_DB
, 1, device
->modeset_byte
);
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
1152 ccw
= tape_ccw_cc(ccw
, NOP
, 0, NULL
);
1153 ccw
= tape_ccw_cc(ccw
, NOP
, 0, NULL
);
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
));
1163 dst
+= TAPEBLOCK_HSEC_SIZE
;
1167 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
1168 DBF_EVENT(6, "xBREDccwg\n");
1173 tape_34xx_free_bread (struct tape_request
*request
)
1177 ccw
= request
->cpaddr
;
1178 if ((ccw
+ 2)->cmd_code
== READ_BLOCK_ID
) {
1180 struct tape_34xx_block_id cbid
;
1181 struct tape_34xx_block_id dbid
;
1182 } __attribute__ ((packed
)) *rbi_data
;
1184 rbi_data
= request
->cpdata
;
1186 if (request
->device
)
1187 tape_34xx_add_sbid(request
->device
, rbi_data
->cbid
);
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
);
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.
1204 tape_34xx_check_locate(struct tape_device
*device
, struct tape_request
*request
)
1206 struct tape_34xx_block_id
* start_block
;
1208 start_block
= (struct tape_34xx_block_id
*) request
->cpdata
;
1209 if (start_block
->block
== device
->blk_data
.block_position
)
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
:
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
);
1226 * List of 3480/3490 magnetic tape commands.
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
,
1246 [MTSETBLK
] = tape_std_mtsetblk
,
1247 [MTSETDENSITY
] = NULL
,
1248 [MTSEEK
] = tape_34xx_mtseek
,
1249 [MTTELL
] = tape_34xx_mttell
,
1250 [MTSETDRVBUFFER
] = NULL
,
1256 [MTLOAD
] = tape_std_mtload
,
1257 [MTUNLOAD
] = tape_std_mtunload
,
1258 [MTCOMPRESSION
] = tape_std_mtcompression
,
1264 * Tape discipline structure for 3480 and 3490.
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
,
1279 .ioctl_fn
= tape_34xx_ioctl
,
1280 .mtop_array
= tape_34xx_mtop
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 */ },
1290 tape_34xx_online(struct ccw_device
*cdev
)
1292 return tape_generic_online(
1293 dev_get_drvdata(&cdev
->dev
),
1294 &tape_discipline_34xx
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
,
1310 tape_34xx_init (void)
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);
1320 DBF_EVENT(3, "34xx init\n");
1321 /* Register driver for 3480/3490 tapes. */
1322 rc
= ccw_driver_register(&tape_34xx_driver
);
1324 DBF_EVENT(3, "34xx init failed\n");
1326 DBF_EVENT(3, "34xx registered\n");
1331 tape_34xx_exit(void)
1333 ccw_driver_unregister(&tape_34xx_driver
);
1335 debug_unregister(TAPE_DBF_AREA
);
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");
1343 module_init(tape_34xx_init
);
1344 module_exit(tape_34xx_exit
);