xref: /openbmc/linux/drivers/s390/char/tape_3590.c (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
16f05e69eSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2b6cba4eeSStefan Bader /*
3b6cba4eeSStefan Bader  *    tape device discipline for 3590 tapes.
4b6cba4eeSStefan Bader  *
53ef32e62SFrank Munzert  *    Copyright IBM Corp. 2001, 2009
6b6cba4eeSStefan Bader  *    Author(s): Stefan Bader <shbader@de.ibm.com>
7b6cba4eeSStefan Bader  *		 Michael Holzheu <holzheu@de.ibm.com>
8b6cba4eeSStefan Bader  *		 Martin Schwidefsky <schwidefsky@de.ibm.com>
9b6cba4eeSStefan Bader  */
10b6cba4eeSStefan Bader 
1159e36927SMichael Holzheu #define KMSG_COMPONENT "tape_3590"
12bb509912SMichael Holzheu #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13ab640db0SCarsten Otte 
14b6cba4eeSStefan Bader #include <linux/module.h>
155a0e3ad6STejun Heo #include <linux/slab.h>
16b6cba4eeSStefan Bader #include <linux/init.h>
17b6cba4eeSStefan Bader #include <linux/bio.h>
18cced1dd4SMichael Holzheu #include <asm/ebcdic.h>
19b6cba4eeSStefan Bader 
20b6cba4eeSStefan Bader #define TAPE_DBF_AREA	tape_3590_dbf
21ab640db0SCarsten Otte #define BUFSIZE 512	/* size of buffers for dynamic generated messages */
22b6cba4eeSStefan Bader 
23b6cba4eeSStefan Bader #include "tape.h"
24b6cba4eeSStefan Bader #include "tape_std.h"
25b6cba4eeSStefan Bader #include "tape_3590.h"
26b6cba4eeSStefan Bader 
276dca467aSTejun Heo static struct workqueue_struct *tape_3590_wq;
286dca467aSTejun Heo 
29b6cba4eeSStefan Bader /*
30b6cba4eeSStefan Bader  * Pointer to debug area.
31b6cba4eeSStefan Bader  */
32b6cba4eeSStefan Bader debug_info_t *TAPE_DBF_AREA = NULL;
33b6cba4eeSStefan Bader EXPORT_SYMBOL(TAPE_DBF_AREA);
34b6cba4eeSStefan Bader 
35b6cba4eeSStefan Bader /*******************************************************************
36eef35c2dSStefan Weil  * Error Recovery functions:
37b6cba4eeSStefan Bader  * - Read Opposite:		 implemented
38b6cba4eeSStefan Bader  * - Read Device (buffered) log: BRA
39b6cba4eeSStefan Bader  * - Read Library log:		 BRA
40b6cba4eeSStefan Bader  * - Swap Devices:		 BRA
41cced1dd4SMichael Holzheu  * - Long Busy:			 implemented
42b6cba4eeSStefan Bader  * - Special Intercept:		 BRA
43b6cba4eeSStefan Bader  * - Read Alternate:		 implemented
44b6cba4eeSStefan Bader  *******************************************************************/
45b6cba4eeSStefan Bader 
46b6cba4eeSStefan Bader static const char *tape_3590_msg[TAPE_3590_MAX_MSG] = {
47b6cba4eeSStefan Bader 	[0x00] = "",
48b6cba4eeSStefan Bader 	[0x10] = "Lost Sense",
49b6cba4eeSStefan Bader 	[0x11] = "Assigned Elsewhere",
50b6cba4eeSStefan Bader 	[0x12] = "Allegiance Reset",
51b6cba4eeSStefan Bader 	[0x13] = "Shared Access Violation",
52b6cba4eeSStefan Bader 	[0x20] = "Command Reject",
53b6cba4eeSStefan Bader 	[0x21] = "Configuration Error",
54b6cba4eeSStefan Bader 	[0x22] = "Protection Exception",
55b6cba4eeSStefan Bader 	[0x23] = "Write Protect",
56b6cba4eeSStefan Bader 	[0x24] = "Write Length",
57b6cba4eeSStefan Bader 	[0x25] = "Read-Only Format",
58b6cba4eeSStefan Bader 	[0x31] = "Beginning of Partition",
59b6cba4eeSStefan Bader 	[0x33] = "End of Partition",
60b6cba4eeSStefan Bader 	[0x34] = "End of Data",
61b6cba4eeSStefan Bader 	[0x35] = "Block not found",
62b6cba4eeSStefan Bader 	[0x40] = "Device Intervention",
63b6cba4eeSStefan Bader 	[0x41] = "Loader Intervention",
64b6cba4eeSStefan Bader 	[0x42] = "Library Intervention",
65b6cba4eeSStefan Bader 	[0x50] = "Write Error",
66b6cba4eeSStefan Bader 	[0x51] = "Erase Error",
67b6cba4eeSStefan Bader 	[0x52] = "Formatting Error",
68b6cba4eeSStefan Bader 	[0x53] = "Read Error",
69b6cba4eeSStefan Bader 	[0x54] = "Unsupported Format",
70b6cba4eeSStefan Bader 	[0x55] = "No Formatting",
71b6cba4eeSStefan Bader 	[0x56] = "Positioning lost",
72b6cba4eeSStefan Bader 	[0x57] = "Read Length",
73b6cba4eeSStefan Bader 	[0x60] = "Unsupported Medium",
74b6cba4eeSStefan Bader 	[0x61] = "Medium Length Error",
75b6cba4eeSStefan Bader 	[0x62] = "Medium removed",
76b6cba4eeSStefan Bader 	[0x64] = "Load Check",
77b6cba4eeSStefan Bader 	[0x65] = "Unload Check",
78b6cba4eeSStefan Bader 	[0x70] = "Equipment Check",
79b6cba4eeSStefan Bader 	[0x71] = "Bus out Check",
80b6cba4eeSStefan Bader 	[0x72] = "Protocol Error",
81b6cba4eeSStefan Bader 	[0x73] = "Interface Error",
82b6cba4eeSStefan Bader 	[0x74] = "Overrun",
83b6cba4eeSStefan Bader 	[0x75] = "Halt Signal",
84b6cba4eeSStefan Bader 	[0x90] = "Device fenced",
85b6cba4eeSStefan Bader 	[0x91] = "Device Path fenced",
86b6cba4eeSStefan Bader 	[0xa0] = "Volume misplaced",
87b6cba4eeSStefan Bader 	[0xa1] = "Volume inaccessible",
88b6cba4eeSStefan Bader 	[0xa2] = "Volume in input",
89b6cba4eeSStefan Bader 	[0xa3] = "Volume ejected",
90b6cba4eeSStefan Bader 	[0xa4] = "All categories reserved",
91b6cba4eeSStefan Bader 	[0xa5] = "Duplicate Volume",
92b6cba4eeSStefan Bader 	[0xa6] = "Library Manager Offline",
93b6cba4eeSStefan Bader 	[0xa7] = "Library Output Station full",
94b6cba4eeSStefan Bader 	[0xa8] = "Vision System non-operational",
95b6cba4eeSStefan Bader 	[0xa9] = "Library Manager Equipment Check",
96b6cba4eeSStefan Bader 	[0xaa] = "Library Equipment Check",
97b6cba4eeSStefan Bader 	[0xab] = "All Library Cells full",
98b6cba4eeSStefan Bader 	[0xac] = "No Cleaner Volumes in Library",
99b6cba4eeSStefan Bader 	[0xad] = "I/O Station door open",
100b6cba4eeSStefan Bader 	[0xae] = "Subsystem environmental alert",
101b6cba4eeSStefan Bader };
102b6cba4eeSStefan Bader 
crypt_supported(struct tape_device * device)103cced1dd4SMichael Holzheu static int crypt_supported(struct tape_device *device)
104cced1dd4SMichael Holzheu {
105cced1dd4SMichael Holzheu 	return TAPE390_CRYPT_SUPPORTED(TAPE_3590_CRYPT_INFO(device));
106cced1dd4SMichael Holzheu }
107cced1dd4SMichael Holzheu 
crypt_enabled(struct tape_device * device)108cced1dd4SMichael Holzheu static int crypt_enabled(struct tape_device *device)
109cced1dd4SMichael Holzheu {
110cced1dd4SMichael Holzheu 	return TAPE390_CRYPT_ON(TAPE_3590_CRYPT_INFO(device));
111cced1dd4SMichael Holzheu }
112cced1dd4SMichael Holzheu 
ext_to_int_kekl(struct tape390_kekl * in,struct tape3592_kekl * out)113cced1dd4SMichael Holzheu static void ext_to_int_kekl(struct tape390_kekl *in,
114cced1dd4SMichael Holzheu 			    struct tape3592_kekl *out)
115cced1dd4SMichael Holzheu {
116276d6050SVasily Gorbik 	int len;
117cced1dd4SMichael Holzheu 
118cced1dd4SMichael Holzheu 	memset(out, 0, sizeof(*out));
119cced1dd4SMichael Holzheu 	if (in->type == TAPE390_KEKL_TYPE_HASH)
120cced1dd4SMichael Holzheu 		out->flags |= 0x40;
121cced1dd4SMichael Holzheu 	if (in->type_on_tape == TAPE390_KEKL_TYPE_HASH)
122cced1dd4SMichael Holzheu 		out->flags |= 0x80;
123276d6050SVasily Gorbik 	len = min(sizeof(out->label), strlen(in->label));
124276d6050SVasily Gorbik 	memcpy(out->label, in->label, len);
125276d6050SVasily Gorbik 	memset(out->label + len, ' ', sizeof(out->label) - len);
126cced1dd4SMichael Holzheu 	ASCEBC(out->label, sizeof(out->label));
127cced1dd4SMichael Holzheu }
128cced1dd4SMichael Holzheu 
int_to_ext_kekl(struct tape3592_kekl * in,struct tape390_kekl * out)129cced1dd4SMichael Holzheu static void int_to_ext_kekl(struct tape3592_kekl *in,
130cced1dd4SMichael Holzheu 			    struct tape390_kekl *out)
131cced1dd4SMichael Holzheu {
132cced1dd4SMichael Holzheu 	memset(out, 0, sizeof(*out));
133cced1dd4SMichael Holzheu 	if(in->flags & 0x40)
134cced1dd4SMichael Holzheu 		out->type = TAPE390_KEKL_TYPE_HASH;
135cced1dd4SMichael Holzheu 	else
136cced1dd4SMichael Holzheu 		out->type = TAPE390_KEKL_TYPE_LABEL;
137cced1dd4SMichael Holzheu 	if(in->flags & 0x80)
138cced1dd4SMichael Holzheu 		out->type_on_tape = TAPE390_KEKL_TYPE_HASH;
139cced1dd4SMichael Holzheu 	else
140cced1dd4SMichael Holzheu 		out->type_on_tape = TAPE390_KEKL_TYPE_LABEL;
141cced1dd4SMichael Holzheu 	memcpy(out->label, in->label, sizeof(in->label));
142cced1dd4SMichael Holzheu 	EBCASC(out->label, sizeof(in->label));
1431d802e24SHeiko Carstens 	strim(out->label);
144cced1dd4SMichael Holzheu }
145cced1dd4SMichael Holzheu 
int_to_ext_kekl_pair(struct tape3592_kekl_pair * in,struct tape390_kekl_pair * out)146cced1dd4SMichael Holzheu static void int_to_ext_kekl_pair(struct tape3592_kekl_pair *in,
147cced1dd4SMichael Holzheu 				 struct tape390_kekl_pair *out)
148cced1dd4SMichael Holzheu {
149cced1dd4SMichael Holzheu 	if (in->count == 0) {
150cced1dd4SMichael Holzheu 		out->kekl[0].type = TAPE390_KEKL_TYPE_NONE;
151cced1dd4SMichael Holzheu 		out->kekl[0].type_on_tape = TAPE390_KEKL_TYPE_NONE;
152cced1dd4SMichael Holzheu 		out->kekl[1].type = TAPE390_KEKL_TYPE_NONE;
153cced1dd4SMichael Holzheu 		out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE;
154cced1dd4SMichael Holzheu 	} else if (in->count == 1) {
155cced1dd4SMichael Holzheu 		int_to_ext_kekl(&in->kekl[0], &out->kekl[0]);
156cced1dd4SMichael Holzheu 		out->kekl[1].type = TAPE390_KEKL_TYPE_NONE;
157cced1dd4SMichael Holzheu 		out->kekl[1].type_on_tape = TAPE390_KEKL_TYPE_NONE;
158cced1dd4SMichael Holzheu 	} else if (in->count == 2) {
159cced1dd4SMichael Holzheu 		int_to_ext_kekl(&in->kekl[0], &out->kekl[0]);
160cced1dd4SMichael Holzheu 		int_to_ext_kekl(&in->kekl[1], &out->kekl[1]);
161cced1dd4SMichael Holzheu 	} else {
162cced1dd4SMichael Holzheu 		printk("Invalid KEKL number: %d\n", in->count);
163cced1dd4SMichael Holzheu 		BUG();
164cced1dd4SMichael Holzheu 	}
165cced1dd4SMichael Holzheu }
166cced1dd4SMichael Holzheu 
check_ext_kekl(struct tape390_kekl * kekl)167cced1dd4SMichael Holzheu static int check_ext_kekl(struct tape390_kekl *kekl)
168cced1dd4SMichael Holzheu {
169cced1dd4SMichael Holzheu 	if (kekl->type == TAPE390_KEKL_TYPE_NONE)
170cced1dd4SMichael Holzheu 		goto invalid;
171cced1dd4SMichael Holzheu 	if (kekl->type > TAPE390_KEKL_TYPE_HASH)
172cced1dd4SMichael Holzheu 		goto invalid;
173cced1dd4SMichael Holzheu 	if (kekl->type_on_tape == TAPE390_KEKL_TYPE_NONE)
174cced1dd4SMichael Holzheu 		goto invalid;
175cced1dd4SMichael Holzheu 	if (kekl->type_on_tape > TAPE390_KEKL_TYPE_HASH)
176cced1dd4SMichael Holzheu 		goto invalid;
177cced1dd4SMichael Holzheu 	if ((kekl->type == TAPE390_KEKL_TYPE_HASH) &&
178cced1dd4SMichael Holzheu 	    (kekl->type_on_tape == TAPE390_KEKL_TYPE_LABEL))
179cced1dd4SMichael Holzheu 		goto invalid;
180cced1dd4SMichael Holzheu 
181cced1dd4SMichael Holzheu 	return 0;
182cced1dd4SMichael Holzheu invalid:
183cced1dd4SMichael Holzheu 	return -EINVAL;
184cced1dd4SMichael Holzheu }
185cced1dd4SMichael Holzheu 
check_ext_kekl_pair(struct tape390_kekl_pair * kekls)186cced1dd4SMichael Holzheu static int check_ext_kekl_pair(struct tape390_kekl_pair *kekls)
187cced1dd4SMichael Holzheu {
188cced1dd4SMichael Holzheu 	if (check_ext_kekl(&kekls->kekl[0]))
189cced1dd4SMichael Holzheu 		goto invalid;
190cced1dd4SMichael Holzheu 	if (check_ext_kekl(&kekls->kekl[1]))
191cced1dd4SMichael Holzheu 		goto invalid;
192cced1dd4SMichael Holzheu 
193cced1dd4SMichael Holzheu 	return 0;
194cced1dd4SMichael Holzheu invalid:
195cced1dd4SMichael Holzheu 	return -EINVAL;
196cced1dd4SMichael Holzheu }
197cced1dd4SMichael Holzheu 
198cced1dd4SMichael Holzheu /*
199cced1dd4SMichael Holzheu  * Query KEKLs
200cced1dd4SMichael Holzheu  */
tape_3592_kekl_query(struct tape_device * device,struct tape390_kekl_pair * ext_kekls)201cced1dd4SMichael Holzheu static int tape_3592_kekl_query(struct tape_device *device,
202cced1dd4SMichael Holzheu 				struct tape390_kekl_pair *ext_kekls)
203cced1dd4SMichael Holzheu {
204cced1dd4SMichael Holzheu 	struct tape_request *request;
205cced1dd4SMichael Holzheu 	struct tape3592_kekl_query_order *order;
206cced1dd4SMichael Holzheu 	struct tape3592_kekl_query_data *int_kekls;
207cced1dd4SMichael Holzheu 	int rc;
208cced1dd4SMichael Holzheu 
209cced1dd4SMichael Holzheu 	DBF_EVENT(6, "tape3592_kekl_query\n");
210cced1dd4SMichael Holzheu 	int_kekls = kmalloc(sizeof(*int_kekls), GFP_KERNEL|GFP_DMA);
211cced1dd4SMichael Holzheu 	if (!int_kekls)
212cced1dd4SMichael Holzheu 		return -ENOMEM;
213cced1dd4SMichael Holzheu 	request = tape_alloc_request(2, sizeof(*order));
214cced1dd4SMichael Holzheu 	if (IS_ERR(request)) {
215cced1dd4SMichael Holzheu 		rc = PTR_ERR(request);
216cced1dd4SMichael Holzheu 		goto fail_malloc;
217cced1dd4SMichael Holzheu 	}
218cced1dd4SMichael Holzheu 	order = request->cpdata;
219cced1dd4SMichael Holzheu 	memset(order,0,sizeof(*order));
220cced1dd4SMichael Holzheu 	order->code = 0xe2;
221cced1dd4SMichael Holzheu 	order->max_count = 2;
222cced1dd4SMichael Holzheu 	request->op = TO_KEKL_QUERY;
223cced1dd4SMichael Holzheu 	tape_ccw_cc(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order);
224cced1dd4SMichael Holzheu 	tape_ccw_end(request->cpaddr + 1, READ_SS_DATA, sizeof(*int_kekls),
225cced1dd4SMichael Holzheu 		     int_kekls);
226cced1dd4SMichael Holzheu 	rc = tape_do_io(device, request);
227cced1dd4SMichael Holzheu 	if (rc)
228cced1dd4SMichael Holzheu 		goto fail_request;
229cced1dd4SMichael Holzheu 	int_to_ext_kekl_pair(&int_kekls->kekls, ext_kekls);
230cced1dd4SMichael Holzheu 
231cced1dd4SMichael Holzheu 	rc = 0;
232cced1dd4SMichael Holzheu fail_request:
233cced1dd4SMichael Holzheu 	tape_free_request(request);
234cced1dd4SMichael Holzheu fail_malloc:
235cced1dd4SMichael Holzheu 	kfree(int_kekls);
236cced1dd4SMichael Holzheu 	return rc;
237cced1dd4SMichael Holzheu }
238cced1dd4SMichael Holzheu 
239cced1dd4SMichael Holzheu /*
240cced1dd4SMichael Holzheu  * IOCTL: Query KEKLs
241cced1dd4SMichael Holzheu  */
tape_3592_ioctl_kekl_query(struct tape_device * device,unsigned long arg)242cced1dd4SMichael Holzheu static int tape_3592_ioctl_kekl_query(struct tape_device *device,
243cced1dd4SMichael Holzheu 				      unsigned long arg)
244cced1dd4SMichael Holzheu {
245cced1dd4SMichael Holzheu 	int rc;
246cced1dd4SMichael Holzheu 	struct tape390_kekl_pair *ext_kekls;
247cced1dd4SMichael Holzheu 
248cced1dd4SMichael Holzheu 	DBF_EVENT(6, "tape_3592_ioctl_kekl_query\n");
249cced1dd4SMichael Holzheu 	if (!crypt_supported(device))
250cced1dd4SMichael Holzheu 		return -ENOSYS;
251cced1dd4SMichael Holzheu 	if (!crypt_enabled(device))
252cced1dd4SMichael Holzheu 		return -EUNATCH;
253cced1dd4SMichael Holzheu 	ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
254cced1dd4SMichael Holzheu 	if (!ext_kekls)
255cced1dd4SMichael Holzheu 		return -ENOMEM;
256cced1dd4SMichael Holzheu 	rc = tape_3592_kekl_query(device, ext_kekls);
257cced1dd4SMichael Holzheu 	if (rc != 0)
258cced1dd4SMichael Holzheu 		goto fail;
259cced1dd4SMichael Holzheu 	if (copy_to_user((char __user *) arg, ext_kekls, sizeof(*ext_kekls))) {
260cced1dd4SMichael Holzheu 		rc = -EFAULT;
261cced1dd4SMichael Holzheu 		goto fail;
262cced1dd4SMichael Holzheu 	}
263cced1dd4SMichael Holzheu 	rc = 0;
264cced1dd4SMichael Holzheu fail:
265cced1dd4SMichael Holzheu 	kfree(ext_kekls);
266cced1dd4SMichael Holzheu 	return rc;
267cced1dd4SMichael Holzheu }
268cced1dd4SMichael Holzheu 
269cced1dd4SMichael Holzheu static int tape_3590_mttell(struct tape_device *device, int mt_count);
270cced1dd4SMichael Holzheu 
271cced1dd4SMichael Holzheu /*
272cced1dd4SMichael Holzheu  * Set KEKLs
273cced1dd4SMichael Holzheu  */
tape_3592_kekl_set(struct tape_device * device,struct tape390_kekl_pair * ext_kekls)274cced1dd4SMichael Holzheu static int tape_3592_kekl_set(struct tape_device *device,
275cced1dd4SMichael Holzheu 			      struct tape390_kekl_pair *ext_kekls)
276cced1dd4SMichael Holzheu {
277cced1dd4SMichael Holzheu 	struct tape_request *request;
278cced1dd4SMichael Holzheu 	struct tape3592_kekl_set_order *order;
279cced1dd4SMichael Holzheu 
280cced1dd4SMichael Holzheu 	DBF_EVENT(6, "tape3592_kekl_set\n");
281cced1dd4SMichael Holzheu 	if (check_ext_kekl_pair(ext_kekls)) {
282cced1dd4SMichael Holzheu 		DBF_EVENT(6, "invalid kekls\n");
283cced1dd4SMichael Holzheu 		return -EINVAL;
284cced1dd4SMichael Holzheu 	}
285cced1dd4SMichael Holzheu 	if (tape_3590_mttell(device, 0) != 0)
286cced1dd4SMichael Holzheu 		return -EBADSLT;
287cced1dd4SMichael Holzheu 	request = tape_alloc_request(1, sizeof(*order));
288cced1dd4SMichael Holzheu 	if (IS_ERR(request))
289cced1dd4SMichael Holzheu 		return PTR_ERR(request);
290cced1dd4SMichael Holzheu 	order = request->cpdata;
291cced1dd4SMichael Holzheu 	memset(order, 0, sizeof(*order));
292cced1dd4SMichael Holzheu 	order->code = 0xe3;
293cced1dd4SMichael Holzheu 	order->kekls.count = 2;
294cced1dd4SMichael Holzheu 	ext_to_int_kekl(&ext_kekls->kekl[0], &order->kekls.kekl[0]);
295cced1dd4SMichael Holzheu 	ext_to_int_kekl(&ext_kekls->kekl[1], &order->kekls.kekl[1]);
296cced1dd4SMichael Holzheu 	request->op = TO_KEKL_SET;
297cced1dd4SMichael Holzheu 	tape_ccw_end(request->cpaddr, PERF_SUBSYS_FUNC, sizeof(*order), order);
298cced1dd4SMichael Holzheu 
299cced1dd4SMichael Holzheu 	return tape_do_io_free(device, request);
300cced1dd4SMichael Holzheu }
301cced1dd4SMichael Holzheu 
302cced1dd4SMichael Holzheu /*
303cced1dd4SMichael Holzheu  * IOCTL: Set KEKLs
304cced1dd4SMichael Holzheu  */
tape_3592_ioctl_kekl_set(struct tape_device * device,unsigned long arg)305cced1dd4SMichael Holzheu static int tape_3592_ioctl_kekl_set(struct tape_device *device,
306cced1dd4SMichael Holzheu 				    unsigned long arg)
307cced1dd4SMichael Holzheu {
308cced1dd4SMichael Holzheu 	int rc;
309cced1dd4SMichael Holzheu 	struct tape390_kekl_pair *ext_kekls;
310cced1dd4SMichael Holzheu 
311cced1dd4SMichael Holzheu 	DBF_EVENT(6, "tape_3592_ioctl_kekl_set\n");
312cced1dd4SMichael Holzheu 	if (!crypt_supported(device))
313cced1dd4SMichael Holzheu 		return -ENOSYS;
314cced1dd4SMichael Holzheu 	if (!crypt_enabled(device))
315cced1dd4SMichael Holzheu 		return -EUNATCH;
3162ccb5bf0SMarkus Elfring 	ext_kekls = memdup_user((char __user *)arg, sizeof(*ext_kekls));
3172ccb5bf0SMarkus Elfring 	if (IS_ERR(ext_kekls))
3182ccb5bf0SMarkus Elfring 		return PTR_ERR(ext_kekls);
319cced1dd4SMichael Holzheu 	rc = tape_3592_kekl_set(device, ext_kekls);
320cced1dd4SMichael Holzheu 	kfree(ext_kekls);
321cced1dd4SMichael Holzheu 	return rc;
322cced1dd4SMichael Holzheu }
323cced1dd4SMichael Holzheu 
324cced1dd4SMichael Holzheu /*
325cced1dd4SMichael Holzheu  * Enable encryption
326cced1dd4SMichael Holzheu  */
__tape_3592_enable_crypt(struct tape_device * device)3270c2bd9b2SMartin Schwidefsky static struct tape_request *__tape_3592_enable_crypt(struct tape_device *device)
328cced1dd4SMichael Holzheu {
329cced1dd4SMichael Holzheu 	struct tape_request *request;
330cced1dd4SMichael Holzheu 	char *data;
331cced1dd4SMichael Holzheu 
332cced1dd4SMichael Holzheu 	DBF_EVENT(6, "tape_3592_enable_crypt\n");
333cced1dd4SMichael Holzheu 	if (!crypt_supported(device))
3340c2bd9b2SMartin Schwidefsky 		return ERR_PTR(-ENOSYS);
335cced1dd4SMichael Holzheu 	request = tape_alloc_request(2, 72);
336cced1dd4SMichael Holzheu 	if (IS_ERR(request))
3370c2bd9b2SMartin Schwidefsky 		return request;
338cced1dd4SMichael Holzheu 	data = request->cpdata;
339cced1dd4SMichael Holzheu 	memset(data,0,72);
340cced1dd4SMichael Holzheu 
341cced1dd4SMichael Holzheu 	data[0]       = 0x05;
342cced1dd4SMichael Holzheu 	data[36 + 0]  = 0x03;
343cced1dd4SMichael Holzheu 	data[36 + 1]  = 0x03;
344cced1dd4SMichael Holzheu 	data[36 + 4]  = 0x40;
345cced1dd4SMichael Holzheu 	data[36 + 6]  = 0x01;
346cced1dd4SMichael Holzheu 	data[36 + 14] = 0x2f;
347cced1dd4SMichael Holzheu 	data[36 + 18] = 0xc3;
348cced1dd4SMichael Holzheu 	data[36 + 35] = 0x72;
349cced1dd4SMichael Holzheu 	request->op = TO_CRYPT_ON;
350cced1dd4SMichael Holzheu 	tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
351cced1dd4SMichael Holzheu 	tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
3520c2bd9b2SMartin Schwidefsky 	return request;
3530c2bd9b2SMartin Schwidefsky }
3540c2bd9b2SMartin Schwidefsky 
tape_3592_enable_crypt(struct tape_device * device)3550c2bd9b2SMartin Schwidefsky static int tape_3592_enable_crypt(struct tape_device *device)
3560c2bd9b2SMartin Schwidefsky {
3570c2bd9b2SMartin Schwidefsky 	struct tape_request *request;
3580c2bd9b2SMartin Schwidefsky 
3590c2bd9b2SMartin Schwidefsky 	request = __tape_3592_enable_crypt(device);
3600c2bd9b2SMartin Schwidefsky 	if (IS_ERR(request))
3610c2bd9b2SMartin Schwidefsky 		return PTR_ERR(request);
362cced1dd4SMichael Holzheu 	return tape_do_io_free(device, request);
363cced1dd4SMichael Holzheu }
364cced1dd4SMichael Holzheu 
tape_3592_enable_crypt_async(struct tape_device * device)3650c2bd9b2SMartin Schwidefsky static void tape_3592_enable_crypt_async(struct tape_device *device)
3660c2bd9b2SMartin Schwidefsky {
3670c2bd9b2SMartin Schwidefsky 	struct tape_request *request;
3680c2bd9b2SMartin Schwidefsky 
3690c2bd9b2SMartin Schwidefsky 	request = __tape_3592_enable_crypt(device);
3700c2bd9b2SMartin Schwidefsky 	if (!IS_ERR(request))
3710c2bd9b2SMartin Schwidefsky 		tape_do_io_async_free(device, request);
3720c2bd9b2SMartin Schwidefsky }
3730c2bd9b2SMartin Schwidefsky 
374cced1dd4SMichael Holzheu /*
375cced1dd4SMichael Holzheu  * Disable encryption
376cced1dd4SMichael Holzheu  */
__tape_3592_disable_crypt(struct tape_device * device)3770c2bd9b2SMartin Schwidefsky static struct tape_request *__tape_3592_disable_crypt(struct tape_device *device)
378cced1dd4SMichael Holzheu {
379cced1dd4SMichael Holzheu 	struct tape_request *request;
380cced1dd4SMichael Holzheu 	char *data;
381cced1dd4SMichael Holzheu 
382cced1dd4SMichael Holzheu 	DBF_EVENT(6, "tape_3592_disable_crypt\n");
383cced1dd4SMichael Holzheu 	if (!crypt_supported(device))
3840c2bd9b2SMartin Schwidefsky 		return ERR_PTR(-ENOSYS);
385cced1dd4SMichael Holzheu 	request = tape_alloc_request(2, 72);
386cced1dd4SMichael Holzheu 	if (IS_ERR(request))
3870c2bd9b2SMartin Schwidefsky 		return request;
388cced1dd4SMichael Holzheu 	data = request->cpdata;
389cced1dd4SMichael Holzheu 	memset(data,0,72);
390cced1dd4SMichael Holzheu 
391cced1dd4SMichael Holzheu 	data[0]       = 0x05;
392cced1dd4SMichael Holzheu 	data[36 + 0]  = 0x03;
393cced1dd4SMichael Holzheu 	data[36 + 1]  = 0x03;
394cced1dd4SMichael Holzheu 	data[36 + 35] = 0x32;
395cced1dd4SMichael Holzheu 
396cced1dd4SMichael Holzheu 	request->op = TO_CRYPT_OFF;
397cced1dd4SMichael Holzheu 	tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
398cced1dd4SMichael Holzheu 	tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
399cced1dd4SMichael Holzheu 
4000c2bd9b2SMartin Schwidefsky 	return request;
4010c2bd9b2SMartin Schwidefsky }
4020c2bd9b2SMartin Schwidefsky 
tape_3592_disable_crypt(struct tape_device * device)4030c2bd9b2SMartin Schwidefsky static int tape_3592_disable_crypt(struct tape_device *device)
4040c2bd9b2SMartin Schwidefsky {
4050c2bd9b2SMartin Schwidefsky 	struct tape_request *request;
4060c2bd9b2SMartin Schwidefsky 
4070c2bd9b2SMartin Schwidefsky 	request = __tape_3592_disable_crypt(device);
4080c2bd9b2SMartin Schwidefsky 	if (IS_ERR(request))
4090c2bd9b2SMartin Schwidefsky 		return PTR_ERR(request);
410cced1dd4SMichael Holzheu 	return tape_do_io_free(device, request);
411cced1dd4SMichael Holzheu }
412cced1dd4SMichael Holzheu 
tape_3592_disable_crypt_async(struct tape_device * device)4130c2bd9b2SMartin Schwidefsky static void tape_3592_disable_crypt_async(struct tape_device *device)
4140c2bd9b2SMartin Schwidefsky {
4150c2bd9b2SMartin Schwidefsky 	struct tape_request *request;
4160c2bd9b2SMartin Schwidefsky 
4170c2bd9b2SMartin Schwidefsky 	request = __tape_3592_disable_crypt(device);
4180c2bd9b2SMartin Schwidefsky 	if (!IS_ERR(request))
4190c2bd9b2SMartin Schwidefsky 		tape_do_io_async_free(device, request);
4200c2bd9b2SMartin Schwidefsky }
4210c2bd9b2SMartin Schwidefsky 
422cced1dd4SMichael Holzheu /*
423cced1dd4SMichael Holzheu  * IOCTL: Set encryption status
424cced1dd4SMichael Holzheu  */
tape_3592_ioctl_crypt_set(struct tape_device * device,unsigned long arg)425cced1dd4SMichael Holzheu static int tape_3592_ioctl_crypt_set(struct tape_device *device,
426cced1dd4SMichael Holzheu 				     unsigned long arg)
427cced1dd4SMichael Holzheu {
428cced1dd4SMichael Holzheu 	struct tape390_crypt_info info;
429cced1dd4SMichael Holzheu 
430cced1dd4SMichael Holzheu 	DBF_EVENT(6, "tape_3592_ioctl_crypt_set\n");
431cced1dd4SMichael Holzheu 	if (!crypt_supported(device))
432cced1dd4SMichael Holzheu 		return -ENOSYS;
433cced1dd4SMichael Holzheu 	if (copy_from_user(&info, (char __user *)arg, sizeof(info)))
434cced1dd4SMichael Holzheu 		return -EFAULT;
435cced1dd4SMichael Holzheu 	if (info.status & ~TAPE390_CRYPT_ON_MASK)
436cced1dd4SMichael Holzheu 		return -EINVAL;
437cced1dd4SMichael Holzheu 	if (info.status & TAPE390_CRYPT_ON_MASK)
438cced1dd4SMichael Holzheu 		return tape_3592_enable_crypt(device);
439cced1dd4SMichael Holzheu 	else
440cced1dd4SMichael Holzheu 		return tape_3592_disable_crypt(device);
441cced1dd4SMichael Holzheu }
442cced1dd4SMichael Holzheu 
443cced1dd4SMichael Holzheu static int tape_3590_sense_medium(struct tape_device *device);
444cced1dd4SMichael Holzheu 
445cced1dd4SMichael Holzheu /*
446cced1dd4SMichael Holzheu  * IOCTL: Query enryption status
447cced1dd4SMichael Holzheu  */
tape_3592_ioctl_crypt_query(struct tape_device * device,unsigned long arg)448cced1dd4SMichael Holzheu static int tape_3592_ioctl_crypt_query(struct tape_device *device,
449cced1dd4SMichael Holzheu 				       unsigned long arg)
450cced1dd4SMichael Holzheu {
451cced1dd4SMichael Holzheu 	DBF_EVENT(6, "tape_3592_ioctl_crypt_query\n");
452cced1dd4SMichael Holzheu 	if (!crypt_supported(device))
453cced1dd4SMichael Holzheu 		return -ENOSYS;
454cced1dd4SMichael Holzheu 	tape_3590_sense_medium(device);
455cced1dd4SMichael Holzheu 	if (copy_to_user((char __user *) arg, &TAPE_3590_CRYPT_INFO(device),
456cced1dd4SMichael Holzheu 		sizeof(TAPE_3590_CRYPT_INFO(device))))
457cced1dd4SMichael Holzheu 		return -EFAULT;
458cced1dd4SMichael Holzheu 	else
459cced1dd4SMichael Holzheu 		return 0;
460cced1dd4SMichael Holzheu }
461cced1dd4SMichael Holzheu 
462b6cba4eeSStefan Bader /*
463b6cba4eeSStefan Bader  * 3590 IOCTL Overload
464b6cba4eeSStefan Bader  */
465b6cba4eeSStefan Bader static int
tape_3590_ioctl(struct tape_device * device,unsigned int cmd,unsigned long arg)466b6cba4eeSStefan Bader tape_3590_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
467b6cba4eeSStefan Bader {
468b6cba4eeSStefan Bader 	switch (cmd) {
469b6cba4eeSStefan Bader 	case TAPE390_DISPLAY: {
470b6cba4eeSStefan Bader 		struct display_struct disp;
471b6cba4eeSStefan Bader 
472b6cba4eeSStefan Bader 		if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)))
473b6cba4eeSStefan Bader 			return -EFAULT;
474b6cba4eeSStefan Bader 
475b6cba4eeSStefan Bader 		return tape_std_display(device, &disp);
476b6cba4eeSStefan Bader 	}
477cced1dd4SMichael Holzheu 	case TAPE390_KEKL_SET:
478cced1dd4SMichael Holzheu 		return tape_3592_ioctl_kekl_set(device, arg);
479cced1dd4SMichael Holzheu 	case TAPE390_KEKL_QUERY:
480cced1dd4SMichael Holzheu 		return tape_3592_ioctl_kekl_query(device, arg);
481cced1dd4SMichael Holzheu 	case TAPE390_CRYPT_SET:
482cced1dd4SMichael Holzheu 		return tape_3592_ioctl_crypt_set(device, arg);
483cced1dd4SMichael Holzheu 	case TAPE390_CRYPT_QUERY:
484cced1dd4SMichael Holzheu 		return tape_3592_ioctl_crypt_query(device, arg);
485b6cba4eeSStefan Bader 	default:
486b6cba4eeSStefan Bader 		return -EINVAL;	/* no additional ioctls */
487b6cba4eeSStefan Bader 	}
488b6cba4eeSStefan Bader }
489b6cba4eeSStefan Bader 
490b6cba4eeSStefan Bader /*
491b6cba4eeSStefan Bader  * SENSE Medium: Get Sense data about medium state
492b6cba4eeSStefan Bader  */
tape_3590_sense_medium(struct tape_device * device)4930c2bd9b2SMartin Schwidefsky static int tape_3590_sense_medium(struct tape_device *device)
494b6cba4eeSStefan Bader {
495b6cba4eeSStefan Bader 	struct tape_request *request;
496b6cba4eeSStefan Bader 
497b6cba4eeSStefan Bader 	request = tape_alloc_request(1, 128);
498b6cba4eeSStefan Bader 	if (IS_ERR(request))
499b6cba4eeSStefan Bader 		return PTR_ERR(request);
500b6cba4eeSStefan Bader 	request->op = TO_MSEN;
501b6cba4eeSStefan Bader 	tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
502b6cba4eeSStefan Bader 	return tape_do_io_free(device, request);
503b6cba4eeSStefan Bader }
504b6cba4eeSStefan Bader 
tape_3590_sense_medium_async(struct tape_device * device)5050c2bd9b2SMartin Schwidefsky static void tape_3590_sense_medium_async(struct tape_device *device)
5060c2bd9b2SMartin Schwidefsky {
5070c2bd9b2SMartin Schwidefsky 	struct tape_request *request;
5080c2bd9b2SMartin Schwidefsky 
5090c2bd9b2SMartin Schwidefsky 	request = tape_alloc_request(1, 128);
5100c2bd9b2SMartin Schwidefsky 	if (IS_ERR(request))
5110c2bd9b2SMartin Schwidefsky 		return;
5120c2bd9b2SMartin Schwidefsky 	request->op = TO_MSEN;
5130c2bd9b2SMartin Schwidefsky 	tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
5140c2bd9b2SMartin Schwidefsky 	tape_do_io_async_free(device, request);
5150c2bd9b2SMartin Schwidefsky }
5160c2bd9b2SMartin Schwidefsky 
517b6cba4eeSStefan Bader /*
518b6cba4eeSStefan Bader  * MTTELL: Tell block. Return the number of block relative to current file.
519b6cba4eeSStefan Bader  */
520b6cba4eeSStefan Bader static int
tape_3590_mttell(struct tape_device * device,int mt_count)521b6cba4eeSStefan Bader tape_3590_mttell(struct tape_device *device, int mt_count)
522b6cba4eeSStefan Bader {
523b6cba4eeSStefan Bader 	__u64 block_id;
524b6cba4eeSStefan Bader 	int rc;
525b6cba4eeSStefan Bader 
526b6cba4eeSStefan Bader 	rc = tape_std_read_block_id(device, &block_id);
527b6cba4eeSStefan Bader 	if (rc)
528b6cba4eeSStefan Bader 		return rc;
529b6cba4eeSStefan Bader 	return block_id >> 32;
530b6cba4eeSStefan Bader }
531b6cba4eeSStefan Bader 
532b6cba4eeSStefan Bader /*
533b6cba4eeSStefan Bader  * MTSEEK: seek to the specified block.
534b6cba4eeSStefan Bader  */
535b6cba4eeSStefan Bader static int
tape_3590_mtseek(struct tape_device * device,int count)536b6cba4eeSStefan Bader tape_3590_mtseek(struct tape_device *device, int count)
537b6cba4eeSStefan Bader {
538b6cba4eeSStefan Bader 	struct tape_request *request;
539b6cba4eeSStefan Bader 
540b6cba4eeSStefan Bader 	DBF_EVENT(6, "xsee id: %x\n", count);
541b6cba4eeSStefan Bader 	request = tape_alloc_request(3, 4);
542b6cba4eeSStefan Bader 	if (IS_ERR(request))
543b6cba4eeSStefan Bader 		return PTR_ERR(request);
544b6cba4eeSStefan Bader 	request->op = TO_LBL;
545b6cba4eeSStefan Bader 	tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
546b6cba4eeSStefan Bader 	*(__u32 *) request->cpdata = count;
547b6cba4eeSStefan Bader 	tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
548b6cba4eeSStefan Bader 	tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
549b6cba4eeSStefan Bader 	return tape_do_io_free(device, request);
550b6cba4eeSStefan Bader }
551b6cba4eeSStefan Bader 
552b6cba4eeSStefan Bader /*
553b6cba4eeSStefan Bader  * Read Opposite Error Recovery Function:
554b6cba4eeSStefan Bader  * Used, when Read Forward does not work
555b6cba4eeSStefan Bader  */
556b6cba4eeSStefan Bader static void
tape_3590_read_opposite(struct tape_device * device,struct tape_request * request)557b6cba4eeSStefan Bader tape_3590_read_opposite(struct tape_device *device,
558b6cba4eeSStefan Bader 			struct tape_request *request)
559b6cba4eeSStefan Bader {
560b6cba4eeSStefan Bader 	struct tape_3590_disc_data *data;
561b6cba4eeSStefan Bader 
562b6cba4eeSStefan Bader 	/*
563b6cba4eeSStefan Bader 	 * We have allocated 4 ccws in tape_std_read, so we can now
564b6cba4eeSStefan Bader 	 * transform the request to a read backward, followed by a
565b6cba4eeSStefan Bader 	 * forward space block.
566b6cba4eeSStefan Bader 	 */
567b6cba4eeSStefan Bader 	request->op = TO_RBA;
568b6cba4eeSStefan Bader 	tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
569b6cba4eeSStefan Bader 	data = device->discdata;
570b6cba4eeSStefan Bader 	tape_ccw_cc_idal(request->cpaddr + 1, data->read_back_op,
571b6cba4eeSStefan Bader 			 device->char_data.idal_buf);
572b6cba4eeSStefan Bader 	tape_ccw_cc(request->cpaddr + 2, FORSPACEBLOCK, 0, NULL);
573b6cba4eeSStefan Bader 	tape_ccw_end(request->cpaddr + 3, NOP, 0, NULL);
574b6cba4eeSStefan Bader 	DBF_EVENT(6, "xrop ccwg\n");
575b6cba4eeSStefan Bader }
576b6cba4eeSStefan Bader 
577b6cba4eeSStefan Bader /*
578b6cba4eeSStefan Bader  * Read Attention Msg
579b6cba4eeSStefan Bader  * This should be done after an interrupt with attention bit (0x80)
580b6cba4eeSStefan Bader  * in device state.
581b6cba4eeSStefan Bader  *
582b6cba4eeSStefan Bader  * After a "read attention message" request there are two possible
583b6cba4eeSStefan Bader  * results:
584b6cba4eeSStefan Bader  *
585b6cba4eeSStefan Bader  * 1. A unit check is presented, when attention sense is present (e.g. when
586b6cba4eeSStefan Bader  * a medium has been unloaded). The attention sense comes then
587b6cba4eeSStefan Bader  * together with the unit check. The recovery action is either "retry"
588b6cba4eeSStefan Bader  * (in case there is an attention message pending) or "permanent error".
589b6cba4eeSStefan Bader  *
590b6cba4eeSStefan Bader  * 2. The attention msg is written to the "read subsystem data" buffer.
591b6cba4eeSStefan Bader  * In this case we probably should print it to the console.
592b6cba4eeSStefan Bader  */
tape_3590_read_attmsg_async(struct tape_device * device)5930c2bd9b2SMartin Schwidefsky static void tape_3590_read_attmsg_async(struct tape_device *device)
594b6cba4eeSStefan Bader {
595b6cba4eeSStefan Bader 	struct tape_request *request;
596b6cba4eeSStefan Bader 	char *buf;
597b6cba4eeSStefan Bader 
598b6cba4eeSStefan Bader 	request = tape_alloc_request(3, 4096);
599b6cba4eeSStefan Bader 	if (IS_ERR(request))
6000c2bd9b2SMartin Schwidefsky 		return;
601b6cba4eeSStefan Bader 	request->op = TO_READ_ATTMSG;
602b6cba4eeSStefan Bader 	buf = request->cpdata;
603b6cba4eeSStefan Bader 	buf[0] = PREP_RD_SS_DATA;
604b6cba4eeSStefan Bader 	buf[6] = RD_ATTMSG;	/* read att msg */
605b6cba4eeSStefan Bader 	tape_ccw_cc(request->cpaddr, PERFORM_SS_FUNC, 12, buf);
606b6cba4eeSStefan Bader 	tape_ccw_cc(request->cpaddr + 1, READ_SS_DATA, 4096 - 12, buf + 12);
607b6cba4eeSStefan Bader 	tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
6080c2bd9b2SMartin Schwidefsky 	tape_do_io_async_free(device, request);
609b6cba4eeSStefan Bader }
610b6cba4eeSStefan Bader 
611b6cba4eeSStefan Bader /*
612b6cba4eeSStefan Bader  * These functions are used to schedule follow-up actions from within an
613b6cba4eeSStefan Bader  * interrupt context (like unsolicited interrupts).
6140c2bd9b2SMartin Schwidefsky  * Note: the work handler is called by the system work queue. The tape
6150c2bd9b2SMartin Schwidefsky  * commands started by the handler need to be asynchrounous, otherwise
6160c2bd9b2SMartin Schwidefsky  * a deadlock can occur e.g. in case of a deferred cc=1 (see __tape_do_irq).
617b6cba4eeSStefan Bader  */
6182cc924b8SStefan Bader struct work_handler_data {
619b6cba4eeSStefan Bader 	struct tape_device *device;
620b6cba4eeSStefan Bader 	enum tape_op        op;
621b6cba4eeSStefan Bader 	struct work_struct  work;
6222cc924b8SStefan Bader };
6232cc924b8SStefan Bader 
6242cc924b8SStefan Bader static void
tape_3590_work_handler(struct work_struct * work)625c1637532SMartin Schwidefsky tape_3590_work_handler(struct work_struct *work)
6262cc924b8SStefan Bader {
627c1637532SMartin Schwidefsky 	struct work_handler_data *p =
628c1637532SMartin Schwidefsky 		container_of(work, struct work_handler_data, work);
629b6cba4eeSStefan Bader 
630b6cba4eeSStefan Bader 	switch (p->op) {
631b6cba4eeSStefan Bader 	case TO_MSEN:
6320c2bd9b2SMartin Schwidefsky 		tape_3590_sense_medium_async(p->device);
633b6cba4eeSStefan Bader 		break;
634b6cba4eeSStefan Bader 	case TO_READ_ATTMSG:
6350c2bd9b2SMartin Schwidefsky 		tape_3590_read_attmsg_async(p->device);
636b6cba4eeSStefan Bader 		break;
637cced1dd4SMichael Holzheu 	case TO_CRYPT_ON:
6380c2bd9b2SMartin Schwidefsky 		tape_3592_enable_crypt_async(p->device);
639cced1dd4SMichael Holzheu 		break;
640cced1dd4SMichael Holzheu 	case TO_CRYPT_OFF:
6410c2bd9b2SMartin Schwidefsky 		tape_3592_disable_crypt_async(p->device);
642cced1dd4SMichael Holzheu 		break;
643b6cba4eeSStefan Bader 	default:
644b6cba4eeSStefan Bader 		DBF_EVENT(3, "T3590: work handler undefined for "
645b6cba4eeSStefan Bader 			  "operation 0x%02x\n", p->op);
646b6cba4eeSStefan Bader 	}
647b6cba4eeSStefan Bader 	tape_put_device(p->device);
648b6cba4eeSStefan Bader 	kfree(p);
649b6cba4eeSStefan Bader }
650b6cba4eeSStefan Bader 
651b6cba4eeSStefan Bader static int
tape_3590_schedule_work(struct tape_device * device,enum tape_op op)652b6cba4eeSStefan Bader tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
653b6cba4eeSStefan Bader {
6542cc924b8SStefan Bader 	struct work_handler_data *p;
655b6cba4eeSStefan Bader 
656b6cba4eeSStefan Bader 	if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
657b6cba4eeSStefan Bader 		return -ENOMEM;
658b6cba4eeSStefan Bader 
659c1637532SMartin Schwidefsky 	INIT_WORK(&p->work, tape_3590_work_handler);
660b6cba4eeSStefan Bader 
6618fd138c3SMartin Schwidefsky 	p->device = tape_get_device(device);
662b6cba4eeSStefan Bader 	p->op = op;
663b6cba4eeSStefan Bader 
6646dca467aSTejun Heo 	queue_work(tape_3590_wq, &p->work);
665b6cba4eeSStefan Bader 	return 0;
666b6cba4eeSStefan Bader }
667b6cba4eeSStefan Bader 
tape_3590_med_state_set(struct tape_device * device,struct tape_3590_med_sense * sense)668cced1dd4SMichael Holzheu static void tape_3590_med_state_set(struct tape_device *device,
669cced1dd4SMichael Holzheu 				    struct tape_3590_med_sense *sense)
670cced1dd4SMichael Holzheu {
671cced1dd4SMichael Holzheu 	struct tape390_crypt_info *c_info;
672cced1dd4SMichael Holzheu 
673cced1dd4SMichael Holzheu 	c_info = &TAPE_3590_CRYPT_INFO(device);
674cced1dd4SMichael Holzheu 
6751b9fd76eSMichael Holzheu 	DBF_EVENT(6, "medium state: %x:%x\n", sense->macst, sense->masst);
6761b9fd76eSMichael Holzheu 	switch (sense->macst) {
6771b9fd76eSMichael Holzheu 	case 0x04:
6781b9fd76eSMichael Holzheu 	case 0x05:
6791b9fd76eSMichael Holzheu 	case 0x06:
680cced1dd4SMichael Holzheu 		tape_med_state_set(device, MS_UNLOADED);
681cced1dd4SMichael Holzheu 		TAPE_3590_CRYPT_INFO(device).medium_status = 0;
682cced1dd4SMichael Holzheu 		return;
6831b9fd76eSMichael Holzheu 	case 0x08:
6841b9fd76eSMichael Holzheu 	case 0x09:
6851b9fd76eSMichael Holzheu 		tape_med_state_set(device, MS_LOADED);
6861b9fd76eSMichael Holzheu 		break;
6871b9fd76eSMichael Holzheu 	default:
6881b9fd76eSMichael Holzheu 		tape_med_state_set(device, MS_UNKNOWN);
689cced1dd4SMichael Holzheu 		return;
690cced1dd4SMichael Holzheu 	}
691cced1dd4SMichael Holzheu 	c_info->medium_status |= TAPE390_MEDIUM_LOADED_MASK;
692cced1dd4SMichael Holzheu 	if (sense->flags & MSENSE_CRYPT_MASK) {
693ab640db0SCarsten Otte 		DBF_EVENT(6, "Medium is encrypted (%04x)\n", sense->flags);
694cced1dd4SMichael Holzheu 		c_info->medium_status |= TAPE390_MEDIUM_ENCRYPTED_MASK;
695cced1dd4SMichael Holzheu 	} else	{
696cced1dd4SMichael Holzheu 		DBF_EVENT(6, "Medium is not encrypted %04x\n", sense->flags);
697cced1dd4SMichael Holzheu 		c_info->medium_status &= ~TAPE390_MEDIUM_ENCRYPTED_MASK;
698cced1dd4SMichael Holzheu 	}
699cced1dd4SMichael Holzheu }
700cced1dd4SMichael Holzheu 
701b6cba4eeSStefan Bader /*
702b6cba4eeSStefan Bader  * The done handler is called at device/channel end and wakes up the sleeping
703b6cba4eeSStefan Bader  * process
704b6cba4eeSStefan Bader  */
705b6cba4eeSStefan Bader static int
tape_3590_done(struct tape_device * device,struct tape_request * request)706b6cba4eeSStefan Bader tape_3590_done(struct tape_device *device, struct tape_request *request)
707b6cba4eeSStefan Bader {
708b6cba4eeSStefan Bader 
709b6cba4eeSStefan Bader 	DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
710b6cba4eeSStefan Bader 
711b6cba4eeSStefan Bader 	switch (request->op) {
712b6cba4eeSStefan Bader 	case TO_BSB:
713b6cba4eeSStefan Bader 	case TO_BSF:
714b6cba4eeSStefan Bader 	case TO_DSE:
715b6cba4eeSStefan Bader 	case TO_FSB:
716b6cba4eeSStefan Bader 	case TO_FSF:
717b6cba4eeSStefan Bader 	case TO_LBL:
718b6cba4eeSStefan Bader 	case TO_RFO:
719b6cba4eeSStefan Bader 	case TO_RBA:
720b6cba4eeSStefan Bader 	case TO_REW:
721b6cba4eeSStefan Bader 	case TO_WRI:
722b6cba4eeSStefan Bader 	case TO_WTM:
723b6cba4eeSStefan Bader 	case TO_BLOCK:
724b6cba4eeSStefan Bader 	case TO_LOAD:
725b6cba4eeSStefan Bader 		tape_med_state_set(device, MS_LOADED);
726b6cba4eeSStefan Bader 		break;
727b6cba4eeSStefan Bader 	case TO_RUN:
728b6cba4eeSStefan Bader 		tape_med_state_set(device, MS_UNLOADED);
729cced1dd4SMichael Holzheu 		tape_3590_schedule_work(device, TO_CRYPT_OFF);
730b6cba4eeSStefan Bader 		break;
731b6cba4eeSStefan Bader 	case TO_MSEN:
732cced1dd4SMichael Holzheu 		tape_3590_med_state_set(device, request->cpdata);
733cced1dd4SMichael Holzheu 		break;
734cced1dd4SMichael Holzheu 	case TO_CRYPT_ON:
735cced1dd4SMichael Holzheu 		TAPE_3590_CRYPT_INFO(device).status
736cced1dd4SMichael Holzheu 			|= TAPE390_CRYPT_ON_MASK;
737cced1dd4SMichael Holzheu 		*(device->modeset_byte) |= 0x03;
738cced1dd4SMichael Holzheu 		break;
739cced1dd4SMichael Holzheu 	case TO_CRYPT_OFF:
740cced1dd4SMichael Holzheu 		TAPE_3590_CRYPT_INFO(device).status
741cced1dd4SMichael Holzheu 			&= ~TAPE390_CRYPT_ON_MASK;
742cced1dd4SMichael Holzheu 		*(device->modeset_byte) &= ~0x03;
743b6cba4eeSStefan Bader 		break;
744b6cba4eeSStefan Bader 	case TO_RBI:	/* RBI seems to succeed even without medium loaded. */
745b6cba4eeSStefan Bader 	case TO_NOP:	/* Same to NOP. */
746b6cba4eeSStefan Bader 	case TO_READ_CONFIG:
747b6cba4eeSStefan Bader 	case TO_READ_ATTMSG:
748b6cba4eeSStefan Bader 	case TO_DIS:
749b6cba4eeSStefan Bader 	case TO_ASSIGN:
750b6cba4eeSStefan Bader 	case TO_UNASSIGN:
751b6cba4eeSStefan Bader 	case TO_SIZE:
752cced1dd4SMichael Holzheu 	case TO_KEKL_SET:
753cced1dd4SMichael Holzheu 	case TO_KEKL_QUERY:
754e2963062SMichael Holzheu 	case TO_RDC:
755b6cba4eeSStefan Bader 		break;
756b6cba4eeSStefan Bader 	}
757b6cba4eeSStefan Bader 	return TAPE_IO_SUCCESS;
758b6cba4eeSStefan Bader }
759b6cba4eeSStefan Bader 
760b6cba4eeSStefan Bader /*
761eef35c2dSStefan Weil  * This function is called, when error recovery was successful
762b6cba4eeSStefan Bader  */
763b6cba4eeSStefan Bader static inline int
tape_3590_erp_succeeded(struct tape_device * device,struct tape_request * request)764*aa0028e6SColin Ian King tape_3590_erp_succeeded(struct tape_device *device, struct tape_request *request)
765b6cba4eeSStefan Bader {
76673ac36eaSColy Li 	DBF_EVENT(3, "Error Recovery successful for %s\n",
767b6cba4eeSStefan Bader 		  tape_op_verbose[request->op]);
768b6cba4eeSStefan Bader 	return tape_3590_done(device, request);
769b6cba4eeSStefan Bader }
770b6cba4eeSStefan Bader 
771b6cba4eeSStefan Bader /*
772eef35c2dSStefan Weil  * This function is called, when error recovery was not successful
773b6cba4eeSStefan Bader  */
774b6cba4eeSStefan Bader static inline int
tape_3590_erp_failed(struct tape_device * device,struct tape_request * request,struct irb * irb,int rc)775b6cba4eeSStefan Bader tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
776b6cba4eeSStefan Bader 		     struct irb *irb, int rc)
777b6cba4eeSStefan Bader {
778b6cba4eeSStefan Bader 	DBF_EVENT(3, "Error Recovery failed for %s\n",
779b6cba4eeSStefan Bader 		  tape_op_verbose[request->op]);
780b6cba4eeSStefan Bader 	tape_dump_sense_dbf(device, request, irb);
781b6cba4eeSStefan Bader 	return rc;
782b6cba4eeSStefan Bader }
783b6cba4eeSStefan Bader 
784b6cba4eeSStefan Bader /*
785b6cba4eeSStefan Bader  * Error Recovery do retry
786b6cba4eeSStefan Bader  */
787b6cba4eeSStefan Bader static inline int
tape_3590_erp_retry(struct tape_device * device,struct tape_request * request,struct irb * irb)788b6cba4eeSStefan Bader tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
789b6cba4eeSStefan Bader 		    struct irb *irb)
790b6cba4eeSStefan Bader {
791b6cba4eeSStefan Bader 	DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]);
792b6cba4eeSStefan Bader 	tape_dump_sense_dbf(device, request, irb);
793b6cba4eeSStefan Bader 	return TAPE_IO_RETRY;
794b6cba4eeSStefan Bader }
795b6cba4eeSStefan Bader 
796b6cba4eeSStefan Bader /*
797b6cba4eeSStefan Bader  * Handle unsolicited interrupts
798b6cba4eeSStefan Bader  */
799b6cba4eeSStefan Bader static int
tape_3590_unsolicited_irq(struct tape_device * device,struct irb * irb)800b6cba4eeSStefan Bader tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
801b6cba4eeSStefan Bader {
80223d805b6SPeter Oberparleiter 	if (irb->scsw.cmd.dstat == DEV_STAT_CHN_END)
803b6cba4eeSStefan Bader 		/* Probably result of halt ssch */
804b6cba4eeSStefan Bader 		return TAPE_IO_PENDING;
80523d805b6SPeter Oberparleiter 	else if (irb->scsw.cmd.dstat == 0x85)
8061b9fd76eSMichael Holzheu 		/* Device Ready */
8071b9fd76eSMichael Holzheu 		DBF_EVENT(3, "unsol.irq! tape ready: %08x\n", device->cdev_id);
80823d805b6SPeter Oberparleiter 	else if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
809b6cba4eeSStefan Bader 		tape_3590_schedule_work(device, TO_READ_ATTMSG);
8101b9fd76eSMichael Holzheu 	} else {
811b6cba4eeSStefan Bader 		DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
812ab640db0SCarsten Otte 		tape_dump_sense_dbf(device, NULL, irb);
813b6cba4eeSStefan Bader 	}
8141b9fd76eSMichael Holzheu 	/* check medium state */
8151b9fd76eSMichael Holzheu 	tape_3590_schedule_work(device, TO_MSEN);
816b6cba4eeSStefan Bader 	return TAPE_IO_SUCCESS;
817b6cba4eeSStefan Bader }
818b6cba4eeSStefan Bader 
819b6cba4eeSStefan Bader /*
820b6cba4eeSStefan Bader  * Basic Recovery routine
821b6cba4eeSStefan Bader  */
822b6cba4eeSStefan Bader static int
tape_3590_erp_basic(struct tape_device * device,struct tape_request * request,struct irb * irb,int rc)823b6cba4eeSStefan Bader tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
824b6cba4eeSStefan Bader 		    struct irb *irb, int rc)
825b6cba4eeSStefan Bader {
826b6cba4eeSStefan Bader 	struct tape_3590_sense *sense;
827b6cba4eeSStefan Bader 
828b6cba4eeSStefan Bader 	sense = (struct tape_3590_sense *) irb->ecw;
829b6cba4eeSStefan Bader 
830b6cba4eeSStefan Bader 	switch (sense->bra) {
831b6cba4eeSStefan Bader 	case SENSE_BRA_PER:
832b6cba4eeSStefan Bader 		return tape_3590_erp_failed(device, request, irb, rc);
833b6cba4eeSStefan Bader 	case SENSE_BRA_CONT:
834*aa0028e6SColin Ian King 		return tape_3590_erp_succeeded(device, request);
835b6cba4eeSStefan Bader 	case SENSE_BRA_RE:
836b6cba4eeSStefan Bader 		return tape_3590_erp_retry(device, request, irb);
837b6cba4eeSStefan Bader 	case SENSE_BRA_DRE:
838b6cba4eeSStefan Bader 		return tape_3590_erp_failed(device, request, irb, rc);
839b6cba4eeSStefan Bader 	default:
840b6cba4eeSStefan Bader 		BUG();
841b6cba4eeSStefan Bader 		return TAPE_IO_STOP;
842b6cba4eeSStefan Bader 	}
843b6cba4eeSStefan Bader }
844b6cba4eeSStefan Bader 
845b6cba4eeSStefan Bader /*
846b6cba4eeSStefan Bader  *  RDL: Read Device (buffered) log
847b6cba4eeSStefan Bader  */
848b6cba4eeSStefan Bader static int
tape_3590_erp_read_buf_log(struct tape_device * device,struct tape_request * request,struct irb * irb)849b6cba4eeSStefan Bader tape_3590_erp_read_buf_log(struct tape_device *device,
850b6cba4eeSStefan Bader 			   struct tape_request *request, struct irb *irb)
851b6cba4eeSStefan Bader {
852b6cba4eeSStefan Bader 	/*
853b6cba4eeSStefan Bader 	 * We just do the basic error recovery at the moment (retry).
854b6cba4eeSStefan Bader 	 * Perhaps in the future, we read the log and dump it somewhere...
855b6cba4eeSStefan Bader 	 */
856b6cba4eeSStefan Bader 	return tape_3590_erp_basic(device, request, irb, -EIO);
857b6cba4eeSStefan Bader }
858b6cba4eeSStefan Bader 
859b6cba4eeSStefan Bader /*
860b6cba4eeSStefan Bader  *  SWAP: Swap Devices
861b6cba4eeSStefan Bader  */
862b6cba4eeSStefan Bader static int
tape_3590_erp_swap(struct tape_device * device,struct tape_request * request,struct irb * irb)863b6cba4eeSStefan Bader tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
864b6cba4eeSStefan Bader 		   struct irb *irb)
865b6cba4eeSStefan Bader {
866b6cba4eeSStefan Bader 	/*
867b6cba4eeSStefan Bader 	 * This error recovery should swap the tapes
868b6cba4eeSStefan Bader 	 * if the original has a problem. The operation
869b6cba4eeSStefan Bader 	 * should proceed with the new tape... this
870b6cba4eeSStefan Bader 	 * should probably be done in user space!
871b6cba4eeSStefan Bader 	 */
872ab640db0SCarsten Otte 	dev_warn (&device->cdev->dev, "The tape medium must be loaded into a "
873ab640db0SCarsten Otte 		"different tape unit\n");
874b6cba4eeSStefan Bader 	return tape_3590_erp_basic(device, request, irb, -EIO);
875b6cba4eeSStefan Bader }
876b6cba4eeSStefan Bader 
877b6cba4eeSStefan Bader /*
878b6cba4eeSStefan Bader  *  LBY: Long Busy
879b6cba4eeSStefan Bader  */
880b6cba4eeSStefan Bader static int
tape_3590_erp_long_busy(struct tape_device * device,struct tape_request * request,struct irb * irb)881b6cba4eeSStefan Bader tape_3590_erp_long_busy(struct tape_device *device,
882b6cba4eeSStefan Bader 			struct tape_request *request, struct irb *irb)
883b6cba4eeSStefan Bader {
884cced1dd4SMichael Holzheu 	DBF_EVENT(6, "Device is busy\n");
885cced1dd4SMichael Holzheu 	return TAPE_IO_LONG_BUSY;
886b6cba4eeSStefan Bader }
887b6cba4eeSStefan Bader 
888b6cba4eeSStefan Bader /*
889b6cba4eeSStefan Bader  *  SPI: Special Intercept
890b6cba4eeSStefan Bader  */
891b6cba4eeSStefan Bader static int
tape_3590_erp_special_interrupt(struct tape_device * device,struct tape_request * request,struct irb * irb)892b6cba4eeSStefan Bader tape_3590_erp_special_interrupt(struct tape_device *device,
893b6cba4eeSStefan Bader 				struct tape_request *request, struct irb *irb)
894b6cba4eeSStefan Bader {
895b6cba4eeSStefan Bader 	return tape_3590_erp_basic(device, request, irb, -EIO);
896b6cba4eeSStefan Bader }
897b6cba4eeSStefan Bader 
898b6cba4eeSStefan Bader /*
899b6cba4eeSStefan Bader  *  RDA: Read Alternate
900b6cba4eeSStefan Bader  */
901b6cba4eeSStefan Bader static int
tape_3590_erp_read_alternate(struct tape_device * device,struct tape_request * request,struct irb * irb)902b6cba4eeSStefan Bader tape_3590_erp_read_alternate(struct tape_device *device,
903b6cba4eeSStefan Bader 			     struct tape_request *request, struct irb *irb)
904b6cba4eeSStefan Bader {
905b6cba4eeSStefan Bader 	struct tape_3590_disc_data *data;
906b6cba4eeSStefan Bader 
907b6cba4eeSStefan Bader 	/*
908b6cba4eeSStefan Bader 	 * The issued Read Backward or Read Previous command is not
909b6cba4eeSStefan Bader 	 * supported by the device
910b6cba4eeSStefan Bader 	 * The recovery action should be to issue another command:
911b6cba4eeSStefan Bader 	 * Read Revious: if Read Backward is not supported
912b6cba4eeSStefan Bader 	 * Read Backward: if Read Previous is not supported
913b6cba4eeSStefan Bader 	 */
914b6cba4eeSStefan Bader 	data = device->discdata;
915b6cba4eeSStefan Bader 	if (data->read_back_op == READ_PREVIOUS) {
916b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
917b6cba4eeSStefan Bader 			  device->cdev_id);
918b6cba4eeSStefan Bader 		data->read_back_op = READ_BACKWARD;
919b6cba4eeSStefan Bader 	} else {
920b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
921b6cba4eeSStefan Bader 			  device->cdev_id);
922b6cba4eeSStefan Bader 		data->read_back_op = READ_PREVIOUS;
923b6cba4eeSStefan Bader 	}
924b6cba4eeSStefan Bader 	tape_3590_read_opposite(device, request);
925b6cba4eeSStefan Bader 	return tape_3590_erp_retry(device, request, irb);
926b6cba4eeSStefan Bader }
927b6cba4eeSStefan Bader 
928b6cba4eeSStefan Bader /*
929b6cba4eeSStefan Bader  * Error Recovery read opposite
930b6cba4eeSStefan Bader  */
931b6cba4eeSStefan Bader static int
tape_3590_erp_read_opposite(struct tape_device * device,struct tape_request * request,struct irb * irb)932b6cba4eeSStefan Bader tape_3590_erp_read_opposite(struct tape_device *device,
933b6cba4eeSStefan Bader 			    struct tape_request *request, struct irb *irb)
934b6cba4eeSStefan Bader {
935b6cba4eeSStefan Bader 	switch (request->op) {
936b6cba4eeSStefan Bader 	case TO_RFO:
937b6cba4eeSStefan Bader 		/*
938b6cba4eeSStefan Bader 		 * We did read forward, but the data could not be read.
939b6cba4eeSStefan Bader 		 * We will read backward and then skip forward again.
940b6cba4eeSStefan Bader 		 */
941b6cba4eeSStefan Bader 		tape_3590_read_opposite(device, request);
942b6cba4eeSStefan Bader 		return tape_3590_erp_retry(device, request, irb);
943b6cba4eeSStefan Bader 	case TO_RBA:
944b6cba4eeSStefan Bader 		/* We tried to read forward and backward, but hat no success */
945b6cba4eeSStefan Bader 		return tape_3590_erp_failed(device, request, irb, -EIO);
946b6cba4eeSStefan Bader 		break;
947b6cba4eeSStefan Bader 	default:
948b6cba4eeSStefan Bader 		return tape_3590_erp_failed(device, request, irb, -EIO);
949b6cba4eeSStefan Bader 	}
950b6cba4eeSStefan Bader }
951b6cba4eeSStefan Bader 
952b6cba4eeSStefan Bader /*
953b6cba4eeSStefan Bader  * Print an MIM (Media Information  Message) (message code f0)
954b6cba4eeSStefan Bader  */
955b6cba4eeSStefan Bader static void
tape_3590_print_mim_msg_f0(struct tape_device * device,struct irb * irb)956b6cba4eeSStefan Bader tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
957b6cba4eeSStefan Bader {
958b6cba4eeSStefan Bader 	struct tape_3590_sense *sense;
959ab640db0SCarsten Otte 	char *exception, *service;
960ab640db0SCarsten Otte 
961ab640db0SCarsten Otte 	exception = kmalloc(BUFSIZE, GFP_ATOMIC);
962ab640db0SCarsten Otte 	service = kmalloc(BUFSIZE, GFP_ATOMIC);
963ab640db0SCarsten Otte 
964ab640db0SCarsten Otte 	if (!exception || !service)
965ab640db0SCarsten Otte 		goto out_nomem;
966b6cba4eeSStefan Bader 
967b6cba4eeSStefan Bader 	sense = (struct tape_3590_sense *) irb->ecw;
968b6cba4eeSStefan Bader 	/* Exception Message */
969b6cba4eeSStefan Bader 	switch (sense->fmt.f70.emc) {
970b6cba4eeSStefan Bader 	case 0x02:
971ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Data degraded");
972b6cba4eeSStefan Bader 		break;
973b6cba4eeSStefan Bader 	case 0x03:
974198ee66aSColin Ian King 		snprintf(exception, BUFSIZE, "Data degraded in partition %i",
975ab640db0SCarsten Otte 			sense->fmt.f70.mp);
976b6cba4eeSStefan Bader 		break;
977b6cba4eeSStefan Bader 	case 0x04:
978ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Medium degraded");
979b6cba4eeSStefan Bader 		break;
980b6cba4eeSStefan Bader 	case 0x05:
981ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Medium degraded in partition %i",
982ab640db0SCarsten Otte 			sense->fmt.f70.mp);
983b6cba4eeSStefan Bader 		break;
984b6cba4eeSStefan Bader 	case 0x06:
985ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Block 0 Error");
986b6cba4eeSStefan Bader 		break;
987b6cba4eeSStefan Bader 	case 0x07:
988ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Medium Exception 0x%02x",
989ab640db0SCarsten Otte 			sense->fmt.f70.md);
990b6cba4eeSStefan Bader 		break;
991b6cba4eeSStefan Bader 	default:
992ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "0x%02x",
993ab640db0SCarsten Otte 			sense->fmt.f70.emc);
994b6cba4eeSStefan Bader 		break;
995b6cba4eeSStefan Bader 	}
996b6cba4eeSStefan Bader 	/* Service Message */
997b6cba4eeSStefan Bader 	switch (sense->fmt.f70.smc) {
998b6cba4eeSStefan Bader 	case 0x02:
999ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Reference Media maintenance "
1000ab640db0SCarsten Otte 			"procedure %i", sense->fmt.f70.md);
1001b6cba4eeSStefan Bader 		break;
1002b6cba4eeSStefan Bader 	default:
1003ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "0x%02x",
1004ab640db0SCarsten Otte 			sense->fmt.f70.smc);
1005b6cba4eeSStefan Bader 		break;
1006b6cba4eeSStefan Bader 	}
1007ab640db0SCarsten Otte 
1008ab640db0SCarsten Otte 	dev_warn (&device->cdev->dev, "Tape media information: exception %s, "
1009ab640db0SCarsten Otte 		"service %s\n", exception, service);
1010ab640db0SCarsten Otte 
1011ab640db0SCarsten Otte out_nomem:
1012ab640db0SCarsten Otte 	kfree(exception);
1013ab640db0SCarsten Otte 	kfree(service);
1014b6cba4eeSStefan Bader }
1015b6cba4eeSStefan Bader 
1016b6cba4eeSStefan Bader /*
1017b6cba4eeSStefan Bader  * Print an I/O Subsystem Service Information Message (message code f1)
1018b6cba4eeSStefan Bader  */
1019b6cba4eeSStefan Bader static void
tape_3590_print_io_sim_msg_f1(struct tape_device * device,struct irb * irb)1020b6cba4eeSStefan Bader tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
1021b6cba4eeSStefan Bader {
1022b6cba4eeSStefan Bader 	struct tape_3590_sense *sense;
1023ab640db0SCarsten Otte 	char *exception, *service;
1024ab640db0SCarsten Otte 
1025ab640db0SCarsten Otte 	exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1026ab640db0SCarsten Otte 	service = kmalloc(BUFSIZE, GFP_ATOMIC);
1027ab640db0SCarsten Otte 
1028ab640db0SCarsten Otte 	if (!exception || !service)
1029ab640db0SCarsten Otte 		goto out_nomem;
1030b6cba4eeSStefan Bader 
1031b6cba4eeSStefan Bader 	sense = (struct tape_3590_sense *) irb->ecw;
1032b6cba4eeSStefan Bader 	/* Exception Message */
1033b6cba4eeSStefan Bader 	switch (sense->fmt.f71.emc) {
1034b6cba4eeSStefan Bader 	case 0x01:
1035ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Effect of failure is unknown");
1036b6cba4eeSStefan Bader 		break;
1037b6cba4eeSStefan Bader 	case 0x02:
1038ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "CU Exception - no performance "
1039ab640db0SCarsten Otte 			"impact");
1040b6cba4eeSStefan Bader 		break;
1041b6cba4eeSStefan Bader 	case 0x03:
1042ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "CU Exception on channel "
1043ab640db0SCarsten Otte 			"interface 0x%02x", sense->fmt.f71.md[0]);
1044b6cba4eeSStefan Bader 		break;
1045b6cba4eeSStefan Bader 	case 0x04:
1046ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "CU Exception on device path "
1047ab640db0SCarsten Otte 			"0x%02x", sense->fmt.f71.md[0]);
1048b6cba4eeSStefan Bader 		break;
1049b6cba4eeSStefan Bader 	case 0x05:
1050ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "CU Exception on library path "
1051ab640db0SCarsten Otte 			"0x%02x", sense->fmt.f71.md[0]);
1052b6cba4eeSStefan Bader 		break;
1053b6cba4eeSStefan Bader 	case 0x06:
1054ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "CU Exception on node 0x%02x",
1055ab640db0SCarsten Otte 			sense->fmt.f71.md[0]);
1056b6cba4eeSStefan Bader 		break;
1057b6cba4eeSStefan Bader 	case 0x07:
1058ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "CU Exception on partition "
1059ab640db0SCarsten Otte 			"0x%02x", sense->fmt.f71.md[0]);
1060b6cba4eeSStefan Bader 		break;
1061b6cba4eeSStefan Bader 	default:
1062ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "0x%02x",
1063ab640db0SCarsten Otte 			sense->fmt.f71.emc);
1064b6cba4eeSStefan Bader 	}
1065b6cba4eeSStefan Bader 	/* Service Message */
1066b6cba4eeSStefan Bader 	switch (sense->fmt.f71.smc) {
1067b6cba4eeSStefan Bader 	case 0x01:
1068ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Repair impact is unknown");
1069b6cba4eeSStefan Bader 		break;
1070b6cba4eeSStefan Bader 	case 0x02:
1071ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Repair will not impact cu "
1072ab640db0SCarsten Otte 			"performance");
1073b6cba4eeSStefan Bader 		break;
1074b6cba4eeSStefan Bader 	case 0x03:
1075b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1076ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable node "
1077ab640db0SCarsten Otte 				"0x%x on CU", sense->fmt.f71.md[1]);
1078b6cba4eeSStefan Bader 		else
1079ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1080ab640db0SCarsten Otte 				"nodes (0x%x-0x%x) on CU", sense->fmt.f71.md[1],
1081ab640db0SCarsten Otte 				sense->fmt.f71.md[2]);
1082b6cba4eeSStefan Bader 		break;
1083b6cba4eeSStefan Bader 	case 0x04:
1084b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1085ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1086ab640db0SCarsten Otte 				"channel path 0x%x on CU",
1087b6cba4eeSStefan Bader 				sense->fmt.f71.md[1]);
1088b6cba4eeSStefan Bader 		else
10896774def6SMasanari Iida 			snprintf(service, BUFSIZE, "Repair will disable channel"
1090ab640db0SCarsten Otte 				" paths (0x%x-0x%x) on CU",
1091b6cba4eeSStefan Bader 				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1092b6cba4eeSStefan Bader 		break;
1093b6cba4eeSStefan Bader 	case 0x05:
1094b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1095ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable device"
1096ab640db0SCarsten Otte 				" path 0x%x on CU", sense->fmt.f71.md[1]);
1097b6cba4eeSStefan Bader 		else
1098ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable device"
1099ab640db0SCarsten Otte 				" paths (0x%x-0x%x) on CU",
1100b6cba4eeSStefan Bader 				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1101b6cba4eeSStefan Bader 		break;
1102b6cba4eeSStefan Bader 	case 0x06:
1103b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1104ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1105ab640db0SCarsten Otte 				"library path 0x%x on CU",
1106b6cba4eeSStefan Bader 				sense->fmt.f71.md[1]);
1107b6cba4eeSStefan Bader 		else
1108ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1109ab640db0SCarsten Otte 				"library paths (0x%x-0x%x) on CU",
1110b6cba4eeSStefan Bader 				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1111b6cba4eeSStefan Bader 		break;
1112b6cba4eeSStefan Bader 	case 0x07:
1113ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Repair will disable access to CU");
1114b6cba4eeSStefan Bader 		break;
1115b6cba4eeSStefan Bader 	default:
1116ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "0x%02x",
1117ab640db0SCarsten Otte 			sense->fmt.f71.smc);
1118b6cba4eeSStefan Bader 	}
1119ab640db0SCarsten Otte 
1120ab640db0SCarsten Otte 	dev_warn (&device->cdev->dev, "I/O subsystem information: exception"
1121ab640db0SCarsten Otte 		" %s, service %s\n", exception, service);
1122ab640db0SCarsten Otte out_nomem:
1123ab640db0SCarsten Otte 	kfree(exception);
1124ab640db0SCarsten Otte 	kfree(service);
1125b6cba4eeSStefan Bader }
1126b6cba4eeSStefan Bader 
1127b6cba4eeSStefan Bader /*
1128b6cba4eeSStefan Bader  * Print an Device Subsystem Service Information Message (message code f2)
1129b6cba4eeSStefan Bader  */
1130b6cba4eeSStefan Bader static void
tape_3590_print_dev_sim_msg_f2(struct tape_device * device,struct irb * irb)1131b6cba4eeSStefan Bader tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
1132b6cba4eeSStefan Bader {
1133b6cba4eeSStefan Bader 	struct tape_3590_sense *sense;
1134ab640db0SCarsten Otte 	char *exception, *service;
1135ab640db0SCarsten Otte 
1136ab640db0SCarsten Otte 	exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1137ab640db0SCarsten Otte 	service = kmalloc(BUFSIZE, GFP_ATOMIC);
1138ab640db0SCarsten Otte 
1139ab640db0SCarsten Otte 	if (!exception || !service)
1140ab640db0SCarsten Otte 		goto out_nomem;
1141b6cba4eeSStefan Bader 
1142b6cba4eeSStefan Bader 	sense = (struct tape_3590_sense *) irb->ecw;
1143b6cba4eeSStefan Bader 	/* Exception Message */
1144b6cba4eeSStefan Bader 	switch (sense->fmt.f71.emc) {
1145b6cba4eeSStefan Bader 	case 0x01:
1146ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Effect of failure is unknown");
1147b6cba4eeSStefan Bader 		break;
1148b6cba4eeSStefan Bader 	case 0x02:
1149ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "DV Exception - no performance"
1150ab640db0SCarsten Otte 			" impact");
1151b6cba4eeSStefan Bader 		break;
1152b6cba4eeSStefan Bader 	case 0x03:
1153ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "DV Exception on channel "
1154ab640db0SCarsten Otte 			"interface 0x%02x", sense->fmt.f71.md[0]);
1155b6cba4eeSStefan Bader 		break;
1156b6cba4eeSStefan Bader 	case 0x04:
1157ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "DV Exception on loader 0x%02x",
1158ab640db0SCarsten Otte 			sense->fmt.f71.md[0]);
1159b6cba4eeSStefan Bader 		break;
1160b6cba4eeSStefan Bader 	case 0x05:
1161ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "DV Exception on message display"
1162ab640db0SCarsten Otte 			" 0x%02x", sense->fmt.f71.md[0]);
1163b6cba4eeSStefan Bader 		break;
1164b6cba4eeSStefan Bader 	case 0x06:
1165ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "DV Exception in tape path");
1166b6cba4eeSStefan Bader 		break;
1167b6cba4eeSStefan Bader 	case 0x07:
1168ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "DV Exception in drive");
1169b6cba4eeSStefan Bader 		break;
1170b6cba4eeSStefan Bader 	default:
1171ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "0x%02x",
1172ab640db0SCarsten Otte 			sense->fmt.f71.emc);
1173b6cba4eeSStefan Bader 	}
1174b6cba4eeSStefan Bader 	/* Service Message */
1175b6cba4eeSStefan Bader 	switch (sense->fmt.f71.smc) {
1176b6cba4eeSStefan Bader 	case 0x01:
1177ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Repair impact is unknown");
1178b6cba4eeSStefan Bader 		break;
1179b6cba4eeSStefan Bader 	case 0x02:
1180ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Repair will not impact device "
1181ab640db0SCarsten Otte 			"performance");
1182b6cba4eeSStefan Bader 		break;
1183b6cba4eeSStefan Bader 	case 0x03:
1184b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1185ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1186ab640db0SCarsten Otte 				"channel path 0x%x on DV",
1187b6cba4eeSStefan Bader 				sense->fmt.f71.md[1]);
1188b6cba4eeSStefan Bader 		else
1189ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1190ab640db0SCarsten Otte 				"channel path (0x%x-0x%x) on DV",
1191b6cba4eeSStefan Bader 				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1192b6cba4eeSStefan Bader 		break;
1193b6cba4eeSStefan Bader 	case 0x04:
1194b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1195ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1196ab640db0SCarsten Otte 				"interface 0x%x on DV", sense->fmt.f71.md[1]);
1197b6cba4eeSStefan Bader 		else
1198ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1199ab640db0SCarsten Otte 				"interfaces (0x%x-0x%x) on DV",
1200b6cba4eeSStefan Bader 				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1201b6cba4eeSStefan Bader 		break;
1202b6cba4eeSStefan Bader 	case 0x05:
1203b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1204ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable loader"
1205ab640db0SCarsten Otte 				" 0x%x on DV", sense->fmt.f71.md[1]);
1206b6cba4eeSStefan Bader 		else
1207ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable loader"
1208ab640db0SCarsten Otte 				" (0x%x-0x%x) on DV",
1209b6cba4eeSStefan Bader 				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1210b6cba4eeSStefan Bader 		break;
1211b6cba4eeSStefan Bader 	case 0x07:
1212ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Repair will disable access to DV");
1213b6cba4eeSStefan Bader 		break;
1214b6cba4eeSStefan Bader 	case 0x08:
1215b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1216ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1217ab640db0SCarsten Otte 				"message display 0x%x on DV",
1218b6cba4eeSStefan Bader 				sense->fmt.f71.md[1]);
1219b6cba4eeSStefan Bader 		else
1220ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1221ab640db0SCarsten Otte 				"message displays (0x%x-0x%x) on DV",
1222b6cba4eeSStefan Bader 				 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1223b6cba4eeSStefan Bader 		break;
1224b6cba4eeSStefan Bader 	case 0x09:
1225ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Clean DV");
1226b6cba4eeSStefan Bader 		break;
1227b6cba4eeSStefan Bader 	default:
1228ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "0x%02x",
1229ab640db0SCarsten Otte 			sense->fmt.f71.smc);
1230b6cba4eeSStefan Bader 	}
1231ab640db0SCarsten Otte 
1232ab640db0SCarsten Otte 	dev_warn (&device->cdev->dev, "Device subsystem information: exception"
1233ab640db0SCarsten Otte 		" %s, service %s\n", exception, service);
1234ab640db0SCarsten Otte out_nomem:
1235ab640db0SCarsten Otte 	kfree(exception);
1236ab640db0SCarsten Otte 	kfree(service);
1237b6cba4eeSStefan Bader }
1238b6cba4eeSStefan Bader 
1239b6cba4eeSStefan Bader /*
1240b6cba4eeSStefan Bader  * Print standard ERA Message
1241b6cba4eeSStefan Bader  */
1242b6cba4eeSStefan Bader static void
tape_3590_print_era_msg(struct tape_device * device,struct irb * irb)1243b6cba4eeSStefan Bader tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
1244b6cba4eeSStefan Bader {
1245b6cba4eeSStefan Bader 	struct tape_3590_sense *sense;
1246b6cba4eeSStefan Bader 
1247b6cba4eeSStefan Bader 	sense = (struct tape_3590_sense *) irb->ecw;
1248b6cba4eeSStefan Bader 	if (sense->mc == 0)
1249b6cba4eeSStefan Bader 		return;
1250b6cba4eeSStefan Bader 	if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) {
1251b6cba4eeSStefan Bader 		if (tape_3590_msg[sense->mc] != NULL)
1252ab640db0SCarsten Otte 			dev_warn (&device->cdev->dev, "The tape unit has "
1253ab640db0SCarsten Otte 				"issued sense message %s\n",
1254b6cba4eeSStefan Bader 				tape_3590_msg[sense->mc]);
1255ab640db0SCarsten Otte 		else
1256ab640db0SCarsten Otte 			dev_warn (&device->cdev->dev, "The tape unit has "
1257ab640db0SCarsten Otte 				"issued an unknown sense message code 0x%x\n",
1258ab640db0SCarsten Otte 				sense->mc);
1259b6cba4eeSStefan Bader 		return;
1260b6cba4eeSStefan Bader 	}
1261b6cba4eeSStefan Bader 	if (sense->mc == 0xf0) {
1262b6cba4eeSStefan Bader 		/* Standard Media Information Message */
1263ab640db0SCarsten Otte 		dev_warn (&device->cdev->dev, "MIM SEV=%i, MC=%02x, ES=%x/%x, "
1264ab640db0SCarsten Otte 			"RC=%02x-%04x-%02x\n", sense->fmt.f70.sev, sense->mc,
1265b6cba4eeSStefan Bader 			sense->fmt.f70.emc, sense->fmt.f70.smc,
1266b6cba4eeSStefan Bader 			sense->fmt.f70.refcode, sense->fmt.f70.mid,
1267b6cba4eeSStefan Bader 			sense->fmt.f70.fid);
1268b6cba4eeSStefan Bader 		tape_3590_print_mim_msg_f0(device, irb);
1269b6cba4eeSStefan Bader 		return;
1270b6cba4eeSStefan Bader 	}
1271b6cba4eeSStefan Bader 	if (sense->mc == 0xf1) {
1272b6cba4eeSStefan Bader 		/* Standard I/O Subsystem Service Information Message */
1273ab640db0SCarsten Otte 		dev_warn (&device->cdev->dev, "IOSIM SEV=%i, DEVTYPE=3590/%02x,"
1274b6cba4eeSStefan Bader 			" MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1275ab640db0SCarsten Otte 			sense->fmt.f71.sev, device->cdev->id.dev_model,
1276ab640db0SCarsten Otte 			sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1277ab640db0SCarsten Otte 			sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1278ab640db0SCarsten Otte 			sense->fmt.f71.refcode3);
1279b6cba4eeSStefan Bader 		tape_3590_print_io_sim_msg_f1(device, irb);
1280b6cba4eeSStefan Bader 		return;
1281b6cba4eeSStefan Bader 	}
1282b6cba4eeSStefan Bader 	if (sense->mc == 0xf2) {
1283b6cba4eeSStefan Bader 		/* Standard Device Service Information Message */
1284ab640db0SCarsten Otte 		dev_warn (&device->cdev->dev, "DEVSIM SEV=%i, DEVTYPE=3590/%02x"
1285ab640db0SCarsten Otte 			", MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1286ab640db0SCarsten Otte 			sense->fmt.f71.sev, device->cdev->id.dev_model,
1287ab640db0SCarsten Otte 			sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1288ab640db0SCarsten Otte 			sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1289ab640db0SCarsten Otte 			sense->fmt.f71.refcode3);
1290b6cba4eeSStefan Bader 		tape_3590_print_dev_sim_msg_f2(device, irb);
1291b6cba4eeSStefan Bader 		return;
1292b6cba4eeSStefan Bader 	}
1293b6cba4eeSStefan Bader 	if (sense->mc == 0xf3) {
1294b6cba4eeSStefan Bader 		/* Standard Library Service Information Message */
1295b6cba4eeSStefan Bader 		return;
1296b6cba4eeSStefan Bader 	}
1297ab640db0SCarsten Otte 	dev_warn (&device->cdev->dev, "The tape unit has issued an unknown "
1298ab640db0SCarsten Otte 		"sense message code %x\n", sense->mc);
1299b6cba4eeSStefan Bader }
1300b6cba4eeSStefan Bader 
tape_3590_crypt_error(struct tape_device * device,struct tape_request * request,struct irb * irb)1301cced1dd4SMichael Holzheu static int tape_3590_crypt_error(struct tape_device *device,
1302cced1dd4SMichael Holzheu 				 struct tape_request *request, struct irb *irb)
1303cced1dd4SMichael Holzheu {
1304160fbf2eSHeiko Carstens 	u8 cu_rc;
1305cced1dd4SMichael Holzheu 	u16 ekm_rc2;
13062a0217d5SKay Sievers 	char *sense;
1307cced1dd4SMichael Holzheu 
1308cced1dd4SMichael Holzheu 	sense = ((struct tape_3590_sense *) irb->ecw)->fmt.data;
1309cced1dd4SMichael Holzheu 	cu_rc = sense[0];
1310cced1dd4SMichael Holzheu 	ekm_rc2 = *((u16*) &sense[10]);
1311cced1dd4SMichael Holzheu 	if ((cu_rc == 0) && (ekm_rc2 == 0xee31))
1312cced1dd4SMichael Holzheu 		/* key not defined on EKM */
1313cced1dd4SMichael Holzheu 		return tape_3590_erp_basic(device, request, irb, -EKEYREJECTED);
1314cced1dd4SMichael Holzheu 	if ((cu_rc == 1) || (cu_rc == 2))
1315cced1dd4SMichael Holzheu 		/* No connection to EKM */
1316cced1dd4SMichael Holzheu 		return tape_3590_erp_basic(device, request, irb, -ENOTCONN);
1317cced1dd4SMichael Holzheu 
1318ab640db0SCarsten Otte 	dev_err (&device->cdev->dev, "The tape unit failed to obtain the "
1319ab640db0SCarsten Otte 		"encryption key from EKM\n");
1320cced1dd4SMichael Holzheu 
1321cced1dd4SMichael Holzheu 	return tape_3590_erp_basic(device, request, irb, -ENOKEY);
1322cced1dd4SMichael Holzheu }
1323cced1dd4SMichael Holzheu 
1324b6cba4eeSStefan Bader /*
1325b6cba4eeSStefan Bader  *  3590 error Recovery routine:
1326b6cba4eeSStefan Bader  *  If possible, it tries to recover from the error. If this is not possible,
1327b6cba4eeSStefan Bader  *  inform the user about the problem.
1328b6cba4eeSStefan Bader  */
1329b6cba4eeSStefan Bader static int
tape_3590_unit_check(struct tape_device * device,struct tape_request * request,struct irb * irb)1330b6cba4eeSStefan Bader tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
1331b6cba4eeSStefan Bader 		     struct irb *irb)
1332b6cba4eeSStefan Bader {
1333b6cba4eeSStefan Bader 	struct tape_3590_sense *sense;
1334b6cba4eeSStefan Bader 
1335b6cba4eeSStefan Bader 	sense = (struct tape_3590_sense *) irb->ecw;
1336b6cba4eeSStefan Bader 
1337cced1dd4SMichael Holzheu 	DBF_EVENT(6, "Unit Check: RQC = %x\n", sense->rc_rqc);
1338cced1dd4SMichael Holzheu 
1339b6cba4eeSStefan Bader 	/*
1340b6cba4eeSStefan Bader 	 * First check all RC-QRCs where we want to do something special
1341b6cba4eeSStefan Bader 	 *   - "break":     basic error recovery is done
1342b6cba4eeSStefan Bader 	 *   - "goto out:": just print error message if available
1343b6cba4eeSStefan Bader 	 */
1344b6cba4eeSStefan Bader 	switch (sense->rc_rqc) {
1345b6cba4eeSStefan Bader 
1346b6cba4eeSStefan Bader 	case 0x1110:
1347b6cba4eeSStefan Bader 		tape_3590_print_era_msg(device, irb);
1348b6cba4eeSStefan Bader 		return tape_3590_erp_read_buf_log(device, request, irb);
1349b6cba4eeSStefan Bader 
1350b6cba4eeSStefan Bader 	case 0x2011:
1351b6cba4eeSStefan Bader 		tape_3590_print_era_msg(device, irb);
1352b6cba4eeSStefan Bader 		return tape_3590_erp_read_alternate(device, request, irb);
1353b6cba4eeSStefan Bader 
1354b6cba4eeSStefan Bader 	case 0x2230:
1355b6cba4eeSStefan Bader 	case 0x2231:
1356b6cba4eeSStefan Bader 		tape_3590_print_era_msg(device, irb);
1357b6cba4eeSStefan Bader 		return tape_3590_erp_special_interrupt(device, request, irb);
1358cced1dd4SMichael Holzheu 	case 0x2240:
1359cced1dd4SMichael Holzheu 		return tape_3590_crypt_error(device, request, irb);
1360b6cba4eeSStefan Bader 
1361b6cba4eeSStefan Bader 	case 0x3010:
1362b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1363b6cba4eeSStefan Bader 			  device->cdev_id);
1364b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1365b6cba4eeSStefan Bader 	case 0x3012:
1366b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1367b6cba4eeSStefan Bader 			  device->cdev_id);
1368b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1369b6cba4eeSStefan Bader 	case 0x3020:
1370b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
1371b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1372b6cba4eeSStefan Bader 
1373b6cba4eeSStefan Bader 	case 0x3122:
1374b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1375b6cba4eeSStefan Bader 			  device->cdev_id);
1376b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EIO);
1377b6cba4eeSStefan Bader 	case 0x3123:
1378b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1379b6cba4eeSStefan Bader 			  device->cdev_id);
1380b6cba4eeSStefan Bader 		tape_med_state_set(device, MS_UNLOADED);
1381cced1dd4SMichael Holzheu 		tape_3590_schedule_work(device, TO_CRYPT_OFF);
1382b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, 0);
1383b6cba4eeSStefan Bader 
1384b6cba4eeSStefan Bader 	case 0x4010:
1385b6cba4eeSStefan Bader 		/*
1386b6cba4eeSStefan Bader 		 * print additional msg since default msg
1387b6cba4eeSStefan Bader 		 * "device intervention" is not very meaningfull
1388b6cba4eeSStefan Bader 		 */
1389b6cba4eeSStefan Bader 		tape_med_state_set(device, MS_UNLOADED);
1390cced1dd4SMichael Holzheu 		tape_3590_schedule_work(device, TO_CRYPT_OFF);
1391b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1392b6cba4eeSStefan Bader 	case 0x4012:		/* Device Long Busy */
1393cced1dd4SMichael Holzheu 		/* XXX: Also use long busy handling here? */
1394cced1dd4SMichael Holzheu 		DBF_EVENT(6, "(%08x): LONG BUSY\n", device->cdev_id);
1395b6cba4eeSStefan Bader 		tape_3590_print_era_msg(device, irb);
1396cced1dd4SMichael Holzheu 		return tape_3590_erp_basic(device, request, irb, -EBUSY);
1397cced1dd4SMichael Holzheu 	case 0x4014:
1398cced1dd4SMichael Holzheu 		DBF_EVENT(6, "(%08x): Crypto LONG BUSY\n", device->cdev_id);
1399b6cba4eeSStefan Bader 		return tape_3590_erp_long_busy(device, request, irb);
1400b6cba4eeSStefan Bader 
1401b6cba4eeSStefan Bader 	case 0x5010:
1402b6cba4eeSStefan Bader 		if (sense->rac == 0xd0) {
1403b6cba4eeSStefan Bader 			/* Swap */
1404b6cba4eeSStefan Bader 			tape_3590_print_era_msg(device, irb);
1405b6cba4eeSStefan Bader 			return tape_3590_erp_swap(device, request, irb);
1406b6cba4eeSStefan Bader 		}
1407b6cba4eeSStefan Bader 		if (sense->rac == 0x26) {
1408b6cba4eeSStefan Bader 			/* Read Opposite */
1409b6cba4eeSStefan Bader 			tape_3590_print_era_msg(device, irb);
1410b6cba4eeSStefan Bader 			return tape_3590_erp_read_opposite(device, request,
1411b6cba4eeSStefan Bader 							   irb);
1412b6cba4eeSStefan Bader 		}
1413b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EIO);
1414b6cba4eeSStefan Bader 	case 0x5020:
1415b6cba4eeSStefan Bader 	case 0x5021:
1416b6cba4eeSStefan Bader 	case 0x5022:
1417b6cba4eeSStefan Bader 	case 0x5040:
1418b6cba4eeSStefan Bader 	case 0x5041:
1419b6cba4eeSStefan Bader 	case 0x5042:
1420b6cba4eeSStefan Bader 		tape_3590_print_era_msg(device, irb);
1421b6cba4eeSStefan Bader 		return tape_3590_erp_swap(device, request, irb);
1422b6cba4eeSStefan Bader 
1423b6cba4eeSStefan Bader 	case 0x5110:
1424b6cba4eeSStefan Bader 	case 0x5111:
1425b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1426b6cba4eeSStefan Bader 
1427b6cba4eeSStefan Bader 	case 0x5120:
1428b6cba4eeSStefan Bader 	case 0x1120:
1429b6cba4eeSStefan Bader 		tape_med_state_set(device, MS_UNLOADED);
1430cced1dd4SMichael Holzheu 		tape_3590_schedule_work(device, TO_CRYPT_OFF);
1431b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1432b6cba4eeSStefan Bader 
1433b6cba4eeSStefan Bader 	case 0x6020:
1434b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1435b6cba4eeSStefan Bader 
1436b6cba4eeSStefan Bader 	case 0x8011:
1437b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EPERM);
1438b6cba4eeSStefan Bader 	case 0x8013:
1439ab640db0SCarsten Otte 		dev_warn (&device->cdev->dev, "A different host has privileged"
1440ab640db0SCarsten Otte 			" access to the tape unit\n");
1441b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EPERM);
1442b6cba4eeSStefan Bader 	default:
1443b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EIO);
1444b6cba4eeSStefan Bader 	}
1445b6cba4eeSStefan Bader }
1446b6cba4eeSStefan Bader 
1447b6cba4eeSStefan Bader /*
1448b6cba4eeSStefan Bader  * 3590 interrupt handler:
1449b6cba4eeSStefan Bader  */
1450b6cba4eeSStefan Bader static int
tape_3590_irq(struct tape_device * device,struct tape_request * request,struct irb * irb)1451b6cba4eeSStefan Bader tape_3590_irq(struct tape_device *device, struct tape_request *request,
1452b6cba4eeSStefan Bader 	      struct irb *irb)
1453b6cba4eeSStefan Bader {
1454b6cba4eeSStefan Bader 	if (request == NULL)
1455b6cba4eeSStefan Bader 		return tape_3590_unsolicited_irq(device, irb);
1456b6cba4eeSStefan Bader 
145723d805b6SPeter Oberparleiter 	if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
145823d805b6SPeter Oberparleiter 	    (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
145923d805b6SPeter Oberparleiter 	    (request->op == TO_WRI)) {
1460b6cba4eeSStefan Bader 		/* Write at end of volume */
1461b6cba4eeSStefan Bader 		DBF_EVENT(2, "End of volume\n");
1462b6cba4eeSStefan Bader 		return tape_3590_erp_failed(device, request, irb, -ENOSPC);
1463b6cba4eeSStefan Bader 	}
1464b6cba4eeSStefan Bader 
146523d805b6SPeter Oberparleiter 	if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
1466b6cba4eeSStefan Bader 		return tape_3590_unit_check(device, request, irb);
1467b6cba4eeSStefan Bader 
146823d805b6SPeter Oberparleiter 	if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
146923d805b6SPeter Oberparleiter 		if (irb->scsw.cmd.dstat == DEV_STAT_UNIT_EXCEP) {
1470b6cba4eeSStefan Bader 			if (request->op == TO_FSB || request->op == TO_BSB)
1471b6cba4eeSStefan Bader 				request->rescnt++;
1472b6cba4eeSStefan Bader 			else
1473b6cba4eeSStefan Bader 				DBF_EVENT(5, "Unit Exception!\n");
1474b6cba4eeSStefan Bader 		}
1475b6cba4eeSStefan Bader 
1476b6cba4eeSStefan Bader 		return tape_3590_done(device, request);
1477b6cba4eeSStefan Bader 	}
1478b6cba4eeSStefan Bader 
147923d805b6SPeter Oberparleiter 	if (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) {
14806774def6SMasanari Iida 		DBF_EVENT(2, "channel end\n");
1481b6cba4eeSStefan Bader 		return TAPE_IO_PENDING;
1482b6cba4eeSStefan Bader 	}
1483b6cba4eeSStefan Bader 
148423d805b6SPeter Oberparleiter 	if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
1485b6cba4eeSStefan Bader 		DBF_EVENT(2, "Unit Attention when busy..\n");
1486b6cba4eeSStefan Bader 		return TAPE_IO_PENDING;
1487b6cba4eeSStefan Bader 	}
1488b6cba4eeSStefan Bader 
1489b6cba4eeSStefan Bader 	DBF_EVENT(6, "xunknownirq\n");
1490ab640db0SCarsten Otte 	tape_dump_sense_dbf(device, request, irb);
1491b6cba4eeSStefan Bader 	return TAPE_IO_STOP;
1492b6cba4eeSStefan Bader }
1493b6cba4eeSStefan Bader 
1494e2963062SMichael Holzheu 
tape_3590_read_dev_chars(struct tape_device * device,struct tape_3590_rdc_data * rdc_data)1495e2963062SMichael Holzheu static int tape_3590_read_dev_chars(struct tape_device *device,
1496e2963062SMichael Holzheu 				    struct tape_3590_rdc_data *rdc_data)
1497e2963062SMichael Holzheu {
1498e2963062SMichael Holzheu 	int rc;
1499e2963062SMichael Holzheu 	struct tape_request *request;
1500e2963062SMichael Holzheu 
1501e2963062SMichael Holzheu 	request = tape_alloc_request(1, sizeof(*rdc_data));
1502e2963062SMichael Holzheu 	if (IS_ERR(request))
1503e2963062SMichael Holzheu 		return PTR_ERR(request);
1504e2963062SMichael Holzheu 	request->op = TO_RDC;
1505e2963062SMichael Holzheu 	tape_ccw_end(request->cpaddr, CCW_CMD_RDC, sizeof(*rdc_data),
1506e2963062SMichael Holzheu 		     request->cpdata);
1507e2963062SMichael Holzheu 	rc = tape_do_io(device, request);
1508e2963062SMichael Holzheu 	if (rc == 0)
1509e2963062SMichael Holzheu 		memcpy(rdc_data, request->cpdata, sizeof(*rdc_data));
1510e2963062SMichael Holzheu 	tape_free_request(request);
1511e2963062SMichael Holzheu 	return rc;
1512e2963062SMichael Holzheu }
1513e2963062SMichael Holzheu 
1514b6cba4eeSStefan Bader /*
1515b6cba4eeSStefan Bader  * Setup device function
1516b6cba4eeSStefan Bader  */
1517b6cba4eeSStefan Bader static int
tape_3590_setup_device(struct tape_device * device)1518b6cba4eeSStefan Bader tape_3590_setup_device(struct tape_device *device)
1519b6cba4eeSStefan Bader {
1520b6cba4eeSStefan Bader 	int rc;
1521b6cba4eeSStefan Bader 	struct tape_3590_disc_data *data;
1522e2963062SMichael Holzheu 	struct tape_3590_rdc_data *rdc_data;
1523b6cba4eeSStefan Bader 
1524b6cba4eeSStefan Bader 	DBF_EVENT(6, "3590 device setup\n");
1525cced1dd4SMichael Holzheu 	data = kzalloc(sizeof(struct tape_3590_disc_data), GFP_KERNEL | GFP_DMA);
1526b6cba4eeSStefan Bader 	if (data == NULL)
1527b6cba4eeSStefan Bader 		return -ENOMEM;
1528b6cba4eeSStefan Bader 	data->read_back_op = READ_PREVIOUS;
1529b6cba4eeSStefan Bader 	device->discdata = data;
1530b6cba4eeSStefan Bader 
1531e2963062SMichael Holzheu 	rdc_data = kmalloc(sizeof(*rdc_data), GFP_KERNEL | GFP_DMA);
1532cced1dd4SMichael Holzheu 	if (!rdc_data) {
1533cced1dd4SMichael Holzheu 		rc = -ENOMEM;
1534cced1dd4SMichael Holzheu 		goto fail_kmalloc;
1535b6cba4eeSStefan Bader 	}
1536e2963062SMichael Holzheu 	rc = tape_3590_read_dev_chars(device, rdc_data);
1537cced1dd4SMichael Holzheu 	if (rc) {
1538cced1dd4SMichael Holzheu 		DBF_LH(3, "Read device characteristics failed!\n");
15391783e60fSJulia Lawall 		goto fail_rdc_data;
1540cced1dd4SMichael Holzheu 	}
1541cced1dd4SMichael Holzheu 	rc = tape_std_assign(device);
1542cced1dd4SMichael Holzheu 	if (rc)
1543cced1dd4SMichael Holzheu 		goto fail_rdc_data;
1544e2963062SMichael Holzheu 	if (rdc_data->data[31] == 0x13) {
1545cced1dd4SMichael Holzheu 		data->crypt_info.capability |= TAPE390_CRYPT_SUPPORTED_MASK;
1546cced1dd4SMichael Holzheu 		tape_3592_disable_crypt(device);
1547cced1dd4SMichael Holzheu 	} else {
1548cced1dd4SMichael Holzheu 		DBF_EVENT(6, "Device has NO crypto support\n");
1549cced1dd4SMichael Holzheu 	}
1550cced1dd4SMichael Holzheu 	/* Try to find out if medium is loaded */
1551cced1dd4SMichael Holzheu 	rc = tape_3590_sense_medium(device);
1552cced1dd4SMichael Holzheu 	if (rc) {
1553cced1dd4SMichael Holzheu 		DBF_LH(3, "3590 medium sense returned %d\n", rc);
1554cced1dd4SMichael Holzheu 		goto fail_rdc_data;
1555cced1dd4SMichael Holzheu 	}
1556cced1dd4SMichael Holzheu 	return 0;
1557b6cba4eeSStefan Bader 
1558cced1dd4SMichael Holzheu fail_rdc_data:
1559cced1dd4SMichael Holzheu 	kfree(rdc_data);
1560cced1dd4SMichael Holzheu fail_kmalloc:
1561cced1dd4SMichael Holzheu 	kfree(data);
1562b6cba4eeSStefan Bader 	return rc;
1563b6cba4eeSStefan Bader }
1564b6cba4eeSStefan Bader 
1565b6cba4eeSStefan Bader /*
1566b6cba4eeSStefan Bader  * Cleanup device function
1567b6cba4eeSStefan Bader  */
1568b6cba4eeSStefan Bader static void
tape_3590_cleanup_device(struct tape_device * device)1569b6cba4eeSStefan Bader tape_3590_cleanup_device(struct tape_device *device)
1570b6cba4eeSStefan Bader {
15716dca467aSTejun Heo 	flush_workqueue(tape_3590_wq);
1572b6cba4eeSStefan Bader 	tape_std_unassign(device);
1573b6cba4eeSStefan Bader 
1574b6cba4eeSStefan Bader 	kfree(device->discdata);
1575b6cba4eeSStefan Bader 	device->discdata = NULL;
1576b6cba4eeSStefan Bader }
1577b6cba4eeSStefan Bader 
1578b6cba4eeSStefan Bader /*
1579b6cba4eeSStefan Bader  * List of 3590 magnetic tape commands.
1580b6cba4eeSStefan Bader  */
1581b6cba4eeSStefan Bader static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = {
1582b6cba4eeSStefan Bader 	[MTRESET]	 = tape_std_mtreset,
1583b6cba4eeSStefan Bader 	[MTFSF]		 = tape_std_mtfsf,
1584b6cba4eeSStefan Bader 	[MTBSF]		 = tape_std_mtbsf,
1585b6cba4eeSStefan Bader 	[MTFSR]		 = tape_std_mtfsr,
1586b6cba4eeSStefan Bader 	[MTBSR]		 = tape_std_mtbsr,
1587b6cba4eeSStefan Bader 	[MTWEOF]	 = tape_std_mtweof,
1588b6cba4eeSStefan Bader 	[MTREW]		 = tape_std_mtrew,
1589b6cba4eeSStefan Bader 	[MTOFFL]	 = tape_std_mtoffl,
1590b6cba4eeSStefan Bader 	[MTNOP]		 = tape_std_mtnop,
1591b6cba4eeSStefan Bader 	[MTRETEN]	 = tape_std_mtreten,
1592b6cba4eeSStefan Bader 	[MTBSFM]	 = tape_std_mtbsfm,
1593b6cba4eeSStefan Bader 	[MTFSFM]	 = tape_std_mtfsfm,
1594b6cba4eeSStefan Bader 	[MTEOM]		 = tape_std_mteom,
1595b6cba4eeSStefan Bader 	[MTERASE]	 = tape_std_mterase,
1596b6cba4eeSStefan Bader 	[MTRAS1]	 = NULL,
1597b6cba4eeSStefan Bader 	[MTRAS2]	 = NULL,
1598b6cba4eeSStefan Bader 	[MTRAS3]	 = NULL,
1599b6cba4eeSStefan Bader 	[MTSETBLK]	 = tape_std_mtsetblk,
1600b6cba4eeSStefan Bader 	[MTSETDENSITY]	 = NULL,
1601b6cba4eeSStefan Bader 	[MTSEEK]	 = tape_3590_mtseek,
1602b6cba4eeSStefan Bader 	[MTTELL]	 = tape_3590_mttell,
1603b6cba4eeSStefan Bader 	[MTSETDRVBUFFER] = NULL,
1604b6cba4eeSStefan Bader 	[MTFSS]		 = NULL,
1605b6cba4eeSStefan Bader 	[MTBSS]		 = NULL,
1606b6cba4eeSStefan Bader 	[MTWSM]		 = NULL,
1607b6cba4eeSStefan Bader 	[MTLOCK]	 = NULL,
1608b6cba4eeSStefan Bader 	[MTUNLOCK]	 = NULL,
1609b6cba4eeSStefan Bader 	[MTLOAD]	 = tape_std_mtload,
1610b6cba4eeSStefan Bader 	[MTUNLOAD]	 = tape_std_mtunload,
1611b6cba4eeSStefan Bader 	[MTCOMPRESSION]	 = tape_std_mtcompression,
1612b6cba4eeSStefan Bader 	[MTSETPART]	 = NULL,
1613b6cba4eeSStefan Bader 	[MTMKPART]	 = NULL
1614b6cba4eeSStefan Bader };
1615b6cba4eeSStefan Bader 
1616b6cba4eeSStefan Bader /*
1617b6cba4eeSStefan Bader  * Tape discipline structure for 3590.
1618b6cba4eeSStefan Bader  */
1619b6cba4eeSStefan Bader static struct tape_discipline tape_discipline_3590 = {
1620b6cba4eeSStefan Bader 	.owner = THIS_MODULE,
1621b6cba4eeSStefan Bader 	.setup_device = tape_3590_setup_device,
1622b6cba4eeSStefan Bader 	.cleanup_device = tape_3590_cleanup_device,
1623b6cba4eeSStefan Bader 	.process_eov = tape_std_process_eov,
1624b6cba4eeSStefan Bader 	.irq = tape_3590_irq,
1625b6cba4eeSStefan Bader 	.read_block = tape_std_read_block,
1626b6cba4eeSStefan Bader 	.write_block = tape_std_write_block,
1627b6cba4eeSStefan Bader 	.ioctl_fn = tape_3590_ioctl,
1628b6cba4eeSStefan Bader 	.mtop_array = tape_3590_mtop
1629b6cba4eeSStefan Bader };
1630b6cba4eeSStefan Bader 
1631b6cba4eeSStefan Bader static struct ccw_device_id tape_3590_ids[] = {
1632b6cba4eeSStefan Bader 	{CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590},
16332cc924b8SStefan Bader 	{CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info = tape_3592},
1634b6cba4eeSStefan Bader 	{ /* end of list */ }
1635b6cba4eeSStefan Bader };
1636b6cba4eeSStefan Bader 
1637b6cba4eeSStefan Bader static int
tape_3590_online(struct ccw_device * cdev)1638b6cba4eeSStefan Bader tape_3590_online(struct ccw_device *cdev)
1639b6cba4eeSStefan Bader {
1640dff59b64SGreg Kroah-Hartman 	return tape_generic_online(dev_get_drvdata(&cdev->dev),
1641b6cba4eeSStefan Bader 				   &tape_discipline_3590);
1642b6cba4eeSStefan Bader }
1643b6cba4eeSStefan Bader 
1644b6cba4eeSStefan Bader static struct ccw_driver tape_3590_driver = {
16453bda058bSSebastian Ott 	.driver = {
1646b6cba4eeSStefan Bader 		.name = "tape_3590",
1647b6cba4eeSStefan Bader 		.owner = THIS_MODULE,
16483bda058bSSebastian Ott 	},
1649b6cba4eeSStefan Bader 	.ids = tape_3590_ids,
1650b6cba4eeSStefan Bader 	.probe = tape_generic_probe,
1651b6cba4eeSStefan Bader 	.remove = tape_generic_remove,
16524d7a3cdfSFrank Munzert 	.set_offline = tape_generic_offline,
1653b6cba4eeSStefan Bader 	.set_online = tape_3590_online,
1654420f42ecSHeiko Carstens 	.int_class = IRQIO_TAP,
1655b6cba4eeSStefan Bader };
1656b6cba4eeSStefan Bader 
1657b6cba4eeSStefan Bader /*
1658b6cba4eeSStefan Bader  * Setup discipline structure.
1659b6cba4eeSStefan Bader  */
1660b6cba4eeSStefan Bader static int
tape_3590_init(void)1661b6cba4eeSStefan Bader tape_3590_init(void)
1662b6cba4eeSStefan Bader {
1663b6cba4eeSStefan Bader 	int rc;
1664b6cba4eeSStefan Bader 
1665b6cba4eeSStefan Bader 	TAPE_DBF_AREA = debug_register("tape_3590", 2, 2, 4 * sizeof(long));
1666b6cba4eeSStefan Bader 	debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1667b6cba4eeSStefan Bader #ifdef DBF_LIKE_HELL
1668b6cba4eeSStefan Bader 	debug_set_level(TAPE_DBF_AREA, 6);
1669b6cba4eeSStefan Bader #endif
1670b6cba4eeSStefan Bader 
1671b6cba4eeSStefan Bader 	DBF_EVENT(3, "3590 init\n");
16726dca467aSTejun Heo 
16736dca467aSTejun Heo 	tape_3590_wq = alloc_workqueue("tape_3590", 0, 0);
16746dca467aSTejun Heo 	if (!tape_3590_wq)
16756dca467aSTejun Heo 		return -ENOMEM;
16766dca467aSTejun Heo 
1677b6cba4eeSStefan Bader 	/* Register driver for 3590 tapes. */
1678b6cba4eeSStefan Bader 	rc = ccw_driver_register(&tape_3590_driver);
16796dca467aSTejun Heo 	if (rc) {
16806dca467aSTejun Heo 		destroy_workqueue(tape_3590_wq);
1681b6cba4eeSStefan Bader 		DBF_EVENT(3, "3590 init failed\n");
16826dca467aSTejun Heo 	} else
1683b6cba4eeSStefan Bader 		DBF_EVENT(3, "3590 registered\n");
1684b6cba4eeSStefan Bader 	return rc;
1685b6cba4eeSStefan Bader }
1686b6cba4eeSStefan Bader 
1687b6cba4eeSStefan Bader static void
tape_3590_exit(void)1688b6cba4eeSStefan Bader tape_3590_exit(void)
1689b6cba4eeSStefan Bader {
1690b6cba4eeSStefan Bader 	ccw_driver_unregister(&tape_3590_driver);
16916dca467aSTejun Heo 	destroy_workqueue(tape_3590_wq);
1692b6cba4eeSStefan Bader 	debug_unregister(TAPE_DBF_AREA);
1693b6cba4eeSStefan Bader }
1694b6cba4eeSStefan Bader 
1695b6cba4eeSStefan Bader MODULE_DEVICE_TABLE(ccw, tape_3590_ids);
1696b6cba4eeSStefan Bader MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
1697b6cba4eeSStefan Bader MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
1698b6cba4eeSStefan Bader MODULE_LICENSE("GPL");
1699b6cba4eeSStefan Bader 
1700b6cba4eeSStefan Bader module_init(tape_3590_init);
1701b6cba4eeSStefan Bader module_exit(tape_3590_exit);
1702