2 * File...........: linux/drivers/s390/block/dasd_eckd.c
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
12 #include <linux/config.h>
13 #include <linux/stddef.h>
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/hdreg.h> /* HDIO_GETGEO */
17 #include <linux/bio.h>
18 #include <linux/module.h>
19 #include <linux/init.h>
21 #include <asm/debug.h>
22 #include <asm/idals.h>
23 #include <asm/ebcdic.h>
25 #include <asm/todclk.h>
26 #include <asm/uaccess.h>
28 #include <asm/ccwdev.h>
31 #include "dasd_eckd.h"
35 #endif /* PRINTK_HEADER */
36 #define PRINTK_HEADER "dasd(eckd):"
38 #define ECKD_C0(i) (i->home_bytes)
39 #define ECKD_F(i) (i->formula)
40 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
41 (i->factors.f_0x02.f1))
42 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
43 (i->factors.f_0x02.f2))
44 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
45 (i->factors.f_0x02.f3))
46 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
47 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
48 #define ECKD_F6(i) (i->factor6)
49 #define ECKD_F7(i) (i->factor7)
50 #define ECKD_F8(i) (i->factor8)
52 MODULE_LICENSE("GPL");
54 static struct dasd_discipline dasd_eckd_discipline;
56 struct dasd_eckd_private {
57 struct dasd_eckd_characteristics rdc_data;
58 struct dasd_eckd_confdata conf_data;
59 struct dasd_eckd_path path_data;
60 struct eckd_count count_area[5];
63 struct attrib_data_t attrib; /* e.g. cache operations */
66 /* The ccw bus type uses this table to find devices that it sends to
68 static struct ccw_device_id dasd_eckd_ids[] = {
69 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), driver_info: 0x1},
70 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), driver_info: 0x2},
71 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), driver_info: 0x3},
72 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), driver_info: 0x4},
73 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), driver_info: 0x5},
74 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), driver_info: 0x6},
75 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), driver_info: 0x7},
76 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), driver_info: 0x8},
77 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), driver_info: 0x9},
78 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), driver_info: 0xa},
79 { /* end of list */ },
82 MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
84 static struct ccw_driver dasd_eckd_driver; /* see below */
86 /* initial attempt at a probe function. this can be simplified once
87 * the other detection code is gone */
89 dasd_eckd_probe (struct ccw_device *cdev)
93 /* set ECKD specific ccw-device options */
94 ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE);
97 "dasd_eckd_probe: could not set ccw-device options "
98 "for %s\n", cdev->dev.bus_id);
101 ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
106 dasd_eckd_set_online(struct ccw_device *cdev)
108 return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
111 static struct ccw_driver dasd_eckd_driver = {
113 .owner = THIS_MODULE,
114 .ids = dasd_eckd_ids,
115 .probe = dasd_eckd_probe,
116 .remove = dasd_generic_remove,
117 .set_offline = dasd_generic_set_offline,
118 .set_online = dasd_eckd_set_online,
119 .notify = dasd_generic_notify,
122 static const int sizes_trk0[] = { 28, 148, 84 };
123 #define LABEL_SIZE 140
125 static inline unsigned int
126 round_up_multiple(unsigned int no, unsigned int mult)
129 return (rem ? no - rem + mult : no);
132 static inline unsigned int
133 ceil_quot(unsigned int d1, unsigned int d2)
135 return (d1 + (d2 - 1)) / d2;
139 bytes_per_record(struct dasd_eckd_characteristics *rdc, int kl, int dl)
141 unsigned int fl1, fl2, int1, int2;
144 switch (rdc->formula) {
146 fl1 = round_up_multiple(ECKD_F2(rdc) + dl, ECKD_F1(rdc));
147 fl2 = round_up_multiple(kl ? ECKD_F2(rdc) + kl : 0,
152 int1 = ceil_quot(dl + ECKD_F6(rdc), ECKD_F5(rdc) << 1);
153 int2 = ceil_quot(kl + ECKD_F6(rdc), ECKD_F5(rdc) << 1);
154 fl1 = round_up_multiple(ECKD_F1(rdc) * ECKD_F2(rdc) + dl +
155 ECKD_F6(rdc) + ECKD_F4(rdc) * int1,
157 fl2 = round_up_multiple(ECKD_F1(rdc) * ECKD_F3(rdc) + kl +
158 ECKD_F6(rdc) + ECKD_F4(rdc) * int2,
169 static inline unsigned int
170 bytes_per_track(struct dasd_eckd_characteristics *rdc)
172 return *(unsigned int *) (rdc->byte_per_track) >> 8;
175 static inline unsigned int
176 recs_per_track(struct dasd_eckd_characteristics * rdc,
177 unsigned int kl, unsigned int dl)
181 switch (rdc->dev_type) {
184 return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
185 ceil_quot(dl + 12, 32));
187 return 1499 / (15 + ceil_quot(dl + 12, 32));
189 dn = ceil_quot(dl + 6, 232) + 1;
191 kn = ceil_quot(kl + 6, 232) + 1;
192 return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
193 9 + ceil_quot(dl + 6 * dn, 34));
195 return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
197 dn = ceil_quot(dl + 6, 232) + 1;
199 kn = ceil_quot(kl + 6, 232) + 1;
200 return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
201 ceil_quot(dl + 6 * dn, 34));
203 return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
209 check_XRC (struct ccw1 *de_ccw,
210 struct DE_eckd_data *data,
211 struct dasd_device *device)
213 struct dasd_eckd_private *private;
215 private = (struct dasd_eckd_private *) device->private;
217 /* switch on System Time Stamp - needed for XRC Support */
218 if (private->rdc_data.facilities.XRC_supported) {
220 data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
221 data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
223 data->ep_sys_time = get_clock ();
225 de_ccw->count = sizeof (struct DE_eckd_data);
226 de_ccw->flags |= CCW_FLAG_SLI;
231 } /* end check_XRC */
234 define_extent(struct ccw1 * ccw, struct DE_eckd_data * data, int trk,
235 int totrk, int cmd, struct dasd_device * device)
237 struct dasd_eckd_private *private;
238 struct ch_t geo, beg, end;
240 private = (struct dasd_eckd_private *) device->private;
242 ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
245 ccw->cda = (__u32) __pa(data);
247 memset(data, 0, sizeof (struct DE_eckd_data));
249 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
250 case DASD_ECKD_CCW_READ_RECORD_ZERO:
251 case DASD_ECKD_CCW_READ:
252 case DASD_ECKD_CCW_READ_MT:
253 case DASD_ECKD_CCW_READ_CKD:
254 case DASD_ECKD_CCW_READ_CKD_MT:
255 case DASD_ECKD_CCW_READ_KD:
256 case DASD_ECKD_CCW_READ_KD_MT:
257 case DASD_ECKD_CCW_READ_COUNT:
258 data->mask.perm = 0x1;
259 data->attributes.operation = private->attrib.operation;
261 case DASD_ECKD_CCW_WRITE:
262 case DASD_ECKD_CCW_WRITE_MT:
263 case DASD_ECKD_CCW_WRITE_KD:
264 case DASD_ECKD_CCW_WRITE_KD_MT:
265 data->mask.perm = 0x02;
266 data->attributes.operation = private->attrib.operation;
267 check_XRC (ccw, data, device);
269 case DASD_ECKD_CCW_WRITE_CKD:
270 case DASD_ECKD_CCW_WRITE_CKD_MT:
271 data->attributes.operation = DASD_BYPASS_CACHE;
272 check_XRC (ccw, data, device);
274 case DASD_ECKD_CCW_ERASE:
275 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
276 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
277 data->mask.perm = 0x3;
278 data->mask.auth = 0x1;
279 data->attributes.operation = DASD_BYPASS_CACHE;
280 check_XRC (ccw, data, device);
283 DEV_MESSAGE(KERN_ERR, device, "unknown opcode 0x%x", cmd);
287 data->attributes.mode = 0x3; /* ECKD */
289 if ((private->rdc_data.cu_type == 0x2105 ||
290 private->rdc_data.cu_type == 0x2107 ||
291 private->rdc_data.cu_type == 0x1750)
292 && !(private->uses_cdl && trk < 2))
293 data->ga_extended |= 0x40; /* Regular Data Format Mode */
295 geo.cyl = private->rdc_data.no_cyl;
296 geo.head = private->rdc_data.trk_per_cyl;
297 beg.cyl = trk / geo.head;
298 beg.head = trk % geo.head;
299 end.cyl = totrk / geo.head;
300 end.head = totrk % geo.head;
302 /* check for sequential prestage - enhance cylinder range */
303 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
304 data->attributes.operation == DASD_SEQ_ACCESS) {
306 if (end.cyl + private->attrib.nr_cyl < geo.cyl)
307 end.cyl += private->attrib.nr_cyl;
309 end.cyl = (geo.cyl - 1);
312 data->beg_ext.cyl = beg.cyl;
313 data->beg_ext.head = beg.head;
314 data->end_ext.cyl = end.cyl;
315 data->end_ext.head = end.head;
319 locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, int trk,
320 int rec_on_trk, int no_rec, int cmd,
321 struct dasd_device * device, int reclen)
323 struct dasd_eckd_private *private;
327 private = (struct dasd_eckd_private *) device->private;
329 DBF_DEV_EVENT(DBF_INFO, device,
330 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
331 trk, rec_on_trk, no_rec, cmd, reclen);
333 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
336 ccw->cda = (__u32) __pa(data);
338 memset(data, 0, sizeof (struct LO_eckd_data));
341 switch (private->rdc_data.dev_type) {
343 dn = ceil_quot(reclen + 6, 232);
344 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
345 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
348 d = 7 + ceil_quot(reclen + 12, 32);
349 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
353 data->sector = sector;
354 data->count = no_rec;
356 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
357 data->operation.orientation = 0x3;
358 data->operation.operation = 0x03;
360 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
361 data->operation.orientation = 0x3;
362 data->operation.operation = 0x16;
364 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
365 data->operation.orientation = 0x1;
366 data->operation.operation = 0x03;
369 case DASD_ECKD_CCW_READ_RECORD_ZERO:
370 data->operation.orientation = 0x3;
371 data->operation.operation = 0x16;
374 case DASD_ECKD_CCW_WRITE:
375 case DASD_ECKD_CCW_WRITE_MT:
376 case DASD_ECKD_CCW_WRITE_KD:
377 case DASD_ECKD_CCW_WRITE_KD_MT:
378 data->auxiliary.last_bytes_used = 0x1;
379 data->length = reclen;
380 data->operation.operation = 0x01;
382 case DASD_ECKD_CCW_WRITE_CKD:
383 case DASD_ECKD_CCW_WRITE_CKD_MT:
384 data->auxiliary.last_bytes_used = 0x1;
385 data->length = reclen;
386 data->operation.operation = 0x03;
388 case DASD_ECKD_CCW_READ:
389 case DASD_ECKD_CCW_READ_MT:
390 case DASD_ECKD_CCW_READ_KD:
391 case DASD_ECKD_CCW_READ_KD_MT:
392 data->auxiliary.last_bytes_used = 0x1;
393 data->length = reclen;
394 data->operation.operation = 0x06;
396 case DASD_ECKD_CCW_READ_CKD:
397 case DASD_ECKD_CCW_READ_CKD_MT:
398 data->auxiliary.last_bytes_used = 0x1;
399 data->length = reclen;
400 data->operation.operation = 0x16;
402 case DASD_ECKD_CCW_READ_COUNT:
403 data->operation.operation = 0x06;
405 case DASD_ECKD_CCW_ERASE:
406 data->length = reclen;
407 data->auxiliary.last_bytes_used = 0x1;
408 data->operation.operation = 0x0b;
411 DEV_MESSAGE(KERN_ERR, device, "unknown opcode 0x%x", cmd);
413 data->seek_addr.cyl = data->search_arg.cyl =
414 trk / private->rdc_data.trk_per_cyl;
415 data->seek_addr.head = data->search_arg.head =
416 trk % private->rdc_data.trk_per_cyl;
417 data->search_arg.record = rec_on_trk;
421 * Returns 1 if the block is one of the special blocks that needs
422 * to get read/written with the KD variant of the command.
423 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
424 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
425 * Luckily the KD variants differ only by one bit (0x08) from the
426 * normal variant. So don't wonder about code like:
427 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
428 * ccw->cmd_code |= 0x8;
431 dasd_eckd_cdl_special(int blk_per_trk, int recid)
435 if (recid < blk_per_trk)
437 if (recid < 2 * blk_per_trk)
443 * Returns the record size for the special blocks of the cdl format.
444 * Only returns something useful if dasd_eckd_cdl_special is true
448 dasd_eckd_cdl_reclen(int recid)
451 return sizes_trk0[recid];
456 * Generate device unique id that specifies the physical device.
459 dasd_eckd_generate_uid(struct dasd_device *device, struct dasd_uid *uid)
461 struct dasd_eckd_private *private;
462 struct dasd_eckd_confdata *confdata;
464 private = (struct dasd_eckd_private *) device->private;
467 confdata = &private->conf_data;
471 memset(uid, 0, sizeof(struct dasd_uid));
472 strncpy(uid->vendor, confdata->ned1.HDA_manufacturer,
473 sizeof(uid->vendor) - 1);
474 EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
475 strncpy(uid->serial, confdata->ned1.HDA_location,
476 sizeof(uid->serial) - 1);
477 EBCASC(uid->serial, sizeof(uid->serial) - 1);
478 uid->ssid = confdata->neq.subsystemID;
479 if (confdata->ned2.sneq.flags == 0x40) {
481 uid->unit_addr = confdata->ned2.sneq.base_unit_addr;
483 uid->unit_addr = confdata->ned1.unit_addr;
489 dasd_eckd_read_conf(struct dasd_device *device)
492 int conf_len, conf_data_saved;
495 struct dasd_eckd_private *private;
496 struct dasd_eckd_path *path_data;
498 private = (struct dasd_eckd_private *) device->private;
499 path_data = (struct dasd_eckd_path *) &private->path_data;
500 path_data->opm = ccw_device_get_path_mask(device->cdev);
504 /* get configuration data per operational path */
505 for (lpm = 0x80; lpm; lpm>>= 1) {
506 if (lpm & path_data->opm){
507 rc = read_conf_data_lpm(device->cdev, &conf_data,
509 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
510 MESSAGE(KERN_WARNING,
511 "Read configuration data returned "
515 if (conf_data == NULL) {
516 MESSAGE(KERN_WARNING, "%s", "No configuration "
518 continue; /* no errror */
520 if (conf_len != sizeof (struct dasd_eckd_confdata)) {
521 MESSAGE(KERN_WARNING,
522 "sizes of configuration data mismatch"
523 "%d (read) vs %ld (expected)",
525 sizeof (struct dasd_eckd_confdata));
527 continue; /* no errror */
529 /* save first valid configuration data */
530 if (!conf_data_saved){
531 memcpy(&private->conf_data, conf_data,
532 sizeof (struct dasd_eckd_confdata));
535 switch (((char *)conf_data)[242] & 0x07){
537 path_data->npm |= lpm;
540 path_data->ppm |= lpm;
550 * Build CP for Perform Subsystem Function - SSC.
552 struct dasd_ccw_req *
553 dasd_eckd_build_psf_ssc(struct dasd_device *device)
555 struct dasd_ccw_req *cqr;
556 struct dasd_psf_ssc_data *psf_ssc_data;
559 cqr = dasd_smalloc_request("ECKD", 1 /* PSF */ ,
560 sizeof(struct dasd_psf_ssc_data),
564 DEV_MESSAGE(KERN_WARNING, device, "%s",
565 "Could not allocate PSF-SSC request");
568 psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
569 psf_ssc_data->order = PSF_ORDER_SSC;
570 psf_ssc_data->suborder = 0x08;
573 ccw->cmd_code = DASD_ECKD_CCW_PSF;
574 ccw->cda = (__u32)(addr_t)psf_ssc_data;
577 cqr->device = device;
578 cqr->expires = 10*HZ;
579 cqr->buildclk = get_clock();
580 cqr->status = DASD_CQR_FILLED;
585 * Perform Subsystem Function.
586 * It is necessary to trigger CIO for channel revalidation since this
587 * call might change behaviour of DASD devices.
590 dasd_eckd_psf_ssc(struct dasd_device *device)
592 struct dasd_ccw_req *cqr;
595 cqr = dasd_eckd_build_psf_ssc(device);
599 rc = dasd_sleep_on(cqr);
601 /* trigger CIO to reprobe devices */
602 css_schedule_reprobe();
603 dasd_sfree_request(cqr, cqr->device);
608 * Valide storage server of current device.
611 dasd_eckd_validate_server(struct dasd_device *device)
615 /* Currently PAV is the only reason to 'validate' server on LPAR */
616 if (dasd_nopav || MACHINE_IS_VM)
619 rc = dasd_eckd_psf_ssc(device);
621 /* may be requested feature is not available on server,
622 * therefore just report error and go ahead */
623 DEV_MESSAGE(KERN_INFO, device,
624 "Perform Subsystem Function returned rc=%d", rc);
625 /* RE-Read Configuration Data */
626 return dasd_eckd_read_conf(device);
630 * Check device characteristics.
631 * If the device is accessible using ECKD discipline, the device is enabled.
634 dasd_eckd_check_characteristics(struct dasd_device *device)
636 struct dasd_eckd_private *private;
641 private = (struct dasd_eckd_private *) device->private;
642 if (private == NULL) {
643 private = kzalloc(sizeof(struct dasd_eckd_private),
644 GFP_KERNEL | GFP_DMA);
645 if (private == NULL) {
646 DEV_MESSAGE(KERN_WARNING, device, "%s",
647 "memory allocation failed for private "
651 device->private = (void *) private;
653 /* Invalidate status of initial analysis. */
654 private->init_cqr_status = -1;
655 /* Set default cache operations. */
656 private->attrib.operation = DASD_NORMAL_CACHE;
657 private->attrib.nr_cyl = 0;
659 /* Read Configuration Data */
660 rc = dasd_eckd_read_conf(device);
664 /* Generate device unique id and register in devmap */
665 rc = dasd_eckd_generate_uid(device, &uid);
668 rc = dasd_set_uid(device->cdev, &uid);
669 if (rc == 1) /* new server found */
670 rc = dasd_eckd_validate_server(device);
674 /* Read Device Characteristics */
675 rdc_data = (void *) &(private->rdc_data);
676 memset(rdc_data, 0, sizeof(rdc_data));
677 rc = read_dev_chars(device->cdev, &rdc_data, 64);
679 DEV_MESSAGE(KERN_WARNING, device,
680 "Read device characteristics returned "
683 DEV_MESSAGE(KERN_INFO, device,
684 "%04X/%02X(CU:%04X/%02X) Cyl:%d Head:%d Sec:%d",
685 private->rdc_data.dev_type,
686 private->rdc_data.dev_model,
687 private->rdc_data.cu_type,
688 private->rdc_data.cu_model.model,
689 private->rdc_data.no_cyl,
690 private->rdc_data.trk_per_cyl,
691 private->rdc_data.sec_per_trk);
695 static struct dasd_ccw_req *
696 dasd_eckd_analysis_ccw(struct dasd_device *device)
698 struct dasd_eckd_private *private;
699 struct eckd_count *count_data;
700 struct LO_eckd_data *LO_data;
701 struct dasd_ccw_req *cqr;
703 int cplength, datasize;
706 private = (struct dasd_eckd_private *) device->private;
709 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
710 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
711 cplength, datasize, device);
715 /* Define extent for the first 3 tracks. */
716 define_extent(ccw++, cqr->data, 0, 2,
717 DASD_ECKD_CCW_READ_COUNT, device);
718 LO_data = cqr->data + sizeof (struct DE_eckd_data);
719 /* Locate record for the first 4 records on track 0. */
720 ccw[-1].flags |= CCW_FLAG_CC;
721 locate_record(ccw++, LO_data++, 0, 0, 4,
722 DASD_ECKD_CCW_READ_COUNT, device, 0);
724 count_data = private->count_area;
725 for (i = 0; i < 4; i++) {
726 ccw[-1].flags |= CCW_FLAG_CC;
727 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
730 ccw->cda = (__u32)(addr_t) count_data;
735 /* Locate record for the first record on track 2. */
736 ccw[-1].flags |= CCW_FLAG_CC;
737 locate_record(ccw++, LO_data++, 2, 0, 1,
738 DASD_ECKD_CCW_READ_COUNT, device, 0);
739 /* Read count ccw. */
740 ccw[-1].flags |= CCW_FLAG_CC;
741 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
744 ccw->cda = (__u32)(addr_t) count_data;
746 cqr->device = device;
748 cqr->buildclk = get_clock();
749 cqr->status = DASD_CQR_FILLED;
754 * This is the callback function for the init_analysis cqr. It saves
755 * the status of the initial analysis ccw before it frees it and kicks
756 * the device to continue the startup sequence. This will call
757 * dasd_eckd_do_analysis again (if the devices has not been marked
758 * for deletion in the meantime).
761 dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, void *data)
763 struct dasd_eckd_private *private;
764 struct dasd_device *device;
766 device = init_cqr->device;
767 private = (struct dasd_eckd_private *) device->private;
768 private->init_cqr_status = init_cqr->status;
769 dasd_sfree_request(init_cqr, device);
770 dasd_kick_device(device);
774 dasd_eckd_start_analysis(struct dasd_device *device)
776 struct dasd_eckd_private *private;
777 struct dasd_ccw_req *init_cqr;
779 private = (struct dasd_eckd_private *) device->private;
780 init_cqr = dasd_eckd_analysis_ccw(device);
781 if (IS_ERR(init_cqr))
782 return PTR_ERR(init_cqr);
783 init_cqr->callback = dasd_eckd_analysis_callback;
784 init_cqr->callback_data = NULL;
785 init_cqr->expires = 5*HZ;
786 dasd_add_request_head(init_cqr);
791 dasd_eckd_end_analysis(struct dasd_device *device)
793 struct dasd_eckd_private *private;
794 struct eckd_count *count_area;
795 unsigned int sb, blk_per_trk;
798 private = (struct dasd_eckd_private *) device->private;
799 status = private->init_cqr_status;
800 private->init_cqr_status = -1;
801 if (status != DASD_CQR_DONE) {
802 DEV_MESSAGE(KERN_WARNING, device, "%s",
803 "volume analysis returned unformatted disk");
807 private->uses_cdl = 1;
808 /* Calculate number of blocks/records per track. */
809 blk_per_trk = recs_per_track(&private->rdc_data, 0, device->bp_block);
810 /* Check Track 0 for Compatible Disk Layout */
812 for (i = 0; i < 3; i++) {
813 if (private->count_area[i].kl != 4 ||
814 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
815 private->uses_cdl = 0;
820 count_area = &private->count_area[4];
822 if (private->uses_cdl == 0) {
823 for (i = 0; i < 5; i++) {
824 if ((private->count_area[i].kl != 0) ||
825 (private->count_area[i].dl !=
826 private->count_area[0].dl))
830 count_area = &private->count_area[0];
832 if (private->count_area[3].record == 1)
833 DEV_MESSAGE(KERN_WARNING, device, "%s",
834 "Trk 0: no records after VTOC!");
836 if (count_area != NULL && count_area->kl == 0) {
837 /* we found notthing violating our disk layout */
838 if (dasd_check_blocksize(count_area->dl) == 0)
839 device->bp_block = count_area->dl;
841 if (device->bp_block == 0) {
842 DEV_MESSAGE(KERN_WARNING, device, "%s",
843 "Volume has incompatible disk layout");
846 device->s2b_shift = 0; /* bits to shift 512 to get a block */
847 for (sb = 512; sb < device->bp_block; sb = sb << 1)
850 blk_per_trk = recs_per_track(&private->rdc_data, 0, device->bp_block);
851 device->blocks = (private->rdc_data.no_cyl *
852 private->rdc_data.trk_per_cyl *
855 DEV_MESSAGE(KERN_INFO, device,
856 "(%dkB blks): %dkB at %dkB/trk %s",
857 (device->bp_block >> 10),
858 ((private->rdc_data.no_cyl *
859 private->rdc_data.trk_per_cyl *
860 blk_per_trk * (device->bp_block >> 9)) >> 1),
861 ((blk_per_trk * device->bp_block) >> 10),
863 "compatible disk layout" : "linux disk layout");
869 dasd_eckd_do_analysis(struct dasd_device *device)
871 struct dasd_eckd_private *private;
873 private = (struct dasd_eckd_private *) device->private;
874 if (private->init_cqr_status < 0)
875 return dasd_eckd_start_analysis(device);
877 return dasd_eckd_end_analysis(device);
881 dasd_eckd_fill_geometry(struct dasd_device *device, struct hd_geometry *geo)
883 struct dasd_eckd_private *private;
885 private = (struct dasd_eckd_private *) device->private;
886 if (dasd_check_blocksize(device->bp_block) == 0) {
887 geo->sectors = recs_per_track(&private->rdc_data,
888 0, device->bp_block);
890 geo->cylinders = private->rdc_data.no_cyl;
891 geo->heads = private->rdc_data.trk_per_cyl;
895 static struct dasd_ccw_req *
896 dasd_eckd_format_device(struct dasd_device * device,
897 struct format_data_t * fdata)
899 struct dasd_eckd_private *private;
900 struct dasd_ccw_req *fcp;
901 struct eckd_count *ect;
905 int cplength, datasize;
908 private = (struct dasd_eckd_private *) device->private;
909 rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
910 cyl = fdata->start_unit / private->rdc_data.trk_per_cyl;
911 head = fdata->start_unit % private->rdc_data.trk_per_cyl;
914 if (fdata->start_unit >=
915 (private->rdc_data.no_cyl * private->rdc_data.trk_per_cyl)) {
916 DEV_MESSAGE(KERN_INFO, device, "Track no %d too big!",
918 return ERR_PTR(-EINVAL);
920 if (fdata->start_unit > fdata->stop_unit) {
921 DEV_MESSAGE(KERN_INFO, device, "Track %d reached! ending.",
923 return ERR_PTR(-EINVAL);
925 if (dasd_check_blocksize(fdata->blksize) != 0) {
926 DEV_MESSAGE(KERN_WARNING, device,
927 "Invalid blocksize %d...terminating!",
929 return ERR_PTR(-EINVAL);
933 * fdata->intensity is a bit string that tells us what to do:
934 * Bit 0: write record zero
935 * Bit 1: write home address, currently not supported
936 * Bit 2: invalidate tracks
937 * Bit 3: use OS/390 compatible disk layout (cdl)
938 * Only some bit combinations do make sense.
940 switch (fdata->intensity) {
941 case 0x00: /* Normal format */
942 case 0x08: /* Normal format, use cdl. */
944 datasize = sizeof(struct DE_eckd_data) +
945 sizeof(struct LO_eckd_data) +
946 rpt * sizeof(struct eckd_count);
948 case 0x01: /* Write record zero and format track. */
949 case 0x09: /* Write record zero and format track, use cdl. */
951 datasize = sizeof(struct DE_eckd_data) +
952 sizeof(struct LO_eckd_data) +
953 sizeof(struct eckd_count) +
954 rpt * sizeof(struct eckd_count);
956 case 0x04: /* Invalidate track. */
957 case 0x0c: /* Invalidate track, use cdl. */
959 datasize = sizeof(struct DE_eckd_data) +
960 sizeof(struct LO_eckd_data) +
961 sizeof(struct eckd_count);
964 DEV_MESSAGE(KERN_WARNING, device, "Invalid flags 0x%x.",
966 return ERR_PTR(-EINVAL);
968 /* Allocate the format ccw request. */
969 fcp = dasd_smalloc_request(dasd_eckd_discipline.name,
970 cplength, datasize, device);
977 switch (fdata->intensity & ~0x08) {
978 case 0x00: /* Normal format. */
979 define_extent(ccw++, (struct DE_eckd_data *) data,
980 fdata->start_unit, fdata->start_unit,
981 DASD_ECKD_CCW_WRITE_CKD, device);
982 data += sizeof(struct DE_eckd_data);
983 ccw[-1].flags |= CCW_FLAG_CC;
984 locate_record(ccw++, (struct LO_eckd_data *) data,
985 fdata->start_unit, 0, rpt,
986 DASD_ECKD_CCW_WRITE_CKD, device,
988 data += sizeof(struct LO_eckd_data);
990 case 0x01: /* Write record zero + format track. */
991 define_extent(ccw++, (struct DE_eckd_data *) data,
992 fdata->start_unit, fdata->start_unit,
993 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
995 data += sizeof(struct DE_eckd_data);
996 ccw[-1].flags |= CCW_FLAG_CC;
997 locate_record(ccw++, (struct LO_eckd_data *) data,
998 fdata->start_unit, 0, rpt + 1,
999 DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
1001 data += sizeof(struct LO_eckd_data);
1003 case 0x04: /* Invalidate track. */
1004 define_extent(ccw++, (struct DE_eckd_data *) data,
1005 fdata->start_unit, fdata->start_unit,
1006 DASD_ECKD_CCW_WRITE_CKD, device);
1007 data += sizeof(struct DE_eckd_data);
1008 ccw[-1].flags |= CCW_FLAG_CC;
1009 locate_record(ccw++, (struct LO_eckd_data *) data,
1010 fdata->start_unit, 0, 1,
1011 DASD_ECKD_CCW_WRITE_CKD, device, 8);
1012 data += sizeof(struct LO_eckd_data);
1015 if (fdata->intensity & 0x01) { /* write record zero */
1016 ect = (struct eckd_count *) data;
1017 data += sizeof(struct eckd_count);
1023 ccw[-1].flags |= CCW_FLAG_CC;
1024 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
1025 ccw->flags = CCW_FLAG_SLI;
1027 ccw->cda = (__u32)(addr_t) ect;
1030 if ((fdata->intensity & ~0x08) & 0x04) { /* erase track */
1031 ect = (struct eckd_count *) data;
1032 data += sizeof(struct eckd_count);
1038 ccw[-1].flags |= CCW_FLAG_CC;
1039 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1040 ccw->flags = CCW_FLAG_SLI;
1042 ccw->cda = (__u32)(addr_t) ect;
1043 } else { /* write remaining records */
1044 for (i = 0; i < rpt; i++) {
1045 ect = (struct eckd_count *) data;
1046 data += sizeof(struct eckd_count);
1049 ect->record = i + 1;
1051 ect->dl = fdata->blksize;
1052 /* Check for special tracks 0-1 when formatting CDL */
1053 if ((fdata->intensity & 0x08) &&
1054 fdata->start_unit == 0) {
1057 ect->dl = sizes_trk0[i] - 4;
1060 if ((fdata->intensity & 0x08) &&
1061 fdata->start_unit == 1) {
1063 ect->dl = LABEL_SIZE - 44;
1065 ccw[-1].flags |= CCW_FLAG_CC;
1066 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
1067 ccw->flags = CCW_FLAG_SLI;
1069 ccw->cda = (__u32)(addr_t) ect;
1073 fcp->device = device;
1074 fcp->retries = 2; /* set retry counter to enable ERP */
1075 fcp->buildclk = get_clock();
1076 fcp->status = DASD_CQR_FILLED;
1081 dasd_eckd_examine_error(struct dasd_ccw_req * cqr, struct irb * irb)
1083 struct dasd_device *device = (struct dasd_device *) cqr->device;
1084 struct ccw_device *cdev = device->cdev;
1086 if (irb->scsw.cstat == 0x00 &&
1087 irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END))
1088 return dasd_era_none;
1090 switch (cdev->id.cu_type) {
1095 return dasd_3990_erp_examine(cqr, irb);
1097 return dasd_9343_erp_examine(cqr, irb);
1100 DEV_MESSAGE(KERN_WARNING, device, "%s",
1101 "default (unknown CU type) - RECOVERABLE return");
1102 return dasd_era_recover;
1106 static dasd_erp_fn_t
1107 dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
1109 struct dasd_device *device = (struct dasd_device *) cqr->device;
1110 struct ccw_device *cdev = device->cdev;
1112 switch (cdev->id.cu_type) {
1117 return dasd_3990_erp_action;
1121 return dasd_default_erp_action;
1125 static dasd_erp_fn_t
1126 dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
1128 return dasd_default_erp_postaction;
1131 static struct dasd_ccw_req *
1132 dasd_eckd_build_cp(struct dasd_device * device, struct request *req)
1134 struct dasd_eckd_private *private;
1135 unsigned long *idaws;
1136 struct LO_eckd_data *LO_data;
1137 struct dasd_ccw_req *cqr;
1142 unsigned int blksize, blk_per_trk, off;
1143 int count, cidaw, cplength, datasize;
1144 sector_t recid, first_rec, last_rec;
1145 sector_t first_trk, last_trk;
1146 unsigned int first_offs, last_offs;
1147 unsigned char cmd, rcmd;
1150 private = (struct dasd_eckd_private *) device->private;
1151 if (rq_data_dir(req) == READ)
1152 cmd = DASD_ECKD_CCW_READ_MT;
1153 else if (rq_data_dir(req) == WRITE)
1154 cmd = DASD_ECKD_CCW_WRITE_MT;
1156 return ERR_PTR(-EINVAL);
1157 /* Calculate number of blocks/records per track. */
1158 blksize = device->bp_block;
1159 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
1160 /* Calculate record id of first and last block. */
1161 first_rec = first_trk = req->sector >> device->s2b_shift;
1162 first_offs = sector_div(first_trk, blk_per_trk);
1163 last_rec = last_trk =
1164 (req->sector + req->nr_sectors - 1) >> device->s2b_shift;
1165 last_offs = sector_div(last_trk, blk_per_trk);
1166 /* Check struct bio and count the number of blocks for the request. */
1169 rq_for_each_bio(bio, req) {
1170 bio_for_each_segment(bv, bio, i) {
1171 if (bv->bv_len & (blksize - 1))
1172 /* Eckd can only do full blocks. */
1173 return ERR_PTR(-EINVAL);
1174 count += bv->bv_len >> (device->s2b_shift + 9);
1175 #if defined(CONFIG_64BIT)
1176 if (idal_is_needed (page_address(bv->bv_page),
1178 cidaw += bv->bv_len >> (device->s2b_shift + 9);
1183 if (count != last_rec - first_rec + 1)
1184 return ERR_PTR(-EINVAL);
1185 /* 1x define extent + 1x locate record + number of blocks */
1186 cplength = 2 + count;
1187 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
1188 datasize = sizeof(struct DE_eckd_data) + sizeof(struct LO_eckd_data) +
1189 cidaw * sizeof(unsigned long);
1190 /* Find out the number of additional locate record ccws for cdl. */
1191 if (private->uses_cdl && first_rec < 2*blk_per_trk) {
1192 if (last_rec >= 2*blk_per_trk)
1193 count = 2*blk_per_trk - first_rec;
1195 datasize += count*sizeof(struct LO_eckd_data);
1197 /* Allocate the ccw request. */
1198 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1199 cplength, datasize, device);
1203 /* First ccw is define extent. */
1204 define_extent(ccw++, cqr->data, first_trk, last_trk, cmd, device);
1205 /* Build locate_record+read/write/ccws. */
1206 idaws = (unsigned long *) (cqr->data + sizeof(struct DE_eckd_data));
1207 LO_data = (struct LO_eckd_data *) (idaws + cidaw);
1209 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
1210 /* Only standard blocks so there is just one locate record. */
1211 ccw[-1].flags |= CCW_FLAG_CC;
1212 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
1213 last_rec - recid + 1, cmd, device, blksize);
1215 rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) {
1216 dst = page_address(bv->bv_page) + bv->bv_offset;
1217 if (dasd_page_cache) {
1218 char *copy = kmem_cache_alloc(dasd_page_cache,
1219 SLAB_DMA | __GFP_NOWARN);
1220 if (copy && rq_data_dir(req) == WRITE)
1221 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
1223 dst = copy + bv->bv_offset;
1225 for (off = 0; off < bv->bv_len; off += blksize) {
1226 sector_t trkid = recid;
1227 unsigned int recoffs = sector_div(trkid, blk_per_trk);
1230 /* Locate record for cdl special block ? */
1231 if (private->uses_cdl && recid < 2*blk_per_trk) {
1232 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
1234 count = dasd_eckd_cdl_reclen(recid);
1235 if (count < blksize &&
1236 rq_data_dir(req) == READ)
1237 memset(dst + count, 0xe5,
1240 ccw[-1].flags |= CCW_FLAG_CC;
1241 locate_record(ccw++, LO_data++,
1243 1, rcmd, device, count);
1245 /* Locate record for standard blocks ? */
1246 if (private->uses_cdl && recid == 2*blk_per_trk) {
1247 ccw[-1].flags |= CCW_FLAG_CC;
1248 locate_record(ccw++, LO_data++,
1250 last_rec - recid + 1,
1251 cmd, device, count);
1253 /* Read/write ccw. */
1254 ccw[-1].flags |= CCW_FLAG_CC;
1255 ccw->cmd_code = rcmd;
1257 if (idal_is_needed(dst, blksize)) {
1258 ccw->cda = (__u32)(addr_t) idaws;
1259 ccw->flags = CCW_FLAG_IDA;
1260 idaws = idal_create_words(idaws, dst, blksize);
1262 ccw->cda = (__u32)(addr_t) dst;
1270 if (req->flags & REQ_FAILFAST)
1271 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1272 cqr->device = device;
1273 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
1274 cqr->lpm = private->path_data.ppm;
1276 cqr->buildclk = get_clock();
1277 cqr->status = DASD_CQR_FILLED;
1282 dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
1284 struct dasd_eckd_private *private;
1289 unsigned int blksize, blk_per_trk, off;
1293 if (!dasd_page_cache)
1295 private = (struct dasd_eckd_private *) cqr->device->private;
1296 blksize = cqr->device->bp_block;
1297 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
1298 recid = req->sector >> cqr->device->s2b_shift;
1300 /* Skip over define extent & locate record. */
1302 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
1304 rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) {
1305 dst = page_address(bv->bv_page) + bv->bv_offset;
1306 for (off = 0; off < bv->bv_len; off += blksize) {
1307 /* Skip locate record. */
1308 if (private->uses_cdl && recid <= 2*blk_per_trk)
1311 if (ccw->flags & CCW_FLAG_IDA)
1312 cda = *((char **)((addr_t) ccw->cda));
1314 cda = (char *)((addr_t) ccw->cda);
1316 if (rq_data_dir(req) == READ)
1317 memcpy(dst, cda, bv->bv_len);
1318 kmem_cache_free(dasd_page_cache,
1319 (void *)((addr_t)cda & PAGE_MASK));
1328 status = cqr->status == DASD_CQR_DONE;
1329 dasd_sfree_request(cqr, cqr->device);
1334 dasd_eckd_fill_info(struct dasd_device * device,
1335 struct dasd_information2_t * info)
1337 struct dasd_eckd_private *private;
1339 private = (struct dasd_eckd_private *) device->private;
1340 info->label_block = 2;
1341 info->FBA_layout = private->uses_cdl ? 0 : 1;
1342 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
1343 info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
1344 memcpy(info->characteristics, &private->rdc_data,
1345 sizeof(struct dasd_eckd_characteristics));
1346 info->confdata_size = sizeof (struct dasd_eckd_confdata);
1347 memcpy(info->configuration_data, &private->conf_data,
1348 sizeof (struct dasd_eckd_confdata));
1353 * SECTION: ioctl functions for eckd devices.
1357 * Release device ioctl.
1358 * Buils a channel programm to releases a prior reserved
1359 * (see dasd_eckd_reserve) device.
1362 dasd_eckd_release(struct dasd_device *device)
1364 struct dasd_ccw_req *cqr;
1367 if (!capable(CAP_SYS_ADMIN))
1370 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1373 DEV_MESSAGE(KERN_WARNING, device, "%s",
1374 "Could not allocate initialization request");
1375 return PTR_ERR(cqr);
1377 cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RELEASE;
1378 cqr->cpaddr->flags |= CCW_FLAG_SLI;
1379 cqr->cpaddr->count = 32;
1380 cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
1381 cqr->device = device;
1382 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1383 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1385 cqr->expires = 2 * HZ;
1386 cqr->buildclk = get_clock();
1387 cqr->status = DASD_CQR_FILLED;
1389 rc = dasd_sleep_on_immediatly(cqr);
1391 dasd_sfree_request(cqr, cqr->device);
1396 * Reserve device ioctl.
1397 * Options are set to 'synchronous wait for interrupt' and
1398 * 'timeout the request'. This leads to a terminate IO if
1399 * the interrupt is outstanding for a certain time.
1402 dasd_eckd_reserve(struct dasd_device *device)
1404 struct dasd_ccw_req *cqr;
1407 if (!capable(CAP_SYS_ADMIN))
1410 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1413 DEV_MESSAGE(KERN_WARNING, device, "%s",
1414 "Could not allocate initialization request");
1415 return PTR_ERR(cqr);
1417 cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RESERVE;
1418 cqr->cpaddr->flags |= CCW_FLAG_SLI;
1419 cqr->cpaddr->count = 32;
1420 cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
1421 cqr->device = device;
1422 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1423 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1425 cqr->expires = 2 * HZ;
1426 cqr->buildclk = get_clock();
1427 cqr->status = DASD_CQR_FILLED;
1429 rc = dasd_sleep_on_immediatly(cqr);
1431 dasd_sfree_request(cqr, cqr->device);
1436 * Steal lock ioctl - unconditional reserve device.
1437 * Buils a channel programm to break a device's reservation.
1438 * (unconditional reserve)
1441 dasd_eckd_steal_lock(struct dasd_device *device)
1443 struct dasd_ccw_req *cqr;
1446 if (!capable(CAP_SYS_ADMIN))
1449 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1452 DEV_MESSAGE(KERN_WARNING, device, "%s",
1453 "Could not allocate initialization request");
1454 return PTR_ERR(cqr);
1456 cqr->cpaddr->cmd_code = DASD_ECKD_CCW_SLCK;
1457 cqr->cpaddr->flags |= CCW_FLAG_SLI;
1458 cqr->cpaddr->count = 32;
1459 cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
1460 cqr->device = device;
1461 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1462 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1464 cqr->expires = 2 * HZ;
1465 cqr->buildclk = get_clock();
1466 cqr->status = DASD_CQR_FILLED;
1468 rc = dasd_sleep_on_immediatly(cqr);
1470 dasd_sfree_request(cqr, cqr->device);
1475 * Read performance statistics
1478 dasd_eckd_performance(struct dasd_device *device, void __user *argp)
1480 struct dasd_psf_prssd_data *prssdp;
1481 struct dasd_rssd_perf_stats_t *stats;
1482 struct dasd_ccw_req *cqr;
1486 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1487 1 /* PSF */ + 1 /* RSSD */ ,
1488 (sizeof (struct dasd_psf_prssd_data) +
1489 sizeof (struct dasd_rssd_perf_stats_t)),
1492 DEV_MESSAGE(KERN_WARNING, device, "%s",
1493 "Could not allocate initialization request");
1494 return PTR_ERR(cqr);
1496 cqr->device = device;
1498 cqr->expires = 10 * HZ;
1500 /* Prepare for Read Subsystem Data */
1501 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1502 memset(prssdp, 0, sizeof (struct dasd_psf_prssd_data));
1503 prssdp->order = PSF_ORDER_PRSSD;
1504 prssdp->suborder = 0x01; /* Perfomance Statistics */
1505 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
1508 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1509 ccw->count = sizeof (struct dasd_psf_prssd_data);
1510 ccw->flags |= CCW_FLAG_CC;
1511 ccw->cda = (__u32)(addr_t) prssdp;
1513 /* Read Subsystem Data - Performance Statistics */
1514 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
1515 memset(stats, 0, sizeof (struct dasd_rssd_perf_stats_t));
1518 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
1519 ccw->count = sizeof (struct dasd_rssd_perf_stats_t);
1520 ccw->cda = (__u32)(addr_t) stats;
1522 cqr->buildclk = get_clock();
1523 cqr->status = DASD_CQR_FILLED;
1524 rc = dasd_sleep_on(cqr);
1526 /* Prepare for Read Subsystem Data */
1527 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1528 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
1529 if (copy_to_user(argp, stats,
1530 sizeof(struct dasd_rssd_perf_stats_t)))
1533 dasd_sfree_request(cqr, cqr->device);
1538 * Get attributes (cache operations)
1539 * Returnes the cache attributes used in Define Extend (DE).
1542 dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
1544 struct dasd_eckd_private *private =
1545 (struct dasd_eckd_private *)device->private;
1546 struct attrib_data_t attrib = private->attrib;
1549 if (!capable(CAP_SYS_ADMIN))
1555 if (copy_to_user(argp, (long *) &attrib,
1556 sizeof (struct attrib_data_t)))
1563 * Set attributes (cache operations)
1564 * Stores the attributes for cache operation to be used in Define Extend (DE).
1567 dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
1569 struct dasd_eckd_private *private =
1570 (struct dasd_eckd_private *)device->private;
1571 struct attrib_data_t attrib;
1573 if (!capable(CAP_SYS_ADMIN))
1578 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
1580 private->attrib = attrib;
1582 DEV_MESSAGE(KERN_INFO, device,
1583 "cache operation mode set to %x (%i cylinder prestage)",
1584 private->attrib.operation, private->attrib.nr_cyl);
1589 dasd_eckd_ioctl(struct dasd_device *device, unsigned int cmd, void __user *argp)
1593 return dasd_eckd_get_attrib(device, argp);
1595 return dasd_eckd_set_attrib(device, argp);
1597 return dasd_eckd_performance(device, argp);
1599 return dasd_eckd_release(device);
1601 return dasd_eckd_reserve(device);
1603 return dasd_eckd_steal_lock(device);
1605 return -ENOIOCTLCMD;
1610 * Dump the range of CCWs into 'page' buffer
1611 * and return number of printed chars.
1614 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
1620 while (from <= to) {
1621 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
1622 " CCW %p: %08X %08X DAT:",
1623 from, ((int *) from)[0], ((int *) from)[1]);
1625 /* get pointer to data (consider IDALs) */
1626 if (from->flags & CCW_FLAG_IDA)
1627 datap = (char *) *((addr_t *) (addr_t) from->cda);
1629 datap = (char *) ((addr_t) from->cda);
1631 /* dump data (max 32 bytes) */
1632 for (count = 0; count < from->count && count < 32; count++) {
1633 if (count % 8 == 0) len += sprintf(page + len, " ");
1634 if (count % 4 == 0) len += sprintf(page + len, " ");
1635 len += sprintf(page + len, "%02x", datap[count]);
1637 len += sprintf(page + len, "\n");
1644 * Print sense data and related channel program.
1645 * Parts are printed because printk buffer is only 1024 bytes.
1648 dasd_eckd_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
1652 struct ccw1 *first, *last, *fail, *from, *to;
1655 page = (char *) get_zeroed_page(GFP_ATOMIC);
1657 DEV_MESSAGE(KERN_ERR, device, " %s",
1658 "No memory to dump sense data");
1661 /* dump the sense data */
1662 len = sprintf(page, KERN_ERR PRINTK_HEADER
1663 " I/O status report for device %s:\n",
1664 device->cdev->dev.bus_id);
1665 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
1666 " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
1667 irb->scsw.cstat, irb->scsw.dstat);
1668 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
1669 " device %s: Failing CCW: %p\n",
1670 device->cdev->dev.bus_id,
1671 (void *) (addr_t) irb->scsw.cpa);
1672 if (irb->esw.esw0.erw.cons) {
1673 for (sl = 0; sl < 4; sl++) {
1674 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
1675 " Sense(hex) %2d-%2d:",
1676 (8 * sl), ((8 * sl) + 7));
1678 for (sct = 0; sct < 8; sct++) {
1679 len += sprintf(page + len, " %02x",
1680 irb->ecw[8 * sl + sct]);
1682 len += sprintf(page + len, "\n");
1685 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
1686 /* 24 Byte Sense Data */
1687 sprintf(page + len, KERN_ERR PRINTK_HEADER
1688 " 24 Byte: %x MSG %x, "
1689 "%s MSGb to SYSOP\n",
1690 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
1691 irb->ecw[1] & 0x10 ? "" : "no");
1693 /* 32 Byte Sense Data */
1694 sprintf(page + len, KERN_ERR PRINTK_HEADER
1695 " 32 Byte: Format: %x "
1696 "Exception class %x\n",
1697 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
1700 sprintf(page + len, KERN_ERR PRINTK_HEADER
1701 " SORRY - NO VALID SENSE AVAILABLE\n");
1705 /* dump the Channel Program (max 140 Bytes per line) */
1706 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
1707 first = req->cpaddr;
1708 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
1709 to = min(first + 6, last);
1710 len = sprintf(page, KERN_ERR PRINTK_HEADER
1711 " Related CP in req: %p\n", req);
1712 dasd_eckd_dump_ccw_range(first, to, page + len);
1715 /* print failing CCW area (maximum 4) */
1716 /* scsw->cda is either valid or zero */
1719 fail = (struct ccw1 *)(addr_t) irb->scsw.cpa; /* failing CCW */
1720 if (from < fail - 2) {
1721 from = fail - 2; /* there is a gap - print header */
1722 len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
1724 to = min(fail + 1, last);
1725 len += dasd_eckd_dump_ccw_range(from, to, page + len);
1727 /* print last CCWs (maximum 2) */
1728 from = max(from, ++to);
1729 if (from < last - 1) {
1730 from = last - 1; /* there is a gap - print header */
1731 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
1733 len += dasd_eckd_dump_ccw_range(from, last, page + len);
1736 free_page((unsigned long) page);
1740 * max_blocks is dependent on the amount of storage that is available
1741 * in the static io buffer for each device. Currently each device has
1742 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
1743 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
1744 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
1745 * addition we have one define extent ccw + 16 bytes of data and one
1746 * locate record ccw + 16 bytes of data. That makes:
1747 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
1748 * We want to fit two into the available memory so that we can immediately
1749 * start the next request if one finishes off. That makes 249.5 blocks
1750 * for one request. Give a little safety and the result is 240.
1752 static struct dasd_discipline dasd_eckd_discipline = {
1753 .owner = THIS_MODULE,
1757 .check_device = dasd_eckd_check_characteristics,
1758 .do_analysis = dasd_eckd_do_analysis,
1759 .fill_geometry = dasd_eckd_fill_geometry,
1760 .start_IO = dasd_start_IO,
1761 .term_IO = dasd_term_IO,
1762 .format_device = dasd_eckd_format_device,
1763 .examine_error = dasd_eckd_examine_error,
1764 .erp_action = dasd_eckd_erp_action,
1765 .erp_postaction = dasd_eckd_erp_postaction,
1766 .build_cp = dasd_eckd_build_cp,
1767 .free_cp = dasd_eckd_free_cp,
1768 .dump_sense = dasd_eckd_dump_sense,
1769 .fill_info = dasd_eckd_fill_info,
1770 .ioctl = dasd_eckd_ioctl,
1774 dasd_eckd_init(void)
1776 ASCEBC(dasd_eckd_discipline.ebcname, 4);
1777 return ccw_driver_register(&dasd_eckd_driver);
1781 dasd_eckd_cleanup(void)
1783 ccw_driver_unregister(&dasd_eckd_driver);
1786 module_init(dasd_eckd_init);
1787 module_exit(dasd_eckd_cleanup);