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/module.h>
12 #include <linux/init.h>
13 #include <linux/bio.h>
15 #define TAPE_DBF_AREA tape_3590_dbf
19 #include "tape_3590.h"
22 * Pointer to debug area.
24 debug_info_t *TAPE_DBF_AREA = NULL;
25 EXPORT_SYMBOL(TAPE_DBF_AREA);
27 /*******************************************************************
28 * Error Recovery fuctions:
29 * - Read Opposite: implemented
30 * - Read Device (buffered) log: BRA
31 * - Read Library log: BRA
34 * - Special Intercept: BRA
35 * - Read Alternate: implemented
36 *******************************************************************/
38 #define PRINTK_HEADER "TAPE_3590: "
40 static const char *tape_3590_msg[TAPE_3590_MAX_MSG] = {
42 [0x10] = "Lost Sense",
43 [0x11] = "Assigned Elsewhere",
44 [0x12] = "Allegiance Reset",
45 [0x13] = "Shared Access Violation",
46 [0x20] = "Command Reject",
47 [0x21] = "Configuration Error",
48 [0x22] = "Protection Exception",
49 [0x23] = "Write Protect",
50 [0x24] = "Write Length",
51 [0x25] = "Read-Only Format",
52 [0x31] = "Beginning of Partition",
53 [0x33] = "End of Partition",
54 [0x34] = "End of Data",
55 [0x35] = "Block not found",
56 [0x40] = "Device Intervention",
57 [0x41] = "Loader Intervention",
58 [0x42] = "Library Intervention",
59 [0x50] = "Write Error",
60 [0x51] = "Erase Error",
61 [0x52] = "Formatting Error",
62 [0x53] = "Read Error",
63 [0x54] = "Unsupported Format",
64 [0x55] = "No Formatting",
65 [0x56] = "Positioning lost",
66 [0x57] = "Read Length",
67 [0x60] = "Unsupported Medium",
68 [0x61] = "Medium Length Error",
69 [0x62] = "Medium removed",
70 [0x64] = "Load Check",
71 [0x65] = "Unload Check",
72 [0x70] = "Equipment Check",
73 [0x71] = "Bus out Check",
74 [0x72] = "Protocol Error",
75 [0x73] = "Interface Error",
77 [0x75] = "Halt Signal",
78 [0x90] = "Device fenced",
79 [0x91] = "Device Path fenced",
80 [0xa0] = "Volume misplaced",
81 [0xa1] = "Volume inaccessible",
82 [0xa2] = "Volume in input",
83 [0xa3] = "Volume ejected",
84 [0xa4] = "All categories reserved",
85 [0xa5] = "Duplicate Volume",
86 [0xa6] = "Library Manager Offline",
87 [0xa7] = "Library Output Station full",
88 [0xa8] = "Vision System non-operational",
89 [0xa9] = "Library Manager Equipment Check",
90 [0xaa] = "Library Equipment Check",
91 [0xab] = "All Library Cells full",
92 [0xac] = "No Cleaner Volumes in Library",
93 [0xad] = "I/O Station door open",
94 [0xae] = "Subsystem environmental alert",
101 tape_3590_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
104 case TAPE390_DISPLAY: {
105 struct display_struct disp;
107 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)))
110 return tape_std_display(device, &disp);
113 return -EINVAL; /* no additional ioctls */
118 * SENSE Medium: Get Sense data about medium state
121 tape_3590_sense_medium(struct tape_device *device)
123 struct tape_request *request;
125 request = tape_alloc_request(1, 128);
127 return PTR_ERR(request);
128 request->op = TO_MSEN;
129 tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
130 return tape_do_io_free(device, request);
134 * MTTELL: Tell block. Return the number of block relative to current file.
137 tape_3590_mttell(struct tape_device *device, int mt_count)
142 rc = tape_std_read_block_id(device, &block_id);
145 return block_id >> 32;
149 * MTSEEK: seek to the specified block.
152 tape_3590_mtseek(struct tape_device *device, int count)
154 struct tape_request *request;
156 DBF_EVENT(6, "xsee id: %x\n", count);
157 request = tape_alloc_request(3, 4);
159 return PTR_ERR(request);
160 request->op = TO_LBL;
161 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
162 *(__u32 *) request->cpdata = count;
163 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
164 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
165 return tape_do_io_free(device, request);
169 * Read Opposite Error Recovery Function:
170 * Used, when Read Forward does not work
173 tape_3590_read_opposite(struct tape_device *device,
174 struct tape_request *request)
176 struct tape_3590_disc_data *data;
179 * We have allocated 4 ccws in tape_std_read, so we can now
180 * transform the request to a read backward, followed by a
181 * forward space block.
183 request->op = TO_RBA;
184 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
185 data = device->discdata;
186 tape_ccw_cc_idal(request->cpaddr + 1, data->read_back_op,
187 device->char_data.idal_buf);
188 tape_ccw_cc(request->cpaddr + 2, FORSPACEBLOCK, 0, NULL);
189 tape_ccw_end(request->cpaddr + 3, NOP, 0, NULL);
190 DBF_EVENT(6, "xrop ccwg\n");
195 * This should be done after an interrupt with attention bit (0x80)
198 * After a "read attention message" request there are two possible
201 * 1. A unit check is presented, when attention sense is present (e.g. when
202 * a medium has been unloaded). The attention sense comes then
203 * together with the unit check. The recovery action is either "retry"
204 * (in case there is an attention message pending) or "permanent error".
206 * 2. The attention msg is written to the "read subsystem data" buffer.
207 * In this case we probably should print it to the console.
210 tape_3590_read_attmsg(struct tape_device *device)
212 struct tape_request *request;
215 request = tape_alloc_request(3, 4096);
217 return PTR_ERR(request);
218 request->op = TO_READ_ATTMSG;
219 buf = request->cpdata;
220 buf[0] = PREP_RD_SS_DATA;
221 buf[6] = RD_ATTMSG; /* read att msg */
222 tape_ccw_cc(request->cpaddr, PERFORM_SS_FUNC, 12, buf);
223 tape_ccw_cc(request->cpaddr + 1, READ_SS_DATA, 4096 - 12, buf + 12);
224 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
225 return tape_do_io_free(device, request);
229 * These functions are used to schedule follow-up actions from within an
230 * interrupt context (like unsolicited interrupts).
232 struct work_handler_data {
233 struct tape_device *device;
235 struct work_struct work;
239 tape_3590_work_handler(void *data)
241 struct work_handler_data *p = data;
245 tape_3590_sense_medium(p->device);
248 tape_3590_read_attmsg(p->device);
251 DBF_EVENT(3, "T3590: work handler undefined for "
252 "operation 0x%02x\n", p->op);
254 tape_put_device(p->device);
259 tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
261 struct work_handler_data *p;
263 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
266 INIT_WORK(&p->work, tape_3590_work_handler, p);
268 p->device = tape_get_device_reference(device);
271 schedule_work(&p->work);
275 #ifdef CONFIG_S390_TAPE_BLOCK
279 static struct tape_request *
280 tape_3590_bread(struct tape_device *device, struct request *req)
282 struct tape_request *request;
284 int count = 0, start_block, i;
290 DBF_EVENT(6, "xBREDid:");
291 start_block = req->sector >> TAPEBLOCK_HSEC_S2B;
292 DBF_EVENT(6, "start_block = %i\n", start_block);
294 rq_for_each_bio(bio, req) {
295 bio_for_each_segment(bv, bio, i) {
296 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
299 request = tape_alloc_request(2 + count + 1, 4);
302 request->op = TO_BLOCK;
303 *(__u32 *) request->cpdata = start_block;
304 ccw = request->cpaddr;
305 ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);
308 * We always setup a nop after the mode set ccw. This slot is
309 * used in tape_std_check_locate to insert a locate ccw if the
310 * current tape position doesn't match the start block to be read.
312 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
314 rq_for_each_bio(bio, req) {
315 bio_for_each_segment(bv, bio, i) {
316 dst = page_address(bv->bv_page) + bv->bv_offset;
317 for (off = 0; off < bv->bv_len;
318 off += TAPEBLOCK_HSEC_SIZE) {
319 ccw->flags = CCW_FLAG_CC;
320 ccw->cmd_code = READ_FORWARD;
321 ccw->count = TAPEBLOCK_HSEC_SIZE;
322 set_normalized_cda(ccw, (void *) __pa(dst));
324 dst += TAPEBLOCK_HSEC_SIZE;
326 if (off > bv->bv_len)
330 ccw = tape_ccw_end(ccw, NOP, 0, NULL);
331 DBF_EVENT(6, "xBREDccwg\n");
336 tape_3590_free_bread(struct tape_request *request)
340 /* Last ccw is a nop and doesn't need clear_normalized_cda */
341 for (ccw = request->cpaddr; ccw->flags & CCW_FLAG_CC; ccw++)
342 if (ccw->cmd_code == READ_FORWARD)
343 clear_normalized_cda(ccw);
344 tape_free_request(request);
348 * check_locate is called just before the tape request is passed to
349 * the common io layer for execution. It has to check the current
350 * tape position and insert a locate ccw if it doesn't match the
351 * start block for the request.
354 tape_3590_check_locate(struct tape_device *device, struct tape_request *request)
358 start_block = (__u32 *) request->cpdata;
359 if (*start_block != device->blk_data.block_position) {
360 /* Add the start offset of the file to get the real block. */
361 *start_block += device->bof;
362 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
368 * The done handler is called at device/channel end and wakes up the sleeping
372 tape_3590_done(struct tape_device *device, struct tape_request *request)
374 struct tape_3590_med_sense *sense;
376 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
378 switch (request->op) {
392 tape_med_state_set(device, MS_LOADED);
395 tape_med_state_set(device, MS_UNLOADED);
398 sense = (struct tape_3590_med_sense *) request->cpdata;
399 if (sense->masst == MSENSE_UNASSOCIATED)
400 tape_med_state_set(device, MS_UNLOADED);
401 if (sense->masst == MSENSE_ASSOCIATED_MOUNT)
402 tape_med_state_set(device, MS_LOADED);
404 case TO_RBI: /* RBI seems to succeed even without medium loaded. */
405 case TO_NOP: /* Same to NOP. */
415 return TAPE_IO_SUCCESS;
419 * This fuction is called, when error recovery was successfull
422 tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request)
424 DBF_EVENT(3, "Error Recovery successfull for %s\n",
425 tape_op_verbose[request->op]);
426 return tape_3590_done(device, request);
430 * This fuction is called, when error recovery was not successfull
433 tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
434 struct irb *irb, int rc)
436 DBF_EVENT(3, "Error Recovery failed for %s\n",
437 tape_op_verbose[request->op]);
438 tape_dump_sense_dbf(device, request, irb);
443 * Error Recovery do retry
446 tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
449 DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]);
450 tape_dump_sense_dbf(device, request, irb);
451 return TAPE_IO_RETRY;
455 * Handle unsolicited interrupts
458 tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
460 if (irb->scsw.dstat == DEV_STAT_CHN_END)
461 /* Probably result of halt ssch */
462 return TAPE_IO_PENDING;
463 else if (irb->scsw.dstat == 0x85)
464 /* Device Ready -> check medium state */
465 tape_3590_schedule_work(device, TO_MSEN);
466 else if (irb->scsw.dstat & DEV_STAT_ATTENTION)
467 tape_3590_schedule_work(device, TO_READ_ATTMSG);
469 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
470 PRINT_WARN("Unsolicited IRQ (Device End) caught.\n");
471 tape_dump_sense(device, NULL, irb);
473 return TAPE_IO_SUCCESS;
477 * Basic Recovery routine
480 tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
481 struct irb *irb, int rc)
483 struct tape_3590_sense *sense;
485 sense = (struct tape_3590_sense *) irb->ecw;
487 switch (sense->bra) {
489 return tape_3590_erp_failed(device, request, irb, rc);
491 return tape_3590_erp_succeded(device, request);
493 return tape_3590_erp_retry(device, request, irb);
495 return tape_3590_erp_failed(device, request, irb, rc);
497 PRINT_ERR("Unknown BRA %x - This should not happen!\n",
505 * RDL: Read Device (buffered) log
508 tape_3590_erp_read_buf_log(struct tape_device *device,
509 struct tape_request *request, struct irb *irb)
512 * We just do the basic error recovery at the moment (retry).
513 * Perhaps in the future, we read the log and dump it somewhere...
515 return tape_3590_erp_basic(device, request, irb, -EIO);
522 tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
526 * This error recovery should swap the tapes
527 * if the original has a problem. The operation
528 * should proceed with the new tape... this
529 * should probably be done in user space!
531 PRINT_WARN("(%s): Swap Tape Device!\n", device->cdev->dev.bus_id);
532 return tape_3590_erp_basic(device, request, irb, -EIO);
539 tape_3590_erp_long_busy(struct tape_device *device,
540 struct tape_request *request, struct irb *irb)
542 /* FIXME: how about WAITING for a minute ? */
543 PRINT_WARN("(%s): Device is busy! Please wait a minute!\n",
544 device->cdev->dev.bus_id);
545 return tape_3590_erp_basic(device, request, irb, -EBUSY);
549 * SPI: Special Intercept
552 tape_3590_erp_special_interrupt(struct tape_device *device,
553 struct tape_request *request, struct irb *irb)
555 return tape_3590_erp_basic(device, request, irb, -EIO);
559 * RDA: Read Alternate
562 tape_3590_erp_read_alternate(struct tape_device *device,
563 struct tape_request *request, struct irb *irb)
565 struct tape_3590_disc_data *data;
568 * The issued Read Backward or Read Previous command is not
569 * supported by the device
570 * The recovery action should be to issue another command:
571 * Read Revious: if Read Backward is not supported
572 * Read Backward: if Read Previous is not supported
574 data = device->discdata;
575 if (data->read_back_op == READ_PREVIOUS) {
576 DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
578 data->read_back_op = READ_BACKWARD;
580 DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
582 data->read_back_op = READ_PREVIOUS;
584 tape_3590_read_opposite(device, request);
585 return tape_3590_erp_retry(device, request, irb);
589 * Error Recovery read opposite
592 tape_3590_erp_read_opposite(struct tape_device *device,
593 struct tape_request *request, struct irb *irb)
595 switch (request->op) {
598 * We did read forward, but the data could not be read.
599 * We will read backward and then skip forward again.
601 tape_3590_read_opposite(device, request);
602 return tape_3590_erp_retry(device, request, irb);
604 /* We tried to read forward and backward, but hat no success */
605 return tape_3590_erp_failed(device, request, irb, -EIO);
608 PRINT_WARN("read_opposite_recovery_called_with_op: %s\n",
609 tape_op_verbose[request->op]);
610 return tape_3590_erp_failed(device, request, irb, -EIO);
615 * Print an MIM (Media Information Message) (message code f0)
618 tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
620 struct tape_3590_sense *sense;
622 sense = (struct tape_3590_sense *) irb->ecw;
623 /* Exception Message */
624 switch (sense->fmt.f70.emc) {
626 PRINT_WARN("(%s): Data degraded\n", device->cdev->dev.bus_id);
629 PRINT_WARN("(%s): Data degraded in partion %i\n",
630 device->cdev->dev.bus_id, sense->fmt.f70.mp);
633 PRINT_WARN("(%s): Medium degraded\n", device->cdev->dev.bus_id);
636 PRINT_WARN("(%s): Medium degraded in partition %i\n",
637 device->cdev->dev.bus_id, sense->fmt.f70.mp);
640 PRINT_WARN("(%s): Block 0 Error\n", device->cdev->dev.bus_id);
643 PRINT_WARN("(%s): Medium Exception 0x%02x\n",
644 device->cdev->dev.bus_id, sense->fmt.f70.md);
647 PRINT_WARN("(%s): MIM ExMsg: 0x%02x\n",
648 device->cdev->dev.bus_id, sense->fmt.f70.emc);
651 /* Service Message */
652 switch (sense->fmt.f70.smc) {
654 PRINT_WARN("(%s): Reference Media maintenance procedure %i\n",
655 device->cdev->dev.bus_id, sense->fmt.f70.md);
658 PRINT_WARN("(%s): MIM ServiceMsg: 0x%02x\n",
659 device->cdev->dev.bus_id, sense->fmt.f70.smc);
665 * Print an I/O Subsystem Service Information Message (message code f1)
668 tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
670 struct tape_3590_sense *sense;
672 sense = (struct tape_3590_sense *) irb->ecw;
673 /* Exception Message */
674 switch (sense->fmt.f71.emc) {
676 PRINT_WARN("(%s): Effect of failure is unknown\n",
677 device->cdev->dev.bus_id);
680 PRINT_WARN("(%s): CU Exception - no performance impact\n",
681 device->cdev->dev.bus_id);
684 PRINT_WARN("(%s): CU Exception on channel interface 0x%02x\n",
685 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
688 PRINT_WARN("(%s): CU Exception on device path 0x%02x\n",
689 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
692 PRINT_WARN("(%s): CU Exception on library path 0x%02x\n",
693 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
696 PRINT_WARN("(%s): CU Exception on node 0x%02x\n",
697 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
700 PRINT_WARN("(%s): CU Exception on partition 0x%02x\n",
701 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
704 PRINT_WARN("(%s): SIM ExMsg: 0x%02x\n",
705 device->cdev->dev.bus_id, sense->fmt.f71.emc);
707 /* Service Message */
708 switch (sense->fmt.f71.smc) {
710 PRINT_WARN("(%s): Repair impact is unknown\n",
711 device->cdev->dev.bus_id);
714 PRINT_WARN("(%s): Repair will not impact cu performance\n",
715 device->cdev->dev.bus_id);
718 if (sense->fmt.f71.mdf == 0)
719 PRINT_WARN("(%s): Repair will disable node "
721 device->cdev->dev.bus_id,
722 sense->fmt.f71.md[1]);
724 PRINT_WARN("(%s): Repair will disable nodes "
725 "(0x%x-0x%x) on CU\n",
726 device->cdev->dev.bus_id,
727 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
730 if (sense->fmt.f71.mdf == 0)
731 PRINT_WARN("(%s): Repair will disable cannel path "
733 device->cdev->dev.bus_id,
734 sense->fmt.f71.md[1]);
736 PRINT_WARN("(%s): Repair will disable cannel paths "
737 "(0x%x-0x%x) on CU\n",
738 device->cdev->dev.bus_id,
739 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
742 if (sense->fmt.f71.mdf == 0)
743 PRINT_WARN("(%s): Repair will disable device path "
745 device->cdev->dev.bus_id,
746 sense->fmt.f71.md[1]);
748 PRINT_WARN("(%s): Repair will disable device paths "
749 "(0x%x-0x%x) on CU\n",
750 device->cdev->dev.bus_id,
751 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
754 if (sense->fmt.f71.mdf == 0)
755 PRINT_WARN("(%s): Repair will disable library path "
757 device->cdev->dev.bus_id,
758 sense->fmt.f71.md[1]);
760 PRINT_WARN("(%s): Repair will disable library paths "
761 "(0x%x-0x%x) on CU\n",
762 device->cdev->dev.bus_id,
763 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
766 PRINT_WARN("(%s): Repair will disable access to CU\n",
767 device->cdev->dev.bus_id);
770 PRINT_WARN("(%s): SIM ServiceMsg: 0x%02x\n",
771 device->cdev->dev.bus_id, sense->fmt.f71.smc);
776 * Print an Device Subsystem Service Information Message (message code f2)
779 tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
781 struct tape_3590_sense *sense;
783 sense = (struct tape_3590_sense *) irb->ecw;
784 /* Exception Message */
785 switch (sense->fmt.f71.emc) {
787 PRINT_WARN("(%s): Effect of failure is unknown\n",
788 device->cdev->dev.bus_id);
791 PRINT_WARN("(%s): DV Exception - no performance impact\n",
792 device->cdev->dev.bus_id);
795 PRINT_WARN("(%s): DV Exception on channel interface 0x%02x\n",
796 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
799 PRINT_WARN("(%s): DV Exception on loader 0x%02x\n",
800 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
803 PRINT_WARN("(%s): DV Exception on message display 0x%02x\n",
804 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
807 PRINT_WARN("(%s): DV Exception in tape path\n",
808 device->cdev->dev.bus_id);
811 PRINT_WARN("(%s): DV Exception in drive\n",
812 device->cdev->dev.bus_id);
815 PRINT_WARN("(%s): DSIM ExMsg: 0x%02x\n",
816 device->cdev->dev.bus_id, sense->fmt.f71.emc);
818 /* Service Message */
819 switch (sense->fmt.f71.smc) {
821 PRINT_WARN("(%s): Repair impact is unknown\n",
822 device->cdev->dev.bus_id);
825 PRINT_WARN("(%s): Repair will not impact device performance\n",
826 device->cdev->dev.bus_id);
829 if (sense->fmt.f71.mdf == 0)
830 PRINT_WARN("(%s): Repair will disable channel path "
832 device->cdev->dev.bus_id,
833 sense->fmt.f71.md[1]);
835 PRINT_WARN("(%s): Repair will disable channel path "
836 "(0x%x-0x%x) on DV\n",
837 device->cdev->dev.bus_id,
838 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
841 if (sense->fmt.f71.mdf == 0)
842 PRINT_WARN("(%s): Repair will disable interface 0x%x "
844 device->cdev->dev.bus_id,
845 sense->fmt.f71.md[1]);
847 PRINT_WARN("(%s): Repair will disable interfaces "
848 "(0x%x-0x%x) on DV\n",
849 device->cdev->dev.bus_id,
850 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
853 if (sense->fmt.f71.mdf == 0)
854 PRINT_WARN("(%s): Repair will disable loader 0x%x "
856 device->cdev->dev.bus_id,
857 sense->fmt.f71.md[1]);
859 PRINT_WARN("(%s): Repair will disable loader "
860 "(0x%x-0x%x) on DV\n",
861 device->cdev->dev.bus_id,
862 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
865 PRINT_WARN("(%s): Repair will disable access to DV\n",
866 device->cdev->dev.bus_id);
869 if (sense->fmt.f71.mdf == 0)
870 PRINT_WARN("(%s): Repair will disable message "
871 "display 0x%x on DV\n",
872 device->cdev->dev.bus_id,
873 sense->fmt.f71.md[1]);
875 PRINT_WARN("(%s): Repair will disable message "
876 "displays (0x%x-0x%x) on DV\n",
877 device->cdev->dev.bus_id,
878 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
881 PRINT_WARN("(%s): Clean DV\n", device->cdev->dev.bus_id);
884 PRINT_WARN("(%s): DSIM ServiceMsg: 0x%02x\n",
885 device->cdev->dev.bus_id, sense->fmt.f71.smc);
890 * Print standard ERA Message
893 tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
895 struct tape_3590_sense *sense;
897 sense = (struct tape_3590_sense *) irb->ecw;
900 if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) {
901 if (tape_3590_msg[sense->mc] != NULL)
902 PRINT_WARN("(%s): %s\n", device->cdev->dev.bus_id,
903 tape_3590_msg[sense->mc]);
905 PRINT_WARN("(%s): Message Code 0x%x\n",
906 device->cdev->dev.bus_id, sense->mc);
910 if (sense->mc == 0xf0) {
911 /* Standard Media Information Message */
912 PRINT_WARN("(%s): MIM SEV=%i, MC=%02x, ES=%x/%x, "
913 "RC=%02x-%04x-%02x\n", device->cdev->dev.bus_id,
914 sense->fmt.f70.sev, sense->mc,
915 sense->fmt.f70.emc, sense->fmt.f70.smc,
916 sense->fmt.f70.refcode, sense->fmt.f70.mid,
918 tape_3590_print_mim_msg_f0(device, irb);
921 if (sense->mc == 0xf1) {
922 /* Standard I/O Subsystem Service Information Message */
923 PRINT_WARN("(%s): IOSIM SEV=%i, DEVTYPE=3590/%02x, "
924 "MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
925 device->cdev->dev.bus_id, sense->fmt.f71.sev,
926 device->cdev->id.dev_model,
927 sense->mc, sense->fmt.f71.emc,
928 sense->fmt.f71.smc, sense->fmt.f71.refcode1,
929 sense->fmt.f71.refcode2, sense->fmt.f71.refcode3);
930 tape_3590_print_io_sim_msg_f1(device, irb);
933 if (sense->mc == 0xf2) {
934 /* Standard Device Service Information Message */
935 PRINT_WARN("(%s): DEVSIM SEV=%i, DEVTYPE=3590/%02x, "
936 "MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
937 device->cdev->dev.bus_id, sense->fmt.f71.sev,
938 device->cdev->id.dev_model,
939 sense->mc, sense->fmt.f71.emc,
940 sense->fmt.f71.smc, sense->fmt.f71.refcode1,
941 sense->fmt.f71.refcode2, sense->fmt.f71.refcode3);
942 tape_3590_print_dev_sim_msg_f2(device, irb);
945 if (sense->mc == 0xf3) {
946 /* Standard Library Service Information Message */
949 PRINT_WARN("(%s): Device Message(%x)\n",
950 device->cdev->dev.bus_id, sense->mc);
954 * 3590 error Recovery routine:
955 * If possible, it tries to recover from the error. If this is not possible,
956 * inform the user about the problem.
959 tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
962 struct tape_3590_sense *sense;
965 #ifdef CONFIG_S390_TAPE_BLOCK
966 if (request->op == TO_BLOCK) {
968 * Recovery for block device requests. Set the block_position
969 * to something invalid and retry.
971 device->blk_data.block_position = -1;
972 if (request->retries-- <= 0)
973 return tape_3590_erp_failed(device, request, irb, -EIO);
975 return tape_3590_erp_retry(device, request, irb);
979 sense = (struct tape_3590_sense *) irb->ecw;
982 * First check all RC-QRCs where we want to do something special
983 * - "break": basic error recovery is done
984 * - "goto out:": just print error message if available
987 switch (sense->rc_rqc) {
990 tape_3590_print_era_msg(device, irb);
991 return tape_3590_erp_read_buf_log(device, request, irb);
994 tape_3590_print_era_msg(device, irb);
995 return tape_3590_erp_read_alternate(device, request, irb);
999 tape_3590_print_era_msg(device, irb);
1000 return tape_3590_erp_special_interrupt(device, request, irb);
1003 DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1005 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1007 DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1009 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1011 DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
1012 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1015 DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1017 return tape_3590_erp_basic(device, request, irb, -EIO);
1019 DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1021 tape_med_state_set(device, MS_UNLOADED);
1022 return tape_3590_erp_basic(device, request, irb, 0);
1026 * print additional msg since default msg
1027 * "device intervention" is not very meaningfull
1029 PRINT_WARN("(%s): Tape operation when medium not loaded\n",
1030 device->cdev->dev.bus_id);
1031 tape_med_state_set(device, MS_UNLOADED);
1032 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1033 case 0x4012: /* Device Long Busy */
1034 tape_3590_print_era_msg(device, irb);
1035 return tape_3590_erp_long_busy(device, request, irb);
1038 if (sense->rac == 0xd0) {
1040 tape_3590_print_era_msg(device, irb);
1041 return tape_3590_erp_swap(device, request, irb);
1043 if (sense->rac == 0x26) {
1045 tape_3590_print_era_msg(device, irb);
1046 return tape_3590_erp_read_opposite(device, request,
1049 return tape_3590_erp_basic(device, request, irb, -EIO);
1056 tape_3590_print_era_msg(device, irb);
1057 return tape_3590_erp_swap(device, request, irb);
1061 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1065 tape_med_state_set(device, MS_UNLOADED);
1066 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1069 PRINT_WARN("(%s): Cartridge of wrong type ?\n",
1070 device->cdev->dev.bus_id);
1071 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1074 PRINT_WARN("(%s): Another host has reserved the tape device\n",
1075 device->cdev->dev.bus_id);
1076 return tape_3590_erp_basic(device, request, irb, -EPERM);
1078 PRINT_WARN("(%s): Another host has priviliged access to the "
1079 "tape device\n", device->cdev->dev.bus_id);
1080 PRINT_WARN("(%s): To solve the problem unload the current "
1081 "cartridge!\n", device->cdev->dev.bus_id);
1082 return tape_3590_erp_basic(device, request, irb, -EPERM);
1084 return tape_3590_erp_basic(device, request, irb, -EIO);
1089 * 3590 interrupt handler:
1092 tape_3590_irq(struct tape_device *device, struct tape_request *request,
1095 if (request == NULL)
1096 return tape_3590_unsolicited_irq(device, irb);
1098 if ((irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) &&
1099 (irb->scsw.dstat & DEV_STAT_DEV_END) && (request->op == TO_WRI)) {
1100 /* Write at end of volume */
1101 DBF_EVENT(2, "End of volume\n");
1102 return tape_3590_erp_failed(device, request, irb, -ENOSPC);
1105 if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
1106 return tape_3590_unit_check(device, request, irb);
1108 if (irb->scsw.dstat & DEV_STAT_DEV_END) {
1109 if (irb->scsw.dstat == DEV_STAT_UNIT_EXCEP) {
1110 if (request->op == TO_FSB || request->op == TO_BSB)
1113 DBF_EVENT(5, "Unit Exception!\n");
1116 return tape_3590_done(device, request);
1119 if (irb->scsw.dstat & DEV_STAT_CHN_END) {
1120 DBF_EVENT(2, "cannel end\n");
1121 return TAPE_IO_PENDING;
1124 if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
1125 DBF_EVENT(2, "Unit Attention when busy..\n");
1126 return TAPE_IO_PENDING;
1129 DBF_EVENT(6, "xunknownirq\n");
1130 PRINT_ERR("Unexpected interrupt.\n");
1131 PRINT_ERR("Current op is: %s", tape_op_verbose[request->op]);
1132 tape_dump_sense(device, request, irb);
1133 return TAPE_IO_STOP;
1137 * Setup device function
1140 tape_3590_setup_device(struct tape_device *device)
1143 struct tape_3590_disc_data *data;
1145 DBF_EVENT(6, "3590 device setup\n");
1146 data = kmalloc(sizeof(struct tape_3590_disc_data),
1147 GFP_KERNEL | GFP_DMA);
1150 data->read_back_op = READ_PREVIOUS;
1151 device->discdata = data;
1153 if ((rc = tape_std_assign(device)) == 0) {
1154 /* Try to find out if medium is loaded */
1155 if ((rc = tape_3590_sense_medium(device)) != 0)
1156 DBF_LH(3, "3590 medium sense returned %d\n", rc);
1163 * Cleanup device function
1166 tape_3590_cleanup_device(struct tape_device *device)
1168 flush_scheduled_work();
1169 tape_std_unassign(device);
1171 kfree(device->discdata);
1172 device->discdata = NULL;
1176 * List of 3590 magnetic tape commands.
1178 static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = {
1179 [MTRESET] = tape_std_mtreset,
1180 [MTFSF] = tape_std_mtfsf,
1181 [MTBSF] = tape_std_mtbsf,
1182 [MTFSR] = tape_std_mtfsr,
1183 [MTBSR] = tape_std_mtbsr,
1184 [MTWEOF] = tape_std_mtweof,
1185 [MTREW] = tape_std_mtrew,
1186 [MTOFFL] = tape_std_mtoffl,
1187 [MTNOP] = tape_std_mtnop,
1188 [MTRETEN] = tape_std_mtreten,
1189 [MTBSFM] = tape_std_mtbsfm,
1190 [MTFSFM] = tape_std_mtfsfm,
1191 [MTEOM] = tape_std_mteom,
1192 [MTERASE] = tape_std_mterase,
1196 [MTSETBLK] = tape_std_mtsetblk,
1197 [MTSETDENSITY] = NULL,
1198 [MTSEEK] = tape_3590_mtseek,
1199 [MTTELL] = tape_3590_mttell,
1200 [MTSETDRVBUFFER] = NULL,
1206 [MTLOAD] = tape_std_mtload,
1207 [MTUNLOAD] = tape_std_mtunload,
1208 [MTCOMPRESSION] = tape_std_mtcompression,
1214 * Tape discipline structure for 3590.
1216 static struct tape_discipline tape_discipline_3590 = {
1217 .owner = THIS_MODULE,
1218 .setup_device = tape_3590_setup_device,
1219 .cleanup_device = tape_3590_cleanup_device,
1220 .process_eov = tape_std_process_eov,
1221 .irq = tape_3590_irq,
1222 .read_block = tape_std_read_block,
1223 .write_block = tape_std_write_block,
1224 #ifdef CONFIG_S390_TAPE_BLOCK
1225 .bread = tape_3590_bread,
1226 .free_bread = tape_3590_free_bread,
1227 .check_locate = tape_3590_check_locate,
1229 .ioctl_fn = tape_3590_ioctl,
1230 .mtop_array = tape_3590_mtop
1233 static struct ccw_device_id tape_3590_ids[] = {
1234 {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590},
1235 {CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info = tape_3592},
1236 { /* end of list */ }
1240 tape_3590_online(struct ccw_device *cdev)
1242 return tape_generic_online(cdev->dev.driver_data,
1243 &tape_discipline_3590);
1247 tape_3590_offline(struct ccw_device *cdev)
1249 return tape_generic_offline(cdev->dev.driver_data);
1252 static struct ccw_driver tape_3590_driver = {
1253 .name = "tape_3590",
1254 .owner = THIS_MODULE,
1255 .ids = tape_3590_ids,
1256 .probe = tape_generic_probe,
1257 .remove = tape_generic_remove,
1258 .set_offline = tape_3590_offline,
1259 .set_online = tape_3590_online,
1263 * Setup discipline structure.
1266 tape_3590_init(void)
1270 TAPE_DBF_AREA = debug_register("tape_3590", 2, 2, 4 * sizeof(long));
1271 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1272 #ifdef DBF_LIKE_HELL
1273 debug_set_level(TAPE_DBF_AREA, 6);
1276 DBF_EVENT(3, "3590 init\n");
1277 /* Register driver for 3590 tapes. */
1278 rc = ccw_driver_register(&tape_3590_driver);
1280 DBF_EVENT(3, "3590 init failed\n");
1282 DBF_EVENT(3, "3590 registered\n");
1287 tape_3590_exit(void)
1289 ccw_driver_unregister(&tape_3590_driver);
1291 debug_unregister(TAPE_DBF_AREA);
1294 MODULE_DEVICE_TABLE(ccw, tape_3590_ids);
1295 MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
1296 MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
1297 MODULE_LICENSE("GPL");
1299 module_init(tape_3590_init);
1300 module_exit(tape_3590_exit);