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