tape_3590.c 46.8 KB
Newer Older
S
Stefan Bader 已提交
1 2 3 4
/*
 *  drivers/s390/char/tape_3590.c
 *    tape device discipline for 3590 tapes.
 *
5
 *    Copyright IBM Corp. 2001, 2009
S
Stefan Bader 已提交
6 7 8 9 10
 *    Author(s): Stefan Bader <shbader@de.ibm.com>
 *		 Michael Holzheu <holzheu@de.ibm.com>
 *		 Martin Schwidefsky <schwidefsky@de.ibm.com>
 */

11
#define KMSG_COMPONENT "tape_3590"
12
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
C
Carsten Otte 已提交
13

S
Stefan Bader 已提交
14
#include <linux/module.h>
15
#include <linux/slab.h>
S
Stefan Bader 已提交
16 17
#include <linux/init.h>
#include <linux/bio.h>
18
#include <asm/ebcdic.h>
S
Stefan Bader 已提交
19 20

#define TAPE_DBF_AREA	tape_3590_dbf
C
Carsten Otte 已提交
21
#define BUFSIZE 512	/* size of buffers for dynamic generated messages */
S
Stefan Bader 已提交
22 23 24 25 26

#include "tape.h"
#include "tape_std.h"
#include "tape_3590.h"

T
Tejun Heo 已提交
27 28
static struct workqueue_struct *tape_3590_wq;

S
Stefan Bader 已提交
29 30 31 32 33 34 35
/*
 * Pointer to debug area.
 */
debug_info_t *TAPE_DBF_AREA = NULL;
EXPORT_SYMBOL(TAPE_DBF_AREA);

/*******************************************************************
36
 * Error Recovery functions:
S
Stefan Bader 已提交
37 38 39 40
 * - Read Opposite:		 implemented
 * - Read Device (buffered) log: BRA
 * - Read Library log:		 BRA
 * - Swap Devices:		 BRA
41
 * - Long Busy:			 implemented
S
Stefan Bader 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
 * - Special Intercept:		 BRA
 * - Read Alternate:		 implemented
 *******************************************************************/

static const char *tape_3590_msg[TAPE_3590_MAX_MSG] = {
	[0x00] = "",
	[0x10] = "Lost Sense",
	[0x11] = "Assigned Elsewhere",
	[0x12] = "Allegiance Reset",
	[0x13] = "Shared Access Violation",
	[0x20] = "Command Reject",
	[0x21] = "Configuration Error",
	[0x22] = "Protection Exception",
	[0x23] = "Write Protect",
	[0x24] = "Write Length",
	[0x25] = "Read-Only Format",
	[0x31] = "Beginning of Partition",
	[0x33] = "End of Partition",
	[0x34] = "End of Data",
	[0x35] = "Block not found",
	[0x40] = "Device Intervention",
	[0x41] = "Loader Intervention",
	[0x42] = "Library Intervention",
	[0x50] = "Write Error",
	[0x51] = "Erase Error",
	[0x52] = "Formatting Error",
	[0x53] = "Read Error",
	[0x54] = "Unsupported Format",
	[0x55] = "No Formatting",
	[0x56] = "Positioning lost",
	[0x57] = "Read Length",
	[0x60] = "Unsupported Medium",
	[0x61] = "Medium Length Error",
	[0x62] = "Medium removed",
	[0x64] = "Load Check",
	[0x65] = "Unload Check",
	[0x70] = "Equipment Check",
	[0x71] = "Bus out Check",
	[0x72] = "Protocol Error",
	[0x73] = "Interface Error",
	[0x74] = "Overrun",
	[0x75] = "Halt Signal",
	[0x90] = "Device fenced",
	[0x91] = "Device Path fenced",
	[0xa0] = "Volume misplaced",
	[0xa1] = "Volume inaccessible",
	[0xa2] = "Volume in input",
	[0xa3] = "Volume ejected",
	[0xa4] = "All categories reserved",
	[0xa5] = "Duplicate Volume",
	[0xa6] = "Library Manager Offline",
	[0xa7] = "Library Output Station full",
	[0xa8] = "Vision System non-operational",
	[0xa9] = "Library Manager Equipment Check",
	[0xaa] = "Library Equipment Check",
	[0xab] = "All Library Cells full",
	[0xac] = "No Cleaner Volumes in Library",
	[0xad] = "I/O Station door open",
	[0xae] = "Subsystem environmental alert",
};

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
static int crypt_supported(struct tape_device *device)
{
	return TAPE390_CRYPT_SUPPORTED(TAPE_3590_CRYPT_INFO(device));
}

static int crypt_enabled(struct tape_device *device)
{
	return TAPE390_CRYPT_ON(TAPE_3590_CRYPT_INFO(device));
}

static void ext_to_int_kekl(struct tape390_kekl *in,
			    struct tape3592_kekl *out)
{
	int i;

	memset(out, 0, sizeof(*out));
	if (in->type == TAPE390_KEKL_TYPE_HASH)
		out->flags |= 0x40;
	if (in->type_on_tape == TAPE390_KEKL_TYPE_HASH)
		out->flags |= 0x80;
	strncpy(out->label, in->label, 64);
	for (i = strlen(in->label); i < sizeof(out->label); i++)
		out->label[i] = ' ';
	ASCEBC(out->label, sizeof(out->label));
}

static void int_to_ext_kekl(struct tape3592_kekl *in,
			    struct tape390_kekl *out)
{
	memset(out, 0, sizeof(*out));
	if(in->flags & 0x40)
		out->type = TAPE390_KEKL_TYPE_HASH;
	else
		out->type = TAPE390_KEKL_TYPE_LABEL;
	if(in->flags & 0x80)
		out->type_on_tape = TAPE390_KEKL_TYPE_HASH;
	else
		out->type_on_tape = TAPE390_KEKL_TYPE_LABEL;
	memcpy(out->label, in->label, sizeof(in->label));
	EBCASC(out->label, sizeof(in->label));
143
	strim(out->label);
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
}

static void int_to_ext_kekl_pair(struct tape3592_kekl_pair *in,
				 struct tape390_kekl_pair *out)
{
	if (in->count == 0) {
		out->kekl[0].type = TAPE390_KEKL_TYPE_NONE;
		out->kekl[0].type_on_tape = TAPE390_KEKL_TYPE_NONE;
		out->kekl[1].type = TAPE390_KEKL_TYPE_NONE;
		out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE;
	} else if (in->count == 1) {
		int_to_ext_kekl(&in->kekl[0], &out->kekl[0]);
		out->kekl[1].type = TAPE390_KEKL_TYPE_NONE;
		out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE;
	} else if (in->count == 2) {
		int_to_ext_kekl(&in->kekl[0], &out->kekl[0]);
		int_to_ext_kekl(&in->kekl[1], &out->kekl[1]);
	} else {
		printk("Invalid KEKL number: %d\n", in->count);
		BUG();
	}
}

static int check_ext_kekl(struct tape390_kekl *kekl)
{
	if (kekl->type == TAPE390_KEKL_TYPE_NONE)
		goto invalid;
	if (kekl->type > TAPE390_KEKL_TYPE_HASH)
		goto invalid;
	if (kekl->type_on_tape == TAPE390_KEKL_TYPE_NONE)
		goto invalid;
	if (kekl->type_on_tape > TAPE390_KEKL_TYPE_HASH)
		goto invalid;
	if ((kekl->type == TAPE390_KEKL_TYPE_HASH) &&
	    (kekl->type_on_tape == TAPE390_KEKL_TYPE_LABEL))
		goto invalid;

	return 0;
invalid:
	return -EINVAL;
}

static int check_ext_kekl_pair(struct tape390_kekl_pair *kekls)
{
	if (check_ext_kekl(&kekls->kekl[0]))
		goto invalid;
	if (check_ext_kekl(&kekls->kekl[1]))
		goto invalid;

	return 0;
invalid:
	return -EINVAL;
}

/*
 * Query KEKLs
 */
static int tape_3592_kekl_query(struct tape_device *device,
				struct tape390_kekl_pair *ext_kekls)
{
	struct tape_request *request;
	struct tape3592_kekl_query_order *order;
	struct tape3592_kekl_query_data *int_kekls;
	int rc;

	DBF_EVENT(6, "tape3592_kekl_query\n");
	int_kekls = kmalloc(sizeof(*int_kekls), GFP_KERNEL|GFP_DMA);
	if (!int_kekls)
		return -ENOMEM;
	request = tape_alloc_request(2, sizeof(*order));
	if (IS_ERR(request)) {
		rc = PTR_ERR(request);
		goto fail_malloc;
	}
	order = request->cpdata;
	memset(order,0,sizeof(*order));
	order->code = 0xe2;
	order->max_count = 2;
	request->op = TO_KEKL_QUERY;
	tape_ccw_cc(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order);
	tape_ccw_end(request->cpaddr + 1, READ_SS_DATA, sizeof(*int_kekls),
		     int_kekls);
	rc = tape_do_io(device, request);
	if (rc)
		goto fail_request;
	int_to_ext_kekl_pair(&int_kekls->kekls, ext_kekls);

