0eb5e5888c422cb4cf454fb0e242187f077f9caf
[linux-2.6.git] / drivers / s390 / block / dasd_eckd.c
1 /*
2  * File...........: linux/drivers/s390/block/dasd_eckd.c
3  * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4  *                  Horst Hummel <Horst.Hummel@de.ibm.com>
5  *                  Carsten Otte <Cotte@de.ibm.com>
6  *                  Martin Schwidefsky <schwidefsky@de.ibm.com>
7  * Bugreports.to..: <Linux390@de.ibm.com>
8  * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
9  * EMC Symmetrix ioctl Copyright EMC Corporation, 2008
10  * Author.........: Nigel Hislop <hislop_nigel@emc.com>
11  *
12  */
13
14 #include <linux/stddef.h>
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/hdreg.h>        /* HDIO_GETGEO                      */
18 #include <linux/bio.h>
19 #include <linux/module.h>
20 #include <linux/init.h>
21
22 #include <asm/debug.h>
23 #include <asm/idals.h>
24 #include <asm/ebcdic.h>
25 #include <asm/io.h>
26 #include <asm/todclk.h>
27 #include <asm/uaccess.h>
28 #include <asm/cio.h>
29 #include <asm/ccwdev.h>
30
31 #include "dasd_int.h"
32 #include "dasd_eckd.h"
33
34 #ifdef PRINTK_HEADER
35 #undef PRINTK_HEADER
36 #endif                          /* PRINTK_HEADER */
37 #define PRINTK_HEADER "dasd(eckd):"
38
39 #define ECKD_C0(i) (i->home_bytes)
40 #define ECKD_F(i) (i->formula)
41 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
42                     (i->factors.f_0x02.f1))
43 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
44                     (i->factors.f_0x02.f2))
45 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
46                     (i->factors.f_0x02.f3))
47 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
48 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
49 #define ECKD_F6(i) (i->factor6)
50 #define ECKD_F7(i) (i->factor7)
51 #define ECKD_F8(i) (i->factor8)
52
53 MODULE_LICENSE("GPL");
54
55 static struct dasd_discipline dasd_eckd_discipline;
56
57 /* The ccw bus type uses this table to find devices that it sends to
58  * dasd_eckd_probe */
59 static struct ccw_device_id dasd_eckd_ids[] = {
60         { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
61         { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
62         { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info = 0x3},
63         { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
64         { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
65         { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
66         { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
67         { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
68         { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
69         { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
70         { /* end of list */ },
71 };
72
73 MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
74
75 static struct ccw_driver dasd_eckd_driver; /* see below */
76
77 /* initial attempt at a probe function. this can be simplified once
78  * the other detection code is gone */
79 static int
80 dasd_eckd_probe (struct ccw_device *cdev)
81 {
82         int ret;
83
84         /* set ECKD specific ccw-device options */
85         ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE);
86         if (ret) {
87                 printk(KERN_WARNING
88                        "dasd_eckd_probe: could not set ccw-device options "
89                        "for %s\n", dev_name(&cdev->dev));
90                 return ret;
91         }
92         ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
93         return ret;
94 }
95
96 static int
97 dasd_eckd_set_online(struct ccw_device *cdev)
98 {
99         return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
100 }
101
102 static struct ccw_driver dasd_eckd_driver = {
103         .name        = "dasd-eckd",
104         .owner       = THIS_MODULE,
105         .ids         = dasd_eckd_ids,
106         .probe       = dasd_eckd_probe,
107         .remove      = dasd_generic_remove,
108         .set_offline = dasd_generic_set_offline,
109         .set_online  = dasd_eckd_set_online,
110         .notify      = dasd_generic_notify,
111 };
112
113 static const int sizes_trk0[] = { 28, 148, 84 };
114 #define LABEL_SIZE 140
115
116 static inline unsigned int
117 round_up_multiple(unsigned int no, unsigned int mult)
118 {
119         int rem = no % mult;
120         return (rem ? no - rem + mult : no);
121 }
122
123 static inline unsigned int
124 ceil_quot(unsigned int d1, unsigned int d2)
125 {
126         return (d1 + (d2 - 1)) / d2;
127 }
128
129 static unsigned int
130 recs_per_track(struct dasd_eckd_characteristics * rdc,
131                unsigned int kl, unsigned int dl)
132 {
133         int dn, kn;
134
135         switch (rdc->dev_type) {
136         case 0x3380:
137                 if (kl)
138                         return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
139                                        ceil_quot(dl + 12, 32));
140                 else
141                         return 1499 / (15 + ceil_quot(dl + 12, 32));
142         case 0x3390:
143                 dn = ceil_quot(dl + 6, 232) + 1;
144                 if (kl) {
145                         kn = ceil_quot(kl + 6, 232) + 1;
146                         return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
147                                        9 + ceil_quot(dl + 6 * dn, 34));
148                 } else
149                         return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
150         case 0x9345:
151                 dn = ceil_quot(dl + 6, 232) + 1;
152                 if (kl) {
153                         kn = ceil_quot(kl + 6, 232) + 1;
154                         return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
155                                        ceil_quot(dl + 6 * dn, 34));
156                 } else
157                         return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
158         }
159         return 0;
160 }
161
162 static int
163 check_XRC (struct ccw1         *de_ccw,
164            struct DE_eckd_data *data,
165            struct dasd_device  *device)
166 {
167         struct dasd_eckd_private *private;
168         int rc;
169
170         private = (struct dasd_eckd_private *) device->private;
171         if (!private->rdc_data.facilities.XRC_supported)
172                 return 0;
173
174         /* switch on System Time Stamp - needed for XRC Support */
175         data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid'   */
176         data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
177
178         rc = get_sync_clock(&data->ep_sys_time);
179         /* Ignore return code if sync clock is switched off. */
180         if (rc == -ENOSYS || rc == -EACCES)
181                 rc = 0;
182
183         de_ccw->count = sizeof(struct DE_eckd_data);
184         de_ccw->flags |= CCW_FLAG_SLI;
185         return rc;
186 }
187
188 static int
189 define_extent(struct ccw1 * ccw, struct DE_eckd_data * data, int trk,
190               int totrk, int cmd, struct dasd_device * device)
191 {
192         struct dasd_eckd_private *private;
193         struct ch_t geo, beg, end;
194         int rc = 0;
195
196         private = (struct dasd_eckd_private *) device->private;
197
198         ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
199         ccw->flags = 0;
200         ccw->count = 16;
201         ccw->cda = (__u32) __pa(data);
202
203         memset(data, 0, sizeof(struct DE_eckd_data));
204         switch (cmd) {
205         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
206         case DASD_ECKD_CCW_READ_RECORD_ZERO:
207         case DASD_ECKD_CCW_READ:
208         case DASD_ECKD_CCW_READ_MT:
209         case DASD_ECKD_CCW_READ_CKD:
210         case DASD_ECKD_CCW_READ_CKD_MT:
211         case DASD_ECKD_CCW_READ_KD:
212         case DASD_ECKD_CCW_READ_KD_MT:
213         case DASD_ECKD_CCW_READ_COUNT:
214                 data->mask.perm = 0x1;
215                 data->attributes.operation = private->attrib.operation;
216                 break;
217         case DASD_ECKD_CCW_WRITE:
218         case DASD_ECKD_CCW_WRITE_MT:
219         case DASD_ECKD_CCW_WRITE_KD:
220         case DASD_ECKD_CCW_WRITE_KD_MT:
221                 data->mask.perm = 0x02;
222                 data->attributes.operation = private->attrib.operation;
223                 rc = check_XRC (ccw, data, device);
224                 break;
225         case DASD_ECKD_CCW_WRITE_CKD:
226         case DASD_ECKD_CCW_WRITE_CKD_MT:
227                 data->attributes.operation = DASD_BYPASS_CACHE;
228                 rc = check_XRC (ccw, data, device);
229                 break;
230         case DASD_ECKD_CCW_ERASE:
231         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
232         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
233                 data->mask.perm = 0x3;
234                 data->mask.auth = 0x1;
235                 data->attributes.operation = DASD_BYPASS_CACHE;
236                 rc = check_XRC (ccw, data, device);
237                 break;
238         default:
239                 DEV_MESSAGE(KERN_ERR, device, "unknown opcode 0x%x", cmd);
240                 break;
241         }
242
243         data->attributes.mode = 0x3;    /* ECKD */
244
245         if ((private->rdc_data.cu_type == 0x2105 ||
246              private->rdc_data.cu_type == 0x2107 ||
247              private->rdc_data.cu_type == 0x1750)
248             && !(private->uses_cdl && trk < 2))
249                 data->ga_extended |= 0x40; /* Regular Data Format Mode */
250
251         geo.cyl = private->rdc_data.no_cyl;
252         geo.head = private->rdc_data.trk_per_cyl;
253         beg.cyl = trk / geo.head;
254         beg.head = trk % geo.head;
255         end.cyl = totrk / geo.head;
256         end.head = totrk % geo.head;
257
258         /* check for sequential prestage - enhance cylinder range */
259         if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
260             data->attributes.operation == DASD_SEQ_ACCESS) {
261
262                 if (end.cyl + private->attrib.nr_cyl < geo.cyl)
263                         end.cyl += private->attrib.nr_cyl;
264                 else
265                         end.cyl = (geo.cyl - 1);
266         }
267
268         data->beg_ext.cyl = beg.cyl;
269         data->beg_ext.head = beg.head;
270         data->end_ext.cyl = end.cyl;
271         data->end_ext.head = end.head;
272         return rc;
273 }
274
275 static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
276                                struct dasd_device  *device)
277 {
278         struct dasd_eckd_private *private;
279         int rc;
280
281         private = (struct dasd_eckd_private *) device->private;
282         if (!private->rdc_data.facilities.XRC_supported)
283                 return 0;
284
285         /* switch on System Time Stamp - needed for XRC Support */
286         pfxdata->define_extend.ga_extended |= 0x08; /* 'Time Stamp Valid'   */
287         pfxdata->define_extend.ga_extended |= 0x02; /* 'Extended Parameter' */
288         pfxdata->validity.time_stamp = 1;           /* 'Time Stamp Valid'   */
289
290         rc = get_sync_clock(&pfxdata->define_extend.ep_sys_time);
291         /* Ignore return code if sync clock is switched off. */
292         if (rc == -ENOSYS || rc == -EACCES)
293                 rc = 0;
294         return rc;
295 }
296
297 static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata, int trk,
298                   int totrk, int cmd, struct dasd_device *basedev,
299                   struct dasd_device *startdev)
300 {
301         struct dasd_eckd_private *basepriv, *startpriv;
302         struct DE_eckd_data *data;
303         struct ch_t geo, beg, end;
304         int rc = 0;
305
306         basepriv = (struct dasd_eckd_private *) basedev->private;
307         startpriv = (struct dasd_eckd_private *) startdev->private;
308         data = &pfxdata->define_extend;
309
310         ccw->cmd_code = DASD_ECKD_CCW_PFX;
311         ccw->flags = 0;
312         ccw->count = sizeof(*pfxdata);
313         ccw->cda = (__u32) __pa(pfxdata);
314
315         memset(pfxdata, 0, sizeof(*pfxdata));
316         /* prefix data */
317         pfxdata->format = 0;
318         pfxdata->base_address = basepriv->ned->unit_addr;
319         pfxdata->base_lss = basepriv->ned->ID;
320         pfxdata->validity.define_extend = 1;
321
322         /* private uid is kept up to date, conf_data may be outdated */
323         if (startpriv->uid.type != UA_BASE_DEVICE) {
324                 pfxdata->validity.verify_base = 1;
325                 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
326                         pfxdata->validity.hyper_pav = 1;
327         }
328
329         /* define extend data (mostly)*/
330         switch (cmd) {
331         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
332         case DASD_ECKD_CCW_READ_RECORD_ZERO:
333         case DASD_ECKD_CCW_READ:
334         case DASD_ECKD_CCW_READ_MT:
335         case DASD_ECKD_CCW_READ_CKD:
336         case DASD_ECKD_CCW_READ_CKD_MT:
337         case DASD_ECKD_CCW_READ_KD:
338         case DASD_ECKD_CCW_READ_KD_MT:
339         case DASD_ECKD_CCW_READ_COUNT:
340                 data->mask.perm = 0x1;
341                 data->attributes.operation = basepriv->attrib.operation;
342                 break;
343         case DASD_ECKD_CCW_WRITE:
344         case DASD_ECKD_CCW_WRITE_MT:
345         case DASD_ECKD_CCW_WRITE_KD:
346         case DASD_ECKD_CCW_WRITE_KD_MT:
347                 data->mask.perm = 0x02;
348                 data->attributes.operation = basepriv->attrib.operation;
349                 rc = check_XRC_on_prefix(pfxdata, basedev);
350                 break;
351         case DASD_ECKD_CCW_WRITE_CKD:
352         case DASD_ECKD_CCW_WRITE_CKD_MT:
353                 data->attributes.operation = DASD_BYPASS_CACHE;
354                 rc = check_XRC_on_prefix(pfxdata, basedev);
355                 break;
356         case DASD_ECKD_CCW_ERASE:
357         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
358         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
359                 data->mask.perm = 0x3;
360                 data->mask.auth = 0x1;
361                 data->attributes.operation = DASD_BYPASS_CACHE;
362                 rc = check_XRC_on_prefix(pfxdata, basedev);
363                 break;
364         default:
365                 DEV_MESSAGE(KERN_ERR, basedev, "unknown opcode 0x%x", cmd);
366                 break;
367         }
368
369         data->attributes.mode = 0x3;    /* ECKD */
370
371         if ((basepriv->rdc_data.cu_type == 0x2105 ||
372              basepriv->rdc_data.cu_type == 0x2107 ||
373              basepriv->rdc_data.cu_type == 0x1750)
374             && !(basepriv->uses_cdl && trk < 2))
375                 data->ga_extended |= 0x40; /* Regular Data Format Mode */
376
377         geo.cyl = basepriv->rdc_data.no_cyl;
378         geo.head = basepriv->rdc_data.trk_per_cyl;
379         beg.cyl = trk / geo.head;
380         beg.head = trk % geo.head;
381         end.cyl = totrk / geo.head;
382         end.head = totrk % geo.head;
383
384         /* check for sequential prestage - enhance cylinder range */
385         if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
386             data->attributes.operation == DASD_SEQ_ACCESS) {
387
388                 if (end.cyl + basepriv->attrib.nr_cyl < geo.cyl)
389                         end.cyl += basepriv->attrib.nr_cyl;
390                 else
391                         end.cyl = (geo.cyl - 1);
392         }
393
394         data->beg_ext.cyl = beg.cyl;
395         data->beg_ext.head = beg.head;
396         data->end_ext.cyl = end.cyl;
397         data->end_ext.head = end.head;
398         return rc;
399 }
400
401 static void
402 locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, int trk,
403               int rec_on_trk, int no_rec, int cmd,
404               struct dasd_device * device, int reclen)
405 {
406         struct dasd_eckd_private *private;
407         int sector;
408         int dn, d;
409
410         private = (struct dasd_eckd_private *) device->private;
411
412         DBF_DEV_EVENT(DBF_INFO, device,
413                   "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
414                   trk, rec_on_trk, no_rec, cmd, reclen);
415
416         ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
417         ccw->flags = 0;
418         ccw->count = 16;
419         ccw->cda = (__u32) __pa(data);
420
421         memset(data, 0, sizeof(struct LO_eckd_data));
422         sector = 0;
423         if (rec_on_trk) {
424                 switch (private->rdc_data.dev_type) {
425                 case 0x3390:
426                         dn = ceil_quot(reclen + 6, 232);
427                         d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
428                         sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
429                         break;
430                 case 0x3380:
431                         d = 7 + ceil_quot(reclen + 12, 32);
432                         sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
433                         break;
434                 }
435         }
436         data->sector = sector;
437         data->count = no_rec;
438         switch (cmd) {
439         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
440                 data->operation.orientation = 0x3;
441                 data->operation.operation = 0x03;
442                 break;
443         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
444                 data->operation.orientation = 0x3;
445                 data->operation.operation = 0x16;
446                 break;
447         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
448                 data->operation.orientation = 0x1;
449                 data->operation.operation = 0x03;
450                 data->count++;
451                 break;
452         case DASD_ECKD_CCW_READ_RECORD_ZERO:
453                 data->operation.orientation = 0x3;
454                 data->operation.operation = 0x16;
455                 data->count++;
456                 break;
457         case DASD_ECKD_CCW_WRITE:
458         case DASD_ECKD_CCW_WRITE_MT:
459         case DASD_ECKD_CCW_WRITE_KD:
460         case DASD_ECKD_CCW_WRITE_KD_MT:
461                 data->auxiliary.last_bytes_used = 0x1;
462                 data->length = reclen;
463                 data->operation.operation = 0x01;
464                 break;
465         case DASD_ECKD_CCW_WRITE_CKD:
466         case DASD_ECKD_CCW_WRITE_CKD_MT:
467                 data->auxiliary.last_bytes_used = 0x1;
468                 data->length = reclen;
469                 data->operation.operation = 0x03;
470                 break;
471         case DASD_ECKD_CCW_READ:
472         case DASD_ECKD_CCW_READ_MT:
473         case DASD_ECKD_CCW_READ_KD:
474         case DASD_ECKD_CCW_READ_KD_MT:
475                 data->auxiliary.last_bytes_used = 0x1;
476                 data->length = reclen;
477                 data->operation.operation = 0x06;
478                 break;
479         case DASD_ECKD_CCW_READ_CKD:
480         case DASD_ECKD_CCW_READ_CKD_MT:
481                 data->auxiliary.last_bytes_used = 0x1;
482                 data->length = reclen;
483                 data->operation.operation = 0x16;
484                 break;
485         case DASD_ECKD_CCW_READ_COUNT:
486                 data->operation.operation = 0x06;
487                 break;
488         case DASD_ECKD_CCW_ERASE:
489                 data->length = reclen;
490                 data->auxiliary.last_bytes_used = 0x1;
491                 data->operation.operation = 0x0b;
492                 break;
493         default:
494                 DEV_MESSAGE(KERN_ERR, device, "unknown opcode 0x%x", cmd);
495         }
496         data->seek_addr.cyl = data->search_arg.cyl =
497                 trk / private->rdc_data.trk_per_cyl;
498         data->seek_addr.head = data->search_arg.head =
499                 trk % private->rdc_data.trk_per_cyl;
500         data->search_arg.record = rec_on_trk;
501 }
502
503 /*
504  * Returns 1 if the block is one of the special blocks that needs
505  * to get read/written with the KD variant of the command.
506  * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
507  * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
508  * Luckily the KD variants differ only by one bit (0x08) from the
509  * normal variant. So don't wonder about code like:
510  * if (dasd_eckd_cdl_special(blk_per_trk, recid))
511  *         ccw->cmd_code |= 0x8;
512  */
513 static inline int
514 dasd_eckd_cdl_special(int blk_per_trk, int recid)
515 {
516         if (recid < 3)
517                 return 1;
518         if (recid < blk_per_trk)
519                 return 0;
520         if (recid < 2 * blk_per_trk)
521                 return 1;
522         return 0;
523 }
524
525 /*
526  * Returns the record size for the special blocks of the cdl format.
527  * Only returns something useful if dasd_eckd_cdl_special is true
528  * for the recid.
529  */
530 static inline int
531 dasd_eckd_cdl_reclen(int recid)
532 {
533         if (recid < 3)
534                 return sizes_trk0[recid];
535         return LABEL_SIZE;
536 }
537
538 /*
539  * Generate device unique id that specifies the physical device.
540  */
541 static int dasd_eckd_generate_uid(struct dasd_device *device,
542                                   struct dasd_uid *uid)
543 {
544         struct dasd_eckd_private *private;
545         int count;
546
547         private = (struct dasd_eckd_private *) device->private;
548         if (!private)
549                 return -ENODEV;
550         if (!private->ned || !private->gneq)
551                 return -ENODEV;
552
553         memset(uid, 0, sizeof(struct dasd_uid));
554         memcpy(uid->vendor, private->ned->HDA_manufacturer,
555                sizeof(uid->vendor) - 1);
556         EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
557         memcpy(uid->serial, private->ned->HDA_location,
558                sizeof(uid->serial) - 1);
559         EBCASC(uid->serial, sizeof(uid->serial) - 1);
560         uid->ssid = private->gneq->subsystemID;
561         uid->real_unit_addr = private->ned->unit_addr;;
562         if (private->sneq) {
563                 uid->type = private->sneq->sua_flags;
564                 if (uid->type == UA_BASE_PAV_ALIAS)
565                         uid->base_unit_addr = private->sneq->base_unit_addr;
566         } else {
567                 uid->type = UA_BASE_DEVICE;
568         }
569         if (private->vdsneq) {
570                 for (count = 0; count < 16; count++) {
571                         sprintf(uid->vduit+2*count, "%02x",
572                                 private->vdsneq->uit[count]);
573                 }
574         }
575         return 0;
576 }
577
578 static struct dasd_ccw_req *dasd_eckd_build_rcd_lpm(struct dasd_device *device,
579                                                     void *rcd_buffer,
580                                                     struct ciw *ciw, __u8 lpm)
581 {
582         struct dasd_ccw_req *cqr;
583         struct ccw1 *ccw;
584
585         cqr = dasd_smalloc_request("ECKD", 1 /* RCD */, ciw->count, device);
586
587         if (IS_ERR(cqr)) {
588                 DEV_MESSAGE(KERN_WARNING, device, "%s",
589                             "Could not allocate RCD request");
590                 return cqr;
591         }
592
593         ccw = cqr->cpaddr;
594         ccw->cmd_code = ciw->cmd;
595         ccw->cda = (__u32)(addr_t)rcd_buffer;
596         ccw->count = ciw->count;
597
598         cqr->startdev = device;
599         cqr->memdev = device;
600         cqr->block = NULL;
601         cqr->expires = 10*HZ;
602         cqr->lpm = lpm;
603         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
604         cqr->retries = 2;
605         cqr->buildclk = get_clock();
606         cqr->status = DASD_CQR_FILLED;
607         return cqr;
608 }
609
610 static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
611                                    void **rcd_buffer,
612                                    int *rcd_buffer_size, __u8 lpm)
613 {
614         struct ciw *ciw;
615         char *rcd_buf = NULL;
616         int ret;
617         struct dasd_ccw_req *cqr;
618
619         /*
620          * scan for RCD command in extended SenseID data
621          */
622         ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
623         if (!ciw || ciw->cmd == 0) {
624                 ret = -EOPNOTSUPP;
625                 goto out_error;
626         }
627         rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
628         if (!rcd_buf) {
629                 ret = -ENOMEM;
630                 goto out_error;
631         }
632
633         /*
634          * buffer has to start with EBCDIC "V1.0" to show
635          * support for virtual device SNEQ
636          */
637         rcd_buf[0] = 0xE5;
638         rcd_buf[1] = 0xF1;
639         rcd_buf[2] = 0x4B;
640         rcd_buf[3] = 0xF0;
641         cqr = dasd_eckd_build_rcd_lpm(device, rcd_buf, ciw, lpm);
642         if (IS_ERR(cqr)) {
643                 ret =  PTR_ERR(cqr);
644                 goto out_error;
645         }
646         ret = dasd_sleep_on(cqr);
647         /*
648          * on success we update the user input parms
649          */
650         dasd_sfree_request(cqr, cqr->memdev);
651         if (ret)
652                 goto out_error;
653
654         *rcd_buffer_size = ciw->count;
655         *rcd_buffer = rcd_buf;
656         return 0;
657 out_error:
658         kfree(rcd_buf);
659         *rcd_buffer = NULL;
660         *rcd_buffer_size = 0;
661         return ret;
662 }
663
664 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
665 {
666
667         struct dasd_sneq *sneq;
668         int i, count;
669
670         private->ned = NULL;
671         private->sneq = NULL;
672         private->vdsneq = NULL;
673         private->gneq = NULL;
674         count = private->conf_len / sizeof(struct dasd_sneq);
675         sneq = (struct dasd_sneq *)private->conf_data;
676         for (i = 0; i < count; ++i) {
677                 if (sneq->flags.identifier == 1 && sneq->format == 1)
678                         private->sneq = sneq;
679                 else if (sneq->flags.identifier == 1 && sneq->format == 4)
680                         private->vdsneq = (struct vd_sneq *)sneq;
681                 else if (sneq->flags.identifier == 2)
682                         private->gneq = (struct dasd_gneq *)sneq;
683                 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
684                         private->ned = (struct dasd_ned *)sneq;
685                 sneq++;
686         }
687         if (!private->ned || !private->gneq) {
688                 private->ned = NULL;
689                 private->sneq = NULL;
690                 private->vdsneq = NULL;
691                 private->gneq = NULL;
692                 return -EINVAL;
693         }
694         return 0;
695
696 };
697
698 static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
699 {
700         struct dasd_gneq *gneq;
701         int i, count, found;
702
703         count = conf_len / sizeof(*gneq);
704         gneq = (struct dasd_gneq *)conf_data;
705         found = 0;
706         for (i = 0; i < count; ++i) {
707                 if (gneq->flags.identifier == 2) {
708                         found = 1;
709                         break;
710                 }
711                 gneq++;
712         }
713         if (found)
714                 return ((char *)gneq)[18] & 0x07;
715         else
716                 return 0;
717 }
718
719 static int dasd_eckd_read_conf(struct dasd_device *device)
720 {
721         void *conf_data;
722         int conf_len, conf_data_saved;
723         int rc;
724         __u8 lpm;
725         struct dasd_eckd_private *private;
726         struct dasd_eckd_path *path_data;
727
728         private = (struct dasd_eckd_private *) device->private;
729         path_data = (struct dasd_eckd_path *) &private->path_data;
730         path_data->opm = ccw_device_get_path_mask(device->cdev);
731         lpm = 0x80;
732         conf_data_saved = 0;
733         /* get configuration data per operational path */
734         for (lpm = 0x80; lpm; lpm>>= 1) {
735                 if (lpm & path_data->opm){
736                         rc = dasd_eckd_read_conf_lpm(device, &conf_data,
737                                                      &conf_len, lpm);
738                         if (rc && rc != -EOPNOTSUPP) {  /* -EOPNOTSUPP is ok */
739                                 MESSAGE(KERN_WARNING,
740                                         "Read configuration data returned "
741                                         "error %d", rc);
742                                 return rc;
743                         }
744                         if (conf_data == NULL) {
745                                 MESSAGE(KERN_WARNING, "%s", "No configuration "
746                                         "data retrieved");
747                                 continue;       /* no error */
748                         }
749                         /* save first valid configuration data */
750                         if (!conf_data_saved) {
751                                 kfree(private->conf_data);
752                                 private->conf_data = conf_data;
753                                 private->conf_len = conf_len;
754                                 if (dasd_eckd_identify_conf_parts(private)) {
755                                         private->conf_data = NULL;
756                                         private->conf_len = 0;
757                                         kfree(conf_data);
758                                         continue;
759                                 }
760                                 conf_data_saved++;
761                         }
762                         switch (dasd_eckd_path_access(conf_data, conf_len)) {
763                         case 0x02:
764                                 path_data->npm |= lpm;
765                                 break;
766                         case 0x03:
767                                 path_data->ppm |= lpm;
768                                 break;
769                         }
770                         if (conf_data != private->conf_data)
771                                 kfree(conf_data);
772                 }
773         }
774         return 0;
775 }
776
777 static int dasd_eckd_read_features(struct dasd_device *device)
778 {
779         struct dasd_psf_prssd_data *prssdp;
780         struct dasd_rssd_features *features;
781         struct dasd_ccw_req *cqr;
782         struct ccw1 *ccw;
783         int rc;
784         struct dasd_eckd_private *private;
785
786         private = (struct dasd_eckd_private *) device->private;
787         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
788                                    1 /* PSF */  + 1 /* RSSD */ ,
789                                    (sizeof(struct dasd_psf_prssd_data) +
790                                     sizeof(struct dasd_rssd_features)),
791                                    device);
792         if (IS_ERR(cqr)) {
793                 DEV_MESSAGE(KERN_WARNING, device, "%s",
794                             "Could not allocate initialization request");
795                 return PTR_ERR(cqr);
796         }
797         cqr->startdev = device;
798         cqr->memdev = device;
799         cqr->block = NULL;
800         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
801         cqr->retries = 5;
802         cqr->expires = 10 * HZ;
803
804         /* Prepare for Read Subsystem Data */
805         prssdp = (struct dasd_psf_prssd_data *) cqr->data;
806         memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
807         prssdp->order = PSF_ORDER_PRSSD;
808         prssdp->suborder = 0x41;        /* Read Feature Codes */
809         /* all other bytes of prssdp must be zero */
810
811         ccw = cqr->cpaddr;
812         ccw->cmd_code = DASD_ECKD_CCW_PSF;
813         ccw->count = sizeof(struct dasd_psf_prssd_data);
814         ccw->flags |= CCW_FLAG_CC;
815         ccw->cda = (__u32)(addr_t) prssdp;
816
817         /* Read Subsystem Data - feature codes */
818         features = (struct dasd_rssd_features *) (prssdp + 1);
819         memset(features, 0, sizeof(struct dasd_rssd_features));
820
821         ccw++;
822         ccw->cmd_code = DASD_ECKD_CCW_RSSD;
823         ccw->count = sizeof(struct dasd_rssd_features);
824         ccw->cda = (__u32)(addr_t) features;
825
826         cqr->buildclk = get_clock();
827         cqr->status = DASD_CQR_FILLED;
828         rc = dasd_sleep_on(cqr);
829         if (rc == 0) {
830                 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
831                 features = (struct dasd_rssd_features *) (prssdp + 1);
832                 memcpy(&private->features, features,
833                        sizeof(struct dasd_rssd_features));
834         }
835         dasd_sfree_request(cqr, cqr->memdev);
836         return rc;
837 }
838
839
840 /*
841  * Build CP for Perform Subsystem Function - SSC.
842  */
843 static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device)
844 {
845         struct dasd_ccw_req *cqr;
846         struct dasd_psf_ssc_data *psf_ssc_data;
847         struct ccw1 *ccw;
848
849         cqr = dasd_smalloc_request("ECKD", 1 /* PSF */ ,
850                                   sizeof(struct dasd_psf_ssc_data),
851                                   device);
852
853         if (IS_ERR(cqr)) {
854                 DEV_MESSAGE(KERN_WARNING, device, "%s",
855                            "Could not allocate PSF-SSC request");
856                 return cqr;
857         }
858         psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
859         psf_ssc_data->order = PSF_ORDER_SSC;
860         psf_ssc_data->suborder = 0x88;
861         psf_ssc_data->reserved[0] = 0x88;
862
863         ccw = cqr->cpaddr;
864         ccw->cmd_code = DASD_ECKD_CCW_PSF;
865         ccw->cda = (__u32)(addr_t)psf_ssc_data;
866         ccw->count = 66;
867
868         cqr->startdev = device;
869         cqr->memdev = device;
870         cqr->block = NULL;
871         cqr->expires = 10*HZ;
872         cqr->buildclk = get_clock();
873         cqr->status = DASD_CQR_FILLED;
874         return cqr;
875 }
876
877 /*
878  * Perform Subsystem Function.
879  * It is necessary to trigger CIO for channel revalidation since this
880  * call might change behaviour of DASD devices.
881  */
882 static int
883 dasd_eckd_psf_ssc(struct dasd_device *device)
884 {
885         struct dasd_ccw_req *cqr;
886         int rc;
887
888         cqr = dasd_eckd_build_psf_ssc(device);
889         if (IS_ERR(cqr))
890                 return PTR_ERR(cqr);
891
892         rc = dasd_sleep_on(cqr);
893         if (!rc)
894                 /* trigger CIO to reprobe devices */
895                 css_schedule_reprobe();
896         dasd_sfree_request(cqr, cqr->memdev);
897         return rc;
898 }
899
900 /*
901  * Valide storage server of current device.
902  */
903 static int dasd_eckd_validate_server(struct dasd_device *device)
904 {
905         int rc;
906         struct dasd_eckd_private *private;
907
908         /* Currently PAV is the only reason to 'validate' server on LPAR */
909         if (dasd_nopav || MACHINE_IS_VM)
910                 return 0;
911
912         rc = dasd_eckd_psf_ssc(device);
913         /* may be requested feature is not available on server,
914          * therefore just report error and go ahead */
915         private = (struct dasd_eckd_private *) device->private;
916         DEV_MESSAGE(KERN_INFO, device,
917                     "PSF-SSC on storage subsystem %s.%s.%04x returned rc=%d",
918                     private->uid.vendor, private->uid.serial,
919                     private->uid.ssid, rc);
920         /* RE-Read Configuration Data */
921         return dasd_eckd_read_conf(device);
922 }
923
924 /*
925  * Check device characteristics.
926  * If the device is accessible using ECKD discipline, the device is enabled.
927  */
928 static int
929 dasd_eckd_check_characteristics(struct dasd_device *device)
930 {
931         struct dasd_eckd_private *private;
932         struct dasd_block *block;
933         void *rdc_data;
934         int is_known, rc;
935
936         private = (struct dasd_eckd_private *) device->private;
937         if (private == NULL) {
938                 private = kzalloc(sizeof(struct dasd_eckd_private),
939                                   GFP_KERNEL | GFP_DMA);
940                 if (private == NULL) {
941                         DEV_MESSAGE(KERN_WARNING, device, "%s",
942                                     "memory allocation failed for private "
943                                     "data");
944                         return -ENOMEM;
945                 }
946                 device->private = (void *) private;
947         }
948         /* Invalidate status of initial analysis. */
949         private->init_cqr_status = -1;
950         /* Set default cache operations. */
951         private->attrib.operation = DASD_NORMAL_CACHE;
952         private->attrib.nr_cyl = 0;
953
954         /* Read Configuration Data */
955         rc = dasd_eckd_read_conf(device);
956         if (rc)
957                 goto out_err1;
958
959         /* Generate device unique id and register in devmap */
960         rc = dasd_eckd_generate_uid(device, &private->uid);
961         if (rc)
962                 goto out_err1;
963         dasd_set_uid(device->cdev, &private->uid);
964
965         if (private->uid.type == UA_BASE_DEVICE) {
966                 block = dasd_alloc_block();
967                 if (IS_ERR(block)) {
968                         DEV_MESSAGE(KERN_WARNING, device, "%s",
969                                     "could not allocate dasd block structure");
970                         rc = PTR_ERR(block);
971                         goto out_err1;
972                 }
973                 device->block = block;
974                 block->base = device;
975         }
976
977         /* register lcu with alias handling, enable PAV if this is a new lcu */
978         is_known = dasd_alias_make_device_known_to_lcu(device);
979         if (is_known < 0) {
980                 rc = is_known;
981                 goto out_err2;
982         }
983         if (!is_known) {
984                 /* new lcu found */
985                 rc = dasd_eckd_validate_server(device); /* will switch pav on */
986                 if (rc)
987                         goto out_err3;
988         }
989
990         /* Read Feature Codes */
991         rc = dasd_eckd_read_features(device);
992         if (rc)
993                 goto out_err3;
994
995         /* Read Device Characteristics */
996         rdc_data = (void *) &(private->rdc_data);
997         memset(rdc_data, 0, sizeof(rdc_data));
998         rc = dasd_generic_read_dev_chars(device, "ECKD", &rdc_data, 64);
999         if (rc) {
1000                 DEV_MESSAGE(KERN_WARNING, device,
1001                             "Read device characteristics returned "
1002                             "rc=%d", rc);
1003                 goto out_err3;
1004         }
1005         DEV_MESSAGE(KERN_INFO, device,
1006                     "%04X/%02X(CU:%04X/%02X) Cyl:%d Head:%d Sec:%d",
1007                     private->rdc_data.dev_type,
1008                     private->rdc_data.dev_model,
1009                     private->rdc_data.cu_type,
1010                     private->rdc_data.cu_model.model,
1011                     private->rdc_data.no_cyl,
1012                     private->rdc_data.trk_per_cyl,
1013                     private->rdc_data.sec_per_trk);
1014         return 0;
1015
1016 out_err3:
1017         dasd_alias_disconnect_device_from_lcu(device);
1018 out_err2:
1019         dasd_free_block(device->block);
1020         device->block = NULL;
1021 out_err1:
1022         kfree(private->conf_data);
1023         kfree(device->private);
1024         device->private = NULL;
1025         return rc;
1026 }
1027
1028 static void dasd_eckd_uncheck_device(struct dasd_device *device)
1029 {
1030         struct dasd_eckd_private *private;
1031
1032         private = (struct dasd_eckd_private *) device->private;
1033         dasd_alias_disconnect_device_from_lcu(device);
1034         private->ned = NULL;
1035         private->sneq = NULL;
1036         private->vdsneq = NULL;
1037         private->gneq = NULL;
1038         private->conf_len = 0;
1039         kfree(private->conf_data);
1040         private->conf_data = NULL;
1041 }
1042
1043 static struct dasd_ccw_req *
1044 dasd_eckd_analysis_ccw(struct dasd_device *device)
1045 {
1046         struct dasd_eckd_private *private;
1047         struct eckd_count *count_data;
1048         struct LO_eckd_data *LO_data;
1049         struct dasd_ccw_req *cqr;
1050         struct ccw1 *ccw;
1051         int cplength, datasize;
1052         int i;
1053
1054         private = (struct dasd_eckd_private *) device->private;
1055
1056         cplength = 8;
1057         datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
1058         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1059                                    cplength, datasize, device);
1060         if (IS_ERR(cqr))
1061                 return cqr;
1062         ccw = cqr->cpaddr;
1063         /* Define extent for the first 3 tracks. */
1064         define_extent(ccw++, cqr->data, 0, 2,
1065                       DASD_ECKD_CCW_READ_COUNT, device);
1066         LO_data = cqr->data + sizeof(struct DE_eckd_data);
1067         /* Locate record for the first 4 records on track 0. */
1068         ccw[-1].flags |= CCW_FLAG_CC;
1069         locate_record(ccw++, LO_data++, 0, 0, 4,
1070                       DASD_ECKD_CCW_READ_COUNT, device, 0);
1071
1072         count_data = private->count_area;
1073         for (i = 0; i < 4; i++) {
1074                 ccw[-1].flags |= CCW_FLAG_CC;
1075                 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1076                 ccw->flags = 0;
1077                 ccw->count = 8;
1078                 ccw->cda = (__u32)(addr_t) count_data;
1079                 ccw++;
1080                 count_data++;
1081         }
1082
1083         /* Locate record for the first record on track 2. */
1084         ccw[-1].flags |= CCW_FLAG_CC;
1085         locate_record(ccw++, LO_data++, 2, 0, 1,
1086                       DASD_ECKD_CCW_READ_COUNT, device, 0);
1087         /* Read count ccw. */
1088         ccw[-1].flags |= CCW_FLAG_CC;
1089         ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1090         ccw->flags = 0;
1091         ccw->count = 8;
1092         ccw->cda = (__u32)(addr_t) count_data;
1093
1094         cqr->block = NULL;
1095         cqr->startdev = device;
1096         cqr->memdev = device;
1097         cqr->retries = 0;
1098         cqr->buildclk = get_clock();
1099         cqr->status = DASD_CQR_FILLED;
1100         return cqr;
1101 }
1102
1103 /*
1104  * This is the callback function for the init_analysis cqr. It saves
1105  * the status of the initial analysis ccw before it frees it and kicks
1106  * the device to continue the startup sequence. This will call
1107  * dasd_eckd_do_analysis again (if the devices has not been marked
1108  * for deletion in the meantime).
1109  */
1110 static void
1111 dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, void *data)
1112 {
1113         struct dasd_eckd_private *private;
1114         struct dasd_device *device;
1115
1116         device = init_cqr->startdev;
1117         private = (struct dasd_eckd_private *) device->private;
1118         private->init_cqr_status = init_cqr->status;
1119         dasd_sfree_request(init_cqr, device);
1120         dasd_kick_device(device);
1121 }
1122
1123 static int
1124 dasd_eckd_start_analysis(struct dasd_block *block)
1125 {
1126         struct dasd_eckd_private *private;
1127         struct dasd_ccw_req *init_cqr;
1128
1129         private = (struct dasd_eckd_private *) block->base->private;
1130         init_cqr = dasd_eckd_analysis_ccw(block->base);
1131         if (IS_ERR(init_cqr))
1132                 return PTR_ERR(init_cqr);
1133         init_cqr->callback = dasd_eckd_analysis_callback;
1134         init_cqr->callback_data = NULL;
1135         init_cqr->expires = 5*HZ;
1136         dasd_add_request_head(init_cqr);
1137         return -EAGAIN;
1138 }
1139
1140 static int
1141 dasd_eckd_end_analysis(struct dasd_block *block)
1142 {
1143         struct dasd_device *device;
1144         struct dasd_eckd_private *private;
1145         struct eckd_count *count_area;
1146         unsigned int sb, blk_per_trk;
1147         int status, i;
1148
1149         device = block->base;
1150         private = (struct dasd_eckd_private *) device->private;
1151         status = private->init_cqr_status;
1152         private->init_cqr_status = -1;
1153         if (status != DASD_CQR_DONE) {
1154                 DEV_MESSAGE(KERN_WARNING, device, "%s",
1155                             "volume analysis returned unformatted disk");
1156                 return -EMEDIUMTYPE;
1157         }
1158
1159         private->uses_cdl = 1;
1160         /* Calculate number of blocks/records per track. */
1161         blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
1162         /* Check Track 0 for Compatible Disk Layout */
1163         count_area = NULL;
1164         for (i = 0; i < 3; i++) {
1165                 if (private->count_area[i].kl != 4 ||
1166                     private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
1167                         private->uses_cdl = 0;
1168                         break;
1169                 }
1170         }
1171         if (i == 3)
1172                 count_area = &private->count_area[4];
1173
1174         if (private->uses_cdl == 0) {
1175                 for (i = 0; i < 5; i++) {
1176                         if ((private->count_area[i].kl != 0) ||
1177                             (private->count_area[i].dl !=
1178                              private->count_area[0].dl))
1179                                 break;
1180                 }
1181                 if (i == 5)
1182                         count_area = &private->count_area[0];
1183         } else {
1184                 if (private->count_area[3].record == 1)
1185                         DEV_MESSAGE(KERN_WARNING, device, "%s",
1186                                     "Trk 0: no records after VTOC!");
1187         }
1188         if (count_area != NULL && count_area->kl == 0) {
1189                 /* we found notthing violating our disk layout */
1190                 if (dasd_check_blocksize(count_area->dl) == 0)
1191                         block->bp_block = count_area->dl;
1192         }
1193         if (block->bp_block == 0) {
1194                 DEV_MESSAGE(KERN_WARNING, device, "%s",
1195                             "Volume has incompatible disk layout");
1196                 return -EMEDIUMTYPE;
1197         }
1198         block->s2b_shift = 0;   /* bits to shift 512 to get a block */
1199         for (sb = 512; sb < block->bp_block; sb = sb << 1)
1200                 block->s2b_shift++;
1201
1202         blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
1203         block->blocks = (private->rdc_data.no_cyl *
1204                           private->rdc_data.trk_per_cyl *
1205                           blk_per_trk);
1206
1207         DEV_MESSAGE(KERN_INFO, device,
1208                     "(%dkB blks): %dkB at %dkB/trk %s",
1209                     (block->bp_block >> 10),
1210                     ((private->rdc_data.no_cyl *
1211                       private->rdc_data.trk_per_cyl *
1212                       blk_per_trk * (block->bp_block >> 9)) >> 1),
1213                     ((blk_per_trk * block->bp_block) >> 10),
1214                     private->uses_cdl ?
1215                     "compatible disk layout" : "linux disk layout");
1216
1217         return 0;
1218 }
1219
1220 static int dasd_eckd_do_analysis(struct dasd_block *block)
1221 {
1222         struct dasd_eckd_private *private;
1223
1224         private = (struct dasd_eckd_private *) block->base->private;
1225         if (private->init_cqr_status < 0)
1226                 return dasd_eckd_start_analysis(block);
1227         else
1228                 return dasd_eckd_end_analysis(block);
1229 }
1230
1231 static int dasd_eckd_ready_to_online(struct dasd_device *device)
1232 {
1233         return dasd_alias_add_device(device);
1234 };
1235
1236 static int dasd_eckd_online_to_ready(struct dasd_device *device)
1237 {
1238         return dasd_alias_remove_device(device);
1239 };
1240
1241 static int
1242 dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
1243 {
1244         struct dasd_eckd_private *private;
1245
1246         private = (struct dasd_eckd_private *) block->base->private;
1247         if (dasd_check_blocksize(block->bp_block) == 0) {
1248                 geo->sectors = recs_per_track(&private->rdc_data,
1249                                               0, block->bp_block);
1250         }
1251         geo->cylinders = private->rdc_data.no_cyl;
1252         geo->heads = private->rdc_data.trk_per_cyl;
1253         return 0;
1254 }
1255
1256 static struct dasd_ccw_req *
1257 dasd_eckd_format_device(struct dasd_device * device,
1258                         struct format_data_t * fdata)
1259 {
1260         struct dasd_eckd_private *private;
1261         struct dasd_ccw_req *fcp;
1262         struct eckd_count *ect;
1263         struct ccw1 *ccw;
1264         void *data;
1265         int rpt, cyl, head;
1266         int cplength, datasize;
1267         int i;
1268         int intensity = 0;
1269         int r0_perm;
1270
1271         private = (struct dasd_eckd_private *) device->private;
1272         rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
1273         cyl = fdata->start_unit / private->rdc_data.trk_per_cyl;
1274         head = fdata->start_unit % private->rdc_data.trk_per_cyl;
1275
1276         /* Sanity checks. */
1277         if (fdata->start_unit >=
1278             (private->rdc_data.no_cyl * private->rdc_data.trk_per_cyl)) {
1279                 DEV_MESSAGE(KERN_INFO, device, "Track no %d too big!",
1280                             fdata->start_unit);
1281                 return ERR_PTR(-EINVAL);
1282         }
1283         if (fdata->start_unit > fdata->stop_unit) {
1284                 DEV_MESSAGE(KERN_INFO, device, "Track %d reached! ending.",
1285                             fdata->start_unit);
1286                 return ERR_PTR(-EINVAL);
1287         }
1288         if (dasd_check_blocksize(fdata->blksize) != 0) {
1289                 DEV_MESSAGE(KERN_WARNING, device,
1290                             "Invalid blocksize %d...terminating!",
1291                             fdata->blksize);
1292                 return ERR_PTR(-EINVAL);
1293         }
1294
1295         /*
1296          * fdata->intensity is a bit string that tells us what to do:
1297          *   Bit 0: write record zero
1298          *   Bit 1: write home address, currently not supported
1299          *   Bit 2: invalidate tracks
1300          *   Bit 3: use OS/390 compatible disk layout (cdl)
1301          *   Bit 4: do not allow storage subsystem to modify record zero
1302          * Only some bit combinations do make sense.
1303          */
1304         if (fdata->intensity & 0x10) {
1305                 r0_perm = 0;
1306                 intensity = fdata->intensity & ~0x10;
1307         } else {
1308                 r0_perm = 1;
1309                 intensity = fdata->intensity;
1310         }
1311         switch (intensity) {
1312         case 0x00:      /* Normal format */
1313         case 0x08:      /* Normal format, use cdl. */
1314                 cplength = 2 + rpt;
1315                 datasize = sizeof(struct DE_eckd_data) +
1316                         sizeof(struct LO_eckd_data) +
1317                         rpt * sizeof(struct eckd_count);
1318                 break;
1319         case 0x01:      /* Write record zero and format track. */
1320         case 0x09:      /* Write record zero and format track, use cdl. */
1321                 cplength = 3 + rpt;
1322                 datasize = sizeof(struct DE_eckd_data) +
1323                         sizeof(struct LO_eckd_data) +
1324                         sizeof(struct eckd_count) +
1325                         rpt * sizeof(struct eckd_count);
1326                 break;
1327         case 0x04:      /* Invalidate track. */
1328         case 0x0c:      /* Invalidate track, use cdl. */
1329                 cplength = 3;
1330                 datasize = sizeof(struct DE_eckd_data) +
1331                         sizeof(struct LO_eckd_data) +
1332                         sizeof(struct eckd_count);
1333                 break;
1334         default:
1335                 DEV_MESSAGE(KERN_WARNING, device, "Invalid flags 0x%x.",
1336                             fdata->intensity);
1337                 return ERR_PTR(-EINVAL);
1338         }
1339         /* Allocate the format ccw request. */
1340         fcp = dasd_smalloc_request(dasd_eckd_discipline.name,
1341                                    cplength, datasize, device);
1342         if (IS_ERR(fcp))
1343                 return fcp;
1344
1345         data = fcp->data;
1346         ccw = fcp->cpaddr;
1347
1348         switch (intensity & ~0x08) {
1349         case 0x00: /* Normal format. */
1350                 define_extent(ccw++, (struct DE_eckd_data *) data,
1351                               fdata->start_unit, fdata->start_unit,
1352                               DASD_ECKD_CCW_WRITE_CKD, device);
1353                 /* grant subsystem permission to format R0 */
1354                 if (r0_perm)
1355                         ((struct DE_eckd_data *)data)->ga_extended |= 0x04;
1356                 data += sizeof(struct DE_eckd_data);
1357                 ccw[-1].flags |= CCW_FLAG_CC;
1358                 locate_record(ccw++, (struct LO_eckd_data *) data,
1359                               fdata->start_unit, 0, rpt,
1360                               DASD_ECKD_CCW_WRITE_CKD, device,
1361                               fdata->blksize);
1362                 data += sizeof(struct LO_eckd_data);
1363                 break;
1364         case 0x01: /* Write record zero + format track. */
1365                 define_extent(ccw++, (struct DE_eckd_data *) data,
1366                               fdata->start_unit, fdata->start_unit,
1367                               DASD_ECKD_CCW_WRITE_RECORD_ZERO,
1368                               device);
1369                 data += sizeof(struct DE_eckd_data);
1370                 ccw[-1].flags |= CCW_FLAG_CC;
1371                 locate_record(ccw++, (struct LO_eckd_data *) data,
1372                               fdata->start_unit, 0, rpt + 1,
1373                               DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
1374                               device->block->bp_block);
1375                 data += sizeof(struct LO_eckd_data);
1376                 break;
1377         case 0x04: /* Invalidate track. */
1378                 define_extent(ccw++, (struct DE_eckd_data *) data,
1379                               fdata->start_unit, fdata->start_unit,
1380                               DASD_ECKD_CCW_WRITE_CKD, device);
1381                 data += sizeof(struct DE_eckd_data);
1382                 ccw[-1].flags |= CCW_FLAG_CC;
1383                 locate_record(ccw++, (struct LO_eckd_data *) data,
1384                               fdata->start_unit, 0, 1,
1385                               DASD_ECKD_CCW_WRITE_CKD, device, 8);
1386                 data += sizeof(struct LO_eckd_data);
1387                 break;
1388         }
1389         if (intensity & 0x01) { /* write record zero */
1390                 ect = (struct eckd_count *) data;
1391                 data += sizeof(struct eckd_count);
1392                 ect->cyl = cyl;
1393                 ect->head = head;
1394                 ect->record = 0;
1395                 ect->kl = 0;
1396                 ect->dl = 8;
1397                 ccw[-1].flags |= CCW_FLAG_CC;
1398                 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
1399                 ccw->flags = CCW_FLAG_SLI;
1400                 ccw->count = 8;
1401                 ccw->cda = (__u32)(addr_t) ect;
1402                 ccw++;
1403         }
1404         if ((intensity & ~0x08) & 0x04) {       /* erase track */
1405                 ect = (struct eckd_count *) data;
1406                 data += sizeof(struct eckd_count);
1407                 ect->cyl = cyl;
1408                 ect->head = head;
1409                 ect->record = 1;
1410                 ect->kl = 0;
1411                 ect->dl = 0;
1412                 ccw[-1].flags |= CCW_FLAG_CC;
1413                 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1414                 ccw->flags = CCW_FLAG_SLI;
1415                 ccw->count = 8;
1416                 ccw->cda = (__u32)(addr_t) ect;
1417         } else {                /* write remaining records */
1418                 for (i = 0; i < rpt; i++) {
1419                         ect = (struct eckd_count *) data;
1420                         data += sizeof(struct eckd_count);
1421                         ect->cyl = cyl;
1422                         ect->head = head;
1423                         ect->record = i + 1;
1424                         ect->kl = 0;
1425                         ect->dl = fdata->blksize;
1426                         /* Check for special tracks 0-1 when formatting CDL */
1427                         if ((intensity & 0x08) &&
1428                             fdata->start_unit == 0) {
1429                                 if (i < 3) {
1430                                         ect->kl = 4;
1431                                         ect->dl = sizes_trk0[i] - 4;
1432                                 }
1433                         }
1434                         if ((intensity & 0x08) &&
1435                             fdata->start_unit == 1) {
1436                                 ect->kl = 44;
1437                                 ect->dl = LABEL_SIZE - 44;
1438                         }
1439                         ccw[-1].flags |= CCW_FLAG_CC;
1440                         ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1441                         ccw->flags = CCW_FLAG_SLI;
1442                         ccw->count = 8;
1443                         ccw->cda = (__u32)(addr_t) ect;
1444                         ccw++;
1445                 }
1446         }
1447         fcp->startdev = device;
1448         fcp->memdev = device;
1449         clear_bit(DASD_CQR_FLAGS_USE_ERP, &fcp->flags);
1450         fcp->retries = 5;       /* set retry counter to enable default ERP */
1451         fcp->buildclk = get_clock();
1452         fcp->status = DASD_CQR_FILLED;
1453         return fcp;
1454 }
1455
1456 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
1457 {
1458         cqr->status = DASD_CQR_FILLED;
1459         if (cqr->block && (cqr->startdev != cqr->block->base)) {
1460                 dasd_eckd_reset_ccw_to_base_io(cqr);
1461                 cqr->startdev = cqr->block->base;
1462         }
1463 };
1464
1465 static dasd_erp_fn_t
1466 dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
1467 {
1468         struct dasd_device *device = (struct dasd_device *) cqr->startdev;
1469         struct ccw_device *cdev = device->cdev;
1470
1471         switch (cdev->id.cu_type) {
1472         case 0x3990:
1473         case 0x2105:
1474         case 0x2107:
1475         case 0x1750:
1476                 return dasd_3990_erp_action;
1477         case 0x9343:
1478         case 0x3880:
1479         default:
1480                 return dasd_default_erp_action;
1481         }
1482 }
1483
1484 static dasd_erp_fn_t
1485 dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
1486 {
1487         return dasd_default_erp_postaction;
1488 }
1489
1490
1491 static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device *device,
1492                                                    struct irb *irb)
1493 {
1494         char mask;
1495
1496         /* first of all check for state change pending interrupt */
1497         mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
1498         if ((irb->scsw.cmd.dstat & mask) == mask) {
1499                 dasd_generic_handle_state_change(device);
1500                 return;
1501         }
1502
1503         /* summary unit check */
1504         if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
1505             (irb->ecw[7] == 0x0D)) {
1506                 dasd_alias_handle_summary_unit_check(device, irb);
1507                 return;
1508         }
1509
1510
1511         /* service information message SIM */
1512         if (irb->esw.esw0.erw.cons && !(irb->ecw[27] & DASD_SENSE_BIT_0) &&
1513             ((irb->ecw[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
1514                 dasd_3990_erp_handle_sim(device, irb->ecw);
1515                 dasd_schedule_device_bh(device);
1516                 return;
1517         }
1518
1519         if ((irb->scsw.cmd.cc == 1) &&
1520             (irb->scsw.cmd.fctl & SCSW_FCTL_START_FUNC) &&
1521             (irb->scsw.cmd.actl & SCSW_ACTL_START_PEND) &&
1522             (irb->scsw.cmd.stctl & SCSW_STCTL_STATUS_PEND)) {
1523                 /* fake irb do nothing, they are handled elsewhere */
1524                 dasd_schedule_device_bh(device);
1525                 return;
1526         }
1527
1528         if (!(irb->esw.esw0.erw.cons)) {
1529                 /* just report other unsolicited interrupts */
1530                 DEV_MESSAGE(KERN_ERR, device, "%s",
1531                             "unsolicited interrupt received");
1532         } else {
1533                 DEV_MESSAGE(KERN_ERR, device, "%s",
1534                             "unsolicited interrupt received "
1535                             "(sense available)");
1536                 device->discipline->dump_sense(device, NULL, irb);
1537         }
1538
1539         dasd_schedule_device_bh(device);
1540         return;
1541 };
1542
1543 static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
1544                                                struct dasd_block *block,
1545                                                struct request *req)
1546 {
1547         struct dasd_eckd_private *private;
1548         unsigned long *idaws;
1549         struct LO_eckd_data *LO_data;
1550         struct dasd_ccw_req *cqr;
1551         struct ccw1 *ccw;
1552         struct req_iterator iter;
1553         struct bio_vec *bv;
1554         char *dst;
1555         unsigned int blksize, blk_per_trk, off;
1556         int count, cidaw, cplength, datasize;
1557         sector_t recid, first_rec, last_rec;
1558         sector_t first_trk, last_trk;
1559         unsigned int first_offs, last_offs;
1560         unsigned char cmd, rcmd;
1561         int use_prefix;
1562         struct dasd_device *basedev;
1563
1564         basedev = block->base;
1565         private = (struct dasd_eckd_private *) basedev->private;
1566         if (rq_data_dir(req) == READ)
1567                 cmd = DASD_ECKD_CCW_READ_MT;
1568         else if (rq_data_dir(req) == WRITE)
1569                 cmd = DASD_ECKD_CCW_WRITE_MT;
1570         else
1571                 return ERR_PTR(-EINVAL);
1572         /* Calculate number of blocks/records per track. */
1573         blksize = block->bp_block;
1574         blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
1575         /* Calculate record id of first and last block. */
1576         first_rec = first_trk = req->sector >> block->s2b_shift;
1577         first_offs = sector_div(first_trk, blk_per_trk);
1578         last_rec = last_trk =
1579                 (req->sector + req->nr_sectors - 1) >> block->s2b_shift;
1580         last_offs = sector_div(last_trk, blk_per_trk);
1581         /* Check struct bio and count the number of blocks for the request. */
1582         count = 0;
1583         cidaw = 0;
1584         rq_for_each_segment(bv, req, iter) {
1585                 if (bv->bv_len & (blksize - 1))
1586                         /* Eckd can only do full blocks. */
1587                         return ERR_PTR(-EINVAL);
1588                 count += bv->bv_len >> (block->s2b_shift + 9);
1589 #if defined(CONFIG_64BIT)
1590                 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
1591                         cidaw += bv->bv_len >> (block->s2b_shift + 9);
1592 #endif
1593         }
1594         /* Paranoia. */
1595         if (count != last_rec - first_rec + 1)
1596                 return ERR_PTR(-EINVAL);
1597
1598         /* use the prefix command if available */
1599         use_prefix = private->features.feature[8] & 0x01;
1600         if (use_prefix) {
1601                 /* 1x prefix + number of blocks */
1602                 cplength = 2 + count;
1603                 /* 1x prefix + cidaws*sizeof(long) */
1604                 datasize = sizeof(struct PFX_eckd_data) +
1605                         sizeof(struct LO_eckd_data) +
1606                         cidaw * sizeof(unsigned long);
1607         } else {
1608                 /* 1x define extent + 1x locate record + number of blocks */
1609                 cplength = 2 + count;
1610                 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
1611                 datasize = sizeof(struct DE_eckd_data) +
1612                         sizeof(struct LO_eckd_data) +
1613                         cidaw * sizeof(unsigned long);
1614         }
1615         /* Find out the number of additional locate record ccws for cdl. */
1616         if (private->uses_cdl && first_rec < 2*blk_per_trk) {
1617                 if (last_rec >= 2*blk_per_trk)
1618                         count = 2*blk_per_trk - first_rec;
1619                 cplength += count;
1620                 datasize += count*sizeof(struct LO_eckd_data);
1621         }
1622         /* Allocate the ccw request. */
1623         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1624                                    cplength, datasize, startdev);
1625         if (IS_ERR(cqr))
1626                 return cqr;
1627         ccw = cqr->cpaddr;
1628         /* First ccw is define extent or prefix. */
1629         if (use_prefix) {
1630                 if (prefix(ccw++, cqr->data, first_trk,
1631                            last_trk, cmd, basedev, startdev) == -EAGAIN) {
1632                         /* Clock not in sync and XRC is enabled.
1633                          * Try again later.
1634                          */
1635                         dasd_sfree_request(cqr, startdev);
1636                         return ERR_PTR(-EAGAIN);
1637                 }
1638                 idaws = (unsigned long *) (cqr->data +
1639                                            sizeof(struct PFX_eckd_data));
1640         } else {
1641                 if (define_extent(ccw++, cqr->data, first_trk,
1642                                   last_trk, cmd, startdev) == -EAGAIN) {
1643                         /* Clock not in sync and XRC is enabled.
1644                          * Try again later.
1645                          */
1646                         dasd_sfree_request(cqr, startdev);
1647                         return ERR_PTR(-EAGAIN);
1648                 }
1649                 idaws = (unsigned long *) (cqr->data +
1650                                            sizeof(struct DE_eckd_data));
1651         }
1652         /* Build locate_record+read/write/ccws. */
1653         LO_data = (struct LO_eckd_data *) (idaws + cidaw);
1654         recid = first_rec;
1655         if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
1656                 /* Only standard blocks so there is just one locate record. */
1657                 ccw[-1].flags |= CCW_FLAG_CC;
1658                 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
1659                               last_rec - recid + 1, cmd, basedev, blksize);
1660         }
1661         rq_for_each_segment(bv, req, iter) {
1662                 dst = page_address(bv->bv_page) + bv->bv_offset;
1663                 if (dasd_page_cache) {
1664                         char *copy = kmem_cache_alloc(dasd_page_cache,
1665                                                       GFP_DMA | __GFP_NOWARN);
1666                         if (copy && rq_data_dir(req) == WRITE)
1667                                 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
1668                         if (copy)
1669                                 dst = copy + bv->bv_offset;
1670                 }
1671                 for (off = 0; off < bv->bv_len; off += blksize) {
1672                         sector_t trkid = recid;
1673                         unsigned int recoffs = sector_div(trkid, blk_per_trk);
1674                         rcmd = cmd;
1675                         count = blksize;
1676                         /* Locate record for cdl special block ? */
1677                         if (private->uses_cdl && recid < 2*blk_per_trk) {
1678                                 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
1679                                         rcmd |= 0x8;
1680                                         count = dasd_eckd_cdl_reclen(recid);
1681                                         if (count < blksize &&
1682                                             rq_data_dir(req) == READ)
1683                                                 memset(dst + count, 0xe5,
1684                                                        blksize - count);
1685                                 }
1686                                 ccw[-1].flags |= CCW_FLAG_CC;
1687                                 locate_record(ccw++, LO_data++,
1688                                               trkid, recoffs + 1,
1689                                               1, rcmd, basedev, count);
1690                         }
1691                         /* Locate record for standard blocks ? */
1692                         if (private->uses_cdl && recid == 2*blk_per_trk) {
1693                                 ccw[-1].flags |= CCW_FLAG_CC;
1694                                 locate_record(ccw++, LO_data++,
1695                                               trkid, recoffs + 1,
1696                                               last_rec - recid + 1,
1697                                               cmd, basedev, count);
1698                         }
1699                         /* Read/write ccw. */
1700                         ccw[-1].flags |= CCW_FLAG_CC;
1701                         ccw->cmd_code = rcmd;
1702                         ccw->count = count;
1703                         if (idal_is_needed(dst, blksize)) {
1704                                 ccw->cda = (__u32)(addr_t) idaws;
1705                                 ccw->flags = CCW_FLAG_IDA;
1706                                 idaws = idal_create_words(idaws, dst, blksize);
1707                         } else {
1708                                 ccw->cda = (__u32)(addr_t) dst;
1709                                 ccw->flags = 0;
1710                         }
1711                         ccw++;
1712                         dst += blksize;
1713                         recid++;
1714                 }
1715         }
1716         if (blk_noretry_request(req) ||
1717             block->base->features & DASD_FEATURE_FAILFAST)
1718                 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1719         cqr->startdev = startdev;
1720         cqr->memdev = startdev;
1721         cqr->block = block;
1722         cqr->expires = 5 * 60 * HZ;     /* 5 minutes */
1723         cqr->lpm = private->path_data.ppm;
1724         cqr->retries = 256;
1725         cqr->buildclk = get_clock();
1726         cqr->status = DASD_CQR_FILLED;
1727         return cqr;
1728 }
1729
1730 static int
1731 dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
1732 {
1733         struct dasd_eckd_private *private;
1734         struct ccw1 *ccw;
1735         struct req_iterator iter;
1736         struct bio_vec *bv;
1737         char *dst, *cda;
1738         unsigned int blksize, blk_per_trk, off;
1739         sector_t recid;
1740         int status;
1741
1742         if (!dasd_page_cache)
1743                 goto out;
1744         private = (struct dasd_eckd_private *) cqr->block->base->private;
1745         blksize = cqr->block->bp_block;
1746         blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
1747         recid = req->sector >> cqr->block->s2b_shift;
1748         ccw = cqr->cpaddr;
1749         /* Skip over define extent & locate record. */
1750         ccw++;
1751         if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
1752                 ccw++;
1753         rq_for_each_segment(bv, req, iter) {
1754                 dst = page_address(bv->bv_page) + bv->bv_offset;
1755                 for (off = 0; off < bv->bv_len; off += blksize) {
1756                         /* Skip locate record. */
1757                         if (private->uses_cdl && recid <= 2*blk_per_trk)
1758                                 ccw++;
1759                         if (dst) {
1760                                 if (ccw->flags & CCW_FLAG_IDA)
1761                                         cda = *((char **)((addr_t) ccw->cda));
1762                                 else
1763                                         cda = (char *)((addr_t) ccw->cda);
1764                                 if (dst != cda) {
1765                                         if (rq_data_dir(req) == READ)
1766                                                 memcpy(dst, cda, bv->bv_len);
1767                                         kmem_cache_free(dasd_page_cache,
1768                                             (void *)((addr_t)cda & PAGE_MASK));
1769                                 }
1770                                 dst = NULL;
1771                         }
1772                         ccw++;
1773                         recid++;
1774                 }
1775         }
1776 out:
1777         status = cqr->status == DASD_CQR_DONE;
1778         dasd_sfree_request(cqr, cqr->memdev);
1779         return status;
1780 }
1781
1782 /*
1783  * Modify ccw chain in cqr so it can be started on a base device.
1784  *
1785  * Note that this is not enough to restart the cqr!
1786  * Either reset cqr->startdev as well (summary unit check handling)
1787  * or restart via separate cqr (as in ERP handling).
1788  */
1789 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
1790 {
1791         struct ccw1 *ccw;
1792         struct PFX_eckd_data *pfxdata;
1793
1794         ccw = cqr->cpaddr;
1795         pfxdata = cqr->data;
1796
1797         if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
1798                 pfxdata->validity.verify_base = 0;
1799                 pfxdata->validity.hyper_pav = 0;
1800         }
1801 }
1802
1803 #define DASD_ECKD_CHANQ_MAX_SIZE 4
1804
1805 static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
1806                                                      struct dasd_block *block,
1807                                                      struct request *req)
1808 {
1809         struct dasd_eckd_private *private;
1810         struct dasd_device *startdev;
1811         unsigned long flags;
1812         struct dasd_ccw_req *cqr;
1813
1814         startdev = dasd_alias_get_start_dev(base);
1815         if (!startdev)
1816                 startdev = base;
1817         private = (struct dasd_eckd_private *) startdev->private;
1818         if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
1819                 return ERR_PTR(-EBUSY);
1820
1821         spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
1822         private->count++;
1823         cqr = dasd_eckd_build_cp(startdev, block, req);
1824         if (IS_ERR(cqr))
1825                 private->count--;
1826         spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
1827         return cqr;
1828 }
1829
1830 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
1831                                    struct request *req)
1832 {
1833         struct dasd_eckd_private *private;
1834         unsigned long flags;
1835
1836         spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
1837         private = (struct dasd_eckd_private *) cqr->memdev->private;
1838         private->count--;
1839         spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
1840         return dasd_eckd_free_cp(cqr, req);
1841 }
1842
1843 static int
1844 dasd_eckd_fill_info(struct dasd_device * device,
1845                     struct dasd_information2_t * info)
1846 {
1847         struct dasd_eckd_private *private;
1848
1849         private = (struct dasd_eckd_private *) device->private;
1850         info->label_block = 2;
1851         info->FBA_layout = private->uses_cdl ? 0 : 1;
1852         info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
1853         info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
1854         memcpy(info->characteristics, &private->rdc_data,
1855                sizeof(struct dasd_eckd_characteristics));
1856         info->confdata_size = min((unsigned long)private->conf_len,
1857                                   sizeof(info->configuration_data));
1858         memcpy(info->configuration_data, private->conf_data,
1859                info->confdata_size);
1860         return 0;
1861 }
1862
1863 /*
1864  * SECTION: ioctl functions for eckd devices.
1865  */
1866
1867 /*
1868  * Release device ioctl.
1869  * Buils a channel programm to releases a prior reserved
1870  * (see dasd_eckd_reserve) device.
1871  */
1872 static int
1873 dasd_eckd_release(struct dasd_device *device)
1874 {
1875         struct dasd_ccw_req *cqr;
1876         int rc;
1877
1878         if (!capable(CAP_SYS_ADMIN))
1879                 return -EACCES;
1880
1881         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1882                                    1, 32, device);
1883         if (IS_ERR(cqr)) {
1884                 DEV_MESSAGE(KERN_WARNING, device, "%s",
1885                             "Could not allocate initialization request");
1886                 return PTR_ERR(cqr);
1887         }
1888         cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RELEASE;
1889         cqr->cpaddr->flags |= CCW_FLAG_SLI;
1890         cqr->cpaddr->count = 32;
1891         cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
1892         cqr->startdev = device;
1893         cqr->memdev = device;
1894         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1895         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1896         cqr->retries = 2;       /* set retry counter to enable basic ERP */
1897         cqr->expires = 2 * HZ;
1898         cqr->buildclk = get_clock();
1899         cqr->status = DASD_CQR_FILLED;
1900
1901         rc = dasd_sleep_on_immediatly(cqr);
1902
1903         dasd_sfree_request(cqr, cqr->memdev);
1904         return rc;
1905 }
1906
1907 /*
1908  * Reserve device ioctl.
1909  * Options are set to 'synchronous wait for interrupt' and
1910  * 'timeout the request'. This leads to a terminate IO if
1911  * the interrupt is outstanding for a certain time.
1912  */
1913 static int
1914 dasd_eckd_reserve(struct dasd_device *device)
1915 {
1916         struct dasd_ccw_req *cqr;
1917         int rc;
1918
1919         if (!capable(CAP_SYS_ADMIN))
1920                 return -EACCES;
1921
1922         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1923                                    1, 32, device);
1924         if (IS_ERR(cqr)) {
1925                 DEV_MESSAGE(KERN_WARNING, device, "%s",
1926                             "Could not allocate initialization request");
1927                 return PTR_ERR(cqr);
1928         }
1929         cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RESERVE;
1930         cqr->cpaddr->flags |= CCW_FLAG_SLI;
1931         cqr->cpaddr->count = 32;
1932         cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
1933         cqr->startdev = device;
1934         cqr->memdev = device;
1935         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1936         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1937         cqr->retries = 2;       /* set retry counter to enable basic ERP */
1938         cqr->expires = 2 * HZ;
1939         cqr->buildclk = get_clock();
1940         cqr->status = DASD_CQR_FILLED;
1941
1942         rc = dasd_sleep_on_immediatly(cqr);
1943
1944         dasd_sfree_request(cqr, cqr->memdev);
1945         return rc;
1946 }
1947
1948 /*
1949  * Steal lock ioctl - unconditional reserve device.
1950  * Buils a channel programm to break a device's reservation.
1951  * (unconditional reserve)
1952  */
1953 static int
1954 dasd_eckd_steal_lock(struct dasd_device *device)
1955 {
1956         struct dasd_ccw_req *cqr;
1957         int rc;
1958
1959         if (!capable(CAP_SYS_ADMIN))
1960                 return -EACCES;
1961
1962         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1963                                    1, 32, device);
1964         if (IS_ERR(cqr)) {
1965                 DEV_MESSAGE(KERN_WARNING, device, "%s",
1966                             "Could not allocate initialization request");
1967                 return PTR_ERR(cqr);
1968         }
1969         cqr->cpaddr->cmd_code = DASD_ECKD_CCW_SLCK;
1970         cqr->cpaddr->flags |= CCW_FLAG_SLI;
1971         cqr->cpaddr->count = 32;
1972         cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
1973         cqr->startdev = device;
1974         cqr->memdev = device;
1975         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1976         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1977         cqr->retries = 2;       /* set retry counter to enable basic ERP */
1978         cqr->expires = 2 * HZ;
1979         cqr->buildclk = get_clock();
1980         cqr->status = DASD_CQR_FILLED;
1981
1982         rc = dasd_sleep_on_immediatly(cqr);
1983
1984         dasd_sfree_request(cqr, cqr->memdev);
1985         return rc;
1986 }
1987
1988 /*
1989  * Read performance statistics
1990  */
1991 static int
1992 dasd_eckd_performance(struct dasd_device *device, void __user *argp)
1993 {
1994         struct dasd_psf_prssd_data *prssdp;
1995         struct dasd_rssd_perf_stats_t *stats;
1996         struct dasd_ccw_req *cqr;
1997         struct ccw1 *ccw;
1998         int rc;
1999
2000         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
2001                                    1 /* PSF */  + 1 /* RSSD */ ,
2002                                    (sizeof(struct dasd_psf_prssd_data) +
2003                                     sizeof(struct dasd_rssd_perf_stats_t)),
2004                                    device);
2005         if (IS_ERR(cqr)) {
2006                 DEV_MESSAGE(KERN_WARNING, device, "%s",
2007                             "Could not allocate initialization request");
2008                 return PTR_ERR(cqr);
2009         }
2010         cqr->startdev = device;
2011         cqr->memdev = device;
2012         cqr->retries = 0;
2013         cqr->expires = 10 * HZ;
2014
2015         /* Prepare for Read Subsystem Data */
2016         prssdp = (struct dasd_psf_prssd_data *) cqr->data;
2017         memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
2018         prssdp->order = PSF_ORDER_PRSSD;
2019         prssdp->suborder = 0x01;        /* Performance Statistics */
2020         prssdp->varies[1] = 0x01;       /* Perf Statistics for the Subsystem */
2021
2022         ccw = cqr->cpaddr;
2023         ccw->cmd_code = DASD_ECKD_CCW_PSF;
2024         ccw->count = sizeof(struct dasd_psf_prssd_data);
2025         ccw->flags |= CCW_FLAG_CC;
2026         ccw->cda = (__u32)(addr_t) prssdp;
2027
2028         /* Read Subsystem Data - Performance Statistics */
2029         stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
2030         memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
2031
2032         ccw++;
2033         ccw->cmd_code = DASD_ECKD_CCW_RSSD;
2034         ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
2035         ccw->cda = (__u32)(addr_t) stats;
2036
2037         cqr->buildclk = get_clock();
2038         cqr->status = DASD_CQR_FILLED;
2039         rc = dasd_sleep_on(cqr);
2040         if (rc == 0) {
2041                 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
2042                 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
2043                 if (copy_to_user(argp, stats,
2044                                  sizeof(struct dasd_rssd_perf_stats_t)))
2045                         rc = -EFAULT;
2046         }
2047         dasd_sfree_request(cqr, cqr->memdev);
2048         return rc;
2049 }
2050
2051 /*
2052  * Get attributes (cache operations)
2053  * Returnes the cache attributes used in Define Extend (DE).
2054  */
2055 static int
2056 dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
2057 {
2058         struct dasd_eckd_private *private =
2059                 (struct dasd_eckd_private *)device->private;
2060         struct attrib_data_t attrib = private->attrib;
2061         int rc;
2062
2063         if (!capable(CAP_SYS_ADMIN))
2064                 return -EACCES;
2065         if (!argp)
2066                 return -EINVAL;
2067
2068         rc = 0;
2069         if (copy_to_user(argp, (long *) &attrib,
2070                          sizeof(struct attrib_data_t)))
2071                 rc = -EFAULT;
2072
2073         return rc;
2074 }
2075
2076 /*
2077  * Set attributes (cache operations)
2078  * Stores the attributes for cache operation to be used in Define Extend (DE).
2079  */
2080 static int
2081 dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
2082 {
2083         struct dasd_eckd_private *private =
2084                 (struct dasd_eckd_private *)device->private;
2085         struct attrib_data_t attrib;
2086
2087         if (!capable(CAP_SYS_ADMIN))
2088                 return -EACCES;
2089         if (!argp)
2090                 return -EINVAL;
2091
2092         if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
2093                 return -EFAULT;
2094         private->attrib = attrib;
2095
2096         DEV_MESSAGE(KERN_INFO, device,
2097                     "cache operation mode set to %x (%i cylinder prestage)",
2098                     private->attrib.operation, private->attrib.nr_cyl);
2099         return 0;
2100 }
2101
2102 /*
2103  * Issue syscall I/O to EMC Symmetrix array.
2104  * CCWs are PSF and RSSD
2105  */
2106 static int dasd_symm_io(struct dasd_device *device, void __user *argp)
2107 {
2108         struct dasd_symmio_parms usrparm;
2109         char *psf_data, *rssd_result;
2110         struct dasd_ccw_req *cqr;
2111         struct ccw1 *ccw;
2112         int rc;
2113
2114         /* Copy parms from caller */
2115         rc = -EFAULT;
2116         if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
2117                 goto out;
2118 #ifndef CONFIG_64BIT
2119         /* Make sure pointers are sane even on 31 bit. */
2120         if ((usrparm.psf_data >> 32) != 0 || (usrparm.rssd_result >> 32) != 0) {
2121                 rc = -EINVAL;
2122                 goto out;
2123         }
2124 #endif
2125         /* alloc I/O data area */
2126         psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
2127         rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
2128         if (!psf_data || !rssd_result) {
2129                 rc = -ENOMEM;
2130                 goto out_free;
2131         }
2132
2133         /* get syscall header from user space */
2134         rc = -EFAULT;
2135         if (copy_from_user(psf_data,
2136                            (void __user *)(unsigned long) usrparm.psf_data,
2137                            usrparm.psf_data_len))
2138                 goto out_free;
2139
2140         /* sanity check on syscall header */
2141         if (psf_data[0] != 0x17 && psf_data[1] != 0xce) {
2142                 rc = -EINVAL;
2143                 goto out_free;
2144         }
2145
2146         /* setup CCWs for PSF + RSSD */
2147         cqr = dasd_smalloc_request("ECKD", 2 , 0, device);
2148         if (IS_ERR(cqr)) {
2149                 DEV_MESSAGE(KERN_WARNING, device, "%s",
2150                         "Could not allocate initialization request");
2151                 rc = PTR_ERR(cqr);
2152                 goto out_free;
2153         }
2154
2155         cqr->startdev = device;
2156         cqr->memdev = device;
2157         cqr->retries = 3;
2158         cqr->expires = 10 * HZ;
2159         cqr->buildclk = get_clock();
2160         cqr->status = DASD_CQR_FILLED;
2161
2162         /* Build the ccws */
2163         ccw = cqr->cpaddr;
2164
2165         /* PSF ccw */
2166         ccw->cmd_code = DASD_ECKD_CCW_PSF;
2167         ccw->count = usrparm.psf_data_len;
2168         ccw->flags |= CCW_FLAG_CC;
2169         ccw->cda = (__u32)(addr_t) psf_data;
2170
2171         ccw++;
2172
2173         /* RSSD ccw  */
2174         ccw->cmd_code = DASD_ECKD_CCW_RSSD;
2175         ccw->count = usrparm.rssd_result_len;
2176         ccw->flags = CCW_FLAG_SLI ;
2177         ccw->cda = (__u32)(addr_t) rssd_result;
2178
2179         rc = dasd_sleep_on(cqr);
2180         if (rc)
2181                 goto out_sfree;
2182
2183         rc = -EFAULT;
2184         if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
2185                            rssd_result, usrparm.rssd_result_len))
2186                 goto out_sfree;
2187         rc = 0;
2188
2189 out_sfree:
2190         dasd_sfree_request(cqr, cqr->memdev);
2191 out_free:
2192         kfree(rssd_result);
2193         kfree(psf_data);
2194 out:
2195         DBF_DEV_EVENT(DBF_WARNING, device, "Symmetrix ioctl: rc=%d", rc);
2196         return rc;
2197 }
2198
2199 static int
2200 dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
2201 {
2202         struct dasd_device *device = block->base;
2203
2204         switch (cmd) {
2205         case BIODASDGATTR:
2206                 return dasd_eckd_get_attrib(device, argp);
2207         case BIODASDSATTR:
2208                 return dasd_eckd_set_attrib(device, argp);
2209         case BIODASDPSRD:
2210                 return dasd_eckd_performance(device, argp);
2211         case BIODASDRLSE:
2212                 return dasd_eckd_release(device);
2213         case BIODASDRSRV:
2214                 return dasd_eckd_reserve(device);
2215         case BIODASDSLCK:
2216                 return dasd_eckd_steal_lock(device);
2217         case BIODASDSYMMIO:
2218                 return dasd_symm_io(device, argp);
2219         default:
2220                 return -ENOIOCTLCMD;
2221         }
2222 }
2223
2224 /*
2225  * Dump the range of CCWs into 'page' buffer
2226  * and return number of printed chars.
2227  */
2228 static int
2229 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
2230 {
2231         int len, count;
2232         char *datap;
2233
2234         len = 0;
2235         while (from <= to) {
2236                 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2237                                " CCW %p: %08X %08X DAT:",
2238                                from, ((int *) from)[0], ((int *) from)[1]);
2239
2240                 /* get pointer to data (consider IDALs) */
2241                 if (from->flags & CCW_FLAG_IDA)
2242                         datap = (char *) *((addr_t *) (addr_t) from->cda);
2243                 else
2244                         datap = (char *) ((addr_t) from->cda);
2245
2246                 /* dump data (max 32 bytes) */
2247                 for (count = 0; count < from->count && count < 32; count++) {
2248                         if (count % 8 == 0) len += sprintf(page + len, " ");
2249                         if (count % 4 == 0) len += sprintf(page + len, " ");
2250                         len += sprintf(page + len, "%02x", datap[count]);
2251                 }
2252                 len += sprintf(page + len, "\n");
2253                 from++;
2254         }
2255         return len;
2256 }
2257
2258 /*
2259  * Print sense data and related channel program.
2260  * Parts are printed because printk buffer is only 1024 bytes.
2261  */
2262 static void dasd_eckd_dump_sense(struct dasd_device *device,
2263                                  struct dasd_ccw_req *req, struct irb *irb)
2264 {
2265         char *page;
2266         struct ccw1 *first, *last, *fail, *from, *to;
2267         int len, sl, sct;
2268
2269         page = (char *) get_zeroed_page(GFP_ATOMIC);
2270         if (page == NULL) {
2271                 DEV_MESSAGE(KERN_ERR, device, " %s",
2272                             "No memory to dump sense data");
2273                 return;
2274         }
2275         /* dump the sense data */
2276         len = sprintf(page,  KERN_ERR PRINTK_HEADER
2277                       " I/O status report for device %s:\n",
2278                       dev_name(&device->cdev->dev));
2279         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2280                        " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
2281                        irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
2282         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2283                        " device %s: Failing CCW: %p\n",
2284                        dev_name(&device->cdev->dev),
2285                        (void *) (addr_t) irb->scsw.cmd.cpa);
2286         if (irb->esw.esw0.erw.cons) {
2287                 for (sl = 0; sl < 4; sl++) {
2288                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
2289                                        " Sense(hex) %2d-%2d:",
2290                                        (8 * sl), ((8 * sl) + 7));
2291
2292                         for (sct = 0; sct < 8; sct++) {
2293                                 len += sprintf(page + len, " %02x",
2294                                                irb->ecw[8 * sl + sct]);
2295                         }
2296                         len += sprintf(page + len, "\n");
2297                 }
2298
2299                 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
2300                         /* 24 Byte Sense Data */
2301                         sprintf(page + len, KERN_ERR PRINTK_HEADER
2302                                 " 24 Byte: %x MSG %x, "
2303                                 "%s MSGb to SYSOP\n",
2304                                 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
2305                                 irb->ecw[1] & 0x10 ? "" : "no");
2306                 } else {
2307                         /* 32 Byte Sense Data */
2308                         sprintf(page + len, KERN_ERR PRINTK_HEADER
2309                                 " 32 Byte: Format: %x "
2310                                 "Exception class %x\n",
2311                                 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
2312                 }
2313         } else {
2314                 sprintf(page + len, KERN_ERR PRINTK_HEADER
2315                         " SORRY - NO VALID SENSE AVAILABLE\n");
2316         }
2317         printk("%s", page);
2318
2319         if (req) {
2320                 /* req == NULL for unsolicited interrupts */
2321                 /* dump the Channel Program (max 140 Bytes per line) */
2322                 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
2323                 first = req->cpaddr;
2324                 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
2325                 to = min(first + 6, last);
2326                 len = sprintf(page,  KERN_ERR PRINTK_HEADER
2327                               " Related CP in req: %p\n", req);
2328                 dasd_eckd_dump_ccw_range(first, to, page + len);
2329                 printk("%s", page);
2330
2331                 /* print failing CCW area (maximum 4) */
2332                 /* scsw->cda is either valid or zero  */
2333                 len = 0;
2334                 from = ++to;
2335                 fail = (struct ccw1 *)(addr_t)
2336                                 irb->scsw.cmd.cpa; /* failing CCW */
2337                 if (from <  fail - 2) {
2338                         from = fail - 2;     /* there is a gap - print header */
2339                         len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
2340                 }
2341                 to = min(fail + 1, last);
2342                 len += dasd_eckd_dump_ccw_range(from, to, page + len);
2343
2344                 /* print last CCWs (maximum 2) */
2345                 from = max(from, ++to);
2346                 if (from < last - 1) {
2347                         from = last - 1;     /* there is a gap - print header */
2348                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
2349                 }
2350                 len += dasd_eckd_dump_ccw_range(from, last, page + len);
2351                 if (len > 0)
2352                         printk("%s", page);
2353         }
2354         free_page((unsigned long) page);
2355 }
2356
2357 /*
2358  * max_blocks is dependent on the amount of storage that is available
2359  * in the static io buffer for each device. Currently each device has
2360  * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
2361  * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
2362  * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
2363  * addition we have one define extent ccw + 16 bytes of data and one
2364  * locate record ccw + 16 bytes of data. That makes:
2365  * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
2366  * We want to fit two into the available memory so that we can immediately
2367  * start the next request if one finishes off. That makes 249.5 blocks
2368  * for one request. Give a little safety and the result is 240.
2369  */
2370 static struct dasd_discipline dasd_eckd_discipline = {
2371         .owner = THIS_MODULE,
2372         .name = "ECKD",
2373         .ebcname = "ECKD",
2374         .max_blocks = 240,
2375         .check_device = dasd_eckd_check_characteristics,
2376         .uncheck_device = dasd_eckd_uncheck_device,
2377         .do_analysis = dasd_eckd_do_analysis,
2378         .ready_to_online = dasd_eckd_ready_to_online,
2379         .online_to_ready = dasd_eckd_online_to_ready,
2380         .fill_geometry = dasd_eckd_fill_geometry,
2381         .start_IO = dasd_start_IO,
2382         .term_IO = dasd_term_IO,
2383         .handle_terminated_request = dasd_eckd_handle_terminated_request,
2384         .format_device = dasd_eckd_format_device,
2385         .erp_action = dasd_eckd_erp_action,
2386         .erp_postaction = dasd_eckd_erp_postaction,
2387         .handle_unsolicited_interrupt = dasd_eckd_handle_unsolicited_interrupt,
2388         .build_cp = dasd_eckd_build_alias_cp,
2389         .free_cp = dasd_eckd_free_alias_cp,
2390         .dump_sense = dasd_eckd_dump_sense,
2391         .fill_info = dasd_eckd_fill_info,
2392         .ioctl = dasd_eckd_ioctl,
2393 };
2394
2395 static int __init
2396 dasd_eckd_init(void)
2397 {
2398         ASCEBC(dasd_eckd_discipline.ebcname, 4);
2399         return ccw_driver_register(&dasd_eckd_driver);
2400 }
2401
2402 static void __exit
2403 dasd_eckd_cleanup(void)
2404 {
2405         ccw_driver_unregister(&dasd_eckd_driver);
2406 }
2407
2408 module_init(dasd_eckd_init);
2409 module_exit(dasd_eckd_cleanup);