Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-2.6] / 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  *
10  */
11
12 #include <linux/stddef.h>
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
15 #include <linux/hdreg.h>        /* HDIO_GETGEO                      */
16 #include <linux/bio.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19
20 #include <asm/debug.h>
21 #include <asm/idals.h>
22 #include <asm/ebcdic.h>
23 #include <asm/io.h>
24 #include <asm/todclk.h>
25 #include <asm/uaccess.h>
26 #include <asm/cio.h>
27 #include <asm/ccwdev.h>
28
29 #include "dasd_int.h"
30 #include "dasd_eckd.h"
31
32 #ifdef PRINTK_HEADER
33 #undef PRINTK_HEADER
34 #endif                          /* PRINTK_HEADER */
35 #define PRINTK_HEADER "dasd(eckd):"
36
37 #define ECKD_C0(i) (i->home_bytes)
38 #define ECKD_F(i) (i->formula)
39 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
40                     (i->factors.f_0x02.f1))
41 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
42                     (i->factors.f_0x02.f2))
43 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
44                     (i->factors.f_0x02.f3))
45 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
46 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
47 #define ECKD_F6(i) (i->factor6)
48 #define ECKD_F7(i) (i->factor7)
49 #define ECKD_F8(i) (i->factor8)
50
51 MODULE_LICENSE("GPL");
52
53 static struct dasd_discipline dasd_eckd_discipline;
54
55 struct dasd_eckd_private {
56         struct dasd_eckd_characteristics rdc_data;
57         struct dasd_eckd_confdata conf_data;
58         struct dasd_eckd_path path_data;
59         struct eckd_count count_area[5];
60         int init_cqr_status;
61         int uses_cdl;
62         struct attrib_data_t attrib;    /* e.g. cache operations */
63 };
64
65 /* The ccw bus type uses this table to find devices that it sends to
66  * dasd_eckd_probe */
67 static struct ccw_device_id dasd_eckd_ids[] = {
68         { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
69         { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
70         { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info = 0x3},
71         { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
72         { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
73         { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
74         { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
75         { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
76         { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
77         { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
78         { /* end of list */ },
79 };
80
81 MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
82
83 static struct ccw_driver dasd_eckd_driver; /* see below */
84
85 /* initial attempt at a probe function. this can be simplified once
86  * the other detection code is gone */
87 static int
88 dasd_eckd_probe (struct ccw_device *cdev)
89 {
90         int ret;
91
92         /* set ECKD specific ccw-device options */
93         ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE);
94         if (ret) {
95                 printk(KERN_WARNING
96                        "dasd_eckd_probe: could not set ccw-device options "
97                        "for %s\n", cdev->dev.bus_id);
98                 return ret;
99         }
100         ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
101         return ret;
102 }
103
104 static int
105 dasd_eckd_set_online(struct ccw_device *cdev)
106 {
107         return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
108 }
109
110 static struct ccw_driver dasd_eckd_driver = {
111         .name        = "dasd-eckd",
112         .owner       = THIS_MODULE,
113         .ids         = dasd_eckd_ids,
114         .probe       = dasd_eckd_probe,
115         .remove      = dasd_generic_remove,
116         .set_offline = dasd_generic_set_offline,
117         .set_online  = dasd_eckd_set_online,
118         .notify      = dasd_generic_notify,
119 };
120
121 static const int sizes_trk0[] = { 28, 148, 84 };
122 #define LABEL_SIZE 140
123
124 static inline unsigned int
125 round_up_multiple(unsigned int no, unsigned int mult)
126 {
127         int rem = no % mult;
128         return (rem ? no - rem + mult : no);
129 }
130
131 static inline unsigned int
132 ceil_quot(unsigned int d1, unsigned int d2)
133 {
134         return (d1 + (d2 - 1)) / d2;
135 }
136
137 static unsigned int
138 recs_per_track(struct dasd_eckd_characteristics * rdc,
139                unsigned int kl, unsigned int dl)
140 {
141         int dn, kn;
142
143         switch (rdc->dev_type) {
144         case 0x3380:
145                 if (kl)
146                         return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
147                                        ceil_quot(dl + 12, 32));
148                 else
149                         return 1499 / (15 + ceil_quot(dl + 12, 32));
150         case 0x3390:
151                 dn = ceil_quot(dl + 6, 232) + 1;
152                 if (kl) {
153                         kn = ceil_quot(kl + 6, 232) + 1;
154                         return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
155                                        9 + ceil_quot(dl + 6 * dn, 34));
156                 } else
157                         return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
158         case 0x9345:
159                 dn = ceil_quot(dl + 6, 232) + 1;
160                 if (kl) {
161                         kn = ceil_quot(kl + 6, 232) + 1;
162                         return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
163                                        ceil_quot(dl + 6 * dn, 34));
164                 } else
165                         return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
166         }
167         return 0;
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, int trk,
198               int totrk, int cmd, struct dasd_device * device)
199 {
200         struct dasd_eckd_private *private;
201         struct ch_t geo, beg, end;
202         int rc = 0;
203
204         private = (struct dasd_eckd_private *) device->private;
205
206         ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
207         ccw->flags = 0;
208         ccw->count = 16;
209         ccw->cda = (__u32) __pa(data);
210
211         memset(data, 0, sizeof (struct DE_eckd_data));
212         switch (cmd) {
213         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
214         case DASD_ECKD_CCW_READ_RECORD_ZERO:
215         case DASD_ECKD_CCW_READ:
216         case DASD_ECKD_CCW_READ_MT:
217         case DASD_ECKD_CCW_READ_CKD:
218         case DASD_ECKD_CCW_READ_CKD_MT:
219         case DASD_ECKD_CCW_READ_KD:
220         case DASD_ECKD_CCW_READ_KD_MT:
221         case DASD_ECKD_CCW_READ_COUNT:
222                 data->mask.perm = 0x1;
223                 data->attributes.operation = private->attrib.operation;
224                 break;
225         case DASD_ECKD_CCW_WRITE:
226         case DASD_ECKD_CCW_WRITE_MT:
227         case DASD_ECKD_CCW_WRITE_KD:
228         case DASD_ECKD_CCW_WRITE_KD_MT:
229                 data->mask.perm = 0x02;
230                 data->attributes.operation = private->attrib.operation;
231                 rc = check_XRC (ccw, data, device);
232                 break;
233         case DASD_ECKD_CCW_WRITE_CKD:
234         case DASD_ECKD_CCW_WRITE_CKD_MT:
235                 data->attributes.operation = DASD_BYPASS_CACHE;
236                 rc = check_XRC (ccw, data, device);
237                 break;
238         case DASD_ECKD_CCW_ERASE:
239         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
240         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
241                 data->mask.perm = 0x3;
242                 data->mask.auth = 0x1;
243                 data->attributes.operation = DASD_BYPASS_CACHE;
244                 rc = check_XRC (ccw, data, device);
245                 break;
246         default:
247                 DEV_MESSAGE(KERN_ERR, device, "unknown opcode 0x%x", cmd);
248                 break;
249         }
250
251         data->attributes.mode = 0x3;    /* ECKD */
252
253         if ((private->rdc_data.cu_type == 0x2105 ||
254              private->rdc_data.cu_type == 0x2107 ||
255              private->rdc_data.cu_type == 0x1750)
256             && !(private->uses_cdl && trk < 2))
257                 data->ga_extended |= 0x40; /* Regular Data Format Mode */
258
259         geo.cyl = private->rdc_data.no_cyl;
260         geo.head = private->rdc_data.trk_per_cyl;
261         beg.cyl = trk / geo.head;
262         beg.head = trk % geo.head;
263         end.cyl = totrk / geo.head;
264         end.head = totrk % geo.head;
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 (end.cyl + private->attrib.nr_cyl < geo.cyl)
271                         end.cyl += private->attrib.nr_cyl;
272                 else
273                         end.cyl = (geo.cyl - 1);
274         }
275
276         data->beg_ext.cyl = beg.cyl;
277         data->beg_ext.head = beg.head;
278         data->end_ext.cyl = end.cyl;
279         data->end_ext.head = end.head;
280         return rc;
281 }
282
283 static void
284 locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, int trk,
285               int rec_on_trk, int no_rec, int cmd,
286               struct dasd_device * device, int reclen)
287 {
288         struct dasd_eckd_private *private;
289         int sector;
290         int dn, d;
291
292         private = (struct dasd_eckd_private *) device->private;
293
294         DBF_DEV_EVENT(DBF_INFO, device,
295                   "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
296                   trk, rec_on_trk, no_rec, cmd, reclen);
297
298         ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
299         ccw->flags = 0;
300         ccw->count = 16;
301         ccw->cda = (__u32) __pa(data);
302
303         memset(data, 0, sizeof (struct LO_eckd_data));
304         sector = 0;
305         if (rec_on_trk) {
306                 switch (private->rdc_data.dev_type) {
307                 case 0x3390:
308                         dn = ceil_quot(reclen + 6, 232);
309                         d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
310                         sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
311                         break;
312                 case 0x3380:
313                         d = 7 + ceil_quot(reclen + 12, 32);
314                         sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
315                         break;
316                 }
317         }
318         data->sector = sector;
319         data->count = no_rec;
320         switch (cmd) {
321         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
322                 data->operation.orientation = 0x3;
323                 data->operation.operation = 0x03;
324                 break;
325         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
326                 data->operation.orientation = 0x3;
327                 data->operation.operation = 0x16;
328                 break;
329         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
330                 data->operation.orientation = 0x1;
331                 data->operation.operation = 0x03;
332                 data->count++;
333                 break;
334         case DASD_ECKD_CCW_READ_RECORD_ZERO:
335                 data->operation.orientation = 0x3;
336                 data->operation.operation = 0x16;
337                 data->count++;
338                 break;
339         case DASD_ECKD_CCW_WRITE:
340         case DASD_ECKD_CCW_WRITE_MT:
341         case DASD_ECKD_CCW_WRITE_KD:
342         case DASD_ECKD_CCW_WRITE_KD_MT:
343                 data->auxiliary.last_bytes_used = 0x1;
344                 data->length = reclen;
345                 data->operation.operation = 0x01;
346                 break;
347         case DASD_ECKD_CCW_WRITE_CKD:
348         case DASD_ECKD_CCW_WRITE_CKD_MT:
349                 data->auxiliary.last_bytes_used = 0x1;
350                 data->length = reclen;
351                 data->operation.operation = 0x03;
352                 break;
353         case DASD_ECKD_CCW_READ:
354         case DASD_ECKD_CCW_READ_MT:
355         case DASD_ECKD_CCW_READ_KD:
356         case DASD_ECKD_CCW_READ_KD_MT:
357                 data->auxiliary.last_bytes_used = 0x1;
358                 data->length = reclen;
359                 data->operation.operation = 0x06;
360                 break;
361         case DASD_ECKD_CCW_READ_CKD:
362         case DASD_ECKD_CCW_READ_CKD_MT:
363                 data->auxiliary.last_bytes_used = 0x1;
364                 data->length = reclen;
365                 data->operation.operation = 0x16;
366                 break;
367         case DASD_ECKD_CCW_READ_COUNT:
368                 data->operation.operation = 0x06;
369                 break;
370         case DASD_ECKD_CCW_ERASE:
371                 data->length = reclen;
372                 data->auxiliary.last_bytes_used = 0x1;
373                 data->operation.operation = 0x0b;
374                 break;
375         default:
376                 DEV_MESSAGE(KERN_ERR, device, "unknown opcode 0x%x", cmd);
377         }
378         data->seek_addr.cyl = data->search_arg.cyl =
379                 trk / private->rdc_data.trk_per_cyl;
380         data->seek_addr.head = data->search_arg.head =
381                 trk % private->rdc_data.trk_per_cyl;
382         data->search_arg.record = rec_on_trk;
383 }
384
385 /*
386  * Returns 1 if the block is one of the special blocks that needs
387  * to get read/written with the KD variant of the command.
388  * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
389  * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
390  * Luckily the KD variants differ only by one bit (0x08) from the
391  * normal variant. So don't wonder about code like:
392  * if (dasd_eckd_cdl_special(blk_per_trk, recid))
393  *         ccw->cmd_code |= 0x8;
394  */
395 static inline int
396 dasd_eckd_cdl_special(int blk_per_trk, int recid)
397 {
398         if (recid < 3)
399                 return 1;
400         if (recid < blk_per_trk)
401                 return 0;
402         if (recid < 2 * blk_per_trk)
403                 return 1;
404         return 0;
405 }
406
407 /*
408  * Returns the record size for the special blocks of the cdl format.
409  * Only returns something useful if dasd_eckd_cdl_special is true
410  * for the recid.
411  */
412 static inline int
413 dasd_eckd_cdl_reclen(int recid)
414 {
415         if (recid < 3)
416                 return sizes_trk0[recid];
417         return LABEL_SIZE;
418 }
419
420 /*
421  * Generate device unique id that specifies the physical device.
422  */
423 static int
424 dasd_eckd_generate_uid(struct dasd_device *device, struct dasd_uid *uid)
425 {
426         struct dasd_eckd_private *private;
427         struct dasd_eckd_confdata *confdata;
428
429         private = (struct dasd_eckd_private *) device->private;
430         if (!private)
431                 return -ENODEV;
432         confdata = &private->conf_data;
433         if (!confdata)
434                 return -ENODEV;
435
436         memset(uid, 0, sizeof(struct dasd_uid));
437         memcpy(uid->vendor, confdata->ned1.HDA_manufacturer,
438                sizeof(uid->vendor) - 1);
439         EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
440         memcpy(uid->serial, confdata->ned1.HDA_location,
441                sizeof(uid->serial) - 1);
442         EBCASC(uid->serial, sizeof(uid->serial) - 1);
443         uid->ssid = confdata->neq.subsystemID;
444         if (confdata->ned2.sneq.flags == 0x40) {
445                 uid->alias = 1;
446                 uid->unit_addr = confdata->ned2.sneq.base_unit_addr;
447         } else
448                 uid->unit_addr = confdata->ned1.unit_addr;
449
450         return 0;
451 }
452
453 static struct dasd_ccw_req *dasd_eckd_build_rcd_lpm(struct dasd_device *device,
454                                                     void *rcd_buffer,
455                                                     struct ciw *ciw, __u8 lpm)
456 {
457         struct dasd_ccw_req *cqr;
458         struct ccw1 *ccw;
459
460         cqr = dasd_smalloc_request("ECKD", 1 /* RCD */, ciw->count, device);
461
462         if (IS_ERR(cqr)) {
463                 DEV_MESSAGE(KERN_WARNING, device, "%s",
464                             "Could not allocate RCD request");
465                 return cqr;
466         }
467
468         ccw = cqr->cpaddr;
469         ccw->cmd_code = ciw->cmd;
470         ccw->cda = (__u32)(addr_t)rcd_buffer;
471         ccw->count = ciw->count;
472
473         cqr->device = device;
474         cqr->expires = 10*HZ;
475         cqr->lpm = lpm;
476         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
477         cqr->retries = 2;
478         cqr->buildclk = get_clock();
479         cqr->status = DASD_CQR_FILLED;
480         return cqr;
481 }
482
483 static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
484                                    void **rcd_buffer,
485                                    int *rcd_buffer_size, __u8 lpm)
486 {
487         struct ciw *ciw;
488         char *rcd_buf = NULL;
489         int ret;
490         struct dasd_ccw_req *cqr;
491
492         /*
493          * scan for RCD command in extended SenseID data
494          */
495         ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
496         if (!ciw || ciw->cmd == 0) {
497                 ret = -EOPNOTSUPP;
498                 goto out_error;
499         }
500         rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
501         if (!rcd_buf) {
502                 ret = -ENOMEM;
503                 goto out_error;
504         }
505         cqr = dasd_eckd_build_rcd_lpm(device, rcd_buf, ciw, lpm);
506         if (IS_ERR(cqr)) {
507                 ret =  PTR_ERR(cqr);
508                 goto out_error;
509         }
510         ret = dasd_sleep_on(cqr);
511         /*
512          * on success we update the user input parms
513          */
514         dasd_sfree_request(cqr, cqr->device);
515         if (ret)
516                 goto out_error;
517
518         *rcd_buffer_size = ciw->count;
519         *rcd_buffer = rcd_buf;
520         return 0;
521 out_error:
522         kfree(rcd_buf);
523         *rcd_buffer = NULL;
524         *rcd_buffer_size = 0;
525         return ret;
526 }
527
528 static int
529 dasd_eckd_read_conf(struct dasd_device *device)
530 {
531         void *conf_data;
532         int conf_len, conf_data_saved;
533         int rc;
534         __u8 lpm;
535         struct dasd_eckd_private *private;
536         struct dasd_eckd_path *path_data;
537
538         private = (struct dasd_eckd_private *) device->private;
539         path_data = (struct dasd_eckd_path *) &private->path_data;
540         path_data->opm = ccw_device_get_path_mask(device->cdev);
541         lpm = 0x80;
542         conf_data_saved = 0;
543
544         /* get configuration data per operational path */
545         for (lpm = 0x80; lpm; lpm>>= 1) {
546                 if (lpm & path_data->opm){
547                         rc = dasd_eckd_read_conf_lpm(device, &conf_data,
548                                                      &conf_len, lpm);
549                         if (rc && rc != -EOPNOTSUPP) {  /* -EOPNOTSUPP is ok */
550                                 MESSAGE(KERN_WARNING,
551                                         "Read configuration data returned "
552                                         "error %d", rc);
553                                 return rc;
554                         }
555                         if (conf_data == NULL) {
556                                 MESSAGE(KERN_WARNING, "%s", "No configuration "
557                                         "data retrieved");
558                                 continue;       /* no error */
559                         }
560                         if (conf_len != sizeof (struct dasd_eckd_confdata)) {
561                                 MESSAGE(KERN_WARNING,
562                                         "sizes of configuration data mismatch"
563                                         "%d (read) vs %ld (expected)",
564                                         conf_len,
565                                         sizeof (struct dasd_eckd_confdata));
566                                 kfree(conf_data);
567                                 continue;       /* no error */
568                         }
569                         /* save first valid configuration data */
570                         if (!conf_data_saved){
571                                 memcpy(&private->conf_data, conf_data,
572                                        sizeof (struct dasd_eckd_confdata));
573                                 conf_data_saved++;
574                         }
575                         switch (((char *)conf_data)[242] & 0x07){
576                         case 0x02:
577                                 path_data->npm |= lpm;
578                                 break;
579                         case 0x03:
580                                 path_data->ppm |= lpm;
581                                 break;
582                         }
583                         kfree(conf_data);
584                 }
585         }
586         return 0;
587 }
588
589 /*
590  * Build CP for Perform Subsystem Function - SSC.
591  */
592 static struct dasd_ccw_req *
593 dasd_eckd_build_psf_ssc(struct dasd_device *device)
594 {
595        struct dasd_ccw_req *cqr;
596        struct dasd_psf_ssc_data *psf_ssc_data;
597        struct ccw1 *ccw;
598
599        cqr = dasd_smalloc_request("ECKD", 1 /* PSF */ ,
600                                   sizeof(struct dasd_psf_ssc_data),
601                                   device);
602
603        if (IS_ERR(cqr)) {
604                DEV_MESSAGE(KERN_WARNING, device, "%s",
605                            "Could not allocate PSF-SSC request");
606                return cqr;
607        }
608        psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
609        psf_ssc_data->order = PSF_ORDER_SSC;
610        psf_ssc_data->suborder = 0x08;
611
612        ccw = cqr->cpaddr;
613        ccw->cmd_code = DASD_ECKD_CCW_PSF;
614        ccw->cda = (__u32)(addr_t)psf_ssc_data;
615        ccw->count = 66;
616
617        cqr->device = device;
618        cqr->expires = 10*HZ;
619        cqr->buildclk = get_clock();
620        cqr->status = DASD_CQR_FILLED;
621        return cqr;
622 }
623
624 /*
625  * Perform Subsystem Function.
626  * It is necessary to trigger CIO for channel revalidation since this
627  * call might change behaviour of DASD devices.
628  */
629 static int
630 dasd_eckd_psf_ssc(struct dasd_device *device)
631 {
632        struct dasd_ccw_req *cqr;
633        int rc;
634
635        cqr = dasd_eckd_build_psf_ssc(device);
636        if (IS_ERR(cqr))
637                return PTR_ERR(cqr);
638
639        rc = dasd_sleep_on(cqr);
640        if (!rc)
641                /* trigger CIO to reprobe devices */
642                css_schedule_reprobe();
643        dasd_sfree_request(cqr, cqr->device);
644        return rc;
645 }
646
647 /*
648  * Valide storage server of current device.
649  */
650 static int
651 dasd_eckd_validate_server(struct dasd_device *device, struct dasd_uid *uid)
652 {
653         int rc;
654
655         /* Currently PAV is the only reason to 'validate' server on LPAR */
656         if (dasd_nopav || MACHINE_IS_VM)
657                 return 0;
658
659         rc = dasd_eckd_psf_ssc(device);
660         /* may be requested feature is not available on server,
661          * therefore just report error and go ahead */
662         DEV_MESSAGE(KERN_INFO, device,
663                     "PSF-SSC on storage subsystem %s.%s.%04x returned rc=%d",
664                     uid->vendor, uid->serial, uid->ssid, rc);
665         /* RE-Read Configuration Data */
666         return dasd_eckd_read_conf(device);
667 }
668
669 /*
670  * Check device characteristics.
671  * If the device is accessible using ECKD discipline, the device is enabled.
672  */
673 static int
674 dasd_eckd_check_characteristics(struct dasd_device *device)
675 {
676         struct dasd_eckd_private *private;
677         struct dasd_uid uid;
678         void *rdc_data;
679         int rc;
680
681         private = (struct dasd_eckd_private *) device->private;
682         if (private == NULL) {
683                 private = kzalloc(sizeof(struct dasd_eckd_private),
684                                   GFP_KERNEL | GFP_DMA);
685                 if (private == NULL) {
686                         DEV_MESSAGE(KERN_WARNING, device, "%s",
687                                     "memory allocation failed for private "
688                                     "data");
689                         return -ENOMEM;
690                 }
691                 device->private = (void *) private;
692         }
693         /* Invalidate status of initial analysis. */
694         private->init_cqr_status = -1;
695         /* Set default cache operations. */
696         private->attrib.operation = DASD_NORMAL_CACHE;
697         private->attrib.nr_cyl = 0;
698
699         /* Read Configuration Data */
700         rc = dasd_eckd_read_conf(device);
701         if (rc)
702                 return rc;
703
704         /* Generate device unique id and register in devmap */
705         rc = dasd_eckd_generate_uid(device, &uid);
706         if (rc)
707                 return rc;
708         rc = dasd_set_uid(device->cdev, &uid);
709         if (rc == 1)    /* new server found */
710                 rc = dasd_eckd_validate_server(device, &uid);
711         if (rc)
712                 return rc;
713
714         /* Read Device Characteristics */
715         rdc_data = (void *) &(private->rdc_data);
716         memset(rdc_data, 0, sizeof(rdc_data));
717         rc = dasd_generic_read_dev_chars(device, "ECKD", &rdc_data, 64);
718         if (rc)
719                 DEV_MESSAGE(KERN_WARNING, device,
720                             "Read device characteristics returned "
721                             "rc=%d", rc);
722
723         DEV_MESSAGE(KERN_INFO, device,
724                     "%04X/%02X(CU:%04X/%02X) Cyl:%d Head:%d Sec:%d",
725                     private->rdc_data.dev_type,
726                     private->rdc_data.dev_model,
727                     private->rdc_data.cu_type,
728                     private->rdc_data.cu_model.model,
729                     private->rdc_data.no_cyl,
730                     private->rdc_data.trk_per_cyl,
731                     private->rdc_data.sec_per_trk);
732         return rc;
733 }
734
735 static struct dasd_ccw_req *
736 dasd_eckd_analysis_ccw(struct dasd_device *device)
737 {
738         struct dasd_eckd_private *private;
739         struct eckd_count *count_data;
740         struct LO_eckd_data *LO_data;
741         struct dasd_ccw_req *cqr;
742         struct ccw1 *ccw;
743         int cplength, datasize;
744         int i;
745
746         private = (struct dasd_eckd_private *) device->private;
747
748         cplength = 8;
749         datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
750         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
751                                    cplength, datasize, device);
752         if (IS_ERR(cqr))
753                 return cqr;
754         ccw = cqr->cpaddr;
755         /* Define extent for the first 3 tracks. */
756         define_extent(ccw++, cqr->data, 0, 2,
757                       DASD_ECKD_CCW_READ_COUNT, device);
758         LO_data = cqr->data + sizeof (struct DE_eckd_data);
759         /* Locate record for the first 4 records on track 0. */
760         ccw[-1].flags |= CCW_FLAG_CC;
761         locate_record(ccw++, LO_data++, 0, 0, 4,
762                       DASD_ECKD_CCW_READ_COUNT, device, 0);
763
764         count_data = private->count_area;
765         for (i = 0; i < 4; i++) {
766                 ccw[-1].flags |= CCW_FLAG_CC;
767                 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
768                 ccw->flags = 0;
769                 ccw->count = 8;
770                 ccw->cda = (__u32)(addr_t) count_data;
771                 ccw++;
772                 count_data++;
773         }
774
775         /* Locate record for the first record on track 2. */
776         ccw[-1].flags |= CCW_FLAG_CC;
777         locate_record(ccw++, LO_data++, 2, 0, 1,
778                       DASD_ECKD_CCW_READ_COUNT, device, 0);
779         /* Read count ccw. */
780         ccw[-1].flags |= CCW_FLAG_CC;
781         ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
782         ccw->flags = 0;
783         ccw->count = 8;
784         ccw->cda = (__u32)(addr_t) count_data;
785
786         cqr->device = device;
787         cqr->retries = 0;
788         cqr->buildclk = get_clock();
789         cqr->status = DASD_CQR_FILLED;
790         return cqr;
791 }
792
793 /*
794  * This is the callback function for the init_analysis cqr. It saves
795  * the status of the initial analysis ccw before it frees it and kicks
796  * the device to continue the startup sequence. This will call
797  * dasd_eckd_do_analysis again (if the devices has not been marked
798  * for deletion in the meantime).
799  */
800 static void
801 dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, void *data)
802 {
803         struct dasd_eckd_private *private;
804         struct dasd_device *device;
805
806         device = init_cqr->device;
807         private = (struct dasd_eckd_private *) device->private;
808         private->init_cqr_status = init_cqr->status;
809         dasd_sfree_request(init_cqr, device);
810         dasd_kick_device(device);
811 }
812
813 static int
814 dasd_eckd_start_analysis(struct dasd_device *device)
815 {
816         struct dasd_eckd_private *private;
817         struct dasd_ccw_req *init_cqr;
818
819         private = (struct dasd_eckd_private *) device->private;
820         init_cqr = dasd_eckd_analysis_ccw(device);
821         if (IS_ERR(init_cqr))
822                 return PTR_ERR(init_cqr);
823         init_cqr->callback = dasd_eckd_analysis_callback;
824         init_cqr->callback_data = NULL;
825         init_cqr->expires = 5*HZ;
826         dasd_add_request_head(init_cqr);
827         return -EAGAIN;
828 }
829
830 static int
831 dasd_eckd_end_analysis(struct dasd_device *device)
832 {
833         struct dasd_eckd_private *private;
834         struct eckd_count *count_area;
835         unsigned int sb, blk_per_trk;
836         int status, i;
837
838         private = (struct dasd_eckd_private *) device->private;
839         status = private->init_cqr_status;
840         private->init_cqr_status = -1;
841         if (status != DASD_CQR_DONE) {
842                 DEV_MESSAGE(KERN_WARNING, device, "%s",
843                             "volume analysis returned unformatted disk");
844                 return -EMEDIUMTYPE;
845         }
846
847         private->uses_cdl = 1;
848         /* Calculate number of blocks/records per track. */
849         blk_per_trk = recs_per_track(&private->rdc_data, 0, device->bp_block);
850         /* Check Track 0 for Compatible Disk Layout */
851         count_area = NULL;
852         for (i = 0; i < 3; i++) {
853                 if (private->count_area[i].kl != 4 ||
854                     private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
855                         private->uses_cdl = 0;
856                         break;
857                 }
858         }
859         if (i == 3)
860                 count_area = &private->count_area[4];
861
862         if (private->uses_cdl == 0) {
863                 for (i = 0; i < 5; i++) {
864                         if ((private->count_area[i].kl != 0) ||
865                             (private->count_area[i].dl !=
866                              private->count_area[0].dl))
867                                 break;
868                 }
869                 if (i == 5)
870                         count_area = &private->count_area[0];
871         } else {
872                 if (private->count_area[3].record == 1)
873                         DEV_MESSAGE(KERN_WARNING, device, "%s",
874                                     "Trk 0: no records after VTOC!");
875         }
876         if (count_area != NULL && count_area->kl == 0) {
877                 /* we found notthing violating our disk layout */
878                 if (dasd_check_blocksize(count_area->dl) == 0)
879                         device->bp_block = count_area->dl;
880         }
881         if (device->bp_block == 0) {
882                 DEV_MESSAGE(KERN_WARNING, device, "%s",
883                             "Volume has incompatible disk layout");
884                 return -EMEDIUMTYPE;
885         }
886         device->s2b_shift = 0;  /* bits to shift 512 to get a block */
887         for (sb = 512; sb < device->bp_block; sb = sb << 1)
888                 device->s2b_shift++;
889
890         blk_per_trk = recs_per_track(&private->rdc_data, 0, device->bp_block);
891         device->blocks = (private->rdc_data.no_cyl *
892                           private->rdc_data.trk_per_cyl *
893                           blk_per_trk);
894
895         DEV_MESSAGE(KERN_INFO, device,
896                     "(%dkB blks): %dkB at %dkB/trk %s",
897                     (device->bp_block >> 10),
898                     ((private->rdc_data.no_cyl *
899                       private->rdc_data.trk_per_cyl *
900                       blk_per_trk * (device->bp_block >> 9)) >> 1),
901                     ((blk_per_trk * device->bp_block) >> 10),
902                     private->uses_cdl ?
903                     "compatible disk layout" : "linux disk layout");
904
905         return 0;
906 }
907
908 static int
909 dasd_eckd_do_analysis(struct dasd_device *device)
910 {
911         struct dasd_eckd_private *private;
912
913         private = (struct dasd_eckd_private *) device->private;
914         if (private->init_cqr_status < 0)
915                 return dasd_eckd_start_analysis(device);
916         else
917                 return dasd_eckd_end_analysis(device);
918 }
919
920 static int
921 dasd_eckd_fill_geometry(struct dasd_device *device, struct hd_geometry *geo)
922 {
923         struct dasd_eckd_private *private;
924
925         private = (struct dasd_eckd_private *) device->private;
926         if (dasd_check_blocksize(device->bp_block) == 0) {
927                 geo->sectors = recs_per_track(&private->rdc_data,
928                                               0, device->bp_block);
929         }
930         geo->cylinders = private->rdc_data.no_cyl;
931         geo->heads = private->rdc_data.trk_per_cyl;
932         return 0;
933 }
934
935 static struct dasd_ccw_req *
936 dasd_eckd_format_device(struct dasd_device * device,
937                         struct format_data_t * fdata)
938 {
939         struct dasd_eckd_private *private;
940         struct dasd_ccw_req *fcp;
941         struct eckd_count *ect;
942         struct ccw1 *ccw;
943         void *data;
944         int rpt, cyl, head;
945         int cplength, datasize;
946         int i;
947
948         private = (struct dasd_eckd_private *) device->private;
949         rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
950         cyl = fdata->start_unit / private->rdc_data.trk_per_cyl;
951         head = fdata->start_unit % private->rdc_data.trk_per_cyl;
952
953         /* Sanity checks. */
954         if (fdata->start_unit >=
955             (private->rdc_data.no_cyl * private->rdc_data.trk_per_cyl)) {
956                 DEV_MESSAGE(KERN_INFO, device, "Track no %d too big!",
957                             fdata->start_unit);
958                 return ERR_PTR(-EINVAL);
959         }
960         if (fdata->start_unit > fdata->stop_unit) {
961                 DEV_MESSAGE(KERN_INFO, device, "Track %d reached! ending.",
962                             fdata->start_unit);
963                 return ERR_PTR(-EINVAL);
964         }
965         if (dasd_check_blocksize(fdata->blksize) != 0) {
966                 DEV_MESSAGE(KERN_WARNING, device,
967                             "Invalid blocksize %d...terminating!",
968                             fdata->blksize);
969                 return ERR_PTR(-EINVAL);
970         }
971
972         /*
973          * fdata->intensity is a bit string that tells us what to do:
974          *   Bit 0: write record zero
975          *   Bit 1: write home address, currently not supported
976          *   Bit 2: invalidate tracks
977          *   Bit 3: use OS/390 compatible disk layout (cdl)
978          * Only some bit combinations do make sense.
979          */
980         switch (fdata->intensity) {
981         case 0x00:      /* Normal format */
982         case 0x08:      /* Normal format, use cdl. */
983                 cplength = 2 + rpt;
984                 datasize = sizeof(struct DE_eckd_data) +
985                         sizeof(struct LO_eckd_data) +
986                         rpt * sizeof(struct eckd_count);
987                 break;
988         case 0x01:      /* Write record zero and format track. */
989         case 0x09:      /* Write record zero and format track, use cdl. */
990                 cplength = 3 + rpt;
991                 datasize = sizeof(struct DE_eckd_data) +
992                         sizeof(struct LO_eckd_data) +
993                         sizeof(struct eckd_count) +
994                         rpt * sizeof(struct eckd_count);
995                 break;
996         case 0x04:      /* Invalidate track. */
997         case 0x0c:      /* Invalidate track, use cdl. */
998                 cplength = 3;
999                 datasize = sizeof(struct DE_eckd_data) +
1000                         sizeof(struct LO_eckd_data) +
1001                         sizeof(struct eckd_count);
1002                 break;
1003         default:
1004                 DEV_MESSAGE(KERN_WARNING, device, "Invalid flags 0x%x.",
1005                             fdata->intensity);
1006                 return ERR_PTR(-EINVAL);
1007         }
1008         /* Allocate the format ccw request. */
1009         fcp = dasd_smalloc_request(dasd_eckd_discipline.name,
1010                                    cplength, datasize, device);
1011         if (IS_ERR(fcp))
1012                 return fcp;
1013
1014         data = fcp->data;
1015         ccw = fcp->cpaddr;
1016
1017         switch (fdata->intensity & ~0x08) {
1018         case 0x00: /* Normal format. */
1019                 define_extent(ccw++, (struct DE_eckd_data *) data,
1020                               fdata->start_unit, fdata->start_unit,
1021                               DASD_ECKD_CCW_WRITE_CKD, device);
1022                 data += sizeof(struct DE_eckd_data);
1023                 ccw[-1].flags |= CCW_FLAG_CC;
1024                 locate_record(ccw++, (struct LO_eckd_data *) data,
1025                               fdata->start_unit, 0, rpt,
1026                               DASD_ECKD_CCW_WRITE_CKD, device,
1027                               fdata->blksize);
1028                 data += sizeof(struct LO_eckd_data);
1029                 break;
1030         case 0x01: /* Write record zero + format track. */
1031                 define_extent(ccw++, (struct DE_eckd_data *) data,
1032                               fdata->start_unit, fdata->start_unit,
1033                               DASD_ECKD_CCW_WRITE_RECORD_ZERO,
1034                               device);
1035                 data += sizeof(struct DE_eckd_data);
1036                 ccw[-1].flags |= CCW_FLAG_CC;
1037                 locate_record(ccw++, (struct LO_eckd_data *) data,
1038                               fdata->start_unit, 0, rpt + 1,
1039                               DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
1040                               device->bp_block);
1041                 data += sizeof(struct LO_eckd_data);
1042                 break;
1043         case 0x04: /* Invalidate track. */
1044                 define_extent(ccw++, (struct DE_eckd_data *) data,
1045                               fdata->start_unit, fdata->start_unit,
1046                               DASD_ECKD_CCW_WRITE_CKD, device);
1047                 data += sizeof(struct DE_eckd_data);
1048                 ccw[-1].flags |= CCW_FLAG_CC;
1049                 locate_record(ccw++, (struct LO_eckd_data *) data,
1050                               fdata->start_unit, 0, 1,
1051                               DASD_ECKD_CCW_WRITE_CKD, device, 8);
1052                 data += sizeof(struct LO_eckd_data);
1053                 break;
1054         }
1055         if (fdata->intensity & 0x01) {  /* write record zero */
1056                 ect = (struct eckd_count *) data;
1057                 data += sizeof(struct eckd_count);
1058                 ect->cyl = cyl;
1059                 ect->head = head;
1060                 ect->record = 0;
1061                 ect->kl = 0;
1062                 ect->dl = 8;
1063                 ccw[-1].flags |= CCW_FLAG_CC;
1064                 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
1065                 ccw->flags = CCW_FLAG_SLI;
1066                 ccw->count = 8;
1067                 ccw->cda = (__u32)(addr_t) ect;
1068                 ccw++;
1069         }
1070         if ((fdata->intensity & ~0x08) & 0x04) {        /* erase track */
1071                 ect = (struct eckd_count *) data;
1072                 data += sizeof(struct eckd_count);
1073                 ect->cyl = cyl;
1074                 ect->head = head;
1075                 ect->record = 1;
1076                 ect->kl = 0;
1077                 ect->dl = 0;
1078                 ccw[-1].flags |= CCW_FLAG_CC;
1079                 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1080                 ccw->flags = CCW_FLAG_SLI;
1081                 ccw->count = 8;
1082                 ccw->cda = (__u32)(addr_t) ect;
1083         } else {                /* write remaining records */
1084                 for (i = 0; i < rpt; i++) {
1085                         ect = (struct eckd_count *) data;
1086                         data += sizeof(struct eckd_count);
1087                         ect->cyl = cyl;
1088                         ect->head = head;
1089                         ect->record = i + 1;
1090                         ect->kl = 0;
1091                         ect->dl = fdata->blksize;
1092                         /* Check for special tracks 0-1 when formatting CDL */
1093                         if ((fdata->intensity & 0x08) &&
1094                             fdata->start_unit == 0) {
1095                                 if (i < 3) {
1096                                         ect->kl = 4;
1097                                         ect->dl = sizes_trk0[i] - 4;
1098                                 }
1099                         }
1100                         if ((fdata->intensity & 0x08) &&
1101                             fdata->start_unit == 1) {
1102                                 ect->kl = 44;
1103                                 ect->dl = LABEL_SIZE - 44;
1104                         }
1105                         ccw[-1].flags |= CCW_FLAG_CC;
1106                         ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1107                         ccw->flags = CCW_FLAG_SLI;
1108                         ccw->count = 8;
1109                         ccw->cda = (__u32)(addr_t) ect;
1110                         ccw++;
1111                 }
1112         }
1113         fcp->device = device;
1114         fcp->retries = 2;       /* set retry counter to enable ERP */
1115         fcp->buildclk = get_clock();
1116         fcp->status = DASD_CQR_FILLED;
1117         return fcp;
1118 }
1119
1120 static dasd_era_t
1121 dasd_eckd_examine_error(struct dasd_ccw_req * cqr, struct irb * irb)
1122 {
1123         struct dasd_device *device = (struct dasd_device *) cqr->device;
1124         struct ccw_device *cdev = device->cdev;
1125
1126         if (irb->scsw.cstat == 0x00 &&
1127             irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END))
1128                 return dasd_era_none;
1129
1130         switch (cdev->id.cu_type) {
1131         case 0x3990:
1132         case 0x2105:
1133         case 0x2107:
1134         case 0x1750:
1135                 return dasd_3990_erp_examine(cqr, irb);
1136         case 0x9343:
1137                 return dasd_9343_erp_examine(cqr, irb);
1138         case 0x3880:
1139         default:
1140                 DEV_MESSAGE(KERN_WARNING, device, "%s",
1141                             "default (unknown CU type) - RECOVERABLE return");
1142                 return dasd_era_recover;
1143         }
1144 }
1145
1146 static dasd_erp_fn_t
1147 dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
1148 {
1149         struct dasd_device *device = (struct dasd_device *) cqr->device;
1150         struct ccw_device *cdev = device->cdev;
1151
1152         switch (cdev->id.cu_type) {
1153         case 0x3990:
1154         case 0x2105:
1155         case 0x2107:
1156         case 0x1750:
1157                 return dasd_3990_erp_action;
1158         case 0x9343:
1159         case 0x3880:
1160         default:
1161                 return dasd_default_erp_action;
1162         }
1163 }
1164
1165 static dasd_erp_fn_t
1166 dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
1167 {
1168         return dasd_default_erp_postaction;
1169 }
1170
1171 static struct dasd_ccw_req *
1172 dasd_eckd_build_cp(struct dasd_device * device, struct request *req)
1173 {
1174         struct dasd_eckd_private *private;
1175         unsigned long *idaws;
1176         struct LO_eckd_data *LO_data;
1177         struct dasd_ccw_req *cqr;
1178         struct ccw1 *ccw;
1179         struct bio *bio;
1180         struct bio_vec *bv;
1181         char *dst;
1182         unsigned int blksize, blk_per_trk, off;
1183         int count, cidaw, cplength, datasize;
1184         sector_t recid, first_rec, last_rec;
1185         sector_t first_trk, last_trk;
1186         unsigned int first_offs, last_offs;
1187         unsigned char cmd, rcmd;
1188         int i;
1189
1190         private = (struct dasd_eckd_private *) device->private;
1191         if (rq_data_dir(req) == READ)
1192                 cmd = DASD_ECKD_CCW_READ_MT;
1193         else if (rq_data_dir(req) == WRITE)
1194                 cmd = DASD_ECKD_CCW_WRITE_MT;
1195         else
1196                 return ERR_PTR(-EINVAL);
1197         /* Calculate number of blocks/records per track. */
1198         blksize = device->bp_block;
1199         blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
1200         /* Calculate record id of first and last block. */
1201         first_rec = first_trk = req->sector >> device->s2b_shift;
1202         first_offs = sector_div(first_trk, blk_per_trk);
1203         last_rec = last_trk =
1204                 (req->sector + req->nr_sectors - 1) >> device->s2b_shift;
1205         last_offs = sector_div(last_trk, blk_per_trk);
1206         /* Check struct bio and count the number of blocks for the request. */
1207         count = 0;
1208         cidaw = 0;
1209         rq_for_each_bio(bio, req) {
1210                 bio_for_each_segment(bv, bio, i) {
1211                         if (bv->bv_len & (blksize - 1))
1212                                 /* Eckd can only do full blocks. */
1213                                 return ERR_PTR(-EINVAL);
1214                         count += bv->bv_len >> (device->s2b_shift + 9);
1215 #if defined(CONFIG_64BIT)
1216                         if (idal_is_needed (page_address(bv->bv_page),
1217                                             bv->bv_len))
1218                                 cidaw += bv->bv_len >> (device->s2b_shift + 9);
1219 #endif
1220                 }
1221         }
1222         /* Paranoia. */
1223         if (count != last_rec - first_rec + 1)
1224                 return ERR_PTR(-EINVAL);
1225         /* 1x define extent + 1x locate record + number of blocks */
1226         cplength = 2 + count;
1227         /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
1228         datasize = sizeof(struct DE_eckd_data) + sizeof(struct LO_eckd_data) +
1229                 cidaw * sizeof(unsigned long);
1230         /* Find out the number of additional locate record ccws for cdl. */
1231         if (private->uses_cdl && first_rec < 2*blk_per_trk) {
1232                 if (last_rec >= 2*blk_per_trk)
1233                         count = 2*blk_per_trk - first_rec;
1234                 cplength += count;
1235                 datasize += count*sizeof(struct LO_eckd_data);
1236         }
1237         /* Allocate the ccw request. */
1238         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1239                                    cplength, datasize, device);
1240         if (IS_ERR(cqr))
1241                 return cqr;
1242         ccw = cqr->cpaddr;
1243         /* First ccw is define extent. */
1244         if (define_extent(ccw++, cqr->data, first_trk,
1245                           last_trk, cmd, device) == -EAGAIN) {
1246                 /* Clock not in sync and XRC is enabled. Try again later. */
1247                 dasd_sfree_request(cqr, device);
1248                 return ERR_PTR(-EAGAIN);
1249         }
1250         /* Build locate_record+read/write/ccws. */
1251         idaws = (unsigned long *) (cqr->data + sizeof(struct DE_eckd_data));
1252         LO_data = (struct LO_eckd_data *) (idaws + cidaw);
1253         recid = first_rec;
1254         if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
1255                 /* Only standard blocks so there is just one locate record. */
1256                 ccw[-1].flags |= CCW_FLAG_CC;
1257                 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
1258                               last_rec - recid + 1, cmd, device, blksize);
1259         }
1260         rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) {
1261                 dst = page_address(bv->bv_page) + bv->bv_offset;
1262                 if (dasd_page_cache) {
1263                         char *copy = kmem_cache_alloc(dasd_page_cache,
1264                                                       GFP_DMA | __GFP_NOWARN);
1265                         if (copy && rq_data_dir(req) == WRITE)
1266                                 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
1267                         if (copy)
1268                                 dst = copy + bv->bv_offset;
1269                 }
1270                 for (off = 0; off < bv->bv_len; off += blksize) {
1271                         sector_t trkid = recid;
1272                         unsigned int recoffs = sector_div(trkid, blk_per_trk);
1273                         rcmd = cmd;
1274                         count = blksize;
1275                         /* Locate record for cdl special block ? */
1276                         if (private->uses_cdl && recid < 2*blk_per_trk) {
1277                                 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
1278                                         rcmd |= 0x8;
1279                                         count = dasd_eckd_cdl_reclen(recid);
1280                                         if (count < blksize &&
1281                                             rq_data_dir(req) == READ)
1282                                                 memset(dst + count, 0xe5,
1283                                                        blksize - count);
1284                                 }
1285                                 ccw[-1].flags |= CCW_FLAG_CC;
1286                                 locate_record(ccw++, LO_data++,
1287                                               trkid, recoffs + 1,
1288                                               1, rcmd, device, count);
1289                         }
1290                         /* Locate record for standard blocks ? */
1291                         if (private->uses_cdl && recid == 2*blk_per_trk) {
1292                                 ccw[-1].flags |= CCW_FLAG_CC;
1293                                 locate_record(ccw++, LO_data++,
1294                                               trkid, recoffs + 1,
1295                                               last_rec - recid + 1,
1296                                               cmd, device, count);
1297                         }
1298                         /* Read/write ccw. */
1299                         ccw[-1].flags |= CCW_FLAG_CC;
1300                         ccw->cmd_code = rcmd;
1301                         ccw->count = count;
1302                         if (idal_is_needed(dst, blksize)) {
1303                                 ccw->cda = (__u32)(addr_t) idaws;
1304                                 ccw->flags = CCW_FLAG_IDA;
1305                                 idaws = idal_create_words(idaws, dst, blksize);
1306                         } else {
1307                                 ccw->cda = (__u32)(addr_t) dst;
1308                                 ccw->flags = 0;
1309                         }
1310                         ccw++;
1311                         dst += blksize;
1312                         recid++;
1313                 }
1314         }
1315         if (req->cmd_flags & REQ_FAILFAST)
1316                 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1317         cqr->device = device;
1318         cqr->expires = 5 * 60 * HZ;     /* 5 minutes */
1319         cqr->lpm = private->path_data.ppm;
1320         cqr->retries = 256;
1321         cqr->buildclk = get_clock();
1322         cqr->status = DASD_CQR_FILLED;
1323         return cqr;
1324 }
1325
1326 static int
1327 dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
1328 {
1329         struct dasd_eckd_private *private;
1330         struct ccw1 *ccw;
1331         struct bio *bio;
1332         struct bio_vec *bv;
1333         char *dst, *cda;
1334         unsigned int blksize, blk_per_trk, off;
1335         sector_t recid;
1336         int i, status;
1337
1338         if (!dasd_page_cache)
1339                 goto out;
1340         private = (struct dasd_eckd_private *) cqr->device->private;
1341         blksize = cqr->device->bp_block;
1342         blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
1343         recid = req->sector >> cqr->device->s2b_shift;
1344         ccw = cqr->cpaddr;
1345         /* Skip over define extent & locate record. */
1346         ccw++;
1347         if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
1348                 ccw++;
1349         rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) {
1350                 dst = page_address(bv->bv_page) + bv->bv_offset;
1351                 for (off = 0; off < bv->bv_len; off += blksize) {
1352                         /* Skip locate record. */
1353                         if (private->uses_cdl && recid <= 2*blk_per_trk)
1354                                 ccw++;
1355                         if (dst) {
1356                                 if (ccw->flags & CCW_FLAG_IDA)
1357                                         cda = *((char **)((addr_t) ccw->cda));
1358                                 else
1359                                         cda = (char *)((addr_t) ccw->cda);
1360                                 if (dst != cda) {
1361                                         if (rq_data_dir(req) == READ)
1362                                                 memcpy(dst, cda, bv->bv_len);
1363                                         kmem_cache_free(dasd_page_cache,
1364                                             (void *)((addr_t)cda & PAGE_MASK));
1365                                 }
1366                                 dst = NULL;
1367                         }
1368                         ccw++;
1369                         recid++;
1370                 }
1371         }
1372 out:
1373         status = cqr->status == DASD_CQR_DONE;
1374         dasd_sfree_request(cqr, cqr->device);
1375         return status;
1376 }
1377
1378 static int
1379 dasd_eckd_fill_info(struct dasd_device * device,
1380                     struct dasd_information2_t * info)
1381 {
1382         struct dasd_eckd_private *private;
1383
1384         private = (struct dasd_eckd_private *) device->private;
1385         info->label_block = 2;
1386         info->FBA_layout = private->uses_cdl ? 0 : 1;
1387         info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
1388         info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
1389         memcpy(info->characteristics, &private->rdc_data,
1390                sizeof(struct dasd_eckd_characteristics));
1391         info->confdata_size = sizeof (struct dasd_eckd_confdata);
1392         memcpy(info->configuration_data, &private->conf_data,
1393                sizeof (struct dasd_eckd_confdata));
1394         return 0;
1395 }
1396
1397 /*
1398  * SECTION: ioctl functions for eckd devices.
1399  */
1400
1401 /*
1402  * Release device ioctl.
1403  * Buils a channel programm to releases a prior reserved
1404  * (see dasd_eckd_reserve) device.
1405  */
1406 static int
1407 dasd_eckd_release(struct dasd_device *device)
1408 {
1409         struct dasd_ccw_req *cqr;
1410         int rc;
1411
1412         if (!capable(CAP_SYS_ADMIN))
1413                 return -EACCES;
1414
1415         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1416                                    1, 32, device);
1417         if (IS_ERR(cqr)) {
1418                 DEV_MESSAGE(KERN_WARNING, device, "%s",
1419                             "Could not allocate initialization request");
1420                 return PTR_ERR(cqr);
1421         }
1422         cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RELEASE;
1423         cqr->cpaddr->flags |= CCW_FLAG_SLI;
1424         cqr->cpaddr->count = 32;
1425         cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
1426         cqr->device = device;
1427         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1428         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1429         cqr->retries = 2;       /* set retry counter to enable basic ERP */
1430         cqr->expires = 2 * HZ;
1431         cqr->buildclk = get_clock();
1432         cqr->status = DASD_CQR_FILLED;
1433
1434         rc = dasd_sleep_on_immediatly(cqr);
1435
1436         dasd_sfree_request(cqr, cqr->device);
1437         return rc;
1438 }
1439
1440 /*
1441  * Reserve device ioctl.
1442  * Options are set to 'synchronous wait for interrupt' and
1443  * 'timeout the request'. This leads to a terminate IO if
1444  * the interrupt is outstanding for a certain time.
1445  */
1446 static int
1447 dasd_eckd_reserve(struct dasd_device *device)
1448 {
1449         struct dasd_ccw_req *cqr;
1450         int rc;
1451
1452         if (!capable(CAP_SYS_ADMIN))
1453                 return -EACCES;
1454
1455         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1456                                    1, 32, device);
1457         if (IS_ERR(cqr)) {
1458                 DEV_MESSAGE(KERN_WARNING, device, "%s",
1459                             "Could not allocate initialization request");
1460                 return PTR_ERR(cqr);
1461         }
1462         cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RESERVE;
1463         cqr->cpaddr->flags |= CCW_FLAG_SLI;
1464         cqr->cpaddr->count = 32;
1465         cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
1466         cqr->device = device;
1467         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1468         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1469         cqr->retries = 2;       /* set retry counter to enable basic ERP */
1470         cqr->expires = 2 * HZ;
1471         cqr->buildclk = get_clock();
1472         cqr->status = DASD_CQR_FILLED;
1473
1474         rc = dasd_sleep_on_immediatly(cqr);
1475
1476         dasd_sfree_request(cqr, cqr->device);
1477         return rc;
1478 }
1479
1480 /*
1481  * Steal lock ioctl - unconditional reserve device.
1482  * Buils a channel programm to break a device's reservation.
1483  * (unconditional reserve)
1484  */
1485 static int
1486 dasd_eckd_steal_lock(struct dasd_device *device)
1487 {
1488         struct dasd_ccw_req *cqr;
1489         int rc;
1490
1491         if (!capable(CAP_SYS_ADMIN))
1492                 return -EACCES;
1493
1494         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1495                                    1, 32, device);
1496         if (IS_ERR(cqr)) {
1497                 DEV_MESSAGE(KERN_WARNING, device, "%s",
1498                             "Could not allocate initialization request");
1499                 return PTR_ERR(cqr);
1500         }
1501         cqr->cpaddr->cmd_code = DASD_ECKD_CCW_SLCK;
1502         cqr->cpaddr->flags |= CCW_FLAG_SLI;
1503         cqr->cpaddr->count = 32;
1504         cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
1505         cqr->device = device;
1506         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1507         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1508         cqr->retries = 2;       /* set retry counter to enable basic ERP */
1509         cqr->expires = 2 * HZ;
1510         cqr->buildclk = get_clock();
1511         cqr->status = DASD_CQR_FILLED;
1512
1513         rc = dasd_sleep_on_immediatly(cqr);
1514
1515         dasd_sfree_request(cqr, cqr->device);
1516         return rc;
1517 }
1518
1519 /*
1520  * Read performance statistics
1521  */
1522 static int
1523 dasd_eckd_performance(struct dasd_device *device, void __user *argp)
1524 {
1525         struct dasd_psf_prssd_data *prssdp;
1526         struct dasd_rssd_perf_stats_t *stats;
1527         struct dasd_ccw_req *cqr;
1528         struct ccw1 *ccw;
1529         int rc;
1530
1531         cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1532                                    1 /* PSF */  + 1 /* RSSD */ ,
1533                                    (sizeof (struct dasd_psf_prssd_data) +
1534                                     sizeof (struct dasd_rssd_perf_stats_t)),
1535                                    device);
1536         if (IS_ERR(cqr)) {
1537                 DEV_MESSAGE(KERN_WARNING, device, "%s",
1538                             "Could not allocate initialization request");
1539                 return PTR_ERR(cqr);
1540         }
1541         cqr->device = device;
1542         cqr->retries = 0;
1543         cqr->expires = 10 * HZ;
1544
1545         /* Prepare for Read Subsystem Data */
1546         prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1547         memset(prssdp, 0, sizeof (struct dasd_psf_prssd_data));
1548         prssdp->order = PSF_ORDER_PRSSD;
1549         prssdp->suborder = 0x01;        /* Perfomance Statistics */
1550         prssdp->varies[1] = 0x01;       /* Perf Statistics for the Subsystem */
1551
1552         ccw = cqr->cpaddr;
1553         ccw->cmd_code = DASD_ECKD_CCW_PSF;
1554         ccw->count = sizeof (struct dasd_psf_prssd_data);
1555         ccw->flags |= CCW_FLAG_CC;
1556         ccw->cda = (__u32)(addr_t) prssdp;
1557
1558         /* Read Subsystem Data - Performance Statistics */
1559         stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
1560         memset(stats, 0, sizeof (struct dasd_rssd_perf_stats_t));
1561
1562         ccw++;
1563         ccw->cmd_code = DASD_ECKD_CCW_RSSD;
1564         ccw->count = sizeof (struct dasd_rssd_perf_stats_t);
1565         ccw->cda = (__u32)(addr_t) stats;
1566
1567         cqr->buildclk = get_clock();
1568         cqr->status = DASD_CQR_FILLED;
1569         rc = dasd_sleep_on(cqr);
1570         if (rc == 0) {
1571                 /* Prepare for Read Subsystem Data */
1572                 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1573                 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
1574                 if (copy_to_user(argp, stats,
1575                                  sizeof(struct dasd_rssd_perf_stats_t)))
1576                         rc = -EFAULT;
1577         }
1578         dasd_sfree_request(cqr, cqr->device);
1579         return rc;
1580 }
1581
1582 /*
1583  * Get attributes (cache operations)
1584  * Returnes the cache attributes used in Define Extend (DE).
1585  */
1586 static int
1587 dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
1588 {
1589         struct dasd_eckd_private *private =
1590                 (struct dasd_eckd_private *)device->private;
1591         struct attrib_data_t attrib = private->attrib;
1592         int rc;
1593
1594         if (!capable(CAP_SYS_ADMIN))
1595                 return -EACCES;
1596         if (!argp)
1597                 return -EINVAL;
1598
1599         rc = 0;
1600         if (copy_to_user(argp, (long *) &attrib,
1601                          sizeof (struct attrib_data_t)))
1602                 rc = -EFAULT;
1603
1604         return rc;
1605 }
1606
1607 /*
1608  * Set attributes (cache operations)
1609  * Stores the attributes for cache operation to be used in Define Extend (DE).
1610  */
1611 static int
1612 dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
1613 {
1614         struct dasd_eckd_private *private =
1615                 (struct dasd_eckd_private *)device->private;
1616         struct attrib_data_t attrib;
1617
1618         if (!capable(CAP_SYS_ADMIN))
1619                 return -EACCES;
1620         if (!argp)
1621                 return -EINVAL;
1622
1623         if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
1624                 return -EFAULT;
1625         private->attrib = attrib;
1626
1627         DEV_MESSAGE(KERN_INFO, device,
1628                     "cache operation mode set to %x (%i cylinder prestage)",
1629                     private->attrib.operation, private->attrib.nr_cyl);
1630         return 0;
1631 }
1632
1633 static int
1634 dasd_eckd_ioctl(struct dasd_device *device, unsigned int cmd, void __user *argp)
1635 {
1636         switch (cmd) {
1637         case BIODASDGATTR:
1638                 return dasd_eckd_get_attrib(device, argp);
1639         case BIODASDSATTR:
1640                 return dasd_eckd_set_attrib(device, argp);
1641         case BIODASDPSRD:
1642                 return dasd_eckd_performance(device, argp);
1643         case BIODASDRLSE:
1644                 return dasd_eckd_release(device);
1645         case BIODASDRSRV:
1646                 return dasd_eckd_reserve(device);
1647         case BIODASDSLCK:
1648                 return dasd_eckd_steal_lock(device);
1649         default:
1650                 return -ENOIOCTLCMD;
1651         }
1652 }
1653
1654 /*
1655  * Dump the range of CCWs into 'page' buffer
1656  * and return number of printed chars.
1657  */
1658 static int
1659 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
1660 {
1661         int len, count;
1662         char *datap;
1663
1664         len = 0;
1665         while (from <= to) {
1666                 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
1667                                " CCW %p: %08X %08X DAT:",
1668                                from, ((int *) from)[0], ((int *) from)[1]);
1669
1670                 /* get pointer to data (consider IDALs) */
1671                 if (from->flags & CCW_FLAG_IDA)
1672                         datap = (char *) *((addr_t *) (addr_t) from->cda);
1673                 else
1674                         datap = (char *) ((addr_t) from->cda);
1675
1676                 /* dump data (max 32 bytes) */
1677                 for (count = 0; count < from->count && count < 32; count++) {
1678                         if (count % 8 == 0) len += sprintf(page + len, " ");
1679                         if (count % 4 == 0) len += sprintf(page + len, " ");
1680                         len += sprintf(page + len, "%02x", datap[count]);
1681                 }
1682                 len += sprintf(page + len, "\n");
1683                 from++;
1684         }
1685         return len;
1686 }
1687
1688 /*
1689  * Print sense data and related channel program.
1690  * Parts are printed because printk buffer is only 1024 bytes.
1691  */
1692 static void
1693 dasd_eckd_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
1694                      struct irb *irb)
1695 {
1696         char *page;
1697         struct ccw1 *first, *last, *fail, *from, *to;
1698         int len, sl, sct;
1699
1700         page = (char *) get_zeroed_page(GFP_ATOMIC);
1701         if (page == NULL) {
1702                 DEV_MESSAGE(KERN_ERR, device, " %s",
1703                             "No memory to dump sense data");
1704                 return;
1705         }
1706         /* dump the sense data */
1707         len = sprintf(page,  KERN_ERR PRINTK_HEADER
1708                       " I/O status report for device %s:\n",
1709                       device->cdev->dev.bus_id);
1710         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
1711                        " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
1712                        irb->scsw.cstat, irb->scsw.dstat);
1713         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
1714                        " device %s: Failing CCW: %p\n",
1715                        device->cdev->dev.bus_id,
1716                        (void *) (addr_t) irb->scsw.cpa);
1717         if (irb->esw.esw0.erw.cons) {
1718                 for (sl = 0; sl < 4; sl++) {
1719                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
1720                                        " Sense(hex) %2d-%2d:",
1721                                        (8 * sl), ((8 * sl) + 7));
1722
1723                         for (sct = 0; sct < 8; sct++) {
1724                                 len += sprintf(page + len, " %02x",
1725                                                irb->ecw[8 * sl + sct]);
1726                         }
1727                         len += sprintf(page + len, "\n");
1728                 }
1729
1730                 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
1731                         /* 24 Byte Sense Data */
1732                         sprintf(page + len, KERN_ERR PRINTK_HEADER
1733                                 " 24 Byte: %x MSG %x, "
1734                                 "%s MSGb to SYSOP\n",
1735                                 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
1736                                 irb->ecw[1] & 0x10 ? "" : "no");
1737                 } else {
1738                         /* 32 Byte Sense Data */
1739                         sprintf(page + len, KERN_ERR PRINTK_HEADER
1740                                 " 32 Byte: Format: %x "
1741                                 "Exception class %x\n",
1742                                 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
1743                 }
1744         } else {
1745                 sprintf(page + len, KERN_ERR PRINTK_HEADER
1746                         " SORRY - NO VALID SENSE AVAILABLE\n");
1747         }
1748         printk("%s", page);
1749
1750         /* dump the Channel Program (max 140 Bytes per line) */
1751         /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
1752         first = req->cpaddr;
1753         for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
1754         to = min(first + 6, last);
1755         len = sprintf(page,  KERN_ERR PRINTK_HEADER
1756                       " Related CP in req: %p\n", req);
1757         dasd_eckd_dump_ccw_range(first, to, page + len);
1758         printk("%s", page);
1759
1760         /* print failing CCW area (maximum 4) */
1761         /* scsw->cda is either valid or zero  */
1762         len = 0;
1763         from = ++to;
1764         fail = (struct ccw1 *)(addr_t) irb->scsw.cpa; /* failing CCW */
1765         if (from <  fail - 2) {
1766                 from = fail - 2;     /* there is a gap - print header */
1767                 len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
1768         }
1769         to = min(fail + 1, last);
1770         len += dasd_eckd_dump_ccw_range(from, to, page + len);
1771
1772         /* print last CCWs (maximum 2) */
1773         from = max(from, ++to);
1774         if (from < last - 1) {
1775                 from = last - 1;     /* there is a gap - print header */
1776                 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
1777         }
1778         len += dasd_eckd_dump_ccw_range(from, last, page + len);
1779         if (len > 0)
1780                 printk("%s", page);
1781         free_page((unsigned long) page);
1782 }
1783
1784 /*
1785  * max_blocks is dependent on the amount of storage that is available
1786  * in the static io buffer for each device. Currently each device has
1787  * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
1788  * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
1789  * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
1790  * addition we have one define extent ccw + 16 bytes of data and one
1791  * locate record ccw + 16 bytes of data. That makes:
1792  * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
1793  * We want to fit two into the available memory so that we can immediately
1794  * start the next request if one finishes off. That makes 249.5 blocks
1795  * for one request. Give a little safety and the result is 240.
1796  */
1797 static struct dasd_discipline dasd_eckd_discipline = {
1798         .owner = THIS_MODULE,
1799         .name = "ECKD",
1800         .ebcname = "ECKD",
1801         .max_blocks = 240,
1802         .check_device = dasd_eckd_check_characteristics,
1803         .do_analysis = dasd_eckd_do_analysis,
1804         .fill_geometry = dasd_eckd_fill_geometry,
1805         .start_IO = dasd_start_IO,
1806         .term_IO = dasd_term_IO,
1807         .format_device = dasd_eckd_format_device,
1808         .examine_error = dasd_eckd_examine_error,
1809         .erp_action = dasd_eckd_erp_action,
1810         .erp_postaction = dasd_eckd_erp_postaction,
1811         .build_cp = dasd_eckd_build_cp,
1812         .free_cp = dasd_eckd_free_cp,
1813         .dump_sense = dasd_eckd_dump_sense,
1814         .fill_info = dasd_eckd_fill_info,
1815         .ioctl = dasd_eckd_ioctl,
1816 };
1817
1818 static int __init
1819 dasd_eckd_init(void)
1820 {
1821         ASCEBC(dasd_eckd_discipline.ebcname, 4);
1822         return ccw_driver_register(&dasd_eckd_driver);
1823 }
1824
1825 static void __exit
1826 dasd_eckd_cleanup(void)
1827 {
1828         ccw_driver_unregister(&dasd_eckd_driver);
1829 }
1830
1831 module_init(dasd_eckd_init);
1832 module_exit(dasd_eckd_cleanup);