0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #define KMSG_COMPONENT "tape_34xx"
0012 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
0013
0014 #include <linux/module.h>
0015 #include <linux/init.h>
0016 #include <linux/bio.h>
0017 #include <linux/workqueue.h>
0018 #include <linux/slab.h>
0019
0020 #define TAPE_DBF_AREA tape_34xx_dbf
0021
0022 #include "tape.h"
0023 #include "tape_std.h"
0024
0025
0026
0027
0028 debug_info_t *TAPE_DBF_AREA = NULL;
0029 EXPORT_SYMBOL(TAPE_DBF_AREA);
0030
0031 #define TAPE34XX_FMT_3480 0
0032 #define TAPE34XX_FMT_3480_2_XF 1
0033 #define TAPE34XX_FMT_3480_XF 2
0034
0035 struct tape_34xx_block_id {
0036 unsigned int wrap : 1;
0037 unsigned int segment : 7;
0038 unsigned int format : 2;
0039 unsigned int block : 22;
0040 };
0041
0042
0043
0044
0045 struct tape_34xx_sbid {
0046 struct list_head list;
0047 struct tape_34xx_block_id bid;
0048 };
0049
0050 static void tape_34xx_delete_sbid_from(struct tape_device *, int);
0051
0052
0053
0054
0055
0056 static void __tape_34xx_medium_sense(struct tape_request *request)
0057 {
0058 struct tape_device *device = request->device;
0059 unsigned char *sense;
0060
0061 if (request->rc == 0) {
0062 sense = request->cpdata;
0063
0064
0065
0066
0067
0068
0069
0070 if (sense[0] & SENSE_INTERVENTION_REQUIRED)
0071 tape_med_state_set(device, MS_UNLOADED);
0072 else
0073 tape_med_state_set(device, MS_LOADED);
0074
0075 if (sense[1] & SENSE_WRITE_PROTECT)
0076 device->tape_generic_status |= GMT_WR_PROT(~0);
0077 else
0078 device->tape_generic_status &= ~GMT_WR_PROT(~0);
0079 } else
0080 DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
0081 request->rc);
0082 tape_free_request(request);
0083 }
0084
0085 static int tape_34xx_medium_sense(struct tape_device *device)
0086 {
0087 struct tape_request *request;
0088 int rc;
0089
0090 request = tape_alloc_request(1, 32);
0091 if (IS_ERR(request)) {
0092 DBF_EXCEPTION(6, "MSEN fail\n");
0093 return PTR_ERR(request);
0094 }
0095
0096 request->op = TO_MSEN;
0097 tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata);
0098 rc = tape_do_io_interruptible(device, request);
0099 __tape_34xx_medium_sense(request);
0100 return rc;
0101 }
0102
0103 static void tape_34xx_medium_sense_async(struct tape_device *device)
0104 {
0105 struct tape_request *request;
0106
0107 request = tape_alloc_request(1, 32);
0108 if (IS_ERR(request)) {
0109 DBF_EXCEPTION(6, "MSEN fail\n");
0110 return;
0111 }
0112
0113 request->op = TO_MSEN;
0114 tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata);
0115 request->callback = (void *) __tape_34xx_medium_sense;
0116 request->callback_data = NULL;
0117 tape_do_io_async(device, request);
0118 }
0119
0120 struct tape_34xx_work {
0121 struct tape_device *device;
0122 enum tape_op op;
0123 struct work_struct work;
0124 };
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136 static void
0137 tape_34xx_work_handler(struct work_struct *work)
0138 {
0139 struct tape_34xx_work *p =
0140 container_of(work, struct tape_34xx_work, work);
0141 struct tape_device *device = p->device;
0142
0143 switch(p->op) {
0144 case TO_MSEN:
0145 tape_34xx_medium_sense_async(device);
0146 break;
0147 default:
0148 DBF_EVENT(3, "T34XX: internal error: unknown work\n");
0149 }
0150 tape_put_device(device);
0151 kfree(p);
0152 }
0153
0154 static int
0155 tape_34xx_schedule_work(struct tape_device *device, enum tape_op op)
0156 {
0157 struct tape_34xx_work *p;
0158
0159 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
0160 return -ENOMEM;
0161
0162 INIT_WORK(&p->work, tape_34xx_work_handler);
0163
0164 p->device = tape_get_device(device);
0165 p->op = op;
0166
0167 schedule_work(&p->work);
0168 return 0;
0169 }
0170
0171
0172
0173
0174 static inline int
0175 tape_34xx_done(struct tape_request *request)
0176 {
0177 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
0178
0179 switch (request->op) {
0180 case TO_DSE:
0181 case TO_RUN:
0182 case TO_WRI:
0183 case TO_WTM:
0184 case TO_ASSIGN:
0185 case TO_UNASSIGN:
0186 tape_34xx_delete_sbid_from(request->device, 0);
0187 break;
0188 default:
0189 ;
0190 }
0191 return TAPE_IO_SUCCESS;
0192 }
0193
0194 static inline int
0195 tape_34xx_erp_failed(struct tape_request *request, int rc)
0196 {
0197 DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
0198 tape_op_verbose[request->op], rc);
0199 return rc;
0200 }
0201
0202 static inline int
0203 tape_34xx_erp_succeeded(struct tape_request *request)
0204 {
0205 DBF_EVENT(3, "Error Recovery successful for %s\n",
0206 tape_op_verbose[request->op]);
0207 return tape_34xx_done(request);
0208 }
0209
0210 static inline int
0211 tape_34xx_erp_retry(struct tape_request *request)
0212 {
0213 DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose[request->op]);
0214 return TAPE_IO_RETRY;
0215 }
0216
0217
0218
0219
0220
0221 static int
0222 tape_34xx_unsolicited_irq(struct tape_device *device, struct irb *irb)
0223 {
0224 if (irb->scsw.cmd.dstat == 0x85) {
0225
0226 DBF_EVENT(6, "xuud med\n");
0227 tape_34xx_delete_sbid_from(device, 0);
0228 tape_34xx_schedule_work(device, TO_MSEN);
0229 } else {
0230 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
0231 tape_dump_sense_dbf(device, NULL, irb);
0232 }
0233 return TAPE_IO_SUCCESS;
0234 }
0235
0236
0237
0238
0239
0240 static int
0241 tape_34xx_erp_read_opposite(struct tape_device *device,
0242 struct tape_request *request)
0243 {
0244 if (request->op == TO_RFO) {
0245
0246
0247
0248
0249
0250 tape_std_read_backward(device, request);
0251 return tape_34xx_erp_retry(request);
0252 }
0253
0254
0255
0256
0257
0258 return tape_34xx_erp_failed(request, -EIO);
0259 }
0260
0261 static int
0262 tape_34xx_erp_bug(struct tape_device *device, struct tape_request *request,
0263 struct irb *irb, int no)
0264 {
0265 if (request->op != TO_ASSIGN) {
0266 dev_err(&device->cdev->dev, "An unexpected condition %d "
0267 "occurred in tape error recovery\n", no);
0268 tape_dump_sense_dbf(device, request, irb);
0269 }
0270 return tape_34xx_erp_failed(request, -EIO);
0271 }
0272
0273
0274
0275
0276
0277 static int
0278 tape_34xx_erp_overrun(struct tape_device *device, struct tape_request *request,
0279 struct irb *irb)
0280 {
0281 if (irb->ecw[3] == 0x40) {
0282 dev_warn (&device->cdev->dev, "A data overrun occurred between"
0283 " the control unit and tape unit\n");
0284 return tape_34xx_erp_failed(request, -EIO);
0285 }
0286 return tape_34xx_erp_bug(device, request, irb, -1);
0287 }
0288
0289
0290
0291
0292 static int
0293 tape_34xx_erp_sequence(struct tape_device *device,
0294 struct tape_request *request, struct irb *irb)
0295 {
0296 if (irb->ecw[3] == 0x41) {
0297
0298
0299
0300 dev_warn (&device->cdev->dev, "The block ID sequence on the "
0301 "tape is incorrect\n");
0302 return tape_34xx_erp_failed(request, -EIO);
0303 }
0304
0305
0306
0307
0308 return tape_34xx_erp_bug(device, request, irb, -2);
0309 }
0310
0311
0312
0313
0314
0315
0316 static int
0317 tape_34xx_unit_check(struct tape_device *device, struct tape_request *request,
0318 struct irb *irb)
0319 {
0320 int inhibit_cu_recovery;
0321 __u8* sense;
0322
0323 inhibit_cu_recovery = (*device->modeset_byte & 0x80) ? 1 : 0;
0324 sense = irb->ecw;
0325
0326 if (
0327 sense[0] & SENSE_COMMAND_REJECT &&
0328 sense[1] & SENSE_WRITE_PROTECT
0329 ) {
0330 if (
0331 request->op == TO_DSE ||
0332 request->op == TO_WRI ||
0333 request->op == TO_WTM
0334 ) {
0335
0336 return tape_34xx_erp_failed(request, -EACCES);
0337 } else {
0338 return tape_34xx_erp_bug(device, request, irb, -3);
0339 }
0340 }
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354 if ((
0355 sense[0] == SENSE_DATA_CHECK ||
0356 sense[0] == SENSE_EQUIPMENT_CHECK ||
0357 sense[0] == (SENSE_EQUIPMENT_CHECK | SENSE_DEFERRED_UNIT_CHECK)
0358 ) && (
0359 sense[1] == SENSE_DRIVE_ONLINE ||
0360 sense[1] == (SENSE_BEGINNING_OF_TAPE | SENSE_WRITE_MODE)
0361 )) {
0362 switch (request->op) {
0363
0364
0365
0366
0367
0368
0369
0370 case TO_FSF:
0371 case TO_FSB:
0372
0373 return tape_34xx_erp_failed(request, -ENOSPC);
0374 case TO_BSB:
0375 return tape_34xx_erp_retry(request);
0376
0377
0378
0379
0380
0381
0382 case TO_LBL:
0383
0384 tape_34xx_delete_sbid_from(device, 0);
0385 return tape_34xx_erp_failed(request, -EIO);
0386
0387 case TO_RFO:
0388
0389 return tape_34xx_erp_failed(request, 0);
0390
0391
0392
0393
0394
0395
0396 case TO_WRI:
0397
0398 return tape_34xx_erp_failed(request, -ENOSPC);
0399 default:
0400 return tape_34xx_erp_failed(request, 0);
0401 }
0402 }
0403
0404
0405 if (sense[0] & SENSE_BUS_OUT_CHECK)
0406 return tape_34xx_erp_retry(request);
0407
0408 if (sense[0] & SENSE_DATA_CHECK) {
0409
0410
0411
0412
0413 switch (sense[3]) {
0414 case 0x23:
0415
0416 if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
0417 inhibit_cu_recovery)
0418
0419
0420
0421 return tape_34xx_erp_bug(device, request,
0422 irb, -4);
0423
0424
0425 dev_warn (&device->cdev->dev, "A read error occurred "
0426 "that cannot be recovered\n");
0427 return tape_34xx_erp_failed(request, -EIO);
0428 case 0x25:
0429
0430 if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
0431 inhibit_cu_recovery)
0432
0433
0434
0435 return tape_34xx_erp_bug(device, request,
0436 irb, -5);
0437
0438
0439 dev_warn (&device->cdev->dev, "A write error on the "
0440 "tape cannot be recovered\n");
0441 return tape_34xx_erp_failed(request, -EIO);
0442 case 0x26:
0443
0444 return tape_34xx_erp_read_opposite(device, request);
0445 case 0x28:
0446
0447 dev_warn (&device->cdev->dev, "Writing the ID-mark "
0448 "failed\n");
0449 return tape_34xx_erp_failed(request, -EIO);
0450 case 0x31:
0451
0452 dev_warn (&device->cdev->dev, "Reading the tape beyond"
0453 " the end of the recorded area failed\n");
0454 return tape_34xx_erp_failed(request, -ENOSPC);
0455 case 0x41:
0456
0457 dev_warn (&device->cdev->dev, "The tape contains an "
0458 "incorrect block ID sequence\n");
0459 return tape_34xx_erp_failed(request, -EIO);
0460 default:
0461
0462
0463
0464 if (device->cdev->id.driver_info == tape_3480)
0465 return tape_34xx_erp_bug(device, request,
0466 irb, -6);
0467 }
0468 }
0469
0470 if (sense[0] & SENSE_OVERRUN)
0471 return tape_34xx_erp_overrun(device, request, irb);
0472
0473 if (sense[1] & SENSE_RECORD_SEQUENCE_ERR)
0474 return tape_34xx_erp_sequence(device, request, irb);
0475
0476
0477 switch (sense[3]) {
0478 case 0x00:
0479
0480 return TAPE_IO_SUCCESS;
0481 case 0x21:
0482
0483
0484
0485
0486 return tape_34xx_erp_retry(request);
0487 case 0x22:
0488
0489
0490
0491
0492
0493 dev_warn (&device->cdev->dev, "A path equipment check occurred"
0494 " for the tape device\n");
0495 return tape_34xx_erp_failed(request, -EIO);
0496 case 0x24:
0497
0498
0499
0500
0501
0502 return tape_34xx_erp_succeeded(request);
0503 case 0x27:
0504
0505
0506
0507
0508
0509
0510 return tape_34xx_erp_retry(request);
0511 case 0x29:
0512
0513
0514
0515
0516
0517 return tape_34xx_erp_failed(request, -EIO);
0518 case 0x2a:
0519
0520
0521
0522
0523 return tape_34xx_erp_retry(request);
0524 case 0x2b:
0525
0526
0527
0528
0529 if (request->op == TO_RUN) {
0530
0531 tape_med_state_set(device, MS_UNLOADED);
0532 return tape_34xx_erp_succeeded(request);
0533 }
0534
0535 return tape_34xx_erp_bug(device, request, irb, sense[3]);
0536 case 0x2c:
0537
0538
0539
0540
0541 return tape_34xx_erp_failed(request, -EIO);
0542 case 0x2d:
0543
0544 if (request->op == TO_DSE)
0545 return tape_34xx_erp_failed(request, -EIO);
0546
0547 return tape_34xx_erp_bug(device, request, irb, sense[3]);
0548 case 0x2e:
0549
0550
0551
0552
0553
0554 dev_warn (&device->cdev->dev, "The tape unit cannot process "
0555 "the tape format\n");
0556 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
0557 case 0x30:
0558
0559 dev_warn (&device->cdev->dev, "The tape medium is write-"
0560 "protected\n");
0561 return tape_34xx_erp_failed(request, -EACCES);
0562 case 0x32:
0563
0564 dev_warn (&device->cdev->dev, "The tape does not have the "
0565 "required tape tension\n");
0566 return tape_34xx_erp_failed(request, -EIO);
0567 case 0x33:
0568
0569
0570
0571
0572 dev_warn (&device->cdev->dev, "The tape unit failed to load"
0573 " the cartridge\n");
0574 tape_34xx_delete_sbid_from(device, 0);
0575 return tape_34xx_erp_failed(request, -EIO);
0576 case 0x34:
0577
0578
0579
0580
0581 dev_warn (&device->cdev->dev, "Automatic unloading of the tape"
0582 " cartridge failed\n");
0583 if (request->op == TO_RUN)
0584 return tape_34xx_erp_failed(request, -EIO);
0585 return tape_34xx_erp_bug(device, request, irb, sense[3]);
0586 case 0x35:
0587
0588
0589
0590
0591
0592
0593
0594 dev_warn (&device->cdev->dev, "An equipment check has occurred"
0595 " on the tape unit\n");
0596 return tape_34xx_erp_failed(request, -EIO);
0597 case 0x36:
0598 if (device->cdev->id.driver_info == tape_3490)
0599
0600 return tape_34xx_erp_failed(request, -EIO);
0601
0602 return tape_34xx_erp_bug(device, request, irb, sense[3]);
0603 case 0x37:
0604
0605
0606
0607
0608 dev_warn (&device->cdev->dev, "The tape information states an"
0609 " incorrect length\n");
0610 return tape_34xx_erp_failed(request, -EIO);
0611 case 0x38:
0612
0613
0614
0615
0616 if (request->op==TO_WRI ||
0617 request->op==TO_DSE ||
0618 request->op==TO_WTM)
0619 return tape_34xx_erp_failed(request, -ENOSPC);
0620 return tape_34xx_erp_failed(request, -EIO);
0621 case 0x39:
0622
0623 return tape_34xx_erp_failed(request, -EIO);
0624 case 0x3a:
0625
0626 dev_warn (&device->cdev->dev, "The tape unit is not ready\n");
0627 return tape_34xx_erp_failed(request, -EIO);
0628 case 0x3b:
0629
0630 dev_warn (&device->cdev->dev, "The tape medium has been "
0631 "rewound or unloaded manually\n");
0632 tape_34xx_delete_sbid_from(device, 0);
0633 return tape_34xx_erp_failed(request, -EIO);
0634 case 0x42:
0635
0636
0637
0638
0639 dev_warn (&device->cdev->dev, "The tape subsystem is running "
0640 "in degraded mode\n");
0641 return tape_34xx_erp_retry(request);
0642 case 0x43:
0643
0644 tape_34xx_delete_sbid_from(device, 0);
0645 tape_med_state_set(device, MS_UNLOADED);
0646
0647 if (sense[1] & SENSE_DRIVE_ONLINE) {
0648 switch(request->op) {
0649 case TO_ASSIGN:
0650 case TO_UNASSIGN:
0651 case TO_DIS:
0652 case TO_NOP:
0653 return tape_34xx_done(request);
0654 break;
0655 default:
0656 break;
0657 }
0658 }
0659 return tape_34xx_erp_failed(request, -ENOMEDIUM);
0660 case 0x44:
0661
0662 if (request->op != TO_BLOCK && request->op != TO_LBL)
0663
0664 return tape_34xx_erp_bug(device, request,
0665 irb, sense[3]);
0666 return tape_34xx_erp_failed(request, -EIO);
0667 case 0x45:
0668
0669 dev_warn (&device->cdev->dev, "The tape unit is already "
0670 "assigned\n");
0671 return tape_34xx_erp_failed(request, -EIO);
0672 case 0x46:
0673
0674
0675
0676
0677
0678 dev_warn (&device->cdev->dev, "The tape unit is not online\n");
0679 return tape_34xx_erp_failed(request, -EIO);
0680 case 0x47:
0681
0682 dev_warn (&device->cdev->dev, "The control unit has fenced "
0683 "access to the tape volume\n");
0684 tape_34xx_delete_sbid_from(device, 0);
0685 return tape_34xx_erp_failed(request, -EIO);
0686 case 0x48:
0687
0688 return tape_34xx_erp_retry(request);
0689 case 0x49:
0690
0691 dev_warn (&device->cdev->dev, "A parity error occurred on the "
0692 "tape bus\n");
0693 return tape_34xx_erp_failed(request, -EIO);
0694 case 0x4a:
0695
0696 dev_warn (&device->cdev->dev, "I/O error recovery failed on "
0697 "the tape control unit\n");
0698 return tape_34xx_erp_failed(request, -EIO);
0699 case 0x4b:
0700
0701
0702
0703
0704 dev_warn (&device->cdev->dev, "The tape unit requires a "
0705 "firmware update\n");
0706 return tape_34xx_erp_failed(request, -EIO);
0707 case 0x4c:
0708
0709
0710
0711
0712 return tape_34xx_erp_retry(request);
0713 case 0x4d:
0714 if (device->cdev->id.driver_info == tape_3490)
0715
0716
0717
0718
0719
0720 return tape_34xx_erp_retry(request);
0721
0722 return tape_34xx_erp_bug(device, request, irb, sense[3]);
0723 case 0x4e:
0724 if (device->cdev->id.driver_info == tape_3490) {
0725
0726
0727
0728
0729
0730 dev_warn (&device->cdev->dev, "The maximum block size"
0731 " for buffered mode is exceeded\n");
0732 return tape_34xx_erp_failed(request, -ENOBUFS);
0733 }
0734
0735 return tape_34xx_erp_bug(device, request, irb, sense[3]);
0736 case 0x50:
0737
0738
0739
0740
0741
0742
0743 return tape_34xx_erp_retry(request);
0744 case 0x51:
0745
0746
0747
0748
0749
0750
0751 return tape_34xx_erp_retry(request);
0752 case 0x52:
0753
0754 if (request->op == TO_RUN) {
0755 tape_med_state_set(device, MS_UNLOADED);
0756 tape_34xx_delete_sbid_from(device, 0);
0757 return tape_34xx_erp_succeeded(request);
0758 }
0759 return tape_34xx_erp_bug(device, request, irb, sense[3]);
0760 case 0x53:
0761
0762 return tape_34xx_erp_retry(request);
0763 case 0x54:
0764
0765 return tape_34xx_erp_retry(request);
0766 case 0x55:
0767
0768 dev_warn (&device->cdev->dev, "A channel interface error cannot be"
0769 " recovered\n");
0770 return tape_34xx_erp_failed(request, -EIO);
0771 case 0x56:
0772
0773 dev_warn (&device->cdev->dev, "A channel protocol error "
0774 "occurred\n");
0775 return tape_34xx_erp_failed(request, -EIO);
0776 case 0x57:
0777
0778
0779
0780
0781 return tape_34xx_erp_retry(request);
0782 case 0x5a:
0783
0784
0785
0786
0787 dev_warn (&device->cdev->dev, "The tape unit does not support "
0788 "the tape length\n");
0789 return tape_34xx_erp_failed(request, -EIO);
0790 case 0x5b:
0791
0792 if (sense[1] & SENSE_BEGINNING_OF_TAPE)
0793
0794 return tape_34xx_erp_retry(request);
0795 dev_warn (&device->cdev->dev, "The tape unit does not support"
0796 " format 3480 XF\n");
0797 return tape_34xx_erp_failed(request, -EIO);
0798 case 0x5c:
0799
0800 dev_warn (&device->cdev->dev, "The tape unit does not support tape "
0801 "format 3480-2 XF\n");
0802 return tape_34xx_erp_failed(request, -EIO);
0803 case 0x5d:
0804
0805 dev_warn (&device->cdev->dev, "The tape unit does not support"
0806 " the current tape length\n");
0807 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
0808 case 0x5e:
0809
0810 dev_warn (&device->cdev->dev, "The tape unit does not support"
0811 " the compaction algorithm\n");
0812 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
0813
0814
0815 case 0x23:
0816 case 0x25:
0817 case 0x26:
0818 case 0x28:
0819 case 0x31:
0820 case 0x40:
0821 case 0x41:
0822
0823 default:
0824 return tape_34xx_erp_bug(device, request, irb, sense[3]);
0825 }
0826 }
0827
0828
0829
0830
0831 static int
0832 tape_34xx_irq(struct tape_device *device, struct tape_request *request,
0833 struct irb *irb)
0834 {
0835 if (request == NULL)
0836 return tape_34xx_unsolicited_irq(device, irb);
0837
0838 if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
0839 (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
0840 (request->op == TO_WRI)) {
0841
0842 return tape_34xx_erp_failed(request, -ENOSPC);
0843 }
0844
0845 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
0846 return tape_34xx_unit_check(device, request, irb);
0847
0848 if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
0849
0850
0851
0852 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
0853 if (request->op == TO_BSB || request->op == TO_FSB)
0854 request->rescnt++;
0855 else
0856 DBF_EVENT(5, "Unit Exception!\n");
0857 }
0858 return tape_34xx_done(request);
0859 }
0860
0861 DBF_EVENT(6, "xunknownirq\n");
0862 tape_dump_sense_dbf(device, request, irb);
0863 return TAPE_IO_STOP;
0864 }
0865
0866
0867
0868
0869 static int
0870 tape_34xx_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
0871 {
0872 if (cmd == TAPE390_DISPLAY) {
0873 struct display_struct disp;
0874
0875 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)) != 0)
0876 return -EFAULT;
0877
0878 return tape_std_display(device, &disp);
0879 } else
0880 return -EINVAL;
0881 }
0882
0883 static inline void
0884 tape_34xx_append_new_sbid(struct tape_34xx_block_id bid, struct list_head *l)
0885 {
0886 struct tape_34xx_sbid * new_sbid;
0887
0888 new_sbid = kmalloc(sizeof(*new_sbid), GFP_ATOMIC);
0889 if (!new_sbid)
0890 return;
0891
0892 new_sbid->bid = bid;
0893 list_add(&new_sbid->list, l);
0894 }
0895
0896
0897
0898
0899
0900
0901 static void
0902 tape_34xx_add_sbid(struct tape_device *device, struct tape_34xx_block_id bid)
0903 {
0904 struct list_head * sbid_list;
0905 struct tape_34xx_sbid * sbid;
0906 struct list_head * l;
0907
0908
0909
0910
0911
0912
0913 sbid_list = (struct list_head *) device->discdata;
0914 if (!sbid_list || (bid.segment < 2 && bid.wrap == 0))
0915 return;
0916
0917
0918
0919
0920
0921
0922
0923
0924
0925 list_for_each(l, sbid_list) {
0926 sbid = list_entry(l, struct tape_34xx_sbid, list);
0927
0928 if (
0929 (sbid->bid.segment == bid.segment) &&
0930 (sbid->bid.wrap == bid.wrap)
0931 ) {
0932 if (bid.block < sbid->bid.block)
0933 sbid->bid = bid;
0934 else return;
0935 break;
0936 }
0937
0938
0939 if (bid.block < sbid->bid.block) {
0940 tape_34xx_append_new_sbid(bid, l->prev);
0941 break;
0942 }
0943 }
0944
0945 if (l == sbid_list)
0946 tape_34xx_append_new_sbid(bid, l->prev);
0947
0948 DBF_LH(4, "Current list is:\n");
0949 list_for_each(l, sbid_list) {
0950 sbid = list_entry(l, struct tape_34xx_sbid, list);
0951 DBF_LH(4, "%d:%03d@%05d\n",
0952 sbid->bid.wrap,
0953 sbid->bid.segment,
0954 sbid->bid.block
0955 );
0956 }
0957 }
0958
0959
0960
0961
0962
0963 static void
0964 tape_34xx_delete_sbid_from(struct tape_device *device, int from)
0965 {
0966 struct list_head * sbid_list;
0967 struct tape_34xx_sbid * sbid;
0968 struct list_head * l;
0969 struct list_head * n;
0970
0971 sbid_list = (struct list_head *) device->discdata;
0972 if (!sbid_list)
0973 return;
0974
0975 list_for_each_safe(l, n, sbid_list) {
0976 sbid = list_entry(l, struct tape_34xx_sbid, list);
0977 if (sbid->bid.block >= from) {
0978 DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
0979 sbid->bid.wrap,
0980 sbid->bid.segment,
0981 sbid->bid.block
0982 );
0983 list_del(l);
0984 kfree(sbid);
0985 }
0986 }
0987 }
0988
0989
0990
0991
0992 static void
0993 tape_34xx_merge_sbid(
0994 struct tape_device * device,
0995 struct tape_34xx_block_id * bid
0996 ) {
0997 struct tape_34xx_sbid * sbid;
0998 struct tape_34xx_sbid * sbid_to_use;
0999 struct list_head * sbid_list;
1000 struct list_head * l;
1001
1002 sbid_list = (struct list_head *) device->discdata;
1003 bid->wrap = 0;
1004 bid->segment = 1;
1005
1006 if (!sbid_list || list_empty(sbid_list))
1007 return;
1008
1009 sbid_to_use = NULL;
1010 list_for_each(l, sbid_list) {
1011 sbid = list_entry(l, struct tape_34xx_sbid, list);
1012
1013 if (sbid->bid.block >= bid->block)
1014 break;
1015 sbid_to_use = sbid;
1016 }
1017 if (sbid_to_use) {
1018 bid->wrap = sbid_to_use->bid.wrap;
1019 bid->segment = sbid_to_use->bid.segment;
1020 DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
1021 sbid_to_use->bid.wrap,
1022 sbid_to_use->bid.segment,
1023 sbid_to_use->bid.block,
1024 bid->block
1025 );
1026 }
1027 }
1028
1029 static int
1030 tape_34xx_setup_device(struct tape_device * device)
1031 {
1032 int rc;
1033 struct list_head * discdata;
1034
1035 DBF_EVENT(6, "34xx device setup\n");
1036 if ((rc = tape_std_assign(device)) == 0) {
1037 if ((rc = tape_34xx_medium_sense(device)) != 0) {
1038 DBF_LH(3, "34xx medium sense returned %d\n", rc);
1039 }
1040 }
1041 discdata = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1042 if (discdata) {
1043 INIT_LIST_HEAD(discdata);
1044 device->discdata = discdata;
1045 }
1046
1047 return rc;
1048 }
1049
1050 static void
1051 tape_34xx_cleanup_device(struct tape_device *device)
1052 {
1053 tape_std_unassign(device);
1054
1055 if (device->discdata) {
1056 tape_34xx_delete_sbid_from(device, 0);
1057 kfree(device->discdata);
1058 device->discdata = NULL;
1059 }
1060 }
1061
1062
1063
1064
1065
1066 static int
1067 tape_34xx_mttell(struct tape_device *device, int mt_count)
1068 {
1069 struct {
1070 struct tape_34xx_block_id cbid;
1071 struct tape_34xx_block_id dbid;
1072 } __attribute__ ((packed)) block_id;
1073 int rc;
1074
1075 rc = tape_std_read_block_id(device, (__u64 *) &block_id);
1076 if (rc)
1077 return rc;
1078
1079 tape_34xx_add_sbid(device, block_id.cbid);
1080 return block_id.cbid.block;
1081 }
1082
1083
1084
1085
1086 static int
1087 tape_34xx_mtseek(struct tape_device *device, int mt_count)
1088 {
1089 struct tape_request *request;
1090 struct tape_34xx_block_id * bid;
1091
1092 if (mt_count > 0x3fffff) {
1093 DBF_EXCEPTION(6, "xsee parm\n");
1094 return -EINVAL;
1095 }
1096 request = tape_alloc_request(3, 4);
1097 if (IS_ERR(request))
1098 return PTR_ERR(request);
1099
1100
1101 request->op = TO_LBL;
1102 bid = (struct tape_34xx_block_id *) request->cpdata;
1103 bid->format = (*device->modeset_byte & 0x08) ?
1104 TAPE34XX_FMT_3480_XF : TAPE34XX_FMT_3480;
1105 bid->block = mt_count;
1106 tape_34xx_merge_sbid(device, bid);
1107
1108 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
1109 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1110 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
1111
1112
1113 return tape_do_io_free(device, request);
1114 }
1115
1116
1117
1118
1119 static tape_mtop_fn tape_34xx_mtop[TAPE_NR_MTOPS] = {
1120 [MTRESET] = tape_std_mtreset,
1121 [MTFSF] = tape_std_mtfsf,
1122 [MTBSF] = tape_std_mtbsf,
1123 [MTFSR] = tape_std_mtfsr,
1124 [MTBSR] = tape_std_mtbsr,
1125 [MTWEOF] = tape_std_mtweof,
1126 [MTREW] = tape_std_mtrew,
1127 [MTOFFL] = tape_std_mtoffl,
1128 [MTNOP] = tape_std_mtnop,
1129 [MTRETEN] = tape_std_mtreten,
1130 [MTBSFM] = tape_std_mtbsfm,
1131 [MTFSFM] = tape_std_mtfsfm,
1132 [MTEOM] = tape_std_mteom,
1133 [MTERASE] = tape_std_mterase,
1134 [MTRAS1] = NULL,
1135 [MTRAS2] = NULL,
1136 [MTRAS3] = NULL,
1137 [MTSETBLK] = tape_std_mtsetblk,
1138 [MTSETDENSITY] = NULL,
1139 [MTSEEK] = tape_34xx_mtseek,
1140 [MTTELL] = tape_34xx_mttell,
1141 [MTSETDRVBUFFER] = NULL,
1142 [MTFSS] = NULL,
1143 [MTBSS] = NULL,
1144 [MTWSM] = NULL,
1145 [MTLOCK] = NULL,
1146 [MTUNLOCK] = NULL,
1147 [MTLOAD] = tape_std_mtload,
1148 [MTUNLOAD] = tape_std_mtunload,
1149 [MTCOMPRESSION] = tape_std_mtcompression,
1150 [MTSETPART] = NULL,
1151 [MTMKPART] = NULL
1152 };
1153
1154
1155
1156
1157 static struct tape_discipline tape_discipline_34xx = {
1158 .owner = THIS_MODULE,
1159 .setup_device = tape_34xx_setup_device,
1160 .cleanup_device = tape_34xx_cleanup_device,
1161 .process_eov = tape_std_process_eov,
1162 .irq = tape_34xx_irq,
1163 .read_block = tape_std_read_block,
1164 .write_block = tape_std_write_block,
1165 .ioctl_fn = tape_34xx_ioctl,
1166 .mtop_array = tape_34xx_mtop
1167 };
1168
1169 static struct ccw_device_id tape_34xx_ids[] = {
1170 { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), .driver_info = tape_3480},
1171 { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), .driver_info = tape_3490},
1172 { },
1173 };
1174
1175 static int
1176 tape_34xx_online(struct ccw_device *cdev)
1177 {
1178 return tape_generic_online(
1179 dev_get_drvdata(&cdev->dev),
1180 &tape_discipline_34xx
1181 );
1182 }
1183
1184 static struct ccw_driver tape_34xx_driver = {
1185 .driver = {
1186 .name = "tape_34xx",
1187 .owner = THIS_MODULE,
1188 },
1189 .ids = tape_34xx_ids,
1190 .probe = tape_generic_probe,
1191 .remove = tape_generic_remove,
1192 .set_online = tape_34xx_online,
1193 .set_offline = tape_generic_offline,
1194 .int_class = IRQIO_TAP,
1195 };
1196
1197 static int
1198 tape_34xx_init (void)
1199 {
1200 int rc;
1201
1202 TAPE_DBF_AREA = debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
1203 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1204 #ifdef DBF_LIKE_HELL
1205 debug_set_level(TAPE_DBF_AREA, 6);
1206 #endif
1207
1208 DBF_EVENT(3, "34xx init\n");
1209
1210 rc = ccw_driver_register(&tape_34xx_driver);
1211 if (rc)
1212 DBF_EVENT(3, "34xx init failed\n");
1213 else
1214 DBF_EVENT(3, "34xx registered\n");
1215 return rc;
1216 }
1217
1218 static void
1219 tape_34xx_exit(void)
1220 {
1221 ccw_driver_unregister(&tape_34xx_driver);
1222
1223 debug_unregister(TAPE_DBF_AREA);
1224 }
1225
1226 MODULE_DEVICE_TABLE(ccw, tape_34xx_ids);
1227 MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
1228 MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape device driver");
1229 MODULE_LICENSE("GPL");
1230
1231 module_init(tape_34xx_init);
1232 module_exit(tape_34xx_exit);