blob: 5de27c9e4af10b6810a8094f16c68354fc6af50b [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 *
Michael Holzheucced1dd2007-02-05 21:18:26 +01005 * Copyright IBM Corp. 2001,2006
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
Carsten Otteab640db2009-03-26 15:24:38 +010011#define KMSG_COMPONENT "tape"
12
Stefan Baderb6cba4e2006-03-24 03:15:29 -080013#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/bio.h>
Michael Holzheucced1dd2007-02-05 21:18:26 +010016#include <asm/ebcdic.h>
Stefan Baderb6cba4e2006-03-24 03:15:29 -080017
18#define TAPE_DBF_AREA tape_3590_dbf
Carsten Otteab640db2009-03-26 15:24:38 +010019#define BUFSIZE 512 /* size of buffers for dynamic generated messages */
Stefan Baderb6cba4e2006-03-24 03:15:29 -080020
21#include "tape.h"
22#include "tape_std.h"
23#include "tape_3590.h"
24
25/*
26 * Pointer to debug area.
27 */
28debug_info_t *TAPE_DBF_AREA = NULL;
29EXPORT_SYMBOL(TAPE_DBF_AREA);
30
31/*******************************************************************
32 * Error Recovery fuctions:
33 * - Read Opposite: implemented
34 * - Read Device (buffered) log: BRA
35 * - Read Library log: BRA
36 * - Swap Devices: BRA
Michael Holzheucced1dd2007-02-05 21:18:26 +010037 * - Long Busy: implemented
Stefan Baderb6cba4e2006-03-24 03:15:29 -080038 * - Special Intercept: BRA
39 * - Read Alternate: implemented
40 *******************************************************************/
41
Carsten Otteab640db2009-03-26 15:24:38 +010042#define KMSG_COMPONENT "tape"
Stefan Baderb6cba4e2006-03-24 03:15:29 -080043
44static const char *tape_3590_msg[TAPE_3590_MAX_MSG] = {
45 [0x00] = "",
46 [0x10] = "Lost Sense",
47 [0x11] = "Assigned Elsewhere",
48 [0x12] = "Allegiance Reset",
49 [0x13] = "Shared Access Violation",
50 [0x20] = "Command Reject",
51 [0x21] = "Configuration Error",
52 [0x22] = "Protection Exception",
53 [0x23] = "Write Protect",
54 [0x24] = "Write Length",
55 [0x25] = "Read-Only Format",
56 [0x31] = "Beginning of Partition",
57 [0x33] = "End of Partition",
58 [0x34] = "End of Data",
59 [0x35] = "Block not found",
60 [0x40] = "Device Intervention",
61 [0x41] = "Loader Intervention",
62 [0x42] = "Library Intervention",
63 [0x50] = "Write Error",
64 [0x51] = "Erase Error",
65 [0x52] = "Formatting Error",
66 [0x53] = "Read Error",
67 [0x54] = "Unsupported Format",
68 [0x55] = "No Formatting",
69 [0x56] = "Positioning lost",
70 [0x57] = "Read Length",
71 [0x60] = "Unsupported Medium",
72 [0x61] = "Medium Length Error",
73 [0x62] = "Medium removed",
74 [0x64] = "Load Check",
75 [0x65] = "Unload Check",
76 [0x70] = "Equipment Check",
77 [0x71] = "Bus out Check",
78 [0x72] = "Protocol Error",
79 [0x73] = "Interface Error",
80 [0x74] = "Overrun",
81 [0x75] = "Halt Signal",
82 [0x90] = "Device fenced",
83 [0x91] = "Device Path fenced",
84 [0xa0] = "Volume misplaced",
85 [0xa1] = "Volume inaccessible",
86 [0xa2] = "Volume in input",
87 [0xa3] = "Volume ejected",
88 [0xa4] = "All categories reserved",
89 [0xa5] = "Duplicate Volume",
90 [0xa6] = "Library Manager Offline",
91 [0xa7] = "Library Output Station full",
92 [0xa8] = "Vision System non-operational",
93 [0xa9] = "Library Manager Equipment Check",
94 [0xaa] = "Library Equipment Check",
95 [0xab] = "All Library Cells full",
96 [0xac] = "No Cleaner Volumes in Library",
97 [0xad] = "I/O Station door open",
98 [0xae] = "Subsystem environmental alert",
99};
100
Michael Holzheucced1dd2007-02-05 21:18:26 +0100101static int crypt_supported(struct tape_device *device)
102{
103 return TAPE390_CRYPT_SUPPORTED(TAPE_3590_CRYPT_INFO(device));
104}
105
106static int crypt_enabled(struct tape_device *device)
107{
108 return TAPE390_CRYPT_ON(TAPE_3590_CRYPT_INFO(device));
109}
110
111static void ext_to_int_kekl(struct tape390_kekl *in,
112 struct tape3592_kekl *out)
113{
114 int i;
115
116 memset(out, 0, sizeof(*out));
117 if (in->type == TAPE390_KEKL_TYPE_HASH)
118 out->flags |= 0x40;
119 if (in->type_on_tape == TAPE390_KEKL_TYPE_HASH)
120 out->flags |= 0x80;
121 strncpy(out->label, in->label, 64);
122 for (i = strlen(in->label); i < sizeof(out->label); i++)
123 out->label[i] = ' ';
124 ASCEBC(out->label, sizeof(out->label));
125}
126
127static void int_to_ext_kekl(struct tape3592_kekl *in,
128 struct tape390_kekl *out)
129{
130 memset(out, 0, sizeof(*out));
131 if(in->flags & 0x40)
132 out->type = TAPE390_KEKL_TYPE_HASH;
133 else
134 out->type = TAPE390_KEKL_TYPE_LABEL;
135 if(in->flags & 0x80)
136 out->type_on_tape = TAPE390_KEKL_TYPE_HASH;
137 else
138 out->type_on_tape = TAPE390_KEKL_TYPE_LABEL;
139 memcpy(out->label, in->label, sizeof(in->label));
140 EBCASC(out->label, sizeof(in->label));
141 strstrip(out->label);
142}
143
144static void int_to_ext_kekl_pair(struct tape3592_kekl_pair *in,
145 struct tape390_kekl_pair *out)
146{
147 if (in->count == 0) {
148 out->kekl[0].type = TAPE390_KEKL_TYPE_NONE;
149 out->kekl[0].type_on_tape = TAPE390_KEKL_TYPE_NONE;
150 out->kekl[1].type = TAPE390_KEKL_TYPE_NONE;
151 out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE;
152 } else if (in->count == 1) {
153 int_to_ext_kekl(&in->kekl[0], &out->kekl[0]);
154 out->kekl[1].type = TAPE390_KEKL_TYPE_NONE;
155 out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE;
156 } else if (in->count == 2) {
157 int_to_ext_kekl(&in->kekl[0], &out->kekl[0]);
158 int_to_ext_kekl(&in->kekl[1], &out->kekl[1]);
159 } else {
160 printk("Invalid KEKL number: %d\n", in->count);
161 BUG();
162 }
163}
164
165static int check_ext_kekl(struct tape390_kekl *kekl)
166{
167 if (kekl->type == TAPE390_KEKL_TYPE_NONE)
168 goto invalid;
169 if (kekl->type > TAPE390_KEKL_TYPE_HASH)
170 goto invalid;
171 if (kekl->type_on_tape == TAPE390_KEKL_TYPE_NONE)
172 goto invalid;
173 if (kekl->type_on_tape > TAPE390_KEKL_TYPE_HASH)
174 goto invalid;
175 if ((kekl->type == TAPE390_KEKL_TYPE_HASH) &&
176 (kekl->type_on_tape == TAPE390_KEKL_TYPE_LABEL))
177 goto invalid;
178
179 return 0;
180invalid:
181 return -EINVAL;
182}
183
184static int check_ext_kekl_pair(struct tape390_kekl_pair *kekls)
185{
186 if (check_ext_kekl(&kekls->kekl[0]))
187 goto invalid;
188 if (check_ext_kekl(&kekls->kekl[1]))
189 goto invalid;
190
191 return 0;
192invalid:
193 return -EINVAL;
194}
195
196/*
197 * Query KEKLs
198 */
199static int tape_3592_kekl_query(struct tape_device *device,
200 struct tape390_kekl_pair *ext_kekls)
201{
202 struct tape_request *request;
203 struct tape3592_kekl_query_order *order;
204 struct tape3592_kekl_query_data *int_kekls;
205 int rc;
206
207 DBF_EVENT(6, "tape3592_kekl_query\n");
208 int_kekls = kmalloc(sizeof(*int_kekls), GFP_KERNEL|GFP_DMA);
209 if (!int_kekls)
210 return -ENOMEM;
211 request = tape_alloc_request(2, sizeof(*order));
212 if (IS_ERR(request)) {
213 rc = PTR_ERR(request);
214 goto fail_malloc;
215 }
216 order = request->cpdata;
217 memset(order,0,sizeof(*order));
218 order->code = 0xe2;
219 order->max_count = 2;
220 request->op = TO_KEKL_QUERY;
221 tape_ccw_cc(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order);
222 tape_ccw_end(request->cpaddr + 1, READ_SS_DATA, sizeof(*int_kekls),
223 int_kekls);
224 rc = tape_do_io(device, request);
225 if (rc)
226 goto fail_request;
227 int_to_ext_kekl_pair(&int_kekls->kekls, ext_kekls);
228
229 rc = 0;
230fail_request:
231 tape_free_request(request);
232fail_malloc:
233 kfree(int_kekls);
234 return rc;
235}
236
237/*
238 * IOCTL: Query KEKLs
239 */
240static int tape_3592_ioctl_kekl_query(struct tape_device *device,
241 unsigned long arg)
242{
243 int rc;
244 struct tape390_kekl_pair *ext_kekls;
245
246 DBF_EVENT(6, "tape_3592_ioctl_kekl_query\n");
247 if (!crypt_supported(device))
248 return -ENOSYS;
249 if (!crypt_enabled(device))
250 return -EUNATCH;
251 ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
252 if (!ext_kekls)
253 return -ENOMEM;
254 rc = tape_3592_kekl_query(device, ext_kekls);
255 if (rc != 0)
256 goto fail;
257 if (copy_to_user((char __user *) arg, ext_kekls, sizeof(*ext_kekls))) {
258 rc = -EFAULT;
259 goto fail;
260 }
261 rc = 0;
262fail:
263 kfree(ext_kekls);
264 return rc;
265}
266
267static int tape_3590_mttell(struct tape_device *device, int mt_count);
268
269/*
270 * Set KEKLs
271 */
272static int tape_3592_kekl_set(struct tape_device *device,
273 struct tape390_kekl_pair *ext_kekls)
274{
275 struct tape_request *request;
276 struct tape3592_kekl_set_order *order;
277
278 DBF_EVENT(6, "tape3592_kekl_set\n");
279 if (check_ext_kekl_pair(ext_kekls)) {
280 DBF_EVENT(6, "invalid kekls\n");
281 return -EINVAL;
282 }
283 if (tape_3590_mttell(device, 0) != 0)
284 return -EBADSLT;
285 request = tape_alloc_request(1, sizeof(*order));
286 if (IS_ERR(request))
287 return PTR_ERR(request);
288 order = request->cpdata;
289 memset(order, 0, sizeof(*order));
290 order->code = 0xe3;
291 order->kekls.count = 2;
292 ext_to_int_kekl(&ext_kekls->kekl[0], &order->kekls.kekl[0]);
293 ext_to_int_kekl(&ext_kekls->kekl[1], &order->kekls.kekl[1]);
294 request->op = TO_KEKL_SET;
295 tape_ccw_end(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order);
296
297 return tape_do_io_free(device, request);
298}
299
300/*
301 * IOCTL: Set KEKLs
302 */
303static int tape_3592_ioctl_kekl_set(struct tape_device *device,
304 unsigned long arg)
305{
306 int rc;
307 struct tape390_kekl_pair *ext_kekls;
308
309 DBF_EVENT(6, "tape_3592_ioctl_kekl_set\n");
310 if (!crypt_supported(device))
311 return -ENOSYS;
312 if (!crypt_enabled(device))
313 return -EUNATCH;
314 ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
315 if (!ext_kekls)
316 return -ENOMEM;
317 if (copy_from_user(ext_kekls, (char __user *)arg, sizeof(*ext_kekls))) {
318 rc = -EFAULT;
319 goto out;
320 }
321 rc = tape_3592_kekl_set(device, ext_kekls);
322out:
323 kfree(ext_kekls);
324 return rc;
325}
326
327/*
328 * Enable encryption
329 */
330static int tape_3592_enable_crypt(struct tape_device *device)
331{
332 struct tape_request *request;
333 char *data;
334
335 DBF_EVENT(6, "tape_3592_enable_crypt\n");
336 if (!crypt_supported(device))
337 return -ENOSYS;
338 request = tape_alloc_request(2, 72);
339 if (IS_ERR(request))
340 return PTR_ERR(request);
341 data = request->cpdata;
342 memset(data,0,72);
343
344 data[0] = 0x05;
345 data[36 + 0] = 0x03;
346 data[36 + 1] = 0x03;
347 data[36 + 4] = 0x40;
348 data[36 + 6] = 0x01;
349 data[36 + 14] = 0x2f;
350 data[36 + 18] = 0xc3;
351 data[36 + 35] = 0x72;
352 request->op = TO_CRYPT_ON;
353 tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
354 tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
355 return tape_do_io_free(device, request);
356}
357
358/*
359 * Disable encryption
360 */
361static int tape_3592_disable_crypt(struct tape_device *device)
362{
363 struct tape_request *request;
364 char *data;
365
366 DBF_EVENT(6, "tape_3592_disable_crypt\n");
367 if (!crypt_supported(device))
368 return -ENOSYS;
369 request = tape_alloc_request(2, 72);
370 if (IS_ERR(request))
371 return PTR_ERR(request);
372 data = request->cpdata;
373 memset(data,0,72);
374
375 data[0] = 0x05;
376 data[36 + 0] = 0x03;
377 data[36 + 1] = 0x03;
378 data[36 + 35] = 0x32;
379
380 request->op = TO_CRYPT_OFF;
381 tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
382 tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
383
384 return tape_do_io_free(device, request);
385}
386
387/*
388 * IOCTL: Set encryption status
389 */
390static int tape_3592_ioctl_crypt_set(struct tape_device *device,
391 unsigned long arg)
392{
393 struct tape390_crypt_info info;
394
395 DBF_EVENT(6, "tape_3592_ioctl_crypt_set\n");
396 if (!crypt_supported(device))
397 return -ENOSYS;
398 if (copy_from_user(&info, (char __user *)arg, sizeof(info)))
399 return -EFAULT;
400 if (info.status & ~TAPE390_CRYPT_ON_MASK)
401 return -EINVAL;
402 if (info.status & TAPE390_CRYPT_ON_MASK)
403 return tape_3592_enable_crypt(device);
404 else
405 return tape_3592_disable_crypt(device);
406}
407
408static int tape_3590_sense_medium(struct tape_device *device);
409
410/*
411 * IOCTL: Query enryption status
412 */
413static int tape_3592_ioctl_crypt_query(struct tape_device *device,
414 unsigned long arg)
415{
416 DBF_EVENT(6, "tape_3592_ioctl_crypt_query\n");
417 if (!crypt_supported(device))
418 return -ENOSYS;
419 tape_3590_sense_medium(device);
420 if (copy_to_user((char __user *) arg, &TAPE_3590_CRYPT_INFO(device),
421 sizeof(TAPE_3590_CRYPT_INFO(device))))
422 return -EFAULT;
423 else
424 return 0;
425}
426
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800427/*
428 * 3590 IOCTL Overload
429 */
430static int
431tape_3590_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
432{
433 switch (cmd) {
434 case TAPE390_DISPLAY: {
435 struct display_struct disp;
436
437 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)))
438 return -EFAULT;
439
440 return tape_std_display(device, &disp);
441 }
Michael Holzheucced1dd2007-02-05 21:18:26 +0100442 case TAPE390_KEKL_SET:
443 return tape_3592_ioctl_kekl_set(device, arg);
444 case TAPE390_KEKL_QUERY:
445 return tape_3592_ioctl_kekl_query(device, arg);
446 case TAPE390_CRYPT_SET:
447 return tape_3592_ioctl_crypt_set(device, arg);
448 case TAPE390_CRYPT_QUERY:
449 return tape_3592_ioctl_crypt_query(device, arg);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800450 default:
451 return -EINVAL; /* no additional ioctls */
452 }
453}
454
455/*
456 * SENSE Medium: Get Sense data about medium state
457 */
458static int
459tape_3590_sense_medium(struct tape_device *device)
460{
461 struct tape_request *request;
462
463 request = tape_alloc_request(1, 128);
464 if (IS_ERR(request))
465 return PTR_ERR(request);
466 request->op = TO_MSEN;
467 tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
468 return tape_do_io_free(device, request);
469}
470
471/*
472 * MTTELL: Tell block. Return the number of block relative to current file.
473 */
474static int
475tape_3590_mttell(struct tape_device *device, int mt_count)
476{
477 __u64 block_id;
478 int rc;
479
480 rc = tape_std_read_block_id(device, &block_id);
481 if (rc)
482 return rc;
483 return block_id >> 32;
484}
485
486/*
487 * MTSEEK: seek to the specified block.
488 */
489static int
490tape_3590_mtseek(struct tape_device *device, int count)
491{
492 struct tape_request *request;
493
494 DBF_EVENT(6, "xsee id: %x\n", count);
495 request = tape_alloc_request(3, 4);
496 if (IS_ERR(request))
497 return PTR_ERR(request);
498 request->op = TO_LBL;
499 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
500 *(__u32 *) request->cpdata = count;
501 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
502 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
503 return tape_do_io_free(device, request);
504}
505
506/*
507 * Read Opposite Error Recovery Function:
508 * Used, when Read Forward does not work
509 */
510static void
511tape_3590_read_opposite(struct tape_device *device,
512 struct tape_request *request)
513{
514 struct tape_3590_disc_data *data;
515
516 /*
517 * We have allocated 4 ccws in tape_std_read, so we can now
518 * transform the request to a read backward, followed by a
519 * forward space block.
520 */
521 request->op = TO_RBA;
522 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
523 data = device->discdata;
524 tape_ccw_cc_idal(request->cpaddr + 1, data->read_back_op,
525 device->char_data.idal_buf);
526 tape_ccw_cc(request->cpaddr + 2, FORSPACEBLOCK, 0, NULL);
527 tape_ccw_end(request->cpaddr + 3, NOP, 0, NULL);
528 DBF_EVENT(6, "xrop ccwg\n");
529}
530
531/*
532 * Read Attention Msg
533 * This should be done after an interrupt with attention bit (0x80)
534 * in device state.
535 *
536 * After a "read attention message" request there are two possible
537 * results:
538 *
539 * 1. A unit check is presented, when attention sense is present (e.g. when
540 * a medium has been unloaded). The attention sense comes then
541 * together with the unit check. The recovery action is either "retry"
542 * (in case there is an attention message pending) or "permanent error".
543 *
544 * 2. The attention msg is written to the "read subsystem data" buffer.
545 * In this case we probably should print it to the console.
546 */
547static int
548tape_3590_read_attmsg(struct tape_device *device)
549{
550 struct tape_request *request;
551 char *buf;
552
553 request = tape_alloc_request(3, 4096);
554 if (IS_ERR(request))
555 return PTR_ERR(request);
556 request->op = TO_READ_ATTMSG;
557 buf = request->cpdata;
558 buf[0] = PREP_RD_SS_DATA;
559 buf[6] = RD_ATTMSG; /* read att msg */
560 tape_ccw_cc(request->cpaddr, PERFORM_SS_FUNC, 12, buf);
561 tape_ccw_cc(request->cpaddr + 1, READ_SS_DATA, 4096 - 12, buf + 12);
562 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
563 return tape_do_io_free(device, request);
564}
565
566/*
567 * These functions are used to schedule follow-up actions from within an
568 * interrupt context (like unsolicited interrupts).
569 */
Stefan Bader2cc924b2006-04-27 18:40:16 -0700570struct work_handler_data {
571 struct tape_device *device;
572 enum tape_op op;
573 struct work_struct work;
574};
575
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800576static void
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100577tape_3590_work_handler(struct work_struct *work)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800578{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100579 struct work_handler_data *p =
580 container_of(work, struct work_handler_data, work);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800581
582 switch (p->op) {
583 case TO_MSEN:
584 tape_3590_sense_medium(p->device);
585 break;
586 case TO_READ_ATTMSG:
587 tape_3590_read_attmsg(p->device);
588 break;
Michael Holzheucced1dd2007-02-05 21:18:26 +0100589 case TO_CRYPT_ON:
590 tape_3592_enable_crypt(p->device);
591 break;
592 case TO_CRYPT_OFF:
593 tape_3592_disable_crypt(p->device);
594 break;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800595 default:
596 DBF_EVENT(3, "T3590: work handler undefined for "
597 "operation 0x%02x\n", p->op);
598 }
599 tape_put_device(p->device);
600 kfree(p);
601}
602
603static int
604tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
605{
Stefan Bader2cc924b2006-04-27 18:40:16 -0700606 struct work_handler_data *p;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800607
608 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
609 return -ENOMEM;
610
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100611 INIT_WORK(&p->work, tape_3590_work_handler);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800612
613 p->device = tape_get_device_reference(device);
614 p->op = op;
615
616 schedule_work(&p->work);
617 return 0;
618}
619
620#ifdef CONFIG_S390_TAPE_BLOCK
621/*
622 * Tape Block READ
623 */
624static struct tape_request *
625tape_3590_bread(struct tape_device *device, struct request *req)
626{
627 struct tape_request *request;
628 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +0200629 int count = 0, start_block;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800630 unsigned off;
631 char *dst;
632 struct bio_vec *bv;
NeilBrown5705f702007-09-25 12:35:59 +0200633 struct req_iterator iter;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800634
635 DBF_EVENT(6, "xBREDid:");
Tejun Heo83096eb2009-05-07 22:24:39 +0900636 start_block = blk_rq_pos(req) >> TAPEBLOCK_HSEC_S2B;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800637 DBF_EVENT(6, "start_block = %i\n", start_block);
638
NeilBrown5705f702007-09-25 12:35:59 +0200639 rq_for_each_segment(bv, req, iter)
640 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
641
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800642 request = tape_alloc_request(2 + count + 1, 4);
643 if (IS_ERR(request))
644 return request;
645 request->op = TO_BLOCK;
646 *(__u32 *) request->cpdata = start_block;
647 ccw = request->cpaddr;
648 ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);
649
650 /*
651 * We always setup a nop after the mode set ccw. This slot is
652 * used in tape_std_check_locate to insert a locate ccw if the
653 * current tape position doesn't match the start block to be read.
654 */
655 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
656
NeilBrown5705f702007-09-25 12:35:59 +0200657 rq_for_each_segment(bv, req, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +0200658 dst = page_address(bv->bv_page) + bv->bv_offset;
659 for (off = 0; off < bv->bv_len; off += TAPEBLOCK_HSEC_SIZE) {
660 ccw->flags = CCW_FLAG_CC;
661 ccw->cmd_code = READ_FORWARD;
662 ccw->count = TAPEBLOCK_HSEC_SIZE;
663 set_normalized_cda(ccw, (void *) __pa(dst));
664 ccw++;
665 dst += TAPEBLOCK_HSEC_SIZE;
666 }
Stoyan Gaydarov6aa0d3a2009-03-26 15:24:47 +0100667 BUG_ON(off > bv->bv_len);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800668 }
669 ccw = tape_ccw_end(ccw, NOP, 0, NULL);
670 DBF_EVENT(6, "xBREDccwg\n");
671 return request;
672}
673
674static void
675tape_3590_free_bread(struct tape_request *request)
676{
677 struct ccw1 *ccw;
678
679 /* Last ccw is a nop and doesn't need clear_normalized_cda */
680 for (ccw = request->cpaddr; ccw->flags & CCW_FLAG_CC; ccw++)
681 if (ccw->cmd_code == READ_FORWARD)
682 clear_normalized_cda(ccw);
683 tape_free_request(request);
684}
685
686/*
687 * check_locate is called just before the tape request is passed to
688 * the common io layer for execution. It has to check the current
689 * tape position and insert a locate ccw if it doesn't match the
690 * start block for the request.
691 */
692static void
693tape_3590_check_locate(struct tape_device *device, struct tape_request *request)
694{
695 __u32 *start_block;
696
697 start_block = (__u32 *) request->cpdata;
698 if (*start_block != device->blk_data.block_position) {
699 /* Add the start offset of the file to get the real block. */
700 *start_block += device->bof;
701 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
702 }
703}
704#endif
705
Michael Holzheucced1dd2007-02-05 21:18:26 +0100706static void tape_3590_med_state_set(struct tape_device *device,
707 struct tape_3590_med_sense *sense)
708{
709 struct tape390_crypt_info *c_info;
710
711 c_info = &TAPE_3590_CRYPT_INFO(device);
712
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200713 DBF_EVENT(6, "medium state: %x:%x\n", sense->macst, sense->masst);
714 switch (sense->macst) {
715 case 0x04:
716 case 0x05:
717 case 0x06:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100718 tape_med_state_set(device, MS_UNLOADED);
719 TAPE_3590_CRYPT_INFO(device).medium_status = 0;
720 return;
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200721 case 0x08:
722 case 0x09:
723 tape_med_state_set(device, MS_LOADED);
724 break;
725 default:
726 tape_med_state_set(device, MS_UNKNOWN);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100727 return;
728 }
Michael Holzheucced1dd2007-02-05 21:18:26 +0100729 c_info->medium_status |= TAPE390_MEDIUM_LOADED_MASK;
730 if (sense->flags & MSENSE_CRYPT_MASK) {
Carsten Otteab640db2009-03-26 15:24:38 +0100731 DBF_EVENT(6, "Medium is encrypted (%04x)\n", sense->flags);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100732 c_info->medium_status |= TAPE390_MEDIUM_ENCRYPTED_MASK;
733 } else {
734 DBF_EVENT(6, "Medium is not encrypted %04x\n", sense->flags);
735 c_info->medium_status &= ~TAPE390_MEDIUM_ENCRYPTED_MASK;
736 }
737}
738
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800739/*
740 * The done handler is called at device/channel end and wakes up the sleeping
741 * process
742 */
743static int
744tape_3590_done(struct tape_device *device, struct tape_request *request)
745{
Michael Holzheucced1dd2007-02-05 21:18:26 +0100746 struct tape_3590_disc_data *disc_data;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800747
748 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100749 disc_data = device->discdata;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800750
751 switch (request->op) {
752 case TO_BSB:
753 case TO_BSF:
754 case TO_DSE:
755 case TO_FSB:
756 case TO_FSF:
757 case TO_LBL:
758 case TO_RFO:
759 case TO_RBA:
760 case TO_REW:
761 case TO_WRI:
762 case TO_WTM:
763 case TO_BLOCK:
764 case TO_LOAD:
765 tape_med_state_set(device, MS_LOADED);
766 break;
767 case TO_RUN:
768 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100769 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800770 break;
771 case TO_MSEN:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100772 tape_3590_med_state_set(device, request->cpdata);
773 break;
774 case TO_CRYPT_ON:
775 TAPE_3590_CRYPT_INFO(device).status
776 |= TAPE390_CRYPT_ON_MASK;
777 *(device->modeset_byte) |= 0x03;
778 break;
779 case TO_CRYPT_OFF:
780 TAPE_3590_CRYPT_INFO(device).status
781 &= ~TAPE390_CRYPT_ON_MASK;
782 *(device->modeset_byte) &= ~0x03;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800783 break;
784 case TO_RBI: /* RBI seems to succeed even without medium loaded. */
785 case TO_NOP: /* Same to NOP. */
786 case TO_READ_CONFIG:
787 case TO_READ_ATTMSG:
788 case TO_DIS:
789 case TO_ASSIGN:
790 case TO_UNASSIGN:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800791 case TO_SIZE:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100792 case TO_KEKL_SET:
793 case TO_KEKL_QUERY:
Michael Holzheue2963062007-05-04 18:47:53 +0200794 case TO_RDC:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800795 break;
796 }
797 return TAPE_IO_SUCCESS;
798}
799
800/*
801 * This fuction is called, when error recovery was successfull
802 */
803static inline int
804tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request)
805{
Coly Li73ac36e2009-01-07 18:09:16 -0800806 DBF_EVENT(3, "Error Recovery successful for %s\n",
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800807 tape_op_verbose[request->op]);
808 return tape_3590_done(device, request);
809}
810
811/*
812 * This fuction is called, when error recovery was not successfull
813 */
814static inline int
815tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
816 struct irb *irb, int rc)
817{
818 DBF_EVENT(3, "Error Recovery failed for %s\n",
819 tape_op_verbose[request->op]);
820 tape_dump_sense_dbf(device, request, irb);
821 return rc;
822}
823
824/*
825 * Error Recovery do retry
826 */
827static inline int
828tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
829 struct irb *irb)
830{
831 DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]);
832 tape_dump_sense_dbf(device, request, irb);
833 return TAPE_IO_RETRY;
834}
835
836/*
837 * Handle unsolicited interrupts
838 */
839static int
840tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
841{
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200842 if (irb->scsw.cmd.dstat == DEV_STAT_CHN_END)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800843 /* Probably result of halt ssch */
844 return TAPE_IO_PENDING;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200845 else if (irb->scsw.cmd.dstat == 0x85)
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200846 /* Device Ready */
847 DBF_EVENT(3, "unsol.irq! tape ready: %08x\n", device->cdev_id);
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200848 else if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800849 tape_3590_schedule_work(device, TO_READ_ATTMSG);
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200850 } else {
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800851 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
Carsten Otteab640db2009-03-26 15:24:38 +0100852 tape_dump_sense_dbf(device, NULL, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800853 }
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200854 /* check medium state */
855 tape_3590_schedule_work(device, TO_MSEN);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800856 return TAPE_IO_SUCCESS;
857}
858
859/*
860 * Basic Recovery routine
861 */
862static int
863tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
864 struct irb *irb, int rc)
865{
866 struct tape_3590_sense *sense;
867
868 sense = (struct tape_3590_sense *) irb->ecw;
869
870 switch (sense->bra) {
871 case SENSE_BRA_PER:
872 return tape_3590_erp_failed(device, request, irb, rc);
873 case SENSE_BRA_CONT:
874 return tape_3590_erp_succeded(device, request);
875 case SENSE_BRA_RE:
876 return tape_3590_erp_retry(device, request, irb);
877 case SENSE_BRA_DRE:
878 return tape_3590_erp_failed(device, request, irb, rc);
879 default:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800880 BUG();
881 return TAPE_IO_STOP;
882 }
883}
884
885/*
886 * RDL: Read Device (buffered) log
887 */
888static int
889tape_3590_erp_read_buf_log(struct tape_device *device,
890 struct tape_request *request, struct irb *irb)
891{
892 /*
893 * We just do the basic error recovery at the moment (retry).
894 * Perhaps in the future, we read the log and dump it somewhere...
895 */
896 return tape_3590_erp_basic(device, request, irb, -EIO);
897}
898
899/*
900 * SWAP: Swap Devices
901 */
902static int
903tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
904 struct irb *irb)
905{
906 /*
907 * This error recovery should swap the tapes
908 * if the original has a problem. The operation
909 * should proceed with the new tape... this
910 * should probably be done in user space!
911 */
Carsten Otteab640db2009-03-26 15:24:38 +0100912 dev_warn (&device->cdev->dev, "The tape medium must be loaded into a "
913 "different tape unit\n");
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800914 return tape_3590_erp_basic(device, request, irb, -EIO);
915}
916
917/*
918 * LBY: Long Busy
919 */
920static int
921tape_3590_erp_long_busy(struct tape_device *device,
922 struct tape_request *request, struct irb *irb)
923{
Michael Holzheucced1dd2007-02-05 21:18:26 +0100924 DBF_EVENT(6, "Device is busy\n");
925 return TAPE_IO_LONG_BUSY;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800926}
927
928/*
929 * SPI: Special Intercept
930 */
931static int
932tape_3590_erp_special_interrupt(struct tape_device *device,
933 struct tape_request *request, struct irb *irb)
934{
935 return tape_3590_erp_basic(device, request, irb, -EIO);
936}
937
938/*
939 * RDA: Read Alternate
940 */
941static int
942tape_3590_erp_read_alternate(struct tape_device *device,
943 struct tape_request *request, struct irb *irb)
944{
945 struct tape_3590_disc_data *data;
946
947 /*
948 * The issued Read Backward or Read Previous command is not
949 * supported by the device
950 * The recovery action should be to issue another command:
951 * Read Revious: if Read Backward is not supported
952 * Read Backward: if Read Previous is not supported
953 */
954 data = device->discdata;
955 if (data->read_back_op == READ_PREVIOUS) {
956 DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
957 device->cdev_id);
958 data->read_back_op = READ_BACKWARD;
959 } else {
960 DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
961 device->cdev_id);
962 data->read_back_op = READ_PREVIOUS;
963 }
964 tape_3590_read_opposite(device, request);
965 return tape_3590_erp_retry(device, request, irb);
966}
967
968/*
969 * Error Recovery read opposite
970 */
971static int
972tape_3590_erp_read_opposite(struct tape_device *device,
973 struct tape_request *request, struct irb *irb)
974{
975 switch (request->op) {
976 case TO_RFO:
977 /*
978 * We did read forward, but the data could not be read.
979 * We will read backward and then skip forward again.
980 */
981 tape_3590_read_opposite(device, request);
982 return tape_3590_erp_retry(device, request, irb);
983 case TO_RBA:
984 /* We tried to read forward and backward, but hat no success */
985 return tape_3590_erp_failed(device, request, irb, -EIO);
986 break;
987 default:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800988 return tape_3590_erp_failed(device, request, irb, -EIO);
989 }
990}
991
992/*
993 * Print an MIM (Media Information Message) (message code f0)
994 */
995static void
996tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
997{
998 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +0100999 char *exception, *service;
1000
1001 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1002 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1003
1004 if (!exception || !service)
1005 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001006
1007 sense = (struct tape_3590_sense *) irb->ecw;
1008 /* Exception Message */
1009 switch (sense->fmt.f70.emc) {
1010 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001011 snprintf(exception, BUFSIZE, "Data degraded");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001012 break;
1013 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001014 snprintf(exception, BUFSIZE, "Data degraded in partion %i",
1015 sense->fmt.f70.mp);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001016 break;
1017 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001018 snprintf(exception, BUFSIZE, "Medium degraded");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001019 break;
1020 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001021 snprintf(exception, BUFSIZE, "Medium degraded in partition %i",
1022 sense->fmt.f70.mp);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001023 break;
1024 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001025 snprintf(exception, BUFSIZE, "Block 0 Error");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001026 break;
1027 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001028 snprintf(exception, BUFSIZE, "Medium Exception 0x%02x",
1029 sense->fmt.f70.md);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001030 break;
1031 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001032 snprintf(exception, BUFSIZE, "0x%02x",
1033 sense->fmt.f70.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001034 break;
1035 }
1036 /* Service Message */
1037 switch (sense->fmt.f70.smc) {
1038 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001039 snprintf(service, BUFSIZE, "Reference Media maintenance "
1040 "procedure %i", sense->fmt.f70.md);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001041 break;
1042 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001043 snprintf(service, BUFSIZE, "0x%02x",
1044 sense->fmt.f70.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001045 break;
1046 }
Carsten Otteab640db2009-03-26 15:24:38 +01001047
1048 dev_warn (&device->cdev->dev, "Tape media information: exception %s, "
1049 "service %s\n", exception, service);
1050
1051out_nomem:
1052 kfree(exception);
1053 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001054}
1055
1056/*
1057 * Print an I/O Subsystem Service Information Message (message code f1)
1058 */
1059static void
1060tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
1061{
1062 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +01001063 char *exception, *service;
1064
1065 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1066 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1067
1068 if (!exception || !service)
1069 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001070
1071 sense = (struct tape_3590_sense *) irb->ecw;
1072 /* Exception Message */
1073 switch (sense->fmt.f71.emc) {
1074 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001075 snprintf(exception, BUFSIZE, "Effect of failure is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001076 break;
1077 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001078 snprintf(exception, BUFSIZE, "CU Exception - no performance "
1079 "impact");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001080 break;
1081 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001082 snprintf(exception, BUFSIZE, "CU Exception on channel "
1083 "interface 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001084 break;
1085 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001086 snprintf(exception, BUFSIZE, "CU Exception on device path "
1087 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001088 break;
1089 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001090 snprintf(exception, BUFSIZE, "CU Exception on library path "
1091 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001092 break;
1093 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001094 snprintf(exception, BUFSIZE, "CU Exception on node 0x%02x",
1095 sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001096 break;
1097 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001098 snprintf(exception, BUFSIZE, "CU Exception on partition "
1099 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001100 break;
1101 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001102 snprintf(exception, BUFSIZE, "0x%02x",
1103 sense->fmt.f71.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001104 }
1105 /* Service Message */
1106 switch (sense->fmt.f71.smc) {
1107 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001108 snprintf(service, BUFSIZE, "Repair impact is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001109 break;
1110 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001111 snprintf(service, BUFSIZE, "Repair will not impact cu "
1112 "performance");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001113 break;
1114 case 0x03:
1115 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001116 snprintf(service, BUFSIZE, "Repair will disable node "
1117 "0x%x on CU", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001118 else
Carsten Otteab640db2009-03-26 15:24:38 +01001119 snprintf(service, BUFSIZE, "Repair will disable "
1120 "nodes (0x%x-0x%x) on CU", sense->fmt.f71.md[1],
1121 sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001122 break;
1123 case 0x04:
1124 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001125 snprintf(service, BUFSIZE, "Repair will disable "
1126 "channel path 0x%x on CU",
1127 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001128 else
Carsten Otteab640db2009-03-26 15:24:38 +01001129 snprintf(service, BUFSIZE, "Repair will disable cannel"
1130 " paths (0x%x-0x%x) on CU",
1131 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001132 break;
1133 case 0x05:
1134 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001135 snprintf(service, BUFSIZE, "Repair will disable device"
1136 " path 0x%x on CU", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001137 else
Carsten Otteab640db2009-03-26 15:24:38 +01001138 snprintf(service, BUFSIZE, "Repair will disable device"
1139 " paths (0x%x-0x%x) on CU",
1140 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001141 break;
1142 case 0x06:
1143 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001144 snprintf(service, BUFSIZE, "Repair will disable "
1145 "library path 0x%x on CU",
1146 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001147 else
Carsten Otteab640db2009-03-26 15:24:38 +01001148 snprintf(service, BUFSIZE, "Repair will disable "
1149 "library paths (0x%x-0x%x) on CU",
1150 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001151 break;
1152 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001153 snprintf(service, BUFSIZE, "Repair will disable access to CU");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001154 break;
1155 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001156 snprintf(service, BUFSIZE, "0x%02x",
1157 sense->fmt.f71.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001158 }
Carsten Otteab640db2009-03-26 15:24:38 +01001159
1160 dev_warn (&device->cdev->dev, "I/O subsystem information: exception"
1161 " %s, service %s\n", exception, service);
1162out_nomem:
1163 kfree(exception);
1164 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001165}
1166
1167/*
1168 * Print an Device Subsystem Service Information Message (message code f2)
1169 */
1170static void
1171tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
1172{
1173 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +01001174 char *exception, *service;
1175
1176 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1177 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1178
1179 if (!exception || !service)
1180 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001181
1182 sense = (struct tape_3590_sense *) irb->ecw;
1183 /* Exception Message */
1184 switch (sense->fmt.f71.emc) {
1185 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001186 snprintf(exception, BUFSIZE, "Effect of failure is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001187 break;
1188 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001189 snprintf(exception, BUFSIZE, "DV Exception - no performance"
1190 " impact");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001191 break;
1192 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001193 snprintf(exception, BUFSIZE, "DV Exception on channel "
1194 "interface 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001195 break;
1196 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001197 snprintf(exception, BUFSIZE, "DV Exception on loader 0x%02x",
1198 sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001199 break;
1200 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001201 snprintf(exception, BUFSIZE, "DV Exception on message display"
1202 " 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001203 break;
1204 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001205 snprintf(exception, BUFSIZE, "DV Exception in tape path");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001206 break;
1207 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001208 snprintf(exception, BUFSIZE, "DV Exception in drive");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001209 break;
1210 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001211 snprintf(exception, BUFSIZE, "0x%02x",
1212 sense->fmt.f71.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001213 }
1214 /* Service Message */
1215 switch (sense->fmt.f71.smc) {
1216 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001217 snprintf(service, BUFSIZE, "Repair impact is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001218 break;
1219 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001220 snprintf(service, BUFSIZE, "Repair will not impact device "
1221 "performance");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001222 break;
1223 case 0x03:
1224 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001225 snprintf(service, BUFSIZE, "Repair will disable "
1226 "channel path 0x%x on DV",
1227 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001228 else
Carsten Otteab640db2009-03-26 15:24:38 +01001229 snprintf(service, BUFSIZE, "Repair will disable "
1230 "channel path (0x%x-0x%x) on DV",
1231 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001232 break;
1233 case 0x04:
1234 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001235 snprintf(service, BUFSIZE, "Repair will disable "
1236 "interface 0x%x on DV", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001237 else
Carsten Otteab640db2009-03-26 15:24:38 +01001238 snprintf(service, BUFSIZE, "Repair will disable "
1239 "interfaces (0x%x-0x%x) on DV",
1240 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001241 break;
1242 case 0x05:
1243 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001244 snprintf(service, BUFSIZE, "Repair will disable loader"
1245 " 0x%x on DV", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001246 else
Carsten Otteab640db2009-03-26 15:24:38 +01001247 snprintf(service, BUFSIZE, "Repair will disable loader"
1248 " (0x%x-0x%x) on DV",
1249 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001250 break;
1251 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001252 snprintf(service, BUFSIZE, "Repair will disable access to DV");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001253 break;
1254 case 0x08:
1255 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001256 snprintf(service, BUFSIZE, "Repair will disable "
1257 "message display 0x%x on DV",
1258 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001259 else
Carsten Otteab640db2009-03-26 15:24:38 +01001260 snprintf(service, BUFSIZE, "Repair will disable "
1261 "message displays (0x%x-0x%x) on DV",
1262 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001263 break;
1264 case 0x09:
Carsten Otteab640db2009-03-26 15:24:38 +01001265 snprintf(service, BUFSIZE, "Clean DV");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001266 break;
1267 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001268 snprintf(service, BUFSIZE, "0x%02x",
1269 sense->fmt.f71.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001270 }
Carsten Otteab640db2009-03-26 15:24:38 +01001271
1272 dev_warn (&device->cdev->dev, "Device subsystem information: exception"
1273 " %s, service %s\n", exception, service);
1274out_nomem:
1275 kfree(exception);
1276 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001277}
1278
1279/*
1280 * Print standard ERA Message
1281 */
1282static void
1283tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
1284{
1285 struct tape_3590_sense *sense;
1286
1287 sense = (struct tape_3590_sense *) irb->ecw;
1288 if (sense->mc == 0)
1289 return;
1290 if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) {
1291 if (tape_3590_msg[sense->mc] != NULL)
Carsten Otteab640db2009-03-26 15:24:38 +01001292 dev_warn (&device->cdev->dev, "The tape unit has "
1293 "issued sense message %s\n",
1294 tape_3590_msg[sense->mc]);
1295 else
1296 dev_warn (&device->cdev->dev, "The tape unit has "
1297 "issued an unknown sense message code 0x%x\n",
1298 sense->mc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001299 return;
1300 }
1301 if (sense->mc == 0xf0) {
1302 /* Standard Media Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001303 dev_warn (&device->cdev->dev, "MIM SEV=%i, MC=%02x, ES=%x/%x, "
1304 "RC=%02x-%04x-%02x\n", sense->fmt.f70.sev, sense->mc,
1305 sense->fmt.f70.emc, sense->fmt.f70.smc,
1306 sense->fmt.f70.refcode, sense->fmt.f70.mid,
1307 sense->fmt.f70.fid);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001308 tape_3590_print_mim_msg_f0(device, irb);
1309 return;
1310 }
1311 if (sense->mc == 0xf1) {
1312 /* Standard I/O Subsystem Service Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001313 dev_warn (&device->cdev->dev, "IOSIM SEV=%i, DEVTYPE=3590/%02x,"
1314 " MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1315 sense->fmt.f71.sev, device->cdev->id.dev_model,
1316 sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1317 sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1318 sense->fmt.f71.refcode3);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001319 tape_3590_print_io_sim_msg_f1(device, irb);
1320 return;
1321 }
1322 if (sense->mc == 0xf2) {
1323 /* Standard Device Service Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001324 dev_warn (&device->cdev->dev, "DEVSIM SEV=%i, DEVTYPE=3590/%02x"
1325 ", MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1326 sense->fmt.f71.sev, device->cdev->id.dev_model,
1327 sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1328 sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1329 sense->fmt.f71.refcode3);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001330 tape_3590_print_dev_sim_msg_f2(device, irb);
1331 return;
1332 }
1333 if (sense->mc == 0xf3) {
1334 /* Standard Library Service Information Message */
1335 return;
1336 }
Carsten Otteab640db2009-03-26 15:24:38 +01001337 dev_warn (&device->cdev->dev, "The tape unit has issued an unknown "
1338 "sense message code %x\n", sense->mc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001339}
1340
Michael Holzheucced1dd2007-02-05 21:18:26 +01001341static int tape_3590_crypt_error(struct tape_device *device,
1342 struct tape_request *request, struct irb *irb)
1343{
1344 u8 cu_rc, ekm_rc1;
1345 u16 ekm_rc2;
1346 u32 drv_rc;
Kay Sievers2a0217d2008-10-10 21:33:09 +02001347 const char *bus_id;
1348 char *sense;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001349
1350 sense = ((struct tape_3590_sense *) irb->ecw)->fmt.data;
Kay Sievers2a0217d2008-10-10 21:33:09 +02001351 bus_id = dev_name(&device->cdev->dev);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001352 cu_rc = sense[0];
1353 drv_rc = *((u32*) &sense[5]) & 0xffffff;
1354 ekm_rc1 = sense[9];
1355 ekm_rc2 = *((u16*) &sense[10]);
1356 if ((cu_rc == 0) && (ekm_rc2 == 0xee31))
1357 /* key not defined on EKM */
1358 return tape_3590_erp_basic(device, request, irb, -EKEYREJECTED);
1359 if ((cu_rc == 1) || (cu_rc == 2))
1360 /* No connection to EKM */
1361 return tape_3590_erp_basic(device, request, irb, -ENOTCONN);
1362
Carsten Otteab640db2009-03-26 15:24:38 +01001363 dev_err (&device->cdev->dev, "The tape unit failed to obtain the "
1364 "encryption key from EKM\n");
Michael Holzheucced1dd2007-02-05 21:18:26 +01001365
1366 return tape_3590_erp_basic(device, request, irb, -ENOKEY);
1367}
1368
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001369/*
1370 * 3590 error Recovery routine:
1371 * If possible, it tries to recover from the error. If this is not possible,
1372 * inform the user about the problem.
1373 */
1374static int
1375tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
1376 struct irb *irb)
1377{
1378 struct tape_3590_sense *sense;
1379 int rc;
1380
1381#ifdef CONFIG_S390_TAPE_BLOCK
1382 if (request->op == TO_BLOCK) {
1383 /*
1384 * Recovery for block device requests. Set the block_position
1385 * to something invalid and retry.
1386 */
1387 device->blk_data.block_position = -1;
1388 if (request->retries-- <= 0)
1389 return tape_3590_erp_failed(device, request, irb, -EIO);
1390 else
1391 return tape_3590_erp_retry(device, request, irb);
1392 }
1393#endif
1394
1395 sense = (struct tape_3590_sense *) irb->ecw;
1396
Michael Holzheucced1dd2007-02-05 21:18:26 +01001397 DBF_EVENT(6, "Unit Check: RQC = %x\n", sense->rc_rqc);
1398
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001399 /*
1400 * First check all RC-QRCs where we want to do something special
1401 * - "break": basic error recovery is done
1402 * - "goto out:": just print error message if available
1403 */
1404 rc = -EIO;
1405 switch (sense->rc_rqc) {
1406
1407 case 0x1110:
1408 tape_3590_print_era_msg(device, irb);
1409 return tape_3590_erp_read_buf_log(device, request, irb);
1410
1411 case 0x2011:
1412 tape_3590_print_era_msg(device, irb);
1413 return tape_3590_erp_read_alternate(device, request, irb);
1414
1415 case 0x2230:
1416 case 0x2231:
1417 tape_3590_print_era_msg(device, irb);
1418 return tape_3590_erp_special_interrupt(device, request, irb);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001419 case 0x2240:
1420 return tape_3590_crypt_error(device, request, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001421
1422 case 0x3010:
1423 DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1424 device->cdev_id);
1425 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1426 case 0x3012:
1427 DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1428 device->cdev_id);
1429 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1430 case 0x3020:
1431 DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
1432 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1433
1434 case 0x3122:
1435 DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1436 device->cdev_id);
1437 return tape_3590_erp_basic(device, request, irb, -EIO);
1438 case 0x3123:
1439 DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1440 device->cdev_id);
1441 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001442 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001443 return tape_3590_erp_basic(device, request, irb, 0);
1444
1445 case 0x4010:
1446 /*
1447 * print additional msg since default msg
1448 * "device intervention" is not very meaningfull
1449 */
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001450 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001451 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001452 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1453 case 0x4012: /* Device Long Busy */
Michael Holzheucced1dd2007-02-05 21:18:26 +01001454 /* XXX: Also use long busy handling here? */
1455 DBF_EVENT(6, "(%08x): LONG BUSY\n", device->cdev_id);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001456 tape_3590_print_era_msg(device, irb);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001457 return tape_3590_erp_basic(device, request, irb, -EBUSY);
1458 case 0x4014:
1459 DBF_EVENT(6, "(%08x): Crypto LONG BUSY\n", device->cdev_id);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001460 return tape_3590_erp_long_busy(device, request, irb);
1461
1462 case 0x5010:
1463 if (sense->rac == 0xd0) {
1464 /* Swap */
1465 tape_3590_print_era_msg(device, irb);
1466 return tape_3590_erp_swap(device, request, irb);
1467 }
1468 if (sense->rac == 0x26) {
1469 /* Read Opposite */
1470 tape_3590_print_era_msg(device, irb);
1471 return tape_3590_erp_read_opposite(device, request,
1472 irb);
1473 }
1474 return tape_3590_erp_basic(device, request, irb, -EIO);
1475 case 0x5020:
1476 case 0x5021:
1477 case 0x5022:
1478 case 0x5040:
1479 case 0x5041:
1480 case 0x5042:
1481 tape_3590_print_era_msg(device, irb);
1482 return tape_3590_erp_swap(device, request, irb);
1483
1484 case 0x5110:
1485 case 0x5111:
1486 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1487
1488 case 0x5120:
1489 case 0x1120:
1490 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001491 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001492 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1493
1494 case 0x6020:
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001495 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1496
1497 case 0x8011:
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001498 return tape_3590_erp_basic(device, request, irb, -EPERM);
1499 case 0x8013:
Carsten Otteab640db2009-03-26 15:24:38 +01001500 dev_warn (&device->cdev->dev, "A different host has privileged"
1501 " access to the tape unit\n");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001502 return tape_3590_erp_basic(device, request, irb, -EPERM);
1503 default:
1504 return tape_3590_erp_basic(device, request, irb, -EIO);
1505 }
1506}
1507
1508/*
1509 * 3590 interrupt handler:
1510 */
1511static int
1512tape_3590_irq(struct tape_device *device, struct tape_request *request,
1513 struct irb *irb)
1514{
1515 if (request == NULL)
1516 return tape_3590_unsolicited_irq(device, irb);
1517
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001518 if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
1519 (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
1520 (request->op == TO_WRI)) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001521 /* Write at end of volume */
1522 DBF_EVENT(2, "End of volume\n");
1523 return tape_3590_erp_failed(device, request, irb, -ENOSPC);
1524 }
1525
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001526 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001527 return tape_3590_unit_check(device, request, irb);
1528
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001529 if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
1530 if (irb->scsw.cmd.dstat == DEV_STAT_UNIT_EXCEP) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001531 if (request->op == TO_FSB || request->op == TO_BSB)
1532 request->rescnt++;
1533 else
1534 DBF_EVENT(5, "Unit Exception!\n");
1535 }
1536
1537 return tape_3590_done(device, request);
1538 }
1539
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001540 if (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001541 DBF_EVENT(2, "cannel end\n");
1542 return TAPE_IO_PENDING;
1543 }
1544
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001545 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001546 DBF_EVENT(2, "Unit Attention when busy..\n");
1547 return TAPE_IO_PENDING;
1548 }
1549
1550 DBF_EVENT(6, "xunknownirq\n");
Carsten Otteab640db2009-03-26 15:24:38 +01001551 tape_dump_sense_dbf(device, request, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001552 return TAPE_IO_STOP;
1553}
1554
Michael Holzheue2963062007-05-04 18:47:53 +02001555
1556static int tape_3590_read_dev_chars(struct tape_device *device,
1557 struct tape_3590_rdc_data *rdc_data)
1558{
1559 int rc;
1560 struct tape_request *request;
1561
1562 request = tape_alloc_request(1, sizeof(*rdc_data));
1563 if (IS_ERR(request))
1564 return PTR_ERR(request);
1565 request->op = TO_RDC;
1566 tape_ccw_end(request->cpaddr, CCW_CMD_RDC, sizeof(*rdc_data),
1567 request->cpdata);
1568 rc = tape_do_io(device, request);
1569 if (rc == 0)
1570 memcpy(rdc_data, request->cpdata, sizeof(*rdc_data));
1571 tape_free_request(request);
1572 return rc;
1573}
1574
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001575/*
1576 * Setup device function
1577 */
1578static int
1579tape_3590_setup_device(struct tape_device *device)
1580{
1581 int rc;
1582 struct tape_3590_disc_data *data;
Michael Holzheue2963062007-05-04 18:47:53 +02001583 struct tape_3590_rdc_data *rdc_data;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001584
1585 DBF_EVENT(6, "3590 device setup\n");
Michael Holzheucced1dd2007-02-05 21:18:26 +01001586 data = kzalloc(sizeof(struct tape_3590_disc_data), GFP_KERNEL | GFP_DMA);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001587 if (data == NULL)
1588 return -ENOMEM;
1589 data->read_back_op = READ_PREVIOUS;
1590 device->discdata = data;
1591
Michael Holzheue2963062007-05-04 18:47:53 +02001592 rdc_data = kmalloc(sizeof(*rdc_data), GFP_KERNEL | GFP_DMA);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001593 if (!rdc_data) {
1594 rc = -ENOMEM;
1595 goto fail_kmalloc;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001596 }
Michael Holzheue2963062007-05-04 18:47:53 +02001597 rc = tape_3590_read_dev_chars(device, rdc_data);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001598 if (rc) {
1599 DBF_LH(3, "Read device characteristics failed!\n");
Julia Lawall1783e602008-06-10 10:03:25 +02001600 goto fail_rdc_data;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001601 }
1602 rc = tape_std_assign(device);
1603 if (rc)
1604 goto fail_rdc_data;
Michael Holzheue2963062007-05-04 18:47:53 +02001605 if (rdc_data->data[31] == 0x13) {
Michael Holzheucced1dd2007-02-05 21:18:26 +01001606 data->crypt_info.capability |= TAPE390_CRYPT_SUPPORTED_MASK;
1607 tape_3592_disable_crypt(device);
1608 } else {
1609 DBF_EVENT(6, "Device has NO crypto support\n");
1610 }
1611 /* Try to find out if medium is loaded */
1612 rc = tape_3590_sense_medium(device);
1613 if (rc) {
1614 DBF_LH(3, "3590 medium sense returned %d\n", rc);
1615 goto fail_rdc_data;
1616 }
1617 return 0;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001618
Michael Holzheucced1dd2007-02-05 21:18:26 +01001619fail_rdc_data:
1620 kfree(rdc_data);
1621fail_kmalloc:
1622 kfree(data);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001623 return rc;
1624}
1625
1626/*
1627 * Cleanup device function
1628 */
1629static void
1630tape_3590_cleanup_device(struct tape_device *device)
1631{
Stefan Bader2cc924b2006-04-27 18:40:16 -07001632 flush_scheduled_work();
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001633 tape_std_unassign(device);
1634
1635 kfree(device->discdata);
1636 device->discdata = NULL;
1637}
1638
1639/*
1640 * List of 3590 magnetic tape commands.
1641 */
1642static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = {
1643 [MTRESET] = tape_std_mtreset,
1644 [MTFSF] = tape_std_mtfsf,
1645 [MTBSF] = tape_std_mtbsf,
1646 [MTFSR] = tape_std_mtfsr,
1647 [MTBSR] = tape_std_mtbsr,
1648 [MTWEOF] = tape_std_mtweof,
1649 [MTREW] = tape_std_mtrew,
1650 [MTOFFL] = tape_std_mtoffl,
1651 [MTNOP] = tape_std_mtnop,
1652 [MTRETEN] = tape_std_mtreten,
1653 [MTBSFM] = tape_std_mtbsfm,
1654 [MTFSFM] = tape_std_mtfsfm,
1655 [MTEOM] = tape_std_mteom,
1656 [MTERASE] = tape_std_mterase,
1657 [MTRAS1] = NULL,
1658 [MTRAS2] = NULL,
1659 [MTRAS3] = NULL,
1660 [MTSETBLK] = tape_std_mtsetblk,
1661 [MTSETDENSITY] = NULL,
1662 [MTSEEK] = tape_3590_mtseek,
1663 [MTTELL] = tape_3590_mttell,
1664 [MTSETDRVBUFFER] = NULL,
1665 [MTFSS] = NULL,
1666 [MTBSS] = NULL,
1667 [MTWSM] = NULL,
1668 [MTLOCK] = NULL,
1669 [MTUNLOCK] = NULL,
1670 [MTLOAD] = tape_std_mtload,
1671 [MTUNLOAD] = tape_std_mtunload,
1672 [MTCOMPRESSION] = tape_std_mtcompression,
1673 [MTSETPART] = NULL,
1674 [MTMKPART] = NULL
1675};
1676
1677/*
1678 * Tape discipline structure for 3590.
1679 */
1680static struct tape_discipline tape_discipline_3590 = {
1681 .owner = THIS_MODULE,
1682 .setup_device = tape_3590_setup_device,
1683 .cleanup_device = tape_3590_cleanup_device,
1684 .process_eov = tape_std_process_eov,
1685 .irq = tape_3590_irq,
1686 .read_block = tape_std_read_block,
1687 .write_block = tape_std_write_block,
1688#ifdef CONFIG_S390_TAPE_BLOCK
1689 .bread = tape_3590_bread,
1690 .free_bread = tape_3590_free_bread,
1691 .check_locate = tape_3590_check_locate,
1692#endif
1693 .ioctl_fn = tape_3590_ioctl,
1694 .mtop_array = tape_3590_mtop
1695};
1696
1697static struct ccw_device_id tape_3590_ids[] = {
1698 {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590},
Stefan Bader2cc924b2006-04-27 18:40:16 -07001699 {CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info = tape_3592},
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001700 { /* end of list */ }
1701};
1702
1703static int
1704tape_3590_online(struct ccw_device *cdev)
1705{
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07001706 return tape_generic_online(dev_get_drvdata(&cdev->dev),
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001707 &tape_discipline_3590);
1708}
1709
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001710static struct ccw_driver tape_3590_driver = {
1711 .name = "tape_3590",
1712 .owner = THIS_MODULE,
1713 .ids = tape_3590_ids,
1714 .probe = tape_generic_probe,
1715 .remove = tape_generic_remove,
Frank Munzert4d7a3cd2009-04-23 13:58:09 +02001716 .set_offline = tape_generic_offline,
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001717 .set_online = tape_3590_online,
1718};
1719
1720/*
1721 * Setup discipline structure.
1722 */
1723static int
1724tape_3590_init(void)
1725{
1726 int rc;
1727
1728 TAPE_DBF_AREA = debug_register("tape_3590", 2, 2, 4 * sizeof(long));
1729 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1730#ifdef DBF_LIKE_HELL
1731 debug_set_level(TAPE_DBF_AREA, 6);
1732#endif
1733
1734 DBF_EVENT(3, "3590 init\n");
1735 /* Register driver for 3590 tapes. */
1736 rc = ccw_driver_register(&tape_3590_driver);
1737 if (rc)
1738 DBF_EVENT(3, "3590 init failed\n");
1739 else
1740 DBF_EVENT(3, "3590 registered\n");
1741 return rc;
1742}
1743
1744static void
1745tape_3590_exit(void)
1746{
1747 ccw_driver_unregister(&tape_3590_driver);
1748
1749 debug_unregister(TAPE_DBF_AREA);
1750}
1751
1752MODULE_DEVICE_TABLE(ccw, tape_3590_ids);
1753MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
1754MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
1755MODULE_LICENSE("GPL");
1756
1757module_init(tape_3590_init);
1758module_exit(tape_3590_exit);