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).
233 struct work_handler_data {
234 struct tape_device *device;
236 struct work_struct work;
240 tape_3590_work_handler(void *data)
242 struct work_handler_data *p = data;
246 tape_3590_sense_medium(p->device);
249 tape_3590_read_attmsg(p->device);
252 DBF_EVENT(3, "T3590: work handler undefined for "
253 "operation 0x%02x\n", p->op);
255 tape_put_device(p->device);
260 tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
262 struct work_handler_data *p;
264 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
267 INIT_WORK(&p->work, tape_3590_work_handler, p);
269 p->device = tape_get_device_reference(device);
272 schedule_work(&p->work);
276 #ifdef CONFIG_S390_TAPE_BLOCK
280 static struct tape_request *
281 tape_3590_bread(struct tape_device *device, struct request *req)
283 struct tape_request *request;
285 int count = 0, start_block, i;
291 DBF_EVENT(6, "xBREDid:");
292 start_block = req->sector >> TAPEBLOCK_HSEC_S2B;
293 DBF_EVENT(6, "start_block = %i\n", start_block);
295 rq_for_each_bio(bio, req) {
296 bio_for_each_segment(bv, bio, i) {
297 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
300 request = tape_alloc_request(2 + count + 1, 4);
303 request->op = TO_BLOCK;
304 *(__u32 *) request->cpdata = start_block;
305 ccw = request->cpaddr;
306 ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);
309 * We always setup a nop after the mode set ccw. This slot is
310 * used in tape_std_check_locate to insert a locate ccw if the
311 * current tape position doesn't match the start block to be read.
313 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
315 rq_for_each_bio(bio, req) {
316 bio_for_each_segment(bv, bio, i) {
317 dst = page_address(bv->bv_page) + bv->bv_offset;
318 for (off = 0; off < bv->bv_len;
319 off += TAPEBLOCK_HSEC_SIZE) {
320 ccw->flags = CCW_FLAG_CC;
321 ccw->cmd_code = READ_FORWARD;
322 ccw->count = TAPEBLOCK_HSEC_SIZE;
323 set_normalized_cda(ccw, (void *) __pa(dst));
325 dst += TAPEBLOCK_HSEC_SIZE;
327 if (off > bv->bv_len)
331 ccw = tape_ccw_end(ccw, NOP, 0, NULL);
332 DBF_EVENT(6, "xBREDccwg\n");
337 tape_3590_free_bread(struct tape_request *request)
341 /* Last ccw is a nop and doesn't need clear_normalized_cda */
342 for (ccw = request->cpaddr; ccw->flags & CCW_FLAG_CC; ccw++)
343 if (ccw->cmd_code == READ_FORWARD)
344 clear_normalized_cda(ccw);
345 tape_free_request(request);
349 * check_locate is called just before the tape request is passed to
350 * the common io layer for execution. It has to check the current
351 * tape position and insert a locate ccw if it doesn't match the
352 * start block for the request.
355 tape_3590_check_locate(struct tape_device *device, struct tape_request *request)
359 start_block = (__u32 *) request->cpdata;
360 if (*start_block != device->blk_data.block_position) {
361 /* Add the start offset of the file to get the real block. */
362 *start_block += device->bof;
363 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
369 * The done handler is called at device/channel end and wakes up the sleeping
373 tape_3590_done(struct tape_device *device, struct tape_request *request)
375 struct tape_3590_med_sense *sense;
377 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
379 switch (request->op) {
393 tape_med_state_set(device, MS_LOADED);
396 tape_med_state_set(device, MS_UNLOADED);
399 sense = (struct tape_3590_med_sense *) request->cpdata;
400 if (sense->masst == MSENSE_UNASSOCIATED)
401 tape_med_state_set(device, MS_UNLOADED);
402 if (sense->masst == MSENSE_ASSOCIATED_MOUNT)
403 tape_med_state_set(device, MS_LOADED);
405 case TO_RBI: /* RBI seems to succeed even without medium loaded. */
406 case TO_NOP: /* Same to NOP. */
416 return TAPE_IO_SUCCESS;
420 * This fuction is called, when error recovery was successfull
423 tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request)
425 DBF_EVENT(3, "Error Recovery successfull for %s\n",
426 tape_op_verbose[request->op]);
427 return tape_3590_done(device, request);
431 * This fuction is called, when error recovery was not successfull
434 tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
435 struct irb *irb, int rc)
437 DBF_EVENT(3, "Error Recovery failed for %s\n",
438 tape_op_verbose[request->op]);
439 tape_dump_sense_dbf(device, request, irb);
444 * Error Recovery do retry
447 tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
450 DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]);
451 tape_dump_sense_dbf(device, request, irb);
452 return TAPE_IO_RETRY;
456 * Handle unsolicited interrupts
459 tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
461 if (irb->scsw.dstat == DEV_STAT_CHN_END)
462 /* Probably result of halt ssch */
463 return TAPE_IO_PENDING;
464 else if (irb->scsw.dstat == 0x85)
465 /* Device Ready -> check medium state */
466 tape_3590_schedule_work(device, TO_MSEN);
467 else if (irb->scsw.dstat & DEV_STAT_ATTENTION)
468 tape_3590_schedule_work(device, TO_READ_ATTMSG);
470 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
471 PRINT_WARN("Unsolicited IRQ (Device End) caught.\n");
472 tape_dump_sense(device, NULL, irb);
474 return TAPE_IO_SUCCESS;
478 * Basic Recovery routine
481 tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
482 struct irb *irb, int rc)
484 struct tape_3590_sense *sense;
486 sense = (struct tape_3590_sense *) irb->ecw;
488 switch (sense->bra) {
490 return tape_3590_erp_failed(device, request, irb, rc);
492 return tape_3590_erp_succeded(device, request);
494 return tape_3590_erp_retry(device, request, irb);
496 return tape_3590_erp_failed(device, request, irb, rc);
498 PRINT_ERR("Unknown BRA %x - This should not happen!\n",
506 * RDL: Read Device (buffered) log
509 tape_3590_erp_read_buf_log(struct tape_device *device,
510 struct tape_request *request, struct irb *irb)
513 * We just do the basic error recovery at the moment (retry).
514 * Perhaps in the future, we read the log and dump it somewhere...
516 return tape_3590_erp_basic(device, request, irb, -EIO);
523 tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
527 * This error recovery should swap the tapes
528 * if the original has a problem. The operation
529 * should proceed with the new tape... this
530 * should probably be done in user space!
532 PRINT_WARN("(%s): Swap Tape Device!\n", device->cdev->dev.bus_id);
533 return tape_3590_erp_basic(device, request, irb, -EIO);
540 tape_3590_erp_long_busy(struct tape_device *device,
541 struct tape_request *request, struct irb *irb)
543 /* FIXME: how about WAITING for a minute ? */
544 PRINT_WARN("(%s): Device is busy! Please wait a minute!\n",
545 device->cdev->dev.bus_id);
546 return tape_3590_erp_basic(device, request, irb, -EBUSY);
550 * SPI: Special Intercept
553 tape_3590_erp_special_interrupt(struct tape_device *device,
554 struct tape_request *request, struct irb *irb)
556 return tape_3590_erp_basic(device, request, irb, -EIO);
560 * RDA: Read Alternate
563 tape_3590_erp_read_alternate(struct tape_device *device,
564 struct tape_request *request, struct irb *irb)
566 struct tape_3590_disc_data *data;
569 * The issued Read Backward or Read Previous command is not
570 * supported by the device
571 * The recovery action should be to issue another command:
572 * Read Revious: if Read Backward is not supported
573 * Read Backward: if Read Previous is not supported
575 data = device->discdata;
576 if (data->read_back_op == READ_PREVIOUS) {
577 DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
579 data->read_back_op = READ_BACKWARD;
581 DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
583 data->read_back_op = READ_PREVIOUS;
585 tape_3590_read_opposite(device, request);
586 return tape_3590_erp_retry(device, request, irb);
590 * Error Recovery read opposite
593 tape_3590_erp_read_opposite(struct tape_device *device,
594 struct tape_request *request, struct irb *irb)
596 switch (request->op) {
599 * We did read forward, but the data could not be read.
600 * We will read backward and then skip forward again.
602 tape_3590_read_opposite(device, request);
603 return tape_3590_erp_retry(device, request, irb);
605 /* We tried to read forward and backward, but hat no success */
606 return tape_3590_erp_failed(device, request, irb, -EIO);
609 PRINT_WARN("read_opposite_recovery_called_with_op: %s\n",
610 tape_op_verbose[request->op]);
611 return tape_3590_erp_failed(device, request, irb, -EIO);
616 * Print an MIM (Media Information Message) (message code f0)
619 tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
621 struct tape_3590_sense *sense;
623 sense = (struct tape_3590_sense *) irb->ecw;
624 /* Exception Message */
625 switch (sense->fmt.f70.emc) {
627 PRINT_WARN("(%s): Data degraded\n", device->cdev->dev.bus_id);
630 PRINT_WARN("(%s): Data degraded in partion %i\n",
631 device->cdev->dev.bus_id, sense->fmt.f70.mp);
634 PRINT_WARN("(%s): Medium degraded\n", device->cdev->dev.bus_id);
637 PRINT_WARN("(%s): Medium degraded in partition %i\n",
638 device->cdev->dev.bus_id, sense->fmt.f70.mp);
641 PRINT_WARN("(%s): Block 0 Error\n", device->cdev->dev.bus_id);
644 PRINT_WARN("(%s): Medium Exception 0x%02x\n",
645 device->cdev->dev.bus_id, sense->fmt.f70.md);
648 PRINT_WARN("(%s): MIM ExMsg: 0x%02x\n",
649 device->cdev->dev.bus_id, sense->fmt.f70.emc);
652 /* Service Message */
653 switch (sense->fmt.f70.smc) {
655 PRINT_WARN("(%s): Reference Media maintenance procedure %i\n",
656 device->cdev->dev.bus_id, sense->fmt.f70.md);
659 PRINT_WARN("(%s): MIM ServiceMsg: 0x%02x\n",
660 device->cdev->dev.bus_id, sense->fmt.f70.smc);
666 * Print an I/O Subsystem Service Information Message (message code f1)
669 tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
671 struct tape_3590_sense *sense;
673 sense = (struct tape_3590_sense *) irb->ecw;
674 /* Exception Message */
675 switch (sense->fmt.f71.emc) {
677 PRINT_WARN("(%s): Effect of failure is unknown\n",
678 device->cdev->dev.bus_id);
681 PRINT_WARN("(%s): CU Exception - no performance impact\n",
682 device->cdev->dev.bus_id);
685 PRINT_WARN("(%s): CU Exception on channel interface 0x%02x\n",
686 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
689 PRINT_WARN("(%s): CU Exception on device path 0x%02x\n",
690 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
693 PRINT_WARN("(%s): CU Exception on library path 0x%02x\n",
694 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
697 PRINT_WARN("(%s): CU Exception on node 0x%02x\n",
698 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
701 PRINT_WARN("(%s): CU Exception on partition 0x%02x\n",
702 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
705 PRINT_WARN("(%s): SIM ExMsg: 0x%02x\n",
706 device->cdev->dev.bus_id, sense->fmt.f71.emc);
708 /* Service Message */
709 switch (sense->fmt.f71.smc) {
711 PRINT_WARN("(%s): Repair impact is unknown\n",
712 device->cdev->dev.bus_id);
715 PRINT_WARN("(%s): Repair will not impact cu performance\n",
716 device->cdev->dev.bus_id);
719 if (sense->fmt.f71.mdf == 0)
720 PRINT_WARN("(%s): Repair will disable node "
722 device->cdev->dev.bus_id,
723 sense->fmt.f71.md[1]);
725 PRINT_WARN("(%s): Repair will disable nodes "
726 "(0x%x-0x%x) on CU\n",
727 device->cdev->dev.bus_id,
728 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
731 if (sense->fmt.f71.mdf == 0)
732 PRINT_WARN("(%s): Repair will disable cannel path "
734 device->cdev->dev.bus_id,
735 sense->fmt.f71.md[1]);
737 PRINT_WARN("(%s): Repair will disable cannel paths "
738 "(0x%x-0x%x) on CU\n",
739 device->cdev->dev.bus_id,
740 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
743 if (sense->fmt.f71.mdf == 0)
744 PRINT_WARN("(%s): Repair will disable device path "
746 device->cdev->dev.bus_id,
747 sense->fmt.f71.md[1]);
749 PRINT_WARN("(%s): Repair will disable device paths "
750 "(0x%x-0x%x) on CU\n",
751 device->cdev->dev.bus_id,
752 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
755 if (sense->fmt.f71.mdf == 0)
756 PRINT_WARN("(%s): Repair will disable library path "
758 device->cdev->dev.bus_id,
759 sense->fmt.f71.md[1]);
761 PRINT_WARN("(%s): Repair will disable library paths "
762 "(0x%x-0x%x) on CU\n",
763 device->cdev->dev.bus_id,
764 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
767 PRINT_WARN("(%s): Repair will disable access to CU\n",
768 device->cdev->dev.bus_id);
771 PRINT_WARN("(%s): SIM ServiceMsg: 0x%02x\n",
772 device->cdev->dev.bus_id, sense->fmt.f71.smc);
777 * Print an Device Subsystem Service Information Message (message code f2)
780 tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
782 struct tape_3590_sense *sense;
784 sense = (struct tape_3590_sense *) irb->ecw;
785 /* Exception Message */
786 switch (sense->fmt.f71.emc) {
788 PRINT_WARN("(%s): Effect of failure is unknown\n",
789 device->cdev->dev.bus_id);
792 PRINT_WARN("(%s): DV Exception - no performance impact\n",
793 device->cdev->dev.bus_id);
796 PRINT_WARN("(%s): DV Exception on channel interface 0x%02x\n",
797 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
800 PRINT_WARN("(%s): DV Exception on loader 0x%02x\n",
801 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
804 PRINT_WARN("(%s): DV Exception on message display 0x%02x\n",
805 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
808 PRINT_WARN("(%s): DV Exception in tape path\n",
809 device->cdev->dev.bus_id);
812 PRINT_WARN("(%s): DV Exception in drive\n",
813 device->cdev->dev.bus_id);
816 PRINT_WARN("(%s): DSIM ExMsg: 0x%02x\n",
817 device->cdev->dev.bus_id, sense->fmt.f71.emc);
819 /* Service Message */
820 switch (sense->fmt.f71.smc) {
822 PRINT_WARN("(%s): Repair impact is unknown\n",
823 device->cdev->dev.bus_id);
826 PRINT_WARN("(%s): Repair will not impact device performance\n",
827 device->cdev->dev.bus_id);
830 if (sense->fmt.f71.mdf == 0)
831 PRINT_WARN("(%s): Repair will disable channel path "
833 device->cdev->dev.bus_id,
834 sense->fmt.f71.md[1]);
836 PRINT_WARN("(%s): Repair will disable channel path "
837 "(0x%x-0x%x) on DV\n",
838 device->cdev->dev.bus_id,
839 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
842 if (sense->fmt.f71.mdf == 0)
843 PRINT_WARN("(%s): Repair will disable interface 0x%x "
845 device->cdev->dev.bus_id,
846 sense->fmt.f71.md[1]);
848 PRINT_WARN("(%s): Repair will disable interfaces "
849 "(0x%x-0x%x) on DV\n",
850 device->cdev->dev.bus_id,
851 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
854 if (sense->fmt.f71.mdf == 0)
855 PRINT_WARN("(%s): Repair will disable loader 0x%x "
857 device->cdev->dev.bus_id,
858 sense->fmt.f71.md[1]);
860 PRINT_WARN("(%s): Repair will disable loader "
861 "(0x%x-0x%x) on DV\n",
862 device->cdev->dev.bus_id,
863 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
866 PRINT_WARN("(%s): Repair will disable access to DV\n",
867 device->cdev->dev.bus_id);
870 if (sense->fmt.f71.mdf == 0)
871 PRINT_WARN("(%s): Repair will disable message "
872 "display 0x%x on DV\n",
873 device->cdev->dev.bus_id,
874 sense->fmt.f71.md[1]);
876 PRINT_WARN("(%s): Repair will disable message "
877 "displays (0x%x-0x%x) on DV\n",
878 device->cdev->dev.bus_id,
879 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
882 PRINT_WARN("(%s): Clean DV\n", device->cdev->dev.bus_id);
885 PRINT_WARN("(%s): DSIM ServiceMsg: 0x%02x\n",
886 device->cdev->dev.bus_id, sense->fmt.f71.smc);
891 * Print standard ERA Message
894 tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
896 struct tape_3590_sense *sense;
898 sense = (struct tape_3590_sense *) irb->ecw;
901 if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) {
902 if (tape_3590_msg[sense->mc] != NULL)
903 PRINT_WARN("(%s): %s\n", device->cdev->dev.bus_id,
904 tape_3590_msg[sense->mc]);
906 PRINT_WARN("(%s): Message Code 0x%x\n",
907 device->cdev->dev.bus_id, sense->mc);
911 if (sense->mc == 0xf0) {
912 /* Standard Media Information Message */
913 PRINT_WARN("(%s): MIM SEV=%i, MC=%02x, ES=%x/%x, "
914 "RC=%02x-%04x-%02x\n", device->cdev->dev.bus_id,
915 sense->fmt.f70.sev, sense->mc,
916 sense->fmt.f70.emc, sense->fmt.f70.smc,
917 sense->fmt.f70.refcode, sense->fmt.f70.mid,
919 tape_3590_print_mim_msg_f0(device, irb);
922 if (sense->mc == 0xf1) {
923 /* Standard I/O Subsystem Service Information Message */
924 PRINT_WARN("(%s): IOSIM SEV=%i, DEVTYPE=3590/%02x, "
925 "MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
926 device->cdev->dev.bus_id, sense->fmt.f71.sev,
927 device->cdev->id.dev_model,
928 sense->mc, sense->fmt.f71.emc,
929 sense->fmt.f71.smc, sense->fmt.f71.refcode1,
930 sense->fmt.f71.refcode2, sense->fmt.f71.refcode3);
931 tape_3590_print_io_sim_msg_f1(device, irb);
934 if (sense->mc == 0xf2) {
935 /* Standard Device Service Information Message */
936 PRINT_WARN("(%s): DEVSIM SEV=%i, DEVTYPE=3590/%02x, "
937 "MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
938 device->cdev->dev.bus_id, sense->fmt.f71.sev,
939 device->cdev->id.dev_model,
940 sense->mc, sense->fmt.f71.emc,
941 sense->fmt.f71.smc, sense->fmt.f71.refcode1,
942 sense->fmt.f71.refcode2, sense->fmt.f71.refcode3);
943 tape_3590_print_dev_sim_msg_f2(device, irb);
946 if (sense->mc == 0xf3) {
947 /* Standard Library Service Information Message */
950 PRINT_WARN("(%s): Device Message(%x)\n",
951 device->cdev->dev.bus_id, sense->mc);
955 * 3590 error Recovery routine:
956 * If possible, it tries to recover from the error. If this is not possible,
957 * inform the user about the problem.
960 tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
963 struct tape_3590_sense *sense;
966 #ifdef CONFIG_S390_TAPE_BLOCK
967 if (request->op == TO_BLOCK) {
969 * Recovery for block device requests. Set the block_position
970 * to something invalid and retry.
972 device->blk_data.block_position = -1;
973 if (request->retries-- <= 0)
974 return tape_3590_erp_failed(device, request, irb, -EIO);
976 return tape_3590_erp_retry(device, request, irb);
980 sense = (struct tape_3590_sense *) irb->ecw;
983 * First check all RC-QRCs where we want to do something special
984 * - "break": basic error recovery is done
985 * - "goto out:": just print error message if available
988 switch (sense->rc_rqc) {
991 tape_3590_print_era_msg(device, irb);
992 return tape_3590_erp_read_buf_log(device, request, irb);
995 tape_3590_print_era_msg(device, irb);
996 return tape_3590_erp_read_alternate(device, request, irb);
1000 tape_3590_print_era_msg(device, irb);
1001 return tape_3590_erp_special_interrupt(device, request, irb);
1004 DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1006 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1008 DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1010 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1012 DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
1013 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1016 DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1018 return tape_3590_erp_basic(device, request, irb, -EIO);
1020 DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1022 tape_med_state_set(device, MS_UNLOADED);
1023 return tape_3590_erp_basic(device, request, irb, 0);
1027 * print additional msg since default msg
1028 * "device intervention" is not very meaningfull
1030 PRINT_WARN("(%s): Tape operation when medium not loaded\n",
1031 device->cdev->dev.bus_id);
1032 tape_med_state_set(device, MS_UNLOADED);
1033 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1034 case 0x4012: /* Device Long Busy */
1035 tape_3590_print_era_msg(device, irb);
1036 return tape_3590_erp_long_busy(device, request, irb);
1039 if (sense->rac == 0xd0) {
1041 tape_3590_print_era_msg(device, irb);
1042 return tape_3590_erp_swap(device, request, irb);
1044 if (sense->rac == 0x26) {
1046 tape_3590_print_era_msg(device, irb);
1047 return tape_3590_erp_read_opposite(device, request,
1050 return tape_3590_erp_basic(device, request, irb, -EIO);
1057 tape_3590_print_era_msg(device, irb);
1058 return tape_3590_erp_swap(device, request, irb);
1062 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1066 tape_med_state_set(device, MS_UNLOADED);
1067 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1070 PRINT_WARN("(%s): Cartridge of wrong type ?\n",
1071 device->cdev->dev.bus_id);
1072 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1075 PRINT_WARN("(%s): Another host has reserved the tape device\n",
1076 device->cdev->dev.bus_id);
1077 return tape_3590_erp_basic(device, request, irb, -EPERM);
1079 PRINT_WARN("(%s): Another host has priviliged access to the "
1080 "tape device\n", device->cdev->dev.bus_id);
1081 PRINT_WARN("(%s): To solve the problem unload the current "
1082 "cartridge!\n", device->cdev->dev.bus_id);
1083 return tape_3590_erp_basic(device, request, irb, -EPERM);
1085 return tape_3590_erp_basic(device, request, irb, -EIO);
1090 * 3590 interrupt handler:
1093 tape_3590_irq(struct tape_device *device, struct tape_request *request,
1096 if (request == NULL)
1097 return tape_3590_unsolicited_irq(device, irb);
1099 if ((irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) &&
1100 (irb->scsw.dstat & DEV_STAT_DEV_END) && (request->op == TO_WRI)) {
1101 /* Write at end of volume */
1102 DBF_EVENT(2, "End of volume\n");
1103 return tape_3590_erp_failed(device, request, irb, -ENOSPC);
1106 if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
1107 return tape_3590_unit_check(device, request, irb);
1109 if (irb->scsw.dstat & DEV_STAT_DEV_END) {
1110 if (irb->scsw.dstat == DEV_STAT_UNIT_EXCEP) {
1111 if (request->op == TO_FSB || request->op == TO_BSB)
1114 DBF_EVENT(5, "Unit Exception!\n");
1117 return tape_3590_done(device, request);
1120 if (irb->scsw.dstat & DEV_STAT_CHN_END) {
1121 DBF_EVENT(2, "cannel end\n");
1122 return TAPE_IO_PENDING;
1125 if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
1126 DBF_EVENT(2, "Unit Attention when busy..\n");
1127 return TAPE_IO_PENDING;
1130 DBF_EVENT(6, "xunknownirq\n");
1131 PRINT_ERR("Unexpected interrupt.\n");
1132 PRINT_ERR("Current op is: %s", tape_op_verbose[request->op]);
1133 tape_dump_sense(device, request, irb);
1134 return TAPE_IO_STOP;
1138 * Setup device function
1141 tape_3590_setup_device(struct tape_device *device)
1144 struct tape_3590_disc_data *data;
1146 DBF_EVENT(6, "3590 device setup\n");
1147 data = kmalloc(sizeof(struct tape_3590_disc_data),
1148 GFP_KERNEL | GFP_DMA);
1151 data->read_back_op = READ_PREVIOUS;
1152 device->discdata = data;
1154 if ((rc = tape_std_assign(device)) == 0) {
1155 /* Try to find out if medium is loaded */
1156 if ((rc = tape_3590_sense_medium(device)) != 0)
1157 DBF_LH(3, "3590 medium sense returned %d\n", rc);
1164 * Cleanup device function
1167 tape_3590_cleanup_device(struct tape_device *device)
1169 flush_scheduled_work();
1170 tape_std_unassign(device);
1172 kfree(device->discdata);
1173 device->discdata = NULL;
1177 * List of 3590 magnetic tape commands.
1179 static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = {
1180 [MTRESET] = tape_std_mtreset,
1181 [MTFSF] = tape_std_mtfsf,
1182 [MTBSF] = tape_std_mtbsf,
1183 [MTFSR] = tape_std_mtfsr,
1184 [MTBSR] = tape_std_mtbsr,
1185 [MTWEOF] = tape_std_mtweof,
1186 [MTREW] = tape_std_mtrew,
1187 [MTOFFL] = tape_std_mtoffl,
1188 [MTNOP] = tape_std_mtnop,
1189 [MTRETEN] = tape_std_mtreten,
1190 [MTBSFM] = tape_std_mtbsfm,
1191 [MTFSFM] = tape_std_mtfsfm,
1192 [MTEOM] = tape_std_mteom,
1193 [MTERASE] = tape_std_mterase,
1197 [MTSETBLK] = tape_std_mtsetblk,
1198 [MTSETDENSITY] = NULL,
1199 [MTSEEK] = tape_3590_mtseek,
1200 [MTTELL] = tape_3590_mttell,
1201 [MTSETDRVBUFFER] = NULL,
1207 [MTLOAD] = tape_std_mtload,
1208 [MTUNLOAD] = tape_std_mtunload,
1209 [MTCOMPRESSION] = tape_std_mtcompression,
1215 * Tape discipline structure for 3590.
1217 static struct tape_discipline tape_discipline_3590 = {
1218 .owner = THIS_MODULE,
1219 .setup_device = tape_3590_setup_device,
1220 .cleanup_device = tape_3590_cleanup_device,
1221 .process_eov = tape_std_process_eov,
1222 .irq = tape_3590_irq,
1223 .read_block = tape_std_read_block,
1224 .write_block = tape_std_write_block,
1225 #ifdef CONFIG_S390_TAPE_BLOCK
1226 .bread = tape_3590_bread,
1227 .free_bread = tape_3590_free_bread,
1228 .check_locate = tape_3590_check_locate,
1230 .ioctl_fn = tape_3590_ioctl,
1231 .mtop_array = tape_3590_mtop
1234 static struct ccw_device_id tape_3590_ids[] = {
1235 {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590},
1236 {CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info = tape_3592},
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);