blob: 0c72aadb8391f1d4db05a717400cfbb306dbc52a [file] [log] [blame]
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001/*
2 * drivers/s390/char/tape_3590.c
3 * tape device discipline for 3590 tapes.
4 *
Frank Munzert3ef32e62009-06-16 10:30:39 +02005 * Copyright IBM Corp. 2001, 2009
Stefan Baderb6cba4e2006-03-24 03:15:29 -08006 * Author(s): Stefan Bader <shbader@de.ibm.com>
7 * Michael Holzheu <holzheu@de.ibm.com>
8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
9 */
10
Michael Holzheu59e36922009-09-11 10:29:07 +020011#define KMSG_COMPONENT "tape_3590"
Carsten Otteab640db2009-03-26 15:24:38 +010012
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
Stefan Baderb6cba4e2006-03-24 03:15:29 -080042static const char *tape_3590_msg[TAPE_3590_MAX_MSG] = {
43 [0x00] = "",
44 [0x10] = "Lost Sense",
45 [0x11] = "Assigned Elsewhere",
46 [0x12] = "Allegiance Reset",
47 [0x13] = "Shared Access Violation",
48 [0x20] = "Command Reject",
49 [0x21] = "Configuration Error",
50 [0x22] = "Protection Exception",
51 [0x23] = "Write Protect",
52 [0x24] = "Write Length",
53 [0x25] = "Read-Only Format",
54 [0x31] = "Beginning of Partition",
55 [0x33] = "End of Partition",
56 [0x34] = "End of Data",
57 [0x35] = "Block not found",
58 [0x40] = "Device Intervention",
59 [0x41] = "Loader Intervention",
60 [0x42] = "Library Intervention",
61 [0x50] = "Write Error",
62 [0x51] = "Erase Error",
63 [0x52] = "Formatting Error",
64 [0x53] = "Read Error",
65 [0x54] = "Unsupported Format",
66 [0x55] = "No Formatting",
67 [0x56] = "Positioning lost",
68 [0x57] = "Read Length",
69 [0x60] = "Unsupported Medium",
70 [0x61] = "Medium Length Error",
71 [0x62] = "Medium removed",
72 [0x64] = "Load Check",
73 [0x65] = "Unload Check",
74 [0x70] = "Equipment Check",
75 [0x71] = "Bus out Check",
76 [0x72] = "Protocol Error",
77 [0x73] = "Interface Error",
78 [0x74] = "Overrun",
79 [0x75] = "Halt Signal",
80 [0x90] = "Device fenced",
81 [0x91] = "Device Path fenced",
82 [0xa0] = "Volume misplaced",
83 [0xa1] = "Volume inaccessible",
84 [0xa2] = "Volume in input",
85 [0xa3] = "Volume ejected",
86 [0xa4] = "All categories reserved",
87 [0xa5] = "Duplicate Volume",
88 [0xa6] = "Library Manager Offline",
89 [0xa7] = "Library Output Station full",
90 [0xa8] = "Vision System non-operational",
91 [0xa9] = "Library Manager Equipment Check",
92 [0xaa] = "Library Equipment Check",
93 [0xab] = "All Library Cells full",
94 [0xac] = "No Cleaner Volumes in Library",
95 [0xad] = "I/O Station door open",
96 [0xae] = "Subsystem environmental alert",
97};
98
Michael Holzheucced1dd2007-02-05 21:18:26 +010099static int crypt_supported(struct tape_device *device)
100{
101 return TAPE390_CRYPT_SUPPORTED(TAPE_3590_CRYPT_INFO(device));
102}
103
104static int crypt_enabled(struct tape_device *device)
105{
106 return TAPE390_CRYPT_ON(TAPE_3590_CRYPT_INFO(device));
107}
108
109static void ext_to_int_kekl(struct tape390_kekl *in,
110 struct tape3592_kekl *out)
111{
112 int i;
113
114 memset(out, 0, sizeof(*out));
115 if (in->type == TAPE390_KEKL_TYPE_HASH)
116 out->flags |= 0x40;
117 if (in->type_on_tape == TAPE390_KEKL_TYPE_HASH)
118 out->flags |= 0x80;
119 strncpy(out->label, in->label, 64);
120 for (i = strlen(in->label); i < sizeof(out->label); i++)
121 out->label[i] = ' ';
122 ASCEBC(out->label, sizeof(out->label));
123}
124
125static void int_to_ext_kekl(struct tape3592_kekl *in,
126 struct tape390_kekl *out)
127{
128 memset(out, 0, sizeof(*out));
129 if(in->flags & 0x40)
130 out->type = TAPE390_KEKL_TYPE_HASH;
131 else
132 out->type = TAPE390_KEKL_TYPE_LABEL;
133 if(in->flags & 0x80)
134 out->type_on_tape = TAPE390_KEKL_TYPE_HASH;
135 else
136 out->type_on_tape = TAPE390_KEKL_TYPE_LABEL;
137 memcpy(out->label, in->label, sizeof(in->label));
138 EBCASC(out->label, sizeof(in->label));
139 strstrip(out->label);
140}
141
142static void int_to_ext_kekl_pair(struct tape3592_kekl_pair *in,
143 struct tape390_kekl_pair *out)
144{
145 if (in->count == 0) {
146 out->kekl[0].type = TAPE390_KEKL_TYPE_NONE;
147 out->kekl[0].type_on_tape = TAPE390_KEKL_TYPE_NONE;
148 out->kekl[1].type = TAPE390_KEKL_TYPE_NONE;
149 out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE;
150 } else if (in->count == 1) {
151 int_to_ext_kekl(&in->kekl[0], &out->kekl[0]);
152 out->kekl[1].type = TAPE390_KEKL_TYPE_NONE;
153 out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE;
154 } else if (in->count == 2) {
155 int_to_ext_kekl(&in->kekl[0], &out->kekl[0]);
156 int_to_ext_kekl(&in->kekl[1], &out->kekl[1]);
157 } else {
158 printk("Invalid KEKL number: %d\n", in->count);
159 BUG();
160 }
161}
162
163static int check_ext_kekl(struct tape390_kekl *kekl)
164{
165 if (kekl->type == TAPE390_KEKL_TYPE_NONE)
166 goto invalid;
167 if (kekl->type > TAPE390_KEKL_TYPE_HASH)
168 goto invalid;
169 if (kekl->type_on_tape == TAPE390_KEKL_TYPE_NONE)
170 goto invalid;
171 if (kekl->type_on_tape > TAPE390_KEKL_TYPE_HASH)
172 goto invalid;
173 if ((kekl->type == TAPE390_KEKL_TYPE_HASH) &&
174 (kekl->type_on_tape == TAPE390_KEKL_TYPE_LABEL))
175 goto invalid;
176
177 return 0;
178invalid:
179 return -EINVAL;
180}
181
182static int check_ext_kekl_pair(struct tape390_kekl_pair *kekls)
183{
184 if (check_ext_kekl(&kekls->kekl[0]))
185 goto invalid;
186 if (check_ext_kekl(&kekls->kekl[1]))
187 goto invalid;
188
189 return 0;
190invalid:
191 return -EINVAL;
192}
193
194/*
195 * Query KEKLs
196 */
197static int tape_3592_kekl_query(struct tape_device *device,
198 struct tape390_kekl_pair *ext_kekls)
199{
200 struct tape_request *request;
201 struct tape3592_kekl_query_order *order;
202 struct tape3592_kekl_query_data *int_kekls;
203 int rc;
204
205 DBF_EVENT(6, "tape3592_kekl_query\n");
206 int_kekls = kmalloc(sizeof(*int_kekls), GFP_KERNEL|GFP_DMA);
207 if (!int_kekls)
208 return -ENOMEM;
209 request = tape_alloc_request(2, sizeof(*order));
210 if (IS_ERR(request)) {
211 rc = PTR_ERR(request);
212 goto fail_malloc;
213 }
214 order = request->cpdata;
215 memset(order,0,sizeof(*order));
216 order->code = 0xe2;
217 order->max_count = 2;
218 request->op = TO_KEKL_QUERY;
219 tape_ccw_cc(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order);
220 tape_ccw_end(request->cpaddr + 1, READ_SS_DATA, sizeof(*int_kekls),
221 int_kekls);
222 rc = tape_do_io(device, request);
223 if (rc)
224 goto fail_request;
225 int_to_ext_kekl_pair(&int_kekls->kekls, ext_kekls);
226
227 rc = 0;
228fail_request:
229 tape_free_request(request);
230fail_malloc:
231 kfree(int_kekls);
232 return rc;
233}
234
235/*
236 * IOCTL: Query KEKLs
237 */
238static int tape_3592_ioctl_kekl_query(struct tape_device *device,
239 unsigned long arg)
240{
241 int rc;
242 struct tape390_kekl_pair *ext_kekls;
243
244 DBF_EVENT(6, "tape_3592_ioctl_kekl_query\n");
245 if (!crypt_supported(device))
246 return -ENOSYS;
247 if (!crypt_enabled(device))
248 return -EUNATCH;
249 ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
250 if (!ext_kekls)
251 return -ENOMEM;
252 rc = tape_3592_kekl_query(device, ext_kekls);
253 if (rc != 0)
254 goto fail;
255 if (copy_to_user((char __user *) arg, ext_kekls, sizeof(*ext_kekls))) {
256 rc = -EFAULT;
257 goto fail;
258 }
259 rc = 0;
260fail:
261 kfree(ext_kekls);
262 return rc;
263}
264
265static int tape_3590_mttell(struct tape_device *device, int mt_count);
266
267/*
268 * Set KEKLs
269 */
270static int tape_3592_kekl_set(struct tape_device *device,
271 struct tape390_kekl_pair *ext_kekls)
272{
273 struct tape_request *request;
274 struct tape3592_kekl_set_order *order;
275
276 DBF_EVENT(6, "tape3592_kekl_set\n");
277 if (check_ext_kekl_pair(ext_kekls)) {
278 DBF_EVENT(6, "invalid kekls\n");
279 return -EINVAL;
280 }
281 if (tape_3590_mttell(device, 0) != 0)
282 return -EBADSLT;
283 request = tape_alloc_request(1, sizeof(*order));
284 if (IS_ERR(request))
285 return PTR_ERR(request);
286 order = request->cpdata;
287 memset(order, 0, sizeof(*order));
288 order->code = 0xe3;
289 order->kekls.count = 2;
290 ext_to_int_kekl(&ext_kekls->kekl[0], &order->kekls.kekl[0]);
291 ext_to_int_kekl(&ext_kekls->kekl[1], &order->kekls.kekl[1]);
292 request->op = TO_KEKL_SET;
293 tape_ccw_end(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order);
294
295 return tape_do_io_free(device, request);
296}
297
298/*
299 * IOCTL: Set KEKLs
300 */
301static int tape_3592_ioctl_kekl_set(struct tape_device *device,
302 unsigned long arg)
303{
304 int rc;
305 struct tape390_kekl_pair *ext_kekls;
306
307 DBF_EVENT(6, "tape_3592_ioctl_kekl_set\n");
308 if (!crypt_supported(device))
309 return -ENOSYS;
310 if (!crypt_enabled(device))
311 return -EUNATCH;
312 ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
313 if (!ext_kekls)
314 return -ENOMEM;
315 if (copy_from_user(ext_kekls, (char __user *)arg, sizeof(*ext_kekls))) {
316 rc = -EFAULT;
317 goto out;
318 }
319 rc = tape_3592_kekl_set(device, ext_kekls);
320out:
321 kfree(ext_kekls);
322 return rc;
323}
324
325/*
326 * Enable encryption
327 */
328static int tape_3592_enable_crypt(struct tape_device *device)
329{
330 struct tape_request *request;
331 char *data;
332
333 DBF_EVENT(6, "tape_3592_enable_crypt\n");
334 if (!crypt_supported(device))
335 return -ENOSYS;
336 request = tape_alloc_request(2, 72);
337 if (IS_ERR(request))
338 return PTR_ERR(request);
339 data = request->cpdata;
340 memset(data,0,72);
341
342 data[0] = 0x05;
343 data[36 + 0] = 0x03;
344 data[36 + 1] = 0x03;
345 data[36 + 4] = 0x40;
346 data[36 + 6] = 0x01;
347 data[36 + 14] = 0x2f;
348 data[36 + 18] = 0xc3;
349 data[36 + 35] = 0x72;
350 request->op = TO_CRYPT_ON;
351 tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
352 tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
353 return tape_do_io_free(device, request);
354}
355
356/*
357 * Disable encryption
358 */
359static int tape_3592_disable_crypt(struct tape_device *device)
360{
361 struct tape_request *request;
362 char *data;
363
364 DBF_EVENT(6, "tape_3592_disable_crypt\n");
365 if (!crypt_supported(device))
366 return -ENOSYS;
367 request = tape_alloc_request(2, 72);
368 if (IS_ERR(request))
369 return PTR_ERR(request);
370 data = request->cpdata;
371 memset(data,0,72);
372
373 data[0] = 0x05;
374 data[36 + 0] = 0x03;
375 data[36 + 1] = 0x03;
376 data[36 + 35] = 0x32;
377
378 request->op = TO_CRYPT_OFF;
379 tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
380 tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
381
382 return tape_do_io_free(device, request);
383}
384
385/*
386 * IOCTL: Set encryption status
387 */
388static int tape_3592_ioctl_crypt_set(struct tape_device *device,
389 unsigned long arg)
390{
391 struct tape390_crypt_info info;
392
393 DBF_EVENT(6, "tape_3592_ioctl_crypt_set\n");
394 if (!crypt_supported(device))
395 return -ENOSYS;
396 if (copy_from_user(&info, (char __user *)arg, sizeof(info)))
397 return -EFAULT;
398 if (info.status & ~TAPE390_CRYPT_ON_MASK)
399 return -EINVAL;
400 if (info.status & TAPE390_CRYPT_ON_MASK)
401 return tape_3592_enable_crypt(device);
402 else
403 return tape_3592_disable_crypt(device);
404}
405
406static int tape_3590_sense_medium(struct tape_device *device);
407
408/*
409 * IOCTL: Query enryption status
410 */
411static int tape_3592_ioctl_crypt_query(struct tape_device *device,
412 unsigned long arg)
413{
414 DBF_EVENT(6, "tape_3592_ioctl_crypt_query\n");
415 if (!crypt_supported(device))
416 return -ENOSYS;
417 tape_3590_sense_medium(device);
418 if (copy_to_user((char __user *) arg, &TAPE_3590_CRYPT_INFO(device),
419 sizeof(TAPE_3590_CRYPT_INFO(device))))
420 return -EFAULT;
421 else
422 return 0;
423}
424
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800425/*
426 * 3590 IOCTL Overload
427 */
428static int
429tape_3590_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
430{
431 switch (cmd) {
432 case TAPE390_DISPLAY: {
433 struct display_struct disp;
434
435 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)))
436 return -EFAULT;
437
438 return tape_std_display(device, &disp);
439 }
Michael Holzheucced1dd2007-02-05 21:18:26 +0100440 case TAPE390_KEKL_SET:
441 return tape_3592_ioctl_kekl_set(device, arg);
442 case TAPE390_KEKL_QUERY:
443 return tape_3592_ioctl_kekl_query(device, arg);
444 case TAPE390_CRYPT_SET:
445 return tape_3592_ioctl_crypt_set(device, arg);
446 case TAPE390_CRYPT_QUERY:
447 return tape_3592_ioctl_crypt_query(device, arg);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800448 default:
449 return -EINVAL; /* no additional ioctls */
450 }
451}
452
453/*
454 * SENSE Medium: Get Sense data about medium state
455 */
456static int
457tape_3590_sense_medium(struct tape_device *device)
458{
459 struct tape_request *request;
460
461 request = tape_alloc_request(1, 128);
462 if (IS_ERR(request))
463 return PTR_ERR(request);
464 request->op = TO_MSEN;
465 tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
466 return tape_do_io_free(device, request);
467}
468
469/*
470 * MTTELL: Tell block. Return the number of block relative to current file.
471 */
472static int
473tape_3590_mttell(struct tape_device *device, int mt_count)
474{
475 __u64 block_id;
476 int rc;
477
478 rc = tape_std_read_block_id(device, &block_id);
479 if (rc)
480 return rc;
481 return block_id >> 32;
482}
483
484/*
485 * MTSEEK: seek to the specified block.
486 */
487static int
488tape_3590_mtseek(struct tape_device *device, int count)
489{
490 struct tape_request *request;
491
492 DBF_EVENT(6, "xsee id: %x\n", count);
493 request = tape_alloc_request(3, 4);
494 if (IS_ERR(request))
495 return PTR_ERR(request);
496 request->op = TO_LBL;
497 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
498 *(__u32 *) request->cpdata = count;
499 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
500 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
501 return tape_do_io_free(device, request);
502}
503
504/*
505 * Read Opposite Error Recovery Function:
506 * Used, when Read Forward does not work
507 */
508static void
509tape_3590_read_opposite(struct tape_device *device,
510 struct tape_request *request)
511{
512 struct tape_3590_disc_data *data;
513
514 /*
515 * We have allocated 4 ccws in tape_std_read, so we can now
516 * transform the request to a read backward, followed by a
517 * forward space block.
518 */
519 request->op = TO_RBA;
520 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
521 data = device->discdata;
522 tape_ccw_cc_idal(request->cpaddr + 1, data->read_back_op,
523 device->char_data.idal_buf);
524 tape_ccw_cc(request->cpaddr + 2, FORSPACEBLOCK, 0, NULL);
525 tape_ccw_end(request->cpaddr + 3, NOP, 0, NULL);
526 DBF_EVENT(6, "xrop ccwg\n");
527}
528
529/*
530 * Read Attention Msg
531 * This should be done after an interrupt with attention bit (0x80)
532 * in device state.
533 *
534 * After a "read attention message" request there are two possible
535 * results:
536 *
537 * 1. A unit check is presented, when attention sense is present (e.g. when
538 * a medium has been unloaded). The attention sense comes then
539 * together with the unit check. The recovery action is either "retry"
540 * (in case there is an attention message pending) or "permanent error".
541 *
542 * 2. The attention msg is written to the "read subsystem data" buffer.
543 * In this case we probably should print it to the console.
544 */
545static int
546tape_3590_read_attmsg(struct tape_device *device)
547{
548 struct tape_request *request;
549 char *buf;
550
551 request = tape_alloc_request(3, 4096);
552 if (IS_ERR(request))
553 return PTR_ERR(request);
554 request->op = TO_READ_ATTMSG;
555 buf = request->cpdata;
556 buf[0] = PREP_RD_SS_DATA;
557 buf[6] = RD_ATTMSG; /* read att msg */
558 tape_ccw_cc(request->cpaddr, PERFORM_SS_FUNC, 12, buf);
559 tape_ccw_cc(request->cpaddr + 1, READ_SS_DATA, 4096 - 12, buf + 12);
560 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
561 return tape_do_io_free(device, request);
562}
563
564/*
565 * These functions are used to schedule follow-up actions from within an
566 * interrupt context (like unsolicited interrupts).
567 */
Stefan Bader2cc924b2006-04-27 18:40:16 -0700568struct work_handler_data {
569 struct tape_device *device;
570 enum tape_op op;
571 struct work_struct work;
572};
573
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800574static void
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100575tape_3590_work_handler(struct work_struct *work)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800576{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100577 struct work_handler_data *p =
578 container_of(work, struct work_handler_data, work);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800579
580 switch (p->op) {
581 case TO_MSEN:
582 tape_3590_sense_medium(p->device);
583 break;
584 case TO_READ_ATTMSG:
585 tape_3590_read_attmsg(p->device);
586 break;
Michael Holzheucced1dd2007-02-05 21:18:26 +0100587 case TO_CRYPT_ON:
588 tape_3592_enable_crypt(p->device);
589 break;
590 case TO_CRYPT_OFF:
591 tape_3592_disable_crypt(p->device);
592 break;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800593 default:
594 DBF_EVENT(3, "T3590: work handler undefined for "
595 "operation 0x%02x\n", p->op);
596 }
597 tape_put_device(p->device);
598 kfree(p);
599}
600
601static int
602tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
603{
Stefan Bader2cc924b2006-04-27 18:40:16 -0700604 struct work_handler_data *p;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800605
606 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
607 return -ENOMEM;
608
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100609 INIT_WORK(&p->work, tape_3590_work_handler);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800610
Martin Schwidefsky8fd138c2009-12-07 12:52:03 +0100611 p->device = tape_get_device(device);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800612 p->op = op;
613
614 schedule_work(&p->work);
615 return 0;
616}
617
618#ifdef CONFIG_S390_TAPE_BLOCK
619/*
620 * Tape Block READ
621 */
622static struct tape_request *
623tape_3590_bread(struct tape_device *device, struct request *req)
624{
625 struct tape_request *request;
626 struct ccw1 *ccw;
NeilBrown5705f702007-09-25 12:35:59 +0200627 int count = 0, start_block;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800628 unsigned off;
629 char *dst;
630 struct bio_vec *bv;
NeilBrown5705f702007-09-25 12:35:59 +0200631 struct req_iterator iter;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800632
633 DBF_EVENT(6, "xBREDid:");
Tejun Heo83096eb2009-05-07 22:24:39 +0900634 start_block = blk_rq_pos(req) >> TAPEBLOCK_HSEC_S2B;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800635 DBF_EVENT(6, "start_block = %i\n", start_block);
636
NeilBrown5705f702007-09-25 12:35:59 +0200637 rq_for_each_segment(bv, req, iter)
638 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
639
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800640 request = tape_alloc_request(2 + count + 1, 4);
641 if (IS_ERR(request))
642 return request;
643 request->op = TO_BLOCK;
644 *(__u32 *) request->cpdata = start_block;
645 ccw = request->cpaddr;
646 ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);
647
648 /*
649 * We always setup a nop after the mode set ccw. This slot is
650 * used in tape_std_check_locate to insert a locate ccw if the
651 * current tape position doesn't match the start block to be read.
652 */
653 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
654
NeilBrown5705f702007-09-25 12:35:59 +0200655 rq_for_each_segment(bv, req, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +0200656 dst = page_address(bv->bv_page) + bv->bv_offset;
657 for (off = 0; off < bv->bv_len; off += TAPEBLOCK_HSEC_SIZE) {
658 ccw->flags = CCW_FLAG_CC;
659 ccw->cmd_code = READ_FORWARD;
660 ccw->count = TAPEBLOCK_HSEC_SIZE;
661 set_normalized_cda(ccw, (void *) __pa(dst));
662 ccw++;
663 dst += TAPEBLOCK_HSEC_SIZE;
664 }
Stoyan Gaydarov6aa0d3a2009-03-26 15:24:47 +0100665 BUG_ON(off > bv->bv_len);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800666 }
667 ccw = tape_ccw_end(ccw, NOP, 0, NULL);
668 DBF_EVENT(6, "xBREDccwg\n");
669 return request;
670}
671
672static void
673tape_3590_free_bread(struct tape_request *request)
674{
675 struct ccw1 *ccw;
676
677 /* Last ccw is a nop and doesn't need clear_normalized_cda */
678 for (ccw = request->cpaddr; ccw->flags & CCW_FLAG_CC; ccw++)
679 if (ccw->cmd_code == READ_FORWARD)
680 clear_normalized_cda(ccw);
681 tape_free_request(request);
682}
683
684/*
685 * check_locate is called just before the tape request is passed to
686 * the common io layer for execution. It has to check the current
687 * tape position and insert a locate ccw if it doesn't match the
688 * start block for the request.
689 */
690static void
691tape_3590_check_locate(struct tape_device *device, struct tape_request *request)
692{
693 __u32 *start_block;
694
695 start_block = (__u32 *) request->cpdata;
696 if (*start_block != device->blk_data.block_position) {
697 /* Add the start offset of the file to get the real block. */
698 *start_block += device->bof;
699 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
700 }
701}
702#endif
703
Michael Holzheucced1dd2007-02-05 21:18:26 +0100704static void tape_3590_med_state_set(struct tape_device *device,
705 struct tape_3590_med_sense *sense)
706{
707 struct tape390_crypt_info *c_info;
708
709 c_info = &TAPE_3590_CRYPT_INFO(device);
710
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200711 DBF_EVENT(6, "medium state: %x:%x\n", sense->macst, sense->masst);
712 switch (sense->macst) {
713 case 0x04:
714 case 0x05:
715 case 0x06:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100716 tape_med_state_set(device, MS_UNLOADED);
717 TAPE_3590_CRYPT_INFO(device).medium_status = 0;
718 return;
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200719 case 0x08:
720 case 0x09:
721 tape_med_state_set(device, MS_LOADED);
722 break;
723 default:
724 tape_med_state_set(device, MS_UNKNOWN);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100725 return;
726 }
Michael Holzheucced1dd2007-02-05 21:18:26 +0100727 c_info->medium_status |= TAPE390_MEDIUM_LOADED_MASK;
728 if (sense->flags & MSENSE_CRYPT_MASK) {
Carsten Otteab640db2009-03-26 15:24:38 +0100729 DBF_EVENT(6, "Medium is encrypted (%04x)\n", sense->flags);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100730 c_info->medium_status |= TAPE390_MEDIUM_ENCRYPTED_MASK;
731 } else {
732 DBF_EVENT(6, "Medium is not encrypted %04x\n", sense->flags);
733 c_info->medium_status &= ~TAPE390_MEDIUM_ENCRYPTED_MASK;
734 }
735}
736
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800737/*
738 * The done handler is called at device/channel end and wakes up the sleeping
739 * process
740 */
741static int
742tape_3590_done(struct tape_device *device, struct tape_request *request)
743{
Michael Holzheucced1dd2007-02-05 21:18:26 +0100744 struct tape_3590_disc_data *disc_data;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800745
746 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100747 disc_data = device->discdata;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800748
749 switch (request->op) {
750 case TO_BSB:
751 case TO_BSF:
752 case TO_DSE:
753 case TO_FSB:
754 case TO_FSF:
755 case TO_LBL:
756 case TO_RFO:
757 case TO_RBA:
758 case TO_REW:
759 case TO_WRI:
760 case TO_WTM:
761 case TO_BLOCK:
762 case TO_LOAD:
763 tape_med_state_set(device, MS_LOADED);
764 break;
765 case TO_RUN:
766 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +0100767 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800768 break;
769 case TO_MSEN:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100770 tape_3590_med_state_set(device, request->cpdata);
771 break;
772 case TO_CRYPT_ON:
773 TAPE_3590_CRYPT_INFO(device).status
774 |= TAPE390_CRYPT_ON_MASK;
775 *(device->modeset_byte) |= 0x03;
776 break;
777 case TO_CRYPT_OFF:
778 TAPE_3590_CRYPT_INFO(device).status
779 &= ~TAPE390_CRYPT_ON_MASK;
780 *(device->modeset_byte) &= ~0x03;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800781 break;
782 case TO_RBI: /* RBI seems to succeed even without medium loaded. */
783 case TO_NOP: /* Same to NOP. */
784 case TO_READ_CONFIG:
785 case TO_READ_ATTMSG:
786 case TO_DIS:
787 case TO_ASSIGN:
788 case TO_UNASSIGN:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800789 case TO_SIZE:
Michael Holzheucced1dd2007-02-05 21:18:26 +0100790 case TO_KEKL_SET:
791 case TO_KEKL_QUERY:
Michael Holzheue2963062007-05-04 18:47:53 +0200792 case TO_RDC:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800793 break;
794 }
795 return TAPE_IO_SUCCESS;
796}
797
798/*
799 * This fuction is called, when error recovery was successfull
800 */
801static inline int
802tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request)
803{
Coly Li73ac36e2009-01-07 18:09:16 -0800804 DBF_EVENT(3, "Error Recovery successful for %s\n",
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800805 tape_op_verbose[request->op]);
806 return tape_3590_done(device, request);
807}
808
809/*
810 * This fuction is called, when error recovery was not successfull
811 */
812static inline int
813tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
814 struct irb *irb, int rc)
815{
816 DBF_EVENT(3, "Error Recovery failed for %s\n",
817 tape_op_verbose[request->op]);
818 tape_dump_sense_dbf(device, request, irb);
819 return rc;
820}
821
822/*
823 * Error Recovery do retry
824 */
825static inline int
826tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
827 struct irb *irb)
828{
829 DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]);
830 tape_dump_sense_dbf(device, request, irb);
831 return TAPE_IO_RETRY;
832}
833
834/*
835 * Handle unsolicited interrupts
836 */
837static int
838tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
839{
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200840 if (irb->scsw.cmd.dstat == DEV_STAT_CHN_END)
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800841 /* Probably result of halt ssch */
842 return TAPE_IO_PENDING;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200843 else if (irb->scsw.cmd.dstat == 0x85)
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200844 /* Device Ready */
845 DBF_EVENT(3, "unsol.irq! tape ready: %08x\n", device->cdev_id);
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200846 else if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800847 tape_3590_schedule_work(device, TO_READ_ATTMSG);
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200848 } else {
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800849 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
Carsten Otteab640db2009-03-26 15:24:38 +0100850 tape_dump_sense_dbf(device, NULL, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800851 }
Michael Holzheu1b9fd762007-10-12 16:11:47 +0200852 /* check medium state */
853 tape_3590_schedule_work(device, TO_MSEN);
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800854 return TAPE_IO_SUCCESS;
855}
856
857/*
858 * Basic Recovery routine
859 */
860static int
861tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
862 struct irb *irb, int rc)
863{
864 struct tape_3590_sense *sense;
865
866 sense = (struct tape_3590_sense *) irb->ecw;
867
868 switch (sense->bra) {
869 case SENSE_BRA_PER:
870 return tape_3590_erp_failed(device, request, irb, rc);
871 case SENSE_BRA_CONT:
872 return tape_3590_erp_succeded(device, request);
873 case SENSE_BRA_RE:
874 return tape_3590_erp_retry(device, request, irb);
875 case SENSE_BRA_DRE:
876 return tape_3590_erp_failed(device, request, irb, rc);
877 default:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800878 BUG();
879 return TAPE_IO_STOP;
880 }
881}
882
883/*
884 * RDL: Read Device (buffered) log
885 */
886static int
887tape_3590_erp_read_buf_log(struct tape_device *device,
888 struct tape_request *request, struct irb *irb)
889{
890 /*
891 * We just do the basic error recovery at the moment (retry).
892 * Perhaps in the future, we read the log and dump it somewhere...
893 */
894 return tape_3590_erp_basic(device, request, irb, -EIO);
895}
896
897/*
898 * SWAP: Swap Devices
899 */
900static int
901tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
902 struct irb *irb)
903{
904 /*
905 * This error recovery should swap the tapes
906 * if the original has a problem. The operation
907 * should proceed with the new tape... this
908 * should probably be done in user space!
909 */
Carsten Otteab640db2009-03-26 15:24:38 +0100910 dev_warn (&device->cdev->dev, "The tape medium must be loaded into a "
911 "different tape unit\n");
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800912 return tape_3590_erp_basic(device, request, irb, -EIO);
913}
914
915/*
916 * LBY: Long Busy
917 */
918static int
919tape_3590_erp_long_busy(struct tape_device *device,
920 struct tape_request *request, struct irb *irb)
921{
Michael Holzheucced1dd2007-02-05 21:18:26 +0100922 DBF_EVENT(6, "Device is busy\n");
923 return TAPE_IO_LONG_BUSY;
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800924}
925
926/*
927 * SPI: Special Intercept
928 */
929static int
930tape_3590_erp_special_interrupt(struct tape_device *device,
931 struct tape_request *request, struct irb *irb)
932{
933 return tape_3590_erp_basic(device, request, irb, -EIO);
934}
935
936/*
937 * RDA: Read Alternate
938 */
939static int
940tape_3590_erp_read_alternate(struct tape_device *device,
941 struct tape_request *request, struct irb *irb)
942{
943 struct tape_3590_disc_data *data;
944
945 /*
946 * The issued Read Backward or Read Previous command is not
947 * supported by the device
948 * The recovery action should be to issue another command:
949 * Read Revious: if Read Backward is not supported
950 * Read Backward: if Read Previous is not supported
951 */
952 data = device->discdata;
953 if (data->read_back_op == READ_PREVIOUS) {
954 DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
955 device->cdev_id);
956 data->read_back_op = READ_BACKWARD;
957 } else {
958 DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
959 device->cdev_id);
960 data->read_back_op = READ_PREVIOUS;
961 }
962 tape_3590_read_opposite(device, request);
963 return tape_3590_erp_retry(device, request, irb);
964}
965
966/*
967 * Error Recovery read opposite
968 */
969static int
970tape_3590_erp_read_opposite(struct tape_device *device,
971 struct tape_request *request, struct irb *irb)
972{
973 switch (request->op) {
974 case TO_RFO:
975 /*
976 * We did read forward, but the data could not be read.
977 * We will read backward and then skip forward again.
978 */
979 tape_3590_read_opposite(device, request);
980 return tape_3590_erp_retry(device, request, irb);
981 case TO_RBA:
982 /* We tried to read forward and backward, but hat no success */
983 return tape_3590_erp_failed(device, request, irb, -EIO);
984 break;
985 default:
Stefan Baderb6cba4e2006-03-24 03:15:29 -0800986 return tape_3590_erp_failed(device, request, irb, -EIO);
987 }
988}
989
990/*
991 * Print an MIM (Media Information Message) (message code f0)
992 */
993static void
994tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
995{
996 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +0100997 char *exception, *service;
998
999 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1000 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1001
1002 if (!exception || !service)
1003 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001004
1005 sense = (struct tape_3590_sense *) irb->ecw;
1006 /* Exception Message */
1007 switch (sense->fmt.f70.emc) {
1008 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001009 snprintf(exception, BUFSIZE, "Data degraded");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001010 break;
1011 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001012 snprintf(exception, BUFSIZE, "Data degraded in partion %i",
1013 sense->fmt.f70.mp);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001014 break;
1015 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001016 snprintf(exception, BUFSIZE, "Medium degraded");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001017 break;
1018 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001019 snprintf(exception, BUFSIZE, "Medium degraded in partition %i",
1020 sense->fmt.f70.mp);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001021 break;
1022 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001023 snprintf(exception, BUFSIZE, "Block 0 Error");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001024 break;
1025 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001026 snprintf(exception, BUFSIZE, "Medium Exception 0x%02x",
1027 sense->fmt.f70.md);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001028 break;
1029 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001030 snprintf(exception, BUFSIZE, "0x%02x",
1031 sense->fmt.f70.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001032 break;
1033 }
1034 /* Service Message */
1035 switch (sense->fmt.f70.smc) {
1036 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001037 snprintf(service, BUFSIZE, "Reference Media maintenance "
1038 "procedure %i", sense->fmt.f70.md);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001039 break;
1040 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001041 snprintf(service, BUFSIZE, "0x%02x",
1042 sense->fmt.f70.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001043 break;
1044 }
Carsten Otteab640db2009-03-26 15:24:38 +01001045
1046 dev_warn (&device->cdev->dev, "Tape media information: exception %s, "
1047 "service %s\n", exception, service);
1048
1049out_nomem:
1050 kfree(exception);
1051 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001052}
1053
1054/*
1055 * Print an I/O Subsystem Service Information Message (message code f1)
1056 */
1057static void
1058tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
1059{
1060 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +01001061 char *exception, *service;
1062
1063 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1064 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1065
1066 if (!exception || !service)
1067 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001068
1069 sense = (struct tape_3590_sense *) irb->ecw;
1070 /* Exception Message */
1071 switch (sense->fmt.f71.emc) {
1072 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001073 snprintf(exception, BUFSIZE, "Effect of failure is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001074 break;
1075 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001076 snprintf(exception, BUFSIZE, "CU Exception - no performance "
1077 "impact");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001078 break;
1079 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001080 snprintf(exception, BUFSIZE, "CU Exception on channel "
1081 "interface 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001082 break;
1083 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001084 snprintf(exception, BUFSIZE, "CU Exception on device path "
1085 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001086 break;
1087 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001088 snprintf(exception, BUFSIZE, "CU Exception on library path "
1089 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001090 break;
1091 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001092 snprintf(exception, BUFSIZE, "CU Exception on node 0x%02x",
1093 sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001094 break;
1095 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001096 snprintf(exception, BUFSIZE, "CU Exception on partition "
1097 "0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001098 break;
1099 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001100 snprintf(exception, BUFSIZE, "0x%02x",
1101 sense->fmt.f71.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001102 }
1103 /* Service Message */
1104 switch (sense->fmt.f71.smc) {
1105 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001106 snprintf(service, BUFSIZE, "Repair impact is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001107 break;
1108 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001109 snprintf(service, BUFSIZE, "Repair will not impact cu "
1110 "performance");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001111 break;
1112 case 0x03:
1113 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001114 snprintf(service, BUFSIZE, "Repair will disable node "
1115 "0x%x on CU", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001116 else
Carsten Otteab640db2009-03-26 15:24:38 +01001117 snprintf(service, BUFSIZE, "Repair will disable "
1118 "nodes (0x%x-0x%x) on CU", sense->fmt.f71.md[1],
1119 sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001120 break;
1121 case 0x04:
1122 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001123 snprintf(service, BUFSIZE, "Repair will disable "
1124 "channel path 0x%x on CU",
1125 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001126 else
Carsten Otteab640db2009-03-26 15:24:38 +01001127 snprintf(service, BUFSIZE, "Repair will disable cannel"
1128 " paths (0x%x-0x%x) on CU",
1129 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001130 break;
1131 case 0x05:
1132 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001133 snprintf(service, BUFSIZE, "Repair will disable device"
1134 " path 0x%x on CU", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001135 else
Carsten Otteab640db2009-03-26 15:24:38 +01001136 snprintf(service, BUFSIZE, "Repair will disable device"
1137 " paths (0x%x-0x%x) on CU",
1138 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001139 break;
1140 case 0x06:
1141 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001142 snprintf(service, BUFSIZE, "Repair will disable "
1143 "library path 0x%x on CU",
1144 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001145 else
Carsten Otteab640db2009-03-26 15:24:38 +01001146 snprintf(service, BUFSIZE, "Repair will disable "
1147 "library paths (0x%x-0x%x) on CU",
1148 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001149 break;
1150 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001151 snprintf(service, BUFSIZE, "Repair will disable access to CU");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001152 break;
1153 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001154 snprintf(service, BUFSIZE, "0x%02x",
1155 sense->fmt.f71.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001156 }
Carsten Otteab640db2009-03-26 15:24:38 +01001157
1158 dev_warn (&device->cdev->dev, "I/O subsystem information: exception"
1159 " %s, service %s\n", exception, service);
1160out_nomem:
1161 kfree(exception);
1162 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001163}
1164
1165/*
1166 * Print an Device Subsystem Service Information Message (message code f2)
1167 */
1168static void
1169tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
1170{
1171 struct tape_3590_sense *sense;
Carsten Otteab640db2009-03-26 15:24:38 +01001172 char *exception, *service;
1173
1174 exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1175 service = kmalloc(BUFSIZE, GFP_ATOMIC);
1176
1177 if (!exception || !service)
1178 goto out_nomem;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001179
1180 sense = (struct tape_3590_sense *) irb->ecw;
1181 /* Exception Message */
1182 switch (sense->fmt.f71.emc) {
1183 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001184 snprintf(exception, BUFSIZE, "Effect of failure is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001185 break;
1186 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001187 snprintf(exception, BUFSIZE, "DV Exception - no performance"
1188 " impact");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001189 break;
1190 case 0x03:
Carsten Otteab640db2009-03-26 15:24:38 +01001191 snprintf(exception, BUFSIZE, "DV Exception on channel "
1192 "interface 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001193 break;
1194 case 0x04:
Carsten Otteab640db2009-03-26 15:24:38 +01001195 snprintf(exception, BUFSIZE, "DV Exception on loader 0x%02x",
1196 sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001197 break;
1198 case 0x05:
Carsten Otteab640db2009-03-26 15:24:38 +01001199 snprintf(exception, BUFSIZE, "DV Exception on message display"
1200 " 0x%02x", sense->fmt.f71.md[0]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001201 break;
1202 case 0x06:
Carsten Otteab640db2009-03-26 15:24:38 +01001203 snprintf(exception, BUFSIZE, "DV Exception in tape path");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001204 break;
1205 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001206 snprintf(exception, BUFSIZE, "DV Exception in drive");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001207 break;
1208 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001209 snprintf(exception, BUFSIZE, "0x%02x",
1210 sense->fmt.f71.emc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001211 }
1212 /* Service Message */
1213 switch (sense->fmt.f71.smc) {
1214 case 0x01:
Carsten Otteab640db2009-03-26 15:24:38 +01001215 snprintf(service, BUFSIZE, "Repair impact is unknown");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001216 break;
1217 case 0x02:
Carsten Otteab640db2009-03-26 15:24:38 +01001218 snprintf(service, BUFSIZE, "Repair will not impact device "
1219 "performance");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001220 break;
1221 case 0x03:
1222 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001223 snprintf(service, BUFSIZE, "Repair will disable "
1224 "channel path 0x%x on DV",
1225 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001226 else
Carsten Otteab640db2009-03-26 15:24:38 +01001227 snprintf(service, BUFSIZE, "Repair will disable "
1228 "channel path (0x%x-0x%x) on DV",
1229 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001230 break;
1231 case 0x04:
1232 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001233 snprintf(service, BUFSIZE, "Repair will disable "
1234 "interface 0x%x on DV", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001235 else
Carsten Otteab640db2009-03-26 15:24:38 +01001236 snprintf(service, BUFSIZE, "Repair will disable "
1237 "interfaces (0x%x-0x%x) on DV",
1238 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001239 break;
1240 case 0x05:
1241 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001242 snprintf(service, BUFSIZE, "Repair will disable loader"
1243 " 0x%x on DV", sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001244 else
Carsten Otteab640db2009-03-26 15:24:38 +01001245 snprintf(service, BUFSIZE, "Repair will disable loader"
1246 " (0x%x-0x%x) on DV",
1247 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001248 break;
1249 case 0x07:
Carsten Otteab640db2009-03-26 15:24:38 +01001250 snprintf(service, BUFSIZE, "Repair will disable access to DV");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001251 break;
1252 case 0x08:
1253 if (sense->fmt.f71.mdf == 0)
Carsten Otteab640db2009-03-26 15:24:38 +01001254 snprintf(service, BUFSIZE, "Repair will disable "
1255 "message display 0x%x on DV",
1256 sense->fmt.f71.md[1]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001257 else
Carsten Otteab640db2009-03-26 15:24:38 +01001258 snprintf(service, BUFSIZE, "Repair will disable "
1259 "message displays (0x%x-0x%x) on DV",
1260 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001261 break;
1262 case 0x09:
Carsten Otteab640db2009-03-26 15:24:38 +01001263 snprintf(service, BUFSIZE, "Clean DV");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001264 break;
1265 default:
Carsten Otteab640db2009-03-26 15:24:38 +01001266 snprintf(service, BUFSIZE, "0x%02x",
1267 sense->fmt.f71.smc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001268 }
Carsten Otteab640db2009-03-26 15:24:38 +01001269
1270 dev_warn (&device->cdev->dev, "Device subsystem information: exception"
1271 " %s, service %s\n", exception, service);
1272out_nomem:
1273 kfree(exception);
1274 kfree(service);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001275}
1276
1277/*
1278 * Print standard ERA Message
1279 */
1280static void
1281tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
1282{
1283 struct tape_3590_sense *sense;
1284
1285 sense = (struct tape_3590_sense *) irb->ecw;
1286 if (sense->mc == 0)
1287 return;
1288 if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) {
1289 if (tape_3590_msg[sense->mc] != NULL)
Carsten Otteab640db2009-03-26 15:24:38 +01001290 dev_warn (&device->cdev->dev, "The tape unit has "
1291 "issued sense message %s\n",
1292 tape_3590_msg[sense->mc]);
1293 else
1294 dev_warn (&device->cdev->dev, "The tape unit has "
1295 "issued an unknown sense message code 0x%x\n",
1296 sense->mc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001297 return;
1298 }
1299 if (sense->mc == 0xf0) {
1300 /* Standard Media Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001301 dev_warn (&device->cdev->dev, "MIM SEV=%i, MC=%02x, ES=%x/%x, "
1302 "RC=%02x-%04x-%02x\n", sense->fmt.f70.sev, sense->mc,
1303 sense->fmt.f70.emc, sense->fmt.f70.smc,
1304 sense->fmt.f70.refcode, sense->fmt.f70.mid,
1305 sense->fmt.f70.fid);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001306 tape_3590_print_mim_msg_f0(device, irb);
1307 return;
1308 }
1309 if (sense->mc == 0xf1) {
1310 /* Standard I/O Subsystem Service Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001311 dev_warn (&device->cdev->dev, "IOSIM SEV=%i, DEVTYPE=3590/%02x,"
1312 " MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1313 sense->fmt.f71.sev, device->cdev->id.dev_model,
1314 sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1315 sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1316 sense->fmt.f71.refcode3);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001317 tape_3590_print_io_sim_msg_f1(device, irb);
1318 return;
1319 }
1320 if (sense->mc == 0xf2) {
1321 /* Standard Device Service Information Message */
Carsten Otteab640db2009-03-26 15:24:38 +01001322 dev_warn (&device->cdev->dev, "DEVSIM SEV=%i, DEVTYPE=3590/%02x"
1323 ", MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1324 sense->fmt.f71.sev, device->cdev->id.dev_model,
1325 sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1326 sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1327 sense->fmt.f71.refcode3);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001328 tape_3590_print_dev_sim_msg_f2(device, irb);
1329 return;
1330 }
1331 if (sense->mc == 0xf3) {
1332 /* Standard Library Service Information Message */
1333 return;
1334 }
Carsten Otteab640db2009-03-26 15:24:38 +01001335 dev_warn (&device->cdev->dev, "The tape unit has issued an unknown "
1336 "sense message code %x\n", sense->mc);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001337}
1338
Michael Holzheucced1dd2007-02-05 21:18:26 +01001339static int tape_3590_crypt_error(struct tape_device *device,
1340 struct tape_request *request, struct irb *irb)
1341{
1342 u8 cu_rc, ekm_rc1;
1343 u16 ekm_rc2;
1344 u32 drv_rc;
Kay Sievers2a0217d2008-10-10 21:33:09 +02001345 const char *bus_id;
1346 char *sense;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001347
1348 sense = ((struct tape_3590_sense *) irb->ecw)->fmt.data;
Kay Sievers2a0217d2008-10-10 21:33:09 +02001349 bus_id = dev_name(&device->cdev->dev);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001350 cu_rc = sense[0];
1351 drv_rc = *((u32*) &sense[5]) & 0xffffff;
1352 ekm_rc1 = sense[9];
1353 ekm_rc2 = *((u16*) &sense[10]);
1354 if ((cu_rc == 0) && (ekm_rc2 == 0xee31))
1355 /* key not defined on EKM */
1356 return tape_3590_erp_basic(device, request, irb, -EKEYREJECTED);
1357 if ((cu_rc == 1) || (cu_rc == 2))
1358 /* No connection to EKM */
1359 return tape_3590_erp_basic(device, request, irb, -ENOTCONN);
1360
Carsten Otteab640db2009-03-26 15:24:38 +01001361 dev_err (&device->cdev->dev, "The tape unit failed to obtain the "
1362 "encryption key from EKM\n");
Michael Holzheucced1dd2007-02-05 21:18:26 +01001363
1364 return tape_3590_erp_basic(device, request, irb, -ENOKEY);
1365}
1366
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001367/*
1368 * 3590 error Recovery routine:
1369 * If possible, it tries to recover from the error. If this is not possible,
1370 * inform the user about the problem.
1371 */
1372static int
1373tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
1374 struct irb *irb)
1375{
1376 struct tape_3590_sense *sense;
1377 int rc;
1378
1379#ifdef CONFIG_S390_TAPE_BLOCK
1380 if (request->op == TO_BLOCK) {
1381 /*
1382 * Recovery for block device requests. Set the block_position
1383 * to something invalid and retry.
1384 */
1385 device->blk_data.block_position = -1;
1386 if (request->retries-- <= 0)
1387 return tape_3590_erp_failed(device, request, irb, -EIO);
1388 else
1389 return tape_3590_erp_retry(device, request, irb);
1390 }
1391#endif
1392
1393 sense = (struct tape_3590_sense *) irb->ecw;
1394
Michael Holzheucced1dd2007-02-05 21:18:26 +01001395 DBF_EVENT(6, "Unit Check: RQC = %x\n", sense->rc_rqc);
1396
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001397 /*
1398 * First check all RC-QRCs where we want to do something special
1399 * - "break": basic error recovery is done
1400 * - "goto out:": just print error message if available
1401 */
1402 rc = -EIO;
1403 switch (sense->rc_rqc) {
1404
1405 case 0x1110:
1406 tape_3590_print_era_msg(device, irb);
1407 return tape_3590_erp_read_buf_log(device, request, irb);
1408
1409 case 0x2011:
1410 tape_3590_print_era_msg(device, irb);
1411 return tape_3590_erp_read_alternate(device, request, irb);
1412
1413 case 0x2230:
1414 case 0x2231:
1415 tape_3590_print_era_msg(device, irb);
1416 return tape_3590_erp_special_interrupt(device, request, irb);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001417 case 0x2240:
1418 return tape_3590_crypt_error(device, request, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001419
1420 case 0x3010:
1421 DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1422 device->cdev_id);
1423 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1424 case 0x3012:
1425 DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1426 device->cdev_id);
1427 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1428 case 0x3020:
1429 DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
1430 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1431
1432 case 0x3122:
1433 DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1434 device->cdev_id);
1435 return tape_3590_erp_basic(device, request, irb, -EIO);
1436 case 0x3123:
1437 DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1438 device->cdev_id);
1439 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001440 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001441 return tape_3590_erp_basic(device, request, irb, 0);
1442
1443 case 0x4010:
1444 /*
1445 * print additional msg since default msg
1446 * "device intervention" is not very meaningfull
1447 */
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001448 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001449 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001450 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1451 case 0x4012: /* Device Long Busy */
Michael Holzheucced1dd2007-02-05 21:18:26 +01001452 /* XXX: Also use long busy handling here? */
1453 DBF_EVENT(6, "(%08x): LONG BUSY\n", device->cdev_id);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001454 tape_3590_print_era_msg(device, irb);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001455 return tape_3590_erp_basic(device, request, irb, -EBUSY);
1456 case 0x4014:
1457 DBF_EVENT(6, "(%08x): Crypto LONG BUSY\n", device->cdev_id);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001458 return tape_3590_erp_long_busy(device, request, irb);
1459
1460 case 0x5010:
1461 if (sense->rac == 0xd0) {
1462 /* Swap */
1463 tape_3590_print_era_msg(device, irb);
1464 return tape_3590_erp_swap(device, request, irb);
1465 }
1466 if (sense->rac == 0x26) {
1467 /* Read Opposite */
1468 tape_3590_print_era_msg(device, irb);
1469 return tape_3590_erp_read_opposite(device, request,
1470 irb);
1471 }
1472 return tape_3590_erp_basic(device, request, irb, -EIO);
1473 case 0x5020:
1474 case 0x5021:
1475 case 0x5022:
1476 case 0x5040:
1477 case 0x5041:
1478 case 0x5042:
1479 tape_3590_print_era_msg(device, irb);
1480 return tape_3590_erp_swap(device, request, irb);
1481
1482 case 0x5110:
1483 case 0x5111:
1484 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1485
1486 case 0x5120:
1487 case 0x1120:
1488 tape_med_state_set(device, MS_UNLOADED);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001489 tape_3590_schedule_work(device, TO_CRYPT_OFF);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001490 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1491
1492 case 0x6020:
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001493 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1494
1495 case 0x8011:
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001496 return tape_3590_erp_basic(device, request, irb, -EPERM);
1497 case 0x8013:
Carsten Otteab640db2009-03-26 15:24:38 +01001498 dev_warn (&device->cdev->dev, "A different host has privileged"
1499 " access to the tape unit\n");
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001500 return tape_3590_erp_basic(device, request, irb, -EPERM);
1501 default:
1502 return tape_3590_erp_basic(device, request, irb, -EIO);
1503 }
1504}
1505
1506/*
1507 * 3590 interrupt handler:
1508 */
1509static int
1510tape_3590_irq(struct tape_device *device, struct tape_request *request,
1511 struct irb *irb)
1512{
1513 if (request == NULL)
1514 return tape_3590_unsolicited_irq(device, irb);
1515
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001516 if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
1517 (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
1518 (request->op == TO_WRI)) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001519 /* Write at end of volume */
1520 DBF_EVENT(2, "End of volume\n");
1521 return tape_3590_erp_failed(device, request, irb, -ENOSPC);
1522 }
1523
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001524 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001525 return tape_3590_unit_check(device, request, irb);
1526
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001527 if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
1528 if (irb->scsw.cmd.dstat == DEV_STAT_UNIT_EXCEP) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001529 if (request->op == TO_FSB || request->op == TO_BSB)
1530 request->rescnt++;
1531 else
1532 DBF_EVENT(5, "Unit Exception!\n");
1533 }
1534
1535 return tape_3590_done(device, request);
1536 }
1537
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001538 if (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001539 DBF_EVENT(2, "cannel end\n");
1540 return TAPE_IO_PENDING;
1541 }
1542
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001543 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001544 DBF_EVENT(2, "Unit Attention when busy..\n");
1545 return TAPE_IO_PENDING;
1546 }
1547
1548 DBF_EVENT(6, "xunknownirq\n");
Carsten Otteab640db2009-03-26 15:24:38 +01001549 tape_dump_sense_dbf(device, request, irb);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001550 return TAPE_IO_STOP;
1551}
1552
Michael Holzheue2963062007-05-04 18:47:53 +02001553
1554static int tape_3590_read_dev_chars(struct tape_device *device,
1555 struct tape_3590_rdc_data *rdc_data)
1556{
1557 int rc;
1558 struct tape_request *request;
1559
1560 request = tape_alloc_request(1, sizeof(*rdc_data));
1561 if (IS_ERR(request))
1562 return PTR_ERR(request);
1563 request->op = TO_RDC;
1564 tape_ccw_end(request->cpaddr, CCW_CMD_RDC, sizeof(*rdc_data),
1565 request->cpdata);
1566 rc = tape_do_io(device, request);
1567 if (rc == 0)
1568 memcpy(rdc_data, request->cpdata, sizeof(*rdc_data));
1569 tape_free_request(request);
1570 return rc;
1571}
1572
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001573/*
1574 * Setup device function
1575 */
1576static int
1577tape_3590_setup_device(struct tape_device *device)
1578{
1579 int rc;
1580 struct tape_3590_disc_data *data;
Michael Holzheue2963062007-05-04 18:47:53 +02001581 struct tape_3590_rdc_data *rdc_data;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001582
1583 DBF_EVENT(6, "3590 device setup\n");
Michael Holzheucced1dd2007-02-05 21:18:26 +01001584 data = kzalloc(sizeof(struct tape_3590_disc_data), GFP_KERNEL | GFP_DMA);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001585 if (data == NULL)
1586 return -ENOMEM;
1587 data->read_back_op = READ_PREVIOUS;
1588 device->discdata = data;
1589
Michael Holzheue2963062007-05-04 18:47:53 +02001590 rdc_data = kmalloc(sizeof(*rdc_data), GFP_KERNEL | GFP_DMA);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001591 if (!rdc_data) {
1592 rc = -ENOMEM;
1593 goto fail_kmalloc;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001594 }
Michael Holzheue2963062007-05-04 18:47:53 +02001595 rc = tape_3590_read_dev_chars(device, rdc_data);
Michael Holzheucced1dd2007-02-05 21:18:26 +01001596 if (rc) {
1597 DBF_LH(3, "Read device characteristics failed!\n");
Julia Lawall1783e602008-06-10 10:03:25 +02001598 goto fail_rdc_data;
Michael Holzheucced1dd2007-02-05 21:18:26 +01001599 }
1600 rc = tape_std_assign(device);
1601 if (rc)
1602 goto fail_rdc_data;
Michael Holzheue2963062007-05-04 18:47:53 +02001603 if (rdc_data->data[31] == 0x13) {
Michael Holzheucced1dd2007-02-05 21:18:26 +01001604 data->crypt_info.capability |= TAPE390_CRYPT_SUPPORTED_MASK;
1605 tape_3592_disable_crypt(device);
1606 } else {
1607 DBF_EVENT(6, "Device has NO crypto support\n");
1608 }
1609 /* Try to find out if medium is loaded */
1610 rc = tape_3590_sense_medium(device);
1611 if (rc) {
1612 DBF_LH(3, "3590 medium sense returned %d\n", rc);
1613 goto fail_rdc_data;
1614 }
1615 return 0;
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001616
Michael Holzheucced1dd2007-02-05 21:18:26 +01001617fail_rdc_data:
1618 kfree(rdc_data);
1619fail_kmalloc:
1620 kfree(data);
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001621 return rc;
1622}
1623
1624/*
1625 * Cleanup device function
1626 */
1627static void
1628tape_3590_cleanup_device(struct tape_device *device)
1629{
Stefan Bader2cc924b2006-04-27 18:40:16 -07001630 flush_scheduled_work();
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001631 tape_std_unassign(device);
1632
1633 kfree(device->discdata);
1634 device->discdata = NULL;
1635}
1636
1637/*
1638 * List of 3590 magnetic tape commands.
1639 */
1640static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = {
1641 [MTRESET] = tape_std_mtreset,
1642 [MTFSF] = tape_std_mtfsf,
1643 [MTBSF] = tape_std_mtbsf,
1644 [MTFSR] = tape_std_mtfsr,
1645 [MTBSR] = tape_std_mtbsr,
1646 [MTWEOF] = tape_std_mtweof,
1647 [MTREW] = tape_std_mtrew,
1648 [MTOFFL] = tape_std_mtoffl,
1649 [MTNOP] = tape_std_mtnop,
1650 [MTRETEN] = tape_std_mtreten,
1651 [MTBSFM] = tape_std_mtbsfm,
1652 [MTFSFM] = tape_std_mtfsfm,
1653 [MTEOM] = tape_std_mteom,
1654 [MTERASE] = tape_std_mterase,
1655 [MTRAS1] = NULL,
1656 [MTRAS2] = NULL,
1657 [MTRAS3] = NULL,
1658 [MTSETBLK] = tape_std_mtsetblk,
1659 [MTSETDENSITY] = NULL,
1660 [MTSEEK] = tape_3590_mtseek,
1661 [MTTELL] = tape_3590_mttell,
1662 [MTSETDRVBUFFER] = NULL,
1663 [MTFSS] = NULL,
1664 [MTBSS] = NULL,
1665 [MTWSM] = NULL,
1666 [MTLOCK] = NULL,
1667 [MTUNLOCK] = NULL,
1668 [MTLOAD] = tape_std_mtload,
1669 [MTUNLOAD] = tape_std_mtunload,
1670 [MTCOMPRESSION] = tape_std_mtcompression,
1671 [MTSETPART] = NULL,
1672 [MTMKPART] = NULL
1673};
1674
1675/*
1676 * Tape discipline structure for 3590.
1677 */
1678static struct tape_discipline tape_discipline_3590 = {
1679 .owner = THIS_MODULE,
1680 .setup_device = tape_3590_setup_device,
1681 .cleanup_device = tape_3590_cleanup_device,
1682 .process_eov = tape_std_process_eov,
1683 .irq = tape_3590_irq,
1684 .read_block = tape_std_read_block,
1685 .write_block = tape_std_write_block,
1686#ifdef CONFIG_S390_TAPE_BLOCK
1687 .bread = tape_3590_bread,
1688 .free_bread = tape_3590_free_bread,
1689 .check_locate = tape_3590_check_locate,
1690#endif
1691 .ioctl_fn = tape_3590_ioctl,
1692 .mtop_array = tape_3590_mtop
1693};
1694
1695static struct ccw_device_id tape_3590_ids[] = {
1696 {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590},
Stefan Bader2cc924b2006-04-27 18:40:16 -07001697 {CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info = tape_3592},
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001698 { /* end of list */ }
1699};
1700
1701static int
1702tape_3590_online(struct ccw_device *cdev)
1703{
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07001704 return tape_generic_online(dev_get_drvdata(&cdev->dev),
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001705 &tape_discipline_3590);
1706}
1707
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001708static struct ccw_driver tape_3590_driver = {
1709 .name = "tape_3590",
1710 .owner = THIS_MODULE,
1711 .ids = tape_3590_ids,
1712 .probe = tape_generic_probe,
1713 .remove = tape_generic_remove,
Frank Munzert4d7a3cd2009-04-23 13:58:09 +02001714 .set_offline = tape_generic_offline,
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001715 .set_online = tape_3590_online,
Frank Munzert3ef32e62009-06-16 10:30:39 +02001716 .freeze = tape_generic_pm_suspend,
Stefan Baderb6cba4e2006-03-24 03:15:29 -08001717};
1718
1719/*
1720 * Setup discipline structure.
1721 */
1722static int
1723tape_3590_init(void)
1724{
1725 int rc;
1726
1727 TAPE_DBF_AREA = debug_register("tape_3590", 2, 2, 4 * sizeof(long));
1728 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1729#ifdef DBF_LIKE_HELL
1730 debug_set_level(TAPE_DBF_AREA, 6);
1731#endif
1732
1733 DBF_EVENT(3, "3590 init\n");
1734 /* Register driver for 3590 tapes. */
1735 rc = ccw_driver_register(&tape_3590_driver);
1736 if (rc)
1737 DBF_EVENT(3, "3590 init failed\n");
1738 else
1739 DBF_EVENT(3, "3590 registered\n");
1740 return rc;
1741}
1742
1743static void
1744tape_3590_exit(void)
1745{
1746 ccw_driver_unregister(&tape_3590_driver);
1747
1748 debug_unregister(TAPE_DBF_AREA);
1749}
1750
1751MODULE_DEVICE_TABLE(ccw, tape_3590_ids);
1752MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
1753MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
1754MODULE_LICENSE("GPL");
1755
1756module_init(tape_3590_init);
1757module_exit(tape_3590_exit);