Version:  2.0.40 2.2.26 2.4.37 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10

Linux/drivers/s390/block/dasd_eckd.c

  1 /*
  2  * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  3  *                  Horst Hummel <Horst.Hummel@de.ibm.com>
  4  *                  Carsten Otte <Cotte@de.ibm.com>
  5  *                  Martin Schwidefsky <schwidefsky@de.ibm.com>
  6  * Bugreports.to..: <Linux390@de.ibm.com>
  7  * Copyright IBM Corp. 1999, 2009
  8  * EMC Symmetrix ioctl Copyright EMC Corporation, 2008
  9  * Author.........: Nigel Hislop <hislop_nigel@emc.com>
 10  */
 11 
 12 #define KMSG_COMPONENT "dasd-eckd"
 13 
 14 #include <linux/stddef.h>
 15 #include <linux/kernel.h>
 16 #include <linux/slab.h>
 17 #include <linux/hdreg.h>        /* HDIO_GETGEO                      */
 18 #include <linux/bio.h>
 19 #include <linux/module.h>
 20 #include <linux/compat.h>
 21 #include <linux/init.h>
 22 #include <linux/seq_file.h>
 23 
 24 #include <asm/css_chars.h>
 25 #include <asm/debug.h>
 26 #include <asm/idals.h>
 27 #include <asm/ebcdic.h>
 28 #include <asm/io.h>
 29 #include <linux/uaccess.h>
 30 #include <asm/cio.h>
 31 #include <asm/ccwdev.h>
 32 #include <asm/itcw.h>
 33 #include <asm/schid.h>
 34 #include <asm/chpid.h>
 35 
 36 #include "dasd_int.h"
 37 #include "dasd_eckd.h"
 38 
 39 #ifdef PRINTK_HEADER
 40 #undef PRINTK_HEADER
 41 #endif                          /* PRINTK_HEADER */
 42 #define PRINTK_HEADER "dasd(eckd):"
 43 
 44 #define ECKD_C0(i) (i->home_bytes)
 45 #define ECKD_F(i) (i->formula)
 46 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
 47                     (i->factors.f_0x02.f1))
 48 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
 49                     (i->factors.f_0x02.f2))
 50 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
 51                     (i->factors.f_0x02.f3))
 52 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
 53 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
 54 #define ECKD_F6(i) (i->factor6)
 55 #define ECKD_F7(i) (i->factor7)
 56 #define ECKD_F8(i) (i->factor8)
 57 
 58 /*
 59  * raw track access always map to 64k in memory
 60  * so it maps to 16 blocks of 4k per track
 61  */
 62 #define DASD_RAW_BLOCK_PER_TRACK 16
 63 #define DASD_RAW_BLOCKSIZE 4096
 64 /* 64k are 128 x 512 byte sectors  */
 65 #define DASD_RAW_SECTORS_PER_TRACK 128
 66 
 67 MODULE_LICENSE("GPL");
 68 
 69 static struct dasd_discipline dasd_eckd_discipline;
 70 
 71 /* The ccw bus type uses this table to find devices that it sends to
 72  * dasd_eckd_probe */
 73 static struct ccw_device_id dasd_eckd_ids[] = {
 74         { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
 75         { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
 76         { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info = 0x3},
 77         { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
 78         { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
 79         { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
 80         { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
 81         { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
 82         { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
 83         { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
 84         { /* end of list */ },
 85 };
 86 
 87 MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
 88 
 89 static struct ccw_driver dasd_eckd_driver; /* see below */
 90 
 91 static void *rawpadpage;
 92 
 93 #define INIT_CQR_OK 0
 94 #define INIT_CQR_UNFORMATTED 1
 95 #define INIT_CQR_ERROR 2
 96 
 97 /* emergency request for reserve/release */
 98 static struct {
 99         struct dasd_ccw_req cqr;
100         struct ccw1 ccw;
101         char data[32];
102 } *dasd_reserve_req;
103 static DEFINE_MUTEX(dasd_reserve_mutex);
104 
105 /* definitions for the path verification worker */
106 struct path_verification_work_data {
107         struct work_struct worker;
108         struct dasd_device *device;
109         struct dasd_ccw_req cqr;
110         struct ccw1 ccw;
111         __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE];
112         int isglobal;
113         __u8 tbvpm;
114 };
115 static struct path_verification_work_data *path_verification_worker;
116 static DEFINE_MUTEX(dasd_path_verification_mutex);
117 
118 struct check_attention_work_data {
119         struct work_struct worker;
120         struct dasd_device *device;
121         __u8 lpum;
122 };
123 
124 static int prepare_itcw(struct itcw *, unsigned int, unsigned int, int,
125                         struct dasd_device *, struct dasd_device *,
126                         unsigned int, int, unsigned int, unsigned int,
127                         unsigned int, unsigned int);
128 
129 /* initial attempt at a probe function. this can be simplified once
130  * the other detection code is gone */
131 static int
132 dasd_eckd_probe (struct ccw_device *cdev)
133 {
134         int ret;
135 
136         /* set ECKD specific ccw-device options */
137         ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE |
138                                      CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH);
139         if (ret) {
140                 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
141                                 "dasd_eckd_probe: could not set "
142                                 "ccw-device options");
143                 return ret;
144         }
145         ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
146         return ret;
147 }
148 
149 static int
150 dasd_eckd_set_online(struct ccw_device *cdev)
151 {
152         return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
153 }
154 
155 static const int sizes_trk0[] = { 28, 148, 84 };
156 #define LABEL_SIZE 140
157 
158 /* head and record addresses of count_area read in analysis ccw */
159 static const int count_area_head[] = { 0, 0, 0, 0, 2 };
160 static const int count_area_rec[] = { 1, 2, 3, 4, 1 };
161 
162 static inline unsigned int
163 round_up_multiple(unsigned int no, unsigned int mult)
164 {
165         int rem = no % mult;
166         return (rem ? no - rem + mult : no);
167 }
168 
169 static inline unsigned int
170 ceil_quot(unsigned int d1, unsigned int d2)
171 {
172         return (d1 + (d2 - 1)) / d2;
173 }
174 
175 static unsigned int
176 recs_per_track(struct dasd_eckd_characteristics * rdc,
177                unsigned int kl, unsigned int dl)
178 {
179         int dn, kn;
180 
181         switch (rdc->dev_type) {
182         case 0x3380:
183                 if (kl)
184                         return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
185                                        ceil_quot(dl + 12, 32));
186                 else
187                         return 1499 / (15 + ceil_quot(dl + 12, 32));
188         case 0x3390:
189                 dn = ceil_quot(dl + 6, 232) + 1;
190                 if (kl) {
191                         kn = ceil_quot(kl + 6, 232) + 1;
192                         return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
193                                        9 + ceil_quot(dl + 6 * dn, 34));
194                 } else
195                         return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
196         case 0x9345:
197                 dn = ceil_quot(dl + 6, 232) + 1;
198                 if (kl) {
199                         kn = ceil_quot(kl + 6, 232) + 1;
200                         return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
201                                        ceil_quot(dl + 6 * dn, 34));
202                 } else
203                         return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
204         }
205         return 0;
206 }
207 
208 static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
209 {
210         geo->cyl = (__u16) cyl;
211         geo->head = cyl >> 16;
212         geo->head <<= 4;
213         geo->head |= head;
214 }
215 
216 static int
217 check_XRC (struct ccw1         *de_ccw,
218            struct DE_eckd_data *data,
219            struct dasd_device  *device)
220 {
221         struct dasd_eckd_private *private = device->private;
222         int rc;
223 
224         if (!private->rdc_data.facilities.XRC_supported)
225                 return 0;
226 
227         /* switch on System Time Stamp - needed for XRC Support */
228         data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid'   */
229         data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
230 
231         rc = get_phys_clock(&data->ep_sys_time);
232         /* Ignore return code if sync clock is switched off. */
233         if (rc == -EOPNOTSUPP || rc == -EACCES)
234                 rc = 0;
235 
236         de_ccw->count = sizeof(struct DE_eckd_data);
237         de_ccw->flags |= CCW_FLAG_SLI;
238         return rc;
239 }
240 
241 static int
242 define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
243               unsigned int totrk, int cmd, struct dasd_device *device)
244 {
245         struct dasd_eckd_private *private = device->private;
246         u32 begcyl, endcyl;
247         u16 heads, beghead, endhead;
248         int rc = 0;
249 
250         ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
251         ccw->flags = 0;
252         ccw->count = 16;
253         ccw->cda = (__u32) __pa(data);
254 
255         memset(data, 0, sizeof(struct DE_eckd_data));
256         switch (cmd) {
257         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
258         case DASD_ECKD_CCW_READ_RECORD_ZERO:
259         case DASD_ECKD_CCW_READ:
260         case DASD_ECKD_CCW_READ_MT:
261         case DASD_ECKD_CCW_READ_CKD:
262         case DASD_ECKD_CCW_READ_CKD_MT:
263         case DASD_ECKD_CCW_READ_KD:
264         case DASD_ECKD_CCW_READ_KD_MT:
265                 data->mask.perm = 0x1;
266                 data->attributes.operation = private->attrib.operation;
267                 break;
268         case DASD_ECKD_CCW_READ_COUNT:
269                 data->mask.perm = 0x1;
270                 data->attributes.operation = DASD_BYPASS_CACHE;
271                 break;
272         case DASD_ECKD_CCW_WRITE:
273         case DASD_ECKD_CCW_WRITE_MT:
274         case DASD_ECKD_CCW_WRITE_KD:
275         case DASD_ECKD_CCW_WRITE_KD_MT:
276                 data->mask.perm = 0x02;
277                 data->attributes.operation = private->attrib.operation;
278                 rc = check_XRC (ccw, data, device);
279                 break;
280         case DASD_ECKD_CCW_WRITE_CKD:
281         case DASD_ECKD_CCW_WRITE_CKD_MT:
282                 data->attributes.operation = DASD_BYPASS_CACHE;
283                 rc = check_XRC (ccw, data, device);
284                 break;
285         case DASD_ECKD_CCW_ERASE:
286         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
287         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
288                 data->mask.perm = 0x3;
289                 data->mask.auth = 0x1;
290                 data->attributes.operation = DASD_BYPASS_CACHE;
291                 rc = check_XRC (ccw, data, device);
292                 break;
293         default:
294                 dev_err(&device->cdev->dev,
295                         "0x%x is not a known command\n", cmd);
296                 break;
297         }
298 
299         data->attributes.mode = 0x3;    /* ECKD */
300 
301         if ((private->rdc_data.cu_type == 0x2105 ||
302              private->rdc_data.cu_type == 0x2107 ||
303              private->rdc_data.cu_type == 0x1750)
304             && !(private->uses_cdl && trk < 2))
305                 data->ga_extended |= 0x40; /* Regular Data Format Mode */
306 
307         heads = private->rdc_data.trk_per_cyl;
308         begcyl = trk / heads;
309         beghead = trk % heads;
310         endcyl = totrk / heads;
311         endhead = totrk % heads;
312 
313         /* check for sequential prestage - enhance cylinder range */
314         if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
315             data->attributes.operation == DASD_SEQ_ACCESS) {
316 
317                 if (endcyl + private->attrib.nr_cyl < private->real_cyl)
318                         endcyl += private->attrib.nr_cyl;
319                 else
320                         endcyl = (private->real_cyl - 1);
321         }
322 
323         set_ch_t(&data->beg_ext, begcyl, beghead);
324         set_ch_t(&data->end_ext, endcyl, endhead);
325         return rc;
326 }
327 
328 static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
329                                struct dasd_device  *device)
330 {
331         struct dasd_eckd_private *private = device->private;
332         int rc;
333 
334         if (!private->rdc_data.facilities.XRC_supported)
335                 return 0;
336 
337         /* switch on System Time Stamp - needed for XRC Support */
338         pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid'   */
339         pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */
340         pfxdata->validity.time_stamp = 1;           /* 'Time Stamp Valid'   */
341 
342         rc = get_phys_clock(&pfxdata->define_extent.ep_sys_time);
343         /* Ignore return code if sync clock is switched off. */
344         if (rc == -EOPNOTSUPP || rc == -EACCES)
345                 rc = 0;
346         return rc;
347 }
348 
349 static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk,
350                           unsigned int rec_on_trk, int count, int cmd,
351                           struct dasd_device *device, unsigned int reclen,
352                           unsigned int tlf)
353 {
354         struct dasd_eckd_private *private = device->private;
355         int sector;
356         int dn, d;
357 
358         memset(data, 0, sizeof(*data));
359         sector = 0;
360         if (rec_on_trk) {
361                 switch (private->rdc_data.dev_type) {
362                 case 0x3390:
363                         dn = ceil_quot(reclen + 6, 232);
364                         d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
365                         sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
366                         break;
367                 case 0x3380:
368                         d = 7 + ceil_quot(reclen + 12, 32);
369                         sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
370                         break;
371                 }
372         }
373         data->sector = sector;
374         /* note: meaning of count depends on the operation
375          *       for record based I/O it's the number of records, but for
376          *       track based I/O it's the number of tracks
377          */
378         data->count = count;
379         switch (cmd) {
380         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
381                 data->operation.orientation = 0x3;
382                 data->operation.operation = 0x03;
383                 break;
384         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
385                 data->operation.orientation = 0x3;
386                 data->operation.operation = 0x16;
387                 break;
388         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
389                 data->operation.orientation = 0x1;
390                 data->operation.operation = 0x03;
391                 data->count++;
392                 break;
393         case DASD_ECKD_CCW_READ_RECORD_ZERO:
394                 data->operation.orientation = 0x3;
395                 data->operation.operation = 0x16;
396                 data->count++;
397                 break;
398         case DASD_ECKD_CCW_WRITE:
399         case DASD_ECKD_CCW_WRITE_MT:
400         case DASD_ECKD_CCW_WRITE_KD:
401         case DASD_ECKD_CCW_WRITE_KD_MT:
402                 data->auxiliary.length_valid = 0x1;
403                 data->length = reclen;
404                 data->operation.operation = 0x01;
405                 break;
406         case DASD_ECKD_CCW_WRITE_CKD:
407         case DASD_ECKD_CCW_WRITE_CKD_MT:
408                 data->auxiliary.length_valid = 0x1;
409                 data->length = reclen;
410                 data->operation.operation = 0x03;
411                 break;
412         case DASD_ECKD_CCW_WRITE_FULL_TRACK:
413                 data->operation.orientation = 0x0;
414                 data->operation.operation = 0x3F;
415                 data->extended_operation = 0x11;
416                 data->length = 0;
417                 data->extended_parameter_length = 0x02;
418                 if (data->count > 8) {
419                         data->extended_parameter[0] = 0xFF;
420                         data->extended_parameter[1] = 0xFF;
421                         data->extended_parameter[1] <<= (16 - count);
422                 } else {
423                         data->extended_parameter[0] = 0xFF;
424                         data->extended_parameter[0] <<= (8 - count);
425                         data->extended_parameter[1] = 0x00;
426                 }
427                 data->sector = 0xFF;
428                 break;
429         case DASD_ECKD_CCW_WRITE_TRACK_DATA:
430                 data->auxiliary.length_valid = 0x1;
431                 data->length = reclen;  /* not tlf, as one might think */
432                 data->operation.operation = 0x3F;
433                 data->extended_operation = 0x23;
434                 break;
435         case DASD_ECKD_CCW_READ:
436         case DASD_ECKD_CCW_READ_MT:
437         case DASD_ECKD_CCW_READ_KD:
438         case DASD_ECKD_CCW_READ_KD_MT:
439                 data->auxiliary.length_valid = 0x1;
440                 data->length = reclen;
441                 data->operation.operation = 0x06;
442                 break;
443         case DASD_ECKD_CCW_READ_CKD:
444         case DASD_ECKD_CCW_READ_CKD_MT:
445                 data->auxiliary.length_valid = 0x1;
446                 data->length = reclen;
447                 data->operation.operation = 0x16;
448                 break;
449         case DASD_ECKD_CCW_READ_COUNT:
450                 data->operation.operation = 0x06;
451                 break;
452         case DASD_ECKD_CCW_READ_TRACK:
453                 data->operation.orientation = 0x1;
454                 data->operation.operation = 0x0C;
455                 data->extended_parameter_length = 0;
456                 data->sector = 0xFF;
457                 break;
458         case DASD_ECKD_CCW_READ_TRACK_DATA:
459                 data->auxiliary.length_valid = 0x1;
460                 data->length = tlf;
461                 data->operation.operation = 0x0C;
462                 break;
463         case DASD_ECKD_CCW_ERASE:
464                 data->length = reclen;
465                 data->auxiliary.length_valid = 0x1;
466                 data->operation.operation = 0x0b;
467                 break;
468         default:
469                 DBF_DEV_EVENT(DBF_ERR, device,
470                             "fill LRE unknown opcode 0x%x", cmd);
471                 BUG();
472         }
473         set_ch_t(&data->seek_addr,
474                  trk / private->rdc_data.trk_per_cyl,
475                  trk % private->rdc_data.trk_per_cyl);
476         data->search_arg.cyl = data->seek_addr.cyl;
477         data->search_arg.head = data->seek_addr.head;
478         data->search_arg.record = rec_on_trk;
479 }
480 
481 static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
482                       unsigned int trk, unsigned int totrk, int cmd,
483                       struct dasd_device *basedev, struct dasd_device *startdev,
484                       unsigned char format, unsigned int rec_on_trk, int count,
485                       unsigned int blksize, unsigned int tlf)
486 {
487         struct dasd_eckd_private *basepriv, *startpriv;
488         struct DE_eckd_data *dedata;
489         struct LRE_eckd_data *lredata;
490         u32 begcyl, endcyl;
491         u16 heads, beghead, endhead;
492         int rc = 0;
493 
494         basepriv = basedev->private;
495         startpriv = startdev->private;
496         dedata = &pfxdata->define_extent;
497         lredata = &pfxdata->locate_record;
498 
499         ccw->cmd_code = DASD_ECKD_CCW_PFX;
500         ccw->flags = 0;
501         if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) {
502                 ccw->count = sizeof(*pfxdata) + 2;
503                 ccw->cda = (__u32) __pa(pfxdata);
504                 memset(pfxdata, 0, sizeof(*pfxdata) + 2);
505         } else {
506                 ccw->count = sizeof(*pfxdata);
507                 ccw->cda = (__u32) __pa(pfxdata);
508                 memset(pfxdata, 0, sizeof(*pfxdata));
509         }
510 
511         /* prefix data */
512         if (format > 1) {
513                 DBF_DEV_EVENT(DBF_ERR, basedev,
514                               "PFX LRE unknown format 0x%x", format);
515                 BUG();
516                 return -EINVAL;
517         }
518         pfxdata->format = format;
519         pfxdata->base_address = basepriv->ned->unit_addr;
520         pfxdata->base_lss = basepriv->ned->ID;
521         pfxdata->validity.define_extent = 1;
522 
523         /* private uid is kept up to date, conf_data may be outdated */
524         if (startpriv->uid.type != UA_BASE_DEVICE) {
525                 pfxdata->validity.verify_base = 1;
526                 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
527                         pfxdata->validity.hyper_pav = 1;
528         }
529 
530         /* define extend data (mostly)*/
531         switch (cmd) {
532         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
533         case DASD_ECKD_CCW_READ_RECORD_ZERO:
534         case DASD_ECKD_CCW_READ:
535         case DASD_ECKD_CCW_READ_MT:
536         case DASD_ECKD_CCW_READ_CKD:
537         case DASD_ECKD_CCW_READ_CKD_MT:
538         case DASD_ECKD_CCW_READ_KD:
539         case DASD_ECKD_CCW_READ_KD_MT:
540                 dedata->mask.perm = 0x1;
541                 dedata->attributes.operation = basepriv->attrib.operation;
542                 break;
543         case DASD_ECKD_CCW_READ_COUNT:
544                 dedata->mask.perm = 0x1;
545                 dedata->attributes.operation = DASD_BYPASS_CACHE;
546                 break;
547         case DASD_ECKD_CCW_READ_TRACK:
548         case DASD_ECKD_CCW_READ_TRACK_DATA:
549                 dedata->mask.perm = 0x1;
550                 dedata->attributes.operation = basepriv->attrib.operation;
551                 dedata->blk_size = 0;
552                 break;
553         case DASD_ECKD_CCW_WRITE:
554         case DASD_ECKD_CCW_WRITE_MT:
555         case DASD_ECKD_CCW_WRITE_KD:
556         case DASD_ECKD_CCW_WRITE_KD_MT:
557                 dedata->mask.perm = 0x02;
558                 dedata->attributes.operation = basepriv->attrib.operation;
559                 rc = check_XRC_on_prefix(pfxdata, basedev);
560                 break;
561         case DASD_ECKD_CCW_WRITE_CKD:
562         case DASD_ECKD_CCW_WRITE_CKD_MT:
563                 dedata->attributes.operation = DASD_BYPASS_CACHE;
564                 rc = check_XRC_on_prefix(pfxdata, basedev);
565                 break;
566         case DASD_ECKD_CCW_ERASE:
567         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
568         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
569                 dedata->mask.perm = 0x3;
570                 dedata->mask.auth = 0x1;
571                 dedata->attributes.operation = DASD_BYPASS_CACHE;
572                 rc = check_XRC_on_prefix(pfxdata, basedev);
573                 break;
574         case DASD_ECKD_CCW_WRITE_FULL_TRACK:
575                 dedata->mask.perm = 0x03;
576                 dedata->attributes.operation = basepriv->attrib.operation;
577                 dedata->blk_size = 0;
578                 break;
579         case DASD_ECKD_CCW_WRITE_TRACK_DATA:
580                 dedata->mask.perm = 0x02;
581                 dedata->attributes.operation = basepriv->attrib.operation;
582                 dedata->blk_size = blksize;
583                 rc = check_XRC_on_prefix(pfxdata, basedev);
584                 break;
585         default:
586                 DBF_DEV_EVENT(DBF_ERR, basedev,
587                             "PFX LRE unknown opcode 0x%x", cmd);
588                 BUG();
589                 return -EINVAL;
590         }
591 
592         dedata->attributes.mode = 0x3;  /* ECKD */
593 
594         if ((basepriv->rdc_data.cu_type == 0x2105 ||
595              basepriv->rdc_data.cu_type == 0x2107 ||
596              basepriv->rdc_data.cu_type == 0x1750)
597             && !(basepriv->uses_cdl && trk < 2))
598                 dedata->ga_extended |= 0x40; /* Regular Data Format Mode */
599 
600         heads = basepriv->rdc_data.trk_per_cyl;
601         begcyl = trk / heads;
602         beghead = trk % heads;
603         endcyl = totrk / heads;
604         endhead = totrk % heads;
605 
606         /* check for sequential prestage - enhance cylinder range */
607         if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
608             dedata->attributes.operation == DASD_SEQ_ACCESS) {
609 
610                 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
611                         endcyl += basepriv->attrib.nr_cyl;
612                 else
613                         endcyl = (basepriv->real_cyl - 1);
614         }
615 
616         set_ch_t(&dedata->beg_ext, begcyl, beghead);
617         set_ch_t(&dedata->end_ext, endcyl, endhead);
618 
619         if (format == 1) {
620                 fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
621                               basedev, blksize, tlf);
622         }
623 
624         return rc;
625 }
626 
627 static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
628                   unsigned int trk, unsigned int totrk, int cmd,
629                   struct dasd_device *basedev, struct dasd_device *startdev)
630 {
631         return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
632                           0, 0, 0, 0, 0);
633 }
634 
635 static void
636 locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
637               unsigned int rec_on_trk, int no_rec, int cmd,
638               struct dasd_device * device, int reclen)
639 {
640         struct dasd_eckd_private *private = device->private;
641         int sector;
642         int dn, d;
643 
644         DBF_DEV_EVENT(DBF_INFO, device,
645                   "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
646                   trk, rec_on_trk, no_rec, cmd, reclen);
647 
648         ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
649         ccw->flags = 0;
650         ccw->count = 16;
651         ccw->cda = (__u32) __pa(data);
652 
653         memset(data, 0, sizeof(struct LO_eckd_data));
654         sector = 0;
655         if (rec_on_trk) {
656                 switch (private->rdc_data.dev_type) {
657                 case 0x3390:
658                         dn = ceil_quot(reclen + 6, 232);
659                         d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
660                         sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
661                         break;
662                 case 0x3380:
663                         d = 7 + ceil_quot(reclen + 12, 32);
664                         sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
665                         break;
666                 }
667         }
668         data->sector = sector;
669         data->count = no_rec;
670         switch (cmd) {
671         case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
672                 data->operation.orientation = 0x3;
673                 data->operation.operation = 0x03;
674                 break;
675         case DASD_ECKD_CCW_READ_HOME_ADDRESS:
676                 data->operation.orientation = 0x3;
677                 data->operation.operation = 0x16;
678                 break;
679         case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
680                 data->operation.orientation = 0x1;
681                 data->operation.operation = 0x03;
682                 data->count++;
683                 break;
684         case DASD_ECKD_CCW_READ_RECORD_ZERO:
685                 data->operation.orientation = 0x3;
686                 data->operation.operation = 0x16;
687                 data->count++;
688                 break;
689         case DASD_ECKD_CCW_WRITE:
690         case DASD_ECKD_CCW_WRITE_MT:
691         case DASD_ECKD_CCW_WRITE_KD:
692         case DASD_ECKD_CCW_WRITE_KD_MT:
693                 data->auxiliary.last_bytes_used = 0x1;
694                 data->length = reclen;
695                 data->operation.operation = 0x01;
696                 break;
697         case DASD_ECKD_CCW_WRITE_CKD:
698         case DASD_ECKD_CCW_WRITE_CKD_MT:
699                 data->auxiliary.last_bytes_used = 0x1;
700                 data->length = reclen;
701                 data->operation.operation = 0x03;
702                 break;
703         case DASD_ECKD_CCW_READ:
704         case DASD_ECKD_CCW_READ_MT:
705         case DASD_ECKD_CCW_READ_KD:
706         case DASD_ECKD_CCW_READ_KD_MT:
707                 data->auxiliary.last_bytes_used = 0x1;
708                 data->length = reclen;
709                 data->operation.operation = 0x06;
710                 break;
711         case DASD_ECKD_CCW_READ_CKD:
712         case DASD_ECKD_CCW_READ_CKD_MT:
713                 data->auxiliary.last_bytes_used = 0x1;
714                 data->length = reclen;
715                 data->operation.operation = 0x16;
716                 break;
717         case DASD_ECKD_CCW_READ_COUNT:
718                 data->operation.operation = 0x06;
719                 break;
720         case DASD_ECKD_CCW_ERASE:
721                 data->length = reclen;
722                 data->auxiliary.last_bytes_used = 0x1;
723                 data->operation.operation = 0x0b;
724                 break;
725         default:
726                 DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
727                               "opcode 0x%x", cmd);
728         }
729         set_ch_t(&data->seek_addr,
730                  trk / private->rdc_data.trk_per_cyl,
731                  trk % private->rdc_data.trk_per_cyl);
732         data->search_arg.cyl = data->seek_addr.cyl;
733         data->search_arg.head = data->seek_addr.head;
734         data->search_arg.record = rec_on_trk;
735 }
736 
737 /*
738  * Returns 1 if the block is one of the special blocks that needs
739  * to get read/written with the KD variant of the command.
740  * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
741  * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
742  * Luckily the KD variants differ only by one bit (0x08) from the
743  * normal variant. So don't wonder about code like:
744  * if (dasd_eckd_cdl_special(blk_per_trk, recid))
745  *         ccw->cmd_code |= 0x8;
746  */
747 static inline int
748 dasd_eckd_cdl_special(int blk_per_trk, int recid)
749 {
750         if (recid < 3)
751                 return 1;
752         if (recid < blk_per_trk)
753                 return 0;
754         if (recid < 2 * blk_per_trk)
755                 return 1;
756         return 0;
757 }
758 
759 /*
760  * Returns the record size for the special blocks of the cdl format.
761  * Only returns something useful if dasd_eckd_cdl_special is true
762  * for the recid.
763  */
764 static inline int
765 dasd_eckd_cdl_reclen(int recid)
766 {
767         if (recid < 3)
768                 return sizes_trk0[recid];
769         return LABEL_SIZE;
770 }
771 /* create unique id from private structure. */
772 static void create_uid(struct dasd_eckd_private *private)
773 {
774         int count;
775         struct dasd_uid *uid;
776 
777         uid = &private->uid;
778         memset(uid, 0, sizeof(struct dasd_uid));
779         memcpy(uid->vendor, private->ned->HDA_manufacturer,
780                sizeof(uid->vendor) - 1);
781         EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
782         memcpy(uid->serial, private->ned->HDA_location,
783                sizeof(uid->serial) - 1);
784         EBCASC(uid->serial, sizeof(uid->serial) - 1);
785         uid->ssid = private->gneq->subsystemID;
786         uid->real_unit_addr = private->ned->unit_addr;
787         if (private->sneq) {
788                 uid->type = private->sneq->sua_flags;
789                 if (uid->type == UA_BASE_PAV_ALIAS)
790                         uid->base_unit_addr = private->sneq->base_unit_addr;
791         } else {
792                 uid->type = UA_BASE_DEVICE;
793         }
794         if (private->vdsneq) {
795                 for (count = 0; count < 16; count++) {
796                         sprintf(uid->vduit+2*count, "%02x",
797                                 private->vdsneq->uit[count]);
798                 }
799         }
800 }
801 
802 /*
803  * Generate device unique id that specifies the physical device.
804  */
805 static int dasd_eckd_generate_uid(struct dasd_device *device)
806 {
807         struct dasd_eckd_private *private = device->private;
808         unsigned long flags;
809 
810         if (!private)
811                 return -ENODEV;
812         if (!private->ned || !private->gneq)
813                 return -ENODEV;
814         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
815         create_uid(private);
816         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
817         return 0;
818 }
819 
820 static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
821 {
822         struct dasd_eckd_private *private = device->private;
823         unsigned long flags;
824 
825         if (private) {
826                 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
827                 *uid = private->uid;
828                 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
829                 return 0;
830         }
831         return -EINVAL;
832 }
833 
834 /*
835  * compare device UID with data of a given dasd_eckd_private structure
836  * return 0 for match
837  */
838 static int dasd_eckd_compare_path_uid(struct dasd_device *device,
839                                       struct dasd_eckd_private *private)
840 {
841         struct dasd_uid device_uid;
842 
843         create_uid(private);
844         dasd_eckd_get_uid(device, &device_uid);
845 
846         return memcmp(&device_uid, &private->uid, sizeof(struct dasd_uid));
847 }
848 
849 static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device,
850                                    struct dasd_ccw_req *cqr,
851                                    __u8 *rcd_buffer,
852                                    __u8 lpm)
853 {
854         struct ccw1 *ccw;
855         /*
856          * buffer has to start with EBCDIC "V1.0" to show
857          * support for virtual device SNEQ
858          */
859         rcd_buffer[0] = 0xE5;
860         rcd_buffer[1] = 0xF1;
861         rcd_buffer[2] = 0x4B;
862         rcd_buffer[3] = 0xF0;
863 
864         ccw = cqr->cpaddr;
865         ccw->cmd_code = DASD_ECKD_CCW_RCD;
866         ccw->flags = 0;
867         ccw->cda = (__u32)(addr_t)rcd_buffer;
868         ccw->count = DASD_ECKD_RCD_DATA_SIZE;
869         cqr->magic = DASD_ECKD_MAGIC;
870 
871         cqr->startdev = device;
872         cqr->memdev = device;
873         cqr->block = NULL;
874         cqr->expires = 10*HZ;
875         cqr->lpm = lpm;
876         cqr->retries = 256;
877         cqr->buildclk = get_tod_clock();
878         cqr->status = DASD_CQR_FILLED;
879         set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
880 }
881 
882 /*
883  * Wakeup helper for read_conf
884  * if the cqr is not done and needs some error recovery
885  * the buffer has to be re-initialized with the EBCDIC "V1.0"
886  * to show support for virtual device SNEQ
887  */
888 static void read_conf_cb(struct dasd_ccw_req *cqr, void *data)
889 {
890         struct ccw1 *ccw;
891         __u8 *rcd_buffer;
892 
893         if (cqr->status !=  DASD_CQR_DONE) {
894                 ccw = cqr->cpaddr;
895                 rcd_buffer = (__u8 *)((addr_t) ccw->cda);
896                 memset(rcd_buffer, 0, sizeof(*rcd_buffer));
897 
898                 rcd_buffer[0] = 0xE5;
899                 rcd_buffer[1] = 0xF1;
900                 rcd_buffer[2] = 0x4B;
901                 rcd_buffer[3] = 0xF0;
902         }
903         dasd_wakeup_cb(cqr, data);
904 }
905 
906 static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
907                                            struct dasd_ccw_req *cqr,
908                                            __u8 *rcd_buffer,
909                                            __u8 lpm)
910 {
911         struct ciw *ciw;
912         int rc;
913         /*
914          * sanity check: scan for RCD command in extended SenseID data
915          * some devices do not support RCD
916          */
917         ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
918         if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD)
919                 return -EOPNOTSUPP;
920 
921         dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm);
922         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
923         set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
924         cqr->retries = 5;
925         cqr->callback = read_conf_cb;
926         rc = dasd_sleep_on_immediatly(cqr);
927         return rc;
928 }
929 
930 static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
931                                    void **rcd_buffer,
932                                    int *rcd_buffer_size, __u8 lpm)
933 {
934         struct ciw *ciw;
935         char *rcd_buf = NULL;
936         int ret;
937         struct dasd_ccw_req *cqr;
938 
939         /*
940          * sanity check: scan for RCD command in extended SenseID data
941          * some devices do not support RCD
942          */
943         ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
944         if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) {
945                 ret = -EOPNOTSUPP;
946                 goto out_error;
947         }
948         rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA);
949         if (!rcd_buf) {
950                 ret = -ENOMEM;
951                 goto out_error;
952         }
953         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */,
954                                    0, /* use rcd_buf as data ara */
955                                    device);
956         if (IS_ERR(cqr)) {
957                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
958                               "Could not allocate RCD request");
959                 ret = -ENOMEM;
960                 goto out_error;
961         }
962         dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm);
963         cqr->callback = read_conf_cb;
964         ret = dasd_sleep_on(cqr);
965         /*
966          * on success we update the user input parms
967          */
968         dasd_sfree_request(cqr, cqr->memdev);
969         if (ret)
970                 goto out_error;
971 
972         *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE;
973         *rcd_buffer = rcd_buf;
974         return 0;
975 out_error:
976         kfree(rcd_buf);
977         *rcd_buffer = NULL;
978         *rcd_buffer_size = 0;
979         return ret;
980 }
981 
982 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
983 {
984 
985         struct dasd_sneq *sneq;
986         int i, count;
987 
988         private->ned = NULL;
989         private->sneq = NULL;
990         private->vdsneq = NULL;
991         private->gneq = NULL;
992         count = private->conf_len / sizeof(struct dasd_sneq);
993         sneq = (struct dasd_sneq *)private->conf_data;
994         for (i = 0; i < count; ++i) {
995                 if (sneq->flags.identifier == 1 && sneq->format == 1)
996                         private->sneq = sneq;
997                 else if (sneq->flags.identifier == 1 && sneq->format == 4)
998                         private->vdsneq = (struct vd_sneq *)sneq;
999                 else if (sneq->flags.identifier == 2)
1000                         private->gneq = (struct dasd_gneq *)sneq;
1001                 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
1002                         private->ned = (struct dasd_ned *)sneq;
1003                 sneq++;
1004         }
1005         if (!private->ned || !private->gneq) {
1006                 private->ned = NULL;
1007                 private->sneq = NULL;
1008                 private->vdsneq = NULL;
1009                 private->gneq = NULL;
1010                 return -EINVAL;
1011         }
1012         return 0;
1013 
1014 };
1015 
1016 static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
1017 {
1018         struct dasd_gneq *gneq;
1019         int i, count, found;
1020 
1021         count = conf_len / sizeof(*gneq);
1022         gneq = (struct dasd_gneq *)conf_data;
1023         found = 0;
1024         for (i = 0; i < count; ++i) {
1025                 if (gneq->flags.identifier == 2) {
1026                         found = 1;
1027                         break;
1028                 }
1029                 gneq++;
1030         }
1031         if (found)
1032                 return ((char *)gneq)[18] & 0x07;
1033         else
1034                 return 0;
1035 }
1036 
1037 static void dasd_eckd_clear_conf_data(struct dasd_device *device)
1038 {
1039         struct dasd_eckd_private *private = device->private;
1040         int i;
1041 
1042         private->conf_data = NULL;
1043         private->conf_len = 0;
1044         for (i = 0; i < 8; i++) {
1045                 kfree(device->path[i].conf_data);
1046                 device->path[i].conf_data = NULL;
1047                 device->path[i].cssid = 0;
1048                 device->path[i].ssid = 0;
1049                 device->path[i].chpid = 0;
1050         }
1051 }
1052 
1053 
1054 static int dasd_eckd_read_conf(struct dasd_device *device)
1055 {
1056         void *conf_data;
1057         int conf_len, conf_data_saved;
1058         int rc, path_err, pos;
1059         __u8 lpm, opm;
1060         struct dasd_eckd_private *private, path_private;
1061         struct dasd_uid *uid;
1062         char print_path_uid[60], print_device_uid[60];
1063         struct channel_path_desc *chp_desc;
1064         struct subchannel_id sch_id;
1065 
1066         private = device->private;
1067         opm = ccw_device_get_path_mask(device->cdev);
1068         ccw_device_get_schid(device->cdev, &sch_id);
1069         conf_data_saved = 0;
1070         path_err = 0;
1071         /* get configuration data per operational path */
1072         for (lpm = 0x80; lpm; lpm>>= 1) {
1073                 if (!(lpm & opm))
1074                         continue;
1075                 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
1076                                              &conf_len, lpm);
1077                 if (rc && rc != -EOPNOTSUPP) {  /* -EOPNOTSUPP is ok */
1078                         DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1079                                         "Read configuration data returned "
1080                                         "error %d", rc);
1081                         return rc;
1082                 }
1083                 if (conf_data == NULL) {
1084                         DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1085                                         "No configuration data "
1086                                         "retrieved");
1087                         /* no further analysis possible */
1088                         dasd_path_add_opm(device, opm);
1089                         continue;       /* no error */
1090                 }
1091                 /* save first valid configuration data */
1092                 if (!conf_data_saved) {
1093                         /* initially clear previously stored conf_data */
1094                         dasd_eckd_clear_conf_data(device);
1095                         private->conf_data = conf_data;
1096                         private->conf_len = conf_len;
1097                         if (dasd_eckd_identify_conf_parts(private)) {
1098                                 private->conf_data = NULL;
1099                                 private->conf_len = 0;
1100                                 kfree(conf_data);
1101                                 continue;
1102                         }
1103                         pos = pathmask_to_pos(lpm);
1104                         /* store per path conf_data */
1105                         device->path[pos].conf_data = conf_data;
1106                         device->path[pos].cssid = sch_id.cssid;
1107                         device->path[pos].ssid = sch_id.ssid;
1108                         chp_desc = ccw_device_get_chp_desc(device->cdev, pos);
1109                         if (chp_desc)
1110                                 device->path[pos].chpid = chp_desc->chpid;
1111                         kfree(chp_desc);
1112                         /*
1113                          * build device UID that other path data
1114                          * can be compared to it
1115                          */
1116                         dasd_eckd_generate_uid(device);
1117                         conf_data_saved++;
1118                 } else {
1119                         path_private.conf_data = conf_data;
1120                         path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1121                         if (dasd_eckd_identify_conf_parts(
1122                                     &path_private)) {
1123                                 path_private.conf_data = NULL;
1124                                 path_private.conf_len = 0;
1125                                 kfree(conf_data);
1126                                 continue;
1127                         }
1128                         if (dasd_eckd_compare_path_uid(
1129                                     device, &path_private)) {
1130                                 uid = &path_private.uid;
1131                                 if (strlen(uid->vduit) > 0)
1132                                         snprintf(print_path_uid,
1133                                                  sizeof(print_path_uid),
1134                                                  "%s.%s.%04x.%02x.%s",
1135                                                  uid->vendor, uid->serial,
1136                                                  uid->ssid, uid->real_unit_addr,
1137                                                  uid->vduit);
1138                                 else
1139                                         snprintf(print_path_uid,
1140                                                  sizeof(print_path_uid),
1141                                                  "%s.%s.%04x.%02x",
1142                                                  uid->vendor, uid->serial,
1143                                                  uid->ssid,
1144                                                  uid->real_unit_addr);
1145                                 uid = &private->uid;
1146                                 if (strlen(uid->vduit) > 0)
1147                                         snprintf(print_device_uid,
1148                                                  sizeof(print_device_uid),
1149                                                  "%s.%s.%04x.%02x.%s",
1150                                                  uid->vendor, uid->serial,
1151                                                  uid->ssid, uid->real_unit_addr,
1152                                                  uid->vduit);
1153                                 else
1154                                         snprintf(print_device_uid,
1155                                                  sizeof(print_device_uid),
1156                                                  "%s.%s.%04x.%02x",
1157                                                  uid->vendor, uid->serial,
1158                                                  uid->ssid,
1159                                                  uid->real_unit_addr);
1160                                 dev_err(&device->cdev->dev,
1161                                         "Not all channel paths lead to "
1162                                         "the same device, path %02X leads to "
1163                                         "device %s instead of %s\n", lpm,
1164                                         print_path_uid, print_device_uid);
1165                                 path_err = -EINVAL;
1166                                 dasd_path_add_cablepm(device, lpm);
1167                                 continue;
1168                         }
1169                         pos = pathmask_to_pos(lpm);
1170                         /* store per path conf_data */
1171                         device->path[pos].conf_data = conf_data;
1172                         device->path[pos].cssid = sch_id.cssid;
1173                         device->path[pos].ssid = sch_id.ssid;
1174                         chp_desc = ccw_device_get_chp_desc(device->cdev, pos);
1175                         if (chp_desc)
1176                                 device->path[pos].chpid = chp_desc->chpid;
1177                         kfree(chp_desc);
1178                         path_private.conf_data = NULL;
1179                         path_private.conf_len = 0;
1180                 }
1181                 switch (dasd_eckd_path_access(conf_data, conf_len)) {
1182                 case 0x02:
1183                         dasd_path_add_nppm(device, lpm);
1184                         break;
1185                 case 0x03:
1186                         dasd_path_add_ppm(device, lpm);
1187                         break;
1188                 }
1189                 if (!dasd_path_get_opm(device)) {
1190                         dasd_path_set_opm(device, lpm);
1191                         dasd_generic_path_operational(device);
1192                 } else {
1193                         dasd_path_add_opm(device, lpm);
1194                 }
1195         }
1196 
1197         return path_err;
1198 }
1199 
1200 static u32 get_fcx_max_data(struct dasd_device *device)
1201 {
1202         struct dasd_eckd_private *private = device->private;
1203         int fcx_in_css, fcx_in_gneq, fcx_in_features;
1204         int tpm, mdc;
1205 
1206         if (dasd_nofcx)
1207                 return 0;
1208         /* is transport mode supported? */
1209         fcx_in_css = css_general_characteristics.fcx;
1210         fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
1211         fcx_in_features = private->features.feature[40] & 0x80;
1212         tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
1213 
1214         if (!tpm)
1215                 return 0;
1216 
1217         mdc = ccw_device_get_mdc(device->cdev, 0);
1218         if (mdc < 0) {
1219                 dev_warn(&device->cdev->dev, "Detecting the maximum supported data size for zHPF requests failed\n");
1220                 return 0;
1221         } else {
1222                 return (u32)mdc * FCX_MAX_DATA_FACTOR;
1223         }
1224 }
1225 
1226 static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
1227 {
1228         struct dasd_eckd_private *private = device->private;
1229         int mdc;
1230         u32 fcx_max_data;
1231 
1232         if (private->fcx_max_data) {
1233                 mdc = ccw_device_get_mdc(device->cdev, lpm);
1234                 if ((mdc < 0)) {
1235                         dev_warn(&device->cdev->dev,
1236                                  "Detecting the maximum data size for zHPF "
1237                                  "requests failed (rc=%d) for a new path %x\n",
1238                                  mdc, lpm);
1239                         return mdc;
1240                 }
1241                 fcx_max_data = (u32)mdc * FCX_MAX_DATA_FACTOR;
1242                 if (fcx_max_data < private->fcx_max_data) {
1243                         dev_warn(&device->cdev->dev,
1244                                  "The maximum data size for zHPF requests %u "
1245                                  "on a new path %x is below the active maximum "
1246                                  "%u\n", fcx_max_data, lpm,
1247                                  private->fcx_max_data);
1248                         return -EACCES;
1249                 }
1250         }
1251         return 0;
1252 }
1253 
1254 static int rebuild_device_uid(struct dasd_device *device,
1255                               struct path_verification_work_data *data)
1256 {
1257         struct dasd_eckd_private *private = device->private;
1258         __u8 lpm, opm = dasd_path_get_opm(device);
1259         int rc = -ENODEV;
1260 
1261         for (lpm = 0x80; lpm; lpm >>= 1) {
1262                 if (!(lpm & opm))
1263                         continue;
1264                 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1265                 memset(&data->cqr, 0, sizeof(data->cqr));
1266                 data->cqr.cpaddr = &data->ccw;
1267                 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1268                                                      data->rcd_buffer,
1269                                                      lpm);
1270 
1271                 if (rc) {
1272                         if (rc == -EOPNOTSUPP) /* -EOPNOTSUPP is ok */
1273                                 continue;
1274                         DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1275                                         "Read configuration data "
1276                                         "returned error %d", rc);
1277                         break;
1278                 }
1279                 memcpy(private->conf_data, data->rcd_buffer,
1280                        DASD_ECKD_RCD_DATA_SIZE);
1281                 if (dasd_eckd_identify_conf_parts(private)) {
1282                         rc = -ENODEV;
1283                 } else /* first valid path is enough */
1284                         break;
1285         }
1286 
1287         if (!rc)
1288                 rc = dasd_eckd_generate_uid(device);
1289 
1290         return rc;
1291 }
1292 
1293 static void do_path_verification_work(struct work_struct *work)
1294 {
1295         struct path_verification_work_data *data;
1296         struct dasd_device *device;
1297         struct dasd_eckd_private path_private;
1298         struct dasd_uid *uid;
1299         __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE];
1300         __u8 lpm, opm, npm, ppm, epm, hpfpm, cablepm;
1301         unsigned long flags;
1302         char print_uid[60];
1303         int rc;
1304 
1305         data = container_of(work, struct path_verification_work_data, worker);
1306         device = data->device;
1307 
1308         /* delay path verification until device was resumed */
1309         if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
1310                 schedule_work(work);
1311                 return;
1312         }
1313         /* check if path verification already running and delay if so */
1314         if (test_and_set_bit(DASD_FLAG_PATH_VERIFY, &device->flags)) {
1315                 schedule_work(work);
1316                 return;
1317         }
1318         opm = 0;
1319         npm = 0;
1320         ppm = 0;
1321         epm = 0;
1322         hpfpm = 0;
1323         cablepm = 0;
1324 
1325         for (lpm = 0x80; lpm; lpm >>= 1) {
1326                 if (!(lpm & data->tbvpm))
1327                         continue;
1328                 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1329                 memset(&data->cqr, 0, sizeof(data->cqr));
1330                 data->cqr.cpaddr = &data->ccw;
1331                 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1332                                                      data->rcd_buffer,
1333                                                      lpm);
1334                 if (!rc) {
1335                         switch (dasd_eckd_path_access(data->rcd_buffer,
1336                                                       DASD_ECKD_RCD_DATA_SIZE)
1337                                 ) {
1338                         case 0x02:
1339                                 npm |= lpm;
1340                                 break;
1341                         case 0x03:
1342                                 ppm |= lpm;
1343                                 break;
1344                         }
1345                         opm |= lpm;
1346                 } else if (rc == -EOPNOTSUPP) {
1347                         DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1348                                         "path verification: No configuration "
1349                                         "data retrieved");
1350                         opm |= lpm;
1351                 } else if (rc == -EAGAIN) {
1352                         DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1353                                         "path verification: device is stopped,"
1354                                         " try again later");
1355                         epm |= lpm;
1356                 } else {
1357                         dev_warn(&device->cdev->dev,
1358                                  "Reading device feature codes failed "
1359                                  "(rc=%d) for new path %x\n", rc, lpm);
1360                         continue;
1361                 }
1362                 if (verify_fcx_max_data(device, lpm)) {
1363                         opm &= ~lpm;
1364                         npm &= ~lpm;
1365                         ppm &= ~lpm;
1366                         hpfpm |= lpm;
1367                         continue;
1368                 }
1369 
1370                 /*
1371                  * save conf_data for comparison after
1372                  * rebuild_device_uid may have changed
1373                  * the original data
1374                  */
1375                 memcpy(&path_rcd_buf, data->rcd_buffer,
1376                        DASD_ECKD_RCD_DATA_SIZE);
1377                 path_private.conf_data = (void *) &path_rcd_buf;
1378                 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1379                 if (dasd_eckd_identify_conf_parts(&path_private)) {
1380                         path_private.conf_data = NULL;
1381                         path_private.conf_len = 0;
1382                         continue;
1383                 }
1384 
1385                 /*
1386                  * compare path UID with device UID only if at least
1387                  * one valid path is left
1388                  * in other case the device UID may have changed and
1389                  * the first working path UID will be used as device UID
1390                  */
1391                 if (dasd_path_get_opm(device) &&
1392                     dasd_eckd_compare_path_uid(device, &path_private)) {
1393                         /*
1394                          * the comparison was not successful
1395                          * rebuild the device UID with at least one
1396                          * known path in case a z/VM hyperswap command
1397                          * has changed the device
1398                          *
1399                          * after this compare again
1400                          *
1401                          * if either the rebuild or the recompare fails
1402                          * the path can not be used
1403                          */
1404                         if (rebuild_device_uid(device, data) ||
1405                             dasd_eckd_compare_path_uid(
1406                                     device, &path_private)) {
1407                                 uid = &path_private.uid;
1408                                 if (strlen(uid->vduit) > 0)
1409                                         snprintf(print_uid, sizeof(print_uid),
1410                                                  "%s.%s.%04x.%02x.%s",
1411                                                  uid->vendor, uid->serial,
1412                                                  uid->ssid, uid->real_unit_addr,
1413                                                  uid->vduit);
1414                                 else
1415                                         snprintf(print_uid, sizeof(print_uid),
1416                                                  "%s.%s.%04x.%02x",
1417                                                  uid->vendor, uid->serial,
1418                                                  uid->ssid,
1419                                                  uid->real_unit_addr);
1420                                 dev_err(&device->cdev->dev,
1421                                         "The newly added channel path %02X "
1422                                         "will not be used because it leads "
1423                                         "to a different device %s\n",
1424                                         lpm, print_uid);
1425                                 opm &= ~lpm;
1426                                 npm &= ~lpm;
1427                                 ppm &= ~lpm;
1428                                 cablepm |= lpm;
1429                                 continue;
1430                         }
1431                 }
1432 
1433                 /*
1434                  * There is a small chance that a path is lost again between
1435                  * above path verification and the following modification of
1436                  * the device opm mask. We could avoid that race here by using
1437                  * yet another path mask, but we rather deal with this unlikely
1438                  * situation in dasd_start_IO.
1439                  */
1440                 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1441                 if (!dasd_path_get_opm(device) && opm) {
1442                         dasd_path_set_opm(device, opm);
1443                         dasd_generic_path_operational(device);
1444                 } else {
1445                         dasd_path_add_opm(device, opm);
1446                 }
1447                 dasd_path_add_nppm(device, npm);
1448                 dasd_path_add_ppm(device, ppm);
1449                 dasd_path_add_tbvpm(device, epm);
1450                 dasd_path_add_cablepm(device, cablepm);
1451                 dasd_path_add_nohpfpm(device, hpfpm);
1452                 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1453         }
1454         clear_bit(DASD_FLAG_PATH_VERIFY, &device->flags);
1455         dasd_put_device(device);
1456         if (data->isglobal)
1457                 mutex_unlock(&dasd_path_verification_mutex);
1458         else
1459                 kfree(data);
1460 }
1461 
1462 static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm)
1463 {
1464         struct path_verification_work_data *data;
1465 
1466         data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA);
1467         if (!data) {
1468                 if (mutex_trylock(&dasd_path_verification_mutex)) {
1469                         data = path_verification_worker;
1470                         data->isglobal = 1;
1471                 } else
1472                         return -ENOMEM;
1473         } else {
1474                 memset(data, 0, sizeof(*data));
1475                 data->isglobal = 0;
1476         }
1477         INIT_WORK(&data->worker, do_path_verification_work);
1478         dasd_get_device(device);
1479         data->device = device;
1480         data->tbvpm = lpm;
1481         schedule_work(&data->worker);
1482         return 0;
1483 }
1484 
1485 static void dasd_eckd_reset_path(struct dasd_device *device, __u8 pm)
1486 {
1487         struct dasd_eckd_private *private = device->private;
1488         unsigned long flags;
1489 
1490         if (!private->fcx_max_data)
1491                 private->fcx_max_data = get_fcx_max_data(device);
1492         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1493         dasd_path_set_tbvpm(device, pm ? : dasd_path_get_notoperpm(device));
1494         dasd_schedule_device_bh(device);
1495         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1496 }
1497 
1498 static int dasd_eckd_read_features(struct dasd_device *device)
1499 {
1500         struct dasd_eckd_private *private = device->private;
1501         struct dasd_psf_prssd_data *prssdp;
1502         struct dasd_rssd_features *features;
1503         struct dasd_ccw_req *cqr;
1504         struct ccw1 *ccw;
1505         int rc;
1506 
1507         memset(&private->features, 0, sizeof(struct dasd_rssd_features));
1508         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
1509                                    (sizeof(struct dasd_psf_prssd_data) +
1510                                     sizeof(struct dasd_rssd_features)),
1511                                    device);
1512         if (IS_ERR(cqr)) {
1513                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not "
1514                                 "allocate initialization request");
1515                 return PTR_ERR(cqr);
1516         }
1517         cqr->startdev = device;
1518         cqr->memdev = device;
1519         cqr->block = NULL;
1520         cqr->retries = 256;
1521         cqr->expires = 10 * HZ;
1522 
1523         /* Prepare for Read Subsystem Data */
1524         prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1525         memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
1526         prssdp->order = PSF_ORDER_PRSSD;
1527         prssdp->suborder = 0x41;        /* Read Feature Codes */
1528         /* all other bytes of prssdp must be zero */
1529 
1530         ccw = cqr->cpaddr;
1531         ccw->cmd_code = DASD_ECKD_CCW_PSF;
1532         ccw->count = sizeof(struct dasd_psf_prssd_data);
1533         ccw->flags |= CCW_FLAG_CC;
1534         ccw->cda = (__u32)(addr_t) prssdp;
1535 
1536         /* Read Subsystem Data - feature codes */
1537         features = (struct dasd_rssd_features *) (prssdp + 1);
1538         memset(features, 0, sizeof(struct dasd_rssd_features));
1539 
1540         ccw++;
1541         ccw->cmd_code = DASD_ECKD_CCW_RSSD;
1542         ccw->count = sizeof(struct dasd_rssd_features);
1543         ccw->cda = (__u32)(addr_t) features;
1544 
1545         cqr->buildclk = get_tod_clock();
1546         cqr->status = DASD_CQR_FILLED;
1547         rc = dasd_sleep_on(cqr);
1548         if (rc == 0) {
1549                 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1550                 features = (struct dasd_rssd_features *) (prssdp + 1);
1551                 memcpy(&private->features, features,
1552                        sizeof(struct dasd_rssd_features));
1553         } else
1554                 dev_warn(&device->cdev->dev, "Reading device feature codes"
1555                          " failed with rc=%d\n", rc);
1556         dasd_sfree_request(cqr, cqr->memdev);
1557         return rc;
1558 }
1559 
1560 
1561 /*
1562  * Build CP for Perform Subsystem Function - SSC.
1563  */
1564 static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
1565                                                     int enable_pav)
1566 {
1567         struct dasd_ccw_req *cqr;
1568         struct dasd_psf_ssc_data *psf_ssc_data;
1569         struct ccw1 *ccw;
1570 
1571         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
1572                                   sizeof(struct dasd_psf_ssc_data),
1573                                   device);
1574 
1575         if (IS_ERR(cqr)) {
1576                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1577                            "Could not allocate PSF-SSC request");
1578                 return cqr;
1579         }
1580         psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1581         psf_ssc_data->order = PSF_ORDER_SSC;
1582         psf_ssc_data->suborder = 0xc0;
1583         if (enable_pav) {
1584                 psf_ssc_data->suborder |= 0x08;
1585                 psf_ssc_data->reserved[0] = 0x88;
1586         }
1587         ccw = cqr->cpaddr;
1588         ccw->cmd_code = DASD_ECKD_CCW_PSF;
1589         ccw->cda = (__u32)(addr_t)psf_ssc_data;
1590         ccw->count = 66;
1591 
1592         cqr->startdev = device;
1593         cqr->memdev = device;
1594         cqr->block = NULL;
1595         cqr->retries = 256;
1596         cqr->expires = 10*HZ;
1597         cqr->buildclk = get_tod_clock();
1598         cqr->status = DASD_CQR_FILLED;
1599         return cqr;
1600 }
1601 
1602 /*
1603  * Perform Subsystem Function.
1604  * It is necessary to trigger CIO for channel revalidation since this
1605  * call might change behaviour of DASD devices.
1606  */
1607 static int
1608 dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav,
1609                   unsigned long flags)
1610 {
1611         struct dasd_ccw_req *cqr;
1612         int rc;
1613 
1614         cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
1615         if (IS_ERR(cqr))
1616                 return PTR_ERR(cqr);
1617 
1618         /*
1619          * set flags e.g. turn on failfast, to prevent blocking
1620          * the calling function should handle failed requests
1621          */
1622         cqr->flags |= flags;
1623 
1624         rc = dasd_sleep_on(cqr);
1625         if (!rc)
1626                 /* trigger CIO to reprobe devices */
1627                 css_schedule_reprobe();
1628         else if (cqr->intrc == -EAGAIN)
1629                 rc = -EAGAIN;
1630 
1631         dasd_sfree_request(cqr, cqr->memdev);
1632         return rc;
1633 }
1634 
1635 /*
1636  * Valide storage server of current device.
1637  */
1638 static int dasd_eckd_validate_server(struct dasd_device *device,
1639                                      unsigned long flags)
1640 {
1641         struct dasd_eckd_private *private = device->private;
1642         int enable_pav, rc;
1643 
1644         if (private->uid.type == UA_BASE_PAV_ALIAS ||
1645             private->uid.type == UA_HYPER_PAV_ALIAS)
1646                 return 0;
1647         if (dasd_nopav || MACHINE_IS_VM)
1648                 enable_pav = 0;
1649         else
1650                 enable_pav = 1;
1651         rc = dasd_eckd_psf_ssc(device, enable_pav, flags);
1652 
1653         /* may be requested feature is not available on server,
1654          * therefore just report error and go ahead */
1655         DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
1656                         "returned rc=%d", private->uid.ssid, rc);
1657         return rc;
1658 }
1659 
1660 /*
1661  * worker to do a validate server in case of a lost pathgroup
1662  */
1663 static void dasd_eckd_do_validate_server(struct work_struct *work)
1664 {
1665         struct dasd_device *device = container_of(work, struct dasd_device,
1666                                                   kick_validate);
1667         unsigned long flags = 0;
1668 
1669         set_bit(DASD_CQR_FLAGS_FAILFAST, &flags);
1670         if (dasd_eckd_validate_server(device, flags)
1671             == -EAGAIN) {
1672                 /* schedule worker again if failed */
1673                 schedule_work(&device->kick_validate);
1674                 return;
1675         }
1676 
1677         dasd_put_device(device);
1678 }
1679 
1680 static void dasd_eckd_kick_validate_server(struct dasd_device *device)
1681 {
1682         dasd_get_device(device);
1683         /* exit if device not online or in offline processing */
1684         if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1685            device->state < DASD_STATE_ONLINE) {
1686                 dasd_put_device(device);
1687                 return;
1688         }
1689         /* queue call to do_validate_server to the kernel event daemon. */
1690         if (!schedule_work(&device->kick_validate))
1691                 dasd_put_device(device);
1692 }
1693 
1694 /*
1695  * Check device characteristics.
1696  * If the device is accessible using ECKD discipline, the device is enabled.
1697  */
1698 static int
1699 dasd_eckd_check_characteristics(struct dasd_device *device)
1700 {
1701         struct dasd_eckd_private *private = device->private;
1702         struct dasd_block *block;
1703         struct dasd_uid temp_uid;
1704         int rc, i;
1705         int readonly;
1706         unsigned long value;
1707 
1708         /* setup work queue for validate server*/
1709         INIT_WORK(&device->kick_validate, dasd_eckd_do_validate_server);
1710         /* setup work queue for summary unit check */
1711         INIT_WORK(&device->suc_work, dasd_alias_handle_summary_unit_check);
1712 
1713         if (!ccw_device_is_pathgroup(device->cdev)) {
1714                 dev_warn(&device->cdev->dev,
1715                          "A channel path group could not be established\n");
1716                 return -EIO;
1717         }
1718         if (!ccw_device_is_multipath(device->cdev)) {
1719                 dev_info(&device->cdev->dev,
1720                          "The DASD is not operating in multipath mode\n");
1721         }
1722         if (!private) {
1723                 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
1724                 if (!private) {
1725                         dev_warn(&device->cdev->dev,
1726                                  "Allocating memory for private DASD data "
1727                                  "failed\n");
1728                         return -ENOMEM;
1729                 }
1730                 device->private = private;
1731         } else {
1732                 memset(private, 0, sizeof(*private));
1733         }
1734         /* Invalidate status of initial analysis. */
1735         private->init_cqr_status = -1;
1736         /* Set default cache operations. */
1737         private->attrib.operation = DASD_NORMAL_CACHE;
1738         private->attrib.nr_cyl = 0;
1739 
1740         /* Read Configuration Data */
1741         rc = dasd_eckd_read_conf(device);
1742         if (rc)
1743                 goto out_err1;
1744 
1745         /* set some default values */
1746         device->default_expires = DASD_EXPIRES;
1747         device->default_retries = DASD_RETRIES;
1748         device->path_thrhld = DASD_ECKD_PATH_THRHLD;
1749         device->path_interval = DASD_ECKD_PATH_INTERVAL;
1750 
1751         if (private->gneq) {
1752                 value = 1;
1753                 for (i = 0; i < private->gneq->timeout.value; i++)
1754                         value = 10 * value;
1755                 value = value * private->gneq->timeout.number;
1756                 /* do not accept useless values */
1757                 if (value != 0 && value <= DASD_EXPIRES_MAX)
1758                         device->default_expires = value;
1759         }
1760 
1761         dasd_eckd_get_uid(device, &temp_uid);
1762         if (temp_uid.type == UA_BASE_DEVICE) {
1763                 block = dasd_alloc_block();
1764                 if (IS_ERR(block)) {
1765                         DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1766                                         "could not allocate dasd "
1767                                         "block structure");
1768                         rc = PTR_ERR(block);
1769                         goto out_err1;
1770                 }
1771                 device->block = block;
1772                 block->base = device;
1773         }
1774 
1775         /* register lcu with alias handling, enable PAV */
1776         rc = dasd_alias_make_device_known_to_lcu(device);
1777         if (rc)
1778                 goto out_err2;
1779 
1780         dasd_eckd_validate_server(device, 0);
1781 
1782         /* device may report different configuration data after LCU setup */
1783         rc = dasd_eckd_read_conf(device);
1784         if (rc)
1785                 goto out_err3;
1786 
1787         /* Read Feature Codes */
1788         dasd_eckd_read_features(device);
1789 
1790         /* Read Device Characteristics */
1791         rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
1792                                          &private->rdc_data, 64);
1793         if (rc) {
1794                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1795                                 "Read device characteristic failed, rc=%d", rc);
1796                 goto out_err3;
1797         }
1798 
1799         if ((device->features & DASD_FEATURE_USERAW) &&
1800             !(private->rdc_data.facilities.RT_in_LR)) {
1801                 dev_err(&device->cdev->dev, "The storage server does not "
1802                         "support raw-track access\n");
1803                 rc = -EINVAL;
1804                 goto out_err3;
1805         }
1806 
1807         /* find the valid cylinder size */
1808         if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1809             private->rdc_data.long_no_cyl)
1810                 private->real_cyl = private->rdc_data.long_no_cyl;
1811         else
1812                 private->real_cyl = private->rdc_data.no_cyl;
1813 
1814         private->fcx_max_data = get_fcx_max_data(device);
1815 
1816         readonly = dasd_device_is_ro(device);
1817         if (readonly)
1818                 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1819 
1820         dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
1821                  "with %d cylinders, %d heads, %d sectors%s\n",
1822                  private->rdc_data.dev_type,
1823                  private->rdc_data.dev_model,
1824                  private->rdc_data.cu_type,
1825                  private->rdc_data.cu_model.model,
1826                  private->real_cyl,
1827                  private->rdc_data.trk_per_cyl,
1828                  private->rdc_data.sec_per_trk,
1829                  readonly ? ", read-only device" : "");
1830         return 0;
1831 
1832 out_err3:
1833         dasd_alias_disconnect_device_from_lcu(device);
1834 out_err2:
1835         dasd_free_block(device->block);
1836         device->block = NULL;
1837 out_err1:
1838         kfree(private->conf_data);
1839         kfree(device->private);
1840         device->private = NULL;
1841         return rc;
1842 }
1843 
1844 static void dasd_eckd_uncheck_device(struct dasd_device *device)
1845 {
1846         struct dasd_eckd_private *private = device->private;
1847         int i;
1848 
1849         dasd_alias_disconnect_device_from_lcu(device);
1850         private->ned = NULL;
1851         private->sneq = NULL;
1852         private->vdsneq = NULL;
1853         private->gneq = NULL;
1854         private->conf_len = 0;
1855         for (i = 0; i < 8; i++) {
1856                 kfree(device->path[i].conf_data);
1857                 if ((__u8 *)device->path[i].conf_data ==
1858                     private->conf_data) {
1859                         private->conf_data = NULL;
1860                         private->conf_len = 0;
1861                 }
1862                 device->path[i].conf_data = NULL;
1863                 device->path[i].cssid = 0;
1864                 device->path[i].ssid = 0;
1865                 device->path[i].chpid = 0;
1866         }
1867         kfree(private->conf_data);
1868         private->conf_data = NULL;
1869 }
1870 
1871 static struct dasd_ccw_req *
1872 dasd_eckd_analysis_ccw(struct dasd_device *device)
1873 {
1874         struct dasd_eckd_private *private = device->private;
1875         struct eckd_count *count_data;
1876         struct LO_eckd_data *LO_data;
1877         struct dasd_ccw_req *cqr;
1878         struct ccw1 *ccw;
1879         int cplength, datasize;
1880         int i;
1881 
1882         cplength = 8;
1883         datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
1884         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1885         if (IS_ERR(cqr))
1886                 return cqr;
1887         ccw = cqr->cpaddr;
1888         /* Define extent for the first 3 tracks. */
1889         define_extent(ccw++, cqr->data, 0, 2,
1890                       DASD_ECKD_CCW_READ_COUNT, device);
1891         LO_data = cqr->data + sizeof(struct DE_eckd_data);
1892         /* Locate record for the first 4 records on track 0. */
1893         ccw[-1].flags |= CCW_FLAG_CC;
1894         locate_record(ccw++, LO_data++, 0, 0, 4,
1895                       DASD_ECKD_CCW_READ_COUNT, device, 0);
1896 
1897         count_data = private->count_area;
1898         for (i = 0; i < 4; i++) {
1899                 ccw[-1].flags |= CCW_FLAG_CC;
1900                 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1901                 ccw->flags = 0;
1902                 ccw->count = 8;
1903                 ccw->cda = (__u32)(addr_t) count_data;
1904                 ccw++;
1905                 count_data++;
1906         }
1907 
1908         /* Locate record for the first record on track 2. */
1909         ccw[-1].flags |= CCW_FLAG_CC;
1910         locate_record(ccw++, LO_data++, 2, 0, 1,
1911                       DASD_ECKD_CCW_READ_COUNT, device, 0);
1912         /* Read count ccw. */
1913         ccw[-1].flags |= CCW_FLAG_CC;
1914         ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1915         ccw->flags = 0;
1916         ccw->count = 8;
1917         ccw->cda = (__u32)(addr_t) count_data;
1918 
1919         cqr->block = NULL;
1920         cqr->startdev = device;
1921         cqr->memdev = device;
1922         cqr->retries = 255;
1923         cqr->buildclk = get_tod_clock();
1924         cqr->status = DASD_CQR_FILLED;
1925         return cqr;
1926 }
1927 
1928 /* differentiate between 'no record found' and any other error */
1929 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
1930 {
1931         char *sense;
1932         if (init_cqr->status == DASD_CQR_DONE)
1933                 return INIT_CQR_OK;
1934         else if (init_cqr->status == DASD_CQR_NEED_ERP ||
1935                  init_cqr->status == DASD_CQR_FAILED) {
1936                 sense = dasd_get_sense(&init_cqr->irb);
1937                 if (sense && (sense[1] & SNS1_NO_REC_FOUND))
1938                         return INIT_CQR_UNFORMATTED;
1939                 else
1940                         return INIT_CQR_ERROR;
1941         } else
1942                 return INIT_CQR_ERROR;
1943 }
1944 
1945 /*
1946  * This is the callback function for the init_analysis cqr. It saves
1947  * the status of the initial analysis ccw before it frees it and kicks
1948  * the device to continue the startup sequence. This will call
1949  * dasd_eckd_do_analysis again (if the devices has not been marked
1950  * for deletion in the meantime).
1951  */
1952 static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
1953                                         void *data)
1954 {
1955         struct dasd_device *device = init_cqr->startdev;
1956         struct dasd_eckd_private *private = device->private;
1957 
1958         private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
1959         dasd_sfree_request(init_cqr, device);
1960         dasd_kick_device(device);
1961 }
1962 
1963 static int dasd_eckd_start_analysis(struct dasd_block *block)
1964 {
1965         struct dasd_ccw_req *init_cqr;
1966 
1967         init_cqr = dasd_eckd_analysis_ccw(block->base);
1968         if (IS_ERR(init_cqr))
1969                 return PTR_ERR(init_cqr);
1970         init_cqr->callback = dasd_eckd_analysis_callback;
1971         init_cqr->callback_data = NULL;
1972         init_cqr->expires = 5*HZ;
1973         /* first try without ERP, so we can later handle unformatted
1974          * devices as special case
1975          */
1976         clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
1977         init_cqr->retries = 0;
1978         dasd_add_request_head(init_cqr);
1979         return -EAGAIN;
1980 }
1981 
1982 static int dasd_eckd_end_analysis(struct dasd_block *block)
1983 {
1984         struct dasd_device *device = block->base;
1985         struct dasd_eckd_private *private = device->private;
1986         struct eckd_count *count_area;
1987         unsigned int sb, blk_per_trk;
1988         int status, i;
1989         struct dasd_ccw_req *init_cqr;
1990 
1991         status = private->init_cqr_status;
1992         private->init_cqr_status = -1;
1993         if (status == INIT_CQR_ERROR) {
1994                 /* try again, this time with full ERP */
1995                 init_cqr = dasd_eckd_analysis_ccw(device);
1996                 dasd_sleep_on(init_cqr);
1997                 status = dasd_eckd_analysis_evaluation(init_cqr);
1998                 dasd_sfree_request(init_cqr, device);
1999         }
2000 
2001         if (device->features & DASD_FEATURE_USERAW) {
2002                 block->bp_block = DASD_RAW_BLOCKSIZE;
2003                 blk_per_trk = DASD_RAW_BLOCK_PER_TRACK;
2004                 block->s2b_shift = 3;
2005                 goto raw;
2006         }
2007 
2008         if (status == INIT_CQR_UNFORMATTED) {
2009                 dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
2010                 return -EMEDIUMTYPE;
2011         } else if (status == INIT_CQR_ERROR) {
2012                 dev_err(&device->cdev->dev,
2013                         "Detecting the DASD disk layout failed because "
2014                         "of an I/O error\n");
2015                 return -EIO;
2016         }
2017 
2018         private->uses_cdl = 1;
2019         /* Check Track 0 for Compatible Disk Layout */
2020         count_area = NULL;
2021         for (i = 0; i < 3; i++) {
2022                 if (private->count_area[i].kl != 4 ||
2023                     private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4 ||
2024                     private->count_area[i].cyl != 0 ||
2025                     private->count_area[i].head != count_area_head[i] ||
2026                     private->count_area[i].record != count_area_rec[i]) {
2027                         private->uses_cdl = 0;
2028                         break;
2029                 }
2030         }
2031         if (i == 3)
2032                 count_area = &private->count_area[4];
2033 
2034         if (private->uses_cdl == 0) {
2035                 for (i = 0; i < 5; i++) {
2036                         if ((private->count_area[i].kl != 0) ||
2037                             (private->count_area[i].dl !=
2038                              private->count_area[0].dl) ||
2039                             private->count_area[i].cyl !=  0 ||
2040                             private->count_area[i].head != count_area_head[i] ||
2041                             private->count_area[i].record != count_area_rec[i])
2042                                 break;
2043                 }
2044                 if (i == 5)
2045                         count_area = &private->count_area[0];
2046         } else {
2047                 if (private->count_area[3].record == 1)
2048                         dev_warn(&device->cdev->dev,
2049                                  "Track 0 has no records following the VTOC\n");
2050         }
2051 
2052         if (count_area != NULL && count_area->kl == 0) {
2053                 /* we found notthing violating our disk layout */
2054                 if (dasd_check_blocksize(count_area->dl) == 0)
2055                         block->bp_block = count_area->dl;
2056         }
2057         if (block->bp_block == 0) {
2058                 dev_warn(&device->cdev->dev,
2059                          "The disk layout of the DASD is not supported\n");
2060                 return -EMEDIUMTYPE;
2061         }
2062         block->s2b_shift = 0;   /* bits to shift 512 to get a block */
2063         for (sb = 512; sb < block->bp_block; sb = sb << 1)
2064                 block->s2b_shift++;
2065 
2066         blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
2067 
2068 raw:
2069         block->blocks = (private->real_cyl *
2070                           private->rdc_data.trk_per_cyl *
2071                           blk_per_trk);
2072 
2073         dev_info(&device->cdev->dev,
2074                  "DASD with %d KB/block, %d KB total size, %d KB/track, "
2075                  "%s\n", (block->bp_block >> 10),
2076                  ((private->real_cyl *
2077                    private->rdc_data.trk_per_cyl *
2078                    blk_per_trk * (block->bp_block >> 9)) >> 1),
2079                  ((blk_per_trk * block->bp_block) >> 10),
2080                  private->uses_cdl ?
2081                  "compatible disk layout" : "linux disk layout");
2082 
2083         return 0;
2084 }
2085 
2086 static int dasd_eckd_do_analysis(struct dasd_block *block)
2087 {
2088         struct dasd_eckd_private *private = block->base->private;
2089 
2090         if (private->init_cqr_status < 0)
2091                 return dasd_eckd_start_analysis(block);
2092         else
2093                 return dasd_eckd_end_analysis(block);
2094 }
2095 
2096 static int dasd_eckd_basic_to_ready(struct dasd_device *device)
2097 {
2098         return dasd_alias_add_device(device);
2099 };
2100 
2101 static int dasd_eckd_online_to_ready(struct dasd_device *device)
2102 {
2103         cancel_work_sync(&device->reload_device);
2104         cancel_work_sync(&device->kick_validate);
2105         return 0;
2106 };
2107 
2108 static int dasd_eckd_basic_to_known(struct dasd_device *device)
2109 {
2110         return dasd_alias_remove_device(device);
2111 };
2112 
2113 static int
2114 dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
2115 {
2116         struct dasd_eckd_private *private = block->base->private;
2117 
2118         if (dasd_check_blocksize(block->bp_block) == 0) {
2119                 geo->sectors = recs_per_track(&private->rdc_data,
2120                                               0, block->bp_block);
2121         }
2122         geo->cylinders = private->rdc_data.no_cyl;
2123         geo->heads = private->rdc_data.trk_per_cyl;
2124         return 0;
2125 }
2126 
2127 /*
2128  * Build the TCW request for the format check
2129  */
2130 static struct dasd_ccw_req *
2131 dasd_eckd_build_check_tcw(struct dasd_device *base, struct format_data_t *fdata,
2132                           int enable_pav, struct eckd_count *fmt_buffer,
2133                           int rpt)
2134 {
2135         struct dasd_eckd_private *start_priv;
2136         struct dasd_device *startdev = NULL;
2137         struct tidaw *last_tidaw = NULL;
2138         struct dasd_ccw_req *cqr;
2139         struct itcw *itcw;
2140         int itcw_size;
2141         int count;
2142         int rc;
2143         int i;
2144 
2145         if (enable_pav)
2146                 startdev = dasd_alias_get_start_dev(base);
2147 
2148         if (!startdev)
2149                 startdev = base;
2150 
2151         start_priv = startdev->private;
2152 
2153         count = rpt * (fdata->stop_unit - fdata->start_unit + 1);
2154 
2155         /*
2156          * we're adding 'count' amount of tidaw to the itcw.
2157          * calculate the corresponding itcw_size
2158          */
2159         itcw_size = itcw_calc_size(0, count, 0);
2160 
2161         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
2162         if (IS_ERR(cqr))
2163                 return cqr;
2164 
2165         start_priv->count++;
2166 
2167         itcw = itcw_init(cqr->data, itcw_size, ITCW_OP_READ, 0, count, 0);
2168         if (IS_ERR(itcw)) {
2169                 rc = -EINVAL;
2170                 goto out_err;
2171         }
2172 
2173         cqr->cpaddr = itcw_get_tcw(itcw);
2174         rc = prepare_itcw(itcw, fdata->start_unit, fdata->stop_unit,
2175                           DASD_ECKD_CCW_READ_COUNT_MT, base, startdev, 0, count,
2176                           sizeof(struct eckd_count),
2177                           count * sizeof(struct eckd_count), 0, rpt);
2178         if (rc)
2179                 goto out_err;
2180 
2181         for (i = 0; i < count; i++) {
2182                 last_tidaw = itcw_add_tidaw(itcw, 0, fmt_buffer++,
2183                                             sizeof(struct eckd_count));
2184                 if (IS_ERR(last_tidaw)) {
2185                         rc = -EINVAL;
2186                         goto out_err;
2187                 }
2188         }
2189 
2190         last_tidaw->flags |= TIDAW_FLAGS_LAST;
2191         itcw_finalize(itcw);
2192 
2193         cqr->cpmode = 1;
2194         cqr->startdev = startdev;
2195         cqr->memdev = startdev;
2196         cqr->basedev = base;
2197         cqr->retries = startdev->default_retries;
2198         cqr->expires = startdev->default_expires * HZ;
2199         cqr->buildclk = get_tod_clock();
2200         cqr->status = DASD_CQR_FILLED;
2201         /* Set flags to suppress output for expected errors */
2202         set_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
2203         set_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags);
2204 
2205         return cqr;
2206 
2207 out_err:
2208         dasd_sfree_request(cqr, startdev);
2209 
2210         return ERR_PTR(rc);
2211 }
2212 
2213 /*
2214  * Build the CCW request for the format check
2215  */
2216 static struct dasd_ccw_req *
2217 dasd_eckd_build_check(struct dasd_device *base, struct format_data_t *fdata,
2218                       int enable_pav, struct eckd_count *fmt_buffer, int rpt)
2219 {
2220         struct dasd_eckd_private *start_priv;
2221         struct dasd_eckd_private *base_priv;
2222         struct dasd_device *startdev = NULL;
2223         struct dasd_ccw_req *cqr;
2224         struct ccw1 *ccw;
2225         void *data;
2226         int cplength, datasize;
2227         int use_prefix;
2228         int count;
2229         int i;
2230 
2231         if (enable_pav)
2232                 startdev = dasd_alias_get_start_dev(base);
2233 
2234         if (!startdev)
2235                 startdev = base;
2236 
2237         start_priv = startdev->private;
2238         base_priv = base->private;
2239 
2240         count = rpt * (fdata->stop_unit - fdata->start_unit + 1);
2241 
2242         use_prefix = base_priv->features.feature[8] & 0x01;
2243 
2244         if (use_prefix) {
2245                 cplength = 1;
2246                 datasize = sizeof(struct PFX_eckd_data);
2247         } else {
2248                 cplength = 2;
2249                 datasize = sizeof(struct DE_eckd_data) +
2250                         sizeof(struct LO_eckd_data);
2251         }
2252         cplength += count;
2253 
2254         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2255                                   startdev);
2256         if (IS_ERR(cqr))
2257                 return cqr;
2258 
2259         start_priv->count++;
2260         data = cqr->data;
2261         ccw = cqr->cpaddr;
2262 
2263         if (use_prefix) {
2264                 prefix_LRE(ccw++, data, fdata->start_unit, fdata->stop_unit,
2265                            DASD_ECKD_CCW_READ_COUNT, base, startdev, 1, 0,
2266                            count, 0, 0);
2267         } else {
2268                 define_extent(ccw++, data, fdata->start_unit, fdata->stop_unit,
2269                               DASD_ECKD_CCW_READ_COUNT, startdev);
2270 
2271                 data += sizeof(struct DE_eckd_data);
2272                 ccw[-1].flags |= CCW_FLAG_CC;
2273 
2274                 locate_record(ccw++, data, fdata->start_unit, 0, count,
2275                               DASD_ECKD_CCW_READ_COUNT, base, 0);
2276         }
2277 
2278         for (i = 0; i < count; i++) {
2279                 ccw[-1].flags |= CCW_FLAG_CC;
2280                 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
2281                 ccw->flags = CCW_FLAG_SLI;
2282                 ccw->count = 8;
2283                 ccw->cda = (__u32)(addr_t) fmt_buffer;
2284                 ccw++;
2285                 fmt_buffer++;
2286         }
2287 
2288         cqr->startdev = startdev;
2289         cqr->memdev = startdev;
2290         cqr->basedev = base;
2291         cqr->retries = DASD_RETRIES;
2292         cqr->expires = startdev->default_expires * HZ;
2293         cqr->buildclk = get_tod_clock();
2294         cqr->status = DASD_CQR_FILLED;
2295         /* Set flags to suppress output for expected errors */
2296         set_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
2297 
2298         return cqr;
2299 }
2300 
2301 static struct dasd_ccw_req *
2302 dasd_eckd_build_format(struct dasd_device *base,
2303                        struct format_data_t *fdata,
2304                        int enable_pav)
2305 {
2306         struct dasd_eckd_private *base_priv;
2307         struct dasd_eckd_private *start_priv;
2308         struct dasd_device *startdev = NULL;
2309         struct dasd_ccw_req *fcp;
2310         struct eckd_count *ect;
2311         struct ch_t address;
2312         struct ccw1 *ccw;
2313         void *data;
2314         int rpt;
2315         int cplength, datasize;
2316         int i, j;
2317         int intensity = 0;
2318         int r0_perm;
2319         int nr_tracks;
2320         int use_prefix;
2321 
2322         if (enable_pav)
2323                 startdev = dasd_alias_get_start_dev(base);
2324 
2325         if (!startdev)
2326                 startdev = base;
2327 
2328         start_priv = startdev->private;
2329         base_priv = base->private;
2330 
2331         rpt = recs_per_track(&base_priv->rdc_data, 0, fdata->blksize);
2332 
2333         nr_tracks = fdata->stop_unit - fdata->start_unit + 1;
2334 
2335         /*
2336          * fdata->intensity is a bit string that tells us what to do:
2337          *   Bit 0: write record zero
2338          *   Bit 1: write home address, currently not supported
2339          *   Bit 2: invalidate tracks
2340          *   Bit 3: use OS/390 compatible disk layout (cdl)
2341          *   Bit 4: do not allow storage subsystem to modify record zero
2342          * Only some bit combinations do make sense.
2343          */
2344         if (fdata->intensity & 0x10) {
2345                 r0_perm = 0;
2346                 intensity = fdata->intensity & ~0x10;
2347         } else {
2348                 r0_perm = 1;
2349                 intensity = fdata->intensity;
2350         }
2351 
2352         use_prefix = base_priv->features.feature[8] & 0x01;
2353 
2354         switch (intensity) {
2355         case 0x00:      /* Normal format */
2356         case 0x08:      /* Normal format, use cdl. */
2357                 cplength = 2 + (rpt*nr_tracks);
2358                 if (use_prefix)
2359                         datasize = sizeof(struct PFX_eckd_data) +
2360                                 sizeof(struct LO_eckd_data) +
2361                                 rpt * nr_tracks * sizeof(struct eckd_count);
2362                 else
2363                         datasize = sizeof(struct DE_eckd_data) +
2364                                 sizeof(struct LO_eckd_data) +
2365                                 rpt * nr_tracks * sizeof(struct eckd_count);
2366                 break;
2367         case 0x01:      /* Write record zero and format track. */
2368         case 0x09:      /* Write record zero and format track, use cdl. */
2369                 cplength = 2 + rpt * nr_tracks;
2370                 if (use_prefix)
2371                         datasize = sizeof(struct PFX_eckd_data) +
2372                                 sizeof(struct LO_eckd_data) +
2373                                 sizeof(struct eckd_count) +
2374                                 rpt * nr_tracks * sizeof(struct eckd_count);
2375                 else
2376                         datasize = sizeof(struct DE_eckd_data) +
2377                                 sizeof(struct LO_eckd_data) +
2378                                 sizeof(struct eckd_count) +
2379                                 rpt * nr_tracks * sizeof(struct eckd_count);
2380                 break;
2381         case 0x04:      /* Invalidate track. */
2382         case 0x0c:      /* Invalidate track, use cdl. */
2383                 cplength = 3;
2384                 if (use_prefix)
2385                         datasize = sizeof(struct PFX_eckd_data) +
2386                                 sizeof(struct LO_eckd_data) +
2387                                 sizeof(struct eckd_count);
2388                 else
2389                         datasize = sizeof(struct DE_eckd_data) +
2390                                 sizeof(struct LO_eckd_data) +
2391                                 sizeof(struct eckd_count);
2392                 break;
2393         default:
2394                 dev_warn(&startdev->cdev->dev,
2395                          "An I/O control call used incorrect flags 0x%x\n",
2396                          fdata->intensity);
2397                 return ERR_PTR(-EINVAL);
2398         }
2399         /* Allocate the format ccw request. */
2400         fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
2401                                    datasize, startdev);
2402         if (IS_ERR(fcp))
2403                 return fcp;
2404 
2405         start_priv->count++;
2406         data = fcp->data;
2407         ccw = fcp->cpaddr;
2408 
2409         switch (intensity & ~0x08) {
2410         case 0x00: /* Normal format. */
2411                 if (use_prefix) {
2412                         prefix(ccw++, (struct PFX_eckd_data *) data,
2413                                fdata->start_unit, fdata->stop_unit,
2414                                DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2415                         /* grant subsystem permission to format R0 */
2416                         if (r0_perm)
2417                                 ((struct PFX_eckd_data *)data)
2418                                         ->define_extent.ga_extended |= 0x04;
2419                         data += sizeof(struct PFX_eckd_data);
2420                 } else {
2421                         define_extent(ccw++, (struct DE_eckd_data *) data,
2422                                       fdata->start_unit, fdata->stop_unit,
2423                                       DASD_ECKD_CCW_WRITE_CKD, startdev);
2424                         /* grant subsystem permission to format R0 */
2425                         if (r0_perm)
2426                                 ((struct DE_eckd_data *) data)
2427                                         ->ga_extended |= 0x04;
2428                         data += sizeof(struct DE_eckd_data);
2429                 }
2430                 ccw[-1].flags |= CCW_FLAG_CC;
2431                 locate_record(ccw++, (struct LO_eckd_data *) data,
2432                               fdata->start_unit, 0, rpt*nr_tracks,
2433                               DASD_ECKD_CCW_WRITE_CKD, base,
2434                               fdata->blksize);
2435                 data += sizeof(struct LO_eckd_data);
2436                 break;
2437         case 0x01: /* Write record zero + format track. */
2438                 if (use_prefix) {
2439                         prefix(ccw++, (struct PFX_eckd_data *) data,
2440                                fdata->start_unit, fdata->stop_unit,
2441                                DASD_ECKD_CCW_WRITE_RECORD_ZERO,
2442                                base, startdev);
2443                         data += sizeof(struct PFX_eckd_data);
2444                 } else {
2445                         define_extent(ccw++, (struct DE_eckd_data *) data,
2446                                fdata->start_unit, fdata->stop_unit,
2447                                DASD_ECKD_CCW_WRITE_RECORD_ZERO, startdev);
2448                         data += sizeof(struct DE_eckd_data);
2449                 }
2450                 ccw[-1].flags |= CCW_FLAG_CC;
2451                 locate_record(ccw++, (struct LO_eckd_data *) data,
2452                               fdata->start_unit, 0, rpt * nr_tracks + 1,
2453                               DASD_ECKD_CCW_WRITE_RECORD_ZERO, base,
2454                               base->block->bp_block);
2455                 data += sizeof(struct LO_eckd_data);
2456                 break;
2457         case 0x04: /* Invalidate track. */
2458                 if (use_prefix) {
2459                         prefix(ccw++, (struct PFX_eckd_data *) data,
2460                                fdata->start_unit, fdata->stop_unit,
2461                                DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2462                         data += sizeof(struct PFX_eckd_data);
2463                 } else {
2464                         define_extent(ccw++, (struct DE_eckd_data *) data,
2465                                fdata->start_unit, fdata->stop_unit,
2466                                DASD_ECKD_CCW_WRITE_CKD, startdev);
2467                         data += sizeof(struct DE_eckd_data);
2468                 }
2469                 ccw[-1].flags |= CCW_FLAG_CC;
2470                 locate_record(ccw++, (struct LO_eckd_data *) data,
2471                               fdata->start_unit, 0, 1,
2472                               DASD_ECKD_CCW_WRITE_CKD, base, 8);
2473                 data += sizeof(struct LO_eckd_data);
2474                 break;
2475         }
2476 
2477         for (j = 0; j < nr_tracks; j++) {
2478                 /* calculate cylinder and head for the current track */
2479                 set_ch_t(&address,
2480                          (fdata->start_unit + j) /
2481                          base_priv->rdc_data.trk_per_cyl,
2482                          (fdata->start_unit + j) %
2483                          base_priv->rdc_data.trk_per_cyl);
2484                 if (intensity & 0x01) { /* write record zero */
2485                         ect = (struct eckd_count *) data;
2486                         data += sizeof(struct eckd_count);
2487                         ect->cyl = address.cyl;
2488                         ect->head = address.head;
2489                         ect->record = 0;
2490                         ect->kl = 0;
2491                         ect->dl = 8;
2492                         ccw[-1].flags |= CCW_FLAG_CC;
2493                         ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
2494                         ccw->flags = CCW_FLAG_SLI;
2495                         ccw->count = 8;
2496                         ccw->cda = (__u32)(addr_t) ect;
2497                         ccw++;
2498                 }
2499                 if ((intensity & ~0x08) & 0x04) {       /* erase track */
2500                         ect = (struct eckd_count *) data;
2501                         data += sizeof(struct eckd_count);
2502                         ect->cyl = address.cyl;
2503                         ect->head = address.head;
2504                         ect->record = 1;
2505                         ect->kl = 0;
2506                         ect->dl = 0;
2507                         ccw[-1].flags |= CCW_FLAG_CC;
2508                         ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
2509                         ccw->flags = CCW_FLAG_SLI;
2510                         ccw->count = 8;
2511                         ccw->cda = (__u32)(addr_t) ect;
2512                 } else {                /* write remaining records */
2513                         for (i = 0; i < rpt; i++) {
2514                                 ect = (struct eckd_count *) data;
2515                                 data += sizeof(struct eckd_count);
2516                                 ect->cyl = address.cyl;
2517                                 ect->head = address.head;
2518                                 ect->record = i + 1;
2519                                 ect->kl = 0;
2520                                 ect->dl = fdata->blksize;
2521                                 /*
2522                                  * Check for special tracks 0-1
2523                                  * when formatting CDL
2524                                  */
2525                                 if ((intensity & 0x08) &&
2526                                     address.cyl == 0 && address.head == 0) {
2527                                         if (i < 3) {
2528                                                 ect->kl = 4;
2529                                                 ect->dl = sizes_trk0[i] - 4;
2530                                         }
2531                                 }
2532                                 if ((intensity & 0x08) &&
2533                                     address.cyl == 0 && address.head == 1) {
2534                                         ect->kl = 44;
2535                                         ect->dl = LABEL_SIZE - 44;
2536                                 }
2537                                 ccw[-1].flags |= CCW_FLAG_CC;
2538                                 if (i != 0 || j == 0)
2539                                         ccw->cmd_code =
2540                                                 DASD_ECKD_CCW_WRITE_CKD;
2541                                 else
2542                                         ccw->cmd_code =
2543                                                 DASD_ECKD_CCW_WRITE_CKD_MT;
2544                                 ccw->flags = CCW_FLAG_SLI;
2545                                 ccw->count = 8;
2546                                         ccw->cda = (__u32)(addr_t) ect;
2547                                         ccw++;
2548                         }
2549                 }
2550         }
2551 
2552         fcp->startdev = startdev;
2553         fcp->memdev = startdev;
2554         fcp->basedev = base;
2555         fcp->retries = 256;
2556         fcp->expires = startdev->default_expires * HZ;
2557         fcp->buildclk = get_tod_clock();
2558         fcp->status = DASD_CQR_FILLED;
2559 
2560         return fcp;
2561 }
2562 
2563 /*
2564  * Wrapper function to build a CCW request depending on input data
2565  */
2566 static struct dasd_ccw_req *
2567 dasd_eckd_format_build_ccw_req(struct dasd_device *base,
2568                                struct format_data_t *fdata, int enable_pav,
2569                                int tpm, struct eckd_count *fmt_buffer, int rpt)
2570 {
2571         struct dasd_ccw_req *ccw_req;
2572 
2573         if (!fmt_buffer) {
2574                 ccw_req = dasd_eckd_build_format(base, fdata, enable_pav);
2575         } else {
2576                 if (tpm)
2577                         ccw_req = dasd_eckd_build_check_tcw(base, fdata,
2578                                                             enable_pav,
2579                                                             fmt_buffer, rpt);
2580                 else
2581                         ccw_req = dasd_eckd_build_check(base, fdata, enable_pav,
2582                                                         fmt_buffer, rpt);
2583         }
2584 
2585         return ccw_req;
2586 }
2587 
2588 /*
2589  * Sanity checks on format_data
2590  */
2591 static int dasd_eckd_format_sanity_checks(struct dasd_device *base,
2592                                           struct format_data_t *fdata)
2593 {
2594         struct dasd_eckd_private *private = base->private;
2595 
2596         if (fdata->start_unit >=
2597             (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2598                 dev_warn(&base->cdev->dev,
2599                          "Start track number %u used in formatting is too big\n",
2600                          fdata->start_unit);
2601                 return -EINVAL;
2602         }
2603         if (fdata->stop_unit >=
2604             (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2605                 dev_warn(&base->cdev->dev,
2606                          "Stop track number %u used in formatting is too big\n",
2607                          fdata->stop_unit);
2608                 return -EINVAL;
2609         }
2610         if (fdata->start_unit > fdata->stop_unit) {
2611                 dev_warn(&base->cdev->dev,
2612                          "Start track %u used in formatting exceeds end track\n",
2613                          fdata->start_unit);
2614                 return -EINVAL;
2615         }
2616         if (dasd_check_blocksize(fdata->blksize) != 0) {
2617                 dev_warn(&base->cdev->dev,
2618                          "The DASD cannot be formatted with block size %u\n",
2619                          fdata->blksize);
2620                 return -EINVAL;
2621         }
2622         return 0;
2623 }
2624 
2625 /*
2626  * This function will process format_data originally coming from an IOCTL
2627  */
2628 static int dasd_eckd_format_process_data(struct dasd_device *base,
2629                                          struct format_data_t *fdata,
2630                                          int enable_pav, int tpm,
2631                                          struct eckd_count *fmt_buffer, int rpt,
2632                                          struct irb *irb)
2633 {
2634         struct dasd_eckd_private *private = base->private;
2635         struct dasd_ccw_req *cqr, *n;
2636         struct list_head format_queue;
2637         struct dasd_device *device;
2638         char *sense = NULL;
2639         int old_start, old_stop, format_step;
2640         int step, retry;
2641         int rc;
2642 
2643         rc = dasd_eckd_format_sanity_checks(base, fdata);
2644         if (rc)
2645                 return rc;
2646 
2647         INIT_LIST_HEAD(&format_queue);
2648 
2649         old_start = fdata->start_unit;
2650         old_stop = fdata->stop_unit;
2651 
2652         if (!tpm && fmt_buffer != NULL) {
2653                 /* Command Mode / Format Check */
2654                 format_step = 1;
2655         } else if (tpm && fmt_buffer != NULL) {
2656                 /* Transport Mode / Format Check */
2657                 format_step = DASD_CQR_MAX_CCW / rpt;
2658         } else {
2659                 /* Normal Formatting */
2660                 format_step = DASD_CQR_MAX_CCW /
2661                         recs_per_track(&private->rdc_data, 0, fdata->blksize);
2662         }
2663 
2664         do {
2665                 retry = 0;
2666                 while (fdata->start_unit <= old_stop) {
2667                         step = fdata->stop_unit - fdata->start_unit + 1;
2668                         if (step > format_step) {
2669                                 fdata->stop_unit =
2670                                         fdata->start_unit + format_step - 1;
2671                         }
2672 
2673                         cqr = dasd_eckd_format_build_ccw_req(base, fdata,
2674                                                              enable_pav, tpm,
2675                                                              fmt_buffer, rpt);
2676                         if (IS_ERR(cqr)) {
2677                                 rc = PTR_ERR(cqr);
2678                                 if (rc == -ENOMEM) {
2679                                         if (list_empty(&format_queue))
2680                                                 goto out;
2681                                         /*
2682                                          * not enough memory available, start
2683                                          * requests retry after first requests
2684                                          * were finished
2685                                          */
2686                                         retry = 1;
2687                                         break;
2688                                 }
2689                                 goto out_err;
2690                         }
2691                         list_add_tail(&cqr->blocklist, &format_queue);
2692 
2693                         if (fmt_buffer) {
2694                                 step = fdata->stop_unit - fdata->start_unit + 1;
2695                                 fmt_buffer += rpt * step;
2696                         }
2697                         fdata->start_unit = fdata->stop_unit + 1;
2698                         fdata->stop_unit = old_stop;
2699                 }
2700 
2701                 rc = dasd_sleep_on_queue(&format_queue);
2702 
2703 out_err:
2704                 list_for_each_entry_safe(cqr, n, &format_queue, blocklist) {
2705                         device = cqr->startdev;
2706                         private = device->private;
2707 
2708                         if (cqr->status == DASD_CQR_FAILED) {
2709                                 /*
2710                                  * Only get sense data if called by format
2711                                  * check
2712                                  */
2713                                 if (fmt_buffer && irb) {
2714                                         sense = dasd_get_sense(&cqr->irb);
2715                                         memcpy(irb, &cqr->irb, sizeof(*irb));
2716                                 }
2717                                 rc = -EIO;
2718                         }
2719                         list_del_init(&cqr->blocklist);
2720                         dasd_sfree_request(cqr, device);
2721                         private->count--;
2722                 }
2723 
2724                 if (rc && rc != -EIO)
2725                         goto out;
2726                 if (rc == -EIO) {
2727                         /*
2728                          * In case fewer than the expected records are on the
2729                          * track, we will most likely get a 'No Record Found'
2730                          * error (in command mode) or a 'File Protected' error
2731                          * (in transport mode). Those particular cases shouldn't
2732                          * pass the -EIO to the IOCTL, therefore reset the rc
2733                          * and continue.
2734                          */
2735                         if (sense &&
2736                             (sense[1] & SNS1_NO_REC_FOUND ||
2737                              sense[1] & SNS1_FILE_PROTECTED))
2738                                 retry = 1;
2739                         else
2740                                 goto out;
2741                 }
2742 
2743         } while (retry);
2744 
2745 out:
2746         fdata->start_unit = old_start;
2747         fdata->stop_unit = old_stop;
2748 
2749         return rc;
2750 }
2751 
2752 static int dasd_eckd_format_device(struct dasd_device *base,
2753                                    struct format_data_t *fdata, int enable_pav)
2754 {
2755         return dasd_eckd_format_process_data(base, fdata, enable_pav, 0, NULL,
2756                                              0, NULL);
2757 }
2758 
2759 /*
2760  * Helper function to count consecutive records of a single track.
2761  */
2762 static int dasd_eckd_count_records(struct eckd_count *fmt_buffer, int start,
2763                                    int max)
2764 {
2765         int head;
2766         int i;
2767 
2768         head = fmt_buffer[start].head;
2769 
2770         /*
2771          * There are 3 conditions where we stop counting:
2772          * - if data reoccurs (same head and record may reoccur), which may
2773          *   happen due to the way DASD_ECKD_CCW_READ_COUNT works
2774          * - when the head changes, because we're iterating over several tracks
2775          *   then (DASD_ECKD_CCW_READ_COUNT_MT)
2776          * - when we've reached the end of sensible data in the buffer (the
2777          *   record will be 0 then)
2778          */
2779         for (i = start; i < max; i++) {
2780                 if (i > start) {
2781                         if ((fmt_buffer[i].head == head &&
2782                             fmt_buffer[i].record == 1) ||
2783                             fmt_buffer[i].head != head ||
2784                             fmt_buffer[i].record == 0)
2785                                 break;
2786                 }
2787         }
2788 
2789         return i - start;
2790 }
2791 
2792 /*
2793  * Evaluate a given range of tracks. Data like number of records, blocksize,
2794  * record ids, and key length are compared with expected data.
2795  *
2796  * If a mismatch occurs, the corresponding error bit is set, as well as
2797  * additional information, depending on the error.
2798  */
2799 static void dasd_eckd_format_evaluate_tracks(struct eckd_count *fmt_buffer,
2800                                              struct format_check_t *cdata,
2801                                              int rpt_max, int rpt_exp,
2802                                              int trk_per_cyl, int tpm)
2803 {
2804         struct ch_t geo;
2805         int max_entries;
2806         int count = 0;
2807         int trkcount;
2808         int blksize;
2809         int pos = 0;
2810         int i, j;
2811         int kl;
2812 
2813         trkcount = cdata->expect.stop_unit - cdata->expect.start_unit + 1;
2814         max_entries = trkcount * rpt_max;
2815 
2816         for (i = cdata->expect.start_unit; i <= cdata->expect.stop_unit; i++) {
2817                 /* Calculate the correct next starting position in the buffer */
2818                 if (tpm) {
2819                         while (fmt_buffer[pos].record == 0 &&
2820                                fmt_buffer[pos].dl == 0) {
2821                                 if (pos++ > max_entries)
2822                                         break;
2823                         }
2824                 } else {
2825                         if (i != cdata->expect.start_unit)
2826                                 pos += rpt_max - count;
2827                 }
2828 
2829                 /* Calculate the expected geo values for the current track */
2830                 set_ch_t(&geo, i / trk_per_cyl, i % trk_per_cyl);
2831 
2832                 /* Count and check number of records */
2833                 count = dasd_eckd_count_records(fmt_buffer, pos, pos + rpt_max);
2834 
2835                 if (count < rpt_exp) {
2836                         cdata->result = DASD_FMT_ERR_TOO_FEW_RECORDS;
2837                         break;
2838                 }
2839                 if (count > rpt_exp) {
2840                         cdata->result = DASD_FMT_ERR_TOO_MANY_RECORDS;
2841                         break;
2842                 }
2843 
2844                 for (j = 0; j < count; j++, pos++) {
2845                         blksize = cdata->expect.blksize;
2846                         kl = 0;
2847 
2848                         /*
2849                          * Set special values when checking CDL formatted
2850                          * devices.
2851                          */
2852                         if ((cdata->expect.intensity & 0x08) &&
2853                             geo.cyl == 0 && geo.head == 0) {
2854                                 if (j < 3) {
2855                                         blksize = sizes_trk0[j] - 4;
2856                                         kl = 4;
2857                                 }
2858                         }
2859                         if ((cdata->expect.intensity & 0x08) &&
2860                             geo.cyl == 0 && geo.head == 1) {
2861                                 blksize = LABEL_SIZE - 44;
2862                                 kl = 44;
2863                         }
2864 
2865                         /* Check blocksize */
2866                         if (fmt_buffer[pos].dl != blksize) {
2867                                 cdata->result = DASD_FMT_ERR_BLKSIZE;
2868                                 goto out;
2869                         }
2870                         /* Check if key length is 0 */
2871                         if (fmt_buffer[pos].kl != kl) {
2872                                 cdata->result = DASD_FMT_ERR_KEY_LENGTH;
2873                                 goto out;
2874                         }
2875                         /* Check if record_id is correct */
2876                         if (fmt_buffer[pos].cyl != geo.cyl ||
2877                             fmt_buffer[pos].head != geo.head ||
2878                             fmt_buffer[pos].record != (j + 1)) {
2879                                 cdata->result = DASD_FMT_ERR_RECORD_ID;
2880                                 goto out;
2881                         }
2882                 }
2883         }
2884 
2885 out:
2886         /*
2887          * In case of no errors, we need to decrease by one
2888          * to get the correct positions.
2889          */
2890         if (!cdata->result) {
2891                 i--;
2892                 pos--;
2893         }
2894 
2895         cdata->unit = i;
2896         cdata->num_records = count;
2897         cdata->rec = fmt_buffer[pos].record;
2898         cdata->blksize = fmt_buffer[pos].dl;
2899         cdata->key_length = fmt_buffer[pos].kl;
2900 }
2901 
2902 /*
2903  * Check the format of a range of tracks of a DASD.
2904  */
2905 static int dasd_eckd_check_device_format(struct dasd_device *base,
2906                                          struct format_check_t *cdata,
2907                                          int enable_pav)
2908 {
2909         struct dasd_eckd_private *private = base->private;
2910         struct eckd_count *fmt_buffer;
2911         struct irb irb;
2912         int rpt_max, rpt_exp;
2913         int fmt_buffer_size;
2914         int trk_per_cyl;
2915         int trkcount;
2916         int tpm = 0;
2917         int rc;
2918 
2919         trk_per_cyl = private->rdc_data.trk_per_cyl;
2920 
2921         /* Get maximum and expected amount of records per track */
2922         rpt_max = recs_per_track(&private->rdc_data, 0, 512) + 1;
2923         rpt_exp = recs_per_track(&private->rdc_data, 0, cdata->expect.blksize);
2924 
2925         trkcount = cdata->expect.stop_unit - cdata->expect.start_unit + 1;
2926         fmt_buffer_size = trkcount * rpt_max * sizeof(struct eckd_count);
2927 
2928         fmt_buffer = kzalloc(fmt_buffer_size, GFP_KERNEL | GFP_DMA);
2929         if (!fmt_buffer)
2930                 return -ENOMEM;
2931 
2932         /*
2933          * A certain FICON feature subset is needed to operate in transport
2934          * mode. Additionally, the support for transport mode is implicitly
2935          * checked by comparing the buffer size with fcx_max_data. As long as
2936          * the buffer size is smaller we can operate in transport mode and
2937          * process multiple tracks. If not, only one track at once is being
2938          * processed using command mode.
2939          */
2940         if ((private->features.feature[40] & 0x04) &&
2941             fmt_buffer_size <= private->fcx_max_data)
2942                 tpm = 1;
2943 
2944         rc = dasd_eckd_format_process_data(base, &cdata->expect, enable_pav,
2945                                            tpm, fmt_buffer, rpt_max, &irb);
2946         if (rc && rc != -EIO)
2947                 goto out;
2948         if (rc == -EIO) {
2949                 /*
2950                  * If our first attempt with transport mode enabled comes back
2951                  * with an incorrect length error, we're going to retry the
2952                  * check with command mode.
2953                  */
2954                 if (tpm && scsw_cstat(&irb.scsw) == 0x40) {
2955                         tpm = 0;
2956                         rc = dasd_eckd_format_process_data(base, &cdata->expect,
2957                                                            enable_pav, tpm,
2958                                                            fmt_buffer, rpt_max,
2959                                                            &irb);
2960                         if (rc)
2961                                 goto out;
2962                 } else {
2963                         goto out;
2964                 }
2965         }
2966 
2967         dasd_eckd_format_evaluate_tracks(fmt_buffer, cdata, rpt_max, rpt_exp,
2968                                          trk_per_cyl, tpm);
2969 
2970 out:
2971         kfree(fmt_buffer);
2972 
2973         return rc;
2974 }
2975 
2976 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
2977 {
2978         if (cqr->retries < 0) {
2979                 cqr->status = DASD_CQR_FAILED;
2980                 return;
2981         }
2982         cqr->status = DASD_CQR_FILLED;
2983         if (cqr->block && (cqr->startdev != cqr->block->base)) {
2984                 dasd_eckd_reset_ccw_to_base_io(cqr);
2985                 cqr->startdev = cqr->block->base;
2986                 cqr->lpm = dasd_path_get_opm(cqr->block->base);
2987         }
2988 };
2989 
2990 static dasd_erp_fn_t
2991 dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
2992 {
2993         struct dasd_device *device = (struct dasd_device *) cqr->startdev;
2994         struct ccw_device *cdev = device->cdev;
2995 
2996         switch (cdev->id.cu_type) {
2997         case 0x3990:
2998         case 0x2105:
2999         case 0x2107:
3000         case 0x1750:
3001                 return dasd_3990_erp_action;
3002         case 0x9343:
3003         case 0x3880:
3004         default:
3005                 return dasd_default_erp_action;
3006         }
3007 }
3008 
3009 static dasd_erp_fn_t
3010 dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
3011 {
3012         return dasd_default_erp_postaction;
3013 }
3014 
3015 static void dasd_eckd_check_for_device_change(struct dasd_device *device,
3016                                               struct dasd_ccw_req *cqr,
3017                                               struct irb *irb)
3018 {
3019         char mask;
3020         char *sense = NULL;
3021         struct dasd_eckd_private *private = device->private;
3022 
3023         /* first of all check for state change pending interrupt */
3024         mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
3025         if ((scsw_dstat(&irb->scsw) & mask) == mask) {
3026                 /*
3027                  * for alias only, not in offline processing
3028                  * and only if not suspended
3029                  */
3030                 if (!device->block && private->lcu &&
3031                     device->state == DASD_STATE_ONLINE &&
3032                     !test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3033                     !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
3034                         /* schedule worker to reload device */
3035                         dasd_reload_device(device);
3036                 }
3037                 dasd_generic_handle_state_change(device);
3038                 return;
3039         }
3040 
3041         sense = dasd_get_sense(irb);
3042         if (!sense)
3043                 return;
3044 
3045         /* summary unit check */
3046         if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) &&
3047             (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) {
3048                 if (test_and_set_bit(DASD_FLAG_SUC, &device->flags)) {
3049                         DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3050                                       "eckd suc: device already notified");
3051                         return;
3052                 }
3053                 sense = dasd_get_sense(irb);
3054                 if (!sense) {
3055                         DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3056                                       "eckd suc: no reason code available");
3057                         clear_bit(DASD_FLAG_SUC, &device->flags);
3058                         return;
3059 
3060                 }
3061                 private->suc_reason = sense[8];
3062                 DBF_DEV_EVENT(DBF_NOTICE, device, "%s %x",
3063                               "eckd handle summary unit check: reason",
3064                               private->suc_reason);
3065                 dasd_get_device(device);
3066                 if (!schedule_work(&device->suc_work))
3067                         dasd_put_device(device);
3068 
3069                 return;
3070         }
3071 
3072         /* service information message SIM */
3073         if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) &&
3074             ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
3075                 dasd_3990_erp_handle_sim(device, sense);
3076                 return;
3077         }
3078 
3079         /* loss of device reservation is handled via base devices only
3080          * as alias devices may be used with several bases
3081          */
3082         if (device->block && (sense[27] & DASD_SENSE_BIT_0) &&
3083             (sense[7] == 0x3F) &&
3084             (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
3085             test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) {
3086                 if (device->features & DASD_FEATURE_FAILONSLCK)
3087                         set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
3088                 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3089                 dev_err(&device->cdev->dev,
3090                         "The device reservation was lost\n");
3091         }
3092 }
3093 
3094 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
3095                                                struct dasd_device *startdev,
3096                                                struct dasd_block *block,
3097                                                struct request *req,
3098                                                sector_t first_rec,
3099                                                sector_t last_rec,
3100                                                sector_t first_trk,
3101                                                sector_t last_trk,
3102                                                unsigned int first_offs,
3103                                                unsigned int last_offs,
3104                                                unsigned int blk_per_trk,
3105                                                unsigned int blksize)
3106 {
3107         struct dasd_eckd_private *private;
3108         unsigned long *idaws;
3109         struct LO_eckd_data *LO_data;
3110         struct dasd_ccw_req *cqr;
3111         struct ccw1 *ccw;
3112         struct req_iterator iter;
3113         struct bio_vec bv;
3114         char *dst;
3115         unsigned int off;
3116         int count, cidaw, cplength, datasize;
3117         sector_t recid;
3118         unsigned char cmd, rcmd;
3119         int use_prefix;
3120         struct dasd_device *basedev;
3121 
3122         basedev = block->base;
3123         private = basedev->private;
3124         if (rq_data_dir(req) == READ)
3125                 cmd = DASD_ECKD_CCW_READ_MT;
3126         else if (rq_data_dir(req) == WRITE)
3127                 cmd = DASD_ECKD_CCW_WRITE_MT;
3128         else
3129                 return ERR_PTR(-EINVAL);
3130 
3131         /* Check struct bio and count the number of blocks for the request. */
3132         count = 0;
3133         cidaw = 0;
3134         rq_for_each_segment(bv, req, iter) {
3135                 if (bv.bv_len & (blksize - 1))
3136                         /* Eckd can only do full blocks. */
3137                         return ERR_PTR(-EINVAL);
3138                 count += bv.bv_len >> (block->s2b_shift + 9);
3139                 if (idal_is_needed (page_address(bv.bv_page), bv.bv_len))
3140                         cidaw += bv.bv_len >> (block->s2b_shift + 9);
3141         }
3142         /* Paranoia. */
3143         if (count != last_rec - first_rec + 1)
3144                 return ERR_PTR(-EINVAL);
3145 
3146         /* use the prefix command if available */
3147         use_prefix = private->features.feature[8] & 0x01;
3148         if (use_prefix) {
3149                 /* 1x prefix + number of blocks */
3150                 cplength = 2 + count;
3151                 /* 1x prefix + cidaws*sizeof(long) */
3152                 datasize = sizeof(struct PFX_eckd_data) +
3153                         sizeof(struct LO_eckd_data) +
3154                         cidaw * sizeof(unsigned long);
3155         } else {
3156                 /* 1x define extent + 1x locate record + number of blocks */
3157                 cplength = 2 + count;
3158                 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
3159                 datasize = sizeof(struct DE_eckd_data) +
3160                         sizeof(struct LO_eckd_data) +
3161                         cidaw * sizeof(unsigned long);
3162         }
3163         /* Find out the number of additional locate record ccws for cdl. */
3164         if (private->uses_cdl && first_rec < 2*blk_per_trk) {
3165                 if (last_rec >= 2*blk_per_trk)
3166                         count = 2*blk_per_trk - first_rec;
3167                 cplength += count;
3168                 datasize += count*sizeof(struct LO_eckd_data);
3169         }
3170         /* Allocate the ccw request. */
3171         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
3172                                    startdev);
3173         if (IS_ERR(cqr))
3174                 return cqr;
3175         ccw = cqr->cpaddr;
3176         /* First ccw is define extent or prefix. */
3177         if (use_prefix) {
3178                 if (prefix(ccw++, cqr->data, first_trk,
3179                            last_trk, cmd, basedev, startdev) == -EAGAIN) {
3180                         /* Clock not in sync and XRC is enabled.
3181                          * Try again later.
3182                          */
3183                         dasd_sfree_request(cqr, startdev);
3184                         return ERR_PTR(-EAGAIN);
3185                 }
3186                 idaws = (unsigned long *) (cqr->data +
3187                                            sizeof(struct PFX_eckd_data));
3188         } else {
3189                 if (define_extent(ccw++, cqr->data, first_trk,
3190                                   last_trk, cmd, basedev) == -EAGAIN) {
3191                         /* Clock not in sync and XRC is enabled.
3192                          * Try again later.
3193                          */
3194                         dasd_sfree_request(cqr, startdev);
3195                         return ERR_PTR(-EAGAIN);
3196                 }
3197                 idaws = (unsigned long *) (cqr->data +
3198                                            sizeof(struct DE_eckd_data));
3199         }
3200         /* Build locate_record+read/write/ccws. */
3201         LO_data = (struct LO_eckd_data *) (idaws + cidaw);
3202         recid = first_rec;
3203         if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
3204                 /* Only standard blocks so there is just one locate record. */
3205                 ccw[-1].flags |= CCW_FLAG_CC;
3206                 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
3207                               last_rec - recid + 1, cmd, basedev, blksize);
3208         }
3209         rq_for_each_segment(bv, req, iter) {
3210                 dst = page_address(bv.bv_page) + bv.bv_offset;
3211                 if (dasd_page_cache) {
3212                         char *copy = kmem_cache_alloc(dasd_page_cache,
3213                                                       GFP_DMA | __GFP_NOWARN);
3214                         if (copy && rq_data_dir(req) == WRITE)
3215                                 memcpy(copy + bv.bv_offset, dst, bv.bv_len);
3216                         if (copy)
3217                                 dst = copy + bv.bv_offset;
3218                 }
3219                 for (off = 0; off < bv.bv_len; off += blksize) {
3220                         sector_t trkid = recid;
3221                         unsigned int recoffs = sector_div(trkid, blk_per_trk);
3222                         rcmd = cmd;
3223                         count = blksize;
3224                         /* Locate record for cdl special block ? */
3225                         if (private->uses_cdl && recid < 2*blk_per_trk) {
3226                                 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
3227                                         rcmd |= 0x8;
3228                                         count = dasd_eckd_cdl_reclen(recid);
3229                                         if (count < blksize &&
3230                                             rq_data_dir(req) == READ)
3231                                                 memset(dst + count, 0xe5,
3232                                                        blksize - count);
3233                                 }
3234                                 ccw[-1].flags |= CCW_FLAG_CC;
3235                                 locate_record(ccw++, LO_data++,
3236                                               trkid, recoffs + 1,
3237                                               1, rcmd, basedev, count);
3238                         }
3239                         /* Locate record for standard blocks ? */
3240                         if (private->uses_cdl && recid == 2*blk_per_trk) {
3241                                 ccw[-1].flags |= CCW_FLAG_CC;
3242                                 locate_record(ccw++, LO_data++,
3243                                               trkid, recoffs + 1,
3244                                               last_rec - recid + 1,
3245                                               cmd, basedev, count);
3246                         }
3247                         /* Read/write ccw. */
3248                         ccw[-1].flags |= CCW_FLAG_CC;
3249                         ccw->cmd_code = rcmd;
3250                         ccw->count = count;
3251                         if (idal_is_needed(dst, blksize)) {
3252                                 ccw->cda = (__u32)(addr_t) idaws;
3253                                 ccw->flags = CCW_FLAG_IDA;
3254                                 idaws = idal_create_words(idaws, dst, blksize);
3255                         } else {
3256                                 ccw->cda = (__u32)(addr_t) dst;
3257                                 ccw->flags = 0;
3258                         }
3259                         ccw++;
3260                         dst += blksize;
3261                         recid++;
3262                 }
3263         }
3264         if (blk_noretry_request(req) ||
3265             block->base->features & DASD_FEATURE_FAILFAST)
3266                 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3267         cqr->startdev = startdev;
3268         cqr->memdev = startdev;
3269         cqr->block = block;
3270         cqr->expires = startdev->default_expires * HZ;  /* default 5 minutes */
3271         cqr->lpm = dasd_path_get_ppm(startdev);
3272         cqr->retries = startdev->default_retries;
3273         cqr->buildclk = get_tod_clock();
3274         cqr->status = DASD_CQR_FILLED;
3275         return cqr;
3276 }
3277 
3278 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
3279                                                struct dasd_device *startdev,
3280                                                struct dasd_block *block,
3281                                                struct request *req,
3282                                                sector_t first_rec,
3283                                                sector_t last_rec,
3284                                                sector_t first_trk,
3285                                                sector_t last_trk,
3286                                                unsigned int first_offs,
3287                                                unsigned int last_offs,
3288                                                unsigned int blk_per_trk,
3289                                                unsigned int blksize)
3290 {
3291         unsigned long *idaws;
3292         struct dasd_ccw_req *cqr;
3293         struct ccw1 *ccw;
3294         struct req_iterator iter;
3295         struct bio_vec bv;
3296         char *dst, *idaw_dst;
3297         unsigned int cidaw, cplength, datasize;
3298         unsigned int tlf;
3299         sector_t recid;
3300         unsigned char cmd;
3301         struct dasd_device *basedev;
3302         unsigned int trkcount, count, count_to_trk_end;
3303         unsigned int idaw_len, seg_len, part_len, len_to_track_end;
3304         unsigned char new_track, end_idaw;
3305         sector_t trkid;
3306         unsigned int recoffs;
3307 
3308         basedev = block->base;
3309         if (rq_data_dir(req) == READ)
3310                 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
3311         else if (rq_data_dir(req) == WRITE)
3312                 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
3313         else
3314                 return ERR_PTR(-EINVAL);
3315 
3316         /* Track based I/O needs IDAWs for each page, and not just for
3317          * 64 bit addresses. We need additional idals for pages
3318          * that get filled from two tracks, so we use the number
3319          * of records as upper limit.
3320          */
3321         cidaw = last_rec - first_rec + 1;
3322         trkcount = last_trk - first_trk + 1;
3323 
3324         /* 1x prefix + one read/write ccw per track */
3325         cplength = 1 + trkcount;
3326 
3327         /* on 31-bit we need space for two 32 bit addresses per page
3328          * on 64-bit one 64 bit address
3329          */
3330         datasize = sizeof(struct PFX_eckd_data) +
3331                 cidaw * sizeof(unsigned long long);
3332 
3333         /* Allocate the ccw request. */
3334         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
3335                                    startdev);
3336         if (IS_ERR(cqr))
3337                 return cqr;
3338         ccw = cqr->cpaddr;
3339         /* transfer length factor: how many bytes to read from the last track */
3340         if (first_trk == last_trk)
3341                 tlf = last_offs - first_offs + 1;
3342         else
3343                 tlf = last_offs + 1;
3344         tlf *= blksize;
3345 
3346         if (prefix_LRE(ccw++, cqr->data, first_trk,
3347                        last_trk, cmd, basedev, startdev,
3348                        1 /* format */, first_offs + 1,
3349                        trkcount, blksize,
3350                        tlf) == -EAGAIN) {
3351                 /* Clock not in sync and XRC is enabled.
3352                  * Try again later.
3353                  */
3354                 dasd_sfree_request(cqr, startdev);
3355                 return ERR_PTR(-EAGAIN);
3356         }
3357 
3358         /*
3359          * The translation of request into ccw programs must meet the
3360          * following conditions:
3361          * - all idaws but the first and the last must address full pages
3362          *   (or 2K blocks on 31-bit)
3363          * - the scope of a ccw and it's idal ends with the track boundaries
3364          */
3365         idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
3366         recid = first_rec;
3367         new_track = 1;
3368         end_idaw = 0;
3369         len_to_track_end = 0;
3370         idaw_dst = NULL;
3371         idaw_len = 0;
3372         rq_for_each_segment(bv, req, iter) {
3373                 dst = page_address(bv.bv_page) + bv.bv_offset;
3374                 seg_len = bv.bv_len;
3375                 while (seg_len) {
3376                         if (new_track) {
3377                                 trkid = recid;
3378                                 recoffs = sector_div(trkid, blk_per_trk);
3379                                 count_to_trk_end = blk_per_trk - recoffs;
3380                                 count = min((last_rec - recid + 1),
3381                                             (sector_t)count_to_trk_end);
3382                                 len_to_track_end = count * blksize;
3383                                 ccw[-1].flags |= CCW_FLAG_CC;
3384                                 ccw->cmd_code = cmd;
3385                                 ccw->count = len_to_track_end;
3386                                 ccw->cda = (__u32)(addr_t)idaws;
3387                                 ccw->flags = CCW_FLAG_IDA;
3388                                 ccw++;
3389                                 recid += count;
3390                                 new_track = 0;
3391                                 /* first idaw for a ccw may start anywhere */
3392                                 if (!idaw_dst)
3393                                         idaw_dst = dst;
3394                         }
3395                         /* If we start a new idaw, we must make sure that it
3396                          * starts on an IDA_BLOCK_SIZE boundary.
3397                          * If we continue an idaw, we must make sure that the
3398                          * current segment begins where the so far accumulated
3399                          * idaw ends
3400                          */
3401                         if (!idaw_dst) {
3402                                 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
3403                                         dasd_sfree_request(cqr, startdev);
3404                                         return ERR_PTR(-ERANGE);
3405                                 } else
3406                                         idaw_dst = dst;
3407                         }
3408                         if ((idaw_dst + idaw_len) != dst) {
3409                                 dasd_sfree_request(cqr, startdev);
3410                                 return ERR_PTR(-ERANGE);
3411                         }
3412                         part_len = min(seg_len, len_to_track_end);
3413                         seg_len -= part_len;
3414                         dst += part_len;
3415                         idaw_len += part_len;
3416                         len_to_track_end -= part_len;
3417                         /* collected memory area ends on an IDA_BLOCK border,
3418                          * -> create an idaw
3419                          * idal_create_words will handle cases where idaw_len
3420                          * is larger then IDA_BLOCK_SIZE
3421                          */
3422                         if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
3423                                 end_idaw = 1;
3424                         /* We also need to end the idaw at track end */
3425                         if (!len_to_track_end) {
3426                                 new_track = 1;
3427                                 end_idaw = 1;
3428                         }
3429                         if (end_idaw) {
3430                                 idaws = idal_create_words(idaws, idaw_dst,
3431                                                           idaw_len);
3432                                 idaw_dst = NULL;
3433                                 idaw_len = 0;
3434                                 end_idaw = 0;
3435                         }
3436                 }
3437         }
3438 
3439         if (blk_noretry_request(req) ||
3440             block->base->features & DASD_FEATURE_FAILFAST)
3441                 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3442         cqr->startdev = startdev;
3443         cqr->memdev = startdev;
3444         cqr->block = block;
3445         cqr->expires = startdev->default_expires * HZ;  /* default 5 minutes */
3446         cqr->lpm = dasd_path_get_ppm(startdev);
3447         cqr->retries = startdev->default_retries;
3448         cqr->buildclk = get_tod_clock();
3449         cqr->status = DASD_CQR_FILLED;
3450         return cqr;
3451 }
3452 
3453 static int prepare_itcw(struct itcw *itcw,
3454                         unsigned int trk, unsigned int totrk, int cmd,
3455                         struct dasd_device *basedev,
3456                         struct dasd_device *startdev,
3457                         unsigned int rec_on_trk, int count,
3458                         unsigned int blksize,
3459                         unsigned int total_data_size,
3460                         unsigned int tlf,
3461                         unsigned int blk_per_trk)
3462 {
3463         struct PFX_eckd_data pfxdata;
3464         struct dasd_eckd_private *basepriv, *startpriv;
3465         struct DE_eckd_data *dedata;
3466         struct LRE_eckd_data *lredata;
3467         struct dcw *dcw;
3468 
3469         u32 begcyl, endcyl;
3470         u16 heads, beghead, endhead;
3471         u8 pfx_cmd;
3472 
3473         int rc = 0;
3474         int sector = 0;
3475         int dn, d;
3476 
3477 
3478         /* setup prefix data */
3479         basepriv = basedev->private;
3480         startpriv = startdev->private;
3481         dedata = &pfxdata.define_extent;
3482         lredata = &pfxdata.locate_record;
3483 
3484         memset(&pfxdata, 0, sizeof(pfxdata));
3485         pfxdata.format = 1; /* PFX with LRE */
3486         pfxdata.base_address = basepriv->ned->unit_addr;
3487         pfxdata.base_lss = basepriv->ned->ID;
3488         pfxdata.validity.define_extent = 1;
3489 
3490         /* private uid is kept up to date, conf_data may be outdated */
3491         if (startpriv->uid.type != UA_BASE_DEVICE) {
3492                 pfxdata.validity.verify_base = 1;
3493                 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
3494                         pfxdata.validity.hyper_pav = 1;
3495         }
3496 
3497         switch (cmd) {
3498         case DASD_ECKD_CCW_READ_TRACK_DATA:
3499                 dedata->mask.perm = 0x1;
3500                 dedata->attributes.operation = basepriv->attrib.operation;
3501                 dedata->blk_size = blksize;
3502                 dedata->ga_extended |= 0x42;
3503                 lredata->operation.orientation = 0x0;
3504                 lredata->operation.operation = 0x0C;
3505                 lredata->auxiliary.check_bytes = 0x01;
3506                 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
3507                 break;
3508         case DASD_ECKD_CCW_WRITE_TRACK_DATA:
3509                 dedata->mask.perm = 0x02;
3510                 dedata->attributes.operation = basepriv->attrib.operation;
3511                 dedata->blk_size = blksize;
3512                 rc = check_XRC_on_prefix(&pfxdata, basedev);
3513                 dedata->ga_extended |= 0x42;
3514                 lredata->operation.orientation = 0x0;
3515                 lredata->operation.operation = 0x3F;
3516                 lredata->extended_operation = 0x23;
3517                 lredata->auxiliary.check_bytes = 0x2;
3518                 pfx_cmd = DASD_ECKD_CCW_PFX;
3519                 break;
3520         case DASD_ECKD_CCW_READ_COUNT_MT:
3521                 dedata->mask.perm = 0x1;
3522                 dedata->attributes.operation = DASD_BYPASS_CACHE;
3523                 dedata->ga_extended |= 0x42;
3524                 dedata->blk_size = blksize;
3525                 lredata->operation.orientation = 0x2;
3526                 lredata->operation.operation = 0x16;
3527                 lredata->auxiliary.check_bytes = 0x01;
3528                 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
3529                 break;
3530         default:
3531                 DBF_DEV_EVENT(DBF_ERR, basedev,
3532                               "prepare itcw, unknown opcode 0x%x", cmd);
3533                 BUG();
3534                 break;
3535         }
3536         if (rc)
3537                 return rc;
3538 
3539         dedata->attributes.mode = 0x3;  /* ECKD */
3540 
3541         heads = basepriv->rdc_data.trk_per_cyl;
3542         begcyl = trk / heads;
3543         beghead = trk % heads;
3544         endcyl = totrk / heads;
3545         endhead = totrk % heads;
3546 
3547         /* check for sequential prestage - enhance cylinder range */
3548         if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
3549             dedata->attributes.operation == DASD_SEQ_ACCESS) {
3550 
3551                 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
3552                         endcyl += basepriv->attrib.nr_cyl;
3553                 else
3554                         endcyl = (basepriv->real_cyl - 1);
3555         }
3556 
3557         set_ch_t(&dedata->beg_ext, begcyl, beghead);
3558         set_ch_t(&dedata->end_ext, endcyl, endhead);
3559 
3560         dedata->ep_format = 0x20; /* records per track is valid */
3561         dedata->ep_rec_per_track = blk_per_trk;
3562 
3563         if (rec_on_trk) {
3564                 switch (basepriv->rdc_data.dev_type) {
3565                 case 0x3390:
3566                         dn = ceil_quot(blksize + 6, 232);
3567                         d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
3568                         sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
3569                         break;
3570                 case 0x3380:
3571                         d = 7 + ceil_quot(blksize + 12, 32);
3572                         sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
3573                         break;
3574                 }
3575         }
3576 
3577         if (cmd == DASD_ECKD_CCW_READ_COUNT_MT) {
3578                 lredata->auxiliary.length_valid = 0;
3579                 lredata->auxiliary.length_scope = 0;
3580                 lredata->sector = 0xff;
3581         } else {
3582                 lredata->auxiliary.length_valid = 1;
3583                 lredata->auxiliary.length_scope = 1;
3584                 lredata->sector = sector;
3585         }
3586         lredata->auxiliary.imbedded_ccw_valid = 1;
3587         lredata->length = tlf;
3588         lredata->imbedded_ccw = cmd;
3589         lredata->count = count;
3590         set_ch_t(&lredata->seek_addr, begcyl, beghead);
3591         lredata->search_arg.cyl = lredata->seek_addr.cyl;
3592         lredata->search_arg.head = lredata->seek_addr.head;
3593         lredata->search_arg.record = rec_on_trk;
3594 
3595         dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
3596                      &pfxdata, sizeof(pfxdata), total_data_size);
3597         return PTR_RET(dcw);
3598 }
3599 
3600 static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
3601                                                struct dasd_device *startdev,
3602                                                struct dasd_block *block,
3603                                                struct request *req,
3604                                                sector_t first_rec,
3605                                                sector_t last_rec,
3606                                                sector_t first_trk,
3607                                                sector_t last_trk,
3608                                                unsigned int first_offs,
3609                                                unsigned int last_offs,
3610                                                unsigned int blk_per_trk,
3611                                                unsigned int blksize)
3612 {
3613         struct dasd_ccw_req *cqr;
3614         struct req_iterator iter;
3615         struct bio_vec bv;
3616         char *dst;
3617         unsigned int trkcount, ctidaw;
3618         unsigned char cmd;
3619         struct dasd_device *basedev;
3620         unsigned int tlf;
3621         struct itcw *itcw;
3622         struct tidaw *last_tidaw = NULL;
3623         int itcw_op;
3624         size_t itcw_size;
3625         u8 tidaw_flags;
3626         unsigned int seg_len, part_len, len_to_track_end;
3627         unsigned char new_track;
3628         sector_t recid, trkid;
3629         unsigned int offs;
3630         unsigned int count, count_to_trk_end;
3631         int ret;
3632 
3633         basedev = block->base;
3634         if (rq_data_dir(req) == READ) {
3635                 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
3636                 itcw_op = ITCW_OP_READ;
3637         } else if (rq_data_dir(req) == WRITE) {
3638                 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
3639                 itcw_op = ITCW_OP_WRITE;
3640         } else
3641                 return ERR_PTR(-EINVAL);
3642 
3643         /* trackbased I/O needs address all memory via TIDAWs,
3644          * not just for 64 bit addresses. This allows us to map
3645          * each segment directly to one tidaw.
3646          * In the case of write requests, additional tidaws may
3647          * be needed when a segment crosses a track boundary.
3648          */
3649         trkcount = last_trk - first_trk + 1;
3650         ctidaw = 0;
3651         rq_for_each_segment(bv, req, iter) {
3652                 ++ctidaw;
3653         }
3654         if (rq_data_dir(req) == WRITE)
3655                 ctidaw += (last_trk - first_trk);
3656 
3657         /* Allocate the ccw request. */
3658         itcw_size = itcw_calc_size(0, ctidaw, 0);
3659         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
3660         if (IS_ERR(cqr))
3661                 return cqr;
3662 
3663         /* transfer length factor: how many bytes to read from the last track */
3664         if (first_trk == last_trk)
3665                 tlf = last_offs - first_offs + 1;
3666         else
3667                 tlf = last_offs + 1;
3668         tlf *= blksize;
3669 
3670         itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
3671         if (IS_ERR(itcw)) {
3672                 ret = -EINVAL;
3673                 goto out_error;
3674         }
3675         cqr->cpaddr = itcw_get_tcw(itcw);
3676         if (prepare_itcw(itcw, first_trk, last_trk,
3677                          cmd, basedev, startdev,
3678                          first_offs + 1,
3679                          trkcount, blksize,
3680                          (last_rec - first_rec + 1) * blksize,
3681                          tlf, blk_per_trk) == -EAGAIN) {
3682                 /* Clock not in sync and XRC is enabled.
3683                  * Try again later.
3684                  */
3685                 ret = -EAGAIN;
3686                 goto out_error;
3687         }
3688         len_to_track_end = 0;
3689         /*
3690          * A tidaw can address 4k of memory, but must not cross page boundaries
3691          * We can let the block layer handle this by setting
3692          * blk_queue_segment_boundary to page boundaries and
3693          * blk_max_segment_size to page size when setting up the request queue.
3694          * For write requests, a TIDAW must not cross track boundaries, because
3695          * we have to set the CBC flag on the last tidaw for each track.
3696          */
3697         if (rq_data_dir(req) == WRITE) {
3698                 new_track = 1;
3699                 recid = first_rec;
3700                 rq_for_each_segment(bv, req, iter) {
3701                         dst = page_address(bv.bv_page) + bv.bv_offset;
3702                         seg_len = bv.bv_len;
3703                         while (seg_len) {
3704                                 if (new_track) {
3705                                         trkid = recid;
3706                                         offs = sector_div(trkid, blk_per_trk);
3707                                         count_to_trk_end = blk_per_trk - offs;
3708                                         count = min((last_rec - recid + 1),
3709                                                     (sector_t)count_to_trk_end);
3710                                         len_to_track_end = count * blksize;
3711                                         recid += count;
3712                                         new_track = 0;
3713                                 }
3714                                 part_len = min(seg_len, len_to_track_end);
3715                                 seg_len -= part_len;
3716                                 len_to_track_end -= part_len;
3717                                 /* We need to end the tidaw at track end */
3718                                 if (!len_to_track_end) {
3719                                         new_track = 1;
3720                                         tidaw_flags = TIDAW_FLAGS_INSERT_CBC;
3721                                 } else
3722                                         tidaw_flags = 0;
3723                                 last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
3724                                                             dst, part_len);
3725                                 if (IS_ERR(last_tidaw)) {
3726                                         ret = -EINVAL;
3727                                         goto out_error;
3728                                 }
3729                                 dst += part_len;
3730                         }
3731                 }
3732         } else {
3733                 rq_for_each_segment(bv, req, iter) {
3734                         dst = page_address(bv.bv_page) + bv.bv_offset;
3735                         last_tidaw = itcw_add_tidaw(itcw, 0x00,
3736                                                     dst, bv.bv_len);
3737                         if (IS_ERR(last_tidaw)) {
3738                                 ret = -EINVAL;
3739                                 goto out_error;
3740                         }
3741                 }
3742         }
3743         last_tidaw->flags |= TIDAW_FLAGS_LAST;
3744         last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC;
3745         itcw_finalize(itcw);
3746 
3747         if (blk_noretry_request(req) ||
3748             block->base->features & DASD_FEATURE_FAILFAST)
3749                 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3750         cqr->cpmode = 1;
3751         cqr->startdev = startdev;
3752         cqr->memdev = startdev;
3753         cqr->block = block;
3754         cqr->expires = startdev->default_expires * HZ;  /* default 5 minutes */
3755         cqr->lpm = dasd_path_get_ppm(startdev);
3756         cqr->retries = startdev->default_retries;
3757         cqr->buildclk = get_tod_clock();
3758         cqr->status = DASD_CQR_FILLED;
3759         return cqr;
3760 out_error:
3761         dasd_sfree_request(cqr, startdev);
3762         return ERR_PTR(ret);
3763 }
3764 
3765 static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
3766                                                struct dasd_block *block,
3767                                                struct request *req)
3768 {
3769         int cmdrtd, cmdwtd;
3770         int use_prefix;
3771         int fcx_multitrack;
3772         struct dasd_eckd_private *private;
3773         struct dasd_device *basedev;
3774         sector_t first_rec, last_rec;
3775         sector_t first_trk, last_trk;
3776         unsigned int first_offs, last_offs;
3777         unsigned int blk_per_trk, blksize;
3778         int cdlspecial;
3779         unsigned int data_size;
3780         struct dasd_ccw_req *cqr;
3781 
3782         basedev = block->base;
3783         private = basedev->private;
3784 
3785         /* Calculate number of blocks/records per track. */
3786         blksize = block->bp_block;
3787         blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
3788         if (blk_per_trk == 0)
3789                 return ERR_PTR(-EINVAL);
3790         /* Calculate record id of first and last block. */
3791         first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
3792         first_offs = sector_div(first_trk, blk_per_trk);
3793         last_rec = last_trk =
3794                 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
3795         last_offs = sector_div(last_trk, blk_per_trk);
3796         cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
3797 
3798         fcx_multitrack = private->features.feature[40] & 0x20;
3799         data_size = blk_rq_bytes(req);
3800         if (data_size % blksize)
3801                 return ERR_PTR(-EINVAL);
3802         /* tpm write request add CBC data on each track boundary */
3803         if (rq_data_dir(req) == WRITE)
3804                 data_size += (last_trk - first_trk) * 4;
3805 
3806         /* is read track data and write track data in command mode supported? */
3807         cmdrtd = private->features.feature[9] & 0x20;
3808         cmdwtd = private->features.feature[12] & 0x40;
3809         use_prefix = private->features.feature[8] & 0x01;
3810 
3811         cqr = NULL;
3812         if (cdlspecial || dasd_page_cache) {
3813                 /* do nothing, just fall through to the cmd mode single case */
3814         } else if ((data_size <= private->fcx_max_data)
3815                    && (fcx_multitrack || (first_trk == last_trk))) {
3816                 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
3817                                                     first_rec, last_rec,
3818                                                     first_trk, last_trk,
3819                                                     first_offs, last_offs,
3820                                                     blk_per_trk, blksize);
3821                 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3822                     (PTR_ERR(cqr) != -ENOMEM))
3823                         cqr = NULL;
3824         } else if (use_prefix &&
3825                    (((rq_data_dir(req) == READ) && cmdrtd) ||
3826                     ((rq_data_dir(req) == WRITE) && cmdwtd))) {
3827                 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
3828                                                    first_rec, last_rec,
3829                                                    first_trk, last_trk,
3830                                                    first_offs, last_offs,
3831                                                    blk_per_trk, blksize);
3832                 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3833                     (PTR_ERR(cqr) != -ENOMEM))
3834                         cqr = NULL;
3835         }
3836         if (!cqr)
3837                 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
3838                                                     first_rec, last_rec,
3839                                                     first_trk, last_trk,
3840                                                     first_offs, last_offs,
3841                                                     blk_per_trk, blksize);
3842         return cqr;
3843 }
3844 
3845 static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev,
3846                                                struct dasd_block *block,
3847                                                struct request *req)
3848 {
3849         unsigned long *idaws;
3850         struct dasd_device *basedev;
3851         struct dasd_ccw_req *cqr;
3852         struct ccw1 *ccw;
3853         struct req_iterator iter;
3854         struct bio_vec bv;
3855         char *dst;
3856         unsigned char cmd;
3857         unsigned int trkcount;
3858         unsigned int seg_len, len_to_track_end;
3859         unsigned int first_offs;
3860         unsigned int cidaw, cplength, datasize;
3861         sector_t first_trk, last_trk, sectors;
3862         sector_t start_padding_sectors, end_sector_offset, end_padding_sectors;
3863         unsigned int pfx_datasize;
3864 
3865         /*
3866          * raw track access needs to be mutiple of 64k and on 64k boundary
3867          * For read requests we can fix an incorrect alignment by padding
3868          * the request with dummy pages.
3869          */
3870         start_padding_sectors = blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK;
3871         end_sector_offset = (blk_rq_pos(req) + blk_rq_sectors(req)) %
3872                 DASD_RAW_SECTORS_PER_TRACK;
3873         end_padding_sectors = (DASD_RAW_SECTORS_PER_TRACK - end_sector_offset) %
3874                 DASD_RAW_SECTORS_PER_TRACK;
3875         basedev = block->base;
3876         if ((start_padding_sectors || end_padding_sectors) &&
3877             (rq_data_dir(req) == WRITE)) {
3878                 DBF_DEV_EVENT(DBF_ERR, basedev,
3879                               "raw write not track aligned (%lu,%lu) req %p",
3880                               start_padding_sectors, end_padding_sectors, req);
3881                 cqr = ERR_PTR(-EINVAL);
3882                 goto out;
3883         }
3884 
3885         first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK;
3886         last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
3887                 DASD_RAW_SECTORS_PER_TRACK;
3888         trkcount = last_trk - first_trk + 1;
3889         first_offs = 0;
3890 
3891         if (rq_data_dir(req) == READ)
3892                 cmd = DASD_ECKD_CCW_READ_TRACK;
3893         else if (rq_data_dir(req) == WRITE)
3894                 cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK;
3895         else {
3896                 cqr = ERR_PTR(-EINVAL);
3897                 goto out;
3898         }
3899 
3900         /*
3901          * Raw track based I/O needs IDAWs for each page,
3902          * and not just for 64 bit addresses.
3903          */
3904         cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK;
3905 
3906         /* 1x prefix + one read/write ccw per track */
3907         cplength = 1 + trkcount;
3908 
3909         /*
3910          * struct PFX_eckd_data has up to 2 byte as extended parameter
3911          * this is needed for write full track and has to be mentioned
3912          * separately
3913          * add 8 instead of 2 to keep 8 byte boundary
3914          */
3915         pfx_datasize = sizeof(struct PFX_eckd_data) + 8;
3916 
3917         datasize = pfx_datasize + cidaw * sizeof(unsigned long long);
3918 
3919         /* Allocate the ccw request. */
3920         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
3921                                    datasize, startdev);
3922         if (IS_ERR(cqr))
3923                 goto out;
3924         ccw = cqr->cpaddr;
3925 
3926         if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd,
3927                        basedev, startdev, 1 /* format */, first_offs + 1,
3928                        trkcount, 0, 0) == -EAGAIN) {
3929                 /* Clock not in sync and XRC is enabled.
3930                  * Try again later.
3931                  */
3932                 dasd_sfree_request(cqr, startdev);
3933                 cqr = ERR_PTR(-EAGAIN);
3934                 goto out;
3935         }
3936 
3937         idaws = (unsigned long *)(cqr->data + pfx_datasize);
3938         len_to_track_end = 0;
3939         if (start_padding_sectors) {
3940                 ccw[-1].flags |= CCW_FLAG_CC;
3941                 ccw->cmd_code = cmd;
3942                 /* maximum 3390 track size */
3943                 ccw->count = 57326;
3944                 /* 64k map to one track */
3945                 len_to_track_end = 65536 - start_padding_sectors * 512;
3946                 ccw->cda = (__u32)(addr_t)idaws;
3947                 ccw->flags |= CCW_FLAG_IDA;
3948                 ccw->flags |= CCW_FLAG_SLI;
3949                 ccw++;
3950                 for (sectors = 0; sectors < start_padding_sectors; sectors += 8)
3951                         idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE);
3952         }
3953         rq_for_each_segment(bv, req, iter) {
3954                 dst = page_address(bv.bv_page) + bv.bv_offset;
3955                 seg_len = bv.bv_len;
3956                 if (cmd == DASD_ECKD_CCW_READ_TRACK)
3957                         memset(dst, 0, seg_len);
3958                 if (!len_to_track_end) {
3959                         ccw[-1].flags |= CCW_FLAG_CC;
3960                         ccw->cmd_code = cmd;
3961                         /* maximum 3390 track size */
3962                         ccw->count = 57326;
3963                         /* 64k map to one track */
3964                         len_to_track_end = 65536;
3965                         ccw->cda = (__u32)(addr_t)idaws;
3966                         ccw->flags |= CCW_FLAG_IDA;
3967                         ccw->flags |= CCW_FLAG_SLI;
3968                         ccw++;
3969                 }
3970                 len_to_track_end -= seg_len;
3971                 idaws = idal_create_words(idaws, dst, seg_len);
3972         }
3973         for (sectors = 0; sectors < end_padding_sectors; sectors += 8)
3974                 idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE);
3975         if (blk_noretry_request(req) ||
3976             block->base->features & DASD_FEATURE_FAILFAST)
3977                 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3978         cqr->startdev = startdev;
3979         cqr->memdev = startdev;
3980         cqr->block = block;
3981         cqr->expires = startdev->default_expires * HZ;
3982         cqr->lpm = dasd_path_get_ppm(startdev);
3983         cqr->retries = startdev->default_retries;
3984         cqr->buildclk = get_tod_clock();
3985         cqr->status = DASD_CQR_FILLED;
3986 
3987         if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
3988                 cqr = NULL;
3989 out:
3990         return cqr;
3991 }
3992 
3993 
3994 static int
3995 dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
3996 {
3997         struct dasd_eckd_private *private;
3998         struct ccw1 *ccw;
3999         struct req_iterator iter;
4000         struct bio_vec bv;
4001         char *dst, *cda;
4002         unsigned int blksize, blk_per_trk, off;
4003         sector_t recid;
4004         int status;
4005 
4006         if (!dasd_page_cache)
4007                 goto out;
4008         private = cqr->block->base->private;
4009         blksize = cqr->block->bp_block;
4010         blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
4011         recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
4012         ccw = cqr->cpaddr;
4013         /* Skip over define extent & locate record. */
4014         ccw++;
4015         if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
4016                 ccw++;
4017         rq_for_each_segment(bv, req, iter) {
4018                 dst = page_address(bv.bv_page) + bv.bv_offset;
4019                 for (off = 0; off < bv.bv_len; off += blksize) {
4020                         /* Skip locate record. */
4021                         if (private->uses_cdl && recid <= 2*blk_per_trk)
4022                                 ccw++;
4023                         if (dst) {
4024                                 if (ccw->flags & CCW_FLAG_IDA)
4025                                         cda = *((char **)((addr_t) ccw->cda));
4026                                 else
4027                                         cda = (char *)((addr_t) ccw->cda);
4028                                 if (dst != cda) {
4029                                         if (rq_data_dir(req) == READ)
4030                                                 memcpy(dst, cda, bv.bv_len);
4031                                         kmem_cache_free(dasd_page_cache,
4032                                             (void *)((addr_t)cda & PAGE_MASK));
4033                                 }
4034                                 dst = NULL;
4035                         }
4036                         ccw++;
4037                         recid++;
4038                 }
4039         }
4040 out:
4041         status = cqr->status == DASD_CQR_DONE;
4042         dasd_sfree_request(cqr, cqr->memdev);
4043         return status;
4044 }
4045 
4046 /*
4047  * Modify ccw/tcw in cqr so it can be started on a base device.
4048  *
4049  * Note that this is not enough to restart the cqr!
4050  * Either reset cqr->startdev as well (summary unit check handling)
4051  * or restart via separate cqr (as in ERP handling).
4052  */
4053 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
4054 {
4055         struct ccw1 *ccw;
4056         struct PFX_eckd_data *pfxdata;
4057         struct tcw *tcw;
4058         struct tccb *tccb;
4059         struct dcw *dcw;
4060 
4061         if (cqr->cpmode == 1) {
4062                 tcw = cqr->cpaddr;
4063                 tccb = tcw_get_tccb(tcw);
4064                 dcw = (struct dcw *)&tccb->tca[0];
4065                 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
4066                 pfxdata->validity.verify_base = 0;
4067                 pfxdata->validity.hyper_pav = 0;
4068         } else {
4069                 ccw = cqr->cpaddr;
4070                 pfxdata = cqr->data;
4071                 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
4072                         pfxdata->validity.verify_base = 0;
4073                         pfxdata->validity.hyper_pav = 0;
4074                 }
4075         }
4076 }
4077 
4078 #define DASD_ECKD_CHANQ_MAX_SIZE 4
4079 
4080 static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
4081                                                      struct dasd_block *block,
4082                                                      struct request *req)
4083 {
4084         struct dasd_eckd_private *private;
4085         struct dasd_device *startdev;
4086         unsigned long flags;
4087         struct dasd_ccw_req *cqr;
4088 
4089         startdev = dasd_alias_get_start_dev(base);
4090         if (!startdev)
4091                 startdev = base;
4092         private = startdev->private;
4093         if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
4094                 return ERR_PTR(-EBUSY);
4095 
4096         spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
4097         private->count++;
4098         if ((base->features & DASD_FEATURE_USERAW))
4099                 cqr = dasd_raw_build_cp(startdev, block, req);
4100         else
4101                 cqr = dasd_eckd_build_cp(startdev, block, req);
4102         if (IS_ERR(cqr))
4103                 private->count--;
4104         spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
4105         return cqr;
4106 }
4107 
4108 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
4109                                    struct request *req)
4110 {
4111         struct dasd_eckd_private *private;
4112         unsigned long flags;
4113 
4114         spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
4115         private = cqr->memdev->private;
4116         private->count--;
4117         spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
4118         return dasd_eckd_free_cp(cqr, req);
4119 }
4120 
4121 static int
4122 dasd_eckd_fill_info(struct dasd_device * device,
4123                     struct dasd_information2_t * info)
4124 {
4125         struct dasd_eckd_private *private = device->private;
4126 
4127         info->label_block = 2;
4128         info->FBA_layout = private->uses_cdl ? 0 : 1;
4129         info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
4130         info->characteristics_size = sizeof(private->rdc_data);
4131         memcpy(info->characteristics, &private->rdc_data,
4132                sizeof(private->rdc_data));
4133         info->confdata_size = min((unsigned long)private->conf_len,
4134                                   sizeof(info->configuration_data));
4135         memcpy(info->configuration_data, private->conf_data,
4136                info->confdata_size);
4137         return 0;
4138 }
4139 
4140 /*
4141  * SECTION: ioctl functions for eckd devices.
4142  */
4143 
4144 /*
4145  * Release device ioctl.
4146  * Buils a channel programm to releases a prior reserved
4147  * (see dasd_eckd_reserve) device.
4148  */
4149 static int
4150 dasd_eckd_release(struct dasd_device *device)
4151 {
4152         struct dasd_ccw_req *cqr;
4153         int rc;
4154         struct ccw1 *ccw;
4155         int useglobal;
4156 
4157         if (!capable(CAP_SYS_ADMIN))
4158                 return -EACCES;
4159 
4160         useglobal = 0;
4161         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
4162         if (IS_ERR(cqr)) {
4163                 mutex_lock(&dasd_reserve_mutex);
4164                 useglobal = 1;
4165                 cqr = &dasd_reserve_req->cqr;
4166                 memset(cqr, 0, sizeof(*cqr));
4167                 memset(&dasd_reserve_req->ccw, 0,
4168                        sizeof(dasd_reserve_req->ccw));
4169                 cqr->cpaddr = &dasd_reserve_req->ccw;
4170                 cqr->data = &dasd_reserve_req->data;
4171                 cqr->magic = DASD_ECKD_MAGIC;
4172         }
4173         ccw = cqr->cpaddr;
4174         ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
4175         ccw->flags |= CCW_FLAG_SLI;
4176         ccw->count = 32;
4177         ccw->cda = (__u32)(addr_t) cqr->data;
4178         cqr->startdev = device;
4179         cqr->memdev = device;
4180         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4181         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
4182         cqr->retries = 2;       /* set retry counter to enable basic ERP */
4183         cqr->expires = 2 * HZ;
4184         cqr->buildclk = get_tod_clock();
4185         cqr->status = DASD_CQR_FILLED;
4186 
4187         rc = dasd_sleep_on_immediatly(cqr);
4188         if (!rc)
4189                 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
4190 
4191         if (useglobal)
4192                 mutex_unlock(&dasd_reserve_mutex);
4193         else
4194                 dasd_sfree_request(cqr, cqr->memdev);
4195         return rc;
4196 }
4197 
4198 /*
4199  * Reserve device ioctl.
4200  * Options are set to 'synchronous wait for interrupt' and
4201  * 'timeout the request'. This leads to a terminate IO if
4202  * the interrupt is outstanding for a certain time.
4203  */
4204 static int
4205 dasd_eckd_reserve(struct dasd_device *device)
4206 {
4207         struct dasd_ccw_req *cqr;
4208         int rc;
4209         struct ccw1 *ccw;
4210         int useglobal;
4211 
4212         if (!capable(CAP_SYS_ADMIN))
4213                 return -EACCES;
4214 
4215         useglobal = 0;
4216         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
4217         if (IS_ERR(cqr)) {
4218                 mutex_lock(&dasd_reserve_mutex);
4219                 useglobal = 1;
4220                 cqr = &dasd_reserve_req->cqr;
4221                 memset(cqr, 0, sizeof(*cqr));
4222                 memset(&dasd_reserve_req->ccw, 0,
4223                        sizeof(dasd_reserve_req->ccw));
4224                 cqr->cpaddr = &dasd_reserve_req->ccw;
4225                 cqr->data = &dasd_reserve_req->data;
4226                 cqr->magic = DASD_ECKD_MAGIC;
4227         }
4228         ccw = cqr->cpaddr;
4229         ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
4230         ccw->flags |= CCW_FLAG_SLI;
4231         ccw->count = 32;
4232         ccw->cda = (__u32)(addr_t) cqr->data;
4233         cqr->startdev = device;
4234         cqr->memdev = device;
4235         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4236         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
4237         cqr->retries = 2;       /* set retry counter to enable basic ERP */
4238         cqr->expires = 2 * HZ;
4239         cqr->buildclk = get_tod_clock();
4240         cqr->status = DASD_CQR_FILLED;
4241 
4242         rc = dasd_sleep_on_immediatly(cqr);
4243         if (!rc)
4244                 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
4245 
4246         if (useglobal)
4247                 mutex_unlock(&dasd_reserve_mutex);
4248         else
4249                 dasd_sfree_request(cqr, cqr->memdev);
4250         return rc;
4251 }
4252 
4253 /*
4254  * Steal lock ioctl - unconditional reserve device.
4255  * Buils a channel programm to break a device's reservation.
4256  * (unconditional reserve)
4257  */
4258 static int
4259 dasd_eckd_steal_lock(struct dasd_device *device)
4260 {
4261         struct dasd_ccw_req *cqr;
4262         int rc;
4263         struct ccw1 *ccw;
4264         int useglobal;
4265 
4266         if (!capable(CAP_SYS_ADMIN))
4267                 return -EACCES;
4268 
4269         useglobal = 0;
4270         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
4271         if (IS_ERR(cqr)) {
4272                 mutex_lock(&dasd_reserve_mutex);
4273                 useglobal = 1;
4274                 cqr = &dasd_reserve_req->cqr;
4275                 memset(cqr, 0, sizeof(*cqr));
4276                 memset(&dasd_reserve_req->ccw, 0,
4277                        sizeof(dasd_reserve_req->ccw));
4278                 cqr->cpaddr = &dasd_reserve_req->ccw;
4279                 cqr->data = &dasd_reserve_req->data;
4280                 cqr->magic = DASD_ECKD_MAGIC;
4281         }
4282         ccw = cqr->cpaddr;
4283         ccw->cmd_code = DASD_ECKD_CCW_SLCK;
4284         ccw->flags |= CCW_FLAG_SLI;
4285         ccw->count = 32;
4286         ccw->cda = (__u32)(addr_t) cqr->data;
4287         cqr->startdev = device;
4288         cqr->memdev = device;
4289         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4290         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
4291         cqr->retries = 2;       /* set retry counter to enable basic ERP */
4292         cqr->expires = 2 * HZ;
4293         cqr->buildclk = get_tod_clock();
4294         cqr->status = DASD_CQR_FILLED;
4295 
4296         rc = dasd_sleep_on_immediatly(cqr);
4297         if (!rc)
4298                 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
4299 
4300         if (useglobal)
4301                 mutex_unlock(&dasd_reserve_mutex);
4302         else
4303                 dasd_sfree_request(cqr, cqr->memdev);
4304         return rc;
4305 }
4306 
4307 /*
4308  * SNID - Sense Path Group ID
4309  * This ioctl may be used in situations where I/O is stalled due to
4310  * a reserve, so if the normal dasd_smalloc_request fails, we use the
4311  * preallocated dasd_reserve_req.
4312  */
4313 static int dasd_eckd_snid(struct dasd_device *device,
4314                           void __user *argp)
4315 {
4316         struct dasd_ccw_req *cqr;
4317         int rc;
4318         struct ccw1 *ccw;
4319         int useglobal;
4320         struct dasd_snid_ioctl_data usrparm;
4321 
4322         if (!capable(CAP_SYS_ADMIN))
4323                 return -EACCES;
4324 
4325         if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
4326                 return -EFAULT;
4327 
4328         useglobal = 0;
4329         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1,
4330                                    sizeof(struct dasd_snid_data), device);
4331         if (IS_ERR(cqr)) {
4332                 mutex_lock(&dasd_reserve_mutex);
4333                 useglobal = 1;
4334                 cqr = &dasd_reserve_req->cqr;
4335                 memset(cqr, 0, sizeof(*cqr));
4336                 memset(&dasd_reserve_req->ccw, 0,
4337                        sizeof(dasd_reserve_req->ccw));
4338                 cqr->cpaddr = &dasd_reserve_req->ccw;
4339                 cqr->data = &dasd_reserve_req->data;
4340                 cqr->magic = DASD_ECKD_MAGIC;
4341         }
4342         ccw = cqr->cpaddr;
4343         ccw->cmd_code = DASD_ECKD_CCW_SNID;
4344         ccw->flags |= CCW_FLAG_SLI;
4345         ccw->count = 12;
4346         ccw->cda = (__u32)(addr_t) cqr->data;
4347         cqr->startdev = device;
4348         cqr->memdev = device;
4349         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4350         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
4351         set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
4352         cqr->retries = 5;
4353         cqr->expires = 10 * HZ;
4354         cqr->buildclk = get_tod_clock();
4355         cqr->status = DASD_CQR_FILLED;
4356         cqr->lpm = usrparm.path_mask;
4357 
4358         rc = dasd_sleep_on_immediatly(cqr);
4359         /* verify that I/O processing didn't modify the path mask */
4360         if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask))
4361                 rc = -EIO;
4362         if (!rc) {
4363                 usrparm.data = *((struct dasd_snid_data *)cqr->data);
4364                 if (copy_to_user(argp, &usrparm, sizeof(usrparm)))
4365                         rc = -EFAULT;
4366         }
4367 
4368         if (useglobal)
4369                 mutex_unlock(&dasd_reserve_mutex);
4370         else
4371                 dasd_sfree_request(cqr, cqr->memdev);
4372         return rc;
4373 }
4374 
4375 /*
4376  * Read performance statistics
4377  */
4378 static int
4379 dasd_eckd_performance(struct dasd_device *device, void __user *argp)
4380 {
4381         struct dasd_psf_prssd_data *prssdp;
4382         struct dasd_rssd_perf_stats_t *stats;
4383         struct dasd_ccw_req *cqr;
4384         struct ccw1 *ccw;
4385         int rc;
4386 
4387         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */  + 1 /* RSSD */,
4388                                    (sizeof(struct dasd_psf_prssd_data) +
4389                                     sizeof(struct dasd_rssd_perf_stats_t)),
4390                                    device);
4391         if (IS_ERR(cqr)) {
4392                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
4393                             "Could not allocate initialization request");
4394                 return PTR_ERR(cqr);
4395         }
4396         cqr->startdev = device;
4397         cqr->memdev = device;
4398         cqr->retries = 0;
4399         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4400         cqr->expires = 10 * HZ;
4401 
4402         /* Prepare for Read Subsystem Data */
4403         prssdp = (struct dasd_psf_prssd_data *) cqr->data;
4404         memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
4405         prssdp->order = PSF_ORDER_PRSSD;
4406         prssdp->suborder = 0x01;        /* Performance Statistics */
4407         prssdp->varies[1] = 0x01;       /* Perf Statistics for the Subsystem */
4408 
4409         ccw = cqr->cpaddr;
4410         ccw->cmd_code = DASD_ECKD_CCW_PSF;
4411         ccw->count = sizeof(struct dasd_psf_prssd_data);
4412         ccw->flags |= CCW_FLAG_CC;
4413         ccw->cda = (__u32)(addr_t) prssdp;
4414 
4415         /* Read Subsystem Data - Performance Statistics */
4416         stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
4417         memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
4418 
4419         ccw++;
4420         ccw->cmd_code = DASD_ECKD_CCW_RSSD;
4421         ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
4422         ccw->cda = (__u32)(addr_t) stats;
4423 
4424         cqr->buildclk = get_tod_clock();
4425         cqr->status = DASD_CQR_FILLED;
4426         rc = dasd_sleep_on(cqr);
4427         if (rc == 0) {
4428                 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
4429                 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
4430                 if (copy_to_user(argp, stats,
4431                                  sizeof(struct dasd_rssd_perf_stats_t)))
4432                         rc = -EFAULT;
4433         }
4434         dasd_sfree_request(cqr, cqr->memdev);
4435         return rc;
4436 }
4437 
4438 /*
4439  * Get attributes (cache operations)
4440  * Returnes the cache attributes used in Define Extend (DE).
4441  */
4442 static int
4443 dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
4444 {
4445         struct dasd_eckd_private *private = device->private;
4446         struct attrib_data_t attrib = private->attrib;
4447         int rc;
4448 
4449         if (!capable(CAP_SYS_ADMIN))
4450                 return -EACCES;
4451         if (!argp)
4452                 return -EINVAL;
4453 
4454         rc = 0;
4455         if (copy_to_user(argp, (long *) &attrib,
4456                          sizeof(struct attrib_data_t)))
4457                 rc = -EFAULT;
4458 
4459         return rc;
4460 }
4461 
4462 /*
4463  * Set attributes (cache operations)
4464  * Stores the attributes for cache operation to be used in Define Extend (DE).
4465  */
4466 static int
4467 dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
4468 {
4469         struct dasd_eckd_private *private = device->private;
4470         struct attrib_data_t attrib;
4471 
4472         if (!capable(CAP_SYS_ADMIN))
4473                 return -EACCES;
4474         if (!argp)
4475                 return -EINVAL;
4476 
4477         if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
4478                 return -EFAULT;
4479         private->attrib = attrib;
4480 
4481         dev_info(&device->cdev->dev,
4482                  "The DASD cache mode was set to %x (%i cylinder prestage)\n",
4483                  private->attrib.operation, private->attrib.nr_cyl);
4484         return 0;
4485 }
4486 
4487 /*
4488  * Issue syscall I/O to EMC Symmetrix array.
4489  * CCWs are PSF and RSSD
4490  */
4491 static int dasd_symm_io(struct dasd_device *device, void __user *argp)
4492 {
4493         struct dasd_symmio_parms usrparm;
4494         char *psf_data, *rssd_result;
4495         struct dasd_ccw_req *cqr;
4496         struct ccw1 *ccw;
4497         char psf0, psf1;
4498         int rc;
4499 
4500         if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
4501                 return -EACCES;
4502         psf0 = psf1 = 0;
4503 
4504         /* Copy parms from caller */
4505         rc = -EFAULT;
4506         if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
4507                 goto out;
4508         if (is_compat_task()) {
4509                 /* Make sure pointers are sane even on 31 bit. */
4510                 rc = -EINVAL;
4511                 if ((usrparm.psf_data >> 32) != 0)
4512                         goto out;
4513                 if ((usrparm.rssd_result >> 32) != 0)
4514                         goto out;
4515                 usrparm.psf_data &= 0x7fffffffULL;
4516                 usrparm.rssd_result &= 0x7fffffffULL;
4517         }
4518         /* alloc I/O data area */
4519         psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
4520         rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
4521         if (!psf_data || !rssd_result) {
4522                 rc = -ENOMEM;
4523                 goto out_free;
4524         }
4525 
4526         /* get syscall header from user space */
4527         rc = -EFAULT;
4528         if (copy_from_user(psf_data,
4529                            (void __user *)(unsigned long) usrparm.psf_data,
4530                            usrparm.psf_data_len))
4531                 goto out_free;
4532         psf0 = psf_data[0];
4533         psf1 = psf_data[1];
4534 
4535         /* setup CCWs for PSF + RSSD */
4536         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
4537         if (IS_ERR(cqr)) {
4538                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
4539                         "Could not allocate initialization request");
4540                 rc = PTR_ERR(cqr);
4541                 goto out_free;
4542         }
4543 
4544         cqr->startdev = device;
4545         cqr->memdev = device;
4546         cqr->retries = 3;
4547         cqr->expires = 10 * HZ;
4548         cqr->buildclk = get_tod_clock();
4549         cqr->status = DASD_CQR_FILLED;
4550 
4551         /* Build the ccws */
4552         ccw = cqr->cpaddr;
4553 
4554         /* PSF ccw */
4555         ccw->cmd_code = DASD_ECKD_CCW_PSF;
4556         ccw->count = usrparm.psf_data_len;
4557         ccw->flags |= CCW_FLAG_CC;
4558         ccw->cda = (__u32)(addr_t) psf_data;
4559 
4560         ccw++;
4561 
4562         /* RSSD ccw  */
4563         ccw->cmd_code = DASD_ECKD_CCW_RSSD;
4564         ccw->count = usrparm.rssd_result_len;
4565         ccw->flags = CCW_FLAG_SLI ;
4566         ccw->cda = (__u32)(addr_t) rssd_result;
4567 
4568         rc = dasd_sleep_on(cqr);
4569         if (rc)
4570                 goto out_sfree;
4571 
4572         rc = -EFAULT;
4573         if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
4574                            rssd_result, usrparm.rssd_result_len))
4575                 goto out_sfree;
4576         rc = 0;
4577 
4578 out_sfree:
4579         dasd_sfree_request(cqr, cqr->memdev);
4580 out_free:
4581         kfree(rssd_result);
4582         kfree(psf_data);
4583 out:
4584         DBF_DEV_EVENT(DBF_WARNING, device,
4585                       "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
4586                       (int) psf0, (int) psf1, rc);
4587         return rc;
4588 }
4589 
4590 static int
4591 dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
4592 {
4593         struct dasd_device *device = block->base;
4594 
4595         switch (cmd) {
4596         case BIODASDGATTR:
4597                 return dasd_eckd_get_attrib(device, argp);
4598         case BIODASDSATTR:
4599                 return dasd_eckd_set_attrib(device, argp);
4600         case BIODASDPSRD:
4601                 return dasd_eckd_performance(device, argp);
4602         case BIODASDRLSE:
4603                 return dasd_eckd_release(device);
4604         case BIODASDRSRV:
4605                 return dasd_eckd_reserve(device);
4606         case BIODASDSLCK:
4607                 return dasd_eckd_steal_lock(device);
4608         case BIODASDSNID:
4609                 return dasd_eckd_snid(device, argp);
4610         case BIODASDSYMMIO:
4611                 return dasd_symm_io(device, argp);
4612         default:
4613                 return -ENOTTY;
4614         }
4615 }
4616 
4617 /*
4618  * Dump the range of CCWs into 'page' buffer
4619  * and return number of printed chars.
4620  */
4621 static int
4622 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
4623 {
4624         int len, count;
4625         char *datap;
4626 
4627         len = 0;
4628         while (from <= to) {
4629                 len += sprintf(page + len, PRINTK_HEADER
4630                                " CCW %p: %08X %08X DAT:",
4631                                from, ((int *) from)[0], ((int *) from)[1]);
4632 
4633                 /* get pointer to data (consider IDALs) */
4634                 if (from->flags & CCW_FLAG_IDA)
4635                         datap = (char *) *((addr_t *) (addr_t) from->cda);
4636                 else
4637                         datap = (char *) ((addr_t) from->cda);
4638 
4639                 /* dump data (max 32 bytes) */
4640                 for (count = 0; count < from->count && count < 32; count++) {
4641                         if (count % 8 == 0) len += sprintf(page + len, " ");
4642                         if (count % 4 == 0) len += sprintf(page + len, " ");
4643                         len += sprintf(page + len, "%02x", datap[count]);
4644                 }
4645                 len += sprintf(page + len, "\n");
4646                 from++;
4647         }
4648         return len;
4649 }
4650 
4651 static void
4652 dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
4653                          char *reason)
4654 {
4655         u64 *sense;
4656         u64 *stat;
4657 
4658         sense = (u64 *) dasd_get_sense(irb);
4659         stat = (u64 *) &irb->scsw;
4660         if (sense) {
4661                 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : "
4662                               "%016llx %016llx %016llx %016llx",
4663                               reason, *stat, *((u32 *) (stat + 1)),
4664                               sense[0], sense[1], sense[2], sense[3]);
4665         } else {
4666                 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s",
4667                               reason, *stat, *((u32 *) (stat + 1)),
4668                               "NO VALID SENSE");
4669         }
4670 }
4671 
4672 /*
4673  * Print sense data and related channel program.
4674  * Parts are printed because printk buffer is only 1024 bytes.
4675  */
4676 static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
4677                                  struct dasd_ccw_req *req, struct irb *irb)
4678 {
4679         char *page;
4680         struct ccw1 *first, *last, *fail, *from, *to;
4681         int len, sl, sct;
4682 
4683         page = (char *) get_zeroed_page(GFP_ATOMIC);
4684         if (page == NULL) {
4685                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
4686                               "No memory to dump sense data\n");
4687                 return;
4688         }
4689         /* dump the sense data */
4690         len = sprintf(page, PRINTK_HEADER
4691                       " I/O status report for device %s:\n",
4692                       dev_name(&device->cdev->dev));
4693         len += sprintf(page + len, PRINTK_HEADER
4694                        " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4695                        "CS:%02X RC:%d\n",
4696                        req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
4697                        scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
4698                        scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
4699                        req ? req->intrc : 0);
4700         len += sprintf(page + len, PRINTK_HEADER
4701                        " device %s: Failing CCW: %p\n",
4702                        dev_name(&device->cdev->dev),
4703                        (void *) (addr_t) irb->scsw.cmd.cpa);
4704         if (irb->esw.esw0.erw.cons) {
4705                 for (sl = 0; sl < 4; sl++) {
4706                         len += sprintf(page + len, PRINTK_HEADER
4707                                        " Sense(hex) %2d-%2d:",
4708                                        (8 * sl), ((8 * sl) + 7));
4709 
4710                         for (sct = 0; sct < 8; sct++) {
4711                                 len += sprintf(page + len, " %02x",
4712                                                irb->ecw[8 * sl + sct]);
4713                         }
4714                         len += sprintf(page + len, "\n");
4715                 }
4716 
4717                 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
4718                         /* 24 Byte Sense Data */
4719                         sprintf(page + len, PRINTK_HEADER
4720                                 " 24 Byte: %x MSG %x, "
4721                                 "%s MSGb to SYSOP\n",
4722                                 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
4723                                 irb->ecw[1] & 0x10 ? "" : "no");
4724                 } else {
4725                         /* 32 Byte Sense Data */
4726                         sprintf(page + len, PRINTK_HEADER
4727                                 " 32 Byte: Format: %x "
4728                                 "Exception class %x\n",
4729                                 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
4730                 }
4731         } else {
4732                 sprintf(page + len, PRINTK_HEADER
4733                         " SORRY - NO VALID SENSE AVAILABLE\n");
4734         }
4735         printk(KERN_ERR "%s", page);
4736 
4737         if (req) {
4738                 /* req == NULL for unsolicited interrupts */
4739                 /* dump the Channel Program (max 140 Bytes per line) */
4740                 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
4741                 first = req->cpaddr;
4742                 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
4743                 to = min(first + 6, last);
4744                 len = sprintf(page, PRINTK_HEADER
4745                               " Related CP in req: %p\n", req);
4746                 dasd_eckd_dump_ccw_range(first, to, page + len);
4747                 printk(KERN_ERR "%s", page);
4748 
4749                 /* print failing CCW area (maximum 4) */
4750                 /* scsw->cda is either valid or zero  */
4751                 len = 0;
4752                 from = ++to;
4753                 fail = (struct ccw1 *)(addr_t)
4754                                 irb->scsw.cmd.cpa; /* failing CCW */
4755                 if (from <  fail - 2) {
4756                         from = fail - 2;     /* there is a gap - print header */
4757                         len += sprintf(page, PRINTK_HEADER "......\n");
4758                 }
4759                 to = min(fail + 1, last);
4760                 len += dasd_eckd_dump_ccw_range(from, to, page + len);
4761 
4762                 /* print last CCWs (maximum 2) */
4763                 from = max(from, ++to);
4764                 if (from < last - 1) {
4765                         from = last - 1;     /* there is a gap - print header */
4766                         len += sprintf(page + len, PRINTK_HEADER "......\n");
4767                 }
4768                 len += dasd_eckd_dump_ccw_range(from, last, page + len);
4769                 if (len > 0)
4770                         printk(KERN_ERR "%s", page);
4771         }
4772         free_page((unsigned long) page);
4773 }
4774 
4775 
4776 /*
4777  * Print sense data from a tcw.
4778  */
4779 static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
4780                                  struct dasd_ccw_req *req, struct irb *irb)
4781 {
4782         char *page;
4783         int len, sl, sct, residual;
4784         struct tsb *tsb;
4785         u8 *sense, *rcq;
4786 
4787         page = (char *) get_zeroed_page(GFP_ATOMIC);
4788         if (page == NULL) {
4789                 DBF_DEV_EVENT(DBF_WARNING, device, " %s",
4790                             "No memory to dump sense data");
4791                 return;
4792         }
4793         /* dump the sense data */
4794         len = sprintf(page, PRINTK_HEADER
4795                       " I/O status report for device %s:\n",
4796                       dev_name(&device->cdev->dev));
4797         len += sprintf(page + len, PRINTK_HEADER
4798                        " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4799                        "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
4800                        req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
4801                        scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
4802                        scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
4803                        irb->scsw.tm.fcxs,
4804                        (irb->scsw.tm.ifob << 7) | irb->scsw.tm.sesq,
4805                        req ? req->intrc : 0);
4806         len += sprintf(page + len, PRINTK_HEADER
4807                        " device %s: Failing TCW: %p\n",
4808                        dev_name(&device->cdev->dev),
4809                        (void *) (addr_t) irb->scsw.tm.tcw);
4810 
4811         tsb = NULL;
4812         sense = NULL;
4813         if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01))
4814                 tsb = tcw_get_tsb(
4815                         (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
4816 
4817         if (tsb) {
4818                 len += sprintf(page + len, PRINTK_HEADER
4819                                " tsb->length %d\n", tsb->length);
4820                 len += sprintf(page + len, PRINTK_HEADER
4821                                " tsb->flags %x\n", tsb->flags);
4822                 len += sprintf(page + len, PRINTK_HEADER
4823                                " tsb->dcw_offset %d\n", tsb->dcw_offset);
4824                 len += sprintf(page + len, PRINTK_HEADER
4825                                " tsb->count %d\n", tsb->count);
4826                 residual = tsb->count - 28;
4827                 len += sprintf(page + len, PRINTK_HEADER
4828                                " residual %d\n", residual);
4829 
4830                 switch (tsb->flags & 0x07) {
4831                 case 1: /* tsa_iostat */
4832                         len += sprintf(page + len, PRINTK_HEADER
4833                                " tsb->tsa.iostat.dev_time %d\n",
4834                                        tsb->tsa.iostat.dev_time);
4835                         len += sprintf(page + len, PRINTK_HEADER
4836                                " tsb->tsa.iostat.def_time %d\n",
4837                                        tsb->tsa.iostat.def_time);
4838                         len += sprintf(page + len, PRINTK_HEADER
4839                                " tsb->tsa.iostat.queue_time %d\n",
4840                                        tsb->tsa.iostat.queue_time);
4841                         len += sprintf(page + len, PRINTK_HEADER
4842                                " tsb->tsa.iostat.dev_busy_time %d\n",
4843                                        tsb->tsa.iostat.dev_busy_time);
4844                         len += sprintf(page + len, PRINTK_HEADER
4845                                " tsb->tsa.iostat.dev_act_time %d\n",
4846                                        tsb->tsa.iostat.dev_act_time);
4847                         sense = tsb->tsa.iostat.sense;
4848                         break;
4849                 case 2: /* ts_ddpc */
4850                         len += sprintf(page + len, PRINTK_HEADER
4851                                " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
4852                         for (sl = 0; sl < 2; sl++) {
4853                                 len += sprintf(page + len, PRINTK_HEADER
4854                                                " tsb->tsa.ddpc.rcq %2d-%2d: ",
4855                                                (8 * sl), ((8 * sl) + 7));
4856                                 rcq = tsb->tsa.ddpc.rcq;
4857                                 for (sct = 0; sct < 8; sct++) {
4858                                         len += sprintf(page + len, " %02x",
4859                                                        rcq[8 * sl + sct]);
4860                                 }
4861                                 len += sprintf(page + len, "\n");
4862                         }
4863                         sense = tsb->tsa.ddpc.sense;
4864                         break;
4865                 case 3: /* tsa_intrg */
4866                         len += sprintf(page + len, PRINTK_HEADER
4867                                       " tsb->tsa.intrg.: not supportet yet\n");
4868                         break;
4869                 }
4870 
4871                 if (sense) {
4872                         for (sl = 0; sl < 4; sl++) {
4873                                 len += sprintf(page + len, PRINTK_HEADER
4874                                                " Sense(hex) %2d-%2d:",
4875                                                (8 * sl), ((8 * sl) + 7));
4876                                 for (sct = 0; sct < 8; sct++) {
4877                                         len += sprintf(page + len, " %02x",
4878                                                        sense[8 * sl + sct]);
4879                                 }
4880                                 len += sprintf(page + len, "\n");
4881                         }
4882 
4883                         if (sense[27] & DASD_SENSE_BIT_0) {
4884                                 /* 24 Byte Sense Data */
4885                                 sprintf(page + len, PRINTK_HEADER
4886                                         " 24 Byte: %x MSG %x, "
4887                                         "%s MSGb to SYSOP\n",
4888                                         sense[7] >> 4, sense[7] & 0x0f,
4889                                         sense[1] & 0x10 ? "" : "no");
4890                         } else {
4891                                 /* 32 Byte Sense Data */
4892                                 sprintf(page + len, PRINTK_HEADER
4893                                         " 32 Byte: Format: %x "
4894                                         "Exception class %x\n",
4895                                         sense[6] & 0x0f, sense[22] >> 4);
4896                         }
4897                 } else {
4898                         sprintf(page + len, PRINTK_HEADER
4899                                 " SORRY - NO VALID SENSE AVAILABLE\n");
4900                 }
4901         } else {
4902                 sprintf(page + len, PRINTK_HEADER
4903                         " SORRY - NO TSB DATA AVAILABLE\n");
4904         }
4905         printk(KERN_ERR "%s", page);
4906         free_page((unsigned long) page);
4907 }
4908 
4909 static void dasd_eckd_dump_sense(struct dasd_device *device,
4910                                  struct dasd_ccw_req *req, struct irb *irb)
4911 {
4912         u8 *sense = dasd_get_sense(irb);
4913 
4914         if (scsw_is_tm(&irb->scsw)) {
4915                 /*
4916                  * In some cases the 'File Protected' or 'Incorrect Length'
4917                  * error might be expected and log messages shouldn't be written
4918                  * then. Check if the according suppress bit is set.
4919                  */
4920                 if (sense && (sense[1] & SNS1_FILE_PROTECTED) &&
4921                     test_bit(DASD_CQR_SUPPRESS_FP, &req->flags))
4922                         return;
4923                 if (scsw_cstat(&irb->scsw) == 0x40 &&
4924                     test_bit(DASD_CQR_SUPPRESS_IL, &req->flags))
4925                         return;
4926 
4927                 dasd_eckd_dump_sense_tcw(device, req, irb);
4928         } else {
4929                 /*
4930                  * In some cases the 'No Record Found' error might be expected
4931                  * and log messages shouldn't be written then. Check if the
4932                  * according suppress bit is set.
4933                  */
4934                 if (sense && sense[1] & SNS1_NO_REC_FOUND &&
4935                     test_bit(DASD_CQR_SUPPRESS_NRF, &req->flags))
4936                         return;
4937 
4938                 dasd_eckd_dump_sense_ccw(device, req, irb);
4939         }
4940 }
4941 
4942 static int dasd_eckd_pm_freeze(struct dasd_device *device)
4943 {
4944         /*
4945          * the device should be disconnected from our LCU structure
4946          * on restore we will reconnect it and reread LCU specific
4947          * information like PAV support that might have changed
4948          */
4949         dasd_alias_remove_device(device);
4950         dasd_alias_disconnect_device_from_lcu(device);
4951 
4952         return 0;
4953 }
4954 
4955 static int dasd_eckd_restore_device(struct dasd_device *device)
4956 {
4957         struct dasd_eckd_private *private = device->private;
4958         struct dasd_eckd_characteristics temp_rdc_data;
4959         int rc;
4960         struct dasd_uid temp_uid;
4961         unsigned long flags;
4962         unsigned long cqr_flags = 0;
4963 
4964         /* Read Configuration Data */
4965         rc = dasd_eckd_read_conf(device);
4966         if (rc) {
4967                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
4968                                 "Read configuration data failed, rc=%d", rc);
4969                 goto out_err;
4970         }
4971 
4972         dasd_eckd_get_uid(device, &temp_uid);
4973         /* Generate device unique id */
4974         rc = dasd_eckd_generate_uid(device);
4975         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
4976         if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
4977                 dev_err(&device->cdev->dev, "The UID of the DASD has "
4978                         "changed\n");
4979         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4980         if (rc)
4981                 goto out_err;
4982 
4983         /* register lcu with alias handling, enable PAV if this is a new lcu */
4984         rc = dasd_alias_make_device_known_to_lcu(device);
4985         if (rc)
4986                 goto out_err;
4987 
4988         set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr_flags);
4989         dasd_eckd_validate_server(device, cqr_flags);
4990 
4991         /* RE-Read Configuration Data */
4992         rc = dasd_eckd_read_conf(device);
4993         if (rc) {
4994                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
4995                         "Read configuration data failed, rc=%d", rc);
4996                 goto out_err2;
4997         }
4998 
4999         /* Read Feature Codes */
5000         dasd_eckd_read_features(device);
5001 
5002         /* Read Device Characteristics */
5003         rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
5004                                          &temp_rdc_data, 64);
5005         if (rc) {
5006                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
5007                                 "Read device characteristic failed, rc=%d", rc);
5008                 goto out_err2;
5009         }
5010         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
5011         memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
5012         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
5013 
5014         /* add device to alias management */
5015         dasd_alias_add_device(device);
5016 
5017         return 0;
5018 
5019 out_err2:
5020         dasd_alias_disconnect_device_from_lcu(device);
5021 out_err:
5022         return -1;
5023 }
5024 
5025 static int dasd_eckd_reload_device(struct dasd_device *device)
5026 {
5027         struct dasd_eckd_private *private = device->private;
5028         int rc, old_base;
5029         char print_uid[60];
5030         struct dasd_uid uid;
5031         unsigned long flags;
5032 
5033         /*
5034          * remove device from alias handling to prevent new requests
5035          * from being scheduled on the wrong alias device
5036          */
5037         dasd_alias_remove_device(device);
5038 
5039         spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
5040         old_base = private->uid.base_unit_addr;
5041         spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
5042 
5043         /* Read Configuration Data */
5044         rc = dasd_eckd_read_conf(device);
5045         if (rc)
5046                 goto out_err;
5047 
5048         rc = dasd_eckd_generate_uid(device);
5049         if (rc)
5050                 goto out_err;
5051         /*
5052          * update unit address configuration and
5053          * add device to alias management
5054          */
5055         dasd_alias_update_add_device(device);
5056 
5057         dasd_eckd_get_uid(device, &uid);
5058 
5059         if (old_base != uid.base_unit_addr) {
5060                 if (strlen(uid.vduit) > 0)
5061                         snprintf(print_uid, sizeof(print_uid),
5062                                  "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
5063                                  uid.ssid, uid.base_unit_addr, uid.vduit);
5064                 else
5065                         snprintf(print_uid, sizeof(print_uid),
5066                                  "%s.%s.%04x.%02x", uid.vendor, uid.serial,
5067                                  uid.ssid, uid.base_unit_addr);
5068 
5069                 dev_info(&device->cdev->dev,
5070                          "An Alias device was reassigned to a new base device "
5071                          "with UID: %s\n", print_uid);
5072         }
5073         return 0;
5074 
5075 out_err:
5076         return -1;
5077 }
5078 
5079 static int dasd_eckd_read_message_buffer(struct dasd_device *device,
5080                                          struct dasd_rssd_messages *messages,
5081                                          __u8 lpum)
5082 {
5083         struct dasd_rssd_messages *message_buf;
5084         struct dasd_psf_prssd_data *prssdp;
5085         struct dasd_ccw_req *cqr;
5086         struct ccw1 *ccw;
5087         int rc;
5088 
5089         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
5090                                    (sizeof(struct dasd_psf_prssd_data) +
5091                                     sizeof(struct dasd_rssd_messages)),
5092                                    device);
5093         if (IS_ERR(cqr)) {
5094                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5095                                 "Could not allocate read message buffer request");
5096                 return PTR_ERR(cqr);
5097         }
5098 
5099         cqr->lpm = lpum;
5100 retry:
5101         cqr->startdev = device;
5102         cqr->memdev = device;
5103         cqr->block = NULL;
5104         cqr->expires = 10 * HZ;
5105         set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
5106         /* dasd_sleep_on_immediatly does not do complex error
5107          * recovery so clear erp flag and set retry counter to
5108          * do basic erp */
5109         clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
5110         cqr->retries = 256;
5111 
5112         /* Prepare for Read Subsystem Data */
5113         prssdp = (struct dasd_psf_prssd_data *) cqr->data;
5114         memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
5115         prssdp->order = PSF_ORDER_PRSSD;
5116         prssdp->suborder = 0x03;        /* Message Buffer */
5117         /* all other bytes of prssdp must be zero */
5118 
5119         ccw = cqr->cpaddr;
5120         ccw->cmd_code = DASD_ECKD_CCW_PSF;
5121         ccw->count = sizeof(struct dasd_psf_prssd_data);
5122         ccw->flags |= CCW_FLAG_CC;
5123         ccw->flags |= CCW_FLAG_SLI;
5124         ccw->cda = (__u32)(addr_t) prssdp;
5125 
5126         /* Read Subsystem Data - message buffer */
5127         message_buf = (struct dasd_rssd_messages *) (prssdp + 1);
5128         memset(message_buf, 0, sizeof(struct dasd_rssd_messages));
5129 
5130         ccw++;
5131         ccw->cmd_code = DASD_ECKD_CCW_RSSD;
5132         ccw->count = sizeof(struct dasd_rssd_messages);
5133         ccw->flags |= CCW_FLAG_SLI;
5134         ccw->cda = (__u32)(addr_t) message_buf;
5135 
5136         cqr->buildclk = get_tod_clock();
5137         cqr->status = DASD_CQR_FILLED;
5138         rc = dasd_sleep_on_immediatly(cqr);
5139         if (rc == 0) {
5140                 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
5141                 message_buf = (struct dasd_rssd_messages *)
5142                         (prssdp + 1);
5143                 memcpy(messages, message_buf,
5144                        sizeof(struct dasd_rssd_messages));
5145         } else if (cqr->lpm) {
5146                 /*
5147                  * on z/VM we might not be able to do I/O on the requested path
5148                  * but instead we get the required information on any path
5149                  * so retry with open path mask
5150                  */
5151                 cqr->lpm = 0;
5152                 goto retry;
5153         } else
5154                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
5155                                 "Reading messages failed with rc=%d\n"
5156                                 , rc);
5157         dasd_sfree_request(cqr, cqr->memdev);
5158         return rc;
5159 }
5160 
5161 static int dasd_eckd_query_host_access(struct dasd_device *device,
5162                                        struct dasd_psf_query_host_access *data)
5163 {
5164         struct dasd_eckd_private *private = device->private;
5165         struct dasd_psf_query_host_access *host_access;
5166         struct dasd_psf_prssd_data *prssdp;
5167         struct dasd_ccw_req *cqr;
5168         struct ccw1 *ccw;
5169         int rc;
5170 
5171         /* not available for HYPER PAV alias devices */
5172         if (!device->block && private->lcu->pav == HYPER_PAV)
5173                 return -EOPNOTSUPP;
5174 
5175         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
5176                                    sizeof(struct dasd_psf_prssd_data) + 1,
5177                                    device);
5178         if (IS_ERR(cqr)) {
5179                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5180                                 "Could not allocate read message buffer request");
5181                 return PTR_ERR(cqr);
5182         }
5183         host_access = kzalloc(sizeof(*host_access), GFP_KERNEL | GFP_DMA);
5184         if (!host_access) {
5185                 dasd_sfree_request(cqr, device);
5186                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5187                                 "Could not allocate host_access buffer");
5188                 return -ENOMEM;
5189         }
5190         cqr->startdev = device;
5191         cqr->memdev = device;
5192         cqr->block = NULL;
5193         cqr->retries = 256;
5194         cqr->expires = 10 * HZ;
5195 
5196         /* Prepare for Read Subsystem Data */
5197         prssdp = (struct dasd_psf_prssd_data *) cqr->data;
5198         memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
5199         prssdp->order = PSF_ORDER_PRSSD;
5200         prssdp->suborder = PSF_SUBORDER_QHA;    /* query host access */
5201         /* LSS and Volume that will be queried */
5202         prssdp->lss = private->ned->ID;
5203         prssdp->volume = private->ned->unit_addr;
5204         /* all other bytes of prssdp must be zero */
5205 
5206         ccw = cqr->cpaddr;
5207         ccw->cmd_code = DASD_ECKD_CCW_PSF;
5208         ccw->count = sizeof(struct dasd_psf_prssd_data);
5209         ccw->flags |= CCW_FLAG_CC;
5210         ccw->flags |= CCW_FLAG_SLI;
5211         ccw->cda = (__u32)(addr_t) prssdp;
5212 
5213         /* Read Subsystem Data - query host access */
5214         ccw++;
5215         ccw->cmd_code = DASD_ECKD_CCW_RSSD;
5216         ccw->count = sizeof(struct dasd_psf_query_host_access);
5217         ccw->flags |= CCW_FLAG_SLI;
5218         ccw->cda = (__u32)(addr_t) host_access;
5219 
5220         cqr->buildclk = get_tod_clock();
5221         cqr->status = DASD_CQR_FILLED;
5222         rc = dasd_sleep_on_interruptible(cqr);
5223         if (rc == 0) {
5224                 *data = *host_access;
5225         } else {
5226                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
5227                                 "Reading host access data failed with rc=%d\n",
5228                                 rc);
5229                 rc = -EOPNOTSUPP;
5230         }
5231 
5232         dasd_sfree_request(cqr, cqr->memdev);
5233         kfree(host_access);
5234         return rc;
5235 }
5236 /*
5237  * return number of grouped devices
5238  */
5239 static int dasd_eckd_host_access_count(struct dasd_device *device)
5240 {
5241         struct dasd_psf_query_host_access *access;
5242         struct dasd_ckd_path_group_entry *entry;
5243         struct dasd_ckd_host_information *info;
5244         int count = 0;
5245         int rc, i;
5246 
5247         access = kzalloc(sizeof(*access), GFP_NOIO);
5248         if (!access) {
5249                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5250                                 "Could not allocate access buffer");
5251                 return -ENOMEM;
5252         }
5253         rc = dasd_eckd_query_host_access(device, access);
5254         if (rc) {
5255                 kfree(access);
5256                 return rc;
5257         }
5258 
5259         info = (struct dasd_ckd_host_information *)
5260                 access->host_access_information;
5261         for (i = 0; i < info->entry_count; i++) {
5262                 entry = (struct dasd_ckd_path_group_entry *)
5263                         (info->entry + i * info->entry_size);
5264                 if (entry->status_flags & DASD_ECKD_PG_GROUPED)
5265                         count++;
5266         }
5267 
5268         kfree(access);
5269         return count;
5270 }
5271 
5272 /*
5273  * write host access information to a sequential file
5274  */
5275 static int dasd_hosts_print(struct dasd_device *device, struct seq_file *m)
5276 {
5277         struct dasd_psf_query_host_access *access;
5278         struct dasd_ckd_path_group_entry *entry;
5279         struct dasd_ckd_host_information *info;
5280         char sysplex[9] = "";
5281         int rc, i, j;
5282 
5283         access = kzalloc(sizeof(*access), GFP_NOIO);
5284         if (!access) {
5285                 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5286                                 "Could not allocate access buffer");
5287                 return -ENOMEM;
5288         }
5289         rc = dasd_eckd_query_host_access(device, access);
5290         if (rc) {
5291                 kfree(access);
5292                 return rc;
5293         }
5294 
5295         info = (struct dasd_ckd_host_information *)
5296                 access->host_access_information;
5297         for (i = 0; i < info->entry_count; i++) {
5298                 entry = (struct dasd_ckd_path_group_entry *)
5299                         (info->entry + i * info->entry_size);
5300                 /* PGID */
5301                 seq_puts(m, "pgid ");
5302                 for (j = 0; j < 11; j++)
5303                         seq_printf(m, "%02x", entry->pgid[j]);
5304                 seq_putc(m, '\n');
5305                 /* FLAGS */
5306                 seq_printf(m, "status_flags %02x\n", entry->status_flags);
5307                 /* SYSPLEX NAME */
5308                 memcpy(&sysplex, &entry->sysplex_name, sizeof(sysplex) - 1);
5309                 EBCASC(sysplex, sizeof(sysplex));
5310                 seq_printf(m, "sysplex_name %8s\n", sysplex);
5311                 /* SUPPORTED CYLINDER */
5312                 seq_printf(m, "supported_cylinder %d\n", entry->cylinder);
5313                 /* TIMESTAMP */
5314                 seq_printf(m, "timestamp %lu\n", (unsigned long)
5315                            entry->timestamp);
5316         }
5317         kfree(access);
5318 
5319         return 0;
5320 }
5321 
5322 /*
5323  * Perform Subsystem Function - CUIR response
5324  */
5325 static int
5326 dasd_eckd_psf_cuir_response(struct dasd_device *device, int response,
5327                             __u32 message_id, __u8 lpum)
5328 {
5329         struct dasd_psf_cuir_response *psf_cuir;
5330         int pos = pathmask_to_pos(lpum);
5331         struct dasd_ccw_req *cqr;
5332         struct ccw1 *ccw;
5333         int rc;
5334 
5335         cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
5336                                   sizeof(struct dasd_psf_cuir_response),
5337                                   device);
5338 
5339         if (IS_ERR(cqr)) {
5340                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
5341                            "Could not allocate PSF-CUIR request");
5342                 return PTR_ERR(cqr);
5343         }
5344 
5345         psf_cuir = (struct dasd_psf_cuir_response *)cqr->data;
5346         psf_cuir->order = PSF_ORDER_CUIR_RESPONSE;
5347         psf_cuir->cc = response;
5348         psf_cuir->chpid = device->path[pos].chpid;
5349         psf_cuir->message_id = message_id;
5350         psf_cuir->cssid = device->path[pos].cssid;
5351         psf_cuir->ssid = device->path[pos].ssid;
5352         ccw = cqr->cpaddr;
5353         ccw->cmd_code = DASD_ECKD_CCW_PSF;
5354         ccw->cda = (__u32)(addr_t)psf_cuir;
5355         ccw->flags = CCW_FLAG_SLI;
5356         ccw->count = sizeof(struct dasd_psf_cuir_response);
5357 
5358         cqr->startdev = device;
5359         cqr->memdev = device;
5360         cqr->block = NULL;
5361         cqr->retries = 256;
5362         cqr->expires = 10*HZ;
5363         cqr->buildclk = get_tod_clock();
5364         cqr->status = DASD_CQR_FILLED;
5365         set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
5366 
5367         rc = dasd_sleep_on(cqr);
5368 
5369         dasd_sfree_request(cqr, cqr->memdev);
5370         return rc;
5371 }
5372 
5373 /*
5374  * return configuration data that is referenced by record selector
5375  * if a record selector is specified or per default return the
5376  * conf_data pointer for the path specified by lpum
5377  */
5378 static struct dasd_conf_data *dasd_eckd_get_ref_conf(struct dasd_device *device,
5379                                                      __u8 lpum,
5380                                                      struct dasd_cuir_message *cuir)
5381 {
5382         struct dasd_conf_data *conf_data;
5383         int path, pos;
5384 
5385         if (cuir->record_selector == 0)
5386                 goto out;
5387         for (path = 0x80, pos = 0; path; path >>= 1, pos++) {
5388                 conf_data = device->path[pos].conf_data;
5389                 if (conf_data->gneq.record_selector ==
5390                     cuir->record_selector)
5391                         return conf_data;
5392         }
5393 out:
5394         return device->path[pathmask_to_pos(lpum)].conf_data;
5395 }
5396 
5397 /*
5398  * This function determines the scope of a reconfiguration request by
5399  * analysing the path and device selection data provided in the CUIR request.
5400  * Returns a path mask containing CUIR affected paths for the give device.
5401  *
5402  * If the CUIR request does not contain the required information return the
5403  * path mask of the path the attention message for the CUIR request was reveived
5404  * on.
5405  */
5406 static int dasd_eckd_cuir_scope(struct dasd_device *device, __u8 lpum,
5407                                 struct dasd_cuir_message *cuir)
5408 {
5409         struct dasd_conf_data *ref_conf_data;
5410         unsigned long bitmask = 0, mask = 0;
5411         struct dasd_conf_data *conf_data;
5412         unsigned int pos, path;
5413         char *ref_gneq, *gneq;
5414         char *ref_ned, *ned;
5415         int tbcpm = 0;
5416 
5417         /* if CUIR request does not specify the scope use the path
5418            the attention message was presented on */
5419         if (!cuir->ned_map ||
5420             !(cuir->neq_map[0] | cuir->neq_map[1] | cuir->neq_map[2]))
5421                 return lpum;
5422 
5423         /* get reference conf data */
5424         ref_conf_data = dasd_eckd_get_ref_conf(device, lpum, cuir);
5425         /* reference ned is determined by ned_map field */
5426         pos = 8 - ffs(cuir->ned_map);
5427         ref_ned = (char *)&ref_conf_data->neds[pos];
5428         ref_gneq = (char *)&ref_conf_data->gneq;
5429         /* transfer 24 bit neq_map to mask */
5430         mask = cuir->neq_map[2];
5431         mask |= cuir->neq_map[1] << 8;
5432         mask |= cuir->neq_map[0] << 16;
5433 
5434         for (path = 0; path < 8; path++) {
5435                 /* initialise data per path */
5436                 bitmask = mask;
5437                 conf_data = device->path[path].conf_data;
5438                 pos = 8 - ffs(cuir->ned_map);
5439                 ned = (char *) &conf_data->neds[pos];
5440                 /* compare reference ned and per path ned */
5441                 if (memcmp(ref_ned, ned, sizeof(*ned)) != 0)
5442                         continue;
5443                 gneq = (char *)&conf_data->gneq;
5444                 /* compare reference gneq and per_path gneq under
5445                    24 bit mask where mask bit 0 equals byte 7 of
5446                    the gneq and mask bit 24 equals byte 31 */
5447                 while (bitmask) {
5448                         pos = ffs(bitmask) - 1;
5449                         if (memcmp(&ref_gneq[31 - pos], &gneq[31 - pos], 1)
5450                             != 0)
5451                                 break;
5452                         clear_bit(pos, &bitmask);
5453                 }
5454                 if (bitmask)
5455                         continue;
5456                 /* device and path match the reference values
5457                    add path to CUIR scope */
5458                 tbcpm |= 0x80 >> path;
5459         }
5460         return tbcpm;
5461 }
5462 
5463 static void dasd_eckd_cuir_notify_user(struct dasd_device *device,
5464                                        unsigned long paths, int action)
5465 {
5466         int pos;
5467 
5468         while (paths) {
5469                 /* get position of bit in mask */
5470                 pos = 8 - ffs(paths);
5471                 /* get channel path descriptor from this position */
5472                 if (action == CUIR_QUIESCE)
5473                         pr_warn("Service on the storage server caused path %x.%02x to go offline",
5474                                 device->path[pos].cssid,
5475                                 device->path[pos].chpid);
5476                 else if (action == CUIR_RESUME)
5477                         pr_info("Path %x.%02x is back online after service on the storage server",
5478                                 device->path[pos].cssid,
5479                                 device->path[pos].chpid);
5480                 clear_bit(7 - pos, &paths);
5481         }
5482 }
5483 
5484 static int dasd_eckd_cuir_remove_path(struct dasd_device *device, __u8 lpum,
5485                                       struct dasd_cuir_message *cuir)
5486 {
5487         unsigned long tbcpm;
5488 
5489         tbcpm = dasd_eckd_cuir_scope(device, lpum, cuir);
5490         /* nothing to do if path is not in use */
5491         if (!(dasd_path_get_opm(device) & tbcpm))
5492                 return 0;
5493         if (!(dasd_path_get_opm(device) & ~tbcpm)) {
5494                 /* no path would be left if the CUIR action is taken
5495                    return error */
5496                 return -EINVAL;
5497         }
5498         /* remove device from operational path mask */
5499         dasd_path_remove_opm(device, tbcpm);
5500         dasd_path_add_cuirpm(device, tbcpm);
5501         return tbcpm;
5502 }
5503 
5504 /*
5505  * walk through all devices and build a path mask to quiesce them
5506  * return an error if the last path to a device would be removed
5507  *
5508  * if only part of the devices are quiesced and an error
5509  * occurs no onlining necessary, the storage server will
5510  * notify the already set offline devices again
5511  */
5512 static int dasd_eckd_cuir_quiesce(struct dasd_device *device, __u8 lpum,
5513                                   struct dasd_cuir_message *cuir)
5514 {
5515         struct dasd_eckd_private *private = device->private;
5516         struct alias_pav_group *pavgroup, *tempgroup;
5517         struct dasd_device *dev, *n;
5518         unsigned long paths = 0;
5519         unsigned long flags;
5520         int tbcpm;
5521 
5522         /* active devices */
5523         list_for_each_entry_safe(dev, n, &private->lcu->active_devices,
5524                                  alias_list) {
5525                 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
5526                 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
5527                 spin_unlock_irqrestore(get_ccwdev_lock(dev->cdev), flags);
5528                 if (tbcpm < 0)
5529                         goto out_err;
5530                 paths |= tbcpm;
5531         }
5532         /* inactive devices */
5533         list_for_each_entry_safe(dev, n, &private->lcu->inactive_devices,
5534                                  alias_list) {
5535                 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
5536                 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
5537                 spin_unlock_irqrestore(get_ccwdev_lock(dev->cdev), flags);
5538                 if (tbcpm < 0)
5539                         goto out_err;
5540                 paths |= tbcpm;
5541         }
5542         /* devices in PAV groups */
5543         list_for_each_entry_safe(pavgroup, tempgroup,
5544                                  &private->lcu->grouplist, group) {
5545                 list_for_each_entry_safe(dev, n, &pavgroup->baselist,
5546                                          alias_list) {
5547                         spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
5548                         tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
5549                         spin_unlock_irqrestore(
5550                                 get_ccwdev_lock(dev->cdev), flags);
5551                         if (tbcpm < 0)
5552                                 goto out_err;
5553                         paths |= tbcpm;
5554                 }
5555                 list_for_each_entry_safe(dev, n, &pavgroup->aliaslist,
5556                                          alias_list) {
5557                         spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
5558                         tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
5559                         spin_unlock_irqrestore(
5560                                 get_ccwdev_lock(dev->cdev), flags);
5561                         if (tbcpm < 0)
5562                                 goto out_err;
5563                         paths |= tbcpm;
5564                 }
5565         }
5566         /* notify user about all paths affected by CUIR action */
5567         dasd_eckd_cuir_notify_user(device, paths, CUIR_QUIESCE);
5568         return 0;
5569 out_err:
5570         return tbcpm;
5571 }
5572 
5573 static int dasd_eckd_cuir_resume(struct dasd_device *device, __u8 lpum,
5574                                  struct dasd_cuir_message *cuir)
5575 {
5576         struct dasd_eckd_private *private = device->private;
5577         struct alias_pav_group *pavgroup, *tempgroup;
5578         struct dasd_device *dev, *n;
5579         unsigned long paths = 0;
5580         int tbcpm;
5581 
5582         /*
5583          * the path may have been added through a generic path event before
5584          * only trigger path verification if the path is not already in use
5585          */
5586         list_for_each_entry_safe(dev, n,
5587                                  &private->lcu->active_devices,
5588                                  alias_list) {
5589                 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
5590                 paths |= tbcpm;
5591                 if (!(dasd_path_get_opm(dev) & tbcpm)) {
5592                         dasd_path_add_tbvpm(dev, tbcpm);
5593                         dasd_schedule_device_bh(dev);
5594                 }
5595         }
5596         list_for_each_entry_safe(dev, n,
5597                                  &private->lcu->inactive_devices,
5598                                  alias_list) {
5599                 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
5600                 paths |= tbcpm;
5601                 if (!(dasd_path_get_opm(dev) & tbcpm)) {
5602                         dasd_path_add_tbvpm(dev, tbcpm);
5603                         dasd_schedule_device_bh(dev);
5604                 }
5605         }
5606         /* devices in PAV groups */
5607         list_for_each_entry_safe(pavgroup, tempgroup,
5608                                  &private->lcu->grouplist,
5609                                  group) {
5610                 list_for_each_entry_safe(dev, n,
5611                                          &pavgroup->baselist,
5612                                          alias_list) {
5613                         tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
5614                         paths |= tbcpm;
5615                         if (!(dasd_path_get_opm(dev) & tbcpm)) {
5616                                 dasd_path_add_tbvpm(dev, tbcpm);
5617                                 dasd_schedule_device_bh(dev);
5618                         }
5619                 }
5620                 list_for_each_entry_safe(dev, n,
5621                                          &pavgroup->aliaslist,
5622                                          alias_list) {
5623                         tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
5624                         paths |= tbcpm;
5625                         if (!(dasd_path_get_opm(dev) & tbcpm)) {
5626                                 dasd_path_add_tbvpm(dev, tbcpm);
5627                                 dasd_schedule_device_bh(dev);
5628                         }
5629                 }
5630         }
5631         /* notify user about all paths affected by CUIR action */
5632         dasd_eckd_cuir_notify_user(device, paths, CUIR_RESUME);
5633         return 0;
5634 }
5635 
5636 static void dasd_eckd_handle_cuir(struct dasd_device *device, void *messages,
5637                                  __u8 lpum)
5638 {
5639         struct dasd_cuir_message *cuir = messages;
5640         int response;
5641 
5642         DBF_DEV_EVENT(DBF_WARNING, device,
5643                       "CUIR request: %016llx %016llx %016llx %08x",
5644                       ((u64 *)cuir)[0], ((u64 *)cuir)[1], ((u64 *)cuir)[2],
5645                       ((u32 *)cuir)[3]);
5646 
5647         if (cuir->code == CUIR_QUIESCE) {
5648                 /* quiesce */
5649                 if (dasd_eckd_cuir_quiesce(device, lpum, cuir))
5650                         response = PSF_CUIR_LAST_PATH;
5651                 else
5652                         response = PSF_CUIR_COMPLETED;
5653         } else if (cuir->code == CUIR_RESUME) {
5654                 /* resume */
5655                 dasd_eckd_cuir_resume(device, lpum, cuir);
5656                 response = PSF_CUIR_COMPLETED;
5657         } else
5658                 response = PSF_CUIR_NOT_SUPPORTED;
5659 
5660         dasd_eckd_psf_cuir_response(device, response,
5661                                     cuir->message_id, lpum);
5662         DBF_DEV_EVENT(DBF_WARNING, device,
5663                       "CUIR response: %d on message ID %08x", response,
5664                       cuir->message_id);
5665         /* to make sure there is no attention left schedule work again */
5666         device->discipline->check_attention(device, lpum);
5667 }
5668 
5669 static void dasd_eckd_check_attention_work(struct work_struct *work)
5670 {
5671         struct check_attention_work_data *data;
5672         struct dasd_rssd_messages *messages;
5673         struct dasd_device *device;
5674         int rc;
5675 
5676         data = container_of(work, struct check_attention_work_data, worker);
5677         device = data->device;
5678         messages = kzalloc(sizeof(*messages), GFP_KERNEL);
5679         if (!messages) {
5680                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
5681                               "Could not allocate attention message buffer");
5682                 goto out;
5683         }
5684         rc = dasd_eckd_read_message_buffer(device, messages, data->lpum);
5685         if (rc)
5686                 goto out;
5687         if (messages->length == ATTENTION_LENGTH_CUIR &&
5688             messages->format == ATTENTION_FORMAT_CUIR)
5689                 dasd_eckd_handle_cuir(device, messages, data->lpum);
5690 out:
5691         dasd_put_device(device);
5692         kfree(messages);
5693         kfree(data);
5694 }
5695 
5696 static int dasd_eckd_check_attention(struct dasd_device *device, __u8 lpum)
5697 {
5698         struct check_attention_work_data *data;
5699 
5700         data = kzalloc(sizeof(*data), GFP_ATOMIC);
5701         if (!data)
5702                 return -ENOMEM;
5703         INIT_WORK(&data->worker, dasd_eckd_check_attention_work);
5704         dasd_get_device(device);
5705         data->device = device;
5706         data->lpum = lpum;
5707         schedule_work(&data->worker);
5708         return 0;
5709 }
5710 
5711 static int dasd_eckd_disable_hpf_path(struct dasd_device *device, __u8 lpum)
5712 {
5713         if (~lpum & dasd_path_get_opm(device)) {
5714                 dasd_path_add_nohpfpm(device, lpum);
5715                 dasd_path_remove_opm(device, lpum);
5716                 dev_err(&device->cdev->dev,
5717                         "Channel path %02X lost HPF functionality and is disabled\n",
5718                         lpum);
5719                 return 1;
5720         }
5721         return 0;
5722 }
5723 
5724 static void dasd_eckd_disable_hpf_device(struct dasd_device *device)
5725 {
5726         struct dasd_eckd_private *private = device->private;
5727 
5728         dev_err(&device->cdev->dev,
5729                 "High Performance FICON disabled\n");
5730         private->fcx_max_data = 0;
5731 }
5732 
5733 static int dasd_eckd_hpf_enabled(struct dasd_device *device)
5734 {
5735         struct dasd_eckd_private *private = device->private;
5736 
5737         return private->fcx_max_data ? 1 : 0;
5738 }
5739 
5740 static void dasd_eckd_handle_hpf_error(struct dasd_device *device,
5741                                        struct irb *irb)
5742 {
5743         struct dasd_eckd_private *private = device->private;
5744 
5745         if (!private->fcx_max_data) {
5746                 /* sanity check for no HPF, the error makes no sense */
5747                 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
5748                               "Trying to disable HPF for a non HPF device");
5749                 return;
5750         }
5751         if (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX) {
5752                 dasd_eckd_disable_hpf_device(device);
5753         } else if (irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX) {
5754                 if (dasd_eckd_disable_hpf_path(device, irb->esw.esw1.lpum))
5755                         return;
5756                 dasd_eckd_disable_hpf_device(device);
5757                 dasd_path_set_tbvpm(device,
5758                                   dasd_path_get_hpfpm(device));
5759         }
5760         /*
5761          * prevent that any new I/O ist started on the device and schedule a
5762          * requeue of existing requests
5763          */
5764         dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
5765         dasd_schedule_requeue(device);
5766 }
5767 
5768 static struct ccw_driver dasd_eckd_driver = {
5769         .driver = {
5770                 .name   = "dasd-eckd",
5771                 .owner  = THIS_MODULE,
5772         },
5773         .ids         = dasd_eckd_ids,
5774         .probe       = dasd_eckd_probe,
5775         .remove      = dasd_generic_remove,
5776         .set_offline = dasd_generic_set_offline,
5777         .set_online  = dasd_eckd_set_online,
5778         .notify      = dasd_generic_notify,
5779         .path_event  = dasd_generic_path_event,
5780         .shutdown    = dasd_generic_shutdown,
5781         .freeze      = dasd_generic_pm_freeze,
5782         .thaw        = dasd_generic_restore_device,
5783         .restore     = dasd_generic_restore_device,
5784         .uc_handler  = dasd_generic_uc_handler,
5785         .int_class   = IRQIO_DAS,
5786 };
5787 
5788 /*
5789  * max_blocks is dependent on the amount of storage that is available
5790  * in the static io buffer for each device. Currently each device has
5791  * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
5792  * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
5793  * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
5794  * addition we have one define extent ccw + 16 bytes of data and one
5795  * locate record ccw + 16 bytes of data. That makes:
5796  * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
5797  * We want to fit two into the available memory so that we can immediately
5798  * start the next request if one finishes off. That makes 249.5 blocks
5799  * for one request. Give a little safety and the result is 240.
5800  */
5801 static struct dasd_discipline dasd_eckd_discipline = {
5802         .owner = THIS_MODULE,
5803         .name = "ECKD",
5804         .ebcname = "ECKD",
5805         .max_blocks = 190,
5806         .check_device = dasd_eckd_check_characteristics,
5807         .uncheck_device = dasd_eckd_uncheck_device,
5808         .do_analysis = dasd_eckd_do_analysis,
5809         .verify_path = dasd_eckd_verify_path,
5810         .basic_to_ready = dasd_eckd_basic_to_ready,
5811         .online_to_ready = dasd_eckd_online_to_ready,
5812         .basic_to_known = dasd_eckd_basic_to_known,
5813         .fill_geometry = dasd_eckd_fill_geometry,
5814         .start_IO = dasd_start_IO,
5815         .term_IO = dasd_term_IO,
5816         .handle_terminated_request = dasd_eckd_handle_terminated_request,
5817         .format_device = dasd_eckd_format_device,
5818         .check_device_format = dasd_eckd_check_device_format,
5819         .erp_action = dasd_eckd_erp_action,
5820         .erp_postaction = dasd_eckd_erp_postaction,
5821         .check_for_device_change = dasd_eckd_check_for_device_change,
5822         .build_cp = dasd_eckd_build_alias_cp,
5823         .free_cp = dasd_eckd_free_alias_cp,
5824         .dump_sense = dasd_eckd_dump_sense,
5825         .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
5826         .fill_info = dasd_eckd_fill_info,
5827         .ioctl = dasd_eckd_ioctl,
5828         .freeze = dasd_eckd_pm_freeze,
5829         .restore = dasd_eckd_restore_device,
5830         .reload = dasd_eckd_reload_device,
5831         .get_uid = dasd_eckd_get_uid,
5832         .kick_validate = dasd_eckd_kick_validate_server,
5833         .check_attention = dasd_eckd_check_attention,
5834         .host_access_count = dasd_eckd_host_access_count,
5835         .hosts_print = dasd_hosts_print,
5836         .handle_hpf_error = dasd_eckd_handle_hpf_error,
5837         .disable_hpf = dasd_eckd_disable_hpf_device,
5838         .hpf_enabled = dasd_eckd_hpf_enabled,
5839         .reset_path = dasd_eckd_reset_path,
5840 };
5841 
5842 static int __init
5843 dasd_eckd_init(void)
5844 {
5845         int ret;
5846 
5847         ASCEBC(dasd_eckd_discipline.ebcname, 4);
5848         dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
5849                                    GFP_KERNEL | GFP_DMA);
5850         if (!dasd_reserve_req)
5851                 return -ENOMEM;
5852         path_verification_worker = kmalloc(sizeof(*path_verification_worker),
5853                                    GFP_KERNEL | GFP_DMA);
5854         if (!path_verification_worker) {
5855                 kfree(dasd_reserve_req);
5856                 return -ENOMEM;
5857         }
5858         rawpadpage = (void *)__get_free_page(GFP_KERNEL);
5859         if (!rawpadpage) {
5860                 kfree(path_verification_worker);
5861                 kfree(dasd_reserve_req);
5862                 return -ENOMEM;
5863         }
5864         ret = ccw_driver_register(&dasd_eckd_driver);
5865         if (!ret)
5866                 wait_for_device_probe();
5867         else {
5868                 kfree(path_verification_worker);
5869                 kfree(dasd_reserve_req);
5870                 free_page((unsigned long)rawpadpage);
5871         }
5872         return ret;
5873 }
5874 
5875 static void __exit
5876 dasd_eckd_cleanup(void)
5877 {
5878         ccw_driver_unregister(&dasd_eckd_driver);
5879         kfree(path_verification_worker);
5880         kfree(dasd_reserve_req);
5881         free_page((unsigned long)rawpadpage);
5882 }
5883 
5884 module_init(dasd_eckd_init);
5885 module_exit(dasd_eckd_cleanup);
5886 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us