	rc = 0;
fail_request:
	tape_free_request(request);
fail_malloc:
	kfree(int_kekls);
	return rc;
}

/*
 * IOCTL: Query KEKLs
 */
static int tape_3592_ioctl_kekl_query(struct tape_device *device,
				      unsigned long arg)
{
	int rc;
	struct tape390_kekl_pair *ext_kekls;

	DBF_EVENT(6, "tape_3592_ioctl_kekl_query\n");
	if (!crypt_supported(device))
		return -ENOSYS;
	if (!crypt_enabled(device))
		return -EUNATCH;
	ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
	if (!ext_kekls)
		return -ENOMEM;
	rc = tape_3592_kekl_query(device, ext_kekls);
	if (rc != 0)
		goto fail;
	if (copy_to_user((char __user *) arg, ext_kekls, sizeof(*ext_kekls))) {
		rc = -EFAULT;
		goto fail;
	}
	rc = 0;
fail:
	kfree(ext_kekls);
	return rc;
}

static int tape_3590_mttell(struct tape_device *device, int mt_count);

/*
 * Set KEKLs
 */
static int tape_3592_kekl_set(struct tape_device *device,
			      struct tape390_kekl_pair *ext_kekls)
{
	struct tape_request *request;
	struct tape3592_kekl_set_order *order;

	DBF_EVENT(6, "tape3592_kekl_set\n");
	if (check_ext_kekl_pair(ext_kekls)) {
		DBF_EVENT(6, "invalid kekls\n");
		return -EINVAL;
	}
	if (tape_3590_mttell(device, 0) != 0)
		return -EBADSLT;
	request = tape_alloc_request(1, sizeof(*order));
	if (IS_ERR(request))
		return PTR_ERR(request);
	order = request->cpdata;
	memset(order, 0, sizeof(*order));
	order->code = 0xe3;
	order->kekls.count = 2;
	ext_to_int_kekl(&ext_kekls->kekl[0], &order->kekls.kekl[0]);
	ext_to_int_kekl(&ext_kekls->kekl[1], &order->kekls.kekl[1]);
	request->op = TO_KEKL_SET;
	tape_ccw_end(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order);

	return tape_do_io_free(device, request);
}

/*
 * IOCTL: Set KEKLs
 */
static int tape_3592_ioctl_kekl_set(struct tape_device *device,
				    unsigned long arg)
{
	int rc;
	struct tape390_kekl_pair *ext_kekls;

	DBF_EVENT(6, "tape_3592_ioctl_kekl_set\n");
	if (!crypt_supported(device))
		return -ENOSYS;
	if (!crypt_enabled(device))
		return -EUNATCH;
	ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
	if (!ext_kekls)
		return -ENOMEM;
	if (copy_from_user(ext_kekls, (char __user *)arg, sizeof(*ext_kekls))) {
		rc = -EFAULT;
		goto out;
	}
	rc = tape_3592_kekl_set(device, ext_kekls);
out:
	kfree(ext_kekls);
	return rc;
}

/*
 * Enable encryption
 */
332
static struct tape_request *__tape_3592_enable_crypt(struct tape_device *device)
333 334 335 336 337 338
{
	struct tape_request *request;
	char *data;

	DBF_EVENT(6, "tape_3592_enable_crypt\n");
	if (!crypt_supported(device))
339
		return ERR_PTR(-ENOSYS);
340 341
	request = tape_alloc_request(2, 72);
	if (IS_ERR(request))
342
		return request;
343 344 345 346 347 348 349 350 351 352 353 354 355 356
	data = request->cpdata;
	memset(data,0,72);

	data[0]       = 0x05;
	data[36 + 0]  = 0x03;
	data[36 + 1]  = 0x03;
	data[36 + 4]  = 0x40;
	data[36 + 6]  = 0x01;
	data[36 + 14] = 0x2f;
	data[36 + 18] = 0xc3;
	data[36 + 35] = 0x72;
	request->op = TO_CRYPT_ON;
	tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
	tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
357 358 359 360 361 362 363 364 365 366
	return request;
}

static int tape_3592_enable_crypt(struct tape_device *device)
{
	struct tape_request *request;

	request = __tape_3592_enable_crypt(device);
	if (IS_ERR(request))
		return PTR_ERR(request);
367 368 369
	return tape_do_io_free(device, request);
}

370 371 372 373 374 375 376 377 378
static void tape_3592_enable_crypt_async(struct tape_device *device)
{
	struct tape_request *request;

	request = __tape_3592_enable_crypt(device);
	if (!IS_ERR(request))
		tape_do_io_async_free(device, request);
}

379 380 381
/*
 * Disable encryption
 */
382
static struct tape_request *__tape_3592_disable_crypt(struct tape_device *device)
383 384 385 386 387 388
{
	struct tape_request *request;
	char *data;

	DBF_EVENT(6, "tape_3592_disable_crypt\n");
	if (!crypt_supported(device))
389
		return ERR_PTR(-ENOSYS);
390 391
	request = tape_alloc_request(2, 72);
	if (IS_ERR(request))
392
		return request;
393 394 395 396 397 398 399 400 401 402 403 404
	data = request->cpdata;
	memset(data,0,72);

	data[0]       = 0x05;
	data[36 + 0]  = 0x03;
	data[36 + 1]  = 0x03;
	data[36 + 35] = 0x32;

	request->op = TO_CRYPT_OFF;
	tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
	tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);

405 406 407 408 409 410 411 412 413 414
	return request;
}

static int tape_3592_disable_crypt(struct tape_device *device)
{
	struct tape_request *request;

	request = __tape_3592_disable_crypt(device);
	if (IS_ERR(request))
		return PTR_ERR(request);
415 416 417
	return tape_do_io_free(device, request);
}

418 419 420 421 422 423 424 425 426
static void tape_3592_disable_crypt_async(struct tape_device *device)
{
	struct tape_request *request;

	request = __tape_3592_disable_crypt(device);
	if (!IS_ERR(request))
		tape_do_io_async_free(device, request);
}

427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
/*
 * IOCTL: Set encryption status
 */
static int tape_3592_ioctl_crypt_set(struct tape_device *device,
				     unsigned long arg)
{
	struct tape390_crypt_info info;

	DBF_EVENT(6, "tape_3592_ioctl_crypt_set\n");
	if (!crypt_supported(device))
		return -ENOSYS;
	if (copy_from_user(&info, (char __user *)arg, sizeof(info)))
		return -EFAULT;
	if (info.status & ~TAPE390_CRYPT_ON_MASK)
		return -EINVAL;
	if (info.status & TAPE390_CRYPT_ON_MASK)
		return tape_3592_enable_crypt(device);
	else
		return tape_3592_disable_crypt(device);
}

static int tape_3590_sense_medium(struct tape_device *device);

/*
 * IOCTL: Query enryption status
 */
static int tape_3592_ioctl_crypt_query(struct tape_device *device,
				       unsigned long arg)
{
	DBF_EVENT(6, "tape_3592_ioctl_crypt_query\n");
	if (!crypt_supported(device))
		return -ENOSYS;
	tape_3590_sense_medium(device);
	if (copy_to_user((char __user *) arg, &TAPE_3590_CRYPT_INFO(device),
		sizeof(TAPE_3590_CRYPT_INFO(device))))
		return -EFAULT;
	else
		return 0;
}

S
Stefan Bader 已提交
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
/*
 * 3590 IOCTL Overload
 */
static int
tape_3590_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
{
	switch (cmd) {
	case TAPE390_DISPLAY: {
		struct display_struct disp;

		if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)))
			return -EFAULT;

		return tape_std_display(device, &disp);
	}
482 483 484 485 486 487 488 489
	case TAPE390_KEKL_SET:
		return tape_3592_ioctl_kekl_set(device, arg);
	case TAPE390_KEKL_QUERY:
		return tape_3592_ioctl_kekl_query(device, arg);
	case TAPE390_CRYPT_SET:
		return tape_3592_ioctl_crypt_set(device, arg);
	case TAPE390_CRYPT_QUERY:
		return tape_3592_ioctl_crypt_query(device, arg);
S
Stefan Bader 已提交
490 491 492 493 494 495 496 497
	default:
		return -EINVAL;	/* no additional ioctls */
	}
}

/*
 * SENSE Medium: Get Sense data about medium state
 */
498
static int tape_3590_sense_medium(struct tape_device *device)
S
Stefan Bader 已提交
499 500 501 502 503 504 505 506 507 508 509
{
	struct tape_request *request;

	request = tape_alloc_request(1, 128);
	if (IS_ERR(request))
		return PTR_ERR(request);
	request->op = TO_MSEN;
	tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
	return tape_do_io_free(device, request);
}

