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