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