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>
18 #include <linux/slab.h>
20 #define TAPE_DBF_AREA tape_34xx_dbf
26 * Pointer to debug area.
28 debug_info_t
*TAPE_DBF_AREA
= NULL
;
29 EXPORT_SYMBOL(TAPE_DBF_AREA
);
31 #define TAPE34XX_FMT_3480 0
32 #define TAPE34XX_FMT_3480_2_XF 1
33 #define TAPE34XX_FMT_3480_XF 2
35 struct tape_34xx_block_id
{
36 unsigned int wrap
: 1;
37 unsigned int segment
: 7;
38 unsigned int format
: 2;
39 unsigned int block
: 22;
43 * A list of block ID's is used to faster seek blocks.
45 struct tape_34xx_sbid
{
46 struct list_head list
;
47 struct tape_34xx_block_id bid
;
50 static void tape_34xx_delete_sbid_from(struct tape_device
*, int);
53 * Medium sense for 34xx tapes. There is no 'real' medium sense call.
54 * So we just do a normal sense.
57 tape_34xx_medium_sense(struct tape_device
*device
)
59 struct tape_request
*request
;
63 request
= tape_alloc_request(1, 32);
64 if (IS_ERR(request
)) {
65 DBF_EXCEPTION(6, "MSEN fail\n");
66 return PTR_ERR(request
);
69 request
->op
= TO_MSEN
;
70 tape_ccw_end(request
->cpaddr
, SENSE
, 32, request
->cpdata
);
72 rc
= tape_do_io_interruptible(device
, request
);
73 if (request
->rc
== 0) {
74 sense
= request
->cpdata
;
77 * This isn't quite correct. But since INTERVENTION_REQUIRED
78 * means that the drive is 'neither ready nor on-line' it is
79 * only slightly inaccurate to say there is no tape loaded if
80 * the drive isn't online...
82 if (sense
[0] & SENSE_INTERVENTION_REQUIRED
)
83 tape_med_state_set(device
, MS_UNLOADED
);
85 tape_med_state_set(device
, MS_LOADED
);
87 if (sense
[1] & SENSE_WRITE_PROTECT
)
88 device
->tape_generic_status
|= GMT_WR_PROT(~0);
90 device
->tape_generic_status
&= ~GMT_WR_PROT(~0);
92 DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
95 tape_free_request(request
);
100 struct tape_34xx_work
{
101 struct tape_device
*device
;
103 struct work_struct work
;
107 * These functions are currently used only to schedule a medium_sense for
108 * later execution. This is because we get an interrupt whenever a medium
109 * is inserted but cannot call tape_do_io* from an interrupt context.
110 * Maybe that's useful for other actions we want to start from the
114 tape_34xx_work_handler(struct work_struct
*work
)
116 struct tape_34xx_work
*p
=
117 container_of(work
, struct tape_34xx_work
, work
);
118 struct tape_device
*device
= p
->device
;
122 tape_34xx_medium_sense(device
);
125 DBF_EVENT(3, "T34XX: internal error: unknown work\n");
127 tape_put_device(device
);
132 tape_34xx_schedule_work(struct tape_device
*device
, enum tape_op op
)
134 struct tape_34xx_work
*p
;
136 if ((p
= kzalloc(sizeof(*p
), GFP_ATOMIC
)) == NULL
)
139 INIT_WORK(&p
->work
, tape_34xx_work_handler
);
141 p
->device
= tape_get_device(device
);
144 schedule_work(&p
->work
);
149 * Done Handler is called when dev stat = DEVICE-END (successful operation)
152 tape_34xx_done(struct tape_request
*request
)
154 DBF_EVENT(6, "%s done\n", tape_op_verbose
[request
->op
]);
156 switch (request
->op
) {
163 tape_34xx_delete_sbid_from(request
->device
, 0);
168 return TAPE_IO_SUCCESS
;
172 tape_34xx_erp_failed(struct tape_request
*request
, int rc
)
174 DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
175 tape_op_verbose
[request
->op
], rc
);
180 tape_34xx_erp_succeeded(struct tape_request
*request
)
182 DBF_EVENT(3, "Error Recovery successful for %s\n",
183 tape_op_verbose
[request
->op
]);
184 return tape_34xx_done(request
);
188 tape_34xx_erp_retry(struct tape_request
*request
)
190 DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose
[request
->op
]);
191 return TAPE_IO_RETRY
;
195 * This function is called, when no request is outstanding and we get an
199 tape_34xx_unsolicited_irq(struct tape_device
*device
, struct irb
*irb
)
201 if (irb
->scsw
.cmd
.dstat
== 0x85) { /* READY */
202 /* A medium was inserted in the drive. */
203 DBF_EVENT(6, "xuud med\n");
204 tape_34xx_delete_sbid_from(device
, 0);
205 tape_34xx_schedule_work(device
, TO_MSEN
);
207 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device
->cdev_id
);
208 tape_dump_sense_dbf(device
, NULL
, irb
);
210 return TAPE_IO_SUCCESS
;
214 * Read Opposite Error Recovery Function:
215 * Used, when Read Forward does not work
218 tape_34xx_erp_read_opposite(struct tape_device
*device
,
219 struct tape_request
*request
)
221 if (request
->op
== TO_RFO
) {
223 * We did read forward, but the data could not be read
224 * *correctly*. We transform the request to a read backward
227 tape_std_read_backward(device
, request
);
228 return tape_34xx_erp_retry(request
);
232 * We tried to read forward and backward, but hat no
235 return tape_34xx_erp_failed(request
, -EIO
);
239 tape_34xx_erp_bug(struct tape_device
*device
, struct tape_request
*request
,
240 struct irb
*irb
, int no
)
242 if (request
->op
!= TO_ASSIGN
) {
243 dev_err(&device
->cdev
->dev
, "An unexpected condition %d "
244 "occurred in tape error recovery\n", no
);
245 tape_dump_sense_dbf(device
, request
, irb
);
247 return tape_34xx_erp_failed(request
, -EIO
);
251 * Handle data overrun between cu and drive. The channel speed might
255 tape_34xx_erp_overrun(struct tape_device
*device
, struct tape_request
*request
,
258 if (irb
->ecw
[3] == 0x40) {
259 dev_warn (&device
->cdev
->dev
, "A data overrun occurred between"
260 " the control unit and tape unit\n");
261 return tape_34xx_erp_failed(request
, -EIO
);
263 return tape_34xx_erp_bug(device
, request
, irb
, -1);
267 * Handle record sequence error.
270 tape_34xx_erp_sequence(struct tape_device
*device
,
271 struct tape_request
*request
, struct irb
*irb
)
273 if (irb
->ecw
[3] == 0x41) {
275 * cu detected incorrect block-id sequence on tape.
277 dev_warn (&device
->cdev
->dev
, "The block ID sequence on the "
278 "tape is incorrect\n");
279 return tape_34xx_erp_failed(request
, -EIO
);
282 * Record sequence error bit is set, but erpa does not
283 * show record sequence error.
285 return tape_34xx_erp_bug(device
, request
, irb
, -2);
289 * This function analyses the tape's sense-data in case of a unit-check.
290 * If possible, it tries to recover from the error. Else the user is
291 * informed about the problem.
294 tape_34xx_unit_check(struct tape_device
*device
, struct tape_request
*request
,
297 int inhibit_cu_recovery
;
300 inhibit_cu_recovery
= (*device
->modeset_byte
& 0x80) ? 1 : 0;
303 #ifdef CONFIG_S390_TAPE_BLOCK
304 if (request
->op
== TO_BLOCK
) {
306 * Recovery for block device requests. Set the block_position
307 * to something invalid and retry.
309 device
->blk_data
.block_position
= -1;
310 if (request
->retries
-- <= 0)
311 return tape_34xx_erp_failed(request
, -EIO
);
313 return tape_34xx_erp_retry(request
);
318 sense
[0] & SENSE_COMMAND_REJECT
&&
319 sense
[1] & SENSE_WRITE_PROTECT
322 request
->op
== TO_DSE
||
323 request
->op
== TO_WRI
||
324 request
->op
== TO_WTM
326 /* medium is write protected */
327 return tape_34xx_erp_failed(request
, -EACCES
);
329 return tape_34xx_erp_bug(device
, request
, irb
, -3);
334 * Special cases for various tape-states when reaching
335 * end of recorded area
337 * FIXME: Maybe a special case of the special case:
338 * sense[0] == SENSE_EQUIPMENT_CHECK &&
339 * sense[1] == SENSE_DRIVE_ONLINE &&
340 * sense[3] == 0x47 (Volume Fenced)
342 * This was caused by continued FSF or FSR after an
346 sense
[0] == SENSE_DATA_CHECK
||
347 sense
[0] == SENSE_EQUIPMENT_CHECK
||
348 sense
[0] == SENSE_EQUIPMENT_CHECK
+ SENSE_DEFERRED_UNIT_CHECK
350 sense
[1] == SENSE_DRIVE_ONLINE
||
351 sense
[1] == SENSE_BEGINNING_OF_TAPE
+ SENSE_WRITE_MODE
353 switch (request
->op
) {
355 * sense[0] == SENSE_DATA_CHECK &&
356 * sense[1] == SENSE_DRIVE_ONLINE
357 * sense[3] == 0x36 (End Of Data)
359 * Further seeks might return a 'Volume Fenced'.
363 /* Trying to seek beyond end of recorded area */
364 return tape_34xx_erp_failed(request
, -ENOSPC
);
366 return tape_34xx_erp_retry(request
);
369 * sense[0] == SENSE_DATA_CHECK &&
370 * sense[1] == SENSE_DRIVE_ONLINE &&
371 * sense[3] == 0x36 (End Of Data)
374 /* Block could not be located. */
375 tape_34xx_delete_sbid_from(device
, 0);
376 return tape_34xx_erp_failed(request
, -EIO
);
379 /* Read beyond end of recorded area -> 0 bytes read */
380 return tape_34xx_erp_failed(request
, 0);
383 * sense[0] == SENSE_EQUIPMENT_CHECK &&
384 * sense[1] == SENSE_DRIVE_ONLINE &&
385 * sense[3] == 0x38 (Physical End Of Volume)
388 /* Writing at physical end of volume */
389 return tape_34xx_erp_failed(request
, -ENOSPC
);
391 return tape_34xx_erp_failed(request
, 0);
395 /* Sensing special bits */
396 if (sense
[0] & SENSE_BUS_OUT_CHECK
)
397 return tape_34xx_erp_retry(request
);
399 if (sense
[0] & SENSE_DATA_CHECK
) {
401 * hardware failure, damaged tape or improper
402 * operating conditions
406 /* a read data check occurred */
407 if ((sense
[2] & SENSE_TAPE_SYNC_MODE
) ||
409 // data check is not permanent, may be
410 // recovered. We always use async-mode with
411 // cu-recovery, so this should *never* happen.
412 return tape_34xx_erp_bug(device
, request
,
415 /* data check is permanent, CU recovery has failed */
416 dev_warn (&device
->cdev
->dev
, "A read error occurred "
417 "that cannot be recovered\n");
418 return tape_34xx_erp_failed(request
, -EIO
);
420 // a write data check occurred
421 if ((sense
[2] & SENSE_TAPE_SYNC_MODE
) ||
423 // data check is not permanent, may be
424 // recovered. We always use async-mode with
425 // cu-recovery, so this should *never* happen.
426 return tape_34xx_erp_bug(device
, request
,
429 // data check is permanent, cu-recovery has failed
430 dev_warn (&device
->cdev
->dev
, "A write error on the "
431 "tape cannot be recovered\n");
432 return tape_34xx_erp_failed(request
, -EIO
);
434 /* Data Check (read opposite) occurred. */
435 return tape_34xx_erp_read_opposite(device
, request
);
437 /* ID-Mark at tape start couldn't be written */
438 dev_warn (&device
->cdev
->dev
, "Writing the ID-mark "
440 return tape_34xx_erp_failed(request
, -EIO
);
442 /* Tape void. Tried to read beyond end of device. */
443 dev_warn (&device
->cdev
->dev
, "Reading the tape beyond"
444 " the end of the recorded area failed\n");
445 return tape_34xx_erp_failed(request
, -ENOSPC
);
447 /* Record sequence error. */
448 dev_warn (&device
->cdev
->dev
, "The tape contains an "
449 "incorrect block ID sequence\n");
450 return tape_34xx_erp_failed(request
, -EIO
);
452 /* all data checks for 3480 should result in one of
453 * the above erpa-codes. For 3490, other data-check
454 * conditions do exist. */
455 if (device
->cdev
->id
.driver_info
== tape_3480
)
456 return tape_34xx_erp_bug(device
, request
,
461 if (sense
[0] & SENSE_OVERRUN
)
462 return tape_34xx_erp_overrun(device
, request
, irb
);
464 if (sense
[1] & SENSE_RECORD_SEQUENCE_ERR
)
465 return tape_34xx_erp_sequence(device
, request
, irb
);
467 /* Sensing erpa codes */
470 /* Unit check with erpa code 0. Report and ignore. */
471 return TAPE_IO_SUCCESS
;
474 * Data streaming not operational. CU will switch to
475 * interlock mode. Reissue the command.
477 return tape_34xx_erp_retry(request
);
480 * Path equipment check. Might be drive adapter error, buffer
481 * error on the lower interface, internal path not usable,
482 * or error during cartridge load.
484 dev_warn (&device
->cdev
->dev
, "A path equipment check occurred"
485 " for the tape device\n");
486 return tape_34xx_erp_failed(request
, -EIO
);
489 * Load display check. Load display was command was issued,
490 * but the drive is displaying a drive check message. Can
491 * be threated as "device end".
493 return tape_34xx_erp_succeeded(request
);
496 * Command reject. May indicate illegal channel program or
497 * buffer over/underrun. Since all channel programs are
498 * issued by this driver and ought be correct, we assume a
499 * over/underrun situation and retry the channel program.
501 return tape_34xx_erp_retry(request
);
504 * Function incompatible. Either the tape is idrc compressed
505 * but the hardware isn't capable to do idrc, or a perform
506 * subsystem func is issued and the CU is not on-line.
508 return tape_34xx_erp_failed(request
, -EIO
);
511 * Unsolicited environmental data. An internal counter
512 * overflows, we can ignore this and reissue the cmd.
514 return tape_34xx_erp_retry(request
);
517 * Environmental data present. Indicates either unload
518 * completed ok or read buffered log command completed ok.
520 if (request
->op
== TO_RUN
) {
521 /* Rewind unload completed ok. */
522 tape_med_state_set(device
, MS_UNLOADED
);
523 return tape_34xx_erp_succeeded(request
);
525 /* tape_34xx doesn't use read buffered log commands. */
526 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
529 * Permanent equipment check. CU has tried recovery, but
532 return tape_34xx_erp_failed(request
, -EIO
);
534 /* Data security erase failure. */
535 if (request
->op
== TO_DSE
)
536 return tape_34xx_erp_failed(request
, -EIO
);
537 /* Data security erase failure, but no such command issued. */
538 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
541 * Not capable. This indicates either that the drive fails
542 * reading the format id mark or that that format specified
543 * is not supported by the drive.
545 dev_warn (&device
->cdev
->dev
, "The tape unit cannot process "
546 "the tape format\n");
547 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
549 /* The medium is write protected. */
550 dev_warn (&device
->cdev
->dev
, "The tape medium is write-"
552 return tape_34xx_erp_failed(request
, -EACCES
);
554 // Tension loss. We cannot recover this, it's an I/O error.
555 dev_warn (&device
->cdev
->dev
, "The tape does not have the "
556 "required tape tension\n");
557 return tape_34xx_erp_failed(request
, -EIO
);
560 * Load Failure. The cartridge was not inserted correctly or
561 * the tape is not threaded correctly.
563 dev_warn (&device
->cdev
->dev
, "The tape unit failed to load"
565 tape_34xx_delete_sbid_from(device
, 0);
566 return tape_34xx_erp_failed(request
, -EIO
);
569 * Unload failure. The drive cannot maintain tape tension
570 * and control tape movement during an unload operation.
572 dev_warn (&device
->cdev
->dev
, "Automatic unloading of the tape"
573 " cartridge failed\n");
574 if (request
->op
== TO_RUN
)
575 return tape_34xx_erp_failed(request
, -EIO
);
576 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
579 * Drive equipment check. One of the following:
580 * - cu cannot recover from a drive detected error
581 * - a check code message is shown on drive display
582 * - the cartridge loader does not respond correctly
583 * - a failure occurs during an index, load, or unload cycle
585 dev_warn (&device
->cdev
->dev
, "An equipment check has occurred"
586 " on the tape unit\n");
587 return tape_34xx_erp_failed(request
, -EIO
);
589 if (device
->cdev
->id
.driver_info
== tape_3490
)
591 return tape_34xx_erp_failed(request
, -EIO
);
592 /* This erpa is reserved for 3480 */
593 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
596 * Tape length error. The tape is shorter than reported in
597 * the beginning-of-tape data.
599 dev_warn (&device
->cdev
->dev
, "The tape information states an"
600 " incorrect length\n");
601 return tape_34xx_erp_failed(request
, -EIO
);
604 * Physical end of tape. A read/write operation reached
605 * the physical end of tape.
607 if (request
->op
==TO_WRI
||
608 request
->op
==TO_DSE
||
610 return tape_34xx_erp_failed(request
, -ENOSPC
);
611 return tape_34xx_erp_failed(request
, -EIO
);
613 /* Backward at Beginning of tape. */
614 return tape_34xx_erp_failed(request
, -EIO
);
616 /* Drive switched to not ready. */
617 dev_warn (&device
->cdev
->dev
, "The tape unit is not ready\n");
618 return tape_34xx_erp_failed(request
, -EIO
);
620 /* Manual rewind or unload. This causes an I/O error. */
621 dev_warn (&device
->cdev
->dev
, "The tape medium has been "
622 "rewound or unloaded manually\n");
623 tape_34xx_delete_sbid_from(device
, 0);
624 return tape_34xx_erp_failed(request
, -EIO
);
627 * Degraded mode. A condition that can cause degraded
628 * performance is detected.
630 dev_warn (&device
->cdev
->dev
, "The tape subsystem is running "
631 "in degraded mode\n");
632 return tape_34xx_erp_retry(request
);
634 /* Drive not ready. */
635 tape_34xx_delete_sbid_from(device
, 0);
636 tape_med_state_set(device
, MS_UNLOADED
);
637 /* Some commands commands are successful even in this case */
638 if (sense
[1] & SENSE_DRIVE_ONLINE
) {
639 switch(request
->op
) {
644 return tape_34xx_done(request
);
650 return tape_34xx_erp_failed(request
, -ENOMEDIUM
);
652 /* Locate Block unsuccessful. */
653 if (request
->op
!= TO_BLOCK
&& request
->op
!= TO_LBL
)
654 /* No locate block was issued. */
655 return tape_34xx_erp_bug(device
, request
,
657 return tape_34xx_erp_failed(request
, -EIO
);
659 /* The drive is assigned to a different channel path. */
660 dev_warn (&device
->cdev
->dev
, "The tape unit is already "
662 return tape_34xx_erp_failed(request
, -EIO
);
665 * Drive not on-line. Drive may be switched offline,
666 * the power supply may be switched off or
667 * the drive address may not be set correctly.
669 dev_warn (&device
->cdev
->dev
, "The tape unit is not online\n");
670 return tape_34xx_erp_failed(request
, -EIO
);
672 /* Volume fenced. CU reports volume integrity is lost. */
673 dev_warn (&device
->cdev
->dev
, "The control unit has fenced "
674 "access to the tape volume\n");
675 tape_34xx_delete_sbid_from(device
, 0);
676 return tape_34xx_erp_failed(request
, -EIO
);
678 /* Log sense data and retry request. */
679 return tape_34xx_erp_retry(request
);
681 /* Bus out check. A parity check error on the bus was found. */
682 dev_warn (&device
->cdev
->dev
, "A parity error occurred on the "
684 return tape_34xx_erp_failed(request
, -EIO
);
686 /* Control unit erp failed. */
687 dev_warn (&device
->cdev
->dev
, "I/O error recovery failed on "
688 "the tape control unit\n");
689 return tape_34xx_erp_failed(request
, -EIO
);
692 * CU and drive incompatible. The drive requests micro-program
693 * patches, which are not available on the CU.
695 dev_warn (&device
->cdev
->dev
, "The tape unit requires a "
696 "firmware update\n");
697 return tape_34xx_erp_failed(request
, -EIO
);
700 * Recovered Check-One failure. Cu develops a hardware error,
701 * but is able to recover.
703 return tape_34xx_erp_retry(request
);
705 if (device
->cdev
->id
.driver_info
== tape_3490
)
707 * Resetting event received. Since the driver does
708 * not support resetting event recovery (which has to
709 * be handled by the I/O Layer), retry our command.
711 return tape_34xx_erp_retry(request
);
712 /* This erpa is reserved for 3480. */
713 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
715 if (device
->cdev
->id
.driver_info
== tape_3490
) {
717 * Maximum block size exceeded. This indicates, that
718 * the block to be written is larger than allowed for
721 dev_warn (&device
->cdev
->dev
, "The maximum block size"
722 " for buffered mode is exceeded\n");
723 return tape_34xx_erp_failed(request
, -ENOBUFS
);
725 /* This erpa is reserved for 3480. */
726 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
729 * Read buffered log (Overflow). CU is running in extended
730 * buffered log mode, and a counter overflows. This should
731 * never happen, since we're never running in extended
734 return tape_34xx_erp_retry(request
);
737 * Read buffered log (EOV). EOF processing occurs while the
738 * CU is in extended buffered log mode. This should never
739 * happen, since we're never running in extended buffered
742 return tape_34xx_erp_retry(request
);
744 /* End of Volume complete. Rewind unload completed ok. */
745 if (request
->op
== TO_RUN
) {
746 tape_med_state_set(device
, MS_UNLOADED
);
747 tape_34xx_delete_sbid_from(device
, 0);
748 return tape_34xx_erp_succeeded(request
);
750 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
752 /* Global command intercept. */
753 return tape_34xx_erp_retry(request
);
755 /* Channel interface recovery (temporary). */
756 return tape_34xx_erp_retry(request
);
758 /* Channel interface recovery (permanent). */
759 dev_warn (&device
->cdev
->dev
, "A channel interface error cannot be"
761 return tape_34xx_erp_failed(request
, -EIO
);
763 /* Channel protocol error. */
764 dev_warn (&device
->cdev
->dev
, "A channel protocol error "
766 return tape_34xx_erp_failed(request
, -EIO
);
768 if (device
->cdev
->id
.driver_info
== tape_3480
) {
769 /* Attention intercept. */
770 return tape_34xx_erp_retry(request
);
772 /* Global status intercept. */
773 return tape_34xx_erp_retry(request
);
777 * Tape length incompatible. The tape inserted is too long,
778 * which could cause damage to the tape or the drive.
780 dev_warn (&device
->cdev
->dev
, "The tape unit does not support "
781 "the tape length\n");
782 return tape_34xx_erp_failed(request
, -EIO
);
784 /* Format 3480 XF incompatible */
785 if (sense
[1] & SENSE_BEGINNING_OF_TAPE
)
786 /* The tape will get overwritten. */
787 return tape_34xx_erp_retry(request
);
788 dev_warn (&device
->cdev
->dev
, "The tape unit does not support"
789 " format 3480 XF\n");
790 return tape_34xx_erp_failed(request
, -EIO
);
792 /* Format 3480-2 XF incompatible */
793 dev_warn (&device
->cdev
->dev
, "The tape unit does not support tape "
794 "format 3480-2 XF\n");
795 return tape_34xx_erp_failed(request
, -EIO
);
797 /* Tape length violation. */
798 dev_warn (&device
->cdev
->dev
, "The tape unit does not support"
799 " the current tape length\n");
800 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
802 /* Compaction algorithm incompatible. */
803 dev_warn (&device
->cdev
->dev
, "The tape unit does not support"
804 " the compaction algorithm\n");
805 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
807 /* The following erpas should have been covered earlier. */
808 case 0x23: /* Read data check. */
809 case 0x25: /* Write data check. */
810 case 0x26: /* Data check (read opposite). */
811 case 0x28: /* Write id mark check. */
812 case 0x31: /* Tape void. */
813 case 0x40: /* Overrun error. */
814 case 0x41: /* Record sequence error. */
815 /* All other erpas are reserved for future use. */
817 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
822 * 3480/3490 interrupt handler
825 tape_34xx_irq(struct tape_device
*device
, struct tape_request
*request
,
829 return tape_34xx_unsolicited_irq(device
, irb
);
831 if ((irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_EXCEP
) &&
832 (irb
->scsw
.cmd
.dstat
& DEV_STAT_DEV_END
) &&
833 (request
->op
== TO_WRI
)) {
834 /* Write at end of volume */
835 return tape_34xx_erp_failed(request
, -ENOSPC
);
838 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
)
839 return tape_34xx_unit_check(device
, request
, irb
);
841 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_DEV_END
) {
843 * A unit exception occurs on skipping over a tapemark block.
845 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_EXCEP
) {
846 if (request
->op
== TO_BSB
|| request
->op
== TO_FSB
)
849 DBF_EVENT(5, "Unit Exception!\n");
851 return tape_34xx_done(request
);
854 DBF_EVENT(6, "xunknownirq\n");
855 tape_dump_sense_dbf(device
, request
, irb
);
863 tape_34xx_ioctl(struct tape_device
*device
, unsigned int cmd
, unsigned long arg
)
865 if (cmd
== TAPE390_DISPLAY
) {
866 struct display_struct disp
;
868 if (copy_from_user(&disp
, (char __user
*) arg
, sizeof(disp
)) != 0)
871 return tape_std_display(device
, &disp
);
877 tape_34xx_append_new_sbid(struct tape_34xx_block_id bid
, struct list_head
*l
)
879 struct tape_34xx_sbid
* new_sbid
;
881 new_sbid
= kmalloc(sizeof(*new_sbid
), GFP_ATOMIC
);
886 list_add(&new_sbid
->list
, l
);
890 * Build up the search block ID list. The block ID consists of a logical
891 * block number and a hardware specific part. The hardware specific part
892 * helps the tape drive to speed up searching for a specific block.
895 tape_34xx_add_sbid(struct tape_device
*device
, struct tape_34xx_block_id bid
)
897 struct list_head
* sbid_list
;
898 struct tape_34xx_sbid
* sbid
;
899 struct list_head
* l
;
902 * immediately return if there is no list at all or the block to add
903 * is located in segment 1 of wrap 0 because this position is used
904 * if no hardware position data is supplied.
906 sbid_list
= (struct list_head
*) device
->discdata
;
907 if (!sbid_list
|| (bid
.segment
< 2 && bid
.wrap
== 0))
911 * Search the position where to insert the new entry. Hardware
912 * acceleration uses only the segment and wrap number. So we
913 * need only one entry for a specific wrap/segment combination.
914 * If there is a block with a lower number but the same hard-
915 * ware position data we just update the block number in the
918 list_for_each(l
, sbid_list
) {
919 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
922 (sbid
->bid
.segment
== bid
.segment
) &&
923 (sbid
->bid
.wrap
== bid
.wrap
)
925 if (bid
.block
< sbid
->bid
.block
)
931 /* Sort in according to logical block number. */
932 if (bid
.block
< sbid
->bid
.block
) {
933 tape_34xx_append_new_sbid(bid
, l
->prev
);
937 /* List empty or new block bigger than last entry. */
939 tape_34xx_append_new_sbid(bid
, l
->prev
);
941 DBF_LH(4, "Current list is:\n");
942 list_for_each(l
, sbid_list
) {
943 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
944 DBF_LH(4, "%d:%03d@%05d\n",
953 * Delete all entries from the search block ID list that belong to tape blocks
954 * equal or higher than the given number.
957 tape_34xx_delete_sbid_from(struct tape_device
*device
, int from
)
959 struct list_head
* sbid_list
;
960 struct tape_34xx_sbid
* sbid
;
961 struct list_head
* l
;
962 struct list_head
* n
;
964 sbid_list
= (struct list_head
*) device
->discdata
;
968 list_for_each_safe(l
, n
, sbid_list
) {
969 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
970 if (sbid
->bid
.block
>= from
) {
971 DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
983 * Merge hardware position data into a block id.
986 tape_34xx_merge_sbid(
987 struct tape_device
* device
,
988 struct tape_34xx_block_id
* bid
990 struct tape_34xx_sbid
* sbid
;
991 struct tape_34xx_sbid
* sbid_to_use
;
992 struct list_head
* sbid_list
;
993 struct list_head
* l
;
995 sbid_list
= (struct list_head
*) device
->discdata
;
999 if (!sbid_list
|| list_empty(sbid_list
))
1003 list_for_each(l
, sbid_list
) {
1004 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
1006 if (sbid
->bid
.block
>= bid
->block
)
1011 bid
->wrap
= sbid_to_use
->bid
.wrap
;
1012 bid
->segment
= sbid_to_use
->bid
.segment
;
1013 DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
1014 sbid_to_use
->bid
.wrap
,
1015 sbid_to_use
->bid
.segment
,
1016 sbid_to_use
->bid
.block
,
1023 tape_34xx_setup_device(struct tape_device
* device
)
1026 struct list_head
* discdata
;
1028 DBF_EVENT(6, "34xx device setup\n");
1029 if ((rc
= tape_std_assign(device
)) == 0) {
1030 if ((rc
= tape_34xx_medium_sense(device
)) != 0) {
1031 DBF_LH(3, "34xx medium sense returned %d\n", rc
);
1034 discdata
= kmalloc(sizeof(struct list_head
), GFP_KERNEL
);
1036 INIT_LIST_HEAD(discdata
);
1037 device
->discdata
= discdata
;
1044 tape_34xx_cleanup_device(struct tape_device
*device
)
1046 tape_std_unassign(device
);
1048 if (device
->discdata
) {
1049 tape_34xx_delete_sbid_from(device
, 0);
1050 kfree(device
->discdata
);
1051 device
->discdata
= NULL
;
1057 * MTTELL: Tell block. Return the number of block relative to current file.
1060 tape_34xx_mttell(struct tape_device
*device
, int mt_count
)
1063 struct tape_34xx_block_id cbid
;
1064 struct tape_34xx_block_id dbid
;
1065 } __attribute__ ((packed
)) block_id
;
1068 rc
= tape_std_read_block_id(device
, (__u64
*) &block_id
);
1072 tape_34xx_add_sbid(device
, block_id
.cbid
);
1073 return block_id
.cbid
.block
;
1077 * MTSEEK: seek to the specified block.
1080 tape_34xx_mtseek(struct tape_device
*device
, int mt_count
)
1082 struct tape_request
*request
;
1083 struct tape_34xx_block_id
* bid
;
1085 if (mt_count
> 0x3fffff) {
1086 DBF_EXCEPTION(6, "xsee parm\n");
1089 request
= tape_alloc_request(3, 4);
1090 if (IS_ERR(request
))
1091 return PTR_ERR(request
);
1094 request
->op
= TO_LBL
;
1095 bid
= (struct tape_34xx_block_id
*) request
->cpdata
;
1096 bid
->format
= (*device
->modeset_byte
& 0x08) ?
1097 TAPE34XX_FMT_3480_XF
: TAPE34XX_FMT_3480
;
1098 bid
->block
= mt_count
;
1099 tape_34xx_merge_sbid(device
, bid
);
1101 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
1102 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
1103 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
1106 return tape_do_io_free(device
, request
);
1109 #ifdef CONFIG_S390_TAPE_BLOCK
1111 * Tape block read for 34xx.
1113 static struct tape_request
*
1114 tape_34xx_bread(struct tape_device
*device
, struct request
*req
)
1116 struct tape_request
*request
;
1122 struct req_iterator iter
;
1123 struct tape_34xx_block_id
* start_block
;
1125 DBF_EVENT(6, "xBREDid:");
1127 /* Count the number of blocks for the request. */
1128 rq_for_each_segment(bv
, req
, iter
)
1129 count
+= bv
->bv_len
>> (TAPEBLOCK_HSEC_S2B
+ 9);
1131 /* Allocate the ccw request. */
1132 request
= tape_alloc_request(3+count
+1, 8);
1133 if (IS_ERR(request
))
1137 request
->op
= TO_BLOCK
;
1138 start_block
= (struct tape_34xx_block_id
*) request
->cpdata
;
1139 start_block
->block
= blk_rq_pos(req
) >> TAPEBLOCK_HSEC_S2B
;
1140 DBF_EVENT(6, "start_block = %i\n", start_block
->block
);
1142 ccw
= request
->cpaddr
;
1143 ccw
= tape_ccw_cc(ccw
, MODE_SET_DB
, 1, device
->modeset_byte
);
1146 * We always setup a nop after the mode set ccw. This slot is
1147 * used in tape_std_check_locate to insert a locate ccw if the
1148 * current tape position doesn't match the start block to be read.
1149 * The second nop will be filled with a read block id which is in
1150 * turn used by tape_34xx_free_bread to populate the segment bid
1153 ccw
= tape_ccw_cc(ccw
, NOP
, 0, NULL
);
1154 ccw
= tape_ccw_cc(ccw
, NOP
, 0, NULL
);
1156 rq_for_each_segment(bv
, req
, iter
) {
1157 dst
= kmap(bv
->bv_page
) + bv
->bv_offset
;
1158 for (off
= 0; off
< bv
->bv_len
; off
+= TAPEBLOCK_HSEC_SIZE
) {
1159 ccw
->flags
= CCW_FLAG_CC
;
1160 ccw
->cmd_code
= READ_FORWARD
;
1161 ccw
->count
= TAPEBLOCK_HSEC_SIZE
;
1162 set_normalized_cda(ccw
, (void*) __pa(dst
));
1164 dst
+= TAPEBLOCK_HSEC_SIZE
;
1168 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
1169 DBF_EVENT(6, "xBREDccwg\n");
1174 tape_34xx_free_bread (struct tape_request
*request
)
1178 ccw
= request
->cpaddr
;
1179 if ((ccw
+ 2)->cmd_code
== READ_BLOCK_ID
) {
1181 struct tape_34xx_block_id cbid
;
1182 struct tape_34xx_block_id dbid
;
1183 } __attribute__ ((packed
)) *rbi_data
;
1185 rbi_data
= request
->cpdata
;
1187 if (request
->device
)
1188 tape_34xx_add_sbid(request
->device
, rbi_data
->cbid
);
1191 /* Last ccw is a nop and doesn't need clear_normalized_cda */
1192 for (; ccw
->flags
& CCW_FLAG_CC
; ccw
++)
1193 if (ccw
->cmd_code
== READ_FORWARD
)
1194 clear_normalized_cda(ccw
);
1195 tape_free_request(request
);
1199 * check_locate is called just before the tape request is passed to
1200 * the common io layer for execution. It has to check the current
1201 * tape position and insert a locate ccw if it doesn't match the
1202 * start block for the request.
1205 tape_34xx_check_locate(struct tape_device
*device
, struct tape_request
*request
)
1207 struct tape_34xx_block_id
* start_block
;
1209 start_block
= (struct tape_34xx_block_id
*) request
->cpdata
;
1210 if (start_block
->block
== device
->blk_data
.block_position
)
1213 DBF_LH(4, "Block seek(%06d+%06d)\n", start_block
->block
, device
->bof
);
1214 start_block
->wrap
= 0;
1215 start_block
->segment
= 1;
1216 start_block
->format
= (*device
->modeset_byte
& 0x08) ?
1217 TAPE34XX_FMT_3480_XF
:
1219 start_block
->block
= start_block
->block
+ device
->bof
;
1220 tape_34xx_merge_sbid(device
, start_block
);
1221 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
1222 tape_ccw_cc(request
->cpaddr
+ 2, READ_BLOCK_ID
, 8, request
->cpdata
);
1227 * List of 3480/3490 magnetic tape commands.
1229 static tape_mtop_fn tape_34xx_mtop
[TAPE_NR_MTOPS
] = {
1230 [MTRESET
] = tape_std_mtreset
,
1231 [MTFSF
] = tape_std_mtfsf
,
1232 [MTBSF
] = tape_std_mtbsf
,
1233 [MTFSR
] = tape_std_mtfsr
,
1234 [MTBSR
] = tape_std_mtbsr
,
1235 [MTWEOF
] = tape_std_mtweof
,
1236 [MTREW
] = tape_std_mtrew
,
1237 [MTOFFL
] = tape_std_mtoffl
,
1238 [MTNOP
] = tape_std_mtnop
,
1239 [MTRETEN
] = tape_std_mtreten
,
1240 [MTBSFM
] = tape_std_mtbsfm
,
1241 [MTFSFM
] = tape_std_mtfsfm
,
1242 [MTEOM
] = tape_std_mteom
,
1243 [MTERASE
] = tape_std_mterase
,
1247 [MTSETBLK
] = tape_std_mtsetblk
,
1248 [MTSETDENSITY
] = NULL
,
1249 [MTSEEK
] = tape_34xx_mtseek
,
1250 [MTTELL
] = tape_34xx_mttell
,
1251 [MTSETDRVBUFFER
] = NULL
,
1257 [MTLOAD
] = tape_std_mtload
,
1258 [MTUNLOAD
] = tape_std_mtunload
,
1259 [MTCOMPRESSION
] = tape_std_mtcompression
,
1265 * Tape discipline structure for 3480 and 3490.
1267 static struct tape_discipline tape_discipline_34xx
= {
1268 .owner
= THIS_MODULE
,
1269 .setup_device
= tape_34xx_setup_device
,
1270 .cleanup_device
= tape_34xx_cleanup_device
,
1271 .process_eov
= tape_std_process_eov
,
1272 .irq
= tape_34xx_irq
,
1273 .read_block
= tape_std_read_block
,
1274 .write_block
= tape_std_write_block
,
1275 #ifdef CONFIG_S390_TAPE_BLOCK
1276 .bread
= tape_34xx_bread
,
1277 .free_bread
= tape_34xx_free_bread
,
1278 .check_locate
= tape_34xx_check_locate
,
1280 .ioctl_fn
= tape_34xx_ioctl
,
1281 .mtop_array
= tape_34xx_mtop
1284 static struct ccw_device_id tape_34xx_ids
[] = {
1285 { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), .driver_info
= tape_3480
},
1286 { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), .driver_info
= tape_3490
},
1287 { /* end of list */ },
1291 tape_34xx_online(struct ccw_device
*cdev
)
1293 return tape_generic_online(
1294 dev_get_drvdata(&cdev
->dev
),
1295 &tape_discipline_34xx
1299 static struct ccw_driver tape_34xx_driver
= {
1300 .name
= "tape_34xx",
1301 .owner
= THIS_MODULE
,
1302 .ids
= tape_34xx_ids
,
1303 .probe
= tape_generic_probe
,
1304 .remove
= tape_generic_remove
,
1305 .set_online
= tape_34xx_online
,
1306 .set_offline
= tape_generic_offline
,
1307 .freeze
= tape_generic_pm_suspend
,
1311 tape_34xx_init (void)
1315 TAPE_DBF_AREA
= debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
1316 debug_register_view(TAPE_DBF_AREA
, &debug_sprintf_view
);
1317 #ifdef DBF_LIKE_HELL
1318 debug_set_level(TAPE_DBF_AREA
, 6);
1321 DBF_EVENT(3, "34xx init\n");
1322 /* Register driver for 3480/3490 tapes. */
1323 rc
= ccw_driver_register(&tape_34xx_driver
);
1325 DBF_EVENT(3, "34xx init failed\n");
1327 DBF_EVENT(3, "34xx registered\n");
1332 tape_34xx_exit(void)
1334 ccw_driver_unregister(&tape_34xx_driver
);
1336 debug_unregister(TAPE_DBF_AREA
);
1339 MODULE_DEVICE_TABLE(ccw
, tape_34xx_ids
);
1340 MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
1341 MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape device driver");
1342 MODULE_LICENSE("GPL");
1344 module_init(tape_34xx_init
);
1345 module_exit(tape_34xx_exit
);