510 511 512 513 514 515 516 517 518 519 520 521
static void tape_3590_sense_medium_async(struct tape_device *device)
{
	struct tape_request *request;

	request = tape_alloc_request(1, 128);
	if (IS_ERR(request))
		return;
	request->op = TO_MSEN;
	tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
	tape_do_io_async_free(device, request);
}

S
Stefan Bader 已提交
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
/*
 * MTTELL: Tell block. Return the number of block relative to current file.
 */
static int
tape_3590_mttell(struct tape_device *device, int mt_count)
{
	__u64 block_id;
	int rc;

	rc = tape_std_read_block_id(device, &block_id);
	if (rc)
		return rc;
	return block_id >> 32;
}

/*
 * MTSEEK: seek to the specified block.
 */
static int
tape_3590_mtseek(struct tape_device *device, int count)
{
	struct tape_request *request;

	DBF_EVENT(6, "xsee id: %x\n", count);
	request = tape_alloc_request(3, 4);
	if (IS_ERR(request))
		return PTR_ERR(request);
	request->op = TO_LBL;
	tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
	*(__u32 *) request->cpdata = count;
	tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
	tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
	return tape_do_io_free(device, request);
}

/*
 * Read Opposite Error Recovery Function:
 * Used, when Read Forward does not work
 */
static void
tape_3590_read_opposite(struct tape_device *device,
			struct tape_request *request)
{
	struct tape_3590_disc_data *data;

	/*
	 * We have allocated 4 ccws in tape_std_read, so we can now
	 * transform the request to a read backward, followed by a
	 * forward space block.
	 */
	request->op = TO_RBA;
	tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
	data = device->discdata;
	tape_ccw_cc_idal(request->cpaddr + 1, data->read_back_op,
			 device->char_data.idal_buf);
	tape_ccw_cc(request->cpaddr + 2, FORSPACEBLOCK, 0, NULL);
	tape_ccw_end(request->cpaddr + 3, NOP, 0, NULL);
	DBF_EVENT(6, "xrop ccwg\n");
}

/*
 * Read Attention Msg
 * This should be done after an interrupt with attention bit (0x80)
 * in device state.
 *
 * After a "read attention message" request there are two possible
 * results:
 *
 * 1. A unit check is presented, when attention sense is present (e.g. when
 * a medium has been unloaded). The attention sense comes then
 * together with the unit check. The recovery action is either "retry"
 * (in case there is an attention message pending) or "permanent error".
 *
 * 2. The attention msg is written to the "read subsystem data" buffer.
 * In this case we probably should print it to the console.
 */
598
static void tape_3590_read_attmsg_async(struct tape_device *device)
S
Stefan Bader 已提交
599 600 601 602 603 604
{
	struct tape_request *request;
	char *buf;

	request = tape_alloc_request(3, 4096);
	if (IS_ERR(request))
605
		return;
S
Stefan Bader 已提交
606 607 608 609 610 611 612
	request->op = TO_READ_ATTMSG;
	buf = request->cpdata;
	buf[0] = PREP_RD_SS_DATA;
	buf[6] = RD_ATTMSG;	/* read att msg */
	tape_ccw_cc(request->cpaddr, PERFORM_SS_FUNC, 12, buf);
	tape_ccw_cc(request->cpaddr + 1, READ_SS_DATA, 4096 - 12, buf + 12);
	tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
613
	tape_do_io_async_free(device, request);
S
Stefan Bader 已提交
614 615 616 617 618
}

/*
 * These functions are used to schedule follow-up actions from within an
 * interrupt context (like unsolicited interrupts).
619 620 621
 * Note: the work handler is called by the system work queue. The tape
 * commands started by the handler need to be asynchrounous, otherwise
 * a deadlock can occur e.g. in case of a deferred cc=1 (see __tape_do_irq).
S
Stefan Bader 已提交
622
 */
S
Stefan Bader 已提交
623 624 625 626 627 628
struct work_handler_data {
	struct tape_device *device;
	enum tape_op        op;
	struct work_struct  work;
};

S
Stefan Bader 已提交
629
static void
M
Martin Schwidefsky 已提交
630
tape_3590_work_handler(struct work_struct *work)
S
Stefan Bader 已提交
631
{
M
Martin Schwidefsky 已提交
632 633
	struct work_handler_data *p =
		container_of(work, struct work_handler_data, work);
S
Stefan Bader 已提交
634 635 636

	switch (p->op) {
	case TO_MSEN:
637
		tape_3590_sense_medium_async(p->device);
S
Stefan Bader 已提交
638 639
		break;
	case TO_READ_ATTMSG:
640
		tape_3590_read_attmsg_async(p->device);
S
Stefan Bader 已提交
641
		break;
642
	case TO_CRYPT_ON:
643
		tape_3592_enable_crypt_async(p->device);
644 645
		break;
	case TO_CRYPT_OFF:
646
		tape_3592_disable_crypt_async(p->device);
647
		break;
S
Stefan Bader 已提交
648 649 650 651 652 653 654 655 656 657 658
	default:
		DBF_EVENT(3, "T3590: work handler undefined for "
			  "operation 0x%02x\n", p->op);
	}
	tape_put_device(p->device);
	kfree(p);
}

static int
tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
{
S
Stefan Bader 已提交
659
	struct work_handler_data *p;
S
Stefan Bader 已提交
660 661 662 663

	if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
		return -ENOMEM;

M
Martin Schwidefsky 已提交
664
	INIT_WORK(&p->work, tape_3590_work_handler);
S
Stefan Bader 已提交
665

666
	p->device = tape_get_device(device);
S
Stefan Bader 已提交
667 668
	p->op = op;

T
Tejun Heo 已提交
669
	queue_work(tape_3590_wq, &p->work);
S
Stefan Bader 已提交
670 671 672 673 674 675 676 677 678 679 680 681
	return 0;
}

#ifdef CONFIG_S390_TAPE_BLOCK
/*
 * Tape Block READ
 */
static struct tape_request *
tape_3590_bread(struct tape_device *device, struct request *req)
{
	struct tape_request *request;
	struct ccw1 *ccw;
682
	int count = 0, start_block;
S
Stefan Bader 已提交
683 684 685
	unsigned off;
	char *dst;
	struct bio_vec *bv;
686
	struct req_iterator iter;
S
Stefan Bader 已提交
687 688

	DBF_EVENT(6, "xBREDid:");
689
	start_block = blk_rq_pos(req) >> TAPEBLOCK_HSEC_S2B;
S
Stefan Bader 已提交
690 691
	DBF_EVENT(6, "start_block = %i\n", start_block);

692 693 694
	rq_for_each_segment(bv, req, iter)
		count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);

S
Stefan Bader 已提交
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
	request = tape_alloc_request(2 + count + 1, 4);
	if (IS_ERR(request))
		return request;
	request->op = TO_BLOCK;
	*(__u32 *) request->cpdata = start_block;
	ccw = request->cpaddr;
	ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);

	/*
	 * We always setup a nop after the mode set ccw. This slot is
	 * used in tape_std_check_locate to insert a locate ccw if the
	 * current tape position doesn't match the start block to be read.
	 */
	ccw = tape_ccw_cc(ccw, NOP, 0, NULL);

710
	rq_for_each_segment(bv, req, iter) {
711 712 713 714 715 716 717 718 719
		dst = page_address(bv->bv_page) + bv->bv_offset;
		for (off = 0; off < bv->bv_len; off += TAPEBLOCK_HSEC_SIZE) {
			ccw->flags = CCW_FLAG_CC;
			ccw->cmd_code = READ_FORWARD;
			ccw->count = TAPEBLOCK_HSEC_SIZE;
			set_normalized_cda(ccw, (void *) __pa(dst));
			ccw++;
			dst += TAPEBLOCK_HSEC_SIZE;
		}
S
Stoyan Gaydarov 已提交
720
		BUG_ON(off > bv->bv_len);
S
Stefan Bader 已提交
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
	}
	ccw = tape_ccw_end(ccw, NOP, 0, NULL);
	DBF_EVENT(6, "xBREDccwg\n");
	return request;
}

static void
tape_3590_free_bread(struct tape_request *request)
{
	struct ccw1 *ccw;

	/* Last ccw is a nop and doesn't need clear_normalized_cda */
	for (ccw = request->cpaddr; ccw->flags & CCW_FLAG_CC; ccw++)
		if (ccw->cmd_code == READ_FORWARD)
			clear_normalized_cda(ccw);
	tape_free_request(request);
}

/*
 * check_locate is called just before the tape request is passed to
 * the common io layer for execution. It has to check the current
 * tape position and insert a locate ccw if it doesn't match the
 * start block for the request.
 */
