xref: /openbmc/linux/drivers/s390/char/tape_3590.c (revision 420f42ecf48a926ba775ec7d7294425f004b6ade)
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;
315cced1dd4SMichael Holzheu 	ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
316cced1dd4SMichael Holzheu 	if (!ext_kekls)
317cced1dd4SMichael Holzheu 		return -ENOMEM;
318cced1dd4SMichael Holzheu 	if (copy_from_user(ext_kekls, (char __user *)arg, sizeof(*ext_kekls))) {
319cced1dd4SMichael Holzheu 		rc = -EFAULT;
320cced1dd4SMichael Holzheu 		goto out;
321cced1dd4SMichael Holzheu 	}
322cced1dd4SMichael Holzheu 	rc = tape_3592_kekl_set(device, ext_kekls);
323cced1dd4SMichael Holzheu out:
324cced1dd4SMichael Holzheu 	kfree(ext_kekls);
325cced1dd4SMichael Holzheu 	return rc;
326cced1dd4SMichael Holzheu }
327cced1dd4SMichael Holzheu 
328cced1dd4SMichael Holzheu /*
329cced1dd4SMichael Holzheu  * Enable encryption
330cced1dd4SMichael Holzheu  */
3310c2bd9b2SMartin Schwidefsky static struct tape_request *__tape_3592_enable_crypt(struct tape_device *device)
332cced1dd4SMichael Holzheu {
333cced1dd4SMichael Holzheu 	struct tape_request *request;
334cced1dd4SMichael Holzheu 	char *data;
335cced1dd4SMichael Holzheu 
336cced1dd4SMichael Holzheu 	DBF_EVENT(6, "tape_3592_enable_crypt\n");
337cced1dd4SMichael Holzheu 	if (!crypt_supported(device))
3380c2bd9b2SMartin Schwidefsky 		return ERR_PTR(-ENOSYS);
339cced1dd4SMichael Holzheu 	request = tape_alloc_request(2, 72);
340cced1dd4SMichael Holzheu 	if (IS_ERR(request))
3410c2bd9b2SMartin Schwidefsky 		return request;
342cced1dd4SMichael Holzheu 	data = request->cpdata;
343cced1dd4SMichael Holzheu 	memset(data,0,72);
344cced1dd4SMichael Holzheu 
345cced1dd4SMichael Holzheu 	data[0]       = 0x05;
346cced1dd4SMichael Holzheu 	data[36 + 0]  = 0x03;
347cced1dd4SMichael Holzheu 	data[36 + 1]  = 0x03;
348cced1dd4SMichael Holzheu 	data[36 + 4]  = 0x40;
349cced1dd4SMichael Holzheu 	data[36 + 6]  = 0x01;
350cced1dd4SMichael Holzheu 	data[36 + 14] = 0x2f;
351cced1dd4SMichael Holzheu 	data[36 + 18] = 0xc3;
352cced1dd4SMichael Holzheu 	data[36 + 35] = 0x72;
353cced1dd4SMichael Holzheu 	request->op = TO_CRYPT_ON;
354cced1dd4SMichael Holzheu 	tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
355cced1dd4SMichael Holzheu 	tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
3560c2bd9b2SMartin Schwidefsky 	return request;
3570c2bd9b2SMartin Schwidefsky }
3580c2bd9b2SMartin Schwidefsky 
3590c2bd9b2SMartin Schwidefsky static int tape_3592_enable_crypt(struct tape_device *device)
3600c2bd9b2SMartin Schwidefsky {
3610c2bd9b2SMartin Schwidefsky 	struct tape_request *request;
3620c2bd9b2SMartin Schwidefsky 
3630c2bd9b2SMartin Schwidefsky 	request = __tape_3592_enable_crypt(device);
3640c2bd9b2SMartin Schwidefsky 	if (IS_ERR(request))
3650c2bd9b2SMartin Schwidefsky 		return PTR_ERR(request);
366cced1dd4SMichael Holzheu 	return tape_do_io_free(device, request);
367cced1dd4SMichael Holzheu }
368cced1dd4SMichael Holzheu 
3690c2bd9b2SMartin Schwidefsky static void tape_3592_enable_crypt_async(struct tape_device *device)
3700c2bd9b2SMartin Schwidefsky {
3710c2bd9b2SMartin Schwidefsky 	struct tape_request *request;
3720c2bd9b2SMartin Schwidefsky 
3730c2bd9b2SMartin Schwidefsky 	request = __tape_3592_enable_crypt(device);
3740c2bd9b2SMartin Schwidefsky 	if (!IS_ERR(request))
3750c2bd9b2SMartin Schwidefsky 		tape_do_io_async_free(device, request);
3760c2bd9b2SMartin Schwidefsky }
3770c2bd9b2SMartin Schwidefsky 
378cced1dd4SMichael Holzheu /*
379cced1dd4SMichael Holzheu  * Disable encryption
380cced1dd4SMichael Holzheu  */
3810c2bd9b2SMartin Schwidefsky static struct tape_request *__tape_3592_disable_crypt(struct tape_device *device)
382cced1dd4SMichael Holzheu {
383cced1dd4SMichael Holzheu 	struct tape_request *request;
384cced1dd4SMichael Holzheu 	char *data;
385cced1dd4SMichael Holzheu 
386cced1dd4SMichael Holzheu 	DBF_EVENT(6, "tape_3592_disable_crypt\n");
387cced1dd4SMichael Holzheu 	if (!crypt_supported(device))
3880c2bd9b2SMartin Schwidefsky 		return ERR_PTR(-ENOSYS);
389cced1dd4SMichael Holzheu 	request = tape_alloc_request(2, 72);
390cced1dd4SMichael Holzheu 	if (IS_ERR(request))
3910c2bd9b2SMartin Schwidefsky 		return request;
392cced1dd4SMichael Holzheu 	data = request->cpdata;
393cced1dd4SMichael Holzheu 	memset(data,0,72);
394cced1dd4SMichael Holzheu 
395cced1dd4SMichael Holzheu 	data[0]       = 0x05;
396cced1dd4SMichael Holzheu 	data[36 + 0]  = 0x03;
397cced1dd4SMichael Holzheu 	data[36 + 1]  = 0x03;
398cced1dd4SMichael Holzheu 	data[36 + 35] = 0x32;
399cced1dd4SMichael Holzheu 
400cced1dd4SMichael Holzheu 	request->op = TO_CRYPT_OFF;
401cced1dd4SMichael Holzheu 	tape_ccw_cc(request->cpaddr, MODE_SET_CB, 36, data);
402cced1dd4SMichael Holzheu 	tape_ccw_end(request->cpaddr + 1, MODE_SET_CB, 36, data + 36);
403cced1dd4SMichael Holzheu 
4040c2bd9b2SMartin Schwidefsky 	return request;
4050c2bd9b2SMartin Schwidefsky }
4060c2bd9b2SMartin Schwidefsky 
4070c2bd9b2SMartin Schwidefsky static int tape_3592_disable_crypt(struct tape_device *device)
4080c2bd9b2SMartin Schwidefsky {
4090c2bd9b2SMartin Schwidefsky 	struct tape_request *request;
4100c2bd9b2SMartin Schwidefsky 
4110c2bd9b2SMartin Schwidefsky 	request = __tape_3592_disable_crypt(device);
4120c2bd9b2SMartin Schwidefsky 	if (IS_ERR(request))
4130c2bd9b2SMartin Schwidefsky 		return PTR_ERR(request);
414cced1dd4SMichael Holzheu 	return tape_do_io_free(device, request);
415cced1dd4SMichael Holzheu }
416cced1dd4SMichael Holzheu 
4170c2bd9b2SMartin Schwidefsky static void tape_3592_disable_crypt_async(struct tape_device *device)
4180c2bd9b2SMartin Schwidefsky {
4190c2bd9b2SMartin Schwidefsky 	struct tape_request *request;
4200c2bd9b2SMartin Schwidefsky 
4210c2bd9b2SMartin Schwidefsky 	request = __tape_3592_disable_crypt(device);
4220c2bd9b2SMartin Schwidefsky 	if (!IS_ERR(request))
4230c2bd9b2SMartin Schwidefsky 		tape_do_io_async_free(device, request);
4240c2bd9b2SMartin Schwidefsky }
4250c2bd9b2SMartin Schwidefsky 
426cced1dd4SMichael Holzheu /*
427cced1dd4SMichael Holzheu  * IOCTL: Set encryption status
428cced1dd4SMichael Holzheu  */
429cced1dd4SMichael Holzheu static int tape_3592_ioctl_crypt_set(struct tape_device *device,
430cced1dd4SMichael Holzheu 				     unsigned long arg)
431cced1dd4SMichael Holzheu {
432cced1dd4SMichael Holzheu 	struct tape390_crypt_info info;
433cced1dd4SMichael Holzheu 
434cced1dd4SMichael Holzheu 	DBF_EVENT(6, "tape_3592_ioctl_crypt_set\n");
435cced1dd4SMichael Holzheu 	if (!crypt_supported(device))
436cced1dd4SMichael Holzheu 		return -ENOSYS;
437cced1dd4SMichael Holzheu 	if (copy_from_user(&info, (char __user *)arg, sizeof(info)))
438cced1dd4SMichael Holzheu 		return -EFAULT;
439cced1dd4SMichael Holzheu 	if (info.status & ~TAPE390_CRYPT_ON_MASK)
440cced1dd4SMichael Holzheu 		return -EINVAL;
441cced1dd4SMichael Holzheu 	if (info.status & TAPE390_CRYPT_ON_MASK)
442cced1dd4SMichael Holzheu 		return tape_3592_enable_crypt(device);
443cced1dd4SMichael Holzheu 	else
444cced1dd4SMichael Holzheu 		return tape_3592_disable_crypt(device);
445cced1dd4SMichael Holzheu }
446cced1dd4SMichael Holzheu 
447cced1dd4SMichael Holzheu static int tape_3590_sense_medium(struct tape_device *device);
448cced1dd4SMichael Holzheu 
449cced1dd4SMichael Holzheu /*
450cced1dd4SMichael Holzheu  * IOCTL: Query enryption status
451cced1dd4SMichael Holzheu  */
452cced1dd4SMichael Holzheu static int tape_3592_ioctl_crypt_query(struct tape_device *device,
453cced1dd4SMichael Holzheu 				       unsigned long arg)
454cced1dd4SMichael Holzheu {
455cced1dd4SMichael Holzheu 	DBF_EVENT(6, "tape_3592_ioctl_crypt_query\n");
456cced1dd4SMichael Holzheu 	if (!crypt_supported(device))
457cced1dd4SMichael Holzheu 		return -ENOSYS;
458cced1dd4SMichael Holzheu 	tape_3590_sense_medium(device);
459cced1dd4SMichael Holzheu 	if (copy_to_user((char __user *) arg, &TAPE_3590_CRYPT_INFO(device),
460cced1dd4SMichael Holzheu 		sizeof(TAPE_3590_CRYPT_INFO(device))))
461cced1dd4SMichael Holzheu 		return -EFAULT;
462cced1dd4SMichael Holzheu 	else
463cced1dd4SMichael Holzheu 		return 0;
464cced1dd4SMichael Holzheu }
465cced1dd4SMichael Holzheu 
466b6cba4eeSStefan Bader /*
467b6cba4eeSStefan Bader  * 3590 IOCTL Overload
468b6cba4eeSStefan Bader  */
469b6cba4eeSStefan Bader static int
470b6cba4eeSStefan Bader tape_3590_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
471b6cba4eeSStefan Bader {
472b6cba4eeSStefan Bader 	switch (cmd) {
473b6cba4eeSStefan Bader 	case TAPE390_DISPLAY: {
474b6cba4eeSStefan Bader 		struct display_struct disp;
475b6cba4eeSStefan Bader 
476b6cba4eeSStefan Bader 		if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)))
477b6cba4eeSStefan Bader 			return -EFAULT;
478b6cba4eeSStefan Bader 
479b6cba4eeSStefan Bader 		return tape_std_display(device, &disp);
480b6cba4eeSStefan Bader 	}
481cced1dd4SMichael Holzheu 	case TAPE390_KEKL_SET:
482cced1dd4SMichael Holzheu 		return tape_3592_ioctl_kekl_set(device, arg);
483cced1dd4SMichael Holzheu 	case TAPE390_KEKL_QUERY:
484cced1dd4SMichael Holzheu 		return tape_3592_ioctl_kekl_query(device, arg);
485cced1dd4SMichael Holzheu 	case TAPE390_CRYPT_SET:
486cced1dd4SMichael Holzheu 		return tape_3592_ioctl_crypt_set(device, arg);
487cced1dd4SMichael Holzheu 	case TAPE390_CRYPT_QUERY:
488cced1dd4SMichael Holzheu 		return tape_3592_ioctl_crypt_query(device, arg);
489b6cba4eeSStefan Bader 	default:
490b6cba4eeSStefan Bader 		return -EINVAL;	/* no additional ioctls */
491b6cba4eeSStefan Bader 	}
492b6cba4eeSStefan Bader }
493b6cba4eeSStefan Bader 
494b6cba4eeSStefan Bader /*
495b6cba4eeSStefan Bader  * SENSE Medium: Get Sense data about medium state
496b6cba4eeSStefan Bader  */
4970c2bd9b2SMartin Schwidefsky static int tape_3590_sense_medium(struct tape_device *device)
498b6cba4eeSStefan Bader {
499b6cba4eeSStefan Bader 	struct tape_request *request;
500b6cba4eeSStefan Bader 
501b6cba4eeSStefan Bader 	request = tape_alloc_request(1, 128);
502b6cba4eeSStefan Bader 	if (IS_ERR(request))
503b6cba4eeSStefan Bader 		return PTR_ERR(request);
504b6cba4eeSStefan Bader 	request->op = TO_MSEN;
505b6cba4eeSStefan Bader 	tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
506b6cba4eeSStefan Bader 	return tape_do_io_free(device, request);
507b6cba4eeSStefan Bader }
508b6cba4eeSStefan Bader 
5090c2bd9b2SMartin Schwidefsky static void tape_3590_sense_medium_async(struct tape_device *device)
5100c2bd9b2SMartin Schwidefsky {
5110c2bd9b2SMartin Schwidefsky 	struct tape_request *request;
5120c2bd9b2SMartin Schwidefsky 
5130c2bd9b2SMartin Schwidefsky 	request = tape_alloc_request(1, 128);
5140c2bd9b2SMartin Schwidefsky 	if (IS_ERR(request))
5150c2bd9b2SMartin Schwidefsky 		return;
5160c2bd9b2SMartin Schwidefsky 	request->op = TO_MSEN;
5170c2bd9b2SMartin Schwidefsky 	tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
5180c2bd9b2SMartin Schwidefsky 	tape_do_io_async_free(device, request);
5190c2bd9b2SMartin Schwidefsky }
5200c2bd9b2SMartin Schwidefsky 
521b6cba4eeSStefan Bader /*
522b6cba4eeSStefan Bader  * MTTELL: Tell block. Return the number of block relative to current file.
523b6cba4eeSStefan Bader  */
524b6cba4eeSStefan Bader static int
525b6cba4eeSStefan Bader tape_3590_mttell(struct tape_device *device, int mt_count)
526b6cba4eeSStefan Bader {
527b6cba4eeSStefan Bader 	__u64 block_id;
528b6cba4eeSStefan Bader 	int rc;
529b6cba4eeSStefan Bader 
530b6cba4eeSStefan Bader 	rc = tape_std_read_block_id(device, &block_id);
531b6cba4eeSStefan Bader 	if (rc)
532b6cba4eeSStefan Bader 		return rc;
533b6cba4eeSStefan Bader 	return block_id >> 32;
534b6cba4eeSStefan Bader }
535b6cba4eeSStefan Bader 
536b6cba4eeSStefan Bader /*
537b6cba4eeSStefan Bader  * MTSEEK: seek to the specified block.
538b6cba4eeSStefan Bader  */
539b6cba4eeSStefan Bader static int
540b6cba4eeSStefan Bader tape_3590_mtseek(struct tape_device *device, int count)
541b6cba4eeSStefan Bader {
542b6cba4eeSStefan Bader 	struct tape_request *request;
543b6cba4eeSStefan Bader 
544b6cba4eeSStefan Bader 	DBF_EVENT(6, "xsee id: %x\n", count);
545b6cba4eeSStefan Bader 	request = tape_alloc_request(3, 4);
546b6cba4eeSStefan Bader 	if (IS_ERR(request))
547b6cba4eeSStefan Bader 		return PTR_ERR(request);
548b6cba4eeSStefan Bader 	request->op = TO_LBL;
549b6cba4eeSStefan Bader 	tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
550b6cba4eeSStefan Bader 	*(__u32 *) request->cpdata = count;
551b6cba4eeSStefan Bader 	tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
552b6cba4eeSStefan Bader 	tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
553b6cba4eeSStefan Bader 	return tape_do_io_free(device, request);
554b6cba4eeSStefan Bader }
555b6cba4eeSStefan Bader 
556b6cba4eeSStefan Bader /*
557b6cba4eeSStefan Bader  * Read Opposite Error Recovery Function:
558b6cba4eeSStefan Bader  * Used, when Read Forward does not work
559b6cba4eeSStefan Bader  */
560b6cba4eeSStefan Bader static void
561b6cba4eeSStefan Bader tape_3590_read_opposite(struct tape_device *device,
562b6cba4eeSStefan Bader 			struct tape_request *request)
563b6cba4eeSStefan Bader {
564b6cba4eeSStefan Bader 	struct tape_3590_disc_data *data;
565b6cba4eeSStefan Bader 
566b6cba4eeSStefan Bader 	/*
567b6cba4eeSStefan Bader 	 * We have allocated 4 ccws in tape_std_read, so we can now
568b6cba4eeSStefan Bader 	 * transform the request to a read backward, followed by a
569b6cba4eeSStefan Bader 	 * forward space block.
570b6cba4eeSStefan Bader 	 */
571b6cba4eeSStefan Bader 	request->op = TO_RBA;
572b6cba4eeSStefan Bader 	tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
573b6cba4eeSStefan Bader 	data = device->discdata;
574b6cba4eeSStefan Bader 	tape_ccw_cc_idal(request->cpaddr + 1, data->read_back_op,
575b6cba4eeSStefan Bader 			 device->char_data.idal_buf);
576b6cba4eeSStefan Bader 	tape_ccw_cc(request->cpaddr + 2, FORSPACEBLOCK, 0, NULL);
577b6cba4eeSStefan Bader 	tape_ccw_end(request->cpaddr + 3, NOP, 0, NULL);
578b6cba4eeSStefan Bader 	DBF_EVENT(6, "xrop ccwg\n");
579b6cba4eeSStefan Bader }
580b6cba4eeSStefan Bader 
581b6cba4eeSStefan Bader /*
582b6cba4eeSStefan Bader  * Read Attention Msg
583b6cba4eeSStefan Bader  * This should be done after an interrupt with attention bit (0x80)
584b6cba4eeSStefan Bader  * in device state.
585b6cba4eeSStefan Bader  *
586b6cba4eeSStefan Bader  * After a "read attention message" request there are two possible
587b6cba4eeSStefan Bader  * results:
588b6cba4eeSStefan Bader  *
589b6cba4eeSStefan Bader  * 1. A unit check is presented, when attention sense is present (e.g. when
590b6cba4eeSStefan Bader  * a medium has been unloaded). The attention sense comes then
591b6cba4eeSStefan Bader  * together with the unit check. The recovery action is either "retry"
592b6cba4eeSStefan Bader  * (in case there is an attention message pending) or "permanent error".
593b6cba4eeSStefan Bader  *
594b6cba4eeSStefan Bader  * 2. The attention msg is written to the "read subsystem data" buffer.
595b6cba4eeSStefan Bader  * In this case we probably should print it to the console.
596b6cba4eeSStefan Bader  */
5970c2bd9b2SMartin Schwidefsky static void tape_3590_read_attmsg_async(struct tape_device *device)
598b6cba4eeSStefan Bader {
599b6cba4eeSStefan Bader 	struct tape_request *request;
600b6cba4eeSStefan Bader 	char *buf;
601b6cba4eeSStefan Bader 
602b6cba4eeSStefan Bader 	request = tape_alloc_request(3, 4096);
603b6cba4eeSStefan Bader 	if (IS_ERR(request))
6040c2bd9b2SMartin Schwidefsky 		return;
605b6cba4eeSStefan Bader 	request->op = TO_READ_ATTMSG;
606b6cba4eeSStefan Bader 	buf = request->cpdata;
607b6cba4eeSStefan Bader 	buf[0] = PREP_RD_SS_DATA;
608b6cba4eeSStefan Bader 	buf[6] = RD_ATTMSG;	/* read att msg */
609b6cba4eeSStefan Bader 	tape_ccw_cc(request->cpaddr, PERFORM_SS_FUNC, 12, buf);
610b6cba4eeSStefan Bader 	tape_ccw_cc(request->cpaddr + 1, READ_SS_DATA, 4096 - 12, buf + 12);
611b6cba4eeSStefan Bader 	tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
6120c2bd9b2SMartin Schwidefsky 	tape_do_io_async_free(device, request);
613b6cba4eeSStefan Bader }
614b6cba4eeSStefan Bader 
615b6cba4eeSStefan Bader /*
616b6cba4eeSStefan Bader  * These functions are used to schedule follow-up actions from within an
617b6cba4eeSStefan Bader  * interrupt context (like unsolicited interrupts).
6180c2bd9b2SMartin Schwidefsky  * Note: the work handler is called by the system work queue. The tape
6190c2bd9b2SMartin Schwidefsky  * commands started by the handler need to be asynchrounous, otherwise
6200c2bd9b2SMartin Schwidefsky  * a deadlock can occur e.g. in case of a deferred cc=1 (see __tape_do_irq).
621b6cba4eeSStefan Bader  */
6222cc924b8SStefan Bader struct work_handler_data {
623b6cba4eeSStefan Bader 	struct tape_device *device;
624b6cba4eeSStefan Bader 	enum tape_op        op;
625b6cba4eeSStefan Bader 	struct work_struct  work;
6262cc924b8SStefan Bader };
6272cc924b8SStefan Bader 
6282cc924b8SStefan Bader static void
629c1637532SMartin Schwidefsky tape_3590_work_handler(struct work_struct *work)
6302cc924b8SStefan Bader {
631c1637532SMartin Schwidefsky 	struct work_handler_data *p =
632c1637532SMartin Schwidefsky 		container_of(work, struct work_handler_data, work);
633b6cba4eeSStefan Bader 
634b6cba4eeSStefan Bader 	switch (p->op) {
635b6cba4eeSStefan Bader 	case TO_MSEN:
6360c2bd9b2SMartin Schwidefsky 		tape_3590_sense_medium_async(p->device);
637b6cba4eeSStefan Bader 		break;
638b6cba4eeSStefan Bader 	case TO_READ_ATTMSG:
6390c2bd9b2SMartin Schwidefsky 		tape_3590_read_attmsg_async(p->device);
640b6cba4eeSStefan Bader 		break;
641cced1dd4SMichael Holzheu 	case TO_CRYPT_ON:
6420c2bd9b2SMartin Schwidefsky 		tape_3592_enable_crypt_async(p->device);
643cced1dd4SMichael Holzheu 		break;
644cced1dd4SMichael Holzheu 	case TO_CRYPT_OFF:
6450c2bd9b2SMartin Schwidefsky 		tape_3592_disable_crypt_async(p->device);
646cced1dd4SMichael Holzheu 		break;
647b6cba4eeSStefan Bader 	default:
648b6cba4eeSStefan Bader 		DBF_EVENT(3, "T3590: work handler undefined for "
649b6cba4eeSStefan Bader 			  "operation 0x%02x\n", p->op);
650b6cba4eeSStefan Bader 	}
651b6cba4eeSStefan Bader 	tape_put_device(p->device);
652b6cba4eeSStefan Bader 	kfree(p);
653b6cba4eeSStefan Bader }
654b6cba4eeSStefan Bader 
655b6cba4eeSStefan Bader static int
656b6cba4eeSStefan Bader tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
657b6cba4eeSStefan Bader {
6582cc924b8SStefan Bader 	struct work_handler_data *p;
659b6cba4eeSStefan Bader 
660b6cba4eeSStefan Bader 	if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
661b6cba4eeSStefan Bader 		return -ENOMEM;
662b6cba4eeSStefan Bader 
663c1637532SMartin Schwidefsky 	INIT_WORK(&p->work, tape_3590_work_handler);
664b6cba4eeSStefan Bader 
6658fd138c3SMartin Schwidefsky 	p->device = tape_get_device(device);
666b6cba4eeSStefan Bader 	p->op = op;
667b6cba4eeSStefan Bader 
6686dca467aSTejun Heo 	queue_work(tape_3590_wq, &p->work);
669b6cba4eeSStefan Bader 	return 0;
670b6cba4eeSStefan Bader }
671b6cba4eeSStefan Bader 
672cced1dd4SMichael Holzheu static void tape_3590_med_state_set(struct tape_device *device,
673cced1dd4SMichael Holzheu 				    struct tape_3590_med_sense *sense)
674cced1dd4SMichael Holzheu {
675cced1dd4SMichael Holzheu 	struct tape390_crypt_info *c_info;
676cced1dd4SMichael Holzheu 
677cced1dd4SMichael Holzheu 	c_info = &TAPE_3590_CRYPT_INFO(device);
678cced1dd4SMichael Holzheu 
6791b9fd76eSMichael Holzheu 	DBF_EVENT(6, "medium state: %x:%x\n", sense->macst, sense->masst);
6801b9fd76eSMichael Holzheu 	switch (sense->macst) {
6811b9fd76eSMichael Holzheu 	case 0x04:
6821b9fd76eSMichael Holzheu 	case 0x05:
6831b9fd76eSMichael Holzheu 	case 0x06:
684cced1dd4SMichael Holzheu 		tape_med_state_set(device, MS_UNLOADED);
685cced1dd4SMichael Holzheu 		TAPE_3590_CRYPT_INFO(device).medium_status = 0;
686cced1dd4SMichael Holzheu 		return;
6871b9fd76eSMichael Holzheu 	case 0x08:
6881b9fd76eSMichael Holzheu 	case 0x09:
6891b9fd76eSMichael Holzheu 		tape_med_state_set(device, MS_LOADED);
6901b9fd76eSMichael Holzheu 		break;
6911b9fd76eSMichael Holzheu 	default:
6921b9fd76eSMichael Holzheu 		tape_med_state_set(device, MS_UNKNOWN);
693cced1dd4SMichael Holzheu 		return;
694cced1dd4SMichael Holzheu 	}
695cced1dd4SMichael Holzheu 	c_info->medium_status |= TAPE390_MEDIUM_LOADED_MASK;
696cced1dd4SMichael Holzheu 	if (sense->flags & MSENSE_CRYPT_MASK) {
697ab640db0SCarsten Otte 		DBF_EVENT(6, "Medium is encrypted (%04x)\n", sense->flags);
698cced1dd4SMichael Holzheu 		c_info->medium_status |= TAPE390_MEDIUM_ENCRYPTED_MASK;
699cced1dd4SMichael Holzheu 	} else	{
700cced1dd4SMichael Holzheu 		DBF_EVENT(6, "Medium is not encrypted %04x\n", sense->flags);
701cced1dd4SMichael Holzheu 		c_info->medium_status &= ~TAPE390_MEDIUM_ENCRYPTED_MASK;
702cced1dd4SMichael Holzheu 	}
703cced1dd4SMichael Holzheu }
704cced1dd4SMichael Holzheu 
705b6cba4eeSStefan Bader /*
706b6cba4eeSStefan Bader  * The done handler is called at device/channel end and wakes up the sleeping
707b6cba4eeSStefan Bader  * process
708b6cba4eeSStefan Bader  */
709b6cba4eeSStefan Bader static int
710b6cba4eeSStefan Bader tape_3590_done(struct tape_device *device, struct tape_request *request)
711b6cba4eeSStefan Bader {
712b6cba4eeSStefan Bader 
713b6cba4eeSStefan Bader 	DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
714b6cba4eeSStefan Bader 
715b6cba4eeSStefan Bader 	switch (request->op) {
716b6cba4eeSStefan Bader 	case TO_BSB:
717b6cba4eeSStefan Bader 	case TO_BSF:
718b6cba4eeSStefan Bader 	case TO_DSE:
719b6cba4eeSStefan Bader 	case TO_FSB:
720b6cba4eeSStefan Bader 	case TO_FSF:
721b6cba4eeSStefan Bader 	case TO_LBL:
722b6cba4eeSStefan Bader 	case TO_RFO:
723b6cba4eeSStefan Bader 	case TO_RBA:
724b6cba4eeSStefan Bader 	case TO_REW:
725b6cba4eeSStefan Bader 	case TO_WRI:
726b6cba4eeSStefan Bader 	case TO_WTM:
727b6cba4eeSStefan Bader 	case TO_BLOCK:
728b6cba4eeSStefan Bader 	case TO_LOAD:
729b6cba4eeSStefan Bader 		tape_med_state_set(device, MS_LOADED);
730b6cba4eeSStefan Bader 		break;
731b6cba4eeSStefan Bader 	case TO_RUN:
732b6cba4eeSStefan Bader 		tape_med_state_set(device, MS_UNLOADED);
733cced1dd4SMichael Holzheu 		tape_3590_schedule_work(device, TO_CRYPT_OFF);
734b6cba4eeSStefan Bader 		break;
735b6cba4eeSStefan Bader 	case TO_MSEN:
736cced1dd4SMichael Holzheu 		tape_3590_med_state_set(device, request->cpdata);
737cced1dd4SMichael Holzheu 		break;
738cced1dd4SMichael Holzheu 	case TO_CRYPT_ON:
739cced1dd4SMichael Holzheu 		TAPE_3590_CRYPT_INFO(device).status
740cced1dd4SMichael Holzheu 			|= TAPE390_CRYPT_ON_MASK;
741cced1dd4SMichael Holzheu 		*(device->modeset_byte) |= 0x03;
742cced1dd4SMichael Holzheu 		break;
743cced1dd4SMichael Holzheu 	case TO_CRYPT_OFF:
744cced1dd4SMichael Holzheu 		TAPE_3590_CRYPT_INFO(device).status
745cced1dd4SMichael Holzheu 			&= ~TAPE390_CRYPT_ON_MASK;
746cced1dd4SMichael Holzheu 		*(device->modeset_byte) &= ~0x03;
747b6cba4eeSStefan Bader 		break;
748b6cba4eeSStefan Bader 	case TO_RBI:	/* RBI seems to succeed even without medium loaded. */
749b6cba4eeSStefan Bader 	case TO_NOP:	/* Same to NOP. */
750b6cba4eeSStefan Bader 	case TO_READ_CONFIG:
751b6cba4eeSStefan Bader 	case TO_READ_ATTMSG:
752b6cba4eeSStefan Bader 	case TO_DIS:
753b6cba4eeSStefan Bader 	case TO_ASSIGN:
754b6cba4eeSStefan Bader 	case TO_UNASSIGN:
755b6cba4eeSStefan Bader 	case TO_SIZE:
756cced1dd4SMichael Holzheu 	case TO_KEKL_SET:
757cced1dd4SMichael Holzheu 	case TO_KEKL_QUERY:
758e2963062SMichael Holzheu 	case TO_RDC:
759b6cba4eeSStefan Bader 		break;
760b6cba4eeSStefan Bader 	}
761b6cba4eeSStefan Bader 	return TAPE_IO_SUCCESS;
762b6cba4eeSStefan Bader }
763b6cba4eeSStefan Bader 
764b6cba4eeSStefan Bader /*
765eef35c2dSStefan Weil  * This function is called, when error recovery was successful
766b6cba4eeSStefan Bader  */
767b6cba4eeSStefan Bader static inline int
768b6cba4eeSStefan Bader tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request)
769b6cba4eeSStefan Bader {
77073ac36eaSColy Li 	DBF_EVENT(3, "Error Recovery successful for %s\n",
771b6cba4eeSStefan Bader 		  tape_op_verbose[request->op]);
772b6cba4eeSStefan Bader 	return tape_3590_done(device, request);
773b6cba4eeSStefan Bader }
774b6cba4eeSStefan Bader 
775b6cba4eeSStefan Bader /*
776eef35c2dSStefan Weil  * This function is called, when error recovery was not successful
777b6cba4eeSStefan Bader  */
778b6cba4eeSStefan Bader static inline int
779b6cba4eeSStefan Bader tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
780b6cba4eeSStefan Bader 		     struct irb *irb, int rc)
781b6cba4eeSStefan Bader {
782b6cba4eeSStefan Bader 	DBF_EVENT(3, "Error Recovery failed for %s\n",
783b6cba4eeSStefan Bader 		  tape_op_verbose[request->op]);
784b6cba4eeSStefan Bader 	tape_dump_sense_dbf(device, request, irb);
785b6cba4eeSStefan Bader 	return rc;
786b6cba4eeSStefan Bader }
787b6cba4eeSStefan Bader 
788b6cba4eeSStefan Bader /*
789b6cba4eeSStefan Bader  * Error Recovery do retry
790b6cba4eeSStefan Bader  */
791b6cba4eeSStefan Bader static inline int
792b6cba4eeSStefan Bader tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
793b6cba4eeSStefan Bader 		    struct irb *irb)
794b6cba4eeSStefan Bader {
795b6cba4eeSStefan Bader 	DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]);
796b6cba4eeSStefan Bader 	tape_dump_sense_dbf(device, request, irb);
797b6cba4eeSStefan Bader 	return TAPE_IO_RETRY;
798b6cba4eeSStefan Bader }
799b6cba4eeSStefan Bader 
800b6cba4eeSStefan Bader /*
801b6cba4eeSStefan Bader  * Handle unsolicited interrupts
802b6cba4eeSStefan Bader  */
803b6cba4eeSStefan Bader static int
804b6cba4eeSStefan Bader tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
805b6cba4eeSStefan Bader {
80623d805b6SPeter Oberparleiter 	if (irb->scsw.cmd.dstat == DEV_STAT_CHN_END)
807b6cba4eeSStefan Bader 		/* Probably result of halt ssch */
808b6cba4eeSStefan Bader 		return TAPE_IO_PENDING;
80923d805b6SPeter Oberparleiter 	else if (irb->scsw.cmd.dstat == 0x85)
8101b9fd76eSMichael Holzheu 		/* Device Ready */
8111b9fd76eSMichael Holzheu 		DBF_EVENT(3, "unsol.irq! tape ready: %08x\n", device->cdev_id);
81223d805b6SPeter Oberparleiter 	else if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
813b6cba4eeSStefan Bader 		tape_3590_schedule_work(device, TO_READ_ATTMSG);
8141b9fd76eSMichael Holzheu 	} else {
815b6cba4eeSStefan Bader 		DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
816ab640db0SCarsten Otte 		tape_dump_sense_dbf(device, NULL, irb);
817b6cba4eeSStefan Bader 	}
8181b9fd76eSMichael Holzheu 	/* check medium state */
8191b9fd76eSMichael Holzheu 	tape_3590_schedule_work(device, TO_MSEN);
820b6cba4eeSStefan Bader 	return TAPE_IO_SUCCESS;
821b6cba4eeSStefan Bader }
822b6cba4eeSStefan Bader 
823b6cba4eeSStefan Bader /*
824b6cba4eeSStefan Bader  * Basic Recovery routine
825b6cba4eeSStefan Bader  */
826b6cba4eeSStefan Bader static int
827b6cba4eeSStefan Bader tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
828b6cba4eeSStefan Bader 		    struct irb *irb, int rc)
829b6cba4eeSStefan Bader {
830b6cba4eeSStefan Bader 	struct tape_3590_sense *sense;
831b6cba4eeSStefan Bader 
832b6cba4eeSStefan Bader 	sense = (struct tape_3590_sense *) irb->ecw;
833b6cba4eeSStefan Bader 
834b6cba4eeSStefan Bader 	switch (sense->bra) {
835b6cba4eeSStefan Bader 	case SENSE_BRA_PER:
836b6cba4eeSStefan Bader 		return tape_3590_erp_failed(device, request, irb, rc);
837b6cba4eeSStefan Bader 	case SENSE_BRA_CONT:
838b6cba4eeSStefan Bader 		return tape_3590_erp_succeded(device, request);
839b6cba4eeSStefan Bader 	case SENSE_BRA_RE:
840b6cba4eeSStefan Bader 		return tape_3590_erp_retry(device, request, irb);
841b6cba4eeSStefan Bader 	case SENSE_BRA_DRE:
842b6cba4eeSStefan Bader 		return tape_3590_erp_failed(device, request, irb, rc);
843b6cba4eeSStefan Bader 	default:
844b6cba4eeSStefan Bader 		BUG();
845b6cba4eeSStefan Bader 		return TAPE_IO_STOP;
846b6cba4eeSStefan Bader 	}
847b6cba4eeSStefan Bader }
848b6cba4eeSStefan Bader 
849b6cba4eeSStefan Bader /*
850b6cba4eeSStefan Bader  *  RDL: Read Device (buffered) log
851b6cba4eeSStefan Bader  */
852b6cba4eeSStefan Bader static int
853b6cba4eeSStefan Bader tape_3590_erp_read_buf_log(struct tape_device *device,
854b6cba4eeSStefan Bader 			   struct tape_request *request, struct irb *irb)
855b6cba4eeSStefan Bader {
856b6cba4eeSStefan Bader 	/*
857b6cba4eeSStefan Bader 	 * We just do the basic error recovery at the moment (retry).
858b6cba4eeSStefan Bader 	 * Perhaps in the future, we read the log and dump it somewhere...
859b6cba4eeSStefan Bader 	 */
860b6cba4eeSStefan Bader 	return tape_3590_erp_basic(device, request, irb, -EIO);
861b6cba4eeSStefan Bader }
862b6cba4eeSStefan Bader 
863b6cba4eeSStefan Bader /*
864b6cba4eeSStefan Bader  *  SWAP: Swap Devices
865b6cba4eeSStefan Bader  */
866b6cba4eeSStefan Bader static int
867b6cba4eeSStefan Bader tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
868b6cba4eeSStefan Bader 		   struct irb *irb)
869b6cba4eeSStefan Bader {
870b6cba4eeSStefan Bader 	/*
871b6cba4eeSStefan Bader 	 * This error recovery should swap the tapes
872b6cba4eeSStefan Bader 	 * if the original has a problem. The operation
873b6cba4eeSStefan Bader 	 * should proceed with the new tape... this
874b6cba4eeSStefan Bader 	 * should probably be done in user space!
875b6cba4eeSStefan Bader 	 */
876ab640db0SCarsten Otte 	dev_warn (&device->cdev->dev, "The tape medium must be loaded into a "
877ab640db0SCarsten Otte 		"different tape unit\n");
878b6cba4eeSStefan Bader 	return tape_3590_erp_basic(device, request, irb, -EIO);
879b6cba4eeSStefan Bader }
880b6cba4eeSStefan Bader 
881b6cba4eeSStefan Bader /*
882b6cba4eeSStefan Bader  *  LBY: Long Busy
883b6cba4eeSStefan Bader  */
884b6cba4eeSStefan Bader static int
885b6cba4eeSStefan Bader tape_3590_erp_long_busy(struct tape_device *device,
886b6cba4eeSStefan Bader 			struct tape_request *request, struct irb *irb)
887b6cba4eeSStefan Bader {
888cced1dd4SMichael Holzheu 	DBF_EVENT(6, "Device is busy\n");
889cced1dd4SMichael Holzheu 	return TAPE_IO_LONG_BUSY;
890b6cba4eeSStefan Bader }
891b6cba4eeSStefan Bader 
892b6cba4eeSStefan Bader /*
893b6cba4eeSStefan Bader  *  SPI: Special Intercept
894b6cba4eeSStefan Bader  */
895b6cba4eeSStefan Bader static int
896b6cba4eeSStefan Bader tape_3590_erp_special_interrupt(struct tape_device *device,
897b6cba4eeSStefan Bader 				struct tape_request *request, struct irb *irb)
898b6cba4eeSStefan Bader {
899b6cba4eeSStefan Bader 	return tape_3590_erp_basic(device, request, irb, -EIO);
900b6cba4eeSStefan Bader }
901b6cba4eeSStefan Bader 
902b6cba4eeSStefan Bader /*
903b6cba4eeSStefan Bader  *  RDA: Read Alternate
904b6cba4eeSStefan Bader  */
905b6cba4eeSStefan Bader static int
906b6cba4eeSStefan Bader tape_3590_erp_read_alternate(struct tape_device *device,
907b6cba4eeSStefan Bader 			     struct tape_request *request, struct irb *irb)
908b6cba4eeSStefan Bader {
909b6cba4eeSStefan Bader 	struct tape_3590_disc_data *data;
910b6cba4eeSStefan Bader 
911b6cba4eeSStefan Bader 	/*
912b6cba4eeSStefan Bader 	 * The issued Read Backward or Read Previous command is not
913b6cba4eeSStefan Bader 	 * supported by the device
914b6cba4eeSStefan Bader 	 * The recovery action should be to issue another command:
915b6cba4eeSStefan Bader 	 * Read Revious: if Read Backward is not supported
916b6cba4eeSStefan Bader 	 * Read Backward: if Read Previous is not supported
917b6cba4eeSStefan Bader 	 */
918b6cba4eeSStefan Bader 	data = device->discdata;
919b6cba4eeSStefan Bader 	if (data->read_back_op == READ_PREVIOUS) {
920b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
921b6cba4eeSStefan Bader 			  device->cdev_id);
922b6cba4eeSStefan Bader 		data->read_back_op = READ_BACKWARD;
923b6cba4eeSStefan Bader 	} else {
924b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
925b6cba4eeSStefan Bader 			  device->cdev_id);
926b6cba4eeSStefan Bader 		data->read_back_op = READ_PREVIOUS;
927b6cba4eeSStefan Bader 	}
928b6cba4eeSStefan Bader 	tape_3590_read_opposite(device, request);
929b6cba4eeSStefan Bader 	return tape_3590_erp_retry(device, request, irb);
930b6cba4eeSStefan Bader }
931b6cba4eeSStefan Bader 
932b6cba4eeSStefan Bader /*
933b6cba4eeSStefan Bader  * Error Recovery read opposite
934b6cba4eeSStefan Bader  */
935b6cba4eeSStefan Bader static int
936b6cba4eeSStefan Bader tape_3590_erp_read_opposite(struct tape_device *device,
937b6cba4eeSStefan Bader 			    struct tape_request *request, struct irb *irb)
938b6cba4eeSStefan Bader {
939b6cba4eeSStefan Bader 	switch (request->op) {
940b6cba4eeSStefan Bader 	case TO_RFO:
941b6cba4eeSStefan Bader 		/*
942b6cba4eeSStefan Bader 		 * We did read forward, but the data could not be read.
943b6cba4eeSStefan Bader 		 * We will read backward and then skip forward again.
944b6cba4eeSStefan Bader 		 */
945b6cba4eeSStefan Bader 		tape_3590_read_opposite(device, request);
946b6cba4eeSStefan Bader 		return tape_3590_erp_retry(device, request, irb);
947b6cba4eeSStefan Bader 	case TO_RBA:
948b6cba4eeSStefan Bader 		/* We tried to read forward and backward, but hat no success */
949b6cba4eeSStefan Bader 		return tape_3590_erp_failed(device, request, irb, -EIO);
950b6cba4eeSStefan Bader 		break;
951b6cba4eeSStefan Bader 	default:
952b6cba4eeSStefan Bader 		return tape_3590_erp_failed(device, request, irb, -EIO);
953b6cba4eeSStefan Bader 	}
954b6cba4eeSStefan Bader }
955b6cba4eeSStefan Bader 
956b6cba4eeSStefan Bader /*
957b6cba4eeSStefan Bader  * Print an MIM (Media Information  Message) (message code f0)
958b6cba4eeSStefan Bader  */
959b6cba4eeSStefan Bader static void
960b6cba4eeSStefan Bader tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
961b6cba4eeSStefan Bader {
962b6cba4eeSStefan Bader 	struct tape_3590_sense *sense;
963ab640db0SCarsten Otte 	char *exception, *service;
964ab640db0SCarsten Otte 
965ab640db0SCarsten Otte 	exception = kmalloc(BUFSIZE, GFP_ATOMIC);
966ab640db0SCarsten Otte 	service = kmalloc(BUFSIZE, GFP_ATOMIC);
967ab640db0SCarsten Otte 
968ab640db0SCarsten Otte 	if (!exception || !service)
969ab640db0SCarsten Otte 		goto out_nomem;
970b6cba4eeSStefan Bader 
971b6cba4eeSStefan Bader 	sense = (struct tape_3590_sense *) irb->ecw;
972b6cba4eeSStefan Bader 	/* Exception Message */
973b6cba4eeSStefan Bader 	switch (sense->fmt.f70.emc) {
974b6cba4eeSStefan Bader 	case 0x02:
975ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Data degraded");
976b6cba4eeSStefan Bader 		break;
977b6cba4eeSStefan Bader 	case 0x03:
978ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Data degraded in partion %i",
979ab640db0SCarsten Otte 			sense->fmt.f70.mp);
980b6cba4eeSStefan Bader 		break;
981b6cba4eeSStefan Bader 	case 0x04:
982ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Medium degraded");
983b6cba4eeSStefan Bader 		break;
984b6cba4eeSStefan Bader 	case 0x05:
985ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Medium degraded in partition %i",
986ab640db0SCarsten Otte 			sense->fmt.f70.mp);
987b6cba4eeSStefan Bader 		break;
988b6cba4eeSStefan Bader 	case 0x06:
989ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Block 0 Error");
990b6cba4eeSStefan Bader 		break;
991b6cba4eeSStefan Bader 	case 0x07:
992ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Medium Exception 0x%02x",
993ab640db0SCarsten Otte 			sense->fmt.f70.md);
994b6cba4eeSStefan Bader 		break;
995b6cba4eeSStefan Bader 	default:
996ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "0x%02x",
997ab640db0SCarsten Otte 			sense->fmt.f70.emc);
998b6cba4eeSStefan Bader 		break;
999b6cba4eeSStefan Bader 	}
1000b6cba4eeSStefan Bader 	/* Service Message */
1001b6cba4eeSStefan Bader 	switch (sense->fmt.f70.smc) {
1002b6cba4eeSStefan Bader 	case 0x02:
1003ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Reference Media maintenance "
1004ab640db0SCarsten Otte 			"procedure %i", sense->fmt.f70.md);
1005b6cba4eeSStefan Bader 		break;
1006b6cba4eeSStefan Bader 	default:
1007ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "0x%02x",
1008ab640db0SCarsten Otte 			sense->fmt.f70.smc);
1009b6cba4eeSStefan Bader 		break;
1010b6cba4eeSStefan Bader 	}
1011ab640db0SCarsten Otte 
1012ab640db0SCarsten Otte 	dev_warn (&device->cdev->dev, "Tape media information: exception %s, "
1013ab640db0SCarsten Otte 		"service %s\n", exception, service);
1014ab640db0SCarsten Otte 
1015ab640db0SCarsten Otte out_nomem:
1016ab640db0SCarsten Otte 	kfree(exception);
1017ab640db0SCarsten Otte 	kfree(service);
1018b6cba4eeSStefan Bader }
1019b6cba4eeSStefan Bader 
1020b6cba4eeSStefan Bader /*
1021b6cba4eeSStefan Bader  * Print an I/O Subsystem Service Information Message (message code f1)
1022b6cba4eeSStefan Bader  */
1023b6cba4eeSStefan Bader static void
1024b6cba4eeSStefan Bader tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
1025b6cba4eeSStefan Bader {
1026b6cba4eeSStefan Bader 	struct tape_3590_sense *sense;
1027ab640db0SCarsten Otte 	char *exception, *service;
1028ab640db0SCarsten Otte 
1029ab640db0SCarsten Otte 	exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1030ab640db0SCarsten Otte 	service = kmalloc(BUFSIZE, GFP_ATOMIC);
1031ab640db0SCarsten Otte 
1032ab640db0SCarsten Otte 	if (!exception || !service)
1033ab640db0SCarsten Otte 		goto out_nomem;
1034b6cba4eeSStefan Bader 
1035b6cba4eeSStefan Bader 	sense = (struct tape_3590_sense *) irb->ecw;
1036b6cba4eeSStefan Bader 	/* Exception Message */
1037b6cba4eeSStefan Bader 	switch (sense->fmt.f71.emc) {
1038b6cba4eeSStefan Bader 	case 0x01:
1039ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Effect of failure is unknown");
1040b6cba4eeSStefan Bader 		break;
1041b6cba4eeSStefan Bader 	case 0x02:
1042ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "CU Exception - no performance "
1043ab640db0SCarsten Otte 			"impact");
1044b6cba4eeSStefan Bader 		break;
1045b6cba4eeSStefan Bader 	case 0x03:
1046ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "CU Exception on channel "
1047ab640db0SCarsten Otte 			"interface 0x%02x", sense->fmt.f71.md[0]);
1048b6cba4eeSStefan Bader 		break;
1049b6cba4eeSStefan Bader 	case 0x04:
1050ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "CU Exception on device path "
1051ab640db0SCarsten Otte 			"0x%02x", sense->fmt.f71.md[0]);
1052b6cba4eeSStefan Bader 		break;
1053b6cba4eeSStefan Bader 	case 0x05:
1054ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "CU Exception on library path "
1055ab640db0SCarsten Otte 			"0x%02x", sense->fmt.f71.md[0]);
1056b6cba4eeSStefan Bader 		break;
1057b6cba4eeSStefan Bader 	case 0x06:
1058ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "CU Exception on node 0x%02x",
1059ab640db0SCarsten Otte 			sense->fmt.f71.md[0]);
1060b6cba4eeSStefan Bader 		break;
1061b6cba4eeSStefan Bader 	case 0x07:
1062ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "CU Exception on partition "
1063ab640db0SCarsten Otte 			"0x%02x", sense->fmt.f71.md[0]);
1064b6cba4eeSStefan Bader 		break;
1065b6cba4eeSStefan Bader 	default:
1066ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "0x%02x",
1067ab640db0SCarsten Otte 			sense->fmt.f71.emc);
1068b6cba4eeSStefan Bader 	}
1069b6cba4eeSStefan Bader 	/* Service Message */
1070b6cba4eeSStefan Bader 	switch (sense->fmt.f71.smc) {
1071b6cba4eeSStefan Bader 	case 0x01:
1072ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Repair impact is unknown");
1073b6cba4eeSStefan Bader 		break;
1074b6cba4eeSStefan Bader 	case 0x02:
1075ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Repair will not impact cu "
1076ab640db0SCarsten Otte 			"performance");
1077b6cba4eeSStefan Bader 		break;
1078b6cba4eeSStefan Bader 	case 0x03:
1079b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1080ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable node "
1081ab640db0SCarsten Otte 				"0x%x on CU", sense->fmt.f71.md[1]);
1082b6cba4eeSStefan Bader 		else
1083ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1084ab640db0SCarsten Otte 				"nodes (0x%x-0x%x) on CU", sense->fmt.f71.md[1],
1085ab640db0SCarsten Otte 				sense->fmt.f71.md[2]);
1086b6cba4eeSStefan Bader 		break;
1087b6cba4eeSStefan Bader 	case 0x04:
1088b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1089ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1090ab640db0SCarsten Otte 				"channel path 0x%x on CU",
1091b6cba4eeSStefan Bader 				sense->fmt.f71.md[1]);
1092b6cba4eeSStefan Bader 		else
1093ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable cannel"
1094ab640db0SCarsten Otte 				" paths (0x%x-0x%x) on CU",
1095b6cba4eeSStefan Bader 				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1096b6cba4eeSStefan Bader 		break;
1097b6cba4eeSStefan Bader 	case 0x05:
1098b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1099ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable device"
1100ab640db0SCarsten Otte 				" path 0x%x on CU", sense->fmt.f71.md[1]);
1101b6cba4eeSStefan Bader 		else
1102ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable device"
1103ab640db0SCarsten Otte 				" paths (0x%x-0x%x) on CU",
1104b6cba4eeSStefan Bader 				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1105b6cba4eeSStefan Bader 		break;
1106b6cba4eeSStefan Bader 	case 0x06:
1107b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1108ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1109ab640db0SCarsten Otte 				"library path 0x%x on CU",
1110b6cba4eeSStefan Bader 				sense->fmt.f71.md[1]);
1111b6cba4eeSStefan Bader 		else
1112ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1113ab640db0SCarsten Otte 				"library paths (0x%x-0x%x) on CU",
1114b6cba4eeSStefan Bader 				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1115b6cba4eeSStefan Bader 		break;
1116b6cba4eeSStefan Bader 	case 0x07:
1117ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Repair will disable access to CU");
1118b6cba4eeSStefan Bader 		break;
1119b6cba4eeSStefan Bader 	default:
1120ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "0x%02x",
1121ab640db0SCarsten Otte 			sense->fmt.f71.smc);
1122b6cba4eeSStefan Bader 	}
1123ab640db0SCarsten Otte 
1124ab640db0SCarsten Otte 	dev_warn (&device->cdev->dev, "I/O subsystem information: exception"
1125ab640db0SCarsten Otte 		" %s, service %s\n", exception, service);
1126ab640db0SCarsten Otte out_nomem:
1127ab640db0SCarsten Otte 	kfree(exception);
1128ab640db0SCarsten Otte 	kfree(service);
1129b6cba4eeSStefan Bader }
1130b6cba4eeSStefan Bader 
1131b6cba4eeSStefan Bader /*
1132b6cba4eeSStefan Bader  * Print an Device Subsystem Service Information Message (message code f2)
1133b6cba4eeSStefan Bader  */
1134b6cba4eeSStefan Bader static void
1135b6cba4eeSStefan Bader tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
1136b6cba4eeSStefan Bader {
1137b6cba4eeSStefan Bader 	struct tape_3590_sense *sense;
1138ab640db0SCarsten Otte 	char *exception, *service;
1139ab640db0SCarsten Otte 
1140ab640db0SCarsten Otte 	exception = kmalloc(BUFSIZE, GFP_ATOMIC);
1141ab640db0SCarsten Otte 	service = kmalloc(BUFSIZE, GFP_ATOMIC);
1142ab640db0SCarsten Otte 
1143ab640db0SCarsten Otte 	if (!exception || !service)
1144ab640db0SCarsten Otte 		goto out_nomem;
1145b6cba4eeSStefan Bader 
1146b6cba4eeSStefan Bader 	sense = (struct tape_3590_sense *) irb->ecw;
1147b6cba4eeSStefan Bader 	/* Exception Message */
1148b6cba4eeSStefan Bader 	switch (sense->fmt.f71.emc) {
1149b6cba4eeSStefan Bader 	case 0x01:
1150ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "Effect of failure is unknown");
1151b6cba4eeSStefan Bader 		break;
1152b6cba4eeSStefan Bader 	case 0x02:
1153ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "DV Exception - no performance"
1154ab640db0SCarsten Otte 			" impact");
1155b6cba4eeSStefan Bader 		break;
1156b6cba4eeSStefan Bader 	case 0x03:
1157ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "DV Exception on channel "
1158ab640db0SCarsten Otte 			"interface 0x%02x", sense->fmt.f71.md[0]);
1159b6cba4eeSStefan Bader 		break;
1160b6cba4eeSStefan Bader 	case 0x04:
1161ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "DV Exception on loader 0x%02x",
1162ab640db0SCarsten Otte 			sense->fmt.f71.md[0]);
1163b6cba4eeSStefan Bader 		break;
1164b6cba4eeSStefan Bader 	case 0x05:
1165ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "DV Exception on message display"
1166ab640db0SCarsten Otte 			" 0x%02x", sense->fmt.f71.md[0]);
1167b6cba4eeSStefan Bader 		break;
1168b6cba4eeSStefan Bader 	case 0x06:
1169ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "DV Exception in tape path");
1170b6cba4eeSStefan Bader 		break;
1171b6cba4eeSStefan Bader 	case 0x07:
1172ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "DV Exception in drive");
1173b6cba4eeSStefan Bader 		break;
1174b6cba4eeSStefan Bader 	default:
1175ab640db0SCarsten Otte 		snprintf(exception, BUFSIZE, "0x%02x",
1176ab640db0SCarsten Otte 			sense->fmt.f71.emc);
1177b6cba4eeSStefan Bader 	}
1178b6cba4eeSStefan Bader 	/* Service Message */
1179b6cba4eeSStefan Bader 	switch (sense->fmt.f71.smc) {
1180b6cba4eeSStefan Bader 	case 0x01:
1181ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Repair impact is unknown");
1182b6cba4eeSStefan Bader 		break;
1183b6cba4eeSStefan Bader 	case 0x02:
1184ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Repair will not impact device "
1185ab640db0SCarsten Otte 			"performance");
1186b6cba4eeSStefan Bader 		break;
1187b6cba4eeSStefan Bader 	case 0x03:
1188b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1189ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1190ab640db0SCarsten Otte 				"channel path 0x%x on DV",
1191b6cba4eeSStefan Bader 				sense->fmt.f71.md[1]);
1192b6cba4eeSStefan Bader 		else
1193ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1194ab640db0SCarsten Otte 				"channel path (0x%x-0x%x) on DV",
1195b6cba4eeSStefan Bader 				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1196b6cba4eeSStefan Bader 		break;
1197b6cba4eeSStefan Bader 	case 0x04:
1198b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1199ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1200ab640db0SCarsten Otte 				"interface 0x%x on DV", sense->fmt.f71.md[1]);
1201b6cba4eeSStefan Bader 		else
1202ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1203ab640db0SCarsten Otte 				"interfaces (0x%x-0x%x) on DV",
1204b6cba4eeSStefan Bader 				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1205b6cba4eeSStefan Bader 		break;
1206b6cba4eeSStefan Bader 	case 0x05:
1207b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1208ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable loader"
1209ab640db0SCarsten Otte 				" 0x%x on DV", sense->fmt.f71.md[1]);
1210b6cba4eeSStefan Bader 		else
1211ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable loader"
1212ab640db0SCarsten Otte 				" (0x%x-0x%x) on DV",
1213b6cba4eeSStefan Bader 				sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1214b6cba4eeSStefan Bader 		break;
1215b6cba4eeSStefan Bader 	case 0x07:
1216ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Repair will disable access to DV");
1217b6cba4eeSStefan Bader 		break;
1218b6cba4eeSStefan Bader 	case 0x08:
1219b6cba4eeSStefan Bader 		if (sense->fmt.f71.mdf == 0)
1220ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1221ab640db0SCarsten Otte 				"message display 0x%x on DV",
1222b6cba4eeSStefan Bader 				sense->fmt.f71.md[1]);
1223b6cba4eeSStefan Bader 		else
1224ab640db0SCarsten Otte 			snprintf(service, BUFSIZE, "Repair will disable "
1225ab640db0SCarsten Otte 				"message displays (0x%x-0x%x) on DV",
1226b6cba4eeSStefan Bader 				 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
1227b6cba4eeSStefan Bader 		break;
1228b6cba4eeSStefan Bader 	case 0x09:
1229ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "Clean DV");
1230b6cba4eeSStefan Bader 		break;
1231b6cba4eeSStefan Bader 	default:
1232ab640db0SCarsten Otte 		snprintf(service, BUFSIZE, "0x%02x",
1233ab640db0SCarsten Otte 			sense->fmt.f71.smc);
1234b6cba4eeSStefan Bader 	}
1235ab640db0SCarsten Otte 
1236ab640db0SCarsten Otte 	dev_warn (&device->cdev->dev, "Device subsystem information: exception"
1237ab640db0SCarsten Otte 		" %s, service %s\n", exception, service);
1238ab640db0SCarsten Otte out_nomem:
1239ab640db0SCarsten Otte 	kfree(exception);
1240ab640db0SCarsten Otte 	kfree(service);
1241b6cba4eeSStefan Bader }
1242b6cba4eeSStefan Bader 
1243b6cba4eeSStefan Bader /*
1244b6cba4eeSStefan Bader  * Print standard ERA Message
1245b6cba4eeSStefan Bader  */
1246b6cba4eeSStefan Bader static void
1247b6cba4eeSStefan Bader tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
1248b6cba4eeSStefan Bader {
1249b6cba4eeSStefan Bader 	struct tape_3590_sense *sense;
1250b6cba4eeSStefan Bader 
1251b6cba4eeSStefan Bader 	sense = (struct tape_3590_sense *) irb->ecw;
1252b6cba4eeSStefan Bader 	if (sense->mc == 0)
1253b6cba4eeSStefan Bader 		return;
1254b6cba4eeSStefan Bader 	if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) {
1255b6cba4eeSStefan Bader 		if (tape_3590_msg[sense->mc] != NULL)
1256ab640db0SCarsten Otte 			dev_warn (&device->cdev->dev, "The tape unit has "
1257ab640db0SCarsten Otte 				"issued sense message %s\n",
1258b6cba4eeSStefan Bader 				tape_3590_msg[sense->mc]);
1259ab640db0SCarsten Otte 		else
1260ab640db0SCarsten Otte 			dev_warn (&device->cdev->dev, "The tape unit has "
1261ab640db0SCarsten Otte 				"issued an unknown sense message code 0x%x\n",
1262ab640db0SCarsten Otte 				sense->mc);
1263b6cba4eeSStefan Bader 		return;
1264b6cba4eeSStefan Bader 	}
1265b6cba4eeSStefan Bader 	if (sense->mc == 0xf0) {
1266b6cba4eeSStefan Bader 		/* Standard Media Information Message */
1267ab640db0SCarsten Otte 		dev_warn (&device->cdev->dev, "MIM SEV=%i, MC=%02x, ES=%x/%x, "
1268ab640db0SCarsten Otte 			"RC=%02x-%04x-%02x\n", sense->fmt.f70.sev, sense->mc,
1269b6cba4eeSStefan Bader 			sense->fmt.f70.emc, sense->fmt.f70.smc,
1270b6cba4eeSStefan Bader 			sense->fmt.f70.refcode, sense->fmt.f70.mid,
1271b6cba4eeSStefan Bader 			sense->fmt.f70.fid);
1272b6cba4eeSStefan Bader 		tape_3590_print_mim_msg_f0(device, irb);
1273b6cba4eeSStefan Bader 		return;
1274b6cba4eeSStefan Bader 	}
1275b6cba4eeSStefan Bader 	if (sense->mc == 0xf1) {
1276b6cba4eeSStefan Bader 		/* Standard I/O Subsystem Service Information Message */
1277ab640db0SCarsten Otte 		dev_warn (&device->cdev->dev, "IOSIM SEV=%i, DEVTYPE=3590/%02x,"
1278b6cba4eeSStefan Bader 			" MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1279ab640db0SCarsten Otte 			sense->fmt.f71.sev, device->cdev->id.dev_model,
1280ab640db0SCarsten Otte 			sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1281ab640db0SCarsten Otte 			sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1282ab640db0SCarsten Otte 			sense->fmt.f71.refcode3);
1283b6cba4eeSStefan Bader 		tape_3590_print_io_sim_msg_f1(device, irb);
1284b6cba4eeSStefan Bader 		return;
1285b6cba4eeSStefan Bader 	}
1286b6cba4eeSStefan Bader 	if (sense->mc == 0xf2) {
1287b6cba4eeSStefan Bader 		/* Standard Device Service Information Message */
1288ab640db0SCarsten Otte 		dev_warn (&device->cdev->dev, "DEVSIM SEV=%i, DEVTYPE=3590/%02x"
1289ab640db0SCarsten Otte 			", MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
1290ab640db0SCarsten Otte 			sense->fmt.f71.sev, device->cdev->id.dev_model,
1291ab640db0SCarsten Otte 			sense->mc, sense->fmt.f71.emc, sense->fmt.f71.smc,
1292ab640db0SCarsten Otte 			sense->fmt.f71.refcode1, sense->fmt.f71.refcode2,
1293ab640db0SCarsten Otte 			sense->fmt.f71.refcode3);
1294b6cba4eeSStefan Bader 		tape_3590_print_dev_sim_msg_f2(device, irb);
1295b6cba4eeSStefan Bader 		return;
1296b6cba4eeSStefan Bader 	}
1297b6cba4eeSStefan Bader 	if (sense->mc == 0xf3) {
1298b6cba4eeSStefan Bader 		/* Standard Library Service Information Message */
1299b6cba4eeSStefan Bader 		return;
1300b6cba4eeSStefan Bader 	}
1301ab640db0SCarsten Otte 	dev_warn (&device->cdev->dev, "The tape unit has issued an unknown "
1302ab640db0SCarsten Otte 		"sense message code %x\n", sense->mc);
1303b6cba4eeSStefan Bader }
1304b6cba4eeSStefan Bader 
1305cced1dd4SMichael Holzheu static int tape_3590_crypt_error(struct tape_device *device,
1306cced1dd4SMichael Holzheu 				 struct tape_request *request, struct irb *irb)
1307cced1dd4SMichael Holzheu {
1308160fbf2eSHeiko Carstens 	u8 cu_rc;
1309cced1dd4SMichael Holzheu 	u16 ekm_rc2;
13102a0217d5SKay Sievers 	char *sense;
1311cced1dd4SMichael Holzheu 
1312cced1dd4SMichael Holzheu 	sense = ((struct tape_3590_sense *) irb->ecw)->fmt.data;
1313cced1dd4SMichael Holzheu 	cu_rc = sense[0];
1314cced1dd4SMichael Holzheu 	ekm_rc2 = *((u16*) &sense[10]);
1315cced1dd4SMichael Holzheu 	if ((cu_rc == 0) && (ekm_rc2 == 0xee31))
1316cced1dd4SMichael Holzheu 		/* key not defined on EKM */
1317cced1dd4SMichael Holzheu 		return tape_3590_erp_basic(device, request, irb, -EKEYREJECTED);
1318cced1dd4SMichael Holzheu 	if ((cu_rc == 1) || (cu_rc == 2))
1319cced1dd4SMichael Holzheu 		/* No connection to EKM */
1320cced1dd4SMichael Holzheu 		return tape_3590_erp_basic(device, request, irb, -ENOTCONN);
1321cced1dd4SMichael Holzheu 
1322ab640db0SCarsten Otte 	dev_err (&device->cdev->dev, "The tape unit failed to obtain the "
1323ab640db0SCarsten Otte 		"encryption key from EKM\n");
1324cced1dd4SMichael Holzheu 
1325cced1dd4SMichael Holzheu 	return tape_3590_erp_basic(device, request, irb, -ENOKEY);
1326cced1dd4SMichael Holzheu }
1327cced1dd4SMichael Holzheu 
1328b6cba4eeSStefan Bader /*
1329b6cba4eeSStefan Bader  *  3590 error Recovery routine:
1330b6cba4eeSStefan Bader  *  If possible, it tries to recover from the error. If this is not possible,
1331b6cba4eeSStefan Bader  *  inform the user about the problem.
1332b6cba4eeSStefan Bader  */
1333b6cba4eeSStefan Bader static int
1334b6cba4eeSStefan Bader tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
1335b6cba4eeSStefan Bader 		     struct irb *irb)
1336b6cba4eeSStefan Bader {
1337b6cba4eeSStefan Bader 	struct tape_3590_sense *sense;
1338b6cba4eeSStefan Bader 
1339b6cba4eeSStefan Bader 	sense = (struct tape_3590_sense *) irb->ecw;
1340b6cba4eeSStefan Bader 
1341cced1dd4SMichael Holzheu 	DBF_EVENT(6, "Unit Check: RQC = %x\n", sense->rc_rqc);
1342cced1dd4SMichael Holzheu 
1343b6cba4eeSStefan Bader 	/*
1344b6cba4eeSStefan Bader 	 * First check all RC-QRCs where we want to do something special
1345b6cba4eeSStefan Bader 	 *   - "break":     basic error recovery is done
1346b6cba4eeSStefan Bader 	 *   - "goto out:": just print error message if available
1347b6cba4eeSStefan Bader 	 */
1348b6cba4eeSStefan Bader 	switch (sense->rc_rqc) {
1349b6cba4eeSStefan Bader 
1350b6cba4eeSStefan Bader 	case 0x1110:
1351b6cba4eeSStefan Bader 		tape_3590_print_era_msg(device, irb);
1352b6cba4eeSStefan Bader 		return tape_3590_erp_read_buf_log(device, request, irb);
1353b6cba4eeSStefan Bader 
1354b6cba4eeSStefan Bader 	case 0x2011:
1355b6cba4eeSStefan Bader 		tape_3590_print_era_msg(device, irb);
1356b6cba4eeSStefan Bader 		return tape_3590_erp_read_alternate(device, request, irb);
1357b6cba4eeSStefan Bader 
1358b6cba4eeSStefan Bader 	case 0x2230:
1359b6cba4eeSStefan Bader 	case 0x2231:
1360b6cba4eeSStefan Bader 		tape_3590_print_era_msg(device, irb);
1361b6cba4eeSStefan Bader 		return tape_3590_erp_special_interrupt(device, request, irb);
1362cced1dd4SMichael Holzheu 	case 0x2240:
1363cced1dd4SMichael Holzheu 		return tape_3590_crypt_error(device, request, irb);
1364b6cba4eeSStefan Bader 
1365b6cba4eeSStefan Bader 	case 0x3010:
1366b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1367b6cba4eeSStefan Bader 			  device->cdev_id);
1368b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1369b6cba4eeSStefan Bader 	case 0x3012:
1370b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1371b6cba4eeSStefan Bader 			  device->cdev_id);
1372b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1373b6cba4eeSStefan Bader 	case 0x3020:
1374b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
1375b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1376b6cba4eeSStefan Bader 
1377b6cba4eeSStefan Bader 	case 0x3122:
1378b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1379b6cba4eeSStefan Bader 			  device->cdev_id);
1380b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EIO);
1381b6cba4eeSStefan Bader 	case 0x3123:
1382b6cba4eeSStefan Bader 		DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1383b6cba4eeSStefan Bader 			  device->cdev_id);
1384b6cba4eeSStefan Bader 		tape_med_state_set(device, MS_UNLOADED);
1385cced1dd4SMichael Holzheu 		tape_3590_schedule_work(device, TO_CRYPT_OFF);
1386b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, 0);
1387b6cba4eeSStefan Bader 
1388b6cba4eeSStefan Bader 	case 0x4010:
1389b6cba4eeSStefan Bader 		/*
1390b6cba4eeSStefan Bader 		 * print additional msg since default msg
1391b6cba4eeSStefan Bader 		 * "device intervention" is not very meaningfull
1392b6cba4eeSStefan Bader 		 */
1393b6cba4eeSStefan Bader 		tape_med_state_set(device, MS_UNLOADED);
1394cced1dd4SMichael Holzheu 		tape_3590_schedule_work(device, TO_CRYPT_OFF);
1395b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1396b6cba4eeSStefan Bader 	case 0x4012:		/* Device Long Busy */
1397cced1dd4SMichael Holzheu 		/* XXX: Also use long busy handling here? */
1398cced1dd4SMichael Holzheu 		DBF_EVENT(6, "(%08x): LONG BUSY\n", device->cdev_id);
1399b6cba4eeSStefan Bader 		tape_3590_print_era_msg(device, irb);
1400cced1dd4SMichael Holzheu 		return tape_3590_erp_basic(device, request, irb, -EBUSY);
1401cced1dd4SMichael Holzheu 	case 0x4014:
1402cced1dd4SMichael Holzheu 		DBF_EVENT(6, "(%08x): Crypto LONG BUSY\n", device->cdev_id);
1403b6cba4eeSStefan Bader 		return tape_3590_erp_long_busy(device, request, irb);
1404b6cba4eeSStefan Bader 
1405b6cba4eeSStefan Bader 	case 0x5010:
1406b6cba4eeSStefan Bader 		if (sense->rac == 0xd0) {
1407b6cba4eeSStefan Bader 			/* Swap */
1408b6cba4eeSStefan Bader 			tape_3590_print_era_msg(device, irb);
1409b6cba4eeSStefan Bader 			return tape_3590_erp_swap(device, request, irb);
1410b6cba4eeSStefan Bader 		}
1411b6cba4eeSStefan Bader 		if (sense->rac == 0x26) {
1412b6cba4eeSStefan Bader 			/* Read Opposite */
1413b6cba4eeSStefan Bader 			tape_3590_print_era_msg(device, irb);
1414b6cba4eeSStefan Bader 			return tape_3590_erp_read_opposite(device, request,
1415b6cba4eeSStefan Bader 							   irb);
1416b6cba4eeSStefan Bader 		}
1417b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EIO);
1418b6cba4eeSStefan Bader 	case 0x5020:
1419b6cba4eeSStefan Bader 	case 0x5021:
1420b6cba4eeSStefan Bader 	case 0x5022:
1421b6cba4eeSStefan Bader 	case 0x5040:
1422b6cba4eeSStefan Bader 	case 0x5041:
1423b6cba4eeSStefan Bader 	case 0x5042:
1424b6cba4eeSStefan Bader 		tape_3590_print_era_msg(device, irb);
1425b6cba4eeSStefan Bader 		return tape_3590_erp_swap(device, request, irb);
1426b6cba4eeSStefan Bader 
1427b6cba4eeSStefan Bader 	case 0x5110:
1428b6cba4eeSStefan Bader 	case 0x5111:
1429b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1430b6cba4eeSStefan Bader 
1431b6cba4eeSStefan Bader 	case 0x5120:
1432b6cba4eeSStefan Bader 	case 0x1120:
1433b6cba4eeSStefan Bader 		tape_med_state_set(device, MS_UNLOADED);
1434cced1dd4SMichael Holzheu 		tape_3590_schedule_work(device, TO_CRYPT_OFF);
1435b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1436b6cba4eeSStefan Bader 
1437b6cba4eeSStefan Bader 	case 0x6020:
1438b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1439b6cba4eeSStefan Bader 
1440b6cba4eeSStefan Bader 	case 0x8011:
1441b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EPERM);
1442b6cba4eeSStefan Bader 	case 0x8013:
1443ab640db0SCarsten Otte 		dev_warn (&device->cdev->dev, "A different host has privileged"
1444ab640db0SCarsten Otte 			" access to the tape unit\n");
1445b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EPERM);
1446b6cba4eeSStefan Bader 	default:
1447b6cba4eeSStefan Bader 		return tape_3590_erp_basic(device, request, irb, -EIO);
1448b6cba4eeSStefan Bader 	}
1449b6cba4eeSStefan Bader }
1450b6cba4eeSStefan Bader 
1451b6cba4eeSStefan Bader /*
1452b6cba4eeSStefan Bader  * 3590 interrupt handler:
1453b6cba4eeSStefan Bader  */
1454b6cba4eeSStefan Bader static int
1455b6cba4eeSStefan Bader tape_3590_irq(struct tape_device *device, struct tape_request *request,
1456b6cba4eeSStefan Bader 	      struct irb *irb)
1457b6cba4eeSStefan Bader {
1458b6cba4eeSStefan Bader 	if (request == NULL)
1459b6cba4eeSStefan Bader 		return tape_3590_unsolicited_irq(device, irb);
1460b6cba4eeSStefan Bader 
146123d805b6SPeter Oberparleiter 	if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
146223d805b6SPeter Oberparleiter 	    (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
146323d805b6SPeter Oberparleiter 	    (request->op == TO_WRI)) {
1464b6cba4eeSStefan Bader 		/* Write at end of volume */
1465b6cba4eeSStefan Bader 		DBF_EVENT(2, "End of volume\n");
1466b6cba4eeSStefan Bader 		return tape_3590_erp_failed(device, request, irb, -ENOSPC);
1467b6cba4eeSStefan Bader 	}
1468b6cba4eeSStefan Bader 
146923d805b6SPeter Oberparleiter 	if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
1470b6cba4eeSStefan Bader 		return tape_3590_unit_check(device, request, irb);
1471b6cba4eeSStefan Bader 
147223d805b6SPeter Oberparleiter 	if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
147323d805b6SPeter Oberparleiter 		if (irb->scsw.cmd.dstat == DEV_STAT_UNIT_EXCEP) {
1474b6cba4eeSStefan Bader 			if (request->op == TO_FSB || request->op == TO_BSB)
1475b6cba4eeSStefan Bader 				request->rescnt++;
1476b6cba4eeSStefan Bader 			else
1477b6cba4eeSStefan Bader 				DBF_EVENT(5, "Unit Exception!\n");
1478b6cba4eeSStefan Bader 		}
1479b6cba4eeSStefan Bader 
1480b6cba4eeSStefan Bader 		return tape_3590_done(device, request);
1481b6cba4eeSStefan Bader 	}
1482b6cba4eeSStefan Bader 
148323d805b6SPeter Oberparleiter 	if (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) {
1484b6cba4eeSStefan Bader 		DBF_EVENT(2, "cannel end\n");
1485b6cba4eeSStefan Bader 		return TAPE_IO_PENDING;
1486b6cba4eeSStefan Bader 	}
1487b6cba4eeSStefan Bader 
148823d805b6SPeter Oberparleiter 	if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
1489b6cba4eeSStefan Bader 		DBF_EVENT(2, "Unit Attention when busy..\n");
1490b6cba4eeSStefan Bader 		return TAPE_IO_PENDING;
1491b6cba4eeSStefan Bader 	}
1492b6cba4eeSStefan Bader 
1493b6cba4eeSStefan Bader 	DBF_EVENT(6, "xunknownirq\n");
1494ab640db0SCarsten Otte 	tape_dump_sense_dbf(device, request, irb);
1495b6cba4eeSStefan Bader 	return TAPE_IO_STOP;
1496b6cba4eeSStefan Bader }
1497b6cba4eeSStefan Bader 
1498e2963062SMichael Holzheu 
1499e2963062SMichael Holzheu static int tape_3590_read_dev_chars(struct tape_device *device,
1500e2963062SMichael Holzheu 				    struct tape_3590_rdc_data *rdc_data)
1501e2963062SMichael Holzheu {
1502e2963062SMichael Holzheu 	int rc;
1503e2963062SMichael Holzheu 	struct tape_request *request;
1504e2963062SMichael Holzheu 
1505e2963062SMichael Holzheu 	request = tape_alloc_request(1, sizeof(*rdc_data));
1506e2963062SMichael Holzheu 	if (IS_ERR(request))
1507e2963062SMichael Holzheu 		return PTR_ERR(request);
1508e2963062SMichael Holzheu 	request->op = TO_RDC;
1509e2963062SMichael Holzheu 	tape_ccw_end(request->cpaddr, CCW_CMD_RDC, sizeof(*rdc_data),
1510e2963062SMichael Holzheu 		     request->cpdata);
1511e2963062SMichael Holzheu 	rc = tape_do_io(device, request);
1512e2963062SMichael Holzheu 	if (rc == 0)
1513e2963062SMichael Holzheu 		memcpy(rdc_data, request->cpdata, sizeof(*rdc_data));
1514e2963062SMichael Holzheu 	tape_free_request(request);
1515e2963062SMichael Holzheu 	return rc;
1516e2963062SMichael Holzheu }
1517e2963062SMichael Holzheu 
1518b6cba4eeSStefan Bader /*
1519b6cba4eeSStefan Bader  * Setup device function
1520b6cba4eeSStefan Bader  */
1521b6cba4eeSStefan Bader static int
1522b6cba4eeSStefan Bader tape_3590_setup_device(struct tape_device *device)
1523b6cba4eeSStefan Bader {
1524b6cba4eeSStefan Bader 	int rc;
1525b6cba4eeSStefan Bader 	struct tape_3590_disc_data *data;
1526e2963062SMichael Holzheu 	struct tape_3590_rdc_data *rdc_data;
1527b6cba4eeSStefan Bader 
1528b6cba4eeSStefan Bader 	DBF_EVENT(6, "3590 device setup\n");
1529cced1dd4SMichael Holzheu 	data = kzalloc(sizeof(struct tape_3590_disc_data), GFP_KERNEL | GFP_DMA);
1530b6cba4eeSStefan Bader 	if (data == NULL)
1531b6cba4eeSStefan Bader 		return -ENOMEM;
1532b6cba4eeSStefan Bader 	data->read_back_op = READ_PREVIOUS;
1533b6cba4eeSStefan Bader 	device->discdata = data;
1534b6cba4eeSStefan Bader 
1535e2963062SMichael Holzheu 	rdc_data = kmalloc(sizeof(*rdc_data), GFP_KERNEL | GFP_DMA);
1536cced1dd4SMichael Holzheu 	if (!rdc_data) {
1537cced1dd4SMichael Holzheu 		rc = -ENOMEM;
1538cced1dd4SMichael Holzheu 		goto fail_kmalloc;
1539b6cba4eeSStefan Bader 	}
1540e2963062SMichael Holzheu 	rc = tape_3590_read_dev_chars(device, rdc_data);
1541cced1dd4SMichael Holzheu 	if (rc) {
1542cced1dd4SMichael Holzheu 		DBF_LH(3, "Read device characteristics failed!\n");
15431783e60fSJulia Lawall 		goto fail_rdc_data;
1544cced1dd4SMichael Holzheu 	}
1545cced1dd4SMichael Holzheu 	rc = tape_std_assign(device);
1546cced1dd4SMichael Holzheu 	if (rc)
1547cced1dd4SMichael Holzheu 		goto fail_rdc_data;
1548e2963062SMichael Holzheu 	if (rdc_data->data[31] == 0x13) {
1549cced1dd4SMichael Holzheu 		data->crypt_info.capability |= TAPE390_CRYPT_SUPPORTED_MASK;
1550cced1dd4SMichael Holzheu 		tape_3592_disable_crypt(device);
1551cced1dd4SMichael Holzheu 	} else {
1552cced1dd4SMichael Holzheu 		DBF_EVENT(6, "Device has NO crypto support\n");
1553cced1dd4SMichael Holzheu 	}
1554cced1dd4SMichael Holzheu 	/* Try to find out if medium is loaded */
1555cced1dd4SMichael Holzheu 	rc = tape_3590_sense_medium(device);
1556cced1dd4SMichael Holzheu 	if (rc) {
1557cced1dd4SMichael Holzheu 		DBF_LH(3, "3590 medium sense returned %d\n", rc);
1558cced1dd4SMichael Holzheu 		goto fail_rdc_data;
1559cced1dd4SMichael Holzheu 	}
1560cced1dd4SMichael Holzheu 	return 0;
1561b6cba4eeSStefan Bader 
1562cced1dd4SMichael Holzheu fail_rdc_data:
1563cced1dd4SMichael Holzheu 	kfree(rdc_data);
1564cced1dd4SMichael Holzheu fail_kmalloc:
1565cced1dd4SMichael Holzheu 	kfree(data);
1566b6cba4eeSStefan Bader 	return rc;
1567b6cba4eeSStefan Bader }
1568b6cba4eeSStefan Bader 
1569b6cba4eeSStefan Bader /*
1570b6cba4eeSStefan Bader  * Cleanup device function
1571b6cba4eeSStefan Bader  */
1572b6cba4eeSStefan Bader static void
1573b6cba4eeSStefan Bader tape_3590_cleanup_device(struct tape_device *device)
1574b6cba4eeSStefan Bader {
15756dca467aSTejun Heo 	flush_workqueue(tape_3590_wq);
1576b6cba4eeSStefan Bader 	tape_std_unassign(device);
1577b6cba4eeSStefan Bader 
1578b6cba4eeSStefan Bader 	kfree(device->discdata);
1579b6cba4eeSStefan Bader 	device->discdata = NULL;
1580b6cba4eeSStefan Bader }
1581b6cba4eeSStefan Bader 
1582b6cba4eeSStefan Bader /*
1583b6cba4eeSStefan Bader  * List of 3590 magnetic tape commands.
1584b6cba4eeSStefan Bader  */
1585b6cba4eeSStefan Bader static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = {
1586b6cba4eeSStefan Bader 	[MTRESET]	 = tape_std_mtreset,
1587b6cba4eeSStefan Bader 	[MTFSF]		 = tape_std_mtfsf,
1588b6cba4eeSStefan Bader 	[MTBSF]		 = tape_std_mtbsf,
1589b6cba4eeSStefan Bader 	[MTFSR]		 = tape_std_mtfsr,
1590b6cba4eeSStefan Bader 	[MTBSR]		 = tape_std_mtbsr,
1591b6cba4eeSStefan Bader 	[MTWEOF]	 = tape_std_mtweof,
1592b6cba4eeSStefan Bader 	[MTREW]		 = tape_std_mtrew,
1593b6cba4eeSStefan Bader 	[MTOFFL]	 = tape_std_mtoffl,
1594b6cba4eeSStefan Bader 	[MTNOP]		 = tape_std_mtnop,
1595b6cba4eeSStefan Bader 	[MTRETEN]	 = tape_std_mtreten,
1596b6cba4eeSStefan Bader 	[MTBSFM]	 = tape_std_mtbsfm,
1597b6cba4eeSStefan Bader 	[MTFSFM]	 = tape_std_mtfsfm,
1598b6cba4eeSStefan Bader 	[MTEOM]		 = tape_std_mteom,
1599b6cba4eeSStefan Bader 	[MTERASE]	 = tape_std_mterase,
1600b6cba4eeSStefan Bader 	[MTRAS1]	 = NULL,
1601b6cba4eeSStefan Bader 	[MTRAS2]	 = NULL,
1602b6cba4eeSStefan Bader 	[MTRAS3]	 = NULL,
1603b6cba4eeSStefan Bader 	[MTSETBLK]	 = tape_std_mtsetblk,
1604b6cba4eeSStefan Bader 	[MTSETDENSITY]	 = NULL,
1605b6cba4eeSStefan Bader 	[MTSEEK]	 = tape_3590_mtseek,
1606b6cba4eeSStefan Bader 	[MTTELL]	 = tape_3590_mttell,
1607b6cba4eeSStefan Bader 	[MTSETDRVBUFFER] = NULL,
1608b6cba4eeSStefan Bader 	[MTFSS]		 = NULL,
1609b6cba4eeSStefan Bader 	[MTBSS]		 = NULL,
1610b6cba4eeSStefan Bader 	[MTWSM]		 = NULL,
1611b6cba4eeSStefan Bader 	[MTLOCK]	 = NULL,
1612b6cba4eeSStefan Bader 	[MTUNLOCK]	 = NULL,
1613b6cba4eeSStefan Bader 	[MTLOAD]	 = tape_std_mtload,
1614b6cba4eeSStefan Bader 	[MTUNLOAD]	 = tape_std_mtunload,
1615b6cba4eeSStefan Bader 	[MTCOMPRESSION]	 = tape_std_mtcompression,
1616b6cba4eeSStefan Bader 	[MTSETPART]	 = NULL,
1617b6cba4eeSStefan Bader 	[MTMKPART]	 = NULL
1618b6cba4eeSStefan Bader };
1619b6cba4eeSStefan Bader 
1620b6cba4eeSStefan Bader /*
1621b6cba4eeSStefan Bader  * Tape discipline structure for 3590.
1622b6cba4eeSStefan Bader  */
1623b6cba4eeSStefan Bader static struct tape_discipline tape_discipline_3590 = {
1624b6cba4eeSStefan Bader 	.owner = THIS_MODULE,
1625b6cba4eeSStefan Bader 	.setup_device = tape_3590_setup_device,
1626b6cba4eeSStefan Bader 	.cleanup_device = tape_3590_cleanup_device,
1627b6cba4eeSStefan Bader 	.process_eov = tape_std_process_eov,
1628b6cba4eeSStefan Bader 	.irq = tape_3590_irq,
1629b6cba4eeSStefan Bader 	.read_block = tape_std_read_block,
1630b6cba4eeSStefan Bader 	.write_block = tape_std_write_block,
1631b6cba4eeSStefan Bader 	.ioctl_fn = tape_3590_ioctl,
1632b6cba4eeSStefan Bader 	.mtop_array = tape_3590_mtop
1633b6cba4eeSStefan Bader };
1634b6cba4eeSStefan Bader 
1635b6cba4eeSStefan Bader static struct ccw_device_id tape_3590_ids[] = {
1636b6cba4eeSStefan Bader 	{CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590},
16372cc924b8SStefan Bader 	{CCW_DEVICE_DEVTYPE(0x3592, 0, 0x3592, 0), .driver_info = tape_3592},
1638b6cba4eeSStefan Bader 	{ /* end of list */ }
1639b6cba4eeSStefan Bader };
1640b6cba4eeSStefan Bader 
1641b6cba4eeSStefan Bader static int
1642b6cba4eeSStefan Bader tape_3590_online(struct ccw_device *cdev)
1643b6cba4eeSStefan Bader {
1644dff59b64SGreg Kroah-Hartman 	return tape_generic_online(dev_get_drvdata(&cdev->dev),
1645b6cba4eeSStefan Bader 				   &tape_discipline_3590);
1646b6cba4eeSStefan Bader }
1647b6cba4eeSStefan Bader 
1648b6cba4eeSStefan Bader static struct ccw_driver tape_3590_driver = {
16493bda058bSSebastian Ott 	.driver = {
1650b6cba4eeSStefan Bader 		.name = "tape_3590",
1651b6cba4eeSStefan Bader 		.owner = THIS_MODULE,
16523bda058bSSebastian Ott 	},
1653b6cba4eeSStefan Bader 	.ids = tape_3590_ids,
1654b6cba4eeSStefan Bader 	.probe = tape_generic_probe,
1655b6cba4eeSStefan Bader 	.remove = tape_generic_remove,
16564d7a3cdfSFrank Munzert 	.set_offline = tape_generic_offline,
1657b6cba4eeSStefan Bader 	.set_online = tape_3590_online,
16583ef32e62SFrank Munzert 	.freeze = tape_generic_pm_suspend,
1659*420f42ecSHeiko Carstens 	.int_class = IRQIO_TAP,
1660b6cba4eeSStefan Bader };
1661b6cba4eeSStefan Bader 
1662b6cba4eeSStefan Bader /*
1663b6cba4eeSStefan Bader  * Setup discipline structure.
1664b6cba4eeSStefan Bader  */
1665b6cba4eeSStefan Bader static int
1666b6cba4eeSStefan Bader tape_3590_init(void)
1667b6cba4eeSStefan Bader {
1668b6cba4eeSStefan Bader 	int rc;
1669b6cba4eeSStefan Bader 
1670b6cba4eeSStefan Bader 	TAPE_DBF_AREA = debug_register("tape_3590", 2, 2, 4 * sizeof(long));
1671b6cba4eeSStefan Bader 	debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1672b6cba4eeSStefan Bader #ifdef DBF_LIKE_HELL
1673b6cba4eeSStefan Bader 	debug_set_level(TAPE_DBF_AREA, 6);
1674b6cba4eeSStefan Bader #endif
1675b6cba4eeSStefan Bader 
1676b6cba4eeSStefan Bader 	DBF_EVENT(3, "3590 init\n");
16776dca467aSTejun Heo 
16786dca467aSTejun Heo 	tape_3590_wq = alloc_workqueue("tape_3590", 0, 0);
16796dca467aSTejun Heo 	if (!tape_3590_wq)
16806dca467aSTejun Heo 		return -ENOMEM;
16816dca467aSTejun Heo 
1682b6cba4eeSStefan Bader 	/* Register driver for 3590 tapes. */
1683b6cba4eeSStefan Bader 	rc = ccw_driver_register(&tape_3590_driver);
16846dca467aSTejun Heo 	if (rc) {
16856dca467aSTejun Heo 		destroy_workqueue(tape_3590_wq);
1686b6cba4eeSStefan Bader 		DBF_EVENT(3, "3590 init failed\n");
16876dca467aSTejun Heo 	} else
1688b6cba4eeSStefan Bader 		DBF_EVENT(3, "3590 registered\n");
1689b6cba4eeSStefan Bader 	return rc;
1690b6cba4eeSStefan Bader }
1691b6cba4eeSStefan Bader 
1692b6cba4eeSStefan Bader static void
1693b6cba4eeSStefan Bader tape_3590_exit(void)
1694b6cba4eeSStefan Bader {
1695b6cba4eeSStefan Bader 	ccw_driver_unregister(&tape_3590_driver);
16966dca467aSTejun Heo 	destroy_workqueue(tape_3590_wq);
1697b6cba4eeSStefan Bader 	debug_unregister(TAPE_DBF_AREA);
1698b6cba4eeSStefan Bader }
1699b6cba4eeSStefan Bader 
1700b6cba4eeSStefan Bader MODULE_DEVICE_TABLE(ccw, tape_3590_ids);
1701b6cba4eeSStefan Bader MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
1702b6cba4eeSStefan Bader MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
1703b6cba4eeSStefan Bader MODULE_LICENSE("GPL");
1704b6cba4eeSStefan Bader 
1705b6cba4eeSStefan Bader module_init(tape_3590_init);
1706b6cba4eeSStefan Bader module_exit(tape_3590_exit);
1707