2 * drivers/s390/char/tape_34xx.c
3 * tape device discipline for 3480/3490 tapes.
5 * Copyright (C) IBM Corp. 2001,2006
6 * Author(s): Carsten Otte <cotte@de.ibm.com>
7 * Tuan Ngo-Anh <ngoanh@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>
14 #include <linux/workqueue.h>
16 #define TAPE_DBF_AREA tape_34xx_dbf
21 #define PRINTK_HEADER "TAPE_34XX: "
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.
55 tape_34xx_medium_sense(struct tape_device *device)
57 struct tape_request *request;
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);
83 tape_med_state_set(device, MS_LOADED);
85 if (sense[1] & SENSE_WRITE_PROTECT)
86 device->tape_generic_status |= GMT_WR_PROT(~0);
88 device->tape_generic_status &= ~GMT_WR_PROT(~0);
90 DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
93 tape_free_request(request);
99 * These functions are currently used only to schedule a medium_sense for
100 * later execution. This is because we get an interrupt whenever a medium
101 * is inserted but cannot call tape_do_io* from an interrupt context.
102 * Maybe that's useful for other actions we want to start from the
106 tape_34xx_work_handler(void *data)
109 struct tape_device *device;
111 struct work_struct work;
116 tape_34xx_medium_sense(p->device);
119 DBF_EVENT(3, "T34XX: internal error: unknown work\n");
122 p->device = tape_put_device(p->device);
127 tape_34xx_schedule_work(struct tape_device *device, enum tape_op op)
130 struct tape_device *device;
132 struct work_struct work;
135 if ((p = kmalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
138 memset(p, 0, sizeof(*p));
139 INIT_WORK(&p->work, tape_34xx_work_handler, p);
141 p->device = tape_get_device_reference(device);
144 schedule_work(&p->work);
149 * Done Handler is called when dev stat = DEVICE-END (successful operation)
152 tape_34xx_done(struct tape_request *request)
154 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
156 switch (request->op) {
163 tape_34xx_delete_sbid_from(request->device, 0);
168 return TAPE_IO_SUCCESS;
172 tape_34xx_erp_failed(struct tape_request *request, int rc)
174 DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
175 tape_op_verbose[request->op], rc);
180 tape_34xx_erp_succeeded(struct tape_request *request)
182 DBF_EVENT(3, "Error Recovery successful for %s\n",
183 tape_op_verbose[request->op]);
184 return tape_34xx_done(request);
188 tape_34xx_erp_retry(struct tape_request *request)
190 DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose[request->op]);
191 return TAPE_IO_RETRY;
195 * This function is called, when no request is outstanding and we get an
199 tape_34xx_unsolicited_irq(struct tape_device *device, struct irb *irb)
201 if (irb->scsw.dstat == 0x85 /* READY */) {
202 /* A medium was inserted in the drive. */
203 DBF_EVENT(6, "xuud med\n");
204 tape_34xx_delete_sbid_from(device, 0);
205 tape_34xx_schedule_work(device, TO_MSEN);
207 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
208 PRINT_WARN("Unsolicited IRQ (Device End) caught.\n");
209 tape_dump_sense(device, NULL, irb);
211 return TAPE_IO_SUCCESS;
215 * Read Opposite Error Recovery Function:
216 * Used, when Read Forward does not work
219 tape_34xx_erp_read_opposite(struct tape_device *device,
220 struct tape_request *request)
222 if (request->op == TO_RFO) {
224 * We did read forward, but the data could not be read
225 * *correctly*. We transform the request to a read backward
228 tape_std_read_backward(device, request);
229 return tape_34xx_erp_retry(request);
231 if (request->op != TO_RBA)
232 PRINT_ERR("read_opposite called with state:%s\n",
233 tape_op_verbose[request->op]);
235 * We tried to read forward and backward, but hat no
238 return tape_34xx_erp_failed(request, -EIO);
242 tape_34xx_erp_bug(struct tape_device *device, struct tape_request *request,
243 struct irb *irb, int no)
245 if (request->op != TO_ASSIGN) {
246 PRINT_WARN("An unexpected condition #%d was caught in "
247 "tape error recovery.\n", no);
248 PRINT_WARN("Please report this incident.\n");
250 PRINT_WARN("Operation of tape:%s\n",
251 tape_op_verbose[request->op]);
252 tape_dump_sense(device, request, irb);
254 return tape_34xx_erp_failed(request, -EIO);
258 * Handle data overrun between cu and drive. The channel speed might
262 tape_34xx_erp_overrun(struct tape_device *device, struct tape_request *request,
265 if (irb->ecw[3] == 0x40) {
266 PRINT_WARN ("Data overrun error between control-unit "
267 "and drive. Use a faster channel connection, "
269 return tape_34xx_erp_failed(request, -EIO);
271 return tape_34xx_erp_bug(device, request, irb, -1);
275 * Handle record sequence error.
278 tape_34xx_erp_sequence(struct tape_device *device,
279 struct tape_request *request, struct irb *irb)
281 if (irb->ecw[3] == 0x41) {
283 * cu detected incorrect block-id sequence on tape.
285 PRINT_WARN("Illegal block-id sequence found!\n");
286 return tape_34xx_erp_failed(request, -EIO);
289 * Record sequence error bit is set, but erpa does not
290 * show record sequence error.
292 return tape_34xx_erp_bug(device, request, irb, -2);
296 * This function analyses the tape's sense-data in case of a unit-check.
297 * If possible, it tries to recover from the error. Else the user is
298 * informed about the problem.
301 tape_34xx_unit_check(struct tape_device *device, struct tape_request *request,
304 int inhibit_cu_recovery;
307 inhibit_cu_recovery = (*device->modeset_byte & 0x80) ? 1 : 0;
310 #ifdef CONFIG_S390_TAPE_BLOCK
311 if (request->op == TO_BLOCK) {
313 * Recovery for block device requests. Set the block_position
314 * to something invalid and retry.
316 device->blk_data.block_position = -1;
317 if (request->retries-- <= 0)
318 return tape_34xx_erp_failed(request, -EIO);
320 return tape_34xx_erp_retry(request);
325 sense[0] & SENSE_COMMAND_REJECT &&
326 sense[1] & SENSE_WRITE_PROTECT
329 request->op == TO_DSE ||
330 request->op == TO_WRI ||
331 request->op == TO_WTM
333 /* medium is write protected */
334 return tape_34xx_erp_failed(request, -EACCES);
336 return tape_34xx_erp_bug(device, request, irb, -3);
341 * Special cases for various tape-states when reaching
342 * end of recorded area
344 * FIXME: Maybe a special case of the special case:
345 * sense[0] == SENSE_EQUIPMENT_CHECK &&
346 * sense[1] == SENSE_DRIVE_ONLINE &&
347 * sense[3] == 0x47 (Volume Fenced)
349 * This was caused by continued FSF or FSR after an
353 sense[0] == SENSE_DATA_CHECK ||
354 sense[0] == SENSE_EQUIPMENT_CHECK ||
355 sense[0] == SENSE_EQUIPMENT_CHECK + SENSE_DEFERRED_UNIT_CHECK
357 sense[1] == SENSE_DRIVE_ONLINE ||
358 sense[1] == SENSE_BEGINNING_OF_TAPE + SENSE_WRITE_MODE
360 switch (request->op) {
362 * sense[0] == SENSE_DATA_CHECK &&
363 * sense[1] == SENSE_DRIVE_ONLINE
364 * sense[3] == 0x36 (End Of Data)
366 * Further seeks might return a 'Volume Fenced'.
370 /* Trying to seek beyond end of recorded area */
371 return tape_34xx_erp_failed(request, -ENOSPC);
373 return tape_34xx_erp_retry(request);
376 * sense[0] == SENSE_DATA_CHECK &&
377 * sense[1] == SENSE_DRIVE_ONLINE &&
378 * sense[3] == 0x36 (End Of Data)
381 /* Block could not be located. */
382 tape_34xx_delete_sbid_from(device, 0);
383 return tape_34xx_erp_failed(request, -EIO);
386 /* Read beyond end of recorded area -> 0 bytes read */
387 return tape_34xx_erp_failed(request, 0);
390 * sense[0] == SENSE_EQUIPMENT_CHECK &&
391 * sense[1] == SENSE_DRIVE_ONLINE &&
392 * sense[3] == 0x38 (Physical End Of Volume)
395 /* Writing at physical end of volume */
396 return tape_34xx_erp_failed(request, -ENOSPC);
398 PRINT_ERR("Invalid op in %s:%i\n",
399 __FUNCTION__, __LINE__);
400 return tape_34xx_erp_failed(request, 0);
404 /* Sensing special bits */
405 if (sense[0] & SENSE_BUS_OUT_CHECK)
406 return tape_34xx_erp_retry(request);
408 if (sense[0] & SENSE_DATA_CHECK) {
410 * hardware failure, damaged tape or improper
411 * operating conditions
415 /* a read data check occurred */
416 if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
418 // data check is not permanent, may be
419 // recovered. We always use async-mode with
420 // cu-recovery, so this should *never* happen.
421 return tape_34xx_erp_bug(device, request,
424 /* data check is permanent, CU recovery has failed */
425 PRINT_WARN("Permanent read error\n");
426 return tape_34xx_erp_failed(request, -EIO);
428 // a write data check occurred
429 if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
431 // data check is not permanent, may be
432 // recovered. We always use async-mode with
433 // cu-recovery, so this should *never* happen.
434 return tape_34xx_erp_bug(device, request,
437 // data check is permanent, cu-recovery has failed
438 PRINT_WARN("Permanent write error\n");
439 return tape_34xx_erp_failed(request, -EIO);
441 /* Data Check (read opposite) occurred. */
442 return tape_34xx_erp_read_opposite(device, request);
444 /* ID-Mark at tape start couldn't be written */
445 PRINT_WARN("ID-Mark could not be written.\n");
446 return tape_34xx_erp_failed(request, -EIO);
448 /* Tape void. Tried to read beyond end of device. */
449 PRINT_WARN("Read beyond end of recorded area.\n");
450 return tape_34xx_erp_failed(request, -ENOSPC);
452 /* Record sequence error. */
453 PRINT_WARN("Invalid block-id sequence found.\n");
454 return tape_34xx_erp_failed(request, -EIO);
456 /* all data checks for 3480 should result in one of
457 * the above erpa-codes. For 3490, other data-check
458 * conditions do exist. */
459 if (device->cdev->id.driver_info == tape_3480)
460 return tape_34xx_erp_bug(device, request,
465 if (sense[0] & SENSE_OVERRUN)
466 return tape_34xx_erp_overrun(device, request, irb);
468 if (sense[1] & SENSE_RECORD_SEQUENCE_ERR)
469 return tape_34xx_erp_sequence(device, request, irb);
471 /* Sensing erpa codes */
474 /* Unit check with erpa code 0. Report and ignore. */
475 PRINT_WARN("Non-error sense was found. "
476 "Unit-check will be ignored.\n");
477 return TAPE_IO_SUCCESS;
480 * Data streaming not operational. CU will switch to
481 * interlock mode. Reissue the command.
483 PRINT_WARN("Data streaming not operational. "
484 "Switching to interlock-mode.\n");
485 return tape_34xx_erp_retry(request);
488 * Path equipment check. Might be drive adapter error, buffer
489 * error on the lower interface, internal path not usable,
490 * or error during cartridge load.
492 PRINT_WARN("A path equipment check occurred. One of the "
493 "following conditions occurred:\n");
494 PRINT_WARN("drive adapter error, buffer error on the lower "
495 "interface, internal path not usable, error "
496 "during cartridge load.\n");
497 return tape_34xx_erp_failed(request, -EIO);
500 * Load display check. Load display was command was issued,
501 * but the drive is displaying a drive check message. Can
502 * be threated as "device end".
504 return tape_34xx_erp_succeeded(request);
507 * Command reject. May indicate illegal channel program or
508 * buffer over/underrun. Since all channel programs are
509 * issued by this driver and ought be correct, we assume a
510 * over/underrun situation and retry the channel program.
512 return tape_34xx_erp_retry(request);
515 * Function incompatible. Either the tape is idrc compressed
516 * but the hardware isn't capable to do idrc, or a perform
517 * subsystem func is issued and the CU is not on-line.
519 PRINT_WARN ("Function incompatible. Try to switch off idrc\n");
520 return tape_34xx_erp_failed(request, -EIO);
523 * Unsolicited environmental data. An internal counter
524 * overflows, we can ignore this and reissue the cmd.
526 return tape_34xx_erp_retry(request);
529 * Environmental data present. Indicates either unload
530 * completed ok or read buffered log command completed ok.
532 if (request->op == TO_RUN) {
533 /* Rewind unload completed ok. */
534 tape_med_state_set(device, MS_UNLOADED);
535 return tape_34xx_erp_succeeded(request);
537 /* tape_34xx doesn't use read buffered log commands. */
538 return tape_34xx_erp_bug(device, request, irb, sense[3]);
541 * Permanent equipment check. CU has tried recovery, but
544 return tape_34xx_erp_failed(request, -EIO);
546 /* Data security erase failure. */
547 if (request->op == TO_DSE)
548 return tape_34xx_erp_failed(request, -EIO);
549 /* Data security erase failure, but no such command issued. */
550 return tape_34xx_erp_bug(device, request, irb, sense[3]);
553 * Not capable. This indicates either that the drive fails
554 * reading the format id mark or that that format specified
555 * is not supported by the drive.
557 PRINT_WARN("Drive not capable processing the tape format!\n");
558 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
560 /* The medium is write protected. */
561 PRINT_WARN("Medium is write protected!\n");
562 return tape_34xx_erp_failed(request, -EACCES);
564 // Tension loss. We cannot recover this, it's an I/O error.
565 PRINT_WARN("The drive lost tape tension.\n");
566 return tape_34xx_erp_failed(request, -EIO);
569 * Load Failure. The cartridge was not inserted correctly or
570 * the tape is not threaded correctly.
572 PRINT_WARN("Cartridge load failure. Reload the cartridge "
574 tape_34xx_delete_sbid_from(device, 0);
575 return tape_34xx_erp_failed(request, -EIO);
578 * Unload failure. The drive cannot maintain tape tension
579 * and control tape movement during an unload operation.
581 PRINT_WARN("Failure during cartridge unload. "
582 "Please try manually.\n");
583 if (request->op == TO_RUN)
584 return tape_34xx_erp_failed(request, -EIO);
585 return tape_34xx_erp_bug(device, request, irb, sense[3]);
588 * Drive equipment check. One of the following:
589 * - cu cannot recover from a drive detected error
590 * - a check code message is shown on drive display
591 * - the cartridge loader does not respond correctly
592 * - a failure occurs during an index, load, or unload cycle
594 PRINT_WARN("Equipment check! Please check the drive and "
595 "the cartridge loader.\n");
596 return tape_34xx_erp_failed(request, -EIO);
598 if (device->cdev->id.driver_info == tape_3490)
600 return tape_34xx_erp_failed(request, -EIO);
601 /* This erpa is reserved for 3480 */
602 return tape_34xx_erp_bug(device, request, irb, sense[3]);
605 * Tape length error. The tape is shorter than reported in
606 * the beginning-of-tape data.
608 PRINT_WARN("Tape length error.\n");
609 return tape_34xx_erp_failed(request, -EIO);
612 * Physical end of tape. A read/write operation reached
613 * the physical end of tape.
615 if (request->op==TO_WRI ||
616 request->op==TO_DSE ||
618 return tape_34xx_erp_failed(request, -ENOSPC);
619 return tape_34xx_erp_failed(request, -EIO);
621 /* Backward at Beginning of tape. */
622 return tape_34xx_erp_failed(request, -EIO);
624 /* Drive switched to not ready. */
625 PRINT_WARN("Drive not ready. Turn the ready/not ready switch "
626 "to ready position and try again.\n");
627 return tape_34xx_erp_failed(request, -EIO);
629 /* Manual rewind or unload. This causes an I/O error. */
630 PRINT_WARN("Medium was rewound or unloaded manually.\n");
631 tape_34xx_delete_sbid_from(device, 0);
632 return tape_34xx_erp_failed(request, -EIO);
635 * Degraded mode. A condition that can cause degraded
636 * performance is detected.
638 PRINT_WARN("Subsystem is running in degraded mode.\n");
639 return tape_34xx_erp_retry(request);
641 /* Drive not ready. */
642 tape_34xx_delete_sbid_from(device, 0);
643 tape_med_state_set(device, MS_UNLOADED);
644 /* Some commands commands are successful even in this case */
645 if (sense[1] & SENSE_DRIVE_ONLINE) {
646 switch(request->op) {
651 return tape_34xx_done(request);
657 PRINT_WARN("The drive is not ready.\n");
658 return tape_34xx_erp_failed(request, -ENOMEDIUM);
660 /* Locate Block unsuccessful. */
661 if (request->op != TO_BLOCK && request->op != TO_LBL)
662 /* No locate block was issued. */
663 return tape_34xx_erp_bug(device, request,
665 return tape_34xx_erp_failed(request, -EIO);
667 /* The drive is assigned to a different channel path. */
668 PRINT_WARN("The drive is assigned elsewhere.\n");
669 return tape_34xx_erp_failed(request, -EIO);
672 * Drive not on-line. Drive may be switched offline,
673 * the power supply may be switched off or
674 * the drive address may not be set correctly.
676 PRINT_WARN("The drive is not on-line.");
677 return tape_34xx_erp_failed(request, -EIO);
679 /* Volume fenced. CU reports volume integrity is lost. */
680 PRINT_WARN("Volume fenced. The volume integrity is lost.\n");
681 tape_34xx_delete_sbid_from(device, 0);
682 return tape_34xx_erp_failed(request, -EIO);
684 /* Log sense data and retry request. */
685 return tape_34xx_erp_retry(request);
687 /* Bus out check. A parity check error on the bus was found. */
688 PRINT_WARN("Bus out check. A data transfer over the bus "
689 "has been corrupted.\n");
690 return tape_34xx_erp_failed(request, -EIO);
692 /* Control unit erp failed. */
693 PRINT_WARN("The control unit I/O error recovery failed.\n");
694 return tape_34xx_erp_failed(request, -EIO);
697 * CU and drive incompatible. The drive requests micro-program
698 * patches, which are not available on the CU.
700 PRINT_WARN("The drive needs microprogram patches from the "
701 "control unit, which are not available.\n");
702 return tape_34xx_erp_failed(request, -EIO);
705 * Recovered Check-One failure. Cu develops a hardware error,
706 * but is able to recover.
708 return tape_34xx_erp_retry(request);
710 if (device->cdev->id.driver_info == tape_3490)
712 * Resetting event received. Since the driver does
713 * not support resetting event recovery (which has to
714 * be handled by the I/O Layer), retry our command.
716 return tape_34xx_erp_retry(request);
717 /* This erpa is reserved for 3480. */
718 return tape_34xx_erp_bug(device, request, irb, sense[3]);
720 if (device->cdev->id.driver_info == tape_3490) {
722 * Maximum block size exceeded. This indicates, that
723 * the block to be written is larger than allowed for
726 PRINT_WARN("Maximum block size for buffered "
728 return tape_34xx_erp_failed(request, -ENOBUFS);
730 /* This erpa is reserved for 3480. */
731 return tape_34xx_erp_bug(device, request, irb, sense[3]);
734 * Read buffered log (Overflow). CU is running in extended
735 * buffered log mode, and a counter overflows. This should
736 * never happen, since we're never running in extended
739 return tape_34xx_erp_retry(request);
742 * Read buffered log (EOV). EOF processing occurs while the
743 * CU is in extended buffered log mode. This should never
744 * happen, since we're never running in extended buffered
747 return tape_34xx_erp_retry(request);
749 /* End of Volume complete. Rewind unload completed ok. */
750 if (request->op == TO_RUN) {
751 tape_med_state_set(device, MS_UNLOADED);
752 tape_34xx_delete_sbid_from(device, 0);
753 return tape_34xx_erp_succeeded(request);
755 return tape_34xx_erp_bug(device, request, irb, sense[3]);
757 /* Global command intercept. */
758 return tape_34xx_erp_retry(request);
760 /* Channel interface recovery (temporary). */
761 return tape_34xx_erp_retry(request);
763 /* Channel interface recovery (permanent). */
764 PRINT_WARN("A permanent channel interface error occurred.\n");
765 return tape_34xx_erp_failed(request, -EIO);
767 /* Channel protocol error. */
768 PRINT_WARN("A channel protocol error occurred.\n");
769 return tape_34xx_erp_failed(request, -EIO);
771 if (device->cdev->id.driver_info == tape_3480) {
772 /* Attention intercept. */
773 PRINT_WARN("An attention intercept occurred, "
774 "which will be recovered.\n");
775 return tape_34xx_erp_retry(request);
777 /* Global status intercept. */
778 PRINT_WARN("An global status intercept was received, "
779 "which will be recovered.\n");
780 return tape_34xx_erp_retry(request);
784 * Tape length incompatible. The tape inserted is too long,
785 * which could cause damage to the tape or the drive.
787 PRINT_WARN("Tape Length Incompatible\n");
788 PRINT_WARN("Tape length exceeds IBM enhanced capacity "
789 "cartdridge length or a medium\n");
790 PRINT_WARN("with EC-CST identification mark has been mounted "
791 "in a device that writes\n");
792 PRINT_WARN("3480 or 3480 XF format.\n");
793 return tape_34xx_erp_failed(request, -EIO);
795 /* Format 3480 XF incompatible */
796 if (sense[1] & SENSE_BEGINNING_OF_TAPE)
797 /* The tape will get overwritten. */
798 return tape_34xx_erp_retry(request);
799 PRINT_WARN("Format 3480 XF Incompatible\n");
800 PRINT_WARN("Medium has been created in 3480 format. "
801 "To change the format writes\n");
802 PRINT_WARN("must be issued at BOT.\n");
803 return tape_34xx_erp_failed(request, -EIO);
805 /* Format 3480-2 XF incompatible */
806 PRINT_WARN("Format 3480-2 XF Incompatible\n");
807 PRINT_WARN("Device can only read 3480 or 3480 XF format.\n");
808 return tape_34xx_erp_failed(request, -EIO);
810 /* Tape length violation. */
811 PRINT_WARN("Tape Length Violation\n");
812 PRINT_WARN("The mounted tape exceeds IBM Enhanced Capacity "
813 "Cartdridge System Tape length.\n");
814 PRINT_WARN("This may cause damage to the drive or tape when "
815 "processing to the EOV\n");
816 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
818 /* Compaction algorithm incompatible. */
819 PRINT_WARN("Compaction Algorithm Incompatible\n");
820 PRINT_WARN("The volume is recorded using an incompatible "
821 "compaction algorithm,\n");
822 PRINT_WARN("which is not supported by the device.\n");
823 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
825 /* The following erpas should have been covered earlier. */
826 case 0x23: /* Read data check. */
827 case 0x25: /* Write data check. */
828 case 0x26: /* Data check (read opposite). */
829 case 0x28: /* Write id mark check. */
830 case 0x31: /* Tape void. */
831 case 0x40: /* Overrun error. */
832 case 0x41: /* Record sequence error. */
833 /* All other erpas are reserved for future use. */
835 return tape_34xx_erp_bug(device, request, irb, sense[3]);
840 * 3480/3490 interrupt handler
843 tape_34xx_irq(struct tape_device *device, struct tape_request *request,
847 return tape_34xx_unsolicited_irq(device, irb);
849 if ((irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) &&
850 (irb->scsw.dstat & DEV_STAT_DEV_END) &&
851 (request->op == TO_WRI)) {
852 /* Write at end of volume */
853 PRINT_INFO("End of volume\n"); /* XXX */
854 return tape_34xx_erp_failed(request, -ENOSPC);
857 if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
858 return tape_34xx_unit_check(device, request, irb);
860 if (irb->scsw.dstat & DEV_STAT_DEV_END) {
862 * A unit exception occurs on skipping over a tapemark block.
864 if (irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) {
865 if (request->op == TO_BSB || request->op == TO_FSB)
868 DBF_EVENT(5, "Unit Exception!\n");
870 return tape_34xx_done(request);
873 DBF_EVENT(6, "xunknownirq\n");
874 PRINT_ERR("Unexpected interrupt.\n");
875 PRINT_ERR("Current op is: %s", tape_op_verbose[request->op]);
876 tape_dump_sense(device, request, irb);
884 tape_34xx_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
886 if (cmd == TAPE390_DISPLAY) {
887 struct display_struct disp;
889 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)) != 0)
892 return tape_std_display(device, &disp);
898 tape_34xx_append_new_sbid(struct tape_34xx_block_id bid, struct list_head *l)
900 struct tape_34xx_sbid * new_sbid;
902 new_sbid = kmalloc(sizeof(*new_sbid), GFP_ATOMIC);
907 list_add(&new_sbid->list, l);
911 * Build up the search block ID list. The block ID consists of a logical
912 * block number and a hardware specific part. The hardware specific part
913 * helps the tape drive to speed up searching for a specific block.
916 tape_34xx_add_sbid(struct tape_device *device, struct tape_34xx_block_id bid)
918 struct list_head * sbid_list;
919 struct tape_34xx_sbid * sbid;
920 struct list_head * l;
923 * immediately return if there is no list at all or the block to add
924 * is located in segment 1 of wrap 0 because this position is used
925 * if no hardware position data is supplied.
927 sbid_list = (struct list_head *) device->discdata;
928 if (!sbid_list || (bid.segment < 2 && bid.wrap == 0))
932 * Search the position where to insert the new entry. Hardware
933 * acceleration uses only the segment and wrap number. So we
934 * need only one entry for a specific wrap/segment combination.
935 * If there is a block with a lower number but the same hard-
936 * ware position data we just update the block number in the
939 list_for_each(l, sbid_list) {
940 sbid = list_entry(l, struct tape_34xx_sbid, list);
943 (sbid->bid.segment == bid.segment) &&
944 (sbid->bid.wrap == bid.wrap)
946 if (bid.block < sbid->bid.block)
952 /* Sort in according to logical block number. */
953 if (bid.block < sbid->bid.block) {
954 tape_34xx_append_new_sbid(bid, l->prev);
958 /* List empty or new block bigger than last entry. */
960 tape_34xx_append_new_sbid(bid, l->prev);
962 DBF_LH(4, "Current list is:\n");
963 list_for_each(l, sbid_list) {
964 sbid = list_entry(l, struct tape_34xx_sbid, list);
965 DBF_LH(4, "%d:%03d@%05d\n",
974 * Delete all entries from the search block ID list that belong to tape blocks
975 * equal or higher than the given number.
978 tape_34xx_delete_sbid_from(struct tape_device *device, int from)
980 struct list_head * sbid_list;
981 struct tape_34xx_sbid * sbid;
982 struct list_head * l;
983 struct list_head * n;
985 sbid_list = (struct list_head *) device->discdata;
989 list_for_each_safe(l, n, sbid_list) {
990 sbid = list_entry(l, struct tape_34xx_sbid, list);
991 if (sbid->bid.block >= from) {
992 DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
1004 * Merge hardware position data into a block id.
1007 tape_34xx_merge_sbid(
1008 struct tape_device * device,
1009 struct tape_34xx_block_id * bid
1011 struct tape_34xx_sbid * sbid;
1012 struct tape_34xx_sbid * sbid_to_use;
1013 struct list_head * sbid_list;
1014 struct list_head * l;
1016 sbid_list = (struct list_head *) device->discdata;
1020 if (!sbid_list || list_empty(sbid_list))
1024 list_for_each(l, sbid_list) {
1025 sbid = list_entry(l, struct tape_34xx_sbid, list);
1027 if (sbid->bid.block >= bid->block)
1032 bid->wrap = sbid_to_use->bid.wrap;
1033 bid->segment = sbid_to_use->bid.segment;
1034 DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
1035 sbid_to_use->bid.wrap,
1036 sbid_to_use->bid.segment,
1037 sbid_to_use->bid.block,
1044 tape_34xx_setup_device(struct tape_device * device)
1047 struct list_head * discdata;
1049 DBF_EVENT(6, "34xx device setup\n");
1050 if ((rc = tape_std_assign(device)) == 0) {
1051 if ((rc = tape_34xx_medium_sense(device)) != 0) {
1052 DBF_LH(3, "34xx medium sense returned %d\n", rc);
1055 discdata = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1057 INIT_LIST_HEAD(discdata);
1058 device->discdata = discdata;
1065 tape_34xx_cleanup_device(struct tape_device *device)
1067 tape_std_unassign(device);
1069 if (device->discdata) {
1070 tape_34xx_delete_sbid_from(device, 0);
1071 kfree(device->discdata);
1072 device->discdata = NULL;
1078 * MTTELL: Tell block. Return the number of block relative to current file.
1081 tape_34xx_mttell(struct tape_device *device, int mt_count)
1084 struct tape_34xx_block_id cbid;
1085 struct tape_34xx_block_id dbid;
1086 } __attribute__ ((packed)) block_id;
1089 rc = tape_std_read_block_id(device, (__u64 *) &block_id);
1093 tape_34xx_add_sbid(device, block_id.cbid);
1094 return block_id.cbid.block;
1098 * MTSEEK: seek to the specified block.
1101 tape_34xx_mtseek(struct tape_device *device, int mt_count)
1103 struct tape_request *request;
1104 struct tape_34xx_block_id * bid;
1106 if (mt_count > 0x3fffff) {
1107 DBF_EXCEPTION(6, "xsee parm\n");
1110 request = tape_alloc_request(3, 4);
1111 if (IS_ERR(request))
1112 return PTR_ERR(request);
1115 request->op = TO_LBL;
1116 bid = (struct tape_34xx_block_id *) request->cpdata;
1117 bid->format = (*device->modeset_byte & 0x08) ?
1118 TAPE34XX_FMT_3480_XF : TAPE34XX_FMT_3480;
1119 bid->block = mt_count;
1120 tape_34xx_merge_sbid(device, bid);
1122 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
1123 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1124 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
1127 return tape_do_io_free(device, request);
1130 #ifdef CONFIG_S390_TAPE_BLOCK
1132 * Tape block read for 34xx.
1134 static struct tape_request *
1135 tape_34xx_bread(struct tape_device *device, struct request *req)
1137 struct tape_request *request;
1144 struct tape_34xx_block_id * start_block;
1146 DBF_EVENT(6, "xBREDid:");
1148 /* Count the number of blocks for the request. */
1149 rq_for_each_bio(bio, req) {
1150 bio_for_each_segment(bv, bio, i) {
1151 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
1155 /* Allocate the ccw request. */
1156 request = tape_alloc_request(3+count+1, 8);
1157 if (IS_ERR(request))
1161 request->op = TO_BLOCK;
1162 start_block = (struct tape_34xx_block_id *) request->cpdata;
1163 start_block->block = req->sector >> TAPEBLOCK_HSEC_S2B;
1164 DBF_EVENT(6, "start_block = %i\n", start_block->block);
1166 ccw = request->cpaddr;
1167 ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);
1170 * We always setup a nop after the mode set ccw. This slot is
1171 * used in tape_std_check_locate to insert a locate ccw if the
1172 * current tape position doesn't match the start block to be read.
1173 * The second nop will be filled with a read block id which is in
1174 * turn used by tape_34xx_free_bread to populate the segment bid
1177 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
1178 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
1180 rq_for_each_bio(bio, req) {
1181 bio_for_each_segment(bv, bio, i) {
1182 dst = kmap(bv->bv_page) + bv->bv_offset;
1183 for (off = 0; off < bv->bv_len;
1184 off += TAPEBLOCK_HSEC_SIZE) {
1185 ccw->flags = CCW_FLAG_CC;
1186 ccw->cmd_code = READ_FORWARD;
1187 ccw->count = TAPEBLOCK_HSEC_SIZE;
1188 set_normalized_cda(ccw, (void*) __pa(dst));
1190 dst += TAPEBLOCK_HSEC_SIZE;
1195 ccw = tape_ccw_end(ccw, NOP, 0, NULL);
1196 DBF_EVENT(6, "xBREDccwg\n");
1201 tape_34xx_free_bread (struct tape_request *request)
1205 ccw = request->cpaddr;
1206 if ((ccw + 2)->cmd_code == READ_BLOCK_ID) {
1208 struct tape_34xx_block_id cbid;
1209 struct tape_34xx_block_id dbid;
1210 } __attribute__ ((packed)) *rbi_data;
1212 rbi_data = request->cpdata;
1214 if (request->device)
1215 tape_34xx_add_sbid(request->device, rbi_data->cbid);
1218 /* Last ccw is a nop and doesn't need clear_normalized_cda */
1219 for (; ccw->flags & CCW_FLAG_CC; ccw++)
1220 if (ccw->cmd_code == READ_FORWARD)
1221 clear_normalized_cda(ccw);
1222 tape_free_request(request);
1226 * check_locate is called just before the tape request is passed to
1227 * the common io layer for execution. It has to check the current
1228 * tape position and insert a locate ccw if it doesn't match the
1229 * start block for the request.
1232 tape_34xx_check_locate(struct tape_device *device, struct tape_request *request)
1234 struct tape_34xx_block_id * start_block;
1236 start_block = (struct tape_34xx_block_id *) request->cpdata;
1237 if (start_block->block == device->blk_data.block_position)
1240 DBF_LH(4, "Block seek(%06d+%06d)\n", start_block->block, device->bof);
1241 start_block->wrap = 0;
1242 start_block->segment = 1;
1243 start_block->format = (*device->modeset_byte & 0x08) ?
1244 TAPE34XX_FMT_3480_XF :
1246 start_block->block = start_block->block + device->bof;
1247 tape_34xx_merge_sbid(device, start_block);
1248 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1249 tape_ccw_cc(request->cpaddr + 2, READ_BLOCK_ID, 8, request->cpdata);
1254 * List of 3480/3490 magnetic tape commands.
1256 static tape_mtop_fn tape_34xx_mtop[TAPE_NR_MTOPS] = {
1257 [MTRESET] = tape_std_mtreset,
1258 [MTFSF] = tape_std_mtfsf,
1259 [MTBSF] = tape_std_mtbsf,
1260 [MTFSR] = tape_std_mtfsr,
1261 [MTBSR] = tape_std_mtbsr,
1262 [MTWEOF] = tape_std_mtweof,
1263 [MTREW] = tape_std_mtrew,
1264 [MTOFFL] = tape_std_mtoffl,
1265 [MTNOP] = tape_std_mtnop,
1266 [MTRETEN] = tape_std_mtreten,
1267 [MTBSFM] = tape_std_mtbsfm,
1268 [MTFSFM] = tape_std_mtfsfm,
1269 [MTEOM] = tape_std_mteom,
1270 [MTERASE] = tape_std_mterase,
1274 [MTSETBLK] = tape_std_mtsetblk,
1275 [MTSETDENSITY] = NULL,
1276 [MTSEEK] = tape_34xx_mtseek,
1277 [MTTELL] = tape_34xx_mttell,
1278 [MTSETDRVBUFFER] = NULL,
1284 [MTLOAD] = tape_std_mtload,
1285 [MTUNLOAD] = tape_std_mtunload,
1286 [MTCOMPRESSION] = tape_std_mtcompression,
1292 * Tape discipline structure for 3480 and 3490.
1294 static struct tape_discipline tape_discipline_34xx = {
1295 .owner = THIS_MODULE,
1296 .setup_device = tape_34xx_setup_device,
1297 .cleanup_device = tape_34xx_cleanup_device,
1298 .process_eov = tape_std_process_eov,
1299 .irq = tape_34xx_irq,
1300 .read_block = tape_std_read_block,
1301 .write_block = tape_std_write_block,
1302 #ifdef CONFIG_S390_TAPE_BLOCK
1303 .bread = tape_34xx_bread,
1304 .free_bread = tape_34xx_free_bread,
1305 .check_locate = tape_34xx_check_locate,
1307 .ioctl_fn = tape_34xx_ioctl,
1308 .mtop_array = tape_34xx_mtop
1311 static struct ccw_device_id tape_34xx_ids[] = {
1312 { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), .driver_info = tape_3480},
1313 { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), .driver_info = tape_3490},
1314 { /* end of list */ },
1318 tape_34xx_online(struct ccw_device *cdev)
1320 return tape_generic_online(
1321 cdev->dev.driver_data,
1322 &tape_discipline_34xx
1327 tape_34xx_offline(struct ccw_device *cdev)
1329 return tape_generic_offline(cdev->dev.driver_data);
1332 static struct ccw_driver tape_34xx_driver = {
1333 .name = "tape_34xx",
1334 .owner = THIS_MODULE,
1335 .ids = tape_34xx_ids,
1336 .probe = tape_generic_probe,
1337 .remove = tape_generic_remove,
1338 .set_online = tape_34xx_online,
1339 .set_offline = tape_34xx_offline,
1343 tape_34xx_init (void)
1347 TAPE_DBF_AREA = debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
1348 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1349 #ifdef DBF_LIKE_HELL
1350 debug_set_level(TAPE_DBF_AREA, 6);
1353 DBF_EVENT(3, "34xx init\n");
1354 /* Register driver for 3480/3490 tapes. */
1355 rc = ccw_driver_register(&tape_34xx_driver);
1357 DBF_EVENT(3, "34xx init failed\n");
1359 DBF_EVENT(3, "34xx registered\n");
1364 tape_34xx_exit(void)
1366 ccw_driver_unregister(&tape_34xx_driver);
1368 debug_unregister(TAPE_DBF_AREA);
1371 MODULE_DEVICE_TABLE(ccw, tape_34xx_ids);
1372 MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
1373 MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape device driver");
1374 MODULE_LICENSE("GPL");
1376 module_init(tape_34xx_init);
1377 module_exit(tape_34xx_exit);