static void
tape_3590_check_locate(struct tape_device *device, struct tape_request *request)
{
	__u32 *start_block;

	start_block = (__u32 *) request->cpdata;
	if (*start_block != device->blk_data.block_position) {
		/* Add the start offset of the file to get the real block. */
		*start_block += device->bof;
		tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
	}
}
#endif

759 760 761 762 763 764 765
static void tape_3590_med_state_set(struct tape_device *device,
				    struct tape_3590_med_sense *sense)
{
	struct tape390_crypt_info *c_info;

	c_info = &TAPE_3590_CRYPT_INFO(device);

766 767 768 769 770
	DBF_EVENT(6, "medium state: %x:%x\n", sense->macst, sense->masst);
	switch (sense->macst) {
	case 0x04:
	case 0x05:
	case 0x06:
771 772 773
		tape_med_state_set(device, MS_UNLOADED);
		TAPE_3590_CRYPT_INFO(device).medium_status = 0;
		return;
774 775 776 777 778 779
	case 0x08:
	case 0x09:
		tape_med_state_set(device, MS_LOADED);
		break;
	default:
		tape_med_state_set(device, MS_UNKNOWN);
780 781 782 783
		return;
	}
	c_info->medium_status |= TAPE390_MEDIUM_LOADED_MASK;
	if (sense->flags & MSENSE_CRYPT_MASK) {
C
Carsten Otte 已提交
784
		DBF_EVENT(6, "Medium is encrypted (%04x)\n", sense->flags);
785 786 787 788 789 790 791
		c_info->medium_status |= TAPE390_MEDIUM_ENCRYPTED_MASK;
	} else	{
		DBF_EVENT(6, "Medium is not encrypted %04x\n", sense->flags);
		c_info->medium_status &= ~TAPE390_MEDIUM_ENCRYPTED_MASK;
	}
}

S
Stefan Bader 已提交
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
/*
 * The done handler is called at device/channel end and wakes up the sleeping
 * process
 */
static int
tape_3590_done(struct tape_device *device, struct tape_request *request)
{

	DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);

	switch (request->op) {
	case TO_BSB:
	case TO_BSF:
	case TO_DSE:
	case TO_FSB:
	case TO_FSF:
	case TO_LBL:
	case TO_RFO:
	case TO_RBA:
	case TO_REW:
	case TO_WRI:
	case TO_WTM:
	case TO_BLOCK:
	case TO_LOAD:
		tape_med_state_set(device, MS_LOADED);
		break;
	case TO_RUN:
		tape_med_state_set(device, MS_UNLOADED);
820
		tape_3590_schedule_work(device, TO_CRYPT_OFF);
S
Stefan Bader 已提交
821 822
		break;
	case TO_MSEN:
823 824 825 826 827 828 829 830 831 832 833
		tape_3590_med_state_set(device, request->cpdata);
		break;
	case TO_CRYPT_ON:
		TAPE_3590_CRYPT_INFO(device).status
			|= TAPE390_CRYPT_ON_MASK;
		*(device->modeset_byte) |= 0x03;
		break;
	case TO_CRYPT_OFF:
		TAPE_3590_CRYPT_INFO(device).status
			&= ~TAPE390_CRYPT_ON_MASK;
		*(device->modeset_byte) &= ~0x03;
S
Stefan Bader 已提交
834 835 836 837 838 839 840 841 842
		break;
	case TO_RBI:	/* RBI seems to succeed even without medium loaded. */
	case TO_NOP:	/* Same to NOP. */
	case TO_READ_CONFIG:
	case TO_READ_ATTMSG:
	case TO_DIS:
	case TO_ASSIGN:
	case TO_UNASSIGN:
	case TO_SIZE:
843 844
	case TO_KEKL_SET:
	case TO_KEKL_QUERY:
845
	case TO_RDC:
S
Stefan Bader 已提交
846 847 848 849 850 851
		break;
	}
	return TAPE_IO_SUCCESS;
}

/*
852
 * This function is called, when error recovery was successful
S
Stefan Bader 已提交
853 854 855 856
 */
static inline int
tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request)
{
C
Coly Li 已提交
857
	DBF_EVENT(3, "Error Recovery successful for %s\n",
S
Stefan Bader 已提交
858 859 860 861 862
		  tape_op_verbose[request->op]);
	return tape_3590_done(device, request);
}

/*
863
 * This function is called, when error recovery was not successful
S
Stefan Bader 已提交
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
 */
static inline int
tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
		     struct irb *irb, int rc)
{
	DBF_EVENT(3, "Error Recovery failed for %s\n",
		  tape_op_verbose[request->op]);
	tape_dump_sense_dbf(device, request, irb);
	return rc;
}

/*
 * Error Recovery do retry
 */
static inline int
tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
		    struct irb *irb)
{
	DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]);
	tape_dump_sense_dbf(device, request, irb);
	return TAPE_IO_RETRY;
}

/*
 * Handle unsolicited interrupts
 */
static int
tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
{
893
	if (irb->scsw.cmd.dstat == DEV_STAT_CHN_END)
S
Stefan Bader 已提交
894 895
		/* Probably result of halt ssch */
		return TAPE_IO_PENDING;
896
	else if (irb->scsw.cmd.dstat == 0x85)
897 898
		/* Device Ready */
		DBF_EVENT(3, "unsol.irq! tape ready: %08x\n", device->cdev_id);
899
	else if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
S
Stefan Bader 已提交
900
		tape_3590_schedule_work(device, TO_READ_ATTMSG);
901
	} else {
S
Stefan Bader 已提交
902
		DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
C
Carsten Otte 已提交
903
		tape_dump_sense_dbf(device, NULL, irb);
S
Stefan Bader 已提交
904
	}
905 906
	/* check medium state */
	tape_3590_schedule_work(device, TO_MSEN);
S
Stefan Bader 已提交
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
	return TAPE_IO_SUCCESS;
}

/*
 * Basic Recovery routine
 */
static int
tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
		    struct irb *irb, int rc)
{
	struct tape_3590_sense *sense;

	sense = (struct tape_3590_sense *) irb->ecw;

	switch (sense->bra) {
	case SENSE_BRA_PER:
		return tape_3590_erp_failed(device, request, irb, rc);
	case SENSE_BRA_CONT:
		return tape_3590_erp_succeded(device, request);
	case SENSE_BRA_RE:
		return tape_3590_erp_retry(device, request, irb);
	case SENSE_BRA_DRE:
		return tape_3590_erp_failed(device, request, irb, rc);
	default:
		BUG();
		return TAPE_IO_STOP;
	}
}

/*
 *  RDL: Read Device (buffered) log
 */
static int
tape_3590_erp_read_buf_log(struct tape_device *device,
			   struct tape_request *request, struct irb *irb)
{
	/*
	 * We just do the basic error recovery at the moment (retry).
	 * Perhaps in the future, we read the log and dump it somewhere...
	 */
	return tape_3590_erp_basic(device, request, irb, -EIO);
}

/*
 *  SWAP: Swap Devices
 */
static int
tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
		   struct irb *irb)
{
	/*
	 * This error recovery should swap the tapes
	 * if the original has a problem. The operation
	 * should proceed with the new tape... this
	 * should probably be done in user space!
	 */
C
Carsten Otte 已提交
963 964
	dev_warn (&device->cdev->dev, "The tape medium must be loaded into a "
		"different tape unit\n");
S
Stefan Bader 已提交
965 966 967 968 969 970 971 972 973 974
	return tape_3590_erp_basic(device, request, irb, -EIO);
}

/*
 *  LBY: Long Busy
 */
static int
tape_3590_erp_long_busy(struct tape_device *device,
			struct tape_request *request, struct irb *irb)
{
975 976
	DBF_EVENT(6, "Device is busy\n");
	return TAPE_IO_LONG_BUSY;
S
Stefan Bader 已提交
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
}

/*
 *  SPI: Special Intercept
 */
static int
tape_3590_erp_special_interrupt(struct tape_device *device,
				struct tape_request *request, struct irb *irb)
{
	return tape_3590_erp_basic(device, request, irb, -EIO);
}

/*
 *  RDA: Read Alternate
 */
static int
tape_3590_erp_read_alternate(struct tape_device *device,
			     struct tape_request *request, struct irb *irb)
{
	struct tape_3590_disc_data *data;

	/*
	 * The issued Read Backward or Read Previous command is not
	 * supported by the device
	 * The recovery action should be to issue another command:
	 * Read Revious: if Read Backward is not supported
	 * Read Backward: if Read Previous is not supported
	 */
	data = device->discdata;
	if (data->read_back_op == READ_PREVIOUS) {
		DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
			  device->cdev_id);
		data->read_back_op = READ_BACKWARD;
	} else {
		DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
			  device->cdev_id);
		data->read_back_op = READ_PREVIOUS;
	}
	tape_3590_read_opposite(device, request);
	return tape_3590_erp_retry(device, request, irb);
}

