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