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