/*
 * Error Recovery read opposite
 */
static int
tape_3590_erp_read_opposite(struct tape_device *device,
			    struct tape_request *request, struct irb *irb)
{
	switch (request->op) {
	case TO_RFO:
		/*
		 * We did read forward, but the data could not be read.
		 * We will read backward and then skip forward again.
		 */
		tape_3590_read_opposite(device, request);
		return tape_3590_erp_retry(device, request, irb);
	case TO_RBA:
		/* We tried to read forward and backward, but hat no success */
		return tape_3590_erp_failed(device, request, irb, -EIO);
		break;
	default:
		return tape_3590_erp_failed(device, request, irb, -EIO);
	}
}

/*
 * Print an MIM (Media Information  Message) (message code f0)
 */
static void
tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
{
	struct tape_3590_sense *sense;
C
Carsten Otte 已提交
1050 1051 1052 1053 1054 1055 1056
	char *exception, *service;

	exception = kmalloc(BUFSIZE, GFP_ATOMIC);
	service = kmalloc(BUFSIZE, GFP_ATOMIC);

	if (!exception || !service)
		goto out_nomem;
S
Stefan Bader 已提交
1057 1058 1059 1060 1061

	sense = (struct tape_3590_sense *) irb->ecw;
	/* Exception Message */
	switch (sense->fmt.f70.emc) {
	case 0x02:
C
Carsten Otte 已提交
1062
		snprintf(exception, BUFSIZE, "Data degraded");
S
Stefan Bader 已提交
1063 1064
		break;
	case 0x03:
C
Carsten Otte 已提交
1065 1066
		snprintf(exception, BUFSIZE, "Data degraded in partion %i",
			sense->fmt.f70.mp);
S
Stefan Bader 已提交
1067 1068
		break;
	case 0x04:
C
Carsten Otte 已提交
1069
		snprintf(exception, BUFSIZE, "Medium degraded");
S
Stefan Bader 已提交
1070 1071
		break;
	case 0x05:
C
Carsten Otte 已提交
1072 1073
		snprintf(exception, BUFSIZE, "Medium degraded in partition %i",
			sense->fmt.f70.mp);
S
Stefan Bader 已提交
1074 1075
		break;
	case 0x06:
C
Carsten Otte 已提交
1076
		snprintf(exception, BUFSIZE, "Block 0 Error");
S
Stefan Bader 已提交
1077 1078
		break;
	case 0x07:
C
Carsten Otte 已提交
1079 1080
		snprintf(exception, BUFSIZE, "Medium Exception 0x%02x",
			sense->fmt.f70.md);
S
Stefan Bader 已提交
1081 1082
		break;
	default:
C
Carsten Otte 已提交
1083 1084
		snprintf(exception, BUFSIZE, "0x%02x",
			sense->fmt.f70.emc);
S
Stefan Bader 已提交
1085 1086 1087 1088 1089
		break;
	}
	/* Service Message */
	switch (sense->fmt.f70.smc) {
	case 0x02:
C
Carsten Otte 已提交
1090 1091
		snprintf(service, BUFSIZE, "Reference Media maintenance "
			"procedure %i", sense->fmt.f70.md);
S
Stefan Bader 已提交
1092 1093
		break;
	default:
C
Carsten Otte 已提交
1094 1095
		snprintf(service, BUFSIZE, "0x%02x",
			sense->fmt.f70.smc);
S
Stefan Bader 已提交
1096 1097
		break;
	}
C
Carsten Otte 已提交
1098 1099 1100 1101 1102 1103 1104

	dev_warn (&device->cdev->dev, "Tape media information: exception %s, "
		"service %s\n", exception, service);

out_nomem:
	kfree(exception);
	kfree(service);
S
Stefan Bader 已提交
1105 1106 1107 1108 1109 1110 1111 1112 1113
}

/*
 * Print an I/O Subsystem Service Information Message (message code f1)
 */
