Pull sem2mutex-ioc4 into release branch
[linux-2.6] / drivers / s390 / char / tape_34xx.c
1 /*
2  *  drivers/s390/char/tape_34xx.c
3  *    tape device discipline for 3480/3490 tapes.
4  *
5  *  S390 and zSeries version
6  *    Copyright (C) 2001,2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
7  *    Author(s): Carsten Otte <cotte@de.ibm.com>
8  *               Tuan Ngo-Anh <ngoanh@de.ibm.com>
9  *               Martin Schwidefsky <schwidefsky@de.ibm.com>
10  */
11
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/bio.h>
16 #include <linux/workqueue.h>
17
18 #define TAPE_DBF_AREA   tape_34xx_dbf
19
20 #include "tape.h"
21 #include "tape_std.h"
22
23 #define PRINTK_HEADER "TAPE_34XX: "
24
25 /*
26  * Pointer to debug area.
27  */
28 debug_info_t *TAPE_DBF_AREA = NULL;
29 EXPORT_SYMBOL(TAPE_DBF_AREA);
30
31 enum tape_34xx_type {
32         tape_3480,
33         tape_3490,
34 };
35
36 #define TAPE34XX_FMT_3480       0
37 #define TAPE34XX_FMT_3480_2_XF  1
38 #define TAPE34XX_FMT_3480_XF    2
39
40 struct tape_34xx_block_id {
41         unsigned int    wrap            : 1;
42         unsigned int    segment         : 7;
43         unsigned int    format          : 2;
44         unsigned int    block           : 22;
45 };
46
47 /*
48  * A list of block ID's is used to faster seek blocks.
49  */
50 struct tape_34xx_sbid {
51         struct list_head                list;
52         struct tape_34xx_block_id       bid;
53 };
54
55 static void tape_34xx_delete_sbid_from(struct tape_device *, int);
56
57 /*
58  * Medium sense for 34xx tapes. There is no 'real' medium sense call.
59  * So we just do a normal sense.
60  */
61 static int
62 tape_34xx_medium_sense(struct tape_device *device)
63 {
64         struct tape_request *request;
65         unsigned char       *sense;
66         int                  rc;
67
68         request = tape_alloc_request(1, 32);
69         if (IS_ERR(request)) {
70                 DBF_EXCEPTION(6, "MSEN fail\n");
71                 return PTR_ERR(request);
72         }
73
74         request->op = TO_MSEN;
75         tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata);
76
77         rc = tape_do_io_interruptible(device, request);
78         if (request->rc == 0) {
79                 sense = request->cpdata;
80
81                 /*
82                  * This isn't quite correct. But since INTERVENTION_REQUIRED
83                  * means that the drive is 'neither ready nor on-line' it is
84                  * only slightly inaccurate to say there is no tape loaded if
85                  * the drive isn't online...
86                  */
87                 if (sense[0] & SENSE_INTERVENTION_REQUIRED)
88                         tape_med_state_set(device, MS_UNLOADED);
89                 else
90                         tape_med_state_set(device, MS_LOADED);
91
92                 if (sense[1] & SENSE_WRITE_PROTECT)
93                         device->tape_generic_status |= GMT_WR_PROT(~0);
94                 else
95                         device->tape_generic_status &= ~GMT_WR_PROT(~0);
96         } else {
97                 DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
98                         request->rc);
99         }
100         tape_free_request(request);
101
102         return rc;
103 }
104
105 /*
106  * These functions are currently used only to schedule a medium_sense for
107  * later execution. This is because we get an interrupt whenever a medium
108  * is inserted but cannot call tape_do_io* from an interrupt context.
109  * Maybe that's useful for other actions we want to start from the
110  * interrupt handler.
111  */
112 static void
113 tape_34xx_work_handler(void *data)
114 {
115         struct {
116                 struct tape_device      *device;
117                 enum tape_op             op;
118                 struct work_struct       work;
119         } *p = data;
120
121         switch(p->op) {
122                 case TO_MSEN:
123                         tape_34xx_medium_sense(p->device);
124                         break;
125                 default:
126                         DBF_EVENT(3, "T34XX: internal error: unknown work\n");
127         }
128
129         p->device = tape_put_device(p->device);
130         kfree(p);
131 }
132
133 static int
134 tape_34xx_schedule_work(struct tape_device *device, enum tape_op op)
135 {
136         struct {
137                 struct tape_device      *device;
138                 enum tape_op             op;
139                 struct work_struct       work;
140         } *p;
141
142         if ((p = kmalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
143                 return -ENOMEM;
144
145         memset(p, 0, sizeof(*p));
146         INIT_WORK(&p->work, tape_34xx_work_handler, p);
147
148         p->device = tape_get_device_reference(device);
149         p->op     = op;
150
151         schedule_work(&p->work);
152         return 0;
153 }
154
155 /*
156  * Done Handler is called when dev stat = DEVICE-END (successful operation)
157  */
158 static inline int
159 tape_34xx_done(struct tape_request *request)
160 {
161         DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
162
163         switch (request->op) {
164                 case TO_DSE:
165                 case TO_RUN:
166                 case TO_WRI:
167                 case TO_WTM:
168                 case TO_ASSIGN:
169                 case TO_UNASSIGN:
170                         tape_34xx_delete_sbid_from(request->device, 0);
171                         break;
172                 default:
173                         ;
174         }
175         return TAPE_IO_SUCCESS;
176 }
177
178 static inline int
179 tape_34xx_erp_failed(struct tape_request *request, int rc)
180 {
181         DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
182                   tape_op_verbose[request->op], rc);
183         return rc;
184 }
185
186 static inline int
187 tape_34xx_erp_succeeded(struct tape_request *request)
188 {
189         DBF_EVENT(3, "Error Recovery successful for %s\n",
190                   tape_op_verbose[request->op]);
191         return tape_34xx_done(request);
192 }
193
194 static inline int
195 tape_34xx_erp_retry(struct tape_request *request)
196 {
197         DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose[request->op]);
198         return TAPE_IO_RETRY;
199 }
200
201 /*
202  * This function is called, when no request is outstanding and we get an
203  * interrupt
204  */
205 static int
206 tape_34xx_unsolicited_irq(struct tape_device *device, struct irb *irb)
207 {
208         if (irb->scsw.dstat == 0x85 /* READY */) {
209                 /* A medium was inserted in the drive. */
210                 DBF_EVENT(6, "xuud med\n");
211                 tape_34xx_delete_sbid_from(device, 0);
212                 tape_34xx_schedule_work(device, TO_MSEN);
213         } else {
214                 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
215                 PRINT_WARN("Unsolicited IRQ (Device End) caught.\n");
216                 tape_dump_sense(device, NULL, irb);
217         }
218         return TAPE_IO_SUCCESS;
219 }
220
221 /*
222  * Read Opposite Error Recovery Function:
223  * Used, when Read Forward does not work
224  */
225 static int
226 tape_34xx_erp_read_opposite(struct tape_device *device,
227                             struct tape_request *request)
228 {
229         if (request->op == TO_RFO) {
230                 /*
231                  * We did read forward, but the data could not be read
232                  * *correctly*. We transform the request to a read backward
233                  * and try again.
234                  */
235                 tape_std_read_backward(device, request);
236                 return tape_34xx_erp_retry(request);
237         }
238         if (request->op != TO_RBA)
239                 PRINT_ERR("read_opposite called with state:%s\n",
240                           tape_op_verbose[request->op]);
241         /*
242          * We tried to read forward and backward, but hat no
243          * success -> failed.
244          */
245         return tape_34xx_erp_failed(request, -EIO);
246 }
247
248 static int
249 tape_34xx_erp_bug(struct tape_device *device, struct tape_request *request,
250                   struct irb *irb, int no)
251 {
252         if (request->op != TO_ASSIGN) {
253                 PRINT_WARN("An unexpected condition #%d was caught in "
254                            "tape error recovery.\n", no);
255                 PRINT_WARN("Please report this incident.\n");
256                 if (request)
257                         PRINT_WARN("Operation of tape:%s\n",
258                                    tape_op_verbose[request->op]);
259                 tape_dump_sense(device, request, irb);
260         }
261         return tape_34xx_erp_failed(request, -EIO);
262 }
263
264 /*
265  * Handle data overrun between cu and drive. The channel speed might
266  * be too slow.
267  */
268 static int
269 tape_34xx_erp_overrun(struct tape_device *device, struct tape_request *request,
270                       struct irb *irb)
271 {
272         if (irb->ecw[3] == 0x40) {
273                 PRINT_WARN ("Data overrun error between control-unit "
274                             "and drive. Use a faster channel connection, "
275                             "if possible! \n");
276                 return tape_34xx_erp_failed(request, -EIO);
277         }
278         return tape_34xx_erp_bug(device, request, irb, -1);
279 }
280
281 /*
282  * Handle record sequence error.
283  */
284 static int
285 tape_34xx_erp_sequence(struct tape_device *device,
286                        struct tape_request *request, struct irb *irb)
287 {
288         if (irb->ecw[3] == 0x41) {
289                 /*
290                  * cu detected incorrect block-id sequence on tape.
291                  */
292                 PRINT_WARN("Illegal block-id sequence found!\n");
293                 return tape_34xx_erp_failed(request, -EIO);
294         }
295         /*
296          * Record sequence error bit is set, but erpa does not
297          * show record sequence error.
298          */
299         return tape_34xx_erp_bug(device, request, irb, -2);
300 }
301
302 /*
303  * This function analyses the tape's sense-data in case of a unit-check.
304  * If possible, it tries to recover from the error. Else the user is
305  * informed about the problem.
306  */
307 static int
308 tape_34xx_unit_check(struct tape_device *device, struct tape_request *request,
309                      struct irb *irb)
310 {
311         int inhibit_cu_recovery;
312         __u8* sense;
313
314         inhibit_cu_recovery = (*device->modeset_byte & 0x80) ? 1 : 0;
315         sense = irb->ecw;
316
317 #ifdef CONFIG_S390_TAPE_BLOCK
318         if (request->op == TO_BLOCK) {
319                 /*
320                  * Recovery for block device requests. Set the block_position
321                  * to something invalid and retry.
322                  */
323                 device->blk_data.block_position = -1;
324                 if (request->retries-- <= 0)
325                         return tape_34xx_erp_failed(request, -EIO);
326                 else
327                         return tape_34xx_erp_retry(request);
328         }
329 #endif
330
331         if (
332                 sense[0] & SENSE_COMMAND_REJECT &&
333                 sense[1] & SENSE_WRITE_PROTECT
334         ) {
335                 if (
336                         request->op == TO_DSE ||
337                         request->op == TO_WRI ||
338                         request->op == TO_WTM
339                 ) {
340                         /* medium is write protected */
341                         return tape_34xx_erp_failed(request, -EACCES);
342                 } else {
343                         return tape_34xx_erp_bug(device, request, irb, -3);
344                 }
345         }
346
347         /*
348          * Special cases for various tape-states when reaching
349          * end of recorded area
350          *
351          * FIXME: Maybe a special case of the special case:
352          *        sense[0] == SENSE_EQUIPMENT_CHECK &&
353          *        sense[1] == SENSE_DRIVE_ONLINE    &&
354          *        sense[3] == 0x47 (Volume Fenced)
355          *
356          *        This was caused by continued FSF or FSR after an
357          *        'End Of Data'.
358          */
359         if ((
360                 sense[0] == SENSE_DATA_CHECK      ||
361                 sense[0] == SENSE_EQUIPMENT_CHECK ||
362                 sense[0] == SENSE_EQUIPMENT_CHECK + SENSE_DEFERRED_UNIT_CHECK
363         ) && (
364                 sense[1] == SENSE_DRIVE_ONLINE ||
365                 sense[1] == SENSE_BEGINNING_OF_TAPE + SENSE_WRITE_MODE
366         )) {
367                 switch (request->op) {
368                 /*
369                  * sense[0] == SENSE_DATA_CHECK   &&
370                  * sense[1] == SENSE_DRIVE_ONLINE
371                  * sense[3] == 0x36 (End Of Data)
372                  *
373                  * Further seeks might return a 'Volume Fenced'.
374                  */
375                 case TO_FSF:
376                 case TO_FSB:
377                         /* Trying to seek beyond end of recorded area */
378                         return tape_34xx_erp_failed(request, -ENOSPC);
379                 case TO_BSB:
380                         return tape_34xx_erp_retry(request);
381
382                 /*
383                  * sense[0] == SENSE_DATA_CHECK   &&
384                  * sense[1] == SENSE_DRIVE_ONLINE &&
385                  * sense[3] == 0x36 (End Of Data)
386                  */
387                 case TO_LBL:
388                         /* Block could not be located. */
389                         tape_34xx_delete_sbid_from(device, 0);
390                         return tape_34xx_erp_failed(request, -EIO);
391
392                 case TO_RFO:
393                         /* Read beyond end of recorded area -> 0 bytes read */
394                         return tape_34xx_erp_failed(request, 0);
395
396                 /*
397                  * sense[0] == SENSE_EQUIPMENT_CHECK &&
398                  * sense[1] == SENSE_DRIVE_ONLINE    &&
399                  * sense[3] == 0x38 (Physical End Of Volume)
400                  */
401                 case TO_WRI:
402                         /* Writing at physical end of volume */
403                         return tape_34xx_erp_failed(request, -ENOSPC);
404                 default:
405                         PRINT_ERR("Invalid op in %s:%i\n",
406                                   __FUNCTION__, __LINE__);
407                         return tape_34xx_erp_failed(request, 0);
408                 }
409         }
410
411         /* Sensing special bits */
412         if (sense[0] & SENSE_BUS_OUT_CHECK)
413                 return tape_34xx_erp_retry(request);
414
415         if (sense[0] & SENSE_DATA_CHECK) {
416                 /*
417                  * hardware failure, damaged tape or improper
418                  * operating conditions
419                  */
420                 switch (sense[3]) {
421                 case 0x23:
422                         /* a read data check occurred */
423                         if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
424                             inhibit_cu_recovery)
425                                 // data check is not permanent, may be
426                                 // recovered. We always use async-mode with
427                                 // cu-recovery, so this should *never* happen.
428                                 return tape_34xx_erp_bug(device, request,
429                                                          irb, -4);
430
431                         /* data check is permanent, CU recovery has failed */
432                         PRINT_WARN("Permanent read error\n");
433                         return tape_34xx_erp_failed(request, -EIO);
434                 case 0x25:
435                         // a write data check occurred
436                         if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
437                             inhibit_cu_recovery)
438                                 // data check is not permanent, may be
439                                 // recovered. We always use async-mode with
440                                 // cu-recovery, so this should *never* happen.
441                                 return tape_34xx_erp_bug(device, request,
442                                                          irb, -5);
443
444                         // data check is permanent, cu-recovery has failed
445                         PRINT_WARN("Permanent write error\n");
446                         return tape_34xx_erp_failed(request, -EIO);
447                 case 0x26:
448                         /* Data Check (read opposite) occurred. */
449                         return tape_34xx_erp_read_opposite(device, request);
450                 case 0x28:
451                         /* ID-Mark at tape start couldn't be written */
452                         PRINT_WARN("ID-Mark could not be written.\n");
453                         return tape_34xx_erp_failed(request, -EIO);
454                 case 0x31:
455                         /* Tape void. Tried to read beyond end of device. */
456                         PRINT_WARN("Read beyond end of recorded area.\n");
457                         return tape_34xx_erp_failed(request, -ENOSPC);
458                 case 0x41:
459                         /* Record sequence error. */
460                         PRINT_WARN("Invalid block-id sequence found.\n");
461                         return tape_34xx_erp_failed(request, -EIO);
462                 default:
463                         /* all data checks for 3480 should result in one of
464                          * the above erpa-codes. For 3490, other data-check
465                          * conditions do exist. */
466                         if (device->cdev->id.driver_info == tape_3480)
467                                 return tape_34xx_erp_bug(device, request,
468                                                          irb, -6);
469                 }
470         }
471
472         if (sense[0] & SENSE_OVERRUN)
473                 return tape_34xx_erp_overrun(device, request, irb);
474
475         if (sense[1] & SENSE_RECORD_SEQUENCE_ERR)
476                 return tape_34xx_erp_sequence(device, request, irb);
477
478         /* Sensing erpa codes */
479         switch (sense[3]) {
480         case 0x00:
481                 /* Unit check with erpa code 0. Report and ignore. */
482                 PRINT_WARN("Non-error sense was found. "
483                            "Unit-check will be ignored.\n");
484                 return TAPE_IO_SUCCESS;
485         case 0x21:
486                 /*
487                  * Data streaming not operational. CU will switch to
488                  * interlock mode. Reissue the command.
489                  */
490                 PRINT_WARN("Data streaming not operational. "
491                            "Switching to interlock-mode.\n");
492                 return tape_34xx_erp_retry(request);
493         case 0x22:
494                 /*
495                  * Path equipment check. Might be drive adapter error, buffer
496                  * error on the lower interface, internal path not usable,
497                  * or error during cartridge load.
498                  */
499                 PRINT_WARN("A path equipment check occurred. One of the "
500                            "following conditions occurred:\n");
501                 PRINT_WARN("drive adapter error, buffer error on the lower "
502                            "interface, internal path not usable, error "
503                            "during cartridge load.\n");
504                 return tape_34xx_erp_failed(request, -EIO);
505         case 0x24:
506                 /*
507                  * Load display check. Load display was command was issued,
508                  * but the drive is displaying a drive check message. Can
509                  * be threated as "device end".
510                  */
511                 return tape_34xx_erp_succeeded(request);
512         case 0x27:
513                 /*
514                  * Command reject. May indicate illegal channel program or
515                  * buffer over/underrun. Since all channel programs are
516                  * issued by this driver and ought be correct, we assume a
517                  * over/underrun situation and retry the channel program.
518                  */
519                 return tape_34xx_erp_retry(request);
520         case 0x29:
521                 /*
522                  * Function incompatible. Either the tape is idrc compressed
523                  * but the hardware isn't capable to do idrc, or a perform
524                  * subsystem func is issued and the CU is not on-line.
525                  */
526                 PRINT_WARN ("Function incompatible. Try to switch off idrc\n");
527                 return tape_34xx_erp_failed(request, -EIO);
528         case 0x2a:
529                 /*
530                  * Unsolicited environmental data. An internal counter
531                  * overflows, we can ignore this and reissue the cmd.
532                  */
533                 return tape_34xx_erp_retry(request);
534         case 0x2b:
535                 /*
536                  * Environmental data present. Indicates either unload
537                  * completed ok or read buffered log command completed ok.
538                  */
539                 if (request->op == TO_RUN) {
540                         /* Rewind unload completed ok. */
541                         tape_med_state_set(device, MS_UNLOADED);
542                         return tape_34xx_erp_succeeded(request);
543                 }
544                 /* tape_34xx doesn't use read buffered log commands. */
545                 return tape_34xx_erp_bug(device, request, irb, sense[3]);
546         case 0x2c:
547                 /*
548                  * Permanent equipment check. CU has tried recovery, but
549                  * did not succeed.
550                  */
551                 return tape_34xx_erp_failed(request, -EIO);
552         case 0x2d:
553                 /* Data security erase failure. */
554                 if (request->op == TO_DSE)
555                         return tape_34xx_erp_failed(request, -EIO);
556                 /* Data security erase failure, but no such command issued. */
557                 return tape_34xx_erp_bug(device, request, irb, sense[3]);
558         case 0x2e:
559                 /*
560                  * Not capable. This indicates either that the drive fails
561                  * reading the format id mark or that that format specified
562                  * is not supported by the drive.
563                  */
564                 PRINT_WARN("Drive not capable processing the tape format!\n");
565                 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
566         case 0x30:
567                 /* The medium is write protected. */
568                 PRINT_WARN("Medium is write protected!\n");
569                 return tape_34xx_erp_failed(request, -EACCES);
570         case 0x32:
571                 // Tension loss. We cannot recover this, it's an I/O error.
572                 PRINT_WARN("The drive lost tape tension.\n");
573                 return tape_34xx_erp_failed(request, -EIO);
574         case 0x33:
575                 /*
576                  * Load Failure. The cartridge was not inserted correctly or
577                  * the tape is not threaded correctly.
578                  */
579                 PRINT_WARN("Cartridge load failure. Reload the cartridge "
580                            "and try again.\n");
581                 tape_34xx_delete_sbid_from(device, 0);
582                 return tape_34xx_erp_failed(request, -EIO);
583         case 0x34:
584                 /*
585                  * Unload failure. The drive cannot maintain tape tension
586                  * and control tape movement during an unload operation.
587                  */
588                 PRINT_WARN("Failure during cartridge unload. "
589                            "Please try manually.\n");
590                 if (request->op == TO_RUN)
591                         return tape_34xx_erp_failed(request, -EIO);
592                 return tape_34xx_erp_bug(device, request, irb, sense[3]);
593         case 0x35:
594                 /*
595                  * Drive equipment check. One of the following:
596                  * - cu cannot recover from a drive detected error
597                  * - a check code message is shown on drive display
598                  * - the cartridge loader does not respond correctly
599                  * - a failure occurs during an index, load, or unload cycle
600                  */
601                 PRINT_WARN("Equipment check! Please check the drive and "
602                            "the cartridge loader.\n");
603                 return tape_34xx_erp_failed(request, -EIO);
604         case 0x36:
605                 if (device->cdev->id.driver_info == tape_3490)
606                         /* End of data. */
607                         return tape_34xx_erp_failed(request, -EIO);
608                 /* This erpa is reserved for 3480 */
609                 return tape_34xx_erp_bug(device, request, irb, sense[3]);
610         case 0x37:
611                 /*
612                  * Tape length error. The tape is shorter than reported in
613                  * the beginning-of-tape data.
614                  */
615                 PRINT_WARN("Tape length error.\n");
616                 return tape_34xx_erp_failed(request, -EIO);
617         case 0x38:
618                 /*
619                  * Physical end of tape. A read/write operation reached
620                  * the physical end of tape.
621                  */
622                 if (request->op==TO_WRI ||
623                     request->op==TO_DSE ||
624                     request->op==TO_WTM)
625                         return tape_34xx_erp_failed(request, -ENOSPC);
626                 return tape_34xx_erp_failed(request, -EIO);
627         case 0x39:
628                 /* Backward at Beginning of tape. */
629                 return tape_34xx_erp_failed(request, -EIO);
630         case 0x3a:
631                 /* Drive switched to not ready. */
632                 PRINT_WARN("Drive not ready. Turn the ready/not ready switch "
633                            "to ready position and try again.\n");
634                 return tape_34xx_erp_failed(request, -EIO);
635         case 0x3b:
636                 /* Manual rewind or unload. This causes an I/O error. */
637                 PRINT_WARN("Medium was rewound or unloaded manually.\n");
638                 tape_34xx_delete_sbid_from(device, 0);
639                 return tape_34xx_erp_failed(request, -EIO);
640         case 0x42:
641                 /*
642                  * Degraded mode. A condition that can cause degraded
643                  * performance is detected.
644                  */
645                 PRINT_WARN("Subsystem is running in degraded mode.\n");
646                 return tape_34xx_erp_retry(request);
647         case 0x43:
648                 /* Drive not ready. */
649                 tape_34xx_delete_sbid_from(device, 0);
650                 tape_med_state_set(device, MS_UNLOADED);
651                 /* Some commands commands are successful even in this case */
652                 if (sense[1] & SENSE_DRIVE_ONLINE) {
653                         switch(request->op) {
654                                 case TO_ASSIGN:
655                                 case TO_UNASSIGN:
656                                 case TO_DIS:
657                                 case TO_NOP:
658                                         return tape_34xx_done(request);
659                                         break;
660                                 default:
661                                         break;
662                         }
663                 }
664                 PRINT_WARN("The drive is not ready.\n");
665                 return tape_34xx_erp_failed(request, -ENOMEDIUM);
666         case 0x44:
667                 /* Locate Block unsuccessful. */
668                 if (request->op != TO_BLOCK && request->op != TO_LBL)
669                         /* No locate block was issued. */
670                         return tape_34xx_erp_bug(device, request,
671                                                  irb, sense[3]);
672                 return tape_34xx_erp_failed(request, -EIO);
673         case 0x45:
674                 /* The drive is assigned to a different channel path. */
675                 PRINT_WARN("The drive is assigned elsewhere.\n");
676                 return tape_34xx_erp_failed(request, -EIO);
677         case 0x46:
678                 /*
679                  * Drive not on-line. Drive may be switched offline,
680                  * the power supply may be switched off or
681                  * the drive address may not be set correctly.
682                  */
683                 PRINT_WARN("The drive is not on-line.");
684                 return tape_34xx_erp_failed(request, -EIO);
685         case 0x47:
686                 /* Volume fenced. CU reports volume integrity is lost. */
687                 PRINT_WARN("Volume fenced. The volume integrity is lost.\n");
688                 tape_34xx_delete_sbid_from(device, 0);
689                 return tape_34xx_erp_failed(request, -EIO);
690         case 0x48:
691                 /* Log sense data and retry request. */
692                 return tape_34xx_erp_retry(request);
693         case 0x49:
694                 /* Bus out check. A parity check error on the bus was found. */
695                 PRINT_WARN("Bus out check. A data transfer over the bus "
696                            "has been corrupted.\n");
697                 return tape_34xx_erp_failed(request, -EIO);
698         case 0x4a:
699                 /* Control unit erp failed. */
700                 PRINT_WARN("The control unit I/O error recovery failed.\n");
701                 return tape_34xx_erp_failed(request, -EIO);
702         case 0x4b:
703                 /*
704                  * CU and drive incompatible. The drive requests micro-program
705                  * patches, which are not available on the CU.
706                  */
707                 PRINT_WARN("The drive needs microprogram patches from the "
708                            "control unit, which are not available.\n");
709                 return tape_34xx_erp_failed(request, -EIO);
710         case 0x4c:
711                 /*
712                  * Recovered Check-One failure. Cu develops a hardware error,
713                  * but is able to recover.
714                  */
715                 return tape_34xx_erp_retry(request);
716         case 0x4d:
717                 if (device->cdev->id.driver_info == tape_3490)
718                         /*
719                          * Resetting event received. Since the driver does
720                          * not support resetting event recovery (which has to
721                          * be handled by the I/O Layer), retry our command.
722                          */
723                         return tape_34xx_erp_retry(request);
724                 /* This erpa is reserved for 3480. */
725                 return tape_34xx_erp_bug(device, request, irb, sense[3]);
726         case 0x4e:
727                 if (device->cdev->id.driver_info == tape_3490) {
728                         /*
729                          * Maximum block size exceeded. This indicates, that
730                          * the block to be written is larger than allowed for
731                          * buffered mode.
732                          */
733                         PRINT_WARN("Maximum block size for buffered "
734                                    "mode exceeded.\n");
735                         return tape_34xx_erp_failed(request, -ENOBUFS);
736                 }
737                 /* This erpa is reserved for 3480. */
738                 return tape_34xx_erp_bug(device, request, irb, sense[3]);
739         case 0x50:
740                 /*
741                  * Read buffered log (Overflow). CU is running in extended
742                  * buffered log mode, and a counter overflows. This should
743                  * never happen, since we're never running in extended
744                  * buffered log mode.
745                  */
746                 return tape_34xx_erp_retry(request);
747         case 0x51:
748                 /*
749                  * Read buffered log (EOV). EOF processing occurs while the
750                  * CU is in extended buffered log mode. This should never
751                  * happen, since we're never running in extended buffered
752                  * log mode.
753                  */
754                 return tape_34xx_erp_retry(request);
755         case 0x52:
756                 /* End of Volume complete. Rewind unload completed ok. */
757                 if (request->op == TO_RUN) {
758                         tape_med_state_set(device, MS_UNLOADED);
759                         tape_34xx_delete_sbid_from(device, 0);
760                         return tape_34xx_erp_succeeded(request);
761                 }
762                 return tape_34xx_erp_bug(device, request, irb, sense[3]);
763         case 0x53:
764                 /* Global command intercept. */
765                 return tape_34xx_erp_retry(request);
766         case 0x54:
767                 /* Channel interface recovery (temporary). */
768                 return tape_34xx_erp_retry(request);
769         case 0x55:
770                 /* Channel interface recovery (permanent). */
771                 PRINT_WARN("A permanent channel interface error occurred.\n");
772                 return tape_34xx_erp_failed(request, -EIO);
773         case 0x56:
774                 /* Channel protocol error. */
775                 PRINT_WARN("A channel protocol error occurred.\n");
776                 return tape_34xx_erp_failed(request, -EIO);
777         case 0x57:
778                 if (device->cdev->id.driver_info == tape_3480) {
779                         /* Attention intercept. */
780                         PRINT_WARN("An attention intercept occurred, "
781                                    "which will be recovered.\n");
782                         return tape_34xx_erp_retry(request);
783                 } else {
784                         /* Global status intercept. */
785                         PRINT_WARN("An global status intercept was received, "
786                                    "which will be recovered.\n");
787                         return tape_34xx_erp_retry(request);
788                 }
789         case 0x5a:
790                 /*
791                  * Tape length incompatible. The tape inserted is too long,
792                  * which could cause damage to the tape or the drive.
793                  */
794                 PRINT_WARN("Tape Length Incompatible\n");
795                 PRINT_WARN("Tape length exceeds IBM enhanced capacity "
796                         "cartdridge length or a medium\n");
797                 PRINT_WARN("with EC-CST identification mark has been mounted "
798                         "in a device that writes\n");
799                 PRINT_WARN("3480 or 3480 XF format.\n");
800                 return tape_34xx_erp_failed(request, -EIO);
801         case 0x5b:
802                 /* Format 3480 XF incompatible */
803                 if (sense[1] & SENSE_BEGINNING_OF_TAPE)
804                         /* The tape will get overwritten. */
805                         return tape_34xx_erp_retry(request);
806                 PRINT_WARN("Format 3480 XF Incompatible\n");
807                 PRINT_WARN("Medium has been created in 3480 format. "
808                         "To change the format writes\n");
809                 PRINT_WARN("must be issued at BOT.\n");
810                 return tape_34xx_erp_failed(request, -EIO);
811         case 0x5c:
812                 /* Format 3480-2 XF incompatible */
813                 PRINT_WARN("Format 3480-2 XF Incompatible\n");
814                 PRINT_WARN("Device can only read 3480 or 3480 XF format.\n");
815                 return tape_34xx_erp_failed(request, -EIO);
816         case 0x5d:
817                 /* Tape length violation. */
818                 PRINT_WARN("Tape Length Violation\n");
819                 PRINT_WARN("The mounted tape exceeds IBM Enhanced Capacity "
820                         "Cartdridge System Tape length.\n");
821                 PRINT_WARN("This may cause damage to the drive or tape when "
822                         "processing to the EOV\n");
823                 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
824         case 0x5e:
825                 /* Compaction algorithm incompatible. */
826                 PRINT_WARN("Compaction Algorithm Incompatible\n");
827                 PRINT_WARN("The volume is recorded using an incompatible "
828                         "compaction algorithm,\n");
829                 PRINT_WARN("which is not supported by the device.\n");
830                 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
831
832                 /* The following erpas should have been covered earlier. */
833         case 0x23: /* Read data check. */
834         case 0x25: /* Write data check. */
835         case 0x26: /* Data check (read opposite). */
836         case 0x28: /* Write id mark check. */
837         case 0x31: /* Tape void. */
838         case 0x40: /* Overrun error. */
839         case 0x41: /* Record sequence error. */
840                 /* All other erpas are reserved for future use. */
841         default:
842                 return tape_34xx_erp_bug(device, request, irb, sense[3]);
843         }
844 }
845
846 /*
847  * 3480/3490 interrupt handler
848  */
849 static int
850 tape_34xx_irq(struct tape_device *device, struct tape_request *request,
851               struct irb *irb)
852 {
853         if (request == NULL)
854                 return tape_34xx_unsolicited_irq(device, irb);
855
856         if ((irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) &&
857             (irb->scsw.dstat & DEV_STAT_DEV_END) &&
858             (request->op == TO_WRI)) {
859                 /* Write at end of volume */
860                 PRINT_INFO("End of volume\n"); /* XXX */
861                 return tape_34xx_erp_failed(request, -ENOSPC);
862         }
863
864         if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
865                 return tape_34xx_unit_check(device, request, irb);
866
867         if (irb->scsw.dstat & DEV_STAT_DEV_END) {
868                 /*
869                  * A unit exception occurs on skipping over a tapemark block.
870                  */
871                 if (irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) {
872                         if (request->op == TO_BSB || request->op == TO_FSB)
873                                 request->rescnt++;
874                         else
875                                 DBF_EVENT(5, "Unit Exception!\n");
876                 }
877                 return tape_34xx_done(request);
878         }
879
880         DBF_EVENT(6, "xunknownirq\n");
881         PRINT_ERR("Unexpected interrupt.\n");
882         PRINT_ERR("Current op is: %s", tape_op_verbose[request->op]);
883         tape_dump_sense(device, request, irb);
884         return TAPE_IO_STOP;
885 }
886
887 /*
888  * ioctl_overload
889  */
890 static int
891 tape_34xx_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
892 {
893         if (cmd == TAPE390_DISPLAY) {
894                 struct display_struct disp;
895
896                 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)) != 0)
897                         return -EFAULT;
898
899                 return tape_std_display(device, &disp);
900         } else
901                 return -EINVAL;
902 }
903
904 static inline void
905 tape_34xx_append_new_sbid(struct tape_34xx_block_id bid, struct list_head *l)
906 {
907         struct tape_34xx_sbid * new_sbid;
908
909         new_sbid = kmalloc(sizeof(*new_sbid), GFP_ATOMIC);
910         if (!new_sbid)
911                 return;
912
913         new_sbid->bid = bid;
914         list_add(&new_sbid->list, l);
915 }
916
917 /*
918  * Build up the search block ID list. The block ID consists of a logical
919  * block number and a hardware specific part. The hardware specific part
920  * helps the tape drive to speed up searching for a specific block.
921  */
922 static void
923 tape_34xx_add_sbid(struct tape_device *device, struct tape_34xx_block_id bid)
924 {
925         struct list_head *      sbid_list;
926         struct tape_34xx_sbid * sbid;
927         struct list_head *      l;
928
929         /*
930          * immediately return if there is no list at all or the block to add
931          * is located in segment 1 of wrap 0 because this position is used
932          * if no hardware position data is supplied.
933          */
934         sbid_list = (struct list_head *) device->discdata;
935         if (!sbid_list || (bid.segment < 2 && bid.wrap == 0))
936                 return;
937
938         /*
939          * Search the position where to insert the new entry. Hardware
940          * acceleration uses only the segment and wrap number. So we
941          * need only one entry for a specific wrap/segment combination.
942          * If there is a block with a lower number but the same hard-
943          * ware position data we just update the block number in the
944          * existing entry.
945          */
946         list_for_each(l, sbid_list) {
947                 sbid = list_entry(l, struct tape_34xx_sbid, list);
948
949                 if (
950                         (sbid->bid.segment == bid.segment) &&
951                         (sbid->bid.wrap    == bid.wrap)
952                 ) {
953                         if (bid.block < sbid->bid.block)
954                                 sbid->bid = bid;
955                         else return;
956                         break;
957                 }
958
959                 /* Sort in according to logical block number. */
960                 if (bid.block < sbid->bid.block) {
961                         tape_34xx_append_new_sbid(bid, l->prev);
962                         break;
963                 }
964         }
965         /* List empty or new block bigger than last entry. */
966         if (l == sbid_list)
967                 tape_34xx_append_new_sbid(bid, l->prev);
968
969         DBF_LH(4, "Current list is:\n");
970         list_for_each(l, sbid_list) {
971                 sbid = list_entry(l, struct tape_34xx_sbid, list);
972                 DBF_LH(4, "%d:%03d@%05d\n",
973                         sbid->bid.wrap,
974                         sbid->bid.segment,
975                         sbid->bid.block
976                 );
977         }
978 }
979
980 /*
981  * Delete all entries from the search block ID list that belong to tape blocks
982  * equal or higher than the given number.
983  */
984 static void
985 tape_34xx_delete_sbid_from(struct tape_device *device, int from)
986 {
987         struct list_head *      sbid_list;
988         struct tape_34xx_sbid * sbid;
989         struct list_head *      l;
990         struct list_head *      n;
991
992         sbid_list = (struct list_head *) device->discdata;
993         if (!sbid_list)
994                 return;
995
996         list_for_each_safe(l, n, sbid_list) {
997                 sbid = list_entry(l, struct tape_34xx_sbid, list);
998                 if (sbid->bid.block >= from) {
999                         DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
1000                                 sbid->bid.wrap,
1001                                 sbid->bid.segment,
1002                                 sbid->bid.block
1003                         );
1004                         list_del(l);
1005                         kfree(sbid);
1006                 }
1007         }
1008 }
1009
1010 /*
1011  * Merge hardware position data into a block id.
1012  */
1013 static void
1014 tape_34xx_merge_sbid(
1015         struct tape_device *            device,
1016         struct tape_34xx_block_id *     bid
1017 ) {
1018         struct tape_34xx_sbid * sbid;
1019         struct tape_34xx_sbid * sbid_to_use;
1020         struct list_head *      sbid_list;
1021         struct list_head *      l;
1022
1023         sbid_list = (struct list_head *) device->discdata;
1024         bid->wrap    = 0;
1025         bid->segment = 1;
1026
1027         if (!sbid_list || list_empty(sbid_list))
1028                 return;
1029
1030         sbid_to_use = NULL;
1031         list_for_each(l, sbid_list) {
1032                 sbid = list_entry(l, struct tape_34xx_sbid, list);
1033
1034                 if (sbid->bid.block >= bid->block)
1035                         break;
1036                 sbid_to_use = sbid;
1037         }
1038         if (sbid_to_use) {
1039                 bid->wrap    = sbid_to_use->bid.wrap;
1040                 bid->segment = sbid_to_use->bid.segment;
1041                 DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
1042                         sbid_to_use->bid.wrap,
1043                         sbid_to_use->bid.segment,
1044                         sbid_to_use->bid.block,
1045                         bid->block
1046                 );
1047         }
1048 }
1049
1050 static int
1051 tape_34xx_setup_device(struct tape_device * device)
1052 {
1053         int                     rc;
1054         struct list_head *      discdata;
1055
1056         DBF_EVENT(6, "34xx device setup\n");
1057         if ((rc = tape_std_assign(device)) == 0) {
1058                 if ((rc = tape_34xx_medium_sense(device)) != 0) {
1059                         DBF_LH(3, "34xx medium sense returned %d\n", rc);
1060                 }
1061         }
1062         discdata = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1063         if (discdata) {
1064                         INIT_LIST_HEAD(discdata);
1065                         device->discdata = discdata;
1066         }
1067
1068         return rc;
1069 }
1070
1071 static void
1072 tape_34xx_cleanup_device(struct tape_device *device)
1073 {
1074         tape_std_unassign(device);
1075         
1076         if (device->discdata) {
1077                 tape_34xx_delete_sbid_from(device, 0);
1078                 kfree(device->discdata);
1079                 device->discdata = NULL;
1080         }
1081 }
1082
1083
1084 /*
1085  * MTTELL: Tell block. Return the number of block relative to current file.
1086  */
1087 static int
1088 tape_34xx_mttell(struct tape_device *device, int mt_count)
1089 {
1090         struct {
1091                 struct tape_34xx_block_id       cbid;
1092                 struct tape_34xx_block_id       dbid;
1093         } __attribute__ ((packed)) block_id;
1094         int rc;
1095
1096         rc = tape_std_read_block_id(device, (__u64 *) &block_id);
1097         if (rc)
1098                 return rc;
1099
1100         tape_34xx_add_sbid(device, block_id.cbid);
1101         return block_id.cbid.block;
1102 }
1103
1104 /*
1105  * MTSEEK: seek to the specified block.
1106  */
1107 static int
1108 tape_34xx_mtseek(struct tape_device *device, int mt_count)
1109 {
1110         struct tape_request *request;
1111         struct tape_34xx_block_id *     bid;
1112
1113         if (mt_count > 0x3fffff) {
1114                 DBF_EXCEPTION(6, "xsee parm\n");
1115                 return -EINVAL;
1116         }
1117         request = tape_alloc_request(3, 4);
1118         if (IS_ERR(request))
1119                 return PTR_ERR(request);
1120
1121         /* setup ccws */
1122         request->op = TO_LBL;
1123         bid         = (struct tape_34xx_block_id *) request->cpdata;
1124         bid->format = (*device->modeset_byte & 0x08) ?
1125                         TAPE34XX_FMT_3480_XF : TAPE34XX_FMT_3480;
1126         bid->block  = mt_count;
1127         tape_34xx_merge_sbid(device, bid);
1128
1129         tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
1130         tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1131         tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
1132
1133         /* execute it */
1134         return tape_do_io_free(device, request);
1135 }
1136
1137 #ifdef CONFIG_S390_TAPE_BLOCK
1138 /*
1139  * Tape block read for 34xx.
1140  */
1141 static struct tape_request *
1142 tape_34xx_bread(struct tape_device *device, struct request *req)
1143 {
1144         struct tape_request *request;
1145         struct ccw1 *ccw;
1146         int count = 0, i;
1147         unsigned off;
1148         char *dst;
1149         struct bio_vec *bv;
1150         struct bio *bio;
1151         struct tape_34xx_block_id *     start_block;
1152
1153         DBF_EVENT(6, "xBREDid:");
1154
1155         /* Count the number of blocks for the request. */
1156         rq_for_each_bio(bio, req) {
1157                 bio_for_each_segment(bv, bio, i) {
1158                         count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
1159                 }
1160         }
1161
1162         /* Allocate the ccw request. */
1163         request = tape_alloc_request(3+count+1, 8);
1164         if (IS_ERR(request))
1165                 return request;
1166
1167         /* Setup ccws. */
1168         request->op = TO_BLOCK;
1169         start_block = (struct tape_34xx_block_id *) request->cpdata;
1170         start_block->block = req->sector >> TAPEBLOCK_HSEC_S2B;
1171         DBF_EVENT(6, "start_block = %i\n", start_block->block);
1172
1173         ccw = request->cpaddr;
1174         ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);
1175
1176         /*
1177          * We always setup a nop after the mode set ccw. This slot is
1178          * used in tape_std_check_locate to insert a locate ccw if the
1179          * current tape position doesn't match the start block to be read.
1180          * The second nop will be filled with a read block id which is in
1181          * turn used by tape_34xx_free_bread to populate the segment bid
1182          * table.
1183          */
1184         ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
1185         ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
1186
1187         rq_for_each_bio(bio, req) {
1188                 bio_for_each_segment(bv, bio, i) {
1189                         dst = kmap(bv->bv_page) + bv->bv_offset;
1190                         for (off = 0; off < bv->bv_len;
1191                              off += TAPEBLOCK_HSEC_SIZE) {
1192                                 ccw->flags = CCW_FLAG_CC;
1193                                 ccw->cmd_code = READ_FORWARD;
1194                                 ccw->count = TAPEBLOCK_HSEC_SIZE;
1195                                 set_normalized_cda(ccw, (void*) __pa(dst));
1196                                 ccw++;
1197                                 dst += TAPEBLOCK_HSEC_SIZE;
1198                         }
1199                 }
1200         }
1201
1202         ccw = tape_ccw_end(ccw, NOP, 0, NULL);
1203         DBF_EVENT(6, "xBREDccwg\n");
1204         return request;
1205 }
1206
1207 static void
1208 tape_34xx_free_bread (struct tape_request *request)
1209 {
1210         struct ccw1* ccw;
1211
1212         ccw = request->cpaddr;
1213         if ((ccw + 2)->cmd_code == READ_BLOCK_ID) {
1214                 struct {
1215                         struct tape_34xx_block_id       cbid;
1216                         struct tape_34xx_block_id       dbid;
1217                 } __attribute__ ((packed)) *rbi_data;
1218
1219                 rbi_data = request->cpdata;
1220
1221                 if (request->device)
1222                         tape_34xx_add_sbid(request->device, rbi_data->cbid);
1223         }
1224
1225         /* Last ccw is a nop and doesn't need clear_normalized_cda */
1226         for (; ccw->flags & CCW_FLAG_CC; ccw++)
1227                 if (ccw->cmd_code == READ_FORWARD)
1228                         clear_normalized_cda(ccw);
1229         tape_free_request(request);
1230 }
1231
1232 /*
1233  * check_locate is called just before the tape request is passed to
1234  * the common io layer for execution. It has to check the current
1235  * tape position and insert a locate ccw if it doesn't match the
1236  * start block for the request.
1237  */
1238 static void
1239 tape_34xx_check_locate(struct tape_device *device, struct tape_request *request)
1240 {
1241         struct tape_34xx_block_id *     start_block;
1242
1243         start_block = (struct tape_34xx_block_id *) request->cpdata;
1244         if (start_block->block == device->blk_data.block_position)
1245                 return;
1246
1247         DBF_LH(4, "Block seek(%06d+%06d)\n", start_block->block, device->bof);
1248         start_block->wrap    = 0;
1249         start_block->segment = 1;
1250         start_block->format  = (*device->modeset_byte & 0x08) ?
1251                                 TAPE34XX_FMT_3480_XF :
1252                                 TAPE34XX_FMT_3480;
1253         start_block->block   = start_block->block + device->bof;
1254         tape_34xx_merge_sbid(device, start_block);
1255         tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1256         tape_ccw_cc(request->cpaddr + 2, READ_BLOCK_ID, 8, request->cpdata);
1257 }
1258 #endif
1259
1260 /*
1261  * List of 3480/3490 magnetic tape commands.
1262  */
1263 static tape_mtop_fn tape_34xx_mtop[TAPE_NR_MTOPS] = {
1264         [MTRESET]        = tape_std_mtreset,
1265         [MTFSF]          = tape_std_mtfsf,
1266         [MTBSF]          = tape_std_mtbsf,
1267         [MTFSR]          = tape_std_mtfsr,
1268         [MTBSR]          = tape_std_mtbsr,
1269         [MTWEOF]         = tape_std_mtweof,
1270         [MTREW]          = tape_std_mtrew,
1271         [MTOFFL]         = tape_std_mtoffl,
1272         [MTNOP]          = tape_std_mtnop,
1273         [MTRETEN]        = tape_std_mtreten,
1274         [MTBSFM]         = tape_std_mtbsfm,
1275         [MTFSFM]         = tape_std_mtfsfm,
1276         [MTEOM]          = tape_std_mteom,
1277         [MTERASE]        = tape_std_mterase,
1278         [MTRAS1]         = NULL,
1279         [MTRAS2]         = NULL,
1280         [MTRAS3]         = NULL,
1281         [MTSETBLK]       = tape_std_mtsetblk,
1282         [MTSETDENSITY]   = NULL,
1283         [MTSEEK]         = tape_34xx_mtseek,
1284         [MTTELL]         = tape_34xx_mttell,
1285         [MTSETDRVBUFFER] = NULL,
1286         [MTFSS]          = NULL,
1287         [MTBSS]          = NULL,
1288         [MTWSM]          = NULL,
1289         [MTLOCK]         = NULL,
1290         [MTUNLOCK]       = NULL,
1291         [MTLOAD]         = tape_std_mtload,
1292         [MTUNLOAD]       = tape_std_mtunload,
1293         [MTCOMPRESSION]  = tape_std_mtcompression,
1294         [MTSETPART]      = NULL,
1295         [MTMKPART]       = NULL
1296 };
1297
1298 /*
1299  * Tape discipline structure for 3480 and 3490.
1300  */
1301 static struct tape_discipline tape_discipline_34xx = {
1302         .owner = THIS_MODULE,
1303         .setup_device = tape_34xx_setup_device,
1304         .cleanup_device = tape_34xx_cleanup_device,
1305         .process_eov = tape_std_process_eov,
1306         .irq = tape_34xx_irq,
1307         .read_block = tape_std_read_block,
1308         .write_block = tape_std_write_block,
1309 #ifdef CONFIG_S390_TAPE_BLOCK
1310         .bread = tape_34xx_bread,
1311         .free_bread = tape_34xx_free_bread,
1312         .check_locate = tape_34xx_check_locate,
1313 #endif
1314         .ioctl_fn = tape_34xx_ioctl,
1315         .mtop_array = tape_34xx_mtop
1316 };
1317
1318 static struct ccw_device_id tape_34xx_ids[] = {
1319         { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), driver_info: tape_3480},
1320         { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), driver_info: tape_3490},
1321         { /* end of list */ }
1322 };
1323
1324 static int
1325 tape_34xx_online(struct ccw_device *cdev)
1326 {
1327         return tape_generic_online(
1328                 cdev->dev.driver_data,
1329                 &tape_discipline_34xx
1330         );
1331 }
1332
1333 static int
1334 tape_34xx_offline(struct ccw_device *cdev)
1335 {
1336         return tape_generic_offline(cdev->dev.driver_data);
1337 }
1338
1339 static struct ccw_driver tape_34xx_driver = {
1340         .name = "tape_34xx",
1341         .owner = THIS_MODULE,
1342         .ids = tape_34xx_ids,
1343         .probe = tape_generic_probe,
1344         .remove = tape_generic_remove,
1345         .set_online = tape_34xx_online,
1346         .set_offline = tape_34xx_offline,
1347 };
1348
1349 static int
1350 tape_34xx_init (void)
1351 {
1352         int rc;
1353
1354         TAPE_DBF_AREA = debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
1355         debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1356 #ifdef DBF_LIKE_HELL
1357         debug_set_level(TAPE_DBF_AREA, 6);
1358 #endif
1359
1360         DBF_EVENT(3, "34xx init\n");
1361         /* Register driver for 3480/3490 tapes. */
1362         rc = ccw_driver_register(&tape_34xx_driver);
1363         if (rc)
1364                 DBF_EVENT(3, "34xx init failed\n");
1365         else
1366                 DBF_EVENT(3, "34xx registered\n");
1367         return rc;
1368 }
1369
1370 static void
1371 tape_34xx_exit(void)
1372 {
1373         ccw_driver_unregister(&tape_34xx_driver);
1374
1375         debug_unregister(TAPE_DBF_AREA);
1376 }
1377
1378 MODULE_DEVICE_TABLE(ccw, tape_34xx_ids);
1379 MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
1380 MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape device driver");
1381 MODULE_LICENSE("GPL");
1382
1383 module_init(tape_34xx_init);
1384 module_exit(tape_34xx_exit);