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