2 * drivers/s390/char/tape_3590.c
3 * tape device discipline for 3590 tapes.
5 * Copyright IBM Corp. 2001, 2009
6 * Author(s): Stefan Bader <shbader@de.ibm.com>
7 * Michael Holzheu <holzheu@de.ibm.com>
8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
11 #define KMSG_COMPONENT "tape_3590"
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 <asm/ebcdic.h>
19 #define TAPE_DBF_AREA tape_3590_dbf
20 #define BUFSIZE 512 /* size of buffers for dynamic generated messages */
24 #include "tape_3590.h"
27 * Pointer to debug area.
29 debug_info_t
*TAPE_DBF_AREA
= NULL
;
30 EXPORT_SYMBOL(TAPE_DBF_AREA
);
32 /*******************************************************************
33 * Error Recovery fuctions:
34 * - Read Opposite: implemented
35 * - Read Device (buffered) log: BRA
36 * - Read Library log: BRA
38 * - Long Busy: implemented
39 * - Special Intercept: BRA
40 * - Read Alternate: implemented
41 *******************************************************************/
43 static const char *tape_3590_msg
[TAPE_3590_MAX_MSG
] = {
45 [0x10] = "Lost Sense",
46 [0x11] = "Assigned Elsewhere",
47 [0x12] = "Allegiance Reset",
48 [0x13] = "Shared Access Violation",
49 [0x20] = "Command Reject",
50 [0x21] = "Configuration Error",
51 [0x22] = "Protection Exception",
52 [0x23] = "Write Protect",
53 [0x24] = "Write Length",
54 [0x25] = "Read-Only Format",
55 [0x31] = "Beginning of Partition",
56 [0x33] = "End of Partition",
57 [0x34] = "End of Data",
58 [0x35] = "Block not found",
59 [0x40] = "Device Intervention",
60 [0x41] = "Loader Intervention",
61 [0x42] = "Library Intervention",
62 [0x50] = "Write Error",
63 [0x51] = "Erase Error",
64 [0x52] = "Formatting Error",
65 [0x53] = "Read Error",
66 [0x54] = "Unsupported Format",
67 [0x55] = "No Formatting",
68 [0x56] = "Positioning lost",
69 [0x57] = "Read Length",
70 [0x60] = "Unsupported Medium",
71 [0x61] = "Medium Length Error",
72 [0x62] = "Medium removed",
73 [0x64] = "Load Check",
74 [0x65] = "Unload Check",
75 [0x70] = "Equipment Check",
76 [0x71] = "Bus out Check",
77 [0x72] = "Protocol Error",
78 [0x73] = "Interface Error",
80 [0x75] = "Halt Signal",
81 [0x90] = "Device fenced",
82 [0x91] = "Device Path fenced",
83 [0xa0] = "Volume misplaced",
84 [0xa1] = "Volume inaccessible",
85 [0xa2] = "Volume in input",
86 [0xa3] = "Volume ejected",
87 [0xa4] = "All categories reserved",
88 [0xa5] = "Duplicate Volume",
89 [0xa6] = "Library Manager Offline",
90 [0xa7] = "Library Output Station full",
91 [0xa8] = "Vision System non-operational",
92 [0xa9] = "Library Manager Equipment Check",
93 [0xaa] = "Library Equipment Check",
94 [0xab] = "All Library Cells full",
95 [0xac] = "No Cleaner Volumes in Library",
96 [0xad] = "I/O Station door open",
97 [0xae] = "Subsystem environmental alert",
100 static int crypt_supported(struct tape_device
*device
)
102 return TAPE390_CRYPT_SUPPORTED(TAPE_3590_CRYPT_INFO(device
));
105 static int crypt_enabled(struct tape_device
*device
)
107 return TAPE390_CRYPT_ON(TAPE_3590_CRYPT_INFO(device
));
110 static void ext_to_int_kekl(struct tape390_kekl
*in
,
111 struct tape3592_kekl
*out
)
115 memset(out
, 0, sizeof(*out
));
116 if (in
->type
== TAPE390_KEKL_TYPE_HASH
)
118 if (in
->type_on_tape
== TAPE390_KEKL_TYPE_HASH
)
120 strncpy(out
->label
, in
->label
, 64);
121 for (i
= strlen(in
->label
); i
< sizeof(out
->label
); i
++)
123 ASCEBC(out
->label
, sizeof(out
->label
));
126 static void int_to_ext_kekl(struct tape3592_kekl
*in
,
127 struct tape390_kekl
*out
)
129 memset(out
, 0, sizeof(*out
));
131 out
->type
= TAPE390_KEKL_TYPE_HASH
;
133 out
->type
= TAPE390_KEKL_TYPE_LABEL
;
135 out
->type_on_tape
= TAPE390_KEKL_TYPE_HASH
;
137 out
->type_on_tape
= TAPE390_KEKL_TYPE_LABEL
;
138 memcpy(out
->label
, in
->label
, sizeof(in
->label
));
139 EBCASC(out
->label
, sizeof(in
->label
));
143 static void int_to_ext_kekl_pair(struct tape3592_kekl_pair
*in
,
144 struct tape390_kekl_pair
*out
)
146 if (in
->count
== 0) {
147 out
->kekl
[0].type
= TAPE390_KEKL_TYPE_NONE
;
148 out
->kekl
[0].type_on_tape
= TAPE390_KEKL_TYPE_NONE
;
149 out
->kekl
[1].type
= TAPE390_KEKL_TYPE_NONE
;
150 out
->kekl
[1].type_on_tape
= TAPE390_KEKL_TYPE_NONE
;
151 } else if (in
->count
== 1) {
152 int_to_ext_kekl(&in
->kekl
[0], &out
->kekl
[0]);
153 out
->kekl
[1].type
= TAPE390_KEKL_TYPE_NONE
;
154 out
->kekl
[1].type_on_tape
= TAPE390_KEKL_TYPE_NONE
;
155 } else if (in
->count
== 2) {
156 int_to_ext_kekl(&in
->kekl
[0], &out
->kekl
[0]);
157 int_to_ext_kekl(&in
->kekl
[1], &out
->kekl
[1]);
159 printk("Invalid KEKL number: %d\n", in
->count
);
164 static int check_ext_kekl(struct tape390_kekl
*kekl
)
166 if (kekl
->type
== TAPE390_KEKL_TYPE_NONE
)
168 if (kekl
->type
> TAPE390_KEKL_TYPE_HASH
)
170 if (kekl
->type_on_tape
== TAPE390_KEKL_TYPE_NONE
)
172 if (kekl
->type_on_tape
> TAPE390_KEKL_TYPE_HASH
)
174 if ((kekl
->type
== TAPE390_KEKL_TYPE_HASH
) &&
175 (kekl
->type_on_tape
== TAPE390_KEKL_TYPE_LABEL
))
183 static int check_ext_kekl_pair(struct tape390_kekl_pair
*kekls
)
185 if (check_ext_kekl(&kekls
->kekl
[0]))
187 if (check_ext_kekl(&kekls
->kekl
[1]))
198 static int tape_3592_kekl_query(struct tape_device
*device
,
199 struct tape390_kekl_pair
*ext_kekls
)
201 struct tape_request
*request
;
202 struct tape3592_kekl_query_order
*order
;
203 struct tape3592_kekl_query_data
*int_kekls
;
206 DBF_EVENT(6, "tape3592_kekl_query\n");
207 int_kekls
= kmalloc(sizeof(*int_kekls
), GFP_KERNEL
|GFP_DMA
);
210 request
= tape_alloc_request(2, sizeof(*order
));
211 if (IS_ERR(request
)) {
212 rc
= PTR_ERR(request
);
215 order
= request
->cpdata
;
216 memset(order
,0,sizeof(*order
));
218 order
->max_count
= 2;
219 request
->op
= TO_KEKL_QUERY
;
220 tape_ccw_cc(request
->cpaddr
, PERF_SUBSYS_FUNC
, sizeof(*order
), order
);
221 tape_ccw_end(request
->cpaddr
+ 1, READ_SS_DATA
, sizeof(*int_kekls
),
223 rc
= tape_do_io(device
, request
);
226 int_to_ext_kekl_pair(&int_kekls
->kekls
, ext_kekls
);
230 tape_free_request(request
);
239 static int tape_3592_ioctl_kekl_query(struct tape_device
*device
,
243 struct tape390_kekl_pair
*ext_kekls
;
245 DBF_EVENT(6, "tape_3592_ioctl_kekl_query\n");
246 if (!crypt_supported(device
))
248 if (!crypt_enabled(device
))
250 ext_kekls
= kmalloc(sizeof(*ext_kekls
), GFP_KERNEL
);
253 rc
= tape_3592_kekl_query(device
, ext_kekls
);
256 if (copy_to_user((char __user
*) arg
, ext_kekls
, sizeof(*ext_kekls
))) {
266 static int tape_3590_mttell(struct tape_device
*device
, int mt_count
);
271 static int tape_3592_kekl_set(struct tape_device
*device
,
272 struct tape390_kekl_pair
*ext_kekls
)
274 struct tape_request
*request
;
275 struct tape3592_kekl_set_order
*order
;
277 DBF_EVENT(6, "tape3592_kekl_set\n");
278 if (check_ext_kekl_pair(ext_kekls
)) {
279 DBF_EVENT(6, "invalid kekls\n");
282 if (tape_3590_mttell(device
, 0) != 0)
284 request
= tape_alloc_request(1, sizeof(*order
));
286 return PTR_ERR(request
);
287 order
= request
->cpdata
;
288 memset(order
, 0, sizeof(*order
));
290 order
->kekls
.count
= 2;
291 ext_to_int_kekl(&ext_kekls
->kekl
[0], &order
->kekls
.kekl
[0]);
292 ext_to_int_kekl(&ext_kekls
->kekl
[1], &order
->kekls
.kekl
[1]);
293 request
->op
= TO_KEKL_SET
;
294 tape_ccw_end(request
->cpaddr
, PERF_SUBSYS_FUNC
, sizeof(*order
), order
);
296 return tape_do_io_free(device
, request
);
302 static int tape_3592_ioctl_kekl_set(struct tape_device
*device
,
306 struct tape390_kekl_pair
*ext_kekls
;
308 DBF_EVENT(6, "tape_3592_ioctl_kekl_set\n");
309 if (!crypt_supported(device
))
311 if (!crypt_enabled(device
))
313 ext_kekls
= kmalloc(sizeof(*ext_kekls
), GFP_KERNEL
);
316 if (copy_from_user(ext_kekls
, (char __user
*)arg
, sizeof(*ext_kekls
))) {
320 rc
= tape_3592_kekl_set(device
, ext_kekls
);
329 static int tape_3592_enable_crypt(struct tape_device
*device
)
331 struct tape_request
*request
;
334 DBF_EVENT(6, "tape_3592_enable_crypt\n");
335 if (!crypt_supported(device
))
337 request
= tape_alloc_request(2, 72);
339 return PTR_ERR(request
);
340 data
= request
->cpdata
;
348 data
[36 + 14] = 0x2f;
349 data
[36 + 18] = 0xc3;
350 data
[36 + 35] = 0x72;
351 request
->op
= TO_CRYPT_ON
;
352 tape_ccw_cc(request
->cpaddr
, MODE_SET_CB
, 36, data
);
353 tape_ccw_end(request
->cpaddr
+ 1, MODE_SET_CB
, 36, data
+ 36);
354 return tape_do_io_free(device
, request
);
360 static int tape_3592_disable_crypt(struct tape_device
*device
)
362 struct tape_request
*request
;
365 DBF_EVENT(6, "tape_3592_disable_crypt\n");
366 if (!crypt_supported(device
))
368 request
= tape_alloc_request(2, 72);
370 return PTR_ERR(request
);
371 data
= request
->cpdata
;
377 data
[36 + 35] = 0x32;
379 request
->op
= TO_CRYPT_OFF
;
380 tape_ccw_cc(request
->cpaddr
, MODE_SET_CB
, 36, data
);
381 tape_ccw_end(request
->cpaddr
+ 1, MODE_SET_CB
, 36, data
+ 36);
383 return tape_do_io_free(device
, request
);
387 * IOCTL: Set encryption status
389 static int tape_3592_ioctl_crypt_set(struct tape_device
*device
,
392 struct tape390_crypt_info info
;
394 DBF_EVENT(6, "tape_3592_ioctl_crypt_set\n");
395 if (!crypt_supported(device
))
397 if (copy_from_user(&info
, (char __user
*)arg
, sizeof(info
)))
399 if (info
.status
& ~TAPE390_CRYPT_ON_MASK
)
401 if (info
.status
& TAPE390_CRYPT_ON_MASK
)
402 return tape_3592_enable_crypt(device
);
404 return tape_3592_disable_crypt(device
);
407 static int tape_3590_sense_medium(struct tape_device
*device
);
410 * IOCTL: Query enryption status
412 static int tape_3592_ioctl_crypt_query(struct tape_device
*device
,
415 DBF_EVENT(6, "tape_3592_ioctl_crypt_query\n");
416 if (!crypt_supported(device
))
418 tape_3590_sense_medium(device
);
419 if (copy_to_user((char __user
*) arg
, &TAPE_3590_CRYPT_INFO(device
),
420 sizeof(TAPE_3590_CRYPT_INFO(device
))))
427 * 3590 IOCTL Overload
430 tape_3590_ioctl(struct tape_device
*device
, unsigned int cmd
, unsigned long arg
)
433 case TAPE390_DISPLAY
: {
434 struct display_struct disp
;
436 if (copy_from_user(&disp
, (char __user
*) arg
, sizeof(disp
)))
439 return tape_std_display(device
, &disp
);
441 case TAPE390_KEKL_SET
:
442 return tape_3592_ioctl_kekl_set(device
, arg
);
443 case TAPE390_KEKL_QUERY
:
444 return tape_3592_ioctl_kekl_query(device
, arg
);
445 case TAPE390_CRYPT_SET
:
446 return tape_3592_ioctl_crypt_set(device
, arg
);
447 case TAPE390_CRYPT_QUERY
:
448 return tape_3592_ioctl_crypt_query(device
, arg
);
450 return -EINVAL
; /* no additional ioctls */
455 * SENSE Medium: Get Sense data about medium state
458 tape_3590_sense_medium(struct tape_device
*device
)
460 struct tape_request
*request
;
462 request
= tape_alloc_request(1, 128);
464 return PTR_ERR(request
);
465 request
->op
= TO_MSEN
;
466 tape_ccw_end(request
->cpaddr
, MEDIUM_SENSE
, 128, request
->cpdata
);
467 return tape_do_io_free(device
, request
);
471 * MTTELL: Tell block. Return the number of block relative to current file.
474 tape_3590_mttell(struct tape_device
*device
, int mt_count
)
479 rc
= tape_std_read_block_id(device
, &block_id
);
482 return block_id
>> 32;
486 * MTSEEK: seek to the specified block.
489 tape_3590_mtseek(struct tape_device
*device
, int count
)
491 struct tape_request
*request
;
493 DBF_EVENT(6, "xsee id: %x\n", count
);
494 request
= tape_alloc_request(3, 4);
496 return PTR_ERR(request
);
497 request
->op
= TO_LBL
;
498 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
499 *(__u32
*) request
->cpdata
= count
;
500 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
501 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
502 return tape_do_io_free(device
, request
);
506 * Read Opposite Error Recovery Function:
507 * Used, when Read Forward does not work
510 tape_3590_read_opposite(struct tape_device
*device
,
511 struct tape_request
*request
)
513 struct tape_3590_disc_data
*data
;
516 * We have allocated 4 ccws in tape_std_read, so we can now
517 * transform the request to a read backward, followed by a
518 * forward space block.
520 request
->op
= TO_RBA
;
521 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
522 data
= device
->discdata
;
523 tape_ccw_cc_idal(request
->cpaddr
+ 1, data
->read_back_op
,
524 device
->char_data
.idal_buf
);
525 tape_ccw_cc(request
->cpaddr
+ 2, FORSPACEBLOCK
, 0, NULL
);
526 tape_ccw_end(request
->cpaddr
+ 3, NOP
, 0, NULL
);
527 DBF_EVENT(6, "xrop ccwg\n");
532 * This should be done after an interrupt with attention bit (0x80)
535 * After a "read attention message" request there are two possible
538 * 1. A unit check is presented, when attention sense is present (e.g. when
539 * a medium has been unloaded). The attention sense comes then
540 * together with the unit check. The recovery action is either "retry"
541 * (in case there is an attention message pending) or "permanent error".
543 * 2. The attention msg is written to the "read subsystem data" buffer.
544 * In this case we probably should print it to the console.
547 tape_3590_read_attmsg(struct tape_device
*device
)
549 struct tape_request
*request
;
552 request
= tape_alloc_request(3, 4096);
554 return PTR_ERR(request
);
555 request
->op
= TO_READ_ATTMSG
;
556 buf
= request
->cpdata
;
557 buf
[0] = PREP_RD_SS_DATA
;
558 buf
[6] = RD_ATTMSG
; /* read att msg */
559 tape_ccw_cc(request
->cpaddr
, PERFORM_SS_FUNC
, 12, buf
);
560 tape_ccw_cc(request
->cpaddr
+ 1, READ_SS_DATA
, 4096 - 12, buf
+ 12);
561 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
562 return tape_do_io_free(device
, request
);
566 * These functions are used to schedule follow-up actions from within an
567 * interrupt context (like unsolicited interrupts).
569 struct work_handler_data
{
570 struct tape_device
*device
;
572 struct work_struct work
;
576 tape_3590_work_handler(struct work_struct
*work
)
578 struct work_handler_data
*p
=
579 container_of(work
, struct work_handler_data
, work
);
583 tape_3590_sense_medium(p
->device
);
586 tape_3590_read_attmsg(p
->device
);
589 tape_3592_enable_crypt(p
->device
);
592 tape_3592_disable_crypt(p
->device
);
595 DBF_EVENT(3, "T3590: work handler undefined for "
596 "operation 0x%02x\n", p
->op
);
598 tape_put_device(p
->device
);
603 tape_3590_schedule_work(struct tape_device
*device
, enum tape_op op
)
605 struct work_handler_data
*p
;
607 if ((p
= kzalloc(sizeof(*p
), GFP_ATOMIC
)) == NULL
)
610 INIT_WORK(&p
->work
, tape_3590_work_handler
);
612 p
->device
= tape_get_device(device
);
615 schedule_work(&p
->work
);
619 #ifdef CONFIG_S390_TAPE_BLOCK
623 static struct tape_request
*
624 tape_3590_bread(struct tape_device
*device
, struct request
*req
)
626 struct tape_request
*request
;
628 int count
= 0, start_block
;
632 struct req_iterator iter
;
634 DBF_EVENT(6, "xBREDid:");
635 start_block
= blk_rq_pos(req
) >> TAPEBLOCK_HSEC_S2B
;
636 DBF_EVENT(6, "start_block = %i\n", start_block
);
638 rq_for_each_segment(bv
, req
, iter
)
639 count
+= bv
->bv_len
>> (TAPEBLOCK_HSEC_S2B
+ 9);
641 request
= tape_alloc_request(2 + count
+ 1, 4);
644 request
->op
= TO_BLOCK
;
645 *(__u32
*) request
->cpdata
= start_block
;
646 ccw
= request
->cpaddr
;
647 ccw
= tape_ccw_cc(ccw
, MODE_SET_DB
, 1, device
->modeset_byte
);
650 * We always setup a nop after the mode set ccw. This slot is
651 * used in tape_std_check_locate to insert a locate ccw if the
652 * current tape position doesn't match the start block to be read.
654 ccw
= tape_ccw_cc(ccw
, NOP
, 0, NULL
);
656 rq_for_each_segment(bv
, req
, iter
) {
657 dst
= page_address(bv
->bv_page
) + bv
->bv_offset
;
658 for (off
= 0; off
< bv
->bv_len
; off
+= TAPEBLOCK_HSEC_SIZE
) {
659 ccw
->flags
= CCW_FLAG_CC
;
660 ccw
->cmd_code
= READ_FORWARD
;
661 ccw
->count
= TAPEBLOCK_HSEC_SIZE
;
662 set_normalized_cda(ccw
, (void *) __pa(dst
));
664 dst
+= TAPEBLOCK_HSEC_SIZE
;
666 BUG_ON(off
> bv
->bv_len
);
668 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
669 DBF_EVENT(6, "xBREDccwg\n");
674 tape_3590_free_bread(struct tape_request
*request
)
678 /* Last ccw is a nop and doesn't need clear_normalized_cda */
679 for (ccw
= request
->cpaddr
; ccw
->flags
& CCW_FLAG_CC
; ccw
++)
680 if (ccw
->cmd_code
== READ_FORWARD
)
681 clear_normalized_cda(ccw
);
682 tape_free_request(request
);
686 * check_locate is called just before the tape request is passed to
687 * the common io layer for execution. It has to check the current
688 * tape position and insert a locate ccw if it doesn't match the
689 * start block for the request.
692 tape_3590_check_locate(struct tape_device
*device
, struct tape_request
*request
)
696 start_block
= (__u32
*) request
->cpdata
;
697 if (*start_block
!= device
->blk_data
.block_position
) {
698 /* Add the start offset of the file to get the real block. */
699 *start_block
+= device
->bof
;
700 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
705 static void tape_3590_med_state_set(struct tape_device
*device
,
706 struct tape_3590_med_sense
*sense
)
708 struct tape390_crypt_info
*c_info
;
710 c_info
= &TAPE_3590_CRYPT_INFO(device
);
712 DBF_EVENT(6, "medium state: %x:%x\n", sense
->macst
, sense
->masst
);
713 switch (sense
->macst
) {
717 tape_med_state_set(device
, MS_UNLOADED
);
718 TAPE_3590_CRYPT_INFO(device
).medium_status
= 0;
722 tape_med_state_set(device
, MS_LOADED
);
725 tape_med_state_set(device
, MS_UNKNOWN
);
728 c_info
->medium_status
|= TAPE390_MEDIUM_LOADED_MASK
;
729 if (sense
->flags
& MSENSE_CRYPT_MASK
) {
730 DBF_EVENT(6, "Medium is encrypted (%04x)\n", sense
->flags
);
731 c_info
->medium_status
|= TAPE390_MEDIUM_ENCRYPTED_MASK
;
733 DBF_EVENT(6, "Medium is not encrypted %04x\n", sense
->flags
);
734 c_info
->medium_status
&= ~TAPE390_MEDIUM_ENCRYPTED_MASK
;
739 * The done handler is called at device/channel end and wakes up the sleeping
743 tape_3590_done(struct tape_device
*device
, struct tape_request
*request
)
745 struct tape_3590_disc_data
*disc_data
;
747 DBF_EVENT(6, "%s done\n", tape_op_verbose
[request
->op
]);
748 disc_data
= device
->discdata
;
750 switch (request
->op
) {
764 tape_med_state_set(device
, MS_LOADED
);
767 tape_med_state_set(device
, MS_UNLOADED
);
768 tape_3590_schedule_work(device
, TO_CRYPT_OFF
);
771 tape_3590_med_state_set(device
, request
->cpdata
);
774 TAPE_3590_CRYPT_INFO(device
).status
775 |= TAPE390_CRYPT_ON_MASK
;
776 *(device
->modeset_byte
) |= 0x03;
779 TAPE_3590_CRYPT_INFO(device
).status
780 &= ~TAPE390_CRYPT_ON_MASK
;
781 *(device
->modeset_byte
) &= ~0x03;
783 case TO_RBI
: /* RBI seems to succeed even without medium loaded. */
784 case TO_NOP
: /* Same to NOP. */
796 return TAPE_IO_SUCCESS
;
800 * This fuction is called, when error recovery was successfull
803 tape_3590_erp_succeded(struct tape_device
*device
, struct tape_request
*request
)
805 DBF_EVENT(3, "Error Recovery successful for %s\n",
806 tape_op_verbose
[request
->op
]);
807 return tape_3590_done(device
, request
);
811 * This fuction is called, when error recovery was not successfull
814 tape_3590_erp_failed(struct tape_device
*device
, struct tape_request
*request
,
815 struct irb
*irb
, int rc
)
817 DBF_EVENT(3, "Error Recovery failed for %s\n",
818 tape_op_verbose
[request
->op
]);
819 tape_dump_sense_dbf(device
, request
, irb
);
824 * Error Recovery do retry
827 tape_3590_erp_retry(struct tape_device
*device
, struct tape_request
*request
,
830 DBF_EVENT(2, "Retry: %s\n", tape_op_verbose
[request
->op
]);
831 tape_dump_sense_dbf(device
, request
, irb
);
832 return TAPE_IO_RETRY
;
836 * Handle unsolicited interrupts
839 tape_3590_unsolicited_irq(struct tape_device
*device
, struct irb
*irb
)
841 if (irb
->scsw
.cmd
.dstat
== DEV_STAT_CHN_END
)
842 /* Probably result of halt ssch */
843 return TAPE_IO_PENDING
;
844 else if (irb
->scsw
.cmd
.dstat
== 0x85)
846 DBF_EVENT(3, "unsol.irq! tape ready: %08x\n", device
->cdev_id
);
847 else if (irb
->scsw
.cmd
.dstat
& DEV_STAT_ATTENTION
) {
848 tape_3590_schedule_work(device
, TO_READ_ATTMSG
);
850 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device
->cdev_id
);
851 tape_dump_sense_dbf(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
);
885 * RDL: Read Device (buffered) log
888 tape_3590_erp_read_buf_log(struct tape_device
*device
,
889 struct tape_request
*request
, struct irb
*irb
)
892 * We just do the basic error recovery at the moment (retry).
893 * Perhaps in the future, we read the log and dump it somewhere...
895 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
902 tape_3590_erp_swap(struct tape_device
*device
, struct tape_request
*request
,
906 * This error recovery should swap the tapes
907 * if the original has a problem. The operation
908 * should proceed with the new tape... this
909 * should probably be done in user space!
911 dev_warn (&device
->cdev
->dev
, "The tape medium must be loaded into a "
912 "different tape unit\n");
913 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
920 tape_3590_erp_long_busy(struct tape_device
*device
,
921 struct tape_request
*request
, struct irb
*irb
)
923 DBF_EVENT(6, "Device is busy\n");
924 return TAPE_IO_LONG_BUSY
;
928 * SPI: Special Intercept
931 tape_3590_erp_special_interrupt(struct tape_device
*device
,
932 struct tape_request
*request
, struct irb
*irb
)
934 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
938 * RDA: Read Alternate
941 tape_3590_erp_read_alternate(struct tape_device
*device
,
942 struct tape_request
*request
, struct irb
*irb
)
944 struct tape_3590_disc_data
*data
;
947 * The issued Read Backward or Read Previous command is not
948 * supported by the device
949 * The recovery action should be to issue another command:
950 * Read Revious: if Read Backward is not supported
951 * Read Backward: if Read Previous is not supported
953 data
= device
->discdata
;
954 if (data
->read_back_op
== READ_PREVIOUS
) {
955 DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
957 data
->read_back_op
= READ_BACKWARD
;
959 DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
961 data
->read_back_op
= READ_PREVIOUS
;
963 tape_3590_read_opposite(device
, request
);
964 return tape_3590_erp_retry(device
, request
, irb
);
968 * Error Recovery read opposite
971 tape_3590_erp_read_opposite(struct tape_device
*device
,
972 struct tape_request
*request
, struct irb
*irb
)
974 switch (request
->op
) {
977 * We did read forward, but the data could not be read.
978 * We will read backward and then skip forward again.
980 tape_3590_read_opposite(device
, request
);
981 return tape_3590_erp_retry(device
, request
, irb
);
983 /* We tried to read forward and backward, but hat no success */
984 return tape_3590_erp_failed(device
, request
, irb
, -EIO
);
987 return tape_3590_erp_failed(device
, request
, irb
, -EIO
);
992 * Print an MIM (Media Information Message) (message code f0)
995 tape_3590_print_mim_msg_f0(struct tape_device
*device
, struct irb
*irb
)
997 struct tape_3590_sense
*sense
;
998 char *exception
, *service
;
1000 exception
= kmalloc(BUFSIZE
, GFP_ATOMIC
);
1001 service
= kmalloc(BUFSIZE
, GFP_ATOMIC
);
1003 if (!exception
|| !service
)
1006 sense
= (struct tape_3590_sense
*) irb
->ecw
;
1007 /* Exception Message */
1008 switch (sense
->fmt
.f70
.emc
) {
1010 snprintf(exception
, BUFSIZE
, "Data degraded");
1013 snprintf(exception
, BUFSIZE
, "Data degraded in partion %i",
1017 snprintf(exception
, BUFSIZE
, "Medium degraded");
1020 snprintf(exception
, BUFSIZE
, "Medium degraded in partition %i",
1024 snprintf(exception
, BUFSIZE
, "Block 0 Error");
1027 snprintf(exception
, BUFSIZE
, "Medium Exception 0x%02x",
1031 snprintf(exception
, BUFSIZE
, "0x%02x",
1032 sense
->fmt
.f70
.emc
);
1035 /* Service Message */
1036 switch (sense
->fmt
.f70
.smc
) {
1038 snprintf(service
, BUFSIZE
, "Reference Media maintenance "
1039 "procedure %i", sense
->fmt
.f70
.md
);
1042 snprintf(service
, BUFSIZE
, "0x%02x",
1043 sense
->fmt
.f70
.smc
);
1047 dev_warn (&device
->cdev
->dev
, "Tape media information: exception %s, "
1048 "service %s\n", exception
, service
);
1056 * Print an I/O Subsystem Service Information Message (message code f1)
1059 tape_3590_print_io_sim_msg_f1(struct tape_device
*device
, struct irb
*irb
)
1061 struct tape_3590_sense
*sense
;
1062 char *exception
, *service
;
1064 exception
= kmalloc(BUFSIZE
, GFP_ATOMIC
);
1065 service
= kmalloc(BUFSIZE
, GFP_ATOMIC
);
1067 if (!exception
|| !service
)
1070 sense
= (struct tape_3590_sense
*) irb
->ecw
;
1071 /* Exception Message */
1072 switch (sense
->fmt
.f71
.emc
) {
1074 snprintf(exception
, BUFSIZE
, "Effect of failure is unknown");
1077 snprintf(exception
, BUFSIZE
, "CU Exception - no performance "
1081 snprintf(exception
, BUFSIZE
, "CU Exception on channel "
1082 "interface 0x%02x", sense
->fmt
.f71
.md
[0]);
1085 snprintf(exception
, BUFSIZE
, "CU Exception on device path "
1086 "0x%02x", sense
->fmt
.f71
.md
[0]);
1089 snprintf(exception
, BUFSIZE
, "CU Exception on library path "
1090 "0x%02x", sense
->fmt
.f71
.md
[0]);
1093 snprintf(exception
, BUFSIZE
, "CU Exception on node 0x%02x",
1094 sense
->fmt
.f71
.md
[0]);
1097 snprintf(exception
, BUFSIZE
, "CU Exception on partition "
1098 "0x%02x", sense
->fmt
.f71
.md
[0]);
1101 snprintf(exception
, BUFSIZE
, "0x%02x",
1102 sense
->fmt
.f71
.emc
);
1104 /* Service Message */
1105 switch (sense
->fmt
.f71
.smc
) {
1107 snprintf(service
, BUFSIZE
, "Repair impact is unknown");
1110 snprintf(service
, BUFSIZE
, "Repair will not impact cu "
1114 if (sense
->fmt
.f71
.mdf
== 0)
1115 snprintf(service
, BUFSIZE
, "Repair will disable node "
1116 "0x%x on CU", sense
->fmt
.f71
.md
[1]);
1118 snprintf(service
, BUFSIZE
, "Repair will disable "
1119 "nodes (0x%x-0x%x) on CU", sense
->fmt
.f71
.md
[1],
1120 sense
->fmt
.f71
.md
[2]);
1123 if (sense
->fmt
.f71
.mdf
== 0)
1124 snprintf(service
, BUFSIZE
, "Repair will disable "
1125 "channel path 0x%x on CU",
1126 sense
->fmt
.f71
.md
[1]);
1128 snprintf(service
, BUFSIZE
, "Repair will disable cannel"
1129 " paths (0x%x-0x%x) on CU",
1130 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1133 if (sense
->fmt
.f71
.mdf
== 0)
1134 snprintf(service
, BUFSIZE
, "Repair will disable device"
1135 " path 0x%x on CU", sense
->fmt
.f71
.md
[1]);
1137 snprintf(service
, BUFSIZE
, "Repair will disable device"
1138 " paths (0x%x-0x%x) on CU",
1139 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1142 if (sense
->fmt
.f71
.mdf
== 0)
1143 snprintf(service
, BUFSIZE
, "Repair will disable "
1144 "library path 0x%x on CU",
1145 sense
->fmt
.f71
.md
[1]);
1147 snprintf(service
, BUFSIZE
, "Repair will disable "
1148 "library paths (0x%x-0x%x) on CU",
1149 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1152 snprintf(service
, BUFSIZE
, "Repair will disable access to CU");
1155 snprintf(service
, BUFSIZE
, "0x%02x",
1156 sense
->fmt
.f71
.smc
);
1159 dev_warn (&device
->cdev
->dev
, "I/O subsystem information: exception"
1160 " %s, service %s\n", exception
, service
);
1167 * Print an Device Subsystem Service Information Message (message code f2)
1170 tape_3590_print_dev_sim_msg_f2(struct tape_device
*device
, struct irb
*irb
)
1172 struct tape_3590_sense
*sense
;
1173 char *exception
, *service
;
1175 exception
= kmalloc(BUFSIZE
, GFP_ATOMIC
);
1176 service
= kmalloc(BUFSIZE
, GFP_ATOMIC
);
1178 if (!exception
|| !service
)
1181 sense
= (struct tape_3590_sense
*) irb
->ecw
;
1182 /* Exception Message */
1183 switch (sense
->fmt
.f71
.emc
) {
1185 snprintf(exception
, BUFSIZE
, "Effect of failure is unknown");
1188 snprintf(exception
, BUFSIZE
, "DV Exception - no performance"
1192 snprintf(exception
, BUFSIZE
, "DV Exception on channel "
1193 "interface 0x%02x", sense
->fmt
.f71
.md
[0]);
1196 snprintf(exception
, BUFSIZE
, "DV Exception on loader 0x%02x",
1197 sense
->fmt
.f71
.md
[0]);
1200 snprintf(exception
, BUFSIZE
, "DV Exception on message display"
1201 " 0x%02x", sense
->fmt
.f71
.md
[0]);
1204 snprintf(exception
, BUFSIZE
, "DV Exception in tape path");
1207 snprintf(exception
, BUFSIZE
, "DV Exception in drive");
1210 snprintf(exception
, BUFSIZE
, "0x%02x",
1211 sense
->fmt
.f71
.emc
);
1213 /* Service Message */
1214 switch (sense
->fmt
.f71
.smc
) {
1216 snprintf(service
, BUFSIZE
, "Repair impact is unknown");
1219 snprintf(service
, BUFSIZE
, "Repair will not impact device "
1223 if (sense
->fmt
.f71
.mdf
== 0)
1224 snprintf(service
, BUFSIZE
, "Repair will disable "
1225 "channel path 0x%x on DV",
1226 sense
->fmt
.f71
.md
[1]);
1228 snprintf(service
, BUFSIZE
, "Repair will disable "
1229 "channel path (0x%x-0x%x) on DV",
1230 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1233 if (sense
->fmt
.f71
.mdf
== 0)
1234 snprintf(service
, BUFSIZE
, "Repair will disable "
1235 "interface 0x%x on DV", sense
->fmt
.f71
.md
[1]);
1237 snprintf(service
, BUFSIZE
, "Repair will disable "
1238 "interfaces (0x%x-0x%x) on DV",
1239 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1242 if (sense
->fmt
.f71
.mdf
== 0)
1243 snprintf(service
, BUFSIZE
, "Repair will disable loader"
1244 " 0x%x on DV", sense
->fmt
.f71
.md
[1]);
1246 snprintf(service
, BUFSIZE
, "Repair will disable loader"
1247 " (0x%x-0x%x) on DV",
1248 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1251 snprintf(service
, BUFSIZE
, "Repair will disable access to DV");
1254 if (sense
->fmt
.f71
.mdf
== 0)
1255 snprintf(service
, BUFSIZE
, "Repair will disable "
1256 "message display 0x%x on DV",
1257 sense
->fmt
.f71
.md
[1]);
1259 snprintf(service
, BUFSIZE
, "Repair will disable "
1260 "message displays (0x%x-0x%x) on DV",
1261 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
1264 snprintf(service
, BUFSIZE
, "Clean DV");
1267 snprintf(service
, BUFSIZE
, "0x%02x",
1268 sense
->fmt
.f71
.smc
);
1271 dev_warn (&device
->cdev
->dev
, "Device subsystem information: exception"
1272 " %s, service %s\n", exception
, service
);
1279 * Print standard ERA Message
1282 tape_3590_print_era_msg(struct tape_device
*device
, struct irb
*irb
)
1284 struct tape_3590_sense
*sense
;
1286 sense
= (struct tape_3590_sense
*) irb
->ecw
;
1289 if ((sense
->mc
> 0) && (sense
->mc
< TAPE_3590_MAX_MSG
)) {
1290 if (tape_3590_msg
[sense
->mc
] != NULL
)
1291 dev_warn (&device
->cdev
->dev
, "The tape unit has "
1292 "issued sense message %s\n",
1293 tape_3590_msg
[sense
->mc
]);
1295 dev_warn (&device
->cdev
->dev
, "The tape unit has "
1296 "issued an unknown sense message code 0x%x\n",
1300 if (sense
->mc
== 0xf0) {
1301 /* Standard Media Information Message */
1302 dev_warn (&device
->cdev
->dev
, "MIM SEV=%i, MC=%02x, ES=%x/%x, "
1303 "RC=%02x-%04x-%02x\n", sense
->fmt
.f70
.sev
, sense
->mc
,
1304 sense
->fmt
.f70
.emc
, sense
->fmt
.f70
.smc
,
1305 sense
->fmt
.f70
.refcode
, sense
->fmt
.f70
.mid
,
1306 sense
->fmt
.f70
.fid
);
1307 tape_3590_print_mim_msg_f0(device
, irb
);
1310 if (sense
->mc
== 0xf1) {
1311 /* Standard I/O Subsystem Service Information Message */
1312 dev_warn (&device
->cdev
->dev
, "IOSIM SEV=%i, DEVTYPE=3590/%02x,"
1313 " MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1314 sense
->fmt
.f71
.sev
, device
->cdev
->id
.dev_model
,
1315 sense
->mc
, sense
->fmt
.f71
.emc
, sense
->fmt
.f71
.smc
,
1316 sense
->fmt
.f71
.refcode1
, sense
->fmt
.f71
.refcode2
,
1317 sense
->fmt
.f71
.refcode3
);
1318 tape_3590_print_io_sim_msg_f1(device
, irb
);
1321 if (sense
->mc
== 0xf2) {
1322 /* Standard Device Service Information Message */
1323 dev_warn (&device
->cdev
->dev
, "DEVSIM SEV=%i, DEVTYPE=3590/%02x"
1324 ", MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1325 sense
->fmt
.f71
.sev
, device
->cdev
->id
.dev_model
,
1326 sense
->mc
, sense
->fmt
.f71
.emc
, sense
->fmt
.f71
.smc
,
1327 sense
->fmt
.f71
.refcode1
, sense
->fmt
.f71
.refcode2
,
1328 sense
->fmt
.f71
.refcode3
);
1329 tape_3590_print_dev_sim_msg_f2(device
, irb
);
1332 if (sense
->mc
== 0xf3) {
1333 /* Standard Library Service Information Message */
1336 dev_warn (&device
->cdev
->dev
, "The tape unit has issued an unknown "
1337 "sense message code %x\n", sense
->mc
);
1340 static int tape_3590_crypt_error(struct tape_device
*device
,
1341 struct tape_request
*request
, struct irb
*irb
)
1349 sense
= ((struct tape_3590_sense
*) irb
->ecw
)->fmt
.data
;
1350 bus_id
= dev_name(&device
->cdev
->dev
);
1352 drv_rc
= *((u32
*) &sense
[5]) & 0xffffff;
1354 ekm_rc2
= *((u16
*) &sense
[10]);
1355 if ((cu_rc
== 0) && (ekm_rc2
== 0xee31))
1356 /* key not defined on EKM */
1357 return tape_3590_erp_basic(device
, request
, irb
, -EKEYREJECTED
);
1358 if ((cu_rc
== 1) || (cu_rc
== 2))
1359 /* No connection to EKM */
1360 return tape_3590_erp_basic(device
, request
, irb
, -ENOTCONN
);
1362 dev_err (&device
->cdev
->dev
, "The tape unit failed to obtain the "
1363 "encryption key from EKM\n");
1365 return tape_3590_erp_basic(device
, request
, irb
, -ENOKEY
);
1369 * 3590 error Recovery routine:
1370 * If possible, it tries to recover from the error. If this is not possible,
1371 * inform the user about the problem.
1374 tape_3590_unit_check(struct tape_device
*device
, struct tape_request
*request
,
1377 struct tape_3590_sense
*sense
;
1380 #ifdef CONFIG_S390_TAPE_BLOCK
1381 if (request
->op
== TO_BLOCK
) {
1383 * Recovery for block device requests. Set the block_position
1384 * to something invalid and retry.
1386 device
->blk_data
.block_position
= -1;
1387 if (request
->retries
-- <= 0)
1388 return tape_3590_erp_failed(device
, request
, irb
, -EIO
);
1390 return tape_3590_erp_retry(device
, request
, irb
);
1394 sense
= (struct tape_3590_sense
*) irb
->ecw
;
1396 DBF_EVENT(6, "Unit Check: RQC = %x\n", sense
->rc_rqc
);
1399 * First check all RC-QRCs where we want to do something special
1400 * - "break": basic error recovery is done
1401 * - "goto out:": just print error message if available
1404 switch (sense
->rc_rqc
) {
1407 tape_3590_print_era_msg(device
, irb
);
1408 return tape_3590_erp_read_buf_log(device
, request
, irb
);
1411 tape_3590_print_era_msg(device
, irb
);
1412 return tape_3590_erp_read_alternate(device
, request
, irb
);
1416 tape_3590_print_era_msg(device
, irb
);
1417 return tape_3590_erp_special_interrupt(device
, request
, irb
);
1419 return tape_3590_crypt_error(device
, request
, irb
);
1422 DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1424 return tape_3590_erp_basic(device
, request
, irb
, -ENOSPC
);
1426 DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1428 return tape_3590_erp_basic(device
, request
, irb
, -ENOSPC
);
1430 DBF_EVENT(2, "(%08x): End of Data Mark\n", device
->cdev_id
);
1431 return tape_3590_erp_basic(device
, request
, irb
, -ENOSPC
);
1434 DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1436 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
1438 DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1440 tape_med_state_set(device
, MS_UNLOADED
);
1441 tape_3590_schedule_work(device
, TO_CRYPT_OFF
);
1442 return tape_3590_erp_basic(device
, request
, irb
, 0);
1446 * print additional msg since default msg
1447 * "device intervention" is not very meaningfull
1449 tape_med_state_set(device
, MS_UNLOADED
);
1450 tape_3590_schedule_work(device
, TO_CRYPT_OFF
);
1451 return tape_3590_erp_basic(device
, request
, irb
, -ENOMEDIUM
);
1452 case 0x4012: /* Device Long Busy */
1453 /* XXX: Also use long busy handling here? */
1454 DBF_EVENT(6, "(%08x): LONG BUSY\n", device
->cdev_id
);
1455 tape_3590_print_era_msg(device
, irb
);
1456 return tape_3590_erp_basic(device
, request
, irb
, -EBUSY
);
1458 DBF_EVENT(6, "(%08x): Crypto LONG BUSY\n", device
->cdev_id
);
1459 return tape_3590_erp_long_busy(device
, request
, irb
);
1462 if (sense
->rac
== 0xd0) {
1464 tape_3590_print_era_msg(device
, irb
);
1465 return tape_3590_erp_swap(device
, request
, irb
);
1467 if (sense
->rac
== 0x26) {
1469 tape_3590_print_era_msg(device
, irb
);
1470 return tape_3590_erp_read_opposite(device
, request
,
1473 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
1480 tape_3590_print_era_msg(device
, irb
);
1481 return tape_3590_erp_swap(device
, request
, irb
);
1485 return tape_3590_erp_basic(device
, request
, irb
, -EMEDIUMTYPE
);
1489 tape_med_state_set(device
, MS_UNLOADED
);
1490 tape_3590_schedule_work(device
, TO_CRYPT_OFF
);
1491 return tape_3590_erp_basic(device
, request
, irb
, -ENOMEDIUM
);
1494 return tape_3590_erp_basic(device
, request
, irb
, -EMEDIUMTYPE
);
1497 return tape_3590_erp_basic(device
, request
, irb
, -EPERM
);
1499 dev_warn (&device
->cdev
->dev
, "A different host has privileged"
1500 " access to the tape unit\n");
1501 return tape_3590_erp_basic(device
, request
, irb
, -EPERM
);
1503 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
1508 * 3590 interrupt handler:
1511 tape_3590_irq(struct tape_device
*device
, struct tape_request
*request
,
1514 if (request
== NULL
)
1515 return tape_3590_unsolicited_irq(device
, irb
);
1517 if ((irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_EXCEP
) &&
1518 (irb
->scsw
.cmd
.dstat
& DEV_STAT_DEV_END
) &&
1519 (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
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
)
1526 return tape_3590_unit_check(device
, request
, irb
);
1528 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_DEV_END
) {
1529 if (irb
->scsw
.cmd
.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
.cmd
.dstat
& DEV_STAT_CHN_END
) {
1540 DBF_EVENT(2, "cannel end\n");
1541 return TAPE_IO_PENDING
;
1544 if (irb
->scsw
.cmd
.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 tape_dump_sense_dbf(device
, request
, irb
);
1551 return TAPE_IO_STOP
;
1555 static int tape_3590_read_dev_chars(struct tape_device
*device
,
1556 struct tape_3590_rdc_data
*rdc_data
)
1559 struct tape_request
*request
;
1561 request
= tape_alloc_request(1, sizeof(*rdc_data
));
1562 if (IS_ERR(request
))
1563 return PTR_ERR(request
);
1564 request
->op
= TO_RDC
;
1565 tape_ccw_end(request
->cpaddr
, CCW_CMD_RDC
, sizeof(*rdc_data
),
1567 rc
= tape_do_io(device
, request
);
1569 memcpy(rdc_data
, request
->cpdata
, sizeof(*rdc_data
));
1570 tape_free_request(request
);
1575 * Setup device function
1578 tape_3590_setup_device(struct tape_device
*device
)
1581 struct tape_3590_disc_data
*data
;
1582 struct tape_3590_rdc_data
*rdc_data
;
1584 DBF_EVENT(6, "3590 device setup\n");
1585 data
= kzalloc(sizeof(struct tape_3590_disc_data
), GFP_KERNEL
| GFP_DMA
);
1588 data
->read_back_op
= READ_PREVIOUS
;
1589 device
->discdata
= data
;
1591 rdc_data
= kmalloc(sizeof(*rdc_data
), GFP_KERNEL
| GFP_DMA
);
1596 rc
= tape_3590_read_dev_chars(device
, rdc_data
);
1598 DBF_LH(3, "Read device characteristics failed!\n");
1601 rc
= tape_std_assign(device
);
1604 if (rdc_data
->data
[31] == 0x13) {
1605 data
->crypt_info
.capability
|= TAPE390_CRYPT_SUPPORTED_MASK
;
1606 tape_3592_disable_crypt(device
);
1608 DBF_EVENT(6, "Device has NO crypto support\n");
1610 /* Try to find out if medium is loaded */
1611 rc
= tape_3590_sense_medium(device
);
1613 DBF_LH(3, "3590 medium sense returned %d\n", rc
);
1626 * Cleanup device function
1629 tape_3590_cleanup_device(struct tape_device
*device
)
1631 flush_scheduled_work();
1632 tape_std_unassign(device
);
1634 kfree(device
->discdata
);
1635 device
->discdata
= NULL
;
1639 * List of 3590 magnetic tape commands.
1641 static tape_mtop_fn tape_3590_mtop
[TAPE_NR_MTOPS
] = {
1642 [MTRESET
] = tape_std_mtreset
,
1643 [MTFSF
] = tape_std_mtfsf
,
1644 [MTBSF
] = tape_std_mtbsf
,
1645 [MTFSR
] = tape_std_mtfsr
,
1646 [MTBSR
] = tape_std_mtbsr
,
1647 [MTWEOF
] = tape_std_mtweof
,
1648 [MTREW
] = tape_std_mtrew
,
1649 [MTOFFL
] = tape_std_mtoffl
,
1650 [MTNOP
] = tape_std_mtnop
,
1651 [MTRETEN
] = tape_std_mtreten
,
1652 [MTBSFM
] = tape_std_mtbsfm
,
1653 [MTFSFM
] = tape_std_mtfsfm
,
1654 [MTEOM
] = tape_std_mteom
,
1655 [MTERASE
] = tape_std_mterase
,
1659 [MTSETBLK
] = tape_std_mtsetblk
,
1660 [MTSETDENSITY
] = NULL
,
1661 [MTSEEK
] = tape_3590_mtseek
,
1662 [MTTELL
] = tape_3590_mttell
,
1663 [MTSETDRVBUFFER
] = NULL
,
1669 [MTLOAD
] = tape_std_mtload
,
1670 [MTUNLOAD
] = tape_std_mtunload
,
1671 [MTCOMPRESSION
] = tape_std_mtcompression
,
1677 * Tape discipline structure for 3590.
1679 static struct tape_discipline tape_discipline_3590
= {
1680 .owner
= THIS_MODULE
,
1681 .setup_device
= tape_3590_setup_device
,
1682 .cleanup_device
= tape_3590_cleanup_device
,
1683 .process_eov
= tape_std_process_eov
,
1684 .irq
= tape_3590_irq
,
1685 .read_block
= tape_std_read_block
,
1686 .write_block
= tape_std_write_block
,
1687 #ifdef CONFIG_S390_TAPE_BLOCK
1688 .bread
= tape_3590_bread
,
1689 .free_bread
= tape_3590_free_bread
,
1690 .check_locate
= tape_3590_check_locate
,
1692 .ioctl_fn
= tape_3590_ioctl
,
1693 .mtop_array
= tape_3590_mtop
1696 static struct ccw_device_id tape_3590_ids
[] = {
1697 {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info
= tape_3590
},
1698 {CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info
= tape_3592
},
1699 { /* end of list */ }
1703 tape_3590_online(struct ccw_device
*cdev
)
1705 return tape_generic_online(dev_get_drvdata(&cdev
->dev
),
1706 &tape_discipline_3590
);
1709 static struct ccw_driver tape_3590_driver
= {
1710 .name
= "tape_3590",
1711 .owner
= THIS_MODULE
,
1712 .ids
= tape_3590_ids
,
1713 .probe
= tape_generic_probe
,
1714 .remove
= tape_generic_remove
,
1715 .set_offline
= tape_generic_offline
,
1716 .set_online
= tape_3590_online
,
1717 .freeze
= tape_generic_pm_suspend
,
1721 * Setup discipline structure.
1724 tape_3590_init(void)
1728 TAPE_DBF_AREA
= debug_register("tape_3590", 2, 2, 4 * sizeof(long));
1729 debug_register_view(TAPE_DBF_AREA
, &debug_sprintf_view
);
1730 #ifdef DBF_LIKE_HELL
1731 debug_set_level(TAPE_DBF_AREA
, 6);
1734 DBF_EVENT(3, "3590 init\n");
1735 /* Register driver for 3590 tapes. */
1736 rc
= ccw_driver_register(&tape_3590_driver
);
1738 DBF_EVENT(3, "3590 init failed\n");
1740 DBF_EVENT(3, "3590 registered\n");
1745 tape_3590_exit(void)
1747 ccw_driver_unregister(&tape_3590_driver
);
1749 debug_unregister(TAPE_DBF_AREA
);
1752 MODULE_DEVICE_TABLE(ccw
, tape_3590_ids
);
1753 MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
1754 MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
1755 MODULE_LICENSE("GPL");
1757 module_init(tape_3590_init
);
1758 module_exit(tape_3590_exit
);