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