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