xref: /linux/drivers/s390/block/dasd_3990_erp.c (revision ae22a94997b8a03dcb3c922857c203246711f9d4)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Author(s)......: Horst  Hummel    <Horst.Hummel@de.ibm.com>
4  *		    Holger Smolinski <Holger.Smolinski@de.ibm.com>
5  * Bugreports.to..: <Linux390@de.ibm.com>
6  * Copyright IBM Corp. 2000, 2001
7  *
8  */
9 
10 #include <linux/timer.h>
11 #include <asm/idals.h>
12 
13 #include "dasd_int.h"
14 #include "dasd_eckd.h"
15 
16 
17 struct DCTL_data {
18 	unsigned char subcommand;  /* e.g Inhibit Write, Enable Write,... */
19 	unsigned char modifier;	   /* Subcommand modifier */
20 	unsigned short res;	   /* reserved */
21 } __attribute__ ((packed));
22 
23 /*
24  *****************************************************************************
25  * SECTION ERP HANDLING
26  *****************************************************************************
27  */
28 /*
29  *****************************************************************************
30  * 24 and 32 byte sense ERP functions
31  *****************************************************************************
32  */
33 
34 /*
35  * DASD_3990_ERP_CLEANUP
36  *
37  * DESCRIPTION
38  *   Removes the already build but not necessary ERP request and sets
39  *   the status of the original cqr / erp to the given (final) status
40  *
41  *  PARAMETER
42  *   erp		request to be blocked
43  *   final_status	either DASD_CQR_DONE or DASD_CQR_FAILED
44  *
45  * RETURN VALUES
46  *   cqr		original cqr
47  */
48 static struct dasd_ccw_req *
49 dasd_3990_erp_cleanup(struct dasd_ccw_req * erp, char final_status)
50 {
51 	struct dasd_ccw_req *cqr = erp->refers;
52 
53 	dasd_free_erp_request(erp, erp->memdev);
54 	cqr->status = final_status;
55 	return cqr;
56 
57 }				/* end dasd_3990_erp_cleanup */
58 
59 /*
60  * DASD_3990_ERP_BLOCK_QUEUE
61  *
62  * DESCRIPTION
63  *   Block the given device request queue to prevent from further
64  *   processing until the started timer has expired or an related
65  *   interrupt was received.
66  */
67 static void dasd_3990_erp_block_queue(struct dasd_ccw_req *erp, int expires)
68 {
69 
70 	struct dasd_device *device = erp->startdev;
71 	unsigned long flags;
72 
73 	DBF_DEV_EVENT(DBF_INFO, device,
74 		    "blocking request queue for %is", expires/HZ);
75 
76 	spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
77 	dasd_device_set_stop_bits(device, DASD_STOPPED_PENDING);
78 	spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
79 	erp->status = DASD_CQR_FILLED;
80 	if (erp->block)
81 		dasd_block_set_timer(erp->block, expires);
82 	else
83 		dasd_device_set_timer(device, expires);
84 }
85 
86 /*
87  * DASD_3990_ERP_INT_REQ
88  *
89  * DESCRIPTION
90  *   Handles 'Intervention Required' error.
91  *   This means either device offline or not installed.
92  *
93  * PARAMETER
94  *   erp		current erp
95  * RETURN VALUES
96  *   erp		modified erp
97  */
98 static struct dasd_ccw_req *
99 dasd_3990_erp_int_req(struct dasd_ccw_req * erp)
100 {
101 
102 	struct dasd_device *device = erp->startdev;
103 
104 	/* first time set initial retry counter and erp_function */
105 	/* and retry once without blocking queue		 */
106 	/* (this enables easier enqueing of the cqr)		 */
107 	if (erp->function != dasd_3990_erp_int_req) {
108 
109 		erp->retries = 256;
110 		erp->function = dasd_3990_erp_int_req;
111 
112 	} else {
113 
114 		/* issue a message and wait for 'device ready' interrupt */
115 		dev_err(&device->cdev->dev,
116 			    "is offline or not installed - "
117 			    "INTERVENTION REQUIRED!!\n");
118 
119 		dasd_3990_erp_block_queue(erp, 60*HZ);
120 	}
121 
122 	return erp;
123 
124 }				/* end dasd_3990_erp_int_req */
125 
126 /*
127  * DASD_3990_ERP_ALTERNATE_PATH
128  *
129  * DESCRIPTION
130  *   Repeat the operation on a different channel path.
131  *   If all alternate paths have been tried, the request is posted with a
132  *   permanent error.
133  *
134  *  PARAMETER
135  *   erp		pointer to the current ERP
136  *
137  * RETURN VALUES
138  *   erp		modified pointer to the ERP
139  */
140 static void
141 dasd_3990_erp_alternate_path(struct dasd_ccw_req * erp)
142 {
143 	struct dasd_device *device = erp->startdev;
144 	__u8 opm;
145 	unsigned long flags;
146 
147 	/* try alternate valid path */
148 	spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
149 	opm = ccw_device_get_path_mask(device->cdev);
150 	spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
151 	if (erp->lpm == 0)
152 		erp->lpm = dasd_path_get_opm(device) &
153 			~(erp->irb.esw.esw0.sublog.lpum);
154 	else
155 		erp->lpm &= ~(erp->irb.esw.esw0.sublog.lpum);
156 
157 	if ((erp->lpm & opm) != 0x00) {
158 
159 		DBF_DEV_EVENT(DBF_WARNING, device,
160 			    "try alternate lpm=%x (lpum=%x / opm=%x)",
161 			    erp->lpm, erp->irb.esw.esw0.sublog.lpum, opm);
162 
163 		/* reset status to submit the request again... */
164 		erp->status = DASD_CQR_FILLED;
165 		erp->retries = 10;
166 	} else {
167 		dev_err(&device->cdev->dev,
168 			"The DASD cannot be reached on any path (lpum=%x"
169 			"/opm=%x)\n", erp->irb.esw.esw0.sublog.lpum, opm);
170 
171 		/* post request with permanent error */
172 		erp->status = DASD_CQR_FAILED;
173 	}
174 }				/* end dasd_3990_erp_alternate_path */
175 
176 /*
177  * DASD_3990_ERP_DCTL
178  *
179  * DESCRIPTION
180  *   Setup cqr to do the Diagnostic Control (DCTL) command with an
181  *   Inhibit Write subcommand (0x20) and the given modifier.
182  *
183  *  PARAMETER
184  *   erp		pointer to the current (failed) ERP
185  *   modifier		subcommand modifier
186  *
187  * RETURN VALUES
188  *   dctl_cqr		pointer to NEW dctl_cqr
189  *
190  */
191 static struct dasd_ccw_req *
192 dasd_3990_erp_DCTL(struct dasd_ccw_req * erp, char modifier)
193 {
194 
195 	struct dasd_device *device = erp->startdev;
196 	struct DCTL_data *DCTL_data;
197 	struct ccw1 *ccw;
198 	struct dasd_ccw_req *dctl_cqr;
199 
200 	dctl_cqr = dasd_alloc_erp_request(erp->magic, 1,
201 					  sizeof(struct DCTL_data),
202 					  device);
203 	if (IS_ERR(dctl_cqr)) {
204 		dev_err(&device->cdev->dev,
205 			    "Unable to allocate DCTL-CQR\n");
206 		erp->status = DASD_CQR_FAILED;
207 		return erp;
208 	}
209 
210 	DCTL_data = dctl_cqr->data;
211 
212 	DCTL_data->subcommand = 0x02;	/* Inhibit Write */
213 	DCTL_data->modifier = modifier;
214 
215 	ccw = dctl_cqr->cpaddr;
216 	memset(ccw, 0, sizeof(struct ccw1));
217 	ccw->cmd_code = CCW_CMD_DCTL;
218 	ccw->count = 4;
219 	ccw->cda = virt_to_dma32(DCTL_data);
220 	dctl_cqr->flags = erp->flags;
221 	dctl_cqr->function = dasd_3990_erp_DCTL;
222 	dctl_cqr->refers = erp;
223 	dctl_cqr->startdev = device;
224 	dctl_cqr->memdev = device;
225 	dctl_cqr->magic = erp->magic;
226 	dctl_cqr->expires = 5 * 60 * HZ;
227 	dctl_cqr->retries = 2;
228 
229 	dctl_cqr->buildclk = get_tod_clock();
230 
231 	dctl_cqr->status = DASD_CQR_FILLED;
232 
233 	return dctl_cqr;
234 
235 }				/* end dasd_3990_erp_DCTL */
236 
237 /*
238  * DASD_3990_ERP_ACTION_1
239  *
240  * DESCRIPTION
241  *   Setup ERP to do the ERP action 1 (see Reference manual).
242  *   Repeat the operation on a different channel path.
243  *   As deviation from the recommended recovery action, we reset the path mask
244  *   after we have tried each path and go through all paths a second time.
245  *   This will cover situations where only one path at a time is actually down,
246  *   but all paths fail and recover just with the same sequence and timing as
247  *   we try to use them (flapping links).
248  *   If all alternate paths have been tried twice, the request is posted with
249  *   a permanent error.
250  *
251  *  PARAMETER
252  *   erp		pointer to the current ERP
253  *
254  * RETURN VALUES
255  *   erp		pointer to the ERP
256  *
257  */
258 static struct dasd_ccw_req *dasd_3990_erp_action_1_sec(struct dasd_ccw_req *erp)
259 {
260 	erp->function = dasd_3990_erp_action_1_sec;
261 	dasd_3990_erp_alternate_path(erp);
262 	return erp;
263 }
264 
265 static struct dasd_ccw_req *dasd_3990_erp_action_1(struct dasd_ccw_req *erp)
266 {
267 	erp->function = dasd_3990_erp_action_1;
268 	dasd_3990_erp_alternate_path(erp);
269 	if (erp->status == DASD_CQR_FAILED &&
270 	    !test_bit(DASD_CQR_VERIFY_PATH, &erp->flags)) {
271 		erp->status = DASD_CQR_FILLED;
272 		erp->retries = 10;
273 		erp->lpm = dasd_path_get_opm(erp->startdev);
274 		erp->function = dasd_3990_erp_action_1_sec;
275 	}
276 	return erp;
277 }				/* end dasd_3990_erp_action_1(b) */
278 
279 /*
280  * DASD_3990_ERP_ACTION_4
281  *
282  * DESCRIPTION
283  *   Setup ERP to do the ERP action 4 (see Reference manual).
284  *   Set the current request to PENDING to block the CQR queue for that device
285  *   until the state change interrupt appears.
286  *   Use a timer (20 seconds) to retry the cqr if the interrupt is still
287  *   missing.
288  *
289  *  PARAMETER
290  *   sense		sense data of the actual error
291  *   erp		pointer to the current ERP
292  *
293  * RETURN VALUES
294  *   erp		pointer to the ERP
295  *
296  */
297 static struct dasd_ccw_req *
298 dasd_3990_erp_action_4(struct dasd_ccw_req * erp, char *sense)
299 {
300 
301 	struct dasd_device *device = erp->startdev;
302 
303 	/* first time set initial retry counter and erp_function    */
304 	/* and retry once without waiting for state change pending  */
305 	/* interrupt (this enables easier enqueing of the cqr)	    */
306 	if (erp->function != dasd_3990_erp_action_4) {
307 
308 		DBF_DEV_EVENT(DBF_INFO, device, "%s",
309 			    "dasd_3990_erp_action_4: first time retry");
310 
311 		erp->retries = 256;
312 		erp->function = dasd_3990_erp_action_4;
313 
314 	} else {
315 		if (sense && (sense[25] == 0x1D)) { /* state change pending */
316 
317 			DBF_DEV_EVENT(DBF_INFO, device,
318 				    "waiting for state change pending "
319 				    "interrupt, %d retries left",
320 				    erp->retries);
321 
322 			dasd_3990_erp_block_queue(erp, 30*HZ);
323 
324 		} else if (sense && (sense[25] == 0x1E)) {	/* busy */
325 			DBF_DEV_EVENT(DBF_INFO, device,
326 				    "busy - redriving request later, "
327 				    "%d retries left",
328 				    erp->retries);
329                         dasd_3990_erp_block_queue(erp, HZ);
330 		} else {
331 			/* no state change pending - retry */
332 			DBF_DEV_EVENT(DBF_INFO, device,
333 				     "redriving request immediately, "
334 				     "%d retries left",
335 				     erp->retries);
336 			erp->status = DASD_CQR_FILLED;
337 		}
338 	}
339 
340 	return erp;
341 
342 }				/* end dasd_3990_erp_action_4 */
343 
344 /*
345  *****************************************************************************
346  * 24 byte sense ERP functions (only)
347  *****************************************************************************
348  */
349 
350 /*
351  * DASD_3990_ERP_ACTION_5
352  *
353  * DESCRIPTION
354  *   Setup ERP to do the ERP action 5 (see Reference manual).
355  *   NOTE: Further handling is done in xxx_further_erp after the retries.
356  *
357  *  PARAMETER
358  *   erp		pointer to the current ERP
359  *
360  * RETURN VALUES
361  *   erp		pointer to the ERP
362  *
363  */
364 static struct dasd_ccw_req *
365 dasd_3990_erp_action_5(struct dasd_ccw_req * erp)
366 {
367 
368 	/* first of all retry */
369 	erp->retries = 10;
370 	erp->function = dasd_3990_erp_action_5;
371 
372 	return erp;
373 
374 }				/* end dasd_3990_erp_action_5 */
375 
376 /*
377  * DASD_3990_HANDLE_ENV_DATA
378  *
379  * DESCRIPTION
380  *   Handles 24 byte 'Environmental data present'.
381  *   Does a analysis of the sense data (message Format)
382  *   and prints the error messages.
383  *
384  * PARAMETER
385  *   sense		current sense data
386  *
387  * RETURN VALUES
388  *   void
389  */
390 static void
391 dasd_3990_handle_env_data(struct dasd_ccw_req * erp, char *sense)
392 {
393 
394 	struct dasd_device *device = erp->startdev;
395 	char msg_format = (sense[7] & 0xF0);
396 	char msg_no = (sense[7] & 0x0F);
397 
398 	switch (msg_format) {
399 	case 0x00:		/* Format 0 - Program or System Checks */
400 
401 		if (sense[1] & 0x10) {	/* check message to operator bit */
402 
403 			switch (msg_no) {
404 			case 0x00:	/* No Message */
405 				break;
406 			case 0x01:
407 				dev_warn(&device->cdev->dev,
408 					    "FORMAT 0 - Invalid Command\n");
409 				break;
410 			case 0x02:
411 				dev_warn(&device->cdev->dev,
412 					    "FORMAT 0 - Invalid Command "
413 					    "Sequence\n");
414 				break;
415 			case 0x03:
416 				dev_warn(&device->cdev->dev,
417 					    "FORMAT 0 - CCW Count less than "
418 					    "required\n");
419 				break;
420 			case 0x04:
421 				dev_warn(&device->cdev->dev,
422 					    "FORMAT 0 - Invalid Parameter\n");
423 				break;
424 			case 0x05:
425 				dev_warn(&device->cdev->dev,
426 					    "FORMAT 0 - Diagnostic of Special"
427 					    " Command Violates File Mask\n");
428 				break;
429 			case 0x07:
430 				dev_warn(&device->cdev->dev,
431 					    "FORMAT 0 - Channel Returned with "
432 					    "Incorrect retry CCW\n");
433 				break;
434 			case 0x08:
435 				dev_warn(&device->cdev->dev,
436 					    "FORMAT 0 - Reset Notification\n");
437 				break;
438 			case 0x09:
439 				dev_warn(&device->cdev->dev,
440 					 "FORMAT 0 - Storage Path Restart\n");
441 				break;
442 			case 0x0A:
443 				dev_warn(&device->cdev->dev,
444 					    "FORMAT 0 - Channel requested "
445 					    "... %02x\n", sense[8]);
446 				break;
447 			case 0x0B:
448 				dev_warn(&device->cdev->dev,
449 					    "FORMAT 0 - Invalid Defective/"
450 					    "Alternate Track Pointer\n");
451 				break;
452 			case 0x0C:
453 				dev_warn(&device->cdev->dev,
454 					    "FORMAT 0 - DPS Installation "
455 					    "Check\n");
456 				break;
457 			case 0x0E:
458 				dev_warn(&device->cdev->dev,
459 					    "FORMAT 0 - Command Invalid on "
460 					    "Secondary Address\n");
461 				break;
462 			case 0x0F:
463 				dev_warn(&device->cdev->dev,
464 					    "FORMAT 0 - Status Not As "
465 					    "Required: reason %02x\n",
466 					 sense[8]);
467 				break;
468 			default:
469 				dev_warn(&device->cdev->dev,
470 					    "FORMAT 0 - Reserved\n");
471 			}
472 		} else {
473 			switch (msg_no) {
474 			case 0x00:	/* No Message */
475 				break;
476 			case 0x01:
477 				dev_warn(&device->cdev->dev,
478 					 "FORMAT 0 - Device Error "
479 					 "Source\n");
480 				break;
481 			case 0x02:
482 				dev_warn(&device->cdev->dev,
483 					    "FORMAT 0 - Reserved\n");
484 				break;
485 			case 0x03:
486 				dev_warn(&device->cdev->dev,
487 					    "FORMAT 0 - Device Fenced - "
488 					    "device = %02x\n", sense[4]);
489 				break;
490 			case 0x04:
491 				dev_warn(&device->cdev->dev,
492 					    "FORMAT 0 - Data Pinned for "
493 					    "Device\n");
494 				break;
495 			default:
496 				dev_warn(&device->cdev->dev,
497 					    "FORMAT 0 - Reserved\n");
498 			}
499 		}
500 		break;
501 
502 	case 0x10:		/* Format 1 - Device Equipment Checks */
503 		switch (msg_no) {
504 		case 0x00:	/* No Message */
505 			break;
506 		case 0x01:
507 			dev_warn(&device->cdev->dev,
508 				    "FORMAT 1 - Device Status 1 not as "
509 				    "expected\n");
510 			break;
511 		case 0x03:
512 			dev_warn(&device->cdev->dev,
513 				    "FORMAT 1 - Index missing\n");
514 			break;
515 		case 0x04:
516 			dev_warn(&device->cdev->dev,
517 				 "FORMAT 1 - Interruption cannot be "
518 				 "reset\n");
519 			break;
520 		case 0x05:
521 			dev_warn(&device->cdev->dev,
522 				    "FORMAT 1 - Device did not respond to "
523 				    "selection\n");
524 			break;
525 		case 0x06:
526 			dev_warn(&device->cdev->dev,
527 				    "FORMAT 1 - Device check-2 error or Set "
528 				    "Sector is not complete\n");
529 			break;
530 		case 0x07:
531 			dev_warn(&device->cdev->dev,
532 				    "FORMAT 1 - Head address does not "
533 				    "compare\n");
534 			break;
535 		case 0x08:
536 			dev_warn(&device->cdev->dev,
537 				    "FORMAT 1 - Device status 1 not valid\n");
538 			break;
539 		case 0x09:
540 			dev_warn(&device->cdev->dev,
541 				    "FORMAT 1 - Device not ready\n");
542 			break;
543 		case 0x0A:
544 			dev_warn(&device->cdev->dev,
545 				    "FORMAT 1 - Track physical address did "
546 				    "not compare\n");
547 			break;
548 		case 0x0B:
549 			dev_warn(&device->cdev->dev,
550 				    "FORMAT 1 - Missing device address bit\n");
551 			break;
552 		case 0x0C:
553 			dev_warn(&device->cdev->dev,
554 				    "FORMAT 1 - Drive motor switch is off\n");
555 			break;
556 		case 0x0D:
557 			dev_warn(&device->cdev->dev,
558 				    "FORMAT 1 - Seek incomplete\n");
559 			break;
560 		case 0x0E:
561 			dev_warn(&device->cdev->dev,
562 				    "FORMAT 1 - Cylinder address did not "
563 				    "compare\n");
564 			break;
565 		case 0x0F:
566 			dev_warn(&device->cdev->dev,
567 				    "FORMAT 1 - Offset active cannot be "
568 				    "reset\n");
569 			break;
570 		default:
571 			dev_warn(&device->cdev->dev,
572 				    "FORMAT 1 - Reserved\n");
573 		}
574 		break;
575 
576 	case 0x20:		/* Format 2 - 3990 Equipment Checks */
577 		switch (msg_no) {
578 		case 0x08:
579 			dev_warn(&device->cdev->dev,
580 				    "FORMAT 2 - 3990 check-2 error\n");
581 			break;
582 		case 0x0E:
583 			dev_warn(&device->cdev->dev,
584 				    "FORMAT 2 - Support facility errors\n");
585 			break;
586 		case 0x0F:
587 			dev_warn(&device->cdev->dev,
588 				 "FORMAT 2 - Microcode detected error "
589 				 "%02x\n",
590 				 sense[8]);
591 			break;
592 		default:
593 			dev_warn(&device->cdev->dev,
594 				    "FORMAT 2 - Reserved\n");
595 		}
596 		break;
597 
598 	case 0x30:		/* Format 3 - 3990 Control Checks */
599 		switch (msg_no) {
600 		case 0x0F:
601 			dev_warn(&device->cdev->dev,
602 				    "FORMAT 3 - Allegiance terminated\n");
603 			break;
604 		default:
605 			dev_warn(&device->cdev->dev,
606 				    "FORMAT 3 - Reserved\n");
607 		}
608 		break;
609 
610 	case 0x40:		/* Format 4 - Data Checks */
611 		switch (msg_no) {
612 		case 0x00:
613 			dev_warn(&device->cdev->dev,
614 				    "FORMAT 4 - Home address area error\n");
615 			break;
616 		case 0x01:
617 			dev_warn(&device->cdev->dev,
618 				    "FORMAT 4 - Count area error\n");
619 			break;
620 		case 0x02:
621 			dev_warn(&device->cdev->dev,
622 				    "FORMAT 4 - Key area error\n");
623 			break;
624 		case 0x03:
625 			dev_warn(&device->cdev->dev,
626 				    "FORMAT 4 - Data area error\n");
627 			break;
628 		case 0x04:
629 			dev_warn(&device->cdev->dev,
630 				    "FORMAT 4 - No sync byte in home address "
631 				    "area\n");
632 			break;
633 		case 0x05:
634 			dev_warn(&device->cdev->dev,
635 				    "FORMAT 4 - No sync byte in count address "
636 				    "area\n");
637 			break;
638 		case 0x06:
639 			dev_warn(&device->cdev->dev,
640 				    "FORMAT 4 - No sync byte in key area\n");
641 			break;
642 		case 0x07:
643 			dev_warn(&device->cdev->dev,
644 				    "FORMAT 4 - No sync byte in data area\n");
645 			break;
646 		case 0x08:
647 			dev_warn(&device->cdev->dev,
648 				    "FORMAT 4 - Home address area error; "
649 				    "offset active\n");
650 			break;
651 		case 0x09:
652 			dev_warn(&device->cdev->dev,
653 				    "FORMAT 4 - Count area error; offset "
654 				    "active\n");
655 			break;
656 		case 0x0A:
657 			dev_warn(&device->cdev->dev,
658 				    "FORMAT 4 - Key area error; offset "
659 				    "active\n");
660 			break;
661 		case 0x0B:
662 			dev_warn(&device->cdev->dev,
663 				    "FORMAT 4 - Data area error; "
664 				    "offset active\n");
665 			break;
666 		case 0x0C:
667 			dev_warn(&device->cdev->dev,
668 				    "FORMAT 4 - No sync byte in home "
669 				    "address area; offset active\n");
670 			break;
671 		case 0x0D:
672 			dev_warn(&device->cdev->dev,
673 				    "FORMAT 4 - No sync byte in count "
674 				    "address area; offset active\n");
675 			break;
676 		case 0x0E:
677 			dev_warn(&device->cdev->dev,
678 				    "FORMAT 4 - No sync byte in key area; "
679 				    "offset active\n");
680 			break;
681 		case 0x0F:
682 			dev_warn(&device->cdev->dev,
683 				    "FORMAT 4 - No sync byte in data area; "
684 				    "offset active\n");
685 			break;
686 		default:
687 			dev_warn(&device->cdev->dev,
688 				    "FORMAT 4 - Reserved\n");
689 		}
690 		break;
691 
692 	case 0x50:  /* Format 5 - Data Check with displacement information */
693 		switch (msg_no) {
694 		case 0x00:
695 			dev_warn(&device->cdev->dev,
696 				    "FORMAT 5 - Data Check in the "
697 				    "home address area\n");
698 			break;
699 		case 0x01:
700 			dev_warn(&device->cdev->dev,
701 				 "FORMAT 5 - Data Check in the count "
702 				 "area\n");
703 			break;
704 		case 0x02:
705 			dev_warn(&device->cdev->dev,
706 				    "FORMAT 5 - Data Check in the key area\n");
707 			break;
708 		case 0x03:
709 			dev_warn(&device->cdev->dev,
710 				 "FORMAT 5 - Data Check in the data "
711 				 "area\n");
712 			break;
713 		case 0x08:
714 			dev_warn(&device->cdev->dev,
715 				    "FORMAT 5 - Data Check in the "
716 				    "home address area; offset active\n");
717 			break;
718 		case 0x09:
719 			dev_warn(&device->cdev->dev,
720 				    "FORMAT 5 - Data Check in the count area; "
721 				    "offset active\n");
722 			break;
723 		case 0x0A:
724 			dev_warn(&device->cdev->dev,
725 				    "FORMAT 5 - Data Check in the key area; "
726 				    "offset active\n");
727 			break;
728 		case 0x0B:
729 			dev_warn(&device->cdev->dev,
730 				    "FORMAT 5 - Data Check in the data area; "
731 				    "offset active\n");
732 			break;
733 		default:
734 			dev_warn(&device->cdev->dev,
735 				    "FORMAT 5 - Reserved\n");
736 		}
737 		break;
738 
739 	case 0x60:  /* Format 6 - Usage Statistics/Overrun Errors */
740 		switch (msg_no) {
741 		case 0x00:
742 			dev_warn(&device->cdev->dev,
743 				    "FORMAT 6 - Overrun on channel A\n");
744 			break;
745 		case 0x01:
746 			dev_warn(&device->cdev->dev,
747 				    "FORMAT 6 - Overrun on channel B\n");
748 			break;
749 		case 0x02:
750 			dev_warn(&device->cdev->dev,
751 				    "FORMAT 6 - Overrun on channel C\n");
752 			break;
753 		case 0x03:
754 			dev_warn(&device->cdev->dev,
755 				    "FORMAT 6 - Overrun on channel D\n");
756 			break;
757 		case 0x04:
758 			dev_warn(&device->cdev->dev,
759 				    "FORMAT 6 - Overrun on channel E\n");
760 			break;
761 		case 0x05:
762 			dev_warn(&device->cdev->dev,
763 				    "FORMAT 6 - Overrun on channel F\n");
764 			break;
765 		case 0x06:
766 			dev_warn(&device->cdev->dev,
767 				    "FORMAT 6 - Overrun on channel G\n");
768 			break;
769 		case 0x07:
770 			dev_warn(&device->cdev->dev,
771 				    "FORMAT 6 - Overrun on channel H\n");
772 			break;
773 		default:
774 			dev_warn(&device->cdev->dev,
775 				    "FORMAT 6 - Reserved\n");
776 		}
777 		break;
778 
779 	case 0x70:  /* Format 7 - Device Connection Control Checks */
780 		switch (msg_no) {
781 		case 0x00:
782 			dev_warn(&device->cdev->dev,
783 				    "FORMAT 7 - RCC initiated by a connection "
784 				    "check alert\n");
785 			break;
786 		case 0x01:
787 			dev_warn(&device->cdev->dev,
788 				    "FORMAT 7 - RCC 1 sequence not "
789 				    "successful\n");
790 			break;
791 		case 0x02:
792 			dev_warn(&device->cdev->dev,
793 				    "FORMAT 7 - RCC 1 and RCC 2 sequences not "
794 				    "successful\n");
795 			break;
796 		case 0x03:
797 			dev_warn(&device->cdev->dev,
798 				    "FORMAT 7 - Invalid tag-in during "
799 				    "selection sequence\n");
800 			break;
801 		case 0x04:
802 			dev_warn(&device->cdev->dev,
803 				    "FORMAT 7 - extra RCC required\n");
804 			break;
805 		case 0x05:
806 			dev_warn(&device->cdev->dev,
807 				    "FORMAT 7 - Invalid DCC selection "
808 				    "response or timeout\n");
809 			break;
810 		case 0x06:
811 			dev_warn(&device->cdev->dev,
812 				    "FORMAT 7 - Missing end operation; device "
813 				    "transfer complete\n");
814 			break;
815 		case 0x07:
816 			dev_warn(&device->cdev->dev,
817 				    "FORMAT 7 - Missing end operation; device "
818 				    "transfer incomplete\n");
819 			break;
820 		case 0x08:
821 			dev_warn(&device->cdev->dev,
822 				    "FORMAT 7 - Invalid tag-in for an "
823 				    "immediate command sequence\n");
824 			break;
825 		case 0x09:
826 			dev_warn(&device->cdev->dev,
827 				    "FORMAT 7 - Invalid tag-in for an "
828 				    "extended command sequence\n");
829 			break;
830 		case 0x0A:
831 			dev_warn(&device->cdev->dev,
832 				    "FORMAT 7 - 3990 microcode time out when "
833 				    "stopping selection\n");
834 			break;
835 		case 0x0B:
836 			dev_warn(&device->cdev->dev,
837 				    "FORMAT 7 - No response to selection "
838 				    "after a poll interruption\n");
839 			break;
840 		case 0x0C:
841 			dev_warn(&device->cdev->dev,
842 				    "FORMAT 7 - Permanent path error (DASD "
843 				    "controller not available)\n");
844 			break;
845 		case 0x0D:
846 			dev_warn(&device->cdev->dev,
847 				    "FORMAT 7 - DASD controller not available"
848 				    " on disconnected command chain\n");
849 			break;
850 		default:
851 			dev_warn(&device->cdev->dev,
852 				    "FORMAT 7 - Reserved\n");
853 		}
854 		break;
855 
856 	case 0x80:  /* Format 8 - Additional Device Equipment Checks */
857 		switch (msg_no) {
858 		case 0x00:	/* No Message */
859 		case 0x01:
860 			dev_warn(&device->cdev->dev,
861 				    "FORMAT 8 - Error correction code "
862 				    "hardware fault\n");
863 			break;
864 		case 0x03:
865 			dev_warn(&device->cdev->dev,
866 				    "FORMAT 8 - Unexpected end operation "
867 				    "response code\n");
868 			break;
869 		case 0x04:
870 			dev_warn(&device->cdev->dev,
871 				    "FORMAT 8 - End operation with transfer "
872 				    "count not zero\n");
873 			break;
874 		case 0x05:
875 			dev_warn(&device->cdev->dev,
876 				    "FORMAT 8 - End operation with transfer "
877 				    "count zero\n");
878 			break;
879 		case 0x06:
880 			dev_warn(&device->cdev->dev,
881 				    "FORMAT 8 - DPS checks after a system "
882 				    "reset or selective reset\n");
883 			break;
884 		case 0x07:
885 			dev_warn(&device->cdev->dev,
886 				    "FORMAT 8 - DPS cannot be filled\n");
887 			break;
888 		case 0x08:
889 			dev_warn(&device->cdev->dev,
890 				    "FORMAT 8 - Short busy time-out during "
891 				    "device selection\n");
892 			break;
893 		case 0x09:
894 			dev_warn(&device->cdev->dev,
895 				    "FORMAT 8 - DASD controller failed to "
896 				    "set or reset the long busy latch\n");
897 			break;
898 		case 0x0A:
899 			dev_warn(&device->cdev->dev,
900 				    "FORMAT 8 - No interruption from device "
901 				    "during a command chain\n");
902 			break;
903 		default:
904 			dev_warn(&device->cdev->dev,
905 				    "FORMAT 8 - Reserved\n");
906 		}
907 		break;
908 
909 	case 0x90:  /* Format 9 - Device Read, Write, and Seek Checks */
910 		switch (msg_no) {
911 		case 0x00:
912 			break;	/* No Message */
913 		case 0x06:
914 			dev_warn(&device->cdev->dev,
915 				    "FORMAT 9 - Device check-2 error\n");
916 			break;
917 		case 0x07:
918 			dev_warn(&device->cdev->dev,
919 				 "FORMAT 9 - Head address did not "
920 				 "compare\n");
921 			break;
922 		case 0x0A:
923 			dev_warn(&device->cdev->dev,
924 				    "FORMAT 9 - Track physical address did "
925 				    "not compare while oriented\n");
926 			break;
927 		case 0x0E:
928 			dev_warn(&device->cdev->dev,
929 				    "FORMAT 9 - Cylinder address did not "
930 				    "compare\n");
931 			break;
932 		default:
933 			dev_warn(&device->cdev->dev,
934 				    "FORMAT 9 - Reserved\n");
935 		}
936 		break;
937 
938 	case 0xF0:		/* Format F - Cache Storage Checks */
939 		switch (msg_no) {
940 		case 0x00:
941 			dev_warn(&device->cdev->dev,
942 				    "FORMAT F - Operation Terminated\n");
943 			break;
944 		case 0x01:
945 			dev_warn(&device->cdev->dev,
946 				    "FORMAT F - Subsystem Processing Error\n");
947 			break;
948 		case 0x02:
949 			dev_warn(&device->cdev->dev,
950 				    "FORMAT F - Cache or nonvolatile storage "
951 				    "equipment failure\n");
952 			break;
953 		case 0x04:
954 			dev_warn(&device->cdev->dev,
955 				    "FORMAT F - Caching terminated\n");
956 			break;
957 		case 0x06:
958 			dev_warn(&device->cdev->dev,
959 				    "FORMAT F - Cache fast write access not "
960 				    "authorized\n");
961 			break;
962 		case 0x07:
963 			dev_warn(&device->cdev->dev,
964 				    "FORMAT F - Track format incorrect\n");
965 			break;
966 		case 0x09:
967 			dev_warn(&device->cdev->dev,
968 				    "FORMAT F - Caching reinitiated\n");
969 			break;
970 		case 0x0A:
971 			dev_warn(&device->cdev->dev,
972 				    "FORMAT F - Nonvolatile storage "
973 				    "terminated\n");
974 			break;
975 		case 0x0B:
976 			dev_warn(&device->cdev->dev,
977 				    "FORMAT F - Volume is suspended duplex\n");
978 			/* call extended error reporting (EER) */
979 			dasd_eer_write(device, erp->refers,
980 				       DASD_EER_PPRCSUSPEND);
981 			break;
982 		case 0x0C:
983 			dev_warn(&device->cdev->dev,
984 				    "FORMAT F - Subsystem status cannot be "
985 				    "determined\n");
986 			break;
987 		case 0x0D:
988 			dev_warn(&device->cdev->dev,
989 				    "FORMAT F - Caching status reset to "
990 				    "default\n");
991 			break;
992 		case 0x0E:
993 			dev_warn(&device->cdev->dev,
994 				    "FORMAT F - DASD Fast Write inhibited\n");
995 			break;
996 		default:
997 			dev_warn(&device->cdev->dev,
998 				    "FORMAT F - Reserved\n");
999 		}
1000 		break;
1001 
1002 	default:
1003 		dev_err(&device->cdev->dev,
1004 			"Unknown message format %02x", msg_format);
1005 		break;
1006 	}			/* end switch message format */
1007 
1008 }				/* end dasd_3990_handle_env_data */
1009 
1010 /*
1011  * DASD_3990_ERP_COM_REJ
1012  *
1013  * DESCRIPTION
1014  *   Handles 24 byte 'Command Reject' error.
1015  *
1016  * PARAMETER
1017  *   erp		current erp_head
1018  *   sense		current sense data
1019  *
1020  * RETURN VALUES
1021  *   erp		'new' erp_head - pointer to new ERP
1022  */
1023 static struct dasd_ccw_req *
1024 dasd_3990_erp_com_rej(struct dasd_ccw_req * erp, char *sense)
1025 {
1026 
1027 	struct dasd_device *device = erp->startdev;
1028 
1029 	erp->function = dasd_3990_erp_com_rej;
1030 
1031 	/* env data present (ACTION 10 - retry should work) */
1032 	if (sense[2] & SNS2_ENV_DATA_PRESENT) {
1033 
1034 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1035 			    "Command Reject - environmental data present");
1036 
1037 		dasd_3990_handle_env_data(erp, sense);
1038 
1039 		erp->retries = 5;
1040 
1041 	} else if (sense[1] & SNS1_WRITE_INHIBITED) {
1042 		dev_err(&device->cdev->dev, "An I/O request was rejected"
1043 			" because writing is inhibited\n");
1044 		erp = dasd_3990_erp_cleanup(erp, DASD_CQR_FAILED);
1045 	} else if (sense[7] == SNS7_INVALID_ON_SEC) {
1046 		dev_err(&device->cdev->dev, "An I/O request was rejected on a copy pair secondary device\n");
1047 		/* suppress dump of sense data for this error */
1048 		set_bit(DASD_CQR_SUPPRESS_CR, &erp->refers->flags);
1049 		erp = dasd_3990_erp_cleanup(erp, DASD_CQR_FAILED);
1050 	} else {
1051 		if (!test_bit(DASD_CQR_SUPPRESS_CR, &erp->flags))
1052 			dev_err(&device->cdev->dev,
1053 				"An I/O command request was rejected\n");
1054 
1055 		erp = dasd_3990_erp_cleanup(erp, DASD_CQR_FAILED);
1056 	}
1057 
1058 	return erp;
1059 
1060 }				/* end dasd_3990_erp_com_rej */
1061 
1062 /*
1063  * DASD_3990_ERP_BUS_OUT
1064  *
1065  * DESCRIPTION
1066  *   Handles 24 byte 'Bus Out Parity Check' error.
1067  *
1068  * PARAMETER
1069  *   erp		current erp_head
1070  * RETURN VALUES
1071  *   erp		new erp_head - pointer to new ERP
1072  */
1073 static struct dasd_ccw_req *
1074 dasd_3990_erp_bus_out(struct dasd_ccw_req * erp)
1075 {
1076 
1077 	struct dasd_device *device = erp->startdev;
1078 
1079 	/* first time set initial retry counter and erp_function */
1080 	/* and retry once without blocking queue		 */
1081 	/* (this enables easier enqueing of the cqr)		 */
1082 	if (erp->function != dasd_3990_erp_bus_out) {
1083 		erp->retries = 256;
1084 		erp->function = dasd_3990_erp_bus_out;
1085 
1086 	} else {
1087 
1088 		/* issue a message and wait for 'device ready' interrupt */
1089 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1090 			    "bus out parity error or BOPC requested by "
1091 			    "channel");
1092 
1093 		dasd_3990_erp_block_queue(erp, 60*HZ);
1094 
1095 	}
1096 
1097 	return erp;
1098 
1099 }				/* end dasd_3990_erp_bus_out */
1100 
1101 /*
1102  * DASD_3990_ERP_EQUIP_CHECK
1103  *
1104  * DESCRIPTION
1105  *   Handles 24 byte 'Equipment Check' error.
1106  *
1107  * PARAMETER
1108  *   erp		current erp_head
1109  * RETURN VALUES
1110  *   erp		new erp_head - pointer to new ERP
1111  */
1112 static struct dasd_ccw_req *
1113 dasd_3990_erp_equip_check(struct dasd_ccw_req * erp, char *sense)
1114 {
1115 
1116 	struct dasd_device *device = erp->startdev;
1117 
1118 	erp->function = dasd_3990_erp_equip_check;
1119 
1120 	if (sense[1] & SNS1_WRITE_INHIBITED) {
1121 		dev_err(&device->cdev->dev, "Write inhibited path encountered\n");
1122 
1123 		erp = dasd_3990_erp_action_1(erp);
1124 
1125 	} else if (sense[2] & SNS2_ENV_DATA_PRESENT) {
1126 
1127 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1128 			    "Equipment Check - " "environmental data present");
1129 
1130 		dasd_3990_handle_env_data(erp, sense);
1131 
1132 		erp = dasd_3990_erp_action_4(erp, sense);
1133 
1134 	} else if (sense[1] & SNS1_PERM_ERR) {
1135 
1136 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1137 			    "Equipment Check - retry exhausted or "
1138 			    "undesirable");
1139 
1140 		erp = dasd_3990_erp_action_1(erp);
1141 
1142 	} else {
1143 		/* all other equipment checks - Action 5 */
1144 		/* rest is done when retries == 0 */
1145 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1146 			    "Equipment check or processing error");
1147 
1148 		erp = dasd_3990_erp_action_5(erp);
1149 	}
1150 	return erp;
1151 
1152 }				/* end dasd_3990_erp_equip_check */
1153 
1154 /*
1155  * DASD_3990_ERP_DATA_CHECK
1156  *
1157  * DESCRIPTION
1158  *   Handles 24 byte 'Data Check' error.
1159  *
1160  * PARAMETER
1161  *   erp		current erp_head
1162  * RETURN VALUES
1163  *   erp		new erp_head - pointer to new ERP
1164  */
1165 static struct dasd_ccw_req *
1166 dasd_3990_erp_data_check(struct dasd_ccw_req * erp, char *sense)
1167 {
1168 
1169 	struct dasd_device *device = erp->startdev;
1170 
1171 	erp->function = dasd_3990_erp_data_check;
1172 
1173 	if (sense[2] & SNS2_CORRECTABLE) {	/* correctable data check */
1174 
1175 		/* issue message that the data has been corrected */
1176 		dev_emerg(&device->cdev->dev,
1177 			    "Data recovered during retry with PCI "
1178 			    "fetch mode active\n");
1179 
1180 		/* not possible to handle this situation in Linux */
1181 		panic("No way to inform application about the possibly "
1182 		      "incorrect data");
1183 
1184 	} else if (sense[2] & SNS2_ENV_DATA_PRESENT) {
1185 
1186 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1187 			    "Uncorrectable data check recovered secondary "
1188 			    "addr of duplex pair");
1189 
1190 		erp = dasd_3990_erp_action_4(erp, sense);
1191 
1192 	} else if (sense[1] & SNS1_PERM_ERR) {
1193 
1194 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1195 			    "Uncorrectable data check with internal "
1196 			    "retry exhausted");
1197 
1198 		erp = dasd_3990_erp_action_1(erp);
1199 
1200 	} else {
1201 		/* all other data checks */
1202 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1203 			    "Uncorrectable data check with retry count "
1204 			    "exhausted...");
1205 
1206 		erp = dasd_3990_erp_action_5(erp);
1207 	}
1208 
1209 	return erp;
1210 
1211 }				/* end dasd_3990_erp_data_check */
1212 
1213 /*
1214  * DASD_3990_ERP_OVERRUN
1215  *
1216  * DESCRIPTION
1217  *   Handles 24 byte 'Overrun' error.
1218  *
1219  * PARAMETER
1220  *   erp		current erp_head
1221  * RETURN VALUES
1222  *   erp		new erp_head - pointer to new ERP
1223  */
1224 static struct dasd_ccw_req *
1225 dasd_3990_erp_overrun(struct dasd_ccw_req * erp, char *sense)
1226 {
1227 
1228 	struct dasd_device *device = erp->startdev;
1229 
1230 	erp->function = dasd_3990_erp_overrun;
1231 
1232 	DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1233 		    "Overrun - service overrun or overrun"
1234 		    " error requested by channel");
1235 
1236 	erp = dasd_3990_erp_action_5(erp);
1237 
1238 	return erp;
1239 
1240 }				/* end dasd_3990_erp_overrun */
1241 
1242 /*
1243  * DASD_3990_ERP_INV_FORMAT
1244  *
1245  * DESCRIPTION
1246  *   Handles 24 byte 'Invalid Track Format' error.
1247  *
1248  * PARAMETER
1249  *   erp		current erp_head
1250  * RETURN VALUES
1251  *   erp		new erp_head - pointer to new ERP
1252  */
1253 static struct dasd_ccw_req *
1254 dasd_3990_erp_inv_format(struct dasd_ccw_req * erp, char *sense)
1255 {
1256 
1257 	struct dasd_device *device = erp->startdev;
1258 
1259 	erp->function = dasd_3990_erp_inv_format;
1260 
1261 	if (sense[2] & SNS2_ENV_DATA_PRESENT) {
1262 
1263 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1264 			    "Track format error when destaging or "
1265 			    "staging data");
1266 
1267 		dasd_3990_handle_env_data(erp, sense);
1268 
1269 		erp = dasd_3990_erp_action_4(erp, sense);
1270 
1271 	} else {
1272 		dev_err(&device->cdev->dev, "Track format is not valid\n");
1273 		erp = dasd_3990_erp_cleanup(erp, DASD_CQR_FAILED);
1274 	}
1275 
1276 	return erp;
1277 
1278 }				/* end dasd_3990_erp_inv_format */
1279 
1280 /*
1281  * DASD_3990_ERP_EOC
1282  *
1283  * DESCRIPTION
1284  *   Handles 24 byte 'End-of-Cylinder' error.
1285  *
1286  * PARAMETER
1287  *   erp		already added default erp
1288  * RETURN VALUES
1289  *   erp		pointer to original (failed) cqr.
1290  */
1291 static struct dasd_ccw_req *
1292 dasd_3990_erp_EOC(struct dasd_ccw_req * default_erp, char *sense)
1293 {
1294 
1295 	struct dasd_device *device = default_erp->startdev;
1296 
1297 	dev_err(&device->cdev->dev,
1298 		"The cylinder data for accessing the DASD is inconsistent\n");
1299 
1300 	/* implement action 7 - BUG */
1301 	return dasd_3990_erp_cleanup(default_erp, DASD_CQR_FAILED);
1302 
1303 }				/* end dasd_3990_erp_EOC */
1304 
1305 /*
1306  * DASD_3990_ERP_ENV_DATA
1307  *
1308  * DESCRIPTION
1309  *   Handles 24 byte 'Environmental-Data Present' error.
1310  *
1311  * PARAMETER
1312  *   erp		current erp_head
1313  * RETURN VALUES
1314  *   erp		new erp_head - pointer to new ERP
1315  */
1316 static struct dasd_ccw_req *
1317 dasd_3990_erp_env_data(struct dasd_ccw_req * erp, char *sense)
1318 {
1319 
1320 	struct dasd_device *device = erp->startdev;
1321 
1322 	erp->function = dasd_3990_erp_env_data;
1323 
1324 	DBF_DEV_EVENT(DBF_WARNING, device, "%s", "Environmental data present");
1325 
1326 	dasd_3990_handle_env_data(erp, sense);
1327 
1328 	/* don't retry on disabled interface */
1329 	if (sense[7] != 0x0F) {
1330 		erp = dasd_3990_erp_action_4(erp, sense);
1331 	} else {
1332 		erp->status = DASD_CQR_FILLED;
1333 	}
1334 
1335 	return erp;
1336 
1337 }				/* end dasd_3990_erp_env_data */
1338 
1339 /*
1340  * DASD_3990_ERP_NO_REC
1341  *
1342  * DESCRIPTION
1343  *   Handles 24 byte 'No Record Found' error.
1344  *
1345  * PARAMETER
1346  *   erp		already added default ERP
1347  *
1348  * RETURN VALUES
1349  *   erp		new erp_head - pointer to new ERP
1350  */
1351 static struct dasd_ccw_req *
1352 dasd_3990_erp_no_rec(struct dasd_ccw_req * default_erp, char *sense)
1353 {
1354 
1355 	struct dasd_device *device = default_erp->startdev;
1356 
1357 	/*
1358 	 * In some cases the 'No Record Found' error might be expected and
1359 	 * log messages shouldn't be written then.
1360 	 * Check if the according suppress bit is set.
1361 	 */
1362 	if (!test_bit(DASD_CQR_SUPPRESS_NRF, &default_erp->flags))
1363 		dev_err(&device->cdev->dev,
1364 			"The specified record was not found\n");
1365 
1366 	return dasd_3990_erp_cleanup(default_erp, DASD_CQR_FAILED);
1367 
1368 }				/* end dasd_3990_erp_no_rec */
1369 
1370 /*
1371  * DASD_3990_ERP_FILE_PROT
1372  *
1373  * DESCRIPTION
1374  *   Handles 24 byte 'File Protected' error.
1375  *   Note: Seek related recovery is not implemented because
1376  *	   wee don't use the seek command yet.
1377  *
1378  * PARAMETER
1379  *   erp		current erp_head
1380  * RETURN VALUES
1381  *   erp		new erp_head - pointer to new ERP
1382  */
1383 static struct dasd_ccw_req *
1384 dasd_3990_erp_file_prot(struct dasd_ccw_req * erp)
1385 {
1386 
1387 	struct dasd_device *device = erp->startdev;
1388 
1389 	/*
1390 	 * In some cases the 'File Protected' error might be expected and
1391 	 * log messages shouldn't be written then.
1392 	 * Check if the according suppress bit is set.
1393 	 */
1394 	if (!test_bit(DASD_CQR_SUPPRESS_FP, &erp->flags))
1395 		dev_err(&device->cdev->dev,
1396 			"Accessing the DASD failed because of a hardware error\n");
1397 
1398 	return dasd_3990_erp_cleanup(erp, DASD_CQR_FAILED);
1399 
1400 }				/* end dasd_3990_erp_file_prot */
1401 
1402 /*
1403  * DASD_3990_ERP_INSPECT_ALIAS
1404  *
1405  * DESCRIPTION
1406  *   Checks if the original request was started on an alias device.
1407  *   If yes, it modifies the original and the erp request so that
1408  *   the erp request can be started on a base device.
1409  *
1410  * PARAMETER
1411  *   erp		pointer to the currently created default ERP
1412  *
1413  * RETURN VALUES
1414  *   erp		pointer to the modified ERP, or NULL
1415  */
1416 
1417 static struct dasd_ccw_req *dasd_3990_erp_inspect_alias(
1418 						struct dasd_ccw_req *erp)
1419 {
1420 	struct dasd_ccw_req *cqr = erp->refers;
1421 	char *sense;
1422 
1423 	if (cqr->block &&
1424 	    (cqr->block->base != cqr->startdev)) {
1425 
1426 		sense = dasd_get_sense(&erp->refers->irb);
1427 		/*
1428 		 * dynamic pav may have changed base alias mapping
1429 		 */
1430 		if (!test_bit(DASD_FLAG_OFFLINE, &cqr->startdev->flags) && sense
1431 		    && (sense[0] == 0x10) && (sense[7] == 0x0F)
1432 		    && (sense[8] == 0x67)) {
1433 			/*
1434 			 * remove device from alias handling to prevent new
1435 			 * requests from being scheduled on the
1436 			 * wrong alias device
1437 			 */
1438 			dasd_alias_remove_device(cqr->startdev);
1439 
1440 			/* schedule worker to reload device */
1441 			dasd_reload_device(cqr->startdev);
1442 		}
1443 
1444 		if (cqr->startdev->features & DASD_FEATURE_ERPLOG) {
1445 			DBF_DEV_EVENT(DBF_ERR, cqr->startdev,
1446 				    "ERP on alias device for request %p,"
1447 				    " recover on base device %s", cqr,
1448 				    dev_name(&cqr->block->base->cdev->dev));
1449 		}
1450 		dasd_eckd_reset_ccw_to_base_io(cqr);
1451 		erp->startdev = cqr->block->base;
1452 		erp->function = dasd_3990_erp_inspect_alias;
1453 		return erp;
1454 	} else
1455 		return NULL;
1456 }
1457 
1458 
1459 /*
1460  * DASD_3990_ERP_INSPECT_24
1461  *
1462  * DESCRIPTION
1463  *   Does a detailed inspection of the 24 byte sense data
1464  *   and sets up a related error recovery action.
1465  *
1466  * PARAMETER
1467  *   sense		sense data of the actual error
1468  *   erp		pointer to the currently created default ERP
1469  *
1470  * RETURN VALUES
1471  *   erp		pointer to the (addtitional) ERP
1472  */
1473 static struct dasd_ccw_req *
1474 dasd_3990_erp_inspect_24(struct dasd_ccw_req * erp, char *sense)
1475 {
1476 
1477 	struct dasd_ccw_req *erp_filled = NULL;
1478 
1479 	/* Check sense for ....	   */
1480 	/* 'Command Reject'	   */
1481 	if ((erp_filled == NULL) && (sense[0] & SNS0_CMD_REJECT)) {
1482 		erp_filled = dasd_3990_erp_com_rej(erp, sense);
1483 	}
1484 	/* 'Intervention Required' */
1485 	if ((erp_filled == NULL) && (sense[0] & SNS0_INTERVENTION_REQ)) {
1486 		erp_filled = dasd_3990_erp_int_req(erp);
1487 	}
1488 	/* 'Bus Out Parity Check'  */
1489 	if ((erp_filled == NULL) && (sense[0] & SNS0_BUS_OUT_CHECK)) {
1490 		erp_filled = dasd_3990_erp_bus_out(erp);
1491 	}
1492 	/* 'Equipment Check'	   */
1493 	if ((erp_filled == NULL) && (sense[0] & SNS0_EQUIPMENT_CHECK)) {
1494 		erp_filled = dasd_3990_erp_equip_check(erp, sense);
1495 	}
1496 	/* 'Data Check'		   */
1497 	if ((erp_filled == NULL) && (sense[0] & SNS0_DATA_CHECK)) {
1498 		erp_filled = dasd_3990_erp_data_check(erp, sense);
1499 	}
1500 	/* 'Overrun'		   */
1501 	if ((erp_filled == NULL) && (sense[0] & SNS0_OVERRUN)) {
1502 		erp_filled = dasd_3990_erp_overrun(erp, sense);
1503 	}
1504 	/* 'Invalid Track Format'  */
1505 	if ((erp_filled == NULL) && (sense[1] & SNS1_INV_TRACK_FORMAT)) {
1506 		erp_filled = dasd_3990_erp_inv_format(erp, sense);
1507 	}
1508 	/* 'End-of-Cylinder'	   */
1509 	if ((erp_filled == NULL) && (sense[1] & SNS1_EOC)) {
1510 		erp_filled = dasd_3990_erp_EOC(erp, sense);
1511 	}
1512 	/* 'Environmental Data'	   */
1513 	if ((erp_filled == NULL) && (sense[2] & SNS2_ENV_DATA_PRESENT)) {
1514 		erp_filled = dasd_3990_erp_env_data(erp, sense);
1515 	}
1516 	/* 'No Record Found'	   */
1517 	if ((erp_filled == NULL) && (sense[1] & SNS1_NO_REC_FOUND)) {
1518 		erp_filled = dasd_3990_erp_no_rec(erp, sense);
1519 	}
1520 	/* 'File Protected'	   */
1521 	if ((erp_filled == NULL) && (sense[1] & SNS1_FILE_PROTECTED)) {
1522 		erp_filled = dasd_3990_erp_file_prot(erp);
1523 	}
1524 	/* other (unknown) error - do default ERP */
1525 	if (erp_filled == NULL) {
1526 
1527 		erp_filled = erp;
1528 	}
1529 
1530 	return erp_filled;
1531 
1532 }				/* END dasd_3990_erp_inspect_24 */
1533 
1534 /*
1535  *****************************************************************************
1536  * 32 byte sense ERP functions (only)
1537  *****************************************************************************
1538  */
1539 
1540 /*
1541  * DASD_3990_ERPACTION_10_32
1542  *
1543  * DESCRIPTION
1544  *   Handles 32 byte 'Action 10' of Single Program Action Codes.
1545  *   Just retry and if retry doesn't work, return with error.
1546  *
1547  * PARAMETER
1548  *   erp		current erp_head
1549  *   sense		current sense data
1550  * RETURN VALUES
1551  *   erp		modified erp_head
1552  */
1553 static struct dasd_ccw_req *
1554 dasd_3990_erp_action_10_32(struct dasd_ccw_req * erp, char *sense)
1555 {
1556 
1557 	struct dasd_device *device = erp->startdev;
1558 
1559 	erp->retries = 256;
1560 	erp->function = dasd_3990_erp_action_10_32;
1561 
1562 	DBF_DEV_EVENT(DBF_WARNING, device, "%s", "Perform logging requested");
1563 
1564 	return erp;
1565 
1566 }				/* end dasd_3990_erp_action_10_32 */
1567 
1568 /*
1569  * DASD_3990_ERP_ACTION_1B_32
1570  *
1571  * DESCRIPTION
1572  *   Handles 32 byte 'Action 1B' of Single Program Action Codes.
1573  *   A write operation could not be finished because of an unexpected
1574  *   condition.
1575  *   The already created 'default erp' is used to get the link to
1576  *   the erp chain, but it can not be used for this recovery
1577  *   action because it contains no DE/LO data space.
1578  *
1579  * PARAMETER
1580  *   default_erp	already added default erp.
1581  *   sense		current sense data
1582  *
1583  * RETURN VALUES
1584  *   erp		new erp or
1585  *			default_erp in case of imprecise ending or error
1586  */
1587 static struct dasd_ccw_req *
1588 dasd_3990_erp_action_1B_32(struct dasd_ccw_req * default_erp, char *sense)
1589 {
1590 
1591 	struct dasd_device *device = default_erp->startdev;
1592 	dma32_t cpa = 0;
1593 	struct dasd_ccw_req *cqr;
1594 	struct dasd_ccw_req *erp;
1595 	struct DE_eckd_data *DE_data;
1596 	struct PFX_eckd_data *PFX_data;
1597 	char *LO_data;		/* LO_eckd_data_t */
1598 	struct ccw1 *ccw, *oldccw;
1599 
1600 	DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1601 		    "Write not finished because of unexpected condition");
1602 
1603 	default_erp->function = dasd_3990_erp_action_1B_32;
1604 
1605 	/* determine the original cqr */
1606 	cqr = default_erp;
1607 
1608 	while (cqr->refers != NULL) {
1609 		cqr = cqr->refers;
1610 	}
1611 
1612 	if (scsw_is_tm(&cqr->irb.scsw)) {
1613 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1614 			      "32 bit sense, action 1B is not defined"
1615 			      " in transport mode - just retry");
1616 		return default_erp;
1617 	}
1618 
1619 	/* for imprecise ending just do default erp */
1620 	if (sense[1] & 0x01) {
1621 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1622 			    "Imprecise ending is set - just retry");
1623 
1624 		return default_erp;
1625 	}
1626 
1627 	/* determine the address of the CCW to be restarted */
1628 	/* Imprecise ending is not set -> addr from IRB-SCSW */
1629 	cpa = default_erp->refers->irb.scsw.cmd.cpa;
1630 
1631 	if (cpa == 0) {
1632 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1633 			    "Unable to determine address of the CCW "
1634 			    "to be restarted");
1635 
1636 		return dasd_3990_erp_cleanup(default_erp, DASD_CQR_FAILED);
1637 	}
1638 
1639 	/* Build new ERP request including DE/LO */
1640 	erp = dasd_alloc_erp_request(cqr->magic,
1641 				     2 + 1,/* DE/LO + TIC */
1642 				     sizeof(struct DE_eckd_data) +
1643 				     sizeof(struct LO_eckd_data), device);
1644 
1645 	if (IS_ERR(erp)) {
1646 		DBF_DEV_EVENT(DBF_ERR, device, "%s",
1647 			      "Unable to allocate ERP request (1B 32)");
1648 		return dasd_3990_erp_cleanup(default_erp, DASD_CQR_FAILED);
1649 	}
1650 
1651 	/* use original DE */
1652 	DE_data = erp->data;
1653 	oldccw = cqr->cpaddr;
1654 	if (oldccw->cmd_code == DASD_ECKD_CCW_PFX) {
1655 		PFX_data = cqr->data;
1656 		memcpy(DE_data, &PFX_data->define_extent,
1657 		       sizeof(struct DE_eckd_data));
1658 	} else
1659 		memcpy(DE_data, cqr->data, sizeof(struct DE_eckd_data));
1660 
1661 	/* create LO */
1662 	LO_data = erp->data + sizeof(struct DE_eckd_data);
1663 
1664 	if ((sense[3] == 0x01) && (LO_data[1] & 0x01)) {
1665 		/* should not */
1666 		return dasd_3990_erp_cleanup(default_erp, DASD_CQR_FAILED);
1667 	}
1668 
1669 	if ((sense[7] & 0x3F) == 0x01) {
1670 		/* operation code is WRITE DATA -> data area orientation */
1671 		LO_data[0] = 0x81;
1672 
1673 	} else if ((sense[7] & 0x3F) == 0x03) {
1674 		/* operation code is FORMAT WRITE -> index orientation */
1675 		LO_data[0] = 0xC3;
1676 
1677 	} else {
1678 		LO_data[0] = sense[7];	/* operation */
1679 	}
1680 
1681 	LO_data[1] = sense[8];	/* auxiliary */
1682 	LO_data[2] = sense[9];
1683 	LO_data[3] = sense[3];	/* count */
1684 	LO_data[4] = sense[29];	/* seek_addr.cyl */
1685 	LO_data[5] = sense[30];	/* seek_addr.cyl 2nd byte */
1686 	LO_data[7] = sense[31];	/* seek_addr.head 2nd byte */
1687 
1688 	memcpy(&(LO_data[8]), &(sense[11]), 8);
1689 
1690 	/* create DE ccw */
1691 	ccw = erp->cpaddr;
1692 	memset(ccw, 0, sizeof(struct ccw1));
1693 	ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
1694 	ccw->flags = CCW_FLAG_CC;
1695 	ccw->count = 16;
1696 	ccw->cda = virt_to_dma32(DE_data);
1697 
1698 	/* create LO ccw */
1699 	ccw++;
1700 	memset(ccw, 0, sizeof(struct ccw1));
1701 	ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
1702 	ccw->flags = CCW_FLAG_CC;
1703 	ccw->count = 16;
1704 	ccw->cda = virt_to_dma32(LO_data);
1705 
1706 	/* TIC to the failed ccw */
1707 	ccw++;
1708 	ccw->cmd_code = CCW_CMD_TIC;
1709 	ccw->cda = cpa;
1710 
1711 	/* fill erp related fields */
1712 	erp->flags = default_erp->flags;
1713 	erp->function = dasd_3990_erp_action_1B_32;
1714 	erp->refers = default_erp->refers;
1715 	erp->startdev = device;
1716 	erp->memdev = device;
1717 	erp->magic = default_erp->magic;
1718 	erp->expires = default_erp->expires;
1719 	erp->retries = 256;
1720 	erp->buildclk = get_tod_clock();
1721 	erp->status = DASD_CQR_FILLED;
1722 
1723 	/* remove the default erp */
1724 	dasd_free_erp_request(default_erp, device);
1725 
1726 	return erp;
1727 
1728 }				/* end dasd_3990_erp_action_1B_32 */
1729 
1730 /*
1731  * DASD_3990_UPDATE_1B
1732  *
1733  * DESCRIPTION
1734  *   Handles the update to the 32 byte 'Action 1B' of Single Program
1735  *   Action Codes in case the first action was not successful.
1736  *   The already created 'previous_erp' is the currently not successful
1737  *   ERP.
1738  *
1739  * PARAMETER
1740  *   previous_erp	already created previous erp.
1741  *   sense		current sense data
1742  * RETURN VALUES
1743  *   erp		modified erp
1744  */
1745 static struct dasd_ccw_req *
1746 dasd_3990_update_1B(struct dasd_ccw_req * previous_erp, char *sense)
1747 {
1748 
1749 	struct dasd_device *device = previous_erp->startdev;
1750 	dma32_t cpa = 0;
1751 	struct dasd_ccw_req *cqr;
1752 	struct dasd_ccw_req *erp;
1753 	char *LO_data;		/* struct LO_eckd_data */
1754 	struct ccw1 *ccw;
1755 
1756 	DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1757 		    "Write not finished because of unexpected condition"
1758 		    " - follow on");
1759 
1760 	/* determine the original cqr */
1761 	cqr = previous_erp;
1762 
1763 	while (cqr->refers != NULL) {
1764 		cqr = cqr->refers;
1765 	}
1766 
1767 	if (scsw_is_tm(&cqr->irb.scsw)) {
1768 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1769 			      "32 bit sense, action 1B, update,"
1770 			      " in transport mode - just retry");
1771 		return previous_erp;
1772 	}
1773 
1774 	/* for imprecise ending just do default erp */
1775 	if (sense[1] & 0x01) {
1776 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1777 			    "Imprecise ending is set - just retry");
1778 
1779 		previous_erp->status = DASD_CQR_FILLED;
1780 
1781 		return previous_erp;
1782 	}
1783 
1784 	/* determine the address of the CCW to be restarted */
1785 	/* Imprecise ending is not set -> addr from IRB-SCSW */
1786 	cpa = previous_erp->irb.scsw.cmd.cpa;
1787 
1788 	if (cpa == 0) {
1789 		dev_err(&device->cdev->dev,
1790 			"Unable to determine address of to be restarted CCW\n");
1791 
1792 		previous_erp->status = DASD_CQR_FAILED;
1793 
1794 		return previous_erp;
1795 	}
1796 
1797 	erp = previous_erp;
1798 
1799 	/* update the LO with the new returned sense data  */
1800 	LO_data = erp->data + sizeof(struct DE_eckd_data);
1801 
1802 	if ((sense[3] == 0x01) && (LO_data[1] & 0x01)) {
1803 		/* should not happen */
1804 		previous_erp->status = DASD_CQR_FAILED;
1805 
1806 		return previous_erp;
1807 	}
1808 
1809 	if ((sense[7] & 0x3F) == 0x01) {
1810 		/* operation code is WRITE DATA -> data area orientation */
1811 		LO_data[0] = 0x81;
1812 
1813 	} else if ((sense[7] & 0x3F) == 0x03) {
1814 		/* operation code is FORMAT WRITE -> index orientation */
1815 		LO_data[0] = 0xC3;
1816 
1817 	} else {
1818 		LO_data[0] = sense[7];	/* operation */
1819 	}
1820 
1821 	LO_data[1] = sense[8];	/* auxiliary */
1822 	LO_data[2] = sense[9];
1823 	LO_data[3] = sense[3];	/* count */
1824 	LO_data[4] = sense[29];	/* seek_addr.cyl */
1825 	LO_data[5] = sense[30];	/* seek_addr.cyl 2nd byte */
1826 	LO_data[7] = sense[31];	/* seek_addr.head 2nd byte */
1827 
1828 	memcpy(&(LO_data[8]), &(sense[11]), 8);
1829 
1830 	/* TIC to the failed ccw */
1831 	ccw = erp->cpaddr;	/* addr of DE ccw */
1832 	ccw++;			/* addr of LE ccw */
1833 	ccw++;			/* addr of TIC ccw */
1834 	ccw->cda = cpa;
1835 
1836 	erp->status = DASD_CQR_FILLED;
1837 
1838 	return erp;
1839 
1840 }				/* end dasd_3990_update_1B */
1841 
1842 /*
1843  * DASD_3990_ERP_COMPOUND_RETRY
1844  *
1845  * DESCRIPTION
1846  *   Handles the compound ERP action retry code.
1847  *   NOTE: At least one retry is done even if zero is specified
1848  *	   by the sense data. This makes enqueueing of the request
1849  *	   easier.
1850  *
1851  * PARAMETER
1852  *   sense		sense data of the actual error
1853  *   erp		pointer to the currently created ERP
1854  *
1855  * RETURN VALUES
1856  *   erp		modified ERP pointer
1857  *
1858  */
1859 static void
1860 dasd_3990_erp_compound_retry(struct dasd_ccw_req * erp, char *sense)
1861 {
1862 
1863 	switch (sense[25] & 0x03) {
1864 	case 0x00:		/* no not retry */
1865 		erp->retries = 1;
1866 		break;
1867 
1868 	case 0x01:		/* retry 2 times */
1869 		erp->retries = 2;
1870 		break;
1871 
1872 	case 0x02:		/* retry 10 times */
1873 		erp->retries = 10;
1874 		break;
1875 
1876 	case 0x03:		/* retry 256 times */
1877 		erp->retries = 256;
1878 		break;
1879 
1880 	default:
1881 		BUG();
1882 	}
1883 
1884 	erp->function = dasd_3990_erp_compound_retry;
1885 
1886 }				/* end dasd_3990_erp_compound_retry */
1887 
1888 /*
1889  * DASD_3990_ERP_COMPOUND_PATH
1890  *
1891  * DESCRIPTION
1892  *   Handles the compound ERP action for retry on alternate
1893  *   channel path.
1894  *
1895  * PARAMETER
1896  *   sense		sense data of the actual error
1897  *   erp		pointer to the currently created ERP
1898  *
1899  * RETURN VALUES
1900  *   erp		modified ERP pointer
1901  *
1902  */
1903 static void
1904 dasd_3990_erp_compound_path(struct dasd_ccw_req * erp, char *sense)
1905 {
1906 	if (sense[25] & DASD_SENSE_BIT_3) {
1907 		dasd_3990_erp_alternate_path(erp);
1908 
1909 		if (erp->status == DASD_CQR_FAILED &&
1910 		    !test_bit(DASD_CQR_VERIFY_PATH, &erp->flags)) {
1911 			/* reset the lpm and the status to be able to
1912 			 * try further actions. */
1913 			erp->lpm = dasd_path_get_opm(erp->startdev);
1914 			erp->status = DASD_CQR_NEED_ERP;
1915 		}
1916 	}
1917 
1918 	erp->function = dasd_3990_erp_compound_path;
1919 
1920 }				/* end dasd_3990_erp_compound_path */
1921 
1922 /*
1923  * DASD_3990_ERP_COMPOUND_CODE
1924  *
1925  * DESCRIPTION
1926  *   Handles the compound ERP action for retry code.
1927  *
1928  * PARAMETER
1929  *   sense		sense data of the actual error
1930  *   erp		pointer to the currently created ERP
1931  *
1932  * RETURN VALUES
1933  *   erp		NEW ERP pointer
1934  *
1935  */
1936 static struct dasd_ccw_req *
1937 dasd_3990_erp_compound_code(struct dasd_ccw_req * erp, char *sense)
1938 {
1939 
1940 	if (sense[25] & DASD_SENSE_BIT_2) {
1941 
1942 		switch (sense[28]) {
1943 		case 0x17:
1944 			/* issue a Diagnostic Control command with an
1945 			 * Inhibit Write subcommand and controller modifier */
1946 			erp = dasd_3990_erp_DCTL(erp, 0x20);
1947 			break;
1948 
1949 		case 0x25:
1950 			/* wait for 5 seconds and retry again */
1951 			erp->retries = 1;
1952 
1953 			dasd_3990_erp_block_queue (erp, 5*HZ);
1954 			break;
1955 
1956 		default:
1957 			/* should not happen - continue */
1958 			break;
1959 		}
1960 	}
1961 
1962 	erp->function = dasd_3990_erp_compound_code;
1963 
1964 	return erp;
1965 
1966 }				/* end dasd_3990_erp_compound_code */
1967 
1968 /*
1969  * DASD_3990_ERP_COMPOUND_CONFIG
1970  *
1971  * DESCRIPTION
1972  *   Handles the compound ERP action for configuration
1973  *   dependent error.
1974  *   Note: duplex handling is not implemented (yet).
1975  *
1976  * PARAMETER
1977  *   sense		sense data of the actual error
1978  *   erp		pointer to the currently created ERP
1979  *
1980  * RETURN VALUES
1981  *   erp		modified ERP pointer
1982  *
1983  */
1984 static void
1985 dasd_3990_erp_compound_config(struct dasd_ccw_req * erp, char *sense)
1986 {
1987 
1988 	if ((sense[25] & DASD_SENSE_BIT_1) && (sense[26] & DASD_SENSE_BIT_2)) {
1989 		struct dasd_device *device = erp->startdev;
1990 		dev_err(&device->cdev->dev,
1991 			"Compound configuration error occurred\n");
1992 	}
1993 
1994 	erp->function = dasd_3990_erp_compound_config;
1995 
1996 }				/* end dasd_3990_erp_compound_config */
1997 
1998 /*
1999  * DASD_3990_ERP_COMPOUND
2000  *
2001  * DESCRIPTION
2002  *   Does the further compound program action if
2003  *   compound retry was not successful.
2004  *
2005  * PARAMETER
2006  *   sense		sense data of the actual error
2007  *   erp		pointer to the current (failed) ERP
2008  *
2009  * RETURN VALUES
2010  *   erp		(additional) ERP pointer
2011  *
2012  */
2013 static struct dasd_ccw_req *
2014 dasd_3990_erp_compound(struct dasd_ccw_req * erp, char *sense)
2015 {
2016 
2017 	if ((erp->function == dasd_3990_erp_compound_retry) &&
2018 	    (erp->status == DASD_CQR_NEED_ERP)) {
2019 
2020 		dasd_3990_erp_compound_path(erp, sense);
2021 	}
2022 
2023 	if ((erp->function == dasd_3990_erp_compound_path) &&
2024 	    (erp->status == DASD_CQR_NEED_ERP)) {
2025 
2026 		erp = dasd_3990_erp_compound_code(erp, sense);
2027 	}
2028 
2029 	if ((erp->function == dasd_3990_erp_compound_code) &&
2030 	    (erp->status == DASD_CQR_NEED_ERP)) {
2031 
2032 		dasd_3990_erp_compound_config(erp, sense);
2033 	}
2034 
2035 	/* if no compound action ERP specified, the request failed */
2036 	if (erp->status == DASD_CQR_NEED_ERP)
2037 		erp->status = DASD_CQR_FAILED;
2038 
2039 	return erp;
2040 
2041 }				/* end dasd_3990_erp_compound */
2042 
2043 /*
2044  *DASD_3990_ERP_HANDLE_SIM
2045  *
2046  *DESCRIPTION
2047  *  inspects the SIM SENSE data and starts an appropriate action
2048  *
2049  * PARAMETER
2050  *   sense	   sense data of the actual error
2051  *
2052  * RETURN VALUES
2053  *   none
2054  */
2055 void
2056 dasd_3990_erp_handle_sim(struct dasd_device *device, char *sense)
2057 {
2058 	/* print message according to log or message to operator mode */
2059 	if ((sense[24] & DASD_SIM_MSG_TO_OP) || (sense[1] & 0x10)) {
2060 		/* print SIM SRC from RefCode */
2061 		dev_err(&device->cdev->dev, "SIM - SRC: "
2062 			    "%02x%02x%02x%02x\n", sense[22],
2063 			    sense[23], sense[11], sense[12]);
2064 	} else if (sense[24] & DASD_SIM_LOG) {
2065 		/* print SIM SRC Refcode */
2066 		dev_warn(&device->cdev->dev, "log SIM - SRC: "
2067 			    "%02x%02x%02x%02x\n", sense[22],
2068 			    sense[23], sense[11], sense[12]);
2069 	}
2070 }
2071 
2072 /*
2073  * DASD_3990_ERP_INSPECT_32
2074  *
2075  * DESCRIPTION
2076  *   Does a detailed inspection of the 32 byte sense data
2077  *   and sets up a related error recovery action.
2078  *
2079  * PARAMETER
2080  *   sense		sense data of the actual error
2081  *   erp		pointer to the currently created default ERP
2082  *
2083  * RETURN VALUES
2084  *   erp_filled		pointer to the ERP
2085  *
2086  */
2087 static struct dasd_ccw_req *
2088 dasd_3990_erp_inspect_32(struct dasd_ccw_req * erp, char *sense)
2089 {
2090 
2091 	struct dasd_device *device = erp->startdev;
2092 
2093 	erp->function = dasd_3990_erp_inspect_32;
2094 
2095 	/* check for SIM sense data */
2096 	if ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)
2097 		dasd_3990_erp_handle_sim(device, sense);
2098 
2099 	if (sense[25] & DASD_SENSE_BIT_0) {
2100 
2101 		/* compound program action codes (byte25 bit 0 == '1') */
2102 		dasd_3990_erp_compound_retry(erp, sense);
2103 
2104 	} else {
2105 
2106 		/* single program action codes (byte25 bit 0 == '0') */
2107 		switch (sense[25]) {
2108 
2109 		case 0x00:	/* success - use default ERP for retries */
2110 			DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
2111 				    "ERP called for successful request"
2112 				    " - just retry");
2113 			break;
2114 
2115 		case 0x01:	/* fatal error */
2116 			dev_err(&device->cdev->dev,
2117 				    "ERP failed for the DASD\n");
2118 
2119 			erp = dasd_3990_erp_cleanup(erp, DASD_CQR_FAILED);
2120 			break;
2121 
2122 		case 0x02:	/* intervention required */
2123 		case 0x03:	/* intervention required during dual copy */
2124 			erp = dasd_3990_erp_int_req(erp);
2125 			break;
2126 
2127 		case 0x0F:
2128 			dev_err(&device->cdev->dev,
2129 				"Update write command error occurred\n");
2130 
2131 			erp = dasd_3990_erp_cleanup(erp, DASD_CQR_FAILED);
2132 			break;
2133 
2134 		case 0x10:  /* logging required for other channel program */
2135 			erp = dasd_3990_erp_action_10_32(erp, sense);
2136 			break;
2137 
2138 		case 0x15:
2139 			dev_err(&device->cdev->dev,
2140 				"Track outside defined extent error occurred\n");
2141 
2142 			erp = dasd_3990_erp_cleanup(erp, DASD_CQR_FAILED);
2143 			break;
2144 
2145 		case 0x1B:	/* unexpected condition during write */
2146 
2147 			erp = dasd_3990_erp_action_1B_32(erp, sense);
2148 			break;
2149 
2150 		case 0x1C:	/* invalid data */
2151 			dev_emerg(&device->cdev->dev,
2152 				    "Data recovered during retry with PCI "
2153 				    "fetch mode active\n");
2154 
2155 			/* not possible to handle this situation in Linux */
2156 			panic
2157 			    ("Invalid data - No way to inform application "
2158 			     "about the possibly incorrect data");
2159 			break;
2160 
2161 		case 0x1D:	/* state-change pending */
2162 			DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2163 				    "A State change pending condition exists "
2164 				    "for the subsystem or device");
2165 
2166 			erp = dasd_3990_erp_action_4(erp, sense);
2167 			break;
2168 
2169 		case 0x1E:	/* busy */
2170 			DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2171 				    "Busy condition exists "
2172 				    "for the subsystem or device");
2173                         erp = dasd_3990_erp_action_4(erp, sense);
2174 			break;
2175 
2176 		default:	/* all others errors - default erp  */
2177 			break;
2178 		}
2179 	}
2180 
2181 	return erp;
2182 
2183 }				/* end dasd_3990_erp_inspect_32 */
2184 
2185 static void dasd_3990_erp_disable_path(struct dasd_device *device, __u8 lpum)
2186 {
2187 	int pos = pathmask_to_pos(lpum);
2188 
2189 	if (!(device->features & DASD_FEATURE_PATH_AUTODISABLE)) {
2190 		dev_err(&device->cdev->dev,
2191 			"Path %x.%02x (pathmask %02x) is operational despite excessive IFCCs\n",
2192 			device->path[pos].cssid, device->path[pos].chpid, lpum);
2193 		goto out;
2194 	}
2195 
2196 	/* no remaining path, cannot disable */
2197 	if (!(dasd_path_get_opm(device) & ~lpum)) {
2198 		dev_err(&device->cdev->dev,
2199 			"Last path %x.%02x (pathmask %02x) is operational despite excessive IFCCs\n",
2200 			device->path[pos].cssid, device->path[pos].chpid, lpum);
2201 		goto out;
2202 	}
2203 
2204 	dev_err(&device->cdev->dev,
2205 		"Path %x.%02x (pathmask %02x) is disabled - IFCC threshold exceeded\n",
2206 		device->path[pos].cssid, device->path[pos].chpid, lpum);
2207 	dasd_path_remove_opm(device, lpum);
2208 	dasd_path_add_ifccpm(device, lpum);
2209 
2210 out:
2211 	device->path[pos].errorclk = 0;
2212 	atomic_set(&device->path[pos].error_count, 0);
2213 }
2214 
2215 static void dasd_3990_erp_account_error(struct dasd_ccw_req *erp)
2216 {
2217 	struct dasd_device *device = erp->startdev;
2218 	__u8 lpum = erp->refers->irb.esw.esw1.lpum;
2219 	int pos = pathmask_to_pos(lpum);
2220 	unsigned long clk;
2221 
2222 	if (!device->path_thrhld)
2223 		return;
2224 
2225 	clk = get_tod_clock();
2226 	/*
2227 	 * check if the last error is longer ago than the timeout,
2228 	 * if so reset error state
2229 	 */
2230 	if ((tod_to_ns(clk - device->path[pos].errorclk) / NSEC_PER_SEC)
2231 	    >= device->path_interval) {
2232 		atomic_set(&device->path[pos].error_count, 0);
2233 		device->path[pos].errorclk = 0;
2234 	}
2235 	atomic_inc(&device->path[pos].error_count);
2236 	device->path[pos].errorclk = clk;
2237 	/* threshold exceeded disable path if possible */
2238 	if (atomic_read(&device->path[pos].error_count) >=
2239 	    device->path_thrhld)
2240 		dasd_3990_erp_disable_path(device, lpum);
2241 }
2242 
2243 /*
2244  *****************************************************************************
2245  * main ERP control functions (24 and 32 byte sense)
2246  *****************************************************************************
2247  */
2248 
2249 /*
2250  * DASD_3990_ERP_CONTROL_CHECK
2251  *
2252  * DESCRIPTION
2253  *   Does a generic inspection if a control check occurred and sets up
2254  *   the related error recovery procedure
2255  *
2256  * PARAMETER
2257  *   erp		pointer to the currently created default ERP
2258  *
2259  * RETURN VALUES
2260  *   erp_filled		pointer to the erp
2261  */
2262 
2263 static struct dasd_ccw_req *
2264 dasd_3990_erp_control_check(struct dasd_ccw_req *erp)
2265 {
2266 	struct dasd_device *device = erp->startdev;
2267 
2268 	if (scsw_cstat(&erp->refers->irb.scsw) & (SCHN_STAT_INTF_CTRL_CHK
2269 					   | SCHN_STAT_CHN_CTRL_CHK)) {
2270 		DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2271 			    "channel or interface control check");
2272 		dasd_3990_erp_account_error(erp);
2273 		erp = dasd_3990_erp_action_4(erp, NULL);
2274 	}
2275 	return erp;
2276 }
2277 
2278 /*
2279  * DASD_3990_ERP_INSPECT
2280  *
2281  * DESCRIPTION
2282  *   Does a detailed inspection for sense data by calling either
2283  *   the 24-byte or the 32-byte inspection routine.
2284  *
2285  * PARAMETER
2286  *   erp		pointer to the currently created default ERP
2287  * RETURN VALUES
2288  *   erp_new		contens was possibly modified
2289  */
2290 static struct dasd_ccw_req *
2291 dasd_3990_erp_inspect(struct dasd_ccw_req *erp)
2292 {
2293 
2294 	struct dasd_ccw_req *erp_new = NULL;
2295 	char *sense;
2296 
2297 	/* if this problem occurred on an alias retry on base */
2298 	erp_new = dasd_3990_erp_inspect_alias(erp);
2299 	if (erp_new)
2300 		return erp_new;
2301 
2302 	/* sense data are located in the refers record of the
2303 	 * already set up new ERP !
2304 	 * check if concurrent sens is available
2305 	 */
2306 	sense = dasd_get_sense(&erp->refers->irb);
2307 	if (!sense)
2308 		erp_new = dasd_3990_erp_control_check(erp);
2309 	/* distinguish between 24 and 32 byte sense data */
2310 	else if (sense[27] & DASD_SENSE_BIT_0) {
2311 
2312 		/* inspect the 24 byte sense data */
2313 		erp_new = dasd_3990_erp_inspect_24(erp, sense);
2314 
2315 	} else {
2316 
2317 		/* inspect the 32 byte sense data */
2318 		erp_new = dasd_3990_erp_inspect_32(erp, sense);
2319 
2320 	}	/* end distinguish between 24 and 32 byte sense data */
2321 
2322 	return erp_new;
2323 }
2324 
2325 /*
2326  * DASD_3990_ERP_ADD_ERP
2327  *
2328  * DESCRIPTION
2329  *   This function adds an additional request block (ERP) to the head of
2330  *   the given cqr (or erp).
2331  *   For a command mode cqr the erp is initialized as an default erp
2332  *   (retry TIC).
2333  *   For transport mode we make a copy of the original TCW (points to
2334  *   the original TCCB, TIDALs, etc.) but give it a fresh
2335  *   TSB so the original sense data will not be changed.
2336  *
2337  * PARAMETER
2338  *   cqr		head of the current ERP-chain (or single cqr if
2339  *			first error)
2340  * RETURN VALUES
2341  *   erp		pointer to new ERP-chain head
2342  */
2343 static struct dasd_ccw_req *dasd_3990_erp_add_erp(struct dasd_ccw_req *cqr)
2344 {
2345 
2346 	struct dasd_device *device = cqr->startdev;
2347 	struct ccw1 *ccw;
2348 	struct dasd_ccw_req *erp;
2349 	int cplength, datasize;
2350 	struct tcw *tcw;
2351 	struct tsb *tsb;
2352 
2353 	if (cqr->cpmode == 1) {
2354 		cplength = 0;
2355 		/* TCW needs to be 64 byte aligned, so leave enough room */
2356 		datasize = 64 + sizeof(struct tcw) + sizeof(struct tsb);
2357 	} else {
2358 		cplength = 2;
2359 		datasize = 0;
2360 	}
2361 
2362 	/* allocate additional request block */
2363 	erp = dasd_alloc_erp_request(cqr->magic,
2364 				     cplength, datasize, device);
2365 	if (IS_ERR(erp)) {
2366                 if (cqr->retries <= 0) {
2367 			DBF_DEV_EVENT(DBF_ERR, device, "%s",
2368 				    "Unable to allocate ERP request");
2369 			cqr->status = DASD_CQR_FAILED;
2370 			cqr->stopclk = get_tod_clock();
2371 		} else {
2372 			DBF_DEV_EVENT(DBF_ERR, device,
2373                                      "Unable to allocate ERP request "
2374 				     "(%i retries left)",
2375                                      cqr->retries);
2376 			dasd_block_set_timer(device->block, (HZ << 3));
2377                 }
2378 		return erp;
2379 	}
2380 
2381 	ccw = cqr->cpaddr;
2382 	if (cqr->cpmode == 1) {
2383 		/* make a shallow copy of the original tcw but set new tsb */
2384 		erp->cpmode = 1;
2385 		erp->cpaddr = PTR_ALIGN(erp->data, 64);
2386 		tcw = erp->cpaddr;
2387 		tsb = (struct tsb *) &tcw[1];
2388 		*tcw = *((struct tcw *)cqr->cpaddr);
2389 		tcw->tsb = virt_to_dma64(tsb);
2390 	} else if (ccw->cmd_code == DASD_ECKD_CCW_PSF) {
2391 		/* PSF cannot be chained from NOOP/TIC */
2392 		erp->cpaddr = cqr->cpaddr;
2393 	} else {
2394 		/* initialize request with default TIC to current ERP/CQR */
2395 		ccw = erp->cpaddr;
2396 		ccw->cmd_code = CCW_CMD_NOOP;
2397 		ccw->flags = CCW_FLAG_CC;
2398 		ccw++;
2399 		ccw->cmd_code = CCW_CMD_TIC;
2400 		ccw->cda      = virt_to_dma32(cqr->cpaddr);
2401 	}
2402 
2403 	erp->flags = cqr->flags;
2404 	erp->function = dasd_3990_erp_add_erp;
2405 	erp->refers   = cqr;
2406 	erp->startdev = device;
2407 	erp->memdev   = device;
2408 	erp->block    = cqr->block;
2409 	erp->magic    = cqr->magic;
2410 	erp->expires  = cqr->expires;
2411 	erp->retries  = device->default_retries;
2412 	erp->buildclk = get_tod_clock();
2413 	erp->status = DASD_CQR_FILLED;
2414 
2415 	return erp;
2416 }
2417 
2418 /*
2419  * DASD_3990_ERP_ADDITIONAL_ERP
2420  *
2421  * DESCRIPTION
2422  *   An additional ERP is needed to handle the current error.
2423  *   Add ERP to the head of the ERP-chain containing the ERP processing
2424  *   determined based on the sense data.
2425  *
2426  * PARAMETER
2427  *   cqr		head of the current ERP-chain (or single cqr if
2428  *			first error)
2429  *
2430  * RETURN VALUES
2431  *   erp		pointer to new ERP-chain head
2432  */
2433 static struct dasd_ccw_req *
2434 dasd_3990_erp_additional_erp(struct dasd_ccw_req * cqr)
2435 {
2436 
2437 	struct dasd_ccw_req *erp = NULL;
2438 
2439 	/* add erp and initialize with default TIC */
2440 	erp = dasd_3990_erp_add_erp(cqr);
2441 
2442 	if (IS_ERR(erp))
2443 		return erp;
2444 
2445 	/* inspect sense, determine specific ERP if possible */
2446 	if (erp != cqr) {
2447 
2448 		erp = dasd_3990_erp_inspect(erp);
2449 	}
2450 
2451 	return erp;
2452 
2453 }				/* end dasd_3990_erp_additional_erp */
2454 
2455 /*
2456  * DASD_3990_ERP_ERROR_MATCH
2457  *
2458  * DESCRIPTION
2459  *   Check if the device status of the given cqr is the same.
2460  *   This means that the failed CCW and the relevant sense data
2461  *   must match.
2462  *   I don't distinguish between 24 and 32 byte sense because in case of
2463  *   24 byte sense byte 25 and 27 is set as well.
2464  *
2465  * PARAMETER
2466  *   cqr1		first cqr, which will be compared with the
2467  *   cqr2		second cqr.
2468  *
2469  * RETURN VALUES
2470  *   match		'boolean' for match found
2471  *			returns 1 if match found, otherwise 0.
2472  */
2473 static int dasd_3990_erp_error_match(struct dasd_ccw_req *cqr1,
2474 				     struct dasd_ccw_req *cqr2)
2475 {
2476 	char *sense1, *sense2;
2477 
2478 	if (cqr1->startdev != cqr2->startdev)
2479 		return 0;
2480 
2481 	sense1 = dasd_get_sense(&cqr1->irb);
2482 	sense2 = dasd_get_sense(&cqr2->irb);
2483 
2484 	/* one request has sense data, the other not -> no match, return 0 */
2485 	if (!sense1 != !sense2)
2486 		return 0;
2487 	/* no sense data in both cases -> check cstat for IFCC */
2488 	if (!sense1 && !sense2)	{
2489 		if ((scsw_cstat(&cqr1->irb.scsw) & (SCHN_STAT_INTF_CTRL_CHK |
2490 						    SCHN_STAT_CHN_CTRL_CHK)) ==
2491 		    (scsw_cstat(&cqr2->irb.scsw) & (SCHN_STAT_INTF_CTRL_CHK |
2492 						    SCHN_STAT_CHN_CTRL_CHK)))
2493 			return 1; /* match with ifcc*/
2494 	}
2495 	/* check sense data; byte 0-2,25,27 */
2496 	if (!(sense1 && sense2 &&
2497 	      (memcmp(sense1, sense2, 3) == 0) &&
2498 	      (sense1[27] == sense2[27]) &&
2499 	      (sense1[25] == sense2[25]))) {
2500 
2501 		return 0;	/* sense doesn't match */
2502 	}
2503 
2504 	return 1;		/* match */
2505 
2506 }				/* end dasd_3990_erp_error_match */
2507 
2508 /*
2509  * DASD_3990_ERP_IN_ERP
2510  *
2511  * DESCRIPTION
2512  *   check if the current error already happened before.
2513  *   quick exit if current cqr is not an ERP (cqr->refers=NULL)
2514  *
2515  * PARAMETER
2516  *   cqr		failed cqr (either original cqr or already an erp)
2517  *
2518  * RETURN VALUES
2519  *   erp		erp-pointer to the already defined error
2520  *			recovery procedure OR
2521  *			NULL if a 'new' error occurred.
2522  */
2523 static struct dasd_ccw_req *
2524 dasd_3990_erp_in_erp(struct dasd_ccw_req *cqr)
2525 {
2526 
2527 	struct dasd_ccw_req *erp_head = cqr,	/* save erp chain head */
2528 	*erp_match = NULL;	/* save erp chain head */
2529 	int match = 0;		/* 'boolean' for matching error found */
2530 
2531 	if (cqr->refers == NULL) {	/* return if not in erp */
2532 		return NULL;
2533 	}
2534 
2535 	/* check the erp/cqr chain for current error */
2536 	do {
2537 		match = dasd_3990_erp_error_match(erp_head, cqr->refers);
2538 		erp_match = cqr;	/* save possible matching erp  */
2539 		cqr = cqr->refers;	/* check next erp/cqr in queue */
2540 
2541 	} while ((cqr->refers != NULL) && (!match));
2542 
2543 	if (!match) {
2544 		return NULL;	/* no match was found */
2545 	}
2546 
2547 	return erp_match;	/* return address of matching erp */
2548 
2549 }				/* END dasd_3990_erp_in_erp */
2550 
2551 /*
2552  * DASD_3990_ERP_FURTHER_ERP (24 & 32 byte sense)
2553  *
2554  * DESCRIPTION
2555  *   No retry is left for the current ERP. Check what has to be done
2556  *   with the ERP.
2557  *     - do further defined ERP action or
2558  *     - wait for interrupt or
2559  *     - exit with permanent error
2560  *
2561  * PARAMETER
2562  *   erp		ERP which is in progress with no retry left
2563  *
2564  * RETURN VALUES
2565  *   erp		modified/additional ERP
2566  */
2567 static struct dasd_ccw_req *
2568 dasd_3990_erp_further_erp(struct dasd_ccw_req *erp)
2569 {
2570 
2571 	struct dasd_device *device = erp->startdev;
2572 	char *sense = dasd_get_sense(&erp->irb);
2573 
2574 	/* check for 24 byte sense ERP */
2575 	if ((erp->function == dasd_3990_erp_bus_out) ||
2576 	    (erp->function == dasd_3990_erp_action_1) ||
2577 	    (erp->function == dasd_3990_erp_action_4)) {
2578 
2579 		erp = dasd_3990_erp_action_1(erp);
2580 
2581 	} else if (erp->function == dasd_3990_erp_action_1_sec) {
2582 		erp = dasd_3990_erp_action_1_sec(erp);
2583 	} else if (erp->function == dasd_3990_erp_action_5) {
2584 
2585 		/* retries have not been successful */
2586 		/* prepare erp for retry on different channel path */
2587 		erp = dasd_3990_erp_action_1(erp);
2588 
2589 		if (sense && !(sense[2] & DASD_SENSE_BIT_0)) {
2590 
2591 			/* issue a Diagnostic Control command with an
2592 			 * Inhibit Write subcommand */
2593 
2594 			switch (sense[25]) {
2595 			case 0x17:
2596 			case 0x57:{	/* controller */
2597 					erp = dasd_3990_erp_DCTL(erp, 0x20);
2598 					break;
2599 				}
2600 			case 0x18:
2601 			case 0x58:{	/* channel path */
2602 					erp = dasd_3990_erp_DCTL(erp, 0x40);
2603 					break;
2604 				}
2605 			case 0x19:
2606 			case 0x59:{	/* storage director */
2607 					erp = dasd_3990_erp_DCTL(erp, 0x80);
2608 					break;
2609 				}
2610 			default:
2611 				DBF_DEV_EVENT(DBF_WARNING, device,
2612 					    "invalid subcommand modifier 0x%x "
2613 					    "for Diagnostic Control Command",
2614 					    sense[25]);
2615 			}
2616 		}
2617 
2618 		/* check for 32 byte sense ERP */
2619 	} else if (sense &&
2620 		   ((erp->function == dasd_3990_erp_compound_retry) ||
2621 		    (erp->function == dasd_3990_erp_compound_path) ||
2622 		    (erp->function == dasd_3990_erp_compound_code) ||
2623 		    (erp->function == dasd_3990_erp_compound_config))) {
2624 
2625 		erp = dasd_3990_erp_compound(erp, sense);
2626 
2627 	} else {
2628 		/*
2629 		 * No retry left and no additional special handling
2630 		 * necessary
2631 		 */
2632 		dev_err(&device->cdev->dev,
2633 			"ERP %px has run out of retries and failed\n", erp);
2634 
2635 		erp->status = DASD_CQR_FAILED;
2636 	}
2637 
2638 	return erp;
2639 
2640 }				/* end dasd_3990_erp_further_erp */
2641 
2642 /*
2643  * DASD_3990_ERP_HANDLE_MATCH_ERP
2644  *
2645  * DESCRIPTION
2646  *   An error occurred again and an ERP has been detected which is already
2647  *   used to handle this error (e.g. retries).
2648  *   All prior ERP's are asumed to be successful and therefore removed
2649  *   from queue.
2650  *   If retry counter of matching erp is already 0, it is checked if further
2651  *   action is needed (besides retry) or if the ERP has failed.
2652  *
2653  * PARAMETER
2654  *   erp_head		first ERP in ERP-chain
2655  *   erp		ERP that handles the actual error.
2656  *			(matching erp)
2657  *
2658  * RETURN VALUES
2659  *   erp		modified/additional ERP
2660  */
2661 static struct dasd_ccw_req *
2662 dasd_3990_erp_handle_match_erp(struct dasd_ccw_req *erp_head,
2663 			       struct dasd_ccw_req *erp)
2664 {
2665 
2666 	struct dasd_device *device = erp_head->startdev;
2667 	struct dasd_ccw_req *erp_done = erp_head;	/* finished req */
2668 	struct dasd_ccw_req *erp_free = NULL;	/* req to be freed */
2669 
2670 	/* loop over successful ERPs and remove them from chanq */
2671 	while (erp_done != erp) {
2672 
2673 		if (erp_done == NULL)	/* end of chain reached */
2674 			panic("Programming error in ERP! The original request was lost\n");
2675 
2676 		/* remove the request from the device queue */
2677 		list_del(&erp_done->blocklist);
2678 
2679 		erp_free = erp_done;
2680 		erp_done = erp_done->refers;
2681 
2682 		/* free the finished erp request */
2683 		dasd_free_erp_request(erp_free, erp_free->memdev);
2684 
2685 	}			/* end while */
2686 
2687 	if (erp->retries > 0) {
2688 
2689 		char *sense = dasd_get_sense(&erp->refers->irb);
2690 
2691 		/* check for special retries */
2692 		if (sense && erp->function == dasd_3990_erp_action_4) {
2693 
2694 			erp = dasd_3990_erp_action_4(erp, sense);
2695 
2696 		} else if (sense &&
2697 			   erp->function == dasd_3990_erp_action_1B_32) {
2698 
2699 			erp = dasd_3990_update_1B(erp, sense);
2700 
2701 		} else if (sense && erp->function == dasd_3990_erp_int_req) {
2702 
2703 			erp = dasd_3990_erp_int_req(erp);
2704 
2705 		} else {
2706 			/* simple retry	  */
2707 			DBF_DEV_EVENT(DBF_DEBUG, device,
2708 				    "%i retries left for erp %p",
2709 				    erp->retries, erp);
2710 
2711 			/* handle the request again... */
2712 			erp->status = DASD_CQR_FILLED;
2713 		}
2714 
2715 	} else {
2716 		/* no retry left - check for further necessary action	 */
2717 		/* if no further actions, handle rest as permanent error */
2718 		erp = dasd_3990_erp_further_erp(erp);
2719 	}
2720 
2721 	return erp;
2722 
2723 }				/* end dasd_3990_erp_handle_match_erp */
2724 
2725 /*
2726  * DASD_3990_ERP_ACTION
2727  *
2728  * DESCRIPTION
2729  *   control routine for 3990 erp actions.
2730  *   Has to be called with the queue lock (namely the s390_irq_lock) acquired.
2731  *
2732  * PARAMETER
2733  *   cqr		failed cqr (either original cqr or already an erp)
2734  *
2735  * RETURN VALUES
2736  *   erp		erp-pointer to the head of the ERP action chain.
2737  *			This means:
2738  *			 - either a ptr to an additional ERP cqr or
2739  *			 - the original given cqr (which's status might
2740  *			   be modified)
2741  */
2742 struct dasd_ccw_req *
2743 dasd_3990_erp_action(struct dasd_ccw_req * cqr)
2744 {
2745 	struct dasd_ccw_req *erp = NULL;
2746 	struct dasd_device *device = cqr->startdev;
2747 	struct dasd_ccw_req *temp_erp = NULL;
2748 
2749 	if (device->features & DASD_FEATURE_ERPLOG) {
2750 		/* print current erp_chain */
2751 		dev_err(&device->cdev->dev,
2752 			    "ERP chain at BEGINNING of ERP-ACTION\n");
2753 		for (temp_erp = cqr;
2754 		     temp_erp != NULL; temp_erp = temp_erp->refers) {
2755 			dev_err(&device->cdev->dev,
2756 				"ERP %px (%02x) refers to %px\n",
2757 				temp_erp, temp_erp->status, temp_erp->refers);
2758 		}
2759 	}
2760 
2761 	/* double-check if current erp/cqr was successful */
2762 	if ((scsw_cstat(&cqr->irb.scsw) == 0x00) &&
2763 	    (scsw_dstat(&cqr->irb.scsw) ==
2764 	     (DEV_STAT_CHN_END | DEV_STAT_DEV_END))) {
2765 
2766 		DBF_DEV_EVENT(DBF_DEBUG, device,
2767 			    "ERP called for successful request %p"
2768 			    " - NO ERP necessary", cqr);
2769 
2770 		cqr->status = DASD_CQR_DONE;
2771 
2772 		return cqr;
2773 	}
2774 
2775 	/* check if error happened before */
2776 	erp = dasd_3990_erp_in_erp(cqr);
2777 
2778 	if (erp == NULL) {
2779 		/* no matching erp found - set up erp */
2780 		erp = dasd_3990_erp_additional_erp(cqr);
2781 		if (IS_ERR(erp))
2782 			return erp;
2783 	} else {
2784 		/* matching erp found - set all leading erp's to DONE */
2785 		erp = dasd_3990_erp_handle_match_erp(cqr, erp);
2786 	}
2787 
2788 
2789 	/*
2790 	 * For path verification work we need to stick with the path that was
2791 	 * originally chosen so that the per path configuration data is
2792 	 * assigned correctly.
2793 	 */
2794 	if (test_bit(DASD_CQR_VERIFY_PATH, &erp->flags) && cqr->lpm) {
2795 		erp->lpm = cqr->lpm;
2796 	}
2797 
2798 	if (device->features & DASD_FEATURE_ERPLOG) {
2799 		/* print current erp_chain */
2800 		dev_err(&device->cdev->dev,
2801 			    "ERP chain at END of ERP-ACTION\n");
2802 		for (temp_erp = erp;
2803 		     temp_erp != NULL; temp_erp = temp_erp->refers) {
2804 			dev_err(&device->cdev->dev,
2805 				"ERP %px (%02x) refers to %px\n",
2806 				temp_erp, temp_erp->status, temp_erp->refers);
2807 		}
2808 	}
2809 
2810 	/* enqueue ERP request if it's a new one */
2811 	if (list_empty(&erp->blocklist)) {
2812 		cqr->status = DASD_CQR_IN_ERP;
2813 		/* add erp request before the cqr */
2814 		list_add_tail(&erp->blocklist, &cqr->blocklist);
2815 	}
2816 
2817 
2818 
2819 	return erp;
2820 
2821 }				/* end dasd_3990_erp_action */
2822