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