1
2
3
4
5
6
7
8
9
10#define KMSG_COMPONENT "tape_34xx"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/bio.h>
16#include <linux/workqueue.h>
17#include <linux/slab.h>
18
19#define TAPE_DBF_AREA tape_34xx_dbf
20
21#include "tape.h"
22#include "tape_std.h"
23
24
25
26
27debug_info_t *TAPE_DBF_AREA = NULL;
28EXPORT_SYMBOL(TAPE_DBF_AREA);
29
30#define TAPE34XX_FMT_3480 0
31#define TAPE34XX_FMT_3480_2_XF 1
32#define TAPE34XX_FMT_3480_XF 2
33
34struct tape_34xx_block_id {
35 unsigned int wrap : 1;
36 unsigned int segment : 7;
37 unsigned int format : 2;
38 unsigned int block : 22;
39};
40
41
42
43
44struct tape_34xx_sbid {
45 struct list_head list;
46 struct tape_34xx_block_id bid;
47};
48
49static void tape_34xx_delete_sbid_from(struct tape_device *, int);
50
51
52
53
54
55static void __tape_34xx_medium_sense(struct tape_request *request)
56{
57 struct tape_device *device = request->device;
58 unsigned char *sense;
59
60 if (request->rc == 0) {
61 sense = request->cpdata;
62
63
64
65
66
67
68
69 if (sense[0] & SENSE_INTERVENTION_REQUIRED)
70 tape_med_state_set(device, MS_UNLOADED);
71 else
72 tape_med_state_set(device, MS_LOADED);
73
74 if (sense[1] & SENSE_WRITE_PROTECT)
75 device->tape_generic_status |= GMT_WR_PROT(~0);
76 else
77 device->tape_generic_status &= ~GMT_WR_PROT(~0);
78 } else
79 DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
80 request->rc);
81 tape_free_request(request);
82}
83
84static int tape_34xx_medium_sense(struct tape_device *device)
85{
86 struct tape_request *request;
87 int rc;
88
89 request = tape_alloc_request(1, 32);
90 if (IS_ERR(request)) {
91 DBF_EXCEPTION(6, "MSEN fail\n");
92 return PTR_ERR(request);
93 }
94
95 request->op = TO_MSEN;
96 tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata);
97 rc = tape_do_io_interruptible(device, request);
98 __tape_34xx_medium_sense(request);
99 return rc;
100}
101
102static void tape_34xx_medium_sense_async(struct tape_device *device)
103{
104 struct tape_request *request;
105
106 request = tape_alloc_request(1, 32);
107 if (IS_ERR(request)) {
108 DBF_EXCEPTION(6, "MSEN fail\n");
109 return;
110 }
111
112 request->op = TO_MSEN;
113 tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata);
114 request->callback = (void *) __tape_34xx_medium_sense;
115 request->callback_data = NULL;
116 tape_do_io_async(device, request);
117}
118
119struct tape_34xx_work {
120 struct tape_device *device;
121 enum tape_op op;
122 struct work_struct work;
123};
124
125
126
127
128
129
130
131
132
133
134
135static void
136tape_34xx_work_handler(struct work_struct *work)
137{
138 struct tape_34xx_work *p =
139 container_of(work, struct tape_34xx_work, work);
140 struct tape_device *device = p->device;
141
142 switch(p->op) {
143 case TO_MSEN:
144 tape_34xx_medium_sense_async(device);
145 break;
146 default:
147 DBF_EVENT(3, "T34XX: internal error: unknown work\n");
148 }
149 tape_put_device(device);
150 kfree(p);
151}
152
153static int
154tape_34xx_schedule_work(struct tape_device *device, enum tape_op op)
155{
156 struct tape_34xx_work *p;
157
158 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
159 return -ENOMEM;
160
161 INIT_WORK(&p->work, tape_34xx_work_handler);
162
163 p->device = tape_get_device(device);
164 p->op = op;
165
166 schedule_work(&p->work);
167 return 0;
168}
169
170
171
172
173static inline int
174tape_34xx_done(struct tape_request *request)
175{
176 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
177
178 switch (request->op) {
179 case TO_DSE:
180 case TO_RUN:
181 case TO_WRI:
182 case TO_WTM:
183 case TO_ASSIGN:
184 case TO_UNASSIGN:
185 tape_34xx_delete_sbid_from(request->device, 0);
186 break;
187 default:
188 ;
189 }
190 return TAPE_IO_SUCCESS;
191}
192
193static inline int
194tape_34xx_erp_failed(struct tape_request *request, int rc)
195{
196 DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
197 tape_op_verbose[request->op], rc);
198 return rc;
199}
200
201static inline int
202tape_34xx_erp_succeeded(struct tape_request *request)
203{
204 DBF_EVENT(3, "Error Recovery successful for %s\n",
205 tape_op_verbose[request->op]);
206 return tape_34xx_done(request);
207}
208
209static inline int
210tape_34xx_erp_retry(struct tape_request *request)
211{
212 DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose[request->op]);
213 return TAPE_IO_RETRY;
214}
215
216
217
218
219
220static int
221tape_34xx_unsolicited_irq(struct tape_device *device, struct irb *irb)
222{
223 if (irb->scsw.cmd.dstat == 0x85) {
224
225 DBF_EVENT(6, "xuud med\n");
226 tape_34xx_delete_sbid_from(device, 0);
227 tape_34xx_schedule_work(device, TO_MSEN);
228 } else {
229 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
230 tape_dump_sense_dbf(device, NULL, irb);
231 }
232 return TAPE_IO_SUCCESS;
233}
234
235
236
237
238
239static int
240tape_34xx_erp_read_opposite(struct tape_device *device,
241 struct tape_request *request)
242{
243 if (request->op == TO_RFO) {
244
245
246
247
248
249 tape_std_read_backward(device, request);
250 return tape_34xx_erp_retry(request);
251 }
252
253
254
255
256
257 return tape_34xx_erp_failed(request, -EIO);
258}
259
260static int
261tape_34xx_erp_bug(struct tape_device *device, struct tape_request *request,
262 struct irb *irb, int no)
263{
264 if (request->op != TO_ASSIGN) {
265 dev_err(&device->cdev->dev, "An unexpected condition %d "
266 "occurred in tape error recovery\n", no);
267 tape_dump_sense_dbf(device, request, irb);
268 }
269 return tape_34xx_erp_failed(request, -EIO);
270}
271
272
273
274
275
276static int
277tape_34xx_erp_overrun(struct tape_device *device, struct tape_request *request,
278 struct irb *irb)
279{
280 if (irb->ecw[3] == 0x40) {
281 dev_warn (&device->cdev->dev, "A data overrun occurred between"
282 " the control unit and tape unit\n");
283 return tape_34xx_erp_failed(request, -EIO);
284 }
285 return tape_34xx_erp_bug(device, request, irb, -1);
286}
287
288
289
290
291static int
292tape_34xx_erp_sequence(struct tape_device *device,
293 struct tape_request *request, struct irb *irb)
294{
295 if (irb->ecw[3] == 0x41) {
296
297
298
299 dev_warn (&device->cdev->dev, "The block ID sequence on the "
300 "tape is incorrect\n");
301 return tape_34xx_erp_failed(request, -EIO);
302 }
303
304
305
306
307 return tape_34xx_erp_bug(device, request, irb, -2);
308}
309
310
311
312
313
314
315static int
316tape_34xx_unit_check(struct tape_device *device, struct tape_request *request,
317 struct irb *irb)
318{
319 int inhibit_cu_recovery;
320 __u8* sense;
321
322 inhibit_cu_recovery = (*device->modeset_byte & 0x80) ? 1 : 0;
323 sense = irb->ecw;
324
325 if (
326 sense[0] & SENSE_COMMAND_REJECT &&
327 sense[1] & SENSE_WRITE_PROTECT
328 ) {
329 if (
330 request->op == TO_DSE ||
331 request->op == TO_WRI ||
332 request->op == TO_WTM
333 ) {
334
335 return tape_34xx_erp_failed(request, -EACCES);
336 } else {
337 return tape_34xx_erp_bug(device, request, irb, -3);
338 }
339 }
340
341
342
343
344
345
346
347
348
349
350
351
352
353 if ((
354 sense[0] == SENSE_DATA_CHECK ||
355 sense[0] == SENSE_EQUIPMENT_CHECK ||
356 sense[0] == SENSE_EQUIPMENT_CHECK + SENSE_DEFERRED_UNIT_CHECK
357 ) && (
358 sense[1] == SENSE_DRIVE_ONLINE ||
359 sense[1] == SENSE_BEGINNING_OF_TAPE + SENSE_WRITE_MODE
360 )) {
361 switch (request->op) {
362
363
364
365
366
367
368
369 case TO_FSF:
370 case TO_FSB:
371
372 return tape_34xx_erp_failed(request, -ENOSPC);
373 case TO_BSB:
374 return tape_34xx_erp_retry(request);
375
376
377
378
379
380
381 case TO_LBL:
382
383 tape_34xx_delete_sbid_from(device, 0);
384 return tape_34xx_erp_failed(request, -EIO);
385
386 case TO_RFO:
387
388 return tape_34xx_erp_failed(request, 0);
389
390
391
392
393
394
395 case TO_WRI:
396
397 return tape_34xx_erp_failed(request, -ENOSPC);
398 default:
399 return tape_34xx_erp_failed(request, 0);
400 }
401 }
402
403
404 if (sense[0] & SENSE_BUS_OUT_CHECK)
405 return tape_34xx_erp_retry(request);
406
407 if (sense[0] & SENSE_DATA_CHECK) {
408
409
410
411
412 switch (sense[3]) {
413 case 0x23:
414
415 if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
416 inhibit_cu_recovery)
417
418
419
420 return tape_34xx_erp_bug(device, request,
421 irb, -4);
422
423
424 dev_warn (&device->cdev->dev, "A read error occurred "
425 "that cannot be recovered\n");
426 return tape_34xx_erp_failed(request, -EIO);
427 case 0x25:
428
429 if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
430 inhibit_cu_recovery)
431
432
433
434 return tape_34xx_erp_bug(device, request,
435 irb, -5);
436
437
438 dev_warn (&device->cdev->dev, "A write error on the "
439 "tape cannot be recovered\n");
440 return tape_34xx_erp_failed(request, -EIO);
441 case 0x26:
442
443 return tape_34xx_erp_read_opposite(device, request);
444 case 0x28:
445
446 dev_warn (&device->cdev->dev, "Writing the ID-mark "
447 "failed\n");
448 return tape_34xx_erp_failed(request, -EIO);
449 case 0x31:
450
451 dev_warn (&device->cdev->dev, "Reading the tape beyond"
452 " the end of the recorded area failed\n");
453 return tape_34xx_erp_failed(request, -ENOSPC);
454 case 0x41:
455
456 dev_warn (&device->cdev->dev, "The tape contains an "
457 "incorrect block ID sequence\n");
458 return tape_34xx_erp_failed(request, -EIO);
459 default:
460
461
462
463 if (device->cdev->id.driver_info == tape_3480)
464 return tape_34xx_erp_bug(device, request,
465 irb, -6);
466 }
467 }
468
469 if (sense[0] & SENSE_OVERRUN)
470 return tape_34xx_erp_overrun(device, request, irb);
471
472 if (sense[1] & SENSE_RECORD_SEQUENCE_ERR)
473 return tape_34xx_erp_sequence(device, request, irb);
474
475
476 switch (sense[3]) {
477 case 0x00:
478
479 return TAPE_IO_SUCCESS;
480 case 0x21:
481
482
483
484
485 return tape_34xx_erp_retry(request);
486 case 0x22:
487
488
489
490
491
492 dev_warn (&device->cdev->dev, "A path equipment check occurred"
493 " for the tape device\n");
494 return tape_34xx_erp_failed(request, -EIO);
495 case 0x24:
496
497
498
499
500
501 return tape_34xx_erp_succeeded(request);
502 case 0x27:
503
504
505
506
507
508
509 return tape_34xx_erp_retry(request);
510 case 0x29:
511
512
513
514
515
516 return tape_34xx_erp_failed(request, -EIO);
517 case 0x2a:
518
519
520
521
522 return tape_34xx_erp_retry(request);
523 case 0x2b:
524
525
526
527
528 if (request->op == TO_RUN) {
529
530 tape_med_state_set(device, MS_UNLOADED);
531 return tape_34xx_erp_succeeded(request);
532 }
533
534 return tape_34xx_erp_bug(device, request, irb, sense[3]);
535 case 0x2c:
536
537
538
539
540 return tape_34xx_erp_failed(request, -EIO);
541 case 0x2d:
542
543 if (request->op == TO_DSE)
544 return tape_34xx_erp_failed(request, -EIO);
545
546 return tape_34xx_erp_bug(device, request, irb, sense[3]);
547 case 0x2e:
548
549
550
551
552
553 dev_warn (&device->cdev->dev, "The tape unit cannot process "
554 "the tape format\n");
555 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
556 case 0x30:
557
558 dev_warn (&device->cdev->dev, "The tape medium is write-"
559 "protected\n");
560 return tape_34xx_erp_failed(request, -EACCES);
561 case 0x32:
562
563 dev_warn (&device->cdev->dev, "The tape does not have the "
564 "required tape tension\n");
565 return tape_34xx_erp_failed(request, -EIO);
566 case 0x33:
567
568
569
570
571 dev_warn (&device->cdev->dev, "The tape unit failed to load"
572 " the cartridge\n");
573 tape_34xx_delete_sbid_from(device, 0);
574 return tape_34xx_erp_failed(request, -EIO);
575 case 0x34:
576
577
578
579
580 dev_warn (&device->cdev->dev, "Automatic unloading of the tape"
581 " cartridge failed\n");
582 if (request->op == TO_RUN)
583 return tape_34xx_erp_failed(request, -EIO);
584 return tape_34xx_erp_bug(device, request, irb, sense[3]);
585 case 0x35:
586
587
588
589
590
591
592
593 dev_warn (&device->cdev->dev, "An equipment check has occurred"
594 " on the tape unit\n");
595 return tape_34xx_erp_failed(request, -EIO);
596 case 0x36:
597 if (device->cdev->id.driver_info == tape_3490)
598
599 return tape_34xx_erp_failed(request, -EIO);
600
601 return tape_34xx_erp_bug(device, request, irb, sense[3]);
602 case 0x37:
603
604
605
606
607 dev_warn (&device->cdev->dev, "The tape information states an"
608 " incorrect length\n");
609 return tape_34xx_erp_failed(request, -EIO);
610 case 0x38:
611
612
613
614
615 if (request->op==TO_WRI ||
616 request->op==TO_DSE ||
617 request->op==TO_WTM)
618 return tape_34xx_erp_failed(request, -ENOSPC);
619 return tape_34xx_erp_failed(request, -EIO);
620 case 0x39:
621
622 return tape_34xx_erp_failed(request, -EIO);
623 case 0x3a:
624
625 dev_warn (&device->cdev->dev, "The tape unit is not ready\n");
626 return tape_34xx_erp_failed(request, -EIO);
627 case 0x3b:
628
629 dev_warn (&device->cdev->dev, "The tape medium has been "
630 "rewound or unloaded manually\n");
631 tape_34xx_delete_sbid_from(device, 0);
632 return tape_34xx_erp_failed(request, -EIO);
633 case 0x42:
634
635
636
637
638 dev_warn (&device->cdev->dev, "The tape subsystem is running "
639 "in degraded mode\n");
640 return tape_34xx_erp_retry(request);
641 case 0x43:
642
643 tape_34xx_delete_sbid_from(device, 0);
644 tape_med_state_set(device, MS_UNLOADED);
645
646 if (sense[1] & SENSE_DRIVE_ONLINE) {
647 switch(request->op) {
648 case TO_ASSIGN:
649 case TO_UNASSIGN:
650 case TO_DIS:
651 case TO_NOP:
652 return tape_34xx_done(request);
653 break;
654 default:
655 break;
656 }
657 }
658 return tape_34xx_erp_failed(request, -ENOMEDIUM);
659 case 0x44:
660
661 if (request->op != TO_BLOCK && request->op != TO_LBL)
662
663 return tape_34xx_erp_bug(device, request,
664 irb, sense[3]);
665 return tape_34xx_erp_failed(request, -EIO);
666 case 0x45:
667
668 dev_warn (&device->cdev->dev, "The tape unit is already "
669 "assigned\n");
670 return tape_34xx_erp_failed(request, -EIO);
671 case 0x46:
672
673
674
675
676
677 dev_warn (&device->cdev->dev, "The tape unit is not online\n");
678 return tape_34xx_erp_failed(request, -EIO);
679 case 0x47:
680
681 dev_warn (&device->cdev->dev, "The control unit has fenced "
682 "access to the tape volume\n");
683 tape_34xx_delete_sbid_from(device, 0);
684 return tape_34xx_erp_failed(request, -EIO);
685 case 0x48:
686
687 return tape_34xx_erp_retry(request);
688 case 0x49:
689
690 dev_warn (&device->cdev->dev, "A parity error occurred on the "
691 "tape bus\n");
692 return tape_34xx_erp_failed(request, -EIO);
693 case 0x4a:
694
695 dev_warn (&device->cdev->dev, "I/O error recovery failed on "
696 "the tape control unit\n");
697 return tape_34xx_erp_failed(request, -EIO);
698 case 0x4b:
699
700
701
702
703 dev_warn (&device->cdev->dev, "The tape unit requires a "
704 "firmware update\n");
705 return tape_34xx_erp_failed(request, -EIO);
706 case 0x4c:
707
708
709
710
711 return tape_34xx_erp_retry(request);
712 case 0x4d:
713 if (device->cdev->id.driver_info == tape_3490)
714
715
716
717
718
719 return tape_34xx_erp_retry(request);
720
721 return tape_34xx_erp_bug(device, request, irb, sense[3]);
722 case 0x4e:
723 if (device->cdev->id.driver_info == tape_3490) {
724
725
726
727
728
729 dev_warn (&device->cdev->dev, "The maximum block size"
730 " for buffered mode is exceeded\n");
731 return tape_34xx_erp_failed(request, -ENOBUFS);
732 }
733
734 return tape_34xx_erp_bug(device, request, irb, sense[3]);
735 case 0x50:
736
737
738
739
740
741
742 return tape_34xx_erp_retry(request);
743 case 0x51:
744
745
746
747
748
749
750 return tape_34xx_erp_retry(request);
751 case 0x52:
752
753 if (request->op == TO_RUN) {
754 tape_med_state_set(device, MS_UNLOADED);
755 tape_34xx_delete_sbid_from(device, 0);
756 return tape_34xx_erp_succeeded(request);
757 }
758 return tape_34xx_erp_bug(device, request, irb, sense[3]);
759 case 0x53:
760
761 return tape_34xx_erp_retry(request);
762 case 0x54:
763
764 return tape_34xx_erp_retry(request);
765 case 0x55:
766
767 dev_warn (&device->cdev->dev, "A channel interface error cannot be"
768 " recovered\n");
769 return tape_34xx_erp_failed(request, -EIO);
770 case 0x56:
771
772 dev_warn (&device->cdev->dev, "A channel protocol error "
773 "occurred\n");
774 return tape_34xx_erp_failed(request, -EIO);
775 case 0x57:
776 if (device->cdev->id.driver_info == tape_3480) {
777
778 return tape_34xx_erp_retry(request);
779 } else {
780
781 return tape_34xx_erp_retry(request);
782 }
783 case 0x5a:
784
785
786
787
788 dev_warn (&device->cdev->dev, "The tape unit does not support "
789 "the tape length\n");
790 return tape_34xx_erp_failed(request, -EIO);
791 case 0x5b:
792
793 if (sense[1] & SENSE_BEGINNING_OF_TAPE)
794
795 return tape_34xx_erp_retry(request);
796 dev_warn (&device->cdev->dev, "The tape unit does not support"
797 " format 3480 XF\n");
798 return tape_34xx_erp_failed(request, -EIO);
799 case 0x5c:
800
801 dev_warn (&device->cdev->dev, "The tape unit does not support tape "
802 "format 3480-2 XF\n");
803 return tape_34xx_erp_failed(request, -EIO);
804 case 0x5d:
805
806 dev_warn (&device->cdev->dev, "The tape unit does not support"
807 " the current tape length\n");
808 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
809 case 0x5e:
810
811 dev_warn (&device->cdev->dev, "The tape unit does not support"
812 " the compaction algorithm\n");
813 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
814
815
816 case 0x23:
817 case 0x25:
818 case 0x26:
819 case 0x28:
820 case 0x31:
821 case 0x40:
822 case 0x41:
823
824 default:
825 return tape_34xx_erp_bug(device, request, irb, sense[3]);
826 }
827}
828
829
830
831
832static int
833tape_34xx_irq(struct tape_device *device, struct tape_request *request,
834 struct irb *irb)
835{
836 if (request == NULL)
837 return tape_34xx_unsolicited_irq(device, irb);
838
839 if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
840 (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
841 (request->op == TO_WRI)) {
842
843 return tape_34xx_erp_failed(request, -ENOSPC);
844 }
845
846 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
847 return tape_34xx_unit_check(device, request, irb);
848
849 if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
850
851
852
853 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
854 if (request->op == TO_BSB || request->op == TO_FSB)
855 request->rescnt++;
856 else
857 DBF_EVENT(5, "Unit Exception!\n");
858 }
859 return tape_34xx_done(request);
860 }
861
862 DBF_EVENT(6, "xunknownirq\n");
863 tape_dump_sense_dbf(device, request, irb);
864 return TAPE_IO_STOP;
865}
866
867
868
869
870static int
871tape_34xx_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
872{
873 if (cmd == TAPE390_DISPLAY) {
874 struct display_struct disp;
875
876 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)) != 0)
877 return -EFAULT;
878
879 return tape_std_display(device, &disp);
880 } else
881 return -EINVAL;
882}
883
884static inline void
885tape_34xx_append_new_sbid(struct tape_34xx_block_id bid, struct list_head *l)
886{
887 struct tape_34xx_sbid * new_sbid;
888
889 new_sbid = kmalloc(sizeof(*new_sbid), GFP_ATOMIC);
890 if (!new_sbid)
891 return;
892
893 new_sbid->bid = bid;
894 list_add(&new_sbid->list, l);
895}
896
897
898
899
900
901
902static void
903tape_34xx_add_sbid(struct tape_device *device, struct tape_34xx_block_id bid)
904{
905 struct list_head * sbid_list;
906 struct tape_34xx_sbid * sbid;
907 struct list_head * l;
908
909
910
911
912
913
914 sbid_list = (struct list_head *) device->discdata;
915 if (!sbid_list || (bid.segment < 2 && bid.wrap == 0))
916 return;
917
918
919
920
921
922
923
924
925
926 list_for_each(l, sbid_list) {
927 sbid = list_entry(l, struct tape_34xx_sbid, list);
928
929 if (
930 (sbid->bid.segment == bid.segment) &&
931 (sbid->bid.wrap == bid.wrap)
932 ) {
933 if (bid.block < sbid->bid.block)
934 sbid->bid = bid;
935 else return;
936 break;
937 }
938
939
940 if (bid.block < sbid->bid.block) {
941 tape_34xx_append_new_sbid(bid, l->prev);
942 break;
943 }
944 }
945
946 if (l == sbid_list)
947 tape_34xx_append_new_sbid(bid, l->prev);
948
949 DBF_LH(4, "Current list is:\n");
950 list_for_each(l, sbid_list) {
951 sbid = list_entry(l, struct tape_34xx_sbid, list);
952 DBF_LH(4, "%d:%03d@%05d\n",
953 sbid->bid.wrap,
954 sbid->bid.segment,
955 sbid->bid.block
956 );
957 }
958}
959
960
961
962
963
964static void
965tape_34xx_delete_sbid_from(struct tape_device *device, int from)
966{
967 struct list_head * sbid_list;
968 struct tape_34xx_sbid * sbid;
969 struct list_head * l;
970 struct list_head * n;
971
972 sbid_list = (struct list_head *) device->discdata;
973 if (!sbid_list)
974 return;
975
976 list_for_each_safe(l, n, sbid_list) {
977 sbid = list_entry(l, struct tape_34xx_sbid, list);
978 if (sbid->bid.block >= from) {
979 DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
980 sbid->bid.wrap,
981 sbid->bid.segment,
982 sbid->bid.block
983 );
984 list_del(l);
985 kfree(sbid);
986 }
987 }
988}
989
990
991
992
993static void
994tape_34xx_merge_sbid(
995 struct tape_device * device,
996 struct tape_34xx_block_id * bid
997) {
998 struct tape_34xx_sbid * sbid;
999 struct tape_34xx_sbid * sbid_to_use;
1000 struct list_head * sbid_list;
1001 struct list_head * l;
1002
1003 sbid_list = (struct list_head *) device->discdata;
1004 bid->wrap = 0;
1005 bid->segment = 1;
1006
1007 if (!sbid_list || list_empty(sbid_list))
1008 return;
1009
1010 sbid_to_use = NULL;
1011 list_for_each(l, sbid_list) {
1012 sbid = list_entry(l, struct tape_34xx_sbid, list);
1013
1014 if (sbid->bid.block >= bid->block)
1015 break;
1016 sbid_to_use = sbid;
1017 }
1018 if (sbid_to_use) {
1019 bid->wrap = sbid_to_use->bid.wrap;
1020 bid->segment = sbid_to_use->bid.segment;
1021 DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
1022 sbid_to_use->bid.wrap,
1023 sbid_to_use->bid.segment,
1024 sbid_to_use->bid.block,
1025 bid->block
1026 );
1027 }
1028}
1029
1030static int
1031tape_34xx_setup_device(struct tape_device * device)
1032{
1033 int rc;
1034 struct list_head * discdata;
1035
1036 DBF_EVENT(6, "34xx device setup\n");
1037 if ((rc = tape_std_assign(device)) == 0) {
1038 if ((rc = tape_34xx_medium_sense(device)) != 0) {
1039 DBF_LH(3, "34xx medium sense returned %d\n", rc);
1040 }
1041 }
1042 discdata = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1043 if (discdata) {
1044 INIT_LIST_HEAD(discdata);
1045 device->discdata = discdata;
1046 }
1047
1048 return rc;
1049}
1050
1051static void
1052tape_34xx_cleanup_device(struct tape_device *device)
1053{
1054 tape_std_unassign(device);
1055
1056 if (device->discdata) {
1057 tape_34xx_delete_sbid_from(device, 0);
1058 kfree(device->discdata);
1059 device->discdata = NULL;
1060 }
1061}
1062
1063
1064
1065
1066
1067static int
1068tape_34xx_mttell(struct tape_device *device, int mt_count)
1069{
1070 struct {
1071 struct tape_34xx_block_id cbid;
1072 struct tape_34xx_block_id dbid;
1073 } __attribute__ ((packed)) block_id;
1074 int rc;
1075
1076 rc = tape_std_read_block_id(device, (__u64 *) &block_id);
1077 if (rc)
1078 return rc;
1079
1080 tape_34xx_add_sbid(device, block_id.cbid);
1081 return block_id.cbid.block;
1082}
1083
1084
1085
1086
1087static int
1088tape_34xx_mtseek(struct tape_device *device, int mt_count)
1089{
1090 struct tape_request *request;
1091 struct tape_34xx_block_id * bid;
1092
1093 if (mt_count > 0x3fffff) {
1094 DBF_EXCEPTION(6, "xsee parm\n");
1095 return -EINVAL;
1096 }
1097 request = tape_alloc_request(3, 4);
1098 if (IS_ERR(request))
1099 return PTR_ERR(request);
1100
1101
1102 request->op = TO_LBL;
1103 bid = (struct tape_34xx_block_id *) request->cpdata;
1104 bid->format = (*device->modeset_byte & 0x08) ?
1105 TAPE34XX_FMT_3480_XF : TAPE34XX_FMT_3480;
1106 bid->block = mt_count;
1107 tape_34xx_merge_sbid(device, bid);
1108
1109 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
1110 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1111 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
1112
1113
1114 return tape_do_io_free(device, request);
1115}
1116
1117
1118
1119
1120static tape_mtop_fn tape_34xx_mtop[TAPE_NR_MTOPS] = {
1121 [MTRESET] = tape_std_mtreset,
1122 [MTFSF] = tape_std_mtfsf,
1123 [MTBSF] = tape_std_mtbsf,
1124 [MTFSR] = tape_std_mtfsr,
1125 [MTBSR] = tape_std_mtbsr,
1126 [MTWEOF] = tape_std_mtweof,
1127 [MTREW] = tape_std_mtrew,
1128 [MTOFFL] = tape_std_mtoffl,
1129 [MTNOP] = tape_std_mtnop,
1130 [MTRETEN] = tape_std_mtreten,
1131 [MTBSFM] = tape_std_mtbsfm,
1132 [MTFSFM] = tape_std_mtfsfm,
1133 [MTEOM] = tape_std_mteom,
1134 [MTERASE] = tape_std_mterase,
1135 [MTRAS1] = NULL,
1136 [MTRAS2] = NULL,
1137 [MTRAS3] = NULL,
1138 [MTSETBLK] = tape_std_mtsetblk,
1139 [MTSETDENSITY] = NULL,
1140 [MTSEEK] = tape_34xx_mtseek,
1141 [MTTELL] = tape_34xx_mttell,
1142 [MTSETDRVBUFFER] = NULL,
1143 [MTFSS] = NULL,
1144 [MTBSS] = NULL,
1145 [MTWSM] = NULL,
1146 [MTLOCK] = NULL,
1147 [MTUNLOCK] = NULL,
1148 [MTLOAD] = tape_std_mtload,
1149 [MTUNLOAD] = tape_std_mtunload,
1150 [MTCOMPRESSION] = tape_std_mtcompression,
1151 [MTSETPART] = NULL,
1152 [MTMKPART] = NULL
1153};
1154
1155
1156
1157
1158static struct tape_discipline tape_discipline_34xx = {
1159 .owner = THIS_MODULE,
1160 .setup_device = tape_34xx_setup_device,
1161 .cleanup_device = tape_34xx_cleanup_device,
1162 .process_eov = tape_std_process_eov,
1163 .irq = tape_34xx_irq,
1164 .read_block = tape_std_read_block,
1165 .write_block = tape_std_write_block,
1166 .ioctl_fn = tape_34xx_ioctl,
1167 .mtop_array = tape_34xx_mtop
1168};
1169
1170static struct ccw_device_id tape_34xx_ids[] = {
1171 { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), .driver_info = tape_3480},
1172 { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), .driver_info = tape_3490},
1173 { },
1174};
1175
1176static int
1177tape_34xx_online(struct ccw_device *cdev)
1178{
1179 return tape_generic_online(
1180 dev_get_drvdata(&cdev->dev),
1181 &tape_discipline_34xx
1182 );
1183}
1184
1185static struct ccw_driver tape_34xx_driver = {
1186 .driver = {
1187 .name = "tape_34xx",
1188 .owner = THIS_MODULE,
1189 },
1190 .ids = tape_34xx_ids,
1191 .probe = tape_generic_probe,
1192 .remove = tape_generic_remove,
1193 .set_online = tape_34xx_online,
1194 .set_offline = tape_generic_offline,
1195 .freeze = tape_generic_pm_suspend,
1196 .int_class = IRQIO_TAP,
1197};
1198
1199static int
1200tape_34xx_init (void)
1201{
1202 int rc;
1203
1204 TAPE_DBF_AREA = debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
1205 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1206#ifdef DBF_LIKE_HELL
1207 debug_set_level(TAPE_DBF_AREA, 6);
1208#endif
1209
1210 DBF_EVENT(3, "34xx init\n");
1211
1212 rc = ccw_driver_register(&tape_34xx_driver);
1213 if (rc)
1214 DBF_EVENT(3, "34xx init failed\n");
1215 else
1216 DBF_EVENT(3, "34xx registered\n");
1217 return rc;
1218}
1219
1220static void
1221tape_34xx_exit(void)
1222{
1223 ccw_driver_unregister(&tape_34xx_driver);
1224
1225 debug_unregister(TAPE_DBF_AREA);
1226}
1227
1228MODULE_DEVICE_TABLE(ccw, tape_34xx_ids);
1229MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
1230MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape device driver");
1231MODULE_LICENSE("GPL");
1232
1233module_init(tape_34xx_init);
1234module_exit(tape_34xx_exit);
1235