static void
tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
{
	struct tape_3590_sense *sense;
C
Carsten Otte 已提交
1114 1115 1116 1117 1118 1119 1120
	char *exception, *service;

	exception = kmalloc(BUFSIZE, GFP_ATOMIC);
	service = kmalloc(BUFSIZE, GFP_ATOMIC);

	if (!exception || !service)
		goto out_nomem;
S
Stefan Bader 已提交
1121 1122 1123 1124 1125

	sense = (struct tape_3590_sense *) irb->ecw;
	/* Exception Message */
	switch (sense->fmt.f71.emc) {
	case 0x01:
C
Carsten Otte 已提交
1126
		snprintf(exception, BUFSIZE, "Effect of failure is unknown");
S
Stefan Bader 已提交
1127 1128
		break;
	case 0x02:
C
Carsten Otte 已提交
1129 1130
		snprintf(exception, BUFSIZE, "CU Exception - no performance "
			"impact");
S
Stefan Bader 已提交
1131 1132
		break;
	case 0x03:
C
Carsten Otte 已提交
1133 1134
		snprintf(exception, BUFSIZE, "CU Exception on channel "
			"interface 0x%02x", sense->fmt.f71.md[0]);
S
Stefan Bader 已提交
1135 1136
		break;
	case 0x04:
C
Carsten Otte 已提交
1137 1138
		snprintf(exception, BUFSIZE, "CU Exception on device path "
			"0x%02x", sense->fmt.f71.md[0]);
S
Stefan Bader 已提交
1139 1140
		break;
	case 0x05:
C
Carsten Otte 已提交
1141 1142
		snprintf(exception, BUFSIZE, "CU Exception on library path "
			"0x%02x", sense->fmt.f71.md[0]);
S
Stefan Bader 已提交
1143 1144
		break;
	case 0x06:
C
Carsten Otte 已提交
1145 1146
		snprintf(exception, BUFSIZE, "CU Exception on node 0x%02x",
			sense->fmt.f71.md[0]);
S
Stefan Bader 已提交
1147 1148
		break;
	case 0x07:
C
Carsten Otte 已提交
1149 1150
		snprintf(exception, BUFSIZE, "CU Exception on partition "
			"0x%02x", sense->fmt.f71.md[0]);
S
Stefan Bader 已提交
1151 1152
		break;
	default:
C
Carsten Otte 已提交
1153 1154
		snprintf(exception, BUFSIZE, "0x%02x",
			sense->fmt.f71.emc);
S
Stefan Bader 已提交
1155 1156 1157 1158
	}
	/* Service Message */
	switch (sense->fmt.f71.smc) {
	case 0x01:
C
Carsten Otte 已提交
1159
		snprintf(service, BUFSIZE, "Repair impact is unknown");
S
Stefan Bader 已提交
1160 1161
		break;
	case 0x02:
C
Carsten Otte 已提交
1162 1163
		snprintf(service, BUFSIZE, "Repair will not impact cu "
			"performance");
S
Stefan Bader 已提交
1164 1165 1166
		break;
	case 0x03:
		if (sense->fmt.f71.mdf == 0)
C
Carsten Otte 已提交
1167 1168
			snprintf(service, BUFSIZE, "Repair will disable node "
				"0x%x on CU", sense->fmt.f71.md[1]);
S
Stefan Bader 已提交
1169
		else
C
Carsten Otte 已提交
1170 1171 1172
			snprintf(service, BUFSIZE, "Repair will disable "
				"nodes (0x%x-0x%x) on CU", sense->fmt.f71.md[1],
				sense->fmt.f71.md[2]);
S
Stefan Bader 已提交
1173 1174 1175
		break;
	case 0x04:
		if (sense->fmt.f71.mdf == 0)
C
Carsten Otte 已提交
1176 1177 1178
			snprintf(service, BUFSIZE, "Repair will disable "
				"channel path 0x%x on CU",
				sense->fmt.f71.md[1]);
S
Stefan Bader 已提交
1179
		else
C
Carsten Otte 已提交
1180 1181 1182
			snprintf(service, BUFSIZE, "Repair will disable cannel"
				" paths (0x%x-0x%x) on CU",
				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
S
Stefan Bader 已提交
1183 1184 1185
		break;
	case 0x05:
		if (sense->fmt.f71.mdf == 0)
C
Carsten Otte 已提交
1186 1187
			snprintf(service, BUFSIZE, "Repair will disable device"
				" path 0x%x on CU", sense->fmt.f71.md[1]);
S
Stefan Bader 已提交
1188
		else
C
Carsten Otte 已提交
1189 1190 1191
			snprintf(service, BUFSIZE, "Repair will disable device"
				" paths (0x%x-0x%x) on CU",
				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
S
Stefan Bader 已提交
1192 1193 1194
		break;
	case 0x06:
		if (sense->fmt.f71.mdf == 0)
C
Carsten Otte 已提交
1195 1196 1197
			snprintf(service, BUFSIZE, "Repair will disable "
				"library path 0x%x on CU",
				sense->fmt.f71.md[1]);
S
Stefan Bader 已提交
1198
		else
C
Carsten Otte 已提交
1199 1200 1201
			snprintf(service, BUFSIZE, "Repair will disable "
				"library paths (0x%x-0x%x) on CU",
				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
S
Stefan Bader 已提交
1202 1203
		break;
	case 0x07:
C
Carsten Otte 已提交
1204
		snprintf(service, BUFSIZE, "Repair will disable access to CU");
S
Stefan Bader 已提交
1205 1206
		break;
	default:
C
Carsten Otte 已提交
1207 1208
		snprintf(service, BUFSIZE, "0x%02x",
			sense->fmt.f71.smc);
S
Stefan Bader 已提交
1209
	}
C
Carsten Otte 已提交
1210 1211 1212 1213 1214 1215

	dev_warn (&device->cdev->dev, "I/O subsystem information: exception"
		" %s, service %s\n", exception, service);
out_nomem:
	kfree(exception);
	kfree(service);
S
Stefan Bader 已提交
1216 1217 1218 1219 1220 1221 1222 1223 1224
}

/*
 * Print an Device Subsystem Service Information Message (message code f2)
 */
static void
tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
{
	struct tape_3590_sense *sense;
C
Carsten Otte 已提交
1225 1226 1227 1228 1229 1230 1231
	char *exception, *service;

	exception = kmalloc(BUFSIZE, GFP_ATOMIC);
	service = kmalloc(BUFSIZE, GFP_ATOMIC);

	if (!exception || !service)
		goto out_nomem;
S
Stefan Bader 已提交
1232 1233 1234 1235 1236

	sense = (struct tape_3590_sense *) irb->ecw;
	/* Exception Message */
	switch (sense->fmt.f71.emc) {
	case 0x01:
C
Carsten Otte 已提交
1237
		snprintf(exception, BUFSIZE, "Effect of failure is unknown");
S
Stefan Bader 已提交
1238 1239
		break;
	case 0x02:
C
Carsten Otte 已提交
1240 1241
		snprintf(exception, BUFSIZE, "DV Exception - no performance"
			" impact");
S
Stefan Bader 已提交
1242 1243
		break;
	case 0x03:
C
Carsten Otte 已提交
1244 1245
		snprintf(exception, BUFSIZE, "DV Exception on channel "
			"interface 0x%02x", sense->fmt.f71.md[0]);
S
Stefan Bader 已提交
1246 1247
		break;
	case 0x04:
C
Carsten Otte 已提交
1248 1249
		snprintf(exception, BUFSIZE, "DV Exception on loader 0x%02x",
			sense->fmt.f71.md[0]);
S
Stefan Bader 已提交
1250 1251
		break;
	case 0x05:
C
Carsten Otte 已提交
1252 1253
		snprintf(exception, BUFSIZE, "DV Exception on message display"
			" 0x%02x", sense->fmt.f71.md[0]);
S
Stefan Bader 已提交
1254 1255
		break;
	case 0x06:
C
Carsten Otte 已提交
1256
		snprintf(exception, BUFSIZE, "DV Exception in tape path");
S
Stefan Bader 已提交
1257 1258
		break;
	case 0x07:
C
Carsten Otte 已提交
1259
		snprintf(exception, BUFSIZE, "DV Exception in drive");
S
Stefan Bader 已提交
1260 1261
		break;
	default:
C
Carsten Otte 已提交
1262 1263
		snprintf(exception, BUFSIZE, "0x%02x",
			sense->fmt.f71.emc);
S
Stefan Bader 已提交
1264 1265 1266 1267
	}
	/* Service Message */
	switch (sense->fmt.f71.smc) {
	case 0x01:
C
Carsten Otte 已提交
1268
		snprintf(service, BUFSIZE, "Repair impact is unknown");
S
Stefan Bader 已提交
1269 1270
		break;
	case 0x02:
C
Carsten Otte 已提交
1271 1272
		snprintf(service, BUFSIZE, "Repair will not impact device "
			"performance");
S
Stefan Bader 已提交
1273 1274 1275
		break;
	case 0x03:
		if (sense->fmt.f71.mdf == 0)
C
Carsten Otte 已提交
1276 1277 1278
			snprintf(service, BUFSIZE, "Repair will disable "
				"channel path 0x%x on DV",
				sense->fmt.f71.md[1]);
S
Stefan Bader 已提交
1279
		else
C
Carsten Otte 已提交
1280 1281 1282
			snprintf(service, BUFSIZE, "Repair will disable "
				"channel path (0x%x-0x%x) on DV",
				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
S
Stefan Bader 已提交
1283 1284 1285
		break;
	case 0x04:
		if (sense->fmt.f71.mdf == 0)
C
Carsten Otte 已提交
1286 1287
			snprintf(service, BUFSIZE, "Repair will disable "
				"interface 0x%x on DV", sense->fmt.f71.md[1]);
S
Stefan Bader 已提交
1288
		else
C
Carsten Otte 已提交
1289 1290 1291
			snprintf(service, BUFSIZE, "Repair will disable "
				"interfaces (0x%x-0x%x) on DV",
				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
S
Stefan Bader 已提交
1292 1293 1294
		break;
	case 0x05:
		if (sense->fmt.f71.mdf == 0)
C
Carsten Otte 已提交
1295 1296
			snprintf(service, BUFSIZE, "Repair will disable loader"
				" 0x%x on DV", sense->fmt.f71.md[1]);
S
Stefan Bader 已提交
1297
		else
C
Carsten Otte 已提交
1298 1299 1300
			snprintf(service, BUFSIZE, "Repair will disable loader"
				" (0x%x-0x%x) on DV",
				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
S
Stefan Bader 已提交
1301 1302
		break;
	case 0x07:
C
Carsten Otte 已提交
1303
		snprintf(service, BUFSIZE, "Repair will disable access to DV");
S
Stefan Bader 已提交
1304 1305 1306
		break;
	case 0x08:
		if (sense->fmt.f71.mdf == 0)
C
Carsten Otte 已提交
1307 1308 1309
			snprintf(service, BUFSIZE, "Repair will disable "
				"message display 0x%x on DV",
				sense->fmt.f71.md[1]);
S
Stefan Bader 已提交
1310
		else
C
Carsten Otte 已提交
1311 1312 1313
			snprintf(service, BUFSIZE, "Repair will disable "
				"message displays (0x%x-0x%x) on DV",
				 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
S
Stefan Bader 已提交
1314 1315
		break;
	case 0x09:
C
Carsten Otte 已提交
1316
		snprintf(service, BUFSIZE, "Clean DV");
S
Stefan Bader 已提交
1317 1318
		break;
	default:
C
Carsten Otte 已提交
1319 1320
		snprintf(service, BUFSIZE, "0x%02x",
			sense->fmt.f71.smc);
S
Stefan Bader 已提交
1321
	}
C
Carsten Otte 已提交
1322 1323 1324 1325 1326 1327

	dev_warn (&device->cdev->dev, "Device subsystem information: exception"
		" %s, service %s\n", exception, service);
out_nomem:
	kfree(exception);
	kfree(service);
S
Stefan Bader 已提交
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342
}

/*
 * Print standard ERA Message
 */
static void
tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
{
	struct tape_3590_sense *sense;

	sense = (struct tape_3590_sense *) irb->ecw;
	if (sense->mc == 0)
		return;
	if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) {
		if (tape_3590_msg[sense->mc] != NULL)
C
Carsten Otte 已提交
1343 1344 1345 1346 1347 1348 1349
			dev_warn (&device->cdev->dev, "The tape unit has "
				"issued sense message %s\n",
				tape_3590_msg[sense->mc]);
		else
			dev_warn (&device->cdev->dev, "The tape unit has "
				"issued an unknown sense message code 0x%x\n",
				sense->mc);
S
Stefan Bader 已提交
1350 1351 1352 1353
		return;
	}
	if (sense->mc == 0xf0) {
		/* Standard Media Information Message */
C
Carsten Otte 已提交
1354 1355 1356 1357 1358
		dev_warn (&device->cdev->dev, "MIM SEV=%i, MC=%02x, ES=%x/%x, "
			"RC=%02x-%04x-%02x\n", sense->fmt.f70.sev, sense->mc,
			sense->fmt.f70.emc, sense->fmt.f70.smc,
			sense->fmt.f70.refcode, sense->fmt.f70.mid,
			sense->fmt.f70.fid);
S
Stefan Bader 已提交
1359 1360 1361 1362 1363
		tape_3590_print_mim_msg_f0(device, irb);
		return;
	}
	if (sense->mc == 0xf1) {
		/* Standard I/O Subsystem Service Information Message */
C
Carsten Otte 已提交
1364 1365 1366 1367 1368 1369
		dev_warn (&device->cdev->dev, "IOSIM SEV=%i, DEVTYPE=3590/%02x,"
			" MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
			sense->fmt.f71.sev, device->cdev->id.dev_model,
			sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
			sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
			sense->fmt.f71.refcode3);
S
Stefan Bader 已提交
1370 1371 1372 1373 1374
		tape_3590_print_io_sim_msg_f1(device, irb);
		return;
	}
	if (sense->mc == 0xf2) {
		/* Standard Device Service Information Message */
C
Carsten Otte 已提交
1375 1376 1377 1378 1379 1380
		dev_warn (&device->cdev->dev, "DEVSIM SEV=%i, DEVTYPE=3590/%02x"
			", MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
			sense->fmt.f71.sev, device->cdev->id.dev_model,
			sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
			sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
			sense->fmt.f71.refcode3);
S
Stefan Bader 已提交
1381 1382 1383 1384 1385 1386 1387
		tape_3590_print_dev_sim_msg_f2(device, irb);
		return;
	}
	if (sense->mc == 0xf3) {
		/* Standard Library Service Information Message */
		return;
	}
C
Carsten Otte 已提交
1388 1389
	dev_warn (&device->cdev->dev, "The tape unit has issued an unknown "
		"sense message code %x\n", sense->mc);
S
Stefan Bader 已提交
1390 1391
}

1392 1393 1394
static int tape_3590_crypt_error(struct tape_device *device,
				 struct tape_request *request, struct irb *irb)
{
1395
	u8 cu_rc;
1396
	u16 ekm_rc2;
1397
	char *sense;
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408

	sense = ((struct tape_3590_sense *) irb->ecw)->fmt.data;
	cu_rc = sense[0];
	ekm_rc2 = *((u16*) &sense[10]);
	if ((cu_rc == 0) && (ekm_rc2 == 0xee31))
		/* key not defined on EKM */
		return tape_3590_erp_basic(device, request, irb, -EKEYREJECTED);
	if ((cu_rc == 1) || (cu_rc == 2))
		/* No connection to EKM */
		return tape_3590_erp_basic(device, request, irb, -ENOTCONN);

C
Carsten Otte 已提交
1409 1410
	dev_err (&device->cdev->dev, "The tape unit failed to obtain the "
		"encryption key from EKM\n");
1411 1412 1413 1414

	return tape_3590_erp_basic(device, request, irb, -ENOKEY);
}

S
Stefan Bader 已提交
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
/*
 *  3590 error Recovery routine:
 *  If possible, it tries to recover from the error. If this is not possible,
 *  inform the user about the problem.
 */
static int
tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
		     struct irb *irb)
{
	struct tape_3590_sense *sense;

#ifdef CONFIG_S390_TAPE_BLOCK
	if (request->op == TO_BLOCK) {
		/*
		 * Recovery for block device requests. Set the block_position
		 * to something invalid and retry.
		 */
		device->blk_data.block_position = -1;
		if (request->retries-- <= 0)
			return tape_3590_erp_failed(device, request, irb, -EIO);
		else
			return tape_3590_erp_retry(device, request, irb);
	}
#endif

	sense = (struct tape_3590_sense *) irb->ecw;

1442 1443
	DBF_EVENT(6, "Unit Check: RQC = %x\n", sense->rc_rqc);

S
Stefan Bader 已提交
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462
	/*
	 * First check all RC-QRCs where we want to do something special
	 *   - "break":     basic error recovery is done
	 *   - "goto out:": just print error message if available
	 */
	switch (sense->rc_rqc) {

	case 0x1110:
		tape_3590_print_era_msg(device, irb);
		return tape_3590_erp_read_buf_log(device, request, irb);

	case 0x2011:
		tape_3590_print_era_msg(device, irb);
		return tape_3590_erp_read_alternate(device, request, irb);

	case 0x2230:
	case 0x2231:
		tape_3590_print_era_msg(device, irb);
		return tape_3590_erp_special_interrupt(device, request, irb);
1463 1464
	case 0x2240:
		return tape_3590_crypt_error(device, request, irb);
S
Stefan Bader 已提交
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485

	case 0x3010:
		DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
			  device->cdev_id);
		return tape_3590_erp_basic(device, request, irb, -ENOSPC);
	case 0x3012:
		DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
			  device->cdev_id);
		return tape_3590_erp_basic(device, request, irb, -ENOSPC);
	case 0x3020:
		DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
		return tape_3590_erp_basic(device, request, irb, -ENOSPC);

	case 0x3122:
		DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
			  device->cdev_id);
		return tape_3590_erp_basic(device, request, irb, -EIO);
	case 0x3123:
		DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
			  device->cdev_id);
		tape_med_state_set(device, MS_UNLOADED);
1486
		tape_3590_schedule_work(device, TO_CRYPT_OFF);
S
Stefan Bader 已提交
1487 1488 1489 1490 1491 1492 1493 1494
		return tape_3590_erp_basic(device, request, irb, 0);

	case 0x4010:
		/*
		 * print additional msg since default msg
		 * "device intervention" is not very meaningfull
		 */
		tape_med_state_set(device, MS_UNLOADED);
1495
		tape_3590_schedule_work(device, TO_CRYPT_OFF);
S
Stefan Bader 已提交
1496 1497
		return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
	case 0x4012:		/* Device Long Busy */
1498 1499
		/* XXX: Also use long busy handling here? */
		DBF_EVENT(6, "(%08x): LONG BUSY\n", device->cdev_id);
S
Stefan Bader 已提交
1500
		tape_3590_print_era_msg(device, irb);
1501 1502 1503
		return tape_3590_erp_basic(device, request, irb, -EBUSY);
	case 0x4014:
		DBF_EVENT(6, "(%08x): Crypto LONG BUSY\n", device->cdev_id);
S
Stefan Bader 已提交
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
		return tape_3590_erp_long_busy(device, request, irb);

	case 0x5010:
		if (sense->rac == 0xd0) {
			/* Swap */
			tape_3590_print_era_msg(device, irb);
			return tape_3590_erp_swap(device, request, irb);
		}
		if (sense->rac == 0x26) {
			/* Read Opposite */
			tape_3590_print_era_msg(device, irb);
			return tape_3590_erp_read_opposite(device, request,
							   irb);
		}
		return tape_3590_erp_basic(device, request, irb, -EIO);
	case 0x5020:
	case 0x5021:
	case 0x5022:
	case 0x5040:
	case 0x5041:
	case 0x5042:
		tape_3590_print_era_msg(device, irb);
		return tape_3590_erp_swap(device, request, irb);

	case 0x5110:
	case 0x5111:
		return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);

	case 0x5120:
	case 0x1120:
		tape_med_state_set(device, MS_UNLOADED);
1535
		tape_3590_schedule_work(device, TO_CRYPT_OFF);
S
Stefan Bader 已提交
1536 1537 1538 1539 1540 1541 1542 1543
		return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);

	case 0x6020:
		return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);

	case 0x8011:
		return tape_3590_erp_basic(device, request, irb, -EPERM);
	case 0x8013:
