2 * drivers/s390/char/tape_3590.c
3 * tape device discipline for 3590 tapes.
5 * Copyright (C) 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/config.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/bio.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
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",
102 tape_3590_ioctl(struct tape_device
*device
, unsigned int cmd
, unsigned long arg
)
105 case TAPE390_DISPLAY
: {
106 struct display_struct disp
;
108 if (copy_from_user(&disp
, (char __user
*) arg
, sizeof(disp
)))
111 return tape_std_display(device
, &disp
);
114 return -EINVAL
; /* no additional ioctls */
119 * SENSE Medium: Get Sense data about medium state
122 tape_3590_sense_medium(struct tape_device
*device
)
124 struct tape_request
*request
;
126 request
= tape_alloc_request(1, 128);
128 return PTR_ERR(request
);
129 request
->op
= TO_MSEN
;
130 tape_ccw_end(request
->cpaddr
, MEDIUM_SENSE
, 128, request
->cpdata
);
131 return tape_do_io_free(device
, request
);
135 * MTTELL: Tell block. Return the number of block relative to current file.
138 tape_3590_mttell(struct tape_device
*device
, int mt_count
)
143 rc
= tape_std_read_block_id(device
, &block_id
);
146 return block_id
>> 32;
150 * MTSEEK: seek to the specified block.
153 tape_3590_mtseek(struct tape_device
*device
, int count
)
155 struct tape_request
*request
;
157 DBF_EVENT(6, "xsee id: %x\n", count
);
158 request
= tape_alloc_request(3, 4);
160 return PTR_ERR(request
);
161 request
->op
= TO_LBL
;
162 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
163 *(__u32
*) request
->cpdata
= count
;
164 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
165 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
166 return tape_do_io_free(device
, request
);
170 * Read Opposite Error Recovery Function:
171 * Used, when Read Forward does not work
174 tape_3590_read_opposite(struct tape_device
*device
,
175 struct tape_request
*request
)
177 struct tape_3590_disc_data
*data
;
180 * We have allocated 4 ccws in tape_std_read, so we can now
181 * transform the request to a read backward, followed by a
182 * forward space block.
184 request
->op
= TO_RBA
;
185 tape_ccw_cc(request
->cpaddr
, MODE_SET_DB
, 1, device
->modeset_byte
);
186 data
= device
->discdata
;
187 tape_ccw_cc_idal(request
->cpaddr
+ 1, data
->read_back_op
,
188 device
->char_data
.idal_buf
);
189 tape_ccw_cc(request
->cpaddr
+ 2, FORSPACEBLOCK
, 0, NULL
);
190 tape_ccw_end(request
->cpaddr
+ 3, NOP
, 0, NULL
);
191 DBF_EVENT(6, "xrop ccwg\n");
196 * This should be done after an interrupt with attention bit (0x80)
199 * After a "read attention message" request there are two possible
202 * 1. A unit check is presented, when attention sense is present (e.g. when
203 * a medium has been unloaded). The attention sense comes then
204 * together with the unit check. The recovery action is either "retry"
205 * (in case there is an attention message pending) or "permanent error".
207 * 2. The attention msg is written to the "read subsystem data" buffer.
208 * In this case we probably should print it to the console.
211 tape_3590_read_attmsg(struct tape_device
*device
)
213 struct tape_request
*request
;
216 request
= tape_alloc_request(3, 4096);
218 return PTR_ERR(request
);
219 request
->op
= TO_READ_ATTMSG
;
220 buf
= request
->cpdata
;
221 buf
[0] = PREP_RD_SS_DATA
;
222 buf
[6] = RD_ATTMSG
; /* read att msg */
223 tape_ccw_cc(request
->cpaddr
, PERFORM_SS_FUNC
, 12, buf
);
224 tape_ccw_cc(request
->cpaddr
+ 1, READ_SS_DATA
, 4096 - 12, buf
+ 12);
225 tape_ccw_end(request
->cpaddr
+ 2, NOP
, 0, NULL
);
226 return tape_do_io_free(device
, request
);
230 * These functions are used to schedule follow-up actions from within an
231 * interrupt context (like unsolicited interrupts).
234 tape_3590_work_handler(void *data
)
237 struct tape_device
*device
;
239 struct work_struct work
;
244 tape_3590_sense_medium(p
->device
);
247 tape_3590_read_attmsg(p
->device
);
250 DBF_EVENT(3, "T3590: work handler undefined for "
251 "operation 0x%02x\n", p
->op
);
253 tape_put_device(p
->device
);
258 tape_3590_schedule_work(struct tape_device
*device
, enum tape_op op
)
261 struct tape_device
*device
;
263 struct work_struct work
;
266 if ((p
= kzalloc(sizeof(*p
), GFP_ATOMIC
)) == NULL
)
269 INIT_WORK(&p
->work
, tape_3590_work_handler
, p
);
271 p
->device
= tape_get_device_reference(device
);
274 schedule_work(&p
->work
);
278 #ifdef CONFIG_S390_TAPE_BLOCK
282 static struct tape_request
*
283 tape_3590_bread(struct tape_device
*device
, struct request
*req
)
285 struct tape_request
*request
;
287 int count
= 0, start_block
, i
;
293 DBF_EVENT(6, "xBREDid:");
294 start_block
= req
->sector
>> TAPEBLOCK_HSEC_S2B
;
295 DBF_EVENT(6, "start_block = %i\n", start_block
);
297 rq_for_each_bio(bio
, req
) {
298 bio_for_each_segment(bv
, bio
, i
) {
299 count
+= bv
->bv_len
>> (TAPEBLOCK_HSEC_S2B
+ 9);
302 request
= tape_alloc_request(2 + count
+ 1, 4);
305 request
->op
= TO_BLOCK
;
306 *(__u32
*) request
->cpdata
= start_block
;
307 ccw
= request
->cpaddr
;
308 ccw
= tape_ccw_cc(ccw
, MODE_SET_DB
, 1, device
->modeset_byte
);
311 * We always setup a nop after the mode set ccw. This slot is
312 * used in tape_std_check_locate to insert a locate ccw if the
313 * current tape position doesn't match the start block to be read.
315 ccw
= tape_ccw_cc(ccw
, NOP
, 0, NULL
);
317 rq_for_each_bio(bio
, req
) {
318 bio_for_each_segment(bv
, bio
, i
) {
319 dst
= kmap(bv
->bv_page
) + bv
->bv_offset
;
320 for (off
= 0; off
< bv
->bv_len
;
321 off
+= TAPEBLOCK_HSEC_SIZE
) {
322 ccw
->flags
= CCW_FLAG_CC
;
323 ccw
->cmd_code
= READ_FORWARD
;
324 ccw
->count
= TAPEBLOCK_HSEC_SIZE
;
325 set_normalized_cda(ccw
, (void *) __pa(dst
));
327 dst
+= TAPEBLOCK_HSEC_SIZE
;
329 if (off
> bv
->bv_len
)
333 ccw
= tape_ccw_end(ccw
, NOP
, 0, NULL
);
334 DBF_EVENT(6, "xBREDccwg\n");
339 tape_3590_free_bread(struct tape_request
*request
)
343 /* Last ccw is a nop and doesn't need clear_normalized_cda */
344 for (ccw
= request
->cpaddr
; ccw
->flags
& CCW_FLAG_CC
; ccw
++)
345 if (ccw
->cmd_code
== READ_FORWARD
)
346 clear_normalized_cda(ccw
);
347 tape_free_request(request
);
351 * check_locate is called just before the tape request is passed to
352 * the common io layer for execution. It has to check the current
353 * tape position and insert a locate ccw if it doesn't match the
354 * start block for the request.
357 tape_3590_check_locate(struct tape_device
*device
, struct tape_request
*request
)
361 start_block
= (__u32
*) request
->cpdata
;
362 if (*start_block
!= device
->blk_data
.block_position
) {
363 /* Add the start offset of the file to get the real block. */
364 *start_block
+= device
->bof
;
365 tape_ccw_cc(request
->cpaddr
+ 1, LOCATE
, 4, request
->cpdata
);
371 * The done handler is called at device/channel end and wakes up the sleeping
375 tape_3590_done(struct tape_device
*device
, struct tape_request
*request
)
377 struct tape_3590_med_sense
*sense
;
379 DBF_EVENT(6, "%s done\n", tape_op_verbose
[request
->op
]);
381 switch (request
->op
) {
395 tape_med_state_set(device
, MS_LOADED
);
398 tape_med_state_set(device
, MS_UNLOADED
);
401 sense
= (struct tape_3590_med_sense
*) request
->cpdata
;
402 if (sense
->masst
== MSENSE_UNASSOCIATED
)
403 tape_med_state_set(device
, MS_UNLOADED
);
404 if (sense
->masst
== MSENSE_ASSOCIATED_MOUNT
)
405 tape_med_state_set(device
, MS_LOADED
);
407 case TO_RBI
: /* RBI seems to succeed even without medium loaded. */
408 case TO_NOP
: /* Same to NOP. */
418 return TAPE_IO_SUCCESS
;
422 * This fuction is called, when error recovery was successfull
425 tape_3590_erp_succeded(struct tape_device
*device
, struct tape_request
*request
)
427 DBF_EVENT(3, "Error Recovery successfull for %s\n",
428 tape_op_verbose
[request
->op
]);
429 return tape_3590_done(device
, request
);
433 * This fuction is called, when error recovery was not successfull
436 tape_3590_erp_failed(struct tape_device
*device
, struct tape_request
*request
,
437 struct irb
*irb
, int rc
)
439 DBF_EVENT(3, "Error Recovery failed for %s\n",
440 tape_op_verbose
[request
->op
]);
441 tape_dump_sense_dbf(device
, request
, irb
);
446 * Error Recovery do retry
449 tape_3590_erp_retry(struct tape_device
*device
, struct tape_request
*request
,
452 DBF_EVENT(2, "Retry: %s\n", tape_op_verbose
[request
->op
]);
453 tape_dump_sense_dbf(device
, request
, irb
);
454 return TAPE_IO_RETRY
;
458 * Handle unsolicited interrupts
461 tape_3590_unsolicited_irq(struct tape_device
*device
, struct irb
*irb
)
463 if (irb
->scsw
.dstat
== DEV_STAT_CHN_END
)
464 /* Probably result of halt ssch */
465 return TAPE_IO_PENDING
;
466 else if (irb
->scsw
.dstat
== 0x85)
467 /* Device Ready -> check medium state */
468 tape_3590_schedule_work(device
, TO_MSEN
);
469 else if (irb
->scsw
.dstat
& DEV_STAT_ATTENTION
)
470 tape_3590_schedule_work(device
, TO_READ_ATTMSG
);
472 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device
->cdev_id
);
473 PRINT_WARN("Unsolicited IRQ (Device End) caught.\n");
474 tape_dump_sense(device
, NULL
, irb
);
476 return TAPE_IO_SUCCESS
;
480 * Basic Recovery routine
483 tape_3590_erp_basic(struct tape_device
*device
, struct tape_request
*request
,
484 struct irb
*irb
, int rc
)
486 struct tape_3590_sense
*sense
;
488 sense
= (struct tape_3590_sense
*) irb
->ecw
;
490 switch (sense
->bra
) {
492 return tape_3590_erp_failed(device
, request
, irb
, rc
);
494 return tape_3590_erp_succeded(device
, request
);
496 return tape_3590_erp_retry(device
, request
, irb
);
498 return tape_3590_erp_failed(device
, request
, irb
, rc
);
500 PRINT_ERR("Unknown BRA %x - This should not happen!\n",
508 * RDL: Read Device (buffered) log
511 tape_3590_erp_read_buf_log(struct tape_device
*device
,
512 struct tape_request
*request
, struct irb
*irb
)
515 * We just do the basic error recovery at the moment (retry).
516 * Perhaps in the future, we read the log and dump it somewhere...
518 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
525 tape_3590_erp_swap(struct tape_device
*device
, struct tape_request
*request
,
529 * This error recovery should swap the tapes
530 * if the original has a problem. The operation
531 * should proceed with the new tape... this
532 * should probably be done in user space!
534 PRINT_WARN("(%s): Swap Tape Device!\n", device
->cdev
->dev
.bus_id
);
535 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
542 tape_3590_erp_long_busy(struct tape_device
*device
,
543 struct tape_request
*request
, struct irb
*irb
)
545 /* FIXME: how about WAITING for a minute ? */
546 PRINT_WARN("(%s): Device is busy! Please wait a minute!\n",
547 device
->cdev
->dev
.bus_id
);
548 return tape_3590_erp_basic(device
, request
, irb
, -EBUSY
);
552 * SPI: Special Intercept
555 tape_3590_erp_special_interrupt(struct tape_device
*device
,
556 struct tape_request
*request
, struct irb
*irb
)
558 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
562 * RDA: Read Alternate
565 tape_3590_erp_read_alternate(struct tape_device
*device
,
566 struct tape_request
*request
, struct irb
*irb
)
568 struct tape_3590_disc_data
*data
;
571 * The issued Read Backward or Read Previous command is not
572 * supported by the device
573 * The recovery action should be to issue another command:
574 * Read Revious: if Read Backward is not supported
575 * Read Backward: if Read Previous is not supported
577 data
= device
->discdata
;
578 if (data
->read_back_op
== READ_PREVIOUS
) {
579 DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
581 data
->read_back_op
= READ_BACKWARD
;
583 DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
585 data
->read_back_op
= READ_PREVIOUS
;
587 tape_3590_read_opposite(device
, request
);
588 return tape_3590_erp_retry(device
, request
, irb
);
592 * Error Recovery read opposite
595 tape_3590_erp_read_opposite(struct tape_device
*device
,
596 struct tape_request
*request
, struct irb
*irb
)
598 switch (request
->op
) {
601 * We did read forward, but the data could not be read.
602 * We will read backward and then skip forward again.
604 tape_3590_read_opposite(device
, request
);
605 return tape_3590_erp_retry(device
, request
, irb
);
607 /* We tried to read forward and backward, but hat no success */
608 return tape_3590_erp_failed(device
, request
, irb
, -EIO
);
611 PRINT_WARN("read_opposite_recovery_called_with_op: %s\n",
612 tape_op_verbose
[request
->op
]);
613 return tape_3590_erp_failed(device
, request
, irb
, -EIO
);
618 * Print an MIM (Media Information Message) (message code f0)
621 tape_3590_print_mim_msg_f0(struct tape_device
*device
, struct irb
*irb
)
623 struct tape_3590_sense
*sense
;
625 sense
= (struct tape_3590_sense
*) irb
->ecw
;
626 /* Exception Message */
627 switch (sense
->fmt
.f70
.emc
) {
629 PRINT_WARN("(%s): Data degraded\n", device
->cdev
->dev
.bus_id
);
632 PRINT_WARN("(%s): Data degraded in partion %i\n",
633 device
->cdev
->dev
.bus_id
, sense
->fmt
.f70
.mp
);
636 PRINT_WARN("(%s): Medium degraded\n", device
->cdev
->dev
.bus_id
);
639 PRINT_WARN("(%s): Medium degraded in partition %i\n",
640 device
->cdev
->dev
.bus_id
, sense
->fmt
.f70
.mp
);
643 PRINT_WARN("(%s): Block 0 Error\n", device
->cdev
->dev
.bus_id
);
646 PRINT_WARN("(%s): Medium Exception 0x%02x\n",
647 device
->cdev
->dev
.bus_id
, sense
->fmt
.f70
.md
);
650 PRINT_WARN("(%s): MIM ExMsg: 0x%02x\n",
651 device
->cdev
->dev
.bus_id
, sense
->fmt
.f70
.emc
);
654 /* Service Message */
655 switch (sense
->fmt
.f70
.smc
) {
657 PRINT_WARN("(%s): Reference Media maintenance procedure %i\n",
658 device
->cdev
->dev
.bus_id
, sense
->fmt
.f70
.md
);
661 PRINT_WARN("(%s): MIM ServiceMsg: 0x%02x\n",
662 device
->cdev
->dev
.bus_id
, sense
->fmt
.f70
.smc
);
668 * Print an I/O Subsystem Service Information Message (message code f1)
671 tape_3590_print_io_sim_msg_f1(struct tape_device
*device
, struct irb
*irb
)
673 struct tape_3590_sense
*sense
;
675 sense
= (struct tape_3590_sense
*) irb
->ecw
;
676 /* Exception Message */
677 switch (sense
->fmt
.f71
.emc
) {
679 PRINT_WARN("(%s): Effect of failure is unknown\n",
680 device
->cdev
->dev
.bus_id
);
683 PRINT_WARN("(%s): CU Exception - no performance impact\n",
684 device
->cdev
->dev
.bus_id
);
687 PRINT_WARN("(%s): CU Exception on channel interface 0x%02x\n",
688 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
691 PRINT_WARN("(%s): CU Exception on device path 0x%02x\n",
692 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
695 PRINT_WARN("(%s): CU Exception on library path 0x%02x\n",
696 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
699 PRINT_WARN("(%s): CU Exception on node 0x%02x\n",
700 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
703 PRINT_WARN("(%s): CU Exception on partition 0x%02x\n",
704 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
707 PRINT_WARN("(%s): SIM ExMsg: 0x%02x\n",
708 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.emc
);
710 /* Service Message */
711 switch (sense
->fmt
.f71
.smc
) {
713 PRINT_WARN("(%s): Repair impact is unknown\n",
714 device
->cdev
->dev
.bus_id
);
717 PRINT_WARN("(%s): Repair will not impact cu performance\n",
718 device
->cdev
->dev
.bus_id
);
721 if (sense
->fmt
.f71
.mdf
== 0)
722 PRINT_WARN("(%s): Repair will disable node "
724 device
->cdev
->dev
.bus_id
,
725 sense
->fmt
.f71
.md
[1]);
727 PRINT_WARN("(%s): Repair will disable nodes "
728 "(0x%x-0x%x) on CU\n",
729 device
->cdev
->dev
.bus_id
,
730 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
733 if (sense
->fmt
.f71
.mdf
== 0)
734 PRINT_WARN("(%s): Repair will disable cannel path "
736 device
->cdev
->dev
.bus_id
,
737 sense
->fmt
.f71
.md
[1]);
739 PRINT_WARN("(%s): Repair will disable cannel paths "
740 "(0x%x-0x%x) on CU\n",
741 device
->cdev
->dev
.bus_id
,
742 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
745 if (sense
->fmt
.f71
.mdf
== 0)
746 PRINT_WARN("(%s): Repair will disable device path "
748 device
->cdev
->dev
.bus_id
,
749 sense
->fmt
.f71
.md
[1]);
751 PRINT_WARN("(%s): Repair will disable device paths "
752 "(0x%x-0x%x) on CU\n",
753 device
->cdev
->dev
.bus_id
,
754 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
757 if (sense
->fmt
.f71
.mdf
== 0)
758 PRINT_WARN("(%s): Repair will disable library path "
760 device
->cdev
->dev
.bus_id
,
761 sense
->fmt
.f71
.md
[1]);
763 PRINT_WARN("(%s): Repair will disable library paths "
764 "(0x%x-0x%x) on CU\n",
765 device
->cdev
->dev
.bus_id
,
766 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
769 PRINT_WARN("(%s): Repair will disable access to CU\n",
770 device
->cdev
->dev
.bus_id
);
773 PRINT_WARN("(%s): SIM ServiceMsg: 0x%02x\n",
774 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.smc
);
779 * Print an Device Subsystem Service Information Message (message code f2)
782 tape_3590_print_dev_sim_msg_f2(struct tape_device
*device
, struct irb
*irb
)
784 struct tape_3590_sense
*sense
;
786 sense
= (struct tape_3590_sense
*) irb
->ecw
;
787 /* Exception Message */
788 switch (sense
->fmt
.f71
.emc
) {
790 PRINT_WARN("(%s): Effect of failure is unknown\n",
791 device
->cdev
->dev
.bus_id
);
794 PRINT_WARN("(%s): DV Exception - no performance impact\n",
795 device
->cdev
->dev
.bus_id
);
798 PRINT_WARN("(%s): DV Exception on channel interface 0x%02x\n",
799 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
802 PRINT_WARN("(%s): DV Exception on loader 0x%02x\n",
803 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
806 PRINT_WARN("(%s): DV Exception on message display 0x%02x\n",
807 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.md
[0]);
810 PRINT_WARN("(%s): DV Exception in tape path\n",
811 device
->cdev
->dev
.bus_id
);
814 PRINT_WARN("(%s): DV Exception in drive\n",
815 device
->cdev
->dev
.bus_id
);
818 PRINT_WARN("(%s): DSIM ExMsg: 0x%02x\n",
819 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.emc
);
821 /* Service Message */
822 switch (sense
->fmt
.f71
.smc
) {
824 PRINT_WARN("(%s): Repair impact is unknown\n",
825 device
->cdev
->dev
.bus_id
);
828 PRINT_WARN("(%s): Repair will not impact device performance\n",
829 device
->cdev
->dev
.bus_id
);
832 if (sense
->fmt
.f71
.mdf
== 0)
833 PRINT_WARN("(%s): Repair will disable channel path "
835 device
->cdev
->dev
.bus_id
,
836 sense
->fmt
.f71
.md
[1]);
838 PRINT_WARN("(%s): Repair will disable channel path "
839 "(0x%x-0x%x) on DV\n",
840 device
->cdev
->dev
.bus_id
,
841 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
844 if (sense
->fmt
.f71
.mdf
== 0)
845 PRINT_WARN("(%s): Repair will disable interface 0x%x "
847 device
->cdev
->dev
.bus_id
,
848 sense
->fmt
.f71
.md
[1]);
850 PRINT_WARN("(%s): Repair will disable interfaces "
851 "(0x%x-0x%x) on DV\n",
852 device
->cdev
->dev
.bus_id
,
853 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
856 if (sense
->fmt
.f71
.mdf
== 0)
857 PRINT_WARN("(%s): Repair will disable loader 0x%x "
859 device
->cdev
->dev
.bus_id
,
860 sense
->fmt
.f71
.md
[1]);
862 PRINT_WARN("(%s): Repair will disable loader "
863 "(0x%x-0x%x) on DV\n",
864 device
->cdev
->dev
.bus_id
,
865 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
868 PRINT_WARN("(%s): Repair will disable access to DV\n",
869 device
->cdev
->dev
.bus_id
);
872 if (sense
->fmt
.f71
.mdf
== 0)
873 PRINT_WARN("(%s): Repair will disable message "
874 "display 0x%x on DV\n",
875 device
->cdev
->dev
.bus_id
,
876 sense
->fmt
.f71
.md
[1]);
878 PRINT_WARN("(%s): Repair will disable message "
879 "displays (0x%x-0x%x) on DV\n",
880 device
->cdev
->dev
.bus_id
,
881 sense
->fmt
.f71
.md
[1], sense
->fmt
.f71
.md
[2]);
884 PRINT_WARN("(%s): Clean DV\n", device
->cdev
->dev
.bus_id
);
887 PRINT_WARN("(%s): DSIM ServiceMsg: 0x%02x\n",
888 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.smc
);
893 * Print standard ERA Message
896 tape_3590_print_era_msg(struct tape_device
*device
, struct irb
*irb
)
898 struct tape_3590_sense
*sense
;
900 sense
= (struct tape_3590_sense
*) irb
->ecw
;
903 if ((sense
->mc
> 0) && (sense
->mc
< TAPE_3590_MAX_MSG
)) {
904 if (tape_3590_msg
[sense
->mc
] != NULL
)
905 PRINT_WARN("(%s): %s\n", device
->cdev
->dev
.bus_id
,
906 tape_3590_msg
[sense
->mc
]);
908 PRINT_WARN("(%s): Message Code 0x%x\n",
909 device
->cdev
->dev
.bus_id
, sense
->mc
);
913 if (sense
->mc
== 0xf0) {
914 /* Standard Media Information Message */
915 PRINT_WARN("(%s): MIM SEV=%i, MC=%02x, ES=%x/%x, "
916 "RC=%02x-%04x-%02x\n", device
->cdev
->dev
.bus_id
,
917 sense
->fmt
.f70
.sev
, sense
->mc
,
918 sense
->fmt
.f70
.emc
, sense
->fmt
.f70
.smc
,
919 sense
->fmt
.f70
.refcode
, sense
->fmt
.f70
.mid
,
921 tape_3590_print_mim_msg_f0(device
, irb
);
924 if (sense
->mc
== 0xf1) {
925 /* Standard I/O Subsystem Service Information Message */
926 PRINT_WARN("(%s): IOSIM SEV=%i, DEVTYPE=3590/%02x, "
927 "MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
928 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.sev
,
929 device
->cdev
->id
.dev_model
,
930 sense
->mc
, sense
->fmt
.f71
.emc
,
931 sense
->fmt
.f71
.smc
, sense
->fmt
.f71
.refcode1
,
932 sense
->fmt
.f71
.refcode2
, sense
->fmt
.f71
.refcode3
);
933 tape_3590_print_io_sim_msg_f1(device
, irb
);
936 if (sense
->mc
== 0xf2) {
937 /* Standard Device Service Information Message */
938 PRINT_WARN("(%s): DEVSIM SEV=%i, DEVTYPE=3590/%02x, "
939 "MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
940 device
->cdev
->dev
.bus_id
, sense
->fmt
.f71
.sev
,
941 device
->cdev
->id
.dev_model
,
942 sense
->mc
, sense
->fmt
.f71
.emc
,
943 sense
->fmt
.f71
.smc
, sense
->fmt
.f71
.refcode1
,
944 sense
->fmt
.f71
.refcode2
, sense
->fmt
.f71
.refcode3
);
945 tape_3590_print_dev_sim_msg_f2(device
, irb
);
948 if (sense
->mc
== 0xf3) {
949 /* Standard Library Service Information Message */
952 PRINT_WARN("(%s): Device Message(%x)\n",
953 device
->cdev
->dev
.bus_id
, sense
->mc
);
957 * 3590 error Recovery routine:
958 * If possible, it tries to recover from the error. If this is not possible,
959 * inform the user about the problem.
962 tape_3590_unit_check(struct tape_device
*device
, struct tape_request
*request
,
965 struct tape_3590_sense
*sense
;
968 #ifdef CONFIG_S390_TAPE_BLOCK
969 if (request
->op
== TO_BLOCK
) {
971 * Recovery for block device requests. Set the block_position
972 * to something invalid and retry.
974 device
->blk_data
.block_position
= -1;
975 if (request
->retries
-- <= 0)
976 return tape_3590_erp_failed(device
, request
, irb
, -EIO
);
978 return tape_3590_erp_retry(device
, request
, irb
);
982 sense
= (struct tape_3590_sense
*) irb
->ecw
;
985 * First check all RC-QRCs where we want to do something special
986 * - "break": basic error recovery is done
987 * - "goto out:": just print error message if available
990 switch (sense
->rc_rqc
) {
993 tape_3590_print_era_msg(device
, irb
);
994 return tape_3590_erp_read_buf_log(device
, request
, irb
);
997 tape_3590_print_era_msg(device
, irb
);
998 return tape_3590_erp_read_alternate(device
, request
, irb
);
1002 tape_3590_print_era_msg(device
, irb
);
1003 return tape_3590_erp_special_interrupt(device
, request
, irb
);
1006 DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1008 return tape_3590_erp_basic(device
, request
, irb
, -ENOSPC
);
1010 DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1012 return tape_3590_erp_basic(device
, request
, irb
, -ENOSPC
);
1014 DBF_EVENT(2, "(%08x): End of Data Mark\n", device
->cdev_id
);
1015 return tape_3590_erp_basic(device
, request
, irb
, -ENOSPC
);
1018 DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1020 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
1022 DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1024 tape_med_state_set(device
, MS_UNLOADED
);
1025 return tape_3590_erp_basic(device
, request
, irb
, 0);
1029 * print additional msg since default msg
1030 * "device intervention" is not very meaningfull
1032 PRINT_WARN("(%s): Tape operation when medium not loaded\n",
1033 device
->cdev
->dev
.bus_id
);
1034 tape_med_state_set(device
, MS_UNLOADED
);
1035 return tape_3590_erp_basic(device
, request
, irb
, -ENOMEDIUM
);
1036 case 0x4012: /* Device Long Busy */
1037 tape_3590_print_era_msg(device
, irb
);
1038 return tape_3590_erp_long_busy(device
, request
, irb
);
1041 if (sense
->rac
== 0xd0) {
1043 tape_3590_print_era_msg(device
, irb
);
1044 return tape_3590_erp_swap(device
, request
, irb
);
1046 if (sense
->rac
== 0x26) {
1048 tape_3590_print_era_msg(device
, irb
);
1049 return tape_3590_erp_read_opposite(device
, request
,
1052 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
1059 tape_3590_print_era_msg(device
, irb
);
1060 return tape_3590_erp_swap(device
, request
, irb
);
1064 return tape_3590_erp_basic(device
, request
, irb
, -EMEDIUMTYPE
);
1068 tape_med_state_set(device
, MS_UNLOADED
);
1069 return tape_3590_erp_basic(device
, request
, irb
, -ENOMEDIUM
);
1072 PRINT_WARN("(%s): Cartridge of wrong type ?\n",
1073 device
->cdev
->dev
.bus_id
);
1074 return tape_3590_erp_basic(device
, request
, irb
, -EMEDIUMTYPE
);
1077 PRINT_WARN("(%s): Another host has reserved the tape device\n",
1078 device
->cdev
->dev
.bus_id
);
1079 return tape_3590_erp_basic(device
, request
, irb
, -EPERM
);
1081 PRINT_WARN("(%s): Another host has priviliged access to the "
1082 "tape device\n", device
->cdev
->dev
.bus_id
);
1083 PRINT_WARN("(%s): To solve the problem unload the current "
1084 "cartridge!\n", device
->cdev
->dev
.bus_id
);
1085 return tape_3590_erp_basic(device
, request
, irb
, -EPERM
);
1087 return tape_3590_erp_basic(device
, request
, irb
, -EIO
);
1092 * 3590 interrupt handler:
1095 tape_3590_irq(struct tape_device
*device
, struct tape_request
*request
,
1098 if (request
== NULL
)
1099 return tape_3590_unsolicited_irq(device
, irb
);
1101 if ((irb
->scsw
.dstat
& DEV_STAT_UNIT_EXCEP
) &&
1102 (irb
->scsw
.dstat
& DEV_STAT_DEV_END
) && (request
->op
== TO_WRI
)) {
1103 /* Write at end of volume */
1104 DBF_EVENT(2, "End of volume\n");
1105 return tape_3590_erp_failed(device
, request
, irb
, -ENOSPC
);
1108 if (irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
)
1109 return tape_3590_unit_check(device
, request
, irb
);
1111 if (irb
->scsw
.dstat
& DEV_STAT_DEV_END
) {
1112 if (irb
->scsw
.dstat
== DEV_STAT_UNIT_EXCEP
) {
1113 if (request
->op
== TO_FSB
|| request
->op
== TO_BSB
)
1116 DBF_EVENT(5, "Unit Exception!\n");
1119 return tape_3590_done(device
, request
);
1122 if (irb
->scsw
.dstat
& DEV_STAT_CHN_END
) {
1123 DBF_EVENT(2, "cannel end\n");
1124 return TAPE_IO_PENDING
;
1127 if (irb
->scsw
.dstat
& DEV_STAT_ATTENTION
) {
1128 DBF_EVENT(2, "Unit Attention when busy..\n");
1129 return TAPE_IO_PENDING
;
1132 DBF_EVENT(6, "xunknownirq\n");
1133 PRINT_ERR("Unexpected interrupt.\n");
1134 PRINT_ERR("Current op is: %s", tape_op_verbose
[request
->op
]);
1135 tape_dump_sense(device
, request
, irb
);
1136 return TAPE_IO_STOP
;
1140 * Setup device function
1143 tape_3590_setup_device(struct tape_device
*device
)
1146 struct tape_3590_disc_data
*data
;
1148 DBF_EVENT(6, "3590 device setup\n");
1149 data
= kmalloc(sizeof(struct tape_3590_disc_data
),
1150 GFP_KERNEL
| GFP_DMA
);
1153 data
->read_back_op
= READ_PREVIOUS
;
1154 device
->discdata
= data
;
1156 if ((rc
= tape_std_assign(device
)) == 0) {
1157 /* Try to find out if medium is loaded */
1158 if ((rc
= tape_3590_sense_medium(device
)) != 0)
1159 DBF_LH(3, "3590 medium sense returned %d\n", rc
);
1166 * Cleanup device function
1169 tape_3590_cleanup_device(struct tape_device
*device
)
1171 tape_std_unassign(device
);
1173 kfree(device
->discdata
);
1174 device
->discdata
= NULL
;
1178 * List of 3590 magnetic tape commands.
1180 static tape_mtop_fn tape_3590_mtop
[TAPE_NR_MTOPS
] = {
1181 [MTRESET
] = tape_std_mtreset
,
1182 [MTFSF
] = tape_std_mtfsf
,
1183 [MTBSF
] = tape_std_mtbsf
,
1184 [MTFSR
] = tape_std_mtfsr
,
1185 [MTBSR
] = tape_std_mtbsr
,
1186 [MTWEOF
] = tape_std_mtweof
,
1187 [MTREW
] = tape_std_mtrew
,
1188 [MTOFFL
] = tape_std_mtoffl
,
1189 [MTNOP
] = tape_std_mtnop
,
1190 [MTRETEN
] = tape_std_mtreten
,
1191 [MTBSFM
] = tape_std_mtbsfm
,
1192 [MTFSFM
] = tape_std_mtfsfm
,
1193 [MTEOM
] = tape_std_mteom
,
1194 [MTERASE
] = tape_std_mterase
,
1198 [MTSETBLK
] = tape_std_mtsetblk
,
1199 [MTSETDENSITY
] = NULL
,
1200 [MTSEEK
] = tape_3590_mtseek
,
1201 [MTTELL
] = tape_3590_mttell
,
1202 [MTSETDRVBUFFER
] = NULL
,
1208 [MTLOAD
] = tape_std_mtload
,
1209 [MTUNLOAD
] = tape_std_mtunload
,
1210 [MTCOMPRESSION
] = tape_std_mtcompression
,
1216 * Tape discipline structure for 3590.
1218 static struct tape_discipline tape_discipline_3590
= {
1219 .owner
= THIS_MODULE
,
1220 .setup_device
= tape_3590_setup_device
,
1221 .cleanup_device
= tape_3590_cleanup_device
,
1222 .process_eov
= tape_std_process_eov
,
1223 .irq
= tape_3590_irq
,
1224 .read_block
= tape_std_read_block
,
1225 .write_block
= tape_std_write_block
,
1226 #ifdef CONFIG_S390_TAPE_BLOCK
1227 .bread
= tape_3590_bread
,
1228 .free_bread
= tape_3590_free_bread
,
1229 .check_locate
= tape_3590_check_locate
,
1231 .ioctl_fn
= tape_3590_ioctl
,
1232 .mtop_array
= tape_3590_mtop
1235 static struct ccw_device_id tape_3590_ids
[] = {
1236 {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info
= tape_3590
},
1237 { /* end of list */ }
1241 tape_3590_online(struct ccw_device
*cdev
)
1243 return tape_generic_online(cdev
->dev
.driver_data
,
1244 &tape_discipline_3590
);
1248 tape_3590_offline(struct ccw_device
*cdev
)
1250 return tape_generic_offline(cdev
->dev
.driver_data
);
1253 static struct ccw_driver tape_3590_driver
= {
1254 .name
= "tape_3590",
1255 .owner
= THIS_MODULE
,
1256 .ids
= tape_3590_ids
,
1257 .probe
= tape_generic_probe
,
1258 .remove
= tape_generic_remove
,
1259 .set_offline
= tape_3590_offline
,
1260 .set_online
= tape_3590_online
,
1264 * Setup discipline structure.
1267 tape_3590_init(void)
1271 TAPE_DBF_AREA
= debug_register("tape_3590", 2, 2, 4 * sizeof(long));
1272 debug_register_view(TAPE_DBF_AREA
, &debug_sprintf_view
);
1273 #ifdef DBF_LIKE_HELL
1274 debug_set_level(TAPE_DBF_AREA
, 6);
1277 DBF_EVENT(3, "3590 init\n");
1278 /* Register driver for 3590 tapes. */
1279 rc
= ccw_driver_register(&tape_3590_driver
);
1281 DBF_EVENT(3, "3590 init failed\n");
1283 DBF_EVENT(3, "3590 registered\n");
1288 tape_3590_exit(void)
1290 ccw_driver_unregister(&tape_3590_driver
);
1292 debug_unregister(TAPE_DBF_AREA
);
1295 MODULE_DEVICE_TABLE(ccw
, tape_3590_ids
);
1296 MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
1297 MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
1298 MODULE_LICENSE("GPL");
1300 module_init(tape_3590_init
);
1301 module_exit(tape_3590_exit
);