blob: b28de80b7ca48194c760e309b7e9db53c2045892 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/char/tape_34xx.c
3 * tape device discipline for 3480/3490 tapes.
4 *
Frank Munzert3ef32e622009-06-16 10:30:39 +02005 * Copyright IBM Corp. 2001, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * 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
Michael Holzheu59e36922009-09-11 10:29:07 +020011#define KMSG_COMPONENT "tape_34xx"
Michael Holzheubb509912009-12-18 17:43:21 +010012#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
Carsten Otteab640db2009-03-26 15:24:38 +010013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/bio.h>
17#include <linux/workqueue.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#define TAPE_DBF_AREA tape_34xx_dbf
21
22#include "tape.h"
23#include "tape_std.h"
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025/*
26 * Pointer to debug area.
27 */
28debug_info_t *TAPE_DBF_AREA = NULL;
29EXPORT_SYMBOL(TAPE_DBF_AREA);
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#define TAPE34XX_FMT_3480 0
32#define TAPE34XX_FMT_3480_2_XF 1
33#define TAPE34XX_FMT_3480_XF 2
34
35struct tape_34xx_block_id {
36 unsigned int wrap : 1;
37 unsigned int segment : 7;
38 unsigned int format : 2;
39 unsigned int block : 22;
40};
41
42/*
43 * A list of block ID's is used to faster seek blocks.
44 */
45struct tape_34xx_sbid {
46 struct list_head list;
47 struct tape_34xx_block_id bid;
48};
49
50static void tape_34xx_delete_sbid_from(struct tape_device *, int);
51
52/*
53 * Medium sense for 34xx tapes. There is no 'real' medium sense call.
54 * So we just do a normal sense.
55 */
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +010056static void __tape_34xx_medium_sense(struct tape_request *request)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +010058 struct tape_device *device = request->device;
59 unsigned char *sense;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 if (request->rc == 0) {
62 sense = request->cpdata;
63
64 /*
65 * This isn't quite correct. But since INTERVENTION_REQUIRED
66 * means that the drive is 'neither ready nor on-line' it is
67 * only slightly inaccurate to say there is no tape loaded if
68 * the drive isn't online...
69 */
70 if (sense[0] & SENSE_INTERVENTION_REQUIRED)
71 tape_med_state_set(device, MS_UNLOADED);
72 else
73 tape_med_state_set(device, MS_LOADED);
74
75 if (sense[1] & SENSE_WRITE_PROTECT)
76 device->tape_generic_status |= GMT_WR_PROT(~0);
77 else
78 device->tape_generic_status &= ~GMT_WR_PROT(~0);
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +010079 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 DBF_EVENT(4, "tape_34xx: medium sense failed with rc=%d\n",
81 request->rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 tape_free_request(request);
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +010083}
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +010085static int tape_34xx_medium_sense(struct tape_device *device)
86{
87 struct tape_request *request;
88 int rc;
89
90 request = tape_alloc_request(1, 32);
91 if (IS_ERR(request)) {
92 DBF_EXCEPTION(6, "MSEN fail\n");
93 return PTR_ERR(request);
94 }
95
96 request->op = TO_MSEN;
97 tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata);
98 rc = tape_do_io_interruptible(device, request);
99 __tape_34xx_medium_sense(request);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return rc;
101}
102
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100103static void tape_34xx_medium_sense_async(struct tape_device *device)
104{
105 struct tape_request *request;
106
107 request = tape_alloc_request(1, 32);
108 if (IS_ERR(request)) {
109 DBF_EXCEPTION(6, "MSEN fail\n");
110 return;
111 }
112
113 request->op = TO_MSEN;
114 tape_ccw_end(request->cpaddr, SENSE, 32, request->cpdata);
115 request->callback = (void *) __tape_34xx_medium_sense;
116 request->callback_data = NULL;
117 tape_do_io_async(device, request);
118}
119
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100120struct tape_34xx_work {
121 struct tape_device *device;
122 enum tape_op op;
123 struct work_struct work;
124};
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126/*
127 * These functions are currently used only to schedule a medium_sense for
128 * later execution. This is because we get an interrupt whenever a medium
129 * is inserted but cannot call tape_do_io* from an interrupt context.
130 * Maybe that's useful for other actions we want to start from the
131 * interrupt handler.
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100132 * Note: the work handler is called by the system work queue. The tape
133 * commands started by the handler need to be asynchrounous, otherwise
134 * a deadlock can occur e.g. in case of a deferred cc=1 (see __tape_do_irq).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 */
136static void
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100137tape_34xx_work_handler(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100139 struct tape_34xx_work *p =
140 container_of(work, struct tape_34xx_work, work);
Martin Schwidefsky8fd138c2009-12-07 12:52:03 +0100141 struct tape_device *device = p->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 switch(p->op) {
144 case TO_MSEN:
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100145 tape_34xx_medium_sense_async(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 break;
147 default:
148 DBF_EVENT(3, "T34XX: internal error: unknown work\n");
149 }
Martin Schwidefsky8fd138c2009-12-07 12:52:03 +0100150 tape_put_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 kfree(p);
152}
153
154static int
155tape_34xx_schedule_work(struct tape_device *device, enum tape_op op)
156{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100157 struct tape_34xx_work *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700159 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 return -ENOMEM;
161
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100162 INIT_WORK(&p->work, tape_34xx_work_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Martin Schwidefsky8fd138c2009-12-07 12:52:03 +0100164 p->device = tape_get_device(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 p->op = op;
166
167 schedule_work(&p->work);
168 return 0;
169}
170
171/*
172 * Done Handler is called when dev stat = DEVICE-END (successful operation)
173 */
174static inline int
175tape_34xx_done(struct tape_request *request)
176{
177 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
178
179 switch (request->op) {
180 case TO_DSE:
181 case TO_RUN:
182 case TO_WRI:
183 case TO_WTM:
184 case TO_ASSIGN:
185 case TO_UNASSIGN:
186 tape_34xx_delete_sbid_from(request->device, 0);
187 break;
188 default:
189 ;
190 }
191 return TAPE_IO_SUCCESS;
192}
193
194static inline int
195tape_34xx_erp_failed(struct tape_request *request, int rc)
196{
197 DBF_EVENT(3, "Error recovery failed for %s (RC=%d)\n",
198 tape_op_verbose[request->op], rc);
199 return rc;
200}
201
202static inline int
203tape_34xx_erp_succeeded(struct tape_request *request)
204{
205 DBF_EVENT(3, "Error Recovery successful for %s\n",
206 tape_op_verbose[request->op]);
207 return tape_34xx_done(request);
208}
209
210static inline int
211tape_34xx_erp_retry(struct tape_request *request)
212{
213 DBF_EVENT(3, "xerp retr %s\n", tape_op_verbose[request->op]);
214 return TAPE_IO_RETRY;
215}
216
217/*
218 * This function is called, when no request is outstanding and we get an
219 * interrupt
220 */
221static int
222tape_34xx_unsolicited_irq(struct tape_device *device, struct irb *irb)
223{
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200224 if (irb->scsw.cmd.dstat == 0x85) { /* READY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 /* A medium was inserted in the drive. */
226 DBF_EVENT(6, "xuud med\n");
227 tape_34xx_delete_sbid_from(device, 0);
228 tape_34xx_schedule_work(device, TO_MSEN);
229 } else {
230 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
Carsten Otteab640db2009-03-26 15:24:38 +0100231 tape_dump_sense_dbf(device, NULL, irb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
233 return TAPE_IO_SUCCESS;
234}
235
236/*
237 * Read Opposite Error Recovery Function:
238 * Used, when Read Forward does not work
239 */
240static int
241tape_34xx_erp_read_opposite(struct tape_device *device,
242 struct tape_request *request)
243{
244 if (request->op == TO_RFO) {
245 /*
246 * We did read forward, but the data could not be read
247 * *correctly*. We transform the request to a read backward
248 * and try again.
249 */
250 tape_std_read_backward(device, request);
251 return tape_34xx_erp_retry(request);
252 }
Carsten Otteab640db2009-03-26 15:24:38 +0100253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 /*
255 * We tried to read forward and backward, but hat no
256 * success -> failed.
257 */
258 return tape_34xx_erp_failed(request, -EIO);
259}
260
261static int
262tape_34xx_erp_bug(struct tape_device *device, struct tape_request *request,
263 struct irb *irb, int no)
264{
265 if (request->op != TO_ASSIGN) {
Carsten Otteab640db2009-03-26 15:24:38 +0100266 dev_err(&device->cdev->dev, "An unexpected condition %d "
267 "occurred in tape error recovery\n", no);
268 tape_dump_sense_dbf(device, request, irb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 }
270 return tape_34xx_erp_failed(request, -EIO);
271}
272
273/*
274 * Handle data overrun between cu and drive. The channel speed might
275 * be too slow.
276 */
277static int
278tape_34xx_erp_overrun(struct tape_device *device, struct tape_request *request,
279 struct irb *irb)
280{
281 if (irb->ecw[3] == 0x40) {
Carsten Otteab640db2009-03-26 15:24:38 +0100282 dev_warn (&device->cdev->dev, "A data overrun occurred between"
283 " the control unit and tape unit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 return tape_34xx_erp_failed(request, -EIO);
285 }
286 return tape_34xx_erp_bug(device, request, irb, -1);
287}
288
289/*
290 * Handle record sequence error.
291 */
292static int
293tape_34xx_erp_sequence(struct tape_device *device,
294 struct tape_request *request, struct irb *irb)
295{
296 if (irb->ecw[3] == 0x41) {
297 /*
298 * cu detected incorrect block-id sequence on tape.
299 */
Carsten Otteab640db2009-03-26 15:24:38 +0100300 dev_warn (&device->cdev->dev, "The block ID sequence on the "
301 "tape is incorrect\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 return tape_34xx_erp_failed(request, -EIO);
303 }
304 /*
305 * Record sequence error bit is set, but erpa does not
306 * show record sequence error.
307 */
308 return tape_34xx_erp_bug(device, request, irb, -2);
309}
310
311/*
312 * This function analyses the tape's sense-data in case of a unit-check.
313 * If possible, it tries to recover from the error. Else the user is
314 * informed about the problem.
315 */
316static int
317tape_34xx_unit_check(struct tape_device *device, struct tape_request *request,
318 struct irb *irb)
319{
320 int inhibit_cu_recovery;
321 __u8* sense;
322
323 inhibit_cu_recovery = (*device->modeset_byte & 0x80) ? 1 : 0;
324 sense = irb->ecw;
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 if (
327 sense[0] & SENSE_COMMAND_REJECT &&
328 sense[1] & SENSE_WRITE_PROTECT
329 ) {
330 if (
331 request->op == TO_DSE ||
332 request->op == TO_WRI ||
333 request->op == TO_WTM
334 ) {
335 /* medium is write protected */
336 return tape_34xx_erp_failed(request, -EACCES);
337 } else {
338 return tape_34xx_erp_bug(device, request, irb, -3);
339 }
340 }
341
342 /*
343 * Special cases for various tape-states when reaching
344 * end of recorded area
345 *
346 * FIXME: Maybe a special case of the special case:
347 * sense[0] == SENSE_EQUIPMENT_CHECK &&
348 * sense[1] == SENSE_DRIVE_ONLINE &&
349 * sense[3] == 0x47 (Volume Fenced)
350 *
351 * This was caused by continued FSF or FSR after an
352 * 'End Of Data'.
353 */
354 if ((
355 sense[0] == SENSE_DATA_CHECK ||
356 sense[0] == SENSE_EQUIPMENT_CHECK ||
357 sense[0] == SENSE_EQUIPMENT_CHECK + SENSE_DEFERRED_UNIT_CHECK
358 ) && (
359 sense[1] == SENSE_DRIVE_ONLINE ||
360 sense[1] == SENSE_BEGINNING_OF_TAPE + SENSE_WRITE_MODE
361 )) {
362 switch (request->op) {
363 /*
364 * sense[0] == SENSE_DATA_CHECK &&
365 * sense[1] == SENSE_DRIVE_ONLINE
366 * sense[3] == 0x36 (End Of Data)
367 *
368 * Further seeks might return a 'Volume Fenced'.
369 */
370 case TO_FSF:
371 case TO_FSB:
372 /* Trying to seek beyond end of recorded area */
373 return tape_34xx_erp_failed(request, -ENOSPC);
374 case TO_BSB:
375 return tape_34xx_erp_retry(request);
376
377 /*
378 * sense[0] == SENSE_DATA_CHECK &&
379 * sense[1] == SENSE_DRIVE_ONLINE &&
380 * sense[3] == 0x36 (End Of Data)
381 */
382 case TO_LBL:
383 /* Block could not be located. */
384 tape_34xx_delete_sbid_from(device, 0);
385 return tape_34xx_erp_failed(request, -EIO);
386
387 case TO_RFO:
388 /* Read beyond end of recorded area -> 0 bytes read */
389 return tape_34xx_erp_failed(request, 0);
390
391 /*
392 * sense[0] == SENSE_EQUIPMENT_CHECK &&
393 * sense[1] == SENSE_DRIVE_ONLINE &&
394 * sense[3] == 0x38 (Physical End Of Volume)
395 */
396 case TO_WRI:
397 /* Writing at physical end of volume */
398 return tape_34xx_erp_failed(request, -ENOSPC);
399 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 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 */
Carsten Otteab640db2009-03-26 15:24:38 +0100425 dev_warn (&device->cdev->dev, "A read error occurred "
426 "that cannot be recovered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 return tape_34xx_erp_failed(request, -EIO);
428 case 0x25:
429 // a write data check occurred
430 if ((sense[2] & SENSE_TAPE_SYNC_MODE) ||
431 inhibit_cu_recovery)
432 // data check is not permanent, may be
433 // recovered. We always use async-mode with
434 // cu-recovery, so this should *never* happen.
435 return tape_34xx_erp_bug(device, request,
436 irb, -5);
437
438 // data check is permanent, cu-recovery has failed
Carsten Otteab640db2009-03-26 15:24:38 +0100439 dev_warn (&device->cdev->dev, "A write error on the "
440 "tape cannot be recovered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 return tape_34xx_erp_failed(request, -EIO);
442 case 0x26:
443 /* Data Check (read opposite) occurred. */
444 return tape_34xx_erp_read_opposite(device, request);
445 case 0x28:
446 /* ID-Mark at tape start couldn't be written */
Carsten Otteab640db2009-03-26 15:24:38 +0100447 dev_warn (&device->cdev->dev, "Writing the ID-mark "
448 "failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 return tape_34xx_erp_failed(request, -EIO);
450 case 0x31:
451 /* Tape void. Tried to read beyond end of device. */
Carsten Otteab640db2009-03-26 15:24:38 +0100452 dev_warn (&device->cdev->dev, "Reading the tape beyond"
453 " the end of the recorded area failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 return tape_34xx_erp_failed(request, -ENOSPC);
455 case 0x41:
456 /* Record sequence error. */
Carsten Otteab640db2009-03-26 15:24:38 +0100457 dev_warn (&device->cdev->dev, "The tape contains an "
458 "incorrect block ID sequence\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 return tape_34xx_erp_failed(request, -EIO);
460 default:
461 /* all data checks for 3480 should result in one of
462 * the above erpa-codes. For 3490, other data-check
463 * conditions do exist. */
464 if (device->cdev->id.driver_info == tape_3480)
465 return tape_34xx_erp_bug(device, request,
466 irb, -6);
467 }
468 }
469
470 if (sense[0] & SENSE_OVERRUN)
471 return tape_34xx_erp_overrun(device, request, irb);
472
473 if (sense[1] & SENSE_RECORD_SEQUENCE_ERR)
474 return tape_34xx_erp_sequence(device, request, irb);
475
476 /* Sensing erpa codes */
477 switch (sense[3]) {
478 case 0x00:
479 /* Unit check with erpa code 0. Report and ignore. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 return TAPE_IO_SUCCESS;
481 case 0x21:
482 /*
483 * Data streaming not operational. CU will switch to
484 * interlock mode. Reissue the command.
485 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 return tape_34xx_erp_retry(request);
487 case 0x22:
488 /*
489 * Path equipment check. Might be drive adapter error, buffer
490 * error on the lower interface, internal path not usable,
491 * or error during cartridge load.
492 */
Carsten Otteab640db2009-03-26 15:24:38 +0100493 dev_warn (&device->cdev->dev, "A path equipment check occurred"
494 " for the tape device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return tape_34xx_erp_failed(request, -EIO);
518 case 0x2a:
519 /*
520 * Unsolicited environmental data. An internal counter
521 * overflows, we can ignore this and reissue the cmd.
522 */
523 return tape_34xx_erp_retry(request);
524 case 0x2b:
525 /*
526 * Environmental data present. Indicates either unload
527 * completed ok or read buffered log command completed ok.
528 */
529 if (request->op == TO_RUN) {
530 /* Rewind unload completed ok. */
531 tape_med_state_set(device, MS_UNLOADED);
532 return tape_34xx_erp_succeeded(request);
533 }
534 /* tape_34xx doesn't use read buffered log commands. */
535 return tape_34xx_erp_bug(device, request, irb, sense[3]);
536 case 0x2c:
537 /*
538 * Permanent equipment check. CU has tried recovery, but
539 * did not succeed.
540 */
541 return tape_34xx_erp_failed(request, -EIO);
542 case 0x2d:
543 /* Data security erase failure. */
544 if (request->op == TO_DSE)
545 return tape_34xx_erp_failed(request, -EIO);
546 /* Data security erase failure, but no such command issued. */
547 return tape_34xx_erp_bug(device, request, irb, sense[3]);
548 case 0x2e:
549 /*
550 * Not capable. This indicates either that the drive fails
551 * reading the format id mark or that that format specified
552 * is not supported by the drive.
553 */
Carsten Otteab640db2009-03-26 15:24:38 +0100554 dev_warn (&device->cdev->dev, "The tape unit cannot process "
555 "the tape format\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
557 case 0x30:
558 /* The medium is write protected. */
Carsten Otteab640db2009-03-26 15:24:38 +0100559 dev_warn (&device->cdev->dev, "The tape medium is write-"
560 "protected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 return tape_34xx_erp_failed(request, -EACCES);
562 case 0x32:
563 // Tension loss. We cannot recover this, it's an I/O error.
Carsten Otteab640db2009-03-26 15:24:38 +0100564 dev_warn (&device->cdev->dev, "The tape does not have the "
565 "required tape tension\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 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 */
Carsten Otteab640db2009-03-26 15:24:38 +0100572 dev_warn (&device->cdev->dev, "The tape unit failed to load"
573 " the cartridge\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 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 */
Carsten Otteab640db2009-03-26 15:24:38 +0100581 dev_warn (&device->cdev->dev, "Automatic unloading of the tape"
582 " cartridge failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 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 */
Carsten Otteab640db2009-03-26 15:24:38 +0100594 dev_warn (&device->cdev->dev, "An equipment check has occurred"
595 " on the tape unit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 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 */
Carsten Otteab640db2009-03-26 15:24:38 +0100608 dev_warn (&device->cdev->dev, "The tape information states an"
609 " incorrect length\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 return tape_34xx_erp_failed(request, -EIO);
611 case 0x38:
612 /*
613 * Physical end of tape. A read/write operation reached
614 * the physical end of tape.
615 */
616 if (request->op==TO_WRI ||
617 request->op==TO_DSE ||
618 request->op==TO_WTM)
619 return tape_34xx_erp_failed(request, -ENOSPC);
620 return tape_34xx_erp_failed(request, -EIO);
621 case 0x39:
622 /* Backward at Beginning of tape. */
623 return tape_34xx_erp_failed(request, -EIO);
624 case 0x3a:
625 /* Drive switched to not ready. */
Carsten Otteab640db2009-03-26 15:24:38 +0100626 dev_warn (&device->cdev->dev, "The tape unit is not ready\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 return tape_34xx_erp_failed(request, -EIO);
628 case 0x3b:
629 /* Manual rewind or unload. This causes an I/O error. */
Carsten Otteab640db2009-03-26 15:24:38 +0100630 dev_warn (&device->cdev->dev, "The tape medium has been "
631 "rewound or unloaded manually\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 tape_34xx_delete_sbid_from(device, 0);
633 return tape_34xx_erp_failed(request, -EIO);
634 case 0x42:
635 /*
636 * Degraded mode. A condition that can cause degraded
637 * performance is detected.
638 */
Carsten Otteab640db2009-03-26 15:24:38 +0100639 dev_warn (&device->cdev->dev, "The tape subsystem is running "
640 "in degraded mode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 return tape_34xx_erp_retry(request);
642 case 0x43:
643 /* Drive not ready. */
644 tape_34xx_delete_sbid_from(device, 0);
645 tape_med_state_set(device, MS_UNLOADED);
646 /* Some commands commands are successful even in this case */
647 if (sense[1] & SENSE_DRIVE_ONLINE) {
648 switch(request->op) {
649 case TO_ASSIGN:
650 case TO_UNASSIGN:
651 case TO_DIS:
652 case TO_NOP:
653 return tape_34xx_done(request);
654 break;
655 default:
656 break;
657 }
658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 return tape_34xx_erp_failed(request, -ENOMEDIUM);
660 case 0x44:
661 /* Locate Block unsuccessful. */
662 if (request->op != TO_BLOCK && request->op != TO_LBL)
663 /* No locate block was issued. */
664 return tape_34xx_erp_bug(device, request,
665 irb, sense[3]);
666 return tape_34xx_erp_failed(request, -EIO);
667 case 0x45:
668 /* The drive is assigned to a different channel path. */
Carsten Otteab640db2009-03-26 15:24:38 +0100669 dev_warn (&device->cdev->dev, "The tape unit is already "
670 "assigned\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 return tape_34xx_erp_failed(request, -EIO);
672 case 0x46:
673 /*
674 * Drive not on-line. Drive may be switched offline,
675 * the power supply may be switched off or
676 * the drive address may not be set correctly.
677 */
Carsten Otteab640db2009-03-26 15:24:38 +0100678 dev_warn (&device->cdev->dev, "The tape unit is not online\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 return tape_34xx_erp_failed(request, -EIO);
680 case 0x47:
681 /* Volume fenced. CU reports volume integrity is lost. */
Carsten Otteab640db2009-03-26 15:24:38 +0100682 dev_warn (&device->cdev->dev, "The control unit has fenced "
683 "access to the tape volume\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 tape_34xx_delete_sbid_from(device, 0);
685 return tape_34xx_erp_failed(request, -EIO);
686 case 0x48:
687 /* Log sense data and retry request. */
688 return tape_34xx_erp_retry(request);
689 case 0x49:
690 /* Bus out check. A parity check error on the bus was found. */
Carsten Otteab640db2009-03-26 15:24:38 +0100691 dev_warn (&device->cdev->dev, "A parity error occurred on the "
692 "tape bus\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 return tape_34xx_erp_failed(request, -EIO);
694 case 0x4a:
695 /* Control unit erp failed. */
Carsten Otteab640db2009-03-26 15:24:38 +0100696 dev_warn (&device->cdev->dev, "I/O error recovery failed on "
697 "the tape control unit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 return tape_34xx_erp_failed(request, -EIO);
699 case 0x4b:
700 /*
701 * CU and drive incompatible. The drive requests micro-program
702 * patches, which are not available on the CU.
703 */
Carsten Otteab640db2009-03-26 15:24:38 +0100704 dev_warn (&device->cdev->dev, "The tape unit requires a "
705 "firmware update\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 return tape_34xx_erp_failed(request, -EIO);
707 case 0x4c:
708 /*
709 * Recovered Check-One failure. Cu develops a hardware error,
710 * but is able to recover.
711 */
712 return tape_34xx_erp_retry(request);
713 case 0x4d:
714 if (device->cdev->id.driver_info == tape_3490)
715 /*
716 * Resetting event received. Since the driver does
717 * not support resetting event recovery (which has to
718 * be handled by the I/O Layer), retry our command.
719 */
720 return tape_34xx_erp_retry(request);
721 /* This erpa is reserved for 3480. */
722 return tape_34xx_erp_bug(device, request, irb, sense[3]);
723 case 0x4e:
724 if (device->cdev->id.driver_info == tape_3490) {
725 /*
726 * Maximum block size exceeded. This indicates, that
727 * the block to be written is larger than allowed for
728 * buffered mode.
729 */
Carsten Otteab640db2009-03-26 15:24:38 +0100730 dev_warn (&device->cdev->dev, "The maximum block size"
731 " for buffered mode is exceeded\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 return tape_34xx_erp_failed(request, -ENOBUFS);
733 }
734 /* This erpa is reserved for 3480. */
735 return tape_34xx_erp_bug(device, request, irb, sense[3]);
736 case 0x50:
737 /*
738 * Read buffered log (Overflow). CU is running in extended
739 * buffered log mode, and a counter overflows. This should
740 * never happen, since we're never running in extended
741 * buffered log mode.
742 */
743 return tape_34xx_erp_retry(request);
744 case 0x51:
745 /*
746 * Read buffered log (EOV). EOF processing occurs while the
747 * CU is in extended buffered log mode. This should never
748 * happen, since we're never running in extended buffered
749 * log mode.
750 */
751 return tape_34xx_erp_retry(request);
752 case 0x52:
753 /* End of Volume complete. Rewind unload completed ok. */
754 if (request->op == TO_RUN) {
755 tape_med_state_set(device, MS_UNLOADED);
756 tape_34xx_delete_sbid_from(device, 0);
757 return tape_34xx_erp_succeeded(request);
758 }
759 return tape_34xx_erp_bug(device, request, irb, sense[3]);
760 case 0x53:
761 /* Global command intercept. */
762 return tape_34xx_erp_retry(request);
763 case 0x54:
764 /* Channel interface recovery (temporary). */
765 return tape_34xx_erp_retry(request);
766 case 0x55:
767 /* Channel interface recovery (permanent). */
Carsten Otteab640db2009-03-26 15:24:38 +0100768 dev_warn (&device->cdev->dev, "A channel interface error cannot be"
769 " recovered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 return tape_34xx_erp_failed(request, -EIO);
771 case 0x56:
772 /* Channel protocol error. */
Carsten Otteab640db2009-03-26 15:24:38 +0100773 dev_warn (&device->cdev->dev, "A channel protocol error "
774 "occurred\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 return tape_34xx_erp_failed(request, -EIO);
776 case 0x57:
777 if (device->cdev->id.driver_info == tape_3480) {
778 /* Attention intercept. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 return tape_34xx_erp_retry(request);
780 } else {
781 /* Global status intercept. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 return tape_34xx_erp_retry(request);
783 }
784 case 0x5a:
785 /*
786 * Tape length incompatible. The tape inserted is too long,
787 * which could cause damage to the tape or the drive.
788 */
Carsten Otteab640db2009-03-26 15:24:38 +0100789 dev_warn (&device->cdev->dev, "The tape unit does not support "
790 "the tape length\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 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);
Carsten Otteab640db2009-03-26 15:24:38 +0100797 dev_warn (&device->cdev->dev, "The tape unit does not support"
798 " format 3480 XF\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 return tape_34xx_erp_failed(request, -EIO);
800 case 0x5c:
801 /* Format 3480-2 XF incompatible */
Carsten Otteab640db2009-03-26 15:24:38 +0100802 dev_warn (&device->cdev->dev, "The tape unit does not support tape "
803 "format 3480-2 XF\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 return tape_34xx_erp_failed(request, -EIO);
805 case 0x5d:
806 /* Tape length violation. */
Carsten Otteab640db2009-03-26 15:24:38 +0100807 dev_warn (&device->cdev->dev, "The tape unit does not support"
808 " the current tape length\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
810 case 0x5e:
811 /* Compaction algorithm incompatible. */
Carsten Otteab640db2009-03-26 15:24:38 +0100812 dev_warn (&device->cdev->dev, "The tape unit does not support"
813 " the compaction algorithm\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 return tape_34xx_erp_failed(request, -EMEDIUMTYPE);
815
816 /* The following erpas should have been covered earlier. */
817 case 0x23: /* Read data check. */
818 case 0x25: /* Write data check. */
819 case 0x26: /* Data check (read opposite). */
820 case 0x28: /* Write id mark check. */
821 case 0x31: /* Tape void. */
822 case 0x40: /* Overrun error. */
823 case 0x41: /* Record sequence error. */
824 /* All other erpas are reserved for future use. */
825 default:
826 return tape_34xx_erp_bug(device, request, irb, sense[3]);
827 }
828}
829
830/*
831 * 3480/3490 interrupt handler
832 */
833static int
834tape_34xx_irq(struct tape_device *device, struct tape_request *request,
835 struct irb *irb)
836{
837 if (request == NULL)
838 return tape_34xx_unsolicited_irq(device, irb);
839
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200840 if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
841 (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 (request->op == TO_WRI)) {
843 /* Write at end of volume */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 return tape_34xx_erp_failed(request, -ENOSPC);
845 }
846
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200847 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 return tape_34xx_unit_check(device, request, irb);
849
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200850 if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 /*
852 * A unit exception occurs on skipping over a tapemark block.
853 */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200854 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 if (request->op == TO_BSB || request->op == TO_FSB)
856 request->rescnt++;
857 else
858 DBF_EVENT(5, "Unit Exception!\n");
859 }
860 return tape_34xx_done(request);
861 }
862
863 DBF_EVENT(6, "xunknownirq\n");
Carsten Otteab640db2009-03-26 15:24:38 +0100864 tape_dump_sense_dbf(device, request, irb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 return TAPE_IO_STOP;
866}
867
868/*
869 * ioctl_overload
870 */
871static int
872tape_34xx_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
873{
874 if (cmd == TAPE390_DISPLAY) {
875 struct display_struct disp;
876
877 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)) != 0)
878 return -EFAULT;
879
880 return tape_std_display(device, &disp);
881 } else
882 return -EINVAL;
883}
884
885static inline void
886tape_34xx_append_new_sbid(struct tape_34xx_block_id bid, struct list_head *l)
887{
888 struct tape_34xx_sbid * new_sbid;
889
890 new_sbid = kmalloc(sizeof(*new_sbid), GFP_ATOMIC);
891 if (!new_sbid)
892 return;
893
894 new_sbid->bid = bid;
895 list_add(&new_sbid->list, l);
896}
897
898/*
899 * Build up the search block ID list. The block ID consists of a logical
900 * block number and a hardware specific part. The hardware specific part
901 * helps the tape drive to speed up searching for a specific block.
902 */
903static void
904tape_34xx_add_sbid(struct tape_device *device, struct tape_34xx_block_id bid)
905{
906 struct list_head * sbid_list;
907 struct tape_34xx_sbid * sbid;
908 struct list_head * l;
909
910 /*
911 * immediately return if there is no list at all or the block to add
912 * is located in segment 1 of wrap 0 because this position is used
913 * if no hardware position data is supplied.
914 */
915 sbid_list = (struct list_head *) device->discdata;
916 if (!sbid_list || (bid.segment < 2 && bid.wrap == 0))
917 return;
918
919 /*
920 * Search the position where to insert the new entry. Hardware
921 * acceleration uses only the segment and wrap number. So we
922 * need only one entry for a specific wrap/segment combination.
923 * If there is a block with a lower number but the same hard-
924 * ware position data we just update the block number in the
925 * existing entry.
926 */
927 list_for_each(l, sbid_list) {
928 sbid = list_entry(l, struct tape_34xx_sbid, list);
929
930 if (
931 (sbid->bid.segment == bid.segment) &&
932 (sbid->bid.wrap == bid.wrap)
933 ) {
934 if (bid.block < sbid->bid.block)
935 sbid->bid = bid;
936 else return;
937 break;
938 }
939
940 /* Sort in according to logical block number. */
941 if (bid.block < sbid->bid.block) {
942 tape_34xx_append_new_sbid(bid, l->prev);
943 break;
944 }
945 }
946 /* List empty or new block bigger than last entry. */
947 if (l == sbid_list)
948 tape_34xx_append_new_sbid(bid, l->prev);
949
950 DBF_LH(4, "Current list is:\n");
951 list_for_each(l, sbid_list) {
952 sbid = list_entry(l, struct tape_34xx_sbid, list);
953 DBF_LH(4, "%d:%03d@%05d\n",
954 sbid->bid.wrap,
955 sbid->bid.segment,
956 sbid->bid.block
957 );
958 }
959}
960
961/*
962 * Delete all entries from the search block ID list that belong to tape blocks
963 * equal or higher than the given number.
964 */
965static void
966tape_34xx_delete_sbid_from(struct tape_device *device, int from)
967{
968 struct list_head * sbid_list;
969 struct tape_34xx_sbid * sbid;
970 struct list_head * l;
971 struct list_head * n;
972
973 sbid_list = (struct list_head *) device->discdata;
974 if (!sbid_list)
975 return;
976
977 list_for_each_safe(l, n, sbid_list) {
978 sbid = list_entry(l, struct tape_34xx_sbid, list);
979 if (sbid->bid.block >= from) {
980 DBF_LH(4, "Delete sbid %d:%03d@%05d\n",
981 sbid->bid.wrap,
982 sbid->bid.segment,
983 sbid->bid.block
984 );
985 list_del(l);
986 kfree(sbid);
987 }
988 }
989}
990
991/*
992 * Merge hardware position data into a block id.
993 */
994static void
995tape_34xx_merge_sbid(
996 struct tape_device * device,
997 struct tape_34xx_block_id * bid
998) {
999 struct tape_34xx_sbid * sbid;
1000 struct tape_34xx_sbid * sbid_to_use;
1001 struct list_head * sbid_list;
1002 struct list_head * l;
1003
1004 sbid_list = (struct list_head *) device->discdata;
1005 bid->wrap = 0;
1006 bid->segment = 1;
1007
1008 if (!sbid_list || list_empty(sbid_list))
1009 return;
1010
1011 sbid_to_use = NULL;
1012 list_for_each(l, sbid_list) {
1013 sbid = list_entry(l, struct tape_34xx_sbid, list);
1014
1015 if (sbid->bid.block >= bid->block)
1016 break;
1017 sbid_to_use = sbid;
1018 }
1019 if (sbid_to_use) {
1020 bid->wrap = sbid_to_use->bid.wrap;
1021 bid->segment = sbid_to_use->bid.segment;
1022 DBF_LH(4, "Use %d:%03d@%05d for %05d\n",
1023 sbid_to_use->bid.wrap,
1024 sbid_to_use->bid.segment,
1025 sbid_to_use->bid.block,
1026 bid->block
1027 );
1028 }
1029}
1030
1031static int
1032tape_34xx_setup_device(struct tape_device * device)
1033{
1034 int rc;
1035 struct list_head * discdata;
1036
1037 DBF_EVENT(6, "34xx device setup\n");
1038 if ((rc = tape_std_assign(device)) == 0) {
1039 if ((rc = tape_34xx_medium_sense(device)) != 0) {
1040 DBF_LH(3, "34xx medium sense returned %d\n", rc);
1041 }
1042 }
1043 discdata = kmalloc(sizeof(struct list_head), GFP_KERNEL);
1044 if (discdata) {
1045 INIT_LIST_HEAD(discdata);
1046 device->discdata = discdata;
1047 }
1048
1049 return rc;
1050}
1051
1052static void
1053tape_34xx_cleanup_device(struct tape_device *device)
1054{
1055 tape_std_unassign(device);
1056
1057 if (device->discdata) {
1058 tape_34xx_delete_sbid_from(device, 0);
1059 kfree(device->discdata);
1060 device->discdata = NULL;
1061 }
1062}
1063
1064
1065/*
1066 * MTTELL: Tell block. Return the number of block relative to current file.
1067 */
1068static int
1069tape_34xx_mttell(struct tape_device *device, int mt_count)
1070{
1071 struct {
1072 struct tape_34xx_block_id cbid;
1073 struct tape_34xx_block_id dbid;
1074 } __attribute__ ((packed)) block_id;
1075 int rc;
1076
1077 rc = tape_std_read_block_id(device, (__u64 *) &block_id);
1078 if (rc)
1079 return rc;
1080
1081 tape_34xx_add_sbid(device, block_id.cbid);
1082 return block_id.cbid.block;
1083}
1084
1085/*
1086 * MTSEEK: seek to the specified block.
1087 */
1088static int
1089tape_34xx_mtseek(struct tape_device *device, int mt_count)
1090{
1091 struct tape_request *request;
1092 struct tape_34xx_block_id * bid;
1093
1094 if (mt_count > 0x3fffff) {
1095 DBF_EXCEPTION(6, "xsee parm\n");
1096 return -EINVAL;
1097 }
1098 request = tape_alloc_request(3, 4);
1099 if (IS_ERR(request))
1100 return PTR_ERR(request);
1101
1102 /* setup ccws */
1103 request->op = TO_LBL;
1104 bid = (struct tape_34xx_block_id *) request->cpdata;
1105 bid->format = (*device->modeset_byte & 0x08) ?
1106 TAPE34XX_FMT_3480_XF : TAPE34XX_FMT_3480;
1107 bid->block = mt_count;
1108 tape_34xx_merge_sbid(device, bid);
1109
1110 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
1111 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
1112 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
1113
1114 /* execute it */
1115 return tape_do_io_free(device, request);
1116}
1117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118/*
1119 * List of 3480/3490 magnetic tape commands.
1120 */
1121static tape_mtop_fn tape_34xx_mtop[TAPE_NR_MTOPS] = {
1122 [MTRESET] = tape_std_mtreset,
1123 [MTFSF] = tape_std_mtfsf,
1124 [MTBSF] = tape_std_mtbsf,
1125 [MTFSR] = tape_std_mtfsr,
1126 [MTBSR] = tape_std_mtbsr,
1127 [MTWEOF] = tape_std_mtweof,
1128 [MTREW] = tape_std_mtrew,
1129 [MTOFFL] = tape_std_mtoffl,
1130 [MTNOP] = tape_std_mtnop,
1131 [MTRETEN] = tape_std_mtreten,
1132 [MTBSFM] = tape_std_mtbsfm,
1133 [MTFSFM] = tape_std_mtfsfm,
1134 [MTEOM] = tape_std_mteom,
1135 [MTERASE] = tape_std_mterase,
1136 [MTRAS1] = NULL,
1137 [MTRAS2] = NULL,
1138 [MTRAS3] = NULL,
1139 [MTSETBLK] = tape_std_mtsetblk,
1140 [MTSETDENSITY] = NULL,
1141 [MTSEEK] = tape_34xx_mtseek,
1142 [MTTELL] = tape_34xx_mttell,
1143 [MTSETDRVBUFFER] = NULL,
1144 [MTFSS] = NULL,
1145 [MTBSS] = NULL,
1146 [MTWSM] = NULL,
1147 [MTLOCK] = NULL,
1148 [MTUNLOCK] = NULL,
1149 [MTLOAD] = tape_std_mtload,
1150 [MTUNLOAD] = tape_std_mtunload,
1151 [MTCOMPRESSION] = tape_std_mtcompression,
1152 [MTSETPART] = NULL,
1153 [MTMKPART] = NULL
1154};
1155
1156/*
1157 * Tape discipline structure for 3480 and 3490.
1158 */
1159static struct tape_discipline tape_discipline_34xx = {
1160 .owner = THIS_MODULE,
1161 .setup_device = tape_34xx_setup_device,
1162 .cleanup_device = tape_34xx_cleanup_device,
1163 .process_eov = tape_std_process_eov,
1164 .irq = tape_34xx_irq,
1165 .read_block = tape_std_read_block,
1166 .write_block = tape_std_write_block,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 .ioctl_fn = tape_34xx_ioctl,
1168 .mtop_array = tape_34xx_mtop
1169};
1170
1171static struct ccw_device_id tape_34xx_ids[] = {
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001172 { CCW_DEVICE_DEVTYPE(0x3480, 0, 0x3480, 0), .driver_info = tape_3480},
1173 { CCW_DEVICE_DEVTYPE(0x3490, 0, 0x3490, 0), .driver_info = tape_3490},
1174 { /* end of list */ },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175};
1176
1177static int
1178tape_34xx_online(struct ccw_device *cdev)
1179{
1180 return tape_generic_online(
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07001181 dev_get_drvdata(&cdev->dev),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 &tape_discipline_34xx
1183 );
1184}
1185
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186static struct ccw_driver tape_34xx_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +01001187 .driver = {
1188 .name = "tape_34xx",
1189 .owner = THIS_MODULE,
1190 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 .ids = tape_34xx_ids,
1192 .probe = tape_generic_probe,
1193 .remove = tape_generic_remove,
1194 .set_online = tape_34xx_online,
Frank Munzert4d7a3cd2009-04-23 13:58:09 +02001195 .set_offline = tape_generic_offline,
Frank Munzert3ef32e622009-06-16 10:30:39 +02001196 .freeze = tape_generic_pm_suspend,
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001197 .int_class = IOINT_TAP,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198};
1199
1200static int
1201tape_34xx_init (void)
1202{
1203 int rc;
1204
Michael Holzheu66a464d2005-06-25 14:55:33 -07001205 TAPE_DBF_AREA = debug_register ( "tape_34xx", 2, 2, 4*sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1207#ifdef DBF_LIKE_HELL
1208 debug_set_level(TAPE_DBF_AREA, 6);
1209#endif
1210
Heiko Carstense018ba12006-02-01 03:06:31 -08001211 DBF_EVENT(3, "34xx init\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 /* Register driver for 3480/3490 tapes. */
1213 rc = ccw_driver_register(&tape_34xx_driver);
1214 if (rc)
1215 DBF_EVENT(3, "34xx init failed\n");
1216 else
1217 DBF_EVENT(3, "34xx registered\n");
1218 return rc;
1219}
1220
1221static void
1222tape_34xx_exit(void)
1223{
1224 ccw_driver_unregister(&tape_34xx_driver);
1225
1226 debug_unregister(TAPE_DBF_AREA);
1227}
1228
1229MODULE_DEVICE_TABLE(ccw, tape_34xx_ids);
1230MODULE_AUTHOR("(C) 2001-2002 IBM Deutschland Entwicklung GmbH");
Heiko Carstense018ba12006-02-01 03:06:31 -08001231MODULE_DESCRIPTION("Linux on zSeries channel attached 3480 tape device driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232MODULE_LICENSE("GPL");
1233
1234module_init(tape_34xx_init);
1235module_exit(tape_34xx_exit);