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"
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
24 * Pointer to debug area.
26 debug_info_t
*TAPE_DBF_AREA
= NULL
;
27 EXPORT_SYMBOL(TAPE_DBF_AREA
);
29 #define TAPE34XX_FMT_3480 0
30 #define TAPE34XX_FMT_3480_2_XF 1
31 #define TAPE34XX_FMT_3480_XF 2
33 struct tape_34xx_block_id
{
34 unsigned int wrap
: 1;
35 unsigned int segment
: 7;
36 unsigned int format
: 2;
37 unsigned int block
: 22;
41 * A list of block ID's is used to faster seek blocks.
43 struct tape_34xx_sbid
{
44 struct list_head list
;
45 struct tape_34xx_block_id bid
;
48 static void tape_34xx_delete_sbid_from(struct tape_device
*, int);
51 * Medium sense for 34xx tapes. There is no 'real' medium sense call.
52 * So we just do a normal sense.
55 tape_34xx_medium_sense(struct tape_device
*device
)
57 struct tape_request
*request
;
61 request
= tape_alloc_request(1, 32);
62 if (IS_ERR(request
)) {
63 DBF_EXCEPTION(6, "MSEN fail\n");
64 return PTR_ERR(request
);
67 request
->op
= TO_MSEN
;
68 tape_ccw_end(request
->cpaddr
, SENSE
, 32, request
->cpdata
);
70 rc
= tape_do_io_interruptible(device
, request
);
71 if (request
->rc
== 0) {
72 sense
= request
->cpdata
;
75 * This isn't quite correct. But since INTERVENTION_REQUIRED
76 * means that the drive is 'neither ready nor on-line' it is
77 * only slightly inaccurate to say there is no tape loaded if
78 * the drive isn't online...
80 if (sense
[0] & SENSE_INTERVENTION_REQUIRED
)
81 tape_med_state_set(device
, MS_UNLOADED
);
83 tape_med_state_set(device
, MS_LOADED
);
85 if (sense
[1] & SENSE_WRITE_PROTECT
)
86 device
->tape_generic_status
|= GMT_WR_PROT(~0);
88 device
->tape_generic_status
&= ~GMT_WR_PROT(~0);
90 DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
93 tape_free_request(request
);
98 struct tape_34xx_work
{
99 struct tape_device
*device
;
101 struct work_struct work
;
105 * These functions are currently used only to schedule a medium_sense for
106 * later execution. This is because we get an interrupt whenever a medium
107 * is inserted but cannot call tape_do_io* from an interrupt context.
108 * Maybe that's useful for other actions we want to start from the
112 tape_34xx_work_handler(struct work_struct
*work
)
114 struct tape_34xx_work
*p
=
115 container_of(work
, struct tape_34xx_work
, work
);
119 tape_34xx_medium_sense(p
->device
);
122 DBF_EVENT(3, "T34XX: internal error: unknown work\n");
125 p
->device
= tape_put_device(p
->device
);
130 tape_34xx_schedule_work(struct tape_device
*device
, enum tape_op op
)
132 struct tape_34xx_work
*p
;
134 if ((p
= kzalloc(sizeof(*p
), GFP_ATOMIC
)) == NULL
)
137 INIT_WORK(&p
->work
, tape_34xx_work_handler
);
139 p
->device
= tape_get_device_reference(device
);
142 schedule_work(&p
->work
);
147 * Done Handler is called when dev stat = DEVICE-END (successful operation)
150 tape_34xx_done(struct tape_request
*request
)
152 DBF_EVENT(6, "%s done\n", tape_op_verbose
[request
->op
]);
154 switch (request
->op
) {
161 tape_34xx_delete_sbid_from(request
->device
, 0);
166 return TAPE_IO_SUCCESS
;
170 tape_34xx_erp_failed(struct tape_request
*request
, int rc
)
172 DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
173 tape_op_verbose
[request
->op
], rc
);
178 tape_34xx_erp_succeeded(struct tape_request
*request
)
180 DBF_EVENT(3, "Error Recovery successful for %s\n",
181 tape_op_verbose
[request
->op
]);
182 return tape_34xx_done(request
);
186 tape_34xx_erp_retry(struct tape_request
*request
)
188 DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose
[request
->op
]);
189 return TAPE_IO_RETRY
;
193 * This function is called, when no request is outstanding and we get an
197 tape_34xx_unsolicited_irq(struct tape_device
*device
, struct irb
*irb
)
199 if (irb
->scsw
.cmd
.dstat
== 0x85) { /* READY */
200 /* A medium was inserted in the drive. */
201 DBF_EVENT(6, "xuud med\n");
202 tape_34xx_delete_sbid_from(device
, 0);
203 tape_34xx_schedule_work(device
, TO_MSEN
);
205 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device
->cdev_id
);
206 tape_dump_sense_dbf(device
, NULL
, irb
);
208 return TAPE_IO_SUCCESS
;
212 * Read Opposite Error Recovery Function:
213 * Used, when Read Forward does not work
216 tape_34xx_erp_read_opposite(struct tape_device
*device
,
217 struct tape_request
*request
)
219 if (request
->op
== TO_RFO
) {
221 * We did read forward, but the data could not be read
222 * *correctly*. We transform the request to a read backward
225 tape_std_read_backward(device
, request
);
226 return tape_34xx_erp_retry(request
);
230 * We tried to read forward and backward, but hat no
233 return tape_34xx_erp_failed(request
, -EIO
);
237 tape_34xx_erp_bug(struct tape_device
*device
, struct tape_request
*request
,
238 struct irb
*irb
, int no
)
240 if (request
->op
!= TO_ASSIGN
) {
241 dev_err(&device
->cdev
->dev
, "An unexpected condition %d "
242 "occurred in tape error recovery\n", no
);
243 tape_dump_sense_dbf(device
, request
, irb
);
245 return tape_34xx_erp_failed(request
, -EIO
);
249 * Handle data overrun between cu and drive. The channel speed might
253 tape_34xx_erp_overrun(struct tape_device
*device
, struct tape_request
*request
,
256 if (irb
->ecw
[3] == 0x40) {
257 dev_warn (&device
->cdev
->dev
, "A data overrun occurred between"
258 " the control unit and tape unit\n");
259 return tape_34xx_erp_failed(request
, -EIO
);
261 return tape_34xx_erp_bug(device
, request
, irb
, -1);
265 * Handle record sequence error.
268 tape_34xx_erp_sequence(struct tape_device
*device
,
269 struct tape_request
*request
, struct irb
*irb
)
271 if (irb
->ecw
[3] == 0x41) {
273 * cu detected incorrect block-id sequence on tape.
275 dev_warn (&device
->cdev
->dev
, "The block ID sequence on the "
276 "tape is incorrect\n");
277 return tape_34xx_erp_failed(request
, -EIO
);
280 * Record sequence error bit is set, but erpa does not
281 * show record sequence error.
283 return tape_34xx_erp_bug(device
, request
, irb
, -2);
287 * This function analyses the tape's sense-data in case of a unit-check.
288 * If possible, it tries to recover from the error. Else the user is
289 * informed about the problem.
292 tape_34xx_unit_check(struct tape_device
*device
, struct tape_request
*request
,
295 int inhibit_cu_recovery
;
298 inhibit_cu_recovery
= (*device
->modeset_byte
& 0x80) ? 1 : 0;
301 #ifdef CONFIG_S390_TAPE_BLOCK
302 if (request
->op
== TO_BLOCK
) {
304 * Recovery for block device requests. Set the block_position
305 * to something invalid and retry.
307 device
->blk_data
.block_position
= -1;
308 if (request
->retries
-- <= 0)
309 return tape_34xx_erp_failed(request
, -EIO
);
311 return tape_34xx_erp_retry(request
);
316 sense
[0] & SENSE_COMMAND_REJECT
&&
317 sense
[1] & SENSE_WRITE_PROTECT
320 request
->op
== TO_DSE
||
321 request
->op
== TO_WRI
||
322 request
->op
== TO_WTM
324 /* medium is write protected */
325 return tape_34xx_erp_failed(request
, -EACCES
);
327 return tape_34xx_erp_bug(device
, request
, irb
, -3);
332 * Special cases for various tape-states when reaching
333 * end of recorded area
335 * FIXME: Maybe a special case of the special case:
336 * sense[0] == SENSE_EQUIPMENT_CHECK &&
337 * sense[1] == SENSE_DRIVE_ONLINE &&
338 * sense[3] == 0x47 (Volume Fenced)
340 * This was caused by continued FSF or FSR after an
344 sense
[0] == SENSE_DATA_CHECK
||
345 sense
[0] == SENSE_EQUIPMENT_CHECK
||
346 sense
[0] == SENSE_EQUIPMENT_CHECK
+ SENSE_DEFERRED_UNIT_CHECK
348 sense
[1] == SENSE_DRIVE_ONLINE
||
349 sense
[1] == SENSE_BEGINNING_OF_TAPE
+ SENSE_WRITE_MODE
351 switch (request
->op
) {
353 * sense[0] == SENSE_DATA_CHECK &&
354 * sense[1] == SENSE_DRIVE_ONLINE
355 * sense[3] == 0x36 (End Of Data)
357 * Further seeks might return a 'Volume Fenced'.
361 /* Trying to seek beyond end of recorded area */
362 return tape_34xx_erp_failed(request
, -ENOSPC
);
364 return tape_34xx_erp_retry(request
);
367 * sense[0] == SENSE_DATA_CHECK &&
368 * sense[1] == SENSE_DRIVE_ONLINE &&
369 * sense[3] == 0x36 (End Of Data)
372 /* Block could not be located. */
373 tape_34xx_delete_sbid_from(device
, 0);
374 return tape_34xx_erp_failed(request
, -EIO
);
377 /* Read beyond end of recorded area -> 0 bytes read */
378 return tape_34xx_erp_failed(request
, 0);
381 * sense[0] == SENSE_EQUIPMENT_CHECK &&
382 * sense[1] == SENSE_DRIVE_ONLINE &&
383 * sense[3] == 0x38 (Physical End Of Volume)
386 /* Writing at physical end of volume */
387 return tape_34xx_erp_failed(request
, -ENOSPC
);
389 return tape_34xx_erp_failed(request
, 0);
393 /* Sensing special bits */
394 if (sense
[0] & SENSE_BUS_OUT_CHECK
)
395 return tape_34xx_erp_retry(request
);
397 if (sense
[0] & SENSE_DATA_CHECK
) {
399 * hardware failure, damaged tape or improper
400 * operating conditions
404 /* a read data check occurred */
405 if ((sense
[2] & SENSE_TAPE_SYNC_MODE
) ||
407 // data check is not permanent, may be
408 // recovered. We always use async-mode with
409 // cu-recovery, so this should *never* happen.
410 return tape_34xx_erp_bug(device
, request
,
413 /* data check is permanent, CU recovery has failed */
414 dev_warn (&device
->cdev
->dev
, "A read error occurred "
415 "that cannot be recovered\n");
416 return tape_34xx_erp_failed(request
, -EIO
);
418 // a write data check occurred
419 if ((sense
[2] & SENSE_TAPE_SYNC_MODE
) ||
421 // data check is not permanent, may be
422 // recovered. We always use async-mode with
423 // cu-recovery, so this should *never* happen.
424 return tape_34xx_erp_bug(device
, request
,
427 // data check is permanent, cu-recovery has failed
428 dev_warn (&device
->cdev
->dev
, "A write error on the "
429 "tape cannot be recovered\n");
430 return tape_34xx_erp_failed(request
, -EIO
);
432 /* Data Check (read opposite) occurred. */
433 return tape_34xx_erp_read_opposite(device
, request
);
435 /* ID-Mark at tape start couldn't be written */
436 dev_warn (&device
->cdev
->dev
, "Writing the ID-mark "
438 return tape_34xx_erp_failed(request
, -EIO
);
440 /* Tape void. Tried to read beyond end of device. */
441 dev_warn (&device
->cdev
->dev
, "Reading the tape beyond"
442 " the end of the recorded area failed\n");
443 return tape_34xx_erp_failed(request
, -ENOSPC
);
445 /* Record sequence error. */
446 dev_warn (&device
->cdev
->dev
, "The tape contains an "
447 "incorrect block ID sequence\n");
448 return tape_34xx_erp_failed(request
, -EIO
);
450 /* all data checks for 3480 should result in one of
451 * the above erpa-codes. For 3490, other data-check
452 * conditions do exist. */
453 if (device
->cdev
->id
.driver_info
== tape_3480
)
454 return tape_34xx_erp_bug(device
, request
,
459 if (sense
[0] & SENSE_OVERRUN
)
460 return tape_34xx_erp_overrun(device
, request
, irb
);
462 if (sense
[1] & SENSE_RECORD_SEQUENCE_ERR
)
463 return tape_34xx_erp_sequence(device
, request
, irb
);
465 /* Sensing erpa codes */
468 /* Unit check with erpa code 0. Report and ignore. */
469 return TAPE_IO_SUCCESS
;
472 * Data streaming not operational. CU will switch to
473 * interlock mode. Reissue the command.
475 return tape_34xx_erp_retry(request
);
478 * Path equipment check. Might be drive adapter error, buffer
479 * error on the lower interface, internal path not usable,
480 * or error during cartridge load.
482 dev_warn (&device
->cdev
->dev
, "A path equipment check occurred"
483 " for the tape device\n");
484 return tape_34xx_erp_failed(request
, -EIO
);
487 * Load display check. Load display was command was issued,
488 * but the drive is displaying a drive check message. Can
489 * be threated as "device end".
491 return tape_34xx_erp_succeeded(request
);
494 * Command reject. May indicate illegal channel program or
495 * buffer over/underrun. Since all channel programs are
496 * issued by this driver and ought be correct, we assume a
497 * over/underrun situation and retry the channel program.
499 return tape_34xx_erp_retry(request
);
502 * Function incompatible. Either the tape is idrc compressed
503 * but the hardware isn't capable to do idrc, or a perform
504 * subsystem func is issued and the CU is not on-line.
506 return tape_34xx_erp_failed(request
, -EIO
);
509 * Unsolicited environmental data. An internal counter
510 * overflows, we can ignore this and reissue the cmd.
512 return tape_34xx_erp_retry(request
);
515 * Environmental data present. Indicates either unload
516 * completed ok or read buffered log command completed ok.
518 if (request
->op
== TO_RUN
) {
519 /* Rewind unload completed ok. */
520 tape_med_state_set(device
, MS_UNLOADED
);
521 return tape_34xx_erp_succeeded(request
);
523 /* tape_34xx doesn't use read buffered log commands. */
524 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
527 * Permanent equipment check. CU has tried recovery, but
530 return tape_34xx_erp_failed(request
, -EIO
);
532 /* Data security erase failure. */
533 if (request
->op
== TO_DSE
)
534 return tape_34xx_erp_failed(request
, -EIO
);
535 /* Data security erase failure, but no such command issued. */
536 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
539 * Not capable. This indicates either that the drive fails
540 * reading the format id mark or that that format specified
541 * is not supported by the drive.
543 dev_warn (&device
->cdev
->dev
, "The tape unit cannot process "
544 "the tape format\n");
545 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
547 /* The medium is write protected. */
548 dev_warn (&device
->cdev
->dev
, "The tape medium is write-"
550 return tape_34xx_erp_failed(request
, -EACCES
);
552 // Tension loss. We cannot recover this, it's an I/O error.
553 dev_warn (&device
->cdev
->dev
, "The tape does not have the "
554 "required tape tension\n");
555 return tape_34xx_erp_failed(request
, -EIO
);
558 * Load Failure. The cartridge was not inserted correctly or
559 * the tape is not threaded correctly.
561 dev_warn (&device
->cdev
->dev
, "The tape unit failed to load"
563 tape_34xx_delete_sbid_from(device
, 0);
564 return tape_34xx_erp_failed(request
, -EIO
);
567 * Unload failure. The drive cannot maintain tape tension
568 * and control tape movement during an unload operation.
570 dev_warn (&device
->cdev
->dev
, "Automatic unloading of the tape"
571 " cartridge failed\n");
572 if (request
->op
== TO_RUN
)
573 return tape_34xx_erp_failed(request
, -EIO
);
574 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
577 * Drive equipment check. One of the following:
578 * - cu cannot recover from a drive detected error
579 * - a check code message is shown on drive display
580 * - the cartridge loader does not respond correctly
581 * - a failure occurs during an index, load, or unload cycle
583 dev_warn (&device
->cdev
->dev
, "An equipment check has occurred"
584 " on the tape unit\n");
585 return tape_34xx_erp_failed(request
, -EIO
);
587 if (device
->cdev
->id
.driver_info
== tape_3490
)
589 return tape_34xx_erp_failed(request
, -EIO
);
590 /* This erpa is reserved for 3480 */
591 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
594 * Tape length error. The tape is shorter than reported in
595 * the beginning-of-tape data.
597 dev_warn (&device
->cdev
->dev
, "The tape information states an"
598 " incorrect length\n");
599 return tape_34xx_erp_failed(request
, -EIO
);
602 * Physical end of tape. A read/write operation reached
603 * the physical end of tape.
605 if (request
->op
==TO_WRI
||
606 request
->op
==TO_DSE
||
608 return tape_34xx_erp_failed(request
, -ENOSPC
);
609 return tape_34xx_erp_failed(request
, -EIO
);
611 /* Backward at Beginning of tape. */
612 return tape_34xx_erp_failed(request
, -EIO
);
614 /* Drive switched to not ready. */
615 dev_warn (&device
->cdev
->dev
, "The tape unit is not ready\n");
616 return tape_34xx_erp_failed(request
, -EIO
);
618 /* Manual rewind or unload. This causes an I/O error. */
619 dev_warn (&device
->cdev
->dev
, "The tape medium has been "
620 "rewound or unloaded manually\n");
621 tape_34xx_delete_sbid_from(device
, 0);
622 return tape_34xx_erp_failed(request
, -EIO
);
625 * Degraded mode. A condition that can cause degraded
626 * performance is detected.
628 dev_warn (&device
->cdev
->dev
, "The tape subsystem is running "
629 "in degraded mode\n");
630 return tape_34xx_erp_retry(request
);
632 /* Drive not ready. */
633 tape_34xx_delete_sbid_from(device
, 0);
634 tape_med_state_set(device
, MS_UNLOADED
);
635 /* Some commands commands are successful even in this case */
636 if (sense
[1] & SENSE_DRIVE_ONLINE
) {
637 switch(request
->op
) {
642 return tape_34xx_done(request
);
648 return tape_34xx_erp_failed(request
, -ENOMEDIUM
);
650 /* Locate Block unsuccessful. */
651 if (request
->op
!= TO_BLOCK
&& request
->op
!= TO_LBL
)
652 /* No locate block was issued. */
653 return tape_34xx_erp_bug(device
, request
,
655 return tape_34xx_erp_failed(request
, -EIO
);
657 /* The drive is assigned to a different channel path. */
658 dev_warn (&device
->cdev
->dev
, "The tape unit is already "
660 return tape_34xx_erp_failed(request
, -EIO
);
663 * Drive not on-line. Drive may be switched offline,
664 * the power supply may be switched off or
665 * the drive address may not be set correctly.
667 dev_warn (&device
->cdev
->dev
, "The tape unit is not online\n");
668 return tape_34xx_erp_failed(request
, -EIO
);
670 /* Volume fenced. CU reports volume integrity is lost. */
671 dev_warn (&device
->cdev
->dev
, "The control unit has fenced "
672 "access to the tape volume\n");
673 tape_34xx_delete_sbid_from(device
, 0);
674 return tape_34xx_erp_failed(request
, -EIO
);
676 /* Log sense data and retry request. */
677 return tape_34xx_erp_retry(request
);
679 /* Bus out check. A parity check error on the bus was found. */
680 dev_warn (&device
->cdev
->dev
, "A parity error occurred on the "
682 return tape_34xx_erp_failed(request
, -EIO
);
684 /* Control unit erp failed. */
685 dev_warn (&device
->cdev
->dev
, "I/O error recovery failed on "
686 "the tape control unit\n");
687 return tape_34xx_erp_failed(request
, -EIO
);
690 * CU and drive incompatible. The drive requests micro-program
691 * patches, which are not available on the CU.
693 dev_warn (&device
->cdev
->dev
, "The tape unit requires a "
694 "firmware update\n");
695 return tape_34xx_erp_failed(request
, -EIO
);
698 * Recovered Check-One failure. Cu develops a hardware error,
699 * but is able to recover.
701 return tape_34xx_erp_retry(request
);
703 if (device
->cdev
->id
.driver_info
== tape_3490
)
705 * Resetting event received. Since the driver does
706 * not support resetting event recovery (which has to
707 * be handled by the I/O Layer), retry our command.
709 return tape_34xx_erp_retry(request
);
710 /* This erpa is reserved for 3480. */
711 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
713 if (device
->cdev
->id
.driver_info
== tape_3490
) {
715 * Maximum block size exceeded. This indicates, that
716 * the block to be written is larger than allowed for
719 dev_warn (&device
->cdev
->dev
, "The maximum block size"
720 " for buffered mode is exceeded\n");
721 return tape_34xx_erp_failed(request
, -ENOBUFS
);
723 /* This erpa is reserved for 3480. */
724 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
727 * Read buffered log (Overflow). CU is running in extended
728 * buffered log mode, and a counter overflows. This should
729 * never happen, since we're never running in extended
732 return tape_34xx_erp_retry(request
);
735 * Read buffered log (EOV). EOF processing occurs while the
736 * CU is in extended buffered log mode. This should never
737 * happen, since we're never running in extended buffered
740 return tape_34xx_erp_retry(request
);
742 /* End of Volume complete. Rewind unload completed ok. */
743 if (request
->op
== TO_RUN
) {
744 tape_med_state_set(device
, MS_UNLOADED
);
745 tape_34xx_delete_sbid_from(device
, 0);
746 return tape_34xx_erp_succeeded(request
);
748 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
750 /* Global command intercept. */
751 return tape_34xx_erp_retry(request
);
753 /* Channel interface recovery (temporary). */
754 return tape_34xx_erp_retry(request
);
756 /* Channel interface recovery (permanent). */
757 dev_warn (&device
->cdev
->dev
, "A channel interface error cannot be"
759 return tape_34xx_erp_failed(request
, -EIO
);
761 /* Channel protocol error. */
762 dev_warn (&device
->cdev
->dev
, "A channel protocol error "
764 return tape_34xx_erp_failed(request
, -EIO
);
766 if (device
->cdev
->id
.driver_info
== tape_3480
) {
767 /* Attention intercept. */
768 return tape_34xx_erp_retry(request
);
770 /* Global status intercept. */
771 return tape_34xx_erp_retry(request
);
775 * Tape length incompatible. The tape inserted is too long,
776 * which could cause damage to the tape or the drive.
778 dev_warn (&device
->cdev
->dev
, "The tape unit does not support "
779 "the tape length\n");
780 return tape_34xx_erp_failed(request
, -EIO
);
782 /* Format 3480 XF incompatible */
783 if (sense
[1] & SENSE_BEGINNING_OF_TAPE
)
784 /* The tape will get overwritten. */
785 return tape_34xx_erp_retry(request
);
786 dev_warn (&device
->cdev
->dev
, "The tape unit does not support"
787 " format 3480 XF\n");
788 return tape_34xx_erp_failed(request
, -EIO
);
790 /* Format 3480-2 XF incompatible */
791 dev_warn (&device
->cdev
->dev
, "The tape unit does not support tape "
792 "format 3480-2 XF\n");
793 return tape_34xx_erp_failed(request
, -EIO
);
795 /* Tape length violation. */
796 dev_warn (&device
->cdev
->dev
, "The tape unit does not support"
797 " the current tape length\n");
798 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
800 /* Compaction algorithm incompatible. */
801 dev_warn (&device
->cdev
->dev
, "The tape unit does not support"
802 " the compaction algorithm\n");
803 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
805 /* The following erpas should have been covered earlier. */
806 case 0x23: /* Read data check. */
807 case 0x25: /* Write data check. */
808 case 0x26: /* Data check (read opposite). */
809 case 0x28: /* Write id mark check. */
810 case 0x31: /* Tape void. */
811 case 0x40: /* Overrun error. */
812 case 0x41: /* Record sequence error. */
813 /* All other erpas are reserved for future use. */
815 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
820 * 3480/3490 interrupt handler
823 tape_34xx_irq(struct tape_device
*device
, struct tape_request
*request
,
827 return tape_34xx_unsolicited_irq(device
, irb
);
829 if ((irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_EXCEP
) &&
830 (irb
->scsw
.cmd
.dstat
& DEV_STAT_DEV_END
) &&
831 (request
->op
== TO_WRI
)) {
832 /* Write at end of volume */
833 return tape_34xx_erp_failed(request
, -ENOSPC
);
836 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
)
837 return tape_34xx_unit_check(device
, request
, irb
);
839 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_DEV_END
) {
841 * A unit exception occurs on skipping over a tapemark block.
843 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_EXCEP
) {
844 if (request
->op
== TO_BSB
|| request
->op
== TO_FSB
)
847 DBF_EVENT(5, "Unit Exception!\n");
849 return tape_34xx_done(request
);
852 DBF_EVENT(6, "xunknownirq\n");
853 tape_dump_sense_dbf(device
, request
, irb
);
861 tape_34xx_ioctl(struct tape_device
*device
, unsigned int cmd
, unsigned long arg
)
863 if (cmd
== TAPE390_DISPLAY
) {
864 struct display_struct disp
;
866 if (copy_from_user(&disp
, (char __user
*) arg
, sizeof(disp
)) != 0)
869 return tape_std_display(device
, &disp
);
875 tape_34xx_append_new_sbid(struct tape_34xx_block_id bid
, struct list_head
*l
)
877 struct tape_34xx_sbid
* new_sbid
;
879 new_sbid
= kmalloc(sizeof(*new_sbid
), GFP_ATOMIC
);
884 list_add(&new_sbid
->list
, l
);
888 * Build up the search block ID list. The block ID consists of a logical
889 * block number and a hardware specific part. The hardware specific part
890 * helps the tape drive to speed up searching for a specific block.
893 tape_34xx_add_sbid(struct tape_device
*device
, struct tape_34xx_block_id bid
)
895 struct list_head
* sbid_list
;
896 struct tape_34xx_sbid
* sbid
;
897 struct list_head
* l
;
900 * immediately return if there is no list at all or the block to add
901 * is located in segment 1 of wrap 0 because this position is used
902 * if no hardware position data is supplied.
904 sbid_list
= (struct list_head
*) device
->discdata
;
905 if (!sbid_list
|| (bid
.segment
< 2 && bid
.wrap
== 0))
909 * Search the position where to insert the new entry. Hardware
910 * acceleration uses only the segment and wrap number. So we
911 * need only one entry for a specific wrap/segment combination.
912 * If there is a block with a lower number but the same hard-
913 * ware position data we just update the block number in the
916 list_for_each(l
, sbid_list
) {
917 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
920 (sbid
->bid
.segment
== bid
.segment
) &&
921 (sbid
->bid
.wrap
== bid
.wrap
)
923 if (bid
.block
< sbid
->bid
.block
)
929 /* Sort in according to logical block number. */
930 if (bid
.block
< sbid
->bid
.block
) {
931 tape_34xx_append_new_sbid(bid
, l
->prev
);
935 /* List empty or new block bigger than last entry. */
937 tape_34xx_append_new_sbid(bid
, l
->prev
);
939 DBF_LH(4, "Current list is:\n");
940 list_for_each(l
, sbid_list
) {
941 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
942 DBF_LH(4, "%d:%03d@%05d\n",
951 * Delete all entries from the search block ID list that belong to tape blocks
952 * equal or higher than the given number.
955 tape_34xx_delete_sbid_from(struct tape_device
*device
, int from
)
957 struct list_head
* sbid_list
;
958 struct tape_34xx_sbid
* sbid
;
959 struct list_head
* l
;
960 struct list_head
* n
;
962 sbid_list
= (struct list_head
*) device
->discdata
;
966 list_for_each_safe(l
, n
, sbid_list
) {
967 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
968 if (sbid
->bid
.block
>= from
) {
969 DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
981 * Merge hardware position data into a block id.
984 tape_34xx_merge_sbid(
985 struct tape_device
* device
,
986 struct tape_34xx_block_id
* bid
988 struct tape_34xx_sbid
* sbid
;
989 struct tape_34xx_sbid
* sbid_to_use
;
990 struct list_head
* sbid_list
;
991 struct list_head
* l
;
993 sbid_list
= (struct list_head
*) device
->discdata
;
997 if (!sbid_list
|| list_empty(sbid_list
))
1001 list_for_each(l
, sbid_list
) {
1002 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
1004 if (sbid
->bid
.block
>= bid
->block
)
1009 bid
->wrap
= sbid_to_use
->bid
.wrap
;
1010 bid
->segment
= sbid_to_use
->bid
.segment
;
1011 DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
1012 sbid_to_use
->bid
.wrap
,
1013 sbid_to_use
->bid
.segment
,
1014 sbid_to_use
->bid
.block
,
1021 tape_34xx_setup_device(struct tape_device
* device
)
1024 struct list_head
* discdata
;
1026 DBF_EVENT(6, "34xx device setup\n");
1027 if ((rc
= tape_std_assign(device
)) == 0) {
1028 if ((rc
= tape_34xx_medium_sense(device
)) != 0) {
1029 DBF_LH(3, "34xx medium sense returned %d\n", rc
);
1032 discdata
= kmalloc(sizeof(struct list_head
), GFP_KERNEL
);
1034 INIT_LIST_HEAD(discdata
);
1035 device
->discdata
= discdata
;
1042 tape_34xx_cleanup_device(struct tape_device
*device
)
1044 tape_std_unassign(device
);
1046 if (device
->discdata
) {
1047 tape_34xx_delete_sbid_from(device
, 0);
1048 kfree(device
->discdata
);
1049 device
->discdata
= NULL
;
1055 * MTTELL: Tell block. Return the number of block relative to current file.
1058 tape_34xx_mttell(struct tape_device
*device
, int mt_count
)
1061 struct tape_34xx_block_id cbid
;
1062 struct tape_34xx_block_id dbid
;
1063 } __attribute__ ((packed
)) block_id
;
1066 rc
= tape_std_read_block_id(device
, (__u64
*) &block_id
);
1070 tape_34xx_add_sbid(device
, block_id
.cbid
);
1071 return block_id
.cbid
.block
;
1075 * MTSEEK: seek to the specified block.
1078 tape_34xx_mtseek(struct tape_device
*device
, int mt_count
)
1080 struct tape_request
*request
;
1081 struct tape_34xx_block_id
* bid
;
1083 if (mt_count
> 0x3fffff) {
1084 DBF_EXCEPTION(6, "xsee parm\n");
1087 request
= tape_alloc_request(3, 4);
1088 if (IS_ERR(request
))
1089 return PTR_ERR(request
);
1092 request
->op
= TO_LBL
;
1093 bid
= (struct tape_34xx_block_id
*) request
->cpdata
;
1094 bid
->format
= (*device
->modeset_byte
& 0x08) ?
1095 TAPE34XX_FMT_3480_XF
: TAPE34XX_FMT_3480
;
1096 bid
->block
= mt_count
;
1097 tape_34xx_merge_sbid(device
, bid
);
1099 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
1100 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
1101 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
1104 return tape_do_io_free(device
, request
);
1107 #ifdef CONFIG_S390_TAPE_BLOCK
1109 * Tape block read for 34xx.
1111 static struct tape_request
*
1112 tape_34xx_bread(struct tape_device
*device
, struct request
*req
)
1114 struct tape_request
*request
;
1120 struct req_iterator iter
;
1121 struct tape_34xx_block_id
* start_block
;
1123 DBF_EVENT(6, "xBREDid:");
1125 /* Count the number of blocks for the request. */
1126 rq_for_each_segment(bv
, req
, iter
)
1127 count
+= bv
->bv_len
>> (TAPEBLOCK_HSEC_S2B
+ 9);
1129 /* Allocate the ccw request. */
1130 request
= tape_alloc_request(3+count
+1, 8);
1131 if (IS_ERR(request
))
1135 request
->op
= TO_BLOCK
;
1136 start_block
= (struct tape_34xx_block_id
*) request
->cpdata
;
1137 start_block
->block
= blk_rq_pos(req
) >> TAPEBLOCK_HSEC_S2B
;
1138 DBF_EVENT(6, "start_block = %i\n", start_block
->block
);
1140 ccw
= request
->cpaddr
;
1141 ccw
= tape_ccw_cc(ccw
, MODE_SET_DB
, 1, device
->modeset_byte
);
1144 * We always setup a nop after the mode set ccw. This slot is
1145 * used in tape_std_check_locate to insert a locate ccw if the
1146 * current tape position doesn't match the start block to be read.
1147 * The second nop will be filled with a read block id which is in
1148 * turn used by tape_34xx_free_bread to populate the segment bid
1151 ccw
= tape_ccw_cc(ccw
, NOP
, 0, NULL
);
1152 ccw
= tape_ccw_cc(ccw
, NOP
, 0, NULL
);
1154 rq_for_each_segment(bv
, req
, iter
) {
1155 dst
= kmap(bv
->bv_page
) + bv
->bv_offset
;
1156 for (off
= 0; off
< bv
->bv_len
; off
+= TAPEBLOCK_HSEC_SIZE
) {
1157 ccw
->flags
= CCW_FLAG_CC
;
1158 ccw
->cmd_code
= READ_FORWARD
;
1159 ccw
->count
= TAPEBLOCK_HSEC_SIZE
;
1160 set_normalized_cda(ccw
, (void*) __pa(dst
));
1162 dst
+= TAPEBLOCK_HSEC_SIZE
;
1166 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
1167 DBF_EVENT(6, "xBREDccwg\n");
1172 tape_34xx_free_bread (struct tape_request
*request
)
1176 ccw
= request
->cpaddr
;
1177 if ((ccw
+ 2)->cmd_code
== READ_BLOCK_ID
) {
1179 struct tape_34xx_block_id cbid
;
1180 struct tape_34xx_block_id dbid
;
1181 } __attribute__ ((packed
)) *rbi_data
;
1183 rbi_data
= request
->cpdata
;
1185 if (request
->device
)
1186 tape_34xx_add_sbid(request
->device
, rbi_data
->cbid
);
1189 /* Last ccw is a nop and doesn't need clear_normalized_cda */
1190 for (; ccw
->flags
& CCW_FLAG_CC
; ccw
++)
1191 if (ccw
->cmd_code
== READ_FORWARD
)
1192 clear_normalized_cda(ccw
);
1193 tape_free_request(request
);
1197 * check_locate is called just before the tape request is passed to
1198 * the common io layer for execution. It has to check the current
1199 * tape position and insert a locate ccw if it doesn't match the
1200 * start block for the request.
1203 tape_34xx_check_locate(struct tape_device
*device
, struct tape_request
*request
)
1205 struct tape_34xx_block_id
* start_block
;
1207 start_block
= (struct tape_34xx_block_id
*) request
->cpdata
;
1208 if (start_block
->block
== device
->blk_data
.block_position
)
1211 DBF_LH(4, "Block seek(%06d+%06d)\n", start_block
->block
, device
->bof
);
1212 start_block
->wrap
= 0;
1213 start_block
->segment
= 1;
1214 start_block
->format
= (*device
->modeset_byte
& 0x08) ?
1215 TAPE34XX_FMT_3480_XF
:
1217 start_block
->block
= start_block
->block
+ device
->bof
;
1218 tape_34xx_merge_sbid(device
, start_block
);
1219 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
1220 tape_ccw_cc(request
->cpaddr
+ 2, READ_BLOCK_ID
, 8, request
->cpdata
);
1225 * List of 3480/3490 magnetic tape commands.
1227 static tape_mtop_fn tape_34xx_mtop
[TAPE_NR_MTOPS
] = {
1228 [MTRESET
] = tape_std_mtreset
,
1229 [MTFSF
] = tape_std_mtfsf
,
1230 [MTBSF
] = tape_std_mtbsf
,
1231 [MTFSR
] = tape_std_mtfsr
,
1232 [MTBSR
] = tape_std_mtbsr
,
1233 [MTWEOF
] = tape_std_mtweof
,
1234 [MTREW
] = tape_std_mtrew
,
1235 [MTOFFL
] = tape_std_mtoffl
,
1236 [MTNOP
] = tape_std_mtnop
,
1237 [MTRETEN
] = tape_std_mtreten
,
1238 [MTBSFM
] = tape_std_mtbsfm
,
1239 [MTFSFM
] = tape_std_mtfsfm
,
1240 [MTEOM
] = tape_std_mteom
,
1241 [MTERASE
] = tape_std_mterase
,
1245 [MTSETBLK
] = tape_std_mtsetblk
,
1246 [MTSETDENSITY
] = NULL
,
1247 [MTSEEK
] = tape_34xx_mtseek
,
1248 [MTTELL
] = tape_34xx_mttell
,
1249 [MTSETDRVBUFFER
] = NULL
,
1255 [MTLOAD
] = tape_std_mtload
,
1256 [MTUNLOAD
] = tape_std_mtunload
,
1257 [MTCOMPRESSION
] = tape_std_mtcompression
,
1263 * Tape discipline structure for 3480 and 3490.
1265 static struct tape_discipline tape_discipline_34xx
= {
1266 .owner
= THIS_MODULE
,
1267 .setup_device
= tape_34xx_setup_device
,
1268 .cleanup_device
= tape_34xx_cleanup_device
,
1269 .process_eov
= tape_std_process_eov
,
1270 .irq
= tape_34xx_irq
,
1271 .read_block
= tape_std_read_block
,
1272 .write_block
= tape_std_write_block
,
1273 #ifdef CONFIG_S390_TAPE_BLOCK
1274 .bread
= tape_34xx_bread
,
1275 .free_bread
= tape_34xx_free_bread
,
1276 .check_locate
= tape_34xx_check_locate
,
1278 .ioctl_fn
= tape_34xx_ioctl
,
1279 .mtop_array
= tape_34xx_mtop
1282 static struct ccw_device_id tape_34xx_ids
[] = {
1283 { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), .driver_info
= tape_3480
},
1284 { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), .driver_info
= tape_3490
},
1285 { /* end of list */ },
1289 tape_34xx_online(struct ccw_device
*cdev
)
1291 return tape_generic_online(
1292 dev_get_drvdata(&cdev
->dev
),
1293 &tape_discipline_34xx
1297 static struct ccw_driver tape_34xx_driver
= {
1298 .name
= "tape_34xx",
1299 .owner
= THIS_MODULE
,
1300 .ids
= tape_34xx_ids
,
1301 .probe
= tape_generic_probe
,
1302 .remove
= tape_generic_remove
,
1303 .set_online
= tape_34xx_online
,
1304 .set_offline
= tape_generic_offline
,
1305 .freeze
= tape_generic_pm_suspend
,
1309 tape_34xx_init (void)
1313 TAPE_DBF_AREA
= debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
1314 debug_register_view(TAPE_DBF_AREA
, &debug_sprintf_view
);
1315 #ifdef DBF_LIKE_HELL
1316 debug_set_level(TAPE_DBF_AREA
, 6);
1319 DBF_EVENT(3, "34xx init\n");
1320 /* Register driver for 3480/3490 tapes. */
1321 rc
= ccw_driver_register(&tape_34xx_driver
);
1323 DBF_EVENT(3, "34xx init failed\n");
1325 DBF_EVENT(3, "34xx registered\n");
1330 tape_34xx_exit(void)
1332 ccw_driver_unregister(&tape_34xx_driver
);
1334 debug_unregister(TAPE_DBF_AREA
);
1337 MODULE_DEVICE_TABLE(ccw
, tape_34xx_ids
);
1338 MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
1339 MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape device driver");
1340 MODULE_LICENSE("GPL");
1342 module_init(tape_34xx_init
);
1343 module_exit(tape_34xx_exit
);