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/config.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/bio.h>
15 #include <linux/workqueue.h>
17 #define TAPE_DBF_AREA tape_34xx_dbf
22 #define PRINTK_HEADER "TAPE_34XX: "
25 * Pointer to debug area.
27 debug_info_t *TAPE_DBF_AREA = NULL;
28 EXPORT_SYMBOL(TAPE_DBF_AREA);
30 #define TAPE34XX_FMT_3480 0
31 #define TAPE34XX_FMT_3480_2_XF 1
32 #define TAPE34XX_FMT_3480_XF 2
34 struct tape_34xx_block_id {
35 unsigned int wrap : 1;
36 unsigned int segment : 7;
37 unsigned int format : 2;
38 unsigned int block : 22;
42 * A list of block ID's is used to faster seek blocks.
44 struct tape_34xx_sbid {
45 struct list_head list;
46 struct tape_34xx_block_id bid;
49 static void tape_34xx_delete_sbid_from(struct tape_device *, int);
52 * Medium sense for 34xx tapes. There is no 'real' medium sense call.
53 * So we just do a normal sense.
56 tape_34xx_medium_sense(struct tape_device *device)
58 struct tape_request *request;
62 request = tape_alloc_request(1, 32);
63 if (IS_ERR(request)) {
64 DBF_EXCEPTION(6, "MSEN fail\n");
65 return PTR_ERR(request);
68 request->op = TO_MSEN;
69 tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata);
71 rc = tape_do_io_interruptible(device, request);
72 if (request->rc == 0) {
73 sense = request->cpdata;
76 * This isn't quite correct. But since INTERVENTION_REQUIRED
77 * means that the drive is 'neither ready nor on-line' it is
78 * only slightly inaccurate to say there is no tape loaded if
79 * the drive isn't online...
81 if (sense[0] & SENSE_INTERVENTION_REQUIRED)
82 tape_med_state_set(device, MS_UNLOADED);
84 tape_med_state_set(device, MS_LOADED);
86 if (sense[1] & SENSE_WRITE_PROTECT)
87 device->tape_generic_status |= GMT_WR_PROT(~0);
89 device->tape_generic_status &= ~GMT_WR_PROT(~0);
91 DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
94 tape_free_request(request);
100 * These functions are currently used only to schedule a medium_sense for
101 * later execution. This is because we get an interrupt whenever a medium
102 * is inserted but cannot call tape_do_io* from an interrupt context.
103 * Maybe that's useful for other actions we want to start from the
107 tape_34xx_work_handler(void *data)
110 struct tape_device *device;
112 struct work_struct work;
117 tape_34xx_medium_sense(p->device);
120 DBF_EVENT(3, "T34XX: internal error: unknown work\n");
123 p->device = tape_put_device(p->device);
128 tape_34xx_schedule_work(struct tape_device *device, enum tape_op op)
131 struct tape_device *device;
133 struct work_struct work;
136 if ((p = kmalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
139 memset(p, 0, sizeof(*p));
140 INIT_WORK(&p->work, tape_34xx_work_handler, p);
142 p->device = tape_get_device_reference(device);
145 schedule_work(&p->work);
150 * Done Handler is called when dev stat = DEVICE-END (successful operation)
153 tape_34xx_done(struct tape_request *request)
155 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
157 switch (request->op) {
164 tape_34xx_delete_sbid_from(request->device, 0);
169 return TAPE_IO_SUCCESS;
173 tape_34xx_erp_failed(struct tape_request *request, int rc)
175 DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
176 tape_op_verbose[request->op], rc);
181 tape_34xx_erp_succeeded(struct tape_request *request)
183 DBF_EVENT(3, "Error Recovery successful for %s\n",
184 tape_op_verbose[request->op]);
185 return tape_34xx_done(request);
189 tape_34xx_erp_retry(struct tape_request *request)
191 DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose[request->op]);
192 return TAPE_IO_RETRY;
196 * This function is called, when no request is outstanding and we get an
200 tape_34xx_unsolicited_irq(struct tape_device *device, struct irb *irb)
202 if (irb->scsw.dstat == 0x85 /* READY */) {
203 /* A medium was inserted in the drive. */
204 DBF_EVENT(6, "xuud med\n");
205 tape_34xx_delete_sbid_from(device, 0);
206 tape_34xx_schedule_work(device, TO_MSEN);
208 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
209 PRINT_WARN("Unsolicited IRQ (Device End) caught.\n");
210 tape_dump_sense(device, NULL, irb);
212 return TAPE_IO_SUCCESS;
216 * Read Opposite Error Recovery Function:
217 * Used, when Read Forward does not work
220 tape_34xx_erp_read_opposite(struct tape_device *device,
221 struct tape_request *request)
223 if (request->op == TO_RFO) {
225 * We did read forward, but the data could not be read
226 * *correctly*. We transform the request to a read backward
229 tape_std_read_backward(device, request);
230 return tape_34xx_erp_retry(request);
232 if (request->op != TO_RBA)
233 PRINT_ERR("read_opposite called with state:%s\n",
234 tape_op_verbose[request->op]);
236 * We tried to read forward and backward, but hat no
239 return tape_34xx_erp_failed(request, -EIO);
243 tape_34xx_erp_bug(struct tape_device *device, struct tape_request *request,
244 struct irb *irb, int no)
246 if (request->op != TO_ASSIGN) {
247 PRINT_WARN("An unexpected condition #%d was caught in "
248 "tape error recovery.\n", no);
249 PRINT_WARN("Please report this incident.\n");
251 PRINT_WARN("Operation of tape:%s\n",
252 tape_op_verbose[request->op]);
253 tape_dump_sense(device, request, irb);
255 return tape_34xx_erp_failed(request, -EIO);
259 * Handle data overrun between cu and drive. The channel speed might
263 tape_34xx_erp_overrun(struct tape_device *device, struct tape_request *request,
266 if (irb->ecw[3] == 0x40) {
267 PRINT_WARN ("Data overrun error between control-unit "
268 "and drive. Use a faster channel connection, "
270 return tape_34xx_erp_failed(request, -EIO);
272 return tape_34xx_erp_bug(device, request, irb, -1);
276 * Handle record sequence error.
279 tape_34xx_erp_sequence(struct tape_device *device,
280 struct tape_request *request, struct irb *irb)
282 if (irb->ecw[3] == 0x41) {
284 * cu detected incorrect block-id sequence on tape.
286 PRINT_WARN("Illegal block-id sequence found!\n");
287 return tape_34xx_erp_failed(request, -EIO);
290 * Record sequence error bit is set, but erpa does not
291 * show record sequence error.
293 return tape_34xx_erp_bug(device, request, irb, -2);
297 * This function analyses the tape's sense-data in case of a unit-check.
298 * If possible, it tries to recover from the error. Else the user is
299 * informed about the problem.
302 tape_34xx_unit_check(struct tape_device *device, struct tape_request *request,
305 int inhibit_cu_recovery;
308 inhibit_cu_recovery = (*device->modeset_byte & 0x80) ? 1 : 0;
311 #ifdef CONFIG_S390_TAPE_BLOCK
312 if (request->op == TO_BLOCK) {
314 * Recovery for block device requests. Set the block_position
315 * to something invalid and retry.
317 device->blk_data.block_position = -1;
318 if (request->retries-- <= 0)
319 return tape_34xx_erp_failed(request, -EIO);
321 return tape_34xx_erp_retry(request);
326 sense[0] & SENSE_COMMAND_REJECT &&
327 sense[1] & SENSE_WRITE_PROTECT
330 request->op == TO_DSE ||
331 request->op == TO_WRI ||
332 request->op == TO_WTM
334 /* medium is write protected */
335 return tape_34xx_erp_failed(request, -EACCES);
337 return tape_34xx_erp_bug(device, request, irb, -3);
342 * Special cases for various tape-states when reaching
343 * end of recorded area
345 * FIXME: Maybe a special case of the special case:
346 * sense[0] == SENSE_EQUIPMENT_CHECK &&
347 * sense[1] == SENSE_DRIVE_ONLINE &&
348 * sense[3] == 0x47 (Volume Fenced)
350 * This was caused by continued FSF or FSR after an
354 sense[0] == SENSE_DATA_CHECK ||
355 sense[0] == SENSE_EQUIPMENT_CHECK ||
356 sense[0] == SENSE_EQUIPMENT_CHECK + SENSE_DEFERRED_UNIT_CHECK
358 sense[1] == SENSE_DRIVE_ONLINE ||
359 sense[1] == SENSE_BEGINNING_OF_TAPE + SENSE_WRITE_MODE
361 switch (request->op) {
363 * sense[0] == SENSE_DATA_CHECK &&
364 * sense[1] == SENSE_DRIVE_ONLINE
365 * sense[3] == 0x36 (End Of Data)
367 * Further seeks might return a 'Volume Fenced'.
371 /* Trying to seek beyond end of recorded area */
372 return tape_34xx_erp_failed(request, -ENOSPC);
374 return tape_34xx_erp_retry(request);
377 * sense[0] == SENSE_DATA_CHECK &&
378 * sense[1] == SENSE_DRIVE_ONLINE &&
379 * sense[3] == 0x36 (End Of Data)
382 /* Block could not be located. */
383 tape_34xx_delete_sbid_from(device, 0);
384 return tape_34xx_erp_failed(request, -EIO);
387 /* Read beyond end of recorded area -> 0 bytes read */
388 return tape_34xx_erp_failed(request, 0);
391 * sense[0] == SENSE_EQUIPMENT_CHECK &&
392 * sense[1] == SENSE_DRIVE_ONLINE &&
393 * sense[3] == 0x38 (Physical End Of Volume)
396 /* Writing at physical end of volume */
397 return tape_34xx_erp_failed(request, -ENOSPC);
399 PRINT_ERR("Invalid op in %s:%i\n",
400 __FUNCTION__, __LINE__);
401 return tape_34xx_erp_failed(request, 0);
405 /* Sensing special bits */
406 if (sense[0] & SENSE_BUS_OUT_CHECK)
407 return tape_34xx_erp_retry(request);
409 if (sense[0] & SENSE_DATA_CHECK) {
411 * hardware failure, damaged tape or improper
412 * operating conditions
416 /* a read data check occurred */
417 if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
419 // data check is not permanent, may be
420 // recovered. We always use async-mode with
421 // cu-recovery, so this should *never* happen.
422 return tape_34xx_erp_bug(device, request,
425 /* data check is permanent, CU recovery has failed */
426 PRINT_WARN("Permanent read error\n");
427 return tape_34xx_erp_failed(request, -EIO);
429 // a write data check occurred
430 if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
432 // data check is not permanent, may be
433 // recovered. We always use async-mode with
434 // cu-recovery, so this should *never* happen.
435 return tape_34xx_erp_bug(device, request,
438 // data check is permanent, cu-recovery has failed
439 PRINT_WARN("Permanent write error\n");
440 return tape_34xx_erp_failed(request, -EIO);
442 /* Data Check (read opposite) occurred. */
443 return tape_34xx_erp_read_opposite(device, request);
445 /* ID-Mark at tape start couldn't be written */
446 PRINT_WARN("ID-Mark could not be written.\n");
447 return tape_34xx_erp_failed(request, -EIO);
449 /* Tape void. Tried to read beyond end of device. */
450 PRINT_WARN("Read beyond end of recorded area.\n");
451 return tape_34xx_erp_failed(request, -ENOSPC);
453 /* Record sequence error. */
454 PRINT_WARN("Invalid block-id sequence found.\n");
455 return tape_34xx_erp_failed(request, -EIO);
457 /* all data checks for 3480 should result in one of
458 * the above erpa-codes. For 3490, other data-check
459 * conditions do exist. */
460 if (device->cdev->id.driver_info == tape_3480)
461 return tape_34xx_erp_bug(device, request,
466 if (sense[0] & SENSE_OVERRUN)
467 return tape_34xx_erp_overrun(device, request, irb);
469 if (sense[1] & SENSE_RECORD_SEQUENCE_ERR)
470 return tape_34xx_erp_sequence(device, request, irb);
472 /* Sensing erpa codes */
475 /* Unit check with erpa code 0. Report and ignore. */
476 PRINT_WARN("Non-error sense was found. "
477 "Unit-check will be ignored.\n");
478 return TAPE_IO_SUCCESS;
481 * Data streaming not operational. CU will switch to
482 * interlock mode. Reissue the command.
484 PRINT_WARN("Data streaming not operational. "
485 "Switching to interlock-mode.\n");
486 return tape_34xx_erp_retry(request);
489 * Path equipment check. Might be drive adapter error, buffer
490 * error on the lower interface, internal path not usable,
491 * or error during cartridge load.
493 PRINT_WARN("A path equipment check occurred. One of the "
494 "following conditions occurred:\n");
495 PRINT_WARN("drive adapter error, buffer error on the lower "
496 "interface, internal path not usable, error "
497 "during cartridge load.\n");
498 return tape_34xx_erp_failed(request, -EIO);
501 * Load display check. Load display was command was issued,
502 * but the drive is displaying a drive check message. Can
503 * be threated as "device end".
505 return tape_34xx_erp_succeeded(request);
508 * Command reject. May indicate illegal channel program or
509 * buffer over/underrun. Since all channel programs are
510 * issued by this driver and ought be correct, we assume a
511 * over/underrun situation and retry the channel program.
513 return tape_34xx_erp_retry(request);
516 * Function incompatible. Either the tape is idrc compressed
517 * but the hardware isn't capable to do idrc, or a perform
518 * subsystem func is issued and the CU is not on-line.
520 PRINT_WARN ("Function incompatible. Try to switch off idrc\n");
521 return tape_34xx_erp_failed(request, -EIO);
524 * Unsolicited environmental data. An internal counter
525 * overflows, we can ignore this and reissue the cmd.
527 return tape_34xx_erp_retry(request);
530 * Environmental data present. Indicates either unload
531 * completed ok or read buffered log command completed ok.
533 if (request->op == TO_RUN) {
534 /* Rewind unload completed ok. */
535 tape_med_state_set(device, MS_UNLOADED);
536 return tape_34xx_erp_succeeded(request);
538 /* tape_34xx doesn't use read buffered log commands. */
539 return tape_34xx_erp_bug(device, request, irb, sense[3]);
542 * Permanent equipment check. CU has tried recovery, but
545 return tape_34xx_erp_failed(request, -EIO);
547 /* Data security erase failure. */
548 if (request->op == TO_DSE)
549 return tape_34xx_erp_failed(request, -EIO);
550 /* Data security erase failure, but no such command issued. */
551 return tape_34xx_erp_bug(device, request, irb, sense[3]);
554 * Not capable. This indicates either that the drive fails
555 * reading the format id mark or that that format specified
556 * is not supported by the drive.
558 PRINT_WARN("Drive not capable processing the tape format!\n");
559 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
561 /* The medium is write protected. */
562 PRINT_WARN("Medium is write protected!\n");
563 return tape_34xx_erp_failed(request, -EACCES);
565 // Tension loss. We cannot recover this, it's an I/O error.
566 PRINT_WARN("The drive lost tape tension.\n");
567 return tape_34xx_erp_failed(request, -EIO);
570 * Load Failure. The cartridge was not inserted correctly or
571 * the tape is not threaded correctly.
573 PRINT_WARN("Cartridge load failure. Reload the cartridge "
575 tape_34xx_delete_sbid_from(device, 0);
576 return tape_34xx_erp_failed(request, -EIO);
579 * Unload failure. The drive cannot maintain tape tension
580 * and control tape movement during an unload operation.
582 PRINT_WARN("Failure during cartridge unload. "
583 "Please try manually.\n");
584 if (request->op == TO_RUN)
585 return tape_34xx_erp_failed(request, -EIO);
586 return tape_34xx_erp_bug(device, request, irb, sense[3]);
589 * Drive equipment check. One of the following:
590 * - cu cannot recover from a drive detected error
591 * - a check code message is shown on drive display
592 * - the cartridge loader does not respond correctly
593 * - a failure occurs during an index, load, or unload cycle
595 PRINT_WARN("Equipment check! Please check the drive and "
596 "the cartridge loader.\n");
597 return tape_34xx_erp_failed(request, -EIO);
599 if (device->cdev->id.driver_info == tape_3490)
601 return tape_34xx_erp_failed(request, -EIO);
602 /* This erpa is reserved for 3480 */
603 return tape_34xx_erp_bug(device, request, irb, sense[3]);
606 * Tape length error. The tape is shorter than reported in
607 * the beginning-of-tape data.
609 PRINT_WARN("Tape length error.\n");
610 return tape_34xx_erp_failed(request, -EIO);
613 * Physical end of tape. A read/write operation reached
614 * the physical end of tape.
616 if (request->op==TO_WRI ||
617 request->op==TO_DSE ||
619 return tape_34xx_erp_failed(request, -ENOSPC);
620 return tape_34xx_erp_failed(request, -EIO);
622 /* Backward at Beginning of tape. */
623 return tape_34xx_erp_failed(request, -EIO);
625 /* Drive switched to not ready. */
626 PRINT_WARN("Drive not ready. Turn the ready/not ready switch "
627 "to ready position and try again.\n");
628 return tape_34xx_erp_failed(request, -EIO);
630 /* Manual rewind or unload. This causes an I/O error. */
631 PRINT_WARN("Medium was rewound or unloaded manually.\n");
632 tape_34xx_delete_sbid_from(device, 0);
633 return tape_34xx_erp_failed(request, -EIO);
636 * Degraded mode. A condition that can cause degraded
637 * performance is detected.
639 PRINT_WARN("Subsystem is running in degraded mode.\n");
640 return tape_34xx_erp_retry(request);
642 /* Drive not ready. */
643 tape_34xx_delete_sbid_from(device, 0);
644 tape_med_state_set(device, MS_UNLOADED);
645 /* Some commands commands are successful even in this case */
646 if (sense[1] & SENSE_DRIVE_ONLINE) {
647 switch(request->op) {
652 return tape_34xx_done(request);
658 PRINT_WARN("The drive is not ready.\n");
659 return tape_34xx_erp_failed(request, -ENOMEDIUM);
661 /* Locate Block unsuccessful. */
662 if (request->op != TO_BLOCK && request->op != TO_LBL)
663 /* No locate block was issued. */
664 return tape_34xx_erp_bug(device, request,
666 return tape_34xx_erp_failed(request, -EIO);
668 /* The drive is assigned to a different channel path. */
669 PRINT_WARN("The drive is assigned elsewhere.\n");
670 return tape_34xx_erp_failed(request, -EIO);
673 * Drive not on-line. Drive may be switched offline,
674 * the power supply may be switched off or
675 * the drive address may not be set correctly.
677 PRINT_WARN("The drive is not on-line.");
678 return tape_34xx_erp_failed(request, -EIO);
680 /* Volume fenced. CU reports volume integrity is lost. */
681 PRINT_WARN("Volume fenced. The volume integrity is lost.\n");
682 tape_34xx_delete_sbid_from(device, 0);
683 return tape_34xx_erp_failed(request, -EIO);
685 /* Log sense data and retry request. */
686 return tape_34xx_erp_retry(request);
688 /* Bus out check. A parity check error on the bus was found. */
689 PRINT_WARN("Bus out check. A data transfer over the bus "
690 "has been corrupted.\n");
691 return tape_34xx_erp_failed(request, -EIO);
693 /* Control unit erp failed. */
694 PRINT_WARN("The control unit I/O error recovery failed.\n");
695 return tape_34xx_erp_failed(request, -EIO);
698 * CU and drive incompatible. The drive requests micro-program
699 * patches, which are not available on the CU.
701 PRINT_WARN("The drive needs microprogram patches from the "
702 "control unit, which are not available.\n");
703 return tape_34xx_erp_failed(request, -EIO);
706 * Recovered Check-One failure. Cu develops a hardware error,
707 * but is able to recover.
709 return tape_34xx_erp_retry(request);
711 if (device->cdev->id.driver_info == tape_3490)
713 * Resetting event received. Since the driver does
714 * not support resetting event recovery (which has to
715 * be handled by the I/O Layer), retry our command.
717 return tape_34xx_erp_retry(request);
718 /* This erpa is reserved for 3480. */
719 return tape_34xx_erp_bug(device, request, irb, sense[3]);
721 if (device->cdev->id.driver_info == tape_3490) {
723 * Maximum block size exceeded. This indicates, that
724 * the block to be written is larger than allowed for
727 PRINT_WARN("Maximum block size for buffered "
729 return tape_34xx_erp_failed(request, -ENOBUFS);
731 /* This erpa is reserved for 3480. */
732 return tape_34xx_erp_bug(device, request, irb, sense[3]);
735 * Read buffered log (Overflow). CU is running in extended
736 * buffered log mode, and a counter overflows. This should
737 * never happen, since we're never running in extended
740 return tape_34xx_erp_retry(request);
743 * Read buffered log (EOV). EOF processing occurs while the
744 * CU is in extended buffered log mode. This should never
745 * happen, since we're never running in extended buffered
748 return tape_34xx_erp_retry(request);
750 /* End of Volume complete. Rewind unload completed ok. */
751 if (request->op == TO_RUN) {
752 tape_med_state_set(device, MS_UNLOADED);
753 tape_34xx_delete_sbid_from(device, 0);
754 return tape_34xx_erp_succeeded(request);
756 return tape_34xx_erp_bug(device, request, irb, sense[3]);
758 /* Global command intercept. */
759 return tape_34xx_erp_retry(request);
761 /* Channel interface recovery (temporary). */
762 return tape_34xx_erp_retry(request);
764 /* Channel interface recovery (permanent). */
765 PRINT_WARN("A permanent channel interface error occurred.\n");
766 return tape_34xx_erp_failed(request, -EIO);
768 /* Channel protocol error. */
769 PRINT_WARN("A channel protocol error occurred.\n");
770 return tape_34xx_erp_failed(request, -EIO);
772 if (device->cdev->id.driver_info == tape_3480) {
773 /* Attention intercept. */
774 PRINT_WARN("An attention intercept occurred, "
775 "which will be recovered.\n");
776 return tape_34xx_erp_retry(request);
778 /* Global status intercept. */
779 PRINT_WARN("An global status intercept was received, "
780 "which will be recovered.\n");
781 return tape_34xx_erp_retry(request);
785 * Tape length incompatible. The tape inserted is too long,
786 * which could cause damage to the tape or the drive.
788 PRINT_WARN("Tape Length Incompatible\n");
789 PRINT_WARN("Tape length exceeds IBM enhanced capacity "
790 "cartdridge length or a medium\n");
791 PRINT_WARN("with EC-CST identification mark has been mounted "
792 "in a device that writes\n");
793 PRINT_WARN("3480 or 3480 XF format.\n");
794 return tape_34xx_erp_failed(request, -EIO);
796 /* Format 3480 XF incompatible */
797 if (sense[1] & SENSE_BEGINNING_OF_TAPE)
798 /* The tape will get overwritten. */
799 return tape_34xx_erp_retry(request);
800 PRINT_WARN("Format 3480 XF Incompatible\n");
801 PRINT_WARN("Medium has been created in 3480 format. "
802 "To change the format writes\n");
803 PRINT_WARN("must be issued at BOT.\n");
804 return tape_34xx_erp_failed(request, -EIO);
806 /* Format 3480-2 XF incompatible */
807 PRINT_WARN("Format 3480-2 XF Incompatible\n");
808 PRINT_WARN("Device can only read 3480 or 3480 XF format.\n");
809 return tape_34xx_erp_failed(request, -EIO);
811 /* Tape length violation. */
812 PRINT_WARN("Tape Length Violation\n");
813 PRINT_WARN("The mounted tape exceeds IBM Enhanced Capacity "
814 "Cartdridge System Tape length.\n");
815 PRINT_WARN("This may cause damage to the drive or tape when "
816 "processing to the EOV\n");
817 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
819 /* Compaction algorithm incompatible. */
820 PRINT_WARN("Compaction Algorithm Incompatible\n");
821 PRINT_WARN("The volume is recorded using an incompatible "
822 "compaction algorithm,\n");
823 PRINT_WARN("which is not supported by the device.\n");
824 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
826 /* The following erpas should have been covered earlier. */
827 case 0x23: /* Read data check. */
828 case 0x25: /* Write data check. */
829 case 0x26: /* Data check (read opposite). */
830 case 0x28: /* Write id mark check. */
831 case 0x31: /* Tape void. */
832 case 0x40: /* Overrun error. */
833 case 0x41: /* Record sequence error. */
834 /* All other erpas are reserved for future use. */
836 return tape_34xx_erp_bug(device, request, irb, sense[3]);
841 * 3480/3490 interrupt handler
844 tape_34xx_irq(struct tape_device *device, struct tape_request *request,
848 return tape_34xx_unsolicited_irq(device, irb);
850 if ((irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) &&
851 (irb->scsw.dstat & DEV_STAT_DEV_END) &&
852 (request->op == TO_WRI)) {
853 /* Write at end of volume */
854 PRINT_INFO("End of volume\n"); /* XXX */
855 return tape_34xx_erp_failed(request, -ENOSPC);
858 if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
859 return tape_34xx_unit_check(device, request, irb);
861 if (irb->scsw.dstat & DEV_STAT_DEV_END) {
863 * A unit exception occurs on skipping over a tapemark block.
865 if (irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) {
866 if (request->op == TO_BSB || request->op == TO_FSB)
869 DBF_EVENT(5, "Unit Exception!\n");
871 return tape_34xx_done(request);
874 DBF_EVENT(6, "xunknownirq\n");
875 PRINT_ERR("Unexpected interrupt.\n");
876 PRINT_ERR("Current op is: %s", tape_op_verbose[request->op]);
877 tape_dump_sense(device, request, irb);
885 tape_34xx_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
887 if (cmd == TAPE390_DISPLAY) {
888 struct display_struct disp;
890 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)) != 0)
893 return tape_std_display(device, &disp);
899 tape_34xx_append_new_sbid(struct tape_34xx_block_id bid, struct list_head *l)
901 struct tape_34xx_sbid * new_sbid;
903 new_sbid = kmalloc(sizeof(*new_sbid), GFP_ATOMIC);
908 list_add(&new_sbid->list, l);
912 * Build up the search block ID list. The block ID consists of a logical
913 * block number and a hardware specific part. The hardware specific part
914 * helps the tape drive to speed up searching for a specific block.
917 tape_34xx_add_sbid(struct tape_device *device, struct tape_34xx_block_id bid)
919 struct list_head * sbid_list;
920 struct tape_34xx_sbid * sbid;
921 struct list_head * l;
924 * immediately return if there is no list at all or the block to add
925 * is located in segment 1 of wrap 0 because this position is used
926 * if no hardware position data is supplied.
928 sbid_list = (struct list_head *) device->discdata;
929 if (!sbid_list || (bid.segment < 2 && bid.wrap == 0))
933 * Search the position where to insert the new entry. Hardware
934 * acceleration uses only the segment and wrap number. So we
935 * need only one entry for a specific wrap/segment combination.
936 * If there is a block with a lower number but the same hard-
937 * ware position data we just update the block number in the
940 list_for_each(l, sbid_list) {
941 sbid = list_entry(l, struct tape_34xx_sbid, list);
944 (sbid->bid.segment == bid.segment) &&
945 (sbid->bid.wrap == bid.wrap)
947 if (bid.block < sbid->bid.block)
953 /* Sort in according to logical block number. */
954 if (bid.block < sbid->bid.block) {
955 tape_34xx_append_new_sbid(bid, l->prev);
959 /* List empty or new block bigger than last entry. */
961 tape_34xx_append_new_sbid(bid, l->prev);
963 DBF_LH(4, "Current list is:\n");
964 list_for_each(l, sbid_list) {
965 sbid = list_entry(l, struct tape_34xx_sbid, list);
966 DBF_LH(4, "%d:%03d@%05d\n",
975 * Delete all entries from the search block ID list that belong to tape blocks
976 * equal or higher than the given number.
979 tape_34xx_delete_sbid_from(struct tape_device *device, int from)
981 struct list_head * sbid_list;
982 struct tape_34xx_sbid * sbid;
983 struct list_head * l;
984 struct list_head * n;
986 sbid_list = (struct list_head *) device->discdata;
990 list_for_each_safe(l, n, sbid_list) {
991 sbid = list_entry(l, struct tape_34xx_sbid, list);
992 if (sbid->bid.block >= from) {
993 DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
1005 * Merge hardware position data into a block id.
1008 tape_34xx_merge_sbid(
1009 struct tape_device * device,
1010 struct tape_34xx_block_id * bid
1012 struct tape_34xx_sbid * sbid;
1013 struct tape_34xx_sbid * sbid_to_use;
1014 struct list_head * sbid_list;
1015 struct list_head * l;
1017 sbid_list = (struct list_head *) device->discdata;
1021 if (!sbid_list || list_empty(sbid_list))
1025 list_for_each(l, sbid_list) {
1026 sbid = list_entry(l, struct tape_34xx_sbid, list);
1028 if (sbid->bid.block >= bid->block)
1033 bid->wrap = sbid_to_use->bid.wrap;
1034 bid->segment = sbid_to_use->bid.segment;
1035 DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
1036 sbid_to_use->bid.wrap,
1037 sbid_to_use->bid.segment,
1038 sbid_to_use->bid.block,
1045 tape_34xx_setup_device(struct tape_device * device)
1048 struct list_head * discdata;
1050 DBF_EVENT(6, "34xx device setup\n");
1051 if ((rc = tape_std_assign(device)) == 0) {
1052 if ((rc = tape_34xx_medium_sense(device)) != 0) {
1053 DBF_LH(3, "34xx medium sense returned %d\n", rc);
1056 discdata = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1058 INIT_LIST_HEAD(discdata);
1059 device->discdata = discdata;
1066 tape_34xx_cleanup_device(struct tape_device *device)
1068 tape_std_unassign(device);
1070 if (device->discdata) {
1071 tape_34xx_delete_sbid_from(device, 0);
1072 kfree(device->discdata);
1073 device->discdata = NULL;
1079 * MTTELL: Tell block. Return the number of block relative to current file.
1082 tape_34xx_mttell(struct tape_device *device, int mt_count)
1085 struct tape_34xx_block_id cbid;
1086 struct tape_34xx_block_id dbid;
1087 } __attribute__ ((packed)) block_id;
1090 rc = tape_std_read_block_id(device, (__u64 *) &block_id);
1094 tape_34xx_add_sbid(device, block_id.cbid);
1095 return block_id.cbid.block;
1099 * MTSEEK: seek to the specified block.
1102 tape_34xx_mtseek(struct tape_device *device, int mt_count)
1104 struct tape_request *request;
1105 struct tape_34xx_block_id * bid;
1107 if (mt_count > 0x3fffff) {
1108 DBF_EXCEPTION(6, "xsee parm\n");
1111 request = tape_alloc_request(3, 4);
1112 if (IS_ERR(request))
1113 return PTR_ERR(request);
1116 request->op = TO_LBL;
1117 bid = (struct tape_34xx_block_id *) request->cpdata;
1118 bid->format = (*device->modeset_byte & 0x08) ?
1119 TAPE34XX_FMT_3480_XF : TAPE34XX_FMT_3480;
1120 bid->block = mt_count;
1121 tape_34xx_merge_sbid(device, bid);
1123 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
1124 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1125 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
1128 return tape_do_io_free(device, request);
1131 #ifdef CONFIG_S390_TAPE_BLOCK
1133 * Tape block read for 34xx.
1135 static struct tape_request *
1136 tape_34xx_bread(struct tape_device *device, struct request *req)
1138 struct tape_request *request;
1145 struct tape_34xx_block_id * start_block;
1147 DBF_EVENT(6, "xBREDid:");
1149 /* Count the number of blocks for the request. */
1150 rq_for_each_bio(bio, req) {
1151 bio_for_each_segment(bv, bio, i) {
1152 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
1156 /* Allocate the ccw request. */
1157 request = tape_alloc_request(3+count+1, 8);
1158 if (IS_ERR(request))
1162 request->op = TO_BLOCK;
1163 start_block = (struct tape_34xx_block_id *) request->cpdata;
1164 start_block->block = req->sector >> TAPEBLOCK_HSEC_S2B;
1165 DBF_EVENT(6, "start_block = %i\n", start_block->block);
1167 ccw = request->cpaddr;
1168 ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);
1171 * We always setup a nop after the mode set ccw. This slot is
1172 * used in tape_std_check_locate to insert a locate ccw if the
1173 * current tape position doesn't match the start block to be read.
1174 * The second nop will be filled with a read block id which is in
1175 * turn used by tape_34xx_free_bread to populate the segment bid
1178 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
1179 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
1181 rq_for_each_bio(bio, req) {
1182 bio_for_each_segment(bv, bio, i) {
1183 dst = kmap(bv->bv_page) + bv->bv_offset;
1184 for (off = 0; off < bv->bv_len;
1185 off += TAPEBLOCK_HSEC_SIZE) {
1186 ccw->flags = CCW_FLAG_CC;
1187 ccw->cmd_code = READ_FORWARD;
1188 ccw->count = TAPEBLOCK_HSEC_SIZE;
1189 set_normalized_cda(ccw, (void*) __pa(dst));
1191 dst += TAPEBLOCK_HSEC_SIZE;
1196 ccw = tape_ccw_end(ccw, NOP, 0, NULL);
1197 DBF_EVENT(6, "xBREDccwg\n");
1202 tape_34xx_free_bread (struct tape_request *request)
1206 ccw = request->cpaddr;
1207 if ((ccw + 2)->cmd_code == READ_BLOCK_ID) {
1209 struct tape_34xx_block_id cbid;
1210 struct tape_34xx_block_id dbid;
1211 } __attribute__ ((packed)) *rbi_data;
1213 rbi_data = request->cpdata;
1215 if (request->device)
1216 tape_34xx_add_sbid(request->device, rbi_data->cbid);
1219 /* Last ccw is a nop and doesn't need clear_normalized_cda */
1220 for (; ccw->flags & CCW_FLAG_CC; ccw++)
1221 if (ccw->cmd_code == READ_FORWARD)
1222 clear_normalized_cda(ccw);
1223 tape_free_request(request);
1227 * check_locate is called just before the tape request is passed to
1228 * the common io layer for execution. It has to check the current
1229 * tape position and insert a locate ccw if it doesn't match the
1230 * start block for the request.
1233 tape_34xx_check_locate(struct tape_device *device, struct tape_request *request)
1235 struct tape_34xx_block_id * start_block;
1237 start_block = (struct tape_34xx_block_id *) request->cpdata;
1238 if (start_block->block == device->blk_data.block_position)
1241 DBF_LH(4, "Block seek(%06d+%06d)\n", start_block->block, device->bof);
1242 start_block->wrap = 0;
1243 start_block->segment = 1;
1244 start_block->format = (*device->modeset_byte & 0x08) ?
1245 TAPE34XX_FMT_3480_XF :
1247 start_block->block = start_block->block + device->bof;
1248 tape_34xx_merge_sbid(device, start_block);
1249 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1250 tape_ccw_cc(request->cpaddr + 2, READ_BLOCK_ID, 8, request->cpdata);
1255 * List of 3480/3490 magnetic tape commands.
1257 static tape_mtop_fn tape_34xx_mtop[TAPE_NR_MTOPS] = {
1258 [MTRESET] = tape_std_mtreset,
1259 [MTFSF] = tape_std_mtfsf,
1260 [MTBSF] = tape_std_mtbsf,
1261 [MTFSR] = tape_std_mtfsr,
1262 [MTBSR] = tape_std_mtbsr,
1263 [MTWEOF] = tape_std_mtweof,
1264 [MTREW] = tape_std_mtrew,
1265 [MTOFFL] = tape_std_mtoffl,
1266 [MTNOP] = tape_std_mtnop,
1267 [MTRETEN] = tape_std_mtreten,
1268 [MTBSFM] = tape_std_mtbsfm,
1269 [MTFSFM] = tape_std_mtfsfm,
1270 [MTEOM] = tape_std_mteom,
1271 [MTERASE] = tape_std_mterase,
1275 [MTSETBLK] = tape_std_mtsetblk,
1276 [MTSETDENSITY] = NULL,
1277 [MTSEEK] = tape_34xx_mtseek,
1278 [MTTELL] = tape_34xx_mttell,
1279 [MTSETDRVBUFFER] = NULL,
1285 [MTLOAD] = tape_std_mtload,
1286 [MTUNLOAD] = tape_std_mtunload,
1287 [MTCOMPRESSION] = tape_std_mtcompression,
1293 * Tape discipline structure for 3480 and 3490.
1295 static struct tape_discipline tape_discipline_34xx = {
1296 .owner = THIS_MODULE,
1297 .setup_device = tape_34xx_setup_device,
1298 .cleanup_device = tape_34xx_cleanup_device,
1299 .process_eov = tape_std_process_eov,
1300 .irq = tape_34xx_irq,
1301 .read_block = tape_std_read_block,
1302 .write_block = tape_std_write_block,
1303 #ifdef CONFIG_S390_TAPE_BLOCK
1304 .bread = tape_34xx_bread,
1305 .free_bread = tape_34xx_free_bread,
1306 .check_locate = tape_34xx_check_locate,
1308 .ioctl_fn = tape_34xx_ioctl,
1309 .mtop_array = tape_34xx_mtop
1312 static struct ccw_device_id tape_34xx_ids[] = {
1313 { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), driver_info: tape_3480},
1314 { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), driver_info: tape_3490},
1315 { /* end of list */ }
1319 tape_34xx_online(struct ccw_device *cdev)
1321 return tape_generic_online(
1322 cdev->dev.driver_data,
1323 &tape_discipline_34xx
1328 tape_34xx_offline(struct ccw_device *cdev)
1330 return tape_generic_offline(cdev->dev.driver_data);
1333 static struct ccw_driver tape_34xx_driver = {
1334 .name = "tape_34xx",
1335 .owner = THIS_MODULE,
1336 .ids = tape_34xx_ids,
1337 .probe = tape_generic_probe,
1338 .remove = tape_generic_remove,
1339 .set_online = tape_34xx_online,
1340 .set_offline = tape_34xx_offline,
1344 tape_34xx_init (void)
1348 TAPE_DBF_AREA = debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
1349 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1350 #ifdef DBF_LIKE_HELL
1351 debug_set_level(TAPE_DBF_AREA, 6);
1354 DBF_EVENT(3, "34xx init\n");
1355 /* Register driver for 3480/3490 tapes. */
1356 rc = ccw_driver_register(&tape_34xx_driver);
1358 DBF_EVENT(3, "34xx init failed\n");
1360 DBF_EVENT(3, "34xx registered\n");
1365 tape_34xx_exit(void)
1367 ccw_driver_unregister(&tape_34xx_driver);
1369 debug_unregister(TAPE_DBF_AREA);
1372 MODULE_DEVICE_TABLE(ccw, tape_34xx_ids);
1373 MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
1374 MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape device driver");
1375 MODULE_LICENSE("GPL");
1377 module_init(tape_34xx_init);
1378 module_exit(tape_34xx_exit);