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/debug.h>
24 #include <asm/idals.h>
25 #include <asm/ebcdic.h>
27 #include <asm/uaccess.h>
29 #include <asm/ccwdev.h>
33 #include "dasd_eckd.h"
34 #include "../cio/chsc.h"
39 #endif /* PRINTK_HEADER */
40 #define PRINTK_HEADER "dasd(eckd):"
42 #define ECKD_C0(i) (i->home_bytes)
43 #define ECKD_F(i) (i->formula)
44 #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
45 (i->factors.f_0x02.f1))
46 #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
47 (i->factors.f_0x02.f2))
48 #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
49 (i->factors.f_0x02.f3))
50 #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
51 #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
52 #define ECKD_F6(i) (i->factor6)
53 #define ECKD_F7(i) (i->factor7)
54 #define ECKD_F8(i) (i->factor8)
57 * raw track access always map to 64k in memory
58 * so it maps to 16 blocks of 4k per track
60 #define DASD_RAW_BLOCK_PER_TRACK 16
61 #define DASD_RAW_BLOCKSIZE 4096
62 /* 64k are 128 x 512 byte sectors */
63 #define DASD_RAW_SECTORS_PER_TRACK 128
65 MODULE_LICENSE("GPL");
67 static struct dasd_discipline dasd_eckd_discipline;
69 /* The ccw bus type uses this table to find devices that it sends to
71 static struct ccw_device_id dasd_eckd_ids[] = {
72 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
73 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
74 { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info = 0x3},
75 { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
76 { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
77 { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
78 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
79 { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
80 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
81 { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
82 { /* end of list */ },
85 MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
87 static struct ccw_driver dasd_eckd_driver; /* see below */
90 #define INIT_CQR_UNFORMATTED 1
91 #define INIT_CQR_ERROR 2
93 /* emergency request for reserve/release */
95 struct dasd_ccw_req cqr;
99 static DEFINE_MUTEX(dasd_reserve_mutex);
101 /* definitions for the path verification worker */
102 struct path_verification_work_data {
103 struct work_struct worker;
104 struct dasd_device *device;
105 struct dasd_ccw_req cqr;
107 __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE];
111 static struct path_verification_work_data *path_verification_worker;
112 static DEFINE_MUTEX(dasd_path_verification_mutex);
114 /* initial attempt at a probe function. this can be simplified once
115 * the other detection code is gone */
117 dasd_eckd_probe (struct ccw_device *cdev)
121 /* set ECKD specific ccw-device options */
122 ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE |
123 CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH);
125 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
126 "dasd_eckd_probe: could not set "
127 "ccw-device options");
130 ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
135 dasd_eckd_set_online(struct ccw_device *cdev)
137 return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
140 static const int sizes_trk0[] = { 28, 148, 84 };
141 #define LABEL_SIZE 140
143 static inline unsigned int
144 round_up_multiple(unsigned int no, unsigned int mult)
147 return (rem ? no - rem + mult : no);
150 static inline unsigned int
151 ceil_quot(unsigned int d1, unsigned int d2)
153 return (d1 + (d2 - 1)) / d2;
157 recs_per_track(struct dasd_eckd_characteristics * rdc,
158 unsigned int kl, unsigned int dl)
162 switch (rdc->dev_type) {
165 return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
166 ceil_quot(dl + 12, 32));
168 return 1499 / (15 + ceil_quot(dl + 12, 32));
170 dn = ceil_quot(dl + 6, 232) + 1;
172 kn = ceil_quot(kl + 6, 232) + 1;
173 return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
174 9 + ceil_quot(dl + 6 * dn, 34));
176 return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
178 dn = ceil_quot(dl + 6, 232) + 1;
180 kn = ceil_quot(kl + 6, 232) + 1;
181 return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
182 ceil_quot(dl + 6 * dn, 34));
184 return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
189 static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
191 geo->cyl = (__u16) cyl;
192 geo->head = cyl >> 16;
198 check_XRC (struct ccw1 *de_ccw,
199 struct DE_eckd_data *data,
200 struct dasd_device *device)
202 struct dasd_eckd_private *private;
205 private = (struct dasd_eckd_private *) device->private;
206 if (!private->rdc_data.facilities.XRC_supported)
209 /* switch on System Time Stamp - needed for XRC Support */
210 data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
211 data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
213 rc = get_sync_clock(&data->ep_sys_time);
214 /* Ignore return code if sync clock is switched off. */
215 if (rc == -ENOSYS || rc == -EACCES)
218 de_ccw->count = sizeof(struct DE_eckd_data);
219 de_ccw->flags |= CCW_FLAG_SLI;
224 define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
225 unsigned int totrk, int cmd, struct dasd_device *device)
227 struct dasd_eckd_private *private;
229 u16 heads, beghead, endhead;
232 private = (struct dasd_eckd_private *) device->private;
234 ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
237 ccw->cda = (__u32) __pa(data);
239 memset(data, 0, sizeof(struct DE_eckd_data));
241 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
242 case DASD_ECKD_CCW_READ_RECORD_ZERO:
243 case DASD_ECKD_CCW_READ:
244 case DASD_ECKD_CCW_READ_MT:
245 case DASD_ECKD_CCW_READ_CKD:
246 case DASD_ECKD_CCW_READ_CKD_MT:
247 case DASD_ECKD_CCW_READ_KD:
248 case DASD_ECKD_CCW_READ_KD_MT:
249 case DASD_ECKD_CCW_READ_COUNT:
250 data->mask.perm = 0x1;
251 data->attributes.operation = private->attrib.operation;
253 case DASD_ECKD_CCW_WRITE:
254 case DASD_ECKD_CCW_WRITE_MT:
255 case DASD_ECKD_CCW_WRITE_KD:
256 case DASD_ECKD_CCW_WRITE_KD_MT:
257 data->mask.perm = 0x02;
258 data->attributes.operation = private->attrib.operation;
259 rc = check_XRC (ccw, data, device);
261 case DASD_ECKD_CCW_WRITE_CKD:
262 case DASD_ECKD_CCW_WRITE_CKD_MT:
263 data->attributes.operation = DASD_BYPASS_CACHE;
264 rc = check_XRC (ccw, data, device);
266 case DASD_ECKD_CCW_ERASE:
267 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
268 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
269 data->mask.perm = 0x3;
270 data->mask.auth = 0x1;
271 data->attributes.operation = DASD_BYPASS_CACHE;
272 rc = check_XRC (ccw, data, device);
275 dev_err(&device->cdev->dev,
276 "0x%x is not a known command\n", cmd);
280 data->attributes.mode = 0x3; /* ECKD */
282 if ((private->rdc_data.cu_type == 0x2105 ||
283 private->rdc_data.cu_type == 0x2107 ||
284 private->rdc_data.cu_type == 0x1750)
285 && !(private->uses_cdl && trk < 2))
286 data->ga_extended |= 0x40; /* Regular Data Format Mode */
288 heads = private->rdc_data.trk_per_cyl;
289 begcyl = trk / heads;
290 beghead = trk % heads;
291 endcyl = totrk / heads;
292 endhead = totrk % heads;
294 /* check for sequential prestage - enhance cylinder range */
295 if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
296 data->attributes.operation == DASD_SEQ_ACCESS) {
298 if (endcyl + private->attrib.nr_cyl < private->real_cyl)
299 endcyl += private->attrib.nr_cyl;
301 endcyl = (private->real_cyl - 1);
304 set_ch_t(&data->beg_ext, begcyl, beghead);
305 set_ch_t(&data->end_ext, endcyl, endhead);
309 static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
310 struct dasd_device *device)
312 struct dasd_eckd_private *private;
315 private = (struct dasd_eckd_private *) device->private;
316 if (!private->rdc_data.facilities.XRC_supported)
319 /* switch on System Time Stamp - needed for XRC Support */
320 pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */
321 pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */
322 pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */
324 rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time);
325 /* Ignore return code if sync clock is switched off. */
326 if (rc == -ENOSYS || rc == -EACCES)
331 static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk,
332 unsigned int rec_on_trk, int count, int cmd,
333 struct dasd_device *device, unsigned int reclen,
336 struct dasd_eckd_private *private;
340 private = (struct dasd_eckd_private *) device->private;
342 memset(data, 0, sizeof(*data));
345 switch (private->rdc_data.dev_type) {
347 dn = ceil_quot(reclen + 6, 232);
348 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
349 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
352 d = 7 + ceil_quot(reclen + 12, 32);
353 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
357 data->sector = sector;
358 /* note: meaning of count depends on the operation
359 * for record based I/O it's the number of records, but for
360 * track based I/O it's the number of tracks
364 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
365 data->operation.orientation = 0x3;
366 data->operation.operation = 0x03;
368 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
369 data->operation.orientation = 0x3;
370 data->operation.operation = 0x16;
372 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
373 data->operation.orientation = 0x1;
374 data->operation.operation = 0x03;
377 case DASD_ECKD_CCW_READ_RECORD_ZERO:
378 data->operation.orientation = 0x3;
379 data->operation.operation = 0x16;
382 case DASD_ECKD_CCW_WRITE:
383 case DASD_ECKD_CCW_WRITE_MT:
384 case DASD_ECKD_CCW_WRITE_KD:
385 case DASD_ECKD_CCW_WRITE_KD_MT:
386 data->auxiliary.length_valid = 0x1;
387 data->length = reclen;
388 data->operation.operation = 0x01;
390 case DASD_ECKD_CCW_WRITE_CKD:
391 case DASD_ECKD_CCW_WRITE_CKD_MT:
392 data->auxiliary.length_valid = 0x1;
393 data->length = reclen;
394 data->operation.operation = 0x03;
396 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
397 data->operation.orientation = 0x0;
398 data->operation.operation = 0x3F;
399 data->extended_operation = 0x11;
401 data->extended_parameter_length = 0x02;
402 if (data->count > 8) {
403 data->extended_parameter[0] = 0xFF;
404 data->extended_parameter[1] = 0xFF;
405 data->extended_parameter[1] <<= (16 - count);
407 data->extended_parameter[0] = 0xFF;
408 data->extended_parameter[0] <<= (8 - count);
409 data->extended_parameter[1] = 0x00;
413 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
414 data->auxiliary.length_valid = 0x1;
415 data->length = reclen; /* not tlf, as one might think */
416 data->operation.operation = 0x3F;
417 data->extended_operation = 0x23;
419 case DASD_ECKD_CCW_READ:
420 case DASD_ECKD_CCW_READ_MT:
421 case DASD_ECKD_CCW_READ_KD:
422 case DASD_ECKD_CCW_READ_KD_MT:
423 data->auxiliary.length_valid = 0x1;
424 data->length = reclen;
425 data->operation.operation = 0x06;
427 case DASD_ECKD_CCW_READ_CKD:
428 case DASD_ECKD_CCW_READ_CKD_MT:
429 data->auxiliary.length_valid = 0x1;
430 data->length = reclen;
431 data->operation.operation = 0x16;
433 case DASD_ECKD_CCW_READ_COUNT:
434 data->operation.operation = 0x06;
436 case DASD_ECKD_CCW_READ_TRACK:
437 data->operation.orientation = 0x1;
438 data->operation.operation = 0x0C;
439 data->extended_parameter_length = 0;
442 case DASD_ECKD_CCW_READ_TRACK_DATA:
443 data->auxiliary.length_valid = 0x1;
445 data->operation.operation = 0x0C;
447 case DASD_ECKD_CCW_ERASE:
448 data->length = reclen;
449 data->auxiliary.length_valid = 0x1;
450 data->operation.operation = 0x0b;
453 DBF_DEV_EVENT(DBF_ERR, device,
454 "fill LRE unknown opcode 0x%x", cmd);
457 set_ch_t(&data->seek_addr,
458 trk / private->rdc_data.trk_per_cyl,
459 trk % private->rdc_data.trk_per_cyl);
460 data->search_arg.cyl = data->seek_addr.cyl;
461 data->search_arg.head = data->seek_addr.head;
462 data->search_arg.record = rec_on_trk;
465 static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
466 unsigned int trk, unsigned int totrk, int cmd,
467 struct dasd_device *basedev, struct dasd_device *startdev,
468 unsigned char format, unsigned int rec_on_trk, int count,
469 unsigned int blksize, unsigned int tlf)
471 struct dasd_eckd_private *basepriv, *startpriv;
472 struct DE_eckd_data *dedata;
473 struct LRE_eckd_data *lredata;
475 u16 heads, beghead, endhead;
478 basepriv = (struct dasd_eckd_private *) basedev->private;
479 startpriv = (struct dasd_eckd_private *) startdev->private;
480 dedata = &pfxdata->define_extent;
481 lredata = &pfxdata->locate_record;
483 ccw->cmd_code = DASD_ECKD_CCW_PFX;
485 if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) {
486 ccw->count = sizeof(*pfxdata) + 2;
487 ccw->cda = (__u32) __pa(pfxdata);
488 memset(pfxdata, 0, sizeof(*pfxdata) + 2);
490 ccw->count = sizeof(*pfxdata);
491 ccw->cda = (__u32) __pa(pfxdata);
492 memset(pfxdata, 0, sizeof(*pfxdata));
497 DBF_DEV_EVENT(DBF_ERR, basedev,
498 "PFX LRE unknown format 0x%x", format);
502 pfxdata->format = format;
503 pfxdata->base_address = basepriv->ned->unit_addr;
504 pfxdata->base_lss = basepriv->ned->ID;
505 pfxdata->validity.define_extent = 1;
507 /* private uid is kept up to date, conf_data may be outdated */
508 if (startpriv->uid.type != UA_BASE_DEVICE) {
509 pfxdata->validity.verify_base = 1;
510 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
511 pfxdata->validity.hyper_pav = 1;
514 /* define extend data (mostly)*/
516 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
517 case DASD_ECKD_CCW_READ_RECORD_ZERO:
518 case DASD_ECKD_CCW_READ:
519 case DASD_ECKD_CCW_READ_MT:
520 case DASD_ECKD_CCW_READ_CKD:
521 case DASD_ECKD_CCW_READ_CKD_MT:
522 case DASD_ECKD_CCW_READ_KD:
523 case DASD_ECKD_CCW_READ_KD_MT:
524 case DASD_ECKD_CCW_READ_COUNT:
525 dedata->mask.perm = 0x1;
526 dedata->attributes.operation = basepriv->attrib.operation;
528 case DASD_ECKD_CCW_READ_TRACK:
529 case DASD_ECKD_CCW_READ_TRACK_DATA:
530 dedata->mask.perm = 0x1;
531 dedata->attributes.operation = basepriv->attrib.operation;
532 dedata->blk_size = 0;
534 case DASD_ECKD_CCW_WRITE:
535 case DASD_ECKD_CCW_WRITE_MT:
536 case DASD_ECKD_CCW_WRITE_KD:
537 case DASD_ECKD_CCW_WRITE_KD_MT:
538 dedata->mask.perm = 0x02;
539 dedata->attributes.operation = basepriv->attrib.operation;
540 rc = check_XRC_on_prefix(pfxdata, basedev);
542 case DASD_ECKD_CCW_WRITE_CKD:
543 case DASD_ECKD_CCW_WRITE_CKD_MT:
544 dedata->attributes.operation = DASD_BYPASS_CACHE;
545 rc = check_XRC_on_prefix(pfxdata, basedev);
547 case DASD_ECKD_CCW_ERASE:
548 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
549 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
550 dedata->mask.perm = 0x3;
551 dedata->mask.auth = 0x1;
552 dedata->attributes.operation = DASD_BYPASS_CACHE;
553 rc = check_XRC_on_prefix(pfxdata, basedev);
555 case DASD_ECKD_CCW_WRITE_FULL_TRACK:
556 dedata->mask.perm = 0x03;
557 dedata->attributes.operation = basepriv->attrib.operation;
558 dedata->blk_size = 0;
560 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
561 dedata->mask.perm = 0x02;
562 dedata->attributes.operation = basepriv->attrib.operation;
563 dedata->blk_size = blksize;
564 rc = check_XRC_on_prefix(pfxdata, basedev);
567 DBF_DEV_EVENT(DBF_ERR, basedev,
568 "PFX LRE unknown opcode 0x%x", cmd);
573 dedata->attributes.mode = 0x3; /* ECKD */
575 if ((basepriv->rdc_data.cu_type == 0x2105 ||
576 basepriv->rdc_data.cu_type == 0x2107 ||
577 basepriv->rdc_data.cu_type == 0x1750)
578 && !(basepriv->uses_cdl && trk < 2))
579 dedata->ga_extended |= 0x40; /* Regular Data Format Mode */
581 heads = basepriv->rdc_data.trk_per_cyl;
582 begcyl = trk / heads;
583 beghead = trk % heads;
584 endcyl = totrk / heads;
585 endhead = totrk % heads;
587 /* check for sequential prestage - enhance cylinder range */
588 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
589 dedata->attributes.operation == DASD_SEQ_ACCESS) {
591 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
592 endcyl += basepriv->attrib.nr_cyl;
594 endcyl = (basepriv->real_cyl - 1);
597 set_ch_t(&dedata->beg_ext, begcyl, beghead);
598 set_ch_t(&dedata->end_ext, endcyl, endhead);
601 fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
602 basedev, blksize, tlf);
608 static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
609 unsigned int trk, unsigned int totrk, int cmd,
610 struct dasd_device *basedev, struct dasd_device *startdev)
612 return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
617 locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
618 unsigned int rec_on_trk, int no_rec, int cmd,
619 struct dasd_device * device, int reclen)
621 struct dasd_eckd_private *private;
625 private = (struct dasd_eckd_private *) device->private;
627 DBF_DEV_EVENT(DBF_INFO, device,
628 "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
629 trk, rec_on_trk, no_rec, cmd, reclen);
631 ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
634 ccw->cda = (__u32) __pa(data);
636 memset(data, 0, sizeof(struct LO_eckd_data));
639 switch (private->rdc_data.dev_type) {
641 dn = ceil_quot(reclen + 6, 232);
642 d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
643 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
646 d = 7 + ceil_quot(reclen + 12, 32);
647 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
651 data->sector = sector;
652 data->count = no_rec;
654 case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
655 data->operation.orientation = 0x3;
656 data->operation.operation = 0x03;
658 case DASD_ECKD_CCW_READ_HOME_ADDRESS:
659 data->operation.orientation = 0x3;
660 data->operation.operation = 0x16;
662 case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
663 data->operation.orientation = 0x1;
664 data->operation.operation = 0x03;
667 case DASD_ECKD_CCW_READ_RECORD_ZERO:
668 data->operation.orientation = 0x3;
669 data->operation.operation = 0x16;
672 case DASD_ECKD_CCW_WRITE:
673 case DASD_ECKD_CCW_WRITE_MT:
674 case DASD_ECKD_CCW_WRITE_KD:
675 case DASD_ECKD_CCW_WRITE_KD_MT:
676 data->auxiliary.last_bytes_used = 0x1;
677 data->length = reclen;
678 data->operation.operation = 0x01;
680 case DASD_ECKD_CCW_WRITE_CKD:
681 case DASD_ECKD_CCW_WRITE_CKD_MT:
682 data->auxiliary.last_bytes_used = 0x1;
683 data->length = reclen;
684 data->operation.operation = 0x03;
686 case DASD_ECKD_CCW_READ:
687 case DASD_ECKD_CCW_READ_MT:
688 case DASD_ECKD_CCW_READ_KD:
689 case DASD_ECKD_CCW_READ_KD_MT:
690 data->auxiliary.last_bytes_used = 0x1;
691 data->length = reclen;
692 data->operation.operation = 0x06;
694 case DASD_ECKD_CCW_READ_CKD:
695 case DASD_ECKD_CCW_READ_CKD_MT:
696 data->auxiliary.last_bytes_used = 0x1;
697 data->length = reclen;
698 data->operation.operation = 0x16;
700 case DASD_ECKD_CCW_READ_COUNT:
701 data->operation.operation = 0x06;
703 case DASD_ECKD_CCW_ERASE:
704 data->length = reclen;
705 data->auxiliary.last_bytes_used = 0x1;
706 data->operation.operation = 0x0b;
709 DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
712 set_ch_t(&data->seek_addr,
713 trk / private->rdc_data.trk_per_cyl,
714 trk % private->rdc_data.trk_per_cyl);
715 data->search_arg.cyl = data->seek_addr.cyl;
716 data->search_arg.head = data->seek_addr.head;
717 data->search_arg.record = rec_on_trk;
721 * Returns 1 if the block is one of the special blocks that needs
722 * to get read/written with the KD variant of the command.
723 * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
724 * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
725 * Luckily the KD variants differ only by one bit (0x08) from the
726 * normal variant. So don't wonder about code like:
727 * if (dasd_eckd_cdl_special(blk_per_trk, recid))
728 * ccw->cmd_code |= 0x8;
731 dasd_eckd_cdl_special(int blk_per_trk, int recid)
735 if (recid < blk_per_trk)
737 if (recid < 2 * blk_per_trk)
743 * Returns the record size for the special blocks of the cdl format.
744 * Only returns something useful if dasd_eckd_cdl_special is true
748 dasd_eckd_cdl_reclen(int recid)
751 return sizes_trk0[recid];
754 /* create unique id from private structure. */
755 static void create_uid(struct dasd_eckd_private *private)
758 struct dasd_uid *uid;
761 memset(uid, 0, sizeof(struct dasd_uid));
762 memcpy(uid->vendor, private->ned->HDA_manufacturer,
763 sizeof(uid->vendor) - 1);
764 EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
765 memcpy(uid->serial, private->ned->HDA_location,
766 sizeof(uid->serial) - 1);
767 EBCASC(uid->serial, sizeof(uid->serial) - 1);
768 uid->ssid = private->gneq->subsystemID;
769 uid->real_unit_addr = private->ned->unit_addr;
771 uid->type = private->sneq->sua_flags;
772 if (uid->type == UA_BASE_PAV_ALIAS)
773 uid->base_unit_addr = private->sneq->base_unit_addr;
775 uid->type = UA_BASE_DEVICE;
777 if (private->vdsneq) {
778 for (count = 0; count < 16; count++) {
779 sprintf(uid->vduit+2*count, "%02x",
780 private->vdsneq->uit[count]);
786 * Generate device unique id that specifies the physical device.
788 static int dasd_eckd_generate_uid(struct dasd_device *device)
790 struct dasd_eckd_private *private;
793 private = (struct dasd_eckd_private *) device->private;
796 if (!private->ned || !private->gneq)
798 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
800 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
804 static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
806 struct dasd_eckd_private *private;
809 if (device->private) {
810 private = (struct dasd_eckd_private *)device->private;
811 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
813 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
820 * compare device UID with data of a given dasd_eckd_private structure
823 static int dasd_eckd_compare_path_uid(struct dasd_device *device,
824 struct dasd_eckd_private *private)
826 struct dasd_uid device_uid;
829 dasd_eckd_get_uid(device, &device_uid);
831 return memcmp(&device_uid, &private->uid, sizeof(struct dasd_uid));
834 static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device,
835 struct dasd_ccw_req *cqr,
841 * buffer has to start with EBCDIC "V1.0" to show
842 * support for virtual device SNEQ
844 rcd_buffer[0] = 0xE5;
845 rcd_buffer[1] = 0xF1;
846 rcd_buffer[2] = 0x4B;
847 rcd_buffer[3] = 0xF0;
850 ccw->cmd_code = DASD_ECKD_CCW_RCD;
852 ccw->cda = (__u32)(addr_t)rcd_buffer;
853 ccw->count = DASD_ECKD_RCD_DATA_SIZE;
854 cqr->magic = DASD_ECKD_MAGIC;
856 cqr->startdev = device;
857 cqr->memdev = device;
859 cqr->expires = 10*HZ;
862 cqr->buildclk = get_clock();
863 cqr->status = DASD_CQR_FILLED;
864 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
868 * Wakeup helper for read_conf
869 * if the cqr is not done and needs some error recovery
870 * the buffer has to be re-initialized with the EBCDIC "V1.0"
871 * to show support for virtual device SNEQ
873 static void read_conf_cb(struct dasd_ccw_req *cqr, void *data)
878 if (cqr->status != DASD_CQR_DONE) {
880 rcd_buffer = (__u8 *)((addr_t) ccw->cda);
881 memset(rcd_buffer, 0, sizeof(*rcd_buffer));
883 rcd_buffer[0] = 0xE5;
884 rcd_buffer[1] = 0xF1;
885 rcd_buffer[2] = 0x4B;
886 rcd_buffer[3] = 0xF0;
888 dasd_wakeup_cb(cqr, data);
891 static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
892 struct dasd_ccw_req *cqr,
899 * sanity check: scan for RCD command in extended SenseID data
900 * some devices do not support RCD
902 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
903 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD)
906 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm);
907 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
908 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
910 cqr->callback = read_conf_cb;
911 rc = dasd_sleep_on_immediatly(cqr);
915 static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
917 int *rcd_buffer_size, __u8 lpm)
920 char *rcd_buf = NULL;
922 struct dasd_ccw_req *cqr;
925 * sanity check: scan for RCD command in extended SenseID data
926 * some devices do not support RCD
928 ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
929 if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) {
933 rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA);
938 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */,
939 0, /* use rcd_buf as data ara */
942 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
943 "Could not allocate RCD request");
947 dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm);
948 cqr->callback = read_conf_cb;
949 ret = dasd_sleep_on(cqr);
951 * on success we update the user input parms
953 dasd_sfree_request(cqr, cqr->memdev);
957 *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE;
958 *rcd_buffer = rcd_buf;
963 *rcd_buffer_size = 0;
967 static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
970 struct dasd_sneq *sneq;
974 private->sneq = NULL;
975 private->vdsneq = NULL;
976 private->gneq = NULL;
977 count = private->conf_len / sizeof(struct dasd_sneq);
978 sneq = (struct dasd_sneq *)private->conf_data;
979 for (i = 0; i < count; ++i) {
980 if (sneq->flags.identifier == 1 && sneq->format == 1)
981 private->sneq = sneq;
982 else if (sneq->flags.identifier == 1 && sneq->format == 4)
983 private->vdsneq = (struct vd_sneq *)sneq;
984 else if (sneq->flags.identifier == 2)
985 private->gneq = (struct dasd_gneq *)sneq;
986 else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
987 private->ned = (struct dasd_ned *)sneq;
990 if (!private->ned || !private->gneq) {
992 private->sneq = NULL;
993 private->vdsneq = NULL;
994 private->gneq = NULL;
1001 static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
1003 struct dasd_gneq *gneq;
1004 int i, count, found;
1006 count = conf_len / sizeof(*gneq);
1007 gneq = (struct dasd_gneq *)conf_data;
1009 for (i = 0; i < count; ++i) {
1010 if (gneq->flags.identifier == 2) {
1017 return ((char *)gneq)[18] & 0x07;
1022 static int dasd_eckd_read_conf(struct dasd_device *device)
1025 int conf_len, conf_data_saved;
1028 struct dasd_eckd_private *private, path_private;
1029 struct dasd_path *path_data;
1030 struct dasd_uid *uid;
1031 char print_path_uid[60], print_device_uid[60];
1033 private = (struct dasd_eckd_private *) device->private;
1034 path_data = &device->path_data;
1035 opm = ccw_device_get_path_mask(device->cdev);
1036 conf_data_saved = 0;
1037 /* get configuration data per operational path */
1038 for (lpm = 0x80; lpm; lpm>>= 1) {
1041 rc = dasd_eckd_read_conf_lpm(device, &conf_data,
1043 if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
1044 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1045 "Read configuration data returned "
1049 if (conf_data == NULL) {
1050 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1051 "No configuration data "
1053 /* no further analysis possible */
1054 path_data->opm |= lpm;
1055 continue; /* no error */
1057 /* save first valid configuration data */
1058 if (!conf_data_saved) {
1059 kfree(private->conf_data);
1060 private->conf_data = conf_data;
1061 private->conf_len = conf_len;
1062 if (dasd_eckd_identify_conf_parts(private)) {
1063 private->conf_data = NULL;
1064 private->conf_len = 0;
1069 * build device UID that other path data
1070 * can be compared to it
1072 dasd_eckd_generate_uid(device);
1075 path_private.conf_data = conf_data;
1076 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1077 if (dasd_eckd_identify_conf_parts(
1079 path_private.conf_data = NULL;
1080 path_private.conf_len = 0;
1085 if (dasd_eckd_compare_path_uid(
1086 device, &path_private)) {
1087 uid = &path_private.uid;
1088 if (strlen(uid->vduit) > 0)
1089 snprintf(print_path_uid,
1090 sizeof(print_path_uid),
1091 "%s.%s.%04x.%02x.%s",
1092 uid->vendor, uid->serial,
1093 uid->ssid, uid->real_unit_addr,
1096 snprintf(print_path_uid,
1097 sizeof(print_path_uid),
1099 uid->vendor, uid->serial,
1101 uid->real_unit_addr);
1102 uid = &private->uid;
1103 if (strlen(uid->vduit) > 0)
1104 snprintf(print_device_uid,
1105 sizeof(print_device_uid),
1106 "%s.%s.%04x.%02x.%s",
1107 uid->vendor, uid->serial,
1108 uid->ssid, uid->real_unit_addr,
1111 snprintf(print_device_uid,
1112 sizeof(print_device_uid),
1114 uid->vendor, uid->serial,
1116 uid->real_unit_addr);
1117 dev_err(&device->cdev->dev,
1118 "Not all channel paths lead to "
1119 "the same device, path %02X leads to "
1120 "device %s instead of %s\n", lpm,
1121 print_path_uid, print_device_uid);
1125 path_private.conf_data = NULL;
1126 path_private.conf_len = 0;
1128 switch (dasd_eckd_path_access(conf_data, conf_len)) {
1130 path_data->npm |= lpm;
1133 path_data->ppm |= lpm;
1136 path_data->opm |= lpm;
1138 if (conf_data != private->conf_data)
1145 static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
1147 struct dasd_eckd_private *private;
1151 private = (struct dasd_eckd_private *) device->private;
1152 if (private->fcx_max_data) {
1153 mdc = ccw_device_get_mdc(device->cdev, lpm);
1155 dev_warn(&device->cdev->dev,
1156 "Detecting the maximum data size for zHPF "
1157 "requests failed (rc=%d) for a new path %x\n",
1161 fcx_max_data = mdc * FCX_MAX_DATA_FACTOR;
1162 if (fcx_max_data < private->fcx_max_data) {
1163 dev_warn(&device->cdev->dev,
1164 "The maximum data size for zHPF requests %u "
1165 "on a new path %x is below the active maximum "
1166 "%u\n", fcx_max_data, lpm,
1167 private->fcx_max_data);
1174 static int rebuild_device_uid(struct dasd_device *device,
1175 struct path_verification_work_data *data)
1177 struct dasd_eckd_private *private;
1178 struct dasd_path *path_data;
1183 private = (struct dasd_eckd_private *) device->private;
1184 path_data = &device->path_data;
1185 opm = device->path_data.opm;
1187 for (lpm = 0x80; lpm; lpm >>= 1) {
1190 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1191 memset(&data->cqr, 0, sizeof(data->cqr));
1192 data->cqr.cpaddr = &data->ccw;
1193 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1198 if (rc == -EOPNOTSUPP) /* -EOPNOTSUPP is ok */
1200 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1201 "Read configuration data "
1202 "returned error %d", rc);
1205 memcpy(private->conf_data, data->rcd_buffer,
1206 DASD_ECKD_RCD_DATA_SIZE);
1207 if (dasd_eckd_identify_conf_parts(private)) {
1209 } else /* first valid path is enough */
1214 rc = dasd_eckd_generate_uid(device);
1219 static void do_path_verification_work(struct work_struct *work)
1221 struct path_verification_work_data *data;
1222 struct dasd_device *device;
1223 struct dasd_eckd_private path_private;
1224 struct dasd_uid *uid;
1225 __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE];
1226 __u8 lpm, opm, npm, ppm, epm;
1227 unsigned long flags;
1231 data = container_of(work, struct path_verification_work_data, worker);
1232 device = data->device;
1234 /* delay path verification until device was resumed */
1235 if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
1236 schedule_work(work);
1244 for (lpm = 0x80; lpm; lpm >>= 1) {
1245 if (!(lpm & data->tbvpm))
1247 memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
1248 memset(&data->cqr, 0, sizeof(data->cqr));
1249 data->cqr.cpaddr = &data->ccw;
1250 rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
1254 switch (dasd_eckd_path_access(data->rcd_buffer,
1255 DASD_ECKD_RCD_DATA_SIZE)
1265 } else if (rc == -EOPNOTSUPP) {
1266 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1267 "path verification: No configuration "
1270 } else if (rc == -EAGAIN) {
1271 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1272 "path verification: device is stopped,"
1273 " try again later");
1276 dev_warn(&device->cdev->dev,
1277 "Reading device feature codes failed "
1278 "(rc=%d) for new path %x\n", rc, lpm);
1281 if (verify_fcx_max_data(device, lpm)) {
1289 * save conf_data for comparison after
1290 * rebuild_device_uid may have changed
1293 memcpy(&path_rcd_buf, data->rcd_buffer,
1294 DASD_ECKD_RCD_DATA_SIZE);
1295 path_private.conf_data = (void *) &path_rcd_buf;
1296 path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
1297 if (dasd_eckd_identify_conf_parts(&path_private)) {
1298 path_private.conf_data = NULL;
1299 path_private.conf_len = 0;
1304 * compare path UID with device UID only if at least
1305 * one valid path is left
1306 * in other case the device UID may have changed and
1307 * the first working path UID will be used as device UID
1309 if (device->path_data.opm &&
1310 dasd_eckd_compare_path_uid(device, &path_private)) {
1312 * the comparison was not successful
1313 * rebuild the device UID with at least one
1314 * known path in case a z/VM hyperswap command
1315 * has changed the device
1317 * after this compare again
1319 * if either the rebuild or the recompare fails
1320 * the path can not be used
1322 if (rebuild_device_uid(device, data) ||
1323 dasd_eckd_compare_path_uid(
1324 device, &path_private)) {
1325 uid = &path_private.uid;
1326 if (strlen(uid->vduit) > 0)
1327 snprintf(print_uid, sizeof(print_uid),
1328 "%s.%s.%04x.%02x.%s",
1329 uid->vendor, uid->serial,
1330 uid->ssid, uid->real_unit_addr,
1333 snprintf(print_uid, sizeof(print_uid),
1335 uid->vendor, uid->serial,
1337 uid->real_unit_addr);
1338 dev_err(&device->cdev->dev,
1339 "The newly added channel path %02X "
1340 "will not be used because it leads "
1341 "to a different device %s\n",
1351 * There is a small chance that a path is lost again between
1352 * above path verification and the following modification of
1353 * the device opm mask. We could avoid that race here by using
1354 * yet another path mask, but we rather deal with this unlikely
1355 * situation in dasd_start_IO.
1357 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1358 if (!device->path_data.opm && opm) {
1359 device->path_data.opm = opm;
1360 dasd_generic_path_operational(device);
1362 device->path_data.opm |= opm;
1363 device->path_data.npm |= npm;
1364 device->path_data.ppm |= ppm;
1365 device->path_data.tbvpm |= epm;
1366 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1369 dasd_put_device(device);
1371 mutex_unlock(&dasd_path_verification_mutex);
1376 static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm)
1378 struct path_verification_work_data *data;
1380 data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA);
1382 if (mutex_trylock(&dasd_path_verification_mutex)) {
1383 data = path_verification_worker;
1388 memset(data, 0, sizeof(*data));
1391 INIT_WORK(&data->worker, do_path_verification_work);
1392 dasd_get_device(device);
1393 data->device = device;
1395 schedule_work(&data->worker);
1399 static int dasd_eckd_read_features(struct dasd_device *device)
1401 struct dasd_psf_prssd_data *prssdp;
1402 struct dasd_rssd_features *features;
1403 struct dasd_ccw_req *cqr;
1406 struct dasd_eckd_private *private;
1408 private = (struct dasd_eckd_private *) device->private;
1409 memset(&private->features, 0, sizeof(struct dasd_rssd_features));
1410 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
1411 (sizeof(struct dasd_psf_prssd_data) +
1412 sizeof(struct dasd_rssd_features)),
1415 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not "
1416 "allocate initialization request");
1417 return PTR_ERR(cqr);
1419 cqr->startdev = device;
1420 cqr->memdev = device;
1423 cqr->expires = 10 * HZ;
1425 /* Prepare for Read Subsystem Data */
1426 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1427 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
1428 prssdp->order = PSF_ORDER_PRSSD;
1429 prssdp->suborder = 0x41; /* Read Feature Codes */
1430 /* all other bytes of prssdp must be zero */
1433 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1434 ccw->count = sizeof(struct dasd_psf_prssd_data);
1435 ccw->flags |= CCW_FLAG_CC;
1436 ccw->cda = (__u32)(addr_t) prssdp;
1438 /* Read Subsystem Data - feature codes */
1439 features = (struct dasd_rssd_features *) (prssdp + 1);
1440 memset(features, 0, sizeof(struct dasd_rssd_features));
1443 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
1444 ccw->count = sizeof(struct dasd_rssd_features);
1445 ccw->cda = (__u32)(addr_t) features;
1447 cqr->buildclk = get_clock();
1448 cqr->status = DASD_CQR_FILLED;
1449 rc = dasd_sleep_on(cqr);
1451 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1452 features = (struct dasd_rssd_features *) (prssdp + 1);
1453 memcpy(&private->features, features,
1454 sizeof(struct dasd_rssd_features));
1456 dev_warn(&device->cdev->dev, "Reading device feature codes"
1457 " failed with rc=%d\n", rc);
1458 dasd_sfree_request(cqr, cqr->memdev);
1464 * Build CP for Perform Subsystem Function - SSC.
1466 static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
1469 struct dasd_ccw_req *cqr;
1470 struct dasd_psf_ssc_data *psf_ssc_data;
1473 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
1474 sizeof(struct dasd_psf_ssc_data),
1478 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1479 "Could not allocate PSF-SSC request");
1482 psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
1483 psf_ssc_data->order = PSF_ORDER_SSC;
1484 psf_ssc_data->suborder = 0xc0;
1486 psf_ssc_data->suborder |= 0x08;
1487 psf_ssc_data->reserved[0] = 0x88;
1490 ccw->cmd_code = DASD_ECKD_CCW_PSF;
1491 ccw->cda = (__u32)(addr_t)psf_ssc_data;
1494 cqr->startdev = device;
1495 cqr->memdev = device;
1498 cqr->expires = 10*HZ;
1499 cqr->buildclk = get_clock();
1500 cqr->status = DASD_CQR_FILLED;
1505 * Perform Subsystem Function.
1506 * It is necessary to trigger CIO for channel revalidation since this
1507 * call might change behaviour of DASD devices.
1510 dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav)
1512 struct dasd_ccw_req *cqr;
1515 cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
1517 return PTR_ERR(cqr);
1519 rc = dasd_sleep_on(cqr);
1521 /* trigger CIO to reprobe devices */
1522 css_schedule_reprobe();
1523 dasd_sfree_request(cqr, cqr->memdev);
1528 * Valide storage server of current device.
1530 static void dasd_eckd_validate_server(struct dasd_device *device)
1533 struct dasd_eckd_private *private;
1536 private = (struct dasd_eckd_private *) device->private;
1537 if (private->uid.type == UA_BASE_PAV_ALIAS ||
1538 private->uid.type == UA_HYPER_PAV_ALIAS)
1540 if (dasd_nopav || MACHINE_IS_VM)
1544 rc = dasd_eckd_psf_ssc(device, enable_pav);
1546 /* may be requested feature is not available on server,
1547 * therefore just report error and go ahead */
1548 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
1549 "returned rc=%d", private->uid.ssid, rc);
1553 * worker to do a validate server in case of a lost pathgroup
1555 static void dasd_eckd_do_validate_server(struct work_struct *work)
1557 struct dasd_device *device = container_of(work, struct dasd_device,
1559 dasd_eckd_validate_server(device);
1560 dasd_put_device(device);
1563 static void dasd_eckd_kick_validate_server(struct dasd_device *device)
1565 dasd_get_device(device);
1566 /* exit if device not online or in offline processing */
1567 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1568 device->state < DASD_STATE_ONLINE) {
1569 dasd_put_device(device);
1572 /* queue call to do_validate_server to the kernel event daemon. */
1573 schedule_work(&device->kick_validate);
1576 static u32 get_fcx_max_data(struct dasd_device *device)
1578 #if defined(CONFIG_64BIT)
1580 int fcx_in_css, fcx_in_gneq, fcx_in_features;
1581 struct dasd_eckd_private *private;
1585 /* is transport mode supported? */
1586 private = (struct dasd_eckd_private *) device->private;
1587 fcx_in_css = css_general_characteristics.fcx;
1588 fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
1589 fcx_in_features = private->features.feature[40] & 0x80;
1590 tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
1595 mdc = ccw_device_get_mdc(device->cdev, 0);
1597 dev_warn(&device->cdev->dev, "Detecting the maximum supported"
1598 " data size for zHPF requests failed\n");
1601 return mdc * FCX_MAX_DATA_FACTOR;
1608 * Check device characteristics.
1609 * If the device is accessible using ECKD discipline, the device is enabled.
1612 dasd_eckd_check_characteristics(struct dasd_device *device)
1614 struct dasd_eckd_private *private;
1615 struct dasd_block *block;
1616 struct dasd_uid temp_uid;
1619 unsigned long value;
1621 /* setup work queue for validate server*/
1622 INIT_WORK(&device->kick_validate, dasd_eckd_do_validate_server);
1624 if (!ccw_device_is_pathgroup(device->cdev)) {
1625 dev_warn(&device->cdev->dev,
1626 "A channel path group could not be established\n");
1629 if (!ccw_device_is_multipath(device->cdev)) {
1630 dev_info(&device->cdev->dev,
1631 "The DASD is not operating in multipath mode\n");
1633 private = (struct dasd_eckd_private *) device->private;
1635 private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
1637 dev_warn(&device->cdev->dev,
1638 "Allocating memory for private DASD data "
1642 device->private = (void *) private;
1644 memset(private, 0, sizeof(*private));
1646 /* Invalidate status of initial analysis. */
1647 private->init_cqr_status = -1;
1648 /* Set default cache operations. */
1649 private->attrib.operation = DASD_NORMAL_CACHE;
1650 private->attrib.nr_cyl = 0;
1652 /* Read Configuration Data */
1653 rc = dasd_eckd_read_conf(device);
1657 /* set default timeout */
1658 device->default_expires = DASD_EXPIRES;
1659 if (private->gneq) {
1661 for (i = 0; i < private->gneq->timeout.value; i++)
1663 value = value * private->gneq->timeout.number;
1664 /* do not accept useless values */
1665 if (value != 0 && value <= DASD_EXPIRES_MAX)
1666 device->default_expires = value;
1669 dasd_eckd_get_uid(device, &temp_uid);
1670 if (temp_uid.type == UA_BASE_DEVICE) {
1671 block = dasd_alloc_block();
1672 if (IS_ERR(block)) {
1673 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
1674 "could not allocate dasd "
1676 rc = PTR_ERR(block);
1679 device->block = block;
1680 block->base = device;
1683 /* register lcu with alias handling, enable PAV */
1684 rc = dasd_alias_make_device_known_to_lcu(device);
1688 dasd_eckd_validate_server(device);
1690 /* device may report different configuration data after LCU setup */
1691 rc = dasd_eckd_read_conf(device);
1695 /* Read Feature Codes */
1696 dasd_eckd_read_features(device);
1698 /* Read Device Characteristics */
1699 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
1700 &private->rdc_data, 64);
1702 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
1703 "Read device characteristic failed, rc=%d", rc);
1707 if ((device->features & DASD_FEATURE_USERAW) &&
1708 !(private->rdc_data.facilities.RT_in_LR)) {
1709 dev_err(&device->cdev->dev, "The storage server does not "
1710 "support raw-track access\n");
1715 /* find the valid cylinder size */
1716 if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
1717 private->rdc_data.long_no_cyl)
1718 private->real_cyl = private->rdc_data.long_no_cyl;
1720 private->real_cyl = private->rdc_data.no_cyl;
1722 private->fcx_max_data = get_fcx_max_data(device);
1724 readonly = dasd_device_is_ro(device);
1726 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1728 dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
1729 "with %d cylinders, %d heads, %d sectors%s\n",
1730 private->rdc_data.dev_type,
1731 private->rdc_data.dev_model,
1732 private->rdc_data.cu_type,
1733 private->rdc_data.cu_model.model,
1735 private->rdc_data.trk_per_cyl,
1736 private->rdc_data.sec_per_trk,
1737 readonly ? ", read-only device" : "");
1741 dasd_alias_disconnect_device_from_lcu(device);
1743 dasd_free_block(device->block);
1744 device->block = NULL;
1746 kfree(private->conf_data);
1747 kfree(device->private);
1748 device->private = NULL;
1752 static void dasd_eckd_uncheck_device(struct dasd_device *device)
1754 struct dasd_eckd_private *private;
1756 private = (struct dasd_eckd_private *) device->private;
1757 dasd_alias_disconnect_device_from_lcu(device);
1758 private->ned = NULL;
1759 private->sneq = NULL;
1760 private->vdsneq = NULL;
1761 private->gneq = NULL;
1762 private->conf_len = 0;
1763 kfree(private->conf_data);
1764 private->conf_data = NULL;
1767 static struct dasd_ccw_req *
1768 dasd_eckd_analysis_ccw(struct dasd_device *device)
1770 struct dasd_eckd_private *private;
1771 struct eckd_count *count_data;
1772 struct LO_eckd_data *LO_data;
1773 struct dasd_ccw_req *cqr;
1775 int cplength, datasize;
1778 private = (struct dasd_eckd_private *) device->private;
1781 datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
1782 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
1786 /* Define extent for the first 3 tracks. */
1787 define_extent(ccw++, cqr->data, 0, 2,
1788 DASD_ECKD_CCW_READ_COUNT, device);
1789 LO_data = cqr->data + sizeof(struct DE_eckd_data);
1790 /* Locate record for the first 4 records on track 0. */
1791 ccw[-1].flags |= CCW_FLAG_CC;
1792 locate_record(ccw++, LO_data++, 0, 0, 4,
1793 DASD_ECKD_CCW_READ_COUNT, device, 0);
1795 count_data = private->count_area;
1796 for (i = 0; i < 4; i++) {
1797 ccw[-1].flags |= CCW_FLAG_CC;
1798 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1801 ccw->cda = (__u32)(addr_t) count_data;
1806 /* Locate record for the first record on track 2. */
1807 ccw[-1].flags |= CCW_FLAG_CC;
1808 locate_record(ccw++, LO_data++, 2, 0, 1,
1809 DASD_ECKD_CCW_READ_COUNT, device, 0);
1810 /* Read count ccw. */
1811 ccw[-1].flags |= CCW_FLAG_CC;
1812 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
1815 ccw->cda = (__u32)(addr_t) count_data;
1818 cqr->startdev = device;
1819 cqr->memdev = device;
1821 cqr->buildclk = get_clock();
1822 cqr->status = DASD_CQR_FILLED;
1826 /* differentiate between 'no record found' and any other error */
1827 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
1830 if (init_cqr->status == DASD_CQR_DONE)
1832 else if (init_cqr->status == DASD_CQR_NEED_ERP ||
1833 init_cqr->status == DASD_CQR_FAILED) {
1834 sense = dasd_get_sense(&init_cqr->irb);
1835 if (sense && (sense[1] & SNS1_NO_REC_FOUND))
1836 return INIT_CQR_UNFORMATTED;
1838 return INIT_CQR_ERROR;
1840 return INIT_CQR_ERROR;
1844 * This is the callback function for the init_analysis cqr. It saves
1845 * the status of the initial analysis ccw before it frees it and kicks
1846 * the device to continue the startup sequence. This will call
1847 * dasd_eckd_do_analysis again (if the devices has not been marked
1848 * for deletion in the meantime).
1850 static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
1853 struct dasd_eckd_private *private;
1854 struct dasd_device *device;
1856 device = init_cqr->startdev;
1857 private = (struct dasd_eckd_private *) device->private;
1858 private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
1859 dasd_sfree_request(init_cqr, device);
1860 dasd_kick_device(device);
1863 static int dasd_eckd_start_analysis(struct dasd_block *block)
1865 struct dasd_ccw_req *init_cqr;
1867 init_cqr = dasd_eckd_analysis_ccw(block->base);
1868 if (IS_ERR(init_cqr))
1869 return PTR_ERR(init_cqr);
1870 init_cqr->callback = dasd_eckd_analysis_callback;
1871 init_cqr->callback_data = NULL;
1872 init_cqr->expires = 5*HZ;
1873 /* first try without ERP, so we can later handle unformatted
1874 * devices as special case
1876 clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
1877 init_cqr->retries = 0;
1878 dasd_add_request_head(init_cqr);
1882 static int dasd_eckd_end_analysis(struct dasd_block *block)
1884 struct dasd_device *device;
1885 struct dasd_eckd_private *private;
1886 struct eckd_count *count_area;
1887 unsigned int sb, blk_per_trk;
1889 struct dasd_ccw_req *init_cqr;
1891 device = block->base;
1892 private = (struct dasd_eckd_private *) device->private;
1893 status = private->init_cqr_status;
1894 private->init_cqr_status = -1;
1895 if (status == INIT_CQR_ERROR) {
1896 /* try again, this time with full ERP */
1897 init_cqr = dasd_eckd_analysis_ccw(device);
1898 dasd_sleep_on(init_cqr);
1899 status = dasd_eckd_analysis_evaluation(init_cqr);
1900 dasd_sfree_request(init_cqr, device);
1903 if (device->features & DASD_FEATURE_USERAW) {
1904 block->bp_block = DASD_RAW_BLOCKSIZE;
1905 blk_per_trk = DASD_RAW_BLOCK_PER_TRACK;
1906 block->s2b_shift = 3;
1910 if (status == INIT_CQR_UNFORMATTED) {
1911 dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
1912 return -EMEDIUMTYPE;
1913 } else if (status == INIT_CQR_ERROR) {
1914 dev_err(&device->cdev->dev,
1915 "Detecting the DASD disk layout failed because "
1916 "of an I/O error\n");
1920 private->uses_cdl = 1;
1921 /* Check Track 0 for Compatible Disk Layout */
1923 for (i = 0; i < 3; i++) {
1924 if (private->count_area[i].kl != 4 ||
1925 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
1926 private->uses_cdl = 0;
1931 count_area = &private->count_area[4];
1933 if (private->uses_cdl == 0) {
1934 for (i = 0; i < 5; i++) {
1935 if ((private->count_area[i].kl != 0) ||
1936 (private->count_area[i].dl !=
1937 private->count_area[0].dl))
1941 count_area = &private->count_area[0];
1943 if (private->count_area[3].record == 1)
1944 dev_warn(&device->cdev->dev,
1945 "Track 0 has no records following the VTOC\n");
1948 if (count_area != NULL && count_area->kl == 0) {
1949 /* we found notthing violating our disk layout */
1950 if (dasd_check_blocksize(count_area->dl) == 0)
1951 block->bp_block = count_area->dl;
1953 if (block->bp_block == 0) {
1954 dev_warn(&device->cdev->dev,
1955 "The disk layout of the DASD is not supported\n");
1956 return -EMEDIUMTYPE;
1958 block->s2b_shift = 0; /* bits to shift 512 to get a block */
1959 for (sb = 512; sb < block->bp_block; sb = sb << 1)
1962 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
1965 block->blocks = (private->real_cyl *
1966 private->rdc_data.trk_per_cyl *
1969 dev_info(&device->cdev->dev,
1970 "DASD with %d KB/block, %d KB total size, %d KB/track, "
1971 "%s\n", (block->bp_block >> 10),
1972 ((private->real_cyl *
1973 private->rdc_data.trk_per_cyl *
1974 blk_per_trk * (block->bp_block >> 9)) >> 1),
1975 ((blk_per_trk * block->bp_block) >> 10),
1977 "compatible disk layout" : "linux disk layout");
1982 static int dasd_eckd_do_analysis(struct dasd_block *block)
1984 struct dasd_eckd_private *private;
1986 private = (struct dasd_eckd_private *) block->base->private;
1987 if (private->init_cqr_status < 0)
1988 return dasd_eckd_start_analysis(block);
1990 return dasd_eckd_end_analysis(block);
1993 static int dasd_eckd_ready_to_online(struct dasd_device *device)
1995 return dasd_alias_add_device(device);
1998 static int dasd_eckd_online_to_ready(struct dasd_device *device)
2000 cancel_work_sync(&device->reload_device);
2001 cancel_work_sync(&device->kick_validate);
2002 return dasd_alias_remove_device(device);
2006 dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
2008 struct dasd_eckd_private *private;
2010 private = (struct dasd_eckd_private *) block->base->private;
2011 if (dasd_check_blocksize(block->bp_block) == 0) {
2012 geo->sectors = recs_per_track(&private->rdc_data,
2013 0, block->bp_block);
2015 geo->cylinders = private->rdc_data.no_cyl;
2016 geo->heads = private->rdc_data.trk_per_cyl;
2020 static struct dasd_ccw_req *
2021 dasd_eckd_format_device(struct dasd_device * device,
2022 struct format_data_t * fdata)
2024 struct dasd_eckd_private *private;
2025 struct dasd_ccw_req *fcp;
2026 struct eckd_count *ect;
2030 struct ch_t address;
2031 int cplength, datasize;
2036 private = (struct dasd_eckd_private *) device->private;
2037 rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
2039 fdata->start_unit / private->rdc_data.trk_per_cyl,
2040 fdata->start_unit % private->rdc_data.trk_per_cyl);
2042 /* Sanity checks. */
2043 if (fdata->start_unit >=
2044 (private->real_cyl * private->rdc_data.trk_per_cyl)) {
2045 dev_warn(&device->cdev->dev, "Start track number %d used in "
2046 "formatting is too big\n", fdata->start_unit);
2047 return ERR_PTR(-EINVAL);
2049 if (fdata->start_unit > fdata->stop_unit) {
2050 dev_warn(&device->cdev->dev, "Start track %d used in "
2051 "formatting exceeds end track\n", fdata->start_unit);
2052 return ERR_PTR(-EINVAL);
2054 if (dasd_check_blocksize(fdata->blksize) != 0) {
2055 dev_warn(&device->cdev->dev,
2056 "The DASD cannot be formatted with block size %d\n",
2058 return ERR_PTR(-EINVAL);
2062 * fdata->intensity is a bit string that tells us what to do:
2063 * Bit 0: write record zero
2064 * Bit 1: write home address, currently not supported
2065 * Bit 2: invalidate tracks
2066 * Bit 3: use OS/390 compatible disk layout (cdl)
2067 * Bit 4: do not allow storage subsystem to modify record zero
2068 * Only some bit combinations do make sense.
2070 if (fdata->intensity & 0x10) {
2072 intensity = fdata->intensity & ~0x10;
2075 intensity = fdata->intensity;
2077 switch (intensity) {
2078 case 0x00: /* Normal format */
2079 case 0x08: /* Normal format, use cdl. */
2081 datasize = sizeof(struct DE_eckd_data) +
2082 sizeof(struct LO_eckd_data) +
2083 rpt * sizeof(struct eckd_count);
2085 case 0x01: /* Write record zero and format track. */
2086 case 0x09: /* Write record zero and format track, use cdl. */
2088 datasize = sizeof(struct DE_eckd_data) +
2089 sizeof(struct LO_eckd_data) +
2090 sizeof(struct eckd_count) +
2091 rpt * sizeof(struct eckd_count);
2093 case 0x04: /* Invalidate track. */
2094 case 0x0c: /* Invalidate track, use cdl. */
2096 datasize = sizeof(struct DE_eckd_data) +
2097 sizeof(struct LO_eckd_data) +
2098 sizeof(struct eckd_count);
2101 dev_warn(&device->cdev->dev, "An I/O control call used "
2102 "incorrect flags 0x%x\n", fdata->intensity);
2103 return ERR_PTR(-EINVAL);
2105 /* Allocate the format ccw request. */
2106 fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
2113 switch (intensity & ~0x08) {
2114 case 0x00: /* Normal format. */
2115 define_extent(ccw++, (struct DE_eckd_data *) data,
2116 fdata->start_unit, fdata->start_unit,
2117 DASD_ECKD_CCW_WRITE_CKD, device);
2118 /* grant subsystem permission to format R0 */
2120 ((struct DE_eckd_data *)data)->ga_extended |= 0x04;
2121 data += sizeof(struct DE_eckd_data);
2122 ccw[-1].flags |= CCW_FLAG_CC;
2123 locate_record(ccw++, (struct LO_eckd_data *) data,
2124 fdata->start_unit, 0, rpt,
2125 DASD_ECKD_CCW_WRITE_CKD, device,
2127 data += sizeof(struct LO_eckd_data);
2129 case 0x01: /* Write record zero + format track. */
2130 define_extent(ccw++, (struct DE_eckd_data *) data,
2131 fdata->start_unit, fdata->start_unit,
2132 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
2134 data += sizeof(struct DE_eckd_data);
2135 ccw[-1].flags |= CCW_FLAG_CC;
2136 locate_record(ccw++, (struct LO_eckd_data *) data,
2137 fdata->start_unit, 0, rpt + 1,
2138 DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
2139 device->block->bp_block);
2140 data += sizeof(struct LO_eckd_data);
2142 case 0x04: /* Invalidate track. */
2143 define_extent(ccw++, (struct DE_eckd_data *) data,
2144 fdata->start_unit, fdata->start_unit,
2145 DASD_ECKD_CCW_WRITE_CKD, device);
2146 data += sizeof(struct DE_eckd_data);
2147 ccw[-1].flags |= CCW_FLAG_CC;
2148 locate_record(ccw++, (struct LO_eckd_data *) data,
2149 fdata->start_unit, 0, 1,
2150 DASD_ECKD_CCW_WRITE_CKD, device, 8);
2151 data += sizeof(struct LO_eckd_data);
2154 if (intensity & 0x01) { /* write record zero */
2155 ect = (struct eckd_count *) data;
2156 data += sizeof(struct eckd_count);
2157 ect->cyl = address.cyl;
2158 ect->head = address.head;
2162 ccw[-1].flags |= CCW_FLAG_CC;
2163 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
2164 ccw->flags = CCW_FLAG_SLI;
2166 ccw->cda = (__u32)(addr_t) ect;
2169 if ((intensity & ~0x08) & 0x04) { /* erase track */
2170 ect = (struct eckd_count *) data;
2171 data += sizeof(struct eckd_count);
2172 ect->cyl = address.cyl;
2173 ect->head = address.head;
2177 ccw[-1].flags |= CCW_FLAG_CC;
2178 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
2179 ccw->flags = CCW_FLAG_SLI;
2181 ccw->cda = (__u32)(addr_t) ect;
2182 } else { /* write remaining records */
2183 for (i = 0; i < rpt; i++) {
2184 ect = (struct eckd_count *) data;
2185 data += sizeof(struct eckd_count);
2186 ect->cyl = address.cyl;
2187 ect->head = address.head;
2188 ect->record = i + 1;
2190 ect->dl = fdata->blksize;
2191 /* Check for special tracks 0-1 when formatting CDL */
2192 if ((intensity & 0x08) &&
2193 fdata->start_unit == 0) {
2196 ect->dl = sizes_trk0[i] - 4;
2199 if ((intensity & 0x08) &&
2200 fdata->start_unit == 1) {
2202 ect->dl = LABEL_SIZE - 44;
2204 ccw[-1].flags |= CCW_FLAG_CC;
2205 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
2206 ccw->flags = CCW_FLAG_SLI;
2208 ccw->cda = (__u32)(addr_t) ect;
2212 fcp->startdev = device;
2213 fcp->memdev = device;
2215 fcp->buildclk = get_clock();
2216 fcp->status = DASD_CQR_FILLED;
2220 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
2222 cqr->status = DASD_CQR_FILLED;
2223 if (cqr->block && (cqr->startdev != cqr->block->base)) {
2224 dasd_eckd_reset_ccw_to_base_io(cqr);
2225 cqr->startdev = cqr->block->base;
2226 cqr->lpm = cqr->block->base->path_data.opm;
2230 static dasd_erp_fn_t
2231 dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
2233 struct dasd_device *device = (struct dasd_device *) cqr->startdev;
2234 struct ccw_device *cdev = device->cdev;
2236 switch (cdev->id.cu_type) {
2241 return dasd_3990_erp_action;
2245 return dasd_default_erp_action;
2249 static dasd_erp_fn_t
2250 dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
2252 return dasd_default_erp_postaction;
2255 static void dasd_eckd_check_for_device_change(struct dasd_device *device,
2256 struct dasd_ccw_req *cqr,
2261 struct dasd_eckd_private *private;
2263 private = (struct dasd_eckd_private *) device->private;
2264 /* first of all check for state change pending interrupt */
2265 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
2266 if ((scsw_dstat(&irb->scsw) & mask) == mask) {
2268 * for alias only, not in offline processing
2269 * and only if not suspended
2271 if (!device->block && private->lcu &&
2272 device->state == DASD_STATE_ONLINE &&
2273 !test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2274 !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
2276 * the state change could be caused by an alias
2277 * reassignment remove device from alias handling
2278 * to prevent new requests from being scheduled on
2279 * the wrong alias device
2281 dasd_alias_remove_device(device);
2283 /* schedule worker to reload device */
2284 dasd_reload_device(device);
2286 dasd_generic_handle_state_change(device);
2290 sense = dasd_get_sense(irb);
2294 /* summary unit check */
2295 if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) &&
2296 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) {
2297 dasd_alias_handle_summary_unit_check(device, irb);
2301 /* service information message SIM */
2302 if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) &&
2303 ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
2304 dasd_3990_erp_handle_sim(device, sense);
2308 /* loss of device reservation is handled via base devices only
2309 * as alias devices may be used with several bases
2311 if (device->block && (sense[27] & DASD_SENSE_BIT_0) &&
2312 (sense[7] == 0x3F) &&
2313 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
2314 test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) {
2315 if (device->features & DASD_FEATURE_FAILONSLCK)
2316 set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
2317 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
2318 dev_err(&device->cdev->dev,
2319 "The device reservation was lost\n");
2323 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
2324 struct dasd_device *startdev,
2325 struct dasd_block *block,
2326 struct request *req,
2331 unsigned int first_offs,
2332 unsigned int last_offs,
2333 unsigned int blk_per_trk,
2334 unsigned int blksize)
2336 struct dasd_eckd_private *private;
2337 unsigned long *idaws;
2338 struct LO_eckd_data *LO_data;
2339 struct dasd_ccw_req *cqr;
2341 struct req_iterator iter;
2345 int count, cidaw, cplength, datasize;
2347 unsigned char cmd, rcmd;
2349 struct dasd_device *basedev;
2351 basedev = block->base;
2352 private = (struct dasd_eckd_private *) basedev->private;
2353 if (rq_data_dir(req) == READ)
2354 cmd = DASD_ECKD_CCW_READ_MT;
2355 else if (rq_data_dir(req) == WRITE)
2356 cmd = DASD_ECKD_CCW_WRITE_MT;
2358 return ERR_PTR(-EINVAL);
2360 /* Check struct bio and count the number of blocks for the request. */
2363 rq_for_each_segment(bv, req, iter) {
2364 if (bv->bv_len & (blksize - 1))
2365 /* Eckd can only do full blocks. */
2366 return ERR_PTR(-EINVAL);
2367 count += bv->bv_len >> (block->s2b_shift + 9);
2368 #if defined(CONFIG_64BIT)
2369 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
2370 cidaw += bv->bv_len >> (block->s2b_shift + 9);
2374 if (count != last_rec - first_rec + 1)
2375 return ERR_PTR(-EINVAL);
2377 /* use the prefix command if available */
2378 use_prefix = private->features.feature[8] & 0x01;
2380 /* 1x prefix + number of blocks */
2381 cplength = 2 + count;
2382 /* 1x prefix + cidaws*sizeof(long) */
2383 datasize = sizeof(struct PFX_eckd_data) +
2384 sizeof(struct LO_eckd_data) +
2385 cidaw * sizeof(unsigned long);
2387 /* 1x define extent + 1x locate record + number of blocks */
2388 cplength = 2 + count;
2389 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
2390 datasize = sizeof(struct DE_eckd_data) +
2391 sizeof(struct LO_eckd_data) +
2392 cidaw * sizeof(unsigned long);
2394 /* Find out the number of additional locate record ccws for cdl. */
2395 if (private->uses_cdl && first_rec < 2*blk_per_trk) {
2396 if (last_rec >= 2*blk_per_trk)
2397 count = 2*blk_per_trk - first_rec;
2399 datasize += count*sizeof(struct LO_eckd_data);
2401 /* Allocate the ccw request. */
2402 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2407 /* First ccw is define extent or prefix. */
2409 if (prefix(ccw++, cqr->data, first_trk,
2410 last_trk, cmd, basedev, startdev) == -EAGAIN) {
2411 /* Clock not in sync and XRC is enabled.
2414 dasd_sfree_request(cqr, startdev);
2415 return ERR_PTR(-EAGAIN);
2417 idaws = (unsigned long *) (cqr->data +
2418 sizeof(struct PFX_eckd_data));
2420 if (define_extent(ccw++, cqr->data, first_trk,
2421 last_trk, cmd, basedev) == -EAGAIN) {
2422 /* Clock not in sync and XRC is enabled.
2425 dasd_sfree_request(cqr, startdev);
2426 return ERR_PTR(-EAGAIN);
2428 idaws = (unsigned long *) (cqr->data +
2429 sizeof(struct DE_eckd_data));
2431 /* Build locate_record+read/write/ccws. */
2432 LO_data = (struct LO_eckd_data *) (idaws + cidaw);
2434 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
2435 /* Only standard blocks so there is just one locate record. */
2436 ccw[-1].flags |= CCW_FLAG_CC;
2437 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
2438 last_rec - recid + 1, cmd, basedev, blksize);
2440 rq_for_each_segment(bv, req, iter) {
2441 dst = page_address(bv->bv_page) + bv->bv_offset;
2442 if (dasd_page_cache) {
2443 char *copy = kmem_cache_alloc(dasd_page_cache,
2444 GFP_DMA | __GFP_NOWARN);
2445 if (copy && rq_data_dir(req) == WRITE)
2446 memcpy(copy + bv->bv_offset, dst, bv->bv_len);
2448 dst = copy + bv->bv_offset;
2450 for (off = 0; off < bv->bv_len; off += blksize) {
2451 sector_t trkid = recid;
2452 unsigned int recoffs = sector_div(trkid, blk_per_trk);
2455 /* Locate record for cdl special block ? */
2456 if (private->uses_cdl && recid < 2*blk_per_trk) {
2457 if (dasd_eckd_cdl_special(blk_per_trk, recid)){
2459 count = dasd_eckd_cdl_reclen(recid);
2460 if (count < blksize &&
2461 rq_data_dir(req) == READ)
2462 memset(dst + count, 0xe5,
2465 ccw[-1].flags |= CCW_FLAG_CC;
2466 locate_record(ccw++, LO_data++,
2468 1, rcmd, basedev, count);
2470 /* Locate record for standard blocks ? */
2471 if (private->uses_cdl && recid == 2*blk_per_trk) {
2472 ccw[-1].flags |= CCW_FLAG_CC;
2473 locate_record(ccw++, LO_data++,
2475 last_rec - recid + 1,
2476 cmd, basedev, count);
2478 /* Read/write ccw. */
2479 ccw[-1].flags |= CCW_FLAG_CC;
2480 ccw->cmd_code = rcmd;
2482 if (idal_is_needed(dst, blksize)) {
2483 ccw->cda = (__u32)(addr_t) idaws;
2484 ccw->flags = CCW_FLAG_IDA;
2485 idaws = idal_create_words(idaws, dst, blksize);
2487 ccw->cda = (__u32)(addr_t) dst;
2495 if (blk_noretry_request(req) ||
2496 block->base->features & DASD_FEATURE_FAILFAST)
2497 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2498 cqr->startdev = startdev;
2499 cqr->memdev = startdev;
2501 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2502 cqr->lpm = startdev->path_data.ppm;
2504 cqr->buildclk = get_clock();
2505 cqr->status = DASD_CQR_FILLED;
2509 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
2510 struct dasd_device *startdev,
2511 struct dasd_block *block,
2512 struct request *req,
2517 unsigned int first_offs,
2518 unsigned int last_offs,
2519 unsigned int blk_per_trk,
2520 unsigned int blksize)
2522 unsigned long *idaws;
2523 struct dasd_ccw_req *cqr;
2525 struct req_iterator iter;
2527 char *dst, *idaw_dst;
2528 unsigned int cidaw, cplength, datasize;
2532 struct dasd_device *basedev;
2533 unsigned int trkcount, count, count_to_trk_end;
2534 unsigned int idaw_len, seg_len, part_len, len_to_track_end;
2535 unsigned char new_track, end_idaw;
2537 unsigned int recoffs;
2539 basedev = block->base;
2540 if (rq_data_dir(req) == READ)
2541 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2542 else if (rq_data_dir(req) == WRITE)
2543 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2545 return ERR_PTR(-EINVAL);
2547 /* Track based I/O needs IDAWs for each page, and not just for
2548 * 64 bit addresses. We need additional idals for pages
2549 * that get filled from two tracks, so we use the number
2550 * of records as upper limit.
2552 cidaw = last_rec - first_rec + 1;
2553 trkcount = last_trk - first_trk + 1;
2555 /* 1x prefix + one read/write ccw per track */
2556 cplength = 1 + trkcount;
2558 /* on 31-bit we need space for two 32 bit addresses per page
2559 * on 64-bit one 64 bit address
2561 datasize = sizeof(struct PFX_eckd_data) +
2562 cidaw * sizeof(unsigned long long);
2564 /* Allocate the ccw request. */
2565 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
2570 /* transfer length factor: how many bytes to read from the last track */
2571 if (first_trk == last_trk)
2572 tlf = last_offs - first_offs + 1;
2574 tlf = last_offs + 1;
2577 if (prefix_LRE(ccw++, cqr->data, first_trk,
2578 last_trk, cmd, basedev, startdev,
2579 1 /* format */, first_offs + 1,
2582 /* Clock not in sync and XRC is enabled.
2585 dasd_sfree_request(cqr, startdev);
2586 return ERR_PTR(-EAGAIN);
2590 * The translation of request into ccw programs must meet the
2591 * following conditions:
2592 * - all idaws but the first and the last must address full pages
2593 * (or 2K blocks on 31-bit)
2594 * - the scope of a ccw and it's idal ends with the track boundaries
2596 idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
2600 len_to_track_end = 0;
2603 rq_for_each_segment(bv, req, iter) {
2604 dst = page_address(bv->bv_page) + bv->bv_offset;
2605 seg_len = bv->bv_len;
2609 recoffs = sector_div(trkid, blk_per_trk);
2610 count_to_trk_end = blk_per_trk - recoffs;
2611 count = min((last_rec - recid + 1),
2612 (sector_t)count_to_trk_end);
2613 len_to_track_end = count * blksize;
2614 ccw[-1].flags |= CCW_FLAG_CC;
2615 ccw->cmd_code = cmd;
2616 ccw->count = len_to_track_end;
2617 ccw->cda = (__u32)(addr_t)idaws;
2618 ccw->flags = CCW_FLAG_IDA;
2622 /* first idaw for a ccw may start anywhere */
2626 /* If we start a new idaw, we must make sure that it
2627 * starts on an IDA_BLOCK_SIZE boundary.
2628 * If we continue an idaw, we must make sure that the
2629 * current segment begins where the so far accumulated
2633 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
2634 dasd_sfree_request(cqr, startdev);
2635 return ERR_PTR(-ERANGE);
2639 if ((idaw_dst + idaw_len) != dst) {
2640 dasd_sfree_request(cqr, startdev);
2641 return ERR_PTR(-ERANGE);
2643 part_len = min(seg_len, len_to_track_end);
2644 seg_len -= part_len;
2646 idaw_len += part_len;
2647 len_to_track_end -= part_len;
2648 /* collected memory area ends on an IDA_BLOCK border,
2650 * idal_create_words will handle cases where idaw_len
2651 * is larger then IDA_BLOCK_SIZE
2653 if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
2655 /* We also need to end the idaw at track end */
2656 if (!len_to_track_end) {
2661 idaws = idal_create_words(idaws, idaw_dst,
2670 if (blk_noretry_request(req) ||
2671 block->base->features & DASD_FEATURE_FAILFAST)
2672 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2673 cqr->startdev = startdev;
2674 cqr->memdev = startdev;
2676 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2677 cqr->lpm = startdev->path_data.ppm;
2679 cqr->buildclk = get_clock();
2680 cqr->status = DASD_CQR_FILLED;
2684 static int prepare_itcw(struct itcw *itcw,
2685 unsigned int trk, unsigned int totrk, int cmd,
2686 struct dasd_device *basedev,
2687 struct dasd_device *startdev,
2688 unsigned int rec_on_trk, int count,
2689 unsigned int blksize,
2690 unsigned int total_data_size,
2692 unsigned int blk_per_trk)
2694 struct PFX_eckd_data pfxdata;
2695 struct dasd_eckd_private *basepriv, *startpriv;
2696 struct DE_eckd_data *dedata;
2697 struct LRE_eckd_data *lredata;
2701 u16 heads, beghead, endhead;
2709 /* setup prefix data */
2710 basepriv = (struct dasd_eckd_private *) basedev->private;
2711 startpriv = (struct dasd_eckd_private *) startdev->private;
2712 dedata = &pfxdata.define_extent;
2713 lredata = &pfxdata.locate_record;
2715 memset(&pfxdata, 0, sizeof(pfxdata));
2716 pfxdata.format = 1; /* PFX with LRE */
2717 pfxdata.base_address = basepriv->ned->unit_addr;
2718 pfxdata.base_lss = basepriv->ned->ID;
2719 pfxdata.validity.define_extent = 1;
2721 /* private uid is kept up to date, conf_data may be outdated */
2722 if (startpriv->uid.type != UA_BASE_DEVICE) {
2723 pfxdata.validity.verify_base = 1;
2724 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
2725 pfxdata.validity.hyper_pav = 1;
2729 case DASD_ECKD_CCW_READ_TRACK_DATA:
2730 dedata->mask.perm = 0x1;
2731 dedata->attributes.operation = basepriv->attrib.operation;
2732 dedata->blk_size = blksize;
2733 dedata->ga_extended |= 0x42;
2734 lredata->operation.orientation = 0x0;
2735 lredata->operation.operation = 0x0C;
2736 lredata->auxiliary.check_bytes = 0x01;
2737 pfx_cmd = DASD_ECKD_CCW_PFX_READ;
2739 case DASD_ECKD_CCW_WRITE_TRACK_DATA:
2740 dedata->mask.perm = 0x02;
2741 dedata->attributes.operation = basepriv->attrib.operation;
2742 dedata->blk_size = blksize;
2743 rc = check_XRC_on_prefix(&pfxdata, basedev);
2744 dedata->ga_extended |= 0x42;
2745 lredata->operation.orientation = 0x0;
2746 lredata->operation.operation = 0x3F;
2747 lredata->extended_operation = 0x23;
2748 lredata->auxiliary.check_bytes = 0x2;
2749 pfx_cmd = DASD_ECKD_CCW_PFX;
2752 DBF_DEV_EVENT(DBF_ERR, basedev,
2753 "prepare itcw, unknown opcode 0x%x", cmd);
2760 dedata->attributes.mode = 0x3; /* ECKD */
2762 heads = basepriv->rdc_data.trk_per_cyl;
2763 begcyl = trk / heads;
2764 beghead = trk % heads;
2765 endcyl = totrk / heads;
2766 endhead = totrk % heads;
2768 /* check for sequential prestage - enhance cylinder range */
2769 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
2770 dedata->attributes.operation == DASD_SEQ_ACCESS) {
2772 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
2773 endcyl += basepriv->attrib.nr_cyl;
2775 endcyl = (basepriv->real_cyl - 1);
2778 set_ch_t(&dedata->beg_ext, begcyl, beghead);
2779 set_ch_t(&dedata->end_ext, endcyl, endhead);
2781 dedata->ep_format = 0x20; /* records per track is valid */
2782 dedata->ep_rec_per_track = blk_per_trk;
2785 switch (basepriv->rdc_data.dev_type) {
2787 dn = ceil_quot(blksize + 6, 232);
2788 d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
2789 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
2792 d = 7 + ceil_quot(blksize + 12, 32);
2793 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
2798 lredata->auxiliary.length_valid = 1;
2799 lredata->auxiliary.length_scope = 1;
2800 lredata->auxiliary.imbedded_ccw_valid = 1;
2801 lredata->length = tlf;
2802 lredata->imbedded_ccw = cmd;
2803 lredata->count = count;
2804 lredata->sector = sector;
2805 set_ch_t(&lredata->seek_addr, begcyl, beghead);
2806 lredata->search_arg.cyl = lredata->seek_addr.cyl;
2807 lredata->search_arg.head = lredata->seek_addr.head;
2808 lredata->search_arg.record = rec_on_trk;
2810 dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
2811 &pfxdata, sizeof(pfxdata), total_data_size);
2812 return IS_ERR(dcw) ? PTR_ERR(dcw) : 0;
2815 static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2816 struct dasd_device *startdev,
2817 struct dasd_block *block,
2818 struct request *req,
2823 unsigned int first_offs,
2824 unsigned int last_offs,
2825 unsigned int blk_per_trk,
2826 unsigned int blksize)
2828 struct dasd_ccw_req *cqr;
2829 struct req_iterator iter;
2832 unsigned int trkcount, ctidaw;
2834 struct dasd_device *basedev;
2837 struct tidaw *last_tidaw = NULL;
2841 unsigned int seg_len, part_len, len_to_track_end;
2842 unsigned char new_track;
2843 sector_t recid, trkid;
2845 unsigned int count, count_to_trk_end;
2848 basedev = block->base;
2849 if (rq_data_dir(req) == READ) {
2850 cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
2851 itcw_op = ITCW_OP_READ;
2852 } else if (rq_data_dir(req) == WRITE) {
2853 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
2854 itcw_op = ITCW_OP_WRITE;
2856 return ERR_PTR(-EINVAL);
2858 /* trackbased I/O needs address all memory via TIDAWs,
2859 * not just for 64 bit addresses. This allows us to map
2860 * each segment directly to one tidaw.
2861 * In the case of write requests, additional tidaws may
2862 * be needed when a segment crosses a track boundary.
2864 trkcount = last_trk - first_trk + 1;
2866 rq_for_each_segment(bv, req, iter) {
2869 if (rq_data_dir(req) == WRITE)
2870 ctidaw += (last_trk - first_trk);
2872 /* Allocate the ccw request. */
2873 itcw_size = itcw_calc_size(0, ctidaw, 0);
2874 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
2878 /* transfer length factor: how many bytes to read from the last track */
2879 if (first_trk == last_trk)
2880 tlf = last_offs - first_offs + 1;
2882 tlf = last_offs + 1;
2885 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
2890 cqr->cpaddr = itcw_get_tcw(itcw);
2891 if (prepare_itcw(itcw, first_trk, last_trk,
2892 cmd, basedev, startdev,
2895 (last_rec - first_rec + 1) * blksize,
2896 tlf, blk_per_trk) == -EAGAIN) {
2897 /* Clock not in sync and XRC is enabled.
2903 len_to_track_end = 0;
2905 * A tidaw can address 4k of memory, but must not cross page boundaries
2906 * We can let the block layer handle this by setting
2907 * blk_queue_segment_boundary to page boundaries and
2908 * blk_max_segment_size to page size when setting up the request queue.
2909 * For write requests, a TIDAW must not cross track boundaries, because
2910 * we have to set the CBC flag on the last tidaw for each track.
2912 if (rq_data_dir(req) == WRITE) {
2915 rq_for_each_segment(bv, req, iter) {
2916 dst = page_address(bv->bv_page) + bv->bv_offset;
2917 seg_len = bv->bv_len;
2921 offs = sector_div(trkid, blk_per_trk);
2922 count_to_trk_end = blk_per_trk - offs;
2923 count = min((last_rec - recid + 1),
2924 (sector_t)count_to_trk_end);
2925 len_to_track_end = count * blksize;
2929 part_len = min(seg_len, len_to_track_end);
2930 seg_len -= part_len;
2931 len_to_track_end -= part_len;
2932 /* We need to end the tidaw at track end */
2933 if (!len_to_track_end) {
2935 tidaw_flags = TIDAW_FLAGS_INSERT_CBC;
2938 last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
2940 if (IS_ERR(last_tidaw)) {
2948 rq_for_each_segment(bv, req, iter) {
2949 dst = page_address(bv->bv_page) + bv->bv_offset;
2950 last_tidaw = itcw_add_tidaw(itcw, 0x00,
2952 if (IS_ERR(last_tidaw)) {
2958 last_tidaw->flags |= TIDAW_FLAGS_LAST;
2959 last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC;
2960 itcw_finalize(itcw);
2962 if (blk_noretry_request(req) ||
2963 block->base->features & DASD_FEATURE_FAILFAST)
2964 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
2966 cqr->startdev = startdev;
2967 cqr->memdev = startdev;
2969 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2970 cqr->lpm = startdev->path_data.ppm;
2972 cqr->buildclk = get_clock();
2973 cqr->status = DASD_CQR_FILLED;
2976 dasd_sfree_request(cqr, startdev);
2977 return ERR_PTR(ret);
2980 static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
2981 struct dasd_block *block,
2982 struct request *req)
2987 struct dasd_eckd_private *private;
2988 struct dasd_device *basedev;
2989 sector_t first_rec, last_rec;
2990 sector_t first_trk, last_trk;
2991 unsigned int first_offs, last_offs;
2992 unsigned int blk_per_trk, blksize;
2994 unsigned int data_size;
2995 struct dasd_ccw_req *cqr;
2997 basedev = block->base;
2998 private = (struct dasd_eckd_private *) basedev->private;
3000 /* Calculate number of blocks/records per track. */
3001 blksize = block->bp_block;
3002 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
3003 if (blk_per_trk == 0)
3004 return ERR_PTR(-EINVAL);
3005 /* Calculate record id of first and last block. */
3006 first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
3007 first_offs = sector_div(first_trk, blk_per_trk);
3008 last_rec = last_trk =
3009 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
3010 last_offs = sector_div(last_trk, blk_per_trk);
3011 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
3013 fcx_multitrack = private->features.feature[40] & 0x20;
3014 data_size = blk_rq_bytes(req);
3015 /* tpm write request add CBC data on each track boundary */
3016 if (rq_data_dir(req) == WRITE)
3017 data_size += (last_trk - first_trk) * 4;
3019 /* is read track data and write track data in command mode supported? */
3020 cmdrtd = private->features.feature[9] & 0x20;
3021 cmdwtd = private->features.feature[12] & 0x40;
3022 use_prefix = private->features.feature[8] & 0x01;
3025 if (cdlspecial || dasd_page_cache) {
3026 /* do nothing, just fall through to the cmd mode single case */
3027 } else if ((data_size <= private->fcx_max_data)
3028 && (fcx_multitrack || (first_trk == last_trk))) {
3029 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
3030 first_rec, last_rec,
3031 first_trk, last_trk,
3032 first_offs, last_offs,
3033 blk_per_trk, blksize);
3034 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3035 (PTR_ERR(cqr) != -ENOMEM))
3037 } else if (use_prefix &&
3038 (((rq_data_dir(req) == READ) && cmdrtd) ||
3039 ((rq_data_dir(req) == WRITE) && cmdwtd))) {
3040 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
3041 first_rec, last_rec,
3042 first_trk, last_trk,
3043 first_offs, last_offs,
3044 blk_per_trk, blksize);
3045 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
3046 (PTR_ERR(cqr) != -ENOMEM))
3050 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
3051 first_rec, last_rec,
3052 first_trk, last_trk,
3053 first_offs, last_offs,
3054 blk_per_trk, blksize);
3058 static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev,
3059 struct dasd_block *block,
3060 struct request *req)
3062 unsigned long *idaws;
3063 struct dasd_device *basedev;
3064 struct dasd_ccw_req *cqr;
3066 struct req_iterator iter;
3070 unsigned int trkcount;
3071 unsigned int seg_len, len_to_track_end;
3072 unsigned int first_offs;
3073 unsigned int cidaw, cplength, datasize;
3074 sector_t first_trk, last_trk;
3075 unsigned int pfx_datasize;
3078 * raw track access needs to be mutiple of 64k and on 64k boundary
3080 if ((blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK) != 0) {
3081 cqr = ERR_PTR(-EINVAL);
3084 if (((blk_rq_pos(req) + blk_rq_sectors(req)) %
3085 DASD_RAW_SECTORS_PER_TRACK) != 0) {
3086 cqr = ERR_PTR(-EINVAL);
3090 first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK;
3091 last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
3092 DASD_RAW_SECTORS_PER_TRACK;
3093 trkcount = last_trk - first_trk + 1;
3095 basedev = block->base;
3097 if (rq_data_dir(req) == READ)
3098 cmd = DASD_ECKD_CCW_READ_TRACK;
3099 else if (rq_data_dir(req) == WRITE)
3100 cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK;
3102 cqr = ERR_PTR(-EINVAL);
3107 * Raw track based I/O needs IDAWs for each page,
3108 * and not just for 64 bit addresses.
3110 cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK;
3112 /* 1x prefix + one read/write ccw per track */
3113 cplength = 1 + trkcount;
3116 * struct PFX_eckd_data has up to 2 byte as extended parameter
3117 * this is needed for write full track and has to be mentioned
3119 * add 8 instead of 2 to keep 8 byte boundary
3121 pfx_datasize = sizeof(struct PFX_eckd_data) + 8;
3123 datasize = pfx_datasize + cidaw * sizeof(unsigned long long);
3125 /* Allocate the ccw request. */
3126 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
3127 datasize, startdev);
3132 if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd,
3133 basedev, startdev, 1 /* format */, first_offs + 1,
3134 trkcount, 0, 0) == -EAGAIN) {
3135 /* Clock not in sync and XRC is enabled.
3138 dasd_sfree_request(cqr, startdev);
3139 cqr = ERR_PTR(-EAGAIN);
3143 idaws = (unsigned long *)(cqr->data + pfx_datasize);
3145 len_to_track_end = 0;
3147 rq_for_each_segment(bv, req, iter) {
3148 dst = page_address(bv->bv_page) + bv->bv_offset;
3149 seg_len = bv->bv_len;
3150 if (!len_to_track_end) {
3151 ccw[-1].flags |= CCW_FLAG_CC;
3152 ccw->cmd_code = cmd;
3153 /* maximum 3390 track size */
3155 /* 64k map to one track */
3156 len_to_track_end = 65536;
3157 ccw->cda = (__u32)(addr_t)idaws;
3158 ccw->flags |= CCW_FLAG_IDA;
3159 ccw->flags |= CCW_FLAG_SLI;
3162 len_to_track_end -= seg_len;
3163 idaws = idal_create_words(idaws, dst, seg_len);
3166 if (blk_noretry_request(req) ||
3167 block->base->features & DASD_FEATURE_FAILFAST)
3168 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3169 cqr->startdev = startdev;
3170 cqr->memdev = startdev;
3172 cqr->expires = startdev->default_expires * HZ;
3173 cqr->lpm = startdev->path_data.ppm;
3175 cqr->buildclk = get_clock();
3176 cqr->status = DASD_CQR_FILLED;
3178 if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
3186 dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
3188 struct dasd_eckd_private *private;
3190 struct req_iterator iter;
3193 unsigned int blksize, blk_per_trk, off;
3197 if (!dasd_page_cache)
3199 private = (struct dasd_eckd_private *) cqr->block->base->private;
3200 blksize = cqr->block->bp_block;
3201 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
3202 recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
3204 /* Skip over define extent & locate record. */
3206 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
3208 rq_for_each_segment(bv, req, iter) {
3209 dst = page_address(bv->bv_page) + bv->bv_offset;
3210 for (off = 0; off < bv->bv_len; off += blksize) {
3211 /* Skip locate record. */
3212 if (private->uses_cdl && recid <= 2*blk_per_trk)
3215 if (ccw->flags & CCW_FLAG_IDA)
3216 cda = *((char **)((addr_t) ccw->cda));
3218 cda = (char *)((addr_t) ccw->cda);
3220 if (rq_data_dir(req) == READ)
3221 memcpy(dst, cda, bv->bv_len);
3222 kmem_cache_free(dasd_page_cache,
3223 (void *)((addr_t)cda & PAGE_MASK));
3232 status = cqr->status == DASD_CQR_DONE;
3233 dasd_sfree_request(cqr, cqr->memdev);
3238 * Modify ccw/tcw in cqr so it can be started on a base device.
3240 * Note that this is not enough to restart the cqr!
3241 * Either reset cqr->startdev as well (summary unit check handling)
3242 * or restart via separate cqr (as in ERP handling).
3244 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
3247 struct PFX_eckd_data *pfxdata;
3252 if (cqr->cpmode == 1) {
3254 tccb = tcw_get_tccb(tcw);
3255 dcw = (struct dcw *)&tccb->tca[0];
3256 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
3257 pfxdata->validity.verify_base = 0;
3258 pfxdata->validity.hyper_pav = 0;
3261 pfxdata = cqr->data;
3262 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
3263 pfxdata->validity.verify_base = 0;
3264 pfxdata->validity.hyper_pav = 0;
3269 #define DASD_ECKD_CHANQ_MAX_SIZE 4
3271 static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
3272 struct dasd_block *block,
3273 struct request *req)
3275 struct dasd_eckd_private *private;
3276 struct dasd_device *startdev;
3277 unsigned long flags;
3278 struct dasd_ccw_req *cqr;
3280 startdev = dasd_alias_get_start_dev(base);
3283 private = (struct dasd_eckd_private *) startdev->private;
3284 if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
3285 return ERR_PTR(-EBUSY);
3287 spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
3289 if ((base->features & DASD_FEATURE_USERAW))
3290 cqr = dasd_raw_build_cp(startdev, block, req);
3292 cqr = dasd_eckd_build_cp(startdev, block, req);
3295 spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
3299 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
3300 struct request *req)
3302 struct dasd_eckd_private *private;
3303 unsigned long flags;
3305 spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
3306 private = (struct dasd_eckd_private *) cqr->memdev->private;
3308 spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
3309 return dasd_eckd_free_cp(cqr, req);
3313 dasd_eckd_fill_info(struct dasd_device * device,
3314 struct dasd_information2_t * info)
3316 struct dasd_eckd_private *private;
3318 private = (struct dasd_eckd_private *) device->private;
3319 info->label_block = 2;
3320 info->FBA_layout = private->uses_cdl ? 0 : 1;
3321 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
3322 info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
3323 memcpy(info->characteristics, &private->rdc_data,
3324 sizeof(struct dasd_eckd_characteristics));
3325 info->confdata_size = min((unsigned long)private->conf_len,
3326 sizeof(info->configuration_data));
3327 memcpy(info->configuration_data, private->conf_data,
3328 info->confdata_size);
3333 * SECTION: ioctl functions for eckd devices.
3337 * Release device ioctl.
3338 * Buils a channel programm to releases a prior reserved
3339 * (see dasd_eckd_reserve) device.
3342 dasd_eckd_release(struct dasd_device *device)
3344 struct dasd_ccw_req *cqr;
3349 if (!capable(CAP_SYS_ADMIN))
3353 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
3355 mutex_lock(&dasd_reserve_mutex);
3357 cqr = &dasd_reserve_req->cqr;
3358 memset(cqr, 0, sizeof(*cqr));
3359 memset(&dasd_reserve_req->ccw, 0,
3360 sizeof(dasd_reserve_req->ccw));
3361 cqr->cpaddr = &dasd_reserve_req->ccw;
3362 cqr->data = &dasd_reserve_req->data;
3363 cqr->magic = DASD_ECKD_MAGIC;
3366 ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
3367 ccw->flags |= CCW_FLAG_SLI;
3369 ccw->cda = (__u32)(addr_t) cqr->data;
3370 cqr->startdev = device;
3371 cqr->memdev = device;
3372 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3373 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3374 cqr->retries = 2; /* set retry counter to enable basic ERP */
3375 cqr->expires = 2 * HZ;
3376 cqr->buildclk = get_clock();
3377 cqr->status = DASD_CQR_FILLED;
3379 rc = dasd_sleep_on_immediatly(cqr);
3381 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3384 mutex_unlock(&dasd_reserve_mutex);
3386 dasd_sfree_request(cqr, cqr->memdev);
3391 * Reserve device ioctl.
3392 * Options are set to 'synchronous wait for interrupt' and
3393 * 'timeout the request'. This leads to a terminate IO if
3394 * the interrupt is outstanding for a certain time.
3397 dasd_eckd_reserve(struct dasd_device *device)
3399 struct dasd_ccw_req *cqr;
3404 if (!capable(CAP_SYS_ADMIN))
3408 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
3410 mutex_lock(&dasd_reserve_mutex);
3412 cqr = &dasd_reserve_req->cqr;
3413 memset(cqr, 0, sizeof(*cqr));
3414 memset(&dasd_reserve_req->ccw, 0,
3415 sizeof(dasd_reserve_req->ccw));
3416 cqr->cpaddr = &dasd_reserve_req->ccw;
3417 cqr->data = &dasd_reserve_req->data;
3418 cqr->magic = DASD_ECKD_MAGIC;
3421 ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
3422 ccw->flags |= CCW_FLAG_SLI;
3424 ccw->cda = (__u32)(addr_t) cqr->data;
3425 cqr->startdev = device;
3426 cqr->memdev = device;
3427 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3428 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3429 cqr->retries = 2; /* set retry counter to enable basic ERP */
3430 cqr->expires = 2 * HZ;
3431 cqr->buildclk = get_clock();
3432 cqr->status = DASD_CQR_FILLED;
3434 rc = dasd_sleep_on_immediatly(cqr);
3436 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3439 mutex_unlock(&dasd_reserve_mutex);
3441 dasd_sfree_request(cqr, cqr->memdev);
3446 * Steal lock ioctl - unconditional reserve device.
3447 * Buils a channel programm to break a device's reservation.
3448 * (unconditional reserve)
3451 dasd_eckd_steal_lock(struct dasd_device *device)
3453 struct dasd_ccw_req *cqr;
3458 if (!capable(CAP_SYS_ADMIN))
3462 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
3464 mutex_lock(&dasd_reserve_mutex);
3466 cqr = &dasd_reserve_req->cqr;
3467 memset(cqr, 0, sizeof(*cqr));
3468 memset(&dasd_reserve_req->ccw, 0,
3469 sizeof(dasd_reserve_req->ccw));
3470 cqr->cpaddr = &dasd_reserve_req->ccw;
3471 cqr->data = &dasd_reserve_req->data;
3472 cqr->magic = DASD_ECKD_MAGIC;
3475 ccw->cmd_code = DASD_ECKD_CCW_SLCK;
3476 ccw->flags |= CCW_FLAG_SLI;
3478 ccw->cda = (__u32)(addr_t) cqr->data;
3479 cqr->startdev = device;
3480 cqr->memdev = device;
3481 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3482 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3483 cqr->retries = 2; /* set retry counter to enable basic ERP */
3484 cqr->expires = 2 * HZ;
3485 cqr->buildclk = get_clock();
3486 cqr->status = DASD_CQR_FILLED;
3488 rc = dasd_sleep_on_immediatly(cqr);
3490 set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
3493 mutex_unlock(&dasd_reserve_mutex);
3495 dasd_sfree_request(cqr, cqr->memdev);
3500 * SNID - Sense Path Group ID
3501 * This ioctl may be used in situations where I/O is stalled due to
3502 * a reserve, so if the normal dasd_smalloc_request fails, we use the
3503 * preallocated dasd_reserve_req.
3505 static int dasd_eckd_snid(struct dasd_device *device,
3508 struct dasd_ccw_req *cqr;
3512 struct dasd_snid_ioctl_data usrparm;
3514 if (!capable(CAP_SYS_ADMIN))
3517 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
3521 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1,
3522 sizeof(struct dasd_snid_data), device);
3524 mutex_lock(&dasd_reserve_mutex);
3526 cqr = &dasd_reserve_req->cqr;
3527 memset(cqr, 0, sizeof(*cqr));
3528 memset(&dasd_reserve_req->ccw, 0,
3529 sizeof(dasd_reserve_req->ccw));
3530 cqr->cpaddr = &dasd_reserve_req->ccw;
3531 cqr->data = &dasd_reserve_req->data;
3532 cqr->magic = DASD_ECKD_MAGIC;
3535 ccw->cmd_code = DASD_ECKD_CCW_SNID;
3536 ccw->flags |= CCW_FLAG_SLI;
3538 ccw->cda = (__u32)(addr_t) cqr->data;
3539 cqr->startdev = device;
3540 cqr->memdev = device;
3541 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3542 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
3543 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
3545 cqr->expires = 10 * HZ;
3546 cqr->buildclk = get_clock();
3547 cqr->status = DASD_CQR_FILLED;
3548 cqr->lpm = usrparm.path_mask;
3550 rc = dasd_sleep_on_immediatly(cqr);
3551 /* verify that I/O processing didn't modify the path mask */
3552 if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask))
3555 usrparm.data = *((struct dasd_snid_data *)cqr->data);
3556 if (copy_to_user(argp, &usrparm, sizeof(usrparm)))
3561 mutex_unlock(&dasd_reserve_mutex);
3563 dasd_sfree_request(cqr, cqr->memdev);
3568 * Read performance statistics
3571 dasd_eckd_performance(struct dasd_device *device, void __user *argp)
3573 struct dasd_psf_prssd_data *prssdp;
3574 struct dasd_rssd_perf_stats_t *stats;
3575 struct dasd_ccw_req *cqr;
3579 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
3580 (sizeof(struct dasd_psf_prssd_data) +
3581 sizeof(struct dasd_rssd_perf_stats_t)),
3584 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3585 "Could not allocate initialization request");
3586 return PTR_ERR(cqr);
3588 cqr->startdev = device;
3589 cqr->memdev = device;
3591 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
3592 cqr->expires = 10 * HZ;
3594 /* Prepare for Read Subsystem Data */
3595 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
3596 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
3597 prssdp->order = PSF_ORDER_PRSSD;
3598 prssdp->suborder = 0x01; /* Performance Statistics */
3599 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
3602 ccw->cmd_code = DASD_ECKD_CCW_PSF;
3603 ccw->count = sizeof(struct dasd_psf_prssd_data);
3604 ccw->flags |= CCW_FLAG_CC;
3605 ccw->cda = (__u32)(addr_t) prssdp;
3607 /* Read Subsystem Data - Performance Statistics */
3608 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
3609 memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
3612 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
3613 ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
3614 ccw->cda = (__u32)(addr_t) stats;
3616 cqr->buildclk = get_clock();
3617 cqr->status = DASD_CQR_FILLED;
3618 rc = dasd_sleep_on(cqr);
3620 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
3621 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
3622 if (copy_to_user(argp, stats,
3623 sizeof(struct dasd_rssd_perf_stats_t)))
3626 dasd_sfree_request(cqr, cqr->memdev);
3631 * Get attributes (cache operations)
3632 * Returnes the cache attributes used in Define Extend (DE).
3635 dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
3637 struct dasd_eckd_private *private =
3638 (struct dasd_eckd_private *)device->private;
3639 struct attrib_data_t attrib = private->attrib;
3642 if (!capable(CAP_SYS_ADMIN))
3648 if (copy_to_user(argp, (long *) &attrib,
3649 sizeof(struct attrib_data_t)))
3656 * Set attributes (cache operations)
3657 * Stores the attributes for cache operation to be used in Define Extend (DE).
3660 dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
3662 struct dasd_eckd_private *private =
3663 (struct dasd_eckd_private *)device->private;
3664 struct attrib_data_t attrib;
3666 if (!capable(CAP_SYS_ADMIN))
3671 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
3673 private->attrib = attrib;
3675 dev_info(&device->cdev->dev,
3676 "The DASD cache mode was set to %x (%i cylinder prestage)\n",
3677 private->attrib.operation, private->attrib.nr_cyl);
3682 * Issue syscall I/O to EMC Symmetrix array.
3683 * CCWs are PSF and RSSD
3685 static int dasd_symm_io(struct dasd_device *device, void __user *argp)
3687 struct dasd_symmio_parms usrparm;
3688 char *psf_data, *rssd_result;
3689 struct dasd_ccw_req *cqr;
3694 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
3698 /* Copy parms from caller */
3700 if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
3702 if (is_compat_task() || sizeof(long) == 4) {
3703 /* Make sure pointers are sane even on 31 bit. */
3705 if ((usrparm.psf_data >> 32) != 0)
3707 if ((usrparm.rssd_result >> 32) != 0)
3709 usrparm.psf_data &= 0x7fffffffULL;
3710 usrparm.rssd_result &= 0x7fffffffULL;
3712 /* alloc I/O data area */
3713 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
3714 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
3715 if (!psf_data || !rssd_result) {
3720 /* get syscall header from user space */
3722 if (copy_from_user(psf_data,
3723 (void __user *)(unsigned long) usrparm.psf_data,
3724 usrparm.psf_data_len))
3729 /* setup CCWs for PSF + RSSD */
3730 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
3732 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3733 "Could not allocate initialization request");
3738 cqr->startdev = device;
3739 cqr->memdev = device;
3741 cqr->expires = 10 * HZ;
3742 cqr->buildclk = get_clock();
3743 cqr->status = DASD_CQR_FILLED;
3745 /* Build the ccws */
3749 ccw->cmd_code = DASD_ECKD_CCW_PSF;
3750 ccw->count = usrparm.psf_data_len;
3751 ccw->flags |= CCW_FLAG_CC;
3752 ccw->cda = (__u32)(addr_t) psf_data;
3757 ccw->cmd_code = DASD_ECKD_CCW_RSSD;
3758 ccw->count = usrparm.rssd_result_len;
3759 ccw->flags = CCW_FLAG_SLI ;
3760 ccw->cda = (__u32)(addr_t) rssd_result;
3762 rc = dasd_sleep_on(cqr);
3767 if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
3768 rssd_result, usrparm.rssd_result_len))
3773 dasd_sfree_request(cqr, cqr->memdev);
3778 DBF_DEV_EVENT(DBF_WARNING, device,
3779 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
3780 (int) psf0, (int) psf1, rc);
3785 dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
3787 struct dasd_device *device = block->base;
3791 return dasd_eckd_get_attrib(device, argp);
3793 return dasd_eckd_set_attrib(device, argp);
3795 return dasd_eckd_performance(device, argp);
3797 return dasd_eckd_release(device);
3799 return dasd_eckd_reserve(device);
3801 return dasd_eckd_steal_lock(device);
3803 return dasd_eckd_snid(device, argp);
3805 return dasd_symm_io(device, argp);
3812 * Dump the range of CCWs into 'page' buffer
3813 * and return number of printed chars.
3816 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
3822 while (from <= to) {
3823 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3824 " CCW %p: %08X %08X DAT:",
3825 from, ((int *) from)[0], ((int *) from)[1]);
3827 /* get pointer to data (consider IDALs) */
3828 if (from->flags & CCW_FLAG_IDA)
3829 datap = (char *) *((addr_t *) (addr_t) from->cda);
3831 datap = (char *) ((addr_t) from->cda);
3833 /* dump data (max 32 bytes) */
3834 for (count = 0; count < from->count && count < 32; count++) {
3835 if (count % 8 == 0) len += sprintf(page + len, " ");
3836 if (count % 4 == 0) len += sprintf(page + len, " ");
3837 len += sprintf(page + len, "%02x", datap[count]);
3839 len += sprintf(page + len, "\n");
3846 dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
3852 sense = (u64 *) dasd_get_sense(irb);
3853 stat = (u64 *) &irb->scsw;
3855 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : "
3856 "%016llx %016llx %016llx %016llx",
3857 reason, *stat, *((u32 *) (stat + 1)),
3858 sense[0], sense[1], sense[2], sense[3]);
3860 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s",
3861 reason, *stat, *((u32 *) (stat + 1)),
3867 * Print sense data and related channel program.
3868 * Parts are printed because printk buffer is only 1024 bytes.
3870 static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
3871 struct dasd_ccw_req *req, struct irb *irb)
3874 struct ccw1 *first, *last, *fail, *from, *to;
3877 page = (char *) get_zeroed_page(GFP_ATOMIC);
3879 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3880 "No memory to dump sense data\n");
3883 /* dump the sense data */
3884 len = sprintf(page, KERN_ERR PRINTK_HEADER
3885 " I/O status report for device %s:\n",
3886 dev_name(&device->cdev->dev));
3887 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3888 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
3890 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
3891 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
3892 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
3893 req ? req->intrc : 0);
3894 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3895 " device %s: Failing CCW: %p\n",
3896 dev_name(&device->cdev->dev),
3897 (void *) (addr_t) irb->scsw.cmd.cpa);
3898 if (irb->esw.esw0.erw.cons) {
3899 for (sl = 0; sl < 4; sl++) {
3900 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3901 " Sense(hex) %2d-%2d:",
3902 (8 * sl), ((8 * sl) + 7));
3904 for (sct = 0; sct < 8; sct++) {
3905 len += sprintf(page + len, " %02x",
3906 irb->ecw[8 * sl + sct]);
3908 len += sprintf(page + len, "\n");
3911 if (irb->ecw[27] & DASD_SENSE_BIT_0) {
3912 /* 24 Byte Sense Data */
3913 sprintf(page + len, KERN_ERR PRINTK_HEADER
3914 " 24 Byte: %x MSG %x, "
3915 "%s MSGb to SYSOP\n",
3916 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
3917 irb->ecw[1] & 0x10 ? "" : "no");
3919 /* 32 Byte Sense Data */
3920 sprintf(page + len, KERN_ERR PRINTK_HEADER
3921 " 32 Byte: Format: %x "
3922 "Exception class %x\n",
3923 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
3926 sprintf(page + len, KERN_ERR PRINTK_HEADER
3927 " SORRY - NO VALID SENSE AVAILABLE\n");
3932 /* req == NULL for unsolicited interrupts */
3933 /* dump the Channel Program (max 140 Bytes per line) */
3934 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
3935 first = req->cpaddr;
3936 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
3937 to = min(first + 6, last);
3938 len = sprintf(page, KERN_ERR PRINTK_HEADER
3939 " Related CP in req: %p\n", req);
3940 dasd_eckd_dump_ccw_range(first, to, page + len);
3943 /* print failing CCW area (maximum 4) */
3944 /* scsw->cda is either valid or zero */
3947 fail = (struct ccw1 *)(addr_t)
3948 irb->scsw.cmd.cpa; /* failing CCW */
3949 if (from < fail - 2) {
3950 from = fail - 2; /* there is a gap - print header */
3951 len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
3953 to = min(fail + 1, last);
3954 len += dasd_eckd_dump_ccw_range(from, to, page + len);
3956 /* print last CCWs (maximum 2) */
3957 from = max(from, ++to);
3958 if (from < last - 1) {
3959 from = last - 1; /* there is a gap - print header */
3960 len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
3962 len += dasd_eckd_dump_ccw_range(from, last, page + len);
3966 free_page((unsigned long) page);
3971 * Print sense data from a tcw.
3973 static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
3974 struct dasd_ccw_req *req, struct irb *irb)
3977 int len, sl, sct, residual;
3981 page = (char *) get_zeroed_page(GFP_ATOMIC);
3983 DBF_DEV_EVENT(DBF_WARNING, device, " %s",
3984 "No memory to dump sense data");
3987 /* dump the sense data */
3988 len = sprintf(page, KERN_ERR PRINTK_HEADER
3989 " I/O status report for device %s:\n",
3990 dev_name(&device->cdev->dev));
3991 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
3992 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
3993 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
3994 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
3995 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
3996 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
3997 irb->scsw.tm.fcxs, irb->scsw.tm.schxs,
3998 req ? req->intrc : 0);
3999 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4000 " device %s: Failing TCW: %p\n",
4001 dev_name(&device->cdev->dev),
4002 (void *) (addr_t) irb->scsw.tm.tcw);
4006 if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01))
4008 (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
4011 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4012 " tsb->length %d\n", tsb->length);
4013 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4014 " tsb->flags %x\n", tsb->flags);
4015 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4016 " tsb->dcw_offset %d\n", tsb->dcw_offset);
4017 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4018 " tsb->count %d\n", tsb->count);
4019 residual = tsb->count - 28;
4020 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4021 " residual %d\n", residual);
4023 switch (tsb->flags & 0x07) {
4024 case 1: /* tsa_iostat */
4025 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4026 " tsb->tsa.iostat.dev_time %d\n",
4027 tsb->tsa.iostat.dev_time);
4028 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4029 " tsb->tsa.iostat.def_time %d\n",
4030 tsb->tsa.iostat.def_time);
4031 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4032 " tsb->tsa.iostat.queue_time %d\n",
4033 tsb->tsa.iostat.queue_time);
4034 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4035 " tsb->tsa.iostat.dev_busy_time %d\n",
4036 tsb->tsa.iostat.dev_busy_time);
4037 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4038 " tsb->tsa.iostat.dev_act_time %d\n",
4039 tsb->tsa.iostat.dev_act_time);
4040 sense = tsb->tsa.iostat.sense;
4042 case 2: /* ts_ddpc */
4043 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4044 " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
4045 for (sl = 0; sl < 2; sl++) {
4046 len += sprintf(page + len,
4047 KERN_ERR PRINTK_HEADER
4048 " tsb->tsa.ddpc.rcq %2d-%2d: ",
4049 (8 * sl), ((8 * sl) + 7));
4050 rcq = tsb->tsa.ddpc.rcq;
4051 for (sct = 0; sct < 8; sct++) {
4052 len += sprintf(page + len, " %02x",
4055 len += sprintf(page + len, "\n");
4057 sense = tsb->tsa.ddpc.sense;
4059 case 3: /* tsa_intrg */
4060 len += sprintf(page + len, KERN_ERR PRINTK_HEADER
4061 " tsb->tsa.intrg.: not supportet yet \n");
4066 for (sl = 0; sl < 4; sl++) {
4067 len += sprintf(page + len,
4068 KERN_ERR PRINTK_HEADER
4069 " Sense(hex) %2d-%2d:",
4070 (8 * sl), ((8 * sl) + 7));
4071 for (sct = 0; sct < 8; sct++) {
4072 len += sprintf(page + len, " %02x",
4073 sense[8 * sl + sct]);
4075 len += sprintf(page + len, "\n");
4078 if (sense[27] & DASD_SENSE_BIT_0) {
4079 /* 24 Byte Sense Data */
4080 sprintf(page + len, KERN_ERR PRINTK_HEADER
4081 " 24 Byte: %x MSG %x, "
4082 "%s MSGb to SYSOP\n",
4083 sense[7] >> 4, sense[7] & 0x0f,
4084 sense[1] & 0x10 ? "" : "no");
4086 /* 32 Byte Sense Data */
4087 sprintf(page + len, KERN_ERR PRINTK_HEADER
4088 " 32 Byte: Format: %x "
4089 "Exception class %x\n",
4090 sense[6] & 0x0f, sense[22] >> 4);
4093 sprintf(page + len, KERN_ERR PRINTK_HEADER
4094 " SORRY - NO VALID SENSE AVAILABLE\n");
4097 sprintf(page + len, KERN_ERR PRINTK_HEADER
4098 " SORRY - NO TSB DATA AVAILABLE\n");
4101 free_page((unsigned long) page);
4104 static void dasd_eckd_dump_sense(struct dasd_device *device,
4105 struct dasd_ccw_req *req, struct irb *irb)
4107 if (scsw_is_tm(&irb->scsw))
4108 dasd_eckd_dump_sense_tcw(device, req, irb);
4110 dasd_eckd_dump_sense_ccw(device, req, irb);
4113 static int dasd_eckd_pm_freeze(struct dasd_device *device)
4116 * the device should be disconnected from our LCU structure
4117 * on restore we will reconnect it and reread LCU specific
4118 * information like PAV support that might have changed
4120 dasd_alias_remove_device(device);
4121 dasd_alias_disconnect_device_from_lcu(device);
4126 static int dasd_eckd_restore_device(struct dasd_device *device)
4128 struct dasd_eckd_private *private;
4129 struct dasd_eckd_characteristics temp_rdc_data;
4131 struct dasd_uid temp_uid;
4132 unsigned long flags;
4134 private = (struct dasd_eckd_private *) device->private;
4136 /* Read Configuration Data */
4137 rc = dasd_eckd_read_conf(device);
4141 dasd_eckd_get_uid(device, &temp_uid);
4142 /* Generate device unique id */
4143 rc = dasd_eckd_generate_uid(device);
4144 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
4145 if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
4146 dev_err(&device->cdev->dev, "The UID of the DASD has "
4148 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4152 /* register lcu with alias handling, enable PAV if this is a new lcu */
4153 rc = dasd_alias_make_device_known_to_lcu(device);
4156 dasd_eckd_validate_server(device);
4158 /* RE-Read Configuration Data */
4159 rc = dasd_eckd_read_conf(device);
4163 /* Read Feature Codes */
4164 dasd_eckd_read_features(device);
4166 /* Read Device Characteristics */
4167 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
4168 &temp_rdc_data, 64);
4170 DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
4171 "Read device characteristic failed, rc=%d", rc);
4174 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
4175 memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
4176 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4178 /* add device to alias management */
4179 dasd_alias_add_device(device);
4187 static int dasd_eckd_reload_device(struct dasd_device *device)
4189 struct dasd_eckd_private *private;
4192 struct dasd_uid uid;
4193 unsigned long flags;
4195 private = (struct dasd_eckd_private *) device->private;
4197 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
4198 old_base = private->uid.base_unit_addr;
4199 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
4201 /* Read Configuration Data */
4202 rc = dasd_eckd_read_conf(device);
4206 rc = dasd_eckd_generate_uid(device);
4210 * update unit address configuration and
4211 * add device to alias management
4213 dasd_alias_update_add_device(device);
4215 dasd_eckd_get_uid(device, &uid);
4217 if (old_base != uid.base_unit_addr) {
4218 if (strlen(uid.vduit) > 0)
4219 snprintf(print_uid, sizeof(print_uid),
4220 "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
4221 uid.ssid, uid.base_unit_addr, uid.vduit);
4223 snprintf(print_uid, sizeof(print_uid),
4224 "%s.%s.%04x.%02x", uid.vendor, uid.serial,
4225 uid.ssid, uid.base_unit_addr);
4227 dev_info(&device->cdev->dev,
4228 "An Alias device was reassigned to a new base device "
4229 "with UID: %s\n", print_uid);
4237 static struct ccw_driver dasd_eckd_driver = {
4239 .name = "dasd-eckd",
4240 .owner = THIS_MODULE,
4242 .ids = dasd_eckd_ids,
4243 .probe = dasd_eckd_probe,
4244 .remove = dasd_generic_remove,
4245 .set_offline = dasd_generic_set_offline,
4246 .set_online = dasd_eckd_set_online,
4247 .notify = dasd_generic_notify,
4248 .path_event = dasd_generic_path_event,
4249 .shutdown = dasd_generic_shutdown,
4250 .freeze = dasd_generic_pm_freeze,
4251 .thaw = dasd_generic_restore_device,
4252 .restore = dasd_generic_restore_device,
4253 .uc_handler = dasd_generic_uc_handler,
4254 .int_class = IOINT_DAS,
4258 * max_blocks is dependent on the amount of storage that is available
4259 * in the static io buffer for each device. Currently each device has
4260 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
4261 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
4262 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
4263 * addition we have one define extent ccw + 16 bytes of data and one
4264 * locate record ccw + 16 bytes of data. That makes:
4265 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
4266 * We want to fit two into the available memory so that we can immediately
4267 * start the next request if one finishes off. That makes 249.5 blocks
4268 * for one request. Give a little safety and the result is 240.
4270 static struct dasd_discipline dasd_eckd_discipline = {
4271 .owner = THIS_MODULE,
4275 .check_device = dasd_eckd_check_characteristics,
4276 .uncheck_device = dasd_eckd_uncheck_device,
4277 .do_analysis = dasd_eckd_do_analysis,
4278 .verify_path = dasd_eckd_verify_path,
4279 .ready_to_online = dasd_eckd_ready_to_online,
4280 .online_to_ready = dasd_eckd_online_to_ready,
4281 .fill_geometry = dasd_eckd_fill_geometry,
4282 .start_IO = dasd_start_IO,
4283 .term_IO = dasd_term_IO,
4284 .handle_terminated_request = dasd_eckd_handle_terminated_request,
4285 .format_device = dasd_eckd_format_device,
4286 .erp_action = dasd_eckd_erp_action,
4287 .erp_postaction = dasd_eckd_erp_postaction,
4288 .check_for_device_change = dasd_eckd_check_for_device_change,
4289 .build_cp = dasd_eckd_build_alias_cp,
4290 .free_cp = dasd_eckd_free_alias_cp,
4291 .dump_sense = dasd_eckd_dump_sense,
4292 .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
4293 .fill_info = dasd_eckd_fill_info,
4294 .ioctl = dasd_eckd_ioctl,
4295 .freeze = dasd_eckd_pm_freeze,
4296 .restore = dasd_eckd_restore_device,
4297 .reload = dasd_eckd_reload_device,
4298 .get_uid = dasd_eckd_get_uid,
4299 .kick_validate = dasd_eckd_kick_validate_server,
4303 dasd_eckd_init(void)
4307 ASCEBC(dasd_eckd_discipline.ebcname, 4);
4308 dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
4309 GFP_KERNEL | GFP_DMA);
4310 if (!dasd_reserve_req)
4312 path_verification_worker = kmalloc(sizeof(*path_verification_worker),
4313 GFP_KERNEL | GFP_DMA);
4314 if (!path_verification_worker) {
4315 kfree(dasd_reserve_req);
4318 ret = ccw_driver_register(&dasd_eckd_driver);
4320 wait_for_device_probe();
4322 kfree(path_verification_worker);
4323 kfree(dasd_reserve_req);
4329 dasd_eckd_cleanup(void)
4331 ccw_driver_unregister(&dasd_eckd_driver);
4332 kfree(path_verification_worker);
4333 kfree(dasd_reserve_req);
4336 module_init(dasd_eckd_init);
4337 module_exit(dasd_eckd_cleanup);