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