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>
23 #include <asm/css_chars.h>
24 #include <asm/debug.h>
25 #include <asm/idals.h>
26 #include <asm/ebcdic.h>
28 #include <asm/uaccess.h>
30 #include <asm/ccwdev.h>
34 #include "dasd_eckd.h"
38 #endif /* PRINTK_HEADER */
39 #define PRINTK_HEADER "dasd(eckd):"
41 #define ECKD_C0(i) (i->home_bytes)
42 #define ECKD_F(i) (i->formula)
43 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
44 (i->factors.f_0x02.f1))
45 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
46 (i->factors.f_0x02.f2))
47 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
48 (i->factors.f_0x02.f3))
49 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
50 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
51 #define ECKD_F6(i) (i->factor6)
52 #define ECKD_F7(i) (i->factor7)
53 #define ECKD_F8(i) (i->factor8)
56 * raw track access always map to 64k in memory
57 * so it maps to 16 blocks of 4k per track
59 #define DASD_RAW_BLOCK_PER_TRACK 16
60 #define DASD_RAW_BLOCKSIZE 4096
61 /* 64k are 128 x 512 byte sectors */
62 #define DASD_RAW_SECTORS_PER_TRACK 128
64 MODULE_LICENSE("GPL");
66 static struct dasd_discipline dasd_eckd_discipline;
68 /* The ccw bus type uses this table to find devices that it sends to
70 static struct ccw_device_id dasd_eckd_ids[] = {
71 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
72 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
73 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info = 0x3},
74 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
75 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
76 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
77 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
78 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
79 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
80 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
81 { /* end of list */ },
84 MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
86 static struct ccw_driver dasd_eckd_driver; /* see below */
88 static void *rawpadpage;
91 #define INIT_CQR_UNFORMATTED 1
92 #define INIT_CQR_ERROR 2
94 /* emergency request for reserve/release */
96 struct dasd_ccw_req cqr;
100 static DEFINE_MUTEX(dasd_reserve_mutex);
102 /* definitions for the path verification worker */
103 struct path_verification_work_data {
104 struct work_struct worker;
105 struct dasd_device *device;
106 struct dasd_ccw_req cqr;
108 __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE];
112 static struct path_verification_work_data *path_verification_worker;
113 static DEFINE_MUTEX(dasd_path_verification_mutex);
115 /* initial attempt at a probe function. this can be simplified once
116 * the other detection code is gone */
118 dasd_eckd_probe (struct ccw_device *cdev)
122 /* set ECKD specific ccw-device options */
123 ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE |
124 CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH);
126 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
127 "dasd_eckd_probe: could not set "
128 "ccw-device options");
131 ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
136 dasd_eckd_set_online(struct ccw_device *cdev)
138 return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
141 static const int sizes_trk0[] = { 28, 148, 84 };
142 #define LABEL_SIZE 140
144 /* head and record addresses of count_area read in analysis ccw */
145 static const int count_area_head[] = { 0, 0, 0, 0, 2 };
146 static const int count_area_rec[] = { 1, 2, 3, 4, 1 };
148 static inline unsigned int
149 round_up_multiple(unsigned int no, unsigned int mult)
152 return (rem ? no - rem + mult : no);
155 static inline unsigned int
156 ceil_quot(unsigned int d1, unsigned int d2)
158 return (d1 + (d2 - 1)) / d2;
162 recs_per_track(struct dasd_eckd_characteristics * rdc,
163 unsigned int kl, unsigned int dl)
167 switch (rdc->dev_type) {
170 return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
171 ceil_quot(dl + 12, 32));
173 return 1499 / (15 + ceil_quot(dl + 12, 32));
175 dn = ceil_quot(dl + 6, 232) + 1;
177 kn = ceil_quot(kl + 6, 232) + 1;
178 return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
179 9 + ceil_quot(dl + 6 * dn, 34));
181 return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
183 dn = ceil_quot(dl + 6, 232) + 1;
185 kn = ceil_quot(kl + 6, 232) + 1;
186 return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
187 ceil_quot(dl + 6 * dn, 34));
189 return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
194 static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
196 geo->cyl = (__u16) cyl;
197 geo->head = cyl >> 16;
203 check_XRC (struct ccw1 *de_ccw,
204 struct DE_eckd_data *data,
205 struct dasd_device *device)
207 struct dasd_eckd_private *private;
210 private = (struct dasd_eckd_private *) device->private;
211 if (!private->rdc_data.facilities.XRC_supported)
214 /* switch on System Time Stamp - needed for XRC Support */
215 data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
216 data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
218 rc = get_sync_clock(&data->ep_sys_time);
219 /* Ignore return code if sync clock is switched off. */
220 if (rc == -EOPNOTSUPP || rc == -EACCES)
223 de_ccw->count = sizeof(struct DE_eckd_data);
224 de_ccw->flags |= CCW_FLAG_SLI;
229 define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
230 unsigned int totrk, int cmd, struct dasd_device *device)
232 struct dasd_eckd_private *private;
234 u16 heads, beghead, endhead;
237 private = (struct dasd_eckd_private *) device->private;
239 ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
242 ccw->cda = (__u32) __pa(data);
244 memset(data, 0, sizeof(struct DE_eckd_data));
246 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
247 case DASD_ECKD_CCW_READ_RECORD_ZERO:
248 case DASD_ECKD_CCW_READ:
249 case DASD_ECKD_CCW_READ_MT:
250 case DASD_ECKD_CCW_READ_CKD:
251 case DASD_ECKD_CCW_READ_CKD_MT:
252 case DASD_ECKD_CCW_READ_KD:
253 case DASD_ECKD_CCW_READ_KD_MT:
254 case DASD_ECKD_CCW_READ_COUNT:
255 data->mask.perm = 0x1;
256 data->attributes.operation = private->attrib.operation;
258 case DASD_ECKD_CCW_WRITE:
259 case DASD_ECKD_CCW_WRITE_MT:
260 case DASD_ECKD_CCW_WRITE_KD:
261 case DASD_ECKD_CCW_WRITE_KD_MT:
262 data->mask.perm = 0x02;
263 data->attributes.operation = private->attrib.operation;
264 rc = check_XRC (ccw, data, device);
266 case DASD_ECKD_CCW_WRITE_CKD:
267 case DASD_ECKD_CCW_WRITE_CKD_MT:
268 data->attributes.operation = DASD_BYPASS_CACHE;
269 rc = check_XRC (ccw, data, device);
271 case DASD_ECKD_CCW_ERASE:
272 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
273 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
274 data->mask.perm = 0x3;
275 data->mask.auth = 0x1;
276 data->attributes.operation = DASD_BYPASS_CACHE;
277 rc = check_XRC (ccw, data, device);
280 dev_err(&device->cdev->dev,
281 "0x%x is not a known command\n", cmd);
285 data->attributes.mode = 0x3; /* ECKD */
287 if ((private->rdc_data.cu_type == 0x2105 ||
288 private->rdc_data.cu_type == 0x2107 ||
289 private->rdc_data.cu_type == 0x1750)
290 && !(private->uses_cdl && trk < 2))
291 data->ga_extended |= 0x40; /* Regular Data Format Mode */
293 heads = private->rdc_data.trk_per_cyl;
294 begcyl = trk / heads;
295 beghead = trk % heads;
296 endcyl = totrk / heads;
297 endhead = totrk % heads;
299 /* check for sequential prestage - enhance cylinder range */
300 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
301 data->attributes.operation == DASD_SEQ_ACCESS) {
303 if (endcyl + private->attrib.nr_cyl < private->real_cyl)
304 endcyl += private->attrib.nr_cyl;
306 endcyl = (private->real_cyl - 1);
309 set_ch_t(&data->beg_ext, begcyl, beghead);
310 set_ch_t(&data->end_ext, endcyl, endhead);
314 static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
315 struct dasd_device *device)
317 struct dasd_eckd_private *private;
320 private = (struct dasd_eckd_private *) device->private;
321 if (!private->rdc_data.facilities.XRC_supported)
324 /* switch on System Time Stamp - needed for XRC Support */
325 pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */
326 pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */
327 pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */
329 rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time);
330 /* Ignore return code if sync clock is switched off. */
331 if (rc == -EOPNOTSUPP || rc == -EACCES)
336 static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk,
337 unsigned int rec_on_trk, int count, int cmd,
338 struct dasd_device *device, unsigned int reclen,
341 struct dasd_eckd_private *private;
345 private = (struct dasd_eckd_private *) device->private;
347 memset(data, 0, sizeof(*data));
350 switch (private->rdc_data.dev_type) {
352 dn = ceil_quot(reclen + 6, 232);
353 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
354 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
357 d = 7 + ceil_quot(reclen + 12, 32);
358 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
362 data->sector = sector;
363 /* note: meaning of count depends on the operation
364 * for record based I/O it's the number of records, but for
365 * track based I/O it's the number of tracks
369 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
370 data->operation.orientation = 0x3;
371 data->operation.operation = 0x03;
373 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
374 data->operation.orientation = 0x3;
375 data->operation.operation = 0x16;
377 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
378 data->operation.orientation = 0x1;
379 data->operation.operation = 0x03;
382 case DASD_ECKD_CCW_READ_RECORD_ZERO:
383 data->operation.orientation = 0x3;
384 data->operation.operation = 0x16;
387 case DASD_ECKD_CCW_WRITE:
388 case DASD_ECKD_CCW_WRITE_MT:
389 case DASD_ECKD_CCW_WRITE_KD:
390 case DASD_ECKD_CCW_WRITE_KD_MT:
391 data->auxiliary.length_valid = 0x1;
392 data->length = reclen;
393 data->operation.operation = 0x01;
395 case DASD_ECKD_CCW_WRITE_CKD:
396 case DASD_ECKD_CCW_WRITE_CKD_MT:
397 data->auxiliary.length_valid = 0x1;
398 data->length = reclen;
399 data->operation.operation = 0x03;
401 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
402 data->operation.orientation = 0x0;
403 data->operation.operation = 0x3F;
404 data->extended_operation = 0x11;
406 data->extended_parameter_length = 0x02;
407 if (data->count > 8) {
408 data->extended_parameter[0] = 0xFF;
409 data->extended_parameter[1] = 0xFF;
410 data->extended_parameter[1] <<= (16 - count);
412 data->extended_parameter[0] = 0xFF;
413 data->extended_parameter[0] <<= (8 - count);
414 data->extended_parameter[1] = 0x00;
418 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
419 data->auxiliary.length_valid = 0x1;
420 data->length = reclen; /* not tlf, as one might think */
421 data->operation.operation = 0x3F;
422 data->extended_operation = 0x23;
424 case DASD_ECKD_CCW_READ:
425 case DASD_ECKD_CCW_READ_MT:
426 case DASD_ECKD_CCW_READ_KD:
427 case DASD_ECKD_CCW_READ_KD_MT:
428 data->auxiliary.length_valid = 0x1;
429 data->length = reclen;
430 data->operation.operation = 0x06;
432 case DASD_ECKD_CCW_READ_CKD:
433 case DASD_ECKD_CCW_READ_CKD_MT:
434 data->auxiliary.length_valid = 0x1;
435 data->length = reclen;
436 data->operation.operation = 0x16;
438 case DASD_ECKD_CCW_READ_COUNT:
439 data->operation.operation = 0x06;
441 case DASD_ECKD_CCW_READ_TRACK:
442 data->operation.orientation = 0x1;
443 data->operation.operation = 0x0C;
444 data->extended_parameter_length = 0;
447 case DASD_ECKD_CCW_READ_TRACK_DATA:
448 data->auxiliary.length_valid = 0x1;
450 data->operation.operation = 0x0C;
452 case DASD_ECKD_CCW_ERASE:
453 data->length = reclen;
454 data->auxiliary.length_valid = 0x1;
455 data->operation.operation = 0x0b;
458 DBF_DEV_EVENT(DBF_ERR, device,
459 "fill LRE unknown opcode 0x%x", cmd);
462 set_ch_t(&data->seek_addr,
463 trk / private->rdc_data.trk_per_cyl,
464 trk % private->rdc_data.trk_per_cyl);
465 data->search_arg.cyl = data->seek_addr.cyl;
466 data->search_arg.head = data->seek_addr.head;
467 data->search_arg.record = rec_on_trk;
470 static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
471 unsigned int trk, unsigned int totrk, int cmd,
472 struct dasd_device *basedev, struct dasd_device *startdev,
473 unsigned char format, unsigned int rec_on_trk, int count,
474 unsigned int blksize, unsigned int tlf)
476 struct dasd_eckd_private *basepriv, *startpriv;
477 struct DE_eckd_data *dedata;
478 struct LRE_eckd_data *lredata;
480 u16 heads, beghead, endhead;
483 basepriv = (struct dasd_eckd_private *) basedev->private;
484 startpriv = (struct dasd_eckd_private *) startdev->private;
485 dedata = &pfxdata->define_extent;
486 lredata = &pfxdata->locate_record;
488 ccw->cmd_code = DASD_ECKD_CCW_PFX;
490 if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) {
491 ccw->count = sizeof(*pfxdata) + 2;
492 ccw->cda = (__u32) __pa(pfxdata);
493 memset(pfxdata, 0, sizeof(*pfxdata) + 2);
495 ccw->count = sizeof(*pfxdata);
496 ccw->cda = (__u32) __pa(pfxdata);
497 memset(pfxdata, 0, sizeof(*pfxdata));
502 DBF_DEV_EVENT(DBF_ERR, basedev,
503 "PFX LRE unknown format 0x%x", format);
507 pfxdata->format = format;
508 pfxdata->base_address = basepriv->ned->unit_addr;
509 pfxdata->base_lss = basepriv->ned->ID;
510 pfxdata->validity.define_extent = 1;
512 /* private uid is kept up to date, conf_data may be outdated */
513 if (startpriv->uid.type != UA_BASE_DEVICE) {
514 pfxdata->validity.verify_base = 1;
515 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
516 pfxdata->validity.hyper_pav = 1;
519 /* define extend data (mostly)*/
521 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
522 case DASD_ECKD_CCW_READ_RECORD_ZERO:
523 case DASD_ECKD_CCW_READ:
524 case DASD_ECKD_CCW_READ_MT:
525 case DASD_ECKD_CCW_READ_CKD:
526 case DASD_ECKD_CCW_READ_CKD_MT:
527 case DASD_ECKD_CCW_READ_KD:
528 case DASD_ECKD_CCW_READ_KD_MT:
529 case DASD_ECKD_CCW_READ_COUNT:
530 dedata->mask.perm = 0x1;
531 dedata->attributes.operation = basepriv->attrib.operation;
533 case DASD_ECKD_CCW_READ_TRACK:
534 case DASD_ECKD_CCW_READ_TRACK_DATA:
535 dedata->mask.perm = 0x1;
536 dedata->attributes.operation = basepriv->attrib.operation;
537 dedata->blk_size = 0;
539 case DASD_ECKD_CCW_WRITE:
540 case DASD_ECKD_CCW_WRITE_MT:
541 case DASD_ECKD_CCW_WRITE_KD:
542 case DASD_ECKD_CCW_WRITE_KD_MT:
543 dedata->mask.perm = 0x02;
544 dedata->attributes.operation = basepriv->attrib.operation;
545 rc = check_XRC_on_prefix(pfxdata, basedev);
547 case DASD_ECKD_CCW_WRITE_CKD:
548 case DASD_ECKD_CCW_WRITE_CKD_MT:
549 dedata->attributes.operation = DASD_BYPASS_CACHE;
550 rc = check_XRC_on_prefix(pfxdata, basedev);
552 case DASD_ECKD_CCW_ERASE:
553 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
554 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
555 dedata->mask.perm = 0x3;
556 dedata->mask.auth = 0x1;
557 dedata->attributes.operation = DASD_BYPASS_CACHE;
558 rc = check_XRC_on_prefix(pfxdata, basedev);
560 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
561 dedata->mask.perm = 0x03;
562 dedata->attributes.operation = basepriv->attrib.operation;
563 dedata->blk_size = 0;
565 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
566 dedata->mask.perm = 0x02;
567 dedata->attributes.operation = basepriv->attrib.operation;
568 dedata->blk_size = blksize;
569 rc = check_XRC_on_prefix(pfxdata, basedev);
572 DBF_DEV_EVENT(DBF_ERR, basedev,
573 "PFX LRE unknown opcode 0x%x", cmd);
578 dedata->attributes.mode = 0x3; /* ECKD */
580 if ((basepriv->rdc_data.cu_type == 0x2105 ||
581 basepriv->rdc_data.cu_type == 0x2107 ||
582 basepriv->rdc_data.cu_type == 0x1750)
583 && !(basepriv->uses_cdl && trk < 2))
584 dedata->ga_extended |= 0x40; /* Regular Data Format Mode */
586 heads = basepriv->rdc_data.trk_per_cyl;
587 begcyl = trk / heads;
588 beghead = trk % heads;
589 endcyl = totrk / heads;
590 endhead = totrk % heads;
592 /* check for sequential prestage - enhance cylinder range */
593 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
594 dedata->attributes.operation == DASD_SEQ_ACCESS) {
596 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
597 endcyl += basepriv->attrib.nr_cyl;
599 endcyl = (basepriv->real_cyl - 1);
602 set_ch_t(&dedata->beg_ext, begcyl, beghead);
603 set_ch_t(&dedata->end_ext, endcyl, endhead);
606 fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
607 basedev, blksize, tlf);
613 static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
614 unsigned int trk, unsigned int totrk, int cmd,
615 struct dasd_device *basedev, struct dasd_device *startdev)
617 return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
622 locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
623 unsigned int rec_on_trk, int no_rec, int cmd,
624 struct dasd_device * device, int reclen)
626 struct dasd_eckd_private *private;
630 private = (struct dasd_eckd_private *) device->private;
632 DBF_DEV_EVENT(DBF_INFO, device,
633 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
634 trk, rec_on_trk, no_rec, cmd, reclen);
636 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
639 ccw->cda = (__u32) __pa(data);
641 memset(data, 0, sizeof(struct LO_eckd_data));
644 switch (private->rdc_data.dev_type) {
646 dn = ceil_quot(reclen + 6, 232);
647 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
648 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
651 d = 7 + ceil_quot(reclen + 12, 32);
652 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
656 data->sector = sector;
657 data->count = no_rec;
659 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
660 data->operation.orientation = 0x3;
661 data->operation.operation = 0x03;
663 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
664 data->operation.orientation = 0x3;
665 data->operation.operation = 0x16;
667 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
668 data->operation.orientation = 0x1;
669 data->operation.operation = 0x03;
672 case DASD_ECKD_CCW_READ_RECORD_ZERO:
673 data->operation.orientation = 0x3;
674 data->operation.operation = 0x16;
677 case DASD_ECKD_CCW_WRITE:
678 case DASD_ECKD_CCW_WRITE_MT:
679 case DASD_ECKD_CCW_WRITE_KD:
680 case DASD_ECKD_CCW_WRITE_KD_MT:
681 data->auxiliary.last_bytes_used = 0x1;
682 data->length = reclen;
683 data->operation.operation = 0x01;
685 case DASD_ECKD_CCW_WRITE_CKD:
686 case DASD_ECKD_CCW_WRITE_CKD_MT:
687 data->auxiliary.last_bytes_used = 0x1;
688 data->length = reclen;
689 data->operation.operation = 0x03;
691 case DASD_ECKD_CCW_READ:
692 case DASD_ECKD_CCW_READ_MT:
693 case DASD_ECKD_CCW_READ_KD:
694 case DASD_ECKD_CCW_READ_KD_MT:
695 data->auxiliary.last_bytes_used = 0x1;
696 data->length = reclen;
697 data->operation.operation = 0x06;
699 case DASD_ECKD_CCW_READ_CKD:
700 case DASD_ECKD_CCW_READ_CKD_MT:
701 data->auxiliary.last_bytes_used = 0x1;
702 data->length = reclen;
703 data->operation.operation = 0x16;
705 case DASD_ECKD_CCW_READ_COUNT:
706 data->operation.operation = 0x06;
708 case DASD_ECKD_CCW_ERASE:
709 data->length = reclen;
710 data->auxiliary.last_bytes_used = 0x1;
711 data->operation.operation = 0x0b;
714 DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
717 set_ch_t(&data->seek_addr,
718 trk / private->rdc_data.trk_per_cyl,
719 trk % private->rdc_data.trk_per_cyl);
720 data->search_arg.cyl = data->seek_addr.cyl;
721 data->search_arg.head = data->seek_addr.head;
722 data->search_arg.record = rec_on_trk;
726 * Returns 1 if the block is one of the special blocks that needs
727 * to get read/written with the KD variant of the command.
728 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
729 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
730 * Luckily the KD variants differ only by one bit (0x08) from the
731 * normal variant. So don't wonder about code like:
732 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
733 * ccw->cmd_code |= 0x8;
736 dasd_eckd_cdl_special(int blk_per_trk, int recid)
740 if (recid < blk_per_trk)
742 if (recid < 2 * blk_per_trk)
748 * Returns the record size for the special blocks of the cdl format.
749 * Only returns something useful if dasd_eckd_cdl_special is true
753 dasd_eckd_cdl_reclen(int recid)
756 return sizes_trk0[recid];
759 /* create unique id from private structure. */
760 static void create_uid(struct dasd_eckd_private *private)
763 struct dasd_uid *uid;
766 memset(uid, 0, sizeof(struct dasd_uid));
767 memcpy(uid->vendor, private->ned->HDA_manufacturer,
768 sizeof(uid->vendor) - 1);
769 EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
770 memcpy(uid->serial, private->ned->HDA_location,
771 sizeof(uid->serial) - 1);
772 EBCASC(uid->serial, sizeof(uid->serial) - 1);
773 uid->ssid = private->gneq->subsystemID;
774 uid->real_unit_addr = private->ned->unit_addr;
776 uid->type = private->sneq->sua_flags;
777 if (uid->type == UA_BASE_PAV_ALIAS)
778 uid->base_unit_addr = private->sneq->base_unit_addr;
780 uid->type = UA_BASE_DEVICE;
782 if (private->vdsneq) {
783 for (count = 0; count < 16; count++) {
784 sprintf(uid->vduit+2*count, "%02x",
785 private->vdsneq->uit[count]);
791 * Generate device unique id that specifies the physical device.
793 static int dasd_eckd_generate_uid(struct dasd_device *device)
795 struct dasd_eckd_private *private;
798 private = (struct dasd_eckd_private *) device->private;
801 if (!private->ned || !private->gneq)
803 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
805 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
809 static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
811 struct dasd_eckd_private *private;
814 if (device->private) {
815 private = (struct dasd_eckd_private *)device->private;
816 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
818 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
825 * compare device UID with data of a given dasd_eckd_private structure
828 static int dasd_eckd_compare_path_uid(struct dasd_device *device,
829 struct dasd_eckd_private *private)
831 struct dasd_uid device_uid;
834 dasd_eckd_get_uid(device, &device_uid);
836 return memcmp(&device_uid, &private->uid, sizeof(struct dasd_uid));
839 static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device,
840 struct dasd_ccw_req *cqr,
846 * buffer has to start with EBCDIC "V1.0" to show
847 * support for virtual device SNEQ
849 rcd_buffer[0] = 0xE5;
850 rcd_buffer[1] = 0xF1;
851 rcd_buffer[2] = 0x4B;
852 rcd_buffer[3] = 0xF0;
855 ccw->cmd_code = DASD_ECKD_CCW_RCD;
857 ccw->cda = (__u32)(addr_t)rcd_buffer;
858 ccw->count = DASD_ECKD_RCD_DATA_SIZE;
859 cqr->magic = DASD_ECKD_MAGIC;
861 cqr->startdev = device;
862 cqr->memdev = device;
864 cqr->expires = 10*HZ;
867 cqr->buildclk = get_tod_clock();
868 cqr->status = DASD_CQR_FILLED;
869 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
873 * Wakeup helper for read_conf
874 * if the cqr is not done and needs some error recovery
875 * the buffer has to be re-initialized with the EBCDIC "V1.0"
876 * to show support for virtual device SNEQ
878 static void read_conf_cb(struct dasd_ccw_req *cqr, void *data)
883 if (cqr->status != DASD_CQR_DONE) {
885 rcd_buffer = (__u8 *)((addr_t) ccw->cda);
886 memset(rcd_buffer, 0, sizeof(*rcd_buffer));
888 rcd_buffer[0] = 0xE5;
889 rcd_buffer[1] = 0xF1;
890 rcd_buffer[2] = 0x4B;
891 rcd_buffer[3] = 0xF0;
893 dasd_wakeup_cb(cqr, data);
896 static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
897 struct dasd_ccw_req *cqr,
904 * sanity check: scan for RCD command in extended SenseID data
905 * some devices do not support RCD
907 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
908 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD)
911 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm);
912 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
913 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
915 cqr->callback = read_conf_cb;
916 rc = dasd_sleep_on_immediatly(cqr);
920 static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
922 int *rcd_buffer_size, __u8 lpm)
925 char *rcd_buf = NULL;
927 struct dasd_ccw_req *cqr;
930 * sanity check: scan for RCD command in extended SenseID data
931 * some devices do not support RCD
933 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
934 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) {
938 rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA);
943 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */,
944 0, /* use rcd_buf as data ara */
947 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
948 "Could not allocate RCD request");
952 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm);
953 cqr->callback = read_conf_cb;
954 ret = dasd_sleep_on(cqr);
956 * on success we update the user input parms
958 dasd_sfree_request(cqr, cqr->memdev);
962 *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE;
963 *rcd_buffer = rcd_buf;
968 *rcd_buffer_size = 0;
972 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
975 struct dasd_sneq *sneq;
979 private->sneq = NULL;
980 private->vdsneq = NULL;
981 private->gneq = NULL;
982 count = private->conf_len / sizeof(struct dasd_sneq);
983 sneq = (struct dasd_sneq *)private->conf_data;
984 for (i = 0; i < count; ++i) {
985 if (sneq->flags.identifier == 1 && sneq->format == 1)
986 private->sneq = sneq;
987 else if (sneq->flags.identifier == 1 && sneq->format == 4)
988 private->vdsneq = (struct vd_sneq *)sneq;
989 else if (sneq->flags.identifier == 2)
990 private->gneq = (struct dasd_gneq *)sneq;
991 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
992 private->ned = (struct dasd_ned *)sneq;
995 if (!private->ned || !private->gneq) {
997 private->sneq = NULL;
998 private->vdsneq = NULL;
999 private->gneq = NULL;
1006 static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
1008 struct dasd_gneq *gneq;
1009 int i, count, found;
1011 count = conf_len / sizeof(*gneq);
1012 gneq = (struct dasd_gneq *)conf_data;
1014 for (i = 0; i < count; ++i) {
1015 if (gneq->flags.identifier == 2) {
1022 return ((char *)gneq)[18] & 0x07;
1027 static int dasd_eckd_read_conf(struct dasd_device *device)
1030 int conf_len, conf_data_saved;
1033 struct dasd_eckd_private *private, path_private;
1034 struct dasd_path *path_data;
1035 struct dasd_uid *uid;
1036 char print_path_uid[60], print_device_uid[60];
1038 private = (struct dasd_eckd_private *) device->private;
1039 path_data = &device->path_data;
1040 opm = ccw_device_get_path_mask(device->cdev);
1041 conf_data_saved = 0;
1043 /* get configuration data per operational path */
1044 for (lpm = 0x80; lpm; lpm>>= 1) {
1047 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
1049 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
1050 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1051 "Read configuration data returned "
1055 if (conf_data == NULL) {
1056 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1057 "No configuration data "
1059 /* no further analysis possible */
1060 path_data->opm |= lpm;
1061 continue; /* no error */
1063 /* save first valid configuration data */
1064 if (!conf_data_saved) {
1065 kfree(private->conf_data);
1066 private->conf_data = conf_data;
1067 private->conf_len = conf_len;
1068 if (dasd_eckd_identify_conf_parts(private)) {
1069 private->conf_data = NULL;
1070 private->conf_len = 0;
1075 * build device UID that other path data
1076 * can be compared to it
1078 dasd_eckd_generate_uid(device);
1081 path_private.conf_data = conf_data;
1082 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1083 if (dasd_eckd_identify_conf_parts(
1085 path_private.conf_data = NULL;
1086 path_private.conf_len = 0;
1091 if (dasd_eckd_compare_path_uid(
1092 device, &path_private)) {
1093 uid = &path_private.uid;
1094 if (strlen(uid->vduit) > 0)
1095 snprintf(print_path_uid,
1096 sizeof(print_path_uid),
1097 "%s.%s.%04x.%02x.%s",
1098 uid->vendor, uid->serial,
1099 uid->ssid, uid->real_unit_addr,
1102 snprintf(print_path_uid,
1103 sizeof(print_path_uid),
1105 uid->vendor, uid->serial,
1107 uid->real_unit_addr);
1108 uid = &private->uid;
1109 if (strlen(uid->vduit) > 0)
1110 snprintf(print_device_uid,
1111 sizeof(print_device_uid),
1112 "%s.%s.%04x.%02x.%s",
1113 uid->vendor, uid->serial,
1114 uid->ssid, uid->real_unit_addr,
1117 snprintf(print_device_uid,
1118 sizeof(print_device_uid),
1120 uid->vendor, uid->serial,
1122 uid->real_unit_addr);
1123 dev_err(&device->cdev->dev,
1124 "Not all channel paths lead to "
1125 "the same device, path %02X leads to "
1126 "device %s instead of %s\n", lpm,
1127 print_path_uid, print_device_uid);
1132 path_private.conf_data = NULL;
1133 path_private.conf_len = 0;
1135 switch (dasd_eckd_path_access(conf_data, conf_len)) {
1137 path_data->npm |= lpm;
1140 path_data->ppm |= lpm;
1143 path_data->opm |= lpm;
1145 if (conf_data != private->conf_data)
1152 static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
1154 struct dasd_eckd_private *private;
1158 private = (struct dasd_eckd_private *) device->private;
1159 if (private->fcx_max_data) {
1160 mdc = ccw_device_get_mdc(device->cdev, lpm);
1162 dev_warn(&device->cdev->dev,
1163 "Detecting the maximum data size for zHPF "
1164 "requests failed (rc=%d) for a new path %x\n",
1168 fcx_max_data = mdc * FCX_MAX_DATA_FACTOR;
1169 if (fcx_max_data < private->fcx_max_data) {
1170 dev_warn(&device->cdev->dev,
1171 "The maximum data size for zHPF requests %u "
1172 "on a new path %x is below the active maximum "
1173 "%u\n", fcx_max_data, lpm,
1174 private->fcx_max_data);
1181 static int rebuild_device_uid(struct dasd_device *device,
1182 struct path_verification_work_data *data)
1184 struct dasd_eckd_private *private;
1185 struct dasd_path *path_data;
1190 private = (struct dasd_eckd_private *) device->private;
1191 path_data = &device->path_data;
1192 opm = device->path_data.opm;
1194 for (lpm = 0x80; lpm; lpm >>= 1) {
1197 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1198 memset(&data->cqr, 0, sizeof(data->cqr));
1199 data->cqr.cpaddr = &data->ccw;
1200 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1205 if (rc == -EOPNOTSUPP) /* -EOPNOTSUPP is ok */
1207 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1208 "Read configuration data "
1209 "returned error %d", rc);
1212 memcpy(private->conf_data, data->rcd_buffer,
1213 DASD_ECKD_RCD_DATA_SIZE);
1214 if (dasd_eckd_identify_conf_parts(private)) {
1216 } else /* first valid path is enough */
1221 rc = dasd_eckd_generate_uid(device);
1226 static void do_path_verification_work(struct work_struct *work)
1228 struct path_verification_work_data *data;
1229 struct dasd_device *device;
1230 struct dasd_eckd_private path_private;
1231 struct dasd_uid *uid;
1232 __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE];
1233 __u8 lpm, opm, npm, ppm, epm;
1234 unsigned long flags;
1238 data = container_of(work, struct path_verification_work_data, worker);
1239 device = data->device;
1241 /* delay path verification until device was resumed */
1242 if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
1243 schedule_work(work);
1251 for (lpm = 0x80; lpm; lpm >>= 1) {
1252 if (!(lpm & data->tbvpm))
1254 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1255 memset(&data->cqr, 0, sizeof(data->cqr));
1256 data->cqr.cpaddr = &data->ccw;
1257 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1261 switch (dasd_eckd_path_access(data->rcd_buffer,
1262 DASD_ECKD_RCD_DATA_SIZE)
1272 } else if (rc == -EOPNOTSUPP) {
1273 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1274 "path verification: No configuration "
1277 } else if (rc == -EAGAIN) {
1278 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1279 "path verification: device is stopped,"
1280 " try again later");
1283 dev_warn(&device->cdev->dev,
1284 "Reading device feature codes failed "
1285 "(rc=%d) for new path %x\n", rc, lpm);
1288 if (verify_fcx_max_data(device, lpm)) {
1296 * save conf_data for comparison after
1297 * rebuild_device_uid may have changed
1300 memcpy(&path_rcd_buf, data->rcd_buffer,
1301 DASD_ECKD_RCD_DATA_SIZE);
1302 path_private.conf_data = (void *) &path_rcd_buf;
1303 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1304 if (dasd_eckd_identify_conf_parts(&path_private)) {
1305 path_private.conf_data = NULL;
1306 path_private.conf_len = 0;
1311 * compare path UID with device UID only if at least
1312 * one valid path is left
1313 * in other case the device UID may have changed and
1314 * the first working path UID will be used as device UID
1316 if (device->path_data.opm &&
1317 dasd_eckd_compare_path_uid(device, &path_private)) {
1319 * the comparison was not successful
1320 * rebuild the device UID with at least one
1321 * known path in case a z/VM hyperswap command
1322 * has changed the device
1324 * after this compare again
1326 * if either the rebuild or the recompare fails
1327 * the path can not be used
1329 if (rebuild_device_uid(device, data) ||
1330 dasd_eckd_compare_path_uid(
1331 device, &path_private)) {
1332 uid = &path_private.uid;
1333 if (strlen(uid->vduit) > 0)
1334 snprintf(print_uid, sizeof(print_uid),
1335 "%s.%s.%04x.%02x.%s",
1336 uid->vendor, uid->serial,
1337 uid->ssid, uid->real_unit_addr,
1340 snprintf(print_uid, sizeof(print_uid),
1342 uid->vendor, uid->serial,
1344 uid->real_unit_addr);
1345 dev_err(&device->cdev->dev,
1346 "The newly added channel path %02X "
1347 "will not be used because it leads "
1348 "to a different device %s\n",
1358 * There is a small chance that a path is lost again between
1359 * above path verification and the following modification of
1360 * the device opm mask. We could avoid that race here by using
1361 * yet another path mask, but we rather deal with this unlikely
1362 * situation in dasd_start_IO.
1364 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1365 if (!device->path_data.opm && opm) {
1366 device->path_data.opm = opm;
1367 dasd_generic_path_operational(device);
1369 device->path_data.opm |= opm;
1370 device->path_data.npm |= npm;
1371 device->path_data.ppm |= ppm;
1372 device->path_data.tbvpm |= epm;
1373 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1376 dasd_put_device(device);
1378 mutex_unlock(&dasd_path_verification_mutex);
1383 static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm)
1385 struct path_verification_work_data *data;
1387 data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA);
1389 if (mutex_trylock(&dasd_path_verification_mutex)) {
1390 data = path_verification_worker;
1395 memset(data, 0, sizeof(*data));
1398 INIT_WORK(&data->worker, do_path_verification_work);
1399 dasd_get_device(device);
1400 data->device = device;
1402 schedule_work(&data->worker);
1406 static int dasd_eckd_read_features(struct dasd_device *device)
1408 struct dasd_psf_prssd_data *prssdp;
1409 struct dasd_rssd_features *features;
1410 struct dasd_ccw_req *cqr;
1413 struct dasd_eckd_private *private;
1415 private = (struct dasd_eckd_private *) device->private;
1416 memset(&private->features, 0, sizeof(struct dasd_rssd_features));
1417 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
1418 (sizeof(struct dasd_psf_prssd_data) +
1419 sizeof(struct dasd_rssd_features)),
1422 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not "
1423 "allocate initialization request");
1424 return PTR_ERR(cqr);
1426 cqr->startdev = device;
1427 cqr->memdev = device;
1430 cqr->expires = 10 * HZ;
1432 /* Prepare for Read Subsystem Data */
1433 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1434 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
1435 prssdp->order = PSF_ORDER_PRSSD;
1436 prssdp->suborder = 0x41; /* Read Feature Codes */
1437 /* all other bytes of prssdp must be zero */
1440 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1441 ccw->count = sizeof(struct dasd_psf_prssd_data);
1442 ccw->flags |= CCW_FLAG_CC;
1443 ccw->cda = (__u32)(addr_t) prssdp;
1445 /* Read Subsystem Data - feature codes */
1446 features = (struct dasd_rssd_features *) (prssdp + 1);
1447 memset(features, 0, sizeof(struct dasd_rssd_features));
1450 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
1451 ccw->count = sizeof(struct dasd_rssd_features);
1452 ccw->cda = (__u32)(addr_t) features;
1454 cqr->buildclk = get_tod_clock();
1455 cqr->status = DASD_CQR_FILLED;
1456 rc = dasd_sleep_on(cqr);
1458 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1459 features = (struct dasd_rssd_features *) (prssdp + 1);
1460 memcpy(&private->features, features,
1461 sizeof(struct dasd_rssd_features));
1463 dev_warn(&device->cdev->dev, "Reading device feature codes"
1464 " failed with rc=%d\n", rc);
1465 dasd_sfree_request(cqr, cqr->memdev);
1471 * Build CP for Perform Subsystem Function - SSC.
1473 static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
1476 struct dasd_ccw_req *cqr;
1477 struct dasd_psf_ssc_data *psf_ssc_data;
1480 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
1481 sizeof(struct dasd_psf_ssc_data),
1485 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1486 "Could not allocate PSF-SSC request");
1489 psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1490 psf_ssc_data->order = PSF_ORDER_SSC;
1491 psf_ssc_data->suborder = 0xc0;
1493 psf_ssc_data->suborder |= 0x08;
1494 psf_ssc_data->reserved[0] = 0x88;
1497 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1498 ccw->cda = (__u32)(addr_t)psf_ssc_data;
1501 cqr->startdev = device;
1502 cqr->memdev = device;
1505 cqr->expires = 10*HZ;
1506 cqr->buildclk = get_tod_clock();
1507 cqr->status = DASD_CQR_FILLED;
1512 * Perform Subsystem Function.
1513 * It is necessary to trigger CIO for channel revalidation since this
1514 * call might change behaviour of DASD devices.
1517 dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav,
1518 unsigned long flags)
1520 struct dasd_ccw_req *cqr;
1523 cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
1525 return PTR_ERR(cqr);
1528 * set flags e.g. turn on failfast, to prevent blocking
1529 * the calling function should handle failed requests
1531 cqr->flags |= flags;
1533 rc = dasd_sleep_on(cqr);
1535 /* trigger CIO to reprobe devices */
1536 css_schedule_reprobe();
1537 else if (cqr->intrc == -EAGAIN)
1540 dasd_sfree_request(cqr, cqr->memdev);
1545 * Valide storage server of current device.
1547 static int dasd_eckd_validate_server(struct dasd_device *device,
1548 unsigned long flags)
1551 struct dasd_eckd_private *private;
1554 private = (struct dasd_eckd_private *) device->private;
1555 if (private->uid.type == UA_BASE_PAV_ALIAS ||
1556 private->uid.type == UA_HYPER_PAV_ALIAS)
1558 if (dasd_nopav || MACHINE_IS_VM)
1562 rc = dasd_eckd_psf_ssc(device, enable_pav, flags);
1564 /* may be requested feature is not available on server,
1565 * therefore just report error and go ahead */
1566 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
1567 "returned rc=%d", private->uid.ssid, rc);
1572 * worker to do a validate server in case of a lost pathgroup
1574 static void dasd_eckd_do_validate_server(struct work_struct *work)
1576 struct dasd_device *device = container_of(work, struct dasd_device,
1578 unsigned long flags = 0;
1580 set_bit(DASD_CQR_FLAGS_FAILFAST, &flags);
1581 if (dasd_eckd_validate_server(device, flags)
1583 /* schedule worker again if failed */
1584 schedule_work(&device->kick_validate);
1588 dasd_put_device(device);
1591 static void dasd_eckd_kick_validate_server(struct dasd_device *device)
1593 dasd_get_device(device);
1594 /* exit if device not online or in offline processing */
1595 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1596 device->state < DASD_STATE_ONLINE) {
1597 dasd_put_device(device);
1600 /* queue call to do_validate_server to the kernel event daemon. */
1601 schedule_work(&device->kick_validate);
1604 static u32 get_fcx_max_data(struct dasd_device *device)
1606 #if defined(CONFIG_64BIT)
1608 int fcx_in_css, fcx_in_gneq, fcx_in_features;
1609 struct dasd_eckd_private *private;
1613 /* is transport mode supported? */
1614 private = (struct dasd_eckd_private *) device->private;
1615 fcx_in_css = css_general_characteristics.fcx;
1616 fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
1617 fcx_in_features = private->features.feature[40] & 0x80;
1618 tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
1623 mdc = ccw_device_get_mdc(device->cdev, 0);
1625 dev_warn(&device->cdev->dev, "Detecting the maximum supported"
1626 " data size for zHPF requests failed\n");
1629 return mdc * FCX_MAX_DATA_FACTOR;
1636 * Check device characteristics.
1637 * If the device is accessible using ECKD discipline, the device is enabled.
1640 dasd_eckd_check_characteristics(struct dasd_device *device)
1642 struct dasd_eckd_private *private;
1643 struct dasd_block *block;
1644 struct dasd_uid temp_uid;
1647 unsigned long value;
1649 /* setup work queue for validate server*/
1650 INIT_WORK(&device->kick_validate, dasd_eckd_do_validate_server);
1652 if (!ccw_device_is_pathgroup(device->cdev)) {
1653 dev_warn(&device->cdev->dev,
1654 "A channel path group could not be established\n");
1657 if (!ccw_device_is_multipath(device->cdev)) {
1658 dev_info(&device->cdev->dev,
1659 "The DASD is not operating in multipath mode\n");
1661 private = (struct dasd_eckd_private *) device->private;
1663 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
1665 dev_warn(&device->cdev->dev,
1666 "Allocating memory for private DASD data "
1670 device->private = (void *) private;
1672 memset(private, 0, sizeof(*private));
1674 /* Invalidate status of initial analysis. */
1675 private->init_cqr_status = -1;
1676 /* Set default cache operations. */
1677 private->attrib.operation = DASD_NORMAL_CACHE;
1678 private->attrib.nr_cyl = 0;
1680 /* Read Configuration Data */
1681 rc = dasd_eckd_read_conf(device);
1685 /* set default timeout */
1686 device->default_expires = DASD_EXPIRES;
1687 /* set default retry count */
1688 device->default_retries = DASD_RETRIES;
1690 if (private->gneq) {
1692 for (i = 0; i < private->gneq->timeout.value; i++)
1694 value = value * private->gneq->timeout.number;
1695 /* do not accept useless values */
1696 if (value != 0 && value <= DASD_EXPIRES_MAX)
1697 device->default_expires = value;
1700 dasd_eckd_get_uid(device, &temp_uid);
1701 if (temp_uid.type == UA_BASE_DEVICE) {
1702 block = dasd_alloc_block();
1703 if (IS_ERR(block)) {
1704 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1705 "could not allocate dasd "
1707 rc = PTR_ERR(block);
1710 device->block = block;
1711 block->base = device;
1714 /* register lcu with alias handling, enable PAV */
1715 rc = dasd_alias_make_device_known_to_lcu(device);
1719 dasd_eckd_validate_server(device, 0);
1721 /* device may report different configuration data after LCU setup */
1722 rc = dasd_eckd_read_conf(device);
1726 /* Read Feature Codes */
1727 dasd_eckd_read_features(device);
1729 /* Read Device Characteristics */
1730 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
1731 &private->rdc_data, 64);
1733 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1734 "Read device characteristic failed, rc=%d", rc);
1738 if ((device->features & DASD_FEATURE_USERAW) &&
1739 !(private->rdc_data.facilities.RT_in_LR)) {
1740 dev_err(&device->cdev->dev, "The storage server does not "
1741 "support raw-track access\n");
1746 /* find the valid cylinder size */
1747 if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1748 private->rdc_data.long_no_cyl)
1749 private->real_cyl = private->rdc_data.long_no_cyl;
1751 private->real_cyl = private->rdc_data.no_cyl;
1753 private->fcx_max_data = get_fcx_max_data(device);
1755 readonly = dasd_device_is_ro(device);
1757 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1759 dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
1760 "with %d cylinders, %d heads, %d sectors%s\n",
1761 private->rdc_data.dev_type,
1762 private->rdc_data.dev_model,
1763 private->rdc_data.cu_type,
1764 private->rdc_data.cu_model.model,
1766 private->rdc_data.trk_per_cyl,
1767 private->rdc_data.sec_per_trk,
1768 readonly ? ", read-only device" : "");
1772 dasd_alias_disconnect_device_from_lcu(device);
1774 dasd_free_block(device->block);
1775 device->block = NULL;
1777 kfree(private->conf_data);
1778 kfree(device->private);
1779 device->private = NULL;
1783 static void dasd_eckd_uncheck_device(struct dasd_device *device)
1785 struct dasd_eckd_private *private;
1787 private = (struct dasd_eckd_private *) device->private;
1788 dasd_alias_disconnect_device_from_lcu(device);
1789 private->ned = NULL;
1790 private->sneq = NULL;
1791 private->vdsneq = NULL;
1792 private->gneq = NULL;
1793 private->conf_len = 0;
1794 kfree(private->conf_data);
1795 private->conf_data = NULL;
1798 static struct dasd_ccw_req *
1799 dasd_eckd_analysis_ccw(struct dasd_device *device)
1801 struct dasd_eckd_private *private;
1802 struct eckd_count *count_data;
1803 struct LO_eckd_data *LO_data;
1804 struct dasd_ccw_req *cqr;
1806 int cplength, datasize;
1809 private = (struct dasd_eckd_private *) device->private;
1812 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
1813 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1817 /* Define extent for the first 3 tracks. */
1818 define_extent(ccw++, cqr->data, 0, 2,
1819 DASD_ECKD_CCW_READ_COUNT, device);
1820 LO_data = cqr->data + sizeof(struct DE_eckd_data);
1821 /* Locate record for the first 4 records on track 0. */
1822 ccw[-1].flags |= CCW_FLAG_CC;
1823 locate_record(ccw++, LO_data++, 0, 0, 4,
1824 DASD_ECKD_CCW_READ_COUNT, device, 0);
1826 count_data = private->count_area;
1827 for (i = 0; i < 4; i++) {
1828 ccw[-1].flags |= CCW_FLAG_CC;
1829 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1832 ccw->cda = (__u32)(addr_t) count_data;
1837 /* Locate record for the first record on track 2. */
1838 ccw[-1].flags |= CCW_FLAG_CC;
1839 locate_record(ccw++, LO_data++, 2, 0, 1,
1840 DASD_ECKD_CCW_READ_COUNT, device, 0);
1841 /* Read count ccw. */
1842 ccw[-1].flags |= CCW_FLAG_CC;
1843 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1846 ccw->cda = (__u32)(addr_t) count_data;
1849 cqr->startdev = device;
1850 cqr->memdev = device;
1852 cqr->buildclk = get_tod_clock();
1853 cqr->status = DASD_CQR_FILLED;
1857 /* differentiate between 'no record found' and any other error */
1858 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
1861 if (init_cqr->status == DASD_CQR_DONE)
1863 else if (init_cqr->status == DASD_CQR_NEED_ERP ||
1864 init_cqr->status == DASD_CQR_FAILED) {
1865 sense = dasd_get_sense(&init_cqr->irb);
1866 if (sense && (sense[1] & SNS1_NO_REC_FOUND))
1867 return INIT_CQR_UNFORMATTED;
1869 return INIT_CQR_ERROR;
1871 return INIT_CQR_ERROR;
1875 * This is the callback function for the init_analysis cqr. It saves
1876 * the status of the initial analysis ccw before it frees it and kicks
1877 * the device to continue the startup sequence. This will call
1878 * dasd_eckd_do_analysis again (if the devices has not been marked
1879 * for deletion in the meantime).
1881 static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
1884 struct dasd_eckd_private *private;
1885 struct dasd_device *device;
1887 device = init_cqr->startdev;
1888 private = (struct dasd_eckd_private *) device->private;
1889 private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
1890 dasd_sfree_request(init_cqr, device);
1891 dasd_kick_device(device);
1894 static int dasd_eckd_start_analysis(struct dasd_block *block)
1896 struct dasd_ccw_req *init_cqr;
1898 init_cqr = dasd_eckd_analysis_ccw(block->base);
1899 if (IS_ERR(init_cqr))
1900 return PTR_ERR(init_cqr);
1901 init_cqr->callback = dasd_eckd_analysis_callback;
1902 init_cqr->callback_data = NULL;
1903 init_cqr->expires = 5*HZ;
1904 /* first try without ERP, so we can later handle unformatted
1905 * devices as special case
1907 clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
1908 init_cqr->retries = 0;
1909 dasd_add_request_head(init_cqr);
1913 static int dasd_eckd_end_analysis(struct dasd_block *block)
1915 struct dasd_device *device;
1916 struct dasd_eckd_private *private;
1917 struct eckd_count *count_area;
1918 unsigned int sb, blk_per_trk;
1920 struct dasd_ccw_req *init_cqr;
1922 device = block->base;
1923 private = (struct dasd_eckd_private *) device->private;
1924 status = private->init_cqr_status;
1925 private->init_cqr_status = -1;
1926 if (status == INIT_CQR_ERROR) {
1927 /* try again, this time with full ERP */
1928 init_cqr = dasd_eckd_analysis_ccw(device);
1929 dasd_sleep_on(init_cqr);
1930 status = dasd_eckd_analysis_evaluation(init_cqr);
1931 dasd_sfree_request(init_cqr, device);
1934 if (device->features & DASD_FEATURE_USERAW) {
1935 block->bp_block = DASD_RAW_BLOCKSIZE;
1936 blk_per_trk = DASD_RAW_BLOCK_PER_TRACK;
1937 block->s2b_shift = 3;
1941 if (status == INIT_CQR_UNFORMATTED) {
1942 dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
1943 return -EMEDIUMTYPE;
1944 } else if (status == INIT_CQR_ERROR) {
1945 dev_err(&device->cdev->dev,
1946 "Detecting the DASD disk layout failed because "
1947 "of an I/O error\n");
1951 private->uses_cdl = 1;
1952 /* Check Track 0 for Compatible Disk Layout */
1954 for (i = 0; i < 3; i++) {
1955 if (private->count_area[i].kl != 4 ||
1956 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4 ||
1957 private->count_area[i].cyl != 0 ||
1958 private->count_area[i].head != count_area_head[i] ||
1959 private->count_area[i].record != count_area_rec[i]) {
1960 private->uses_cdl = 0;
1965 count_area = &private->count_area[4];
1967 if (private->uses_cdl == 0) {
1968 for (i = 0; i < 5; i++) {
1969 if ((private->count_area[i].kl != 0) ||
1970 (private->count_area[i].dl !=
1971 private->count_area[0].dl) ||
1972 private->count_area[i].cyl != 0 ||
1973 private->count_area[i].head != count_area_head[i] ||
1974 private->count_area[i].record != count_area_rec[i])
1978 count_area = &private->count_area[0];
1980 if (private->count_area[3].record == 1)
1981 dev_warn(&device->cdev->dev,
1982 "Track 0 has no records following the VTOC\n");
1985 if (count_area != NULL && count_area->kl == 0) {
1986 /* we found notthing violating our disk layout */
1987 if (dasd_check_blocksize(count_area->dl) == 0)
1988 block->bp_block = count_area->dl;
1990 if (block->bp_block == 0) {
1991 dev_warn(&device->cdev->dev,
1992 "The disk layout of the DASD is not supported\n");
1993 return -EMEDIUMTYPE;
1995 block->s2b_shift = 0; /* bits to shift 512 to get a block */
1996 for (sb = 512; sb < block->bp_block; sb = sb << 1)
1999 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
2002 block->blocks = (private->real_cyl *
2003 private->rdc_data.trk_per_cyl *
2006 dev_info(&device->cdev->dev,
2007 "DASD with %d KB/block, %d KB total size, %d KB/track, "
2008 "%s\n", (block->bp_block >> 10),
2009 ((private->real_cyl *
2010 private->rdc_data.trk_per_cyl *
2011 blk_per_trk * (block->bp_block >> 9)) >> 1),
2012 ((blk_per_trk * block->bp_block) >> 10),
2014 "compatible disk layout" : "linux disk layout");
2019 static int dasd_eckd_do_analysis(struct dasd_block *block)
2021 struct dasd_eckd_private *private;
2023 private = (struct dasd_eckd_private *) block->base->private;
2024 if (private->init_cqr_status < 0)
2025 return dasd_eckd_start_analysis(block);
2027 return dasd_eckd_end_analysis(block);
2030 static int dasd_eckd_basic_to_ready(struct dasd_device *device)
2032 return dasd_alias_add_device(device);
2035 static int dasd_eckd_online_to_ready(struct dasd_device *device)
2037 cancel_work_sync(&device->reload_device);
2038 cancel_work_sync(&device->kick_validate);
2042 static int dasd_eckd_basic_to_known(struct dasd_device *device)
2044 return dasd_alias_remove_device(device);
2048 dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
2050 struct dasd_eckd_private *private;
2052 private = (struct dasd_eckd_private *) block->base->private;
2053 if (dasd_check_blocksize(block->bp_block) == 0) {
2054 geo->sectors = recs_per_track(&private->rdc_data,
2055 0, block->bp_block);
2057 geo->cylinders = private->rdc_data.no_cyl;
2058 geo->heads = private->rdc_data.trk_per_cyl;
2062 static struct dasd_ccw_req *
2063 dasd_eckd_build_format(struct dasd_device *base,
2064 struct format_data_t *fdata,
2067 struct dasd_eckd_private *base_priv;
2068 struct dasd_eckd_private *start_priv;
2069 struct dasd_device *startdev = NULL;
2070 struct dasd_ccw_req *fcp;
2071 struct eckd_count *ect;
2072 struct ch_t address;
2076 int cplength, datasize;
2084 startdev = dasd_alias_get_start_dev(base);
2089 start_priv = (struct dasd_eckd_private *) startdev->private;
2090 base_priv = (struct dasd_eckd_private *) base->private;
2092 rpt = recs_per_track(&base_priv->rdc_data, 0, fdata->blksize);
2094 nr_tracks = fdata->stop_unit - fdata->start_unit + 1;
2097 * fdata->intensity is a bit string that tells us what to do:
2098 * Bit 0: write record zero
2099 * Bit 1: write home address, currently not supported
2100 * Bit 2: invalidate tracks
2101 * Bit 3: use OS/390 compatible disk layout (cdl)
2102 * Bit 4: do not allow storage subsystem to modify record zero
2103 * Only some bit combinations do make sense.
2105 if (fdata->intensity & 0x10) {
2107 intensity = fdata->intensity & ~0x10;
2110 intensity = fdata->intensity;
2113 use_prefix = base_priv->features.feature[8] & 0x01;
2115 switch (intensity) {
2116 case 0x00: /* Normal format */
2117 case 0x08: /* Normal format, use cdl. */
2118 cplength = 2 + (rpt*nr_tracks);
2120 datasize = sizeof(struct PFX_eckd_data) +
2121 sizeof(struct LO_eckd_data) +
2122 rpt * nr_tracks * sizeof(struct eckd_count);
2124 datasize = sizeof(struct DE_eckd_data) +
2125 sizeof(struct LO_eckd_data) +
2126 rpt * nr_tracks * sizeof(struct eckd_count);
2128 case 0x01: /* Write record zero and format track. */
2129 case 0x09: /* Write record zero and format track, use cdl. */
2130 cplength = 2 + rpt * nr_tracks;
2132 datasize = sizeof(struct PFX_eckd_data) +
2133 sizeof(struct LO_eckd_data) +
2134 sizeof(struct eckd_count) +
2135 rpt * nr_tracks * sizeof(struct eckd_count);
2137 datasize = sizeof(struct DE_eckd_data) +
2138 sizeof(struct LO_eckd_data) +
2139 sizeof(struct eckd_count) +
2140 rpt * nr_tracks * sizeof(struct eckd_count);
2142 case 0x04: /* Invalidate track. */
2143 case 0x0c: /* Invalidate track, use cdl. */
2146 datasize = sizeof(struct PFX_eckd_data) +
2147 sizeof(struct LO_eckd_data) +
2148 sizeof(struct eckd_count);
2150 datasize = sizeof(struct DE_eckd_data) +
2151 sizeof(struct LO_eckd_data) +
2152 sizeof(struct eckd_count);
2155 dev_warn(&startdev->cdev->dev,
2156 "An I/O control call used incorrect flags 0x%x\n",
2158 return ERR_PTR(-EINVAL);
2160 /* Allocate the format ccw request. */
2161 fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
2162 datasize, startdev);
2166 start_priv->count++;
2170 switch (intensity & ~0x08) {
2171 case 0x00: /* Normal format. */
2173 prefix(ccw++, (struct PFX_eckd_data *) data,
2174 fdata->start_unit, fdata->stop_unit,
2175 DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2176 /* grant subsystem permission to format R0 */
2178 ((struct PFX_eckd_data *)data)
2179 ->define_extent.ga_extended |= 0x04;
2180 data += sizeof(struct PFX_eckd_data);
2182 define_extent(ccw++, (struct DE_eckd_data *) data,
2183 fdata->start_unit, fdata->stop_unit,
2184 DASD_ECKD_CCW_WRITE_CKD, startdev);
2185 /* grant subsystem permission to format R0 */
2187 ((struct DE_eckd_data *) data)
2188 ->ga_extended |= 0x04;
2189 data += sizeof(struct DE_eckd_data);
2191 ccw[-1].flags |= CCW_FLAG_CC;
2192 locate_record(ccw++, (struct LO_eckd_data *) data,
2193 fdata->start_unit, 0, rpt*nr_tracks,
2194 DASD_ECKD_CCW_WRITE_CKD, base,
2196 data += sizeof(struct LO_eckd_data);
2198 case 0x01: /* Write record zero + format track. */
2200 prefix(ccw++, (struct PFX_eckd_data *) data,
2201 fdata->start_unit, fdata->stop_unit,
2202 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
2204 data += sizeof(struct PFX_eckd_data);
2206 define_extent(ccw++, (struct DE_eckd_data *) data,
2207 fdata->start_unit, fdata->stop_unit,
2208 DASD_ECKD_CCW_WRITE_RECORD_ZERO, startdev);
2209 data += sizeof(struct DE_eckd_data);
2211 ccw[-1].flags |= CCW_FLAG_CC;
2212 locate_record(ccw++, (struct LO_eckd_data *) data,
2213 fdata->start_unit, 0, rpt * nr_tracks + 1,
2214 DASD_ECKD_CCW_WRITE_RECORD_ZERO, base,
2215 base->block->bp_block);
2216 data += sizeof(struct LO_eckd_data);
2218 case 0x04: /* Invalidate track. */
2220 prefix(ccw++, (struct PFX_eckd_data *) data,
2221 fdata->start_unit, fdata->stop_unit,
2222 DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2223 data += sizeof(struct PFX_eckd_data);
2225 define_extent(ccw++, (struct DE_eckd_data *) data,
2226 fdata->start_unit, fdata->stop_unit,
2227 DASD_ECKD_CCW_WRITE_CKD, startdev);
2228 data += sizeof(struct DE_eckd_data);
2230 ccw[-1].flags |= CCW_FLAG_CC;
2231 locate_record(ccw++, (struct LO_eckd_data *) data,
2232 fdata->start_unit, 0, 1,
2233 DASD_ECKD_CCW_WRITE_CKD, base, 8);
2234 data += sizeof(struct LO_eckd_data);
2238 for (j = 0; j < nr_tracks; j++) {
2239 /* calculate cylinder and head for the current track */
2241 (fdata->start_unit + j) /
2242 base_priv->rdc_data.trk_per_cyl,
2243 (fdata->start_unit + j) %
2244 base_priv->rdc_data.trk_per_cyl);
2245 if (intensity & 0x01) { /* write record zero */
2246 ect = (struct eckd_count *) data;
2247 data += sizeof(struct eckd_count);
2248 ect->cyl = address.cyl;
2249 ect->head = address.head;
2253 ccw[-1].flags |= CCW_FLAG_CC;
2254 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
2255 ccw->flags = CCW_FLAG_SLI;
2257 ccw->cda = (__u32)(addr_t) ect;
2260 if ((intensity & ~0x08) & 0x04) { /* erase track */
2261 ect = (struct eckd_count *) data;
2262 data += sizeof(struct eckd_count);
2263 ect->cyl = address.cyl;
2264 ect->head = address.head;
2268 ccw[-1].flags |= CCW_FLAG_CC;
2269 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
2270 ccw->flags = CCW_FLAG_SLI;
2272 ccw->cda = (__u32)(addr_t) ect;
2273 } else { /* write remaining records */
2274 for (i = 0; i < rpt; i++) {
2275 ect = (struct eckd_count *) data;
2276 data += sizeof(struct eckd_count);
2277 ect->cyl = address.cyl;
2278 ect->head = address.head;
2279 ect->record = i + 1;
2281 ect->dl = fdata->blksize;
2283 * Check for special tracks 0-1
2284 * when formatting CDL
2286 if ((intensity & 0x08) &&
2287 fdata->start_unit == 0) {
2290 ect->dl = sizes_trk0[i] - 4;
2293 if ((intensity & 0x08) &&
2294 fdata->start_unit == 1) {
2296 ect->dl = LABEL_SIZE - 44;
2298 ccw[-1].flags |= CCW_FLAG_CC;
2299 if (i != 0 || j == 0)
2301 DASD_ECKD_CCW_WRITE_CKD;
2304 DASD_ECKD_CCW_WRITE_CKD_MT;
2305 ccw->flags = CCW_FLAG_SLI;
2307 ccw->cda = (__u32)(addr_t) ect;
2313 fcp->startdev = startdev;
2314 fcp->memdev = startdev;
2315 fcp->basedev = base;
2317 fcp->expires = startdev->default_expires * HZ;
2318 fcp->buildclk = get_tod_clock();
2319 fcp->status = DASD_CQR_FILLED;
2325 dasd_eckd_format_device(struct dasd_device *base,
2326 struct format_data_t *fdata,
2329 struct dasd_ccw_req *cqr, *n;
2330 struct dasd_block *block;
2331 struct dasd_eckd_private *private;
2332 struct list_head format_queue;
2333 struct dasd_device *device;
2334 int old_stop, format_step;
2335 int step, rc = 0, sleep_rc;
2337 block = base->block;
2338 private = (struct dasd_eckd_private *) base->private;
2340 /* Sanity checks. */
2341 if (fdata->start_unit >=
2342 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2343 dev_warn(&base->cdev->dev,
2344 "Start track number %u used in formatting is too big\n",
2348 if (fdata->stop_unit >=
2349 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2350 dev_warn(&base->cdev->dev,
2351 "Stop track number %u used in formatting is too big\n",
2355 if (fdata->start_unit > fdata->stop_unit) {
2356 dev_warn(&base->cdev->dev,
2357 "Start track %u used in formatting exceeds end track\n",
2361 if (dasd_check_blocksize(fdata->blksize) != 0) {
2362 dev_warn(&base->cdev->dev,
2363 "The DASD cannot be formatted with block size %u\n",
2368 INIT_LIST_HEAD(&format_queue);
2370 old_stop = fdata->stop_unit;
2371 while (fdata->start_unit <= 1) {
2372 fdata->stop_unit = fdata->start_unit;
2373 cqr = dasd_eckd_build_format(base, fdata, enable_pav);
2374 list_add(&cqr->blocklist, &format_queue);
2376 fdata->stop_unit = old_stop;
2377 fdata->start_unit++;
2379 if (fdata->start_unit > fdata->stop_unit)
2384 format_step = 255 / recs_per_track(&private->rdc_data, 0,
2386 while (fdata->start_unit <= old_stop) {
2387 step = fdata->stop_unit - fdata->start_unit + 1;
2388 if (step > format_step)
2389 fdata->stop_unit = fdata->start_unit + format_step - 1;
2391 cqr = dasd_eckd_build_format(base, fdata, enable_pav);
2393 if (PTR_ERR(cqr) == -ENOMEM) {
2395 * not enough memory available
2396 * go to out and start requests
2397 * retry after first requests were finished
2399 fdata->stop_unit = old_stop;
2402 return PTR_ERR(cqr);
2404 list_add(&cqr->blocklist, &format_queue);
2406 fdata->start_unit = fdata->stop_unit + 1;
2407 fdata->stop_unit = old_stop;
2411 sleep_rc = dasd_sleep_on_queue(&format_queue);
2413 list_for_each_entry_safe(cqr, n, &format_queue, blocklist) {
2414 device = cqr->startdev;
2415 private = (struct dasd_eckd_private *) device->private;
2416 if (cqr->status == DASD_CQR_FAILED)
2418 list_del_init(&cqr->blocklist);
2419 dasd_sfree_request(cqr, device);
2427 * in case of ENOMEM we need to retry after
2428 * first requests are finished
2430 if (fdata->start_unit <= fdata->stop_unit)
2436 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
2438 if (cqr->retries < 0) {
2439 cqr->status = DASD_CQR_FAILED;
2442 cqr->status = DASD_CQR_FILLED;
2443 if (cqr->block && (cqr->startdev != cqr->block->base)) {
2444 dasd_eckd_reset_ccw_to_base_io(cqr);
2445 cqr->startdev = cqr->block->base;
2446 cqr->lpm = cqr->block->base->path_data.opm;
2450 static dasd_erp_fn_t
2451 dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
2453 struct dasd_device *device = (struct dasd_device *) cqr->startdev;
2454 struct ccw_device *cdev = device->cdev;
2456 switch (cdev->id.cu_type) {
2461 return dasd_3990_erp_action;
2465 return dasd_default_erp_action;
2469 static dasd_erp_fn_t
2470 dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
2472 return dasd_default_erp_postaction;
2475 static void dasd_eckd_check_for_device_change(struct dasd_device *device,
2476 struct dasd_ccw_req *cqr,
2481 struct dasd_eckd_private *private;
2483 private = (struct dasd_eckd_private *) device->private;
2484 /* first of all check for state change pending interrupt */
2485 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
2486 if ((scsw_dstat(&irb->scsw) & mask) == mask) {
2488 * for alias only, not in offline processing
2489 * and only if not suspended
2491 if (!device->block && private->lcu &&
2492 device->state == DASD_STATE_ONLINE &&
2493 !test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2494 !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
2496 * the state change could be caused by an alias
2497 * reassignment remove device from alias handling
2498 * to prevent new requests from being scheduled on
2499 * the wrong alias device
2501 dasd_alias_remove_device(device);
2503 /* schedule worker to reload device */
2504 dasd_reload_device(device);
2506 dasd_generic_handle_state_change(device);
2510 sense = dasd_get_sense(irb);
2514 /* summary unit check */
2515 if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) &&
2516 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) {
2517 dasd_alias_handle_summary_unit_check(device, irb);
2521 /* service information message SIM */
2522 if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) &&
2523 ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
2524 dasd_3990_erp_handle_sim(device, sense);
2528 /* loss of device reservation is handled via base devices only
2529 * as alias devices may be used with several bases
2531 if (device->block && (sense[27] & DASD_SENSE_BIT_0) &&
2532 (sense[7] == 0x3F) &&
2533 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
2534 test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) {
2535 if (device->features & DASD_FEATURE_FAILONSLCK)
2536 set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
2537 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
2538 dev_err(&device->cdev->dev,
2539 "The device reservation was lost\n");
2543 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
2544 struct dasd_device *startdev,
2545 struct dasd_block *block,
2546 struct request *req,
2551 unsigned int first_offs,
2552 unsigned int last_offs,
2553 unsigned int blk_per_trk,
2554 unsigned int blksize)
2556 struct dasd_eckd_private *private;
2557 unsigned long *idaws;
2558 struct LO_eckd_data *LO_data;
2559 struct dasd_ccw_req *cqr;
2561 struct req_iterator iter;
2565 int count, cidaw, cplength, datasize;
2567 unsigned char cmd, rcmd;
2569 struct dasd_device *basedev;
2571 basedev = block->base;
2572 private = (struct dasd_eckd_private *) basedev->private;
2573 if (rq_data_dir(req) == READ)
2574 cmd = DASD_ECKD_CCW_READ_MT;
2575 else if (rq_data_dir(req) == WRITE)
2576 cmd = DASD_ECKD_CCW_WRITE_MT;
2578 return ERR_PTR(-EINVAL);
2580 /* Check struct bio and count the number of blocks for the request. */
2583 rq_for_each_segment(bv, req, iter) {
2584 if (bv.bv_len & (blksize - 1))
2585 /* Eckd can only do full blocks. */
2586 return ERR_PTR(-EINVAL);
2587 count += bv.bv_len >> (block->s2b_shift + 9);
2588 #if defined(CONFIG_64BIT)
2589 if (idal_is_needed (page_address(bv.bv_page), bv.bv_len))
2590 cidaw += bv.bv_len >> (block->s2b_shift + 9);
2594 if (count != last_rec - first_rec + 1)
2595 return ERR_PTR(-EINVAL);
2597 /* use the prefix command if available */
2598 use_prefix = private->features.feature[8] & 0x01;
2600 /* 1x prefix + number of blocks */
2601 cplength = 2 + count;
2602 /* 1x prefix + cidaws*sizeof(long) */
2603 datasize = sizeof(struct PFX_eckd_data) +
2604 sizeof(struct LO_eckd_data) +
2605 cidaw * sizeof(unsigned long);
2607 /* 1x define extent + 1x locate record + number of blocks */
2608 cplength = 2 + count;
2609 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
2610 datasize = sizeof(struct DE_eckd_data) +
2611 sizeof(struct LO_eckd_data) +
2612 cidaw * sizeof(unsigned long);
2614 /* Find out the number of additional locate record ccws for cdl. */
2615 if (private->uses_cdl && first_rec < 2*blk_per_trk) {
2616 if (last_rec >= 2*blk_per_trk)
2617 count = 2*blk_per_trk - first_rec;
2619 datasize += count*sizeof(struct LO_eckd_data);
2621 /* Allocate the ccw request. */
2622 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2627 /* First ccw is define extent or prefix. */
2629 if (prefix(ccw++, cqr->data, first_trk,
2630 last_trk, cmd, basedev, startdev) == -EAGAIN) {
2631 /* Clock not in sync and XRC is enabled.
2634 dasd_sfree_request(cqr, startdev);
2635 return ERR_PTR(-EAGAIN);
2637 idaws = (unsigned long *) (cqr->data +
2638 sizeof(struct PFX_eckd_data));
2640 if (define_extent(ccw++, cqr->data, first_trk,
2641 last_trk, cmd, basedev) == -EAGAIN) {
2642 /* Clock not in sync and XRC is enabled.
2645 dasd_sfree_request(cqr, startdev);
2646 return ERR_PTR(-EAGAIN);
2648 idaws = (unsigned long *) (cqr->data +
2649 sizeof(struct DE_eckd_data));
2651 /* Build locate_record+read/write/ccws. */
2652 LO_data = (struct LO_eckd_data *) (idaws + cidaw);
2654 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
2655 /* Only standard blocks so there is just one locate record. */
2656 ccw[-1].flags |= CCW_FLAG_CC;
2657 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
2658 last_rec - recid + 1, cmd, basedev, blksize);
2660 rq_for_each_segment(bv, req, iter) {
2661 dst = page_address(bv.bv_page) + bv.bv_offset;
2662 if (dasd_page_cache) {
2663 char *copy = kmem_cache_alloc(dasd_page_cache,
2664 GFP_DMA | __GFP_NOWARN);
2665 if (copy && rq_data_dir(req) == WRITE)
2666 memcpy(copy + bv.bv_offset, dst, bv.bv_len);
2668 dst = copy + bv.bv_offset;
2670 for (off = 0; off < bv.bv_len; off += blksize) {
2671 sector_t trkid = recid;
2672 unsigned int recoffs = sector_div(trkid, blk_per_trk);
2675 /* Locate record for cdl special block ? */
2676 if (private->uses_cdl && recid < 2*blk_per_trk) {
2677 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
2679 count = dasd_eckd_cdl_reclen(recid);
2680 if (count < blksize &&
2681 rq_data_dir(req) == READ)
2682 memset(dst + count, 0xe5,
2685 ccw[-1].flags |= CCW_FLAG_CC;
2686 locate_record(ccw++, LO_data++,
2688 1, rcmd, basedev, count);
2690 /* Locate record for standard blocks ? */
2691 if (private->uses_cdl && recid == 2*blk_per_trk) {
2692 ccw[-1].flags |= CCW_FLAG_CC;
2693 locate_record(ccw++, LO_data++,
2695 last_rec - recid + 1,
2696 cmd, basedev, count);
2698 /* Read/write ccw. */
2699 ccw[-1].flags |= CCW_FLAG_CC;
2700 ccw->cmd_code = rcmd;
2702 if (idal_is_needed(dst, blksize)) {
2703 ccw->cda = (__u32)(addr_t) idaws;
2704 ccw->flags = CCW_FLAG_IDA;
2705 idaws = idal_create_words(idaws, dst, blksize);
2707 ccw->cda = (__u32)(addr_t) dst;
2715 if (blk_noretry_request(req) ||
2716 block->base->features & DASD_FEATURE_FAILFAST)
2717 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2718 cqr->startdev = startdev;
2719 cqr->memdev = startdev;
2721 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2722 cqr->lpm = startdev->path_data.ppm;
2723 cqr->retries = startdev->default_retries;
2724 cqr->buildclk = get_tod_clock();
2725 cqr->status = DASD_CQR_FILLED;
2729 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
2730 struct dasd_device *startdev,
2731 struct dasd_block *block,
2732 struct request *req,
2737 unsigned int first_offs,
2738 unsigned int last_offs,
2739 unsigned int blk_per_trk,
2740 unsigned int blksize)
2742 unsigned long *idaws;
2743 struct dasd_ccw_req *cqr;
2745 struct req_iterator iter;
2747 char *dst, *idaw_dst;
2748 unsigned int cidaw, cplength, datasize;
2752 struct dasd_device *basedev;
2753 unsigned int trkcount, count, count_to_trk_end;
2754 unsigned int idaw_len, seg_len, part_len, len_to_track_end;
2755 unsigned char new_track, end_idaw;
2757 unsigned int recoffs;
2759 basedev = block->base;
2760 if (rq_data_dir(req) == READ)
2761 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2762 else if (rq_data_dir(req) == WRITE)
2763 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2765 return ERR_PTR(-EINVAL);
2767 /* Track based I/O needs IDAWs for each page, and not just for
2768 * 64 bit addresses. We need additional idals for pages
2769 * that get filled from two tracks, so we use the number
2770 * of records as upper limit.
2772 cidaw = last_rec - first_rec + 1;
2773 trkcount = last_trk - first_trk + 1;
2775 /* 1x prefix + one read/write ccw per track */
2776 cplength = 1 + trkcount;
2778 /* on 31-bit we need space for two 32 bit addresses per page
2779 * on 64-bit one 64 bit address
2781 datasize = sizeof(struct PFX_eckd_data) +
2782 cidaw * sizeof(unsigned long long);
2784 /* Allocate the ccw request. */
2785 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2790 /* transfer length factor: how many bytes to read from the last track */
2791 if (first_trk == last_trk)
2792 tlf = last_offs - first_offs + 1;
2794 tlf = last_offs + 1;
2797 if (prefix_LRE(ccw++, cqr->data, first_trk,
2798 last_trk, cmd, basedev, startdev,
2799 1 /* format */, first_offs + 1,
2802 /* Clock not in sync and XRC is enabled.
2805 dasd_sfree_request(cqr, startdev);
2806 return ERR_PTR(-EAGAIN);
2810 * The translation of request into ccw programs must meet the
2811 * following conditions:
2812 * - all idaws but the first and the last must address full pages
2813 * (or 2K blocks on 31-bit)
2814 * - the scope of a ccw and it's idal ends with the track boundaries
2816 idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
2820 len_to_track_end = 0;
2823 rq_for_each_segment(bv, req, iter) {
2824 dst = page_address(bv.bv_page) + bv.bv_offset;
2825 seg_len = bv.bv_len;
2829 recoffs = sector_div(trkid, blk_per_trk);
2830 count_to_trk_end = blk_per_trk - recoffs;
2831 count = min((last_rec - recid + 1),
2832 (sector_t)count_to_trk_end);
2833 len_to_track_end = count * blksize;
2834 ccw[-1].flags |= CCW_FLAG_CC;
2835 ccw->cmd_code = cmd;
2836 ccw->count = len_to_track_end;
2837 ccw->cda = (__u32)(addr_t)idaws;
2838 ccw->flags = CCW_FLAG_IDA;
2842 /* first idaw for a ccw may start anywhere */
2846 /* If we start a new idaw, we must make sure that it
2847 * starts on an IDA_BLOCK_SIZE boundary.
2848 * If we continue an idaw, we must make sure that the
2849 * current segment begins where the so far accumulated
2853 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
2854 dasd_sfree_request(cqr, startdev);
2855 return ERR_PTR(-ERANGE);
2859 if ((idaw_dst + idaw_len) != dst) {
2860 dasd_sfree_request(cqr, startdev);
2861 return ERR_PTR(-ERANGE);
2863 part_len = min(seg_len, len_to_track_end);
2864 seg_len -= part_len;
2866 idaw_len += part_len;
2867 len_to_track_end -= part_len;
2868 /* collected memory area ends on an IDA_BLOCK border,
2870 * idal_create_words will handle cases where idaw_len
2871 * is larger then IDA_BLOCK_SIZE
2873 if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
2875 /* We also need to end the idaw at track end */
2876 if (!len_to_track_end) {
2881 idaws = idal_create_words(idaws, idaw_dst,
2890 if (blk_noretry_request(req) ||
2891 block->base->features & DASD_FEATURE_FAILFAST)
2892 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2893 cqr->startdev = startdev;
2894 cqr->memdev = startdev;
2896 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2897 cqr->lpm = startdev->path_data.ppm;
2898 cqr->retries = startdev->default_retries;
2899 cqr->buildclk = get_tod_clock();
2900 cqr->status = DASD_CQR_FILLED;
2904 static int prepare_itcw(struct itcw *itcw,
2905 unsigned int trk, unsigned int totrk, int cmd,
2906 struct dasd_device *basedev,
2907 struct dasd_device *startdev,
2908 unsigned int rec_on_trk, int count,
2909 unsigned int blksize,
2910 unsigned int total_data_size,
2912 unsigned int blk_per_trk)
2914 struct PFX_eckd_data pfxdata;
2915 struct dasd_eckd_private *basepriv, *startpriv;
2916 struct DE_eckd_data *dedata;
2917 struct LRE_eckd_data *lredata;
2921 u16 heads, beghead, endhead;
2929 /* setup prefix data */
2930 basepriv = (struct dasd_eckd_private *) basedev->private;
2931 startpriv = (struct dasd_eckd_private *) startdev->private;
2932 dedata = &pfxdata.define_extent;
2933 lredata = &pfxdata.locate_record;
2935 memset(&pfxdata, 0, sizeof(pfxdata));
2936 pfxdata.format = 1; /* PFX with LRE */
2937 pfxdata.base_address = basepriv->ned->unit_addr;
2938 pfxdata.base_lss = basepriv->ned->ID;
2939 pfxdata.validity.define_extent = 1;
2941 /* private uid is kept up to date, conf_data may be outdated */
2942 if (startpriv->uid.type != UA_BASE_DEVICE) {
2943 pfxdata.validity.verify_base = 1;
2944 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
2945 pfxdata.validity.hyper_pav = 1;
2949 case DASD_ECKD_CCW_READ_TRACK_DATA:
2950 dedata->mask.perm = 0x1;
2951 dedata->attributes.operation = basepriv->attrib.operation;
2952 dedata->blk_size = blksize;
2953 dedata->ga_extended |= 0x42;
2954 lredata->operation.orientation = 0x0;
2955 lredata->operation.operation = 0x0C;
2956 lredata->auxiliary.check_bytes = 0x01;
2957 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
2959 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
2960 dedata->mask.perm = 0x02;
2961 dedata->attributes.operation = basepriv->attrib.operation;
2962 dedata->blk_size = blksize;
2963 rc = check_XRC_on_prefix(&pfxdata, basedev);
2964 dedata->ga_extended |= 0x42;
2965 lredata->operation.orientation = 0x0;
2966 lredata->operation.operation = 0x3F;
2967 lredata->extended_operation = 0x23;
2968 lredata->auxiliary.check_bytes = 0x2;
2969 pfx_cmd = DASD_ECKD_CCW_PFX;
2972 DBF_DEV_EVENT(DBF_ERR, basedev,
2973 "prepare itcw, unknown opcode 0x%x", cmd);
2980 dedata->attributes.mode = 0x3; /* ECKD */
2982 heads = basepriv->rdc_data.trk_per_cyl;
2983 begcyl = trk / heads;
2984 beghead = trk % heads;
2985 endcyl = totrk / heads;
2986 endhead = totrk % heads;
2988 /* check for sequential prestage - enhance cylinder range */
2989 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
2990 dedata->attributes.operation == DASD_SEQ_ACCESS) {
2992 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
2993 endcyl += basepriv->attrib.nr_cyl;
2995 endcyl = (basepriv->real_cyl - 1);
2998 set_ch_t(&dedata->beg_ext, begcyl, beghead);
2999 set_ch_t(&dedata->end_ext, endcyl, endhead);
3001 dedata->ep_format = 0x20; /* records per track is valid */
3002 dedata->ep_rec_per_track = blk_per_trk;
3005 switch (basepriv->rdc_data.dev_type) {
3007 dn = ceil_quot(blksize + 6, 232);
3008 d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
3009 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
3012 d = 7 + ceil_quot(blksize + 12, 32);
3013 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
3018 lredata->auxiliary.length_valid = 1;
3019 lredata->auxiliary.length_scope = 1;
3020 lredata->auxiliary.imbedded_ccw_valid = 1;
3021 lredata->length = tlf;
3022 lredata->imbedded_ccw = cmd;
3023 lredata->count = count;
3024 lredata->sector = sector;
3025 set_ch_t(&lredata->seek_addr, begcyl, beghead);
3026 lredata->search_arg.cyl = lredata->seek_addr.cyl;
3027 lredata->search_arg.head = lredata->seek_addr.head;
3028 lredata->search_arg.record = rec_on_trk;
3030 dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
3031 &pfxdata, sizeof(pfxdata), total_data_size);
3032 return PTR_RET(dcw);
3035 static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
3036 struct dasd_device *startdev,
3037 struct dasd_block *block,
3038 struct request *req,
3043 unsigned int first_offs,
3044 unsigned int last_offs,
3045 unsigned int blk_per_trk,
3046 unsigned int blksize)
3048 struct dasd_ccw_req *cqr;
3049 struct req_iterator iter;
3052 unsigned int trkcount, ctidaw;
3054 struct dasd_device *basedev;
3057 struct tidaw *last_tidaw = NULL;
3061 unsigned int seg_len, part_len, len_to_track_end;
3062 unsigned char new_track;
3063 sector_t recid, trkid;
3065 unsigned int count, count_to_trk_end;
3068 basedev = block->base;
3069 if (rq_data_dir(req) == READ) {
3070 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
3071 itcw_op = ITCW_OP_READ;
3072 } else if (rq_data_dir(req) == WRITE) {
3073 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
3074 itcw_op = ITCW_OP_WRITE;
3076 return ERR_PTR(-EINVAL);
3078 /* trackbased I/O needs address all memory via TIDAWs,
3079 * not just for 64 bit addresses. This allows us to map
3080 * each segment directly to one tidaw.
3081 * In the case of write requests, additional tidaws may
3082 * be needed when a segment crosses a track boundary.
3084 trkcount = last_trk - first_trk + 1;
3086 rq_for_each_segment(bv, req, iter) {
3089 if (rq_data_dir(req) == WRITE)
3090 ctidaw += (last_trk - first_trk);
3092 /* Allocate the ccw request. */
3093 itcw_size = itcw_calc_size(0, ctidaw, 0);
3094 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
3098 /* transfer length factor: how many bytes to read from the last track */
3099 if (first_trk == last_trk)
3100 tlf = last_offs - first_offs + 1;
3102 tlf = last_offs + 1;
3105 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
3110 cqr->cpaddr = itcw_get_tcw(itcw);
3111 if (prepare_itcw(itcw, first_trk, last_trk,
3112 cmd, basedev, startdev,
3115 (last_rec - first_rec + 1) * blksize,
3116 tlf, blk_per_trk) == -EAGAIN) {
3117 /* Clock not in sync and XRC is enabled.
3123 len_to_track_end = 0;
3125 * A tidaw can address 4k of memory, but must not cross page boundaries
3126 * We can let the block layer handle this by setting
3127 * blk_queue_segment_boundary to page boundaries and
3128 * blk_max_segment_size to page size when setting up the request queue.
3129 * For write requests, a TIDAW must not cross track boundaries, because
3130 * we have to set the CBC flag on the last tidaw for each track.
3132 if (rq_data_dir(req) == WRITE) {
3135 rq_for_each_segment(bv, req, iter) {
3136 dst = page_address(bv.bv_page) + bv.bv_offset;
3137 seg_len = bv.bv_len;
3141 offs = sector_div(trkid, blk_per_trk);
3142 count_to_trk_end = blk_per_trk - offs;
3143 count = min((last_rec - recid + 1),
3144 (sector_t)count_to_trk_end);
3145 len_to_track_end = count * blksize;
3149 part_len = min(seg_len, len_to_track_end);
3150 seg_len -= part_len;
3151 len_to_track_end -= part_len;
3152 /* We need to end the tidaw at track end */
3153 if (!len_to_track_end) {
3155 tidaw_flags = TIDAW_FLAGS_INSERT_CBC;
3158 last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
3160 if (IS_ERR(last_tidaw)) {
3168 rq_for_each_segment(bv, req, iter) {
3169 dst = page_address(bv.bv_page) + bv.bv_offset;
3170 last_tidaw = itcw_add_tidaw(itcw, 0x00,
3172 if (IS_ERR(last_tidaw)) {
3178 last_tidaw->flags |= TIDAW_FLAGS_LAST;
3179 last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC;
3180 itcw_finalize(itcw);
3182 if (blk_noretry_request(req) ||
3183 block->base->features & DASD_FEATURE_FAILFAST)
3184 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3186 cqr->startdev = startdev;
3187 cqr->memdev = startdev;
3189 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
3190 cqr->lpm = startdev->path_data.ppm;
3191 cqr->retries = startdev->default_retries;
3192 cqr->buildclk = get_tod_clock();
3193 cqr->status = DASD_CQR_FILLED;
3196 dasd_sfree_request(cqr, startdev);
3197 return ERR_PTR(ret);
3200 static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
3201 struct dasd_block *block,
3202 struct request *req)
3207 struct dasd_eckd_private *private;
3208 struct dasd_device *basedev;
3209 sector_t first_rec, last_rec;
3210 sector_t first_trk, last_trk;
3211 unsigned int first_offs, last_offs;
3212 unsigned int blk_per_trk, blksize;
3214 unsigned int data_size;
3215 struct dasd_ccw_req *cqr;
3217 basedev = block->base;
3218 private = (struct dasd_eckd_private *) basedev->private;
3220 /* Calculate number of blocks/records per track. */
3221 blksize = block->bp_block;
3222 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
3223 if (blk_per_trk == 0)
3224 return ERR_PTR(-EINVAL);
3225 /* Calculate record id of first and last block. */
3226 first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
3227 first_offs = sector_div(first_trk, blk_per_trk);
3228 last_rec = last_trk =
3229 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
3230 last_offs = sector_div(last_trk, blk_per_trk);
3231 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
3233 fcx_multitrack = private->features.feature[40] & 0x20;
3234 data_size = blk_rq_bytes(req);
3235 if (data_size % blksize)
3236 return ERR_PTR(-EINVAL);
3237 /* tpm write request add CBC data on each track boundary */
3238 if (rq_data_dir(req) == WRITE)
3239 data_size += (last_trk - first_trk) * 4;
3241 /* is read track data and write track data in command mode supported? */
3242 cmdrtd = private->features.feature[9] & 0x20;
3243 cmdwtd = private->features.feature[12] & 0x40;
3244 use_prefix = private->features.feature[8] & 0x01;
3247 if (cdlspecial || dasd_page_cache) {
3248 /* do nothing, just fall through to the cmd mode single case */
3249 } else if ((data_size <= private->fcx_max_data)
3250 && (fcx_multitrack || (first_trk == last_trk))) {
3251 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
3252 first_rec, last_rec,
3253 first_trk, last_trk,
3254 first_offs, last_offs,
3255 blk_per_trk, blksize);
3256 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3257 (PTR_ERR(cqr) != -ENOMEM))
3259 } else if (use_prefix &&
3260 (((rq_data_dir(req) == READ) && cmdrtd) ||
3261 ((rq_data_dir(req) == WRITE) && cmdwtd))) {
3262 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
3263 first_rec, last_rec,
3264 first_trk, last_trk,
3265 first_offs, last_offs,
3266 blk_per_trk, blksize);
3267 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3268 (PTR_ERR(cqr) != -ENOMEM))
3272 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
3273 first_rec, last_rec,
3274 first_trk, last_trk,
3275 first_offs, last_offs,
3276 blk_per_trk, blksize);
3280 static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev,
3281 struct dasd_block *block,
3282 struct request *req)
3284 unsigned long *idaws;
3285 struct dasd_device *basedev;
3286 struct dasd_ccw_req *cqr;
3288 struct req_iterator iter;
3292 unsigned int trkcount;
3293 unsigned int seg_len, len_to_track_end;
3294 unsigned int first_offs;
3295 unsigned int cidaw, cplength, datasize;
3296 sector_t first_trk, last_trk, sectors;
3297 sector_t start_padding_sectors, end_sector_offset, end_padding_sectors;
3298 unsigned int pfx_datasize;
3301 * raw track access needs to be mutiple of 64k and on 64k boundary
3302 * For read requests we can fix an incorrect alignment by padding
3303 * the request with dummy pages.
3305 start_padding_sectors = blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK;
3306 end_sector_offset = (blk_rq_pos(req) + blk_rq_sectors(req)) %
3307 DASD_RAW_SECTORS_PER_TRACK;
3308 end_padding_sectors = (DASD_RAW_SECTORS_PER_TRACK - end_sector_offset) %
3309 DASD_RAW_SECTORS_PER_TRACK;
3310 basedev = block->base;
3311 if ((start_padding_sectors || end_padding_sectors) &&
3312 (rq_data_dir(req) == WRITE)) {
3313 DBF_DEV_EVENT(DBF_ERR, basedev,
3314 "raw write not track aligned (%lu,%lu) req %p",
3315 start_padding_sectors, end_padding_sectors, req);
3316 cqr = ERR_PTR(-EINVAL);
3320 first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK;
3321 last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
3322 DASD_RAW_SECTORS_PER_TRACK;
3323 trkcount = last_trk - first_trk + 1;
3326 if (rq_data_dir(req) == READ)
3327 cmd = DASD_ECKD_CCW_READ_TRACK;
3328 else if (rq_data_dir(req) == WRITE)
3329 cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK;
3331 cqr = ERR_PTR(-EINVAL);
3336 * Raw track based I/O needs IDAWs for each page,
3337 * and not just for 64 bit addresses.
3339 cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK;
3341 /* 1x prefix + one read/write ccw per track */
3342 cplength = 1 + trkcount;
3345 * struct PFX_eckd_data has up to 2 byte as extended parameter
3346 * this is needed for write full track and has to be mentioned
3348 * add 8 instead of 2 to keep 8 byte boundary
3350 pfx_datasize = sizeof(struct PFX_eckd_data) + 8;
3352 datasize = pfx_datasize + cidaw * sizeof(unsigned long long);
3354 /* Allocate the ccw request. */
3355 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
3356 datasize, startdev);
3361 if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd,
3362 basedev, startdev, 1 /* format */, first_offs + 1,
3363 trkcount, 0, 0) == -EAGAIN) {
3364 /* Clock not in sync and XRC is enabled.
3367 dasd_sfree_request(cqr, startdev);
3368 cqr = ERR_PTR(-EAGAIN);
3372 idaws = (unsigned long *)(cqr->data + pfx_datasize);
3373 len_to_track_end = 0;
3374 if (start_padding_sectors) {
3375 ccw[-1].flags |= CCW_FLAG_CC;
3376 ccw->cmd_code = cmd;
3377 /* maximum 3390 track size */
3379 /* 64k map to one track */
3380 len_to_track_end = 65536 - start_padding_sectors * 512;
3381 ccw->cda = (__u32)(addr_t)idaws;
3382 ccw->flags |= CCW_FLAG_IDA;
3383 ccw->flags |= CCW_FLAG_SLI;
3385 for (sectors = 0; sectors < start_padding_sectors; sectors += 8)
3386 idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE);
3388 rq_for_each_segment(bv, req, iter) {
3389 dst = page_address(bv.bv_page) + bv.bv_offset;
3390 seg_len = bv.bv_len;
3391 if (cmd == DASD_ECKD_CCW_READ_TRACK)
3392 memset(dst, 0, seg_len);
3393 if (!len_to_track_end) {
3394 ccw[-1].flags |= CCW_FLAG_CC;
3395 ccw->cmd_code = cmd;
3396 /* maximum 3390 track size */
3398 /* 64k map to one track */
3399 len_to_track_end = 65536;
3400 ccw->cda = (__u32)(addr_t)idaws;
3401 ccw->flags |= CCW_FLAG_IDA;
3402 ccw->flags |= CCW_FLAG_SLI;
3405 len_to_track_end -= seg_len;
3406 idaws = idal_create_words(idaws, dst, seg_len);
3408 for (sectors = 0; sectors < end_padding_sectors; sectors += 8)
3409 idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE);
3410 if (blk_noretry_request(req) ||
3411 block->base->features & DASD_FEATURE_FAILFAST)
3412 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3413 cqr->startdev = startdev;
3414 cqr->memdev = startdev;
3416 cqr->expires = startdev->default_expires * HZ;
3417 cqr->lpm = startdev->path_data.ppm;
3418 cqr->retries = startdev->default_retries;
3419 cqr->buildclk = get_tod_clock();
3420 cqr->status = DASD_CQR_FILLED;
3422 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
3430 dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
3432 struct dasd_eckd_private *private;
3434 struct req_iterator iter;
3437 unsigned int blksize, blk_per_trk, off;
3441 if (!dasd_page_cache)
3443 private = (struct dasd_eckd_private *) cqr->block->base->private;
3444 blksize = cqr->block->bp_block;
3445 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
3446 recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
3448 /* Skip over define extent & locate record. */
3450 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
3452 rq_for_each_segment(bv, req, iter) {
3453 dst = page_address(bv.bv_page) + bv.bv_offset;
3454 for (off = 0; off < bv.bv_len; off += blksize) {
3455 /* Skip locate record. */
3456 if (private->uses_cdl && recid <= 2*blk_per_trk)
3459 if (ccw->flags & CCW_FLAG_IDA)
3460 cda = *((char **)((addr_t) ccw->cda));
3462 cda = (char *)((addr_t) ccw->cda);
3464 if (rq_data_dir(req) == READ)
3465 memcpy(dst, cda, bv.bv_len);
3466 kmem_cache_free(dasd_page_cache,
3467 (void *)((addr_t)cda & PAGE_MASK));
3476 status = cqr->status == DASD_CQR_DONE;
3477 dasd_sfree_request(cqr, cqr->memdev);
3482 * Modify ccw/tcw in cqr so it can be started on a base device.
3484 * Note that this is not enough to restart the cqr!
3485 * Either reset cqr->startdev as well (summary unit check handling)
3486 * or restart via separate cqr (as in ERP handling).
3488 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
3491 struct PFX_eckd_data *pfxdata;
3496 if (cqr->cpmode == 1) {
3498 tccb = tcw_get_tccb(tcw);
3499 dcw = (struct dcw *)&tccb->tca[0];
3500 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
3501 pfxdata->validity.verify_base = 0;
3502 pfxdata->validity.hyper_pav = 0;
3505 pfxdata = cqr->data;
3506 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
3507 pfxdata->validity.verify_base = 0;
3508 pfxdata->validity.hyper_pav = 0;
3513 #define DASD_ECKD_CHANQ_MAX_SIZE 4
3515 static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
3516 struct dasd_block *block,
3517 struct request *req)
3519 struct dasd_eckd_private *private;
3520 struct dasd_device *startdev;
3521 unsigned long flags;
3522 struct dasd_ccw_req *cqr;
3524 startdev = dasd_alias_get_start_dev(base);
3527 private = (struct dasd_eckd_private *) startdev->private;
3528 if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
3529 return ERR_PTR(-EBUSY);
3531 spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
3533 if ((base->features & DASD_FEATURE_USERAW))
3534 cqr = dasd_raw_build_cp(startdev, block, req);
3536 cqr = dasd_eckd_build_cp(startdev, block, req);
3539 spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
3543 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
3544 struct request *req)
3546 struct dasd_eckd_private *private;
3547 unsigned long flags;
3549 spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
3550 private = (struct dasd_eckd_private *) cqr->memdev->private;
3552 spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
3553 return dasd_eckd_free_cp(cqr, req);
3557 dasd_eckd_fill_info(struct dasd_device * device,
3558 struct dasd_information2_t * info)
3560 struct dasd_eckd_private *private;
3562 private = (struct dasd_eckd_private *) device->private;
3563 info->label_block = 2;
3564 info->FBA_layout = private->uses_cdl ? 0 : 1;
3565 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
3566 info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
3567 memcpy(info->characteristics, &private->rdc_data,
3568 sizeof(struct dasd_eckd_characteristics));
3569 info->confdata_size = min((unsigned long)private->conf_len,
3570 sizeof(info->configuration_data));
3571 memcpy(info->configuration_data, private->conf_data,
3572 info->confdata_size);
3577 * SECTION: ioctl functions for eckd devices.
3581 * Release device ioctl.
3582 * Buils a channel programm to releases a prior reserved
3583 * (see dasd_eckd_reserve) device.
3586 dasd_eckd_release(struct dasd_device *device)
3588 struct dasd_ccw_req *cqr;
3593 if (!capable(CAP_SYS_ADMIN))
3597 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
3599 mutex_lock(&dasd_reserve_mutex);
3601 cqr = &dasd_reserve_req->cqr;
3602 memset(cqr, 0, sizeof(*cqr));
3603 memset(&dasd_reserve_req->ccw, 0,
3604 sizeof(dasd_reserve_req->ccw));
3605 cqr->cpaddr = &dasd_reserve_req->ccw;
3606 cqr->data = &dasd_reserve_req->data;
3607 cqr->magic = DASD_ECKD_MAGIC;
3610 ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
3611 ccw->flags |= CCW_FLAG_SLI;
3613 ccw->cda = (__u32)(addr_t) cqr->data;
3614 cqr->startdev = device;
3615 cqr->memdev = device;
3616 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3617 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3618 cqr->retries = 2; /* set retry counter to enable basic ERP */
3619 cqr->expires = 2 * HZ;
3620 cqr->buildclk = get_tod_clock();
3621 cqr->status = DASD_CQR_FILLED;
3623 rc = dasd_sleep_on_immediatly(cqr);
3625 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3628 mutex_unlock(&dasd_reserve_mutex);
3630 dasd_sfree_request(cqr, cqr->memdev);
3635 * Reserve device ioctl.
3636 * Options are set to 'synchronous wait for interrupt' and
3637 * 'timeout the request'. This leads to a terminate IO if
3638 * the interrupt is outstanding for a certain time.
3641 dasd_eckd_reserve(struct dasd_device *device)
3643 struct dasd_ccw_req *cqr;
3648 if (!capable(CAP_SYS_ADMIN))
3652 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
3654 mutex_lock(&dasd_reserve_mutex);
3656 cqr = &dasd_reserve_req->cqr;
3657 memset(cqr, 0, sizeof(*cqr));
3658 memset(&dasd_reserve_req->ccw, 0,
3659 sizeof(dasd_reserve_req->ccw));
3660 cqr->cpaddr = &dasd_reserve_req->ccw;
3661 cqr->data = &dasd_reserve_req->data;
3662 cqr->magic = DASD_ECKD_MAGIC;
3665 ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
3666 ccw->flags |= CCW_FLAG_SLI;
3668 ccw->cda = (__u32)(addr_t) cqr->data;
3669 cqr->startdev = device;
3670 cqr->memdev = device;
3671 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3672 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3673 cqr->retries = 2; /* set retry counter to enable basic ERP */
3674 cqr->expires = 2 * HZ;
3675 cqr->buildclk = get_tod_clock();
3676 cqr->status = DASD_CQR_FILLED;
3678 rc = dasd_sleep_on_immediatly(cqr);
3680 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3683 mutex_unlock(&dasd_reserve_mutex);
3685 dasd_sfree_request(cqr, cqr->memdev);
3690 * Steal lock ioctl - unconditional reserve device.
3691 * Buils a channel programm to break a device's reservation.
3692 * (unconditional reserve)
3695 dasd_eckd_steal_lock(struct dasd_device *device)
3697 struct dasd_ccw_req *cqr;
3702 if (!capable(CAP_SYS_ADMIN))
3706 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
3708 mutex_lock(&dasd_reserve_mutex);
3710 cqr = &dasd_reserve_req->cqr;
3711 memset(cqr, 0, sizeof(*cqr));
3712 memset(&dasd_reserve_req->ccw, 0,
3713 sizeof(dasd_reserve_req->ccw));
3714 cqr->cpaddr = &dasd_reserve_req->ccw;
3715 cqr->data = &dasd_reserve_req->data;
3716 cqr->magic = DASD_ECKD_MAGIC;
3719 ccw->cmd_code = DASD_ECKD_CCW_SLCK;
3720 ccw->flags |= CCW_FLAG_SLI;
3722 ccw->cda = (__u32)(addr_t) cqr->data;
3723 cqr->startdev = device;
3724 cqr->memdev = device;
3725 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3726 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3727 cqr->retries = 2; /* set retry counter to enable basic ERP */
3728 cqr->expires = 2 * HZ;
3729 cqr->buildclk = get_tod_clock();
3730 cqr->status = DASD_CQR_FILLED;
3732 rc = dasd_sleep_on_immediatly(cqr);
3734 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3737 mutex_unlock(&dasd_reserve_mutex);
3739 dasd_sfree_request(cqr, cqr->memdev);
3744 * SNID - Sense Path Group ID
3745 * This ioctl may be used in situations where I/O is stalled due to
3746 * a reserve, so if the normal dasd_smalloc_request fails, we use the
3747 * preallocated dasd_reserve_req.
3749 static int dasd_eckd_snid(struct dasd_device *device,
3752 struct dasd_ccw_req *cqr;
3756 struct dasd_snid_ioctl_data usrparm;
3758 if (!capable(CAP_SYS_ADMIN))
3761 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
3765 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1,
3766 sizeof(struct dasd_snid_data), device);
3768 mutex_lock(&dasd_reserve_mutex);
3770 cqr = &dasd_reserve_req->cqr;
3771 memset(cqr, 0, sizeof(*cqr));
3772 memset(&dasd_reserve_req->ccw, 0,
3773 sizeof(dasd_reserve_req->ccw));
3774 cqr->cpaddr = &dasd_reserve_req->ccw;
3775 cqr->data = &dasd_reserve_req->data;
3776 cqr->magic = DASD_ECKD_MAGIC;
3779 ccw->cmd_code = DASD_ECKD_CCW_SNID;
3780 ccw->flags |= CCW_FLAG_SLI;
3782 ccw->cda = (__u32)(addr_t) cqr->data;
3783 cqr->startdev = device;
3784 cqr->memdev = device;
3785 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3786 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3787 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
3789 cqr->expires = 10 * HZ;
3790 cqr->buildclk = get_tod_clock();
3791 cqr->status = DASD_CQR_FILLED;
3792 cqr->lpm = usrparm.path_mask;
3794 rc = dasd_sleep_on_immediatly(cqr);
3795 /* verify that I/O processing didn't modify the path mask */
3796 if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask))
3799 usrparm.data = *((struct dasd_snid_data *)cqr->data);
3800 if (copy_to_user(argp, &usrparm, sizeof(usrparm)))
3805 mutex_unlock(&dasd_reserve_mutex);
3807 dasd_sfree_request(cqr, cqr->memdev);
3812 * Read performance statistics
3815 dasd_eckd_performance(struct dasd_device *device, void __user *argp)
3817 struct dasd_psf_prssd_data *prssdp;
3818 struct dasd_rssd_perf_stats_t *stats;
3819 struct dasd_ccw_req *cqr;
3823 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
3824 (sizeof(struct dasd_psf_prssd_data) +
3825 sizeof(struct dasd_rssd_perf_stats_t)),
3828 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3829 "Could not allocate initialization request");
3830 return PTR_ERR(cqr);
3832 cqr->startdev = device;
3833 cqr->memdev = device;
3835 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3836 cqr->expires = 10 * HZ;
3838 /* Prepare for Read Subsystem Data */
3839 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
3840 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
3841 prssdp->order = PSF_ORDER_PRSSD;
3842 prssdp->suborder = 0x01; /* Performance Statistics */
3843 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
3846 ccw->cmd_code = DASD_ECKD_CCW_PSF;
3847 ccw->count = sizeof(struct dasd_psf_prssd_data);
3848 ccw->flags |= CCW_FLAG_CC;
3849 ccw->cda = (__u32)(addr_t) prssdp;
3851 /* Read Subsystem Data - Performance Statistics */
3852 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
3853 memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
3856 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
3857 ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
3858 ccw->cda = (__u32)(addr_t) stats;
3860 cqr->buildclk = get_tod_clock();
3861 cqr->status = DASD_CQR_FILLED;
3862 rc = dasd_sleep_on(cqr);
3864 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
3865 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
3866 if (copy_to_user(argp, stats,
3867 sizeof(struct dasd_rssd_perf_stats_t)))
3870 dasd_sfree_request(cqr, cqr->memdev);
3875 * Get attributes (cache operations)
3876 * Returnes the cache attributes used in Define Extend (DE).
3879 dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
3881 struct dasd_eckd_private *private =
3882 (struct dasd_eckd_private *)device->private;
3883 struct attrib_data_t attrib = private->attrib;
3886 if (!capable(CAP_SYS_ADMIN))
3892 if (copy_to_user(argp, (long *) &attrib,
3893 sizeof(struct attrib_data_t)))
3900 * Set attributes (cache operations)
3901 * Stores the attributes for cache operation to be used in Define Extend (DE).
3904 dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
3906 struct dasd_eckd_private *private =
3907 (struct dasd_eckd_private *)device->private;
3908 struct attrib_data_t attrib;
3910 if (!capable(CAP_SYS_ADMIN))
3915 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
3917 private->attrib = attrib;
3919 dev_info(&device->cdev->dev,
3920 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
3921 private->attrib.operation, private->attrib.nr_cyl);
3926 * Issue syscall I/O to EMC Symmetrix array.
3927 * CCWs are PSF and RSSD
3929 static int dasd_symm_io(struct dasd_device *device, void __user *argp)
3931 struct dasd_symmio_parms usrparm;
3932 char *psf_data, *rssd_result;
3933 struct dasd_ccw_req *cqr;
3938 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
3942 /* Copy parms from caller */
3944 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
3946 if (is_compat_task() || sizeof(long) == 4) {
3947 /* Make sure pointers are sane even on 31 bit. */
3949 if ((usrparm.psf_data >> 32) != 0)
3951 if ((usrparm.rssd_result >> 32) != 0)
3953 usrparm.psf_data &= 0x7fffffffULL;
3954 usrparm.rssd_result &= 0x7fffffffULL;
3956 /* alloc I/O data area */
3957 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
3958 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
3959 if (!psf_data || !rssd_result) {
3964 /* get syscall header from user space */
3966 if (copy_from_user(psf_data,
3967 (void __user *)(unsigned long) usrparm.psf_data,
3968 usrparm.psf_data_len))
3973 /* setup CCWs for PSF + RSSD */
3974 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
3976 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3977 "Could not allocate initialization request");
3982 cqr->startdev = device;
3983 cqr->memdev = device;
3985 cqr->expires = 10 * HZ;
3986 cqr->buildclk = get_tod_clock();
3987 cqr->status = DASD_CQR_FILLED;
3989 /* Build the ccws */
3993 ccw->cmd_code = DASD_ECKD_CCW_PSF;
3994 ccw->count = usrparm.psf_data_len;
3995 ccw->flags |= CCW_FLAG_CC;
3996 ccw->cda = (__u32)(addr_t) psf_data;
4001 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
4002 ccw->count = usrparm.rssd_result_len;
4003 ccw->flags = CCW_FLAG_SLI ;
4004 ccw->cda = (__u32)(addr_t) rssd_result;
4006 rc = dasd_sleep_on(cqr);
4011 if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
4012 rssd_result, usrparm.rssd_result_len))
4017 dasd_sfree_request(cqr, cqr->memdev);
4022 DBF_DEV_EVENT(DBF_WARNING, device,
4023 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
4024 (int) psf0, (int) psf1, rc);
4029 dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
4031 struct dasd_device *device = block->base;
4035 return dasd_eckd_get_attrib(device, argp);
4037 return dasd_eckd_set_attrib(device, argp);
4039 return dasd_eckd_performance(device, argp);
4041 return dasd_eckd_release(device);
4043 return dasd_eckd_reserve(device);
4045 return dasd_eckd_steal_lock(device);
4047 return dasd_eckd_snid(device, argp);
4049 return dasd_symm_io(device, argp);
4056 * Dump the range of CCWs into 'page' buffer
4057 * and return number of printed chars.
4060 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
4066 while (from <= to) {
4067 len += sprintf(page + len, PRINTK_HEADER
4068 " CCW %p: %08X %08X DAT:",
4069 from, ((int *) from)[0], ((int *) from)[1]);
4071 /* get pointer to data (consider IDALs) */
4072 if (from->flags & CCW_FLAG_IDA)
4073 datap = (char *) *((addr_t *) (addr_t) from->cda);
4075 datap = (char *) ((addr_t) from->cda);
4077 /* dump data (max 32 bytes) */
4078 for (count = 0; count < from->count && count < 32; count++) {
4079 if (count % 8 == 0) len += sprintf(page + len, " ");
4080 if (count % 4 == 0) len += sprintf(page + len, " ");
4081 len += sprintf(page + len, "%02x", datap[count]);
4083 len += sprintf(page + len, "\n");
4090 dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
4096 sense = (u64 *) dasd_get_sense(irb);
4097 stat = (u64 *) &irb->scsw;
4099 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : "
4100 "%016llx %016llx %016llx %016llx",
4101 reason, *stat, *((u32 *) (stat + 1)),
4102 sense[0], sense[1], sense[2], sense[3]);
4104 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s",
4105 reason, *stat, *((u32 *) (stat + 1)),
4111 * Print sense data and related channel program.
4112 * Parts are printed because printk buffer is only 1024 bytes.
4114 static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
4115 struct dasd_ccw_req *req, struct irb *irb)
4118 struct ccw1 *first, *last, *fail, *from, *to;
4121 page = (char *) get_zeroed_page(GFP_ATOMIC);
4123 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
4124 "No memory to dump sense data\n");
4127 /* dump the sense data */
4128 len = sprintf(page, PRINTK_HEADER
4129 " I/O status report for device %s:\n",
4130 dev_name(&device->cdev->dev));
4131 len += sprintf(page + len, PRINTK_HEADER
4132 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4134 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
4135 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
4136 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
4137 req ? req->intrc : 0);
4138 len += sprintf(page + len, PRINTK_HEADER
4139 " device %s: Failing CCW: %p\n",
4140 dev_name(&device->cdev->dev),
4141 (void *) (addr_t) irb->scsw.cmd.cpa);
4142 if (irb->esw.esw0.erw.cons) {
4143 for (sl = 0; sl < 4; sl++) {
4144 len += sprintf(page + len, PRINTK_HEADER
4145 " Sense(hex) %2d-%2d:",
4146 (8 * sl), ((8 * sl) + 7));
4148 for (sct = 0; sct < 8; sct++) {
4149 len += sprintf(page + len, " %02x",
4150 irb->ecw[8 * sl + sct]);
4152 len += sprintf(page + len, "\n");
4155 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
4156 /* 24 Byte Sense Data */
4157 sprintf(page + len, PRINTK_HEADER
4158 " 24 Byte: %x MSG %x, "
4159 "%s MSGb to SYSOP\n",
4160 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
4161 irb->ecw[1] & 0x10 ? "" : "no");
4163 /* 32 Byte Sense Data */
4164 sprintf(page + len, PRINTK_HEADER
4165 " 32 Byte: Format: %x "
4166 "Exception class %x\n",
4167 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
4170 sprintf(page + len, PRINTK_HEADER
4171 " SORRY - NO VALID SENSE AVAILABLE\n");
4173 printk(KERN_ERR "%s", page);
4176 /* req == NULL for unsolicited interrupts */
4177 /* dump the Channel Program (max 140 Bytes per line) */
4178 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
4179 first = req->cpaddr;
4180 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
4181 to = min(first + 6, last);
4182 len = sprintf(page, PRINTK_HEADER
4183 " Related CP in req: %p\n", req);
4184 dasd_eckd_dump_ccw_range(first, to, page + len);
4185 printk(KERN_ERR "%s", page);
4187 /* print failing CCW area (maximum 4) */
4188 /* scsw->cda is either valid or zero */
4191 fail = (struct ccw1 *)(addr_t)
4192 irb->scsw.cmd.cpa; /* failing CCW */
4193 if (from < fail - 2) {
4194 from = fail - 2; /* there is a gap - print header */
4195 len += sprintf(page, PRINTK_HEADER "......\n");
4197 to = min(fail + 1, last);
4198 len += dasd_eckd_dump_ccw_range(from, to, page + len);
4200 /* print last CCWs (maximum 2) */
4201 from = max(from, ++to);
4202 if (from < last - 1) {
4203 from = last - 1; /* there is a gap - print header */
4204 len += sprintf(page + len, PRINTK_HEADER "......\n");
4206 len += dasd_eckd_dump_ccw_range(from, last, page + len);
4208 printk(KERN_ERR "%s", page);
4210 free_page((unsigned long) page);
4215 * Print sense data from a tcw.
4217 static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
4218 struct dasd_ccw_req *req, struct irb *irb)
4221 int len, sl, sct, residual;
4225 page = (char *) get_zeroed_page(GFP_ATOMIC);
4227 DBF_DEV_EVENT(DBF_WARNING, device, " %s",
4228 "No memory to dump sense data");
4231 /* dump the sense data */
4232 len = sprintf(page, PRINTK_HEADER
4233 " I/O status report for device %s:\n",
4234 dev_name(&device->cdev->dev));
4235 len += sprintf(page + len, PRINTK_HEADER
4236 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
4237 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
4238 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
4239 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
4240 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
4241 irb->scsw.tm.fcxs, irb->scsw.tm.schxs,
4242 req ? req->intrc : 0);
4243 len += sprintf(page + len, PRINTK_HEADER
4244 " device %s: Failing TCW: %p\n",
4245 dev_name(&device->cdev->dev),
4246 (void *) (addr_t) irb->scsw.tm.tcw);
4250 if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01))
4252 (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
4255 len += sprintf(page + len, PRINTK_HEADER
4256 " tsb->length %d\n", tsb->length);
4257 len += sprintf(page + len, PRINTK_HEADER
4258 " tsb->flags %x\n", tsb->flags);
4259 len += sprintf(page + len, PRINTK_HEADER
4260 " tsb->dcw_offset %d\n", tsb->dcw_offset);
4261 len += sprintf(page + len, PRINTK_HEADER
4262 " tsb->count %d\n", tsb->count);
4263 residual = tsb->count - 28;
4264 len += sprintf(page + len, PRINTK_HEADER
4265 " residual %d\n", residual);
4267 switch (tsb->flags & 0x07) {
4268 case 1: /* tsa_iostat */
4269 len += sprintf(page + len, PRINTK_HEADER
4270 " tsb->tsa.iostat.dev_time %d\n",
4271 tsb->tsa.iostat.dev_time);
4272 len += sprintf(page + len, PRINTK_HEADER
4273 " tsb->tsa.iostat.def_time %d\n",
4274 tsb->tsa.iostat.def_time);
4275 len += sprintf(page + len, PRINTK_HEADER
4276 " tsb->tsa.iostat.queue_time %d\n",
4277 tsb->tsa.iostat.queue_time);
4278 len += sprintf(page + len, PRINTK_HEADER
4279 " tsb->tsa.iostat.dev_busy_time %d\n",
4280 tsb->tsa.iostat.dev_busy_time);
4281 len += sprintf(page + len, PRINTK_HEADER
4282 " tsb->tsa.iostat.dev_act_time %d\n",
4283 tsb->tsa.iostat.dev_act_time);
4284 sense = tsb->tsa.iostat.sense;
4286 case 2: /* ts_ddpc */
4287 len += sprintf(page + len, PRINTK_HEADER
4288 " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
4289 for (sl = 0; sl < 2; sl++) {
4290 len += sprintf(page + len, PRINTK_HEADER
4291 " tsb->tsa.ddpc.rcq %2d-%2d: ",
4292 (8 * sl), ((8 * sl) + 7));
4293 rcq = tsb->tsa.ddpc.rcq;
4294 for (sct = 0; sct < 8; sct++) {
4295 len += sprintf(page + len, " %02x",
4298 len += sprintf(page + len, "\n");
4300 sense = tsb->tsa.ddpc.sense;
4302 case 3: /* tsa_intrg */
4303 len += sprintf(page + len, PRINTK_HEADER
4304 " tsb->tsa.intrg.: not supportet yet\n");
4309 for (sl = 0; sl < 4; sl++) {
4310 len += sprintf(page + len, PRINTK_HEADER
4311 " Sense(hex) %2d-%2d:",
4312 (8 * sl), ((8 * sl) + 7));
4313 for (sct = 0; sct < 8; sct++) {
4314 len += sprintf(page + len, " %02x",
4315 sense[8 * sl + sct]);
4317 len += sprintf(page + len, "\n");
4320 if (sense[27] & DASD_SENSE_BIT_0) {
4321 /* 24 Byte Sense Data */
4322 sprintf(page + len, PRINTK_HEADER
4323 " 24 Byte: %x MSG %x, "
4324 "%s MSGb to SYSOP\n",
4325 sense[7] >> 4, sense[7] & 0x0f,
4326 sense[1] & 0x10 ? "" : "no");
4328 /* 32 Byte Sense Data */
4329 sprintf(page + len, PRINTK_HEADER
4330 " 32 Byte: Format: %x "
4331 "Exception class %x\n",
4332 sense[6] & 0x0f, sense[22] >> 4);
4335 sprintf(page + len, PRINTK_HEADER
4336 " SORRY - NO VALID SENSE AVAILABLE\n");
4339 sprintf(page + len, PRINTK_HEADER
4340 " SORRY - NO TSB DATA AVAILABLE\n");
4342 printk(KERN_ERR "%s", page);
4343 free_page((unsigned long) page);
4346 static void dasd_eckd_dump_sense(struct dasd_device *device,
4347 struct dasd_ccw_req *req, struct irb *irb)
4349 if (scsw_is_tm(&irb->scsw))
4350 dasd_eckd_dump_sense_tcw(device, req, irb);
4352 dasd_eckd_dump_sense_ccw(device, req, irb);
4355 static int dasd_eckd_pm_freeze(struct dasd_device *device)
4358 * the device should be disconnected from our LCU structure
4359 * on restore we will reconnect it and reread LCU specific
4360 * information like PAV support that might have changed
4362 dasd_alias_remove_device(device);
4363 dasd_alias_disconnect_device_from_lcu(device);
4368 static int dasd_eckd_restore_device(struct dasd_device *device)
4370 struct dasd_eckd_private *private;
4371 struct dasd_eckd_characteristics temp_rdc_data;
4373 struct dasd_uid temp_uid;
4374 unsigned long flags;
4375 unsigned long cqr_flags = 0;
4377 private = (struct dasd_eckd_private *) device->private;
4379 /* Read Configuration Data */
4380 dasd_eckd_read_conf(device);
4382 dasd_eckd_get_uid(device, &temp_uid);
4383 /* Generate device unique id */
4384 rc = dasd_eckd_generate_uid(device);
4385 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
4386 if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
4387 dev_err(&device->cdev->dev, "The UID of the DASD has "
4389 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4393 /* register lcu with alias handling, enable PAV if this is a new lcu */
4394 rc = dasd_alias_make_device_known_to_lcu(device);
4398 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr_flags);
4399 dasd_eckd_validate_server(device, cqr_flags);
4401 /* RE-Read Configuration Data */
4402 dasd_eckd_read_conf(device);
4404 /* Read Feature Codes */
4405 dasd_eckd_read_features(device);
4407 /* Read Device Characteristics */
4408 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
4409 &temp_rdc_data, 64);
4411 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
4412 "Read device characteristic failed, rc=%d", rc);
4415 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
4416 memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
4417 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4419 /* add device to alias management */
4420 dasd_alias_add_device(device);
4428 static int dasd_eckd_reload_device(struct dasd_device *device)
4430 struct dasd_eckd_private *private;
4433 struct dasd_uid uid;
4434 unsigned long flags;
4436 private = (struct dasd_eckd_private *) device->private;
4438 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
4439 old_base = private->uid.base_unit_addr;
4440 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4442 /* Read Configuration Data */
4443 rc = dasd_eckd_read_conf(device);
4447 rc = dasd_eckd_generate_uid(device);
4451 * update unit address configuration and
4452 * add device to alias management
4454 dasd_alias_update_add_device(device);
4456 dasd_eckd_get_uid(device, &uid);
4458 if (old_base != uid.base_unit_addr) {
4459 if (strlen(uid.vduit) > 0)
4460 snprintf(print_uid, sizeof(print_uid),
4461 "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
4462 uid.ssid, uid.base_unit_addr, uid.vduit);
4464 snprintf(print_uid, sizeof(print_uid),
4465 "%s.%s.%04x.%02x", uid.vendor, uid.serial,
4466 uid.ssid, uid.base_unit_addr);
4468 dev_info(&device->cdev->dev,
4469 "An Alias device was reassigned to a new base device "
4470 "with UID: %s\n", print_uid);
4478 static struct ccw_driver dasd_eckd_driver = {
4480 .name = "dasd-eckd",
4481 .owner = THIS_MODULE,
4483 .ids = dasd_eckd_ids,
4484 .probe = dasd_eckd_probe,
4485 .remove = dasd_generic_remove,
4486 .set_offline = dasd_generic_set_offline,
4487 .set_online = dasd_eckd_set_online,
4488 .notify = dasd_generic_notify,
4489 .path_event = dasd_generic_path_event,
4490 .shutdown = dasd_generic_shutdown,
4491 .freeze = dasd_generic_pm_freeze,
4492 .thaw = dasd_generic_restore_device,
4493 .restore = dasd_generic_restore_device,
4494 .uc_handler = dasd_generic_uc_handler,
4495 .int_class = IRQIO_DAS,
4499 * max_blocks is dependent on the amount of storage that is available
4500 * in the static io buffer for each device. Currently each device has
4501 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
4502 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
4503 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
4504 * addition we have one define extent ccw + 16 bytes of data and one
4505 * locate record ccw + 16 bytes of data. That makes:
4506 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
4507 * We want to fit two into the available memory so that we can immediately
4508 * start the next request if one finishes off. That makes 249.5 blocks
4509 * for one request. Give a little safety and the result is 240.
4511 static struct dasd_discipline dasd_eckd_discipline = {
4512 .owner = THIS_MODULE,
4516 .check_device = dasd_eckd_check_characteristics,
4517 .uncheck_device = dasd_eckd_uncheck_device,
4518 .do_analysis = dasd_eckd_do_analysis,
4519 .verify_path = dasd_eckd_verify_path,
4520 .basic_to_ready = dasd_eckd_basic_to_ready,
4521 .online_to_ready = dasd_eckd_online_to_ready,
4522 .basic_to_known = dasd_eckd_basic_to_known,
4523 .fill_geometry = dasd_eckd_fill_geometry,
4524 .start_IO = dasd_start_IO,
4525 .term_IO = dasd_term_IO,
4526 .handle_terminated_request = dasd_eckd_handle_terminated_request,
4527 .format_device = dasd_eckd_format_device,
4528 .erp_action = dasd_eckd_erp_action,
4529 .erp_postaction = dasd_eckd_erp_postaction,
4530 .check_for_device_change = dasd_eckd_check_for_device_change,
4531 .build_cp = dasd_eckd_build_alias_cp,
4532 .free_cp = dasd_eckd_free_alias_cp,
4533 .dump_sense = dasd_eckd_dump_sense,
4534 .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
4535 .fill_info = dasd_eckd_fill_info,
4536 .ioctl = dasd_eckd_ioctl,
4537 .freeze = dasd_eckd_pm_freeze,
4538 .restore = dasd_eckd_restore_device,
4539 .reload = dasd_eckd_reload_device,
4540 .get_uid = dasd_eckd_get_uid,
4541 .kick_validate = dasd_eckd_kick_validate_server,
4545 dasd_eckd_init(void)
4549 ASCEBC(dasd_eckd_discipline.ebcname, 4);
4550 dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
4551 GFP_KERNEL | GFP_DMA);
4552 if (!dasd_reserve_req)
4554 path_verification_worker = kmalloc(sizeof(*path_verification_worker),
4555 GFP_KERNEL | GFP_DMA);
4556 if (!path_verification_worker) {
4557 kfree(dasd_reserve_req);
4560 rawpadpage = (void *)__get_free_page(GFP_KERNEL);
4562 kfree(path_verification_worker);
4563 kfree(dasd_reserve_req);
4566 ret = ccw_driver_register(&dasd_eckd_driver);
4568 wait_for_device_probe();
4570 kfree(path_verification_worker);
4571 kfree(dasd_reserve_req);
4572 free_page((unsigned long)rawpadpage);
4578 dasd_eckd_cleanup(void)
4580 ccw_driver_unregister(&dasd_eckd_driver);
4581 kfree(path_verification_worker);
4582 kfree(dasd_reserve_req);
4583 free_page((unsigned long)rawpadpage);
4586 module_init(dasd_eckd_init);
4587 module_exit(dasd_eckd_cleanup);