2 * drivers/s390/char/tape_3590.c
3 * tape device discipline for 3590 tapes.
5 * Copyright IBM Corp. 2001,2006
6 * Author(s): Stefan Bader <shbader@de.ibm.com>
7 * Michael Holzheu <holzheu@de.ibm.com>
8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/bio.h>
14 #include <asm/ebcdic.h>
16 #define TAPE_DBF_AREA tape_3590_dbf
20 #include "tape_3590.h"
23 * Pointer to debug area.
25 debug_info_t
*TAPE_DBF_AREA
= NULL
;
26 EXPORT_SYMBOL(TAPE_DBF_AREA
);
28 /*******************************************************************
29 * Error Recovery fuctions:
30 * - Read Opposite: implemented
31 * - Read Device (buffered) log: BRA
32 * - Read Library log: BRA
34 * - Long Busy: implemented
35 * - Special Intercept: BRA
36 * - Read Alternate: implemented
37 *******************************************************************/
39 #define PRINTK_HEADER "TAPE_3590: "
41 static const char *tape_3590_msg
[TAPE_3590_MAX_MSG
] = {
43 [0x10] = "Lost Sense",
44 [0x11] = "Assigned Elsewhere",
45 [0x12] = "Allegiance Reset",
46 [0x13] = "Shared Access Violation",
47 [0x20] = "Command Reject",
48 [0x21] = "Configuration Error",
49 [0x22] = "Protection Exception",
50 [0x23] = "Write Protect",
51 [0x24] = "Write Length",
52 [0x25] = "Read-Only Format",
53 [0x31] = "Beginning of Partition",
54 [0x33] = "End of Partition",
55 [0x34] = "End of Data",
56 [0x35] = "Block not found",
57 [0x40] = "Device Intervention",
58 [0x41] = "Loader Intervention",
59 [0x42] = "Library Intervention",
60 [0x50] = "Write Error",
61 [0x51] = "Erase Error",
62 [0x52] = "Formatting Error",
63 [0x53] = "Read Error",
64 [0x54] = "Unsupported Format",
65 [0x55] = "No Formatting",
66 [0x56] = "Positioning lost",
67 [0x57] = "Read Length",
68 [0x60] = "Unsupported Medium",
69 [0x61] = "Medium Length Error",
70 [0x62] = "Medium removed",
71 [0x64] = "Load Check",
72 [0x65] = "Unload Check",
73 [0x70] = "Equipment Check",
74 [0x71] = "Bus out Check",
75 [0x72] = "Protocol Error",
76 [0x73] = "Interface Error",
78 [0x75] = "Halt Signal",
79 [0x90] = "Device fenced",
80 [0x91] = "Device Path fenced",
81 [0xa0] = "Volume misplaced",
82 [0xa1] = "Volume inaccessible",
83 [0xa2] = "Volume in input",
84 [0xa3] = "Volume ejected",
85 [0xa4] = "All categories reserved",
86 [0xa5] = "Duplicate Volume",
87 [0xa6] = "Library Manager Offline",
88 [0xa7] = "Library Output Station full",
89 [0xa8] = "Vision System non-operational",
90 [0xa9] = "Library Manager Equipment Check",
91 [0xaa] = "Library Equipment Check",
92 [0xab] = "All Library Cells full",
93 [0xac] = "No Cleaner Volumes in Library",
94 [0xad] = "I/O Station door open",
95 [0xae] = "Subsystem environmental alert",
98 static int crypt_supported(struct tape_device
*device
)
100 return TAPE390_CRYPT_SUPPORTED(TAPE_3590_CRYPT_INFO(device
));
103 static int crypt_enabled(struct tape_device
*device
)
105 return TAPE390_CRYPT_ON(TAPE_3590_CRYPT_INFO(device
));
108 static void ext_to_int_kekl(struct tape390_kekl
*in
,
109 struct tape3592_kekl
*out
)
113 memset(out
, 0, sizeof(*out
));
114 if (in
->type
== TAPE390_KEKL_TYPE_HASH
)
116 if (in
->type_on_tape
== TAPE390_KEKL_TYPE_HASH
)
118 strncpy(out
->label
, in
->label
, 64);
119 for (i
= strlen(in
->label
); i
< sizeof(out
->label
); i
++)
121 ASCEBC(out
->label
, sizeof(out
->label
));
124 static void int_to_ext_kekl(struct tape3592_kekl
*in
,
125 struct tape390_kekl
*out
)
127 memset(out
, 0, sizeof(*out
));
129 out
->type
= TAPE390_KEKL_TYPE_HASH
;
131 out
->type
= TAPE390_KEKL_TYPE_LABEL
;
133 out
->type_on_tape
= TAPE390_KEKL_TYPE_HASH
;
135 out
->type_on_tape
= TAPE390_KEKL_TYPE_LABEL
;
136 memcpy(out
->label
, in
->label
, sizeof(in
->label
));
137 EBCASC(out
->label
, sizeof(in
->label
));
138 strstrip(out
->label
);
141 static void int_to_ext_kekl_pair(struct tape3592_kekl_pair
*in
,
142 struct tape390_kekl_pair
*out
)
144 if (in
->count
== 0) {
145 out
->kekl
[0].type
= TAPE390_KEKL_TYPE_NONE
;
146 out
->kekl
[0].type_on_tape
= TAPE390_KEKL_TYPE_NONE
;
147 out
->kekl
[1].type
= TAPE390_KEKL_TYPE_NONE
;
148 out
->kekl
[1].type_on_tape
= TAPE390_KEKL_TYPE_NONE
;
149 } else if (in
->count
== 1) {
150 int_to_ext_kekl(&in
->kekl
[0], &out
->kekl
[0]);
151 out
->kekl
[1].type
= TAPE390_KEKL_TYPE_NONE
;
152 out
->kekl
[1].type_on_tape
= TAPE390_KEKL_TYPE_NONE
;
153 } else if (in
->count
== 2) {
154 int_to_ext_kekl(&in
->kekl
[0], &out
->kekl
[0]);
155 int_to_ext_kekl(&in
->kekl
[1], &out
->kekl
[1]);
157 printk("Invalid KEKL number: %d\n", in
->count
);
162 static int check_ext_kekl(struct tape390_kekl
*kekl
)
164 if (kekl
->type
== TAPE390_KEKL_TYPE_NONE
)
166 if (kekl
->type
> TAPE390_KEKL_TYPE_HASH
)
168 if (kekl
->type_on_tape
== TAPE390_KEKL_TYPE_NONE
)
170 if (kekl
->type_on_tape
> TAPE390_KEKL_TYPE_HASH
)
172 if ((kekl
->type
== TAPE390_KEKL_TYPE_HASH
) &&
173 (kekl
->type_on_tape
== TAPE390_KEKL_TYPE_LABEL
))
181 static int check_ext_kekl_pair(struct tape390_kekl_pair
*kekls
)
183 if (check_ext_kekl(&kekls
->kekl
[0]))
185 if (check_ext_kekl(&kekls
->kekl
[1]))
196 static int tape_3592_kekl_query(struct tape_device
*device
,
197 struct tape390_kekl_pair
*ext_kekls
)
199 struct tape_request
*request
;
200 struct tape3592_kekl_query_order
*order
;
201 struct tape3592_kekl_query_data
*int_kekls
;
204 DBF_EVENT(6, "tape3592_kekl_query\n");
205 int_kekls
= kmalloc(sizeof(*int_kekls
), GFP_KERNEL
|GFP_DMA
);
208 request
= tape_alloc_request(2, sizeof(*order
));
209 if (IS_ERR(request
)) {
210 rc
= PTR_ERR(request
);
213 order
= request
->cpdata
;
214 memset(order
,0,sizeof(*order
));
216 order
->max_count
= 2;
217 request
->op
= TO_KEKL_QUERY
;
218 tape_ccw_cc(request
->cpaddr
, PERF_SUBSYS_FUNC
, sizeof(*order
), order
);
219 tape_ccw_end(request
->cpaddr
+ 1, READ_SS_DATA
, sizeof(*int_kekls
),
221 rc
= tape_do_io(device
, request
);
224 int_to_ext_kekl_pair(&int_kekls
->kekls
, ext_kekls
);
228 tape_free_request(request
);
237 static int tape_3592_ioctl_kekl_query(struct tape_device
*device
,
241 struct tape390_kekl_pair
*ext_kekls
;
243 DBF_EVENT(6, "tape_3592_ioctl_kekl_query\n");
244 if (!crypt_supported(device
))
246 if (!crypt_enabled(device
))
248 ext_kekls
= kmalloc(sizeof(*ext_kekls
), GFP_KERNEL
);
251 rc
= tape_3592_kekl_query(device
, ext_kekls
);
254 if (copy_to_user((char __user
*) arg
, ext_kekls
, sizeof(*ext_kekls
))) {
264 static int tape_3590_mttell(struct tape_device
*device
, int mt_count
);
269 static int tape_3592_kekl_set(struct tape_device
*device
,
270 struct tape390_kekl_pair
*ext_kekls
)
272 struct tape_request
*request
;
273 struct tape3592_kekl_set_order
*order
;
275 DBF_EVENT(6, "tape3592_kekl_set\n");
276 if (check_ext_kekl_pair(ext_kekls
)) {
277 DBF_EVENT(6, "invalid kekls\n");
280 if (tape_3590_mttell(device
, 0) != 0)
282 request
= tape_alloc_request(1, sizeof(*order
));
284 return PTR_ERR(request
);
285 order
= request
->cpdata
;
286 memset(order
, 0, sizeof(*order
));
288 order
->kekls
.count
= 2;
289 ext_to_int_kekl(&ext_kekls
->kekl
[0], &order
->kekls
.kekl
[0]);
290 ext_to_int_kekl(&ext_kekls
->kekl
[1], &order
->kekls
.kekl
[1]);
291 request
->op
= TO_KEKL_SET
;
292 tape_ccw_end(request
->cpaddr
, PERF_SUBSYS_FUNC
, sizeof(*order
), order
);
294 return tape_do_io_free(device
, request
);
300 static int tape_3592_ioctl_kekl_set(struct tape_device
*device
,
304 struct tape390_kekl_pair
*ext_kekls
;
306 DBF_EVENT(6, "tape_3592_ioctl_kekl_set\n");
307 if (!crypt_supported(device
))
309 if (!crypt_enabled(device
))
311 ext_kekls
= kmalloc(sizeof(*ext_kekls
), GFP_KERNEL
);
314 if (copy_from_user(ext_kekls
, (char __user
*)arg
, sizeof(*ext_kekls
))) {
318 rc
= tape_3592_kekl_set(device
, ext_kekls
);
327 static int tape_3592_enable_crypt(struct tape_device
*device
)
329 struct tape_request
*request
;
332 DBF_EVENT(6, "tape_3592_enable_crypt\n");
333 if (!crypt_supported(device
))
335 request
= tape_alloc_request(2, 72);
337 return PTR_ERR(request
);
338 data
= request
->cpdata
;
346 data
[36 + 14] = 0x2f;
347 data
[36 + 18] = 0xc3;
348 data
[36 + 35] = 0x72;
349 request
->op
= TO_CRYPT_ON
;
350 tape_ccw_cc(request
->cpaddr
, MODE_SET_CB
, 36, data
);
351 tape_ccw_end(request
->cpaddr
+ 1, MODE_SET_CB
, 36, data
+ 36);
352 return tape_do_io_free(device
, request
);
358 static int tape_3592_disable_crypt(struct tape_device
*device
)
360 struct tape_request
*request
;
363 DBF_EVENT(6, "tape_3592_disable_crypt\n");
364 if (!crypt_supported(device
))
366 request
= tape_alloc_request(2, 72);
368 return PTR_ERR(request
);
369 data
= request
->cpdata
;
375 data
[36 + 35] = 0x32;
377 request
->op
= TO_CRYPT_OFF
;
378 tape_ccw_cc(request
->cpaddr
, MODE_SET_CB
, 36, data
);
379 tape_ccw_end(request
->cpaddr
+ 1, MODE_SET_CB
, 36, data
+ 36);
381 return tape_do_io_free(device
, request
);
385 * IOCTL: Set encryption status
387 static int tape_3592_ioctl_crypt_set(struct tape_device
*device
,
390 struct tape390_crypt_info info
;
392 DBF_EVENT(6, "tape_3592_ioctl_crypt_set\n");
393 if (!crypt_supported(device
))
395 if (copy_from_user(&info
, (char __user
*)arg
, sizeof(info
)))
397 if (info
.status
& ~TAPE390_CRYPT_ON_MASK
)
399 if (info
.status
& TAPE390_CRYPT_ON_MASK
)
400 return tape_3592_enable_crypt(device
);
402 return tape_3592_disable_crypt(device
);
405 static int tape_3590_sense_medium(struct tape_device
*device
);
408 * IOCTL: Query enryption status
410 static int tape_3592_ioctl_crypt_query(struct tape_device
*device
,
413 DBF_EVENT(6, "tape_3592_ioctl_crypt_query\n");
414 if (!crypt_supported(device
))
416 tape_3590_sense_medium(device
);
417 if (copy_to_user((char __user
*) arg
, &TAPE_3590_CRYPT_INFO(device
),
418 sizeof(TAPE_3590_CRYPT_INFO(device
))))
425 * 3590 IOCTL Overload
428 tape_3590_ioctl(struct tape_device
*device
, unsigned int cmd
, unsigned long arg
)
431 case TAPE390_DISPLAY
: {
432 struct display_struct disp
;
434 if (copy_from_user(&disp
, (char __user
*) arg
, sizeof(disp
)))
437 return tape_std_display(device
, &disp
);
439 case TAPE390_KEKL_SET
:
440 return tape_3592_ioctl_kekl_set(device
, arg
);
441 case TAPE390_KEKL_QUERY
:
442 return tape_3592_ioctl_kekl_query(device
, arg
);
443 case TAPE390_CRYPT_SET
:
444 return tape_3592_ioctl_crypt_set(device
, arg
);
445 case TAPE390_CRYPT_QUERY
:
446 return tape_3592_ioctl_crypt_query(device
, arg
);
448 return -EINVAL
; /* no additional ioctls */
453 * SENSE Medium: Get Sense data about medium state
456 tape_3590_sense_medium(struct tape_device
*device
)
458 struct tape_request
*request
;
460 request
= tape_alloc_request(1, 128);
462 return PTR_ERR(request
);
463 request
->op
= TO_MSEN
;
464 tape_ccw_end(request
->cpaddr
, MEDIUM_SENSE
, 128, request
->cpdata
);
465 return tape_do_io_free(device
, request
);
469 * MTTELL: Tell block. Return the number of block relative to current file.
472 tape_3590_mttell(struct tape_device
*device
, int mt_count
)
477 rc
= tape_std_read_block_id(device
, &block_id
);
480 return block_id
>> 32;
484 * MTSEEK: seek to the specified block.
487 tape_3590_mtseek(struct tape_device
*device
, int count
)
489 struct tape_request
*request
;
491 DBF_EVENT(6, "xsee id: %x\n", count
);
492 request
= tape_alloc_request(3, 4);
494 return PTR_ERR(request
);
495 request
->op
= TO_LBL
;
496 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
497 *(__u32
*) request
->cpdata
= count
;
498 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
499 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
500 return tape_do_io_free(device
, request
);
504 * Read Opposite Error Recovery Function:
505 * Used, when Read Forward does not work
508 tape_3590_read_opposite(struct tape_device
*device
,
509 struct tape_request
*request
)
511 struct tape_3590_disc_data
*data
;
514 * We have allocated 4 ccws in tape_std_read, so we can now
515 * transform the request to a read backward, followed by a
516 * forward space block.
518 request
->op
= TO_RBA
;
519 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
520 data
= device
->discdata
;
521 tape_ccw_cc_idal(request
->cpaddr
+ 1, data
->read_back_op
,
522 device
->char_data
.idal_buf
);
523 tape_ccw_cc(request
->cpaddr
+ 2, FORSPACEBLOCK
, 0, NULL
);
524 tape_ccw_end(request
->cpaddr
+ 3, NOP
, 0, NULL
);
525 DBF_EVENT(6, "xrop ccwg\n");
530 * This should be done after an interrupt with attention bit (0x80)
533 * After a "read attention message" request there are two possible
536 * 1. A unit check is presented, when attention sense is present (e.g. when
537 * a medium has been unloaded). The attention sense comes then
538 * together with the unit check. The recovery action is either "retry"
539 * (in case there is an attention message pending) or "permanent error".
541 * 2. The attention msg is written to the "read subsystem data" buffer.
542 * In this case we probably should print it to the console.
545 tape_3590_read_attmsg(struct tape_device
*device
)
547 struct tape_request
*request
;
550 request
= tape_alloc_request(3, 4096);
552 return PTR_ERR(request
);
553 request
->op
= TO_READ_ATTMSG
;
554 buf
= request
->cpdata
;
555 buf
[0] = PREP_RD_SS_DATA
;
556 buf
[6] = RD_ATTMSG
; /* read att msg */
557 tape_ccw_cc(request
->cpaddr
, PERFORM_SS_FUNC
, 12, buf
);
558 tape_ccw_cc(request
->cpaddr
+ 1, READ_SS_DATA
, 4096 - 12, buf
+ 12);
559 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
560 return tape_do_io_free(device
, request
);
564 * These functions are used to schedule follow-up actions from within an
565 * interrupt context (like unsolicited interrupts).
567 struct work_handler_data
{
568 struct tape_device
*device
;
570 struct work_struct work
;
574 tape_3590_work_handler(struct work_struct
*work
)
576 struct work_handler_data
*p
=
577 container_of(work
, struct work_handler_data
, work
);
581 tape_3590_sense_medium(p
->device
);
584 tape_3590_read_attmsg(p
->device
);
587 tape_3592_enable_crypt(p
->device
);
590 tape_3592_disable_crypt(p
->device
);
593 DBF_EVENT(3, "T3590: work handler undefined for "
594 "operation 0x%02x\n", p
->op
);
596 tape_put_device(p
->device
);
601 tape_3590_schedule_work(struct tape_device
*device
, enum tape_op op
)
603 struct work_handler_data
*p
;
605 if ((p
= kzalloc(sizeof(*p
), GFP_ATOMIC
)) == NULL
)
608 INIT_WORK(&p
->work
, tape_3590_work_handler
);
610 p
->device
= tape_get_device_reference(device
);
613 schedule_work(&p
->work
);
617 #ifdef CONFIG_S390_TAPE_BLOCK
621 static struct tape_request
*
622 tape_3590_bread(struct tape_device
*device
, struct request
*req
)
624 struct tape_request
*request
;
626 int count
= 0, start_block
;
630 struct req_iterator iter
;
632 DBF_EVENT(6, "xBREDid:");
633 start_block
= req
->sector
>> TAPEBLOCK_HSEC_S2B
;
634 DBF_EVENT(6, "start_block = %i\n", start_block
);
636 rq_for_each_segment(bv
, req
, iter
)
637 count
+= bv
->bv_len
>> (TAPEBLOCK_HSEC_S2B
+ 9);
639 request
= tape_alloc_request(2 + count
+ 1, 4);
642 request
->op
= TO_BLOCK
;
643 *(__u32
*) request
->cpdata
= start_block
;
644 ccw
= request
->cpaddr
;
645 ccw
= tape_ccw_cc(ccw
, MODE_SET_DB
, 1, device
->modeset_byte
);
648 * We always setup a nop after the mode set ccw. This slot is
649 * used in tape_std_check_locate to insert a locate ccw if the
650 * current tape position doesn't match the start block to be read.
652 ccw
= tape_ccw_cc(ccw
, NOP
, 0, NULL
);
654 rq_for_each_segment(bv
, req
, iter
) {
655 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
656 for (off
= 0; off
< bv
->bv_len
; off
+= TAPEBLOCK_HSEC_SIZE
) {
657 ccw
->flags
= CCW_FLAG_CC
;
658 ccw
->cmd_code
= READ_FORWARD
;
659 ccw
->count
= TAPEBLOCK_HSEC_SIZE
;
660 set_normalized_cda(ccw
, (void *) __pa(dst
));
662 dst
+= TAPEBLOCK_HSEC_SIZE
;
664 if (off
> bv
->bv_len
)
667 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
668 DBF_EVENT(6, "xBREDccwg\n");
673 tape_3590_free_bread(struct tape_request
*request
)
677 /* Last ccw is a nop and doesn't need clear_normalized_cda */
678 for (ccw
= request
->cpaddr
; ccw
->flags
& CCW_FLAG_CC
; ccw
++)
679 if (ccw
->cmd_code
== READ_FORWARD
)
680 clear_normalized_cda(ccw
);
681 tape_free_request(request
);
685 * check_locate is called just before the tape request is passed to
686 * the common io layer for execution. It has to check the current
687 * tape position and insert a locate ccw if it doesn't match the
688 * start block for the request.
691 tape_3590_check_locate(struct tape_device
*device
, struct tape_request
*request
)
695 start_block
= (__u32
*) request
->cpdata
;
696 if (*start_block
!= device
->blk_data
.block_position
) {
697 /* Add the start offset of the file to get the real block. */
698 *start_block
+= device
->bof
;
699 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
704 static void tape_3590_med_state_set(struct tape_device
*device
,
705 struct tape_3590_med_sense
*sense
)
707 struct tape390_crypt_info
*c_info
;
709 c_info
= &TAPE_3590_CRYPT_INFO(device
);
711 DBF_EVENT(6, "medium state: %x:%x\n", sense
->macst
, sense
->masst
);
712 switch (sense
->macst
) {
716 tape_med_state_set(device
, MS_UNLOADED
);
717 TAPE_3590_CRYPT_INFO(device
).medium_status
= 0;
721 tape_med_state_set(device
, MS_LOADED
);
724 tape_med_state_set(device
, MS_UNKNOWN
);
727 c_info
->medium_status
|= TAPE390_MEDIUM_LOADED_MASK
;
728 if (sense
->flags
& MSENSE_CRYPT_MASK
) {
729 PRINT_INFO("Medium is encrypted (%04x)\n", sense
->flags
);
730 c_info
->medium_status
|= TAPE390_MEDIUM_ENCRYPTED_MASK
;
732 DBF_EVENT(6, "Medium is not encrypted %04x\n", sense
->flags
);
733 c_info
->medium_status
&= ~TAPE390_MEDIUM_ENCRYPTED_MASK
;
738 * The done handler is called at device/channel end and wakes up the sleeping
742 tape_3590_done(struct tape_device
*device
, struct tape_request
*request
)
744 struct tape_3590_disc_data
*disc_data
;
746 DBF_EVENT(6, "%s done\n", tape_op_verbose
[request
->op
]);
747 disc_data
= device
->discdata
;
749 switch (request
->op
) {
763 tape_med_state_set(device
, MS_LOADED
);
766 tape_med_state_set(device
, MS_UNLOADED
);
767 tape_3590_schedule_work(device
, TO_CRYPT_OFF
);
770 tape_3590_med_state_set(device
, request
->cpdata
);
773 TAPE_3590_CRYPT_INFO(device
).status
774 |= TAPE390_CRYPT_ON_MASK
;
775 *(device
->modeset_byte
) |= 0x03;
778 TAPE_3590_CRYPT_INFO(device
).status
779 &= ~TAPE390_CRYPT_ON_MASK
;
780 *(device
->modeset_byte
) &= ~0x03;
782 case TO_RBI
: /* RBI seems to succeed even without medium loaded. */
783 case TO_NOP
: /* Same to NOP. */
795 return TAPE_IO_SUCCESS
;
799 * This fuction is called, when error recovery was successfull
802 tape_3590_erp_succeded(struct tape_device
*device
, struct tape_request
*request
)
804 DBF_EVENT(3, "Error Recovery successfull for %s\n",
805 tape_op_verbose
[request
->op
]);
806 return tape_3590_done(device
, request
);
810 * This fuction is called, when error recovery was not successfull
813 tape_3590_erp_failed(struct tape_device
*device
, struct tape_request
*request
,
814 struct irb
*irb
, int rc
)
816 DBF_EVENT(3, "Error Recovery failed for %s\n",
817 tape_op_verbose
[request
->op
]);
818 tape_dump_sense_dbf(device
, request
, irb
);
823 * Error Recovery do retry
826 tape_3590_erp_retry(struct tape_device
*device
, struct tape_request
*request
,
829 DBF_EVENT(2, "Retry: %s\n", tape_op_verbose
[request
->op
]);
830 tape_dump_sense_dbf(device
, request
, irb
);
831 return TAPE_IO_RETRY
;
835 * Handle unsolicited interrupts
838 tape_3590_unsolicited_irq(struct tape_device
*device
, struct irb
*irb
)
840 if (irb
->scsw
.dstat
== DEV_STAT_CHN_END
)
841 /* Probably result of halt ssch */
842 return TAPE_IO_PENDING
;
843 else if (irb
->scsw
.dstat
== 0x85)
845 DBF_EVENT(3, "unsol.irq! tape ready: %08x\n", device
->cdev_id
);
846 else if (irb
->scsw
.dstat
& DEV_STAT_ATTENTION
) {
847 tape_3590_schedule_work(device
, TO_READ_ATTMSG
);
849 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device
->cdev_id
);
850 PRINT_WARN("Unsolicited IRQ (Device End) caught.\n");
851 tape_dump_sense(device
, NULL
, irb
);
853 /* check medium state */
854 tape_3590_schedule_work(device
, TO_MSEN
);
855 return TAPE_IO_SUCCESS
;
859 * Basic Recovery routine
862 tape_3590_erp_basic(struct tape_device
*device
, struct tape_request
*request
,
863 struct irb
*irb
, int rc
)
865 struct tape_3590_sense
*sense
;
867 sense
= (struct tape_3590_sense
*) irb
->ecw
;
869 switch (sense
->bra
) {
871 return tape_3590_erp_failed(device
, request
, irb
, rc
);
873 return tape_3590_erp_succeded(device
, request
);
875 return tape_3590_erp_retry(device
, request
, irb
);
877 return tape_3590_erp_failed(device
, request
, irb
, rc
);
879 PRINT_ERR("Unknown BRA %x - This should not happen!\n",
887 * RDL: Read Device (buffered) log
890 tape_3590_erp_read_buf_log(struct tape_device
*device
,
891 struct tape_request
*request
, struct irb
*irb
)
894 * We just do the basic error recovery at the moment (retry).
895 * Perhaps in the future, we read the log and dump it somewhere...
897 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
904 tape_3590_erp_swap(struct tape_device
*device
, struct tape_request
*request
,
908 * This error recovery should swap the tapes
909 * if the original has a problem. The operation
910 * should proceed with the new tape... this
911 * should probably be done in user space!
913 PRINT_WARN("(%s): Swap Tape Device!\n", device
->cdev
->dev
.bus_id
);
914 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
921 tape_3590_erp_long_busy(struct tape_device
*device
,
922 struct tape_request
*request
, struct irb
*irb
)
924 DBF_EVENT(6, "Device is busy\n");
925 return TAPE_IO_LONG_BUSY
;
929 * SPI: Special Intercept
932 tape_3590_erp_special_interrupt(struct tape_device
*device
,
933 struct tape_request
*request
, struct irb
*irb
)
935 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
939 * RDA: Read Alternate
942 tape_3590_erp_read_alternate(struct tape_device
*device
,
943 struct tape_request
*request
, struct irb
*irb
)
945 struct tape_3590_disc_data
*data
;
948 * The issued Read Backward or Read Previous command is not
949 * supported by the device
950 * The recovery action should be to issue another command:
951 * Read Revious: if Read Backward is not supported
952 * Read Backward: if Read Previous is not supported
954 data
= device
->discdata
;
955 if (data
->read_back_op
== READ_PREVIOUS
) {
956 DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
958 data
->read_back_op
= READ_BACKWARD
;
960 DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
962 data
->read_back_op
= READ_PREVIOUS
;
964 tape_3590_read_opposite(device
, request
);
965 return tape_3590_erp_retry(device
, request
, irb
);
969 * Error Recovery read opposite
972 tape_3590_erp_read_opposite(struct tape_device
*device
,
973 struct tape_request
*request
, struct irb
*irb
)
975 switch (request
->op
) {
978 * We did read forward, but the data could not be read.
979 * We will read backward and then skip forward again.
981 tape_3590_read_opposite(device
, request
);
982 return tape_3590_erp_retry(device
, request
, irb
);
984 /* We tried to read forward and backward, but hat no success */
985 return tape_3590_erp_failed(device
, request
, irb
, -EIO
);
988 PRINT_WARN("read_opposite_recovery_called_with_op: %s\n",
989 tape_op_verbose
[request
->op
]);
990 return tape_3590_erp_failed(device
, request
, irb
, -EIO
);
995 * Print an MIM (Media Information Message) (message code f0)
998 tape_3590_print_mim_msg_f0(struct tape_device
*device
, struct irb
*irb
)
1000 struct tape_3590_sense
*sense
;
1002 sense
= (struct tape_3590_sense
*) irb
->ecw
;
1003 /* Exception Message */
1004 switch (sense
->fmt
.f70
.emc
) {
1006 PRINT_WARN("(%s): Data degraded\n", device
->cdev
->dev
.bus_id
);
1009 PRINT_WARN("(%s): Data degraded in partion %i\n",
1010 device
->cdev
->dev
.bus_id
, sense
->fmt
.f70
.mp
);
1013 PRINT_WARN("(%s): Medium degraded\n", device
->cdev
->dev
.bus_id
);
1016 PRINT_WARN("(%s): Medium degraded in partition %i\n",
1017 device
->cdev
->dev
.bus_id
, sense
->fmt
.f70
.mp
);
1020 PRINT_WARN("(%s): Block 0 Error\n", device
->cdev
->dev
.bus_id
);
1023 PRINT_WARN("(%s): Medium Exception 0x%02x\n",
1024 device
->cdev
->dev
.bus_id
, sense
->fmt
.f70
.md
);
1027 PRINT_WARN("(%s): MIM ExMsg: 0x%02x\n",
1028 device
->cdev
->dev
.bus_id
, sense
->fmt
.f70
.emc
);
1031 /* Service Message */
1032 switch (sense
->fmt
.f70
.smc
) {
1034 PRINT_WARN("(%s): Reference Media maintenance procedure %i\n",
1035 device
->cdev
->dev
.bus_id
, sense
->fmt
.f70
.md
);
1038 PRINT_WARN("(%s): MIM ServiceMsg: 0x%02x\n",
1039 device
->cdev
->dev
.bus_id
, sense
->fmt
.f70
.smc
);
1045 * Print an I/O Subsystem Service Information Message (message code f1)
1048 tape_3590_print_io_sim_msg_f1(struct tape_device
*device
, struct irb
*irb
)
1050 struct tape_3590_sense
*sense
;
1052 sense
= (struct tape_3590_sense
*) irb
->ecw
;
1053 /* Exception Message */
1054 switch (sense
->fmt
.f71
.emc
) {
1056 PRINT_WARN("(%s): Effect of failure is unknown\n",
1057 device
->cdev
->dev
.bus_id
);
1060 PRINT_WARN("(%s): CU Exception - no performance impact\n",
1061 device
->cdev
->dev
.bus_id
);
1064 PRINT_WARN("(%s): CU Exception on channel interface 0x%02x\n",
1065 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
1068 PRINT_WARN("(%s): CU Exception on device path 0x%02x\n",
1069 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
1072 PRINT_WARN("(%s): CU Exception on library path 0x%02x\n",
1073 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
1076 PRINT_WARN("(%s): CU Exception on node 0x%02x\n",
1077 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
1080 PRINT_WARN("(%s): CU Exception on partition 0x%02x\n",
1081 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
1084 PRINT_WARN("(%s): SIM ExMsg: 0x%02x\n",
1085 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.emc
);
1087 /* Service Message */
1088 switch (sense
->fmt
.f71
.smc
) {
1090 PRINT_WARN("(%s): Repair impact is unknown\n",
1091 device
->cdev
->dev
.bus_id
);
1094 PRINT_WARN("(%s): Repair will not impact cu performance\n",
1095 device
->cdev
->dev
.bus_id
);
1098 if (sense
->fmt
.f71
.mdf
== 0)
1099 PRINT_WARN("(%s): Repair will disable node "
1101 device
->cdev
->dev
.bus_id
,
1102 sense
->fmt
.f71
.md
[1]);
1104 PRINT_WARN("(%s): Repair will disable nodes "
1105 "(0x%x-0x%x) on CU\n",
1106 device
->cdev
->dev
.bus_id
,
1107 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1110 if (sense
->fmt
.f71
.mdf
== 0)
1111 PRINT_WARN("(%s): Repair will disable cannel path "
1113 device
->cdev
->dev
.bus_id
,
1114 sense
->fmt
.f71
.md
[1]);
1116 PRINT_WARN("(%s): Repair will disable cannel paths "
1117 "(0x%x-0x%x) on CU\n",
1118 device
->cdev
->dev
.bus_id
,
1119 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1122 if (sense
->fmt
.f71
.mdf
== 0)
1123 PRINT_WARN("(%s): Repair will disable device path "
1125 device
->cdev
->dev
.bus_id
,
1126 sense
->fmt
.f71
.md
[1]);
1128 PRINT_WARN("(%s): Repair will disable device paths "
1129 "(0x%x-0x%x) on CU\n",
1130 device
->cdev
->dev
.bus_id
,
1131 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1134 if (sense
->fmt
.f71
.mdf
== 0)
1135 PRINT_WARN("(%s): Repair will disable library path "
1137 device
->cdev
->dev
.bus_id
,
1138 sense
->fmt
.f71
.md
[1]);
1140 PRINT_WARN("(%s): Repair will disable library paths "
1141 "(0x%x-0x%x) on CU\n",
1142 device
->cdev
->dev
.bus_id
,
1143 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1146 PRINT_WARN("(%s): Repair will disable access to CU\n",
1147 device
->cdev
->dev
.bus_id
);
1150 PRINT_WARN("(%s): SIM ServiceMsg: 0x%02x\n",
1151 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.smc
);
1156 * Print an Device Subsystem Service Information Message (message code f2)
1159 tape_3590_print_dev_sim_msg_f2(struct tape_device
*device
, struct irb
*irb
)
1161 struct tape_3590_sense
*sense
;
1163 sense
= (struct tape_3590_sense
*) irb
->ecw
;
1164 /* Exception Message */
1165 switch (sense
->fmt
.f71
.emc
) {
1167 PRINT_WARN("(%s): Effect of failure is unknown\n",
1168 device
->cdev
->dev
.bus_id
);
1171 PRINT_WARN("(%s): DV Exception - no performance impact\n",
1172 device
->cdev
->dev
.bus_id
);
1175 PRINT_WARN("(%s): DV Exception on channel interface 0x%02x\n",
1176 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
1179 PRINT_WARN("(%s): DV Exception on loader 0x%02x\n",
1180 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
1183 PRINT_WARN("(%s): DV Exception on message display 0x%02x\n",
1184 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
1187 PRINT_WARN("(%s): DV Exception in tape path\n",
1188 device
->cdev
->dev
.bus_id
);
1191 PRINT_WARN("(%s): DV Exception in drive\n",
1192 device
->cdev
->dev
.bus_id
);
1195 PRINT_WARN("(%s): DSIM ExMsg: 0x%02x\n",
1196 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.emc
);
1198 /* Service Message */
1199 switch (sense
->fmt
.f71
.smc
) {
1201 PRINT_WARN("(%s): Repair impact is unknown\n",
1202 device
->cdev
->dev
.bus_id
);
1205 PRINT_WARN("(%s): Repair will not impact device performance\n",
1206 device
->cdev
->dev
.bus_id
);
1209 if (sense
->fmt
.f71
.mdf
== 0)
1210 PRINT_WARN("(%s): Repair will disable channel path "
1212 device
->cdev
->dev
.bus_id
,
1213 sense
->fmt
.f71
.md
[1]);
1215 PRINT_WARN("(%s): Repair will disable channel path "
1216 "(0x%x-0x%x) on DV\n",
1217 device
->cdev
->dev
.bus_id
,
1218 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1221 if (sense
->fmt
.f71
.mdf
== 0)
1222 PRINT_WARN("(%s): Repair will disable interface 0x%x "
1224 device
->cdev
->dev
.bus_id
,
1225 sense
->fmt
.f71
.md
[1]);
1227 PRINT_WARN("(%s): Repair will disable interfaces "
1228 "(0x%x-0x%x) on DV\n",
1229 device
->cdev
->dev
.bus_id
,
1230 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1233 if (sense
->fmt
.f71
.mdf
== 0)
1234 PRINT_WARN("(%s): Repair will disable loader 0x%x "
1236 device
->cdev
->dev
.bus_id
,
1237 sense
->fmt
.f71
.md
[1]);
1239 PRINT_WARN("(%s): Repair will disable loader "
1240 "(0x%x-0x%x) on DV\n",
1241 device
->cdev
->dev
.bus_id
,
1242 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1245 PRINT_WARN("(%s): Repair will disable access to DV\n",
1246 device
->cdev
->dev
.bus_id
);
1249 if (sense
->fmt
.f71
.mdf
== 0)
1250 PRINT_WARN("(%s): Repair will disable message "
1251 "display 0x%x on DV\n",
1252 device
->cdev
->dev
.bus_id
,
1253 sense
->fmt
.f71
.md
[1]);
1255 PRINT_WARN("(%s): Repair will disable message "
1256 "displays (0x%x-0x%x) on DV\n",
1257 device
->cdev
->dev
.bus_id
,
1258 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1261 PRINT_WARN("(%s): Clean DV\n", device
->cdev
->dev
.bus_id
);
1264 PRINT_WARN("(%s): DSIM ServiceMsg: 0x%02x\n",
1265 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.smc
);
1270 * Print standard ERA Message
1273 tape_3590_print_era_msg(struct tape_device
*device
, struct irb
*irb
)
1275 struct tape_3590_sense
*sense
;
1277 sense
= (struct tape_3590_sense
*) irb
->ecw
;
1280 if ((sense
->mc
> 0) && (sense
->mc
< TAPE_3590_MAX_MSG
)) {
1281 if (tape_3590_msg
[sense
->mc
] != NULL
)
1282 PRINT_WARN("(%s): %s\n", device
->cdev
->dev
.bus_id
,
1283 tape_3590_msg
[sense
->mc
]);
1285 PRINT_WARN("(%s): Message Code 0x%x\n",
1286 device
->cdev
->dev
.bus_id
, sense
->mc
);
1290 if (sense
->mc
== 0xf0) {
1291 /* Standard Media Information Message */
1292 PRINT_WARN("(%s): MIM SEV=%i, MC=%02x, ES=%x/%x, "
1293 "RC=%02x-%04x-%02x\n", device
->cdev
->dev
.bus_id
,
1294 sense
->fmt
.f70
.sev
, sense
->mc
,
1295 sense
->fmt
.f70
.emc
, sense
->fmt
.f70
.smc
,
1296 sense
->fmt
.f70
.refcode
, sense
->fmt
.f70
.mid
,
1297 sense
->fmt
.f70
.fid
);
1298 tape_3590_print_mim_msg_f0(device
, irb
);
1301 if (sense
->mc
== 0xf1) {
1302 /* Standard I/O Subsystem Service Information Message */
1303 PRINT_WARN("(%s): IOSIM SEV=%i, DEVTYPE=3590/%02x, "
1304 "MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1305 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.sev
,
1306 device
->cdev
->id
.dev_model
,
1307 sense
->mc
, sense
->fmt
.f71
.emc
,
1308 sense
->fmt
.f71
.smc
, sense
->fmt
.f71
.refcode1
,
1309 sense
->fmt
.f71
.refcode2
, sense
->fmt
.f71
.refcode3
);
1310 tape_3590_print_io_sim_msg_f1(device
, irb
);
1313 if (sense
->mc
== 0xf2) {
1314 /* Standard Device Service Information Message */
1315 PRINT_WARN("(%s): DEVSIM SEV=%i, DEVTYPE=3590/%02x, "
1316 "MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1317 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.sev
,
1318 device
->cdev
->id
.dev_model
,
1319 sense
->mc
, sense
->fmt
.f71
.emc
,
1320 sense
->fmt
.f71
.smc
, sense
->fmt
.f71
.refcode1
,
1321 sense
->fmt
.f71
.refcode2
, sense
->fmt
.f71
.refcode3
);
1322 tape_3590_print_dev_sim_msg_f2(device
, irb
);
1325 if (sense
->mc
== 0xf3) {
1326 /* Standard Library Service Information Message */
1329 PRINT_WARN("(%s): Device Message(%x)\n",
1330 device
->cdev
->dev
.bus_id
, sense
->mc
);
1333 static int tape_3590_crypt_error(struct tape_device
*device
,
1334 struct tape_request
*request
, struct irb
*irb
)
1339 char *bus_id
, *sense
;
1341 sense
= ((struct tape_3590_sense
*) irb
->ecw
)->fmt
.data
;
1342 bus_id
= device
->cdev
->dev
.bus_id
;
1344 drv_rc
= *((u32
*) &sense
[5]) & 0xffffff;
1346 ekm_rc2
= *((u16
*) &sense
[10]);
1347 if ((cu_rc
== 0) && (ekm_rc2
== 0xee31))
1348 /* key not defined on EKM */
1349 return tape_3590_erp_basic(device
, request
, irb
, -EKEYREJECTED
);
1350 if ((cu_rc
== 1) || (cu_rc
== 2))
1351 /* No connection to EKM */
1352 return tape_3590_erp_basic(device
, request
, irb
, -ENOTCONN
);
1354 PRINT_ERR("(%s): Unable to get encryption key from EKM\n", bus_id
);
1355 PRINT_ERR("(%s): CU=%02X DRIVE=%06X EKM=%02X:%04X\n", bus_id
, cu_rc
,
1356 drv_rc
, ekm_rc1
, ekm_rc2
);
1358 return tape_3590_erp_basic(device
, request
, irb
, -ENOKEY
);
1362 * 3590 error Recovery routine:
1363 * If possible, it tries to recover from the error. If this is not possible,
1364 * inform the user about the problem.
1367 tape_3590_unit_check(struct tape_device
*device
, struct tape_request
*request
,
1370 struct tape_3590_sense
*sense
;
1373 #ifdef CONFIG_S390_TAPE_BLOCK
1374 if (request
->op
== TO_BLOCK
) {
1376 * Recovery for block device requests. Set the block_position
1377 * to something invalid and retry.
1379 device
->blk_data
.block_position
= -1;
1380 if (request
->retries
-- <= 0)
1381 return tape_3590_erp_failed(device
, request
, irb
, -EIO
);
1383 return tape_3590_erp_retry(device
, request
, irb
);
1387 sense
= (struct tape_3590_sense
*) irb
->ecw
;
1389 DBF_EVENT(6, "Unit Check: RQC = %x\n", sense
->rc_rqc
);
1392 * First check all RC-QRCs where we want to do something special
1393 * - "break": basic error recovery is done
1394 * - "goto out:": just print error message if available
1397 switch (sense
->rc_rqc
) {
1400 tape_3590_print_era_msg(device
, irb
);
1401 return tape_3590_erp_read_buf_log(device
, request
, irb
);
1404 tape_3590_print_era_msg(device
, irb
);
1405 return tape_3590_erp_read_alternate(device
, request
, irb
);
1409 tape_3590_print_era_msg(device
, irb
);
1410 return tape_3590_erp_special_interrupt(device
, request
, irb
);
1412 return tape_3590_crypt_error(device
, request
, irb
);
1415 DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1417 return tape_3590_erp_basic(device
, request
, irb
, -ENOSPC
);
1419 DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1421 return tape_3590_erp_basic(device
, request
, irb
, -ENOSPC
);
1423 DBF_EVENT(2, "(%08x): End of Data Mark\n", device
->cdev_id
);
1424 return tape_3590_erp_basic(device
, request
, irb
, -ENOSPC
);
1427 DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1429 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
1431 DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1433 tape_med_state_set(device
, MS_UNLOADED
);
1434 tape_3590_schedule_work(device
, TO_CRYPT_OFF
);
1435 return tape_3590_erp_basic(device
, request
, irb
, 0);
1439 * print additional msg since default msg
1440 * "device intervention" is not very meaningfull
1442 PRINT_WARN("(%s): Tape operation when medium not loaded\n",
1443 device
->cdev
->dev
.bus_id
);
1444 tape_med_state_set(device
, MS_UNLOADED
);
1445 tape_3590_schedule_work(device
, TO_CRYPT_OFF
);
1446 return tape_3590_erp_basic(device
, request
, irb
, -ENOMEDIUM
);
1447 case 0x4012: /* Device Long Busy */
1448 /* XXX: Also use long busy handling here? */
1449 DBF_EVENT(6, "(%08x): LONG BUSY\n", device
->cdev_id
);
1450 tape_3590_print_era_msg(device
, irb
);
1451 return tape_3590_erp_basic(device
, request
, irb
, -EBUSY
);
1453 DBF_EVENT(6, "(%08x): Crypto LONG BUSY\n", device
->cdev_id
);
1454 return tape_3590_erp_long_busy(device
, request
, irb
);
1457 if (sense
->rac
== 0xd0) {
1459 tape_3590_print_era_msg(device
, irb
);
1460 return tape_3590_erp_swap(device
, request
, irb
);
1462 if (sense
->rac
== 0x26) {
1464 tape_3590_print_era_msg(device
, irb
);
1465 return tape_3590_erp_read_opposite(device
, request
,
1468 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
1475 tape_3590_print_era_msg(device
, irb
);
1476 return tape_3590_erp_swap(device
, request
, irb
);
1480 return tape_3590_erp_basic(device
, request
, irb
, -EMEDIUMTYPE
);
1484 tape_med_state_set(device
, MS_UNLOADED
);
1485 tape_3590_schedule_work(device
, TO_CRYPT_OFF
);
1486 return tape_3590_erp_basic(device
, request
, irb
, -ENOMEDIUM
);
1489 PRINT_WARN("(%s): Cartridge of wrong type ?\n",
1490 device
->cdev
->dev
.bus_id
);
1491 return tape_3590_erp_basic(device
, request
, irb
, -EMEDIUMTYPE
);
1494 PRINT_WARN("(%s): Another host has reserved the tape device\n",
1495 device
->cdev
->dev
.bus_id
);
1496 return tape_3590_erp_basic(device
, request
, irb
, -EPERM
);
1498 PRINT_WARN("(%s): Another host has priviliged access to the "
1499 "tape device\n", device
->cdev
->dev
.bus_id
);
1500 PRINT_WARN("(%s): To solve the problem unload the current "
1501 "cartridge!\n", device
->cdev
->dev
.bus_id
);
1502 return tape_3590_erp_basic(device
, request
, irb
, -EPERM
);
1504 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
1509 * 3590 interrupt handler:
1512 tape_3590_irq(struct tape_device
*device
, struct tape_request
*request
,
1515 if (request
== NULL
)
1516 return tape_3590_unsolicited_irq(device
, irb
);
1518 if ((irb
->scsw
.dstat
& DEV_STAT_UNIT_EXCEP
) &&
1519 (irb
->scsw
.dstat
& DEV_STAT_DEV_END
) && (request
->op
== TO_WRI
)) {
1520 /* Write at end of volume */
1521 DBF_EVENT(2, "End of volume\n");
1522 return tape_3590_erp_failed(device
, request
, irb
, -ENOSPC
);
1525 if (irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
)
1526 return tape_3590_unit_check(device
, request
, irb
);
1528 if (irb
->scsw
.dstat
& DEV_STAT_DEV_END
) {
1529 if (irb
->scsw
.dstat
== DEV_STAT_UNIT_EXCEP
) {
1530 if (request
->op
== TO_FSB
|| request
->op
== TO_BSB
)
1533 DBF_EVENT(5, "Unit Exception!\n");
1536 return tape_3590_done(device
, request
);
1539 if (irb
->scsw
.dstat
& DEV_STAT_CHN_END
) {
1540 DBF_EVENT(2, "cannel end\n");
1541 return TAPE_IO_PENDING
;
1544 if (irb
->scsw
.dstat
& DEV_STAT_ATTENTION
) {
1545 DBF_EVENT(2, "Unit Attention when busy..\n");
1546 return TAPE_IO_PENDING
;
1549 DBF_EVENT(6, "xunknownirq\n");
1550 PRINT_ERR("Unexpected interrupt.\n");
1551 PRINT_ERR("Current op is: %s", tape_op_verbose
[request
->op
]);
1552 tape_dump_sense(device
, request
, irb
);
1553 return TAPE_IO_STOP
;
1557 static int tape_3590_read_dev_chars(struct tape_device
*device
,
1558 struct tape_3590_rdc_data
*rdc_data
)
1561 struct tape_request
*request
;
1563 request
= tape_alloc_request(1, sizeof(*rdc_data
));
1564 if (IS_ERR(request
))
1565 return PTR_ERR(request
);
1566 request
->op
= TO_RDC
;
1567 tape_ccw_end(request
->cpaddr
, CCW_CMD_RDC
, sizeof(*rdc_data
),
1569 rc
= tape_do_io(device
, request
);
1571 memcpy(rdc_data
, request
->cpdata
, sizeof(*rdc_data
));
1572 tape_free_request(request
);
1577 * Setup device function
1580 tape_3590_setup_device(struct tape_device
*device
)
1583 struct tape_3590_disc_data
*data
;
1584 struct tape_3590_rdc_data
*rdc_data
;
1586 DBF_EVENT(6, "3590 device setup\n");
1587 data
= kzalloc(sizeof(struct tape_3590_disc_data
), GFP_KERNEL
| GFP_DMA
);
1590 data
->read_back_op
= READ_PREVIOUS
;
1591 device
->discdata
= data
;
1593 rdc_data
= kmalloc(sizeof(*rdc_data
), GFP_KERNEL
| GFP_DMA
);
1598 rc
= tape_3590_read_dev_chars(device
, rdc_data
);
1600 DBF_LH(3, "Read device characteristics failed!\n");
1603 rc
= tape_std_assign(device
);
1606 if (rdc_data
->data
[31] == 0x13) {
1607 PRINT_INFO("Device has crypto support\n");
1608 data
->crypt_info
.capability
|= TAPE390_CRYPT_SUPPORTED_MASK
;
1609 tape_3592_disable_crypt(device
);
1611 DBF_EVENT(6, "Device has NO crypto support\n");
1613 /* Try to find out if medium is loaded */
1614 rc
= tape_3590_sense_medium(device
);
1616 DBF_LH(3, "3590 medium sense returned %d\n", rc
);
1629 * Cleanup device function
1632 tape_3590_cleanup_device(struct tape_device
*device
)
1634 flush_scheduled_work();
1635 tape_std_unassign(device
);
1637 kfree(device
->discdata
);
1638 device
->discdata
= NULL
;
1642 * List of 3590 magnetic tape commands.
1644 static tape_mtop_fn tape_3590_mtop
[TAPE_NR_MTOPS
] = {
1645 [MTRESET
] = tape_std_mtreset
,
1646 [MTFSF
] = tape_std_mtfsf
,
1647 [MTBSF
] = tape_std_mtbsf
,
1648 [MTFSR
] = tape_std_mtfsr
,
1649 [MTBSR
] = tape_std_mtbsr
,
1650 [MTWEOF
] = tape_std_mtweof
,
1651 [MTREW
] = tape_std_mtrew
,
1652 [MTOFFL
] = tape_std_mtoffl
,
1653 [MTNOP
] = tape_std_mtnop
,
1654 [MTRETEN
] = tape_std_mtreten
,
1655 [MTBSFM
] = tape_std_mtbsfm
,
1656 [MTFSFM
] = tape_std_mtfsfm
,
1657 [MTEOM
] = tape_std_mteom
,
1658 [MTERASE
] = tape_std_mterase
,
1662 [MTSETBLK
] = tape_std_mtsetblk
,
1663 [MTSETDENSITY
] = NULL
,
1664 [MTSEEK
] = tape_3590_mtseek
,
1665 [MTTELL
] = tape_3590_mttell
,
1666 [MTSETDRVBUFFER
] = NULL
,
1672 [MTLOAD
] = tape_std_mtload
,
1673 [MTUNLOAD
] = tape_std_mtunload
,
1674 [MTCOMPRESSION
] = tape_std_mtcompression
,
1680 * Tape discipline structure for 3590.
1682 static struct tape_discipline tape_discipline_3590
= {
1683 .owner
= THIS_MODULE
,
1684 .setup_device
= tape_3590_setup_device
,
1685 .cleanup_device
= tape_3590_cleanup_device
,
1686 .process_eov
= tape_std_process_eov
,
1687 .irq
= tape_3590_irq
,
1688 .read_block
= tape_std_read_block
,
1689 .write_block
= tape_std_write_block
,
1690 #ifdef CONFIG_S390_TAPE_BLOCK
1691 .bread
= tape_3590_bread
,
1692 .free_bread
= tape_3590_free_bread
,
1693 .check_locate
= tape_3590_check_locate
,
1695 .ioctl_fn
= tape_3590_ioctl
,
1696 .mtop_array
= tape_3590_mtop
1699 static struct ccw_device_id tape_3590_ids
[] = {
1700 {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info
= tape_3590
},
1701 {CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info
= tape_3592
},
1702 { /* end of list */ }
1706 tape_3590_online(struct ccw_device
*cdev
)
1708 return tape_generic_online(cdev
->dev
.driver_data
,
1709 &tape_discipline_3590
);
1713 tape_3590_offline(struct ccw_device
*cdev
)
1715 return tape_generic_offline(cdev
->dev
.driver_data
);
1718 static struct ccw_driver tape_3590_driver
= {
1719 .name
= "tape_3590",
1720 .owner
= THIS_MODULE
,
1721 .ids
= tape_3590_ids
,
1722 .probe
= tape_generic_probe
,
1723 .remove
= tape_generic_remove
,
1724 .set_offline
= tape_3590_offline
,
1725 .set_online
= tape_3590_online
,
1729 * Setup discipline structure.
1732 tape_3590_init(void)
1736 TAPE_DBF_AREA
= debug_register("tape_3590", 2, 2, 4 * sizeof(long));
1737 debug_register_view(TAPE_DBF_AREA
, &debug_sprintf_view
);
1738 #ifdef DBF_LIKE_HELL
1739 debug_set_level(TAPE_DBF_AREA
, 6);
1742 DBF_EVENT(3, "3590 init\n");
1743 /* Register driver for 3590 tapes. */
1744 rc
= ccw_driver_register(&tape_3590_driver
);
1746 DBF_EVENT(3, "3590 init failed\n");
1748 DBF_EVENT(3, "3590 registered\n");
1753 tape_3590_exit(void)
1755 ccw_driver_unregister(&tape_3590_driver
);
1757 debug_unregister(TAPE_DBF_AREA
);
1760 MODULE_DEVICE_TABLE(ccw
, tape_3590_ids
);
1761 MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
1762 MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
1763 MODULE_LICENSE("GPL");
1765 module_init(tape_3590_init
);
1766 module_exit(tape_3590_exit
);