]> git.openfabrics.org - ~shefty/rdma-dev.git/blob - drivers/s390/block/dasd_eckd.c
0483b2e76b11c787e0212000f884715aa388edf7
[~shefty/rdma-dev.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  * Copyright IBM Corp. 1999, 2009
9  * EMC Symmetrix ioctl Copyright EMC Corporation, 2008
10  * Author.........: Nigel Hislop <hislop_nigel@emc.com>
11  */
12
13 #define KMSG_COMPONENT "dasd-eckd"
14
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
18 #include <linux/hdreg.h>        /* HDIO_GETGEO                      */
19 #include <linux/bio.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
22
23 #include <asm/debug.h>
24 #include <asm/idals.h>
25 #include <asm/ebcdic.h>
26 #include <asm/compat.h>
27 #include <asm/io.h>
28 #include <asm/uaccess.h>
29 #include <asm/cio.h>
30 #include <asm/ccwdev.h>
31 #include <asm/itcw.h>
32
33 #include "dasd_int.h"
34 #include "dasd_eckd.h"
35 #include "../cio/chsc.h"
36
37
38 #ifdef PRINTK_HEADER
39 #undef PRINTK_HEADER
40 #endif                          /* PRINTK_HEADER */
41 #define PRINTK_HEADER "dasd(eckd):"
42
43 #define ECKD_C0(i) (i->home_bytes)
44 #define ECKD_F(i) (i->formula)
45 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
46                     (i->factors.f_0x02.f1))
47 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
48                     (i->factors.f_0x02.f2))
49 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
50                     (i->factors.f_0x02.f3))
51 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
52 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
53 #define ECKD_F6(i) (i->factor6)
54 #define ECKD_F7(i) (i->factor7)
55 #define ECKD_F8(i) (i->factor8)
56
57 MODULE_LICENSE("GPL");
58
59 static struct dasd_discipline dasd_eckd_discipline;
60
61 /* The ccw bus type uses this table to find devices that it sends to
62  * dasd_eckd_probe */
63 static struct ccw_device_id dasd_eckd_ids[] = {
64         { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
65         { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
66         { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), .driver_info = 0x3},
67         { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
68         { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
69         { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
70         { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
71         { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
72         { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
73         { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
74         { /* end of list */ },
75 };
76
77 MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
78
79 static struct ccw_driver dasd_eckd_driver; /* see below */
80
81 #define INIT_CQR_OK 0
82 #define INIT_CQR_UNFORMATTED 1
83 #define INIT_CQR_ERROR 2
84
85 /* emergency request for reserve/release */
86 static struct {
87         struct dasd_ccw_req cqr;
88         struct ccw1 ccw;
89         char data[32];
90 } *dasd_reserve_req;
91 static DEFINE_MUTEX(dasd_reserve_mutex);
92
93
94 /* initial attempt at a probe function. this can be simplified once
95  * the other detection code is gone */
96 static int
97 dasd_eckd_probe (struct ccw_device *cdev)
98 {
99         int ret;
100
101         /* set ECKD specific ccw-device options */
102         ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE |
103                                      CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH);
104         if (ret) {
105                 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
106                                 "dasd_eckd_probe: could not set "
107                                 "ccw-device options");
108                 return ret;
109         }
110         ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
111         return ret;
112 }
113
114 static int
115 dasd_eckd_set_online(struct ccw_device *cdev)
116 {
117         return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
118 }
119
120 static const int sizes_trk0[] = { 28, 148, 84 };
121 #define LABEL_SIZE 140
122
123 static inline unsigned int
124 round_up_multiple(unsigned int no, unsigned int mult)
125 {
126         int rem = no % mult;
127         return (rem ? no - rem + mult : no);
128 }
129
130 static inline unsigned int
131 ceil_quot(unsigned int d1, unsigned int d2)
132 {
133         return (d1 + (d2 - 1)) / d2;
134 }
135
136 static unsigned int
137 recs_per_track(struct dasd_eckd_characteristics * rdc,
138                unsigned int kl, unsigned int dl)
139 {
140         int dn, kn;
141
142         switch (rdc->dev_type) {
143         case 0x3380:
144                 if (kl)
145                         return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
146                                        ceil_quot(dl + 12, 32));
147                 else
148                         return 1499 / (15 + ceil_quot(dl + 12, 32));
149         case 0x3390:
150                 dn = ceil_quot(dl + 6, 232) + 1;
151                 if (kl) {
152                         kn = ceil_quot(kl + 6, 232) + 1;
153                         return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
154                                        9 + ceil_quot(dl + 6 * dn, 34));
155                 } else
156                         return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
157         case 0x9345:
158                 dn = ceil_quot(dl + 6, 232) + 1;
159                 if (kl) {
160                         kn = ceil_quot(kl + 6, 232) + 1;
161                         return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
162                                        ceil_quot(dl + 6 * dn, 34));
163                 } else
164                         return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
165         }
166         return 0;
167 }
168
169 static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
170 {
171         geo->cyl = (__u16) cyl;
172         geo->head = cyl >> 16;
173         geo->head <<= 4;
174         geo->head |= head;
175 }
176
177 static int
178 check_XRC (struct ccw1         *de_ccw,
179            struct DE_eckd_data *data,
180            struct dasd_device  *device)
181 {
182         struct dasd_eckd_private *private;
183         int rc;
184
185         private = (struct dasd_eckd_private *) device->private;
186         if (!private->rdc_data.facilities.XRC_supported)
187                 return 0;
188
189         /* switch on System Time Stamp - needed for XRC Support */
190         data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid'   */
191         data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
192
193         rc = get_sync_clock(&data->ep_sys_time);
194         /* Ignore return code if sync clock is switched off. */
195         if (rc == -ENOSYS || rc == -EACCES)
196                 rc = 0;
197
198         de_ccw->count = sizeof(struct DE_eckd_data);
199         de_ccw->flags |= CCW_FLAG_SLI;
200         return rc;
201 }
202
203 static int
204 define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
205               unsigned int totrk, int cmd, struct dasd_device *device)
206 {
207         struct dasd_eckd_private *private;
208         u32 begcyl, endcyl;
209         u16 heads, beghead, endhead;
210         int rc = 0;
211
212         private = (struct dasd_eckd_private *) device->private;
213
214         ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
215         ccw->flags = 0;
216         ccw->count = 16;
217         ccw->cda = (__u32) __pa(data);
218
219         memset(data, 0, sizeof(struct DE_eckd_data));
220         switch (cmd) {
221         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
222         case DASD_ECKD_CCW_READ_RECORD_ZERO:
223         case DASD_ECKD_CCW_READ:
224         case DASD_ECKD_CCW_READ_MT:
225         case DASD_ECKD_CCW_READ_CKD:
226         case DASD_ECKD_CCW_READ_CKD_MT:
227         case DASD_ECKD_CCW_READ_KD:
228         case DASD_ECKD_CCW_READ_KD_MT:
229         case DASD_ECKD_CCW_READ_COUNT:
230                 data->mask.perm = 0x1;
231                 data->attributes.operation = private->attrib.operation;
232                 break;
233         case DASD_ECKD_CCW_WRITE:
234         case DASD_ECKD_CCW_WRITE_MT:
235         case DASD_ECKD_CCW_WRITE_KD:
236         case DASD_ECKD_CCW_WRITE_KD_MT:
237                 data->mask.perm = 0x02;
238                 data->attributes.operation = private->attrib.operation;
239                 rc = check_XRC (ccw, data, device);
240                 break;
241         case DASD_ECKD_CCW_WRITE_CKD:
242         case DASD_ECKD_CCW_WRITE_CKD_MT:
243                 data->attributes.operation = DASD_BYPASS_CACHE;
244                 rc = check_XRC (ccw, data, device);
245                 break;
246         case DASD_ECKD_CCW_ERASE:
247         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
248         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
249                 data->mask.perm = 0x3;
250                 data->mask.auth = 0x1;
251                 data->attributes.operation = DASD_BYPASS_CACHE;
252                 rc = check_XRC (ccw, data, device);
253                 break;
254         default:
255                 dev_err(&device->cdev->dev,
256                         "0x%x is not a known command\n", cmd);
257                 break;
258         }
259
260         data->attributes.mode = 0x3;    /* ECKD */
261
262         if ((private->rdc_data.cu_type == 0x2105 ||
263              private->rdc_data.cu_type == 0x2107 ||
264              private->rdc_data.cu_type == 0x1750)
265             && !(private->uses_cdl && trk < 2))
266                 data->ga_extended |= 0x40; /* Regular Data Format Mode */
267
268         heads = private->rdc_data.trk_per_cyl;
269         begcyl = trk / heads;
270         beghead = trk % heads;
271         endcyl = totrk / heads;
272         endhead = totrk % heads;
273
274         /* check for sequential prestage - enhance cylinder range */
275         if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
276             data->attributes.operation == DASD_SEQ_ACCESS) {
277
278                 if (endcyl + private->attrib.nr_cyl < private->real_cyl)
279                         endcyl += private->attrib.nr_cyl;
280                 else
281                         endcyl = (private->real_cyl - 1);
282         }
283
284         set_ch_t(&data->beg_ext, begcyl, beghead);
285         set_ch_t(&data->end_ext, endcyl, endhead);
286         return rc;
287 }
288
289 static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
290                                struct dasd_device  *device)
291 {
292         struct dasd_eckd_private *private;
293         int rc;
294
295         private = (struct dasd_eckd_private *) device->private;
296         if (!private->rdc_data.facilities.XRC_supported)
297                 return 0;
298
299         /* switch on System Time Stamp - needed for XRC Support */
300         pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid'   */
301         pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */
302         pfxdata->validity.time_stamp = 1;           /* 'Time Stamp Valid'   */
303
304         rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time);
305         /* Ignore return code if sync clock is switched off. */
306         if (rc == -ENOSYS || rc == -EACCES)
307                 rc = 0;
308         return rc;
309 }
310
311 static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk,
312                           unsigned int rec_on_trk, int count, int cmd,
313                           struct dasd_device *device, unsigned int reclen,
314                           unsigned int tlf)
315 {
316         struct dasd_eckd_private *private;
317         int sector;
318         int dn, d;
319
320         private = (struct dasd_eckd_private *) device->private;
321
322         memset(data, 0, sizeof(*data));
323         sector = 0;
324         if (rec_on_trk) {
325                 switch (private->rdc_data.dev_type) {
326                 case 0x3390:
327                         dn = ceil_quot(reclen + 6, 232);
328                         d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
329                         sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
330                         break;
331                 case 0x3380:
332                         d = 7 + ceil_quot(reclen + 12, 32);
333                         sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
334                         break;
335                 }
336         }
337         data->sector = sector;
338         /* note: meaning of count depends on the operation
339          *       for record based I/O it's the number of records, but for
340          *       track based I/O it's the number of tracks
341          */
342         data->count = count;
343         switch (cmd) {
344         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
345                 data->operation.orientation = 0x3;
346                 data->operation.operation = 0x03;
347                 break;
348         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
349                 data->operation.orientation = 0x3;
350                 data->operation.operation = 0x16;
351                 break;
352         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
353                 data->operation.orientation = 0x1;
354                 data->operation.operation = 0x03;
355                 data->count++;
356                 break;
357         case DASD_ECKD_CCW_READ_RECORD_ZERO:
358                 data->operation.orientation = 0x3;
359                 data->operation.operation = 0x16;
360                 data->count++;
361                 break;
362         case DASD_ECKD_CCW_WRITE:
363         case DASD_ECKD_CCW_WRITE_MT:
364         case DASD_ECKD_CCW_WRITE_KD:
365         case DASD_ECKD_CCW_WRITE_KD_MT:
366                 data->auxiliary.length_valid = 0x1;
367                 data->length = reclen;
368                 data->operation.operation = 0x01;
369                 break;
370         case DASD_ECKD_CCW_WRITE_CKD:
371         case DASD_ECKD_CCW_WRITE_CKD_MT:
372                 data->auxiliary.length_valid = 0x1;
373                 data->length = reclen;
374                 data->operation.operation = 0x03;
375                 break;
376         case DASD_ECKD_CCW_WRITE_TRACK_DATA:
377                 data->auxiliary.length_valid = 0x1;
378                 data->length = reclen;  /* not tlf, as one might think */
379                 data->operation.operation = 0x3F;
380                 data->extended_operation = 0x23;
381                 break;
382         case DASD_ECKD_CCW_READ:
383         case DASD_ECKD_CCW_READ_MT:
384         case DASD_ECKD_CCW_READ_KD:
385         case DASD_ECKD_CCW_READ_KD_MT:
386                 data->auxiliary.length_valid = 0x1;
387                 data->length = reclen;
388                 data->operation.operation = 0x06;
389                 break;
390         case DASD_ECKD_CCW_READ_CKD:
391         case DASD_ECKD_CCW_READ_CKD_MT:
392                 data->auxiliary.length_valid = 0x1;
393                 data->length = reclen;
394                 data->operation.operation = 0x16;
395                 break;
396         case DASD_ECKD_CCW_READ_COUNT:
397                 data->operation.operation = 0x06;
398                 break;
399         case DASD_ECKD_CCW_READ_TRACK_DATA:
400                 data->auxiliary.length_valid = 0x1;
401                 data->length = tlf;
402                 data->operation.operation = 0x0C;
403                 break;
404         case DASD_ECKD_CCW_ERASE:
405                 data->length = reclen;
406                 data->auxiliary.length_valid = 0x1;
407                 data->operation.operation = 0x0b;
408                 break;
409         default:
410                 DBF_DEV_EVENT(DBF_ERR, device,
411                             "fill LRE unknown opcode 0x%x", cmd);
412                 BUG();
413         }
414         set_ch_t(&data->seek_addr,
415                  trk / private->rdc_data.trk_per_cyl,
416                  trk % private->rdc_data.trk_per_cyl);
417         data->search_arg.cyl = data->seek_addr.cyl;
418         data->search_arg.head = data->seek_addr.head;
419         data->search_arg.record = rec_on_trk;
420 }
421
422 static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
423                       unsigned int trk, unsigned int totrk, int cmd,
424                       struct dasd_device *basedev, struct dasd_device *startdev,
425                       unsigned char format, unsigned int rec_on_trk, int count,
426                       unsigned int blksize, unsigned int tlf)
427 {
428         struct dasd_eckd_private *basepriv, *startpriv;
429         struct DE_eckd_data *dedata;
430         struct LRE_eckd_data *lredata;
431         u32 begcyl, endcyl;
432         u16 heads, beghead, endhead;
433         int rc = 0;
434
435         basepriv = (struct dasd_eckd_private *) basedev->private;
436         startpriv = (struct dasd_eckd_private *) startdev->private;
437         dedata = &pfxdata->define_extent;
438         lredata = &pfxdata->locate_record;
439
440         ccw->cmd_code = DASD_ECKD_CCW_PFX;
441         ccw->flags = 0;
442         ccw->count = sizeof(*pfxdata);
443         ccw->cda = (__u32) __pa(pfxdata);
444
445         memset(pfxdata, 0, sizeof(*pfxdata));
446         /* prefix data */
447         if (format > 1) {
448                 DBF_DEV_EVENT(DBF_ERR, basedev,
449                               "PFX LRE unknown format 0x%x", format);
450                 BUG();
451                 return -EINVAL;
452         }
453         pfxdata->format = format;
454         pfxdata->base_address = basepriv->ned->unit_addr;
455         pfxdata->base_lss = basepriv->ned->ID;
456         pfxdata->validity.define_extent = 1;
457
458         /* private uid is kept up to date, conf_data may be outdated */
459         if (startpriv->uid.type != UA_BASE_DEVICE) {
460                 pfxdata->validity.verify_base = 1;
461                 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
462                         pfxdata->validity.hyper_pav = 1;
463         }
464
465         /* define extend data (mostly)*/
466         switch (cmd) {
467         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
468         case DASD_ECKD_CCW_READ_RECORD_ZERO:
469         case DASD_ECKD_CCW_READ:
470         case DASD_ECKD_CCW_READ_MT:
471         case DASD_ECKD_CCW_READ_CKD:
472         case DASD_ECKD_CCW_READ_CKD_MT:
473         case DASD_ECKD_CCW_READ_KD:
474         case DASD_ECKD_CCW_READ_KD_MT:
475         case DASD_ECKD_CCW_READ_COUNT:
476                 dedata->mask.perm = 0x1;
477                 dedata->attributes.operation = basepriv->attrib.operation;
478                 break;
479         case DASD_ECKD_CCW_READ_TRACK_DATA:
480                 dedata->mask.perm = 0x1;
481                 dedata->attributes.operation = basepriv->attrib.operation;
482                 dedata->blk_size = 0;
483                 break;
484         case DASD_ECKD_CCW_WRITE:
485         case DASD_ECKD_CCW_WRITE_MT:
486         case DASD_ECKD_CCW_WRITE_KD:
487         case DASD_ECKD_CCW_WRITE_KD_MT:
488                 dedata->mask.perm = 0x02;
489                 dedata->attributes.operation = basepriv->attrib.operation;
490                 rc = check_XRC_on_prefix(pfxdata, basedev);
491                 break;
492         case DASD_ECKD_CCW_WRITE_CKD:
493         case DASD_ECKD_CCW_WRITE_CKD_MT:
494                 dedata->attributes.operation = DASD_BYPASS_CACHE;
495                 rc = check_XRC_on_prefix(pfxdata, basedev);
496                 break;
497         case DASD_ECKD_CCW_ERASE:
498         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
499         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
500                 dedata->mask.perm = 0x3;
501                 dedata->mask.auth = 0x1;
502                 dedata->attributes.operation = DASD_BYPASS_CACHE;
503                 rc = check_XRC_on_prefix(pfxdata, basedev);
504                 break;
505         case DASD_ECKD_CCW_WRITE_TRACK_DATA:
506                 dedata->mask.perm = 0x02;
507                 dedata->attributes.operation = basepriv->attrib.operation;
508                 dedata->blk_size = blksize;
509                 rc = check_XRC_on_prefix(pfxdata, basedev);
510                 break;
511         default:
512                 DBF_DEV_EVENT(DBF_ERR, basedev,
513                             "PFX LRE unknown opcode 0x%x", cmd);
514                 BUG();
515                 return -EINVAL;
516         }
517
518         dedata->attributes.mode = 0x3;  /* ECKD */
519
520         if ((basepriv->rdc_data.cu_type == 0x2105 ||
521              basepriv->rdc_data.cu_type == 0x2107 ||
522              basepriv->rdc_data.cu_type == 0x1750)
523             && !(basepriv->uses_cdl && trk < 2))
524                 dedata->ga_extended |= 0x40; /* Regular Data Format Mode */
525
526         heads = basepriv->rdc_data.trk_per_cyl;
527         begcyl = trk / heads;
528         beghead = trk % heads;
529         endcyl = totrk / heads;
530         endhead = totrk % heads;
531
532         /* check for sequential prestage - enhance cylinder range */
533         if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
534             dedata->attributes.operation == DASD_SEQ_ACCESS) {
535
536                 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
537                         endcyl += basepriv->attrib.nr_cyl;
538                 else
539                         endcyl = (basepriv->real_cyl - 1);
540         }
541
542         set_ch_t(&dedata->beg_ext, begcyl, beghead);
543         set_ch_t(&dedata->end_ext, endcyl, endhead);
544
545         if (format == 1) {
546                 fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
547                               basedev, blksize, tlf);
548         }
549
550         return rc;
551 }
552
553 static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
554                   unsigned int trk, unsigned int totrk, int cmd,
555                   struct dasd_device *basedev, struct dasd_device *startdev)
556 {
557         return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
558                           0, 0, 0, 0, 0);
559 }
560
561 static void
562 locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
563               unsigned int rec_on_trk, int no_rec, int cmd,
564               struct dasd_device * device, int reclen)
565 {
566         struct dasd_eckd_private *private;
567         int sector;
568         int dn, d;
569
570         private = (struct dasd_eckd_private *) device->private;
571
572         DBF_DEV_EVENT(DBF_INFO, device,
573                   "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
574                   trk, rec_on_trk, no_rec, cmd, reclen);
575
576         ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
577         ccw->flags = 0;
578         ccw->count = 16;
579         ccw->cda = (__u32) __pa(data);
580
581         memset(data, 0, sizeof(struct LO_eckd_data));
582         sector = 0;
583         if (rec_on_trk) {
584                 switch (private->rdc_data.dev_type) {
585                 case 0x3390:
586                         dn = ceil_quot(reclen + 6, 232);
587                         d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
588                         sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
589                         break;
590                 case 0x3380:
591                         d = 7 + ceil_quot(reclen + 12, 32);
592                         sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
593                         break;
594                 }
595         }
596         data->sector = sector;
597         data->count = no_rec;
598         switch (cmd) {
599         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
600                 data->operation.orientation = 0x3;
601                 data->operation.operation = 0x03;
602                 break;
603         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
604                 data->operation.orientation = 0x3;
605                 data->operation.operation = 0x16;
606                 break;
607         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
608                 data->operation.orientation = 0x1;
609                 data->operation.operation = 0x03;
610                 data->count++;
611                 break;
612         case DASD_ECKD_CCW_READ_RECORD_ZERO:
613                 data->operation.orientation = 0x3;
614                 data->operation.operation = 0x16;
615                 data->count++;
616                 break;
617         case DASD_ECKD_CCW_WRITE:
618         case DASD_ECKD_CCW_WRITE_MT:
619         case DASD_ECKD_CCW_WRITE_KD:
620         case DASD_ECKD_CCW_WRITE_KD_MT:
621                 data->auxiliary.last_bytes_used = 0x1;
622                 data->length = reclen;
623                 data->operation.operation = 0x01;
624                 break;
625         case DASD_ECKD_CCW_WRITE_CKD:
626         case DASD_ECKD_CCW_WRITE_CKD_MT:
627                 data->auxiliary.last_bytes_used = 0x1;
628                 data->length = reclen;
629                 data->operation.operation = 0x03;
630                 break;
631         case DASD_ECKD_CCW_READ:
632         case DASD_ECKD_CCW_READ_MT:
633         case DASD_ECKD_CCW_READ_KD:
634         case DASD_ECKD_CCW_READ_KD_MT:
635                 data->auxiliary.last_bytes_used = 0x1;
636                 data->length = reclen;
637                 data->operation.operation = 0x06;
638                 break;
639         case DASD_ECKD_CCW_READ_CKD:
640         case DASD_ECKD_CCW_READ_CKD_MT:
641                 data->auxiliary.last_bytes_used = 0x1;
642                 data->length = reclen;
643                 data->operation.operation = 0x16;
644                 break;
645         case DASD_ECKD_CCW_READ_COUNT:
646                 data->operation.operation = 0x06;
647                 break;
648         case DASD_ECKD_CCW_ERASE:
649                 data->length = reclen;
650                 data->auxiliary.last_bytes_used = 0x1;
651                 data->operation.operation = 0x0b;
652                 break;
653         default:
654                 DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
655                               "opcode 0x%x", cmd);
656         }
657         set_ch_t(&data->seek_addr,
658                  trk / private->rdc_data.trk_per_cyl,
659                  trk % private->rdc_data.trk_per_cyl);
660         data->search_arg.cyl = data->seek_addr.cyl;
661         data->search_arg.head = data->seek_addr.head;
662         data->search_arg.record = rec_on_trk;
663 }
664
665 /*
666  * Returns 1 if the block is one of the special blocks that needs
667  * to get read/written with the KD variant of the command.
668  * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
669  * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
670  * Luckily the KD variants differ only by one bit (0x08) from the
671  * normal variant. So don't wonder about code like:
672  * if (dasd_eckd_cdl_special(blk_per_trk, recid))
673  *         ccw->cmd_code |= 0x8;
674  */
675 static inline int
676 dasd_eckd_cdl_special(int blk_per_trk, int recid)
677 {
678         if (recid < 3)
679                 return 1;
680         if (recid < blk_per_trk)
681                 return 0;
682         if (recid < 2 * blk_per_trk)
683                 return 1;
684         return 0;
685 }
686
687 /*
688  * Returns the record size for the special blocks of the cdl format.
689  * Only returns something useful if dasd_eckd_cdl_special is true
690  * for the recid.
691  */
692 static inline int
693 dasd_eckd_cdl_reclen(int recid)
694 {
695         if (recid < 3)
696                 return sizes_trk0[recid];
697         return LABEL_SIZE;
698 }
699
700 /*
701  * Generate device unique id that specifies the physical device.
702  */
703 static int dasd_eckd_generate_uid(struct dasd_device *device)
704 {
705         struct dasd_eckd_private *private;
706         struct dasd_uid *uid;
707         int count;
708         unsigned long flags;
709
710         private = (struct dasd_eckd_private *) device->private;
711         if (!private)
712                 return -ENODEV;
713         if (!private->ned || !private->gneq)
714                 return -ENODEV;
715         uid = &private->uid;
716         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
717         memset(uid, 0, sizeof(struct dasd_uid));
718         memcpy(uid->vendor, private->ned->HDA_manufacturer,
719                sizeof(uid->vendor) - 1);
720         EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
721         memcpy(uid->serial, private->ned->HDA_location,
722                sizeof(uid->serial) - 1);
723         EBCASC(uid->serial, sizeof(uid->serial) - 1);
724         uid->ssid = private->gneq->subsystemID;
725         uid->real_unit_addr = private->ned->unit_addr;
726         if (private->sneq) {
727                 uid->type = private->sneq->sua_flags;
728                 if (uid->type == UA_BASE_PAV_ALIAS)
729                         uid->base_unit_addr = private->sneq->base_unit_addr;
730         } else {
731                 uid->type = UA_BASE_DEVICE;
732         }
733         if (private->vdsneq) {
734                 for (count = 0; count < 16; count++) {
735                         sprintf(uid->vduit+2*count, "%02x",
736                                 private->vdsneq->uit[count]);
737                 }
738         }
739         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
740         return 0;
741 }
742
743 static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
744 {
745         struct dasd_eckd_private *private;
746         unsigned long flags;
747
748         if (device->private) {
749                 private = (struct dasd_eckd_private *)device->private;
750                 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
751                 *uid = private->uid;
752                 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
753                 return 0;
754         }
755         return -EINVAL;
756 }
757
758 static struct dasd_ccw_req *dasd_eckd_build_rcd_lpm(struct dasd_device *device,
759                                                     void *rcd_buffer,
760                                                     struct ciw *ciw, __u8 lpm)
761 {
762         struct dasd_ccw_req *cqr;
763         struct ccw1 *ccw;
764
765         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */, ciw->count,
766                                    device);
767
768         if (IS_ERR(cqr)) {
769                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
770                               "Could not allocate RCD request");
771                 return cqr;
772         }
773
774         ccw = cqr->cpaddr;
775         ccw->cmd_code = ciw->cmd;
776         ccw->cda = (__u32)(addr_t)rcd_buffer;
777         ccw->count = ciw->count;
778
779         cqr->startdev = device;
780         cqr->memdev = device;
781         cqr->block = NULL;
782         cqr->expires = 10*HZ;
783         cqr->lpm = lpm;
784         cqr->retries = 256;
785         cqr->buildclk = get_clock();
786         cqr->status = DASD_CQR_FILLED;
787         return cqr;
788 }
789
790 static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
791                                    void **rcd_buffer,
792                                    int *rcd_buffer_size, __u8 lpm)
793 {
794         struct ciw *ciw;
795         char *rcd_buf = NULL;
796         int ret;
797         struct dasd_ccw_req *cqr;
798
799         /*
800          * scan for RCD command in extended SenseID data
801          */
802         ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
803         if (!ciw || ciw->cmd == 0) {
804                 ret = -EOPNOTSUPP;
805                 goto out_error;
806         }
807         rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
808         if (!rcd_buf) {
809                 ret = -ENOMEM;
810                 goto out_error;
811         }
812
813         /*
814          * buffer has to start with EBCDIC "V1.0" to show
815          * support for virtual device SNEQ
816          */
817         rcd_buf[0] = 0xE5;
818         rcd_buf[1] = 0xF1;
819         rcd_buf[2] = 0x4B;
820         rcd_buf[3] = 0xF0;
821         cqr = dasd_eckd_build_rcd_lpm(device, rcd_buf, ciw, lpm);
822         if (IS_ERR(cqr)) {
823                 ret =  PTR_ERR(cqr);
824                 goto out_error;
825         }
826         ret = dasd_sleep_on(cqr);
827         /*
828          * on success we update the user input parms
829          */
830         dasd_sfree_request(cqr, cqr->memdev);
831         if (ret)
832                 goto out_error;
833
834         *rcd_buffer_size = ciw->count;
835         *rcd_buffer = rcd_buf;
836         return 0;
837 out_error:
838         kfree(rcd_buf);
839         *rcd_buffer = NULL;
840         *rcd_buffer_size = 0;
841         return ret;
842 }
843
844 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
845 {
846
847         struct dasd_sneq *sneq;
848         int i, count;
849
850         private->ned = NULL;
851         private->sneq = NULL;
852         private->vdsneq = NULL;
853         private->gneq = NULL;
854         count = private->conf_len / sizeof(struct dasd_sneq);
855         sneq = (struct dasd_sneq *)private->conf_data;
856         for (i = 0; i < count; ++i) {
857                 if (sneq->flags.identifier == 1 && sneq->format == 1)
858                         private->sneq = sneq;
859                 else if (sneq->flags.identifier == 1 && sneq->format == 4)
860                         private->vdsneq = (struct vd_sneq *)sneq;
861                 else if (sneq->flags.identifier == 2)
862                         private->gneq = (struct dasd_gneq *)sneq;
863                 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
864                         private->ned = (struct dasd_ned *)sneq;
865                 sneq++;
866         }
867         if (!private->ned || !private->gneq) {
868                 private->ned = NULL;
869                 private->sneq = NULL;
870                 private->vdsneq = NULL;
871                 private->gneq = NULL;
872                 return -EINVAL;
873         }
874         return 0;
875
876 };
877
878 static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
879 {
880         struct dasd_gneq *gneq;
881         int i, count, found;
882
883         count = conf_len / sizeof(*gneq);
884         gneq = (struct dasd_gneq *)conf_data;
885         found = 0;
886         for (i = 0; i < count; ++i) {
887                 if (gneq->flags.identifier == 2) {
888                         found = 1;
889                         break;
890                 }
891                 gneq++;
892         }
893         if (found)
894                 return ((char *)gneq)[18] & 0x07;
895         else
896                 return 0;
897 }
898
899 static int dasd_eckd_read_conf(struct dasd_device *device)
900 {
901         void *conf_data;
902         int conf_len, conf_data_saved;
903         int rc;
904         __u8 lpm;
905         struct dasd_eckd_private *private;
906         struct dasd_eckd_path *path_data;
907
908         private = (struct dasd_eckd_private *) device->private;
909         path_data = (struct dasd_eckd_path *) &private->path_data;
910         path_data->opm = ccw_device_get_path_mask(device->cdev);
911         lpm = 0x80;
912         conf_data_saved = 0;
913         /* get configuration data per operational path */
914         for (lpm = 0x80; lpm; lpm>>= 1) {
915                 if (lpm & path_data->opm){
916                         rc = dasd_eckd_read_conf_lpm(device, &conf_data,
917                                                      &conf_len, lpm);
918                         if (rc && rc != -EOPNOTSUPP) {  /* -EOPNOTSUPP is ok */
919                                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
920                                           "Read configuration data returned "
921                                           "error %d", rc);
922                                 return rc;
923                         }
924                         if (conf_data == NULL) {
925                                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
926                                                 "No configuration data "
927                                                 "retrieved");
928                                 continue;       /* no error */
929                         }
930                         /* save first valid configuration data */
931                         if (!conf_data_saved) {
932                                 kfree(private->conf_data);
933                                 private->conf_data = conf_data;
934                                 private->conf_len = conf_len;
935                                 if (dasd_eckd_identify_conf_parts(private)) {
936                                         private->conf_data = NULL;
937                                         private->conf_len = 0;
938                                         kfree(conf_data);
939                                         continue;
940                                 }
941                                 conf_data_saved++;
942                         }
943                         switch (dasd_eckd_path_access(conf_data, conf_len)) {
944                         case 0x02:
945                                 path_data->npm |= lpm;
946                                 break;
947                         case 0x03:
948                                 path_data->ppm |= lpm;
949                                 break;
950                         }
951                         if (conf_data != private->conf_data)
952                                 kfree(conf_data);
953                 }
954         }
955         return 0;
956 }
957
958 static int dasd_eckd_read_features(struct dasd_device *device)
959 {
960         struct dasd_psf_prssd_data *prssdp;
961         struct dasd_rssd_features *features;
962         struct dasd_ccw_req *cqr;
963         struct ccw1 *ccw;
964         int rc;
965         struct dasd_eckd_private *private;
966
967         private = (struct dasd_eckd_private *) device->private;
968         memset(&private->features, 0, sizeof(struct dasd_rssd_features));
969         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
970                                    (sizeof(struct dasd_psf_prssd_data) +
971                                     sizeof(struct dasd_rssd_features)),
972                                    device);
973         if (IS_ERR(cqr)) {
974                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not "
975                                 "allocate initialization request");
976                 return PTR_ERR(cqr);
977         }
978         cqr->startdev = device;
979         cqr->memdev = device;
980         cqr->block = NULL;
981         cqr->retries = 256;
982         cqr->expires = 10 * HZ;
983
984         /* Prepare for Read Subsystem Data */
985         prssdp = (struct dasd_psf_prssd_data *) cqr->data;
986         memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
987         prssdp->order = PSF_ORDER_PRSSD;
988         prssdp->suborder = 0x41;        /* Read Feature Codes */
989         /* all other bytes of prssdp must be zero */
990
991         ccw = cqr->cpaddr;
992         ccw->cmd_code = DASD_ECKD_CCW_PSF;
993         ccw->count = sizeof(struct dasd_psf_prssd_data);
994         ccw->flags |= CCW_FLAG_CC;
995         ccw->cda = (__u32)(addr_t) prssdp;
996
997         /* Read Subsystem Data - feature codes */
998         features = (struct dasd_rssd_features *) (prssdp + 1);
999         memset(features, 0, sizeof(struct dasd_rssd_features));
1000
1001         ccw++;
1002         ccw->cmd_code = DASD_ECKD_CCW_RSSD;
1003         ccw->count = sizeof(struct dasd_rssd_features);
1004         ccw->cda = (__u32)(addr_t) features;
1005
1006         cqr->buildclk = get_clock();
1007         cqr->status = DASD_CQR_FILLED;
1008         rc = dasd_sleep_on(cqr);
1009         if (rc == 0) {
1010                 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1011                 features = (struct dasd_rssd_features *) (prssdp + 1);
1012                 memcpy(&private->features, features,
1013                        sizeof(struct dasd_rssd_features));
1014         } else
1015                 dev_warn(&device->cdev->dev, "Reading device feature codes"
1016                          " failed with rc=%d\n", rc);
1017         dasd_sfree_request(cqr, cqr->memdev);
1018         return rc;
1019 }
1020
1021
1022 /*
1023  * Build CP for Perform Subsystem Function - SSC.
1024  */
1025 static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
1026                                                     int enable_pav)
1027 {
1028         struct dasd_ccw_req *cqr;
1029         struct dasd_psf_ssc_data *psf_ssc_data;
1030         struct ccw1 *ccw;
1031
1032         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
1033                                   sizeof(struct dasd_psf_ssc_data),
1034                                   device);
1035
1036         if (IS_ERR(cqr)) {
1037                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1038                            "Could not allocate PSF-SSC request");
1039                 return cqr;
1040         }
1041         psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1042         psf_ssc_data->order = PSF_ORDER_SSC;
1043         psf_ssc_data->suborder = 0xc0;
1044         if (enable_pav) {
1045                 psf_ssc_data->suborder |= 0x08;
1046                 psf_ssc_data->reserved[0] = 0x88;
1047         }
1048         ccw = cqr->cpaddr;
1049         ccw->cmd_code = DASD_ECKD_CCW_PSF;
1050         ccw->cda = (__u32)(addr_t)psf_ssc_data;
1051         ccw->count = 66;
1052
1053         cqr->startdev = device;
1054         cqr->memdev = device;
1055         cqr->block = NULL;
1056         cqr->retries = 256;
1057         cqr->expires = 10*HZ;
1058         cqr->buildclk = get_clock();
1059         cqr->status = DASD_CQR_FILLED;
1060         return cqr;
1061 }
1062
1063 /*
1064  * Perform Subsystem Function.
1065  * It is necessary to trigger CIO for channel revalidation since this
1066  * call might change behaviour of DASD devices.
1067  */
1068 static int
1069 dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav)
1070 {
1071         struct dasd_ccw_req *cqr;
1072         int rc;
1073
1074         cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
1075         if (IS_ERR(cqr))
1076                 return PTR_ERR(cqr);
1077
1078         rc = dasd_sleep_on(cqr);
1079         if (!rc)
1080                 /* trigger CIO to reprobe devices */
1081                 css_schedule_reprobe();
1082         dasd_sfree_request(cqr, cqr->memdev);
1083         return rc;
1084 }
1085
1086 /*
1087  * Valide storage server of current device.
1088  */
1089 static void dasd_eckd_validate_server(struct dasd_device *device)
1090 {
1091         int rc;
1092         struct dasd_eckd_private *private;
1093         int enable_pav;
1094
1095         if (dasd_nopav || MACHINE_IS_VM)
1096                 enable_pav = 0;
1097         else
1098                 enable_pav = 1;
1099         rc = dasd_eckd_psf_ssc(device, enable_pav);
1100
1101         /* may be requested feature is not available on server,
1102          * therefore just report error and go ahead */
1103         private = (struct dasd_eckd_private *) device->private;
1104         DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
1105                         "returned rc=%d", private->uid.ssid, rc);
1106 }
1107
1108 /*
1109  * Check device characteristics.
1110  * If the device is accessible using ECKD discipline, the device is enabled.
1111  */
1112 static int
1113 dasd_eckd_check_characteristics(struct dasd_device *device)
1114 {
1115         struct dasd_eckd_private *private;
1116         struct dasd_block *block;
1117         struct dasd_uid temp_uid;
1118         int is_known, rc;
1119         int readonly;
1120
1121         if (!ccw_device_is_pathgroup(device->cdev)) {
1122                 dev_warn(&device->cdev->dev,
1123                          "A channel path group could not be established\n");
1124                 return -EIO;
1125         }
1126         if (!ccw_device_is_multipath(device->cdev)) {
1127                 dev_info(&device->cdev->dev,
1128                          "The DASD is not operating in multipath mode\n");
1129         }
1130         private = (struct dasd_eckd_private *) device->private;
1131         if (!private) {
1132                 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
1133                 if (!private) {
1134                         dev_warn(&device->cdev->dev,
1135                                  "Allocating memory for private DASD data "
1136                                  "failed\n");
1137                         return -ENOMEM;
1138                 }
1139                 device->private = (void *) private;
1140         } else {
1141                 memset(private, 0, sizeof(*private));
1142         }
1143         /* Invalidate status of initial analysis. */
1144         private->init_cqr_status = -1;
1145         /* Set default cache operations. */
1146         private->attrib.operation = DASD_NORMAL_CACHE;
1147         private->attrib.nr_cyl = 0;
1148
1149         /* Read Configuration Data */
1150         rc = dasd_eckd_read_conf(device);
1151         if (rc)
1152                 goto out_err1;
1153
1154         /* Generate device unique id */
1155         rc = dasd_eckd_generate_uid(device);
1156         if (rc)
1157                 goto out_err1;
1158
1159         dasd_eckd_get_uid(device, &temp_uid);
1160         if (temp_uid.type == UA_BASE_DEVICE) {
1161                 block = dasd_alloc_block();
1162                 if (IS_ERR(block)) {
1163                         DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1164                                         "could not allocate dasd "
1165                                         "block structure");
1166                         rc = PTR_ERR(block);
1167                         goto out_err1;
1168                 }
1169                 device->block = block;
1170                 block->base = device;
1171         }
1172
1173         /* register lcu with alias handling, enable PAV if this is a new lcu */
1174         is_known = dasd_alias_make_device_known_to_lcu(device);
1175         if (is_known < 0) {
1176                 rc = is_known;
1177                 goto out_err2;
1178         }
1179         /*
1180          * dasd_eckd_vaildate_server is done on the first device that
1181          * is found for an LCU. All later other devices have to wait
1182          * for it, so they will read the correct feature codes.
1183          */
1184         if (!is_known) {
1185                 dasd_eckd_validate_server(device);
1186                 dasd_alias_lcu_setup_complete(device);
1187         } else
1188                 dasd_alias_wait_for_lcu_setup(device);
1189
1190         /* device may report different configuration data after LCU setup */
1191         rc = dasd_eckd_read_conf(device);
1192         if (rc)
1193                 goto out_err3;
1194
1195         /* Read Feature Codes */
1196         dasd_eckd_read_features(device);
1197
1198         /* Read Device Characteristics */
1199         rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
1200                                          &private->rdc_data, 64);
1201         if (rc) {
1202                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1203                                 "Read device characteristic failed, rc=%d", rc);
1204                 goto out_err3;
1205         }
1206         /* find the vaild cylinder size */
1207         if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1208             private->rdc_data.long_no_cyl)
1209                 private->real_cyl = private->rdc_data.long_no_cyl;
1210         else
1211                 private->real_cyl = private->rdc_data.no_cyl;
1212
1213         readonly = dasd_device_is_ro(device);
1214         if (readonly)
1215                 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1216
1217         dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
1218                  "with %d cylinders, %d heads, %d sectors%s\n",
1219                  private->rdc_data.dev_type,
1220                  private->rdc_data.dev_model,
1221                  private->rdc_data.cu_type,
1222                  private->rdc_data.cu_model.model,
1223                  private->real_cyl,
1224                  private->rdc_data.trk_per_cyl,
1225                  private->rdc_data.sec_per_trk,
1226                  readonly ? ", read-only device" : "");
1227         return 0;
1228
1229 out_err3:
1230         dasd_alias_disconnect_device_from_lcu(device);
1231 out_err2:
1232         dasd_free_block(device->block);
1233         device->block = NULL;
1234 out_err1:
1235         kfree(private->conf_data);
1236         kfree(device->private);
1237         device->private = NULL;
1238         return rc;
1239 }
1240
1241 static void dasd_eckd_uncheck_device(struct dasd_device *device)
1242 {
1243         struct dasd_eckd_private *private;
1244
1245         private = (struct dasd_eckd_private *) device->private;
1246         dasd_alias_disconnect_device_from_lcu(device);
1247         private->ned = NULL;
1248         private->sneq = NULL;
1249         private->vdsneq = NULL;
1250         private->gneq = NULL;
1251         private->conf_len = 0;
1252         kfree(private->conf_data);
1253         private->conf_data = NULL;
1254 }
1255
1256 static struct dasd_ccw_req *
1257 dasd_eckd_analysis_ccw(struct dasd_device *device)
1258 {
1259         struct dasd_eckd_private *private;
1260         struct eckd_count *count_data;
1261         struct LO_eckd_data *LO_data;
1262         struct dasd_ccw_req *cqr;
1263         struct ccw1 *ccw;
1264         int cplength, datasize;
1265         int i;
1266
1267         private = (struct dasd_eckd_private *) device->private;
1268
1269         cplength = 8;
1270         datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
1271         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1272         if (IS_ERR(cqr))
1273                 return cqr;
1274         ccw = cqr->cpaddr;
1275         /* Define extent for the first 3 tracks. */
1276         define_extent(ccw++, cqr->data, 0, 2,
1277                       DASD_ECKD_CCW_READ_COUNT, device);
1278         LO_data = cqr->data + sizeof(struct DE_eckd_data);
1279         /* Locate record for the first 4 records on track 0. */
1280         ccw[-1].flags |= CCW_FLAG_CC;
1281         locate_record(ccw++, LO_data++, 0, 0, 4,
1282                       DASD_ECKD_CCW_READ_COUNT, device, 0);
1283
1284         count_data = private->count_area;
1285         for (i = 0; i < 4; i++) {
1286                 ccw[-1].flags |= CCW_FLAG_CC;
1287                 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1288                 ccw->flags = 0;
1289                 ccw->count = 8;
1290                 ccw->cda = (__u32)(addr_t) count_data;
1291                 ccw++;
1292                 count_data++;
1293         }
1294
1295         /* Locate record for the first record on track 2. */
1296         ccw[-1].flags |= CCW_FLAG_CC;
1297         locate_record(ccw++, LO_data++, 2, 0, 1,
1298                       DASD_ECKD_CCW_READ_COUNT, device, 0);
1299         /* Read count ccw. */
1300         ccw[-1].flags |= CCW_FLAG_CC;
1301         ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1302         ccw->flags = 0;
1303         ccw->count = 8;
1304         ccw->cda = (__u32)(addr_t) count_data;
1305
1306         cqr->block = NULL;
1307         cqr->startdev = device;
1308         cqr->memdev = device;
1309         cqr->retries = 255;
1310         cqr->buildclk = get_clock();
1311         cqr->status = DASD_CQR_FILLED;
1312         return cqr;
1313 }
1314
1315 /* differentiate between 'no record found' and any other error */
1316 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
1317 {
1318         char *sense;
1319         if (init_cqr->status == DASD_CQR_DONE)
1320                 return INIT_CQR_OK;
1321         else if (init_cqr->status == DASD_CQR_NEED_ERP ||
1322                  init_cqr->status == DASD_CQR_FAILED) {
1323                 sense = dasd_get_sense(&init_cqr->irb);
1324                 if (sense && (sense[1] & SNS1_NO_REC_FOUND))
1325                         return INIT_CQR_UNFORMATTED;
1326                 else
1327                         return INIT_CQR_ERROR;
1328         } else
1329                 return INIT_CQR_ERROR;
1330 }
1331
1332 /*
1333  * This is the callback function for the init_analysis cqr. It saves
1334  * the status of the initial analysis ccw before it frees it and kicks
1335  * the device to continue the startup sequence. This will call
1336  * dasd_eckd_do_analysis again (if the devices has not been marked
1337  * for deletion in the meantime).
1338  */
1339 static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
1340                                         void *data)
1341 {
1342         struct dasd_eckd_private *private;
1343         struct dasd_device *device;
1344
1345         device = init_cqr->startdev;
1346         private = (struct dasd_eckd_private *) device->private;
1347         private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
1348         dasd_sfree_request(init_cqr, device);
1349         dasd_kick_device(device);
1350 }
1351
1352 static int dasd_eckd_start_analysis(struct dasd_block *block)
1353 {
1354         struct dasd_eckd_private *private;
1355         struct dasd_ccw_req *init_cqr;
1356
1357         private = (struct dasd_eckd_private *) block->base->private;
1358         init_cqr = dasd_eckd_analysis_ccw(block->base);
1359         if (IS_ERR(init_cqr))
1360                 return PTR_ERR(init_cqr);
1361         init_cqr->callback = dasd_eckd_analysis_callback;
1362         init_cqr->callback_data = NULL;
1363         init_cqr->expires = 5*HZ;
1364         /* first try without ERP, so we can later handle unformatted
1365          * devices as special case
1366          */
1367         clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
1368         init_cqr->retries = 0;
1369         dasd_add_request_head(init_cqr);
1370         return -EAGAIN;
1371 }
1372
1373 static int dasd_eckd_end_analysis(struct dasd_block *block)
1374 {
1375         struct dasd_device *device;
1376         struct dasd_eckd_private *private;
1377         struct eckd_count *count_area;
1378         unsigned int sb, blk_per_trk;
1379         int status, i;
1380         struct dasd_ccw_req *init_cqr;
1381
1382         device = block->base;
1383         private = (struct dasd_eckd_private *) device->private;
1384         status = private->init_cqr_status;
1385         private->init_cqr_status = -1;
1386         if (status == INIT_CQR_ERROR) {
1387                 /* try again, this time with full ERP */
1388                 init_cqr = dasd_eckd_analysis_ccw(device);
1389                 dasd_sleep_on(init_cqr);
1390                 status = dasd_eckd_analysis_evaluation(init_cqr);
1391                 dasd_sfree_request(init_cqr, device);
1392         }
1393
1394         if (status == INIT_CQR_UNFORMATTED) {
1395                 dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
1396                 return -EMEDIUMTYPE;
1397         } else if (status == INIT_CQR_ERROR) {
1398                 dev_err(&device->cdev->dev,
1399                         "Detecting the DASD disk layout failed because "
1400                         "of an I/O error\n");
1401                 return -EIO;
1402         }
1403
1404         private->uses_cdl = 1;
1405         /* Check Track 0 for Compatible Disk Layout */
1406         count_area = NULL;
1407         for (i = 0; i < 3; i++) {
1408                 if (private->count_area[i].kl != 4 ||
1409                     private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
1410                         private->uses_cdl = 0;
1411                         break;
1412                 }
1413         }
1414         if (i == 3)
1415                 count_area = &private->count_area[4];
1416
1417         if (private->uses_cdl == 0) {
1418                 for (i = 0; i < 5; i++) {
1419                         if ((private->count_area[i].kl != 0) ||
1420                             (private->count_area[i].dl !=
1421                              private->count_area[0].dl))
1422                                 break;
1423                 }
1424                 if (i == 5)
1425                         count_area = &private->count_area[0];
1426         } else {
1427                 if (private->count_area[3].record == 1)
1428                         dev_warn(&device->cdev->dev,
1429                                  "Track 0 has no records following the VTOC\n");
1430         }
1431         if (count_area != NULL && count_area->kl == 0) {
1432                 /* we found notthing violating our disk layout */
1433                 if (dasd_check_blocksize(count_area->dl) == 0)
1434                         block->bp_block = count_area->dl;
1435         }
1436         if (block->bp_block == 0) {
1437                 dev_warn(&device->cdev->dev,
1438                          "The disk layout of the DASD is not supported\n");
1439                 return -EMEDIUMTYPE;
1440         }
1441         block->s2b_shift = 0;   /* bits to shift 512 to get a block */
1442         for (sb = 512; sb < block->bp_block; sb = sb << 1)
1443                 block->s2b_shift++;
1444
1445         blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
1446         block->blocks = (private->real_cyl *
1447                           private->rdc_data.trk_per_cyl *
1448                           blk_per_trk);
1449
1450         dev_info(&device->cdev->dev,
1451                  "DASD with %d KB/block, %d KB total size, %d KB/track, "
1452                  "%s\n", (block->bp_block >> 10),
1453                  ((private->real_cyl *
1454                    private->rdc_data.trk_per_cyl *
1455                    blk_per_trk * (block->bp_block >> 9)) >> 1),
1456                  ((blk_per_trk * block->bp_block) >> 10),
1457                  private->uses_cdl ?
1458                  "compatible disk layout" : "linux disk layout");
1459
1460         return 0;
1461 }
1462
1463 static int dasd_eckd_do_analysis(struct dasd_block *block)
1464 {
1465         struct dasd_eckd_private *private;
1466
1467         private = (struct dasd_eckd_private *) block->base->private;
1468         if (private->init_cqr_status < 0)
1469                 return dasd_eckd_start_analysis(block);
1470         else
1471                 return dasd_eckd_end_analysis(block);
1472 }
1473
1474 static int dasd_eckd_ready_to_online(struct dasd_device *device)
1475 {
1476         return dasd_alias_add_device(device);
1477 };
1478
1479 static int dasd_eckd_online_to_ready(struct dasd_device *device)
1480 {
1481         cancel_work_sync(&device->reload_device);
1482         return dasd_alias_remove_device(device);
1483 };
1484
1485 static int
1486 dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
1487 {
1488         struct dasd_eckd_private *private;
1489
1490         private = (struct dasd_eckd_private *) block->base->private;
1491         if (dasd_check_blocksize(block->bp_block) == 0) {
1492                 geo->sectors = recs_per_track(&private->rdc_data,
1493                                               0, block->bp_block);
1494         }
1495         geo->cylinders = private->rdc_data.no_cyl;
1496         geo->heads = private->rdc_data.trk_per_cyl;
1497         return 0;
1498 }
1499
1500 static struct dasd_ccw_req *
1501 dasd_eckd_format_device(struct dasd_device * device,
1502                         struct format_data_t * fdata)
1503 {
1504         struct dasd_eckd_private *private;
1505         struct dasd_ccw_req *fcp;
1506         struct eckd_count *ect;
1507         struct ccw1 *ccw;
1508         void *data;
1509         int rpt;
1510         struct ch_t address;
1511         int cplength, datasize;
1512         int i;
1513         int intensity = 0;
1514         int r0_perm;
1515
1516         private = (struct dasd_eckd_private *) device->private;
1517         rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
1518         set_ch_t(&address,
1519                  fdata->start_unit / private->rdc_data.trk_per_cyl,
1520                  fdata->start_unit % private->rdc_data.trk_per_cyl);
1521
1522         /* Sanity checks. */
1523         if (fdata->start_unit >=
1524             (private->real_cyl * private->rdc_data.trk_per_cyl)) {
1525                 dev_warn(&device->cdev->dev, "Start track number %d used in "
1526                          "formatting is too big\n", fdata->start_unit);
1527                 return ERR_PTR(-EINVAL);
1528         }
1529         if (fdata->start_unit > fdata->stop_unit) {
1530                 dev_warn(&device->cdev->dev, "Start track %d used in "
1531                          "formatting exceeds end track\n", fdata->start_unit);
1532                 return ERR_PTR(-EINVAL);
1533         }
1534         if (dasd_check_blocksize(fdata->blksize) != 0) {
1535                 dev_warn(&device->cdev->dev,
1536                          "The DASD cannot be formatted with block size %d\n",
1537                          fdata->blksize);
1538                 return ERR_PTR(-EINVAL);
1539         }
1540
1541         /*
1542          * fdata->intensity is a bit string that tells us what to do:
1543          *   Bit 0: write record zero
1544          *   Bit 1: write home address, currently not supported
1545          *   Bit 2: invalidate tracks
1546          *   Bit 3: use OS/390 compatible disk layout (cdl)
1547          *   Bit 4: do not allow storage subsystem to modify record zero
1548          * Only some bit combinations do make sense.
1549          */
1550         if (fdata->intensity & 0x10) {
1551                 r0_perm = 0;
1552                 intensity = fdata->intensity & ~0x10;
1553         } else {
1554                 r0_perm = 1;
1555                 intensity = fdata->intensity;
1556         }
1557         switch (intensity) {
1558         case 0x00:      /* Normal format */
1559         case 0x08:      /* Normal format, use cdl. */
1560                 cplength = 2 + rpt;
1561                 datasize = sizeof(struct DE_eckd_data) +
1562                         sizeof(struct LO_eckd_data) +
1563                         rpt * sizeof(struct eckd_count);
1564                 break;
1565         case 0x01:      /* Write record zero and format track. */
1566         case 0x09:      /* Write record zero and format track, use cdl. */
1567                 cplength = 3 + rpt;
1568                 datasize = sizeof(struct DE_eckd_data) +
1569                         sizeof(struct LO_eckd_data) +
1570                         sizeof(struct eckd_count) +
1571                         rpt * sizeof(struct eckd_count);
1572                 break;
1573         case 0x04:      /* Invalidate track. */
1574         case 0x0c:      /* Invalidate track, use cdl. */
1575                 cplength = 3;
1576                 datasize = sizeof(struct DE_eckd_data) +
1577                         sizeof(struct LO_eckd_data) +
1578                         sizeof(struct eckd_count);
1579                 break;
1580         default:
1581                 dev_warn(&device->cdev->dev, "An I/O control call used "
1582                          "incorrect flags 0x%x\n", fdata->intensity);
1583                 return ERR_PTR(-EINVAL);
1584         }
1585         /* Allocate the format ccw request. */
1586         fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1587         if (IS_ERR(fcp))
1588                 return fcp;
1589
1590         data = fcp->data;
1591         ccw = fcp->cpaddr;
1592
1593         switch (intensity & ~0x08) {
1594         case 0x00: /* Normal format. */
1595                 define_extent(ccw++, (struct DE_eckd_data *) data,
1596                               fdata->start_unit, fdata->start_unit,
1597                               DASD_ECKD_CCW_WRITE_CKD, device);
1598                 /* grant subsystem permission to format R0 */
1599                 if (r0_perm)
1600                         ((struct DE_eckd_data *)data)->ga_extended |= 0x04;
1601                 data += sizeof(struct DE_eckd_data);
1602                 ccw[-1].flags |= CCW_FLAG_CC;
1603                 locate_record(ccw++, (struct LO_eckd_data *) data,
1604                               fdata->start_unit, 0, rpt,
1605                               DASD_ECKD_CCW_WRITE_CKD, device,
1606                               fdata->blksize);
1607                 data += sizeof(struct LO_eckd_data);
1608                 break;
1609         case 0x01: /* Write record zero + format track. */
1610                 define_extent(ccw++, (struct DE_eckd_data *) data,
1611                               fdata->start_unit, fdata->start_unit,
1612                               DASD_ECKD_CCW_WRITE_RECORD_ZERO,
1613                               device);
1614                 data += sizeof(struct DE_eckd_data);
1615                 ccw[-1].flags |= CCW_FLAG_CC;
1616                 locate_record(ccw++, (struct LO_eckd_data *) data,
1617                               fdata->start_unit, 0, rpt + 1,
1618                               DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
1619                               device->block->bp_block);
1620                 data += sizeof(struct LO_eckd_data);
1621                 break;
1622         case 0x04: /* Invalidate track. */
1623                 define_extent(ccw++, (struct DE_eckd_data *) data,
1624                               fdata->start_unit, fdata->start_unit,
1625                               DASD_ECKD_CCW_WRITE_CKD, device);
1626                 data += sizeof(struct DE_eckd_data);
1627                 ccw[-1].flags |= CCW_FLAG_CC;
1628                 locate_record(ccw++, (struct LO_eckd_data *) data,
1629                               fdata->start_unit, 0, 1,
1630                               DASD_ECKD_CCW_WRITE_CKD, device, 8);
1631                 data += sizeof(struct LO_eckd_data);
1632                 break;
1633         }
1634         if (intensity & 0x01) { /* write record zero */
1635                 ect = (struct eckd_count *) data;
1636                 data += sizeof(struct eckd_count);
1637                 ect->cyl = address.cyl;
1638                 ect->head = address.head;
1639                 ect->record = 0;
1640                 ect->kl = 0;
1641                 ect->dl = 8;
1642                 ccw[-1].flags |= CCW_FLAG_CC;
1643                 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
1644                 ccw->flags = CCW_FLAG_SLI;
1645                 ccw->count = 8;
1646                 ccw->cda = (__u32)(addr_t) ect;
1647                 ccw++;
1648         }
1649         if ((intensity & ~0x08) & 0x04) {       /* erase track */
1650                 ect = (struct eckd_count *) data;
1651                 data += sizeof(struct eckd_count);
1652                 ect->cyl = address.cyl;
1653                 ect->head = address.head;
1654                 ect->record = 1;
1655                 ect->kl = 0;
1656                 ect->dl = 0;
1657                 ccw[-1].flags |= CCW_FLAG_CC;
1658                 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1659                 ccw->flags = CCW_FLAG_SLI;
1660                 ccw->count = 8;
1661                 ccw->cda = (__u32)(addr_t) ect;
1662         } else {                /* write remaining records */
1663                 for (i = 0; i < rpt; i++) {
1664                         ect = (struct eckd_count *) data;
1665                         data += sizeof(struct eckd_count);
1666                         ect->cyl = address.cyl;
1667                         ect->head = address.head;
1668                         ect->record = i + 1;
1669                         ect->kl = 0;
1670                         ect->dl = fdata->blksize;
1671                         /* Check for special tracks 0-1 when formatting CDL */
1672                         if ((intensity & 0x08) &&
1673                             fdata->start_unit == 0) {
1674                                 if (i < 3) {
1675                                         ect->kl = 4;
1676                                         ect->dl = sizes_trk0[i] - 4;
1677                                 }
1678                         }
1679                         if ((intensity & 0x08) &&
1680                             fdata->start_unit == 1) {
1681                                 ect->kl = 44;
1682                                 ect->dl = LABEL_SIZE - 44;
1683                         }
1684                         ccw[-1].flags |= CCW_FLAG_CC;
1685                         ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1686                         ccw->flags = CCW_FLAG_SLI;
1687                         ccw->count = 8;
1688                         ccw->cda = (__u32)(addr_t) ect;
1689                         ccw++;
1690                 }
1691         }
1692         fcp->startdev = device;
1693         fcp->memdev = device;
1694         fcp->retries = 256;
1695         fcp->buildclk = get_clock();
1696         fcp->status = DASD_CQR_FILLED;
1697         return fcp;
1698 }
1699
1700 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
1701 {
1702         cqr->status = DASD_CQR_FILLED;
1703         if (cqr->block && (cqr->startdev != cqr->block->base)) {
1704                 dasd_eckd_reset_ccw_to_base_io(cqr);
1705                 cqr->startdev = cqr->block->base;
1706         }
1707 };
1708
1709 static dasd_erp_fn_t
1710 dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
1711 {
1712         struct dasd_device *device = (struct dasd_device *) cqr->startdev;
1713         struct ccw_device *cdev = device->cdev;
1714
1715         switch (cdev->id.cu_type) {
1716         case 0x3990:
1717         case 0x2105:
1718         case 0x2107:
1719         case 0x1750:
1720                 return dasd_3990_erp_action;
1721         case 0x9343:
1722         case 0x3880:
1723         default:
1724                 return dasd_default_erp_action;
1725         }
1726 }
1727
1728 static dasd_erp_fn_t
1729 dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
1730 {
1731         return dasd_default_erp_postaction;
1732 }
1733
1734
1735 static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device *device,
1736                                                    struct irb *irb)
1737 {
1738         char mask;
1739         char *sense = NULL;
1740         struct dasd_eckd_private *private;
1741
1742         private = (struct dasd_eckd_private *) device->private;
1743         /* first of all check for state change pending interrupt */
1744         mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
1745         if ((scsw_dstat(&irb->scsw) & mask) == mask) {
1746                 /* for alias only and not in offline processing*/
1747                 if (!device->block && private->lcu &&
1748                     !test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1749                         /*
1750                          * the state change could be caused by an alias
1751                          * reassignment remove device from alias handling
1752                          * to prevent new requests from being scheduled on
1753                          * the wrong alias device
1754                          */
1755                         dasd_alias_remove_device(device);
1756
1757                         /* schedule worker to reload device */
1758                         dasd_reload_device(device);
1759                 }
1760
1761                 dasd_generic_handle_state_change(device);
1762                 return;
1763         }
1764
1765         /* summary unit check */
1766         if ((scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
1767             (irb->ecw[7] == 0x0D)) {
1768                 dasd_alias_handle_summary_unit_check(device, irb);
1769                 return;
1770         }
1771
1772         sense = dasd_get_sense(irb);
1773         /* service information message SIM */
1774         if (sense && !(sense[27] & DASD_SENSE_BIT_0) &&
1775             ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
1776                 dasd_3990_erp_handle_sim(device, sense);
1777                 dasd_schedule_device_bh(device);
1778                 return;
1779         }
1780
1781         if ((scsw_cc(&irb->scsw) == 1) &&
1782             (scsw_fctl(&irb->scsw) & SCSW_FCTL_START_FUNC) &&
1783             (scsw_actl(&irb->scsw) & SCSW_ACTL_START_PEND) &&
1784             (scsw_stctl(&irb->scsw) & SCSW_STCTL_STATUS_PEND)) {
1785                 /* fake irb do nothing, they are handled elsewhere */
1786                 dasd_schedule_device_bh(device);
1787                 return;
1788         }
1789
1790         if (!sense) {
1791                 /* just report other unsolicited interrupts */
1792                 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1793                             "unsolicited interrupt received");
1794         } else {
1795                 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1796                             "unsolicited interrupt received "
1797                             "(sense available)");
1798                 device->discipline->dump_sense_dbf(device, irb, "unsolicited");
1799         }
1800
1801         dasd_schedule_device_bh(device);
1802         return;
1803 };
1804
1805
1806 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
1807                                                struct dasd_device *startdev,
1808                                                struct dasd_block *block,
1809                                                struct request *req,
1810                                                sector_t first_rec,
1811                                                sector_t last_rec,
1812                                                sector_t first_trk,
1813                                                sector_t last_trk,
1814                                                unsigned int first_offs,
1815                                                unsigned int last_offs,
1816                                                unsigned int blk_per_trk,
1817                                                unsigned int blksize)
1818 {
1819         struct dasd_eckd_private *private;
1820         unsigned long *idaws;
1821         struct LO_eckd_data *LO_data;
1822         struct dasd_ccw_req *cqr;
1823         struct ccw1 *ccw;
1824         struct req_iterator iter;
1825         struct bio_vec *bv;
1826         char *dst;
1827         unsigned int off;
1828         int count, cidaw, cplength, datasize;
1829         sector_t recid;
1830         unsigned char cmd, rcmd;
1831         int use_prefix;
1832         struct dasd_device *basedev;
1833
1834         basedev = block->base;
1835         private = (struct dasd_eckd_private *) basedev->private;
1836         if (rq_data_dir(req) == READ)
1837                 cmd = DASD_ECKD_CCW_READ_MT;
1838         else if (rq_data_dir(req) == WRITE)
1839                 cmd = DASD_ECKD_CCW_WRITE_MT;
1840         else
1841                 return ERR_PTR(-EINVAL);
1842
1843         /* Check struct bio and count the number of blocks for the request. */
1844         count = 0;
1845         cidaw = 0;
1846         rq_for_each_segment(bv, req, iter) {
1847                 if (bv->bv_len & (blksize - 1))
1848                         /* Eckd can only do full blocks. */
1849                         return ERR_PTR(-EINVAL);
1850                 count += bv->bv_len >> (block->s2b_shift + 9);
1851 #if defined(CONFIG_64BIT)
1852                 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
1853                         cidaw += bv->bv_len >> (block->s2b_shift + 9);
1854 #endif
1855         }
1856         /* Paranoia. */
1857         if (count != last_rec - first_rec + 1)
1858                 return ERR_PTR(-EINVAL);
1859
1860         /* use the prefix command if available */
1861         use_prefix = private->features.feature[8] & 0x01;
1862         if (use_prefix) {
1863                 /* 1x prefix + number of blocks */
1864                 cplength = 2 + count;
1865                 /* 1x prefix + cidaws*sizeof(long) */
1866                 datasize = sizeof(struct PFX_eckd_data) +
1867                         sizeof(struct LO_eckd_data) +
1868                         cidaw * sizeof(unsigned long);
1869         } else {
1870                 /* 1x define extent + 1x locate record + number of blocks */
1871                 cplength = 2 + count;
1872                 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
1873                 datasize = sizeof(struct DE_eckd_data) +
1874                         sizeof(struct LO_eckd_data) +
1875                         cidaw * sizeof(unsigned long);
1876         }
1877         /* Find out the number of additional locate record ccws for cdl. */
1878         if (private->uses_cdl && first_rec < 2*blk_per_trk) {
1879                 if (last_rec >= 2*blk_per_trk)
1880                         count = 2*blk_per_trk - first_rec;
1881                 cplength += count;
1882                 datasize += count*sizeof(struct LO_eckd_data);
1883         }
1884         /* Allocate the ccw request. */
1885         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
1886                                    startdev);
1887         if (IS_ERR(cqr))
1888                 return cqr;
1889         ccw = cqr->cpaddr;
1890         /* First ccw is define extent or prefix. */
1891         if (use_prefix) {
1892                 if (prefix(ccw++, cqr->data, first_trk,
1893                            last_trk, cmd, basedev, startdev) == -EAGAIN) {
1894                         /* Clock not in sync and XRC is enabled.
1895                          * Try again later.
1896                          */
1897                         dasd_sfree_request(cqr, startdev);
1898                         return ERR_PTR(-EAGAIN);
1899                 }
1900                 idaws = (unsigned long *) (cqr->data +
1901                                            sizeof(struct PFX_eckd_data));
1902         } else {
1903                 if (define_extent(ccw++, cqr->data, first_trk,
1904                                   last_trk, cmd, startdev) == -EAGAIN) {
1905                         /* Clock not in sync and XRC is enabled.
1906                          * Try again later.
1907                          */
1908                         dasd_sfree_request(cqr, startdev);
1909                         return ERR_PTR(-EAGAIN);
1910                 }
1911                 idaws = (unsigned long *) (cqr->data +
1912                                            sizeof(struct DE_eckd_data));
1913         }
1914         /* Build locate_record+read/write/ccws. */
1915         LO_data = (struct LO_eckd_data *) (idaws + cidaw);
1916         recid = first_rec;
1917         if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
1918                 /* Only standard blocks so there is just one locate record. */
1919                 ccw[-1].flags |= CCW_FLAG_CC;
1920                 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
1921                               last_rec - recid + 1, cmd, basedev, blksize);
1922         }
1923         rq_for_each_segment(bv, req, iter) {
1924                 dst = page_address(bv->bv_page) + bv->bv_offset;
1925                 if (dasd_page_cache) {
1926                         char *copy = kmem_cache_alloc(dasd_page_cache,
1927                                                       GFP_DMA | __GFP_NOWARN);
1928                         if (copy && rq_data_dir(req) == WRITE)
1929                                 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
1930                         if (copy)
1931                                 dst = copy + bv->bv_offset;
1932                 }
1933                 for (off = 0; off < bv->bv_len; off += blksize) {
1934                         sector_t trkid = recid;
1935                         unsigned int recoffs = sector_div(trkid, blk_per_trk);
1936                         rcmd = cmd;
1937                         count = blksize;
1938                         /* Locate record for cdl special block ? */
1939                         if (private->uses_cdl && recid < 2*blk_per_trk) {
1940                                 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
1941                                         rcmd |= 0x8;
1942                                         count = dasd_eckd_cdl_reclen(recid);
1943                                         if (count < blksize &&
1944                                             rq_data_dir(req) == READ)
1945                                                 memset(dst + count, 0xe5,
1946                                                        blksize - count);
1947                                 }
1948                                 ccw[-1].flags |= CCW_FLAG_CC;
1949                                 locate_record(ccw++, LO_data++,
1950                                               trkid, recoffs + 1,
1951                                               1, rcmd, basedev, count);
1952                         }
1953                         /* Locate record for standard blocks ? */
1954                         if (private->uses_cdl && recid == 2*blk_per_trk) {
1955                                 ccw[-1].flags |= CCW_FLAG_CC;
1956                                 locate_record(ccw++, LO_data++,
1957                                               trkid, recoffs + 1,
1958                                               last_rec - recid + 1,
1959                                               cmd, basedev, count);
1960                         }
1961                         /* Read/write ccw. */
1962                         ccw[-1].flags |= CCW_FLAG_CC;
1963                         ccw->cmd_code = rcmd;
1964                         ccw->count = count;
1965                         if (idal_is_needed(dst, blksize)) {
1966                                 ccw->cda = (__u32)(addr_t) idaws;
1967                                 ccw->flags = CCW_FLAG_IDA;
1968                                 idaws = idal_create_words(idaws, dst, blksize);
1969                         } else {
1970                                 ccw->cda = (__u32)(addr_t) dst;
1971                                 ccw->flags = 0;
1972                         }
1973                         ccw++;
1974                         dst += blksize;
1975                         recid++;
1976                 }
1977         }
1978         if (blk_noretry_request(req) ||
1979             block->base->features & DASD_FEATURE_FAILFAST)
1980                 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1981         cqr->startdev = startdev;
1982         cqr->memdev = startdev;
1983         cqr->block = block;
1984         cqr->expires = 5 * 60 * HZ;     /* 5 minutes */
1985         cqr->lpm = private->path_data.ppm;
1986         cqr->retries = 256;
1987         cqr->buildclk = get_clock();
1988         cqr->status = DASD_CQR_FILLED;
1989         return cqr;
1990 }
1991
1992 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
1993                                                struct dasd_device *startdev,
1994                                                struct dasd_block *block,
1995                                                struct request *req,
1996                                                sector_t first_rec,
1997                                                sector_t last_rec,
1998                                                sector_t first_trk,
1999                                                sector_t last_trk,
2000                                                unsigned int first_offs,
2001                                                unsigned int last_offs,
2002                                                unsigned int blk_per_trk,
2003                                                unsigned int blksize)
2004 {
2005         struct dasd_eckd_private *private;
2006         unsigned long *idaws;
2007         struct dasd_ccw_req *cqr;
2008         struct ccw1 *ccw;
2009         struct req_iterator iter;
2010         struct bio_vec *bv;
2011         char *dst, *idaw_dst;
2012         unsigned int cidaw, cplength, datasize;
2013         unsigned int tlf;
2014         sector_t recid;
2015         unsigned char cmd;
2016         struct dasd_device *basedev;
2017         unsigned int trkcount, count, count_to_trk_end;
2018         unsigned int idaw_len, seg_len, part_len, len_to_track_end;
2019         unsigned char new_track, end_idaw;
2020         sector_t trkid;
2021         unsigned int recoffs;
2022
2023         basedev = block->base;
2024         private = (struct dasd_eckd_private *) basedev->private;
2025         if (rq_data_dir(req) == READ)
2026                 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2027         else if (rq_data_dir(req) == WRITE)
2028                 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2029         else
2030                 return ERR_PTR(-EINVAL);
2031
2032         /* Track based I/O needs IDAWs for each page, and not just for
2033          * 64 bit addresses. We need additional idals for pages
2034          * that get filled from two tracks, so we use the number
2035          * of records as upper limit.
2036          */
2037         cidaw = last_rec - first_rec + 1;
2038         trkcount = last_trk - first_trk + 1;
2039
2040         /* 1x prefix + one read/write ccw per track */
2041         cplength = 1 + trkcount;
2042
2043         /* on 31-bit we need space for two 32 bit addresses per page
2044          * on 64-bit one 64 bit address
2045          */
2046         datasize = sizeof(struct PFX_eckd_data) +
2047                 cidaw * sizeof(unsigned long long);
2048
2049         /* Allocate the ccw request. */
2050         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2051                                    startdev);
2052         if (IS_ERR(cqr))
2053                 return cqr;
2054         ccw = cqr->cpaddr;
2055         /* transfer length factor: how many bytes to read from the last track */
2056         if (first_trk == last_trk)
2057                 tlf = last_offs - first_offs + 1;
2058         else
2059                 tlf = last_offs + 1;
2060         tlf *= blksize;
2061
2062         if (prefix_LRE(ccw++, cqr->data, first_trk,
2063                        last_trk, cmd, basedev, startdev,
2064                        1 /* format */, first_offs + 1,
2065                        trkcount, blksize,
2066                        tlf) == -EAGAIN) {
2067                 /* Clock not in sync and XRC is enabled.
2068                  * Try again later.
2069                  */
2070                 dasd_sfree_request(cqr, startdev);
2071                 return ERR_PTR(-EAGAIN);
2072         }
2073
2074         /*
2075          * The translation of request into ccw programs must meet the
2076          * following conditions:
2077          * - all idaws but the first and the last must address full pages
2078          *   (or 2K blocks on 31-bit)
2079          * - the scope of a ccw and it's idal ends with the track boundaries
2080          */
2081         idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
2082         recid = first_rec;
2083         new_track = 1;
2084         end_idaw = 0;
2085         len_to_track_end = 0;
2086         idaw_dst = 0;
2087         idaw_len = 0;
2088         rq_for_each_segment(bv, req, iter) {
2089                 dst = page_address(bv->bv_page) + bv->bv_offset;
2090                 seg_len = bv->bv_len;
2091                 while (seg_len) {
2092                         if (new_track) {
2093                                 trkid = recid;
2094                                 recoffs = sector_div(trkid, blk_per_trk);
2095                                 count_to_trk_end = blk_per_trk - recoffs;
2096                                 count = min((last_rec - recid + 1),
2097                                             (sector_t)count_to_trk_end);
2098                                 len_to_track_end = count * blksize;
2099                                 ccw[-1].flags |= CCW_FLAG_CC;
2100                                 ccw->cmd_code = cmd;
2101                                 ccw->count = len_to_track_end;
2102                                 ccw->cda = (__u32)(addr_t)idaws;
2103                                 ccw->flags = CCW_FLAG_IDA;
2104                                 ccw++;
2105                                 recid += count;
2106                                 new_track = 0;
2107                                 /* first idaw for a ccw may start anywhere */
2108                                 if (!idaw_dst)
2109                                         idaw_dst = dst;
2110                         }
2111                         /* If we start a new idaw, we must make sure that it
2112                          * starts on an IDA_BLOCK_SIZE boundary.
2113                          * If we continue an idaw, we must make sure that the
2114                          * current segment begins where the so far accumulated
2115                          * idaw ends
2116                          */
2117                         if (!idaw_dst) {
2118                                 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
2119                                         dasd_sfree_request(cqr, startdev);
2120                                         return ERR_PTR(-ERANGE);
2121                                 } else
2122                                         idaw_dst = dst;
2123                         }
2124                         if ((idaw_dst + idaw_len) != dst) {
2125                                 dasd_sfree_request(cqr, startdev);
2126                                 return ERR_PTR(-ERANGE);
2127                         }
2128                         part_len = min(seg_len, len_to_track_end);
2129                         seg_len -= part_len;
2130                         dst += part_len;
2131                         idaw_len += part_len;
2132                         len_to_track_end -= part_len;
2133                         /* collected memory area ends on an IDA_BLOCK border,
2134                          * -> create an idaw
2135                          * idal_create_words will handle cases where idaw_len
2136                          * is larger then IDA_BLOCK_SIZE
2137                          */
2138                         if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
2139                                 end_idaw = 1;
2140                         /* We also need to end the idaw at track end */
2141                         if (!len_to_track_end) {
2142                                 new_track = 1;
2143                                 end_idaw = 1;
2144                         }
2145                         if (end_idaw) {
2146                                 idaws = idal_create_words(idaws, idaw_dst,
2147                                                           idaw_len);
2148                                 idaw_dst = 0;
2149                                 idaw_len = 0;
2150                                 end_idaw = 0;
2151                         }
2152                 }
2153         }
2154
2155         if (blk_noretry_request(req) ||
2156             block->base->features & DASD_FEATURE_FAILFAST)
2157                 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2158         cqr->startdev = startdev;
2159         cqr->memdev = startdev;
2160         cqr->block = block;
2161         cqr->expires = 5 * 60 * HZ;     /* 5 minutes */
2162         cqr->lpm = private->path_data.ppm;
2163         cqr->retries = 256;
2164         cqr->buildclk = get_clock();
2165         cqr->status = DASD_CQR_FILLED;
2166         return cqr;
2167 }
2168
2169 static int prepare_itcw(struct itcw *itcw,
2170                         unsigned int trk, unsigned int totrk, int cmd,
2171                         struct dasd_device *basedev,
2172                         struct dasd_device *startdev,
2173                         unsigned int rec_on_trk, int count,
2174                         unsigned int blksize,
2175                         unsigned int total_data_size,
2176                         unsigned int tlf,
2177                         unsigned int blk_per_trk)
2178 {
2179         struct PFX_eckd_data pfxdata;
2180         struct dasd_eckd_private *basepriv, *startpriv;
2181         struct DE_eckd_data *dedata;
2182         struct LRE_eckd_data *lredata;
2183         struct dcw *dcw;
2184
2185         u32 begcyl, endcyl;
2186         u16 heads, beghead, endhead;
2187         u8 pfx_cmd;
2188
2189         int rc = 0;
2190         int sector = 0;
2191         int dn, d;
2192
2193
2194         /* setup prefix data */
2195         basepriv = (struct dasd_eckd_private *) basedev->private;
2196         startpriv = (struct dasd_eckd_private *) startdev->private;
2197         dedata = &pfxdata.define_extent;
2198         lredata = &pfxdata.locate_record;
2199
2200         memset(&pfxdata, 0, sizeof(pfxdata));
2201         pfxdata.format = 1; /* PFX with LRE */
2202         pfxdata.base_address = basepriv->ned->unit_addr;
2203         pfxdata.base_lss = basepriv->ned->ID;
2204         pfxdata.validity.define_extent = 1;
2205
2206         /* private uid is kept up to date, conf_data may be outdated */
2207         if (startpriv->uid.type != UA_BASE_DEVICE) {
2208                 pfxdata.validity.verify_base = 1;
2209                 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
2210                         pfxdata.validity.hyper_pav = 1;
2211         }
2212
2213         switch (cmd) {
2214         case DASD_ECKD_CCW_READ_TRACK_DATA:
2215                 dedata->mask.perm = 0x1;
2216                 dedata->attributes.operation = basepriv->attrib.operation;
2217                 dedata->blk_size = blksize;
2218                 dedata->ga_extended |= 0x42;
2219                 lredata->operation.orientation = 0x0;
2220                 lredata->operation.operation = 0x0C;
2221                 lredata->auxiliary.check_bytes = 0x01;
2222                 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
2223                 break;
2224         case DASD_ECKD_CCW_WRITE_TRACK_DATA:
2225                 dedata->mask.perm = 0x02;
2226                 dedata->attributes.operation = basepriv->attrib.operation;
2227                 dedata->blk_size = blksize;
2228                 rc = check_XRC_on_prefix(&pfxdata, basedev);
2229                 dedata->ga_extended |= 0x42;
2230                 lredata->operation.orientation = 0x0;
2231                 lredata->operation.operation = 0x3F;
2232                 lredata->extended_operation = 0x23;
2233                 lredata->auxiliary.check_bytes = 0x2;
2234                 pfx_cmd = DASD_ECKD_CCW_PFX;
2235                 break;
2236         default:
2237                 DBF_DEV_EVENT(DBF_ERR, basedev,
2238                               "prepare itcw, unknown opcode 0x%x", cmd);
2239                 BUG();
2240                 break;
2241         }
2242         if (rc)
2243                 return rc;
2244
2245         dedata->attributes.mode = 0x3;  /* ECKD */
2246
2247         heads = basepriv->rdc_data.trk_per_cyl;
2248         begcyl = trk / heads;
2249         beghead = trk % heads;
2250         endcyl = totrk / heads;
2251         endhead = totrk % heads;
2252
2253         /* check for sequential prestage - enhance cylinder range */
2254         if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
2255             dedata->attributes.operation == DASD_SEQ_ACCESS) {
2256
2257                 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
2258                         endcyl += basepriv->attrib.nr_cyl;
2259                 else
2260                         endcyl = (basepriv->real_cyl - 1);
2261         }
2262
2263         set_ch_t(&dedata->beg_ext, begcyl, beghead);
2264         set_ch_t(&dedata->end_ext, endcyl, endhead);
2265
2266         dedata->ep_format = 0x20; /* records per track is valid */
2267         dedata->ep_rec_per_track = blk_per_trk;
2268
2269         if (rec_on_trk) {
2270                 switch (basepriv->rdc_data.dev_type) {
2271                 case 0x3390:
2272                         dn = ceil_quot(blksize + 6, 232);
2273                         d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
2274                         sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
2275                         break;
2276                 case 0x3380:
2277                         d = 7 + ceil_quot(blksize + 12, 32);
2278                         sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
2279                         break;
2280                 }
2281         }
2282
2283         lredata->auxiliary.length_valid = 1;
2284         lredata->auxiliary.length_scope = 1;
2285         lredata->auxiliary.imbedded_ccw_valid = 1;
2286         lredata->length = tlf;
2287         lredata->imbedded_ccw = cmd;
2288         lredata->count = count;
2289         lredata->sector = sector;
2290         set_ch_t(&lredata->seek_addr, begcyl, beghead);
2291         lredata->search_arg.cyl = lredata->seek_addr.cyl;
2292         lredata->search_arg.head = lredata->seek_addr.head;
2293         lredata->search_arg.record = rec_on_trk;
2294
2295         dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
2296                      &pfxdata, sizeof(pfxdata), total_data_size);
2297
2298         return rc;
2299 }
2300
2301 static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2302                                                struct dasd_device *startdev,
2303                                                struct dasd_block *block,
2304                                                struct request *req,
2305                                                sector_t first_rec,
2306                                                sector_t last_rec,
2307                                                sector_t first_trk,
2308                                                sector_t last_trk,
2309                                                unsigned int first_offs,
2310                                                unsigned int last_offs,
2311                                                unsigned int blk_per_trk,
2312                                                unsigned int blksize)
2313 {
2314         struct dasd_eckd_private *private;
2315         struct dasd_ccw_req *cqr;
2316         struct req_iterator iter;
2317         struct bio_vec *bv;
2318         char *dst;
2319         unsigned int trkcount, ctidaw;
2320         unsigned char cmd;
2321         struct dasd_device *basedev;
2322         unsigned int tlf;
2323         struct itcw *itcw;
2324         struct tidaw *last_tidaw = NULL;
2325         int itcw_op;
2326         size_t itcw_size;
2327
2328         basedev = block->base;
2329         private = (struct dasd_eckd_private *) basedev->private;
2330         if (rq_data_dir(req) == READ) {
2331                 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2332                 itcw_op = ITCW_OP_READ;
2333         } else if (rq_data_dir(req) == WRITE) {
2334                 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2335                 itcw_op = ITCW_OP_WRITE;
2336         } else
2337                 return ERR_PTR(-EINVAL);
2338
2339         /* trackbased I/O needs address all memory via TIDAWs,
2340          * not just for 64 bit addresses. This allows us to map
2341          * each segment directly to one tidaw.
2342          */
2343         trkcount = last_trk - first_trk + 1;
2344         ctidaw = 0;
2345         rq_for_each_segment(bv, req, iter) {
2346                 ++ctidaw;
2347         }
2348
2349         /* Allocate the ccw request. */
2350         itcw_size = itcw_calc_size(0, ctidaw, 0);
2351         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
2352         if (IS_ERR(cqr))
2353                 return cqr;
2354
2355         cqr->cpmode = 1;
2356         cqr->startdev = startdev;
2357         cqr->memdev = startdev;
2358         cqr->block = block;
2359         cqr->expires = 100*HZ;
2360         cqr->buildclk = get_clock();
2361         cqr->status = DASD_CQR_FILLED;
2362         cqr->retries = 10;
2363
2364         /* transfer length factor: how many bytes to read from the last track */
2365         if (first_trk == last_trk)
2366                 tlf = last_offs - first_offs + 1;
2367         else
2368                 tlf = last_offs + 1;
2369         tlf *= blksize;
2370
2371         itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
2372         cqr->cpaddr = itcw_get_tcw(itcw);
2373
2374         if (prepare_itcw(itcw, first_trk, last_trk,
2375                          cmd, basedev, startdev,
2376                          first_offs + 1,
2377                          trkcount, blksize,
2378                          (last_rec - first_rec + 1) * blksize,
2379                          tlf, blk_per_trk) == -EAGAIN) {
2380                 /* Clock not in sync and XRC is enabled.
2381                  * Try again later.
2382                  */
2383                 dasd_sfree_request(cqr, startdev);
2384                 return ERR_PTR(-EAGAIN);
2385         }
2386
2387         /*
2388          * A tidaw can address 4k of memory, but must not cross page boundaries
2389          * We can let the block layer handle this by setting
2390          * blk_queue_segment_boundary to page boundaries and
2391          * blk_max_segment_size to page size when setting up the request queue.
2392          */
2393         rq_for_each_segment(bv, req, iter) {
2394                 dst = page_address(bv->bv_page) + bv->bv_offset;
2395                 last_tidaw = itcw_add_tidaw(itcw, 0x00, dst, bv->bv_len);
2396                 if (IS_ERR(last_tidaw))
2397                         return (struct dasd_ccw_req *)last_tidaw;
2398         }
2399
2400         last_tidaw->flags |= 0x80;
2401         itcw_finalize(itcw);
2402
2403         if (blk_noretry_request(req) ||
2404             block->base->features & DASD_FEATURE_FAILFAST)
2405                 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2406         cqr->startdev = startdev;
2407         cqr->memdev = startdev;
2408         cqr->block = block;
2409         cqr->expires = 5 * 60 * HZ;     /* 5 minutes */
2410         cqr->lpm = private->path_data.ppm;
2411         cqr->retries = 256;
2412         cqr->buildclk = get_clock();
2413         cqr->status = DASD_CQR_FILLED;
2414         return cqr;
2415 }
2416
2417 static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
2418                                                struct dasd_block *block,
2419                                                struct request *req)
2420 {
2421         int tpm, cmdrtd, cmdwtd;
2422         int use_prefix;
2423 #if defined(CONFIG_64BIT)
2424         int fcx_in_css, fcx_in_gneq, fcx_in_features;
2425 #endif
2426         struct dasd_eckd_private *private;
2427         struct dasd_device *basedev;
2428         sector_t first_rec, last_rec;
2429         sector_t first_trk, last_trk;
2430         unsigned int first_offs, last_offs;
2431         unsigned int blk_per_trk, blksize;
2432         int cdlspecial;
2433         struct dasd_ccw_req *cqr;
2434
2435         basedev = block->base;
2436         private = (struct dasd_eckd_private *) basedev->private;
2437
2438         /* Calculate number of blocks/records per track. */
2439         blksize = block->bp_block;
2440         blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
2441         if (blk_per_trk == 0)
2442                 return ERR_PTR(-EINVAL);
2443         /* Calculate record id of first and last block. */
2444         first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
2445         first_offs = sector_div(first_trk, blk_per_trk);
2446         last_rec = last_trk =
2447                 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
2448         last_offs = sector_div(last_trk, blk_per_trk);
2449         cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
2450
2451         /* is transport mode supported? */
2452 #if defined(CONFIG_64BIT)
2453         fcx_in_css = css_general_characteristics.fcx;
2454         fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
2455         fcx_in_features = private->features.feature[40] & 0x80;
2456         tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
2457 #else
2458         tpm = 0;
2459 #endif
2460
2461         /* is read track data and write track data in command mode supported? */
2462         cmdrtd = private->features.feature[9] & 0x20;
2463         cmdwtd = private->features.feature[12] & 0x40;
2464         use_prefix = private->features.feature[8] & 0x01;
2465
2466         cqr = NULL;
2467         if (cdlspecial || dasd_page_cache) {
2468                 /* do nothing, just fall through to the cmd mode single case */
2469         } else if (!dasd_nofcx && tpm && (first_trk == last_trk)) {
2470                 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
2471                                                     first_rec, last_rec,
2472                                                     first_trk, last_trk,
2473                                                     first_offs, last_offs,
2474                                                     blk_per_trk, blksize);
2475                 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
2476                         cqr = NULL;
2477         } else if (use_prefix &&
2478                    (((rq_data_dir(req) == READ) && cmdrtd) ||
2479                     ((rq_data_dir(req) == WRITE) && cmdwtd))) {
2480                 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
2481                                                    first_rec, last_rec,
2482                                                    first_trk, last_trk,
2483                                                    first_offs, last_offs,
2484                                                    blk_per_trk, blksize);
2485                 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
2486                         cqr = NULL;
2487         }
2488         if (!cqr)
2489                 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
2490                                                     first_rec, last_rec,
2491                                                     first_trk, last_trk,
2492                                                     first_offs, last_offs,
2493                                                     blk_per_trk, blksize);
2494         return cqr;
2495 }
2496
2497 static int
2498 dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
2499 {
2500         struct dasd_eckd_private *private;
2501         struct ccw1 *ccw;
2502         struct req_iterator iter;
2503         struct bio_vec *bv;
2504         char *dst, *cda;
2505         unsigned int blksize, blk_per_trk, off;
2506         sector_t recid;
2507         int status;
2508
2509         if (!dasd_page_cache)
2510                 goto out;
2511         private = (struct dasd_eckd_private *) cqr->block->base->private;
2512         blksize = cqr->block->bp_block;
2513         blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
2514         recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
2515         ccw = cqr->cpaddr;
2516         /* Skip over define extent & locate record. */
2517         ccw++;
2518         if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
2519                 ccw++;
2520         rq_for_each_segment(bv, req, iter) {
2521                 dst = page_address(bv->bv_page) + bv->bv_offset;
2522                 for (off = 0; off < bv->bv_len; off += blksize) {
2523                         /* Skip locate record. */
2524                         if (private->uses_cdl && recid <= 2*blk_per_trk)
2525                                 ccw++;
2526                         if (dst) {
2527                                 if (ccw->flags & CCW_FLAG_IDA)
2528                                         cda = *((char **)((addr_t) ccw->cda));
2529                                 else
2530                                         cda = (char *)((addr_t) ccw->cda);
2531                                 if (dst != cda) {
2532                                         if (rq_data_dir(req) == READ)
2533                                                 memcpy(dst, cda, bv->bv_len);
2534                                         kmem_cache_free(dasd_page_cache,
2535                                             (void *)((addr_t)cda & PAGE_MASK));
2536                                 }
2537                                 dst = NULL;
2538                         }
2539                         ccw++;
2540                         recid++;
2541                 }
2542         }
2543 out:
2544         status = cqr->status == DASD_CQR_DONE;
2545         dasd_sfree_request(cqr, cqr->memdev);
2546         return status;
2547 }
2548
2549 /*
2550  * Modify ccw/tcw in cqr so it can be started on a base device.
2551  *
2552  * Note that this is not enough to restart the cqr!
2553  * Either reset cqr->startdev as well (summary unit check handling)
2554  * or restart via separate cqr (as in ERP handling).
2555  */
2556 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
2557 {
2558         struct ccw1 *ccw;
2559         struct PFX_eckd_data *pfxdata;
2560         struct tcw *tcw;
2561         struct tccb *tccb;
2562         struct dcw *dcw;
2563
2564         if (cqr->cpmode == 1) {
2565                 tcw = cqr->cpaddr;
2566                 tccb = tcw_get_tccb(tcw);
2567                 dcw = (struct dcw *)&tccb->tca[0];
2568                 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
2569                 pfxdata->validity.verify_base = 0;
2570                 pfxdata->validity.hyper_pav = 0;
2571         } else {
2572                 ccw = cqr->cpaddr;
2573                 pfxdata = cqr->data;
2574                 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
2575                         pfxdata->validity.verify_base = 0;
2576                         pfxdata->validity.hyper_pav = 0;
2577                 }
2578         }
2579 }
2580
2581 #define DASD_ECKD_CHANQ_MAX_SIZE 4
2582
2583 static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
2584                                                      struct dasd_block *block,
2585                                                      struct request *req)
2586 {
2587         struct dasd_eckd_private *private;
2588         struct dasd_device *startdev;
2589         unsigned long flags;
2590         struct dasd_ccw_req *cqr;
2591
2592         startdev = dasd_alias_get_start_dev(base);
2593         if (!startdev)
2594                 startdev = base;
2595         private = (struct dasd_eckd_private *) startdev->private;
2596         if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
2597                 return ERR_PTR(-EBUSY);
2598
2599         spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
2600         private->count++;
2601         cqr = dasd_eckd_build_cp(startdev, block, req);
2602         if (IS_ERR(cqr))
2603                 private->count--;
2604         spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
2605         return cqr;
2606 }
2607
2608 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
2609                                    struct request *req)
2610 {
2611         struct dasd_eckd_private *private;
2612         unsigned long flags;
2613
2614         spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
2615         private = (struct dasd_eckd_private *) cqr->memdev->private;
2616         private->count--;
2617         spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
2618         return dasd_eckd_free_cp(cqr, req);
2619 }
2620
2621 static int
2622 dasd_eckd_fill_info(struct dasd_device * device,
2623                     struct dasd_information2_t * info)
2624 {
2625         struct dasd_eckd_private *private;
2626
2627         private = (struct dasd_eckd_private *) device->private;
2628         info->label_block = 2;
2629         info->FBA_layout = private->uses_cdl ? 0 : 1;
2630         info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
2631         info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
2632         memcpy(info->characteristics, &private->rdc_data,
2633                sizeof(struct dasd_eckd_characteristics));
2634         info->confdata_size = min((unsigned long)private->conf_len,
2635                                   sizeof(info->configuration_data));
2636         memcpy(info->configuration_data, private->conf_data,
2637                info->confdata_size);
2638         return 0;
2639 }
2640
2641 /*
2642  * SECTION: ioctl functions for eckd devices.
2643  */
2644
2645 /*
2646  * Release device ioctl.
2647  * Buils a channel programm to releases a prior reserved
2648  * (see dasd_eckd_reserve) device.
2649  */
2650 static int
2651 dasd_eckd_release(struct dasd_device *device)
2652 {
2653         struct dasd_ccw_req *cqr;
2654         int rc;
2655         struct ccw1 *ccw;
2656         int useglobal;
2657
2658         if (!capable(CAP_SYS_ADMIN))
2659                 return -EACCES;
2660
2661         useglobal = 0;
2662         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
2663         if (IS_ERR(cqr)) {
2664                 mutex_lock(&dasd_reserve_mutex);
2665                 useglobal = 1;
2666                 cqr = &dasd_reserve_req->cqr;
2667                 memset(cqr, 0, sizeof(*cqr));
2668                 memset(&dasd_reserve_req->ccw, 0,
2669                        sizeof(dasd_reserve_req->ccw));
2670                 cqr->cpaddr = &dasd_reserve_req->ccw;
2671                 cqr->data = &dasd_reserve_req->data;
2672                 cqr->magic = DASD_ECKD_MAGIC;
2673         }
2674         ccw = cqr->cpaddr;
2675         ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
2676         ccw->flags |= CCW_FLAG_SLI;
2677         ccw->count = 32;
2678         ccw->cda = (__u32)(addr_t) cqr->data;
2679         cqr->startdev = device;
2680         cqr->memdev = device;
2681         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
2682         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2683         cqr->retries = 2;       /* set retry counter to enable basic ERP */
2684         cqr->expires = 2 * HZ;
2685         cqr->buildclk = get_clock();
2686         cqr->status = DASD_CQR_FILLED;
2687
2688         rc = dasd_sleep_on_immediatly(cqr);
2689
2690         if (useglobal)
2691                 mutex_unlock(&dasd_reserve_mutex);
2692         else
2693                 dasd_sfree_request(cqr, cqr->memdev);
2694         return rc;
2695 }
2696
2697 /*
2698  * Reserve device ioctl.
2699  * Options are set to 'synchronous wait for interrupt' and
2700  * 'timeout the request'. This leads to a terminate IO if
2701  * the interrupt is outstanding for a certain time.
2702  */
2703 static int
2704 dasd_eckd_reserve(struct dasd_device *device)
2705 {
2706         struct dasd_ccw_req *cqr;
2707         int rc;
2708         struct ccw1 *ccw;
2709         int useglobal;
2710
2711         if (!capable(CAP_SYS_ADMIN))
2712                 return -EACCES;
2713
2714         useglobal = 0;
2715         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
2716         if (IS_ERR(cqr)) {
2717                 mutex_lock(&dasd_reserve_mutex);
2718                 useglobal = 1;
2719                 cqr = &dasd_reserve_req->cqr;
2720                 memset(cqr, 0, sizeof(*cqr));
2721                 memset(&dasd_reserve_req->ccw, 0,
2722                        sizeof(dasd_reserve_req->ccw));
2723                 cqr->cpaddr = &dasd_reserve_req->ccw;
2724                 cqr->data = &dasd_reserve_req->data;
2725                 cqr->magic = DASD_ECKD_MAGIC;
2726         }
2727         ccw = cqr->cpaddr;
2728         ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
2729         ccw->flags |= CCW_FLAG_SLI;
2730         ccw->count = 32;
2731         ccw->cda = (__u32)(addr_t) cqr->data;
2732         cqr->startdev = device;
2733         cqr->memdev = device;
2734         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
2735         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2736         cqr->retries = 2;       /* set retry counter to enable basic ERP */
2737         cqr->expires = 2 * HZ;
2738         cqr->buildclk = get_clock();
2739         cqr->status = DASD_CQR_FILLED;
2740
2741         rc = dasd_sleep_on_immediatly(cqr);
2742
2743         if (useglobal)
2744                 mutex_unlock(&dasd_reserve_mutex);
2745         else
2746                 dasd_sfree_request(cqr, cqr->memdev);
2747         return rc;
2748 }
2749
2750 /*
2751  * Steal lock ioctl - unconditional reserve device.
2752  * Buils a channel programm to break a device's reservation.
2753  * (unconditional reserve)
2754  */
2755 static int
2756 dasd_eckd_steal_lock(struct dasd_device *device)
2757 {
2758         struct dasd_ccw_req *cqr;
2759         int rc;
2760         struct ccw1 *ccw;
2761         int useglobal;
2762
2763         if (!capable(CAP_SYS_ADMIN))
2764                 return -EACCES;
2765
2766         useglobal = 0;
2767         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
2768         if (IS_ERR(cqr)) {
2769                 mutex_lock(&dasd_reserve_mutex);
2770                 useglobal = 1;
2771                 cqr = &dasd_reserve_req->cqr;
2772                 memset(cqr, 0, sizeof(*cqr));
2773                 memset(&dasd_reserve_req->ccw, 0,
2774                        sizeof(dasd_reserve_req->ccw));
2775                 cqr->cpaddr = &dasd_reserve_req->ccw;
2776                 cqr->data = &dasd_reserve_req->data;
2777                 cqr->magic = DASD_ECKD_MAGIC;
2778         }
2779         ccw = cqr->cpaddr;
2780         ccw->cmd_code = DASD_ECKD_CCW_SLCK;
2781         ccw->flags |= CCW_FLAG_SLI;
2782         ccw->count = 32;
2783         ccw->cda = (__u32)(addr_t) cqr->data;
2784         cqr->startdev = device;
2785         cqr->memdev = device;
2786         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
2787         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2788         cqr->retries = 2;       /* set retry counter to enable basic ERP */
2789         cqr->expires = 2 * HZ;
2790         cqr->buildclk = get_clock();
2791         cqr->status = DASD_CQR_FILLED;
2792
2793         rc = dasd_sleep_on_immediatly(cqr);
2794
2795         if (useglobal)
2796                 mutex_unlock(&dasd_reserve_mutex);
2797         else
2798                 dasd_sfree_request(cqr, cqr->memdev);
2799         return rc;
2800 }
2801
2802 /*
2803  * Read performance statistics
2804  */
2805 static int
2806 dasd_eckd_performance(struct dasd_device *device, void __user *argp)
2807 {
2808         struct dasd_psf_prssd_data *prssdp;
2809         struct dasd_rssd_perf_stats_t *stats;
2810         struct dasd_ccw_req *cqr;
2811         struct ccw1 *ccw;
2812         int rc;
2813
2814         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */  + 1 /* RSSD */,
2815                                    (sizeof(struct dasd_psf_prssd_data) +
2816                                     sizeof(struct dasd_rssd_perf_stats_t)),
2817                                    device);
2818         if (IS_ERR(cqr)) {
2819                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2820                             "Could not allocate initialization request");
2821                 return PTR_ERR(cqr);
2822         }
2823         cqr->startdev = device;
2824         cqr->memdev = device;
2825         cqr->retries = 0;
2826         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
2827         cqr->expires = 10 * HZ;
2828
2829         /* Prepare for Read Subsystem Data */
2830         prssdp = (struct dasd_psf_prssd_data *) cqr->data;
2831         memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
2832         prssdp->order = PSF_ORDER_PRSSD;
2833         prssdp->suborder = 0x01;        /* Performance Statistics */
2834         prssdp->varies[1] = 0x01;       /* Perf Statistics for the Subsystem */
2835
2836         ccw = cqr->cpaddr;
2837         ccw->cmd_code = DASD_ECKD_CCW_PSF;
2838         ccw->count = sizeof(struct dasd_psf_prssd_data);
2839         ccw->flags |= CCW_FLAG_CC;
2840         ccw->cda = (__u32)(addr_t) prssdp;
2841
2842         /* Read Subsystem Data - Performance Statistics */
2843         stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
2844         memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
2845
2846         ccw++;
2847         ccw->cmd_code = DASD_ECKD_CCW_RSSD;
2848         ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
2849         ccw->cda = (__u32)(addr_t) stats;
2850
2851         cqr->buildclk = get_clock();
2852         cqr->status = DASD_CQR_FILLED;
2853         rc = dasd_sleep_on(cqr);
2854         if (rc == 0) {
2855                 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
2856                 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
2857                 if (copy_to_user(argp, stats,
2858                                  sizeof(struct dasd_rssd_perf_stats_t)))
2859                         rc = -EFAULT;
2860         }
2861         dasd_sfree_request(cqr, cqr->memdev);
2862         return rc;
2863 }
2864
2865 /*
2866  * Get attributes (cache operations)
2867  * Returnes the cache attributes used in Define Extend (DE).
2868  */
2869 static int
2870 dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
2871 {
2872         struct dasd_eckd_private *private =
2873                 (struct dasd_eckd_private *)device->private;
2874         struct attrib_data_t attrib = private->attrib;
2875         int rc;
2876
2877         if (!capable(CAP_SYS_ADMIN))
2878                 return -EACCES;
2879         if (!argp)
2880                 return -EINVAL;
2881
2882         rc = 0;
2883         if (copy_to_user(argp, (long *) &attrib,
2884                          sizeof(struct attrib_data_t)))
2885                 rc = -EFAULT;
2886
2887         return rc;
2888 }
2889
2890 /*
2891  * Set attributes (cache operations)
2892  * Stores the attributes for cache operation to be used in Define Extend (DE).
2893  */
2894 static int
2895 dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
2896 {
2897         struct dasd_eckd_private *private =
2898                 (struct dasd_eckd_private *)device->private;
2899         struct attrib_data_t attrib;
2900
2901         if (!capable(CAP_SYS_ADMIN))
2902                 return -EACCES;
2903         if (!argp)
2904                 return -EINVAL;
2905
2906         if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
2907                 return -EFAULT;
2908         private->attrib = attrib;
2909
2910         dev_info(&device->cdev->dev,
2911                  "The DASD cache mode was set to %x (%i cylinder prestage)\n",
2912                  private->attrib.operation, private->attrib.nr_cyl);
2913         return 0;
2914 }
2915
2916 /*
2917  * Issue syscall I/O to EMC Symmetrix array.
2918  * CCWs are PSF and RSSD
2919  */
2920 static int dasd_symm_io(struct dasd_device *device, void __user *argp)
2921 {
2922         struct dasd_symmio_parms usrparm;
2923         char *psf_data, *rssd_result;
2924         struct dasd_ccw_req *cqr;
2925         struct ccw1 *ccw;
2926         char psf0, psf1;
2927         int rc;
2928
2929         if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
2930                 return -EACCES;
2931         psf0 = psf1 = 0;
2932
2933         /* Copy parms from caller */
2934         rc = -EFAULT;
2935         if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
2936                 goto out;
2937         if (is_compat_task() || sizeof(long) == 4) {
2938                 /* Make sure pointers are sane even on 31 bit. */
2939                 rc = -EINVAL;
2940                 if ((usrparm.psf_data >> 32) != 0)
2941                         goto out;
2942                 if ((usrparm.rssd_result >> 32) != 0)
2943                         goto out;
2944                 usrparm.psf_data &= 0x7fffffffULL;
2945                 usrparm.rssd_result &= 0x7fffffffULL;
2946         }
2947         /* alloc I/O data area */
2948         psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
2949         rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
2950         if (!psf_data || !rssd_result) {
2951                 rc = -ENOMEM;
2952                 goto out_free;
2953         }
2954
2955         /* get syscall header from user space */
2956         rc = -EFAULT;
2957         if (copy_from_user(psf_data,
2958                            (void __user *)(unsigned long) usrparm.psf_data,
2959                            usrparm.psf_data_len))
2960                 goto out_free;
2961         psf0 = psf_data[0];
2962         psf1 = psf_data[1];
2963
2964         /* setup CCWs for PSF + RSSD */
2965         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
2966         if (IS_ERR(cqr)) {
2967                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
2968                         "Could not allocate initialization request");
2969                 rc = PTR_ERR(cqr);
2970                 goto out_free;
2971         }
2972
2973         cqr->startdev = device;
2974         cqr->memdev = device;
2975         cqr->retries = 3;
2976         cqr->expires = 10 * HZ;
2977         cqr->buildclk = get_clock();
2978         cqr->status = DASD_CQR_FILLED;
2979
2980         /* Build the ccws */
2981         ccw = cqr->cpaddr;
2982
2983         /* PSF ccw */
2984         ccw->cmd_code = DASD_ECKD_CCW_PSF;
2985         ccw->count = usrparm.psf_data_len;
2986         ccw->flags |= CCW_FLAG_CC;
2987         ccw->cda = (__u32)(addr_t) psf_data;
2988
2989         ccw++;
2990
2991         /* RSSD ccw  */
2992         ccw->cmd_code = DASD_ECKD_CCW_RSSD;
2993         ccw->count = usrparm.rssd_result_len;
2994         ccw->flags = CCW_FLAG_SLI ;
2995         ccw->cda = (__u32)(addr_t) rssd_result;
2996
2997         rc = dasd_sleep_on(cqr);
2998         if (rc)
2999                 goto out_sfree;
3000
3001         rc = -EFAULT;
3002         if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
3003                            rssd_result, usrparm.rssd_result_len))
3004                 goto out_sfree;
3005         rc = 0;
3006
3007 out_sfree:
3008         dasd_sfree_request(cqr, cqr->memdev);
3009 out_free:
3010         kfree(rssd_result);
3011         kfree(psf_data);
3012 out:
3013         DBF_DEV_EVENT(DBF_WARNING, device,
3014                       "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
3015                       (int) psf0, (int) psf1, rc);
3016         return rc;
3017 }
3018
3019 static int
3020 dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
3021 {
3022         struct dasd_device *device = block->base;
3023
3024         switch (cmd) {
3025         case BIODASDGATTR:
3026                 return dasd_eckd_get_attrib(device, argp);
3027         case BIODASDSATTR:
3028                 return dasd_eckd_set_attrib(device, argp);
3029         case BIODASDPSRD:
3030                 return dasd_eckd_performance(device, argp);
3031         case BIODASDRLSE:
3032                 return dasd_eckd_release(device);
3033         case BIODASDRSRV:
3034                 return dasd_eckd_reserve(device);
3035         case BIODASDSLCK:
3036                 return dasd_eckd_steal_lock(device);
3037         case BIODASDSYMMIO:
3038                 return dasd_symm_io(device, argp);
3039         default:
3040                 return -ENOIOCTLCMD;
3041         }
3042 }
3043
3044 /*
3045  * Dump the range of CCWs into 'page' buffer
3046  * and return number of printed chars.
3047  */
3048 static int
3049 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
3050 {
3051         int len, count;
3052         char *datap;
3053
3054         len = 0;
3055         while (from <= to) {
3056                 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3057                                " CCW %p: %08X %08X DAT:",
3058                                from, ((int *) from)[0], ((int *) from)[1]);
3059
3060                 /* get pointer to data (consider IDALs) */
3061                 if (from->flags & CCW_FLAG_IDA)
3062                         datap = (char *) *((addr_t *) (addr_t) from->cda);
3063                 else
3064                         datap = (char *) ((addr_t) from->cda);
3065
3066                 /* dump data (max 32 bytes) */
3067                 for (count = 0; count < from->count && count < 32; count++) {
3068                         if (count % 8 == 0) len += sprintf(page + len, " ");
3069                         if (count % 4 == 0) len += sprintf(page + len, " ");
3070                         len += sprintf(page + len, "%02x", datap[count]);
3071                 }
3072                 len += sprintf(page + len, "\n");
3073                 from++;
3074         }
3075         return len;
3076 }
3077
3078 static void
3079 dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
3080                          char *reason)
3081 {
3082         u64 *sense;
3083
3084         sense = (u64 *) dasd_get_sense(irb);
3085         if (sense) {
3086                 DBF_DEV_EVENT(DBF_EMERG, device,
3087                               "%s: %s %02x%02x%02x %016llx %016llx %016llx "
3088                               "%016llx", reason,
3089                               scsw_is_tm(&irb->scsw) ? "t" : "c",
3090                               scsw_cc(&irb->scsw), scsw_cstat(&irb->scsw),
3091                               scsw_dstat(&irb->scsw), sense[0], sense[1],
3092                               sense[2], sense[3]);
3093         } else {
3094                 DBF_DEV_EVENT(DBF_EMERG, device, "%s",
3095                               "SORRY - NO VALID SENSE AVAILABLE\n");
3096         }
3097 }
3098
3099 /*
3100  * Print sense data and related channel program.
3101  * Parts are printed because printk buffer is only 1024 bytes.
3102  */
3103 static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
3104                                  struct dasd_ccw_req *req, struct irb *irb)
3105 {
3106         char *page;
3107         struct ccw1 *first, *last, *fail, *from, *to;
3108         int len, sl, sct;
3109
3110         page = (char *) get_zeroed_page(GFP_ATOMIC);
3111         if (page == NULL) {
3112                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3113                               "No memory to dump sense data\n");
3114                 return;
3115         }
3116         /* dump the sense data */
3117         len = sprintf(page,  KERN_ERR PRINTK_HEADER
3118                       " I/O status report for device %s:\n",
3119                       dev_name(&device->cdev->dev));
3120         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3121                        " in req: %p CS: 0x%02X DS: 0x%02X CC: 0x%02X RC: %d\n",
3122                        req, scsw_cstat(&irb->scsw), scsw_dstat(&irb->scsw),
3123                        scsw_cc(&irb->scsw), req ? req->intrc : 0);
3124         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3125                        " device %s: Failing CCW: %p\n",
3126                        dev_name(&device->cdev->dev),
3127                        (void *) (addr_t) irb->scsw.cmd.cpa);
3128         if (irb->esw.esw0.erw.cons) {
3129                 for (sl = 0; sl < 4; sl++) {
3130                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3131                                        " Sense(hex) %2d-%2d:",
3132                                        (8 * sl), ((8 * sl) + 7));
3133
3134                         for (sct = 0; sct < 8; sct++) {
3135                                 len += sprintf(page + len, " %02x",
3136                                                irb->ecw[8 * sl + sct]);
3137                         }
3138                         len += sprintf(page + len, "\n");
3139                 }
3140
3141                 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
3142                         /* 24 Byte Sense Data */
3143                         sprintf(page + len, KERN_ERR PRINTK_HEADER
3144                                 " 24 Byte: %x MSG %x, "
3145                                 "%s MSGb to SYSOP\n",
3146                                 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
3147                                 irb->ecw[1] & 0x10 ? "" : "no");
3148                 } else {
3149                         /* 32 Byte Sense Data */
3150                         sprintf(page + len, KERN_ERR PRINTK_HEADER
3151                                 " 32 Byte: Format: %x "
3152                                 "Exception class %x\n",
3153                                 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
3154                 }
3155         } else {
3156                 sprintf(page + len, KERN_ERR PRINTK_HEADER
3157                         " SORRY - NO VALID SENSE AVAILABLE\n");
3158         }
3159         printk("%s", page);
3160
3161         if (req) {
3162                 /* req == NULL for unsolicited interrupts */
3163                 /* dump the Channel Program (max 140 Bytes per line) */
3164                 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
3165                 first = req->cpaddr;
3166                 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
3167                 to = min(first + 6, last);
3168                 len = sprintf(page,  KERN_ERR PRINTK_HEADER
3169                               " Related CP in req: %p\n", req);
3170                 dasd_eckd_dump_ccw_range(first, to, page + len);
3171                 printk("%s", page);
3172
3173                 /* print failing CCW area (maximum 4) */
3174                 /* scsw->cda is either valid or zero  */
3175                 len = 0;
3176                 from = ++to;
3177                 fail = (struct ccw1 *)(addr_t)
3178                                 irb->scsw.cmd.cpa; /* failing CCW */
3179                 if (from <  fail - 2) {
3180                         from = fail - 2;     /* there is a gap - print header */
3181                         len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
3182                 }
3183                 to = min(fail + 1, last);
3184                 len += dasd_eckd_dump_ccw_range(from, to, page + len);
3185
3186                 /* print last CCWs (maximum 2) */
3187                 from = max(from, ++to);
3188                 if (from < last - 1) {
3189                         from = last - 1;     /* there is a gap - print header */
3190                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
3191                 }
3192                 len += dasd_eckd_dump_ccw_range(from, last, page + len);
3193                 if (len > 0)
3194                         printk("%s", page);
3195         }
3196         free_page((unsigned long) page);
3197 }
3198
3199
3200 /*
3201  * Print sense data from a tcw.
3202  */
3203 static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
3204                                  struct dasd_ccw_req *req, struct irb *irb)
3205 {
3206         char *page;
3207         int len, sl, sct, residual;
3208
3209         struct tsb *tsb;
3210         u8 *sense;
3211
3212
3213         page = (char *) get_zeroed_page(GFP_ATOMIC);
3214         if (page == NULL) {
3215                 DBF_DEV_EVENT(DBF_WARNING, device, " %s",
3216                             "No memory to dump sense data");
3217                 return;
3218         }
3219         /* dump the sense data */
3220         len = sprintf(page,  KERN_ERR PRINTK_HEADER
3221                       " I/O status report for device %s:\n",
3222                       dev_name(&device->cdev->dev));
3223         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3224                        " in req: %p CS: 0x%02X DS: 0x%02X CC: 0x%02X RC: %d "
3225                        "fcxs: 0x%02X schxs: 0x%02X\n", req,
3226                        scsw_cstat(&irb->scsw), scsw_dstat(&irb->scsw),
3227                        scsw_cc(&irb->scsw), req->intrc,
3228                        irb->scsw.tm.fcxs, irb->scsw.tm.schxs);
3229         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3230                        " device %s: Failing TCW: %p\n",
3231                        dev_name(&device->cdev->dev),
3232                        (void *) (addr_t) irb->scsw.tm.tcw);
3233
3234         tsb = NULL;
3235         sense = NULL;
3236         if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs == 0x01))
3237                 tsb = tcw_get_tsb(
3238                         (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
3239
3240         if (tsb) {
3241                 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3242                                " tsb->length %d\n", tsb->length);
3243                 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3244                                " tsb->flags %x\n", tsb->flags);
3245                 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3246                                " tsb->dcw_offset %d\n", tsb->dcw_offset);
3247                 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3248                                " tsb->count %d\n", tsb->count);
3249                 residual = tsb->count - 28;
3250                 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3251                                " residual %d\n", residual);
3252
3253                 switch (tsb->flags & 0x07) {
3254                 case 1: /* tsa_iostat */
3255                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3256                                " tsb->tsa.iostat.dev_time %d\n",
3257                                        tsb->tsa.iostat.dev_time);
3258                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3259                                " tsb->tsa.iostat.def_time %d\n",
3260                                        tsb->tsa.iostat.def_time);
3261                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3262                                " tsb->tsa.iostat.queue_time %d\n",
3263                                        tsb->tsa.iostat.queue_time);
3264                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3265                                " tsb->tsa.iostat.dev_busy_time %d\n",
3266                                        tsb->tsa.iostat.dev_busy_time);
3267                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3268                                " tsb->tsa.iostat.dev_act_time %d\n",
3269                                        tsb->tsa.iostat.dev_act_time);
3270                         sense = tsb->tsa.iostat.sense;
3271                         break;
3272                 case 2: /* ts_ddpc */
3273                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3274                                " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
3275                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3276                                " tsb->tsa.ddpc.rcq:  ");
3277                         for (sl = 0; sl < 16; sl++) {
3278                                 for (sct = 0; sct < 8; sct++) {
3279                                         len += sprintf(page + len, " %02x",
3280                                                        tsb->tsa.ddpc.rcq[sl]);
3281                                 }
3282                                 len += sprintf(page + len, "\n");
3283                         }
3284                         sense = tsb->tsa.ddpc.sense;
3285                         break;
3286                 case 3: /* tsa_intrg */
3287                         len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3288                                       " tsb->tsa.intrg.: not supportet yet \n");
3289                         break;
3290                 }
3291
3292                 if (sense) {
3293                         for (sl = 0; sl < 4; sl++) {
3294                                 len += sprintf(page + len,
3295                                                KERN_ERR PRINTK_HEADER
3296                                                " Sense(hex) %2d-%2d:",
3297                                                (8 * sl), ((8 * sl) + 7));
3298                                 for (sct = 0; sct < 8; sct++) {
3299                                         len += sprintf(page + len, " %02x",
3300                                                        sense[8 * sl + sct]);
3301                                 }
3302                                 len += sprintf(page + len, "\n");
3303                         }
3304
3305                         if (sense[27] & DASD_SENSE_BIT_0) {
3306                                 /* 24 Byte Sense Data */
3307                                 sprintf(page + len, KERN_ERR PRINTK_HEADER
3308                                         " 24 Byte: %x MSG %x, "
3309                                         "%s MSGb to SYSOP\n",
3310                                         sense[7] >> 4, sense[7] & 0x0f,
3311                                         sense[1] & 0x10 ? "" : "no");
3312                         } else {
3313                                 /* 32 Byte Sense Data */
3314                                 sprintf(page + len, KERN_ERR PRINTK_HEADER
3315                                         " 32 Byte: Format: %x "
3316                                         "Exception class %x\n",
3317                                         sense[6] & 0x0f, sense[22] >> 4);
3318                         }
3319                 } else {
3320                         sprintf(page + len, KERN_ERR PRINTK_HEADER
3321                                 " SORRY - NO VALID SENSE AVAILABLE\n");
3322                 }
3323         } else {
3324                 sprintf(page + len, KERN_ERR PRINTK_HEADER
3325                         " SORRY - NO TSB DATA AVAILABLE\n");
3326         }
3327         printk("%s", page);
3328         free_page((unsigned long) page);
3329 }
3330
3331 static void dasd_eckd_dump_sense(struct dasd_device *device,
3332                                  struct dasd_ccw_req *req, struct irb *irb)
3333 {
3334         if (req && scsw_is_tm(&req->irb.scsw))
3335                 dasd_eckd_dump_sense_tcw(device, req, irb);
3336         else
3337                 dasd_eckd_dump_sense_ccw(device, req, irb);
3338 }
3339
3340 static int dasd_eckd_pm_freeze(struct dasd_device *device)
3341 {
3342         /*
3343          * the device should be disconnected from our LCU structure
3344          * on restore we will reconnect it and reread LCU specific
3345          * information like PAV support that might have changed
3346          */
3347         dasd_alias_remove_device(device);
3348         dasd_alias_disconnect_device_from_lcu(device);
3349
3350         return 0;
3351 }
3352
3353 static int dasd_eckd_restore_device(struct dasd_device *device)
3354 {
3355         struct dasd_eckd_private *private;
3356         struct dasd_eckd_characteristics temp_rdc_data;
3357         int is_known, rc;
3358         struct dasd_uid temp_uid;
3359         unsigned long flags;
3360
3361         private = (struct dasd_eckd_private *) device->private;
3362
3363         /* Read Configuration Data */
3364         rc = dasd_eckd_read_conf(device);
3365         if (rc)
3366                 goto out_err;
3367
3368         dasd_eckd_get_uid(device, &temp_uid);
3369         /* Generate device unique id */
3370         rc = dasd_eckd_generate_uid(device);
3371         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
3372         if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
3373                 dev_err(&device->cdev->dev, "The UID of the DASD has "
3374                         "changed\n");
3375         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
3376         if (rc)
3377                 goto out_err;
3378
3379         /* register lcu with alias handling, enable PAV if this is a new lcu */
3380         is_known = dasd_alias_make_device_known_to_lcu(device);
3381         if (is_known < 0)
3382                 return is_known;
3383         if (!is_known) {
3384                 dasd_eckd_validate_server(device);
3385                 dasd_alias_lcu_setup_complete(device);
3386         } else
3387                 dasd_alias_wait_for_lcu_setup(device);
3388
3389         /* RE-Read Configuration Data */
3390         rc = dasd_eckd_read_conf(device);
3391         if (rc)
3392                 goto out_err;
3393
3394         /* Read Feature Codes */
3395         dasd_eckd_read_features(device);
3396
3397         /* Read Device Characteristics */
3398         rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
3399                                          &temp_rdc_data, 64);
3400         if (rc) {
3401                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
3402                                 "Read device characteristic failed, rc=%d", rc);
3403                 goto out_err;
3404         }
3405         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
3406         memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
3407         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
3408
3409         /* add device to alias management */
3410         dasd_alias_add_device(device);
3411
3412         return 0;
3413
3414 out_err:
3415         return -1;
3416 }
3417
3418 static int dasd_eckd_reload_device(struct dasd_device *device)
3419 {
3420         struct dasd_eckd_private *private;
3421         int rc, old_base;
3422         char print_uid[60];
3423         struct dasd_uid uid;
3424         unsigned long flags;
3425
3426         private = (struct dasd_eckd_private *) device->private;
3427
3428         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
3429         old_base = private->uid.base_unit_addr;
3430         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
3431
3432         /* Read Configuration Data */
3433         rc = dasd_eckd_read_conf(device);
3434         if (rc)
3435                 goto out_err;
3436
3437         rc = dasd_eckd_generate_uid(device);
3438         if (rc)
3439                 goto out_err;
3440         /*
3441          * update unit address configuration and
3442          * add device to alias management
3443          */
3444         dasd_alias_update_add_device(device);
3445
3446         dasd_eckd_get_uid(device, &uid);
3447
3448         if (old_base != uid.base_unit_addr) {
3449                 if (strlen(uid.vduit) > 0)
3450                         snprintf(print_uid, sizeof(print_uid),
3451                                  "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
3452                                  uid.ssid, uid.base_unit_addr, uid.vduit);
3453                 else
3454                         snprintf(print_uid, sizeof(print_uid),
3455                                  "%s.%s.%04x.%02x", uid.vendor, uid.serial,
3456                                  uid.ssid, uid.base_unit_addr);
3457
3458                 dev_info(&device->cdev->dev,
3459                          "An Alias device was reassigned to a new base device "
3460                          "with UID: %s\n", print_uid);
3461         }
3462         return 0;
3463
3464 out_err:
3465         return -1;
3466 }
3467
3468 static struct ccw_driver dasd_eckd_driver = {
3469         .name        = "dasd-eckd",
3470         .owner       = THIS_MODULE,
3471         .ids         = dasd_eckd_ids,
3472         .probe       = dasd_eckd_probe,
3473         .remove      = dasd_generic_remove,
3474         .set_offline = dasd_generic_set_offline,
3475         .set_online  = dasd_eckd_set_online,
3476         .notify      = dasd_generic_notify,
3477         .freeze      = dasd_generic_pm_freeze,
3478         .thaw        = dasd_generic_restore_device,
3479         .restore     = dasd_generic_restore_device,
3480         .uc_handler  = dasd_generic_uc_handler,
3481 };
3482
3483 /*
3484  * max_blocks is dependent on the amount of storage that is available
3485  * in the static io buffer for each device. Currently each device has
3486  * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
3487  * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
3488  * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
3489  * addition we have one define extent ccw + 16 bytes of data and one
3490  * locate record ccw + 16 bytes of data. That makes:
3491  * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
3492  * We want to fit two into the available memory so that we can immediately
3493  * start the next request if one finishes off. That makes 249.5 blocks
3494  * for one request. Give a little safety and the result is 240.
3495  */
3496 static struct dasd_discipline dasd_eckd_discipline = {
3497         .owner = THIS_MODULE,
3498         .name = "ECKD",
3499         .ebcname = "ECKD",
3500         .max_blocks = 240,
3501         .check_device = dasd_eckd_check_characteristics,
3502         .uncheck_device = dasd_eckd_uncheck_device,
3503         .do_analysis = dasd_eckd_do_analysis,
3504         .ready_to_online = dasd_eckd_ready_to_online,
3505         .online_to_ready = dasd_eckd_online_to_ready,
3506         .fill_geometry = dasd_eckd_fill_geometry,
3507         .start_IO = dasd_start_IO,
3508         .term_IO = dasd_term_IO,
3509         .handle_terminated_request = dasd_eckd_handle_terminated_request,
3510         .format_device = dasd_eckd_format_device,
3511         .erp_action = dasd_eckd_erp_action,
3512         .erp_postaction = dasd_eckd_erp_postaction,
3513         .handle_unsolicited_interrupt = dasd_eckd_handle_unsolicited_interrupt,
3514         .build_cp = dasd_eckd_build_alias_cp,
3515         .free_cp = dasd_eckd_free_alias_cp,
3516         .dump_sense = dasd_eckd_dump_sense,
3517         .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
3518         .fill_info = dasd_eckd_fill_info,
3519         .ioctl = dasd_eckd_ioctl,
3520         .freeze = dasd_eckd_pm_freeze,
3521         .restore = dasd_eckd_restore_device,
3522         .reload = dasd_eckd_reload_device,
3523         .get_uid = dasd_eckd_get_uid,
3524 };
3525
3526 static int __init
3527 dasd_eckd_init(void)
3528 {
3529         int ret;
3530
3531         ASCEBC(dasd_eckd_discipline.ebcname, 4);
3532         dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
3533                                    GFP_KERNEL | GFP_DMA);
3534         if (!dasd_reserve_req)
3535                 return -ENOMEM;
3536         ret = ccw_driver_register(&dasd_eckd_driver);
3537         if (!ret)
3538                 wait_for_device_probe();
3539         else
3540                 kfree(dasd_reserve_req);
3541         return ret;
3542 }
3543
3544 static void __exit
3545 dasd_eckd_cleanup(void)
3546 {
3547         ccw_driver_unregister(&dasd_eckd_driver);
3548         kfree(dasd_reserve_req);
3549 }
3550
3551 module_init(dasd_eckd_init);
3552 module_exit(dasd_eckd_cleanup);