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>
12 #define KMSG_COMPONENT "dasd-eckd"
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>
24 #include <asm/css_chars.h>
25 #include <asm/debug.h>
26 #include <asm/idals.h>
27 #include <asm/ebcdic.h>
29 #include <asm/uaccess.h>
31 #include <asm/ccwdev.h>
33 #include <asm/schid.h>
34 #include <asm/chpid.h>
37 #include "dasd_eckd.h"
41 #endif /* PRINTK_HEADER */
42 #define PRINTK_HEADER "dasd(eckd):"
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)
59 * raw track access always map to 64k in memory
60 * so it maps to 16 blocks of 4k per track
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
67 MODULE_LICENSE("GPL");
69 static struct dasd_discipline dasd_eckd_discipline;
71 /* The ccw bus type uses this table to find devices that it sends to
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 */ },
87 MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
89 static struct ccw_driver dasd_eckd_driver; /* see below */
91 static void *rawpadpage;
94 #define INIT_CQR_UNFORMATTED 1
95 #define INIT_CQR_ERROR 2
97 /* emergency request for reserve/release */
99 struct dasd_ccw_req cqr;
103 static DEFINE_MUTEX(dasd_reserve_mutex);
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;
111 __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE];
115 static struct path_verification_work_data *path_verification_worker;
116 static DEFINE_MUTEX(dasd_path_verification_mutex);
118 struct check_attention_work_data {
119 struct work_struct worker;
120 struct dasd_device *device;
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);
129 /* initial attempt at a probe function. this can be simplified once
130 * the other detection code is gone */
132 dasd_eckd_probe (struct ccw_device *cdev)
136 /* set ECKD specific ccw-device options */
137 ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE |
138 CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH);
140 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
141 "dasd_eckd_probe: could not set "
142 "ccw-device options");
145 ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
150 dasd_eckd_set_online(struct ccw_device *cdev)
152 return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
155 static const int sizes_trk0[] = { 28, 148, 84 };
156 #define LABEL_SIZE 140
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 };
162 static inline unsigned int
163 round_up_multiple(unsigned int no, unsigned int mult)
166 return (rem ? no - rem + mult : no);
169 static inline unsigned int
170 ceil_quot(unsigned int d1, unsigned int d2)
172 return (d1 + (d2 - 1)) / d2;
176 recs_per_track(struct dasd_eckd_characteristics * rdc,
177 unsigned int kl, unsigned int dl)
181 switch (rdc->dev_type) {
184 return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
185 ceil_quot(dl + 12, 32));
187 return 1499 / (15 + ceil_quot(dl + 12, 32));
189 dn = ceil_quot(dl + 6, 232) + 1;
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));
195 return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
197 dn = ceil_quot(dl + 6, 232) + 1;
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));
203 return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
208 static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
210 geo->cyl = (__u16) cyl;
211 geo->head = cyl >> 16;
217 check_XRC (struct ccw1 *de_ccw,
218 struct DE_eckd_data *data,
219 struct dasd_device *device)
221 struct dasd_eckd_private *private = device->private;
224 if (!private->rdc_data.facilities.XRC_supported)
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' */
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)
236 de_ccw->count = sizeof(struct DE_eckd_data);
237 de_ccw->flags |= CCW_FLAG_SLI;
242 define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
243 unsigned int totrk, int cmd, struct dasd_device *device)
245 struct dasd_eckd_private *private = device->private;
247 u16 heads, beghead, endhead;
250 ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
253 ccw->cda = (__u32) __pa(data);
255 memset(data, 0, sizeof(struct DE_eckd_data));
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;
268 case DASD_ECKD_CCW_READ_COUNT:
269 data->mask.perm = 0x1;
270 data->attributes.operation = DASD_BYPASS_CACHE;
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);
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);
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);
294 dev_err(&device->cdev->dev,
295 "0x%x is not a known command\n", cmd);
299 data->attributes.mode = 0x3; /* ECKD */
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 */
307 heads = private->rdc_data.trk_per_cyl;
308 begcyl = trk / heads;
309 beghead = trk % heads;
310 endcyl = totrk / heads;
311 endhead = totrk % heads;
313 /* check for sequential prestage - enhance cylinder range */
314 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
315 data->attributes.operation == DASD_SEQ_ACCESS) {
317 if (endcyl + private->attrib.nr_cyl < private->real_cyl)
318 endcyl += private->attrib.nr_cyl;
320 endcyl = (private->real_cyl - 1);
323 set_ch_t(&data->beg_ext, begcyl, beghead);
324 set_ch_t(&data->end_ext, endcyl, endhead);
328 static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
329 struct dasd_device *device)
331 struct dasd_eckd_private *private = device->private;
334 if (!private->rdc_data.facilities.XRC_supported)
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' */
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)
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,
354 struct dasd_eckd_private *private = device->private;
358 memset(data, 0, sizeof(*data));
361 switch (private->rdc_data.dev_type) {
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;
368 d = 7 + ceil_quot(reclen + 12, 32);
369 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
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
380 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
381 data->operation.orientation = 0x3;
382 data->operation.operation = 0x03;
384 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
385 data->operation.orientation = 0x3;
386 data->operation.operation = 0x16;
388 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
389 data->operation.orientation = 0x1;
390 data->operation.operation = 0x03;
393 case DASD_ECKD_CCW_READ_RECORD_ZERO:
394 data->operation.orientation = 0x3;
395 data->operation.operation = 0x16;
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;
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;
412 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
413 data->operation.orientation = 0x0;
414 data->operation.operation = 0x3F;
415 data->extended_operation = 0x11;
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);
423 data->extended_parameter[0] = 0xFF;
424 data->extended_parameter[0] <<= (8 - count);
425 data->extended_parameter[1] = 0x00;
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;
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;
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;
449 case DASD_ECKD_CCW_READ_COUNT:
450 data->operation.operation = 0x06;
452 case DASD_ECKD_CCW_READ_TRACK:
453 data->operation.orientation = 0x1;
454 data->operation.operation = 0x0C;
455 data->extended_parameter_length = 0;
458 case DASD_ECKD_CCW_READ_TRACK_DATA:
459 data->auxiliary.length_valid = 0x1;
461 data->operation.operation = 0x0C;
463 case DASD_ECKD_CCW_ERASE:
464 data->length = reclen;
465 data->auxiliary.length_valid = 0x1;
466 data->operation.operation = 0x0b;
469 DBF_DEV_EVENT(DBF_ERR, device,
470 "fill LRE unknown opcode 0x%x", cmd);
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;
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)
487 struct dasd_eckd_private *basepriv, *startpriv;
488 struct DE_eckd_data *dedata;
489 struct LRE_eckd_data *lredata;
491 u16 heads, beghead, endhead;
494 basepriv = basedev->private;
495 startpriv = startdev->private;
496 dedata = &pfxdata->define_extent;
497 lredata = &pfxdata->locate_record;
499 ccw->cmd_code = DASD_ECKD_CCW_PFX;
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);
506 ccw->count = sizeof(*pfxdata);
507 ccw->cda = (__u32) __pa(pfxdata);
508 memset(pfxdata, 0, sizeof(*pfxdata));
513 DBF_DEV_EVENT(DBF_ERR, basedev,
514 "PFX LRE unknown format 0x%x", format);
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;
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;
530 /* define extend data (mostly)*/
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;
543 case DASD_ECKD_CCW_READ_COUNT:
544 dedata->mask.perm = 0x1;
545 dedata->attributes.operation = DASD_BYPASS_CACHE;
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;
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);
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);
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);
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;
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);
586 DBF_DEV_EVENT(DBF_ERR, basedev,
587 "PFX LRE unknown opcode 0x%x", cmd);
592 dedata->attributes.mode = 0x3; /* ECKD */
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 */
600 heads = basepriv->rdc_data.trk_per_cyl;
601 begcyl = trk / heads;
602 beghead = trk % heads;
603 endcyl = totrk / heads;
604 endhead = totrk % heads;
606 /* check for sequential prestage - enhance cylinder range */
607 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
608 dedata->attributes.operation == DASD_SEQ_ACCESS) {
610 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
611 endcyl += basepriv->attrib.nr_cyl;
613 endcyl = (basepriv->real_cyl - 1);
616 set_ch_t(&dedata->beg_ext, begcyl, beghead);
617 set_ch_t(&dedata->end_ext, endcyl, endhead);
620 fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
621 basedev, blksize, tlf);
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)
631 return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
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)
640 struct dasd_eckd_private *private = device->private;
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);
648 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
651 ccw->cda = (__u32) __pa(data);
653 memset(data, 0, sizeof(struct LO_eckd_data));
656 switch (private->rdc_data.dev_type) {
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;
663 d = 7 + ceil_quot(reclen + 12, 32);
664 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
668 data->sector = sector;
669 data->count = no_rec;
671 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
672 data->operation.orientation = 0x3;
673 data->operation.operation = 0x03;
675 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
676 data->operation.orientation = 0x3;
677 data->operation.operation = 0x16;
679 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
680 data->operation.orientation = 0x1;
681 data->operation.operation = 0x03;
684 case DASD_ECKD_CCW_READ_RECORD_ZERO:
685 data->operation.orientation = 0x3;
686 data->operation.operation = 0x16;
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;
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;
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;
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;
717 case DASD_ECKD_CCW_READ_COUNT:
718 data->operation.operation = 0x06;
720 case DASD_ECKD_CCW_ERASE:
721 data->length = reclen;
722 data->auxiliary.last_bytes_used = 0x1;
723 data->operation.operation = 0x0b;
726 DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
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;
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;
748 dasd_eckd_cdl_special(int blk_per_trk, int recid)
752 if (recid < blk_per_trk)
754 if (recid < 2 * blk_per_trk)
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
765 dasd_eckd_cdl_reclen(int recid)
768 return sizes_trk0[recid];
771 /* create unique id from private structure. */
772 static void create_uid(struct dasd_eckd_private *private)
775 struct dasd_uid *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;
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;
792 uid->type = UA_BASE_DEVICE;
794 if (private->vdsneq) {
795 for (count = 0; count < 16; count++) {
796 sprintf(uid->vduit+2*count, "%02x",
797 private->vdsneq->uit[count]);
803 * Generate device unique id that specifies the physical device.
805 static int dasd_eckd_generate_uid(struct dasd_device *device)
807 struct dasd_eckd_private *private = device->private;
812 if (!private->ned || !private->gneq)
814 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
816 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
820 static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
822 struct dasd_eckd_private *private = device->private;
826 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
828 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
835 * compare device UID with data of a given dasd_eckd_private structure
838 static int dasd_eckd_compare_path_uid(struct dasd_device *device,
839 struct dasd_eckd_private *private)
841 struct dasd_uid device_uid;
844 dasd_eckd_get_uid(device, &device_uid);
846 return memcmp(&device_uid, &private->uid, sizeof(struct dasd_uid));
849 static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device,
850 struct dasd_ccw_req *cqr,
856 * buffer has to start with EBCDIC "V1.0" to show
857 * support for virtual device SNEQ
859 rcd_buffer[0] = 0xE5;
860 rcd_buffer[1] = 0xF1;
861 rcd_buffer[2] = 0x4B;
862 rcd_buffer[3] = 0xF0;
865 ccw->cmd_code = DASD_ECKD_CCW_RCD;
867 ccw->cda = (__u32)(addr_t)rcd_buffer;
868 ccw->count = DASD_ECKD_RCD_DATA_SIZE;
869 cqr->magic = DASD_ECKD_MAGIC;
871 cqr->startdev = device;
872 cqr->memdev = device;
874 cqr->expires = 10*HZ;
877 cqr->buildclk = get_tod_clock();
878 cqr->status = DASD_CQR_FILLED;
879 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
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
888 static void read_conf_cb(struct dasd_ccw_req *cqr, void *data)
893 if (cqr->status != DASD_CQR_DONE) {
895 rcd_buffer = (__u8 *)((addr_t) ccw->cda);
896 memset(rcd_buffer, 0, sizeof(*rcd_buffer));
898 rcd_buffer[0] = 0xE5;
899 rcd_buffer[1] = 0xF1;
900 rcd_buffer[2] = 0x4B;
901 rcd_buffer[3] = 0xF0;
903 dasd_wakeup_cb(cqr, data);
906 static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
907 struct dasd_ccw_req *cqr,
914 * sanity check: scan for RCD command in extended SenseID data
915 * some devices do not support RCD
917 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
918 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD)
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);
925 cqr->callback = read_conf_cb;
926 rc = dasd_sleep_on_immediatly(cqr);
930 static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
932 int *rcd_buffer_size, __u8 lpm)
935 char *rcd_buf = NULL;
937 struct dasd_ccw_req *cqr;
940 * sanity check: scan for RCD command in extended SenseID data
941 * some devices do not support RCD
943 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
944 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) {
948 rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA);
953 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */,
954 0, /* use rcd_buf as data ara */
957 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
958 "Could not allocate RCD request");
962 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm);
963 cqr->callback = read_conf_cb;
964 ret = dasd_sleep_on(cqr);
966 * on success we update the user input parms
968 dasd_sfree_request(cqr, cqr->memdev);
972 *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE;
973 *rcd_buffer = rcd_buf;
978 *rcd_buffer_size = 0;
982 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
985 struct dasd_sneq *sneq;
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;
1005 if (!private->ned || !private->gneq) {
1006 private->ned = NULL;
1007 private->sneq = NULL;
1008 private->vdsneq = NULL;
1009 private->gneq = NULL;
1016 static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
1018 struct dasd_gneq *gneq;
1019 int i, count, found;
1021 count = conf_len / sizeof(*gneq);
1022 gneq = (struct dasd_gneq *)conf_data;
1024 for (i = 0; i < count; ++i) {
1025 if (gneq->flags.identifier == 2) {
1032 return ((char *)gneq)[18] & 0x07;
1037 static void dasd_eckd_clear_conf_data(struct dasd_device *device)
1039 struct dasd_eckd_private *private = device->private;
1042 private->conf_data = NULL;
1043 private->conf_len = 0;
1044 for (i = 0; i < 8; i++) {
1045 kfree(private->path_conf_data[i]);
1046 private->path_conf_data[i] = NULL;
1051 static int dasd_eckd_read_conf(struct dasd_device *device)
1054 int conf_len, conf_data_saved;
1055 int rc, path_err, pos;
1057 struct dasd_eckd_private *private, path_private;
1058 struct dasd_path *path_data;
1059 struct dasd_uid *uid;
1060 char print_path_uid[60], print_device_uid[60];
1062 private = device->private;
1063 path_data = &device->path_data;
1064 opm = ccw_device_get_path_mask(device->cdev);
1065 conf_data_saved = 0;
1067 /* get configuration data per operational path */
1068 for (lpm = 0x80; lpm; lpm>>= 1) {
1071 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
1073 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
1074 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1075 "Read configuration data returned "
1079 if (conf_data == NULL) {
1080 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1081 "No configuration data "
1083 /* no further analysis possible */
1084 path_data->opm |= lpm;
1085 continue; /* no error */
1087 /* save first valid configuration data */
1088 if (!conf_data_saved) {
1089 /* initially clear previously stored conf_data */
1090 dasd_eckd_clear_conf_data(device);
1091 private->conf_data = conf_data;
1092 private->conf_len = conf_len;
1093 if (dasd_eckd_identify_conf_parts(private)) {
1094 private->conf_data = NULL;
1095 private->conf_len = 0;
1099 pos = pathmask_to_pos(lpm);
1100 /* store per path conf_data */
1101 private->path_conf_data[pos] =
1102 (struct dasd_conf_data *) conf_data;
1104 * build device UID that other path data
1105 * can be compared to it
1107 dasd_eckd_generate_uid(device);
1110 path_private.conf_data = conf_data;
1111 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1112 if (dasd_eckd_identify_conf_parts(
1114 path_private.conf_data = NULL;
1115 path_private.conf_len = 0;
1119 if (dasd_eckd_compare_path_uid(
1120 device, &path_private)) {
1121 uid = &path_private.uid;
1122 if (strlen(uid->vduit) > 0)
1123 snprintf(print_path_uid,
1124 sizeof(print_path_uid),
1125 "%s.%s.%04x.%02x.%s",
1126 uid->vendor, uid->serial,
1127 uid->ssid, uid->real_unit_addr,
1130 snprintf(print_path_uid,
1131 sizeof(print_path_uid),
1133 uid->vendor, uid->serial,
1135 uid->real_unit_addr);
1136 uid = &private->uid;
1137 if (strlen(uid->vduit) > 0)
1138 snprintf(print_device_uid,
1139 sizeof(print_device_uid),
1140 "%s.%s.%04x.%02x.%s",
1141 uid->vendor, uid->serial,
1142 uid->ssid, uid->real_unit_addr,
1145 snprintf(print_device_uid,
1146 sizeof(print_device_uid),
1148 uid->vendor, uid->serial,
1150 uid->real_unit_addr);
1151 dev_err(&device->cdev->dev,
1152 "Not all channel paths lead to "
1153 "the same device, path %02X leads to "
1154 "device %s instead of %s\n", lpm,
1155 print_path_uid, print_device_uid);
1157 path_data->cablepm |= lpm;
1160 pos = pathmask_to_pos(lpm);
1161 /* store per path conf_data */
1162 private->path_conf_data[pos] =
1163 (struct dasd_conf_data *) conf_data;
1164 path_private.conf_data = NULL;
1165 path_private.conf_len = 0;
1167 switch (dasd_eckd_path_access(conf_data, conf_len)) {
1169 path_data->npm |= lpm;
1172 path_data->ppm |= lpm;
1175 if (!path_data->opm) {
1176 path_data->opm = lpm;
1177 dasd_generic_path_operational(device);
1179 path_data->opm |= lpm;
1182 * if the path is used
1183 * it should not be in one of the negative lists
1185 path_data->cablepm &= ~lpm;
1186 path_data->hpfpm &= ~lpm;
1187 path_data->cuirpm &= ~lpm;
1193 static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
1195 struct dasd_eckd_private *private = device->private;
1199 if (private->fcx_max_data) {
1200 mdc = ccw_device_get_mdc(device->cdev, lpm);
1202 dev_warn(&device->cdev->dev,
1203 "Detecting the maximum data size for zHPF "
1204 "requests failed (rc=%d) for a new path %x\n",
1208 fcx_max_data = mdc * FCX_MAX_DATA_FACTOR;
1209 if (fcx_max_data < private->fcx_max_data) {
1210 dev_warn(&device->cdev->dev,
1211 "The maximum data size for zHPF requests %u "
1212 "on a new path %x is below the active maximum "
1213 "%u\n", fcx_max_data, lpm,
1214 private->fcx_max_data);
1221 static int rebuild_device_uid(struct dasd_device *device,
1222 struct path_verification_work_data *data)
1224 struct dasd_eckd_private *private = device->private;
1225 struct dasd_path *path_data = &device->path_data;
1226 __u8 lpm, opm = path_data->opm;
1229 for (lpm = 0x80; lpm; lpm >>= 1) {
1232 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1233 memset(&data->cqr, 0, sizeof(data->cqr));
1234 data->cqr.cpaddr = &data->ccw;
1235 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1240 if (rc == -EOPNOTSUPP) /* -EOPNOTSUPP is ok */
1242 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1243 "Read configuration data "
1244 "returned error %d", rc);
1247 memcpy(private->conf_data, data->rcd_buffer,
1248 DASD_ECKD_RCD_DATA_SIZE);
1249 if (dasd_eckd_identify_conf_parts(private)) {
1251 } else /* first valid path is enough */
1256 rc = dasd_eckd_generate_uid(device);
1261 static void do_path_verification_work(struct work_struct *work)
1263 struct path_verification_work_data *data;
1264 struct dasd_device *device;
1265 struct dasd_eckd_private path_private;
1266 struct dasd_uid *uid;
1267 __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE];
1268 __u8 lpm, opm, npm, ppm, epm, hpfpm, cablepm;
1269 unsigned long flags;
1273 data = container_of(work, struct path_verification_work_data, worker);
1274 device = data->device;
1276 /* delay path verification until device was resumed */
1277 if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
1278 schedule_work(work);
1281 /* check if path verification already running and delay if so */
1282 if (test_and_set_bit(DASD_FLAG_PATH_VERIFY, &device->flags)) {
1283 schedule_work(work);
1293 for (lpm = 0x80; lpm; lpm >>= 1) {
1294 if (!(lpm & data->tbvpm))
1296 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1297 memset(&data->cqr, 0, sizeof(data->cqr));
1298 data->cqr.cpaddr = &data->ccw;
1299 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1303 switch (dasd_eckd_path_access(data->rcd_buffer,
1304 DASD_ECKD_RCD_DATA_SIZE)
1314 } else if (rc == -EOPNOTSUPP) {
1315 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1316 "path verification: No configuration "
1319 } else if (rc == -EAGAIN) {
1320 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1321 "path verification: device is stopped,"
1322 " try again later");
1325 dev_warn(&device->cdev->dev,
1326 "Reading device feature codes failed "
1327 "(rc=%d) for new path %x\n", rc, lpm);
1330 if (verify_fcx_max_data(device, lpm)) {
1339 * save conf_data for comparison after
1340 * rebuild_device_uid may have changed
1343 memcpy(&path_rcd_buf, data->rcd_buffer,
1344 DASD_ECKD_RCD_DATA_SIZE);
1345 path_private.conf_data = (void *) &path_rcd_buf;
1346 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1347 if (dasd_eckd_identify_conf_parts(&path_private)) {
1348 path_private.conf_data = NULL;
1349 path_private.conf_len = 0;
1354 * compare path UID with device UID only if at least
1355 * one valid path is left
1356 * in other case the device UID may have changed and
1357 * the first working path UID will be used as device UID
1359 if (device->path_data.opm &&
1360 dasd_eckd_compare_path_uid(device, &path_private)) {
1362 * the comparison was not successful
1363 * rebuild the device UID with at least one
1364 * known path in case a z/VM hyperswap command
1365 * has changed the device
1367 * after this compare again
1369 * if either the rebuild or the recompare fails
1370 * the path can not be used
1372 if (rebuild_device_uid(device, data) ||
1373 dasd_eckd_compare_path_uid(
1374 device, &path_private)) {
1375 uid = &path_private.uid;
1376 if (strlen(uid->vduit) > 0)
1377 snprintf(print_uid, sizeof(print_uid),
1378 "%s.%s.%04x.%02x.%s",
1379 uid->vendor, uid->serial,
1380 uid->ssid, uid->real_unit_addr,
1383 snprintf(print_uid, sizeof(print_uid),
1385 uid->vendor, uid->serial,
1387 uid->real_unit_addr);
1388 dev_err(&device->cdev->dev,
1389 "The newly added channel path %02X "
1390 "will not be used because it leads "
1391 "to a different device %s\n",
1402 * There is a small chance that a path is lost again between
1403 * above path verification and the following modification of
1404 * the device opm mask. We could avoid that race here by using
1405 * yet another path mask, but we rather deal with this unlikely
1406 * situation in dasd_start_IO.
1408 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1409 if (!device->path_data.opm && opm) {
1410 device->path_data.opm = opm;
1411 device->path_data.cablepm &= ~opm;
1412 device->path_data.cuirpm &= ~opm;
1413 device->path_data.hpfpm &= ~opm;
1414 dasd_generic_path_operational(device);
1416 device->path_data.opm |= opm;
1417 device->path_data.cablepm &= ~opm;
1418 device->path_data.cuirpm &= ~opm;
1419 device->path_data.hpfpm &= ~opm;
1421 device->path_data.npm |= npm;
1422 device->path_data.ppm |= ppm;
1423 device->path_data.tbvpm |= epm;
1424 device->path_data.cablepm |= cablepm;
1425 device->path_data.hpfpm |= hpfpm;
1426 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1428 clear_bit(DASD_FLAG_PATH_VERIFY, &device->flags);
1429 dasd_put_device(device);
1431 mutex_unlock(&dasd_path_verification_mutex);
1436 static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm)
1438 struct path_verification_work_data *data;
1440 data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA);
1442 if (mutex_trylock(&dasd_path_verification_mutex)) {
1443 data = path_verification_worker;
1448 memset(data, 0, sizeof(*data));
1451 INIT_WORK(&data->worker, do_path_verification_work);
1452 dasd_get_device(device);
1453 data->device = device;
1455 schedule_work(&data->worker);
1459 static int dasd_eckd_read_features(struct dasd_device *device)
1461 struct dasd_eckd_private *private = device->private;
1462 struct dasd_psf_prssd_data *prssdp;
1463 struct dasd_rssd_features *features;
1464 struct dasd_ccw_req *cqr;
1468 memset(&private->features, 0, sizeof(struct dasd_rssd_features));
1469 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
1470 (sizeof(struct dasd_psf_prssd_data) +
1471 sizeof(struct dasd_rssd_features)),
1474 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not "
1475 "allocate initialization request");
1476 return PTR_ERR(cqr);
1478 cqr->startdev = device;
1479 cqr->memdev = device;
1482 cqr->expires = 10 * HZ;
1484 /* Prepare for Read Subsystem Data */
1485 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1486 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
1487 prssdp->order = PSF_ORDER_PRSSD;
1488 prssdp->suborder = 0x41; /* Read Feature Codes */
1489 /* all other bytes of prssdp must be zero */
1492 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1493 ccw->count = sizeof(struct dasd_psf_prssd_data);
1494 ccw->flags |= CCW_FLAG_CC;
1495 ccw->cda = (__u32)(addr_t) prssdp;
1497 /* Read Subsystem Data - feature codes */
1498 features = (struct dasd_rssd_features *) (prssdp + 1);
1499 memset(features, 0, sizeof(struct dasd_rssd_features));
1502 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
1503 ccw->count = sizeof(struct dasd_rssd_features);
1504 ccw->cda = (__u32)(addr_t) features;
1506 cqr->buildclk = get_tod_clock();
1507 cqr->status = DASD_CQR_FILLED;
1508 rc = dasd_sleep_on(cqr);
1510 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1511 features = (struct dasd_rssd_features *) (prssdp + 1);
1512 memcpy(&private->features, features,
1513 sizeof(struct dasd_rssd_features));
1515 dev_warn(&device->cdev->dev, "Reading device feature codes"
1516 " failed with rc=%d\n", rc);
1517 dasd_sfree_request(cqr, cqr->memdev);
1523 * Build CP for Perform Subsystem Function - SSC.
1525 static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
1528 struct dasd_ccw_req *cqr;
1529 struct dasd_psf_ssc_data *psf_ssc_data;
1532 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
1533 sizeof(struct dasd_psf_ssc_data),
1537 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1538 "Could not allocate PSF-SSC request");
1541 psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1542 psf_ssc_data->order = PSF_ORDER_SSC;
1543 psf_ssc_data->suborder = 0xc0;
1545 psf_ssc_data->suborder |= 0x08;
1546 psf_ssc_data->reserved[0] = 0x88;
1549 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1550 ccw->cda = (__u32)(addr_t)psf_ssc_data;
1553 cqr->startdev = device;
1554 cqr->memdev = device;
1557 cqr->expires = 10*HZ;
1558 cqr->buildclk = get_tod_clock();
1559 cqr->status = DASD_CQR_FILLED;
1564 * Perform Subsystem Function.
1565 * It is necessary to trigger CIO for channel revalidation since this
1566 * call might change behaviour of DASD devices.
1569 dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav,
1570 unsigned long flags)
1572 struct dasd_ccw_req *cqr;
1575 cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
1577 return PTR_ERR(cqr);
1580 * set flags e.g. turn on failfast, to prevent blocking
1581 * the calling function should handle failed requests
1583 cqr->flags |= flags;
1585 rc = dasd_sleep_on(cqr);
1587 /* trigger CIO to reprobe devices */
1588 css_schedule_reprobe();
1589 else if (cqr->intrc == -EAGAIN)
1592 dasd_sfree_request(cqr, cqr->memdev);
1597 * Valide storage server of current device.
1599 static int dasd_eckd_validate_server(struct dasd_device *device,
1600 unsigned long flags)
1602 struct dasd_eckd_private *private = device->private;
1605 if (private->uid.type == UA_BASE_PAV_ALIAS ||
1606 private->uid.type == UA_HYPER_PAV_ALIAS)
1608 if (dasd_nopav || MACHINE_IS_VM)
1612 rc = dasd_eckd_psf_ssc(device, enable_pav, flags);
1614 /* may be requested feature is not available on server,
1615 * therefore just report error and go ahead */
1616 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
1617 "returned rc=%d", private->uid.ssid, rc);
1622 * worker to do a validate server in case of a lost pathgroup
1624 static void dasd_eckd_do_validate_server(struct work_struct *work)
1626 struct dasd_device *device = container_of(work, struct dasd_device,
1628 unsigned long flags = 0;
1630 set_bit(DASD_CQR_FLAGS_FAILFAST, &flags);
1631 if (dasd_eckd_validate_server(device, flags)
1633 /* schedule worker again if failed */
1634 schedule_work(&device->kick_validate);
1638 dasd_put_device(device);
1641 static void dasd_eckd_kick_validate_server(struct dasd_device *device)
1643 dasd_get_device(device);
1644 /* exit if device not online or in offline processing */
1645 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1646 device->state < DASD_STATE_ONLINE) {
1647 dasd_put_device(device);
1650 /* queue call to do_validate_server to the kernel event daemon. */
1651 if (!schedule_work(&device->kick_validate))
1652 dasd_put_device(device);
1655 static u32 get_fcx_max_data(struct dasd_device *device)
1657 struct dasd_eckd_private *private = device->private;
1658 int fcx_in_css, fcx_in_gneq, fcx_in_features;
1663 /* is transport mode supported? */
1664 fcx_in_css = css_general_characteristics.fcx;
1665 fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
1666 fcx_in_features = private->features.feature[40] & 0x80;
1667 tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
1672 mdc = ccw_device_get_mdc(device->cdev, 0);
1674 dev_warn(&device->cdev->dev, "Detecting the maximum supported"
1675 " data size for zHPF requests failed\n");
1678 return mdc * FCX_MAX_DATA_FACTOR;
1682 * Check device characteristics.
1683 * If the device is accessible using ECKD discipline, the device is enabled.
1686 dasd_eckd_check_characteristics(struct dasd_device *device)
1688 struct dasd_eckd_private *private = device->private;
1689 struct dasd_block *block;
1690 struct dasd_uid temp_uid;
1693 unsigned long value;
1695 /* setup work queue for validate server*/
1696 INIT_WORK(&device->kick_validate, dasd_eckd_do_validate_server);
1697 /* setup work queue for summary unit check */
1698 INIT_WORK(&device->suc_work, dasd_alias_handle_summary_unit_check);
1700 if (!ccw_device_is_pathgroup(device->cdev)) {
1701 dev_warn(&device->cdev->dev,
1702 "A channel path group could not be established\n");
1705 if (!ccw_device_is_multipath(device->cdev)) {
1706 dev_info(&device->cdev->dev,
1707 "The DASD is not operating in multipath mode\n");
1710 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
1712 dev_warn(&device->cdev->dev,
1713 "Allocating memory for private DASD data "
1717 device->private = private;
1719 memset(private, 0, sizeof(*private));
1721 /* Invalidate status of initial analysis. */
1722 private->init_cqr_status = -1;
1723 /* Set default cache operations. */
1724 private->attrib.operation = DASD_NORMAL_CACHE;
1725 private->attrib.nr_cyl = 0;
1727 /* Read Configuration Data */
1728 rc = dasd_eckd_read_conf(device);
1732 /* set default timeout */
1733 device->default_expires = DASD_EXPIRES;
1734 /* set default retry count */
1735 device->default_retries = DASD_RETRIES;
1737 if (private->gneq) {
1739 for (i = 0; i < private->gneq->timeout.value; i++)
1741 value = value * private->gneq->timeout.number;
1742 /* do not accept useless values */
1743 if (value != 0 && value <= DASD_EXPIRES_MAX)
1744 device->default_expires = value;
1747 dasd_eckd_get_uid(device, &temp_uid);
1748 if (temp_uid.type == UA_BASE_DEVICE) {
1749 block = dasd_alloc_block();
1750 if (IS_ERR(block)) {
1751 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1752 "could not allocate dasd "
1754 rc = PTR_ERR(block);
1757 device->block = block;
1758 block->base = device;
1761 /* register lcu with alias handling, enable PAV */
1762 rc = dasd_alias_make_device_known_to_lcu(device);
1766 dasd_eckd_validate_server(device, 0);
1768 /* device may report different configuration data after LCU setup */
1769 rc = dasd_eckd_read_conf(device);
1773 /* Read Feature Codes */
1774 dasd_eckd_read_features(device);
1776 /* Read Device Characteristics */
1777 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
1778 &private->rdc_data, 64);
1780 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1781 "Read device characteristic failed, rc=%d", rc);
1785 if ((device->features & DASD_FEATURE_USERAW) &&
1786 !(private->rdc_data.facilities.RT_in_LR)) {
1787 dev_err(&device->cdev->dev, "The storage server does not "
1788 "support raw-track access\n");
1793 /* find the valid cylinder size */
1794 if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1795 private->rdc_data.long_no_cyl)
1796 private->real_cyl = private->rdc_data.long_no_cyl;
1798 private->real_cyl = private->rdc_data.no_cyl;
1800 private->fcx_max_data = get_fcx_max_data(device);
1802 readonly = dasd_device_is_ro(device);
1804 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1806 dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
1807 "with %d cylinders, %d heads, %d sectors%s\n",
1808 private->rdc_data.dev_type,
1809 private->rdc_data.dev_model,
1810 private->rdc_data.cu_type,
1811 private->rdc_data.cu_model.model,
1813 private->rdc_data.trk_per_cyl,
1814 private->rdc_data.sec_per_trk,
1815 readonly ? ", read-only device" : "");
1819 dasd_alias_disconnect_device_from_lcu(device);
1821 dasd_free_block(device->block);
1822 device->block = NULL;
1824 kfree(private->conf_data);
1825 kfree(device->private);
1826 device->private = NULL;
1830 static void dasd_eckd_uncheck_device(struct dasd_device *device)
1832 struct dasd_eckd_private *private = device->private;
1835 dasd_alias_disconnect_device_from_lcu(device);
1836 private->ned = NULL;
1837 private->sneq = NULL;
1838 private->vdsneq = NULL;
1839 private->gneq = NULL;
1840 private->conf_len = 0;
1841 for (i = 0; i < 8; i++) {
1842 kfree(private->path_conf_data[i]);
1843 if ((__u8 *)private->path_conf_data[i] ==
1844 private->conf_data) {
1845 private->conf_data = NULL;
1846 private->conf_len = 0;
1848 private->path_conf_data[i] = NULL;
1850 kfree(private->conf_data);
1851 private->conf_data = NULL;
1854 static struct dasd_ccw_req *
1855 dasd_eckd_analysis_ccw(struct dasd_device *device)
1857 struct dasd_eckd_private *private = device->private;
1858 struct eckd_count *count_data;
1859 struct LO_eckd_data *LO_data;
1860 struct dasd_ccw_req *cqr;
1862 int cplength, datasize;
1866 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
1867 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1871 /* Define extent for the first 3 tracks. */
1872 define_extent(ccw++, cqr->data, 0, 2,
1873 DASD_ECKD_CCW_READ_COUNT, device);
1874 LO_data = cqr->data + sizeof(struct DE_eckd_data);
1875 /* Locate record for the first 4 records on track 0. */
1876 ccw[-1].flags |= CCW_FLAG_CC;
1877 locate_record(ccw++, LO_data++, 0, 0, 4,
1878 DASD_ECKD_CCW_READ_COUNT, device, 0);
1880 count_data = private->count_area;
1881 for (i = 0; i < 4; i++) {
1882 ccw[-1].flags |= CCW_FLAG_CC;
1883 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1886 ccw->cda = (__u32)(addr_t) count_data;
1891 /* Locate record for the first record on track 2. */
1892 ccw[-1].flags |= CCW_FLAG_CC;
1893 locate_record(ccw++, LO_data++, 2, 0, 1,
1894 DASD_ECKD_CCW_READ_COUNT, device, 0);
1895 /* Read count ccw. */
1896 ccw[-1].flags |= CCW_FLAG_CC;
1897 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1900 ccw->cda = (__u32)(addr_t) count_data;
1903 cqr->startdev = device;
1904 cqr->memdev = device;
1906 cqr->buildclk = get_tod_clock();
1907 cqr->status = DASD_CQR_FILLED;
1911 /* differentiate between 'no record found' and any other error */
1912 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
1915 if (init_cqr->status == DASD_CQR_DONE)
1917 else if (init_cqr->status == DASD_CQR_NEED_ERP ||
1918 init_cqr->status == DASD_CQR_FAILED) {
1919 sense = dasd_get_sense(&init_cqr->irb);
1920 if (sense && (sense[1] & SNS1_NO_REC_FOUND))
1921 return INIT_CQR_UNFORMATTED;
1923 return INIT_CQR_ERROR;
1925 return INIT_CQR_ERROR;
1929 * This is the callback function for the init_analysis cqr. It saves
1930 * the status of the initial analysis ccw before it frees it and kicks
1931 * the device to continue the startup sequence. This will call
1932 * dasd_eckd_do_analysis again (if the devices has not been marked
1933 * for deletion in the meantime).
1935 static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
1938 struct dasd_device *device = init_cqr->startdev;
1939 struct dasd_eckd_private *private = device->private;
1941 private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
1942 dasd_sfree_request(init_cqr, device);
1943 dasd_kick_device(device);
1946 static int dasd_eckd_start_analysis(struct dasd_block *block)
1948 struct dasd_ccw_req *init_cqr;
1950 init_cqr = dasd_eckd_analysis_ccw(block->base);
1951 if (IS_ERR(init_cqr))
1952 return PTR_ERR(init_cqr);
1953 init_cqr->callback = dasd_eckd_analysis_callback;
1954 init_cqr->callback_data = NULL;
1955 init_cqr->expires = 5*HZ;
1956 /* first try without ERP, so we can later handle unformatted
1957 * devices as special case
1959 clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
1960 init_cqr->retries = 0;
1961 dasd_add_request_head(init_cqr);
1965 static int dasd_eckd_end_analysis(struct dasd_block *block)
1967 struct dasd_device *device = block->base;
1968 struct dasd_eckd_private *private = device->private;
1969 struct eckd_count *count_area;
1970 unsigned int sb, blk_per_trk;
1972 struct dasd_ccw_req *init_cqr;
1974 status = private->init_cqr_status;
1975 private->init_cqr_status = -1;
1976 if (status == INIT_CQR_ERROR) {
1977 /* try again, this time with full ERP */
1978 init_cqr = dasd_eckd_analysis_ccw(device);
1979 dasd_sleep_on(init_cqr);
1980 status = dasd_eckd_analysis_evaluation(init_cqr);
1981 dasd_sfree_request(init_cqr, device);
1984 if (device->features & DASD_FEATURE_USERAW) {
1985 block->bp_block = DASD_RAW_BLOCKSIZE;
1986 blk_per_trk = DASD_RAW_BLOCK_PER_TRACK;
1987 block->s2b_shift = 3;
1991 if (status == INIT_CQR_UNFORMATTED) {
1992 dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
1993 return -EMEDIUMTYPE;
1994 } else if (status == INIT_CQR_ERROR) {
1995 dev_err(&device->cdev->dev,
1996 "Detecting the DASD disk layout failed because "
1997 "of an I/O error\n");
2001 private->uses_cdl = 1;
2002 /* Check Track 0 for Compatible Disk Layout */
2004 for (i = 0; i < 3; i++) {
2005 if (private->count_area[i].kl != 4 ||
2006 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4 ||
2007 private->count_area[i].cyl != 0 ||
2008 private->count_area[i].head != count_area_head[i] ||
2009 private->count_area[i].record != count_area_rec[i]) {
2010 private->uses_cdl = 0;
2015 count_area = &private->count_area[4];
2017 if (private->uses_cdl == 0) {
2018 for (i = 0; i < 5; i++) {
2019 if ((private->count_area[i].kl != 0) ||
2020 (private->count_area[i].dl !=
2021 private->count_area[0].dl) ||
2022 private->count_area[i].cyl != 0 ||
2023 private->count_area[i].head != count_area_head[i] ||
2024 private->count_area[i].record != count_area_rec[i])
2028 count_area = &private->count_area[0];
2030 if (private->count_area[3].record == 1)
2031 dev_warn(&device->cdev->dev,
2032 "Track 0 has no records following the VTOC\n");
2035 if (count_area != NULL && count_area->kl == 0) {
2036 /* we found notthing violating our disk layout */
2037 if (dasd_check_blocksize(count_area->dl) == 0)
2038 block->bp_block = count_area->dl;
2040 if (block->bp_block == 0) {
2041 dev_warn(&device->cdev->dev,
2042 "The disk layout of the DASD is not supported\n");
2043 return -EMEDIUMTYPE;
2045 block->s2b_shift = 0; /* bits to shift 512 to get a block */
2046 for (sb = 512; sb < block->bp_block; sb = sb << 1)
2049 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
2052 block->blocks = (private->real_cyl *
2053 private->rdc_data.trk_per_cyl *
2056 dev_info(&device->cdev->dev,
2057 "DASD with %d KB/block, %d KB total size, %d KB/track, "
2058 "%s\n", (block->bp_block >> 10),
2059 ((private->real_cyl *
2060 private->rdc_data.trk_per_cyl *
2061 blk_per_trk * (block->bp_block >> 9)) >> 1),
2062 ((blk_per_trk * block->bp_block) >> 10),
2064 "compatible disk layout" : "linux disk layout");
2069 static int dasd_eckd_do_analysis(struct dasd_block *block)
2071 struct dasd_eckd_private *private = block->base->private;
2073 if (private->init_cqr_status < 0)
2074 return dasd_eckd_start_analysis(block);
2076 return dasd_eckd_end_analysis(block);
2079 static int dasd_eckd_basic_to_ready(struct dasd_device *device)
2081 return dasd_alias_add_device(device);
2084 static int dasd_eckd_online_to_ready(struct dasd_device *device)
2086 cancel_work_sync(&device->reload_device);
2087 cancel_work_sync(&device->kick_validate);
2091 static int dasd_eckd_basic_to_known(struct dasd_device *device)
2093 return dasd_alias_remove_device(device);
2097 dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
2099 struct dasd_eckd_private *private = block->base->private;
2101 if (dasd_check_blocksize(block->bp_block) == 0) {
2102 geo->sectors = recs_per_track(&private->rdc_data,
2103 0, block->bp_block);
2105 geo->cylinders = private->rdc_data.no_cyl;
2106 geo->heads = private->rdc_data.trk_per_cyl;
2111 * Build the TCW request for the format check
2113 static struct dasd_ccw_req *
2114 dasd_eckd_build_check_tcw(struct dasd_device *base, struct format_data_t *fdata,
2115 int enable_pav, struct eckd_count *fmt_buffer,
2118 struct dasd_eckd_private *start_priv;
2119 struct dasd_device *startdev = NULL;
2120 struct tidaw *last_tidaw = NULL;
2121 struct dasd_ccw_req *cqr;
2129 startdev = dasd_alias_get_start_dev(base);
2134 start_priv = startdev->private;
2136 count = rpt * (fdata->stop_unit - fdata->start_unit + 1);
2139 * we're adding 'count' amount of tidaw to the itcw.
2140 * calculate the corresponding itcw_size
2142 itcw_size = itcw_calc_size(0, count, 0);
2144 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
2148 start_priv->count++;
2150 itcw = itcw_init(cqr->data, itcw_size, ITCW_OP_READ, 0, count, 0);
2156 cqr->cpaddr = itcw_get_tcw(itcw);
2157 rc = prepare_itcw(itcw, fdata->start_unit, fdata->stop_unit,
2158 DASD_ECKD_CCW_READ_COUNT_MT, base, startdev, 0, count,
2159 sizeof(struct eckd_count),
2160 count * sizeof(struct eckd_count), 0, rpt);
2164 for (i = 0; i < count; i++) {
2165 last_tidaw = itcw_add_tidaw(itcw, 0, fmt_buffer++,
2166 sizeof(struct eckd_count));
2167 if (IS_ERR(last_tidaw)) {
2173 last_tidaw->flags |= TIDAW_FLAGS_LAST;
2174 itcw_finalize(itcw);
2177 cqr->startdev = startdev;
2178 cqr->memdev = startdev;
2179 cqr->basedev = base;
2180 cqr->retries = startdev->default_retries;
2181 cqr->expires = startdev->default_expires * HZ;
2182 cqr->buildclk = get_tod_clock();
2183 cqr->status = DASD_CQR_FILLED;
2184 /* Set flags to suppress output for expected errors */
2185 set_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
2186 set_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags);
2191 dasd_sfree_request(cqr, startdev);
2197 * Build the CCW request for the format check
2199 static struct dasd_ccw_req *
2200 dasd_eckd_build_check(struct dasd_device *base, struct format_data_t *fdata,
2201 int enable_pav, struct eckd_count *fmt_buffer, int rpt)
2203 struct dasd_eckd_private *start_priv;
2204 struct dasd_eckd_private *base_priv;
2205 struct dasd_device *startdev = NULL;
2206 struct dasd_ccw_req *cqr;
2209 int cplength, datasize;
2215 startdev = dasd_alias_get_start_dev(base);
2220 start_priv = startdev->private;
2221 base_priv = base->private;
2223 count = rpt * (fdata->stop_unit - fdata->start_unit + 1);
2225 use_prefix = base_priv->features.feature[8] & 0x01;
2229 datasize = sizeof(struct PFX_eckd_data);
2232 datasize = sizeof(struct DE_eckd_data) +
2233 sizeof(struct LO_eckd_data);
2237 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2242 start_priv->count++;
2247 prefix_LRE(ccw++, data, fdata->start_unit, fdata->stop_unit,
2248 DASD_ECKD_CCW_READ_COUNT, base, startdev, 1, 0,
2251 define_extent(ccw++, data, fdata->start_unit, fdata->stop_unit,
2252 DASD_ECKD_CCW_READ_COUNT, startdev);
2254 data += sizeof(struct DE_eckd_data);
2255 ccw[-1].flags |= CCW_FLAG_CC;
2257 locate_record(ccw++, data, fdata->start_unit, 0, count,
2258 DASD_ECKD_CCW_READ_COUNT, base, 0);
2261 for (i = 0; i < count; i++) {
2262 ccw[-1].flags |= CCW_FLAG_CC;
2263 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
2264 ccw->flags = CCW_FLAG_SLI;
2266 ccw->cda = (__u32)(addr_t) fmt_buffer;
2271 cqr->startdev = startdev;
2272 cqr->memdev = startdev;
2273 cqr->basedev = base;
2274 cqr->retries = DASD_RETRIES;
2275 cqr->expires = startdev->default_expires * HZ;
2276 cqr->buildclk = get_tod_clock();
2277 cqr->status = DASD_CQR_FILLED;
2278 /* Set flags to suppress output for expected errors */
2279 set_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
2284 static struct dasd_ccw_req *
2285 dasd_eckd_build_format(struct dasd_device *base,
2286 struct format_data_t *fdata,
2289 struct dasd_eckd_private *base_priv;
2290 struct dasd_eckd_private *start_priv;
2291 struct dasd_device *startdev = NULL;
2292 struct dasd_ccw_req *fcp;
2293 struct eckd_count *ect;
2294 struct ch_t address;
2298 int cplength, datasize;
2306 startdev = dasd_alias_get_start_dev(base);
2311 start_priv = startdev->private;
2312 base_priv = base->private;
2314 rpt = recs_per_track(&base_priv->rdc_data, 0, fdata->blksize);
2316 nr_tracks = fdata->stop_unit - fdata->start_unit + 1;
2319 * fdata->intensity is a bit string that tells us what to do:
2320 * Bit 0: write record zero
2321 * Bit 1: write home address, currently not supported
2322 * Bit 2: invalidate tracks
2323 * Bit 3: use OS/390 compatible disk layout (cdl)
2324 * Bit 4: do not allow storage subsystem to modify record zero
2325 * Only some bit combinations do make sense.
2327 if (fdata->intensity & 0x10) {
2329 intensity = fdata->intensity & ~0x10;
2332 intensity = fdata->intensity;
2335 use_prefix = base_priv->features.feature[8] & 0x01;
2337 switch (intensity) {
2338 case 0x00: /* Normal format */
2339 case 0x08: /* Normal format, use cdl. */
2340 cplength = 2 + (rpt*nr_tracks);
2342 datasize = sizeof(struct PFX_eckd_data) +
2343 sizeof(struct LO_eckd_data) +
2344 rpt * nr_tracks * sizeof(struct eckd_count);
2346 datasize = sizeof(struct DE_eckd_data) +
2347 sizeof(struct LO_eckd_data) +
2348 rpt * nr_tracks * sizeof(struct eckd_count);
2350 case 0x01: /* Write record zero and format track. */
2351 case 0x09: /* Write record zero and format track, use cdl. */
2352 cplength = 2 + rpt * nr_tracks;
2354 datasize = sizeof(struct PFX_eckd_data) +
2355 sizeof(struct LO_eckd_data) +
2356 sizeof(struct eckd_count) +
2357 rpt * nr_tracks * sizeof(struct eckd_count);
2359 datasize = sizeof(struct DE_eckd_data) +
2360 sizeof(struct LO_eckd_data) +
2361 sizeof(struct eckd_count) +
2362 rpt * nr_tracks * sizeof(struct eckd_count);
2364 case 0x04: /* Invalidate track. */
2365 case 0x0c: /* Invalidate track, use cdl. */
2368 datasize = sizeof(struct PFX_eckd_data) +
2369 sizeof(struct LO_eckd_data) +
2370 sizeof(struct eckd_count);
2372 datasize = sizeof(struct DE_eckd_data) +
2373 sizeof(struct LO_eckd_data) +
2374 sizeof(struct eckd_count);
2377 dev_warn(&startdev->cdev->dev,
2378 "An I/O control call used incorrect flags 0x%x\n",
2380 return ERR_PTR(-EINVAL);
2382 /* Allocate the format ccw request. */
2383 fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
2384 datasize, startdev);
2388 start_priv->count++;
2392 switch (intensity & ~0x08) {
2393 case 0x00: /* Normal format. */
2395 prefix(ccw++, (struct PFX_eckd_data *) data,
2396 fdata->start_unit, fdata->stop_unit,
2397 DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2398 /* grant subsystem permission to format R0 */
2400 ((struct PFX_eckd_data *)data)
2401 ->define_extent.ga_extended |= 0x04;
2402 data += sizeof(struct PFX_eckd_data);
2404 define_extent(ccw++, (struct DE_eckd_data *) data,
2405 fdata->start_unit, fdata->stop_unit,
2406 DASD_ECKD_CCW_WRITE_CKD, startdev);
2407 /* grant subsystem permission to format R0 */
2409 ((struct DE_eckd_data *) data)
2410 ->ga_extended |= 0x04;
2411 data += sizeof(struct DE_eckd_data);
2413 ccw[-1].flags |= CCW_FLAG_CC;
2414 locate_record(ccw++, (struct LO_eckd_data *) data,
2415 fdata->start_unit, 0, rpt*nr_tracks,
2416 DASD_ECKD_CCW_WRITE_CKD, base,
2418 data += sizeof(struct LO_eckd_data);
2420 case 0x01: /* Write record zero + format track. */
2422 prefix(ccw++, (struct PFX_eckd_data *) data,
2423 fdata->start_unit, fdata->stop_unit,
2424 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
2426 data += sizeof(struct PFX_eckd_data);
2428 define_extent(ccw++, (struct DE_eckd_data *) data,
2429 fdata->start_unit, fdata->stop_unit,
2430 DASD_ECKD_CCW_WRITE_RECORD_ZERO, startdev);
2431 data += sizeof(struct DE_eckd_data);
2433 ccw[-1].flags |= CCW_FLAG_CC;
2434 locate_record(ccw++, (struct LO_eckd_data *) data,
2435 fdata->start_unit, 0, rpt * nr_tracks + 1,
2436 DASD_ECKD_CCW_WRITE_RECORD_ZERO, base,
2437 base->block->bp_block);
2438 data += sizeof(struct LO_eckd_data);
2440 case 0x04: /* Invalidate track. */
2442 prefix(ccw++, (struct PFX_eckd_data *) data,
2443 fdata->start_unit, fdata->stop_unit,
2444 DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2445 data += sizeof(struct PFX_eckd_data);
2447 define_extent(ccw++, (struct DE_eckd_data *) data,
2448 fdata->start_unit, fdata->stop_unit,
2449 DASD_ECKD_CCW_WRITE_CKD, startdev);
2450 data += sizeof(struct DE_eckd_data);
2452 ccw[-1].flags |= CCW_FLAG_CC;
2453 locate_record(ccw++, (struct LO_eckd_data *) data,
2454 fdata->start_unit, 0, 1,
2455 DASD_ECKD_CCW_WRITE_CKD, base, 8);
2456 data += sizeof(struct LO_eckd_data);
2460 for (j = 0; j < nr_tracks; j++) {
2461 /* calculate cylinder and head for the current track */
2463 (fdata->start_unit + j) /
2464 base_priv->rdc_data.trk_per_cyl,
2465 (fdata->start_unit + j) %
2466 base_priv->rdc_data.trk_per_cyl);
2467 if (intensity & 0x01) { /* write record zero */
2468 ect = (struct eckd_count *) data;
2469 data += sizeof(struct eckd_count);
2470 ect->cyl = address.cyl;
2471 ect->head = address.head;
2475 ccw[-1].flags |= CCW_FLAG_CC;
2476 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
2477 ccw->flags = CCW_FLAG_SLI;
2479 ccw->cda = (__u32)(addr_t) ect;
2482 if ((intensity & ~0x08) & 0x04) { /* erase track */
2483 ect = (struct eckd_count *) data;
2484 data += sizeof(struct eckd_count);
2485 ect->cyl = address.cyl;
2486 ect->head = address.head;
2490 ccw[-1].flags |= CCW_FLAG_CC;
2491 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
2492 ccw->flags = CCW_FLAG_SLI;
2494 ccw->cda = (__u32)(addr_t) ect;
2495 } else { /* write remaining records */
2496 for (i = 0; i < rpt; i++) {
2497 ect = (struct eckd_count *) data;
2498 data += sizeof(struct eckd_count);
2499 ect->cyl = address.cyl;
2500 ect->head = address.head;
2501 ect->record = i + 1;
2503 ect->dl = fdata->blksize;
2505 * Check for special tracks 0-1
2506 * when formatting CDL
2508 if ((intensity & 0x08) &&
2509 address.cyl == 0 && address.head == 0) {
2512 ect->dl = sizes_trk0[i] - 4;
2515 if ((intensity & 0x08) &&
2516 address.cyl == 0 && address.head == 1) {
2518 ect->dl = LABEL_SIZE - 44;
2520 ccw[-1].flags |= CCW_FLAG_CC;
2521 if (i != 0 || j == 0)
2523 DASD_ECKD_CCW_WRITE_CKD;
2526 DASD_ECKD_CCW_WRITE_CKD_MT;
2527 ccw->flags = CCW_FLAG_SLI;
2529 ccw->cda = (__u32)(addr_t) ect;
2535 fcp->startdev = startdev;
2536 fcp->memdev = startdev;
2537 fcp->basedev = base;
2539 fcp->expires = startdev->default_expires * HZ;
2540 fcp->buildclk = get_tod_clock();
2541 fcp->status = DASD_CQR_FILLED;
2547 * Wrapper function to build a CCW request depending on input data
2549 static struct dasd_ccw_req *
2550 dasd_eckd_format_build_ccw_req(struct dasd_device *base,
2551 struct format_data_t *fdata, int enable_pav,
2552 int tpm, struct eckd_count *fmt_buffer, int rpt)
2554 struct dasd_ccw_req *ccw_req;
2557 ccw_req = dasd_eckd_build_format(base, fdata, enable_pav);
2560 ccw_req = dasd_eckd_build_check_tcw(base, fdata,
2564 ccw_req = dasd_eckd_build_check(base, fdata, enable_pav,
2572 * Sanity checks on format_data
2574 static int dasd_eckd_format_sanity_checks(struct dasd_device *base,
2575 struct format_data_t *fdata)
2577 struct dasd_eckd_private *private = base->private;
2579 if (fdata->start_unit >=
2580 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2581 dev_warn(&base->cdev->dev,
2582 "Start track number %u used in formatting is too big\n",
2586 if (fdata->stop_unit >=
2587 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2588 dev_warn(&base->cdev->dev,
2589 "Stop track number %u used in formatting is too big\n",
2593 if (fdata->start_unit > fdata->stop_unit) {
2594 dev_warn(&base->cdev->dev,
2595 "Start track %u used in formatting exceeds end track\n",
2599 if (dasd_check_blocksize(fdata->blksize) != 0) {
2600 dev_warn(&base->cdev->dev,
2601 "The DASD cannot be formatted with block size %u\n",
2609 * This function will process format_data originally coming from an IOCTL
2611 static int dasd_eckd_format_process_data(struct dasd_device *base,
2612 struct format_data_t *fdata,
2613 int enable_pav, int tpm,
2614 struct eckd_count *fmt_buffer, int rpt,
2617 struct dasd_eckd_private *private = base->private;
2618 struct dasd_ccw_req *cqr, *n;
2619 struct list_head format_queue;
2620 struct dasd_device *device;
2622 int old_start, old_stop, format_step;
2626 rc = dasd_eckd_format_sanity_checks(base, fdata);
2630 INIT_LIST_HEAD(&format_queue);
2632 old_start = fdata->start_unit;
2633 old_stop = fdata->stop_unit;
2635 if (!tpm && fmt_buffer != NULL) {
2636 /* Command Mode / Format Check */
2638 } else if (tpm && fmt_buffer != NULL) {
2639 /* Transport Mode / Format Check */
2640 format_step = DASD_CQR_MAX_CCW / rpt;
2642 /* Normal Formatting */
2643 format_step = DASD_CQR_MAX_CCW /
2644 recs_per_track(&private->rdc_data, 0, fdata->blksize);
2649 while (fdata->start_unit <= old_stop) {
2650 step = fdata->stop_unit - fdata->start_unit + 1;
2651 if (step > format_step) {
2653 fdata->start_unit + format_step - 1;
2656 cqr = dasd_eckd_format_build_ccw_req(base, fdata,
2661 if (rc == -ENOMEM) {
2662 if (list_empty(&format_queue))
2665 * not enough memory available, start
2666 * requests retry after first requests
2674 list_add_tail(&cqr->blocklist, &format_queue);
2677 step = fdata->stop_unit - fdata->start_unit + 1;
2678 fmt_buffer += rpt * step;
2680 fdata->start_unit = fdata->stop_unit + 1;
2681 fdata->stop_unit = old_stop;
2684 rc = dasd_sleep_on_queue(&format_queue);
2687 list_for_each_entry_safe(cqr, n, &format_queue, blocklist) {
2688 device = cqr->startdev;
2689 private = device->private;
2691 if (cqr->status == DASD_CQR_FAILED) {
2693 * Only get sense data if called by format
2696 if (fmt_buffer && irb) {
2697 sense = dasd_get_sense(&cqr->irb);
2698 memcpy(irb, &cqr->irb, sizeof(*irb));
2702 list_del_init(&cqr->blocklist);
2703 dasd_sfree_request(cqr, device);
2707 if (rc && rc != -EIO)
2711 * In case fewer than the expected records are on the
2712 * track, we will most likely get a 'No Record Found'
2713 * error (in command mode) or a 'File Protected' error
2714 * (in transport mode). Those particular cases shouldn't
2715 * pass the -EIO to the IOCTL, therefore reset the rc
2719 (sense[1] & SNS1_NO_REC_FOUND ||
2720 sense[1] & SNS1_FILE_PROTECTED))
2729 fdata->start_unit = old_start;
2730 fdata->stop_unit = old_stop;
2735 static int dasd_eckd_format_device(struct dasd_device *base,
2736 struct format_data_t *fdata, int enable_pav)
2738 return dasd_eckd_format_process_data(base, fdata, enable_pav, 0, NULL,
2743 * Helper function to count consecutive records of a single track.
2745 static int dasd_eckd_count_records(struct eckd_count *fmt_buffer, int start,
2751 head = fmt_buffer[start].head;
2754 * There are 3 conditions where we stop counting:
2755 * - if data reoccurs (same head and record may reoccur), which may
2756 * happen due to the way DASD_ECKD_CCW_READ_COUNT works
2757 * - when the head changes, because we're iterating over several tracks
2758 * then (DASD_ECKD_CCW_READ_COUNT_MT)
2759 * - when we've reached the end of sensible data in the buffer (the
2760 * record will be 0 then)
2762 for (i = start; i < max; i++) {
2764 if ((fmt_buffer[i].head == head &&
2765 fmt_buffer[i].record == 1) ||
2766 fmt_buffer[i].head != head ||
2767 fmt_buffer[i].record == 0)
2776 * Evaluate a given range of tracks. Data like number of records, blocksize,
2777 * record ids, and key length are compared with expected data.
2779 * If a mismatch occurs, the corresponding error bit is set, as well as
2780 * additional information, depending on the error.
2782 static void dasd_eckd_format_evaluate_tracks(struct eckd_count *fmt_buffer,
2783 struct format_check_t *cdata,
2784 int rpt_max, int rpt_exp,
2785 int trk_per_cyl, int tpm)
2796 trkcount = cdata->expect.stop_unit - cdata->expect.start_unit + 1;
2797 max_entries = trkcount * rpt_max;
2799 for (i = cdata->expect.start_unit; i <= cdata->expect.stop_unit; i++) {
2800 /* Calculate the correct next starting position in the buffer */
2802 while (fmt_buffer[pos].record == 0 &&
2803 fmt_buffer[pos].dl == 0) {
2804 if (pos++ > max_entries)
2808 if (i != cdata->expect.start_unit)
2809 pos += rpt_max - count;
2812 /* Calculate the expected geo values for the current track */
2813 set_ch_t(&geo, i / trk_per_cyl, i % trk_per_cyl);
2815 /* Count and check number of records */
2816 count = dasd_eckd_count_records(fmt_buffer, pos, pos + rpt_max);
2818 if (count < rpt_exp) {
2819 cdata->result = DASD_FMT_ERR_TOO_FEW_RECORDS;
2822 if (count > rpt_exp) {
2823 cdata->result = DASD_FMT_ERR_TOO_MANY_RECORDS;
2827 for (j = 0; j < count; j++, pos++) {
2828 blksize = cdata->expect.blksize;
2832 * Set special values when checking CDL formatted
2835 if ((cdata->expect.intensity & 0x08) &&
2836 geo.cyl == 0 && geo.head == 0) {
2838 blksize = sizes_trk0[j] - 4;
2842 if ((cdata->expect.intensity & 0x08) &&
2843 geo.cyl == 0 && geo.head == 1) {
2844 blksize = LABEL_SIZE - 44;
2848 /* Check blocksize */
2849 if (fmt_buffer[pos].dl != blksize) {
2850 cdata->result = DASD_FMT_ERR_BLKSIZE;
2853 /* Check if key length is 0 */
2854 if (fmt_buffer[pos].kl != kl) {
2855 cdata->result = DASD_FMT_ERR_KEY_LENGTH;
2858 /* Check if record_id is correct */
2859 if (fmt_buffer[pos].cyl != geo.cyl ||
2860 fmt_buffer[pos].head != geo.head ||
2861 fmt_buffer[pos].record != (j + 1)) {
2862 cdata->result = DASD_FMT_ERR_RECORD_ID;
2870 * In case of no errors, we need to decrease by one
2871 * to get the correct positions.
2873 if (!cdata->result) {
2879 cdata->num_records = count;
2880 cdata->rec = fmt_buffer[pos].record;
2881 cdata->blksize = fmt_buffer[pos].dl;
2882 cdata->key_length = fmt_buffer[pos].kl;
2886 * Check the format of a range of tracks of a DASD.
2888 static int dasd_eckd_check_device_format(struct dasd_device *base,
2889 struct format_check_t *cdata,
2892 struct dasd_eckd_private *private = base->private;
2893 struct eckd_count *fmt_buffer;
2895 int rpt_max, rpt_exp;
2896 int fmt_buffer_size;
2902 trk_per_cyl = private->rdc_data.trk_per_cyl;
2904 /* Get maximum and expected amount of records per track */
2905 rpt_max = recs_per_track(&private->rdc_data, 0, 512) + 1;
2906 rpt_exp = recs_per_track(&private->rdc_data, 0, cdata->expect.blksize);
2908 trkcount = cdata->expect.stop_unit - cdata->expect.start_unit + 1;
2909 fmt_buffer_size = trkcount * rpt_max * sizeof(struct eckd_count);
2911 fmt_buffer = kzalloc(fmt_buffer_size, GFP_KERNEL | GFP_DMA);
2916 * A certain FICON feature subset is needed to operate in transport
2917 * mode. Additionally, the support for transport mode is implicitly
2918 * checked by comparing the buffer size with fcx_max_data. As long as
2919 * the buffer size is smaller we can operate in transport mode and
2920 * process multiple tracks. If not, only one track at once is being
2921 * processed using command mode.
2923 if ((private->features.feature[40] & 0x04) &&
2924 fmt_buffer_size <= private->fcx_max_data)
2927 rc = dasd_eckd_format_process_data(base, &cdata->expect, enable_pav,
2928 tpm, fmt_buffer, rpt_max, &irb);
2929 if (rc && rc != -EIO)
2933 * If our first attempt with transport mode enabled comes back
2934 * with an incorrect length error, we're going to retry the
2935 * check with command mode.
2937 if (tpm && scsw_cstat(&irb.scsw) == 0x40) {
2939 rc = dasd_eckd_format_process_data(base, &cdata->expect,
2941 fmt_buffer, rpt_max,
2950 dasd_eckd_format_evaluate_tracks(fmt_buffer, cdata, rpt_max, rpt_exp,
2959 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
2961 if (cqr->retries < 0) {
2962 cqr->status = DASD_CQR_FAILED;
2965 cqr->status = DASD_CQR_FILLED;
2966 if (cqr->block && (cqr->startdev != cqr->block->base)) {
2967 dasd_eckd_reset_ccw_to_base_io(cqr);
2968 cqr->startdev = cqr->block->base;
2969 cqr->lpm = cqr->block->base->path_data.opm;
2973 static dasd_erp_fn_t
2974 dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
2976 struct dasd_device *device = (struct dasd_device *) cqr->startdev;
2977 struct ccw_device *cdev = device->cdev;
2979 switch (cdev->id.cu_type) {
2984 return dasd_3990_erp_action;
2988 return dasd_default_erp_action;
2992 static dasd_erp_fn_t
2993 dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
2995 return dasd_default_erp_postaction;
2998 static void dasd_eckd_check_for_device_change(struct dasd_device *device,
2999 struct dasd_ccw_req *cqr,
3004 struct dasd_eckd_private *private = device->private;
3006 /* first of all check for state change pending interrupt */
3007 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
3008 if ((scsw_dstat(&irb->scsw) & mask) == mask) {
3010 * for alias only, not in offline processing
3011 * and only if not suspended
3013 if (!device->block && private->lcu &&
3014 device->state == DASD_STATE_ONLINE &&
3015 !test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3016 !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
3017 /* schedule worker to reload device */
3018 dasd_reload_device(device);
3020 dasd_generic_handle_state_change(device);
3024 sense = dasd_get_sense(irb);
3028 /* summary unit check */
3029 if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) &&
3030 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) {
3031 if (test_and_set_bit(DASD_FLAG_SUC, &device->flags)) {
3032 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3033 "eckd suc: device already notified");
3036 sense = dasd_get_sense(irb);
3038 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3039 "eckd suc: no reason code available");
3040 clear_bit(DASD_FLAG_SUC, &device->flags);
3044 private->suc_reason = sense[8];
3045 DBF_DEV_EVENT(DBF_NOTICE, device, "%s %x",
3046 "eckd handle summary unit check: reason",
3047 private->suc_reason);
3048 dasd_get_device(device);
3049 if (!schedule_work(&device->suc_work))
3050 dasd_put_device(device);
3055 /* service information message SIM */
3056 if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) &&
3057 ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
3058 dasd_3990_erp_handle_sim(device, sense);
3062 /* loss of device reservation is handled via base devices only
3063 * as alias devices may be used with several bases
3065 if (device->block && (sense[27] & DASD_SENSE_BIT_0) &&
3066 (sense[7] == 0x3F) &&
3067 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
3068 test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) {
3069 if (device->features & DASD_FEATURE_FAILONSLCK)
3070 set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
3071 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3072 dev_err(&device->cdev->dev,
3073 "The device reservation was lost\n");
3077 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
3078 struct dasd_device *startdev,
3079 struct dasd_block *block,
3080 struct request *req,
3085 unsigned int first_offs,
3086 unsigned int last_offs,
3087 unsigned int blk_per_trk,
3088 unsigned int blksize)
3090 struct dasd_eckd_private *private;
3091 unsigned long *idaws;
3092 struct LO_eckd_data *LO_data;
3093 struct dasd_ccw_req *cqr;
3095 struct req_iterator iter;
3099 int count, cidaw, cplength, datasize;
3101 unsigned char cmd, rcmd;
3103 struct dasd_device *basedev;
3105 basedev = block->base;
3106 private = basedev->private;
3107 if (rq_data_dir(req) == READ)
3108 cmd = DASD_ECKD_CCW_READ_MT;
3109 else if (rq_data_dir(req) == WRITE)
3110 cmd = DASD_ECKD_CCW_WRITE_MT;
3112 return ERR_PTR(-EINVAL);
3114 /* Check struct bio and count the number of blocks for the request. */
3117 rq_for_each_segment(bv, req, iter) {
3118 if (bv.bv_len & (blksize - 1))
3119 /* Eckd can only do full blocks. */
3120 return ERR_PTR(-EINVAL);
3121 count += bv.bv_len >> (block->s2b_shift + 9);
3122 if (idal_is_needed (page_address(bv.bv_page), bv.bv_len))
3123 cidaw += bv.bv_len >> (block->s2b_shift + 9);
3126 if (count != last_rec - first_rec + 1)
3127 return ERR_PTR(-EINVAL);
3129 /* use the prefix command if available */
3130 use_prefix = private->features.feature[8] & 0x01;
3132 /* 1x prefix + number of blocks */
3133 cplength = 2 + count;
3134 /* 1x prefix + cidaws*sizeof(long) */
3135 datasize = sizeof(struct PFX_eckd_data) +
3136 sizeof(struct LO_eckd_data) +
3137 cidaw * sizeof(unsigned long);
3139 /* 1x define extent + 1x locate record + number of blocks */
3140 cplength = 2 + count;
3141 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
3142 datasize = sizeof(struct DE_eckd_data) +
3143 sizeof(struct LO_eckd_data) +
3144 cidaw * sizeof(unsigned long);
3146 /* Find out the number of additional locate record ccws for cdl. */
3147 if (private->uses_cdl && first_rec < 2*blk_per_trk) {
3148 if (last_rec >= 2*blk_per_trk)
3149 count = 2*blk_per_trk - first_rec;
3151 datasize += count*sizeof(struct LO_eckd_data);
3153 /* Allocate the ccw request. */
3154 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
3159 /* First ccw is define extent or prefix. */
3161 if (prefix(ccw++, cqr->data, first_trk,
3162 last_trk, cmd, basedev, startdev) == -EAGAIN) {
3163 /* Clock not in sync and XRC is enabled.
3166 dasd_sfree_request(cqr, startdev);
3167 return ERR_PTR(-EAGAIN);
3169 idaws = (unsigned long *) (cqr->data +
3170 sizeof(struct PFX_eckd_data));
3172 if (define_extent(ccw++, cqr->data, first_trk,
3173 last_trk, cmd, basedev) == -EAGAIN) {
3174 /* Clock not in sync and XRC is enabled.
3177 dasd_sfree_request(cqr, startdev);
3178 return ERR_PTR(-EAGAIN);
3180 idaws = (unsigned long *) (cqr->data +
3181 sizeof(struct DE_eckd_data));
3183 /* Build locate_record+read/write/ccws. */
3184 LO_data = (struct LO_eckd_data *) (idaws + cidaw);
3186 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
3187 /* Only standard blocks so there is just one locate record. */
3188 ccw[-1].flags |= CCW_FLAG_CC;
3189 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
3190 last_rec - recid + 1, cmd, basedev, blksize);
3192 rq_for_each_segment(bv, req, iter) {
3193 dst = page_address(bv.bv_page) + bv.bv_offset;
3194 if (dasd_page_cache) {
3195 char *copy = kmem_cache_alloc(dasd_page_cache,
3196 GFP_DMA | __GFP_NOWARN);
3197 if (copy && rq_data_dir(req) == WRITE)
3198 memcpy(copy + bv.bv_offset, dst, bv.bv_len);
3200 dst = copy + bv.bv_offset;
3202 for (off = 0; off < bv.bv_len; off += blksize) {
3203 sector_t trkid = recid;
3204 unsigned int recoffs = sector_div(trkid, blk_per_trk);
3207 /* Locate record for cdl special block ? */
3208 if (private->uses_cdl && recid < 2*blk_per_trk) {
3209 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
3211 count = dasd_eckd_cdl_reclen(recid);
3212 if (count < blksize &&
3213 rq_data_dir(req) == READ)
3214 memset(dst + count, 0xe5,
3217 ccw[-1].flags |= CCW_FLAG_CC;
3218 locate_record(ccw++, LO_data++,
3220 1, rcmd, basedev, count);
3222 /* Locate record for standard blocks ? */
3223 if (private->uses_cdl && recid == 2*blk_per_trk) {
3224 ccw[-1].flags |= CCW_FLAG_CC;
3225 locate_record(ccw++, LO_data++,
3227 last_rec - recid + 1,
3228 cmd, basedev, count);
3230 /* Read/write ccw. */
3231 ccw[-1].flags |= CCW_FLAG_CC;
3232 ccw->cmd_code = rcmd;
3234 if (idal_is_needed(dst, blksize)) {
3235 ccw->cda = (__u32)(addr_t) idaws;
3236 ccw->flags = CCW_FLAG_IDA;
3237 idaws = idal_create_words(idaws, dst, blksize);
3239 ccw->cda = (__u32)(addr_t) dst;
3247 if (blk_noretry_request(req) ||
3248 block->base->features & DASD_FEATURE_FAILFAST)
3249 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3250 cqr->startdev = startdev;
3251 cqr->memdev = startdev;
3253 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
3254 cqr->lpm = startdev->path_data.ppm;
3255 cqr->retries = startdev->default_retries;
3256 cqr->buildclk = get_tod_clock();
3257 cqr->status = DASD_CQR_FILLED;
3261 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
3262 struct dasd_device *startdev,
3263 struct dasd_block *block,
3264 struct request *req,
3269 unsigned int first_offs,
3270 unsigned int last_offs,
3271 unsigned int blk_per_trk,
3272 unsigned int blksize)
3274 unsigned long *idaws;
3275 struct dasd_ccw_req *cqr;
3277 struct req_iterator iter;
3279 char *dst, *idaw_dst;
3280 unsigned int cidaw, cplength, datasize;
3284 struct dasd_device *basedev;
3285 unsigned int trkcount, count, count_to_trk_end;
3286 unsigned int idaw_len, seg_len, part_len, len_to_track_end;
3287 unsigned char new_track, end_idaw;
3289 unsigned int recoffs;
3291 basedev = block->base;
3292 if (rq_data_dir(req) == READ)
3293 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
3294 else if (rq_data_dir(req) == WRITE)
3295 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
3297 return ERR_PTR(-EINVAL);
3299 /* Track based I/O needs IDAWs for each page, and not just for
3300 * 64 bit addresses. We need additional idals for pages
3301 * that get filled from two tracks, so we use the number
3302 * of records as upper limit.
3304 cidaw = last_rec - first_rec + 1;
3305 trkcount = last_trk - first_trk + 1;
3307 /* 1x prefix + one read/write ccw per track */
3308 cplength = 1 + trkcount;
3310 /* on 31-bit we need space for two 32 bit addresses per page
3311 * on 64-bit one 64 bit address
3313 datasize = sizeof(struct PFX_eckd_data) +
3314 cidaw * sizeof(unsigned long long);
3316 /* Allocate the ccw request. */
3317 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
3322 /* transfer length factor: how many bytes to read from the last track */
3323 if (first_trk == last_trk)
3324 tlf = last_offs - first_offs + 1;
3326 tlf = last_offs + 1;
3329 if (prefix_LRE(ccw++, cqr->data, first_trk,
3330 last_trk, cmd, basedev, startdev,
3331 1 /* format */, first_offs + 1,
3334 /* Clock not in sync and XRC is enabled.
3337 dasd_sfree_request(cqr, startdev);
3338 return ERR_PTR(-EAGAIN);
3342 * The translation of request into ccw programs must meet the
3343 * following conditions:
3344 * - all idaws but the first and the last must address full pages
3345 * (or 2K blocks on 31-bit)
3346 * - the scope of a ccw and it's idal ends with the track boundaries
3348 idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
3352 len_to_track_end = 0;
3355 rq_for_each_segment(bv, req, iter) {
3356 dst = page_address(bv.bv_page) + bv.bv_offset;
3357 seg_len = bv.bv_len;
3361 recoffs = sector_div(trkid, blk_per_trk);
3362 count_to_trk_end = blk_per_trk - recoffs;
3363 count = min((last_rec - recid + 1),
3364 (sector_t)count_to_trk_end);
3365 len_to_track_end = count * blksize;
3366 ccw[-1].flags |= CCW_FLAG_CC;
3367 ccw->cmd_code = cmd;
3368 ccw->count = len_to_track_end;
3369 ccw->cda = (__u32)(addr_t)idaws;
3370 ccw->flags = CCW_FLAG_IDA;
3374 /* first idaw for a ccw may start anywhere */
3378 /* If we start a new idaw, we must make sure that it
3379 * starts on an IDA_BLOCK_SIZE boundary.
3380 * If we continue an idaw, we must make sure that the
3381 * current segment begins where the so far accumulated
3385 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
3386 dasd_sfree_request(cqr, startdev);
3387 return ERR_PTR(-ERANGE);
3391 if ((idaw_dst + idaw_len) != dst) {
3392 dasd_sfree_request(cqr, startdev);
3393 return ERR_PTR(-ERANGE);
3395 part_len = min(seg_len, len_to_track_end);
3396 seg_len -= part_len;
3398 idaw_len += part_len;
3399 len_to_track_end -= part_len;
3400 /* collected memory area ends on an IDA_BLOCK border,
3402 * idal_create_words will handle cases where idaw_len
3403 * is larger then IDA_BLOCK_SIZE
3405 if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
3407 /* We also need to end the idaw at track end */
3408 if (!len_to_track_end) {
3413 idaws = idal_create_words(idaws, idaw_dst,
3422 if (blk_noretry_request(req) ||
3423 block->base->features & DASD_FEATURE_FAILFAST)
3424 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3425 cqr->startdev = startdev;
3426 cqr->memdev = startdev;
3428 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
3429 cqr->lpm = startdev->path_data.ppm;
3430 cqr->retries = startdev->default_retries;
3431 cqr->buildclk = get_tod_clock();
3432 cqr->status = DASD_CQR_FILLED;
3436 static int prepare_itcw(struct itcw *itcw,
3437 unsigned int trk, unsigned int totrk, int cmd,
3438 struct dasd_device *basedev,
3439 struct dasd_device *startdev,
3440 unsigned int rec_on_trk, int count,
3441 unsigned int blksize,
3442 unsigned int total_data_size,
3444 unsigned int blk_per_trk)
3446 struct PFX_eckd_data pfxdata;
3447 struct dasd_eckd_private *basepriv, *startpriv;
3448 struct DE_eckd_data *dedata;
3449 struct LRE_eckd_data *lredata;
3453 u16 heads, beghead, endhead;
3461 /* setup prefix data */
3462 basepriv = basedev->private;
3463 startpriv = startdev->private;
3464 dedata = &pfxdata.define_extent;
3465 lredata = &pfxdata.locate_record;
3467 memset(&pfxdata, 0, sizeof(pfxdata));
3468 pfxdata.format = 1; /* PFX with LRE */
3469 pfxdata.base_address = basepriv->ned->unit_addr;
3470 pfxdata.base_lss = basepriv->ned->ID;
3471 pfxdata.validity.define_extent = 1;
3473 /* private uid is kept up to date, conf_data may be outdated */
3474 if (startpriv->uid.type != UA_BASE_DEVICE) {
3475 pfxdata.validity.verify_base = 1;
3476 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
3477 pfxdata.validity.hyper_pav = 1;
3481 case DASD_ECKD_CCW_READ_TRACK_DATA:
3482 dedata->mask.perm = 0x1;
3483 dedata->attributes.operation = basepriv->attrib.operation;
3484 dedata->blk_size = blksize;
3485 dedata->ga_extended |= 0x42;
3486 lredata->operation.orientation = 0x0;
3487 lredata->operation.operation = 0x0C;
3488 lredata->auxiliary.check_bytes = 0x01;
3489 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
3491 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
3492 dedata->mask.perm = 0x02;
3493 dedata->attributes.operation = basepriv->attrib.operation;
3494 dedata->blk_size = blksize;
3495 rc = check_XRC_on_prefix(&pfxdata, basedev);
3496 dedata->ga_extended |= 0x42;
3497 lredata->operation.orientation = 0x0;
3498 lredata->operation.operation = 0x3F;
3499 lredata->extended_operation = 0x23;
3500 lredata->auxiliary.check_bytes = 0x2;
3501 pfx_cmd = DASD_ECKD_CCW_PFX;
3503 case DASD_ECKD_CCW_READ_COUNT_MT:
3504 dedata->mask.perm = 0x1;
3505 dedata->attributes.operation = DASD_BYPASS_CACHE;
3506 dedata->ga_extended |= 0x42;
3507 dedata->blk_size = blksize;
3508 lredata->operation.orientation = 0x2;
3509 lredata->operation.operation = 0x16;
3510 lredata->auxiliary.check_bytes = 0x01;
3511 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
3514 DBF_DEV_EVENT(DBF_ERR, basedev,
3515 "prepare itcw, unknown opcode 0x%x", cmd);
3522 dedata->attributes.mode = 0x3; /* ECKD */
3524 heads = basepriv->rdc_data.trk_per_cyl;
3525 begcyl = trk / heads;
3526 beghead = trk % heads;
3527 endcyl = totrk / heads;
3528 endhead = totrk % heads;
3530 /* check for sequential prestage - enhance cylinder range */
3531 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
3532 dedata->attributes.operation == DASD_SEQ_ACCESS) {
3534 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
3535 endcyl += basepriv->attrib.nr_cyl;
3537 endcyl = (basepriv->real_cyl - 1);
3540 set_ch_t(&dedata->beg_ext, begcyl, beghead);
3541 set_ch_t(&dedata->end_ext, endcyl, endhead);
3543 dedata->ep_format = 0x20; /* records per track is valid */
3544 dedata->ep_rec_per_track = blk_per_trk;
3547 switch (basepriv->rdc_data.dev_type) {
3549 dn = ceil_quot(blksize + 6, 232);
3550 d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
3551 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
3554 d = 7 + ceil_quot(blksize + 12, 32);
3555 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
3560 if (cmd == DASD_ECKD_CCW_READ_COUNT_MT) {
3561 lredata->auxiliary.length_valid = 0;
3562 lredata->auxiliary.length_scope = 0;
3563 lredata->sector = 0xff;
3565 lredata->auxiliary.length_valid = 1;
3566 lredata->auxiliary.length_scope = 1;
3567 lredata->sector = sector;
3569 lredata->auxiliary.imbedded_ccw_valid = 1;
3570 lredata->length = tlf;
3571 lredata->imbedded_ccw = cmd;
3572 lredata->count = count;
3573 set_ch_t(&lredata->seek_addr, begcyl, beghead);
3574 lredata->search_arg.cyl = lredata->seek_addr.cyl;
3575 lredata->search_arg.head = lredata->seek_addr.head;
3576 lredata->search_arg.record = rec_on_trk;
3578 dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
3579 &pfxdata, sizeof(pfxdata), total_data_size);
3580 return PTR_RET(dcw);
3583 static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
3584 struct dasd_device *startdev,
3585 struct dasd_block *block,
3586 struct request *req,
3591 unsigned int first_offs,
3592 unsigned int last_offs,
3593 unsigned int blk_per_trk,
3594 unsigned int blksize)
3596 struct dasd_ccw_req *cqr;
3597 struct req_iterator iter;
3600 unsigned int trkcount, ctidaw;
3602 struct dasd_device *basedev;
3605 struct tidaw *last_tidaw = NULL;
3609 unsigned int seg_len, part_len, len_to_track_end;
3610 unsigned char new_track;
3611 sector_t recid, trkid;
3613 unsigned int count, count_to_trk_end;
3616 basedev = block->base;
3617 if (rq_data_dir(req) == READ) {
3618 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
3619 itcw_op = ITCW_OP_READ;
3620 } else if (rq_data_dir(req) == WRITE) {
3621 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
3622 itcw_op = ITCW_OP_WRITE;
3624 return ERR_PTR(-EINVAL);
3626 /* trackbased I/O needs address all memory via TIDAWs,
3627 * not just for 64 bit addresses. This allows us to map
3628 * each segment directly to one tidaw.
3629 * In the case of write requests, additional tidaws may
3630 * be needed when a segment crosses a track boundary.
3632 trkcount = last_trk - first_trk + 1;
3634 rq_for_each_segment(bv, req, iter) {
3637 if (rq_data_dir(req) == WRITE)
3638 ctidaw += (last_trk - first_trk);
3640 /* Allocate the ccw request. */
3641 itcw_size = itcw_calc_size(0, ctidaw, 0);
3642 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
3646 /* transfer length factor: how many bytes to read from the last track */
3647 if (first_trk == last_trk)
3648 tlf = last_offs - first_offs + 1;
3650 tlf = last_offs + 1;
3653 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
3658 cqr->cpaddr = itcw_get_tcw(itcw);
3659 if (prepare_itcw(itcw, first_trk, last_trk,
3660 cmd, basedev, startdev,
3663 (last_rec - first_rec + 1) * blksize,
3664 tlf, blk_per_trk) == -EAGAIN) {
3665 /* Clock not in sync and XRC is enabled.
3671 len_to_track_end = 0;
3673 * A tidaw can address 4k of memory, but must not cross page boundaries
3674 * We can let the block layer handle this by setting
3675 * blk_queue_segment_boundary to page boundaries and
3676 * blk_max_segment_size to page size when setting up the request queue.
3677 * For write requests, a TIDAW must not cross track boundaries, because
3678 * we have to set the CBC flag on the last tidaw for each track.
3680 if (rq_data_dir(req) == WRITE) {
3683 rq_for_each_segment(bv, req, iter) {
3684 dst = page_address(bv.bv_page) + bv.bv_offset;
3685 seg_len = bv.bv_len;
3689 offs = sector_div(trkid, blk_per_trk);
3690 count_to_trk_end = blk_per_trk - offs;
3691 count = min((last_rec - recid + 1),
3692 (sector_t)count_to_trk_end);
3693 len_to_track_end = count * blksize;
3697 part_len = min(seg_len, len_to_track_end);
3698 seg_len -= part_len;
3699 len_to_track_end -= part_len;
3700 /* We need to end the tidaw at track end */
3701 if (!len_to_track_end) {
3703 tidaw_flags = TIDAW_FLAGS_INSERT_CBC;
3706 last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
3708 if (IS_ERR(last_tidaw)) {
3716 rq_for_each_segment(bv, req, iter) {
3717 dst = page_address(bv.bv_page) + bv.bv_offset;
3718 last_tidaw = itcw_add_tidaw(itcw, 0x00,
3720 if (IS_ERR(last_tidaw)) {
3726 last_tidaw->flags |= TIDAW_FLAGS_LAST;
3727 last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC;
3728 itcw_finalize(itcw);
3730 if (blk_noretry_request(req) ||
3731 block->base->features & DASD_FEATURE_FAILFAST)
3732 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3734 cqr->startdev = startdev;
3735 cqr->memdev = startdev;
3737 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
3738 cqr->lpm = startdev->path_data.ppm;
3739 cqr->retries = startdev->default_retries;
3740 cqr->buildclk = get_tod_clock();
3741 cqr->status = DASD_CQR_FILLED;
3744 dasd_sfree_request(cqr, startdev);
3745 return ERR_PTR(ret);
3748 static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
3749 struct dasd_block *block,
3750 struct request *req)
3755 struct dasd_eckd_private *private;
3756 struct dasd_device *basedev;
3757 sector_t first_rec, last_rec;
3758 sector_t first_trk, last_trk;
3759 unsigned int first_offs, last_offs;
3760 unsigned int blk_per_trk, blksize;
3762 unsigned int data_size;
3763 struct dasd_ccw_req *cqr;
3765 basedev = block->base;
3766 private = basedev->private;
3768 /* Calculate number of blocks/records per track. */
3769 blksize = block->bp_block;
3770 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
3771 if (blk_per_trk == 0)
3772 return ERR_PTR(-EINVAL);
3773 /* Calculate record id of first and last block. */
3774 first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
3775 first_offs = sector_div(first_trk, blk_per_trk);
3776 last_rec = last_trk =
3777 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
3778 last_offs = sector_div(last_trk, blk_per_trk);
3779 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
3781 fcx_multitrack = private->features.feature[40] & 0x20;
3782 data_size = blk_rq_bytes(req);
3783 if (data_size % blksize)
3784 return ERR_PTR(-EINVAL);
3785 /* tpm write request add CBC data on each track boundary */
3786 if (rq_data_dir(req) == WRITE)
3787 data_size += (last_trk - first_trk) * 4;
3789 /* is read track data and write track data in command mode supported? */
3790 cmdrtd = private->features.feature[9] & 0x20;
3791 cmdwtd = private->features.feature[12] & 0x40;
3792 use_prefix = private->features.feature[8] & 0x01;
3795 if (cdlspecial || dasd_page_cache) {
3796 /* do nothing, just fall through to the cmd mode single case */
3797 } else if ((data_size <= private->fcx_max_data)
3798 && (fcx_multitrack || (first_trk == last_trk))) {
3799 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
3800 first_rec, last_rec,
3801 first_trk, last_trk,
3802 first_offs, last_offs,
3803 blk_per_trk, blksize);
3804 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3805 (PTR_ERR(cqr) != -ENOMEM))
3807 } else if (use_prefix &&
3808 (((rq_data_dir(req) == READ) && cmdrtd) ||
3809 ((rq_data_dir(req) == WRITE) && cmdwtd))) {
3810 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
3811 first_rec, last_rec,
3812 first_trk, last_trk,
3813 first_offs, last_offs,
3814 blk_per_trk, blksize);
3815 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3816 (PTR_ERR(cqr) != -ENOMEM))
3820 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
3821 first_rec, last_rec,
3822 first_trk, last_trk,
3823 first_offs, last_offs,
3824 blk_per_trk, blksize);
3828 static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev,
3829 struct dasd_block *block,
3830 struct request *req)
3832 unsigned long *idaws;
3833 struct dasd_device *basedev;
3834 struct dasd_ccw_req *cqr;
3836 struct req_iterator iter;
3840 unsigned int trkcount;
3841 unsigned int seg_len, len_to_track_end;
3842 unsigned int first_offs;
3843 unsigned int cidaw, cplength, datasize;
3844 sector_t first_trk, last_trk, sectors;
3845 sector_t start_padding_sectors, end_sector_offset, end_padding_sectors;
3846 unsigned int pfx_datasize;
3849 * raw track access needs to be mutiple of 64k and on 64k boundary
3850 * For read requests we can fix an incorrect alignment by padding
3851 * the request with dummy pages.
3853 start_padding_sectors = blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK;
3854 end_sector_offset = (blk_rq_pos(req) + blk_rq_sectors(req)) %
3855 DASD_RAW_SECTORS_PER_TRACK;
3856 end_padding_sectors = (DASD_RAW_SECTORS_PER_TRACK - end_sector_offset) %
3857 DASD_RAW_SECTORS_PER_TRACK;
3858 basedev = block->base;
3859 if ((start_padding_sectors || end_padding_sectors) &&
3860 (rq_data_dir(req) == WRITE)) {
3861 DBF_DEV_EVENT(DBF_ERR, basedev,
3862 "raw write not track aligned (%lu,%lu) req %p",
3863 start_padding_sectors, end_padding_sectors, req);
3864 cqr = ERR_PTR(-EINVAL);
3868 first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK;
3869 last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
3870 DASD_RAW_SECTORS_PER_TRACK;
3871 trkcount = last_trk - first_trk + 1;
3874 if (rq_data_dir(req) == READ)
3875 cmd = DASD_ECKD_CCW_READ_TRACK;
3876 else if (rq_data_dir(req) == WRITE)
3877 cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK;
3879 cqr = ERR_PTR(-EINVAL);
3884 * Raw track based I/O needs IDAWs for each page,
3885 * and not just for 64 bit addresses.
3887 cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK;
3889 /* 1x prefix + one read/write ccw per track */
3890 cplength = 1 + trkcount;
3893 * struct PFX_eckd_data has up to 2 byte as extended parameter
3894 * this is needed for write full track and has to be mentioned
3896 * add 8 instead of 2 to keep 8 byte boundary
3898 pfx_datasize = sizeof(struct PFX_eckd_data) + 8;
3900 datasize = pfx_datasize + cidaw * sizeof(unsigned long long);
3902 /* Allocate the ccw request. */
3903 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
3904 datasize, startdev);
3909 if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd,
3910 basedev, startdev, 1 /* format */, first_offs + 1,
3911 trkcount, 0, 0) == -EAGAIN) {
3912 /* Clock not in sync and XRC is enabled.
3915 dasd_sfree_request(cqr, startdev);
3916 cqr = ERR_PTR(-EAGAIN);
3920 idaws = (unsigned long *)(cqr->data + pfx_datasize);
3921 len_to_track_end = 0;
3922 if (start_padding_sectors) {
3923 ccw[-1].flags |= CCW_FLAG_CC;
3924 ccw->cmd_code = cmd;
3925 /* maximum 3390 track size */
3927 /* 64k map to one track */
3928 len_to_track_end = 65536 - start_padding_sectors * 512;
3929 ccw->cda = (__u32)(addr_t)idaws;
3930 ccw->flags |= CCW_FLAG_IDA;
3931 ccw->flags |= CCW_FLAG_SLI;
3933 for (sectors = 0; sectors < start_padding_sectors; sectors += 8)
3934 idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE);
3936 rq_for_each_segment(bv, req, iter) {
3937 dst = page_address(bv.bv_page) + bv.bv_offset;
3938 seg_len = bv.bv_len;
3939 if (cmd == DASD_ECKD_CCW_READ_TRACK)
3940 memset(dst, 0, seg_len);
3941 if (!len_to_track_end) {
3942 ccw[-1].flags |= CCW_FLAG_CC;
3943 ccw->cmd_code = cmd;
3944 /* maximum 3390 track size */
3946 /* 64k map to one track */
3947 len_to_track_end = 65536;
3948 ccw->cda = (__u32)(addr_t)idaws;
3949 ccw->flags |= CCW_FLAG_IDA;
3950 ccw->flags |= CCW_FLAG_SLI;
3953 len_to_track_end -= seg_len;
3954 idaws = idal_create_words(idaws, dst, seg_len);
3956 for (sectors = 0; sectors < end_padding_sectors; sectors += 8)
3957 idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE);
3958 if (blk_noretry_request(req) ||
3959 block->base->features & DASD_FEATURE_FAILFAST)
3960 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3961 cqr->startdev = startdev;
3962 cqr->memdev = startdev;
3964 cqr->expires = startdev->default_expires * HZ;
3965 cqr->lpm = startdev->path_data.ppm;
3966 cqr->retries = startdev->default_retries;
3967 cqr->buildclk = get_tod_clock();
3968 cqr->status = DASD_CQR_FILLED;
3970 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
3978 dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
3980 struct dasd_eckd_private *private;
3982 struct req_iterator iter;
3985 unsigned int blksize, blk_per_trk, off;
3989 if (!dasd_page_cache)
3991 private = cqr->block->base->private;
3992 blksize = cqr->block->bp_block;
3993 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
3994 recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
3996 /* Skip over define extent & locate record. */
3998 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
4000 rq_for_each_segment(bv, req, iter) {
4001 dst = page_address(bv.bv_page) + bv.bv_offset;
4002 for (off = 0; off < bv.bv_len; off += blksize) {
4003 /* Skip locate record. */
4004 if (private->uses_cdl && recid <= 2*blk_per_trk)
4007 if (ccw->flags & CCW_FLAG_IDA)
4008 cda = *((char **)((addr_t) ccw->cda));
4010 cda = (char *)((addr_t) ccw->cda);
4012 if (rq_data_dir(req) == READ)
4013 memcpy(dst, cda, bv.bv_len);
4014 kmem_cache_free(dasd_page_cache,
4015 (void *)((addr_t)cda & PAGE_MASK));
4024 status = cqr->status == DASD_CQR_DONE;
4025 dasd_sfree_request(cqr, cqr->memdev);
4030 * Modify ccw/tcw in cqr so it can be started on a base device.
4032 * Note that this is not enough to restart the cqr!
4033 * Either reset cqr->startdev as well (summary unit check handling)
4034 * or restart via separate cqr (as in ERP handling).
4036 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
4039 struct PFX_eckd_data *pfxdata;
4044 if (cqr->cpmode == 1) {
4046 tccb = tcw_get_tccb(tcw);
4047 dcw = (struct dcw *)&tccb->tca[0];
4048 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
4049 pfxdata->validity.verify_base = 0;
4050 pfxdata->validity.hyper_pav = 0;
4053 pfxdata = cqr->data;
4054 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
4055 pfxdata->validity.verify_base = 0;
4056 pfxdata->validity.hyper_pav = 0;
4061 #define DASD_ECKD_CHANQ_MAX_SIZE 4
4063 static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
4064 struct dasd_block *block,
4065 struct request *req)
4067 struct dasd_eckd_private *private;
4068 struct dasd_device *startdev;
4069 unsigned long flags;
4070 struct dasd_ccw_req *cqr;
4072 startdev = dasd_alias_get_start_dev(base);
4075 private = startdev->private;
4076 if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
4077 return ERR_PTR(-EBUSY);
4079 spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
4081 if ((base->features & DASD_FEATURE_USERAW))
4082 cqr = dasd_raw_build_cp(startdev, block, req);
4084 cqr = dasd_eckd_build_cp(startdev, block, req);
4087 spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
4091 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
4092 struct request *req)
4094 struct dasd_eckd_private *private;
4095 unsigned long flags;
4097 spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
4098 private = cqr->memdev->private;
4100 spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
4101 return dasd_eckd_free_cp(cqr, req);
4105 dasd_eckd_fill_info(struct dasd_device * device,
4106 struct dasd_information2_t * info)
4108 struct dasd_eckd_private *private = device->private;
4110 info->label_block = 2;
4111 info->FBA_layout = private->uses_cdl ? 0 : 1;
4112 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
4113 info->characteristics_size = sizeof(private->rdc_data);
4114 memcpy(info->characteristics, &private->rdc_data,
4115 sizeof(private->rdc_data));
4116 info->confdata_size = min((unsigned long)private->conf_len,
4117 sizeof(info->configuration_data));
4118 memcpy(info->configuration_data, private->conf_data,
4119 info->confdata_size);
4124 * SECTION: ioctl functions for eckd devices.
4128 * Release device ioctl.
4129 * Buils a channel programm to releases a prior reserved
4130 * (see dasd_eckd_reserve) device.
4133 dasd_eckd_release(struct dasd_device *device)
4135 struct dasd_ccw_req *cqr;
4140 if (!capable(CAP_SYS_ADMIN))
4144 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
4146 mutex_lock(&dasd_reserve_mutex);
4148 cqr = &dasd_reserve_req->cqr;
4149 memset(cqr, 0, sizeof(*cqr));
4150 memset(&dasd_reserve_req->ccw, 0,
4151 sizeof(dasd_reserve_req->ccw));
4152 cqr->cpaddr = &dasd_reserve_req->ccw;
4153 cqr->data = &dasd_reserve_req->data;
4154 cqr->magic = DASD_ECKD_MAGIC;
4157 ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
4158 ccw->flags |= CCW_FLAG_SLI;
4160 ccw->cda = (__u32)(addr_t) cqr->data;
4161 cqr->startdev = device;
4162 cqr->memdev = device;
4163 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4164 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
4165 cqr->retries = 2; /* set retry counter to enable basic ERP */
4166 cqr->expires = 2 * HZ;
4167 cqr->buildclk = get_tod_clock();
4168 cqr->status = DASD_CQR_FILLED;
4170 rc = dasd_sleep_on_immediatly(cqr);
4172 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
4175 mutex_unlock(&dasd_reserve_mutex);
4177 dasd_sfree_request(cqr, cqr->memdev);
4182 * Reserve device ioctl.
4183 * Options are set to 'synchronous wait for interrupt' and
4184 * 'timeout the request'. This leads to a terminate IO if
4185 * the interrupt is outstanding for a certain time.
4188 dasd_eckd_reserve(struct dasd_device *device)
4190 struct dasd_ccw_req *cqr;
4195 if (!capable(CAP_SYS_ADMIN))
4199 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
4201 mutex_lock(&dasd_reserve_mutex);
4203 cqr = &dasd_reserve_req->cqr;
4204 memset(cqr, 0, sizeof(*cqr));
4205 memset(&dasd_reserve_req->ccw, 0,
4206 sizeof(dasd_reserve_req->ccw));
4207 cqr->cpaddr = &dasd_reserve_req->ccw;
4208 cqr->data = &dasd_reserve_req->data;
4209 cqr->magic = DASD_ECKD_MAGIC;
4212 ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
4213 ccw->flags |= CCW_FLAG_SLI;
4215 ccw->cda = (__u32)(addr_t) cqr->data;
4216 cqr->startdev = device;
4217 cqr->memdev = device;
4218 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4219 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
4220 cqr->retries = 2; /* set retry counter to enable basic ERP */
4221 cqr->expires = 2 * HZ;
4222 cqr->buildclk = get_tod_clock();
4223 cqr->status = DASD_CQR_FILLED;
4225 rc = dasd_sleep_on_immediatly(cqr);
4227 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
4230 mutex_unlock(&dasd_reserve_mutex);
4232 dasd_sfree_request(cqr, cqr->memdev);
4237 * Steal lock ioctl - unconditional reserve device.
4238 * Buils a channel programm to break a device's reservation.
4239 * (unconditional reserve)
4242 dasd_eckd_steal_lock(struct dasd_device *device)
4244 struct dasd_ccw_req *cqr;
4249 if (!capable(CAP_SYS_ADMIN))
4253 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
4255 mutex_lock(&dasd_reserve_mutex);
4257 cqr = &dasd_reserve_req->cqr;
4258 memset(cqr, 0, sizeof(*cqr));
4259 memset(&dasd_reserve_req->ccw, 0,
4260 sizeof(dasd_reserve_req->ccw));
4261 cqr->cpaddr = &dasd_reserve_req->ccw;
4262 cqr->data = &dasd_reserve_req->data;
4263 cqr->magic = DASD_ECKD_MAGIC;
4266 ccw->cmd_code = DASD_ECKD_CCW_SLCK;
4267 ccw->flags |= CCW_FLAG_SLI;
4269 ccw->cda = (__u32)(addr_t) cqr->data;
4270 cqr->startdev = device;
4271 cqr->memdev = device;
4272 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4273 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
4274 cqr->retries = 2; /* set retry counter to enable basic ERP */
4275 cqr->expires = 2 * HZ;
4276 cqr->buildclk = get_tod_clock();
4277 cqr->status = DASD_CQR_FILLED;
4279 rc = dasd_sleep_on_immediatly(cqr);
4281 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
4284 mutex_unlock(&dasd_reserve_mutex);
4286 dasd_sfree_request(cqr, cqr->memdev);
4291 * SNID - Sense Path Group ID
4292 * This ioctl may be used in situations where I/O is stalled due to
4293 * a reserve, so if the normal dasd_smalloc_request fails, we use the
4294 * preallocated dasd_reserve_req.
4296 static int dasd_eckd_snid(struct dasd_device *device,
4299 struct dasd_ccw_req *cqr;
4303 struct dasd_snid_ioctl_data usrparm;
4305 if (!capable(CAP_SYS_ADMIN))
4308 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
4312 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1,
4313 sizeof(struct dasd_snid_data), device);
4315 mutex_lock(&dasd_reserve_mutex);
4317 cqr = &dasd_reserve_req->cqr;
4318 memset(cqr, 0, sizeof(*cqr));
4319 memset(&dasd_reserve_req->ccw, 0,
4320 sizeof(dasd_reserve_req->ccw));
4321 cqr->cpaddr = &dasd_reserve_req->ccw;
4322 cqr->data = &dasd_reserve_req->data;
4323 cqr->magic = DASD_ECKD_MAGIC;
4326 ccw->cmd_code = DASD_ECKD_CCW_SNID;
4327 ccw->flags |= CCW_FLAG_SLI;
4329 ccw->cda = (__u32)(addr_t) cqr->data;
4330 cqr->startdev = device;
4331 cqr->memdev = device;
4332 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4333 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
4334 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
4336 cqr->expires = 10 * HZ;
4337 cqr->buildclk = get_tod_clock();
4338 cqr->status = DASD_CQR_FILLED;
4339 cqr->lpm = usrparm.path_mask;
4341 rc = dasd_sleep_on_immediatly(cqr);
4342 /* verify that I/O processing didn't modify the path mask */
4343 if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask))
4346 usrparm.data = *((struct dasd_snid_data *)cqr->data);
4347 if (copy_to_user(argp, &usrparm, sizeof(usrparm)))
4352 mutex_unlock(&dasd_reserve_mutex);
4354 dasd_sfree_request(cqr, cqr->memdev);
4359 * Read performance statistics
4362 dasd_eckd_performance(struct dasd_device *device, void __user *argp)
4364 struct dasd_psf_prssd_data *prssdp;
4365 struct dasd_rssd_perf_stats_t *stats;
4366 struct dasd_ccw_req *cqr;
4370 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
4371 (sizeof(struct dasd_psf_prssd_data) +
4372 sizeof(struct dasd_rssd_perf_stats_t)),
4375 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
4376 "Could not allocate initialization request");
4377 return PTR_ERR(cqr);
4379 cqr->startdev = device;
4380 cqr->memdev = device;
4382 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
4383 cqr->expires = 10 * HZ;
4385 /* Prepare for Read Subsystem Data */
4386 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
4387 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
4388 prssdp->order = PSF_ORDER_PRSSD;
4389 prssdp->suborder = 0x01; /* Performance Statistics */
4390 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
4393 ccw->cmd_code = DASD_ECKD_CCW_PSF;
4394 ccw->count = sizeof(struct dasd_psf_prssd_data);
4395 ccw->flags |= CCW_FLAG_CC;
4396 ccw->cda = (__u32)(addr_t) prssdp;
4398 /* Read Subsystem Data - Performance Statistics */
4399 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
4400 memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
4403 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
4404 ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
4405 ccw->cda = (__u32)(addr_t) stats;
4407 cqr->buildclk = get_tod_clock();
4408 cqr->status = DASD_CQR_FILLED;
4409 rc = dasd_sleep_on(cqr);
4411 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
4412 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
4413 if (copy_to_user(argp, stats,
4414 sizeof(struct dasd_rssd_perf_stats_t)))
4417 dasd_sfree_request(cqr, cqr->memdev);
4422 * Get attributes (cache operations)
4423 * Returnes the cache attributes used in Define Extend (DE).
4426 dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
4428 struct dasd_eckd_private *private = device->private;
4429 struct attrib_data_t attrib = private->attrib;
4432 if (!capable(CAP_SYS_ADMIN))
4438 if (copy_to_user(argp, (long *) &attrib,
4439 sizeof(struct attrib_data_t)))
4446 * Set attributes (cache operations)
4447 * Stores the attributes for cache operation to be used in Define Extend (DE).
4450 dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
4452 struct dasd_eckd_private *private = device->private;
4453 struct attrib_data_t attrib;
4455 if (!capable(CAP_SYS_ADMIN))
4460 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
4462 private->attrib = attrib;
4464 dev_info(&device->cdev->dev,
4465 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
4466 private->attrib.operation, private->attrib.nr_cyl);
4471 * Issue syscall I/O to EMC Symmetrix array.
4472 * CCWs are PSF and RSSD
4474 static int dasd_symm_io(struct dasd_device *device, void __user *argp)
4476 struct dasd_symmio_parms usrparm;
4477 char *psf_data, *rssd_result;
4478 struct dasd_ccw_req *cqr;
4483 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
4487 /* Copy parms from caller */
4489 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
4491 if (is_compat_task()) {
4492 /* Make sure pointers are sane even on 31 bit. */
4494 if ((usrparm.psf_data >> 32) != 0)
4496 if ((usrparm.rssd_result >> 32) != 0)
4498 usrparm.psf_data &= 0x7fffffffULL;
4499 usrparm.rssd_result &= 0x7fffffffULL;
4501 /* alloc I/O data area */
4502 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
4503 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
4504 if (!psf_data || !rssd_result) {
4509 /* get syscall header from user space */
4511 if (copy_from_user(psf_data,
4512 (void __user *)(unsigned long) usrparm.psf_data,
4513 usrparm.psf_data_len))
4518 /* setup CCWs for PSF + RSSD */
4519 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
4521 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
4522 "Could not allocate initialization request");
4527 cqr->startdev = device;
4528 cqr->memdev = device;
4530 cqr->expires = 10 * HZ;
4531 cqr->buildclk = get_tod_clock();
4532 cqr->status = DASD_CQR_FILLED;
4534 /* Build the ccws */
4538 ccw->cmd_code = DASD_ECKD_CCW_PSF;
4539 ccw->count = usrparm.psf_data_len;
4540 ccw->flags |= CCW_FLAG_CC;
4541 ccw->cda = (__u32)(addr_t) psf_data;
4546 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
4547 ccw->count = usrparm.rssd_result_len;
4548 ccw->flags = CCW_FLAG_SLI ;
4549 ccw->cda = (__u32)(addr_t) rssd_result;
4551 rc = dasd_sleep_on(cqr);
4556 if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
4557 rssd_result, usrparm.rssd_result_len))
4562 dasd_sfree_request(cqr, cqr->memdev);
4567 DBF_DEV_EVENT(DBF_WARNING, device,
4568 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
4569 (int) psf0, (int) psf1, rc);
4574 dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
4576 struct dasd_device *device = block->base;
4580 return dasd_eckd_get_attrib(device, argp);
4582 return dasd_eckd_set_attrib(device, argp);
4584 return dasd_eckd_performance(device, argp);
4586 return dasd_eckd_release(device);
4588 return dasd_eckd_reserve(device);
4590 return dasd_eckd_steal_lock(device);
4592 return dasd_eckd_snid(device, argp);
4594 return dasd_symm_io(device, argp);
4601 * Dump the range of CCWs into 'page' buffer
4602 * and return number of printed chars.
4605 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
4611 while (from <= to) {
4612 len += sprintf(page + len, PRINTK_HEADER
4613 " CCW %p: %08X %08X DAT:",
4614 from, ((int *) from)[0], ((int *) from)[1]);
4616 /* get pointer to data (consider IDALs) */
4617 if (from->flags & CCW_FLAG_IDA)
4618 datap = (char *) *((addr_t *) (addr_t) from->cda);
4620 datap = (char *) ((addr_t) from->cda);
4622 /* dump data (max 32 bytes) */
4623 for (count = 0; count < from->count && count < 32; count++) {
4624 if (count % 8 == 0) len += sprintf(page + len, " ");
4625 if (count % 4 == 0) len += sprintf(page + len, " ");
4626 len += sprintf(page + len, "%02x", datap[count]);
4628 len += sprintf(page + len, "\n");
4635 dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
4641 sense = (u64 *) dasd_get_sense(irb);
4642 stat = (u64 *) &irb->scsw;
4644 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : "
4645 "%016llx %016llx %016llx %016llx",
4646 reason, *stat, *((u32 *) (stat + 1)),
4647 sense[0], sense[1], sense[2], sense[3]);
4649 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s",
4650 reason, *stat, *((u32 *) (stat + 1)),
4656 * Print sense data and related channel program.
4657 * Parts are printed because printk buffer is only 1024 bytes.
4659 static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
4660 struct dasd_ccw_req *req, struct irb *irb)
4663 struct ccw1 *first, *last, *fail, *from, *to;
4666 page = (char *) get_zeroed_page(GFP_ATOMIC);
4668 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
4669 "No memory to dump sense data\n");
4672 /* dump the sense data */
4673 len = sprintf(page, PRINTK_HEADER
4674 " I/O status report for device %s:\n",
4675 dev_name(&device->cdev->dev));
4676 len += sprintf(page + len, PRINTK_HEADER
4677 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4679 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
4680 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
4681 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
4682 req ? req->intrc : 0);
4683 len += sprintf(page + len, PRINTK_HEADER
4684 " device %s: Failing CCW: %p\n",
4685 dev_name(&device->cdev->dev),
4686 (void *) (addr_t) irb->scsw.cmd.cpa);
4687 if (irb->esw.esw0.erw.cons) {
4688 for (sl = 0; sl < 4; sl++) {
4689 len += sprintf(page + len, PRINTK_HEADER
4690 " Sense(hex) %2d-%2d:",
4691 (8 * sl), ((8 * sl) + 7));
4693 for (sct = 0; sct < 8; sct++) {
4694 len += sprintf(page + len, " %02x",
4695 irb->ecw[8 * sl + sct]);
4697 len += sprintf(page + len, "\n");
4700 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
4701 /* 24 Byte Sense Data */
4702 sprintf(page + len, PRINTK_HEADER
4703 " 24 Byte: %x MSG %x, "
4704 "%s MSGb to SYSOP\n",
4705 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
4706 irb->ecw[1] & 0x10 ? "" : "no");
4708 /* 32 Byte Sense Data */
4709 sprintf(page + len, PRINTK_HEADER
4710 " 32 Byte: Format: %x "
4711 "Exception class %x\n",
4712 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
4715 sprintf(page + len, PRINTK_HEADER
4716 " SORRY - NO VALID SENSE AVAILABLE\n");
4718 printk(KERN_ERR "%s", page);
4721 /* req == NULL for unsolicited interrupts */
4722 /* dump the Channel Program (max 140 Bytes per line) */
4723 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
4724 first = req->cpaddr;
4725 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
4726 to = min(first + 6, last);
4727 len = sprintf(page, PRINTK_HEADER
4728 " Related CP in req: %p\n", req);
4729 dasd_eckd_dump_ccw_range(first, to, page + len);
4730 printk(KERN_ERR "%s", page);
4732 /* print failing CCW area (maximum 4) */
4733 /* scsw->cda is either valid or zero */
4736 fail = (struct ccw1 *)(addr_t)
4737 irb->scsw.cmd.cpa; /* failing CCW */
4738 if (from < fail - 2) {
4739 from = fail - 2; /* there is a gap - print header */
4740 len += sprintf(page, PRINTK_HEADER "......\n");
4742 to = min(fail + 1, last);
4743 len += dasd_eckd_dump_ccw_range(from, to, page + len);
4745 /* print last CCWs (maximum 2) */
4746 from = max(from, ++to);
4747 if (from < last - 1) {
4748 from = last - 1; /* there is a gap - print header */
4749 len += sprintf(page + len, PRINTK_HEADER "......\n");
4751 len += dasd_eckd_dump_ccw_range(from, last, page + len);
4753 printk(KERN_ERR "%s", page);
4755 free_page((unsigned long) page);
4760 * Print sense data from a tcw.
4762 static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
4763 struct dasd_ccw_req *req, struct irb *irb)
4766 int len, sl, sct, residual;
4770 page = (char *) get_zeroed_page(GFP_ATOMIC);
4772 DBF_DEV_EVENT(DBF_WARNING, device, " %s",
4773 "No memory to dump sense data");
4776 /* dump the sense data */
4777 len = sprintf(page, PRINTK_HEADER
4778 " I/O status report for device %s:\n",
4779 dev_name(&device->cdev->dev));
4780 len += sprintf(page + len, PRINTK_HEADER
4781 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4782 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
4783 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
4784 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
4785 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
4786 irb->scsw.tm.fcxs, irb->scsw.tm.schxs,
4787 req ? req->intrc : 0);
4788 len += sprintf(page + len, PRINTK_HEADER
4789 " device %s: Failing TCW: %p\n",
4790 dev_name(&device->cdev->dev),
4791 (void *) (addr_t) irb->scsw.tm.tcw);
4795 if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01))
4797 (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
4800 len += sprintf(page + len, PRINTK_HEADER
4801 " tsb->length %d\n", tsb->length);
4802 len += sprintf(page + len, PRINTK_HEADER
4803 " tsb->flags %x\n", tsb->flags);
4804 len += sprintf(page + len, PRINTK_HEADER
4805 " tsb->dcw_offset %d\n", tsb->dcw_offset);
4806 len += sprintf(page + len, PRINTK_HEADER
4807 " tsb->count %d\n", tsb->count);
4808 residual = tsb->count - 28;
4809 len += sprintf(page + len, PRINTK_HEADER
4810 " residual %d\n", residual);
4812 switch (tsb->flags & 0x07) {
4813 case 1: /* tsa_iostat */
4814 len += sprintf(page + len, PRINTK_HEADER
4815 " tsb->tsa.iostat.dev_time %d\n",
4816 tsb->tsa.iostat.dev_time);
4817 len += sprintf(page + len, PRINTK_HEADER
4818 " tsb->tsa.iostat.def_time %d\n",
4819 tsb->tsa.iostat.def_time);
4820 len += sprintf(page + len, PRINTK_HEADER
4821 " tsb->tsa.iostat.queue_time %d\n",
4822 tsb->tsa.iostat.queue_time);
4823 len += sprintf(page + len, PRINTK_HEADER
4824 " tsb->tsa.iostat.dev_busy_time %d\n",
4825 tsb->tsa.iostat.dev_busy_time);
4826 len += sprintf(page + len, PRINTK_HEADER
4827 " tsb->tsa.iostat.dev_act_time %d\n",
4828 tsb->tsa.iostat.dev_act_time);
4829 sense = tsb->tsa.iostat.sense;
4831 case 2: /* ts_ddpc */
4832 len += sprintf(page + len, PRINTK_HEADER
4833 " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
4834 for (sl = 0; sl < 2; sl++) {
4835 len += sprintf(page + len, PRINTK_HEADER
4836 " tsb->tsa.ddpc.rcq %2d-%2d: ",
4837 (8 * sl), ((8 * sl) + 7));
4838 rcq = tsb->tsa.ddpc.rcq;
4839 for (sct = 0; sct < 8; sct++) {
4840 len += sprintf(page + len, " %02x",
4843 len += sprintf(page + len, "\n");
4845 sense = tsb->tsa.ddpc.sense;
4847 case 3: /* tsa_intrg */
4848 len += sprintf(page + len, PRINTK_HEADER
4849 " tsb->tsa.intrg.: not supportet yet\n");
4854 for (sl = 0; sl < 4; sl++) {
4855 len += sprintf(page + len, PRINTK_HEADER
4856 " Sense(hex) %2d-%2d:",
4857 (8 * sl), ((8 * sl) + 7));
4858 for (sct = 0; sct < 8; sct++) {
4859 len += sprintf(page + len, " %02x",
4860 sense[8 * sl + sct]);
4862 len += sprintf(page + len, "\n");
4865 if (sense[27] & DASD_SENSE_BIT_0) {
4866 /* 24 Byte Sense Data */
4867 sprintf(page + len, PRINTK_HEADER
4868 " 24 Byte: %x MSG %x, "
4869 "%s MSGb to SYSOP\n",
4870 sense[7] >> 4, sense[7] & 0x0f,
4871 sense[1] & 0x10 ? "" : "no");
4873 /* 32 Byte Sense Data */
4874 sprintf(page + len, PRINTK_HEADER
4875 " 32 Byte: Format: %x "
4876 "Exception class %x\n",
4877 sense[6] & 0x0f, sense[22] >> 4);
4880 sprintf(page + len, PRINTK_HEADER
4881 " SORRY - NO VALID SENSE AVAILABLE\n");
4884 sprintf(page + len, PRINTK_HEADER
4885 " SORRY - NO TSB DATA AVAILABLE\n");
4887 printk(KERN_ERR "%s", page);
4888 free_page((unsigned long) page);
4891 static void dasd_eckd_dump_sense(struct dasd_device *device,
4892 struct dasd_ccw_req *req, struct irb *irb)
4894 u8 *sense = dasd_get_sense(irb);
4896 if (scsw_is_tm(&irb->scsw)) {
4898 * In some cases the 'File Protected' or 'Incorrect Length'
4899 * error might be expected and log messages shouldn't be written
4900 * then. Check if the according suppress bit is set.
4902 if (sense && (sense[1] & SNS1_FILE_PROTECTED) &&
4903 test_bit(DASD_CQR_SUPPRESS_FP, &req->flags))
4905 if (scsw_cstat(&irb->scsw) == 0x40 &&
4906 test_bit(DASD_CQR_SUPPRESS_IL, &req->flags))
4909 dasd_eckd_dump_sense_tcw(device, req, irb);
4912 * In some cases the 'No Record Found' error might be expected
4913 * and log messages shouldn't be written then. Check if the
4914 * according suppress bit is set.
4916 if (sense && sense[1] & SNS1_NO_REC_FOUND &&
4917 test_bit(DASD_CQR_SUPPRESS_NRF, &req->flags))
4920 dasd_eckd_dump_sense_ccw(device, req, irb);
4924 static int dasd_eckd_pm_freeze(struct dasd_device *device)
4927 * the device should be disconnected from our LCU structure
4928 * on restore we will reconnect it and reread LCU specific
4929 * information like PAV support that might have changed
4931 dasd_alias_remove_device(device);
4932 dasd_alias_disconnect_device_from_lcu(device);
4937 static int dasd_eckd_restore_device(struct dasd_device *device)
4939 struct dasd_eckd_private *private = device->private;
4940 struct dasd_eckd_characteristics temp_rdc_data;
4942 struct dasd_uid temp_uid;
4943 unsigned long flags;
4944 unsigned long cqr_flags = 0;
4946 /* Read Configuration Data */
4947 rc = dasd_eckd_read_conf(device);
4949 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
4950 "Read configuration data failed, rc=%d", rc);
4954 dasd_eckd_get_uid(device, &temp_uid);
4955 /* Generate device unique id */
4956 rc = dasd_eckd_generate_uid(device);
4957 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
4958 if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
4959 dev_err(&device->cdev->dev, "The UID of the DASD has "
4961 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4965 /* register lcu with alias handling, enable PAV if this is a new lcu */
4966 rc = dasd_alias_make_device_known_to_lcu(device);
4970 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr_flags);
4971 dasd_eckd_validate_server(device, cqr_flags);
4973 /* RE-Read Configuration Data */
4974 rc = dasd_eckd_read_conf(device);
4976 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
4977 "Read configuration data failed, rc=%d", rc);
4981 /* Read Feature Codes */
4982 dasd_eckd_read_features(device);
4984 /* Read Device Characteristics */
4985 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
4986 &temp_rdc_data, 64);
4988 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
4989 "Read device characteristic failed, rc=%d", rc);
4992 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
4993 memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
4994 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4996 /* add device to alias management */
4997 dasd_alias_add_device(device);
5002 dasd_alias_disconnect_device_from_lcu(device);
5007 static int dasd_eckd_reload_device(struct dasd_device *device)
5009 struct dasd_eckd_private *private = device->private;
5012 struct dasd_uid uid;
5013 unsigned long flags;
5016 * remove device from alias handling to prevent new requests
5017 * from being scheduled on the wrong alias device
5019 dasd_alias_remove_device(device);
5021 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
5022 old_base = private->uid.base_unit_addr;
5023 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
5025 /* Read Configuration Data */
5026 rc = dasd_eckd_read_conf(device);
5030 rc = dasd_eckd_generate_uid(device);
5034 * update unit address configuration and
5035 * add device to alias management
5037 dasd_alias_update_add_device(device);
5039 dasd_eckd_get_uid(device, &uid);
5041 if (old_base != uid.base_unit_addr) {
5042 if (strlen(uid.vduit) > 0)
5043 snprintf(print_uid, sizeof(print_uid),
5044 "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
5045 uid.ssid, uid.base_unit_addr, uid.vduit);
5047 snprintf(print_uid, sizeof(print_uid),
5048 "%s.%s.%04x.%02x", uid.vendor, uid.serial,
5049 uid.ssid, uid.base_unit_addr);
5051 dev_info(&device->cdev->dev,
5052 "An Alias device was reassigned to a new base device "
5053 "with UID: %s\n", print_uid);
5061 static int dasd_eckd_read_message_buffer(struct dasd_device *device,
5062 struct dasd_rssd_messages *messages,
5065 struct dasd_rssd_messages *message_buf;
5066 struct dasd_psf_prssd_data *prssdp;
5067 struct dasd_ccw_req *cqr;
5071 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
5072 (sizeof(struct dasd_psf_prssd_data) +
5073 sizeof(struct dasd_rssd_messages)),
5076 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5077 "Could not allocate read message buffer request");
5078 return PTR_ERR(cqr);
5081 cqr->startdev = device;
5082 cqr->memdev = device;
5084 cqr->expires = 10 * HZ;
5085 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
5086 /* dasd_sleep_on_immediatly does not do complex error
5087 * recovery so clear erp flag and set retry counter to
5089 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
5092 /* Prepare for Read Subsystem Data */
5093 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
5094 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
5095 prssdp->order = PSF_ORDER_PRSSD;
5096 prssdp->suborder = 0x03; /* Message Buffer */
5097 /* all other bytes of prssdp must be zero */
5100 ccw->cmd_code = DASD_ECKD_CCW_PSF;
5101 ccw->count = sizeof(struct dasd_psf_prssd_data);
5102 ccw->flags |= CCW_FLAG_CC;
5103 ccw->flags |= CCW_FLAG_SLI;
5104 ccw->cda = (__u32)(addr_t) prssdp;
5106 /* Read Subsystem Data - message buffer */
5107 message_buf = (struct dasd_rssd_messages *) (prssdp + 1);
5108 memset(message_buf, 0, sizeof(struct dasd_rssd_messages));
5111 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
5112 ccw->count = sizeof(struct dasd_rssd_messages);
5113 ccw->flags |= CCW_FLAG_SLI;
5114 ccw->cda = (__u32)(addr_t) message_buf;
5116 cqr->buildclk = get_tod_clock();
5117 cqr->status = DASD_CQR_FILLED;
5118 rc = dasd_sleep_on_immediatly(cqr);
5120 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
5121 message_buf = (struct dasd_rssd_messages *)
5123 memcpy(messages, message_buf,
5124 sizeof(struct dasd_rssd_messages));
5126 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
5127 "Reading messages failed with rc=%d\n"
5129 dasd_sfree_request(cqr, cqr->memdev);
5133 static int dasd_eckd_query_host_access(struct dasd_device *device,
5134 struct dasd_psf_query_host_access *data)
5136 struct dasd_eckd_private *private = device->private;
5137 struct dasd_psf_query_host_access *host_access;
5138 struct dasd_psf_prssd_data *prssdp;
5139 struct dasd_ccw_req *cqr;
5143 /* not available for HYPER PAV alias devices */
5144 if (!device->block && private->lcu->pav == HYPER_PAV)
5147 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
5148 sizeof(struct dasd_psf_prssd_data) + 1,
5151 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5152 "Could not allocate read message buffer request");
5153 return PTR_ERR(cqr);
5155 host_access = kzalloc(sizeof(*host_access), GFP_KERNEL | GFP_DMA);
5157 dasd_sfree_request(cqr, device);
5158 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5159 "Could not allocate host_access buffer");
5162 cqr->startdev = device;
5163 cqr->memdev = device;
5166 cqr->expires = 10 * HZ;
5168 /* Prepare for Read Subsystem Data */
5169 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
5170 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
5171 prssdp->order = PSF_ORDER_PRSSD;
5172 prssdp->suborder = PSF_SUBORDER_QHA; /* query host access */
5173 /* LSS and Volume that will be queried */
5174 prssdp->lss = private->ned->ID;
5175 prssdp->volume = private->ned->unit_addr;
5176 /* all other bytes of prssdp must be zero */
5179 ccw->cmd_code = DASD_ECKD_CCW_PSF;
5180 ccw->count = sizeof(struct dasd_psf_prssd_data);
5181 ccw->flags |= CCW_FLAG_CC;
5182 ccw->flags |= CCW_FLAG_SLI;
5183 ccw->cda = (__u32)(addr_t) prssdp;
5185 /* Read Subsystem Data - query host access */
5187 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
5188 ccw->count = sizeof(struct dasd_psf_query_host_access);
5189 ccw->flags |= CCW_FLAG_SLI;
5190 ccw->cda = (__u32)(addr_t) host_access;
5192 cqr->buildclk = get_tod_clock();
5193 cqr->status = DASD_CQR_FILLED;
5194 rc = dasd_sleep_on(cqr);
5196 *data = *host_access;
5198 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
5199 "Reading host access data failed with rc=%d\n",
5204 dasd_sfree_request(cqr, cqr->memdev);
5209 * return number of grouped devices
5211 static int dasd_eckd_host_access_count(struct dasd_device *device)
5213 struct dasd_psf_query_host_access *access;
5214 struct dasd_ckd_path_group_entry *entry;
5215 struct dasd_ckd_host_information *info;
5219 access = kzalloc(sizeof(*access), GFP_NOIO);
5221 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5222 "Could not allocate access buffer");
5225 rc = dasd_eckd_query_host_access(device, access);
5231 info = (struct dasd_ckd_host_information *)
5232 access->host_access_information;
5233 for (i = 0; i < info->entry_count; i++) {
5234 entry = (struct dasd_ckd_path_group_entry *)
5235 (info->entry + i * info->entry_size);
5236 if (entry->status_flags & DASD_ECKD_PG_GROUPED)
5245 * write host access information to a sequential file
5247 static int dasd_hosts_print(struct dasd_device *device, struct seq_file *m)
5249 struct dasd_psf_query_host_access *access;
5250 struct dasd_ckd_path_group_entry *entry;
5251 struct dasd_ckd_host_information *info;
5252 char sysplex[9] = "";
5255 access = kzalloc(sizeof(*access), GFP_NOIO);
5257 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
5258 "Could not allocate access buffer");
5261 rc = dasd_eckd_query_host_access(device, access);
5267 info = (struct dasd_ckd_host_information *)
5268 access->host_access_information;
5269 for (i = 0; i < info->entry_count; i++) {
5270 entry = (struct dasd_ckd_path_group_entry *)
5271 (info->entry + i * info->entry_size);
5273 seq_puts(m, "pgid ");
5274 for (j = 0; j < 11; j++)
5275 seq_printf(m, "%02x", entry->pgid[j]);
5278 seq_printf(m, "status_flags %02x\n", entry->status_flags);
5280 memcpy(&sysplex, &entry->sysplex_name, sizeof(sysplex) - 1);
5281 EBCASC(sysplex, sizeof(sysplex));
5282 seq_printf(m, "sysplex_name %8s\n", sysplex);
5283 /* SUPPORTED CYLINDER */
5284 seq_printf(m, "supported_cylinder %d\n", entry->cylinder);
5286 seq_printf(m, "timestamp %lu\n", (unsigned long)
5295 * Perform Subsystem Function - CUIR response
5298 dasd_eckd_psf_cuir_response(struct dasd_device *device, int response,
5300 struct channel_path_desc *desc,
5301 struct subchannel_id sch_id)
5303 struct dasd_psf_cuir_response *psf_cuir;
5304 struct dasd_ccw_req *cqr;
5308 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
5309 sizeof(struct dasd_psf_cuir_response),
5313 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
5314 "Could not allocate PSF-CUIR request");
5315 return PTR_ERR(cqr);
5318 psf_cuir = (struct dasd_psf_cuir_response *)cqr->data;
5319 psf_cuir->order = PSF_ORDER_CUIR_RESPONSE;
5320 psf_cuir->cc = response;
5322 psf_cuir->chpid = desc->chpid;
5323 psf_cuir->message_id = message_id;
5324 psf_cuir->cssid = sch_id.cssid;
5325 psf_cuir->ssid = sch_id.ssid;
5327 ccw->cmd_code = DASD_ECKD_CCW_PSF;
5328 ccw->cda = (__u32)(addr_t)psf_cuir;
5329 ccw->flags = CCW_FLAG_SLI;
5330 ccw->count = sizeof(struct dasd_psf_cuir_response);
5332 cqr->startdev = device;
5333 cqr->memdev = device;
5336 cqr->expires = 10*HZ;
5337 cqr->buildclk = get_tod_clock();
5338 cqr->status = DASD_CQR_FILLED;
5339 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
5341 rc = dasd_sleep_on(cqr);
5343 dasd_sfree_request(cqr, cqr->memdev);
5348 * return configuration data that is referenced by record selector
5349 * if a record selector is specified or per default return the
5350 * conf_data pointer for the path specified by lpum
5352 static struct dasd_conf_data *dasd_eckd_get_ref_conf(struct dasd_device *device,
5354 struct dasd_cuir_message *cuir)
5356 struct dasd_eckd_private *private = device->private;
5357 struct dasd_conf_data *conf_data;
5360 if (cuir->record_selector == 0)
5362 for (path = 0x80, pos = 0; path; path >>= 1, pos++) {
5363 conf_data = private->path_conf_data[pos];
5364 if (conf_data->gneq.record_selector ==
5365 cuir->record_selector)
5369 return private->path_conf_data[pathmask_to_pos(lpum)];
5373 * This function determines the scope of a reconfiguration request by
5374 * analysing the path and device selection data provided in the CUIR request.
5375 * Returns a path mask containing CUIR affected paths for the give device.
5377 * If the CUIR request does not contain the required information return the
5378 * path mask of the path the attention message for the CUIR request was reveived
5381 static int dasd_eckd_cuir_scope(struct dasd_device *device, __u8 lpum,
5382 struct dasd_cuir_message *cuir)
5384 struct dasd_eckd_private *private = device->private;
5385 struct dasd_conf_data *ref_conf_data;
5386 unsigned long bitmask = 0, mask = 0;
5387 struct dasd_conf_data *conf_data;
5388 unsigned int pos, path;
5389 char *ref_gneq, *gneq;
5390 char *ref_ned, *ned;
5393 /* if CUIR request does not specify the scope use the path
5394 the attention message was presented on */
5395 if (!cuir->ned_map ||
5396 !(cuir->neq_map[0] | cuir->neq_map[1] | cuir->neq_map[2]))
5399 /* get reference conf data */
5400 ref_conf_data = dasd_eckd_get_ref_conf(device, lpum, cuir);
5401 /* reference ned is determined by ned_map field */
5402 pos = 8 - ffs(cuir->ned_map);
5403 ref_ned = (char *)&ref_conf_data->neds[pos];
5404 ref_gneq = (char *)&ref_conf_data->gneq;
5405 /* transfer 24 bit neq_map to mask */
5406 mask = cuir->neq_map[2];
5407 mask |= cuir->neq_map[1] << 8;
5408 mask |= cuir->neq_map[0] << 16;
5410 for (path = 0x80; path; path >>= 1) {
5411 /* initialise data per path */
5413 pos = pathmask_to_pos(path);
5414 conf_data = private->path_conf_data[pos];
5415 pos = 8 - ffs(cuir->ned_map);
5416 ned = (char *) &conf_data->neds[pos];
5417 /* compare reference ned and per path ned */
5418 if (memcmp(ref_ned, ned, sizeof(*ned)) != 0)
5420 gneq = (char *)&conf_data->gneq;
5421 /* compare reference gneq and per_path gneq under
5422 24 bit mask where mask bit 0 equals byte 7 of
5423 the gneq and mask bit 24 equals byte 31 */
5425 pos = ffs(bitmask) - 1;
5426 if (memcmp(&ref_gneq[31 - pos], &gneq[31 - pos], 1)
5429 clear_bit(pos, &bitmask);
5433 /* device and path match the reference values
5434 add path to CUIR scope */
5440 static void dasd_eckd_cuir_notify_user(struct dasd_device *device,
5441 unsigned long paths,
5442 struct subchannel_id sch_id, int action)
5444 struct channel_path_desc *desc;
5448 /* get position of bit in mask */
5449 pos = ffs(paths) - 1;
5450 /* get channel path descriptor from this position */
5451 desc = ccw_device_get_chp_desc(device->cdev, 7 - pos);
5452 if (action == CUIR_QUIESCE)
5453 pr_warn("Service on the storage server caused path "
5454 "%x.%02x to go offline", sch_id.cssid,
5455 desc ? desc->chpid : 0);
5456 else if (action == CUIR_RESUME)
5457 pr_info("Path %x.%02x is back online after service "
5458 "on the storage server", sch_id.cssid,
5459 desc ? desc->chpid : 0);
5461 clear_bit(pos, &paths);
5465 static int dasd_eckd_cuir_remove_path(struct dasd_device *device, __u8 lpum,
5466 struct dasd_cuir_message *cuir)
5468 unsigned long tbcpm;
5470 tbcpm = dasd_eckd_cuir_scope(device, lpum, cuir);
5471 /* nothing to do if path is not in use */
5472 if (!(device->path_data.opm & tbcpm))
5474 if (!(device->path_data.opm & ~tbcpm)) {
5475 /* no path would be left if the CUIR action is taken
5479 /* remove device from operational path mask */
5480 device->path_data.opm &= ~tbcpm;
5481 device->path_data.cuirpm |= tbcpm;
5486 * walk through all devices and build a path mask to quiesce them
5487 * return an error if the last path to a device would be removed
5489 * if only part of the devices are quiesced and an error
5490 * occurs no onlining necessary, the storage server will
5491 * notify the already set offline devices again
5493 static int dasd_eckd_cuir_quiesce(struct dasd_device *device, __u8 lpum,
5494 struct subchannel_id sch_id,
5495 struct dasd_cuir_message *cuir)
5497 struct dasd_eckd_private *private = device->private;
5498 struct alias_pav_group *pavgroup, *tempgroup;
5499 struct dasd_device *dev, *n;
5500 unsigned long paths = 0;
5501 unsigned long flags;
5504 /* active devices */
5505 list_for_each_entry_safe(dev, n, &private->lcu->active_devices,
5507 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
5508 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
5509 spin_unlock_irqrestore(get_ccwdev_lock(dev->cdev), flags);
5514 /* inactive devices */
5515 list_for_each_entry_safe(dev, n, &private->lcu->inactive_devices,
5517 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
5518 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
5519 spin_unlock_irqrestore(get_ccwdev_lock(dev->cdev), flags);
5524 /* devices in PAV groups */
5525 list_for_each_entry_safe(pavgroup, tempgroup,
5526 &private->lcu->grouplist, group) {
5527 list_for_each_entry_safe(dev, n, &pavgroup->baselist,
5529 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
5530 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
5531 spin_unlock_irqrestore(
5532 get_ccwdev_lock(dev->cdev), flags);
5537 list_for_each_entry_safe(dev, n, &pavgroup->aliaslist,
5539 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
5540 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
5541 spin_unlock_irqrestore(
5542 get_ccwdev_lock(dev->cdev), flags);
5548 /* notify user about all paths affected by CUIR action */
5549 dasd_eckd_cuir_notify_user(device, paths, sch_id, CUIR_QUIESCE);
5555 static int dasd_eckd_cuir_resume(struct dasd_device *device, __u8 lpum,
5556 struct subchannel_id sch_id,
5557 struct dasd_cuir_message *cuir)
5559 struct dasd_eckd_private *private = device->private;
5560 struct alias_pav_group *pavgroup, *tempgroup;
5561 struct dasd_device *dev, *n;
5562 unsigned long paths = 0;
5566 * the path may have been added through a generic path event before
5567 * only trigger path verification if the path is not already in use
5569 list_for_each_entry_safe(dev, n,
5570 &private->lcu->active_devices,
5572 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
5574 if (!(dev->path_data.opm & tbcpm)) {
5575 dev->path_data.tbvpm |= tbcpm;
5576 dasd_schedule_device_bh(dev);
5579 list_for_each_entry_safe(dev, n,
5580 &private->lcu->inactive_devices,
5582 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
5584 if (!(dev->path_data.opm & tbcpm)) {
5585 dev->path_data.tbvpm |= tbcpm;
5586 dasd_schedule_device_bh(dev);
5589 /* devices in PAV groups */
5590 list_for_each_entry_safe(pavgroup, tempgroup,
5591 &private->lcu->grouplist,
5593 list_for_each_entry_safe(dev, n,
5594 &pavgroup->baselist,
5596 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
5598 if (!(dev->path_data.opm & tbcpm)) {
5599 dev->path_data.tbvpm |= tbcpm;
5600 dasd_schedule_device_bh(dev);
5603 list_for_each_entry_safe(dev, n,
5604 &pavgroup->aliaslist,
5606 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
5608 if (!(dev->path_data.opm & tbcpm)) {
5609 dev->path_data.tbvpm |= tbcpm;
5610 dasd_schedule_device_bh(dev);
5614 /* notify user about all paths affected by CUIR action */
5615 dasd_eckd_cuir_notify_user(device, paths, sch_id, CUIR_RESUME);
5619 static void dasd_eckd_handle_cuir(struct dasd_device *device, void *messages,
5622 struct dasd_cuir_message *cuir = messages;
5623 struct channel_path_desc *desc;
5624 struct subchannel_id sch_id;
5627 DBF_DEV_EVENT(DBF_WARNING, device,
5628 "CUIR request: %016llx %016llx %016llx %08x",
5629 ((u64 *)cuir)[0], ((u64 *)cuir)[1], ((u64 *)cuir)[2],
5631 ccw_device_get_schid(device->cdev, &sch_id);
5632 pos = pathmask_to_pos(lpum);
5633 desc = ccw_device_get_chp_desc(device->cdev, pos);
5635 if (cuir->code == CUIR_QUIESCE) {
5637 if (dasd_eckd_cuir_quiesce(device, lpum, sch_id, cuir))
5638 response = PSF_CUIR_LAST_PATH;
5640 response = PSF_CUIR_COMPLETED;
5641 } else if (cuir->code == CUIR_RESUME) {
5643 dasd_eckd_cuir_resume(device, lpum, sch_id, cuir);
5644 response = PSF_CUIR_COMPLETED;
5646 response = PSF_CUIR_NOT_SUPPORTED;
5648 dasd_eckd_psf_cuir_response(device, response,
5649 cuir->message_id, desc, sch_id);
5650 DBF_DEV_EVENT(DBF_WARNING, device,
5651 "CUIR response: %d on message ID %08x", response,
5653 /* free descriptor copy */
5655 /* to make sure there is no attention left schedule work again */
5656 device->discipline->check_attention(device, lpum);
5659 static void dasd_eckd_check_attention_work(struct work_struct *work)
5661 struct check_attention_work_data *data;
5662 struct dasd_rssd_messages *messages;
5663 struct dasd_device *device;
5666 data = container_of(work, struct check_attention_work_data, worker);
5667 device = data->device;
5668 messages = kzalloc(sizeof(*messages), GFP_KERNEL);
5670 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
5671 "Could not allocate attention message buffer");
5674 rc = dasd_eckd_read_message_buffer(device, messages, data->lpum);
5677 if (messages->length == ATTENTION_LENGTH_CUIR &&
5678 messages->format == ATTENTION_FORMAT_CUIR)
5679 dasd_eckd_handle_cuir(device, messages, data->lpum);
5681 dasd_put_device(device);
5686 static int dasd_eckd_check_attention(struct dasd_device *device, __u8 lpum)
5688 struct check_attention_work_data *data;
5690 data = kzalloc(sizeof(*data), GFP_ATOMIC);
5693 INIT_WORK(&data->worker, dasd_eckd_check_attention_work);
5694 dasd_get_device(device);
5695 data->device = device;
5697 schedule_work(&data->worker);
5701 static struct ccw_driver dasd_eckd_driver = {
5703 .name = "dasd-eckd",
5704 .owner = THIS_MODULE,
5706 .ids = dasd_eckd_ids,
5707 .probe = dasd_eckd_probe,
5708 .remove = dasd_generic_remove,
5709 .set_offline = dasd_generic_set_offline,
5710 .set_online = dasd_eckd_set_online,
5711 .notify = dasd_generic_notify,
5712 .path_event = dasd_generic_path_event,
5713 .shutdown = dasd_generic_shutdown,
5714 .freeze = dasd_generic_pm_freeze,
5715 .thaw = dasd_generic_restore_device,
5716 .restore = dasd_generic_restore_device,
5717 .uc_handler = dasd_generic_uc_handler,
5718 .int_class = IRQIO_DAS,
5722 * max_blocks is dependent on the amount of storage that is available
5723 * in the static io buffer for each device. Currently each device has
5724 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
5725 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
5726 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
5727 * addition we have one define extent ccw + 16 bytes of data and one
5728 * locate record ccw + 16 bytes of data. That makes:
5729 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
5730 * We want to fit two into the available memory so that we can immediately
5731 * start the next request if one finishes off. That makes 249.5 blocks
5732 * for one request. Give a little safety and the result is 240.
5734 static struct dasd_discipline dasd_eckd_discipline = {
5735 .owner = THIS_MODULE,
5739 .check_device = dasd_eckd_check_characteristics,
5740 .uncheck_device = dasd_eckd_uncheck_device,
5741 .do_analysis = dasd_eckd_do_analysis,
5742 .verify_path = dasd_eckd_verify_path,
5743 .basic_to_ready = dasd_eckd_basic_to_ready,
5744 .online_to_ready = dasd_eckd_online_to_ready,
5745 .basic_to_known = dasd_eckd_basic_to_known,
5746 .fill_geometry = dasd_eckd_fill_geometry,
5747 .start_IO = dasd_start_IO,
5748 .term_IO = dasd_term_IO,
5749 .handle_terminated_request = dasd_eckd_handle_terminated_request,
5750 .format_device = dasd_eckd_format_device,
5751 .check_device_format = dasd_eckd_check_device_format,
5752 .erp_action = dasd_eckd_erp_action,
5753 .erp_postaction = dasd_eckd_erp_postaction,
5754 .check_for_device_change = dasd_eckd_check_for_device_change,
5755 .build_cp = dasd_eckd_build_alias_cp,
5756 .free_cp = dasd_eckd_free_alias_cp,
5757 .dump_sense = dasd_eckd_dump_sense,
5758 .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
5759 .fill_info = dasd_eckd_fill_info,
5760 .ioctl = dasd_eckd_ioctl,
5761 .freeze = dasd_eckd_pm_freeze,
5762 .restore = dasd_eckd_restore_device,
5763 .reload = dasd_eckd_reload_device,
5764 .get_uid = dasd_eckd_get_uid,
5765 .kick_validate = dasd_eckd_kick_validate_server,
5766 .check_attention = dasd_eckd_check_attention,
5767 .host_access_count = dasd_eckd_host_access_count,
5768 .hosts_print = dasd_hosts_print,
5772 dasd_eckd_init(void)
5776 ASCEBC(dasd_eckd_discipline.ebcname, 4);
5777 dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
5778 GFP_KERNEL | GFP_DMA);
5779 if (!dasd_reserve_req)
5781 path_verification_worker = kmalloc(sizeof(*path_verification_worker),
5782 GFP_KERNEL | GFP_DMA);
5783 if (!path_verification_worker) {
5784 kfree(dasd_reserve_req);
5787 rawpadpage = (void *)__get_free_page(GFP_KERNEL);
5789 kfree(path_verification_worker);
5790 kfree(dasd_reserve_req);
5793 ret = ccw_driver_register(&dasd_eckd_driver);
5795 wait_for_device_probe();
5797 kfree(path_verification_worker);
5798 kfree(dasd_reserve_req);
5799 free_page((unsigned long)rawpadpage);
5805 dasd_eckd_cleanup(void)
5807 ccw_driver_unregister(&dasd_eckd_driver);
5808 kfree(path_verification_worker);
5809 kfree(dasd_reserve_req);
5810 free_page((unsigned long)rawpadpage);
5813 module_init(dasd_eckd_init);
5814 module_exit(dasd_eckd_cleanup);