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