blob: fbe361fcd2c09437e49bc8be0b82c56f08739769 [file] [log] [blame]
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001/*
2 * drivers/s390/char/tape_3590.c
3 * tape device discipline for 3590 tapes.
4 *
Frank Munzert3ef32e622009-06-16 10:30:39 +02005 * Copyright IBM Corp. 2001, 2009
Stefan Baderb6cba4e2006-03-24 03:15:29 -08006 * Author(s): Stefan Bader <shbader@de.ibm.com>
7 * Michael Holzheu <holzheu@de.ibm.com>
8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
9 */
10
Michael Holzheu59e36922009-09-11 10:29:07 +020011#define KMSG_COMPONENT "tape_3590"
Michael Holzheubb509912009-12-18 17:43:21 +010012#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
Carsten Otteab640db2009-03-26 15:24:38 +010013
Stefan Baderb6cba4e2006-03-24 03:15:29 -080014#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Stefan Baderb6cba4e2006-03-24 03:15:29 -080016#include <linux/init.h>
17#include <linux/bio.h>
Michael Holzheucced1dd2007-02-05 21:18:26 +010018#include <asm/ebcdic.h>
Stefan Baderb6cba4e2006-03-24 03:15:29 -080019
20#define TAPE_DBF_AREA tape_3590_dbf
Carsten Otteab640db2009-03-26 15:24:38 +010021#define BUFSIZE 512 /* size of buffers for dynamic generated messages */
Stefan Baderb6cba4e2006-03-24 03:15:29 -080022
23#include "tape.h"
24#include "tape_std.h"
25#include "tape_3590.h"
26
Tejun Heo6dca4672010-12-24 16:00:18 +010027static struct workqueue_struct *tape_3590_wq;
28
Stefan Baderb6cba4e2006-03-24 03:15:29 -080029/*
30 * Pointer to debug area.
31 */
32debug_info_t *TAPE_DBF_AREA = NULL;
33EXPORT_SYMBOL(TAPE_DBF_AREA);
34
35/*******************************************************************
Stefan Weileef35c22010-08-06 21:11:15 +020036 * Error Recovery functions:
Stefan Baderb6cba4e2006-03-24 03:15:29 -080037 * - Read Opposite: implemented
38 * - Read Device (buffered) log: BRA
39 * - Read Library log: BRA
40 * - Swap Devices: BRA
Michael Holzheucced1dd2007-02-05 21:18:26 +010041 * - Long Busy: implemented
Stefan Baderb6cba4e2006-03-24 03:15:29 -080042 * - Special Intercept: BRA
43 * - Read Alternate: implemented
44 *******************************************************************/
45
Stefan Baderb6cba4e2006-03-24 03:15:29 -080046static const char *tape_3590_msg[TAPE_3590_MAX_MSG] = {
47 [0x00] = "",
48 [0x10] = "Lost Sense",
49 [0x11] = "Assigned Elsewhere",
50 [0x12] = "Allegiance Reset",
51 [0x13] = "Shared Access Violation",
52 [0x20] = "Command Reject",
53 [0x21] = "Configuration Error",
54 [0x22] = "Protection Exception",
55 [0x23] = "Write Protect",
56 [0x24] = "Write Length",
57 [0x25] = "Read-Only Format",
58 [0x31] = "Beginning of Partition",
59 [0x33] = "End of Partition",
60 [0x34] = "End of Data",
61 [0x35] = "Block not found",
62 [0x40] = "Device Intervention",
63 [0x41] = "Loader Intervention",
64 [0x42] = "Library Intervention",
65 [0x50] = "Write Error",
66 [0x51] = "Erase Error",
67 [0x52] = "Formatting Error",
68 [0x53] = "Read Error",
69 [0x54] = "Unsupported Format",
70 [0x55] = "No Formatting",
71 [0x56] = "Positioning lost",
72 [0x57] = "Read Length",
73 [0x60] = "Unsupported Medium",
74 [0x61] = "Medium Length Error",
75 [0x62] = "Medium removed",
76 [0x64] = "Load Check",
77 [0x65] = "Unload Check",
78 [0x70] = "Equipment Check",
79 [0x71] = "Bus out Check",
80 [0x72] = "Protocol Error",
81 [0x73] = "Interface Error",
82 [0x74] = "Overrun",
83 [0x75] = "Halt Signal",
84 [0x90] = "Device fenced",
85 [0x91] = "Device Path fenced",
86 [0xa0] = "Volume misplaced",
87 [0xa1] = "Volume inaccessible",
88 [0xa2] = "Volume in input",
89 [0xa3] = "Volume ejected",
90 [0xa4] = "All categories reserved",
91 [0xa5] = "Duplicate Volume",
92 [0xa6] = "Library Manager Offline",
93 [0xa7] = "Library Output Station full",
94 [0xa8] = "Vision System non-operational",
95 [0xa9] = "Library Manager Equipment Check",
96 [0xaa] = "Library Equipment Check",
97 [0xab] = "All Library Cells full",
98 [0xac] = "No Cleaner Volumes in Library",
99 [0xad] = "I/O Station door open",
100 [0xae] = "Subsystem environmental alert",
101};
102
Michael Holzheucced1dd2007-02-05 21:18:26 +0100103static int crypt_supported(struct tape_device *device)
104{
105 return TAPE390_CRYPT_SUPPORTED(TAPE_3590_CRYPT_INFO(device));
106}
107
108static int crypt_enabled(struct tape_device *device)
109{
110 return TAPE390_CRYPT_ON(TAPE_3590_CRYPT_INFO(device));
111}
112
113static void ext_to_int_kekl(struct tape390_kekl *in,
114 struct tape3592_kekl *out)
115{
116 int i;
117
118 memset(out, 0, sizeof(*out));
119 if (in->type == TAPE390_KEKL_TYPE_HASH)
120 out->flags |= 0x40;
121 if (in->type_on_tape == TAPE390_KEKL_TYPE_HASH)
122 out->flags |= 0x80;
123 strncpy(out->label, in->label, 64);
124 for (i = strlen(in->label); i < sizeof(out->label); i++)
125 out->label[i] = ' ';
126 ASCEBC(out->label, sizeof(out->label));
127}
128
129static void int_to_ext_kekl(struct tape3592_kekl *in,
130 struct tape390_kekl *out)
131{
132 memset(out, 0, sizeof(*out));
133 if(in->flags & 0x40)
134 out->type = TAPE390_KEKL_TYPE_HASH;
135 else
136 out->type = TAPE390_KEKL_TYPE_LABEL;
137 if(in->flags & 0x80)
138 out->type_on_tape = TAPE390_KEKL_TYPE_HASH;
139 else
140 out->type_on_tape = TAPE390_KEKL_TYPE_LABEL;
141 memcpy(out->label, in->label, sizeof(in->label));
142 EBCASC(out->label, sizeof(in->label));
Heiko Carstens1d802e22009-12-18 17:43:27 +0100143 strim(out->label);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100144}
145
146static void int_to_ext_kekl_pair(struct tape3592_kekl_pair *in,
147 struct tape390_kekl_pair *out)
148{
149 if (in->count == 0) {
150 out->kekl[0].type = TAPE390_KEKL_TYPE_NONE;
151 out->kekl[0].type_on_tape = TAPE390_KEKL_TYPE_NONE;
152 out->kekl[1].type = TAPE390_KEKL_TYPE_NONE;
153 out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE;
154 } else if (in->count == 1) {
155 int_to_ext_kekl(&in->kekl[0], &out->kekl[0]);
156 out->kekl[1].type = TAPE390_KEKL_TYPE_NONE;
157 out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE;
158 } else if (in->count == 2) {
159 int_to_ext_kekl(&in->kekl[0], &out->kekl[0]);
160 int_to_ext_kekl(&in->kekl[1], &out->kekl[1]);
161 } else {
162 printk("Invalid KEKL number: %d\n", in->count);
163 BUG();
164 }
165}
166
167static int check_ext_kekl(struct tape390_kekl *kekl)
168{
169 if (kekl->type == TAPE390_KEKL_TYPE_NONE)
170 goto invalid;
171 if (kekl->type > TAPE390_KEKL_TYPE_HASH)
172 goto invalid;
173 if (kekl->type_on_tape == TAPE390_KEKL_TYPE_NONE)
174 goto invalid;
175 if (kekl->type_on_tape > TAPE390_KEKL_TYPE_HASH)
176 goto invalid;
177 if ((kekl->type == TAPE390_KEKL_TYPE_HASH) &&
178 (kekl->type_on_tape == TAPE390_KEKL_TYPE_LABEL))
179 goto invalid;
180
181 return 0;
182invalid:
183 return -EINVAL;
184}
185
186static int check_ext_kekl_pair(struct tape390_kekl_pair *kekls)
187{
188 if (check_ext_kekl(&kekls->kekl[0]))
189 goto invalid;
190 if (check_ext_kekl(&kekls->kekl[1]))
191 goto invalid;
192
193 return 0;
194invalid:
195 return -EINVAL;
196}
197
198/*
199 * Query KEKLs
200 */
201static int tape_3592_kekl_query(struct tape_device *device,
202 struct tape390_kekl_pair *ext_kekls)
203{
204 struct tape_request *request;
205 struct tape3592_kekl_query_order *order;
206 struct tape3592_kekl_query_data *int_kekls;
207 int rc;
208
209 DBF_EVENT(6, "tape3592_kekl_query\n");
210 int_kekls = kmalloc(sizeof(*int_kekls), GFP_KERNEL|GFP_DMA);
211 if (!int_kekls)
212 return -ENOMEM;
213 request = tape_alloc_request(2, sizeof(*order));
214 if (IS_ERR(request)) {
215 rc = PTR_ERR(request);
216 goto fail_malloc;
217 }
218 order = request->cpdata;
219 memset(order,0,sizeof(*order));
220 order->code = 0xe2;
221 order->max_count = 2;
222 request->op = TO_KEKL_QUERY;
223 tape_ccw_cc(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order);
224 tape_ccw_end(request->cpaddr + 1, READ_SS_DATA, sizeof(*int_kekls),
225 int_kekls);
226 rc = tape_do_io(device, request);
227 if (rc)
228 goto fail_request;
229 int_to_ext_kekl_pair(&int_kekls->kekls, ext_kekls);
230
231 rc = 0;
232fail_request:
233 tape_free_request(request);
234fail_malloc:
235 kfree(int_kekls);
236 return rc;
237}
238
239/*
240 * IOCTL: Query KEKLs
241 */
242static int tape_3592_ioctl_kekl_query(struct tape_device *device,
243 unsigned long arg)
244{
245 int rc;
246 struct tape390_kekl_pair *ext_kekls;
247
248 DBF_EVENT(6, "tape_3592_ioctl_kekl_query\n");
249 if (!crypt_supported(device))
250 return -ENOSYS;
251 if (!crypt_enabled(device))
252 return -EUNATCH;
253 ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
254 if (!ext_kekls)
255 return -ENOMEM;
256 rc = tape_3592_kekl_query(device, ext_kekls);
257 if (rc != 0)
258 goto fail;
259 if (copy_to_user((char __user *) arg, ext_kekls, sizeof(*ext_kekls))) {
260 rc = -EFAULT;
261 goto fail;
262 }
263 rc = 0;
264fail:
265 kfree(ext_kekls);
266 return rc;
267}
268
269static int tape_3590_mttell(struct tape_device *device, int mt_count);
270
271/*
272 * Set KEKLs
273 */
274static int tape_3592_kekl_set(struct tape_device *device,
275 struct tape390_kekl_pair *ext_kekls)
276{
277 struct tape_request *request;
278 struct tape3592_kekl_set_order *order;
279
280 DBF_EVENT(6, "tape3592_kekl_set\n");
281 if (check_ext_kekl_pair(ext_kekls)) {
282 DBF_EVENT(6, "invalid kekls\n");
283 return -EINVAL;
284 }
285 if (tape_3590_mttell(device, 0) != 0)
286 return -EBADSLT;
287 request = tape_alloc_request(1, sizeof(*order));
288 if (IS_ERR(request))
289 return PTR_ERR(request);
290 order = request->cpdata;
291 memset(order, 0, sizeof(*order));
292 order->code = 0xe3;
293 order->kekls.count = 2;
294 ext_to_int_kekl(&ext_kekls->kekl[0], &order->kekls.kekl[0]);
295 ext_to_int_kekl(&ext_kekls->kekl[1], &order->kekls.kekl[1]);
296 request->op = TO_KEKL_SET;
297 tape_ccw_end(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order);
298
299 return tape_do_io_free(device, request);
300}
301
302/*
303 * IOCTL: Set KEKLs
304 */
305static int tape_3592_ioctl_kekl_set(struct tape_device *device,
306 unsigned long arg)
307{
308 int rc;
309 struct tape390_kekl_pair *ext_kekls;
310
311 DBF_EVENT(6, "tape_3592_ioctl_kekl_set\n");
312 if (!crypt_supported(device))
313 return -ENOSYS;
314 if (!crypt_enabled(device))
315 return -EUNATCH;
316 ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
317 if (!ext_kekls)
318 return -ENOMEM;
319 if (copy_from_user(ext_kekls, (char __user *)arg, sizeof(*ext_kekls))) {
320 rc = -EFAULT;
321 goto out;
322 }
323 rc = tape_3592_kekl_set(device, ext_kekls);
324out:
325 kfree(ext_kekls);
326 return rc;
327}
328
329/*
330 * Enable encryption
331 */
332static int tape_3592_enable_crypt(struct tape_device *device)
333{
334 struct tape_request *request;
335 char *data;
336
337 DBF_EVENT(6, "tape_3592_enable_crypt\n");
338 if (!crypt_supported(device))
339 return -ENOSYS;
340 request = tape_alloc_request(2, 72);
341 if (IS_ERR(request))
342 return PTR_ERR(request);
343 data = request->cpdata;
344 memset(data,0,72);
345
346 data[0] = 0x05;
347 data[36 + 0] = 0x03;
348 data[36 + 1] = 0x03;
349 data[36 + 4] = 0x40;
350 data[36 + 6] = 0x01;
351 data[36 + 14] = 0x2f;
352 data[36 + 18] = 0xc3;
353 data[36 + 35] = 0x72;
354 request->op = TO_CRYPT_ON;
355 tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
356 tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
357 return tape_do_io_free(device, request);
358}
359
360/*
361 * Disable encryption
362 */
363static int tape_3592_disable_crypt(struct tape_device *device)
364{
365 struct tape_request *request;
366 char *data;
367
368 DBF_EVENT(6, "tape_3592_disable_crypt\n");
369 if (!crypt_supported(device))
370 return -ENOSYS;
371 request = tape_alloc_request(2, 72);
372 if (IS_ERR(request))
373 return PTR_ERR(request);
374 data = request->cpdata;
375 memset(data,0,72);
376
377 data[0] = 0x05;
378 data[36 + 0] = 0x03;
379 data[36 + 1] = 0x03;
380 data[36 + 35] = 0x32;
381
382 request->op = TO_CRYPT_OFF;
383 tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
384 tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
385
386 return tape_do_io_free(device, request);
387}
388
389/*
390 * IOCTL: Set encryption status
391 */
392static int tape_3592_ioctl_crypt_set(struct tape_device *device,
393 unsigned long arg)
394{
395 struct tape390_crypt_info info;
396
397 DBF_EVENT(6, "tape_3592_ioctl_crypt_set\n");
398 if (!crypt_supported(device))
399 return -ENOSYS;
400 if (copy_from_user(&info, (char __user *)arg, sizeof(info)))
401 return -EFAULT;
402 if (info.status & ~TAPE390_CRYPT_ON_MASK)
403 return -EINVAL;
404 if (info.status & TAPE390_CRYPT_ON_MASK)
405 return tape_3592_enable_crypt(device);
406 else
407 return tape_3592_disable_crypt(device);
408}
409
410static int tape_3590_sense_medium(struct tape_device *device);
411
412/*
413 * IOCTL: Query enryption status
414 */
415static int tape_3592_ioctl_crypt_query(struct tape_device *device,
416 unsigned long arg)
417{
418 DBF_EVENT(6, "tape_3592_ioctl_crypt_query\n");
419 if (!crypt_supported(device))
420 return -ENOSYS;
421 tape_3590_sense_medium(device);
422 if (copy_to_user((char __user *) arg, &TAPE_3590_CRYPT_INFO(device),
423 sizeof(TAPE_3590_CRYPT_INFO(device))))
424 return -EFAULT;
425 else
426 return 0;
427}
428
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800429/*
430 * 3590 IOCTL Overload
431 */
432static int
433tape_3590_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
434{
435 switch (cmd) {
436 case TAPE390_DISPLAY: {
437 struct display_struct disp;
438
439 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)))
440 return -EFAULT;
441
442 return tape_std_display(device, &disp);
443 }
Michael Holzheucced1dd2007-02-05 21:18:26 +0100444 case TAPE390_KEKL_SET:
445 return tape_3592_ioctl_kekl_set(device, arg);
446 case TAPE390_KEKL_QUERY:
447 return tape_3592_ioctl_kekl_query(device, arg);
448 case TAPE390_CRYPT_SET:
449 return tape_3592_ioctl_crypt_set(device, arg);
450 case TAPE390_CRYPT_QUERY:
451 return tape_3592_ioctl_crypt_query(device, arg);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800452 default:
453 return -EINVAL; /* no additional ioctls */
454 }
455}
456
457/*
458 * SENSE Medium: Get Sense data about medium state
459 */
460static int
461tape_3590_sense_medium(struct tape_device *device)
462{
463 struct tape_request *request;
464
465 request = tape_alloc_request(1, 128);
466 if (IS_ERR(request))
467 return PTR_ERR(request);
468 request->op = TO_MSEN;
469 tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
470 return tape_do_io_free(device, request);
471}
472
473/*
474 * MTTELL: Tell block. Return the number of block relative to current file.
475 */
476static int
477tape_3590_mttell(struct tape_device *device, int mt_count)
478{
479 __u64 block_id;
480 int rc;
481
482 rc = tape_std_read_block_id(device, &block_id);
483 if (rc)
484 return rc;
485 return block_id >> 32;
486}
487
488/*
489 * MTSEEK: seek to the specified block.
490 */
491static int
492tape_3590_mtseek(struct tape_device *device, int count)
493{
494 struct tape_request *request;
495
496 DBF_EVENT(6, "xsee id: %x\n", count);
497 request = tape_alloc_request(3, 4);
498 if (IS_ERR(request))
499 return PTR_ERR(request);
500 request->op = TO_LBL;
501 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
502 *(__u32 *) request->cpdata = count;
503 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
504 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
505 return tape_do_io_free(device, request);
506}
507
508/*
509 * Read Opposite Error Recovery Function:
510 * Used, when Read Forward does not work
511 */
512static void
513tape_3590_read_opposite(struct tape_device *device,
514 struct tape_request *request)
515{
516 struct tape_3590_disc_data *data;
517
518 /*
519 * We have allocated 4 ccws in tape_std_read, so we can now
520 * transform the request to a read backward, followed by a
521 * forward space block.
522 */
523 request->op = TO_RBA;
524 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
525 data = device->discdata;
526 tape_ccw_cc_idal(request->cpaddr + 1, data->read_back_op,
527 device->char_data.idal_buf);
528 tape_ccw_cc(request->cpaddr + 2, FORSPACEBLOCK, 0, NULL);
529 tape_ccw_end(request->cpaddr + 3, NOP, 0, NULL);
530 DBF_EVENT(6, "xrop ccwg\n");
531}
532
533/*
534 * Read Attention Msg
535 * This should be done after an interrupt with attention bit (0x80)
536 * in device state.
537 *
538 * After a "read attention message" request there are two possible
539 * results:
540 *
541 * 1. A unit check is presented, when attention sense is present (e.g. when
542 * a medium has been unloaded). The attention sense comes then
543 * together with the unit check. The recovery action is either "retry"
544 * (in case there is an attention message pending) or "permanent error".
545 *
546 * 2. The attention msg is written to the "read subsystem data" buffer.
547 * In this case we probably should print it to the console.
548 */
549static int
550tape_3590_read_attmsg(struct tape_device *device)
551{
552 struct tape_request *request;
553 char *buf;
554
555 request = tape_alloc_request(3, 4096);
556 if (IS_ERR(request))
557 return PTR_ERR(request);
558 request->op = TO_READ_ATTMSG;
559 buf = request->cpdata;
560 buf[0] = PREP_RD_SS_DATA;
561 buf[6] = RD_ATTMSG; /* read att msg */
562 tape_ccw_cc(request->cpaddr, PERFORM_SS_FUNC, 12, buf);
563 tape_ccw_cc(request->cpaddr + 1, READ_SS_DATA, 4096 - 12, buf + 12);
564 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
565 return tape_do_io_free(device, request);
566}
567
568/*
569 * These functions are used to schedule follow-up actions from within an
570 * interrupt context (like unsolicited interrupts).
571 */
Stefan Bader2cc924b2006-04-27 18:40:16 -0700572struct work_handler_data {
573 struct tape_device *device;
574 enum tape_op op;
575 struct work_struct work;
576};
577
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800578static void
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100579tape_3590_work_handler(struct work_struct *work)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800580{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100581 struct work_handler_data *p =
582 container_of(work, struct work_handler_data, work);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800583
584 switch (p->op) {
585 case TO_MSEN:
586 tape_3590_sense_medium(p->device);
587 break;
588 case TO_READ_ATTMSG:
589 tape_3590_read_attmsg(p->device);
590 break;
Michael Holzheucced1dd2007-02-05 21:18:26 +0100591 case TO_CRYPT_ON:
592 tape_3592_enable_crypt(p->device);
593 break;
594 case TO_CRYPT_OFF:
595 tape_3592_disable_crypt(p->device);
596 break;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800597 default:
598 DBF_EVENT(3, "T3590: work handler undefined for "
599 "operation 0x%02x\n", p->op);
600 }
601 tape_put_device(p->device);
602 kfree(p);
603}
604
605static int
606tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
607{
Stefan Bader2cc924b2006-04-27 18:40:16 -0700608 struct work_handler_data *p;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800609
610 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
611 return -ENOMEM;
612
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100613 INIT_WORK(&p->work, tape_3590_work_handler);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800614
Martin Schwidefsky8fd138c2009-12-07 12:52:03 +0100615 p->device = tape_get_device(device);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800616 p->op = op;
617
Tejun Heo6dca4672010-12-24 16:00:18 +0100618 queue_work(tape_3590_wq, &p->work);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800619 return 0;
620}
621
622#ifdef CONFIG_S390_TAPE_BLOCK
623/*
624 * Tape Block READ
625 */
626static struct tape_request *
627tape_3590_bread(struct tape_device *device, struct request *req)
628{
629 struct tape_request *request;
630 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +0200631 int count = 0, start_block;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800632 unsigned off;
633 char *dst;
634 struct bio_vec *bv;
NeilBrown5705f702007-09-25 12:35:59 +0200635 struct req_iterator iter;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800636
637 DBF_EVENT(6, "xBREDid:");
Tejun Heo83096eb2009-05-07 22:24:39 +0900638 start_block = blk_rq_pos(req) >> TAPEBLOCK_HSEC_S2B;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800639 DBF_EVENT(6, "start_block = %i\n", start_block);
640
NeilBrown5705f702007-09-25 12:35:59 +0200641 rq_for_each_segment(bv, req, iter)
642 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
643
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800644 request = tape_alloc_request(2 + count + 1, 4);
645 if (IS_ERR(request))
646 return request;
647 request->op = TO_BLOCK;
648 *(__u32 *) request->cpdata = start_block;
649 ccw = request->cpaddr;
650 ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);
651
652 /*
653 * We always setup a nop after the mode set ccw. This slot is
654 * used in tape_std_check_locate to insert a locate ccw if the
655 * current tape position doesn't match the start block to be read.
656 */
657 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
658
NeilBrown5705f702007-09-25 12:35:59 +0200659 rq_for_each_segment(bv, req, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +0200660 dst = page_address(bv->bv_page) + bv->bv_offset;
661 for (off = 0; off < bv->bv_len; off += TAPEBLOCK_HSEC_SIZE) {
662 ccw->flags = CCW_FLAG_CC;
663 ccw->cmd_code = READ_FORWARD;
664 ccw->count = TAPEBLOCK_HSEC_SIZE;
665 set_normalized_cda(ccw, (void *) __pa(dst));
666 ccw++;
667 dst += TAPEBLOCK_HSEC_SIZE;
668 }
Stoyan Gaydarov6aa0d3a2009-03-26 15:24:47 +0100669 BUG_ON(off > bv->bv_len);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800670 }
671 ccw = tape_ccw_end(ccw, NOP, 0, NULL);
672 DBF_EVENT(6, "xBREDccwg\n");
673 return request;
674}
675
676static void
677tape_3590_free_bread(struct tape_request *request)
678{
679 struct ccw1 *ccw;
680
681 /* Last ccw is a nop and doesn't need clear_normalized_cda */
682 for (ccw = request->cpaddr; ccw->flags & CCW_FLAG_CC; ccw++)
683 if (ccw->cmd_code == READ_FORWARD)
684 clear_normalized_cda(ccw);
685 tape_free_request(request);
686}
687
688/*
689 * check_locate is called just before the tape request is passed to
690 * the common io layer for execution. It has to check the current
691 * tape position and insert a locate ccw if it doesn't match the
692 * start block for the request.
693 */
694static void
695tape_3590_check_locate(struct tape_device *device, struct tape_request *request)
696{
697 __u32 *start_block;
698
699 start_block = (__u32 *) request->cpdata;
700 if (*start_block != device->blk_data.block_position) {
701 /* Add the start offset of the file to get the real block. */
702 *start_block += device->bof;
703 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
704 }
705}
706#endif
707
Michael Holzheucced1dd2007-02-05 21:18:26 +0100708static void tape_3590_med_state_set(struct tape_device *device,
709 struct tape_3590_med_sense *sense)
710{
711 struct tape390_crypt_info *c_info;
712
713 c_info = &TAPE_3590_CRYPT_INFO(device);
714
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200715 DBF_EVENT(6, "medium state: %x:%x\n", sense->macst, sense->masst);
716 switch (sense->macst) {
717 case 0x04:
718 case 0x05:
719 case 0x06:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100720 tape_med_state_set(device, MS_UNLOADED);
721 TAPE_3590_CRYPT_INFO(device).medium_status = 0;
722 return;
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200723 case 0x08:
724 case 0x09:
725 tape_med_state_set(device, MS_LOADED);
726 break;
727 default:
728 tape_med_state_set(device, MS_UNKNOWN);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100729 return;
730 }
Michael Holzheucced1dd2007-02-05 21:18:26 +0100731 c_info->medium_status |= TAPE390_MEDIUM_LOADED_MASK;
732 if (sense->flags & MSENSE_CRYPT_MASK) {
Carsten Otteab640db2009-03-26 15:24:38 +0100733 DBF_EVENT(6, "Medium is encrypted (%04x)\n", sense->flags);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100734 c_info->medium_status |= TAPE390_MEDIUM_ENCRYPTED_MASK;
735 } else {
736 DBF_EVENT(6, "Medium is not encrypted %04x\n", sense->flags);
737 c_info->medium_status &= ~TAPE390_MEDIUM_ENCRYPTED_MASK;
738 }
739}
740
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800741/*
742 * The done handler is called at device/channel end and wakes up the sleeping
743 * process
744 */
745static int
746tape_3590_done(struct tape_device *device, struct tape_request *request)
747{
Michael Holzheucced1dd2007-02-05 21:18:26 +0100748 struct tape_3590_disc_data *disc_data;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800749
750 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100751 disc_data = device->discdata;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800752
753 switch (request->op) {
754 case TO_BSB:
755 case TO_BSF:
756 case TO_DSE:
757 case TO_FSB:
758 case TO_FSF:
759 case TO_LBL:
760 case TO_RFO:
761 case TO_RBA:
762 case TO_REW:
763 case TO_WRI:
764 case TO_WTM:
765 case TO_BLOCK:
766 case TO_LOAD:
767 tape_med_state_set(device, MS_LOADED);
768 break;
769 case TO_RUN:
770 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100771 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800772 break;
773 case TO_MSEN:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100774 tape_3590_med_state_set(device, request->cpdata);
775 break;
776 case TO_CRYPT_ON:
777 TAPE_3590_CRYPT_INFO(device).status
778 |= TAPE390_CRYPT_ON_MASK;
779 *(device->modeset_byte) |= 0x03;
780 break;
781 case TO_CRYPT_OFF:
782 TAPE_3590_CRYPT_INFO(device).status
783 &= ~TAPE390_CRYPT_ON_MASK;
784 *(device->modeset_byte) &= ~0x03;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800785 break;
786 case TO_RBI: /* RBI seems to succeed even without medium loaded. */
787 case TO_NOP: /* Same to NOP. */
788 case TO_READ_CONFIG:
789 case TO_READ_ATTMSG:
790 case TO_DIS:
791 case TO_ASSIGN:
792 case TO_UNASSIGN:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800793 case TO_SIZE:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100794 case TO_KEKL_SET:
795 case TO_KEKL_QUERY:
Michael Holzheue2963062007-05-04 18:47:53 +0200796 case TO_RDC:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800797 break;
798 }
799 return TAPE_IO_SUCCESS;
800}
801
802/*
Stefan Weileef35c22010-08-06 21:11:15 +0200803 * This function is called, when error recovery was successful
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800804 */
805static inline int
806tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request)
807{
Coly Li73ac36e2009-01-07 18:09:16 -0800808 DBF_EVENT(3, "Error Recovery successful for %s\n",
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800809 tape_op_verbose[request->op]);
810 return tape_3590_done(device, request);
811}
812
813/*
Stefan Weileef35c22010-08-06 21:11:15 +0200814 * This function is called, when error recovery was not successful
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800815 */
816static inline int
817tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
818 struct irb *irb, int rc)
819{
820 DBF_EVENT(3, "Error Recovery failed for %s\n",
821 tape_op_verbose[request->op]);
822 tape_dump_sense_dbf(device, request, irb);
823 return rc;
824}
825
826/*
827 * Error Recovery do retry
828 */
829static inline int
830tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
831 struct irb *irb)
832{
833 DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]);
834 tape_dump_sense_dbf(device, request, irb);
835 return TAPE_IO_RETRY;
836}
837
838/*
839 * Handle unsolicited interrupts
840 */
841static int
842tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
843{
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200844 if (irb->scsw.cmd.dstat == DEV_STAT_CHN_END)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800845 /* Probably result of halt ssch */
846 return TAPE_IO_PENDING;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200847 else if (irb->scsw.cmd.dstat == 0x85)
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200848 /* Device Ready */
849 DBF_EVENT(3, "unsol.irq! tape ready: %08x\n", device->cdev_id);
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200850 else if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800851 tape_3590_schedule_work(device, TO_READ_ATTMSG);
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200852 } else {
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800853 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
Carsten Otteab640db2009-03-26 15:24:38 +0100854 tape_dump_sense_dbf(device, NULL, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800855 }
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200856 /* check medium state */
857 tape_3590_schedule_work(device, TO_MSEN);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800858 return TAPE_IO_SUCCESS;
859}
860
861/*
862 * Basic Recovery routine
863 */
864static int
865tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
866 struct irb *irb, int rc)
867{
868 struct tape_3590_sense *sense;
869
870 sense = (struct tape_3590_sense *) irb->ecw;
871
872 switch (sense->bra) {
873 case SENSE_BRA_PER:
874 return tape_3590_erp_failed(device, request, irb, rc);
875 case SENSE_BRA_CONT:
876 return tape_3590_erp_succeded(device, request);
877 case SENSE_BRA_RE:
878 return tape_3590_erp_retry(device, request, irb);
879 case SENSE_BRA_DRE:
880 return tape_3590_erp_failed(device, request, irb, rc);
881 default:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800882 BUG();
883 return TAPE_IO_STOP;
884 }
885}
886
887/*
888 * RDL: Read Device (buffered) log
889 */
890static int
891tape_3590_erp_read_buf_log(struct tape_device *device,
892 struct tape_request *request, struct irb *irb)
893{
894 /*
895 * We just do the basic error recovery at the moment (retry).
896 * Perhaps in the future, we read the log and dump it somewhere...
897 */
898 return tape_3590_erp_basic(device, request, irb, -EIO);
899}
900
901/*
902 * SWAP: Swap Devices
903 */
904static int
905tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
906 struct irb *irb)
907{
908 /*
909 * This error recovery should swap the tapes
910 * if the original has a problem. The operation
911 * should proceed with the new tape... this
912 * should probably be done in user space!
913 */
Carsten Otteab640db2009-03-26 15:24:38 +0100914 dev_warn (&device->cdev->dev, "The tape medium must be loaded into a "
915 "different tape unit\n");
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800916 return tape_3590_erp_basic(device, request, irb, -EIO);
917}
918
919/*
920 * LBY: Long Busy
921 */
922static int
923tape_3590_erp_long_busy(struct tape_device *device,
924 struct tape_request *request, struct irb *irb)
925{
Michael Holzheucced1dd2007-02-05 21:18:26 +0100926 DBF_EVENT(6, "Device is busy\n");
927 return TAPE_IO_LONG_BUSY;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800928}
929
930/*
931 * SPI: Special Intercept
932 */
933static int
934tape_3590_erp_special_interrupt(struct tape_device *device,
935 struct tape_request *request, struct irb *irb)
936{
937 return tape_3590_erp_basic(device, request, irb, -EIO);
938}
939
940/*
941 * RDA: Read Alternate
942 */
943static int
944tape_3590_erp_read_alternate(struct tape_device *device,
945 struct tape_request *request, struct irb *irb)
946{
947 struct tape_3590_disc_data *data;
948
949 /*
950 * The issued Read Backward or Read Previous command is not
951 * supported by the device
952 * The recovery action should be to issue another command:
953 * Read Revious: if Read Backward is not supported
954 * Read Backward: if Read Previous is not supported
955 */
956 data = device->discdata;
957 if (data->read_back_op == READ_PREVIOUS) {
958 DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
959 device->cdev_id);
960 data->read_back_op = READ_BACKWARD;
961 } else {
962 DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
963 device->cdev_id);
964 data->read_back_op = READ_PREVIOUS;
965 }
966 tape_3590_read_opposite(device, request);
967 return tape_3590_erp_retry(device, request, irb);
968}
969
970/*
971 * Error Recovery read opposite
972 */
973static int
974tape_3590_erp_read_opposite(struct tape_device *device,
975 struct tape_request *request, struct irb *irb)
976{
977 switch (request->op) {
978 case TO_RFO:
979 /*
980 * We did read forward, but the data could not be read.
981 * We will read backward and then skip forward again.
982 */
983 tape_3590_read_opposite(device, request);
984 return tape_3590_erp_retry(device, request, irb);
985 case TO_RBA:
986 /* We tried to read forward and backward, but hat no success */
987 return tape_3590_erp_failed(device, request, irb, -EIO);
988 break;
989 default:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800990 return tape_3590_erp_failed(device, request, irb, -EIO);
991 }
992}
993
994/*
995 * Print an MIM (Media Information Message) (message code f0)
996 */
997static void
998tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
999{
1000 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +01001001 char *exception, *service;
1002
1003 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1004 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1005
1006 if (!exception || !service)
1007 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001008
1009 sense = (struct tape_3590_sense *) irb->ecw;
1010 /* Exception Message */
1011 switch (sense->fmt.f70.emc) {
1012 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001013 snprintf(exception, BUFSIZE, "Data degraded");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001014 break;
1015 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001016 snprintf(exception, BUFSIZE, "Data degraded in partion %i",
1017 sense->fmt.f70.mp);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001018 break;
1019 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001020 snprintf(exception, BUFSIZE, "Medium degraded");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001021 break;
1022 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001023 snprintf(exception, BUFSIZE, "Medium degraded in partition %i",
1024 sense->fmt.f70.mp);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001025 break;
1026 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001027 snprintf(exception, BUFSIZE, "Block 0 Error");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001028 break;
1029 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001030 snprintf(exception, BUFSIZE, "Medium Exception 0x%02x",
1031 sense->fmt.f70.md);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001032 break;
1033 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001034 snprintf(exception, BUFSIZE, "0x%02x",
1035 sense->fmt.f70.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001036 break;
1037 }
1038 /* Service Message */
1039 switch (sense->fmt.f70.smc) {
1040 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001041 snprintf(service, BUFSIZE, "Reference Media maintenance "
1042 "procedure %i", sense->fmt.f70.md);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001043 break;
1044 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001045 snprintf(service, BUFSIZE, "0x%02x",
1046 sense->fmt.f70.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001047 break;
1048 }
Carsten Otteab640db2009-03-26 15:24:38 +01001049
1050 dev_warn (&device->cdev->dev, "Tape media information: exception %s, "
1051 "service %s\n", exception, service);
1052
1053out_nomem:
1054 kfree(exception);
1055 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001056}
1057
1058/*
1059 * Print an I/O Subsystem Service Information Message (message code f1)
1060 */
1061static void
1062tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
1063{
1064 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +01001065 char *exception, *service;
1066
1067 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1068 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1069
1070 if (!exception || !service)
1071 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001072
1073 sense = (struct tape_3590_sense *) irb->ecw;
1074 /* Exception Message */
1075 switch (sense->fmt.f71.emc) {
1076 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001077 snprintf(exception, BUFSIZE, "Effect of failure is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001078 break;
1079 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001080 snprintf(exception, BUFSIZE, "CU Exception - no performance "
1081 "impact");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001082 break;
1083 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001084 snprintf(exception, BUFSIZE, "CU Exception on channel "
1085 "interface 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001086 break;
1087 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001088 snprintf(exception, BUFSIZE, "CU Exception on device path "
1089 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001090 break;
1091 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001092 snprintf(exception, BUFSIZE, "CU Exception on library path "
1093 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001094 break;
1095 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001096 snprintf(exception, BUFSIZE, "CU Exception on node 0x%02x",
1097 sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001098 break;
1099 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001100 snprintf(exception, BUFSIZE, "CU Exception on partition "
1101 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001102 break;
1103 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001104 snprintf(exception, BUFSIZE, "0x%02x",
1105 sense->fmt.f71.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001106 }
1107 /* Service Message */
1108 switch (sense->fmt.f71.smc) {
1109 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001110 snprintf(service, BUFSIZE, "Repair impact is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001111 break;
1112 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001113 snprintf(service, BUFSIZE, "Repair will not impact cu "
1114 "performance");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001115 break;
1116 case 0x03:
1117 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001118 snprintf(service, BUFSIZE, "Repair will disable node "
1119 "0x%x on CU", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001120 else
Carsten Otteab640db2009-03-26 15:24:38 +01001121 snprintf(service, BUFSIZE, "Repair will disable "
1122 "nodes (0x%x-0x%x) on CU", sense->fmt.f71.md[1],
1123 sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001124 break;
1125 case 0x04:
1126 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001127 snprintf(service, BUFSIZE, "Repair will disable "
1128 "channel path 0x%x on CU",
1129 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001130 else
Carsten Otteab640db2009-03-26 15:24:38 +01001131 snprintf(service, BUFSIZE, "Repair will disable cannel"
1132 " paths (0x%x-0x%x) on CU",
1133 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001134 break;
1135 case 0x05:
1136 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001137 snprintf(service, BUFSIZE, "Repair will disable device"
1138 " path 0x%x on CU", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001139 else
Carsten Otteab640db2009-03-26 15:24:38 +01001140 snprintf(service, BUFSIZE, "Repair will disable device"
1141 " paths (0x%x-0x%x) on CU",
1142 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001143 break;
1144 case 0x06:
1145 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001146 snprintf(service, BUFSIZE, "Repair will disable "
1147 "library path 0x%x on CU",
1148 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001149 else
Carsten Otteab640db2009-03-26 15:24:38 +01001150 snprintf(service, BUFSIZE, "Repair will disable "
1151 "library paths (0x%x-0x%x) on CU",
1152 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001153 break;
1154 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001155 snprintf(service, BUFSIZE, "Repair will disable access to CU");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001156 break;
1157 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001158 snprintf(service, BUFSIZE, "0x%02x",
1159 sense->fmt.f71.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001160 }
Carsten Otteab640db2009-03-26 15:24:38 +01001161
1162 dev_warn (&device->cdev->dev, "I/O subsystem information: exception"
1163 " %s, service %s\n", exception, service);
1164out_nomem:
1165 kfree(exception);
1166 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001167}
1168
1169/*
1170 * Print an Device Subsystem Service Information Message (message code f2)
1171 */
1172static void
1173tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
1174{
1175 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +01001176 char *exception, *service;
1177
1178 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1179 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1180
1181 if (!exception || !service)
1182 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001183
1184 sense = (struct tape_3590_sense *) irb->ecw;
1185 /* Exception Message */
1186 switch (sense->fmt.f71.emc) {
1187 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001188 snprintf(exception, BUFSIZE, "Effect of failure is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001189 break;
1190 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001191 snprintf(exception, BUFSIZE, "DV Exception - no performance"
1192 " impact");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001193 break;
1194 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001195 snprintf(exception, BUFSIZE, "DV Exception on channel "
1196 "interface 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001197 break;
1198 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001199 snprintf(exception, BUFSIZE, "DV Exception on loader 0x%02x",
1200 sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001201 break;
1202 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001203 snprintf(exception, BUFSIZE, "DV Exception on message display"
1204 " 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001205 break;
1206 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001207 snprintf(exception, BUFSIZE, "DV Exception in tape path");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001208 break;
1209 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001210 snprintf(exception, BUFSIZE, "DV Exception in drive");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001211 break;
1212 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001213 snprintf(exception, BUFSIZE, "0x%02x",
1214 sense->fmt.f71.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001215 }
1216 /* Service Message */
1217 switch (sense->fmt.f71.smc) {
1218 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001219 snprintf(service, BUFSIZE, "Repair impact is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001220 break;
1221 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001222 snprintf(service, BUFSIZE, "Repair will not impact device "
1223 "performance");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001224 break;
1225 case 0x03:
1226 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001227 snprintf(service, BUFSIZE, "Repair will disable "
1228 "channel path 0x%x on DV",
1229 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001230 else
Carsten Otteab640db2009-03-26 15:24:38 +01001231 snprintf(service, BUFSIZE, "Repair will disable "
1232 "channel path (0x%x-0x%x) on DV",
1233 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001234 break;
1235 case 0x04:
1236 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001237 snprintf(service, BUFSIZE, "Repair will disable "
1238 "interface 0x%x on DV", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001239 else
Carsten Otteab640db2009-03-26 15:24:38 +01001240 snprintf(service, BUFSIZE, "Repair will disable "
1241 "interfaces (0x%x-0x%x) on DV",
1242 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001243 break;
1244 case 0x05:
1245 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001246 snprintf(service, BUFSIZE, "Repair will disable loader"
1247 " 0x%x on DV", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001248 else
Carsten Otteab640db2009-03-26 15:24:38 +01001249 snprintf(service, BUFSIZE, "Repair will disable loader"
1250 " (0x%x-0x%x) on DV",
1251 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001252 break;
1253 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001254 snprintf(service, BUFSIZE, "Repair will disable access to DV");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001255 break;
1256 case 0x08:
1257 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001258 snprintf(service, BUFSIZE, "Repair will disable "
1259 "message display 0x%x on DV",
1260 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001261 else
Carsten Otteab640db2009-03-26 15:24:38 +01001262 snprintf(service, BUFSIZE, "Repair will disable "
1263 "message displays (0x%x-0x%x) on DV",
1264 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001265 break;
1266 case 0x09:
Carsten Otteab640db2009-03-26 15:24:38 +01001267 snprintf(service, BUFSIZE, "Clean DV");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001268 break;
1269 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001270 snprintf(service, BUFSIZE, "0x%02x",
1271 sense->fmt.f71.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001272 }
Carsten Otteab640db2009-03-26 15:24:38 +01001273
1274 dev_warn (&device->cdev->dev, "Device subsystem information: exception"
1275 " %s, service %s\n", exception, service);
1276out_nomem:
1277 kfree(exception);
1278 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001279}
1280
1281/*
1282 * Print standard ERA Message
1283 */
1284static void
1285tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
1286{
1287 struct tape_3590_sense *sense;
1288
1289 sense = (struct tape_3590_sense *) irb->ecw;
1290 if (sense->mc == 0)
1291 return;
1292 if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) {
1293 if (tape_3590_msg[sense->mc] != NULL)
Carsten Otteab640db2009-03-26 15:24:38 +01001294 dev_warn (&device->cdev->dev, "The tape unit has "
1295 "issued sense message %s\n",
1296 tape_3590_msg[sense->mc]);
1297 else
1298 dev_warn (&device->cdev->dev, "The tape unit has "
1299 "issued an unknown sense message code 0x%x\n",
1300 sense->mc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001301 return;
1302 }
1303 if (sense->mc == 0xf0) {
1304 /* Standard Media Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001305 dev_warn (&device->cdev->dev, "MIM SEV=%i, MC=%02x, ES=%x/%x, "
1306 "RC=%02x-%04x-%02x\n", sense->fmt.f70.sev, sense->mc,
1307 sense->fmt.f70.emc, sense->fmt.f70.smc,
1308 sense->fmt.f70.refcode, sense->fmt.f70.mid,
1309 sense->fmt.f70.fid);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001310 tape_3590_print_mim_msg_f0(device, irb);
1311 return;
1312 }
1313 if (sense->mc == 0xf1) {
1314 /* Standard I/O Subsystem Service Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001315 dev_warn (&device->cdev->dev, "IOSIM SEV=%i, DEVTYPE=3590/%02x,"
1316 " MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1317 sense->fmt.f71.sev, device->cdev->id.dev_model,
1318 sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1319 sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1320 sense->fmt.f71.refcode3);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001321 tape_3590_print_io_sim_msg_f1(device, irb);
1322 return;
1323 }
1324 if (sense->mc == 0xf2) {
1325 /* Standard Device Service Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001326 dev_warn (&device->cdev->dev, "DEVSIM SEV=%i, DEVTYPE=3590/%02x"
1327 ", MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1328 sense->fmt.f71.sev, device->cdev->id.dev_model,
1329 sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1330 sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1331 sense->fmt.f71.refcode3);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001332 tape_3590_print_dev_sim_msg_f2(device, irb);
1333 return;
1334 }
1335 if (sense->mc == 0xf3) {
1336 /* Standard Library Service Information Message */
1337 return;
1338 }
Carsten Otteab640db2009-03-26 15:24:38 +01001339 dev_warn (&device->cdev->dev, "The tape unit has issued an unknown "
1340 "sense message code %x\n", sense->mc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001341}
1342
Michael Holzheucced1dd2007-02-05 21:18:26 +01001343static int tape_3590_crypt_error(struct tape_device *device,
1344 struct tape_request *request, struct irb *irb)
1345{
1346 u8 cu_rc, ekm_rc1;
1347 u16 ekm_rc2;
1348 u32 drv_rc;
Kay Sievers2a0217d2008-10-10 21:33:09 +02001349 const char *bus_id;
1350 char *sense;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001351
1352 sense = ((struct tape_3590_sense *) irb->ecw)->fmt.data;
Kay Sievers2a0217d2008-10-10 21:33:09 +02001353 bus_id = dev_name(&device->cdev->dev);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001354 cu_rc = sense[0];
1355 drv_rc = *((u32*) &sense[5]) & 0xffffff;
1356 ekm_rc1 = sense[9];
1357 ekm_rc2 = *((u16*) &sense[10]);
1358 if ((cu_rc == 0) && (ekm_rc2 == 0xee31))
1359 /* key not defined on EKM */
1360 return tape_3590_erp_basic(device, request, irb, -EKEYREJECTED);
1361 if ((cu_rc == 1) || (cu_rc == 2))
1362 /* No connection to EKM */
1363 return tape_3590_erp_basic(device, request, irb, -ENOTCONN);
1364
Carsten Otteab640db2009-03-26 15:24:38 +01001365 dev_err (&device->cdev->dev, "The tape unit failed to obtain the "
1366 "encryption key from EKM\n");
Michael Holzheucced1dd2007-02-05 21:18:26 +01001367
1368 return tape_3590_erp_basic(device, request, irb, -ENOKEY);
1369}
1370
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001371/*
1372 * 3590 error Recovery routine:
1373 * If possible, it tries to recover from the error. If this is not possible,
1374 * inform the user about the problem.
1375 */
1376static int
1377tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
1378 struct irb *irb)
1379{
1380 struct tape_3590_sense *sense;
1381 int rc;
1382
1383#ifdef CONFIG_S390_TAPE_BLOCK
1384 if (request->op == TO_BLOCK) {
1385 /*
1386 * Recovery for block device requests. Set the block_position
1387 * to something invalid and retry.
1388 */
1389 device->blk_data.block_position = -1;
1390 if (request->retries-- <= 0)
1391 return tape_3590_erp_failed(device, request, irb, -EIO);
1392 else
1393 return tape_3590_erp_retry(device, request, irb);
1394 }
1395#endif
1396
1397 sense = (struct tape_3590_sense *) irb->ecw;
1398
Michael Holzheucced1dd2007-02-05 21:18:26 +01001399 DBF_EVENT(6, "Unit Check: RQC = %x\n", sense->rc_rqc);
1400
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001401 /*
1402 * First check all RC-QRCs where we want to do something special
1403 * - "break": basic error recovery is done
1404 * - "goto out:": just print error message if available
1405 */
1406 rc = -EIO;
1407 switch (sense->rc_rqc) {
1408
1409 case 0x1110:
1410 tape_3590_print_era_msg(device, irb);
1411 return tape_3590_erp_read_buf_log(device, request, irb);
1412
1413 case 0x2011:
1414 tape_3590_print_era_msg(device, irb);
1415 return tape_3590_erp_read_alternate(device, request, irb);
1416
1417 case 0x2230:
1418 case 0x2231:
1419 tape_3590_print_era_msg(device, irb);
1420 return tape_3590_erp_special_interrupt(device, request, irb);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001421 case 0x2240:
1422 return tape_3590_crypt_error(device, request, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001423
1424 case 0x3010:
1425 DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1426 device->cdev_id);
1427 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1428 case 0x3012:
1429 DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1430 device->cdev_id);
1431 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1432 case 0x3020:
1433 DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
1434 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1435
1436 case 0x3122:
1437 DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1438 device->cdev_id);
1439 return tape_3590_erp_basic(device, request, irb, -EIO);
1440 case 0x3123:
1441 DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1442 device->cdev_id);
1443 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001444 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001445 return tape_3590_erp_basic(device, request, irb, 0);
1446
1447 case 0x4010:
1448 /*
1449 * print additional msg since default msg
1450 * "device intervention" is not very meaningfull
1451 */
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001452 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001453 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001454 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1455 case 0x4012: /* Device Long Busy */
Michael Holzheucced1dd2007-02-05 21:18:26 +01001456 /* XXX: Also use long busy handling here? */
1457 DBF_EVENT(6, "(%08x): LONG BUSY\n", device->cdev_id);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001458 tape_3590_print_era_msg(device, irb);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001459 return tape_3590_erp_basic(device, request, irb, -EBUSY);
1460 case 0x4014:
1461 DBF_EVENT(6, "(%08x): Crypto LONG BUSY\n", device->cdev_id);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001462 return tape_3590_erp_long_busy(device, request, irb);
1463
1464 case 0x5010:
1465 if (sense->rac == 0xd0) {
1466 /* Swap */
1467 tape_3590_print_era_msg(device, irb);
1468 return tape_3590_erp_swap(device, request, irb);
1469 }
1470 if (sense->rac == 0x26) {
1471 /* Read Opposite */
1472 tape_3590_print_era_msg(device, irb);
1473 return tape_3590_erp_read_opposite(device, request,
1474 irb);
1475 }
1476 return tape_3590_erp_basic(device, request, irb, -EIO);
1477 case 0x5020:
1478 case 0x5021:
1479 case 0x5022:
1480 case 0x5040:
1481 case 0x5041:
1482 case 0x5042:
1483 tape_3590_print_era_msg(device, irb);
1484 return tape_3590_erp_swap(device, request, irb);
1485
1486 case 0x5110:
1487 case 0x5111:
1488 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1489
1490 case 0x5120:
1491 case 0x1120:
1492 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001493 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001494 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1495
1496 case 0x6020:
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001497 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1498
1499 case 0x8011:
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001500 return tape_3590_erp_basic(device, request, irb, -EPERM);
1501 case 0x8013:
Carsten Otteab640db2009-03-26 15:24:38 +01001502 dev_warn (&device->cdev->dev, "A different host has privileged"
1503 " access to the tape unit\n");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001504 return tape_3590_erp_basic(device, request, irb, -EPERM);
1505 default:
1506 return tape_3590_erp_basic(device, request, irb, -EIO);
1507 }
1508}
1509
1510/*
1511 * 3590 interrupt handler:
1512 */
1513static int
1514tape_3590_irq(struct tape_device *device, struct tape_request *request,
1515 struct irb *irb)
1516{
1517 if (request == NULL)
1518 return tape_3590_unsolicited_irq(device, irb);
1519
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001520 if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
1521 (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
1522 (request->op == TO_WRI)) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001523 /* Write at end of volume */
1524 DBF_EVENT(2, "End of volume\n");
1525 return tape_3590_erp_failed(device, request, irb, -ENOSPC);
1526 }
1527
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001528 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001529 return tape_3590_unit_check(device, request, irb);
1530
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001531 if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
1532 if (irb->scsw.cmd.dstat == DEV_STAT_UNIT_EXCEP) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001533 if (request->op == TO_FSB || request->op == TO_BSB)
1534 request->rescnt++;
1535 else
1536 DBF_EVENT(5, "Unit Exception!\n");
1537 }
1538
1539 return tape_3590_done(device, request);
1540 }
1541
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001542 if (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001543 DBF_EVENT(2, "cannel end\n");
1544 return TAPE_IO_PENDING;
1545 }
1546
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001547 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001548 DBF_EVENT(2, "Unit Attention when busy..\n");
1549 return TAPE_IO_PENDING;
1550 }
1551
1552 DBF_EVENT(6, "xunknownirq\n");
Carsten Otteab640db2009-03-26 15:24:38 +01001553 tape_dump_sense_dbf(device, request, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001554 return TAPE_IO_STOP;
1555}
1556
Michael Holzheue2963062007-05-04 18:47:53 +02001557
1558static int tape_3590_read_dev_chars(struct tape_device *device,
1559 struct tape_3590_rdc_data *rdc_data)
1560{
1561 int rc;
1562 struct tape_request *request;
1563
1564 request = tape_alloc_request(1, sizeof(*rdc_data));
1565 if (IS_ERR(request))
1566 return PTR_ERR(request);
1567 request->op = TO_RDC;
1568 tape_ccw_end(request->cpaddr, CCW_CMD_RDC, sizeof(*rdc_data),
1569 request->cpdata);
1570 rc = tape_do_io(device, request);
1571 if (rc == 0)
1572 memcpy(rdc_data, request->cpdata, sizeof(*rdc_data));
1573 tape_free_request(request);
1574 return rc;
1575}
1576
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001577/*
1578 * Setup device function
1579 */
1580static int
1581tape_3590_setup_device(struct tape_device *device)
1582{
1583 int rc;
1584 struct tape_3590_disc_data *data;
Michael Holzheue2963062007-05-04 18:47:53 +02001585 struct tape_3590_rdc_data *rdc_data;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001586
1587 DBF_EVENT(6, "3590 device setup\n");
Michael Holzheucced1dd2007-02-05 21:18:26 +01001588 data = kzalloc(sizeof(struct tape_3590_disc_data), GFP_KERNEL | GFP_DMA);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001589 if (data == NULL)
1590 return -ENOMEM;
1591 data->read_back_op = READ_PREVIOUS;
1592 device->discdata = data;
1593
Michael Holzheue2963062007-05-04 18:47:53 +02001594 rdc_data = kmalloc(sizeof(*rdc_data), GFP_KERNEL | GFP_DMA);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001595 if (!rdc_data) {
1596 rc = -ENOMEM;
1597 goto fail_kmalloc;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001598 }
Michael Holzheue2963062007-05-04 18:47:53 +02001599 rc = tape_3590_read_dev_chars(device, rdc_data);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001600 if (rc) {
1601 DBF_LH(3, "Read device characteristics failed!\n");
Julia Lawall1783e602008-06-10 10:03:25 +02001602 goto fail_rdc_data;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001603 }
1604 rc = tape_std_assign(device);
1605 if (rc)
1606 goto fail_rdc_data;
Michael Holzheue2963062007-05-04 18:47:53 +02001607 if (rdc_data->data[31] == 0x13) {
Michael Holzheucced1dd2007-02-05 21:18:26 +01001608 data->crypt_info.capability |= TAPE390_CRYPT_SUPPORTED_MASK;
1609 tape_3592_disable_crypt(device);
1610 } else {
1611 DBF_EVENT(6, "Device has NO crypto support\n");
1612 }
1613 /* Try to find out if medium is loaded */
1614 rc = tape_3590_sense_medium(device);
1615 if (rc) {
1616 DBF_LH(3, "3590 medium sense returned %d\n", rc);
1617 goto fail_rdc_data;
1618 }
1619 return 0;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001620
Michael Holzheucced1dd2007-02-05 21:18:26 +01001621fail_rdc_data:
1622 kfree(rdc_data);
1623fail_kmalloc:
1624 kfree(data);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001625 return rc;
1626}
1627
1628/*
1629 * Cleanup device function
1630 */
1631static void
1632tape_3590_cleanup_device(struct tape_device *device)
1633{
Tejun Heo6dca4672010-12-24 16:00:18 +01001634 flush_workqueue(tape_3590_wq);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001635 tape_std_unassign(device);
1636
1637 kfree(device->discdata);
1638 device->discdata = NULL;
1639}
1640
1641/*
1642 * List of 3590 magnetic tape commands.
1643 */
1644static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = {
1645 [MTRESET] = tape_std_mtreset,
1646 [MTFSF] = tape_std_mtfsf,
1647 [MTBSF] = tape_std_mtbsf,
1648 [MTFSR] = tape_std_mtfsr,
1649 [MTBSR] = tape_std_mtbsr,
1650 [MTWEOF] = tape_std_mtweof,
1651 [MTREW] = tape_std_mtrew,
1652 [MTOFFL] = tape_std_mtoffl,
1653 [MTNOP] = tape_std_mtnop,
1654 [MTRETEN] = tape_std_mtreten,
1655 [MTBSFM] = tape_std_mtbsfm,
1656 [MTFSFM] = tape_std_mtfsfm,
1657 [MTEOM] = tape_std_mteom,
1658 [MTERASE] = tape_std_mterase,
1659 [MTRAS1] = NULL,
1660 [MTRAS2] = NULL,
1661 [MTRAS3] = NULL,
1662 [MTSETBLK] = tape_std_mtsetblk,
1663 [MTSETDENSITY] = NULL,
1664 [MTSEEK] = tape_3590_mtseek,
1665 [MTTELL] = tape_3590_mttell,
1666 [MTSETDRVBUFFER] = NULL,
1667 [MTFSS] = NULL,
1668 [MTBSS] = NULL,
1669 [MTWSM] = NULL,
1670 [MTLOCK] = NULL,
1671 [MTUNLOCK] = NULL,
1672 [MTLOAD] = tape_std_mtload,
1673 [MTUNLOAD] = tape_std_mtunload,
1674 [MTCOMPRESSION] = tape_std_mtcompression,
1675 [MTSETPART] = NULL,
1676 [MTMKPART] = NULL
1677};
1678
1679/*
1680 * Tape discipline structure for 3590.
1681 */
1682static struct tape_discipline tape_discipline_3590 = {
1683 .owner = THIS_MODULE,
1684 .setup_device = tape_3590_setup_device,
1685 .cleanup_device = tape_3590_cleanup_device,
1686 .process_eov = tape_std_process_eov,
1687 .irq = tape_3590_irq,
1688 .read_block = tape_std_read_block,
1689 .write_block = tape_std_write_block,
1690#ifdef CONFIG_S390_TAPE_BLOCK
1691 .bread = tape_3590_bread,
1692 .free_bread = tape_3590_free_bread,
1693 .check_locate = tape_3590_check_locate,
1694#endif
1695 .ioctl_fn = tape_3590_ioctl,
1696 .mtop_array = tape_3590_mtop
1697};
1698
1699static struct ccw_device_id tape_3590_ids[] = {
1700 {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590},
Stefan Bader2cc924b2006-04-27 18:40:16 -07001701 {CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info = tape_3592},
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001702 { /* end of list */ }
1703};
1704
1705static int
1706tape_3590_online(struct ccw_device *cdev)
1707{
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07001708 return tape_generic_online(dev_get_drvdata(&cdev->dev),
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001709 &tape_discipline_3590);
1710}
1711
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001712static struct ccw_driver tape_3590_driver = {
1713 .name = "tape_3590",
1714 .owner = THIS_MODULE,
1715 .ids = tape_3590_ids,
1716 .probe = tape_generic_probe,
1717 .remove = tape_generic_remove,
Frank Munzert4d7a3cd2009-04-23 13:58:09 +02001718 .set_offline = tape_generic_offline,
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001719 .set_online = tape_3590_online,
Frank Munzert3ef32e622009-06-16 10:30:39 +02001720 .freeze = tape_generic_pm_suspend,
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001721};
1722
1723/*
1724 * Setup discipline structure.
1725 */
1726static int
1727tape_3590_init(void)
1728{
1729 int rc;
1730
1731 TAPE_DBF_AREA = debug_register("tape_3590", 2, 2, 4 * sizeof(long));
1732 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1733#ifdef DBF_LIKE_HELL
1734 debug_set_level(TAPE_DBF_AREA, 6);
1735#endif
1736
1737 DBF_EVENT(3, "3590 init\n");
Tejun Heo6dca4672010-12-24 16:00:18 +01001738
1739 tape_3590_wq = alloc_workqueue("tape_3590", 0, 0);
1740 if (!tape_3590_wq)
1741 return -ENOMEM;
1742
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001743 /* Register driver for 3590 tapes. */
1744 rc = ccw_driver_register(&tape_3590_driver);
Tejun Heo6dca4672010-12-24 16:00:18 +01001745 if (rc) {
1746 destroy_workqueue(tape_3590_wq);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001747 DBF_EVENT(3, "3590 init failed\n");
Tejun Heo6dca4672010-12-24 16:00:18 +01001748 } else
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001749 DBF_EVENT(3, "3590 registered\n");
1750 return rc;
1751}
1752
1753static void
1754tape_3590_exit(void)
1755{
1756 ccw_driver_unregister(&tape_3590_driver);
Tejun Heo6dca4672010-12-24 16:00:18 +01001757 destroy_workqueue(tape_3590_wq);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001758 debug_unregister(TAPE_DBF_AREA);
1759}
1760
1761MODULE_DEVICE_TABLE(ccw, tape_3590_ids);
1762MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
1763MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
1764MODULE_LICENSE("GPL");
1765
1766module_init(tape_3590_init);
1767module_exit(tape_3590_exit);