blob: d3d1936057b48404f440c94d8ac853d7d92975aa [file] [log] [blame]
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001/*
Stefan Baderb6cba4e2006-03-24 03:15:29 -08002 * tape device discipline for 3590 tapes.
3 *
Frank Munzert3ef32e622009-06-16 10:30:39 +02004 * Copyright IBM Corp. 2001, 2009
Stefan Baderb6cba4e2006-03-24 03:15:29 -08005 * Author(s): Stefan Bader <shbader@de.ibm.com>
6 * Michael Holzheu <holzheu@de.ibm.com>
7 * Martin Schwidefsky <schwidefsky@de.ibm.com>
8 */
9
Michael Holzheu59e36922009-09-11 10:29:07 +020010#define KMSG_COMPONENT "tape_3590"
Michael Holzheubb509912009-12-18 17:43:21 +010011#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
Carsten Otteab640db2009-03-26 15:24:38 +010012
Stefan Baderb6cba4e2006-03-24 03:15:29 -080013#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Stefan Baderb6cba4e2006-03-24 03:15:29 -080015#include <linux/init.h>
16#include <linux/bio.h>
Michael Holzheucced1dd2007-02-05 21:18:26 +010017#include <asm/ebcdic.h>
Stefan Baderb6cba4e2006-03-24 03:15:29 -080018
19#define TAPE_DBF_AREA tape_3590_dbf
Carsten Otteab640db2009-03-26 15:24:38 +010020#define BUFSIZE 512 /* size of buffers for dynamic generated messages */
Stefan Baderb6cba4e2006-03-24 03:15:29 -080021
22#include "tape.h"
23#include "tape_std.h"
24#include "tape_3590.h"
25
Tejun Heo6dca4672010-12-24 16:00:18 +010026static struct workqueue_struct *tape_3590_wq;
27
Stefan Baderb6cba4e2006-03-24 03:15:29 -080028/*
29 * Pointer to debug area.
30 */
31debug_info_t *TAPE_DBF_AREA = NULL;
32EXPORT_SYMBOL(TAPE_DBF_AREA);
33
34/*******************************************************************
Stefan Weileef35c22010-08-06 21:11:15 +020035 * Error Recovery functions:
Stefan Baderb6cba4e2006-03-24 03:15:29 -080036 * - Read Opposite: implemented
37 * - Read Device (buffered) log: BRA
38 * - Read Library log: BRA
39 * - Swap Devices: BRA
Michael Holzheucced1dd2007-02-05 21:18:26 +010040 * - Long Busy: implemented
Stefan Baderb6cba4e2006-03-24 03:15:29 -080041 * - Special Intercept: BRA
42 * - Read Alternate: implemented
43 *******************************************************************/
44
Stefan Baderb6cba4e2006-03-24 03:15:29 -080045static const char *tape_3590_msg[TAPE_3590_MAX_MSG] = {
46 [0x00] = "",
47 [0x10] = "Lost Sense",
48 [0x11] = "Assigned Elsewhere",
49 [0x12] = "Allegiance Reset",
50 [0x13] = "Shared Access Violation",
51 [0x20] = "Command Reject",
52 [0x21] = "Configuration Error",
53 [0x22] = "Protection Exception",
54 [0x23] = "Write Protect",
55 [0x24] = "Write Length",
56 [0x25] = "Read-Only Format",
57 [0x31] = "Beginning of Partition",
58 [0x33] = "End of Partition",
59 [0x34] = "End of Data",
60 [0x35] = "Block not found",
61 [0x40] = "Device Intervention",
62 [0x41] = "Loader Intervention",
63 [0x42] = "Library Intervention",
64 [0x50] = "Write Error",
65 [0x51] = "Erase Error",
66 [0x52] = "Formatting Error",
67 [0x53] = "Read Error",
68 [0x54] = "Unsupported Format",
69 [0x55] = "No Formatting",
70 [0x56] = "Positioning lost",
71 [0x57] = "Read Length",
72 [0x60] = "Unsupported Medium",
73 [0x61] = "Medium Length Error",
74 [0x62] = "Medium removed",
75 [0x64] = "Load Check",
76 [0x65] = "Unload Check",
77 [0x70] = "Equipment Check",
78 [0x71] = "Bus out Check",
79 [0x72] = "Protocol Error",
80 [0x73] = "Interface Error",
81 [0x74] = "Overrun",
82 [0x75] = "Halt Signal",
83 [0x90] = "Device fenced",
84 [0x91] = "Device Path fenced",
85 [0xa0] = "Volume misplaced",
86 [0xa1] = "Volume inaccessible",
87 [0xa2] = "Volume in input",
88 [0xa3] = "Volume ejected",
89 [0xa4] = "All categories reserved",
90 [0xa5] = "Duplicate Volume",
91 [0xa6] = "Library Manager Offline",
92 [0xa7] = "Library Output Station full",
93 [0xa8] = "Vision System non-operational",
94 [0xa9] = "Library Manager Equipment Check",
95 [0xaa] = "Library Equipment Check",
96 [0xab] = "All Library Cells full",
97 [0xac] = "No Cleaner Volumes in Library",
98 [0xad] = "I/O Station door open",
99 [0xae] = "Subsystem environmental alert",
100};
101
Michael Holzheucced1dd2007-02-05 21:18:26 +0100102static int crypt_supported(struct tape_device *device)
103{
104 return TAPE390_CRYPT_SUPPORTED(TAPE_3590_CRYPT_INFO(device));
105}
106
107static int crypt_enabled(struct tape_device *device)
108{
109 return TAPE390_CRYPT_ON(TAPE_3590_CRYPT_INFO(device));
110}
111
112static void ext_to_int_kekl(struct tape390_kekl *in,
113 struct tape3592_kekl *out)
114{
115 int i;
116
117 memset(out, 0, sizeof(*out));
118 if (in->type == TAPE390_KEKL_TYPE_HASH)
119 out->flags |= 0x40;
120 if (in->type_on_tape == TAPE390_KEKL_TYPE_HASH)
121 out->flags |= 0x80;
122 strncpy(out->label, in->label, 64);
123 for (i = strlen(in->label); i < sizeof(out->label); i++)
124 out->label[i] = ' ';
125 ASCEBC(out->label, sizeof(out->label));
126}
127
128static void int_to_ext_kekl(struct tape3592_kekl *in,
129 struct tape390_kekl *out)
130{
131 memset(out, 0, sizeof(*out));
132 if(in->flags & 0x40)
133 out->type = TAPE390_KEKL_TYPE_HASH;
134 else
135 out->type = TAPE390_KEKL_TYPE_LABEL;
136 if(in->flags & 0x80)
137 out->type_on_tape = TAPE390_KEKL_TYPE_HASH;
138 else
139 out->type_on_tape = TAPE390_KEKL_TYPE_LABEL;
140 memcpy(out->label, in->label, sizeof(in->label));
141 EBCASC(out->label, sizeof(in->label));
Heiko Carstens1d802e22009-12-18 17:43:27 +0100142 strim(out->label);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100143}
144
145static void int_to_ext_kekl_pair(struct tape3592_kekl_pair *in,
146 struct tape390_kekl_pair *out)
147{
148 if (in->count == 0) {
149 out->kekl[0].type = TAPE390_KEKL_TYPE_NONE;
150 out->kekl[0].type_on_tape = TAPE390_KEKL_TYPE_NONE;
151 out->kekl[1].type = TAPE390_KEKL_TYPE_NONE;
152 out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE;
153 } else if (in->count == 1) {
154 int_to_ext_kekl(&in->kekl[0], &out->kekl[0]);
155 out->kekl[1].type = TAPE390_KEKL_TYPE_NONE;
156 out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE;
157 } else if (in->count == 2) {
158 int_to_ext_kekl(&in->kekl[0], &out->kekl[0]);
159 int_to_ext_kekl(&in->kekl[1], &out->kekl[1]);
160 } else {
161 printk("Invalid KEKL number: %d\n", in->count);
162 BUG();
163 }
164}
165
166static int check_ext_kekl(struct tape390_kekl *kekl)
167{
168 if (kekl->type == TAPE390_KEKL_TYPE_NONE)
169 goto invalid;
170 if (kekl->type > TAPE390_KEKL_TYPE_HASH)
171 goto invalid;
172 if (kekl->type_on_tape == TAPE390_KEKL_TYPE_NONE)
173 goto invalid;
174 if (kekl->type_on_tape > TAPE390_KEKL_TYPE_HASH)
175 goto invalid;
176 if ((kekl->type == TAPE390_KEKL_TYPE_HASH) &&
177 (kekl->type_on_tape == TAPE390_KEKL_TYPE_LABEL))
178 goto invalid;
179
180 return 0;
181invalid:
182 return -EINVAL;
183}
184
185static int check_ext_kekl_pair(struct tape390_kekl_pair *kekls)
186{
187 if (check_ext_kekl(&kekls->kekl[0]))
188 goto invalid;
189 if (check_ext_kekl(&kekls->kekl[1]))
190 goto invalid;
191
192 return 0;
193invalid:
194 return -EINVAL;
195}
196
197/*
198 * Query KEKLs
199 */
200static int tape_3592_kekl_query(struct tape_device *device,
201 struct tape390_kekl_pair *ext_kekls)
202{
203 struct tape_request *request;
204 struct tape3592_kekl_query_order *order;
205 struct tape3592_kekl_query_data *int_kekls;
206 int rc;
207
208 DBF_EVENT(6, "tape3592_kekl_query\n");
209 int_kekls = kmalloc(sizeof(*int_kekls), GFP_KERNEL|GFP_DMA);
210 if (!int_kekls)
211 return -ENOMEM;
212 request = tape_alloc_request(2, sizeof(*order));
213 if (IS_ERR(request)) {
214 rc = PTR_ERR(request);
215 goto fail_malloc;
216 }
217 order = request->cpdata;
218 memset(order,0,sizeof(*order));
219 order->code = 0xe2;
220 order->max_count = 2;
221 request->op = TO_KEKL_QUERY;
222 tape_ccw_cc(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order);
223 tape_ccw_end(request->cpaddr + 1, READ_SS_DATA, sizeof(*int_kekls),
224 int_kekls);
225 rc = tape_do_io(device, request);
226 if (rc)
227 goto fail_request;
228 int_to_ext_kekl_pair(&int_kekls->kekls, ext_kekls);
229
230 rc = 0;
231fail_request:
232 tape_free_request(request);
233fail_malloc:
234 kfree(int_kekls);
235 return rc;
236}
237
238/*
239 * IOCTL: Query KEKLs
240 */
241static int tape_3592_ioctl_kekl_query(struct tape_device *device,
242 unsigned long arg)
243{
244 int rc;
245 struct tape390_kekl_pair *ext_kekls;
246
247 DBF_EVENT(6, "tape_3592_ioctl_kekl_query\n");
248 if (!crypt_supported(device))
249 return -ENOSYS;
250 if (!crypt_enabled(device))
251 return -EUNATCH;
252 ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
253 if (!ext_kekls)
254 return -ENOMEM;
255 rc = tape_3592_kekl_query(device, ext_kekls);
256 if (rc != 0)
257 goto fail;
258 if (copy_to_user((char __user *) arg, ext_kekls, sizeof(*ext_kekls))) {
259 rc = -EFAULT;
260 goto fail;
261 }
262 rc = 0;
263fail:
264 kfree(ext_kekls);
265 return rc;
266}
267
268static int tape_3590_mttell(struct tape_device *device, int mt_count);
269
270/*
271 * Set KEKLs
272 */
273static int tape_3592_kekl_set(struct tape_device *device,
274 struct tape390_kekl_pair *ext_kekls)
275{
276 struct tape_request *request;
277 struct tape3592_kekl_set_order *order;
278
279 DBF_EVENT(6, "tape3592_kekl_set\n");
280 if (check_ext_kekl_pair(ext_kekls)) {
281 DBF_EVENT(6, "invalid kekls\n");
282 return -EINVAL;
283 }
284 if (tape_3590_mttell(device, 0) != 0)
285 return -EBADSLT;
286 request = tape_alloc_request(1, sizeof(*order));
287 if (IS_ERR(request))
288 return PTR_ERR(request);
289 order = request->cpdata;
290 memset(order, 0, sizeof(*order));
291 order->code = 0xe3;
292 order->kekls.count = 2;
293 ext_to_int_kekl(&ext_kekls->kekl[0], &order->kekls.kekl[0]);
294 ext_to_int_kekl(&ext_kekls->kekl[1], &order->kekls.kekl[1]);
295 request->op = TO_KEKL_SET;
296 tape_ccw_end(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order);
297
298 return tape_do_io_free(device, request);
299}
300
301/*
302 * IOCTL: Set KEKLs
303 */
304static int tape_3592_ioctl_kekl_set(struct tape_device *device,
305 unsigned long arg)
306{
307 int rc;
308 struct tape390_kekl_pair *ext_kekls;
309
310 DBF_EVENT(6, "tape_3592_ioctl_kekl_set\n");
311 if (!crypt_supported(device))
312 return -ENOSYS;
313 if (!crypt_enabled(device))
314 return -EUNATCH;
315 ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
316 if (!ext_kekls)
317 return -ENOMEM;
318 if (copy_from_user(ext_kekls, (char __user *)arg, sizeof(*ext_kekls))) {
319 rc = -EFAULT;
320 goto out;
321 }
322 rc = tape_3592_kekl_set(device, ext_kekls);
323out:
324 kfree(ext_kekls);
325 return rc;
326}
327
328/*
329 * Enable encryption
330 */
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100331static struct tape_request *__tape_3592_enable_crypt(struct tape_device *device)
Michael Holzheucced1dd2007-02-05 21:18:26 +0100332{
333 struct tape_request *request;
334 char *data;
335
336 DBF_EVENT(6, "tape_3592_enable_crypt\n");
337 if (!crypt_supported(device))
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100338 return ERR_PTR(-ENOSYS);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100339 request = tape_alloc_request(2, 72);
340 if (IS_ERR(request))
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100341 return request;
Michael Holzheucced1dd2007-02-05 21:18:26 +0100342 data = request->cpdata;
343 memset(data,0,72);
344
345 data[0] = 0x05;
346 data[36 + 0] = 0x03;
347 data[36 + 1] = 0x03;
348 data[36 + 4] = 0x40;
349 data[36 + 6] = 0x01;
350 data[36 + 14] = 0x2f;
351 data[36 + 18] = 0xc3;
352 data[36 + 35] = 0x72;
353 request->op = TO_CRYPT_ON;
354 tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
355 tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100356 return request;
357}
358
359static int tape_3592_enable_crypt(struct tape_device *device)
360{
361 struct tape_request *request;
362
363 request = __tape_3592_enable_crypt(device);
364 if (IS_ERR(request))
365 return PTR_ERR(request);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100366 return tape_do_io_free(device, request);
367}
368
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100369static void tape_3592_enable_crypt_async(struct tape_device *device)
370{
371 struct tape_request *request;
372
373 request = __tape_3592_enable_crypt(device);
374 if (!IS_ERR(request))
375 tape_do_io_async_free(device, request);
376}
377
Michael Holzheucced1dd2007-02-05 21:18:26 +0100378/*
379 * Disable encryption
380 */
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100381static struct tape_request *__tape_3592_disable_crypt(struct tape_device *device)
Michael Holzheucced1dd2007-02-05 21:18:26 +0100382{
383 struct tape_request *request;
384 char *data;
385
386 DBF_EVENT(6, "tape_3592_disable_crypt\n");
387 if (!crypt_supported(device))
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100388 return ERR_PTR(-ENOSYS);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100389 request = tape_alloc_request(2, 72);
390 if (IS_ERR(request))
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100391 return request;
Michael Holzheucced1dd2007-02-05 21:18:26 +0100392 data = request->cpdata;
393 memset(data,0,72);
394
395 data[0] = 0x05;
396 data[36 + 0] = 0x03;
397 data[36 + 1] = 0x03;
398 data[36 + 35] = 0x32;
399
400 request->op = TO_CRYPT_OFF;
401 tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
402 tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
403
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100404 return request;
405}
406
407static int tape_3592_disable_crypt(struct tape_device *device)
408{
409 struct tape_request *request;
410
411 request = __tape_3592_disable_crypt(device);
412 if (IS_ERR(request))
413 return PTR_ERR(request);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100414 return tape_do_io_free(device, request);
415}
416
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100417static void tape_3592_disable_crypt_async(struct tape_device *device)
418{
419 struct tape_request *request;
420
421 request = __tape_3592_disable_crypt(device);
422 if (!IS_ERR(request))
423 tape_do_io_async_free(device, request);
424}
425
Michael Holzheucced1dd2007-02-05 21:18:26 +0100426/*
427 * IOCTL: Set encryption status
428 */
429static int tape_3592_ioctl_crypt_set(struct tape_device *device,
430 unsigned long arg)
431{
432 struct tape390_crypt_info info;
433
434 DBF_EVENT(6, "tape_3592_ioctl_crypt_set\n");
435 if (!crypt_supported(device))
436 return -ENOSYS;
437 if (copy_from_user(&info, (char __user *)arg, sizeof(info)))
438 return -EFAULT;
439 if (info.status & ~TAPE390_CRYPT_ON_MASK)
440 return -EINVAL;
441 if (info.status & TAPE390_CRYPT_ON_MASK)
442 return tape_3592_enable_crypt(device);
443 else
444 return tape_3592_disable_crypt(device);
445}
446
447static int tape_3590_sense_medium(struct tape_device *device);
448
449/*
450 * IOCTL: Query enryption status
451 */
452static int tape_3592_ioctl_crypt_query(struct tape_device *device,
453 unsigned long arg)
454{
455 DBF_EVENT(6, "tape_3592_ioctl_crypt_query\n");
456 if (!crypt_supported(device))
457 return -ENOSYS;
458 tape_3590_sense_medium(device);
459 if (copy_to_user((char __user *) arg, &TAPE_3590_CRYPT_INFO(device),
460 sizeof(TAPE_3590_CRYPT_INFO(device))))
461 return -EFAULT;
462 else
463 return 0;
464}
465
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800466/*
467 * 3590 IOCTL Overload
468 */
469static int
470tape_3590_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
471{
472 switch (cmd) {
473 case TAPE390_DISPLAY: {
474 struct display_struct disp;
475
476 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)))
477 return -EFAULT;
478
479 return tape_std_display(device, &disp);
480 }
Michael Holzheucced1dd2007-02-05 21:18:26 +0100481 case TAPE390_KEKL_SET:
482 return tape_3592_ioctl_kekl_set(device, arg);
483 case TAPE390_KEKL_QUERY:
484 return tape_3592_ioctl_kekl_query(device, arg);
485 case TAPE390_CRYPT_SET:
486 return tape_3592_ioctl_crypt_set(device, arg);
487 case TAPE390_CRYPT_QUERY:
488 return tape_3592_ioctl_crypt_query(device, arg);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800489 default:
490 return -EINVAL; /* no additional ioctls */
491 }
492}
493
494/*
495 * SENSE Medium: Get Sense data about medium state
496 */
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100497static int tape_3590_sense_medium(struct tape_device *device)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800498{
499 struct tape_request *request;
500
501 request = tape_alloc_request(1, 128);
502 if (IS_ERR(request))
503 return PTR_ERR(request);
504 request->op = TO_MSEN;
505 tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
506 return tape_do_io_free(device, request);
507}
508
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100509static void tape_3590_sense_medium_async(struct tape_device *device)
510{
511 struct tape_request *request;
512
513 request = tape_alloc_request(1, 128);
514 if (IS_ERR(request))
515 return;
516 request->op = TO_MSEN;
517 tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
518 tape_do_io_async_free(device, request);
519}
520
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800521/*
522 * MTTELL: Tell block. Return the number of block relative to current file.
523 */
524static int
525tape_3590_mttell(struct tape_device *device, int mt_count)
526{
527 __u64 block_id;
528 int rc;
529
530 rc = tape_std_read_block_id(device, &block_id);
531 if (rc)
532 return rc;
533 return block_id >> 32;
534}
535
536/*
537 * MTSEEK: seek to the specified block.
538 */
539static int
540tape_3590_mtseek(struct tape_device *device, int count)
541{
542 struct tape_request *request;
543
544 DBF_EVENT(6, "xsee id: %x\n", count);
545 request = tape_alloc_request(3, 4);
546 if (IS_ERR(request))
547 return PTR_ERR(request);
548 request->op = TO_LBL;
549 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
550 *(__u32 *) request->cpdata = count;
551 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
552 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
553 return tape_do_io_free(device, request);
554}
555
556/*
557 * Read Opposite Error Recovery Function:
558 * Used, when Read Forward does not work
559 */
560static void
561tape_3590_read_opposite(struct tape_device *device,
562 struct tape_request *request)
563{
564 struct tape_3590_disc_data *data;
565
566 /*
567 * We have allocated 4 ccws in tape_std_read, so we can now
568 * transform the request to a read backward, followed by a
569 * forward space block.
570 */
571 request->op = TO_RBA;
572 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
573 data = device->discdata;
574 tape_ccw_cc_idal(request->cpaddr + 1, data->read_back_op,
575 device->char_data.idal_buf);
576 tape_ccw_cc(request->cpaddr + 2, FORSPACEBLOCK, 0, NULL);
577 tape_ccw_end(request->cpaddr + 3, NOP, 0, NULL);
578 DBF_EVENT(6, "xrop ccwg\n");
579}
580
581/*
582 * Read Attention Msg
583 * This should be done after an interrupt with attention bit (0x80)
584 * in device state.
585 *
586 * After a "read attention message" request there are two possible
587 * results:
588 *
589 * 1. A unit check is presented, when attention sense is present (e.g. when
590 * a medium has been unloaded). The attention sense comes then
591 * together with the unit check. The recovery action is either "retry"
592 * (in case there is an attention message pending) or "permanent error".
593 *
594 * 2. The attention msg is written to the "read subsystem data" buffer.
595 * In this case we probably should print it to the console.
596 */
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100597static void tape_3590_read_attmsg_async(struct tape_device *device)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800598{
599 struct tape_request *request;
600 char *buf;
601
602 request = tape_alloc_request(3, 4096);
603 if (IS_ERR(request))
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100604 return;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800605 request->op = TO_READ_ATTMSG;
606 buf = request->cpdata;
607 buf[0] = PREP_RD_SS_DATA;
608 buf[6] = RD_ATTMSG; /* read att msg */
609 tape_ccw_cc(request->cpaddr, PERFORM_SS_FUNC, 12, buf);
610 tape_ccw_cc(request->cpaddr + 1, READ_SS_DATA, 4096 - 12, buf + 12);
611 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100612 tape_do_io_async_free(device, request);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800613}
614
615/*
616 * These functions are used to schedule follow-up actions from within an
617 * interrupt context (like unsolicited interrupts).
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100618 * Note: the work handler is called by the system work queue. The tape
619 * commands started by the handler need to be asynchrounous, otherwise
620 * a deadlock can occur e.g. in case of a deferred cc=1 (see __tape_do_irq).
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800621 */
Stefan Bader2cc924b2006-04-27 18:40:16 -0700622struct work_handler_data {
623 struct tape_device *device;
624 enum tape_op op;
625 struct work_struct work;
626};
627
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800628static void
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100629tape_3590_work_handler(struct work_struct *work)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800630{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100631 struct work_handler_data *p =
632 container_of(work, struct work_handler_data, work);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800633
634 switch (p->op) {
635 case TO_MSEN:
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100636 tape_3590_sense_medium_async(p->device);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800637 break;
638 case TO_READ_ATTMSG:
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100639 tape_3590_read_attmsg_async(p->device);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800640 break;
Michael Holzheucced1dd2007-02-05 21:18:26 +0100641 case TO_CRYPT_ON:
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100642 tape_3592_enable_crypt_async(p->device);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100643 break;
644 case TO_CRYPT_OFF:
Martin Schwidefsky0c2bd9b2011-03-03 17:56:07 +0100645 tape_3592_disable_crypt_async(p->device);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100646 break;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800647 default:
648 DBF_EVENT(3, "T3590: work handler undefined for "
649 "operation 0x%02x\n", p->op);
650 }
651 tape_put_device(p->device);
652 kfree(p);
653}
654
655static int
656tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
657{
Stefan Bader2cc924b2006-04-27 18:40:16 -0700658 struct work_handler_data *p;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800659
660 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
661 return -ENOMEM;
662
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100663 INIT_WORK(&p->work, tape_3590_work_handler);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800664
Martin Schwidefsky8fd138c2009-12-07 12:52:03 +0100665 p->device = tape_get_device(device);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800666 p->op = op;
667
Tejun Heo6dca4672010-12-24 16:00:18 +0100668 queue_work(tape_3590_wq, &p->work);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800669 return 0;
670}
671
Michael Holzheucced1dd2007-02-05 21:18:26 +0100672static void tape_3590_med_state_set(struct tape_device *device,
673 struct tape_3590_med_sense *sense)
674{
675 struct tape390_crypt_info *c_info;
676
677 c_info = &TAPE_3590_CRYPT_INFO(device);
678
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200679 DBF_EVENT(6, "medium state: %x:%x\n", sense->macst, sense->masst);
680 switch (sense->macst) {
681 case 0x04:
682 case 0x05:
683 case 0x06:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100684 tape_med_state_set(device, MS_UNLOADED);
685 TAPE_3590_CRYPT_INFO(device).medium_status = 0;
686 return;
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200687 case 0x08:
688 case 0x09:
689 tape_med_state_set(device, MS_LOADED);
690 break;
691 default:
692 tape_med_state_set(device, MS_UNKNOWN);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100693 return;
694 }
Michael Holzheucced1dd2007-02-05 21:18:26 +0100695 c_info->medium_status |= TAPE390_MEDIUM_LOADED_MASK;
696 if (sense->flags & MSENSE_CRYPT_MASK) {
Carsten Otteab640db2009-03-26 15:24:38 +0100697 DBF_EVENT(6, "Medium is encrypted (%04x)\n", sense->flags);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100698 c_info->medium_status |= TAPE390_MEDIUM_ENCRYPTED_MASK;
699 } else {
700 DBF_EVENT(6, "Medium is not encrypted %04x\n", sense->flags);
701 c_info->medium_status &= ~TAPE390_MEDIUM_ENCRYPTED_MASK;
702 }
703}
704
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800705/*
706 * The done handler is called at device/channel end and wakes up the sleeping
707 * process
708 */
709static int
710tape_3590_done(struct tape_device *device, struct tape_request *request)
711{
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800712
713 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
714
715 switch (request->op) {
716 case TO_BSB:
717 case TO_BSF:
718 case TO_DSE:
719 case TO_FSB:
720 case TO_FSF:
721 case TO_LBL:
722 case TO_RFO:
723 case TO_RBA:
724 case TO_REW:
725 case TO_WRI:
726 case TO_WTM:
727 case TO_BLOCK:
728 case TO_LOAD:
729 tape_med_state_set(device, MS_LOADED);
730 break;
731 case TO_RUN:
732 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100733 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800734 break;
735 case TO_MSEN:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100736 tape_3590_med_state_set(device, request->cpdata);
737 break;
738 case TO_CRYPT_ON:
739 TAPE_3590_CRYPT_INFO(device).status
740 |= TAPE390_CRYPT_ON_MASK;
741 *(device->modeset_byte) |= 0x03;
742 break;
743 case TO_CRYPT_OFF:
744 TAPE_3590_CRYPT_INFO(device).status
745 &= ~TAPE390_CRYPT_ON_MASK;
746 *(device->modeset_byte) &= ~0x03;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800747 break;
748 case TO_RBI: /* RBI seems to succeed even without medium loaded. */
749 case TO_NOP: /* Same to NOP. */
750 case TO_READ_CONFIG:
751 case TO_READ_ATTMSG:
752 case TO_DIS:
753 case TO_ASSIGN:
754 case TO_UNASSIGN:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800755 case TO_SIZE:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100756 case TO_KEKL_SET:
757 case TO_KEKL_QUERY:
Michael Holzheue2963062007-05-04 18:47:53 +0200758 case TO_RDC:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800759 break;
760 }
761 return TAPE_IO_SUCCESS;
762}
763
764/*
Stefan Weileef35c22010-08-06 21:11:15 +0200765 * This function is called, when error recovery was successful
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800766 */
767static inline int
768tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request)
769{
Coly Li73ac36e2009-01-07 18:09:16 -0800770 DBF_EVENT(3, "Error Recovery successful for %s\n",
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800771 tape_op_verbose[request->op]);
772 return tape_3590_done(device, request);
773}
774
775/*
Stefan Weileef35c22010-08-06 21:11:15 +0200776 * This function is called, when error recovery was not successful
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800777 */
778static inline int
779tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
780 struct irb *irb, int rc)
781{
782 DBF_EVENT(3, "Error Recovery failed for %s\n",
783 tape_op_verbose[request->op]);
784 tape_dump_sense_dbf(device, request, irb);
785 return rc;
786}
787
788/*
789 * Error Recovery do retry
790 */
791static inline int
792tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
793 struct irb *irb)
794{
795 DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]);
796 tape_dump_sense_dbf(device, request, irb);
797 return TAPE_IO_RETRY;
798}
799
800/*
801 * Handle unsolicited interrupts
802 */
803static int
804tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
805{
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200806 if (irb->scsw.cmd.dstat == DEV_STAT_CHN_END)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800807 /* Probably result of halt ssch */
808 return TAPE_IO_PENDING;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200809 else if (irb->scsw.cmd.dstat == 0x85)
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200810 /* Device Ready */
811 DBF_EVENT(3, "unsol.irq! tape ready: %08x\n", device->cdev_id);
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200812 else if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800813 tape_3590_schedule_work(device, TO_READ_ATTMSG);
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200814 } else {
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800815 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
Carsten Otteab640db2009-03-26 15:24:38 +0100816 tape_dump_sense_dbf(device, NULL, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800817 }
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200818 /* check medium state */
819 tape_3590_schedule_work(device, TO_MSEN);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800820 return TAPE_IO_SUCCESS;
821}
822
823/*
824 * Basic Recovery routine
825 */
826static int
827tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
828 struct irb *irb, int rc)
829{
830 struct tape_3590_sense *sense;
831
832 sense = (struct tape_3590_sense *) irb->ecw;
833
834 switch (sense->bra) {
835 case SENSE_BRA_PER:
836 return tape_3590_erp_failed(device, request, irb, rc);
837 case SENSE_BRA_CONT:
838 return tape_3590_erp_succeded(device, request);
839 case SENSE_BRA_RE:
840 return tape_3590_erp_retry(device, request, irb);
841 case SENSE_BRA_DRE:
842 return tape_3590_erp_failed(device, request, irb, rc);
843 default:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800844 BUG();
845 return TAPE_IO_STOP;
846 }
847}
848
849/*
850 * RDL: Read Device (buffered) log
851 */
852static int
853tape_3590_erp_read_buf_log(struct tape_device *device,
854 struct tape_request *request, struct irb *irb)
855{
856 /*
857 * We just do the basic error recovery at the moment (retry).
858 * Perhaps in the future, we read the log and dump it somewhere...
859 */
860 return tape_3590_erp_basic(device, request, irb, -EIO);
861}
862
863/*
864 * SWAP: Swap Devices
865 */
866static int
867tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
868 struct irb *irb)
869{
870 /*
871 * This error recovery should swap the tapes
872 * if the original has a problem. The operation
873 * should proceed with the new tape... this
874 * should probably be done in user space!
875 */
Carsten Otteab640db2009-03-26 15:24:38 +0100876 dev_warn (&device->cdev->dev, "The tape medium must be loaded into a "
877 "different tape unit\n");
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800878 return tape_3590_erp_basic(device, request, irb, -EIO);
879}
880
881/*
882 * LBY: Long Busy
883 */
884static int
885tape_3590_erp_long_busy(struct tape_device *device,
886 struct tape_request *request, struct irb *irb)
887{
Michael Holzheucced1dd2007-02-05 21:18:26 +0100888 DBF_EVENT(6, "Device is busy\n");
889 return TAPE_IO_LONG_BUSY;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800890}
891
892/*
893 * SPI: Special Intercept
894 */
895static int
896tape_3590_erp_special_interrupt(struct tape_device *device,
897 struct tape_request *request, struct irb *irb)
898{
899 return tape_3590_erp_basic(device, request, irb, -EIO);
900}
901
902/*
903 * RDA: Read Alternate
904 */
905static int
906tape_3590_erp_read_alternate(struct tape_device *device,
907 struct tape_request *request, struct irb *irb)
908{
909 struct tape_3590_disc_data *data;
910
911 /*
912 * The issued Read Backward or Read Previous command is not
913 * supported by the device
914 * The recovery action should be to issue another command:
915 * Read Revious: if Read Backward is not supported
916 * Read Backward: if Read Previous is not supported
917 */
918 data = device->discdata;
919 if (data->read_back_op == READ_PREVIOUS) {
920 DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
921 device->cdev_id);
922 data->read_back_op = READ_BACKWARD;
923 } else {
924 DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
925 device->cdev_id);
926 data->read_back_op = READ_PREVIOUS;
927 }
928 tape_3590_read_opposite(device, request);
929 return tape_3590_erp_retry(device, request, irb);
930}
931
932/*
933 * Error Recovery read opposite
934 */
935static int
936tape_3590_erp_read_opposite(struct tape_device *device,
937 struct tape_request *request, struct irb *irb)
938{
939 switch (request->op) {
940 case TO_RFO:
941 /*
942 * We did read forward, but the data could not be read.
943 * We will read backward and then skip forward again.
944 */
945 tape_3590_read_opposite(device, request);
946 return tape_3590_erp_retry(device, request, irb);
947 case TO_RBA:
948 /* We tried to read forward and backward, but hat no success */
949 return tape_3590_erp_failed(device, request, irb, -EIO);
950 break;
951 default:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800952 return tape_3590_erp_failed(device, request, irb, -EIO);
953 }
954}
955
956/*
957 * Print an MIM (Media Information Message) (message code f0)
958 */
959static void
960tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
961{
962 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +0100963 char *exception, *service;
964
965 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
966 service = kmalloc(BUFSIZE, GFP_ATOMIC);
967
968 if (!exception || !service)
969 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800970
971 sense = (struct tape_3590_sense *) irb->ecw;
972 /* Exception Message */
973 switch (sense->fmt.f70.emc) {
974 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +0100975 snprintf(exception, BUFSIZE, "Data degraded");
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800976 break;
977 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +0100978 snprintf(exception, BUFSIZE, "Data degraded in partion %i",
979 sense->fmt.f70.mp);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800980 break;
981 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +0100982 snprintf(exception, BUFSIZE, "Medium degraded");
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800983 break;
984 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +0100985 snprintf(exception, BUFSIZE, "Medium degraded in partition %i",
986 sense->fmt.f70.mp);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800987 break;
988 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +0100989 snprintf(exception, BUFSIZE, "Block 0 Error");
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800990 break;
991 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +0100992 snprintf(exception, BUFSIZE, "Medium Exception 0x%02x",
993 sense->fmt.f70.md);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800994 break;
995 default:
Carsten Otteab640db2009-03-26 15:24:38 +0100996 snprintf(exception, BUFSIZE, "0x%02x",
997 sense->fmt.f70.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800998 break;
999 }
1000 /* Service Message */
1001 switch (sense->fmt.f70.smc) {
1002 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001003 snprintf(service, BUFSIZE, "Reference Media maintenance "
1004 "procedure %i", sense->fmt.f70.md);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001005 break;
1006 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001007 snprintf(service, BUFSIZE, "0x%02x",
1008 sense->fmt.f70.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001009 break;
1010 }
Carsten Otteab640db2009-03-26 15:24:38 +01001011
1012 dev_warn (&device->cdev->dev, "Tape media information: exception %s, "
1013 "service %s\n", exception, service);
1014
1015out_nomem:
1016 kfree(exception);
1017 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001018}
1019
1020/*
1021 * Print an I/O Subsystem Service Information Message (message code f1)
1022 */
1023static void
1024tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
1025{
1026 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +01001027 char *exception, *service;
1028
1029 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1030 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1031
1032 if (!exception || !service)
1033 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001034
1035 sense = (struct tape_3590_sense *) irb->ecw;
1036 /* Exception Message */
1037 switch (sense->fmt.f71.emc) {
1038 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001039 snprintf(exception, BUFSIZE, "Effect of failure is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001040 break;
1041 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001042 snprintf(exception, BUFSIZE, "CU Exception - no performance "
1043 "impact");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001044 break;
1045 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001046 snprintf(exception, BUFSIZE, "CU Exception on channel "
1047 "interface 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001048 break;
1049 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001050 snprintf(exception, BUFSIZE, "CU Exception on device path "
1051 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001052 break;
1053 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001054 snprintf(exception, BUFSIZE, "CU Exception on library path "
1055 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001056 break;
1057 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001058 snprintf(exception, BUFSIZE, "CU Exception on node 0x%02x",
1059 sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001060 break;
1061 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001062 snprintf(exception, BUFSIZE, "CU Exception on partition "
1063 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001064 break;
1065 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001066 snprintf(exception, BUFSIZE, "0x%02x",
1067 sense->fmt.f71.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001068 }
1069 /* Service Message */
1070 switch (sense->fmt.f71.smc) {
1071 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001072 snprintf(service, BUFSIZE, "Repair impact is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001073 break;
1074 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001075 snprintf(service, BUFSIZE, "Repair will not impact cu "
1076 "performance");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001077 break;
1078 case 0x03:
1079 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001080 snprintf(service, BUFSIZE, "Repair will disable node "
1081 "0x%x on CU", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001082 else
Carsten Otteab640db2009-03-26 15:24:38 +01001083 snprintf(service, BUFSIZE, "Repair will disable "
1084 "nodes (0x%x-0x%x) on CU", sense->fmt.f71.md[1],
1085 sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001086 break;
1087 case 0x04:
1088 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001089 snprintf(service, BUFSIZE, "Repair will disable "
1090 "channel path 0x%x on CU",
1091 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001092 else
Masanari Iida6774def2014-11-05 22:26:48 +09001093 snprintf(service, BUFSIZE, "Repair will disable channel"
Carsten Otteab640db2009-03-26 15:24:38 +01001094 " paths (0x%x-0x%x) on CU",
1095 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001096 break;
1097 case 0x05:
1098 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001099 snprintf(service, BUFSIZE, "Repair will disable device"
1100 " path 0x%x on CU", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001101 else
Carsten Otteab640db2009-03-26 15:24:38 +01001102 snprintf(service, BUFSIZE, "Repair will disable device"
1103 " paths (0x%x-0x%x) on CU",
1104 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001105 break;
1106 case 0x06:
1107 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001108 snprintf(service, BUFSIZE, "Repair will disable "
1109 "library path 0x%x on CU",
1110 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001111 else
Carsten Otteab640db2009-03-26 15:24:38 +01001112 snprintf(service, BUFSIZE, "Repair will disable "
1113 "library paths (0x%x-0x%x) on CU",
1114 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001115 break;
1116 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001117 snprintf(service, BUFSIZE, "Repair will disable access to CU");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001118 break;
1119 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001120 snprintf(service, BUFSIZE, "0x%02x",
1121 sense->fmt.f71.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001122 }
Carsten Otteab640db2009-03-26 15:24:38 +01001123
1124 dev_warn (&device->cdev->dev, "I/O subsystem information: exception"
1125 " %s, service %s\n", exception, service);
1126out_nomem:
1127 kfree(exception);
1128 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001129}
1130
1131/*
1132 * Print an Device Subsystem Service Information Message (message code f2)
1133 */
1134static void
1135tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
1136{
1137 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +01001138 char *exception, *service;
1139
1140 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1141 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1142
1143 if (!exception || !service)
1144 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001145
1146 sense = (struct tape_3590_sense *) irb->ecw;
1147 /* Exception Message */
1148 switch (sense->fmt.f71.emc) {
1149 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001150 snprintf(exception, BUFSIZE, "Effect of failure is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001151 break;
1152 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001153 snprintf(exception, BUFSIZE, "DV Exception - no performance"
1154 " impact");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001155 break;
1156 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001157 snprintf(exception, BUFSIZE, "DV Exception on channel "
1158 "interface 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001159 break;
1160 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001161 snprintf(exception, BUFSIZE, "DV Exception on loader 0x%02x",
1162 sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001163 break;
1164 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001165 snprintf(exception, BUFSIZE, "DV Exception on message display"
1166 " 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001167 break;
1168 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001169 snprintf(exception, BUFSIZE, "DV Exception in tape path");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001170 break;
1171 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001172 snprintf(exception, BUFSIZE, "DV Exception in drive");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001173 break;
1174 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001175 snprintf(exception, BUFSIZE, "0x%02x",
1176 sense->fmt.f71.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001177 }
1178 /* Service Message */
1179 switch (sense->fmt.f71.smc) {
1180 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001181 snprintf(service, BUFSIZE, "Repair impact is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001182 break;
1183 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001184 snprintf(service, BUFSIZE, "Repair will not impact device "
1185 "performance");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001186 break;
1187 case 0x03:
1188 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001189 snprintf(service, BUFSIZE, "Repair will disable "
1190 "channel path 0x%x on DV",
1191 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001192 else
Carsten Otteab640db2009-03-26 15:24:38 +01001193 snprintf(service, BUFSIZE, "Repair will disable "
1194 "channel path (0x%x-0x%x) on DV",
1195 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001196 break;
1197 case 0x04:
1198 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001199 snprintf(service, BUFSIZE, "Repair will disable "
1200 "interface 0x%x on DV", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001201 else
Carsten Otteab640db2009-03-26 15:24:38 +01001202 snprintf(service, BUFSIZE, "Repair will disable "
1203 "interfaces (0x%x-0x%x) on DV",
1204 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001205 break;
1206 case 0x05:
1207 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001208 snprintf(service, BUFSIZE, "Repair will disable loader"
1209 " 0x%x on DV", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001210 else
Carsten Otteab640db2009-03-26 15:24:38 +01001211 snprintf(service, BUFSIZE, "Repair will disable loader"
1212 " (0x%x-0x%x) on DV",
1213 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001214 break;
1215 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001216 snprintf(service, BUFSIZE, "Repair will disable access to DV");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001217 break;
1218 case 0x08:
1219 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001220 snprintf(service, BUFSIZE, "Repair will disable "
1221 "message display 0x%x on DV",
1222 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001223 else
Carsten Otteab640db2009-03-26 15:24:38 +01001224 snprintf(service, BUFSIZE, "Repair will disable "
1225 "message displays (0x%x-0x%x) on DV",
1226 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001227 break;
1228 case 0x09:
Carsten Otteab640db2009-03-26 15:24:38 +01001229 snprintf(service, BUFSIZE, "Clean DV");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001230 break;
1231 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001232 snprintf(service, BUFSIZE, "0x%02x",
1233 sense->fmt.f71.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001234 }
Carsten Otteab640db2009-03-26 15:24:38 +01001235
1236 dev_warn (&device->cdev->dev, "Device subsystem information: exception"
1237 " %s, service %s\n", exception, service);
1238out_nomem:
1239 kfree(exception);
1240 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001241}
1242
1243/*
1244 * Print standard ERA Message
1245 */
1246static void
1247tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
1248{
1249 struct tape_3590_sense *sense;
1250
1251 sense = (struct tape_3590_sense *) irb->ecw;
1252 if (sense->mc == 0)
1253 return;
1254 if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) {
1255 if (tape_3590_msg[sense->mc] != NULL)
Carsten Otteab640db2009-03-26 15:24:38 +01001256 dev_warn (&device->cdev->dev, "The tape unit has "
1257 "issued sense message %s\n",
1258 tape_3590_msg[sense->mc]);
1259 else
1260 dev_warn (&device->cdev->dev, "The tape unit has "
1261 "issued an unknown sense message code 0x%x\n",
1262 sense->mc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001263 return;
1264 }
1265 if (sense->mc == 0xf0) {
1266 /* Standard Media Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001267 dev_warn (&device->cdev->dev, "MIM SEV=%i, MC=%02x, ES=%x/%x, "
1268 "RC=%02x-%04x-%02x\n", sense->fmt.f70.sev, sense->mc,
1269 sense->fmt.f70.emc, sense->fmt.f70.smc,
1270 sense->fmt.f70.refcode, sense->fmt.f70.mid,
1271 sense->fmt.f70.fid);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001272 tape_3590_print_mim_msg_f0(device, irb);
1273 return;
1274 }
1275 if (sense->mc == 0xf1) {
1276 /* Standard I/O Subsystem Service Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001277 dev_warn (&device->cdev->dev, "IOSIM SEV=%i, DEVTYPE=3590/%02x,"
1278 " MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1279 sense->fmt.f71.sev, device->cdev->id.dev_model,
1280 sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1281 sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1282 sense->fmt.f71.refcode3);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001283 tape_3590_print_io_sim_msg_f1(device, irb);
1284 return;
1285 }
1286 if (sense->mc == 0xf2) {
1287 /* Standard Device Service Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001288 dev_warn (&device->cdev->dev, "DEVSIM SEV=%i, DEVTYPE=3590/%02x"
1289 ", MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1290 sense->fmt.f71.sev, device->cdev->id.dev_model,
1291 sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1292 sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1293 sense->fmt.f71.refcode3);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001294 tape_3590_print_dev_sim_msg_f2(device, irb);
1295 return;
1296 }
1297 if (sense->mc == 0xf3) {
1298 /* Standard Library Service Information Message */
1299 return;
1300 }
Carsten Otteab640db2009-03-26 15:24:38 +01001301 dev_warn (&device->cdev->dev, "The tape unit has issued an unknown "
1302 "sense message code %x\n", sense->mc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001303}
1304
Michael Holzheucced1dd2007-02-05 21:18:26 +01001305static int tape_3590_crypt_error(struct tape_device *device,
1306 struct tape_request *request, struct irb *irb)
1307{
Heiko Carstens160fbf22011-05-23 10:24:28 +02001308 u8 cu_rc;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001309 u16 ekm_rc2;
Kay Sievers2a0217d2008-10-10 21:33:09 +02001310 char *sense;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001311
1312 sense = ((struct tape_3590_sense *) irb->ecw)->fmt.data;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001313 cu_rc = sense[0];
Michael Holzheucced1dd2007-02-05 21:18:26 +01001314 ekm_rc2 = *((u16*) &sense[10]);
1315 if ((cu_rc == 0) && (ekm_rc2 == 0xee31))
1316 /* key not defined on EKM */
1317 return tape_3590_erp_basic(device, request, irb, -EKEYREJECTED);
1318 if ((cu_rc == 1) || (cu_rc == 2))
1319 /* No connection to EKM */
1320 return tape_3590_erp_basic(device, request, irb, -ENOTCONN);
1321
Carsten Otteab640db2009-03-26 15:24:38 +01001322 dev_err (&device->cdev->dev, "The tape unit failed to obtain the "
1323 "encryption key from EKM\n");
Michael Holzheucced1dd2007-02-05 21:18:26 +01001324
1325 return tape_3590_erp_basic(device, request, irb, -ENOKEY);
1326}
1327
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001328/*
1329 * 3590 error Recovery routine:
1330 * If possible, it tries to recover from the error. If this is not possible,
1331 * inform the user about the problem.
1332 */
1333static int
1334tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
1335 struct irb *irb)
1336{
1337 struct tape_3590_sense *sense;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001338
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001339 sense = (struct tape_3590_sense *) irb->ecw;
1340
Michael Holzheucced1dd2007-02-05 21:18:26 +01001341 DBF_EVENT(6, "Unit Check: RQC = %x\n", sense->rc_rqc);
1342
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001343 /*
1344 * First check all RC-QRCs where we want to do something special
1345 * - "break": basic error recovery is done
1346 * - "goto out:": just print error message if available
1347 */
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001348 switch (sense->rc_rqc) {
1349
1350 case 0x1110:
1351 tape_3590_print_era_msg(device, irb);
1352 return tape_3590_erp_read_buf_log(device, request, irb);
1353
1354 case 0x2011:
1355 tape_3590_print_era_msg(device, irb);
1356 return tape_3590_erp_read_alternate(device, request, irb);
1357
1358 case 0x2230:
1359 case 0x2231:
1360 tape_3590_print_era_msg(device, irb);
1361 return tape_3590_erp_special_interrupt(device, request, irb);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001362 case 0x2240:
1363 return tape_3590_crypt_error(device, request, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001364
1365 case 0x3010:
1366 DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1367 device->cdev_id);
1368 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1369 case 0x3012:
1370 DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1371 device->cdev_id);
1372 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1373 case 0x3020:
1374 DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
1375 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1376
1377 case 0x3122:
1378 DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1379 device->cdev_id);
1380 return tape_3590_erp_basic(device, request, irb, -EIO);
1381 case 0x3123:
1382 DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1383 device->cdev_id);
1384 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001385 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001386 return tape_3590_erp_basic(device, request, irb, 0);
1387
1388 case 0x4010:
1389 /*
1390 * print additional msg since default msg
1391 * "device intervention" is not very meaningfull
1392 */
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001393 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001394 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001395 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1396 case 0x4012: /* Device Long Busy */
Michael Holzheucced1dd2007-02-05 21:18:26 +01001397 /* XXX: Also use long busy handling here? */
1398 DBF_EVENT(6, "(%08x): LONG BUSY\n", device->cdev_id);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001399 tape_3590_print_era_msg(device, irb);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001400 return tape_3590_erp_basic(device, request, irb, -EBUSY);
1401 case 0x4014:
1402 DBF_EVENT(6, "(%08x): Crypto LONG BUSY\n", device->cdev_id);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001403 return tape_3590_erp_long_busy(device, request, irb);
1404
1405 case 0x5010:
1406 if (sense->rac == 0xd0) {
1407 /* Swap */
1408 tape_3590_print_era_msg(device, irb);
1409 return tape_3590_erp_swap(device, request, irb);
1410 }
1411 if (sense->rac == 0x26) {
1412 /* Read Opposite */
1413 tape_3590_print_era_msg(device, irb);
1414 return tape_3590_erp_read_opposite(device, request,
1415 irb);
1416 }
1417 return tape_3590_erp_basic(device, request, irb, -EIO);
1418 case 0x5020:
1419 case 0x5021:
1420 case 0x5022:
1421 case 0x5040:
1422 case 0x5041:
1423 case 0x5042:
1424 tape_3590_print_era_msg(device, irb);
1425 return tape_3590_erp_swap(device, request, irb);
1426
1427 case 0x5110:
1428 case 0x5111:
1429 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1430
1431 case 0x5120:
1432 case 0x1120:
1433 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001434 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001435 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1436
1437 case 0x6020:
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001438 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1439
1440 case 0x8011:
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001441 return tape_3590_erp_basic(device, request, irb, -EPERM);
1442 case 0x8013:
Carsten Otteab640db2009-03-26 15:24:38 +01001443 dev_warn (&device->cdev->dev, "A different host has privileged"
1444 " access to the tape unit\n");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001445 return tape_3590_erp_basic(device, request, irb, -EPERM);
1446 default:
1447 return tape_3590_erp_basic(device, request, irb, -EIO);
1448 }
1449}
1450
1451/*
1452 * 3590 interrupt handler:
1453 */
1454static int
1455tape_3590_irq(struct tape_device *device, struct tape_request *request,
1456 struct irb *irb)
1457{
1458 if (request == NULL)
1459 return tape_3590_unsolicited_irq(device, irb);
1460
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001461 if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
1462 (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
1463 (request->op == TO_WRI)) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001464 /* Write at end of volume */
1465 DBF_EVENT(2, "End of volume\n");
1466 return tape_3590_erp_failed(device, request, irb, -ENOSPC);
1467 }
1468
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001469 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001470 return tape_3590_unit_check(device, request, irb);
1471
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001472 if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
1473 if (irb->scsw.cmd.dstat == DEV_STAT_UNIT_EXCEP) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001474 if (request->op == TO_FSB || request->op == TO_BSB)
1475 request->rescnt++;
1476 else
1477 DBF_EVENT(5, "Unit Exception!\n");
1478 }
1479
1480 return tape_3590_done(device, request);
1481 }
1482
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001483 if (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) {
Masanari Iida6774def2014-11-05 22:26:48 +09001484 DBF_EVENT(2, "channel end\n");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001485 return TAPE_IO_PENDING;
1486 }
1487
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001488 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001489 DBF_EVENT(2, "Unit Attention when busy..\n");
1490 return TAPE_IO_PENDING;
1491 }
1492
1493 DBF_EVENT(6, "xunknownirq\n");
Carsten Otteab640db2009-03-26 15:24:38 +01001494 tape_dump_sense_dbf(device, request, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001495 return TAPE_IO_STOP;
1496}
1497
Michael Holzheue2963062007-05-04 18:47:53 +02001498
1499static int tape_3590_read_dev_chars(struct tape_device *device,
1500 struct tape_3590_rdc_data *rdc_data)
1501{
1502 int rc;
1503 struct tape_request *request;
1504
1505 request = tape_alloc_request(1, sizeof(*rdc_data));
1506 if (IS_ERR(request))
1507 return PTR_ERR(request);
1508 request->op = TO_RDC;
1509 tape_ccw_end(request->cpaddr, CCW_CMD_RDC, sizeof(*rdc_data),
1510 request->cpdata);
1511 rc = tape_do_io(device, request);
1512 if (rc == 0)
1513 memcpy(rdc_data, request->cpdata, sizeof(*rdc_data));
1514 tape_free_request(request);
1515 return rc;
1516}
1517
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001518/*
1519 * Setup device function
1520 */
1521static int
1522tape_3590_setup_device(struct tape_device *device)
1523{
1524 int rc;
1525 struct tape_3590_disc_data *data;
Michael Holzheue2963062007-05-04 18:47:53 +02001526 struct tape_3590_rdc_data *rdc_data;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001527
1528 DBF_EVENT(6, "3590 device setup\n");
Michael Holzheucced1dd2007-02-05 21:18:26 +01001529 data = kzalloc(sizeof(struct tape_3590_disc_data), GFP_KERNEL | GFP_DMA);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001530 if (data == NULL)
1531 return -ENOMEM;
1532 data->read_back_op = READ_PREVIOUS;
1533 device->discdata = data;
1534
Michael Holzheue2963062007-05-04 18:47:53 +02001535 rdc_data = kmalloc(sizeof(*rdc_data), GFP_KERNEL | GFP_DMA);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001536 if (!rdc_data) {
1537 rc = -ENOMEM;
1538 goto fail_kmalloc;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001539 }
Michael Holzheue2963062007-05-04 18:47:53 +02001540 rc = tape_3590_read_dev_chars(device, rdc_data);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001541 if (rc) {
1542 DBF_LH(3, "Read device characteristics failed!\n");
Julia Lawall1783e602008-06-10 10:03:25 +02001543 goto fail_rdc_data;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001544 }
1545 rc = tape_std_assign(device);
1546 if (rc)
1547 goto fail_rdc_data;
Michael Holzheue2963062007-05-04 18:47:53 +02001548 if (rdc_data->data[31] == 0x13) {
Michael Holzheucced1dd2007-02-05 21:18:26 +01001549 data->crypt_info.capability |= TAPE390_CRYPT_SUPPORTED_MASK;
1550 tape_3592_disable_crypt(device);
1551 } else {
1552 DBF_EVENT(6, "Device has NO crypto support\n");
1553 }
1554 /* Try to find out if medium is loaded */
1555 rc = tape_3590_sense_medium(device);
1556 if (rc) {
1557 DBF_LH(3, "3590 medium sense returned %d\n", rc);
1558 goto fail_rdc_data;
1559 }
1560 return 0;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001561
Michael Holzheucced1dd2007-02-05 21:18:26 +01001562fail_rdc_data:
1563 kfree(rdc_data);
1564fail_kmalloc:
1565 kfree(data);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001566 return rc;
1567}
1568
1569/*
1570 * Cleanup device function
1571 */
1572static void
1573tape_3590_cleanup_device(struct tape_device *device)
1574{
Tejun Heo6dca4672010-12-24 16:00:18 +01001575 flush_workqueue(tape_3590_wq);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001576 tape_std_unassign(device);
1577
1578 kfree(device->discdata);
1579 device->discdata = NULL;
1580}
1581
1582/*
1583 * List of 3590 magnetic tape commands.
1584 */
1585static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = {
1586 [MTRESET] = tape_std_mtreset,
1587 [MTFSF] = tape_std_mtfsf,
1588 [MTBSF] = tape_std_mtbsf,
1589 [MTFSR] = tape_std_mtfsr,
1590 [MTBSR] = tape_std_mtbsr,
1591 [MTWEOF] = tape_std_mtweof,
1592 [MTREW] = tape_std_mtrew,
1593 [MTOFFL] = tape_std_mtoffl,
1594 [MTNOP] = tape_std_mtnop,
1595 [MTRETEN] = tape_std_mtreten,
1596 [MTBSFM] = tape_std_mtbsfm,
1597 [MTFSFM] = tape_std_mtfsfm,
1598 [MTEOM] = tape_std_mteom,
1599 [MTERASE] = tape_std_mterase,
1600 [MTRAS1] = NULL,
1601 [MTRAS2] = NULL,
1602 [MTRAS3] = NULL,
1603 [MTSETBLK] = tape_std_mtsetblk,
1604 [MTSETDENSITY] = NULL,
1605 [MTSEEK] = tape_3590_mtseek,
1606 [MTTELL] = tape_3590_mttell,
1607 [MTSETDRVBUFFER] = NULL,
1608 [MTFSS] = NULL,
1609 [MTBSS] = NULL,
1610 [MTWSM] = NULL,
1611 [MTLOCK] = NULL,
1612 [MTUNLOCK] = NULL,
1613 [MTLOAD] = tape_std_mtload,
1614 [MTUNLOAD] = tape_std_mtunload,
1615 [MTCOMPRESSION] = tape_std_mtcompression,
1616 [MTSETPART] = NULL,
1617 [MTMKPART] = NULL
1618};
1619
1620/*
1621 * Tape discipline structure for 3590.
1622 */
1623static struct tape_discipline tape_discipline_3590 = {
1624 .owner = THIS_MODULE,
1625 .setup_device = tape_3590_setup_device,
1626 .cleanup_device = tape_3590_cleanup_device,
1627 .process_eov = tape_std_process_eov,
1628 .irq = tape_3590_irq,
1629 .read_block = tape_std_read_block,
1630 .write_block = tape_std_write_block,
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001631 .ioctl_fn = tape_3590_ioctl,
1632 .mtop_array = tape_3590_mtop
1633};
1634
1635static struct ccw_device_id tape_3590_ids[] = {
1636 {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590},
Stefan Bader2cc924b2006-04-27 18:40:16 -07001637 {CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info = tape_3592},
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001638 { /* end of list */ }
1639};
1640
1641static int
1642tape_3590_online(struct ccw_device *cdev)
1643{
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07001644 return tape_generic_online(dev_get_drvdata(&cdev->dev),
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001645 &tape_discipline_3590);
1646}
1647
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001648static struct ccw_driver tape_3590_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +01001649 .driver = {
1650 .name = "tape_3590",
1651 .owner = THIS_MODULE,
1652 },
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001653 .ids = tape_3590_ids,
1654 .probe = tape_generic_probe,
1655 .remove = tape_generic_remove,
Frank Munzert4d7a3cd2009-04-23 13:58:09 +02001656 .set_offline = tape_generic_offline,
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001657 .set_online = tape_3590_online,
Frank Munzert3ef32e622009-06-16 10:30:39 +02001658 .freeze = tape_generic_pm_suspend,
Heiko Carstens420f42e2013-01-02 15:18:18 +01001659 .int_class = IRQIO_TAP,
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001660};
1661
1662/*
1663 * Setup discipline structure.
1664 */
1665static int
1666tape_3590_init(void)
1667{
1668 int rc;
1669
1670 TAPE_DBF_AREA = debug_register("tape_3590", 2, 2, 4 * sizeof(long));
1671 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1672#ifdef DBF_LIKE_HELL
1673 debug_set_level(TAPE_DBF_AREA, 6);
1674#endif
1675
1676 DBF_EVENT(3, "3590 init\n");
Tejun Heo6dca4672010-12-24 16:00:18 +01001677
1678 tape_3590_wq = alloc_workqueue("tape_3590", 0, 0);
1679 if (!tape_3590_wq)
1680 return -ENOMEM;
1681
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001682 /* Register driver for 3590 tapes. */
1683 rc = ccw_driver_register(&tape_3590_driver);
Tejun Heo6dca4672010-12-24 16:00:18 +01001684 if (rc) {
1685 destroy_workqueue(tape_3590_wq);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001686 DBF_EVENT(3, "3590 init failed\n");
Tejun Heo6dca4672010-12-24 16:00:18 +01001687 } else
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001688 DBF_EVENT(3, "3590 registered\n");
1689 return rc;
1690}
1691
1692static void
1693tape_3590_exit(void)
1694{
1695 ccw_driver_unregister(&tape_3590_driver);
Tejun Heo6dca4672010-12-24 16:00:18 +01001696 destroy_workqueue(tape_3590_wq);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001697 debug_unregister(TAPE_DBF_AREA);
1698}
1699
1700MODULE_DEVICE_TABLE(ccw, tape_3590_ids);
1701MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
1702MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
1703MODULE_LICENSE("GPL");
1704
1705module_init(tape_3590_init);
1706module_exit(tape_3590_exit);