]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/s390/char/tape_3590.c
[PATCH] s390: tape 3590 changes
[mirror_ubuntu-zesty-kernel.git] / drivers / s390 / char / tape_3590.c
1 /*
2 * drivers/s390/char/tape_3590.c
3 * tape device discipline for 3590 tapes.
4 *
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>
9 */
10
11 #include <linux/config.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/bio.h>
15
16 #define TAPE_DBF_AREA tape_3590_dbf
17
18 #include "tape.h"
19 #include "tape_std.h"
20 #include "tape_3590.h"
21
22 /*
23 * Pointer to debug area.
24 */
25 debug_info_t *TAPE_DBF_AREA = NULL;
26 EXPORT_SYMBOL(TAPE_DBF_AREA);
27
28 /*******************************************************************
29 * Error Recovery fuctions:
30 * - Read Opposite: implemented
31 * - Read Device (buffered) log: BRA
32 * - Read Library log: BRA
33 * - Swap Devices: BRA
34 * - Long Busy: BRA
35 * - Special Intercept: BRA
36 * - Read Alternate: implemented
37 *******************************************************************/
38
39 #define PRINTK_HEADER "TAPE_3590: "
40
41 static const char *tape_3590_msg[TAPE_3590_MAX_MSG] = {
42 [0x00] = "",
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",
77 [0x74] = "Overrun",
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",
96 };
97
98 /*
99 * 3590 IOCTL Overload
100 */
101 static int
102 tape_3590_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
103 {
104 switch (cmd) {
105 case TAPE390_DISPLAY: {
106 struct display_struct disp;
107
108 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)))
109 return -EFAULT;
110
111 return tape_std_display(device, &disp);
112 }
113 default:
114 return -EINVAL; /* no additional ioctls */
115 }
116 }
117
118 /*
119 * SENSE Medium: Get Sense data about medium state
120 */
121 static int
122 tape_3590_sense_medium(struct tape_device *device)
123 {
124 struct tape_request *request;
125
126 request = tape_alloc_request(1, 128);
127 if (IS_ERR(request))
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);
132 }
133
134 /*
135 * MTTELL: Tell block. Return the number of block relative to current file.
136 */
137 static int
138 tape_3590_mttell(struct tape_device *device, int mt_count)
139 {
140 __u64 block_id;
141 int rc;
142
143 rc = tape_std_read_block_id(device, &block_id);
144 if (rc)
145 return rc;
146 return block_id >> 32;
147 }
148
149 /*
150 * MTSEEK: seek to the specified block.
151 */
152 static int
153 tape_3590_mtseek(struct tape_device *device, int count)
154 {
155 struct tape_request *request;
156
157 DBF_EVENT(6, "xsee id: %x\n", count);
158 request = tape_alloc_request(3, 4);
159 if (IS_ERR(request))
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);
167 }
168
169 /*
170 * Read Opposite Error Recovery Function:
171 * Used, when Read Forward does not work
172 */
173 static void
174 tape_3590_read_opposite(struct tape_device *device,
175 struct tape_request *request)
176 {
177 struct tape_3590_disc_data *data;
178
179 /*
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.
183 */
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");
192 }
193
194 /*
195 * Read Attention Msg
196 * This should be done after an interrupt with attention bit (0x80)
197 * in device state.
198 *
199 * After a "read attention message" request there are two possible
200 * results:
201 *
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".
206 *
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.
209 */
210 static int
211 tape_3590_read_attmsg(struct tape_device *device)
212 {
213 struct tape_request *request;
214 char *buf;
215
216 request = tape_alloc_request(3, 4096);
217 if (IS_ERR(request))
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);
227 }
228
229 /*
230 * These functions are used to schedule follow-up actions from within an
231 * interrupt context (like unsolicited interrupts).
232 */
233 struct work_handler_data {
234 struct tape_device *device;
235 enum tape_op op;
236 struct work_struct work;
237 };
238
239 static void
240 tape_3590_work_handler(void *data)
241 {
242 struct work_handler_data *p = data;
243
244 switch (p->op) {
245 case TO_MSEN:
246 tape_3590_sense_medium(p->device);
247 break;
248 case TO_READ_ATTMSG:
249 tape_3590_read_attmsg(p->device);
250 break;
251 default:
252 DBF_EVENT(3, "T3590: work handler undefined for "
253 "operation 0x%02x\n", p->op);
254 }
255 tape_put_device(p->device);
256 kfree(p);
257 }
258
259 static int
260 tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
261 {
262 struct work_handler_data *p;
263
264 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
265 return -ENOMEM;
266
267 INIT_WORK(&p->work, tape_3590_work_handler, p);
268
269 p->device = tape_get_device_reference(device);
270 p->op = op;
271
272 schedule_work(&p->work);
273 return 0;
274 }
275
276 #ifdef CONFIG_S390_TAPE_BLOCK
277 /*
278 * Tape Block READ
279 */
280 static struct tape_request *
281 tape_3590_bread(struct tape_device *device, struct request *req)
282 {
283 struct tape_request *request;
284 struct ccw1 *ccw;
285 int count = 0, start_block, i;
286 unsigned off;
287 char *dst;
288 struct bio_vec *bv;
289 struct bio *bio;
290
291 DBF_EVENT(6, "xBREDid:");
292 start_block = req->sector >> TAPEBLOCK_HSEC_S2B;
293 DBF_EVENT(6, "start_block = %i\n", start_block);
294
295 rq_for_each_bio(bio, req) {
296 bio_for_each_segment(bv, bio, i) {
297 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
298 }
299 }
300 request = tape_alloc_request(2 + count + 1, 4);
301 if (IS_ERR(request))
302 return request;
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);
307
308 /*
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.
312 */
313 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
314
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));
324 ccw++;
325 dst += TAPEBLOCK_HSEC_SIZE;
326 }
327 if (off > bv->bv_len)
328 BUG();
329 }
330 }
331 ccw = tape_ccw_end(ccw, NOP, 0, NULL);
332 DBF_EVENT(6, "xBREDccwg\n");
333 return request;
334 }
335
336 static void
337 tape_3590_free_bread(struct tape_request *request)
338 {
339 struct ccw1 *ccw;
340
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);
346 }
347
348 /*
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.
353 */
354 static void
355 tape_3590_check_locate(struct tape_device *device, struct tape_request *request)
356 {
357 __u32 *start_block;
358
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);
364 }
365 }
366 #endif
367
368 /*
369 * The done handler is called at device/channel end and wakes up the sleeping
370 * process
371 */
372 static int
373 tape_3590_done(struct tape_device *device, struct tape_request *request)
374 {
375 struct tape_3590_med_sense *sense;
376
377 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
378
379 switch (request->op) {
380 case TO_BSB:
381 case TO_BSF:
382 case TO_DSE:
383 case TO_FSB:
384 case TO_FSF:
385 case TO_LBL:
386 case TO_RFO:
387 case TO_RBA:
388 case TO_REW:
389 case TO_WRI:
390 case TO_WTM:
391 case TO_BLOCK:
392 case TO_LOAD:
393 tape_med_state_set(device, MS_LOADED);
394 break;
395 case TO_RUN:
396 tape_med_state_set(device, MS_UNLOADED);
397 break;
398 case TO_MSEN:
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);
404 break;
405 case TO_RBI: /* RBI seems to succeed even without medium loaded. */
406 case TO_NOP: /* Same to NOP. */
407 case TO_READ_CONFIG:
408 case TO_READ_ATTMSG:
409 case TO_DIS:
410 case TO_ASSIGN:
411 case TO_UNASSIGN:
412 break;
413 case TO_SIZE:
414 break;
415 }
416 return TAPE_IO_SUCCESS;
417 }
418
419 /*
420 * This fuction is called, when error recovery was successfull
421 */
422 static inline int
423 tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request)
424 {
425 DBF_EVENT(3, "Error Recovery successfull for %s\n",
426 tape_op_verbose[request->op]);
427 return tape_3590_done(device, request);
428 }
429
430 /*
431 * This fuction is called, when error recovery was not successfull
432 */
433 static inline int
434 tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
435 struct irb *irb, int rc)
436 {
437 DBF_EVENT(3, "Error Recovery failed for %s\n",
438 tape_op_verbose[request->op]);
439 tape_dump_sense_dbf(device, request, irb);
440 return rc;
441 }
442
443 /*
444 * Error Recovery do retry
445 */
446 static inline int
447 tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
448 struct irb *irb)
449 {
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;
453 }
454
455 /*
456 * Handle unsolicited interrupts
457 */
458 static int
459 tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
460 {
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);
469 else {
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);
473 }
474 return TAPE_IO_SUCCESS;
475 }
476
477 /*
478 * Basic Recovery routine
479 */
480 static int
481 tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
482 struct irb *irb, int rc)
483 {
484 struct tape_3590_sense *sense;
485
486 sense = (struct tape_3590_sense *) irb->ecw;
487
488 switch (sense->bra) {
489 case SENSE_BRA_PER:
490 return tape_3590_erp_failed(device, request, irb, rc);
491 case SENSE_BRA_CONT:
492 return tape_3590_erp_succeded(device, request);
493 case SENSE_BRA_RE:
494 return tape_3590_erp_retry(device, request, irb);
495 case SENSE_BRA_DRE:
496 return tape_3590_erp_failed(device, request, irb, rc);
497 default:
498 PRINT_ERR("Unknown BRA %x - This should not happen!\n",
499 sense->bra);
500 BUG();
501 return TAPE_IO_STOP;
502 }
503 }
504
505 /*
506 * RDL: Read Device (buffered) log
507 */
508 static int
509 tape_3590_erp_read_buf_log(struct tape_device *device,
510 struct tape_request *request, struct irb *irb)
511 {
512 /*
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...
515 */
516 return tape_3590_erp_basic(device, request, irb, -EIO);
517 }
518
519 /*
520 * SWAP: Swap Devices
521 */
522 static int
523 tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
524 struct irb *irb)
525 {
526 /*
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!
531 */
532 PRINT_WARN("(%s): Swap Tape Device!\n", device->cdev->dev.bus_id);
533 return tape_3590_erp_basic(device, request, irb, -EIO);
534 }
535
536 /*
537 * LBY: Long Busy
538 */
539 static int
540 tape_3590_erp_long_busy(struct tape_device *device,
541 struct tape_request *request, struct irb *irb)
542 {
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);
547 }
548
549 /*
550 * SPI: Special Intercept
551 */
552 static int
553 tape_3590_erp_special_interrupt(struct tape_device *device,
554 struct tape_request *request, struct irb *irb)
555 {
556 return tape_3590_erp_basic(device, request, irb, -EIO);
557 }
558
559 /*
560 * RDA: Read Alternate
561 */
562 static int
563 tape_3590_erp_read_alternate(struct tape_device *device,
564 struct tape_request *request, struct irb *irb)
565 {
566 struct tape_3590_disc_data *data;
567
568 /*
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
574 */
575 data = device->discdata;
576 if (data->read_back_op == READ_PREVIOUS) {
577 DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
578 device->cdev_id);
579 data->read_back_op = READ_BACKWARD;
580 } else {
581 DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
582 device->cdev_id);
583 data->read_back_op = READ_PREVIOUS;
584 }
585 tape_3590_read_opposite(device, request);
586 return tape_3590_erp_retry(device, request, irb);
587 }
588
589 /*
590 * Error Recovery read opposite
591 */
592 static int
593 tape_3590_erp_read_opposite(struct tape_device *device,
594 struct tape_request *request, struct irb *irb)
595 {
596 switch (request->op) {
597 case TO_RFO:
598 /*
599 * We did read forward, but the data could not be read.
600 * We will read backward and then skip forward again.
601 */
602 tape_3590_read_opposite(device, request);
603 return tape_3590_erp_retry(device, request, irb);
604 case TO_RBA:
605 /* We tried to read forward and backward, but hat no success */
606 return tape_3590_erp_failed(device, request, irb, -EIO);
607 break;
608 default:
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);
612 }
613 }
614
615 /*
616 * Print an MIM (Media Information Message) (message code f0)
617 */
618 static void
619 tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
620 {
621 struct tape_3590_sense *sense;
622
623 sense = (struct tape_3590_sense *) irb->ecw;
624 /* Exception Message */
625 switch (sense->fmt.f70.emc) {
626 case 0x02:
627 PRINT_WARN("(%s): Data degraded\n", device->cdev->dev.bus_id);
628 break;
629 case 0x03:
630 PRINT_WARN("(%s): Data degraded in partion %i\n",
631 device->cdev->dev.bus_id, sense->fmt.f70.mp);
632 break;
633 case 0x04:
634 PRINT_WARN("(%s): Medium degraded\n", device->cdev->dev.bus_id);
635 break;
636 case 0x05:
637 PRINT_WARN("(%s): Medium degraded in partition %i\n",
638 device->cdev->dev.bus_id, sense->fmt.f70.mp);
639 break;
640 case 0x06:
641 PRINT_WARN("(%s): Block 0 Error\n", device->cdev->dev.bus_id);
642 break;
643 case 0x07:
644 PRINT_WARN("(%s): Medium Exception 0x%02x\n",
645 device->cdev->dev.bus_id, sense->fmt.f70.md);
646 break;
647 default:
648 PRINT_WARN("(%s): MIM ExMsg: 0x%02x\n",
649 device->cdev->dev.bus_id, sense->fmt.f70.emc);
650 break;
651 }
652 /* Service Message */
653 switch (sense->fmt.f70.smc) {
654 case 0x02:
655 PRINT_WARN("(%s): Reference Media maintenance procedure %i\n",
656 device->cdev->dev.bus_id, sense->fmt.f70.md);
657 break;
658 default:
659 PRINT_WARN("(%s): MIM ServiceMsg: 0x%02x\n",
660 device->cdev->dev.bus_id, sense->fmt.f70.smc);
661 break;
662 }
663 }
664
665 /*
666 * Print an I/O Subsystem Service Information Message (message code f1)
667 */
668 static void
669 tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
670 {
671 struct tape_3590_sense *sense;
672
673 sense = (struct tape_3590_sense *) irb->ecw;
674 /* Exception Message */
675 switch (sense->fmt.f71.emc) {
676 case 0x01:
677 PRINT_WARN("(%s): Effect of failure is unknown\n",
678 device->cdev->dev.bus_id);
679 break;
680 case 0x02:
681 PRINT_WARN("(%s): CU Exception - no performance impact\n",
682 device->cdev->dev.bus_id);
683 break;
684 case 0x03:
685 PRINT_WARN("(%s): CU Exception on channel interface 0x%02x\n",
686 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
687 break;
688 case 0x04:
689 PRINT_WARN("(%s): CU Exception on device path 0x%02x\n",
690 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
691 break;
692 case 0x05:
693 PRINT_WARN("(%s): CU Exception on library path 0x%02x\n",
694 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
695 break;
696 case 0x06:
697 PRINT_WARN("(%s): CU Exception on node 0x%02x\n",
698 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
699 break;
700 case 0x07:
701 PRINT_WARN("(%s): CU Exception on partition 0x%02x\n",
702 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
703 break;
704 default:
705 PRINT_WARN("(%s): SIM ExMsg: 0x%02x\n",
706 device->cdev->dev.bus_id, sense->fmt.f71.emc);
707 }
708 /* Service Message */
709 switch (sense->fmt.f71.smc) {
710 case 0x01:
711 PRINT_WARN("(%s): Repair impact is unknown\n",
712 device->cdev->dev.bus_id);
713 break;
714 case 0x02:
715 PRINT_WARN("(%s): Repair will not impact cu performance\n",
716 device->cdev->dev.bus_id);
717 break;
718 case 0x03:
719 if (sense->fmt.f71.mdf == 0)
720 PRINT_WARN("(%s): Repair will disable node "
721 "0x%x on CU\n",
722 device->cdev->dev.bus_id,
723 sense->fmt.f71.md[1]);
724 else
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]);
729 break;
730 case 0x04:
731 if (sense->fmt.f71.mdf == 0)
732 PRINT_WARN("(%s): Repair will disable cannel path "
733 "0x%x on CU\n",
734 device->cdev->dev.bus_id,
735 sense->fmt.f71.md[1]);
736 else
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]);
741 break;
742 case 0x05:
743 if (sense->fmt.f71.mdf == 0)
744 PRINT_WARN("(%s): Repair will disable device path "
745 "0x%x on CU\n",
746 device->cdev->dev.bus_id,
747 sense->fmt.f71.md[1]);
748 else
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]);
753 break;
754 case 0x06:
755 if (sense->fmt.f71.mdf == 0)
756 PRINT_WARN("(%s): Repair will disable library path "
757 "0x%x on CU\n",
758 device->cdev->dev.bus_id,
759 sense->fmt.f71.md[1]);
760 else
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]);
765 break;
766 case 0x07:
767 PRINT_WARN("(%s): Repair will disable access to CU\n",
768 device->cdev->dev.bus_id);
769 break;
770 default:
771 PRINT_WARN("(%s): SIM ServiceMsg: 0x%02x\n",
772 device->cdev->dev.bus_id, sense->fmt.f71.smc);
773 }
774 }
775
776 /*
777 * Print an Device Subsystem Service Information Message (message code f2)
778 */
779 static void
780 tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
781 {
782 struct tape_3590_sense *sense;
783
784 sense = (struct tape_3590_sense *) irb->ecw;
785 /* Exception Message */
786 switch (sense->fmt.f71.emc) {
787 case 0x01:
788 PRINT_WARN("(%s): Effect of failure is unknown\n",
789 device->cdev->dev.bus_id);
790 break;
791 case 0x02:
792 PRINT_WARN("(%s): DV Exception - no performance impact\n",
793 device->cdev->dev.bus_id);
794 break;
795 case 0x03:
796 PRINT_WARN("(%s): DV Exception on channel interface 0x%02x\n",
797 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
798 break;
799 case 0x04:
800 PRINT_WARN("(%s): DV Exception on loader 0x%02x\n",
801 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
802 break;
803 case 0x05:
804 PRINT_WARN("(%s): DV Exception on message display 0x%02x\n",
805 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
806 break;
807 case 0x06:
808 PRINT_WARN("(%s): DV Exception in tape path\n",
809 device->cdev->dev.bus_id);
810 break;
811 case 0x07:
812 PRINT_WARN("(%s): DV Exception in drive\n",
813 device->cdev->dev.bus_id);
814 break;
815 default:
816 PRINT_WARN("(%s): DSIM ExMsg: 0x%02x\n",
817 device->cdev->dev.bus_id, sense->fmt.f71.emc);
818 }
819 /* Service Message */
820 switch (sense->fmt.f71.smc) {
821 case 0x01:
822 PRINT_WARN("(%s): Repair impact is unknown\n",
823 device->cdev->dev.bus_id);
824 break;
825 case 0x02:
826 PRINT_WARN("(%s): Repair will not impact device performance\n",
827 device->cdev->dev.bus_id);
828 break;
829 case 0x03:
830 if (sense->fmt.f71.mdf == 0)
831 PRINT_WARN("(%s): Repair will disable channel path "
832 "0x%x on DV\n",
833 device->cdev->dev.bus_id,
834 sense->fmt.f71.md[1]);
835 else
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]);
840 break;
841 case 0x04:
842 if (sense->fmt.f71.mdf == 0)
843 PRINT_WARN("(%s): Repair will disable interface 0x%x "
844 "on DV\n",
845 device->cdev->dev.bus_id,
846 sense->fmt.f71.md[1]);
847 else
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]);
852 break;
853 case 0x05:
854 if (sense->fmt.f71.mdf == 0)
855 PRINT_WARN("(%s): Repair will disable loader 0x%x "
856 "on DV\n",
857 device->cdev->dev.bus_id,
858 sense->fmt.f71.md[1]);
859 else
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]);
864 break;
865 case 0x07:
866 PRINT_WARN("(%s): Repair will disable access to DV\n",
867 device->cdev->dev.bus_id);
868 break;
869 case 0x08:
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]);
875 else
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]);
880 break;
881 case 0x09:
882 PRINT_WARN("(%s): Clean DV\n", device->cdev->dev.bus_id);
883 break;
884 default:
885 PRINT_WARN("(%s): DSIM ServiceMsg: 0x%02x\n",
886 device->cdev->dev.bus_id, sense->fmt.f71.smc);
887 }
888 }
889
890 /*
891 * Print standard ERA Message
892 */
893 static void
894 tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
895 {
896 struct tape_3590_sense *sense;
897
898 sense = (struct tape_3590_sense *) irb->ecw;
899 if (sense->mc == 0)
900 return;
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]);
905 else {
906 PRINT_WARN("(%s): Message Code 0x%x\n",
907 device->cdev->dev.bus_id, sense->mc);
908 }
909 return;
910 }
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,
918 sense->fmt.f70.fid);
919 tape_3590_print_mim_msg_f0(device, irb);
920 return;
921 }
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);
932 return;
933 }
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);
944 return;
945 }
946 if (sense->mc == 0xf3) {
947 /* Standard Library Service Information Message */
948 return;
949 }
950 PRINT_WARN("(%s): Device Message(%x)\n",
951 device->cdev->dev.bus_id, sense->mc);
952 }
953
954 /*
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.
958 */
959 static int
960 tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
961 struct irb *irb)
962 {
963 struct tape_3590_sense *sense;
964 int rc;
965
966 #ifdef CONFIG_S390_TAPE_BLOCK
967 if (request->op == TO_BLOCK) {
968 /*
969 * Recovery for block device requests. Set the block_position
970 * to something invalid and retry.
971 */
972 device->blk_data.block_position = -1;
973 if (request->retries-- <= 0)
974 return tape_3590_erp_failed(device, request, irb, -EIO);
975 else
976 return tape_3590_erp_retry(device, request, irb);
977 }
978 #endif
979
980 sense = (struct tape_3590_sense *) irb->ecw;
981
982 /*
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
986 */
987 rc = -EIO;
988 switch (sense->rc_rqc) {
989
990 case 0x1110:
991 tape_3590_print_era_msg(device, irb);
992 return tape_3590_erp_read_buf_log(device, request, irb);
993
994 case 0x2011:
995 tape_3590_print_era_msg(device, irb);
996 return tape_3590_erp_read_alternate(device, request, irb);
997
998 case 0x2230:
999 case 0x2231:
1000 tape_3590_print_era_msg(device, irb);
1001 return tape_3590_erp_special_interrupt(device, request, irb);
1002
1003 case 0x3010:
1004 DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1005 device->cdev_id);
1006 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1007 case 0x3012:
1008 DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1009 device->cdev_id);
1010 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1011 case 0x3020:
1012 DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
1013 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1014
1015 case 0x3122:
1016 DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1017 device->cdev_id);
1018 return tape_3590_erp_basic(device, request, irb, -EIO);
1019 case 0x3123:
1020 DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1021 device->cdev_id);
1022 tape_med_state_set(device, MS_UNLOADED);
1023 return tape_3590_erp_basic(device, request, irb, 0);
1024
1025 case 0x4010:
1026 /*
1027 * print additional msg since default msg
1028 * "device intervention" is not very meaningfull
1029 */
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);
1037
1038 case 0x5010:
1039 if (sense->rac == 0xd0) {
1040 /* Swap */
1041 tape_3590_print_era_msg(device, irb);
1042 return tape_3590_erp_swap(device, request, irb);
1043 }
1044 if (sense->rac == 0x26) {
1045 /* Read Opposite */
1046 tape_3590_print_era_msg(device, irb);
1047 return tape_3590_erp_read_opposite(device, request,
1048 irb);
1049 }
1050 return tape_3590_erp_basic(device, request, irb, -EIO);
1051 case 0x5020:
1052 case 0x5021:
1053 case 0x5022:
1054 case 0x5040:
1055 case 0x5041:
1056 case 0x5042:
1057 tape_3590_print_era_msg(device, irb);
1058 return tape_3590_erp_swap(device, request, irb);
1059
1060 case 0x5110:
1061 case 0x5111:
1062 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1063
1064 case 0x5120:
1065 case 0x1120:
1066 tape_med_state_set(device, MS_UNLOADED);
1067 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1068
1069 case 0x6020:
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);
1073
1074 case 0x8011:
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);
1078 case 0x8013:
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);
1084 default:
1085 return tape_3590_erp_basic(device, request, irb, -EIO);
1086 }
1087 }
1088
1089 /*
1090 * 3590 interrupt handler:
1091 */
1092 static int
1093 tape_3590_irq(struct tape_device *device, struct tape_request *request,
1094 struct irb *irb)
1095 {
1096 if (request == NULL)
1097 return tape_3590_unsolicited_irq(device, irb);
1098
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);
1104 }
1105
1106 if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
1107 return tape_3590_unit_check(device, request, irb);
1108
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)
1112 request->rescnt++;
1113 else
1114 DBF_EVENT(5, "Unit Exception!\n");
1115 }
1116
1117 return tape_3590_done(device, request);
1118 }
1119
1120 if (irb->scsw.dstat & DEV_STAT_CHN_END) {
1121 DBF_EVENT(2, "cannel end\n");
1122 return TAPE_IO_PENDING;
1123 }
1124
1125 if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
1126 DBF_EVENT(2, "Unit Attention when busy..\n");
1127 return TAPE_IO_PENDING;
1128 }
1129
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;
1135 }
1136
1137 /*
1138 * Setup device function
1139 */
1140 static int
1141 tape_3590_setup_device(struct tape_device *device)
1142 {
1143 int rc;
1144 struct tape_3590_disc_data *data;
1145
1146 DBF_EVENT(6, "3590 device setup\n");
1147 data = kmalloc(sizeof(struct tape_3590_disc_data),
1148 GFP_KERNEL | GFP_DMA);
1149 if (data == NULL)
1150 return -ENOMEM;
1151 data->read_back_op = READ_PREVIOUS;
1152 device->discdata = data;
1153
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);
1158 }
1159
1160 return rc;
1161 }
1162
1163 /*
1164 * Cleanup device function
1165 */
1166 static void
1167 tape_3590_cleanup_device(struct tape_device *device)
1168 {
1169 flush_scheduled_work();
1170 tape_std_unassign(device);
1171
1172 kfree(device->discdata);
1173 device->discdata = NULL;
1174 }
1175
1176 /*
1177 * List of 3590 magnetic tape commands.
1178 */
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,
1194 [MTRAS1] = NULL,
1195 [MTRAS2] = NULL,
1196 [MTRAS3] = NULL,
1197 [MTSETBLK] = tape_std_mtsetblk,
1198 [MTSETDENSITY] = NULL,
1199 [MTSEEK] = tape_3590_mtseek,
1200 [MTTELL] = tape_3590_mttell,
1201 [MTSETDRVBUFFER] = NULL,
1202 [MTFSS] = NULL,
1203 [MTBSS] = NULL,
1204 [MTWSM] = NULL,
1205 [MTLOCK] = NULL,
1206 [MTUNLOCK] = NULL,
1207 [MTLOAD] = tape_std_mtload,
1208 [MTUNLOAD] = tape_std_mtunload,
1209 [MTCOMPRESSION] = tape_std_mtcompression,
1210 [MTSETPART] = NULL,
1211 [MTMKPART] = NULL
1212 };
1213
1214 /*
1215 * Tape discipline structure for 3590.
1216 */
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,
1229 #endif
1230 .ioctl_fn = tape_3590_ioctl,
1231 .mtop_array = tape_3590_mtop
1232 };
1233
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 */ }
1238 };
1239
1240 static int
1241 tape_3590_online(struct ccw_device *cdev)
1242 {
1243 return tape_generic_online(cdev->dev.driver_data,
1244 &tape_discipline_3590);
1245 }
1246
1247 static int
1248 tape_3590_offline(struct ccw_device *cdev)
1249 {
1250 return tape_generic_offline(cdev->dev.driver_data);
1251 }
1252
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,
1261 };
1262
1263 /*
1264 * Setup discipline structure.
1265 */
1266 static int
1267 tape_3590_init(void)
1268 {
1269 int rc;
1270
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);
1275 #endif
1276
1277 DBF_EVENT(3, "3590 init\n");
1278 /* Register driver for 3590 tapes. */
1279 rc = ccw_driver_register(&tape_3590_driver);
1280 if (rc)
1281 DBF_EVENT(3, "3590 init failed\n");
1282 else
1283 DBF_EVENT(3, "3590 registered\n");
1284 return rc;
1285 }
1286
1287 static void
1288 tape_3590_exit(void)
1289 {
1290 ccw_driver_unregister(&tape_3590_driver);
1291
1292 debug_unregister(TAPE_DBF_AREA);
1293 }
1294
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");
1299
1300 module_init(tape_3590_init);
1301 module_exit(tape_3590_exit);