2 * tape device discipline for 3480/3490 tapes.
4 * Copyright IBM Corp. 2001, 2009
5 * Author(s): Carsten Otte <cotte@de.ibm.com>
6 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
7 * Martin Schwidefsky <schwidefsky@de.ibm.com>
10 #define KMSG_COMPONENT "tape_34xx"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/bio.h>
16 #include <linux/workqueue.h>
17 #include <linux/slab.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.
55 static void __tape_34xx_medium_sense(struct tape_request
*request
)
57 struct tape_device
*device
= request
->device
;
60 if (request
->rc
== 0) {
61 sense
= request
->cpdata
;
64 * This isn't quite correct. But since INTERVENTION_REQUIRED
65 * means that the drive is 'neither ready nor on-line' it is
66 * only slightly inaccurate to say there is no tape loaded if
67 * the drive isn't online...
69 if (sense
[0] & SENSE_INTERVENTION_REQUIRED
)
70 tape_med_state_set(device
, MS_UNLOADED
);
72 tape_med_state_set(device
, MS_LOADED
);
74 if (sense
[1] & SENSE_WRITE_PROTECT
)
75 device
->tape_generic_status
|= GMT_WR_PROT(~0);
77 device
->tape_generic_status
&= ~GMT_WR_PROT(~0);
79 DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
81 tape_free_request(request
);
84 static int tape_34xx_medium_sense(struct tape_device
*device
)
86 struct tape_request
*request
;
89 request
= tape_alloc_request(1, 32);
90 if (IS_ERR(request
)) {
91 DBF_EXCEPTION(6, "MSEN fail\n");
92 return PTR_ERR(request
);
95 request
->op
= TO_MSEN
;
96 tape_ccw_end(request
->cpaddr
, SENSE
, 32, request
->cpdata
);
97 rc
= tape_do_io_interruptible(device
, request
);
98 __tape_34xx_medium_sense(request
);
102 static void tape_34xx_medium_sense_async(struct tape_device
*device
)
104 struct tape_request
*request
;
106 request
= tape_alloc_request(1, 32);
107 if (IS_ERR(request
)) {
108 DBF_EXCEPTION(6, "MSEN fail\n");
112 request
->op
= TO_MSEN
;
113 tape_ccw_end(request
->cpaddr
, SENSE
, 32, request
->cpdata
);
114 request
->callback
= (void *) __tape_34xx_medium_sense
;
115 request
->callback_data
= NULL
;
116 tape_do_io_async(device
, request
);
119 struct tape_34xx_work
{
120 struct tape_device
*device
;
122 struct work_struct work
;
126 * These functions are currently used only to schedule a medium_sense for
127 * later execution. This is because we get an interrupt whenever a medium
128 * is inserted but cannot call tape_do_io* from an interrupt context.
129 * Maybe that's useful for other actions we want to start from the
131 * Note: the work handler is called by the system work queue. The tape
132 * commands started by the handler need to be asynchrounous, otherwise
133 * a deadlock can occur e.g. in case of a deferred cc=1 (see __tape_do_irq).
136 tape_34xx_work_handler(struct work_struct
*work
)
138 struct tape_34xx_work
*p
=
139 container_of(work
, struct tape_34xx_work
, work
);
140 struct tape_device
*device
= p
->device
;
144 tape_34xx_medium_sense_async(device
);
147 DBF_EVENT(3, "T34XX: internal error: unknown work\n");
149 tape_put_device(device
);
154 tape_34xx_schedule_work(struct tape_device
*device
, enum tape_op op
)
156 struct tape_34xx_work
*p
;
158 if ((p
= kzalloc(sizeof(*p
), GFP_ATOMIC
)) == NULL
)
161 INIT_WORK(&p
->work
, tape_34xx_work_handler
);
163 p
->device
= tape_get_device(device
);
166 schedule_work(&p
->work
);
171 * Done Handler is called when dev stat = DEVICE-END (successful operation)
174 tape_34xx_done(struct tape_request
*request
)
176 DBF_EVENT(6, "%s done\n", tape_op_verbose
[request
->op
]);
178 switch (request
->op
) {
185 tape_34xx_delete_sbid_from(request
->device
, 0);
190 return TAPE_IO_SUCCESS
;
194 tape_34xx_erp_failed(struct tape_request
*request
, int rc
)
196 DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
197 tape_op_verbose
[request
->op
], rc
);
202 tape_34xx_erp_succeeded(struct tape_request
*request
)
204 DBF_EVENT(3, "Error Recovery successful for %s\n",
205 tape_op_verbose
[request
->op
]);
206 return tape_34xx_done(request
);
210 tape_34xx_erp_retry(struct tape_request
*request
)
212 DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose
[request
->op
]);
213 return TAPE_IO_RETRY
;
217 * This function is called, when no request is outstanding and we get an
221 tape_34xx_unsolicited_irq(struct tape_device
*device
, struct irb
*irb
)
223 if (irb
->scsw
.cmd
.dstat
== 0x85) { /* READY */
224 /* A medium was inserted in the drive. */
225 DBF_EVENT(6, "xuud med\n");
226 tape_34xx_delete_sbid_from(device
, 0);
227 tape_34xx_schedule_work(device
, TO_MSEN
);
229 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device
->cdev_id
);
230 tape_dump_sense_dbf(device
, NULL
, irb
);
232 return TAPE_IO_SUCCESS
;
236 * Read Opposite Error Recovery Function:
237 * Used, when Read Forward does not work
240 tape_34xx_erp_read_opposite(struct tape_device
*device
,
241 struct tape_request
*request
)
243 if (request
->op
== TO_RFO
) {
245 * We did read forward, but the data could not be read
246 * *correctly*. We transform the request to a read backward
249 tape_std_read_backward(device
, request
);
250 return tape_34xx_erp_retry(request
);
254 * We tried to read forward and backward, but hat no
257 return tape_34xx_erp_failed(request
, -EIO
);
261 tape_34xx_erp_bug(struct tape_device
*device
, struct tape_request
*request
,
262 struct irb
*irb
, int no
)
264 if (request
->op
!= TO_ASSIGN
) {
265 dev_err(&device
->cdev
->dev
, "An unexpected condition %d "
266 "occurred in tape error recovery\n", no
);
267 tape_dump_sense_dbf(device
, request
, irb
);
269 return tape_34xx_erp_failed(request
, -EIO
);
273 * Handle data overrun between cu and drive. The channel speed might
277 tape_34xx_erp_overrun(struct tape_device
*device
, struct tape_request
*request
,
280 if (irb
->ecw
[3] == 0x40) {
281 dev_warn (&device
->cdev
->dev
, "A data overrun occurred between"
282 " the control unit and tape unit\n");
283 return tape_34xx_erp_failed(request
, -EIO
);
285 return tape_34xx_erp_bug(device
, request
, irb
, -1);
289 * Handle record sequence error.
292 tape_34xx_erp_sequence(struct tape_device
*device
,
293 struct tape_request
*request
, struct irb
*irb
)
295 if (irb
->ecw
[3] == 0x41) {
297 * cu detected incorrect block-id sequence on tape.
299 dev_warn (&device
->cdev
->dev
, "The block ID sequence on the "
300 "tape is incorrect\n");
301 return tape_34xx_erp_failed(request
, -EIO
);
304 * Record sequence error bit is set, but erpa does not
305 * show record sequence error.
307 return tape_34xx_erp_bug(device
, request
, irb
, -2);
311 * This function analyses the tape's sense-data in case of a unit-check.
312 * If possible, it tries to recover from the error. Else the user is
313 * informed about the problem.
316 tape_34xx_unit_check(struct tape_device
*device
, struct tape_request
*request
,
319 int inhibit_cu_recovery
;
322 inhibit_cu_recovery
= (*device
->modeset_byte
& 0x80) ? 1 : 0;
326 sense
[0] & SENSE_COMMAND_REJECT
&&
327 sense
[1] & SENSE_WRITE_PROTECT
330 request
->op
== TO_DSE
||
331 request
->op
== TO_WRI
||
332 request
->op
== TO_WTM
334 /* medium is write protected */
335 return tape_34xx_erp_failed(request
, -EACCES
);
337 return tape_34xx_erp_bug(device
, request
, irb
, -3);
342 * Special cases for various tape-states when reaching
343 * end of recorded area
345 * FIXME: Maybe a special case of the special case:
346 * sense[0] == SENSE_EQUIPMENT_CHECK &&
347 * sense[1] == SENSE_DRIVE_ONLINE &&
348 * sense[3] == 0x47 (Volume Fenced)
350 * This was caused by continued FSF or FSR after an
354 sense
[0] == SENSE_DATA_CHECK
||
355 sense
[0] == SENSE_EQUIPMENT_CHECK
||
356 sense
[0] == SENSE_EQUIPMENT_CHECK
+ SENSE_DEFERRED_UNIT_CHECK
358 sense
[1] == SENSE_DRIVE_ONLINE
||
359 sense
[1] == SENSE_BEGINNING_OF_TAPE
+ SENSE_WRITE_MODE
361 switch (request
->op
) {
363 * sense[0] == SENSE_DATA_CHECK &&
364 * sense[1] == SENSE_DRIVE_ONLINE
365 * sense[3] == 0x36 (End Of Data)
367 * Further seeks might return a 'Volume Fenced'.
371 /* Trying to seek beyond end of recorded area */
372 return tape_34xx_erp_failed(request
, -ENOSPC
);
374 return tape_34xx_erp_retry(request
);
377 * sense[0] == SENSE_DATA_CHECK &&
378 * sense[1] == SENSE_DRIVE_ONLINE &&
379 * sense[3] == 0x36 (End Of Data)
382 /* Block could not be located. */
383 tape_34xx_delete_sbid_from(device
, 0);
384 return tape_34xx_erp_failed(request
, -EIO
);
387 /* Read beyond end of recorded area -> 0 bytes read */
388 return tape_34xx_erp_failed(request
, 0);
391 * sense[0] == SENSE_EQUIPMENT_CHECK &&
392 * sense[1] == SENSE_DRIVE_ONLINE &&
393 * sense[3] == 0x38 (Physical End Of Volume)
396 /* Writing at physical end of volume */
397 return tape_34xx_erp_failed(request
, -ENOSPC
);
399 return tape_34xx_erp_failed(request
, 0);
403 /* Sensing special bits */
404 if (sense
[0] & SENSE_BUS_OUT_CHECK
)
405 return tape_34xx_erp_retry(request
);
407 if (sense
[0] & SENSE_DATA_CHECK
) {
409 * hardware failure, damaged tape or improper
410 * operating conditions
414 /* a read data check occurred */
415 if ((sense
[2] & SENSE_TAPE_SYNC_MODE
) ||
417 // data check is not permanent, may be
418 // recovered. We always use async-mode with
419 // cu-recovery, so this should *never* happen.
420 return tape_34xx_erp_bug(device
, request
,
423 /* data check is permanent, CU recovery has failed */
424 dev_warn (&device
->cdev
->dev
, "A read error occurred "
425 "that cannot be recovered\n");
426 return tape_34xx_erp_failed(request
, -EIO
);
428 // a write data check occurred
429 if ((sense
[2] & SENSE_TAPE_SYNC_MODE
) ||
431 // data check is not permanent, may be
432 // recovered. We always use async-mode with
433 // cu-recovery, so this should *never* happen.
434 return tape_34xx_erp_bug(device
, request
,
437 // data check is permanent, cu-recovery has failed
438 dev_warn (&device
->cdev
->dev
, "A write error on the "
439 "tape cannot be recovered\n");
440 return tape_34xx_erp_failed(request
, -EIO
);
442 /* Data Check (read opposite) occurred. */
443 return tape_34xx_erp_read_opposite(device
, request
);
445 /* ID-Mark at tape start couldn't be written */
446 dev_warn (&device
->cdev
->dev
, "Writing the ID-mark "
448 return tape_34xx_erp_failed(request
, -EIO
);
450 /* Tape void. Tried to read beyond end of device. */
451 dev_warn (&device
->cdev
->dev
, "Reading the tape beyond"
452 " the end of the recorded area failed\n");
453 return tape_34xx_erp_failed(request
, -ENOSPC
);
455 /* Record sequence error. */
456 dev_warn (&device
->cdev
->dev
, "The tape contains an "
457 "incorrect block ID sequence\n");
458 return tape_34xx_erp_failed(request
, -EIO
);
460 /* all data checks for 3480 should result in one of
461 * the above erpa-codes. For 3490, other data-check
462 * conditions do exist. */
463 if (device
->cdev
->id
.driver_info
== tape_3480
)
464 return tape_34xx_erp_bug(device
, request
,
469 if (sense
[0] & SENSE_OVERRUN
)
470 return tape_34xx_erp_overrun(device
, request
, irb
);
472 if (sense
[1] & SENSE_RECORD_SEQUENCE_ERR
)
473 return tape_34xx_erp_sequence(device
, request
, irb
);
475 /* Sensing erpa codes */
478 /* Unit check with erpa code 0. Report and ignore. */
479 return TAPE_IO_SUCCESS
;
482 * Data streaming not operational. CU will switch to
483 * interlock mode. Reissue the command.
485 return tape_34xx_erp_retry(request
);
488 * Path equipment check. Might be drive adapter error, buffer
489 * error on the lower interface, internal path not usable,
490 * or error during cartridge load.
492 dev_warn (&device
->cdev
->dev
, "A path equipment check occurred"
493 " for the tape device\n");
494 return tape_34xx_erp_failed(request
, -EIO
);
497 * Load display check. Load display was command was issued,
498 * but the drive is displaying a drive check message. Can
499 * be threated as "device end".
501 return tape_34xx_erp_succeeded(request
);
504 * Command reject. May indicate illegal channel program or
505 * buffer over/underrun. Since all channel programs are
506 * issued by this driver and ought be correct, we assume a
507 * over/underrun situation and retry the channel program.
509 return tape_34xx_erp_retry(request
);
512 * Function incompatible. Either the tape is idrc compressed
513 * but the hardware isn't capable to do idrc, or a perform
514 * subsystem func is issued and the CU is not on-line.
516 return tape_34xx_erp_failed(request
, -EIO
);
519 * Unsolicited environmental data. An internal counter
520 * overflows, we can ignore this and reissue the cmd.
522 return tape_34xx_erp_retry(request
);
525 * Environmental data present. Indicates either unload
526 * completed ok or read buffered log command completed ok.
528 if (request
->op
== TO_RUN
) {
529 /* Rewind unload completed ok. */
530 tape_med_state_set(device
, MS_UNLOADED
);
531 return tape_34xx_erp_succeeded(request
);
533 /* tape_34xx doesn't use read buffered log commands. */
534 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
537 * Permanent equipment check. CU has tried recovery, but
540 return tape_34xx_erp_failed(request
, -EIO
);
542 /* Data security erase failure. */
543 if (request
->op
== TO_DSE
)
544 return tape_34xx_erp_failed(request
, -EIO
);
545 /* Data security erase failure, but no such command issued. */
546 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
549 * Not capable. This indicates either that the drive fails
550 * reading the format id mark or that that format specified
551 * is not supported by the drive.
553 dev_warn (&device
->cdev
->dev
, "The tape unit cannot process "
554 "the tape format\n");
555 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
557 /* The medium is write protected. */
558 dev_warn (&device
->cdev
->dev
, "The tape medium is write-"
560 return tape_34xx_erp_failed(request
, -EACCES
);
562 // Tension loss. We cannot recover this, it's an I/O error.
563 dev_warn (&device
->cdev
->dev
, "The tape does not have the "
564 "required tape tension\n");
565 return tape_34xx_erp_failed(request
, -EIO
);
568 * Load Failure. The cartridge was not inserted correctly or
569 * the tape is not threaded correctly.
571 dev_warn (&device
->cdev
->dev
, "The tape unit failed to load"
573 tape_34xx_delete_sbid_from(device
, 0);
574 return tape_34xx_erp_failed(request
, -EIO
);
577 * Unload failure. The drive cannot maintain tape tension
578 * and control tape movement during an unload operation.
580 dev_warn (&device
->cdev
->dev
, "Automatic unloading of the tape"
581 " cartridge failed\n");
582 if (request
->op
== TO_RUN
)
583 return tape_34xx_erp_failed(request
, -EIO
);
584 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
587 * Drive equipment check. One of the following:
588 * - cu cannot recover from a drive detected error
589 * - a check code message is shown on drive display
590 * - the cartridge loader does not respond correctly
591 * - a failure occurs during an index, load, or unload cycle
593 dev_warn (&device
->cdev
->dev
, "An equipment check has occurred"
594 " on the tape unit\n");
595 return tape_34xx_erp_failed(request
, -EIO
);
597 if (device
->cdev
->id
.driver_info
== tape_3490
)
599 return tape_34xx_erp_failed(request
, -EIO
);
600 /* This erpa is reserved for 3480 */
601 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
604 * Tape length error. The tape is shorter than reported in
605 * the beginning-of-tape data.
607 dev_warn (&device
->cdev
->dev
, "The tape information states an"
608 " incorrect length\n");
609 return tape_34xx_erp_failed(request
, -EIO
);
612 * Physical end of tape. A read/write operation reached
613 * the physical end of tape.
615 if (request
->op
==TO_WRI
||
616 request
->op
==TO_DSE
||
618 return tape_34xx_erp_failed(request
, -ENOSPC
);
619 return tape_34xx_erp_failed(request
, -EIO
);
621 /* Backward at Beginning of tape. */
622 return tape_34xx_erp_failed(request
, -EIO
);
624 /* Drive switched to not ready. */
625 dev_warn (&device
->cdev
->dev
, "The tape unit is not ready\n");
626 return tape_34xx_erp_failed(request
, -EIO
);
628 /* Manual rewind or unload. This causes an I/O error. */
629 dev_warn (&device
->cdev
->dev
, "The tape medium has been "
630 "rewound or unloaded manually\n");
631 tape_34xx_delete_sbid_from(device
, 0);
632 return tape_34xx_erp_failed(request
, -EIO
);
635 * Degraded mode. A condition that can cause degraded
636 * performance is detected.
638 dev_warn (&device
->cdev
->dev
, "The tape subsystem is running "
639 "in degraded mode\n");
640 return tape_34xx_erp_retry(request
);
642 /* Drive not ready. */
643 tape_34xx_delete_sbid_from(device
, 0);
644 tape_med_state_set(device
, MS_UNLOADED
);
645 /* Some commands commands are successful even in this case */
646 if (sense
[1] & SENSE_DRIVE_ONLINE
) {
647 switch(request
->op
) {
652 return tape_34xx_done(request
);
658 return tape_34xx_erp_failed(request
, -ENOMEDIUM
);
660 /* Locate Block unsuccessful. */
661 if (request
->op
!= TO_BLOCK
&& request
->op
!= TO_LBL
)
662 /* No locate block was issued. */
663 return tape_34xx_erp_bug(device
, request
,
665 return tape_34xx_erp_failed(request
, -EIO
);
667 /* The drive is assigned to a different channel path. */
668 dev_warn (&device
->cdev
->dev
, "The tape unit is already "
670 return tape_34xx_erp_failed(request
, -EIO
);
673 * Drive not on-line. Drive may be switched offline,
674 * the power supply may be switched off or
675 * the drive address may not be set correctly.
677 dev_warn (&device
->cdev
->dev
, "The tape unit is not online\n");
678 return tape_34xx_erp_failed(request
, -EIO
);
680 /* Volume fenced. CU reports volume integrity is lost. */
681 dev_warn (&device
->cdev
->dev
, "The control unit has fenced "
682 "access to the tape volume\n");
683 tape_34xx_delete_sbid_from(device
, 0);
684 return tape_34xx_erp_failed(request
, -EIO
);
686 /* Log sense data and retry request. */
687 return tape_34xx_erp_retry(request
);
689 /* Bus out check. A parity check error on the bus was found. */
690 dev_warn (&device
->cdev
->dev
, "A parity error occurred on the "
692 return tape_34xx_erp_failed(request
, -EIO
);
694 /* Control unit erp failed. */
695 dev_warn (&device
->cdev
->dev
, "I/O error recovery failed on "
696 "the tape control unit\n");
697 return tape_34xx_erp_failed(request
, -EIO
);
700 * CU and drive incompatible. The drive requests micro-program
701 * patches, which are not available on the CU.
703 dev_warn (&device
->cdev
->dev
, "The tape unit requires a "
704 "firmware update\n");
705 return tape_34xx_erp_failed(request
, -EIO
);
708 * Recovered Check-One failure. Cu develops a hardware error,
709 * but is able to recover.
711 return tape_34xx_erp_retry(request
);
713 if (device
->cdev
->id
.driver_info
== tape_3490
)
715 * Resetting event received. Since the driver does
716 * not support resetting event recovery (which has to
717 * be handled by the I/O Layer), retry our command.
719 return tape_34xx_erp_retry(request
);
720 /* This erpa is reserved for 3480. */
721 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
723 if (device
->cdev
->id
.driver_info
== tape_3490
) {
725 * Maximum block size exceeded. This indicates, that
726 * the block to be written is larger than allowed for
729 dev_warn (&device
->cdev
->dev
, "The maximum block size"
730 " for buffered mode is exceeded\n");
731 return tape_34xx_erp_failed(request
, -ENOBUFS
);
733 /* This erpa is reserved for 3480. */
734 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
737 * Read buffered log (Overflow). CU is running in extended
738 * buffered log mode, and a counter overflows. This should
739 * never happen, since we're never running in extended
742 return tape_34xx_erp_retry(request
);
745 * Read buffered log (EOV). EOF processing occurs while the
746 * CU is in extended buffered log mode. This should never
747 * happen, since we're never running in extended buffered
750 return tape_34xx_erp_retry(request
);
752 /* End of Volume complete. Rewind unload completed ok. */
753 if (request
->op
== TO_RUN
) {
754 tape_med_state_set(device
, MS_UNLOADED
);
755 tape_34xx_delete_sbid_from(device
, 0);
756 return tape_34xx_erp_succeeded(request
);
758 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
760 /* Global command intercept. */
761 return tape_34xx_erp_retry(request
);
763 /* Channel interface recovery (temporary). */
764 return tape_34xx_erp_retry(request
);
766 /* Channel interface recovery (permanent). */
767 dev_warn (&device
->cdev
->dev
, "A channel interface error cannot be"
769 return tape_34xx_erp_failed(request
, -EIO
);
771 /* Channel protocol error. */
772 dev_warn (&device
->cdev
->dev
, "A channel protocol error "
774 return tape_34xx_erp_failed(request
, -EIO
);
777 * 3480: Attention intercept.
778 * 3490: Global status intercept.
780 return tape_34xx_erp_retry(request
);
783 * Tape length incompatible. The tape inserted is too long,
784 * which could cause damage to the tape or the drive.
786 dev_warn (&device
->cdev
->dev
, "The tape unit does not support "
787 "the tape length\n");
788 return tape_34xx_erp_failed(request
, -EIO
);
790 /* Format 3480 XF incompatible */
791 if (sense
[1] & SENSE_BEGINNING_OF_TAPE
)
792 /* The tape will get overwritten. */
793 return tape_34xx_erp_retry(request
);
794 dev_warn (&device
->cdev
->dev
, "The tape unit does not support"
795 " format 3480 XF\n");
796 return tape_34xx_erp_failed(request
, -EIO
);
798 /* Format 3480-2 XF incompatible */
799 dev_warn (&device
->cdev
->dev
, "The tape unit does not support tape "
800 "format 3480-2 XF\n");
801 return tape_34xx_erp_failed(request
, -EIO
);
803 /* Tape length violation. */
804 dev_warn (&device
->cdev
->dev
, "The tape unit does not support"
805 " the current tape length\n");
806 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
808 /* Compaction algorithm incompatible. */
809 dev_warn (&device
->cdev
->dev
, "The tape unit does not support"
810 " the compaction algorithm\n");
811 return tape_34xx_erp_failed(request
, -EMEDIUMTYPE
);
813 /* The following erpas should have been covered earlier. */
814 case 0x23: /* Read data check. */
815 case 0x25: /* Write data check. */
816 case 0x26: /* Data check (read opposite). */
817 case 0x28: /* Write id mark check. */
818 case 0x31: /* Tape void. */
819 case 0x40: /* Overrun error. */
820 case 0x41: /* Record sequence error. */
821 /* All other erpas are reserved for future use. */
823 return tape_34xx_erp_bug(device
, request
, irb
, sense
[3]);
828 * 3480/3490 interrupt handler
831 tape_34xx_irq(struct tape_device
*device
, struct tape_request
*request
,
835 return tape_34xx_unsolicited_irq(device
, irb
);
837 if ((irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_EXCEP
) &&
838 (irb
->scsw
.cmd
.dstat
& DEV_STAT_DEV_END
) &&
839 (request
->op
== TO_WRI
)) {
840 /* Write at end of volume */
841 return tape_34xx_erp_failed(request
, -ENOSPC
);
844 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
)
845 return tape_34xx_unit_check(device
, request
, irb
);
847 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_DEV_END
) {
849 * A unit exception occurs on skipping over a tapemark block.
851 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_EXCEP
) {
852 if (request
->op
== TO_BSB
|| request
->op
== TO_FSB
)
855 DBF_EVENT(5, "Unit Exception!\n");
857 return tape_34xx_done(request
);
860 DBF_EVENT(6, "xunknownirq\n");
861 tape_dump_sense_dbf(device
, request
, irb
);
869 tape_34xx_ioctl(struct tape_device
*device
, unsigned int cmd
, unsigned long arg
)
871 if (cmd
== TAPE390_DISPLAY
) {
872 struct display_struct disp
;
874 if (copy_from_user(&disp
, (char __user
*) arg
, sizeof(disp
)) != 0)
877 return tape_std_display(device
, &disp
);
883 tape_34xx_append_new_sbid(struct tape_34xx_block_id bid
, struct list_head
*l
)
885 struct tape_34xx_sbid
* new_sbid
;
887 new_sbid
= kmalloc(sizeof(*new_sbid
), GFP_ATOMIC
);
892 list_add(&new_sbid
->list
, l
);
896 * Build up the search block ID list. The block ID consists of a logical
897 * block number and a hardware specific part. The hardware specific part
898 * helps the tape drive to speed up searching for a specific block.
901 tape_34xx_add_sbid(struct tape_device
*device
, struct tape_34xx_block_id bid
)
903 struct list_head
* sbid_list
;
904 struct tape_34xx_sbid
* sbid
;
905 struct list_head
* l
;
908 * immediately return if there is no list at all or the block to add
909 * is located in segment 1 of wrap 0 because this position is used
910 * if no hardware position data is supplied.
912 sbid_list
= (struct list_head
*) device
->discdata
;
913 if (!sbid_list
|| (bid
.segment
< 2 && bid
.wrap
== 0))
917 * Search the position where to insert the new entry. Hardware
918 * acceleration uses only the segment and wrap number. So we
919 * need only one entry for a specific wrap/segment combination.
920 * If there is a block with a lower number but the same hard-
921 * ware position data we just update the block number in the
924 list_for_each(l
, sbid_list
) {
925 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
928 (sbid
->bid
.segment
== bid
.segment
) &&
929 (sbid
->bid
.wrap
== bid
.wrap
)
931 if (bid
.block
< sbid
->bid
.block
)
937 /* Sort in according to logical block number. */
938 if (bid
.block
< sbid
->bid
.block
) {
939 tape_34xx_append_new_sbid(bid
, l
->prev
);
943 /* List empty or new block bigger than last entry. */
945 tape_34xx_append_new_sbid(bid
, l
->prev
);
947 DBF_LH(4, "Current list is:\n");
948 list_for_each(l
, sbid_list
) {
949 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
950 DBF_LH(4, "%d:%03d@%05d\n",
959 * Delete all entries from the search block ID list that belong to tape blocks
960 * equal or higher than the given number.
963 tape_34xx_delete_sbid_from(struct tape_device
*device
, int from
)
965 struct list_head
* sbid_list
;
966 struct tape_34xx_sbid
* sbid
;
967 struct list_head
* l
;
968 struct list_head
* n
;
970 sbid_list
= (struct list_head
*) device
->discdata
;
974 list_for_each_safe(l
, n
, sbid_list
) {
975 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
976 if (sbid
->bid
.block
>= from
) {
977 DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
989 * Merge hardware position data into a block id.
992 tape_34xx_merge_sbid(
993 struct tape_device
* device
,
994 struct tape_34xx_block_id
* bid
996 struct tape_34xx_sbid
* sbid
;
997 struct tape_34xx_sbid
* sbid_to_use
;
998 struct list_head
* sbid_list
;
999 struct list_head
* l
;
1001 sbid_list
= (struct list_head
*) device
->discdata
;
1005 if (!sbid_list
|| list_empty(sbid_list
))
1009 list_for_each(l
, sbid_list
) {
1010 sbid
= list_entry(l
, struct tape_34xx_sbid
, list
);
1012 if (sbid
->bid
.block
>= bid
->block
)
1017 bid
->wrap
= sbid_to_use
->bid
.wrap
;
1018 bid
->segment
= sbid_to_use
->bid
.segment
;
1019 DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
1020 sbid_to_use
->bid
.wrap
,
1021 sbid_to_use
->bid
.segment
,
1022 sbid_to_use
->bid
.block
,
1029 tape_34xx_setup_device(struct tape_device
* device
)
1032 struct list_head
* discdata
;
1034 DBF_EVENT(6, "34xx device setup\n");
1035 if ((rc
= tape_std_assign(device
)) == 0) {
1036 if ((rc
= tape_34xx_medium_sense(device
)) != 0) {
1037 DBF_LH(3, "34xx medium sense returned %d\n", rc
);
1040 discdata
= kmalloc(sizeof(struct list_head
), GFP_KERNEL
);
1042 INIT_LIST_HEAD(discdata
);
1043 device
->discdata
= discdata
;
1050 tape_34xx_cleanup_device(struct tape_device
*device
)
1052 tape_std_unassign(device
);
1054 if (device
->discdata
) {
1055 tape_34xx_delete_sbid_from(device
, 0);
1056 kfree(device
->discdata
);
1057 device
->discdata
= NULL
;
1063 * MTTELL: Tell block. Return the number of block relative to current file.
1066 tape_34xx_mttell(struct tape_device
*device
, int mt_count
)
1069 struct tape_34xx_block_id cbid
;
1070 struct tape_34xx_block_id dbid
;
1071 } __attribute__ ((packed
)) block_id
;
1074 rc
= tape_std_read_block_id(device
, (__u64
*) &block_id
);
1078 tape_34xx_add_sbid(device
, block_id
.cbid
);
1079 return block_id
.cbid
.block
;
1083 * MTSEEK: seek to the specified block.
1086 tape_34xx_mtseek(struct tape_device
*device
, int mt_count
)
1088 struct tape_request
*request
;
1089 struct tape_34xx_block_id
* bid
;
1091 if (mt_count
> 0x3fffff) {
1092 DBF_EXCEPTION(6, "xsee parm\n");
1095 request
= tape_alloc_request(3, 4);
1096 if (IS_ERR(request
))
1097 return PTR_ERR(request
);
1100 request
->op
= TO_LBL
;
1101 bid
= (struct tape_34xx_block_id
*) request
->cpdata
;
1102 bid
->format
= (*device
->modeset_byte
& 0x08) ?
1103 TAPE34XX_FMT_3480_XF
: TAPE34XX_FMT_3480
;
1104 bid
->block
= mt_count
;
1105 tape_34xx_merge_sbid(device
, bid
);
1107 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
1108 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
1109 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
1112 return tape_do_io_free(device
, request
);
1116 * List of 3480/3490 magnetic tape commands.
1118 static tape_mtop_fn tape_34xx_mtop
[TAPE_NR_MTOPS
] = {
1119 [MTRESET
] = tape_std_mtreset
,
1120 [MTFSF
] = tape_std_mtfsf
,
1121 [MTBSF
] = tape_std_mtbsf
,
1122 [MTFSR
] = tape_std_mtfsr
,
1123 [MTBSR
] = tape_std_mtbsr
,
1124 [MTWEOF
] = tape_std_mtweof
,
1125 [MTREW
] = tape_std_mtrew
,
1126 [MTOFFL
] = tape_std_mtoffl
,
1127 [MTNOP
] = tape_std_mtnop
,
1128 [MTRETEN
] = tape_std_mtreten
,
1129 [MTBSFM
] = tape_std_mtbsfm
,
1130 [MTFSFM
] = tape_std_mtfsfm
,
1131 [MTEOM
] = tape_std_mteom
,
1132 [MTERASE
] = tape_std_mterase
,
1136 [MTSETBLK
] = tape_std_mtsetblk
,
1137 [MTSETDENSITY
] = NULL
,
1138 [MTSEEK
] = tape_34xx_mtseek
,
1139 [MTTELL
] = tape_34xx_mttell
,
1140 [MTSETDRVBUFFER
] = NULL
,
1146 [MTLOAD
] = tape_std_mtload
,
1147 [MTUNLOAD
] = tape_std_mtunload
,
1148 [MTCOMPRESSION
] = tape_std_mtcompression
,
1154 * Tape discipline structure for 3480 and 3490.
1156 static struct tape_discipline tape_discipline_34xx
= {
1157 .owner
= THIS_MODULE
,
1158 .setup_device
= tape_34xx_setup_device
,
1159 .cleanup_device
= tape_34xx_cleanup_device
,
1160 .process_eov
= tape_std_process_eov
,
1161 .irq
= tape_34xx_irq
,
1162 .read_block
= tape_std_read_block
,
1163 .write_block
= tape_std_write_block
,
1164 .ioctl_fn
= tape_34xx_ioctl
,
1165 .mtop_array
= tape_34xx_mtop
1168 static struct ccw_device_id tape_34xx_ids
[] = {
1169 { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), .driver_info
= tape_3480
},
1170 { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), .driver_info
= tape_3490
},
1171 { /* end of list */ },
1175 tape_34xx_online(struct ccw_device
*cdev
)
1177 return tape_generic_online(
1178 dev_get_drvdata(&cdev
->dev
),
1179 &tape_discipline_34xx
1183 static struct ccw_driver tape_34xx_driver
= {
1185 .name
= "tape_34xx",
1186 .owner
= THIS_MODULE
,
1188 .ids
= tape_34xx_ids
,
1189 .probe
= tape_generic_probe
,
1190 .remove
= tape_generic_remove
,
1191 .set_online
= tape_34xx_online
,
1192 .set_offline
= tape_generic_offline
,
1193 .freeze
= tape_generic_pm_suspend
,
1194 .int_class
= IRQIO_TAP
,
1198 tape_34xx_init (void)
1202 TAPE_DBF_AREA
= debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
1203 debug_register_view(TAPE_DBF_AREA
, &debug_sprintf_view
);
1204 #ifdef DBF_LIKE_HELL
1205 debug_set_level(TAPE_DBF_AREA
, 6);
1208 DBF_EVENT(3, "34xx init\n");
1209 /* Register driver for 3480/3490 tapes. */
1210 rc
= ccw_driver_register(&tape_34xx_driver
);
1212 DBF_EVENT(3, "34xx init failed\n");
1214 DBF_EVENT(3, "34xx registered\n");
1219 tape_34xx_exit(void)
1221 ccw_driver_unregister(&tape_34xx_driver
);
1223 debug_unregister(TAPE_DBF_AREA
);
1226 MODULE_DEVICE_TABLE(ccw
, tape_34xx_ids
);
1227 MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
1228 MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape device driver");
1229 MODULE_LICENSE("GPL");
1231 module_init(tape_34xx_init
);
1232 module_exit(tape_34xx_exit
);