blob: a5c6614b0db259429e034c7817714b3a59c64158 [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 */
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100332static struct tape_request *__tape_3592_enable_crypt(struct tape_device *device)
Michael Holzheucced1dd2007-02-05 21:18:26 +0100333{
334 struct tape_request *request;
335 char *data;
336
337 DBF_EVENT(6, "tape_3592_enable_crypt\n");
338 if (!crypt_supported(device))
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100339 return ERR_PTR(-ENOSYS);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100340 request = tape_alloc_request(2, 72);
341 if (IS_ERR(request))
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100342 return request;
Michael Holzheucced1dd2007-02-05 21:18:26 +0100343 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);
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100357 return request;
358}
359
360static int tape_3592_enable_crypt(struct tape_device *device)
361{
362 struct tape_request *request;
363
364 request = __tape_3592_enable_crypt(device);
365 if (IS_ERR(request))
366 return PTR_ERR(request);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100367 return tape_do_io_free(device, request);
368}
369
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100370static void tape_3592_enable_crypt_async(struct tape_device *device)
371{
372 struct tape_request *request;
373
374 request = __tape_3592_enable_crypt(device);
375 if (!IS_ERR(request))
376 tape_do_io_async_free(device, request);
377}
378
Michael Holzheucced1dd2007-02-05 21:18:26 +0100379/*
380 * Disable encryption
381 */
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100382static struct tape_request *__tape_3592_disable_crypt(struct tape_device *device)
Michael Holzheucced1dd2007-02-05 21:18:26 +0100383{
384 struct tape_request *request;
385 char *data;
386
387 DBF_EVENT(6, "tape_3592_disable_crypt\n");
388 if (!crypt_supported(device))
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100389 return ERR_PTR(-ENOSYS);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100390 request = tape_alloc_request(2, 72);
391 if (IS_ERR(request))
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100392 return request;
Michael Holzheucced1dd2007-02-05 21:18:26 +0100393 data = request->cpdata;
394 memset(data,0,72);
395
396 data[0] = 0x05;
397 data[36 + 0] = 0x03;
398 data[36 + 1] = 0x03;
399 data[36 + 35] = 0x32;
400
401 request->op = TO_CRYPT_OFF;
402 tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
403 tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
404
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100405 return request;
406}
407
408static int tape_3592_disable_crypt(struct tape_device *device)
409{
410 struct tape_request *request;
411
412 request = __tape_3592_disable_crypt(device);
413 if (IS_ERR(request))
414 return PTR_ERR(request);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100415 return tape_do_io_free(device, request);
416}
417
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100418static void tape_3592_disable_crypt_async(struct tape_device *device)
419{
420 struct tape_request *request;
421
422 request = __tape_3592_disable_crypt(device);
423 if (!IS_ERR(request))
424 tape_do_io_async_free(device, request);
425}
426
Michael Holzheucced1dd2007-02-05 21:18:26 +0100427/*
428 * IOCTL: Set encryption status
429 */
430static int tape_3592_ioctl_crypt_set(struct tape_device *device,
431 unsigned long arg)
432{
433 struct tape390_crypt_info info;
434
435 DBF_EVENT(6, "tape_3592_ioctl_crypt_set\n");
436 if (!crypt_supported(device))
437 return -ENOSYS;
438 if (copy_from_user(&info, (char __user *)arg, sizeof(info)))
439 return -EFAULT;
440 if (info.status & ~TAPE390_CRYPT_ON_MASK)
441 return -EINVAL;
442 if (info.status & TAPE390_CRYPT_ON_MASK)
443 return tape_3592_enable_crypt(device);
444 else
445 return tape_3592_disable_crypt(device);
446}
447
448static int tape_3590_sense_medium(struct tape_device *device);
449
450/*
451 * IOCTL: Query enryption status
452 */
453static int tape_3592_ioctl_crypt_query(struct tape_device *device,
454 unsigned long arg)
455{
456 DBF_EVENT(6, "tape_3592_ioctl_crypt_query\n");
457 if (!crypt_supported(device))
458 return -ENOSYS;
459 tape_3590_sense_medium(device);
460 if (copy_to_user((char __user *) arg, &TAPE_3590_CRYPT_INFO(device),
461 sizeof(TAPE_3590_CRYPT_INFO(device))))
462 return -EFAULT;
463 else
464 return 0;
465}
466
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800467/*
468 * 3590 IOCTL Overload
469 */
470static int
471tape_3590_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
472{
473 switch (cmd) {
474 case TAPE390_DISPLAY: {
475 struct display_struct disp;
476
477 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)))
478 return -EFAULT;
479
480 return tape_std_display(device, &disp);
481 }
Michael Holzheucced1dd2007-02-05 21:18:26 +0100482 case TAPE390_KEKL_SET:
483 return tape_3592_ioctl_kekl_set(device, arg);
484 case TAPE390_KEKL_QUERY:
485 return tape_3592_ioctl_kekl_query(device, arg);
486 case TAPE390_CRYPT_SET:
487 return tape_3592_ioctl_crypt_set(device, arg);
488 case TAPE390_CRYPT_QUERY:
489 return tape_3592_ioctl_crypt_query(device, arg);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800490 default:
491 return -EINVAL; /* no additional ioctls */
492 }
493}
494
495/*
496 * SENSE Medium: Get Sense data about medium state
497 */
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100498static int tape_3590_sense_medium(struct tape_device *device)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800499{
500 struct tape_request *request;
501
502 request = tape_alloc_request(1, 128);
503 if (IS_ERR(request))
504 return PTR_ERR(request);
505 request->op = TO_MSEN;
506 tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
507 return tape_do_io_free(device, request);
508}
509
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100510static void tape_3590_sense_medium_async(struct tape_device *device)
511{
512 struct tape_request *request;
513
514 request = tape_alloc_request(1, 128);
515 if (IS_ERR(request))
516 return;
517 request->op = TO_MSEN;
518 tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
519 tape_do_io_async_free(device, request);
520}
521
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800522/*
523 * MTTELL: Tell block. Return the number of block relative to current file.
524 */
525static int
526tape_3590_mttell(struct tape_device *device, int mt_count)
527{
528 __u64 block_id;
529 int rc;
530
531 rc = tape_std_read_block_id(device, &block_id);
532 if (rc)
533 return rc;
534 return block_id >> 32;
535}
536
537/*
538 * MTSEEK: seek to the specified block.
539 */
540static int
541tape_3590_mtseek(struct tape_device *device, int count)
542{
543 struct tape_request *request;
544
545 DBF_EVENT(6, "xsee id: %x\n", count);
546 request = tape_alloc_request(3, 4);
547 if (IS_ERR(request))
548 return PTR_ERR(request);
549 request->op = TO_LBL;
550 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
551 *(__u32 *) request->cpdata = count;
552 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
553 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
554 return tape_do_io_free(device, request);
555}
556
557/*
558 * Read Opposite Error Recovery Function:
559 * Used, when Read Forward does not work
560 */
561static void
562tape_3590_read_opposite(struct tape_device *device,
563 struct tape_request *request)
564{
565 struct tape_3590_disc_data *data;
566
567 /*
568 * We have allocated 4 ccws in tape_std_read, so we can now
569 * transform the request to a read backward, followed by a
570 * forward space block.
571 */
572 request->op = TO_RBA;
573 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
574 data = device->discdata;
575 tape_ccw_cc_idal(request->cpaddr + 1, data->read_back_op,
576 device->char_data.idal_buf);
577 tape_ccw_cc(request->cpaddr + 2, FORSPACEBLOCK, 0, NULL);
578 tape_ccw_end(request->cpaddr + 3, NOP, 0, NULL);
579 DBF_EVENT(6, "xrop ccwg\n");
580}
581
582/*
583 * Read Attention Msg
584 * This should be done after an interrupt with attention bit (0x80)
585 * in device state.
586 *
587 * After a "read attention message" request there are two possible
588 * results:
589 *
590 * 1. A unit check is presented, when attention sense is present (e.g. when
591 * a medium has been unloaded). The attention sense comes then
592 * together with the unit check. The recovery action is either "retry"
593 * (in case there is an attention message pending) or "permanent error".
594 *
595 * 2. The attention msg is written to the "read subsystem data" buffer.
596 * In this case we probably should print it to the console.
597 */
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100598static void tape_3590_read_attmsg_async(struct tape_device *device)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800599{
600 struct tape_request *request;
601 char *buf;
602
603 request = tape_alloc_request(3, 4096);
604 if (IS_ERR(request))
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100605 return;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800606 request->op = TO_READ_ATTMSG;
607 buf = request->cpdata;
608 buf[0] = PREP_RD_SS_DATA;
609 buf[6] = RD_ATTMSG; /* read att msg */
610 tape_ccw_cc(request->cpaddr, PERFORM_SS_FUNC, 12, buf);
611 tape_ccw_cc(request->cpaddr + 1, READ_SS_DATA, 4096 - 12, buf + 12);
612 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100613 tape_do_io_async_free(device, request);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800614}
615
616/*
617 * These functions are used to schedule follow-up actions from within an
618 * interrupt context (like unsolicited interrupts).
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100619 * Note: the work handler is called by the system work queue. The tape
620 * commands started by the handler need to be asynchrounous, otherwise
621 * a deadlock can occur e.g. in case of a deferred cc=1 (see __tape_do_irq).
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800622 */
Stefan Bader2cc924b2006-04-27 18:40:16 -0700623struct work_handler_data {
624 struct tape_device *device;
625 enum tape_op op;
626 struct work_struct work;
627};
628
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800629static void
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100630tape_3590_work_handler(struct work_struct *work)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800631{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100632 struct work_handler_data *p =
633 container_of(work, struct work_handler_data, work);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800634
635 switch (p->op) {
636 case TO_MSEN:
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100637 tape_3590_sense_medium_async(p->device);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800638 break;
639 case TO_READ_ATTMSG:
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100640 tape_3590_read_attmsg_async(p->device);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800641 break;
Michael Holzheucced1dd2007-02-05 21:18:26 +0100642 case TO_CRYPT_ON:
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100643 tape_3592_enable_crypt_async(p->device);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100644 break;
645 case TO_CRYPT_OFF:
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100646 tape_3592_disable_crypt_async(p->device);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100647 break;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800648 default:
649 DBF_EVENT(3, "T3590: work handler undefined for "
650 "operation 0x%02x\n", p->op);
651 }
652 tape_put_device(p->device);
653 kfree(p);
654}
655
656static int
657tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
658{
Stefan Bader2cc924b2006-04-27 18:40:16 -0700659 struct work_handler_data *p;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800660
661 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
662 return -ENOMEM;
663
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100664 INIT_WORK(&p->work, tape_3590_work_handler);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800665
Martin Schwidefsky8fd138c2009-12-07 12:52:03 +0100666 p->device = tape_get_device(device);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800667 p->op = op;
668
Tejun Heo6dca4672010-12-24 16:00:18 +0100669 queue_work(tape_3590_wq, &p->work);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800670 return 0;
671}
672
Michael Holzheucced1dd2007-02-05 21:18:26 +0100673static void tape_3590_med_state_set(struct tape_device *device,
674 struct tape_3590_med_sense *sense)
675{
676 struct tape390_crypt_info *c_info;
677
678 c_info = &TAPE_3590_CRYPT_INFO(device);
679
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200680 DBF_EVENT(6, "medium state: %x:%x\n", sense->macst, sense->masst);
681 switch (sense->macst) {
682 case 0x04:
683 case 0x05:
684 case 0x06:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100685 tape_med_state_set(device, MS_UNLOADED);
686 TAPE_3590_CRYPT_INFO(device).medium_status = 0;
687 return;
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200688 case 0x08:
689 case 0x09:
690 tape_med_state_set(device, MS_LOADED);
691 break;
692 default:
693 tape_med_state_set(device, MS_UNKNOWN);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100694 return;
695 }
Michael Holzheucced1dd2007-02-05 21:18:26 +0100696 c_info->medium_status |= TAPE390_MEDIUM_LOADED_MASK;
697 if (sense->flags & MSENSE_CRYPT_MASK) {
Carsten Otteab640db2009-03-26 15:24:38 +0100698 DBF_EVENT(6, "Medium is encrypted (%04x)\n", sense->flags);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100699 c_info->medium_status |= TAPE390_MEDIUM_ENCRYPTED_MASK;
700 } else {
701 DBF_EVENT(6, "Medium is not encrypted %04x\n", sense->flags);
702 c_info->medium_status &= ~TAPE390_MEDIUM_ENCRYPTED_MASK;
703 }
704}
705
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800706/*
707 * The done handler is called at device/channel end and wakes up the sleeping
708 * process
709 */
710static int
711tape_3590_done(struct tape_device *device, struct tape_request *request)
712{
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800713
714 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
715
716 switch (request->op) {
717 case TO_BSB:
718 case TO_BSF:
719 case TO_DSE:
720 case TO_FSB:
721 case TO_FSF:
722 case TO_LBL:
723 case TO_RFO:
724 case TO_RBA:
725 case TO_REW:
726 case TO_WRI:
727 case TO_WTM:
728 case TO_BLOCK:
729 case TO_LOAD:
730 tape_med_state_set(device, MS_LOADED);
731 break;
732 case TO_RUN:
733 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100734 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800735 break;
736 case TO_MSEN:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100737 tape_3590_med_state_set(device, request->cpdata);
738 break;
739 case TO_CRYPT_ON:
740 TAPE_3590_CRYPT_INFO(device).status
741 |= TAPE390_CRYPT_ON_MASK;
742 *(device->modeset_byte) |= 0x03;
743 break;
744 case TO_CRYPT_OFF:
745 TAPE_3590_CRYPT_INFO(device).status
746 &= ~TAPE390_CRYPT_ON_MASK;
747 *(device->modeset_byte) &= ~0x03;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800748 break;
749 case TO_RBI: /* RBI seems to succeed even without medium loaded. */
750 case TO_NOP: /* Same to NOP. */
751 case TO_READ_CONFIG:
752 case TO_READ_ATTMSG:
753 case TO_DIS:
754 case TO_ASSIGN:
755 case TO_UNASSIGN:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800756 case TO_SIZE:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100757 case TO_KEKL_SET:
758 case TO_KEKL_QUERY:
Michael Holzheue2963062007-05-04 18:47:53 +0200759 case TO_RDC:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800760 break;
761 }
762 return TAPE_IO_SUCCESS;
763}
764
765/*
Stefan Weileef35c22010-08-06 21:11:15 +0200766 * This function is called, when error recovery was successful
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800767 */
768static inline int
769tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request)
770{
Coly Li73ac36e2009-01-07 18:09:16 -0800771 DBF_EVENT(3, "Error Recovery successful for %s\n",
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800772 tape_op_verbose[request->op]);
773 return tape_3590_done(device, request);
774}
775
776/*
Stefan Weileef35c22010-08-06 21:11:15 +0200777 * This function is called, when error recovery was not successful
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800778 */
779static inline int
780tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
781 struct irb *irb, int rc)
782{
783 DBF_EVENT(3, "Error Recovery failed for %s\n",
784 tape_op_verbose[request->op]);
785 tape_dump_sense_dbf(device, request, irb);
786 return rc;
787}
788
789/*
790 * Error Recovery do retry
791 */
792static inline int
793tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
794 struct irb *irb)
795{
796 DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]);
797 tape_dump_sense_dbf(device, request, irb);
798 return TAPE_IO_RETRY;
799}
800
801/*
802 * Handle unsolicited interrupts
803 */
804static int
805tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
806{
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200807 if (irb->scsw.cmd.dstat == DEV_STAT_CHN_END)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800808 /* Probably result of halt ssch */
809 return TAPE_IO_PENDING;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200810 else if (irb->scsw.cmd.dstat == 0x85)
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200811 /* Device Ready */
812 DBF_EVENT(3, "unsol.irq! tape ready: %08x\n", device->cdev_id);
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200813 else if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800814 tape_3590_schedule_work(device, TO_READ_ATTMSG);
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200815 } else {
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800816 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
Carsten Otteab640db2009-03-26 15:24:38 +0100817 tape_dump_sense_dbf(device, NULL, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800818 }
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200819 /* check medium state */
820 tape_3590_schedule_work(device, TO_MSEN);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800821 return TAPE_IO_SUCCESS;
822}
823
824/*
825 * Basic Recovery routine
826 */
827static int
828tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
829 struct irb *irb, int rc)
830{
831 struct tape_3590_sense *sense;
832
833 sense = (struct tape_3590_sense *) irb->ecw;
834
835 switch (sense->bra) {
836 case SENSE_BRA_PER:
837 return tape_3590_erp_failed(device, request, irb, rc);
838 case SENSE_BRA_CONT:
839 return tape_3590_erp_succeded(device, request);
840 case SENSE_BRA_RE:
841 return tape_3590_erp_retry(device, request, irb);
842 case SENSE_BRA_DRE:
843 return tape_3590_erp_failed(device, request, irb, rc);
844 default:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800845 BUG();
846 return TAPE_IO_STOP;
847 }
848}
849
850/*
851 * RDL: Read Device (buffered) log
852 */
853static int
854tape_3590_erp_read_buf_log(struct tape_device *device,
855 struct tape_request *request, struct irb *irb)
856{
857 /*
858 * We just do the basic error recovery at the moment (retry).
859 * Perhaps in the future, we read the log and dump it somewhere...
860 */
861 return tape_3590_erp_basic(device, request, irb, -EIO);
862}
863
864/*
865 * SWAP: Swap Devices
866 */
867static int
868tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
869 struct irb *irb)
870{
871 /*
872 * This error recovery should swap the tapes
873 * if the original has a problem. The operation
874 * should proceed with the new tape... this
875 * should probably be done in user space!
876 */
Carsten Otteab640db2009-03-26 15:24:38 +0100877 dev_warn (&device->cdev->dev, "The tape medium must be loaded into a "
878 "different tape unit\n");
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800879 return tape_3590_erp_basic(device, request, irb, -EIO);
880}
881
882/*
883 * LBY: Long Busy
884 */
885static int
886tape_3590_erp_long_busy(struct tape_device *device,
887 struct tape_request *request, struct irb *irb)
888{
Michael Holzheucced1dd2007-02-05 21:18:26 +0100889 DBF_EVENT(6, "Device is busy\n");
890 return TAPE_IO_LONG_BUSY;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800891}
892
893/*
894 * SPI: Special Intercept
895 */
896static int
897tape_3590_erp_special_interrupt(struct tape_device *device,
898 struct tape_request *request, struct irb *irb)
899{
900 return tape_3590_erp_basic(device, request, irb, -EIO);
901}
902
903/*
904 * RDA: Read Alternate
905 */
906static int
907tape_3590_erp_read_alternate(struct tape_device *device,
908 struct tape_request *request, struct irb *irb)
909{
910 struct tape_3590_disc_data *data;
911
912 /*
913 * The issued Read Backward or Read Previous command is not
914 * supported by the device
915 * The recovery action should be to issue another command:
916 * Read Revious: if Read Backward is not supported
917 * Read Backward: if Read Previous is not supported
918 */
919 data = device->discdata;
920 if (data->read_back_op == READ_PREVIOUS) {
921 DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
922 device->cdev_id);
923 data->read_back_op = READ_BACKWARD;
924 } else {
925 DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
926 device->cdev_id);
927 data->read_back_op = READ_PREVIOUS;
928 }
929 tape_3590_read_opposite(device, request);
930 return tape_3590_erp_retry(device, request, irb);
931}
932
933/*
934 * Error Recovery read opposite
935 */
936static int
937tape_3590_erp_read_opposite(struct tape_device *device,
938 struct tape_request *request, struct irb *irb)
939{
940 switch (request->op) {
941 case TO_RFO:
942 /*
943 * We did read forward, but the data could not be read.
944 * We will read backward and then skip forward again.
945 */
946 tape_3590_read_opposite(device, request);
947 return tape_3590_erp_retry(device, request, irb);
948 case TO_RBA:
949 /* We tried to read forward and backward, but hat no success */
950 return tape_3590_erp_failed(device, request, irb, -EIO);
951 break;
952 default:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800953 return tape_3590_erp_failed(device, request, irb, -EIO);
954 }
955}
956
957/*
958 * Print an MIM (Media Information Message) (message code f0)
959 */
960static void
961tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
962{
963 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +0100964 char *exception, *service;
965
966 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
967 service = kmalloc(BUFSIZE, GFP_ATOMIC);
968
969 if (!exception || !service)
970 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800971
972 sense = (struct tape_3590_sense *) irb->ecw;
973 /* Exception Message */
974 switch (sense->fmt.f70.emc) {
975 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +0100976 snprintf(exception, BUFSIZE, "Data degraded");
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800977 break;
978 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +0100979 snprintf(exception, BUFSIZE, "Data degraded in partion %i",
980 sense->fmt.f70.mp);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800981 break;
982 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +0100983 snprintf(exception, BUFSIZE, "Medium degraded");
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800984 break;
985 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +0100986 snprintf(exception, BUFSIZE, "Medium degraded in partition %i",
987 sense->fmt.f70.mp);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800988 break;
989 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +0100990 snprintf(exception, BUFSIZE, "Block 0 Error");
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800991 break;
992 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +0100993 snprintf(exception, BUFSIZE, "Medium Exception 0x%02x",
994 sense->fmt.f70.md);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800995 break;
996 default:
Carsten Otteab640db2009-03-26 15:24:38 +0100997 snprintf(exception, BUFSIZE, "0x%02x",
998 sense->fmt.f70.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800999 break;
1000 }
1001 /* Service Message */
1002 switch (sense->fmt.f70.smc) {
1003 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001004 snprintf(service, BUFSIZE, "Reference Media maintenance "
1005 "procedure %i", sense->fmt.f70.md);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001006 break;
1007 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001008 snprintf(service, BUFSIZE, "0x%02x",
1009 sense->fmt.f70.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001010 break;
1011 }
Carsten Otteab640db2009-03-26 15:24:38 +01001012
1013 dev_warn (&device->cdev->dev, "Tape media information: exception %s, "
1014 "service %s\n", exception, service);
1015
1016out_nomem:
1017 kfree(exception);
1018 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001019}
1020
1021/*
1022 * Print an I/O Subsystem Service Information Message (message code f1)
1023 */
1024static void
1025tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
1026{
1027 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +01001028 char *exception, *service;
1029
1030 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1031 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1032
1033 if (!exception || !service)
1034 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001035
1036 sense = (struct tape_3590_sense *) irb->ecw;
1037 /* Exception Message */
1038 switch (sense->fmt.f71.emc) {
1039 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001040 snprintf(exception, BUFSIZE, "Effect of failure is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001041 break;
1042 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001043 snprintf(exception, BUFSIZE, "CU Exception - no performance "
1044 "impact");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001045 break;
1046 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001047 snprintf(exception, BUFSIZE, "CU Exception on channel "
1048 "interface 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001049 break;
1050 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001051 snprintf(exception, BUFSIZE, "CU Exception on device path "
1052 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001053 break;
1054 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001055 snprintf(exception, BUFSIZE, "CU Exception on library path "
1056 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001057 break;
1058 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001059 snprintf(exception, BUFSIZE, "CU Exception on node 0x%02x",
1060 sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001061 break;
1062 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001063 snprintf(exception, BUFSIZE, "CU Exception on partition "
1064 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001065 break;
1066 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001067 snprintf(exception, BUFSIZE, "0x%02x",
1068 sense->fmt.f71.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001069 }
1070 /* Service Message */
1071 switch (sense->fmt.f71.smc) {
1072 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001073 snprintf(service, BUFSIZE, "Repair impact is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001074 break;
1075 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001076 snprintf(service, BUFSIZE, "Repair will not impact cu "
1077 "performance");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001078 break;
1079 case 0x03:
1080 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001081 snprintf(service, BUFSIZE, "Repair will disable node "
1082 "0x%x on CU", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001083 else
Carsten Otteab640db2009-03-26 15:24:38 +01001084 snprintf(service, BUFSIZE, "Repair will disable "
1085 "nodes (0x%x-0x%x) on CU", sense->fmt.f71.md[1],
1086 sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001087 break;
1088 case 0x04:
1089 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001090 snprintf(service, BUFSIZE, "Repair will disable "
1091 "channel path 0x%x on CU",
1092 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001093 else
Carsten Otteab640db2009-03-26 15:24:38 +01001094 snprintf(service, BUFSIZE, "Repair will disable cannel"
1095 " paths (0x%x-0x%x) on CU",
1096 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001097 break;
1098 case 0x05:
1099 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001100 snprintf(service, BUFSIZE, "Repair will disable device"
1101 " path 0x%x on CU", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001102 else
Carsten Otteab640db2009-03-26 15:24:38 +01001103 snprintf(service, BUFSIZE, "Repair will disable device"
1104 " paths (0x%x-0x%x) on CU",
1105 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001106 break;
1107 case 0x06:
1108 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001109 snprintf(service, BUFSIZE, "Repair will disable "
1110 "library path 0x%x on CU",
1111 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001112 else
Carsten Otteab640db2009-03-26 15:24:38 +01001113 snprintf(service, BUFSIZE, "Repair will disable "
1114 "library paths (0x%x-0x%x) on CU",
1115 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001116 break;
1117 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001118 snprintf(service, BUFSIZE, "Repair will disable access to CU");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001119 break;
1120 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001121 snprintf(service, BUFSIZE, "0x%02x",
1122 sense->fmt.f71.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001123 }
Carsten Otteab640db2009-03-26 15:24:38 +01001124
1125 dev_warn (&device->cdev->dev, "I/O subsystem information: exception"
1126 " %s, service %s\n", exception, service);
1127out_nomem:
1128 kfree(exception);
1129 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001130}
1131
1132/*
1133 * Print an Device Subsystem Service Information Message (message code f2)
1134 */
1135static void
1136tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
1137{
1138 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +01001139 char *exception, *service;
1140
1141 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1142 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1143
1144 if (!exception || !service)
1145 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001146
1147 sense = (struct tape_3590_sense *) irb->ecw;
1148 /* Exception Message */
1149 switch (sense->fmt.f71.emc) {
1150 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001151 snprintf(exception, BUFSIZE, "Effect of failure is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001152 break;
1153 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001154 snprintf(exception, BUFSIZE, "DV Exception - no performance"
1155 " impact");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001156 break;
1157 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001158 snprintf(exception, BUFSIZE, "DV Exception on channel "
1159 "interface 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001160 break;
1161 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001162 snprintf(exception, BUFSIZE, "DV Exception on loader 0x%02x",
1163 sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001164 break;
1165 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001166 snprintf(exception, BUFSIZE, "DV Exception on message display"
1167 " 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001168 break;
1169 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001170 snprintf(exception, BUFSIZE, "DV Exception in tape path");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001171 break;
1172 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001173 snprintf(exception, BUFSIZE, "DV Exception in drive");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001174 break;
1175 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001176 snprintf(exception, BUFSIZE, "0x%02x",
1177 sense->fmt.f71.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001178 }
1179 /* Service Message */
1180 switch (sense->fmt.f71.smc) {
1181 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001182 snprintf(service, BUFSIZE, "Repair impact is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001183 break;
1184 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001185 snprintf(service, BUFSIZE, "Repair will not impact device "
1186 "performance");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001187 break;
1188 case 0x03:
1189 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001190 snprintf(service, BUFSIZE, "Repair will disable "
1191 "channel path 0x%x on DV",
1192 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001193 else
Carsten Otteab640db2009-03-26 15:24:38 +01001194 snprintf(service, BUFSIZE, "Repair will disable "
1195 "channel path (0x%x-0x%x) on DV",
1196 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001197 break;
1198 case 0x04:
1199 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001200 snprintf(service, BUFSIZE, "Repair will disable "
1201 "interface 0x%x on DV", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001202 else
Carsten Otteab640db2009-03-26 15:24:38 +01001203 snprintf(service, BUFSIZE, "Repair will disable "
1204 "interfaces (0x%x-0x%x) on DV",
1205 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001206 break;
1207 case 0x05:
1208 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001209 snprintf(service, BUFSIZE, "Repair will disable loader"
1210 " 0x%x on DV", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001211 else
Carsten Otteab640db2009-03-26 15:24:38 +01001212 snprintf(service, BUFSIZE, "Repair will disable loader"
1213 " (0x%x-0x%x) on DV",
1214 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001215 break;
1216 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001217 snprintf(service, BUFSIZE, "Repair will disable access to DV");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001218 break;
1219 case 0x08:
1220 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001221 snprintf(service, BUFSIZE, "Repair will disable "
1222 "message display 0x%x on DV",
1223 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001224 else
Carsten Otteab640db2009-03-26 15:24:38 +01001225 snprintf(service, BUFSIZE, "Repair will disable "
1226 "message displays (0x%x-0x%x) on DV",
1227 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001228 break;
1229 case 0x09:
Carsten Otteab640db2009-03-26 15:24:38 +01001230 snprintf(service, BUFSIZE, "Clean DV");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001231 break;
1232 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001233 snprintf(service, BUFSIZE, "0x%02x",
1234 sense->fmt.f71.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001235 }
Carsten Otteab640db2009-03-26 15:24:38 +01001236
1237 dev_warn (&device->cdev->dev, "Device subsystem information: exception"
1238 " %s, service %s\n", exception, service);
1239out_nomem:
1240 kfree(exception);
1241 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001242}
1243
1244/*
1245 * Print standard ERA Message
1246 */
1247static void
1248tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
1249{
1250 struct tape_3590_sense *sense;
1251
1252 sense = (struct tape_3590_sense *) irb->ecw;
1253 if (sense->mc == 0)
1254 return;
1255 if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) {
1256 if (tape_3590_msg[sense->mc] != NULL)
Carsten Otteab640db2009-03-26 15:24:38 +01001257 dev_warn (&device->cdev->dev, "The tape unit has "
1258 "issued sense message %s\n",
1259 tape_3590_msg[sense->mc]);
1260 else
1261 dev_warn (&device->cdev->dev, "The tape unit has "
1262 "issued an unknown sense message code 0x%x\n",
1263 sense->mc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001264 return;
1265 }
1266 if (sense->mc == 0xf0) {
1267 /* Standard Media Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001268 dev_warn (&device->cdev->dev, "MIM SEV=%i, MC=%02x, ES=%x/%x, "
1269 "RC=%02x-%04x-%02x\n", sense->fmt.f70.sev, sense->mc,
1270 sense->fmt.f70.emc, sense->fmt.f70.smc,
1271 sense->fmt.f70.refcode, sense->fmt.f70.mid,
1272 sense->fmt.f70.fid);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001273 tape_3590_print_mim_msg_f0(device, irb);
1274 return;
1275 }
1276 if (sense->mc == 0xf1) {
1277 /* Standard I/O Subsystem Service Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001278 dev_warn (&device->cdev->dev, "IOSIM SEV=%i, DEVTYPE=3590/%02x,"
1279 " MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1280 sense->fmt.f71.sev, device->cdev->id.dev_model,
1281 sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1282 sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1283 sense->fmt.f71.refcode3);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001284 tape_3590_print_io_sim_msg_f1(device, irb);
1285 return;
1286 }
1287 if (sense->mc == 0xf2) {
1288 /* Standard Device Service Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001289 dev_warn (&device->cdev->dev, "DEVSIM SEV=%i, DEVTYPE=3590/%02x"
1290 ", MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1291 sense->fmt.f71.sev, device->cdev->id.dev_model,
1292 sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1293 sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1294 sense->fmt.f71.refcode3);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001295 tape_3590_print_dev_sim_msg_f2(device, irb);
1296 return;
1297 }
1298 if (sense->mc == 0xf3) {
1299 /* Standard Library Service Information Message */
1300 return;
1301 }
Carsten Otteab640db2009-03-26 15:24:38 +01001302 dev_warn (&device->cdev->dev, "The tape unit has issued an unknown "
1303 "sense message code %x\n", sense->mc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001304}
1305
Michael Holzheucced1dd2007-02-05 21:18:26 +01001306static int tape_3590_crypt_error(struct tape_device *device,
1307 struct tape_request *request, struct irb *irb)
1308{
Heiko Carstens160fbf22011-05-23 10:24:28 +02001309 u8 cu_rc;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001310 u16 ekm_rc2;
Kay Sievers2a0217d2008-10-10 21:33:09 +02001311 char *sense;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001312
1313 sense = ((struct tape_3590_sense *) irb->ecw)->fmt.data;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001314 cu_rc = sense[0];
Michael Holzheucced1dd2007-02-05 21:18:26 +01001315 ekm_rc2 = *((u16*) &sense[10]);
1316 if ((cu_rc == 0) && (ekm_rc2 == 0xee31))
1317 /* key not defined on EKM */
1318 return tape_3590_erp_basic(device, request, irb, -EKEYREJECTED);
1319 if ((cu_rc == 1) || (cu_rc == 2))
1320 /* No connection to EKM */
1321 return tape_3590_erp_basic(device, request, irb, -ENOTCONN);
1322
Carsten Otteab640db2009-03-26 15:24:38 +01001323 dev_err (&device->cdev->dev, "The tape unit failed to obtain the "
1324 "encryption key from EKM\n");
Michael Holzheucced1dd2007-02-05 21:18:26 +01001325
1326 return tape_3590_erp_basic(device, request, irb, -ENOKEY);
1327}
1328
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001329/*
1330 * 3590 error Recovery routine:
1331 * If possible, it tries to recover from the error. If this is not possible,
1332 * inform the user about the problem.
1333 */
1334static int
1335tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
1336 struct irb *irb)
1337{
1338 struct tape_3590_sense *sense;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001339
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001340 sense = (struct tape_3590_sense *) irb->ecw;
1341
Michael Holzheucced1dd2007-02-05 21:18:26 +01001342 DBF_EVENT(6, "Unit Check: RQC = %x\n", sense->rc_rqc);
1343
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001344 /*
1345 * First check all RC-QRCs where we want to do something special
1346 * - "break": basic error recovery is done
1347 * - "goto out:": just print error message if available
1348 */
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001349 switch (sense->rc_rqc) {
1350
1351 case 0x1110:
1352 tape_3590_print_era_msg(device, irb);
1353 return tape_3590_erp_read_buf_log(device, request, irb);
1354
1355 case 0x2011:
1356 tape_3590_print_era_msg(device, irb);
1357 return tape_3590_erp_read_alternate(device, request, irb);
1358
1359 case 0x2230:
1360 case 0x2231:
1361 tape_3590_print_era_msg(device, irb);
1362 return tape_3590_erp_special_interrupt(device, request, irb);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001363 case 0x2240:
1364 return tape_3590_crypt_error(device, request, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001365
1366 case 0x3010:
1367 DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1368 device->cdev_id);
1369 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1370 case 0x3012:
1371 DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1372 device->cdev_id);
1373 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1374 case 0x3020:
1375 DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
1376 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1377
1378 case 0x3122:
1379 DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1380 device->cdev_id);
1381 return tape_3590_erp_basic(device, request, irb, -EIO);
1382 case 0x3123:
1383 DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1384 device->cdev_id);
1385 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001386 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001387 return tape_3590_erp_basic(device, request, irb, 0);
1388
1389 case 0x4010:
1390 /*
1391 * print additional msg since default msg
1392 * "device intervention" is not very meaningfull
1393 */
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001394 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001395 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001396 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1397 case 0x4012: /* Device Long Busy */
Michael Holzheucced1dd2007-02-05 21:18:26 +01001398 /* XXX: Also use long busy handling here? */
1399 DBF_EVENT(6, "(%08x): LONG BUSY\n", device->cdev_id);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001400 tape_3590_print_era_msg(device, irb);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001401 return tape_3590_erp_basic(device, request, irb, -EBUSY);
1402 case 0x4014:
1403 DBF_EVENT(6, "(%08x): Crypto LONG BUSY\n", device->cdev_id);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001404 return tape_3590_erp_long_busy(device, request, irb);
1405
1406 case 0x5010:
1407 if (sense->rac == 0xd0) {
1408 /* Swap */
1409 tape_3590_print_era_msg(device, irb);
1410 return tape_3590_erp_swap(device, request, irb);
1411 }
1412 if (sense->rac == 0x26) {
1413 /* Read Opposite */
1414 tape_3590_print_era_msg(device, irb);
1415 return tape_3590_erp_read_opposite(device, request,
1416 irb);
1417 }
1418 return tape_3590_erp_basic(device, request, irb, -EIO);
1419 case 0x5020:
1420 case 0x5021:
1421 case 0x5022:
1422 case 0x5040:
1423 case 0x5041:
1424 case 0x5042:
1425 tape_3590_print_era_msg(device, irb);
1426 return tape_3590_erp_swap(device, request, irb);
1427
1428 case 0x5110:
1429 case 0x5111:
1430 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1431
1432 case 0x5120:
1433 case 0x1120:
1434 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001435 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001436 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1437
1438 case 0x6020:
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001439 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1440
1441 case 0x8011:
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001442 return tape_3590_erp_basic(device, request, irb, -EPERM);
1443 case 0x8013:
Carsten Otteab640db2009-03-26 15:24:38 +01001444 dev_warn (&device->cdev->dev, "A different host has privileged"
1445 " access to the tape unit\n");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001446 return tape_3590_erp_basic(device, request, irb, -EPERM);
1447 default:
1448 return tape_3590_erp_basic(device, request, irb, -EIO);
1449 }
1450}
1451
1452/*
1453 * 3590 interrupt handler:
1454 */
1455static int
1456tape_3590_irq(struct tape_device *device, struct tape_request *request,
1457 struct irb *irb)
1458{
1459 if (request == NULL)
1460 return tape_3590_unsolicited_irq(device, irb);
1461
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001462 if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
1463 (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
1464 (request->op == TO_WRI)) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001465 /* Write at end of volume */
1466 DBF_EVENT(2, "End of volume\n");
1467 return tape_3590_erp_failed(device, request, irb, -ENOSPC);
1468 }
1469
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001470 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001471 return tape_3590_unit_check(device, request, irb);
1472
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001473 if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
1474 if (irb->scsw.cmd.dstat == DEV_STAT_UNIT_EXCEP) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001475 if (request->op == TO_FSB || request->op == TO_BSB)
1476 request->rescnt++;
1477 else
1478 DBF_EVENT(5, "Unit Exception!\n");
1479 }
1480
1481 return tape_3590_done(device, request);
1482 }
1483
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001484 if (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001485 DBF_EVENT(2, "cannel end\n");
1486 return TAPE_IO_PENDING;
1487 }
1488
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001489 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001490 DBF_EVENT(2, "Unit Attention when busy..\n");
1491 return TAPE_IO_PENDING;
1492 }
1493
1494 DBF_EVENT(6, "xunknownirq\n");
Carsten Otteab640db2009-03-26 15:24:38 +01001495 tape_dump_sense_dbf(device, request, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001496 return TAPE_IO_STOP;
1497}
1498
Michael Holzheue2963062007-05-04 18:47:53 +02001499
1500static int tape_3590_read_dev_chars(struct tape_device *device,
1501 struct tape_3590_rdc_data *rdc_data)
1502{
1503 int rc;
1504 struct tape_request *request;
1505
1506 request = tape_alloc_request(1, sizeof(*rdc_data));
1507 if (IS_ERR(request))
1508 return PTR_ERR(request);
1509 request->op = TO_RDC;
1510 tape_ccw_end(request->cpaddr, CCW_CMD_RDC, sizeof(*rdc_data),
1511 request->cpdata);
1512 rc = tape_do_io(device, request);
1513 if (rc == 0)
1514 memcpy(rdc_data, request->cpdata, sizeof(*rdc_data));
1515 tape_free_request(request);
1516 return rc;
1517}
1518
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001519/*
1520 * Setup device function
1521 */
1522static int
1523tape_3590_setup_device(struct tape_device *device)
1524{
1525 int rc;
1526 struct tape_3590_disc_data *data;
Michael Holzheue2963062007-05-04 18:47:53 +02001527 struct tape_3590_rdc_data *rdc_data;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001528
1529 DBF_EVENT(6, "3590 device setup\n");
Michael Holzheucced1dd2007-02-05 21:18:26 +01001530 data = kzalloc(sizeof(struct tape_3590_disc_data), GFP_KERNEL | GFP_DMA);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001531 if (data == NULL)
1532 return -ENOMEM;
1533 data->read_back_op = READ_PREVIOUS;
1534 device->discdata = data;
1535
Michael Holzheue2963062007-05-04 18:47:53 +02001536 rdc_data = kmalloc(sizeof(*rdc_data), GFP_KERNEL | GFP_DMA);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001537 if (!rdc_data) {
1538 rc = -ENOMEM;
1539 goto fail_kmalloc;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001540 }
Michael Holzheue2963062007-05-04 18:47:53 +02001541 rc = tape_3590_read_dev_chars(device, rdc_data);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001542 if (rc) {
1543 DBF_LH(3, "Read device characteristics failed!\n");
Julia Lawall1783e602008-06-10 10:03:25 +02001544 goto fail_rdc_data;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001545 }
1546 rc = tape_std_assign(device);
1547 if (rc)
1548 goto fail_rdc_data;
Michael Holzheue2963062007-05-04 18:47:53 +02001549 if (rdc_data->data[31] == 0x13) {
Michael Holzheucced1dd2007-02-05 21:18:26 +01001550 data->crypt_info.capability |= TAPE390_CRYPT_SUPPORTED_MASK;
1551 tape_3592_disable_crypt(device);
1552 } else {
1553 DBF_EVENT(6, "Device has NO crypto support\n");
1554 }
1555 /* Try to find out if medium is loaded */
1556 rc = tape_3590_sense_medium(device);
1557 if (rc) {
1558 DBF_LH(3, "3590 medium sense returned %d\n", rc);
1559 goto fail_rdc_data;
1560 }
1561 return 0;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001562
Michael Holzheucced1dd2007-02-05 21:18:26 +01001563fail_rdc_data:
1564 kfree(rdc_data);
1565fail_kmalloc:
1566 kfree(data);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001567 return rc;
1568}
1569
1570/*
1571 * Cleanup device function
1572 */
1573static void
1574tape_3590_cleanup_device(struct tape_device *device)
1575{
Tejun Heo6dca4672010-12-24 16:00:18 +01001576 flush_workqueue(tape_3590_wq);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001577 tape_std_unassign(device);
1578
1579 kfree(device->discdata);
1580 device->discdata = NULL;
1581}
1582
1583/*
1584 * List of 3590 magnetic tape commands.
1585 */
1586static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = {
1587 [MTRESET] = tape_std_mtreset,
1588 [MTFSF] = tape_std_mtfsf,
1589 [MTBSF] = tape_std_mtbsf,
1590 [MTFSR] = tape_std_mtfsr,
1591 [MTBSR] = tape_std_mtbsr,
1592 [MTWEOF] = tape_std_mtweof,
1593 [MTREW] = tape_std_mtrew,
1594 [MTOFFL] = tape_std_mtoffl,
1595 [MTNOP] = tape_std_mtnop,
1596 [MTRETEN] = tape_std_mtreten,
1597 [MTBSFM] = tape_std_mtbsfm,
1598 [MTFSFM] = tape_std_mtfsfm,
1599 [MTEOM] = tape_std_mteom,
1600 [MTERASE] = tape_std_mterase,
1601 [MTRAS1] = NULL,
1602 [MTRAS2] = NULL,
1603 [MTRAS3] = NULL,
1604 [MTSETBLK] = tape_std_mtsetblk,
1605 [MTSETDENSITY] = NULL,
1606 [MTSEEK] = tape_3590_mtseek,
1607 [MTTELL] = tape_3590_mttell,
1608 [MTSETDRVBUFFER] = NULL,
1609 [MTFSS] = NULL,
1610 [MTBSS] = NULL,
1611 [MTWSM] = NULL,
1612 [MTLOCK] = NULL,
1613 [MTUNLOCK] = NULL,
1614 [MTLOAD] = tape_std_mtload,
1615 [MTUNLOAD] = tape_std_mtunload,
1616 [MTCOMPRESSION] = tape_std_mtcompression,
1617 [MTSETPART] = NULL,
1618 [MTMKPART] = NULL
1619};
1620
1621/*
1622 * Tape discipline structure for 3590.
1623 */
1624static struct tape_discipline tape_discipline_3590 = {
1625 .owner = THIS_MODULE,
1626 .setup_device = tape_3590_setup_device,
1627 .cleanup_device = tape_3590_cleanup_device,
1628 .process_eov = tape_std_process_eov,
1629 .irq = tape_3590_irq,
1630 .read_block = tape_std_read_block,
1631 .write_block = tape_std_write_block,
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001632 .ioctl_fn = tape_3590_ioctl,
1633 .mtop_array = tape_3590_mtop
1634};
1635
1636static struct ccw_device_id tape_3590_ids[] = {
1637 {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590},
Stefan Bader2cc924b2006-04-27 18:40:16 -07001638 {CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info = tape_3592},
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001639 { /* end of list */ }
1640};
1641
1642static int
1643tape_3590_online(struct ccw_device *cdev)
1644{
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07001645 return tape_generic_online(dev_get_drvdata(&cdev->dev),
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001646 &tape_discipline_3590);
1647}
1648
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001649static struct ccw_driver tape_3590_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +01001650 .driver = {
1651 .name = "tape_3590",
1652 .owner = THIS_MODULE,
1653 },
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001654 .ids = tape_3590_ids,
1655 .probe = tape_generic_probe,
1656 .remove = tape_generic_remove,
Frank Munzert4d7a3cd2009-04-23 13:58:09 +02001657 .set_offline = tape_generic_offline,
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001658 .set_online = tape_3590_online,
Frank Munzert3ef32e622009-06-16 10:30:39 +02001659 .freeze = tape_generic_pm_suspend,
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001660 .int_class = IOINT_TAP,
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001661};
1662
1663/*
1664 * Setup discipline structure.
1665 */
1666static int
1667tape_3590_init(void)
1668{
1669 int rc;
1670
1671 TAPE_DBF_AREA = debug_register("tape_3590", 2, 2, 4 * sizeof(long));
1672 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1673#ifdef DBF_LIKE_HELL
1674 debug_set_level(TAPE_DBF_AREA, 6);
1675#endif
1676
1677 DBF_EVENT(3, "3590 init\n");
Tejun Heo6dca4672010-12-24 16:00:18 +01001678
1679 tape_3590_wq = alloc_workqueue("tape_3590", 0, 0);
1680 if (!tape_3590_wq)
1681 return -ENOMEM;
1682
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001683 /* Register driver for 3590 tapes. */
1684 rc = ccw_driver_register(&tape_3590_driver);
Tejun Heo6dca4672010-12-24 16:00:18 +01001685 if (rc) {
1686 destroy_workqueue(tape_3590_wq);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001687 DBF_EVENT(3, "3590 init failed\n");
Tejun Heo6dca4672010-12-24 16:00:18 +01001688 } else
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001689 DBF_EVENT(3, "3590 registered\n");
1690 return rc;
1691}
1692
1693static void
1694tape_3590_exit(void)
1695{
1696 ccw_driver_unregister(&tape_3590_driver);
Tejun Heo6dca4672010-12-24 16:00:18 +01001697 destroy_workqueue(tape_3590_wq);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001698 debug_unregister(TAPE_DBF_AREA);
1699}
1700
1701MODULE_DEVICE_TABLE(ccw, tape_3590_ids);
1702MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
1703MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
1704MODULE_LICENSE("GPL");
1705
1706module_init(tape_3590_init);
1707module_exit(tape_3590_exit);