C
Carsten Otte 已提交
1544 1545
		dev_warn (&device->cdev->dev, "A different host has privileged"
			" access to the tape unit\n");
S
Stefan Bader 已提交
1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561
		return tape_3590_erp_basic(device, request, irb, -EPERM);
	default:
		return tape_3590_erp_basic(device, request, irb, -EIO);
	}
}

/*
 * 3590 interrupt handler:
 */
static int
tape_3590_irq(struct tape_device *device, struct tape_request *request,
	      struct irb *irb)
{
	if (request == NULL)
		return tape_3590_unsolicited_irq(device, irb);

1562 1563 1564
	if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
	    (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
	    (request->op == TO_WRI)) {
S
Stefan Bader 已提交
1565 1566 1567 1568 1569
		/* Write at end of volume */
		DBF_EVENT(2, "End of volume\n");
		return tape_3590_erp_failed(device, request, irb, -ENOSPC);
	}

1570
	if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
S
Stefan Bader 已提交
1571 1572
		return tape_3590_unit_check(device, request, irb);

1573 1574
	if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
		if (irb->scsw.cmd.dstat == DEV_STAT_UNIT_EXCEP) {
S
Stefan Bader 已提交
1575 1576 1577 1578 1579 1580 1581 1582 1583
			if (request->op == TO_FSB || request->op == TO_BSB)
				request->rescnt++;
			else
				DBF_EVENT(5, "Unit Exception!\n");
		}

		return tape_3590_done(device, request);
	}

1584
	if (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) {
S
Stefan Bader 已提交
1585 1586 1587 1588
		DBF_EVENT(2, "cannel end\n");
		return TAPE_IO_PENDING;
	}

1589
	if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
S
Stefan Bader 已提交
1590 1591 1592 1593 1594
		DBF_EVENT(2, "Unit Attention when busy..\n");
		return TAPE_IO_PENDING;
	}

	DBF_EVENT(6, "xunknownirq\n");
