mtd: nand_base: use __func__ instead of typing names
[linux/fpc-iii.git] / drivers / s390 / char / tape_34xx.c
blob5a519fac37b7187505499ff33e95103da31a9e9a
1 /*
2 * drivers/s390/char/tape_34xx.c
3 * tape device discipline for 3480/3490 tapes.
5 * Copyright IBM Corp. 2001, 2009
6 * Author(s): Carsten Otte <cotte@de.ibm.com>
7 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
9 */
11 #define KMSG_COMPONENT "tape"
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/bio.h>
16 #include <linux/workqueue.h>
18 #define TAPE_DBF_AREA tape_34xx_dbf
20 #include "tape.h"
21 #include "tape_std.h"
24 * Pointer to debug area.
26 debug_info_t *TAPE_DBF_AREA = NULL;
27 EXPORT_SYMBOL(TAPE_DBF_AREA);
29 #define TAPE34XX_FMT_3480 0
30 #define TAPE34XX_FMT_3480_2_XF 1
31 #define TAPE34XX_FMT_3480_XF 2
33 struct tape_34xx_block_id {
34 unsigned int wrap : 1;
35 unsigned int segment : 7;
36 unsigned int format : 2;
37 unsigned int block : 22;
41 * A list of block ID's is used to faster seek blocks.
43 struct tape_34xx_sbid {
44 struct list_head list;
45 struct tape_34xx_block_id bid;
48 static void tape_34xx_delete_sbid_from(struct tape_device *, int);
51 * Medium sense for 34xx tapes. There is no 'real' medium sense call.
52 * So we just do a normal sense.
54 static int
55 tape_34xx_medium_sense(struct tape_device *device)
57 struct tape_request *request;
58 unsigned char *sense;
59 int rc;
61 request = tape_alloc_request(1, 32);
62 if (IS_ERR(request)) {
63 DBF_EXCEPTION(6, "MSEN fail\n");
64 return PTR_ERR(request);
67 request->op = TO_MSEN;
68 tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata);
70 rc = tape_do_io_interruptible(device, request);
71 if (request->rc == 0) {
72 sense = request->cpdata;
75 * This isn't quite correct. But since INTERVENTION_REQUIRED
76 * means that the drive is 'neither ready nor on-line' it is
77 * only slightly inaccurate to say there is no tape loaded if
78 * the drive isn't online...
80 if (sense[0] & SENSE_INTERVENTION_REQUIRED)
81 tape_med_state_set(device, MS_UNLOADED);
82 else
83 tape_med_state_set(device, MS_LOADED);
85 if (sense[1] & SENSE_WRITE_PROTECT)
86 device->tape_generic_status |= GMT_WR_PROT(~0);
87 else
88 device->tape_generic_status &= ~GMT_WR_PROT(~0);
89 } else {
90 DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
91 request->rc);
93 tape_free_request(request);
95 return rc;
98 struct tape_34xx_work {
99 struct tape_device *device;
100 enum tape_op op;
101 struct work_struct work;
105 * These functions are currently used only to schedule a medium_sense for
106 * later execution. This is because we get an interrupt whenever a medium
107 * is inserted but cannot call tape_do_io* from an interrupt context.
108 * Maybe that's useful for other actions we want to start from the
109 * interrupt handler.
111 static void
112 tape_34xx_work_handler(struct work_struct *work)
114 struct tape_34xx_work *p =
115 container_of(work, struct tape_34xx_work, work);
117 switch(p->op) {
118 case TO_MSEN:
119 tape_34xx_medium_sense(p->device);
120 break;
121 default:
122 DBF_EVENT(3, "T34XX: internal error: unknown work\n");
125 p->device = tape_put_device(p->device);
126 kfree(p);
129 static int
130 tape_34xx_schedule_work(struct tape_device *device, enum tape_op op)
132 struct tape_34xx_work *p;
134 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
135 return -ENOMEM;
137 INIT_WORK(&p->work, tape_34xx_work_handler);
139 p->device = tape_get_device_reference(device);
140 p->op = op;
142 schedule_work(&p->work);
143 return 0;
147 * Done Handler is called when dev stat = DEVICE-END (successful operation)
149 static inline int
150 tape_34xx_done(struct tape_request *request)
152 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
154 switch (request->op) {
155 case TO_DSE:
156 case TO_RUN:
157 case TO_WRI:
158 case TO_WTM:
159 case TO_ASSIGN:
160 case TO_UNASSIGN:
161 tape_34xx_delete_sbid_from(request->device, 0);
162 break;
163 default:
166 return TAPE_IO_SUCCESS;
169 static inline int
170 tape_34xx_erp_failed(struct tape_request *request, int rc)
172 DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
173 tape_op_verbose[request->op], rc);
174 return rc;
177 static inline int
178 tape_34xx_erp_succeeded(struct tape_request *request)
180 DBF_EVENT(3, "Error Recovery successful for %s\n",
181 tape_op_verbose[request->op]);
182 return tape_34xx_done(request);
185 static inline int
186 tape_34xx_erp_retry(struct tape_request *request)
188 DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose[request->op]);
189 return TAPE_IO_RETRY;
193 * This function is called, when no request is outstanding and we get an
194 * interrupt
196 static int
197 tape_34xx_unsolicited_irq(struct tape_device *device, struct irb *irb)
199 if (irb->scsw.cmd.dstat == 0x85) { /* READY */
200 /* A medium was inserted in the drive. */
201 DBF_EVENT(6, "xuud med\n");
202 tape_34xx_delete_sbid_from(device, 0);
203 tape_34xx_schedule_work(device, TO_MSEN);
204 } else {
205 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
206 tape_dump_sense_dbf(device, NULL, irb);
208 return TAPE_IO_SUCCESS;
212 * Read Opposite Error Recovery Function:
213 * Used, when Read Forward does not work
215 static int
216 tape_34xx_erp_read_opposite(struct tape_device *device,
217 struct tape_request *request)
219 if (request->op == TO_RFO) {
221 * We did read forward, but the data could not be read
222 * *correctly*. We transform the request to a read backward
223 * and try again.
225 tape_std_read_backward(device, request);
226 return tape_34xx_erp_retry(request);
230 * We tried to read forward and backward, but hat no
231 * success -> failed.
233 return tape_34xx_erp_failed(request, -EIO);
236 static int
237 tape_34xx_erp_bug(struct tape_device *device, struct tape_request *request,
238 struct irb *irb, int no)
240 if (request->op != TO_ASSIGN) {
241 dev_err(&device->cdev->dev, "An unexpected condition %d "
242 "occurred in tape error recovery\n", no);
243 tape_dump_sense_dbf(device, request, irb);
245 return tape_34xx_erp_failed(request, -EIO);
249 * Handle data overrun between cu and drive. The channel speed might
250 * be too slow.
252 static int
253 tape_34xx_erp_overrun(struct tape_device *device, struct tape_request *request,
254 struct irb *irb)
256 if (irb->ecw[3] == 0x40) {
257 dev_warn (&device->cdev->dev, "A data overrun occurred between"
258 " the control unit and tape unit\n");
259 return tape_34xx_erp_failed(request, -EIO);
261 return tape_34xx_erp_bug(device, request, irb, -1);
265 * Handle record sequence error.
267 static int
268 tape_34xx_erp_sequence(struct tape_device *device,
269 struct tape_request *request, struct irb *irb)
271 if (irb->ecw[3] == 0x41) {
273 * cu detected incorrect block-id sequence on tape.
275 dev_warn (&device->cdev->dev, "The block ID sequence on the "
276 "tape is incorrect\n");
277 return tape_34xx_erp_failed(request, -EIO);
280 * Record sequence error bit is set, but erpa does not
281 * show record sequence error.
283 return tape_34xx_erp_bug(device, request, irb, -2);
287 * This function analyses the tape's sense-data in case of a unit-check.
288 * If possible, it tries to recover from the error. Else the user is
289 * informed about the problem.
291 static int
292 tape_34xx_unit_check(struct tape_device *device, struct tape_request *request,
293 struct irb *irb)
295 int inhibit_cu_recovery;
296 __u8* sense;
298 inhibit_cu_recovery = (*device->modeset_byte & 0x80) ? 1 : 0;
299 sense = irb->ecw;
301 #ifdef CONFIG_S390_TAPE_BLOCK
302 if (request->op == TO_BLOCK) {
304 * Recovery for block device requests. Set the block_position
305 * to something invalid and retry.
307 device->blk_data.block_position = -1;
308 if (request->retries-- <= 0)
309 return tape_34xx_erp_failed(request, -EIO);
310 else
311 return tape_34xx_erp_retry(request);
313 #endif
315 if (
316 sense[0] & SENSE_COMMAND_REJECT &&
317 sense[1] & SENSE_WRITE_PROTECT
319 if (
320 request->op == TO_DSE ||
321 request->op == TO_WRI ||
322 request->op == TO_WTM
324 /* medium is write protected */
325 return tape_34xx_erp_failed(request, -EACCES);
326 } else {
327 return tape_34xx_erp_bug(device, request, irb, -3);
332 * Special cases for various tape-states when reaching
333 * end of recorded area
335 * FIXME: Maybe a special case of the special case:
336 * sense[0] == SENSE_EQUIPMENT_CHECK &&
337 * sense[1] == SENSE_DRIVE_ONLINE &&
338 * sense[3] == 0x47 (Volume Fenced)
340 * This was caused by continued FSF or FSR after an
341 * 'End Of Data'.
343 if ((
344 sense[0] == SENSE_DATA_CHECK ||
345 sense[0] == SENSE_EQUIPMENT_CHECK ||
346 sense[0] == SENSE_EQUIPMENT_CHECK + SENSE_DEFERRED_UNIT_CHECK
347 ) && (
348 sense[1] == SENSE_DRIVE_ONLINE ||
349 sense[1] == SENSE_BEGINNING_OF_TAPE + SENSE_WRITE_MODE
350 )) {
351 switch (request->op) {
353 * sense[0] == SENSE_DATA_CHECK &&
354 * sense[1] == SENSE_DRIVE_ONLINE
355 * sense[3] == 0x36 (End Of Data)
357 * Further seeks might return a 'Volume Fenced'.
359 case TO_FSF:
360 case TO_FSB:
361 /* Trying to seek beyond end of recorded area */
362 return tape_34xx_erp_failed(request, -ENOSPC);
363 case TO_BSB:
364 return tape_34xx_erp_retry(request);
367 * sense[0] == SENSE_DATA_CHECK &&
368 * sense[1] == SENSE_DRIVE_ONLINE &&
369 * sense[3] == 0x36 (End Of Data)
371 case TO_LBL:
372 /* Block could not be located. */
373 tape_34xx_delete_sbid_from(device, 0);
374 return tape_34xx_erp_failed(request, -EIO);
376 case TO_RFO:
377 /* Read beyond end of recorded area -> 0 bytes read */
378 return tape_34xx_erp_failed(request, 0);
381 * sense[0] == SENSE_EQUIPMENT_CHECK &&
382 * sense[1] == SENSE_DRIVE_ONLINE &&
383 * sense[3] == 0x38 (Physical End Of Volume)
385 case TO_WRI:
386 /* Writing at physical end of volume */
387 return tape_34xx_erp_failed(request, -ENOSPC);
388 default:
389 return tape_34xx_erp_failed(request, 0);
393 /* Sensing special bits */
394 if (sense[0] & SENSE_BUS_OUT_CHECK)
395 return tape_34xx_erp_retry(request);
397 if (sense[0] & SENSE_DATA_CHECK) {
399 * hardware failure, damaged tape or improper
400 * operating conditions
402 switch (sense[3]) {
403 case 0x23:
404 /* a read data check occurred */
405 if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
406 inhibit_cu_recovery)
407 // data check is not permanent, may be
408 // recovered. We always use async-mode with
409 // cu-recovery, so this should *never* happen.
410 return tape_34xx_erp_bug(device, request,
411 irb, -4);
413 /* data check is permanent, CU recovery has failed */
414 dev_warn (&device->cdev->dev, "A read error occurred "
415 "that cannot be recovered\n");
416 return tape_34xx_erp_failed(request, -EIO);
417 case 0x25:
418 // a write data check occurred
419 if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
420 inhibit_cu_recovery)
421 // data check is not permanent, may be
422 // recovered. We always use async-mode with
423 // cu-recovery, so this should *never* happen.
424 return tape_34xx_erp_bug(device, request,
425 irb, -5);
427 // data check is permanent, cu-recovery has failed
428 dev_warn (&device->cdev->dev, "A write error on the "
429 "tape cannot be recovered\n");
430 return tape_34xx_erp_failed(request, -EIO);
431 case 0x26:
432 /* Data Check (read opposite) occurred. */
433 return tape_34xx_erp_read_opposite(device, request);
434 case 0x28:
435 /* ID-Mark at tape start couldn't be written */
436 dev_warn (&device->cdev->dev, "Writing the ID-mark "
437 "failed\n");
438 return tape_34xx_erp_failed(request, -EIO);
439 case 0x31:
440 /* Tape void. Tried to read beyond end of device. */
441 dev_warn (&device->cdev->dev, "Reading the tape beyond"
442 " the end of the recorded area failed\n");
443 return tape_34xx_erp_failed(request, -ENOSPC);
444 case 0x41:
445 /* Record sequence error. */
446 dev_warn (&device->cdev->dev, "The tape contains an "
447 "incorrect block ID sequence\n");
448 return tape_34xx_erp_failed(request, -EIO);
449 default:
450 /* all data checks for 3480 should result in one of
451 * the above erpa-codes. For 3490, other data-check
452 * conditions do exist. */
453 if (device->cdev->id.driver_info == tape_3480)
454 return tape_34xx_erp_bug(device, request,
455 irb, -6);
459 if (sense[0] & SENSE_OVERRUN)
460 return tape_34xx_erp_overrun(device, request, irb);
462 if (sense[1] & SENSE_RECORD_SEQUENCE_ERR)
463 return tape_34xx_erp_sequence(device, request, irb);
465 /* Sensing erpa codes */
466 switch (sense[3]) {
467 case 0x00:
468 /* Unit check with erpa code 0. Report and ignore. */
469 return TAPE_IO_SUCCESS;
470 case 0x21:
472 * Data streaming not operational. CU will switch to
473 * interlock mode. Reissue the command.
475 return tape_34xx_erp_retry(request);
476 case 0x22:
478 * Path equipment check. Might be drive adapter error, buffer
479 * error on the lower interface, internal path not usable,
480 * or error during cartridge load.
482 dev_warn (&device->cdev->dev, "A path equipment check occurred"
483 " for the tape device\n");
484 return tape_34xx_erp_failed(request, -EIO);
485 case 0x24:
487 * Load display check. Load display was command was issued,
488 * but the drive is displaying a drive check message. Can
489 * be threated as "device end".
491 return tape_34xx_erp_succeeded(request);
492 case 0x27:
494 * Command reject. May indicate illegal channel program or
495 * buffer over/underrun. Since all channel programs are
496 * issued by this driver and ought be correct, we assume a
497 * over/underrun situation and retry the channel program.
499 return tape_34xx_erp_retry(request);
500 case 0x29:
502 * Function incompatible. Either the tape is idrc compressed
503 * but the hardware isn't capable to do idrc, or a perform
504 * subsystem func is issued and the CU is not on-line.
506 return tape_34xx_erp_failed(request, -EIO);
507 case 0x2a:
509 * Unsolicited environmental data. An internal counter
510 * overflows, we can ignore this and reissue the cmd.
512 return tape_34xx_erp_retry(request);
513 case 0x2b:
515 * Environmental data present. Indicates either unload
516 * completed ok or read buffered log command completed ok.
518 if (request->op == TO_RUN) {
519 /* Rewind unload completed ok. */
520 tape_med_state_set(device, MS_UNLOADED);
521 return tape_34xx_erp_succeeded(request);
523 /* tape_34xx doesn't use read buffered log commands. */
524 return tape_34xx_erp_bug(device, request, irb, sense[3]);
525 case 0x2c:
527 * Permanent equipment check. CU has tried recovery, but
528 * did not succeed.
530 return tape_34xx_erp_failed(request, -EIO);
531 case 0x2d:
532 /* Data security erase failure. */
533 if (request->op == TO_DSE)
534 return tape_34xx_erp_failed(request, -EIO);
535 /* Data security erase failure, but no such command issued. */
536 return tape_34xx_erp_bug(device, request, irb, sense[3]);
537 case 0x2e:
539 * Not capable. This indicates either that the drive fails
540 * reading the format id mark or that that format specified
541 * is not supported by the drive.
543 dev_warn (&device->cdev->dev, "The tape unit cannot process "
544 "the tape format\n");
545 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
546 case 0x30:
547 /* The medium is write protected. */
548 dev_warn (&device->cdev->dev, "The tape medium is write-"
549 "protected\n");
550 return tape_34xx_erp_failed(request, -EACCES);
551 case 0x32:
552 // Tension loss. We cannot recover this, it's an I/O error.
553 dev_warn (&device->cdev->dev, "The tape does not have the "
554 "required tape tension\n");
555 return tape_34xx_erp_failed(request, -EIO);
556 case 0x33:
558 * Load Failure. The cartridge was not inserted correctly or
559 * the tape is not threaded correctly.
561 dev_warn (&device->cdev->dev, "The tape unit failed to load"
562 " the cartridge\n");
563 tape_34xx_delete_sbid_from(device, 0);
564 return tape_34xx_erp_failed(request, -EIO);
565 case 0x34:
567 * Unload failure. The drive cannot maintain tape tension
568 * and control tape movement during an unload operation.
570 dev_warn (&device->cdev->dev, "Automatic unloading of the tape"
571 " cartridge failed\n");
572 if (request->op == TO_RUN)
573 return tape_34xx_erp_failed(request, -EIO);
574 return tape_34xx_erp_bug(device, request, irb, sense[3]);
575 case 0x35:
577 * Drive equipment check. One of the following:
578 * - cu cannot recover from a drive detected error
579 * - a check code message is shown on drive display
580 * - the cartridge loader does not respond correctly
581 * - a failure occurs during an index, load, or unload cycle
583 dev_warn (&device->cdev->dev, "An equipment check has occurred"
584 " on the tape unit\n");
585 return tape_34xx_erp_failed(request, -EIO);
586 case 0x36:
587 if (device->cdev->id.driver_info == tape_3490)
588 /* End of data. */
589 return tape_34xx_erp_failed(request, -EIO);
590 /* This erpa is reserved for 3480 */
591 return tape_34xx_erp_bug(device, request, irb, sense[3]);
592 case 0x37:
594 * Tape length error. The tape is shorter than reported in
595 * the beginning-of-tape data.
597 dev_warn (&device->cdev->dev, "The tape information states an"
598 " incorrect length\n");
599 return tape_34xx_erp_failed(request, -EIO);
600 case 0x38:
602 * Physical end of tape. A read/write operation reached
603 * the physical end of tape.
605 if (request->op==TO_WRI ||
606 request->op==TO_DSE ||
607 request->op==TO_WTM)
608 return tape_34xx_erp_failed(request, -ENOSPC);
609 return tape_34xx_erp_failed(request, -EIO);
610 case 0x39:
611 /* Backward at Beginning of tape. */
612 return tape_34xx_erp_failed(request, -EIO);
613 case 0x3a:
614 /* Drive switched to not ready. */
615 dev_warn (&device->cdev->dev, "The tape unit is not ready\n");
616 return tape_34xx_erp_failed(request, -EIO);
617 case 0x3b:
618 /* Manual rewind or unload. This causes an I/O error. */
619 dev_warn (&device->cdev->dev, "The tape medium has been "
620 "rewound or unloaded manually\n");
621 tape_34xx_delete_sbid_from(device, 0);
622 return tape_34xx_erp_failed(request, -EIO);
623 case 0x42:
625 * Degraded mode. A condition that can cause degraded
626 * performance is detected.
628 dev_warn (&device->cdev->dev, "The tape subsystem is running "
629 "in degraded mode\n");
630 return tape_34xx_erp_retry(request);
631 case 0x43:
632 /* Drive not ready. */
633 tape_34xx_delete_sbid_from(device, 0);
634 tape_med_state_set(device, MS_UNLOADED);
635 /* Some commands commands are successful even in this case */
636 if (sense[1] & SENSE_DRIVE_ONLINE) {
637 switch(request->op) {
638 case TO_ASSIGN:
639 case TO_UNASSIGN:
640 case TO_DIS:
641 case TO_NOP:
642 return tape_34xx_done(request);
643 break;
644 default:
645 break;
648 return tape_34xx_erp_failed(request, -ENOMEDIUM);
649 case 0x44:
650 /* Locate Block unsuccessful. */
651 if (request->op != TO_BLOCK && request->op != TO_LBL)
652 /* No locate block was issued. */
653 return tape_34xx_erp_bug(device, request,
654 irb, sense[3]);
655 return tape_34xx_erp_failed(request, -EIO);
656 case 0x45:
657 /* The drive is assigned to a different channel path. */
658 dev_warn (&device->cdev->dev, "The tape unit is already "
659 "assigned\n");
660 return tape_34xx_erp_failed(request, -EIO);
661 case 0x46:
663 * Drive not on-line. Drive may be switched offline,
664 * the power supply may be switched off or
665 * the drive address may not be set correctly.
667 dev_warn (&device->cdev->dev, "The tape unit is not online\n");
668 return tape_34xx_erp_failed(request, -EIO);
669 case 0x47:
670 /* Volume fenced. CU reports volume integrity is lost. */
671 dev_warn (&device->cdev->dev, "The control unit has fenced "
672 "access to the tape volume\n");
673 tape_34xx_delete_sbid_from(device, 0);
674 return tape_34xx_erp_failed(request, -EIO);
675 case 0x48:
676 /* Log sense data and retry request. */
677 return tape_34xx_erp_retry(request);
678 case 0x49:
679 /* Bus out check. A parity check error on the bus was found. */
680 dev_warn (&device->cdev->dev, "A parity error occurred on the "
681 "tape bus\n");
682 return tape_34xx_erp_failed(request, -EIO);
683 case 0x4a:
684 /* Control unit erp failed. */
685 dev_warn (&device->cdev->dev, "I/O error recovery failed on "
686 "the tape control unit\n");
687 return tape_34xx_erp_failed(request, -EIO);
688 case 0x4b:
690 * CU and drive incompatible. The drive requests micro-program
691 * patches, which are not available on the CU.
693 dev_warn (&device->cdev->dev, "The tape unit requires a "
694 "firmware update\n");
695 return tape_34xx_erp_failed(request, -EIO);
696 case 0x4c:
698 * Recovered Check-One failure. Cu develops a hardware error,
699 * but is able to recover.
701 return tape_34xx_erp_retry(request);
702 case 0x4d:
703 if (device->cdev->id.driver_info == tape_3490)
705 * Resetting event received. Since the driver does
706 * not support resetting event recovery (which has to
707 * be handled by the I/O Layer), retry our command.
709 return tape_34xx_erp_retry(request);
710 /* This erpa is reserved for 3480. */
711 return tape_34xx_erp_bug(device, request, irb, sense[3]);
712 case 0x4e:
713 if (device->cdev->id.driver_info == tape_3490) {
715 * Maximum block size exceeded. This indicates, that
716 * the block to be written is larger than allowed for
717 * buffered mode.
719 dev_warn (&device->cdev->dev, "The maximum block size"
720 " for buffered mode is exceeded\n");
721 return tape_34xx_erp_failed(request, -ENOBUFS);
723 /* This erpa is reserved for 3480. */
724 return tape_34xx_erp_bug(device, request, irb, sense[3]);
725 case 0x50:
727 * Read buffered log (Overflow). CU is running in extended
728 * buffered log mode, and a counter overflows. This should
729 * never happen, since we're never running in extended
730 * buffered log mode.
732 return tape_34xx_erp_retry(request);
733 case 0x51:
735 * Read buffered log (EOV). EOF processing occurs while the
736 * CU is in extended buffered log mode. This should never
737 * happen, since we're never running in extended buffered
738 * log mode.
740 return tape_34xx_erp_retry(request);
741 case 0x52:
742 /* End of Volume complete. Rewind unload completed ok. */
743 if (request->op == TO_RUN) {
744 tape_med_state_set(device, MS_UNLOADED);
745 tape_34xx_delete_sbid_from(device, 0);
746 return tape_34xx_erp_succeeded(request);
748 return tape_34xx_erp_bug(device, request, irb, sense[3]);
749 case 0x53:
750 /* Global command intercept. */
751 return tape_34xx_erp_retry(request);
752 case 0x54:
753 /* Channel interface recovery (temporary). */
754 return tape_34xx_erp_retry(request);
755 case 0x55:
756 /* Channel interface recovery (permanent). */
757 dev_warn (&device->cdev->dev, "A channel interface error cannot be"
758 " recovered\n");
759 return tape_34xx_erp_failed(request, -EIO);
760 case 0x56:
761 /* Channel protocol error. */
762 dev_warn (&device->cdev->dev, "A channel protocol error "
763 "occurred\n");
764 return tape_34xx_erp_failed(request, -EIO);
765 case 0x57:
766 if (device->cdev->id.driver_info == tape_3480) {
767 /* Attention intercept. */
768 return tape_34xx_erp_retry(request);
769 } else {
770 /* Global status intercept. */
771 return tape_34xx_erp_retry(request);
773 case 0x5a:
775 * Tape length incompatible. The tape inserted is too long,
776 * which could cause damage to the tape or the drive.
778 dev_warn (&device->cdev->dev, "The tape unit does not support "
779 "the tape length\n");
780 return tape_34xx_erp_failed(request, -EIO);
781 case 0x5b:
782 /* Format 3480 XF incompatible */
783 if (sense[1] & SENSE_BEGINNING_OF_TAPE)
784 /* The tape will get overwritten. */
785 return tape_34xx_erp_retry(request);
786 dev_warn (&device->cdev->dev, "The tape unit does not support"
787 " format 3480 XF\n");
788 return tape_34xx_erp_failed(request, -EIO);
789 case 0x5c:
790 /* Format 3480-2 XF incompatible */
791 dev_warn (&device->cdev->dev, "The tape unit does not support tape "
792 "format 3480-2 XF\n");
793 return tape_34xx_erp_failed(request, -EIO);
794 case 0x5d:
795 /* Tape length violation. */
796 dev_warn (&device->cdev->dev, "The tape unit does not support"
797 " the current tape length\n");
798 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
799 case 0x5e:
800 /* Compaction algorithm incompatible. */
801 dev_warn (&device->cdev->dev, "The tape unit does not support"
802 " the compaction algorithm\n");
803 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
805 /* The following erpas should have been covered earlier. */
806 case 0x23: /* Read data check. */
807 case 0x25: /* Write data check. */
808 case 0x26: /* Data check (read opposite). */
809 case 0x28: /* Write id mark check. */
810 case 0x31: /* Tape void. */
811 case 0x40: /* Overrun error. */
812 case 0x41: /* Record sequence error. */
813 /* All other erpas are reserved for future use. */
814 default:
815 return tape_34xx_erp_bug(device, request, irb, sense[3]);
820 * 3480/3490 interrupt handler
822 static int
823 tape_34xx_irq(struct tape_device *device, struct tape_request *request,
824 struct irb *irb)
826 if (request == NULL)
827 return tape_34xx_unsolicited_irq(device, irb);
829 if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
830 (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
831 (request->op == TO_WRI)) {
832 /* Write at end of volume */
833 return tape_34xx_erp_failed(request, -ENOSPC);
836 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
837 return tape_34xx_unit_check(device, request, irb);
839 if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
841 * A unit exception occurs on skipping over a tapemark block.
843 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
844 if (request->op == TO_BSB || request->op == TO_FSB)
845 request->rescnt++;
846 else
847 DBF_EVENT(5, "Unit Exception!\n");
849 return tape_34xx_done(request);
852 DBF_EVENT(6, "xunknownirq\n");
853 tape_dump_sense_dbf(device, request, irb);
854 return TAPE_IO_STOP;
858 * ioctl_overload
860 static int
861 tape_34xx_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
863 if (cmd == TAPE390_DISPLAY) {
864 struct display_struct disp;
866 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)) != 0)
867 return -EFAULT;
869 return tape_std_display(device, &disp);
870 } else
871 return -EINVAL;
874 static inline void
875 tape_34xx_append_new_sbid(struct tape_34xx_block_id bid, struct list_head *l)
877 struct tape_34xx_sbid * new_sbid;
879 new_sbid = kmalloc(sizeof(*new_sbid), GFP_ATOMIC);
880 if (!new_sbid)
881 return;
883 new_sbid->bid = bid;
884 list_add(&new_sbid->list, l);
888 * Build up the search block ID list. The block ID consists of a logical
889 * block number and a hardware specific part. The hardware specific part
890 * helps the tape drive to speed up searching for a specific block.
892 static void
893 tape_34xx_add_sbid(struct tape_device *device, struct tape_34xx_block_id bid)
895 struct list_head * sbid_list;
896 struct tape_34xx_sbid * sbid;
897 struct list_head * l;
900 * immediately return if there is no list at all or the block to add
901 * is located in segment 1 of wrap 0 because this position is used
902 * if no hardware position data is supplied.
904 sbid_list = (struct list_head *) device->discdata;
905 if (!sbid_list || (bid.segment < 2 && bid.wrap == 0))
906 return;
909 * Search the position where to insert the new entry. Hardware
910 * acceleration uses only the segment and wrap number. So we
911 * need only one entry for a specific wrap/segment combination.
912 * If there is a block with a lower number but the same hard-
913 * ware position data we just update the block number in the
914 * existing entry.
916 list_for_each(l, sbid_list) {
917 sbid = list_entry(l, struct tape_34xx_sbid, list);
919 if (
920 (sbid->bid.segment == bid.segment) &&
921 (sbid->bid.wrap == bid.wrap)
923 if (bid.block < sbid->bid.block)
924 sbid->bid = bid;
925 else return;
926 break;
929 /* Sort in according to logical block number. */
930 if (bid.block < sbid->bid.block) {
931 tape_34xx_append_new_sbid(bid, l->prev);
932 break;
935 /* List empty or new block bigger than last entry. */
936 if (l == sbid_list)
937 tape_34xx_append_new_sbid(bid, l->prev);
939 DBF_LH(4, "Current list is:\n");
940 list_for_each(l, sbid_list) {
941 sbid = list_entry(l, struct tape_34xx_sbid, list);
942 DBF_LH(4, "%d:%03d@%05d\n",
943 sbid->bid.wrap,
944 sbid->bid.segment,
945 sbid->bid.block
951 * Delete all entries from the search block ID list that belong to tape blocks
952 * equal or higher than the given number.
954 static void
955 tape_34xx_delete_sbid_from(struct tape_device *device, int from)
957 struct list_head * sbid_list;
958 struct tape_34xx_sbid * sbid;
959 struct list_head * l;
960 struct list_head * n;
962 sbid_list = (struct list_head *) device->discdata;
963 if (!sbid_list)
964 return;
966 list_for_each_safe(l, n, sbid_list) {
967 sbid = list_entry(l, struct tape_34xx_sbid, list);
968 if (sbid->bid.block >= from) {
969 DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
970 sbid->bid.wrap,
971 sbid->bid.segment,
972 sbid->bid.block
974 list_del(l);
975 kfree(sbid);
981 * Merge hardware position data into a block id.
983 static void
984 tape_34xx_merge_sbid(
985 struct tape_device * device,
986 struct tape_34xx_block_id * bid
988 struct tape_34xx_sbid * sbid;
989 struct tape_34xx_sbid * sbid_to_use;
990 struct list_head * sbid_list;
991 struct list_head * l;
993 sbid_list = (struct list_head *) device->discdata;
994 bid->wrap = 0;
995 bid->segment = 1;
997 if (!sbid_list || list_empty(sbid_list))
998 return;
1000 sbid_to_use = NULL;
1001 list_for_each(l, sbid_list) {
1002 sbid = list_entry(l, struct tape_34xx_sbid, list);
1004 if (sbid->bid.block >= bid->block)
1005 break;
1006 sbid_to_use = sbid;
1008 if (sbid_to_use) {
1009 bid->wrap = sbid_to_use->bid.wrap;
1010 bid->segment = sbid_to_use->bid.segment;
1011 DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
1012 sbid_to_use->bid.wrap,
1013 sbid_to_use->bid.segment,
1014 sbid_to_use->bid.block,
1015 bid->block
1020 static int
1021 tape_34xx_setup_device(struct tape_device * device)
1023 int rc;
1024 struct list_head * discdata;
1026 DBF_EVENT(6, "34xx device setup\n");
1027 if ((rc = tape_std_assign(device)) == 0) {
1028 if ((rc = tape_34xx_medium_sense(device)) != 0) {
1029 DBF_LH(3, "34xx medium sense returned %d\n", rc);
1032 discdata = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1033 if (discdata) {
1034 INIT_LIST_HEAD(discdata);
1035 device->discdata = discdata;
1038 return rc;
1041 static void
1042 tape_34xx_cleanup_device(struct tape_device *device)
1044 tape_std_unassign(device);
1046 if (device->discdata) {
1047 tape_34xx_delete_sbid_from(device, 0);
1048 kfree(device->discdata);
1049 device->discdata = NULL;
1055 * MTTELL: Tell block. Return the number of block relative to current file.
1057 static int
1058 tape_34xx_mttell(struct tape_device *device, int mt_count)
1060 struct {
1061 struct tape_34xx_block_id cbid;
1062 struct tape_34xx_block_id dbid;
1063 } __attribute__ ((packed)) block_id;
1064 int rc;
1066 rc = tape_std_read_block_id(device, (__u64 *) &block_id);
1067 if (rc)
1068 return rc;
1070 tape_34xx_add_sbid(device, block_id.cbid);
1071 return block_id.cbid.block;
1075 * MTSEEK: seek to the specified block.
1077 static int
1078 tape_34xx_mtseek(struct tape_device *device, int mt_count)
1080 struct tape_request *request;
1081 struct tape_34xx_block_id * bid;
1083 if (mt_count > 0x3fffff) {
1084 DBF_EXCEPTION(6, "xsee parm\n");
1085 return -EINVAL;
1087 request = tape_alloc_request(3, 4);
1088 if (IS_ERR(request))
1089 return PTR_ERR(request);
1091 /* setup ccws */
1092 request->op = TO_LBL;
1093 bid = (struct tape_34xx_block_id *) request->cpdata;
1094 bid->format = (*device->modeset_byte & 0x08) ?
1095 TAPE34XX_FMT_3480_XF : TAPE34XX_FMT_3480;
1096 bid->block = mt_count;
1097 tape_34xx_merge_sbid(device, bid);
1099 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
1100 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1101 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
1103 /* execute it */
1104 return tape_do_io_free(device, request);
1107 #ifdef CONFIG_S390_TAPE_BLOCK
1109 * Tape block read for 34xx.
1111 static struct tape_request *
1112 tape_34xx_bread(struct tape_device *device, struct request *req)
1114 struct tape_request *request;
1115 struct ccw1 *ccw;
1116 int count = 0;
1117 unsigned off;
1118 char *dst;
1119 struct bio_vec *bv;
1120 struct req_iterator iter;
1121 struct tape_34xx_block_id * start_block;
1123 DBF_EVENT(6, "xBREDid:");
1125 /* Count the number of blocks for the request. */
1126 rq_for_each_segment(bv, req, iter)
1127 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
1129 /* Allocate the ccw request. */
1130 request = tape_alloc_request(3+count+1, 8);
1131 if (IS_ERR(request))
1132 return request;
1134 /* Setup ccws. */
1135 request->op = TO_BLOCK;
1136 start_block = (struct tape_34xx_block_id *) request->cpdata;
1137 start_block->block = blk_rq_pos(req) >> TAPEBLOCK_HSEC_S2B;
1138 DBF_EVENT(6, "start_block = %i\n", start_block->block);
1140 ccw = request->cpaddr;
1141 ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);
1144 * We always setup a nop after the mode set ccw. This slot is
1145 * used in tape_std_check_locate to insert a locate ccw if the
1146 * current tape position doesn't match the start block to be read.
1147 * The second nop will be filled with a read block id which is in
1148 * turn used by tape_34xx_free_bread to populate the segment bid
1149 * table.
1151 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
1152 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
1154 rq_for_each_segment(bv, req, iter) {
1155 dst = kmap(bv->bv_page) + bv->bv_offset;
1156 for (off = 0; off < bv->bv_len; off += TAPEBLOCK_HSEC_SIZE) {
1157 ccw->flags = CCW_FLAG_CC;
1158 ccw->cmd_code = READ_FORWARD;
1159 ccw->count = TAPEBLOCK_HSEC_SIZE;
1160 set_normalized_cda(ccw, (void*) __pa(dst));
1161 ccw++;
1162 dst += TAPEBLOCK_HSEC_SIZE;
1166 ccw = tape_ccw_end(ccw, NOP, 0, NULL);
1167 DBF_EVENT(6, "xBREDccwg\n");
1168 return request;
1171 static void
1172 tape_34xx_free_bread (struct tape_request *request)
1174 struct ccw1* ccw;
1176 ccw = request->cpaddr;
1177 if ((ccw + 2)->cmd_code == READ_BLOCK_ID) {
1178 struct {
1179 struct tape_34xx_block_id cbid;
1180 struct tape_34xx_block_id dbid;
1181 } __attribute__ ((packed)) *rbi_data;
1183 rbi_data = request->cpdata;
1185 if (request->device)
1186 tape_34xx_add_sbid(request->device, rbi_data->cbid);
1189 /* Last ccw is a nop and doesn't need clear_normalized_cda */
1190 for (; ccw->flags & CCW_FLAG_CC; ccw++)
1191 if (ccw->cmd_code == READ_FORWARD)
1192 clear_normalized_cda(ccw);
1193 tape_free_request(request);
1197 * check_locate is called just before the tape request is passed to
1198 * the common io layer for execution. It has to check the current
1199 * tape position and insert a locate ccw if it doesn't match the
1200 * start block for the request.
1202 static void
1203 tape_34xx_check_locate(struct tape_device *device, struct tape_request *request)
1205 struct tape_34xx_block_id * start_block;
1207 start_block = (struct tape_34xx_block_id *) request->cpdata;
1208 if (start_block->block == device->blk_data.block_position)
1209 return;
1211 DBF_LH(4, "Block seek(%06d+%06d)\n", start_block->block, device->bof);
1212 start_block->wrap = 0;
1213 start_block->segment = 1;
1214 start_block->format = (*device->modeset_byte & 0x08) ?
1215 TAPE34XX_FMT_3480_XF :
1216 TAPE34XX_FMT_3480;
1217 start_block->block = start_block->block + device->bof;
1218 tape_34xx_merge_sbid(device, start_block);
1219 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1220 tape_ccw_cc(request->cpaddr + 2, READ_BLOCK_ID, 8, request->cpdata);
1222 #endif
1225 * List of 3480/3490 magnetic tape commands.
1227 static tape_mtop_fn tape_34xx_mtop[TAPE_NR_MTOPS] = {
1228 [MTRESET] = tape_std_mtreset,
1229 [MTFSF] = tape_std_mtfsf,
1230 [MTBSF] = tape_std_mtbsf,
1231 [MTFSR] = tape_std_mtfsr,
1232 [MTBSR] = tape_std_mtbsr,
1233 [MTWEOF] = tape_std_mtweof,
1234 [MTREW] = tape_std_mtrew,
1235 [MTOFFL] = tape_std_mtoffl,
1236 [MTNOP] = tape_std_mtnop,
1237 [MTRETEN] = tape_std_mtreten,
1238 [MTBSFM] = tape_std_mtbsfm,
1239 [MTFSFM] = tape_std_mtfsfm,
1240 [MTEOM] = tape_std_mteom,
1241 [MTERASE] = tape_std_mterase,
1242 [MTRAS1] = NULL,
1243 [MTRAS2] = NULL,
1244 [MTRAS3] = NULL,
1245 [MTSETBLK] = tape_std_mtsetblk,
1246 [MTSETDENSITY] = NULL,
1247 [MTSEEK] = tape_34xx_mtseek,
1248 [MTTELL] = tape_34xx_mttell,
1249 [MTSETDRVBUFFER] = NULL,
1250 [MTFSS] = NULL,
1251 [MTBSS] = NULL,
1252 [MTWSM] = NULL,
1253 [MTLOCK] = NULL,
1254 [MTUNLOCK] = NULL,
1255 [MTLOAD] = tape_std_mtload,
1256 [MTUNLOAD] = tape_std_mtunload,
1257 [MTCOMPRESSION] = tape_std_mtcompression,
1258 [MTSETPART] = NULL,
1259 [MTMKPART] = NULL
1263 * Tape discipline structure for 3480 and 3490.
1265 static struct tape_discipline tape_discipline_34xx = {
1266 .owner = THIS_MODULE,
1267 .setup_device = tape_34xx_setup_device,
1268 .cleanup_device = tape_34xx_cleanup_device,
1269 .process_eov = tape_std_process_eov,
1270 .irq = tape_34xx_irq,
1271 .read_block = tape_std_read_block,
1272 .write_block = tape_std_write_block,
1273 #ifdef CONFIG_S390_TAPE_BLOCK
1274 .bread = tape_34xx_bread,
1275 .free_bread = tape_34xx_free_bread,
1276 .check_locate = tape_34xx_check_locate,
1277 #endif
1278 .ioctl_fn = tape_34xx_ioctl,
1279 .mtop_array = tape_34xx_mtop
1282 static struct ccw_device_id tape_34xx_ids[] = {
1283 { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), .driver_info = tape_3480},
1284 { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), .driver_info = tape_3490},
1285 { /* end of list */ },
1288 static int
1289 tape_34xx_online(struct ccw_device *cdev)
1291 return tape_generic_online(
1292 dev_get_drvdata(&cdev->dev),
1293 &tape_discipline_34xx
1297 static struct ccw_driver tape_34xx_driver = {
1298 .name = "tape_34xx",
1299 .owner = THIS_MODULE,
1300 .ids = tape_34xx_ids,
1301 .probe = tape_generic_probe,
1302 .remove = tape_generic_remove,
1303 .set_online = tape_34xx_online,
1304 .set_offline = tape_generic_offline,
1305 .freeze = tape_generic_pm_suspend,
1308 static int
1309 tape_34xx_init (void)
1311 int rc;
1313 TAPE_DBF_AREA = debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
1314 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1315 #ifdef DBF_LIKE_HELL
1316 debug_set_level(TAPE_DBF_AREA, 6);
1317 #endif
1319 DBF_EVENT(3, "34xx init\n");
1320 /* Register driver for 3480/3490 tapes. */
1321 rc = ccw_driver_register(&tape_34xx_driver);
1322 if (rc)
1323 DBF_EVENT(3, "34xx init failed\n");
1324 else
1325 DBF_EVENT(3, "34xx registered\n");
1326 return rc;
1329 static void
1330 tape_34xx_exit(void)
1332 ccw_driver_unregister(&tape_34xx_driver);
1334 debug_unregister(TAPE_DBF_AREA);
1337 MODULE_DEVICE_TABLE(ccw, tape_34xx_ids);
1338 MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
1339 MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape device driver");
1340 MODULE_LICENSE("GPL");
1342 module_init(tape_34xx_init);
1343 module_exit(tape_34xx_exit);