C
Carsten Otte 已提交
1595
	tape_dump_sense_dbf(device, request, irb);
S
Stefan Bader 已提交
1596 1597 1598
	return TAPE_IO_STOP;
}

1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618

static int tape_3590_read_dev_chars(struct tape_device *device,
				    struct tape_3590_rdc_data *rdc_data)
{
	int rc;
	struct tape_request *request;

	request = tape_alloc_request(1, sizeof(*rdc_data));
	if (IS_ERR(request))
		return PTR_ERR(request);
	request->op = TO_RDC;
	tape_ccw_end(request->cpaddr, CCW_CMD_RDC, sizeof(*rdc_data),
		     request->cpdata);
	rc = tape_do_io(device, request);
	if (rc == 0)
		memcpy(rdc_data, request->cpdata, sizeof(*rdc_data));
	tape_free_request(request);
	return rc;
}

S
Stefan Bader 已提交
1619 1620 1621 1622 1623 1624 1625 1626
/*
 * Setup device function
 */
static int
tape_3590_setup_device(struct tape_device *device)
{
	int rc;
	struct tape_3590_disc_data *data;
1627
	struct tape_3590_rdc_data *rdc_data;
S
Stefan Bader 已提交
1628 1629

	DBF_EVENT(6, "3590 device setup\n");
1630
	data = kzalloc(sizeof(struct tape_3590_disc_data), GFP_KERNEL | GFP_DMA);
S
Stefan Bader 已提交
1631 1632 1633 1634 1635
	if (data == NULL)
		return -ENOMEM;
	data->read_back_op = READ_PREVIOUS;
	device->discdata = data;

1636
	rdc_data = kmalloc(sizeof(*rdc_data), GFP_KERNEL | GFP_DMA);
1637 1638 1639 1640
	if (!rdc_data) {
		rc = -ENOMEM;
		goto fail_kmalloc;
	}
1641
	rc = tape_3590_read_dev_chars(device, rdc_data);
1642 1643
	if (rc) {
		DBF_LH(3, "Read device characteristics failed!\n");
1644
		goto fail_rdc_data;
1645 1646 1647 1648
	}
	rc = tape_std_assign(device);
	if (rc)
		goto fail_rdc_data;
1649
	if (rdc_data->data[31] == 0x13) {
1650 1651 1652 1653
		data->crypt_info.capability |= TAPE390_CRYPT_SUPPORTED_MASK;
		tape_3592_disable_crypt(device);
	} else {
		DBF_EVENT(6, "Device has NO crypto support\n");
S
Stefan Bader 已提交
1654
	}
1655 1656 1657 1658 1659 1660 1661
	/* Try to find out if medium is loaded */
	rc = tape_3590_sense_medium(device);
	if (rc) {
		DBF_LH(3, "3590 medium sense returned %d\n", rc);
		goto fail_rdc_data;
	}
	return 0;
S
Stefan Bader 已提交
1662

1663 1664 1665 1666
fail_rdc_data:
	kfree(rdc_data);
fail_kmalloc:
	kfree(data);
S
Stefan Bader 已提交
1667 1668 1669 1670 1671 1672 1673 1674 1675
	return rc;
}

/*
 * Cleanup device function
 */
static void
tape_3590_cleanup_device(struct tape_device *device)
{
T
Tejun Heo 已提交
1676
	flush_workqueue(tape_3590_wq);
S
Stefan Bader 已提交
1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742
	tape_std_unassign(device);

	kfree(device->discdata);
	device->discdata = NULL;
}

/*
 * List of 3590 magnetic tape commands.
 */
static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = {
	[MTRESET]	 = tape_std_mtreset,
	[MTFSF]		 = tape_std_mtfsf,
	[MTBSF]		 = tape_std_mtbsf,
	[MTFSR]		 = tape_std_mtfsr,
	[MTBSR]		 = tape_std_mtbsr,
	[MTWEOF]	 = tape_std_mtweof,
	[MTREW]		 = tape_std_mtrew,
	[MTOFFL]	 = tape_std_mtoffl,
	[MTNOP]		 = tape_std_mtnop,
	[MTRETEN]	 = tape_std_mtreten,
	[MTBSFM]	 = tape_std_mtbsfm,
	[MTFSFM]	 = tape_std_mtfsfm,
	[MTEOM]		 = tape_std_mteom,
	[MTERASE]	 = tape_std_mterase,
	[MTRAS1]	 = NULL,
	[MTRAS2]	 = NULL,
	[MTRAS3]	 = NULL,
	[MTSETBLK]	 = tape_std_mtsetblk,
	[MTSETDENSITY]	 = NULL,
	[MTSEEK]	 = tape_3590_mtseek,
	[MTTELL]	 = tape_3590_mttell,
	[MTSETDRVBUFFER] = NULL,
	[MTFSS]		 = NULL,
	[MTBSS]		 = NULL,
	[MTWSM]		 = NULL,
	[MTLOCK]	 = NULL,
	[MTUNLOCK]	 = NULL,
	[MTLOAD]	 = tape_std_mtload,
	[MTUNLOAD]	 = tape_std_mtunload,
	[MTCOMPRESSION]	 = tape_std_mtcompression,
	[MTSETPART]	 = NULL,
	[MTMKPART]	 = NULL
};

/*
 * Tape discipline structure for 3590.
 */
static struct tape_discipline tape_discipline_3590 = {
	.owner = THIS_MODULE,
	.setup_device = tape_3590_setup_device,
	.cleanup_device = tape_3590_cleanup_device,
	.process_eov = tape_std_process_eov,
	.irq = tape_3590_irq,
	.read_block = tape_std_read_block,
	.write_block = tape_std_write_block,
#ifdef CONFIG_S390_TAPE_BLOCK
	.bread = tape_3590_bread,
	.free_bread = tape_3590_free_bread,
	.check_locate = tape_3590_check_locate,
#endif
	.ioctl_fn = tape_3590_ioctl,
	.mtop_array = tape_3590_mtop
};

static struct ccw_device_id tape_3590_ids[] = {
	{CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590},
S
Stefan Bader 已提交
1743
	{CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info = tape_3592},
S
Stefan Bader 已提交
1744 1745 1746 1747 1748 1749
	{ /* end of list */ }
};

static int
tape_3590_online(struct ccw_device *cdev)
{
1750
	return tape_generic_online(dev_get_drvdata(&cdev->dev),
S
Stefan Bader 已提交
1751 1752 1753 1754
				   &tape_discipline_3590);
}

static struct ccw_driver tape_3590_driver = {
1755 1756 1757 1758
	.driver = {
		.name = "tape_3590",
		.owner = THIS_MODULE,
	},
S
Stefan Bader 已提交
1759 1760 1761
	.ids = tape_3590_ids,
	.probe = tape_generic_probe,
	.remove = tape_generic_remove,
1762
	.set_offline = tape_generic_offline,
S
Stefan Bader 已提交
1763
	.set_online = tape_3590_online,
1764
	.freeze = tape_generic_pm_suspend,
1765
	.int_class = IOINT_TAP,
S
Stefan Bader 已提交
1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782
};

/*
 * Setup discipline structure.
 */
static int
tape_3590_init(void)
{
	int rc;

	TAPE_DBF_AREA = debug_register("tape_3590", 2, 2, 4 * sizeof(long));
	debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
#ifdef DBF_LIKE_HELL
	debug_set_level(TAPE_DBF_AREA, 6);
#endif

	DBF_EVENT(3, "3590 init\n");
T
Tejun Heo 已提交
1783 1784 1785 1786 1787

	tape_3590_wq = alloc_workqueue("tape_3590", 0, 0);
	if (!tape_3590_wq)
		return -ENOMEM;

S
Stefan Bader 已提交
1788 1789
	/* Register driver for 3590 tapes. */
	rc = ccw_driver_register(&tape_3590_driver);
T
Tejun Heo 已提交
1790 1791
	if (rc) {
		destroy_workqueue(tape_3590_wq);
S
Stefan Bader 已提交
1792
		DBF_EVENT(3, "3590 init failed\n");
T
Tejun Heo 已提交
1793
	} else
S
Stefan Bader 已提交
1794 1795 1796 1797 1798 1799 1800 1801
		DBF_EVENT(3, "3590 registered\n");
	return rc;
}

static void
tape_3590_exit(void)
{
	ccw_driver_unregister(&tape_3590_driver);
T
Tejun Heo 已提交
1802
	destroy_workqueue(tape_3590_wq);
S
Stefan Bader 已提交
1803 1804 1805 1806 1807 1808 1809 1810 1811 1812
	debug_unregister(TAPE_DBF_AREA);
}

MODULE_DEVICE_TABLE(ccw, tape_3590_ids);
MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
MODULE_LICENSE("GPL");

module_init(tape_3590_init);
module_exit(tape_3590_exit);