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, NULL); 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, NULL); 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, NULL); 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 NULL); 1820 if (IS_ERR(cqr)) 1821 return cqr; 1822 ccw = cqr->cpaddr; 1823 /* Define extent for the first 3 tracks. */ 1824 define_extent(ccw++, cqr->data, 0, 2, 1825 DASD_ECKD_CCW_READ_COUNT, device, 0); 1826 LO_data = cqr->data + sizeof(struct DE_eckd_data); 1827 /* Locate record for the first 4 records on track 0. */ 1828 ccw[-1].flags |= CCW_FLAG_CC; 1829 locate_record(ccw++, LO_data++, 0, 0, 4, 1830 DASD_ECKD_CCW_READ_COUNT, device, 0); 1831 1832 count_data = private->count_area; 1833 for (i = 0; i < 4; i++) { 1834 ccw[-1].flags |= CCW_FLAG_CC; 1835 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; 1836 ccw->flags = 0; 1837 ccw->count = 8; 1838 ccw->cda = (__u32)(addr_t) count_data; 1839 ccw++; 1840 count_data++; 1841 } 1842 1843 /* Locate record for the first record on track 2. */ 1844 ccw[-1].flags |= CCW_FLAG_CC; 1845 locate_record(ccw++, LO_data++, 2, 0, 1, 1846 DASD_ECKD_CCW_READ_COUNT, device, 0); 1847 /* Read count ccw. */ 1848 ccw[-1].flags |= CCW_FLAG_CC; 1849 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; 1850 ccw->flags = 0; 1851 ccw->count = 8; 1852 ccw->cda = (__u32)(addr_t) count_data; 1853 1854 cqr->block = NULL; 1855 cqr->startdev = device; 1856 cqr->memdev = device; 1857 cqr->retries = 255; 1858 cqr->buildclk = get_tod_clock(); 1859 cqr->status = DASD_CQR_FILLED; 1860 return cqr; 1861 } 1862 1863 /* differentiate between 'no record found' and any other error */ 1864 static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr) 1865 { 1866 char *sense; 1867 if (init_cqr->status == DASD_CQR_DONE) 1868 return INIT_CQR_OK; 1869 else if (init_cqr->status == DASD_CQR_NEED_ERP || 1870 init_cqr->status == DASD_CQR_FAILED) { 1871 sense = dasd_get_sense(&init_cqr->irb); 1872 if (sense && (sense[1] & SNS1_NO_REC_FOUND)) 1873 return INIT_CQR_UNFORMATTED; 1874 else 1875 return INIT_CQR_ERROR; 1876 } else 1877 return INIT_CQR_ERROR; 1878 } 1879 1880 /* 1881 * This is the callback function for the init_analysis cqr. It saves 1882 * the status of the initial analysis ccw before it frees it and kicks 1883 * the device to continue the startup sequence. This will call 1884 * dasd_eckd_do_analysis again (if the devices has not been marked 1885 * for deletion in the meantime). 1886 */ 1887 static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, 1888 void *data) 1889 { 1890 struct dasd_device *device = init_cqr->startdev; 1891 struct dasd_eckd_private *private = device->private; 1892 1893 private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr); 1894 dasd_sfree_request(init_cqr, device); 1895 dasd_kick_device(device); 1896 } 1897 1898 static int dasd_eckd_start_analysis(struct dasd_block *block) 1899 { 1900 struct dasd_ccw_req *init_cqr; 1901 1902 init_cqr = dasd_eckd_analysis_ccw(block->base); 1903 if (IS_ERR(init_cqr)) 1904 return PTR_ERR(init_cqr); 1905 init_cqr->callback = dasd_eckd_analysis_callback; 1906 init_cqr->callback_data = NULL; 1907 init_cqr->expires = 5*HZ; 1908 /* first try without ERP, so we can later handle unformatted 1909 * devices as special case 1910 */ 1911 clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags); 1912 init_cqr->retries = 0; 1913 dasd_add_request_head(init_cqr); 1914 return -EAGAIN; 1915 } 1916 1917 static int dasd_eckd_end_analysis(struct dasd_block *block) 1918 { 1919 struct dasd_device *device = block->base; 1920 struct dasd_eckd_private *private = device->private; 1921 struct eckd_count *count_area; 1922 unsigned int sb, blk_per_trk; 1923 int status, i; 1924 struct dasd_ccw_req *init_cqr; 1925 1926 status = private->init_cqr_status; 1927 private->init_cqr_status = -1; 1928 if (status == INIT_CQR_ERROR) { 1929 /* try again, this time with full ERP */ 1930 init_cqr = dasd_eckd_analysis_ccw(device); 1931 dasd_sleep_on(init_cqr); 1932 status = dasd_eckd_analysis_evaluation(init_cqr); 1933 dasd_sfree_request(init_cqr, device); 1934 } 1935 1936 if (device->features & DASD_FEATURE_USERAW) { 1937 block->bp_block = DASD_RAW_BLOCKSIZE; 1938 blk_per_trk = DASD_RAW_BLOCK_PER_TRACK; 1939 block->s2b_shift = 3; 1940 goto raw; 1941 } 1942 1943 if (status == INIT_CQR_UNFORMATTED) { 1944 dev_warn(&device->cdev->dev, "The DASD is not formatted\n"); 1945 return -EMEDIUMTYPE; 1946 } else if (status == INIT_CQR_ERROR) { 1947 dev_err(&device->cdev->dev, 1948 "Detecting the DASD disk layout failed because " 1949 "of an I/O error\n"); 1950 return -EIO; 1951 } 1952 1953 private->uses_cdl = 1; 1954 /* Check Track 0 for Compatible Disk Layout */ 1955 count_area = NULL; 1956 for (i = 0; i < 3; i++) { 1957 if (private->count_area[i].kl != 4 || 1958 private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4 || 1959 private->count_area[i].cyl != 0 || 1960 private->count_area[i].head != count_area_head[i] || 1961 private->count_area[i].record != count_area_rec[i]) { 1962 private->uses_cdl = 0; 1963 break; 1964 } 1965 } 1966 if (i == 3) 1967 count_area = &private->count_area[4]; 1968 1969 if (private->uses_cdl == 0) { 1970 for (i = 0; i < 5; i++) { 1971 if ((private->count_area[i].kl != 0) || 1972 (private->count_area[i].dl != 1973 private->count_area[0].dl) || 1974 private->count_area[i].cyl != 0 || 1975 private->count_area[i].head != count_area_head[i] || 1976 private->count_area[i].record != count_area_rec[i]) 1977 break; 1978 } 1979 if (i == 5) 1980 count_area = &private->count_area[0]; 1981 } else { 1982 if (private->count_area[3].record == 1) 1983 dev_warn(&device->cdev->dev, 1984 "Track 0 has no records following the VTOC\n"); 1985 } 1986 1987 if (count_area != NULL && count_area->kl == 0) { 1988 /* we found notthing violating our disk layout */ 1989 if (dasd_check_blocksize(count_area->dl) == 0) 1990 block->bp_block = count_area->dl; 1991 } 1992 if (block->bp_block == 0) { 1993 dev_warn(&device->cdev->dev, 1994 "The disk layout of the DASD is not supported\n"); 1995 return -EMEDIUMTYPE; 1996 } 1997 block->s2b_shift = 0; /* bits to shift 512 to get a block */ 1998 for (sb = 512; sb < block->bp_block; sb = sb << 1) 1999 block->s2b_shift++; 2000 2001 blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block); 2002 2003 raw: 2004 block->blocks = (private->real_cyl * 2005 private->rdc_data.trk_per_cyl * 2006 blk_per_trk); 2007 2008 dev_info(&device->cdev->dev, 2009 "DASD with %d KB/block, %d KB total size, %d KB/track, " 2010 "%s\n", (block->bp_block >> 10), 2011 ((private->real_cyl * 2012 private->rdc_data.trk_per_cyl * 2013 blk_per_trk * (block->bp_block >> 9)) >> 1), 2014 ((blk_per_trk * block->bp_block) >> 10), 2015 private->uses_cdl ? 2016 "compatible disk layout" : "linux disk layout"); 2017 2018 return 0; 2019 } 2020 2021 static int dasd_eckd_do_analysis(struct dasd_block *block) 2022 { 2023 struct dasd_eckd_private *private = block->base->private; 2024 2025 if (private->init_cqr_status < 0) 2026 return dasd_eckd_start_analysis(block); 2027 else 2028 return dasd_eckd_end_analysis(block); 2029 } 2030 2031 static int dasd_eckd_basic_to_ready(struct dasd_device *device) 2032 { 2033 return dasd_alias_add_device(device); 2034 }; 2035 2036 static int dasd_eckd_online_to_ready(struct dasd_device *device) 2037 { 2038 cancel_work_sync(&device->reload_device); 2039 cancel_work_sync(&device->kick_validate); 2040 return 0; 2041 }; 2042 2043 static int dasd_eckd_basic_to_known(struct dasd_device *device) 2044 { 2045 return dasd_alias_remove_device(device); 2046 }; 2047 2048 static int 2049 dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo) 2050 { 2051 struct dasd_eckd_private *private = block->base->private; 2052 2053 if (dasd_check_blocksize(block->bp_block) == 0) { 2054 geo->sectors = recs_per_track(&private->rdc_data, 2055 0, block->bp_block); 2056 } 2057 geo->cylinders = private->rdc_data.no_cyl; 2058 geo->heads = private->rdc_data.trk_per_cyl; 2059 return 0; 2060 } 2061 2062 /* 2063 * Build the TCW request for the format check 2064 */ 2065 static struct dasd_ccw_req * 2066 dasd_eckd_build_check_tcw(struct dasd_device *base, struct format_data_t *fdata, 2067 int enable_pav, struct eckd_count *fmt_buffer, 2068 int rpt) 2069 { 2070 struct dasd_eckd_private *start_priv; 2071 struct dasd_device *startdev = NULL; 2072 struct tidaw *last_tidaw = NULL; 2073 struct dasd_ccw_req *cqr; 2074 struct itcw *itcw; 2075 int itcw_size; 2076 int count; 2077 int rc; 2078 int i; 2079 2080 if (enable_pav) 2081 startdev = dasd_alias_get_start_dev(base); 2082 2083 if (!startdev) 2084 startdev = base; 2085 2086 start_priv = startdev->private; 2087 2088 count = rpt * (fdata->stop_unit - fdata->start_unit + 1); 2089 2090 /* 2091 * we're adding 'count' amount of tidaw to the itcw. 2092 * calculate the corresponding itcw_size 2093 */ 2094 itcw_size = itcw_calc_size(0, count, 0); 2095 2096 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev, 2097 NULL); 2098 if (IS_ERR(cqr)) 2099 return cqr; 2100 2101 start_priv->count++; 2102 2103 itcw = itcw_init(cqr->data, itcw_size, ITCW_OP_READ, 0, count, 0); 2104 if (IS_ERR(itcw)) { 2105 rc = -EINVAL; 2106 goto out_err; 2107 } 2108 2109 cqr->cpaddr = itcw_get_tcw(itcw); 2110 rc = prepare_itcw(itcw, fdata->start_unit, fdata->stop_unit, 2111 DASD_ECKD_CCW_READ_COUNT_MT, base, startdev, 0, count, 2112 sizeof(struct eckd_count), 2113 count * sizeof(struct eckd_count), 0, rpt); 2114 if (rc) 2115 goto out_err; 2116 2117 for (i = 0; i < count; i++) { 2118 last_tidaw = itcw_add_tidaw(itcw, 0, fmt_buffer++, 2119 sizeof(struct eckd_count)); 2120 if (IS_ERR(last_tidaw)) { 2121 rc = -EINVAL; 2122 goto out_err; 2123 } 2124 } 2125 2126 last_tidaw->flags |= TIDAW_FLAGS_LAST; 2127 itcw_finalize(itcw); 2128 2129 cqr->cpmode = 1; 2130 cqr->startdev = startdev; 2131 cqr->memdev = startdev; 2132 cqr->basedev = base; 2133 cqr->retries = startdev->default_retries; 2134 cqr->expires = startdev->default_expires * HZ; 2135 cqr->buildclk = get_tod_clock(); 2136 cqr->status = DASD_CQR_FILLED; 2137 /* Set flags to suppress output for expected errors */ 2138 set_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags); 2139 set_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags); 2140 2141 return cqr; 2142 2143 out_err: 2144 dasd_sfree_request(cqr, startdev); 2145 2146 return ERR_PTR(rc); 2147 } 2148 2149 /* 2150 * Build the CCW request for the format check 2151 */ 2152 static struct dasd_ccw_req * 2153 dasd_eckd_build_check(struct dasd_device *base, struct format_data_t *fdata, 2154 int enable_pav, struct eckd_count *fmt_buffer, int rpt) 2155 { 2156 struct dasd_eckd_private *start_priv; 2157 struct dasd_eckd_private *base_priv; 2158 struct dasd_device *startdev = NULL; 2159 struct dasd_ccw_req *cqr; 2160 struct ccw1 *ccw; 2161 void *data; 2162 int cplength, datasize; 2163 int use_prefix; 2164 int count; 2165 int i; 2166 2167 if (enable_pav) 2168 startdev = dasd_alias_get_start_dev(base); 2169 2170 if (!startdev) 2171 startdev = base; 2172 2173 start_priv = startdev->private; 2174 base_priv = base->private; 2175 2176 count = rpt * (fdata->stop_unit - fdata->start_unit + 1); 2177 2178 use_prefix = base_priv->features.feature[8] & 0x01; 2179 2180 if (use_prefix) { 2181 cplength = 1; 2182 datasize = sizeof(struct PFX_eckd_data); 2183 } else { 2184 cplength = 2; 2185 datasize = sizeof(struct DE_eckd_data) + 2186 sizeof(struct LO_eckd_data); 2187 } 2188 cplength += count; 2189 2190 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, 2191 startdev, NULL); 2192 if (IS_ERR(cqr)) 2193 return cqr; 2194 2195 start_priv->count++; 2196 data = cqr->data; 2197 ccw = cqr->cpaddr; 2198 2199 if (use_prefix) { 2200 prefix_LRE(ccw++, data, fdata->start_unit, fdata->stop_unit, 2201 DASD_ECKD_CCW_READ_COUNT, base, startdev, 1, 0, 2202 count, 0, 0); 2203 } else { 2204 define_extent(ccw++, data, fdata->start_unit, fdata->stop_unit, 2205 DASD_ECKD_CCW_READ_COUNT, startdev, 0); 2206 2207 data += sizeof(struct DE_eckd_data); 2208 ccw[-1].flags |= CCW_FLAG_CC; 2209 2210 locate_record(ccw++, data, fdata->start_unit, 0, count, 2211 DASD_ECKD_CCW_READ_COUNT, base, 0); 2212 } 2213 2214 for (i = 0; i < count; i++) { 2215 ccw[-1].flags |= CCW_FLAG_CC; 2216 ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT; 2217 ccw->flags = CCW_FLAG_SLI; 2218 ccw->count = 8; 2219 ccw->cda = (__u32)(addr_t) fmt_buffer; 2220 ccw++; 2221 fmt_buffer++; 2222 } 2223 2224 cqr->startdev = startdev; 2225 cqr->memdev = startdev; 2226 cqr->basedev = base; 2227 cqr->retries = DASD_RETRIES; 2228 cqr->expires = startdev->default_expires * HZ; 2229 cqr->buildclk = get_tod_clock(); 2230 cqr->status = DASD_CQR_FILLED; 2231 /* Set flags to suppress output for expected errors */ 2232 set_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags); 2233 2234 return cqr; 2235 } 2236 2237 static struct dasd_ccw_req * 2238 dasd_eckd_build_format(struct dasd_device *base, 2239 struct format_data_t *fdata, 2240 int enable_pav) 2241 { 2242 struct dasd_eckd_private *base_priv; 2243 struct dasd_eckd_private *start_priv; 2244 struct dasd_device *startdev = NULL; 2245 struct dasd_ccw_req *fcp; 2246 struct eckd_count *ect; 2247 struct ch_t address; 2248 struct ccw1 *ccw; 2249 void *data; 2250 int rpt; 2251 int cplength, datasize; 2252 int i, j; 2253 int intensity = 0; 2254 int r0_perm; 2255 int nr_tracks; 2256 int use_prefix; 2257 2258 if (enable_pav) 2259 startdev = dasd_alias_get_start_dev(base); 2260 2261 if (!startdev) 2262 startdev = base; 2263 2264 start_priv = startdev->private; 2265 base_priv = base->private; 2266 2267 rpt = recs_per_track(&base_priv->rdc_data, 0, fdata->blksize); 2268 2269 nr_tracks = fdata->stop_unit - fdata->start_unit + 1; 2270 2271 /* 2272 * fdata->intensity is a bit string that tells us what to do: 2273 * Bit 0: write record zero 2274 * Bit 1: write home address, currently not supported 2275 * Bit 2: invalidate tracks 2276 * Bit 3: use OS/390 compatible disk layout (cdl) 2277 * Bit 4: do not allow storage subsystem to modify record zero 2278 * Only some bit combinations do make sense. 2279 */ 2280 if (fdata->intensity & 0x10) { 2281 r0_perm = 0; 2282 intensity = fdata->intensity & ~0x10; 2283 } else { 2284 r0_perm = 1; 2285 intensity = fdata->intensity; 2286 } 2287 2288 use_prefix = base_priv->features.feature[8] & 0x01; 2289 2290 switch (intensity) { 2291 case 0x00: /* Normal format */ 2292 case 0x08: /* Normal format, use cdl. */ 2293 cplength = 2 + (rpt*nr_tracks); 2294 if (use_prefix) 2295 datasize = sizeof(struct PFX_eckd_data) + 2296 sizeof(struct LO_eckd_data) + 2297 rpt * nr_tracks * sizeof(struct eckd_count); 2298 else 2299 datasize = sizeof(struct DE_eckd_data) + 2300 sizeof(struct LO_eckd_data) + 2301 rpt * nr_tracks * sizeof(struct eckd_count); 2302 break; 2303 case 0x01: /* Write record zero and format track. */ 2304 case 0x09: /* Write record zero and format track, use cdl. */ 2305 cplength = 2 + rpt * nr_tracks; 2306 if (use_prefix) 2307 datasize = sizeof(struct PFX_eckd_data) + 2308 sizeof(struct LO_eckd_data) + 2309 sizeof(struct eckd_count) + 2310 rpt * nr_tracks * sizeof(struct eckd_count); 2311 else 2312 datasize = sizeof(struct DE_eckd_data) + 2313 sizeof(struct LO_eckd_data) + 2314 sizeof(struct eckd_count) + 2315 rpt * nr_tracks * sizeof(struct eckd_count); 2316 break; 2317 case 0x04: /* Invalidate track. */ 2318 case 0x0c: /* Invalidate track, use cdl. */ 2319 cplength = 3; 2320 if (use_prefix) 2321 datasize = sizeof(struct PFX_eckd_data) + 2322 sizeof(struct LO_eckd_data) + 2323 sizeof(struct eckd_count); 2324 else 2325 datasize = sizeof(struct DE_eckd_data) + 2326 sizeof(struct LO_eckd_data) + 2327 sizeof(struct eckd_count); 2328 break; 2329 default: 2330 dev_warn(&startdev->cdev->dev, 2331 "An I/O control call used incorrect flags 0x%x\n", 2332 fdata->intensity); 2333 return ERR_PTR(-EINVAL); 2334 } 2335 /* Allocate the format ccw request. */ 2336 fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, 2337 datasize, startdev, NULL); 2338 if (IS_ERR(fcp)) 2339 return fcp; 2340 2341 start_priv->count++; 2342 data = fcp->data; 2343 ccw = fcp->cpaddr; 2344 2345 switch (intensity & ~0x08) { 2346 case 0x00: /* Normal format. */ 2347 if (use_prefix) { 2348 prefix(ccw++, (struct PFX_eckd_data *) data, 2349 fdata->start_unit, fdata->stop_unit, 2350 DASD_ECKD_CCW_WRITE_CKD, base, startdev); 2351 /* grant subsystem permission to format R0 */ 2352 if (r0_perm) 2353 ((struct PFX_eckd_data *)data) 2354 ->define_extent.ga_extended |= 0x04; 2355 data += sizeof(struct PFX_eckd_data); 2356 } else { 2357 define_extent(ccw++, (struct DE_eckd_data *) data, 2358 fdata->start_unit, fdata->stop_unit, 2359 DASD_ECKD_CCW_WRITE_CKD, startdev, 0); 2360 /* grant subsystem permission to format R0 */ 2361 if (r0_perm) 2362 ((struct DE_eckd_data *) data) 2363 ->ga_extended |= 0x04; 2364 data += sizeof(struct DE_eckd_data); 2365 } 2366 ccw[-1].flags |= CCW_FLAG_CC; 2367 locate_record(ccw++, (struct LO_eckd_data *) data, 2368 fdata->start_unit, 0, rpt*nr_tracks, 2369 DASD_ECKD_CCW_WRITE_CKD, base, 2370 fdata->blksize); 2371 data += sizeof(struct LO_eckd_data); 2372 break; 2373 case 0x01: /* Write record zero + format track. */ 2374 if (use_prefix) { 2375 prefix(ccw++, (struct PFX_eckd_data *) data, 2376 fdata->start_unit, fdata->stop_unit, 2377 DASD_ECKD_CCW_WRITE_RECORD_ZERO, 2378 base, startdev); 2379 data += sizeof(struct PFX_eckd_data); 2380 } else { 2381 define_extent(ccw++, (struct DE_eckd_data *) data, 2382 fdata->start_unit, fdata->stop_unit, 2383 DASD_ECKD_CCW_WRITE_RECORD_ZERO, startdev, 0); 2384 data += sizeof(struct DE_eckd_data); 2385 } 2386 ccw[-1].flags |= CCW_FLAG_CC; 2387 locate_record(ccw++, (struct LO_eckd_data *) data, 2388 fdata->start_unit, 0, rpt * nr_tracks + 1, 2389 DASD_ECKD_CCW_WRITE_RECORD_ZERO, base, 2390 base->block->bp_block); 2391 data += sizeof(struct LO_eckd_data); 2392 break; 2393 case 0x04: /* Invalidate track. */ 2394 if (use_prefix) { 2395 prefix(ccw++, (struct PFX_eckd_data *) data, 2396 fdata->start_unit, fdata->stop_unit, 2397 DASD_ECKD_CCW_WRITE_CKD, base, startdev); 2398 data += sizeof(struct PFX_eckd_data); 2399 } else { 2400 define_extent(ccw++, (struct DE_eckd_data *) data, 2401 fdata->start_unit, fdata->stop_unit, 2402 DASD_ECKD_CCW_WRITE_CKD, startdev, 0); 2403 data += sizeof(struct DE_eckd_data); 2404 } 2405 ccw[-1].flags |= CCW_FLAG_CC; 2406 locate_record(ccw++, (struct LO_eckd_data *) data, 2407 fdata->start_unit, 0, 1, 2408 DASD_ECKD_CCW_WRITE_CKD, base, 8); 2409 data += sizeof(struct LO_eckd_data); 2410 break; 2411 } 2412 2413 for (j = 0; j < nr_tracks; j++) { 2414 /* calculate cylinder and head for the current track */ 2415 set_ch_t(&address, 2416 (fdata->start_unit + j) / 2417 base_priv->rdc_data.trk_per_cyl, 2418 (fdata->start_unit + j) % 2419 base_priv->rdc_data.trk_per_cyl); 2420 if (intensity & 0x01) { /* write record zero */ 2421 ect = (struct eckd_count *) data; 2422 data += sizeof(struct eckd_count); 2423 ect->cyl = address.cyl; 2424 ect->head = address.head; 2425 ect->record = 0; 2426 ect->kl = 0; 2427 ect->dl = 8; 2428 ccw[-1].flags |= CCW_FLAG_CC; 2429 ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO; 2430 ccw->flags = CCW_FLAG_SLI; 2431 ccw->count = 8; 2432 ccw->cda = (__u32)(addr_t) ect; 2433 ccw++; 2434 } 2435 if ((intensity & ~0x08) & 0x04) { /* erase track */ 2436 ect = (struct eckd_count *) data; 2437 data += sizeof(struct eckd_count); 2438 ect->cyl = address.cyl; 2439 ect->head = address.head; 2440 ect->record = 1; 2441 ect->kl = 0; 2442 ect->dl = 0; 2443 ccw[-1].flags |= CCW_FLAG_CC; 2444 ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD; 2445 ccw->flags = CCW_FLAG_SLI; 2446 ccw->count = 8; 2447 ccw->cda = (__u32)(addr_t) ect; 2448 } else { /* write remaining records */ 2449 for (i = 0; i < rpt; i++) { 2450 ect = (struct eckd_count *) data; 2451 data += sizeof(struct eckd_count); 2452 ect->cyl = address.cyl; 2453 ect->head = address.head; 2454 ect->record = i + 1; 2455 ect->kl = 0; 2456 ect->dl = fdata->blksize; 2457 /* 2458 * Check for special tracks 0-1 2459 * when formatting CDL 2460 */ 2461 if ((intensity & 0x08) && 2462 address.cyl == 0 && address.head == 0) { 2463 if (i < 3) { 2464 ect->kl = 4; 2465 ect->dl = sizes_trk0[i] - 4; 2466 } 2467 } 2468 if ((intensity & 0x08) && 2469 address.cyl == 0 && address.head == 1) { 2470 ect->kl = 44; 2471 ect->dl = LABEL_SIZE - 44; 2472 } 2473 ccw[-1].flags |= CCW_FLAG_CC; 2474 if (i != 0 || j == 0) 2475 ccw->cmd_code = 2476 DASD_ECKD_CCW_WRITE_CKD; 2477 else 2478 ccw->cmd_code = 2479 DASD_ECKD_CCW_WRITE_CKD_MT; 2480 ccw->flags = CCW_FLAG_SLI; 2481 ccw->count = 8; 2482 ccw->cda = (__u32)(addr_t) ect; 2483 ccw++; 2484 } 2485 } 2486 } 2487 2488 fcp->startdev = startdev; 2489 fcp->memdev = startdev; 2490 fcp->basedev = base; 2491 fcp->retries = 256; 2492 fcp->expires = startdev->default_expires * HZ; 2493 fcp->buildclk = get_tod_clock(); 2494 fcp->status = DASD_CQR_FILLED; 2495 2496 return fcp; 2497 } 2498 2499 /* 2500 * Wrapper function to build a CCW request depending on input data 2501 */ 2502 static struct dasd_ccw_req * 2503 dasd_eckd_format_build_ccw_req(struct dasd_device *base, 2504 struct format_data_t *fdata, int enable_pav, 2505 int tpm, struct eckd_count *fmt_buffer, int rpt) 2506 { 2507 struct dasd_ccw_req *ccw_req; 2508 2509 if (!fmt_buffer) { 2510 ccw_req = dasd_eckd_build_format(base, fdata, enable_pav); 2511 } else { 2512 if (tpm) 2513 ccw_req = dasd_eckd_build_check_tcw(base, fdata, 2514 enable_pav, 2515 fmt_buffer, rpt); 2516 else 2517 ccw_req = dasd_eckd_build_check(base, fdata, enable_pav, 2518 fmt_buffer, rpt); 2519 } 2520 2521 return ccw_req; 2522 } 2523 2524 /* 2525 * Sanity checks on format_data 2526 */ 2527 static int dasd_eckd_format_sanity_checks(struct dasd_device *base, 2528 struct format_data_t *fdata) 2529 { 2530 struct dasd_eckd_private *private = base->private; 2531 2532 if (fdata->start_unit >= 2533 (private->real_cyl * private->rdc_data.trk_per_cyl)) { 2534 dev_warn(&base->cdev->dev, 2535 "Start track number %u used in formatting is too big\n", 2536 fdata->start_unit); 2537 return -EINVAL; 2538 } 2539 if (fdata->stop_unit >= 2540 (private->real_cyl * private->rdc_data.trk_per_cyl)) { 2541 dev_warn(&base->cdev->dev, 2542 "Stop track number %u used in formatting is too big\n", 2543 fdata->stop_unit); 2544 return -EINVAL; 2545 } 2546 if (fdata->start_unit > fdata->stop_unit) { 2547 dev_warn(&base->cdev->dev, 2548 "Start track %u used in formatting exceeds end track\n", 2549 fdata->start_unit); 2550 return -EINVAL; 2551 } 2552 if (dasd_check_blocksize(fdata->blksize) != 0) { 2553 dev_warn(&base->cdev->dev, 2554 "The DASD cannot be formatted with block size %u\n", 2555 fdata->blksize); 2556 return -EINVAL; 2557 } 2558 return 0; 2559 } 2560 2561 /* 2562 * This function will process format_data originally coming from an IOCTL 2563 */ 2564 static int dasd_eckd_format_process_data(struct dasd_device *base, 2565 struct format_data_t *fdata, 2566 int enable_pav, int tpm, 2567 struct eckd_count *fmt_buffer, int rpt, 2568 struct irb *irb) 2569 { 2570 struct dasd_eckd_private *private = base->private; 2571 struct dasd_ccw_req *cqr, *n; 2572 struct list_head format_queue; 2573 struct dasd_device *device; 2574 char *sense = NULL; 2575 int old_start, old_stop, format_step; 2576 int step, retry; 2577 int rc; 2578 2579 rc = dasd_eckd_format_sanity_checks(base, fdata); 2580 if (rc) 2581 return rc; 2582 2583 INIT_LIST_HEAD(&format_queue); 2584 2585 old_start = fdata->start_unit; 2586 old_stop = fdata->stop_unit; 2587 2588 if (!tpm && fmt_buffer != NULL) { 2589 /* Command Mode / Format Check */ 2590 format_step = 1; 2591 } else if (tpm && fmt_buffer != NULL) { 2592 /* Transport Mode / Format Check */ 2593 format_step = DASD_CQR_MAX_CCW / rpt; 2594 } else { 2595 /* Normal Formatting */ 2596 format_step = DASD_CQR_MAX_CCW / 2597 recs_per_track(&private->rdc_data, 0, fdata->blksize); 2598 } 2599 2600 do { 2601 retry = 0; 2602 while (fdata->start_unit <= old_stop) { 2603 step = fdata->stop_unit - fdata->start_unit + 1; 2604 if (step > format_step) { 2605 fdata->stop_unit = 2606 fdata->start_unit + format_step - 1; 2607 } 2608 2609 cqr = dasd_eckd_format_build_ccw_req(base, fdata, 2610 enable_pav, tpm, 2611 fmt_buffer, rpt); 2612 if (IS_ERR(cqr)) { 2613 rc = PTR_ERR(cqr); 2614 if (rc == -ENOMEM) { 2615 if (list_empty(&format_queue)) 2616 goto out; 2617 /* 2618 * not enough memory available, start 2619 * requests retry after first requests 2620 * were finished 2621 */ 2622 retry = 1; 2623 break; 2624 } 2625 goto out_err; 2626 } 2627 list_add_tail(&cqr->blocklist, &format_queue); 2628 2629 if (fmt_buffer) { 2630 step = fdata->stop_unit - fdata->start_unit + 1; 2631 fmt_buffer += rpt * step; 2632 } 2633 fdata->start_unit = fdata->stop_unit + 1; 2634 fdata->stop_unit = old_stop; 2635 } 2636 2637 rc = dasd_sleep_on_queue(&format_queue); 2638 2639 out_err: 2640 list_for_each_entry_safe(cqr, n, &format_queue, blocklist) { 2641 device = cqr->startdev; 2642 private = device->private; 2643 2644 if (cqr->status == DASD_CQR_FAILED) { 2645 /* 2646 * Only get sense data if called by format 2647 * check 2648 */ 2649 if (fmt_buffer && irb) { 2650 sense = dasd_get_sense(&cqr->irb); 2651 memcpy(irb, &cqr->irb, sizeof(*irb)); 2652 } 2653 rc = -EIO; 2654 } 2655 list_del_init(&cqr->blocklist); 2656 dasd_sfree_request(cqr, device); 2657 private->count--; 2658 } 2659 2660 if (rc && rc != -EIO) 2661 goto out; 2662 if (rc == -EIO) { 2663 /* 2664 * In case fewer than the expected records are on the 2665 * track, we will most likely get a 'No Record Found' 2666 * error (in command mode) or a 'File Protected' error 2667 * (in transport mode). Those particular cases shouldn't 2668 * pass the -EIO to the IOCTL, therefore reset the rc 2669 * and continue. 2670 */ 2671 if (sense && 2672 (sense[1] & SNS1_NO_REC_FOUND || 2673 sense[1] & SNS1_FILE_PROTECTED)) 2674 retry = 1; 2675 else 2676 goto out; 2677 } 2678 2679 } while (retry); 2680 2681 out: 2682 fdata->start_unit = old_start; 2683 fdata->stop_unit = old_stop; 2684 2685 return rc; 2686 } 2687 2688 static int dasd_eckd_format_device(struct dasd_device *base, 2689 struct format_data_t *fdata, int enable_pav) 2690 { 2691 return dasd_eckd_format_process_data(base, fdata, enable_pav, 0, NULL, 2692 0, NULL); 2693 } 2694 2695 /* 2696 * Helper function to count consecutive records of a single track. 2697 */ 2698 static int dasd_eckd_count_records(struct eckd_count *fmt_buffer, int start, 2699 int max) 2700 { 2701 int head; 2702 int i; 2703 2704 head = fmt_buffer[start].head; 2705 2706 /* 2707 * There are 3 conditions where we stop counting: 2708 * - if data reoccurs (same head and record may reoccur), which may 2709 * happen due to the way DASD_ECKD_CCW_READ_COUNT works 2710 * - when the head changes, because we're iterating over several tracks 2711 * then (DASD_ECKD_CCW_READ_COUNT_MT) 2712 * - when we've reached the end of sensible data in the buffer (the 2713 * record will be 0 then) 2714 */ 2715 for (i = start; i < max; i++) { 2716 if (i > start) { 2717 if ((fmt_buffer[i].head == head && 2718 fmt_buffer[i].record == 1) || 2719 fmt_buffer[i].head != head || 2720 fmt_buffer[i].record == 0) 2721 break; 2722 } 2723 } 2724 2725 return i - start; 2726 } 2727 2728 /* 2729 * Evaluate a given range of tracks. Data like number of records, blocksize, 2730 * record ids, and key length are compared with expected data. 2731 * 2732 * If a mismatch occurs, the corresponding error bit is set, as well as 2733 * additional information, depending on the error. 2734 */ 2735 static void dasd_eckd_format_evaluate_tracks(struct eckd_count *fmt_buffer, 2736 struct format_check_t *cdata, 2737 int rpt_max, int rpt_exp, 2738 int trk_per_cyl, int tpm) 2739 { 2740 struct ch_t geo; 2741 int max_entries; 2742 int count = 0; 2743 int trkcount; 2744 int blksize; 2745 int pos = 0; 2746 int i, j; 2747 int kl; 2748 2749 trkcount = cdata->expect.stop_unit - cdata->expect.start_unit + 1; 2750 max_entries = trkcount * rpt_max; 2751 2752 for (i = cdata->expect.start_unit; i <= cdata->expect.stop_unit; i++) { 2753 /* Calculate the correct next starting position in the buffer */ 2754 if (tpm) { 2755 while (fmt_buffer[pos].record == 0 && 2756 fmt_buffer[pos].dl == 0) { 2757 if (pos++ > max_entries) 2758 break; 2759 } 2760 } else { 2761 if (i != cdata->expect.start_unit) 2762 pos += rpt_max - count; 2763 } 2764 2765 /* Calculate the expected geo values for the current track */ 2766 set_ch_t(&geo, i / trk_per_cyl, i % trk_per_cyl); 2767 2768 /* Count and check number of records */ 2769 count = dasd_eckd_count_records(fmt_buffer, pos, pos + rpt_max); 2770 2771 if (count < rpt_exp) { 2772 cdata->result = DASD_FMT_ERR_TOO_FEW_RECORDS; 2773 break; 2774 } 2775 if (count > rpt_exp) { 2776 cdata->result = DASD_FMT_ERR_TOO_MANY_RECORDS; 2777 break; 2778 } 2779 2780 for (j = 0; j < count; j++, pos++) { 2781 blksize = cdata->expect.blksize; 2782 kl = 0; 2783 2784 /* 2785 * Set special values when checking CDL formatted 2786 * devices. 2787 */ 2788 if ((cdata->expect.intensity & 0x08) && 2789 geo.cyl == 0 && geo.head == 0) { 2790 if (j < 3) { 2791 blksize = sizes_trk0[j] - 4; 2792 kl = 4; 2793 } 2794 } 2795 if ((cdata->expect.intensity & 0x08) && 2796 geo.cyl == 0 && geo.head == 1) { 2797 blksize = LABEL_SIZE - 44; 2798 kl = 44; 2799 } 2800 2801 /* Check blocksize */ 2802 if (fmt_buffer[pos].dl != blksize) { 2803 cdata->result = DASD_FMT_ERR_BLKSIZE; 2804 goto out; 2805 } 2806 /* Check if key length is 0 */ 2807 if (fmt_buffer[pos].kl != kl) { 2808 cdata->result = DASD_FMT_ERR_KEY_LENGTH; 2809 goto out; 2810 } 2811 /* Check if record_id is correct */ 2812 if (fmt_buffer[pos].cyl != geo.cyl || 2813 fmt_buffer[pos].head != geo.head || 2814 fmt_buffer[pos].record != (j + 1)) { 2815 cdata->result = DASD_FMT_ERR_RECORD_ID; 2816 goto out; 2817 } 2818 } 2819 } 2820 2821 out: 2822 /* 2823 * In case of no errors, we need to decrease by one 2824 * to get the correct positions. 2825 */ 2826 if (!cdata->result) { 2827 i--; 2828 pos--; 2829 } 2830 2831 cdata->unit = i; 2832 cdata->num_records = count; 2833 cdata->rec = fmt_buffer[pos].record; 2834 cdata->blksize = fmt_buffer[pos].dl; 2835 cdata->key_length = fmt_buffer[pos].kl; 2836 } 2837 2838 /* 2839 * Check the format of a range of tracks of a DASD. 2840 */ 2841 static int dasd_eckd_check_device_format(struct dasd_device *base, 2842 struct format_check_t *cdata, 2843 int enable_pav) 2844 { 2845 struct dasd_eckd_private *private = base->private; 2846 struct eckd_count *fmt_buffer; 2847 struct irb irb; 2848 int rpt_max, rpt_exp; 2849 int fmt_buffer_size; 2850 int trk_per_cyl; 2851 int trkcount; 2852 int tpm = 0; 2853 int rc; 2854 2855 trk_per_cyl = private->rdc_data.trk_per_cyl; 2856 2857 /* Get maximum and expected amount of records per track */ 2858 rpt_max = recs_per_track(&private->rdc_data, 0, 512) + 1; 2859 rpt_exp = recs_per_track(&private->rdc_data, 0, cdata->expect.blksize); 2860 2861 trkcount = cdata->expect.stop_unit - cdata->expect.start_unit + 1; 2862 fmt_buffer_size = trkcount * rpt_max * sizeof(struct eckd_count); 2863 2864 fmt_buffer = kzalloc(fmt_buffer_size, GFP_KERNEL | GFP_DMA); 2865 if (!fmt_buffer) 2866 return -ENOMEM; 2867 2868 /* 2869 * A certain FICON feature subset is needed to operate in transport 2870 * mode. Additionally, the support for transport mode is implicitly 2871 * checked by comparing the buffer size with fcx_max_data. As long as 2872 * the buffer size is smaller we can operate in transport mode and 2873 * process multiple tracks. If not, only one track at once is being 2874 * processed using command mode. 2875 */ 2876 if ((private->features.feature[40] & 0x04) && 2877 fmt_buffer_size <= private->fcx_max_data) 2878 tpm = 1; 2879 2880 rc = dasd_eckd_format_process_data(base, &cdata->expect, enable_pav, 2881 tpm, fmt_buffer, rpt_max, &irb); 2882 if (rc && rc != -EIO) 2883 goto out; 2884 if (rc == -EIO) { 2885 /* 2886 * If our first attempt with transport mode enabled comes back 2887 * with an incorrect length error, we're going to retry the 2888 * check with command mode. 2889 */ 2890 if (tpm && scsw_cstat(&irb.scsw) == 0x40) { 2891 tpm = 0; 2892 rc = dasd_eckd_format_process_data(base, &cdata->expect, 2893 enable_pav, tpm, 2894 fmt_buffer, rpt_max, 2895 &irb); 2896 if (rc) 2897 goto out; 2898 } else { 2899 goto out; 2900 } 2901 } 2902 2903 dasd_eckd_format_evaluate_tracks(fmt_buffer, cdata, rpt_max, rpt_exp, 2904 trk_per_cyl, tpm); 2905 2906 out: 2907 kfree(fmt_buffer); 2908 2909 return rc; 2910 } 2911 2912 static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr) 2913 { 2914 if (cqr->retries < 0) { 2915 cqr->status = DASD_CQR_FAILED; 2916 return; 2917 } 2918 cqr->status = DASD_CQR_FILLED; 2919 if (cqr->block && (cqr->startdev != cqr->block->base)) { 2920 dasd_eckd_reset_ccw_to_base_io(cqr); 2921 cqr->startdev = cqr->block->base; 2922 cqr->lpm = dasd_path_get_opm(cqr->block->base); 2923 } 2924 }; 2925 2926 static dasd_erp_fn_t 2927 dasd_eckd_erp_action(struct dasd_ccw_req * cqr) 2928 { 2929 struct dasd_device *device = (struct dasd_device *) cqr->startdev; 2930 struct ccw_device *cdev = device->cdev; 2931 2932 switch (cdev->id.cu_type) { 2933 case 0x3990: 2934 case 0x2105: 2935 case 0x2107: 2936 case 0x1750: 2937 return dasd_3990_erp_action; 2938 case 0x9343: 2939 case 0x3880: 2940 default: 2941 return dasd_default_erp_action; 2942 } 2943 } 2944 2945 static dasd_erp_fn_t 2946 dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr) 2947 { 2948 return dasd_default_erp_postaction; 2949 } 2950 2951 static void dasd_eckd_check_for_device_change(struct dasd_device *device, 2952 struct dasd_ccw_req *cqr, 2953 struct irb *irb) 2954 { 2955 char mask; 2956 char *sense = NULL; 2957 struct dasd_eckd_private *private = device->private; 2958 2959 /* first of all check for state change pending interrupt */ 2960 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP; 2961 if ((scsw_dstat(&irb->scsw) & mask) == mask) { 2962 /* 2963 * for alias only, not in offline processing 2964 * and only if not suspended 2965 */ 2966 if (!device->block && private->lcu && 2967 device->state == DASD_STATE_ONLINE && 2968 !test_bit(DASD_FLAG_OFFLINE, &device->flags) && 2969 !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) { 2970 /* schedule worker to reload device */ 2971 dasd_reload_device(device); 2972 } 2973 dasd_generic_handle_state_change(device); 2974 return; 2975 } 2976 2977 sense = dasd_get_sense(irb); 2978 if (!sense) 2979 return; 2980 2981 /* summary unit check */ 2982 if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) && 2983 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) { 2984 if (test_and_set_bit(DASD_FLAG_SUC, &device->flags)) { 2985 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 2986 "eckd suc: device already notified"); 2987 return; 2988 } 2989 sense = dasd_get_sense(irb); 2990 if (!sense) { 2991 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 2992 "eckd suc: no reason code available"); 2993 clear_bit(DASD_FLAG_SUC, &device->flags); 2994 return; 2995 2996 } 2997 private->suc_reason = sense[8]; 2998 DBF_DEV_EVENT(DBF_NOTICE, device, "%s %x", 2999 "eckd handle summary unit check: reason", 3000 private->suc_reason); 3001 dasd_get_device(device); 3002 if (!schedule_work(&device->suc_work)) 3003 dasd_put_device(device); 3004 3005 return; 3006 } 3007 3008 /* service information message SIM */ 3009 if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) && 3010 ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) { 3011 dasd_3990_erp_handle_sim(device, sense); 3012 return; 3013 } 3014 3015 /* loss of device reservation is handled via base devices only 3016 * as alias devices may be used with several bases 3017 */ 3018 if (device->block && (sense[27] & DASD_SENSE_BIT_0) && 3019 (sense[7] == 0x3F) && 3020 (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) && 3021 test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) { 3022 if (device->features & DASD_FEATURE_FAILONSLCK) 3023 set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags); 3024 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags); 3025 dev_err(&device->cdev->dev, 3026 "The device reservation was lost\n"); 3027 } 3028 } 3029 3030 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single( 3031 struct dasd_device *startdev, 3032 struct dasd_block *block, 3033 struct request *req, 3034 sector_t first_rec, 3035 sector_t last_rec, 3036 sector_t first_trk, 3037 sector_t last_trk, 3038 unsigned int first_offs, 3039 unsigned int last_offs, 3040 unsigned int blk_per_trk, 3041 unsigned int blksize) 3042 { 3043 struct dasd_eckd_private *private; 3044 unsigned long *idaws; 3045 struct LO_eckd_data *LO_data; 3046 struct dasd_ccw_req *cqr; 3047 struct ccw1 *ccw; 3048 struct req_iterator iter; 3049 struct bio_vec bv; 3050 char *dst; 3051 unsigned int off; 3052 int count, cidaw, cplength, datasize; 3053 sector_t recid; 3054 unsigned char cmd, rcmd; 3055 int use_prefix; 3056 struct dasd_device *basedev; 3057 3058 basedev = block->base; 3059 private = basedev->private; 3060 if (rq_data_dir(req) == READ) 3061 cmd = DASD_ECKD_CCW_READ_MT; 3062 else if (rq_data_dir(req) == WRITE) 3063 cmd = DASD_ECKD_CCW_WRITE_MT; 3064 else 3065 return ERR_PTR(-EINVAL); 3066 3067 /* Check struct bio and count the number of blocks for the request. */ 3068 count = 0; 3069 cidaw = 0; 3070 rq_for_each_segment(bv, req, iter) { 3071 if (bv.bv_len & (blksize - 1)) 3072 /* Eckd can only do full blocks. */ 3073 return ERR_PTR(-EINVAL); 3074 count += bv.bv_len >> (block->s2b_shift + 9); 3075 if (idal_is_needed (page_address(bv.bv_page), bv.bv_len)) 3076 cidaw += bv.bv_len >> (block->s2b_shift + 9); 3077 } 3078 /* Paranoia. */ 3079 if (count != last_rec - first_rec + 1) 3080 return ERR_PTR(-EINVAL); 3081 3082 /* use the prefix command if available */ 3083 use_prefix = private->features.feature[8] & 0x01; 3084 if (use_prefix) { 3085 /* 1x prefix + number of blocks */ 3086 cplength = 2 + count; 3087 /* 1x prefix + cidaws*sizeof(long) */ 3088 datasize = sizeof(struct PFX_eckd_data) + 3089 sizeof(struct LO_eckd_data) + 3090 cidaw * sizeof(unsigned long); 3091 } else { 3092 /* 1x define extent + 1x locate record + number of blocks */ 3093 cplength = 2 + count; 3094 /* 1x define extent + 1x locate record + cidaws*sizeof(long) */ 3095 datasize = sizeof(struct DE_eckd_data) + 3096 sizeof(struct LO_eckd_data) + 3097 cidaw * sizeof(unsigned long); 3098 } 3099 /* Find out the number of additional locate record ccws for cdl. */ 3100 if (private->uses_cdl && first_rec < 2*blk_per_trk) { 3101 if (last_rec >= 2*blk_per_trk) 3102 count = 2*blk_per_trk - first_rec; 3103 cplength += count; 3104 datasize += count*sizeof(struct LO_eckd_data); 3105 } 3106 /* Allocate the ccw request. */ 3107 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, 3108 startdev, blk_mq_rq_to_pdu(req)); 3109 if (IS_ERR(cqr)) 3110 return cqr; 3111 ccw = cqr->cpaddr; 3112 /* First ccw is define extent or prefix. */ 3113 if (use_prefix) { 3114 if (prefix(ccw++, cqr->data, first_trk, 3115 last_trk, cmd, basedev, startdev) == -EAGAIN) { 3116 /* Clock not in sync and XRC is enabled. 3117 * Try again later. 3118 */ 3119 dasd_sfree_request(cqr, startdev); 3120 return ERR_PTR(-EAGAIN); 3121 } 3122 idaws = (unsigned long *) (cqr->data + 3123 sizeof(struct PFX_eckd_data)); 3124 } else { 3125 if (define_extent(ccw++, cqr->data, first_trk, 3126 last_trk, cmd, basedev, 0) == -EAGAIN) { 3127 /* Clock not in sync and XRC is enabled. 3128 * Try again later. 3129 */ 3130 dasd_sfree_request(cqr, startdev); 3131 return ERR_PTR(-EAGAIN); 3132 } 3133 idaws = (unsigned long *) (cqr->data + 3134 sizeof(struct DE_eckd_data)); 3135 } 3136 /* Build locate_record+read/write/ccws. */ 3137 LO_data = (struct LO_eckd_data *) (idaws + cidaw); 3138 recid = first_rec; 3139 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) { 3140 /* Only standard blocks so there is just one locate record. */ 3141 ccw[-1].flags |= CCW_FLAG_CC; 3142 locate_record(ccw++, LO_data++, first_trk, first_offs + 1, 3143 last_rec - recid + 1, cmd, basedev, blksize); 3144 } 3145 rq_for_each_segment(bv, req, iter) { 3146 dst = page_address(bv.bv_page) + bv.bv_offset; 3147 if (dasd_page_cache) { 3148 char *copy = kmem_cache_alloc(dasd_page_cache, 3149 GFP_DMA | __GFP_NOWARN); 3150 if (copy && rq_data_dir(req) == WRITE) 3151 memcpy(copy + bv.bv_offset, dst, bv.bv_len); 3152 if (copy) 3153 dst = copy + bv.bv_offset; 3154 } 3155 for (off = 0; off < bv.bv_len; off += blksize) { 3156 sector_t trkid = recid; 3157 unsigned int recoffs = sector_div(trkid, blk_per_trk); 3158 rcmd = cmd; 3159 count = blksize; 3160 /* Locate record for cdl special block ? */ 3161 if (private->uses_cdl && recid < 2*blk_per_trk) { 3162 if (dasd_eckd_cdl_special(blk_per_trk, recid)){ 3163 rcmd |= 0x8; 3164 count = dasd_eckd_cdl_reclen(recid); 3165 if (count < blksize && 3166 rq_data_dir(req) == READ) 3167 memset(dst + count, 0xe5, 3168 blksize - count); 3169 } 3170 ccw[-1].flags |= CCW_FLAG_CC; 3171 locate_record(ccw++, LO_data++, 3172 trkid, recoffs + 1, 3173 1, rcmd, basedev, count); 3174 } 3175 /* Locate record for standard blocks ? */ 3176 if (private->uses_cdl && recid == 2*blk_per_trk) { 3177 ccw[-1].flags |= CCW_FLAG_CC; 3178 locate_record(ccw++, LO_data++, 3179 trkid, recoffs + 1, 3180 last_rec - recid + 1, 3181 cmd, basedev, count); 3182 } 3183 /* Read/write ccw. */ 3184 ccw[-1].flags |= CCW_FLAG_CC; 3185 ccw->cmd_code = rcmd; 3186 ccw->count = count; 3187 if (idal_is_needed(dst, blksize)) { 3188 ccw->cda = (__u32)(addr_t) idaws; 3189 ccw->flags = CCW_FLAG_IDA; 3190 idaws = idal_create_words(idaws, dst, blksize); 3191 } else { 3192 ccw->cda = (__u32)(addr_t) dst; 3193 ccw->flags = 0; 3194 } 3195 ccw++; 3196 dst += blksize; 3197 recid++; 3198 } 3199 } 3200 if (blk_noretry_request(req) || 3201 block->base->features & DASD_FEATURE_FAILFAST) 3202 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 3203 cqr->startdev = startdev; 3204 cqr->memdev = startdev; 3205 cqr->block = block; 3206 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */ 3207 cqr->lpm = dasd_path_get_ppm(startdev); 3208 cqr->retries = startdev->default_retries; 3209 cqr->buildclk = get_tod_clock(); 3210 cqr->status = DASD_CQR_FILLED; 3211 return cqr; 3212 } 3213 3214 static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track( 3215 struct dasd_device *startdev, 3216 struct dasd_block *block, 3217 struct request *req, 3218 sector_t first_rec, 3219 sector_t last_rec, 3220 sector_t first_trk, 3221 sector_t last_trk, 3222 unsigned int first_offs, 3223 unsigned int last_offs, 3224 unsigned int blk_per_trk, 3225 unsigned int blksize) 3226 { 3227 unsigned long *idaws; 3228 struct dasd_ccw_req *cqr; 3229 struct ccw1 *ccw; 3230 struct req_iterator iter; 3231 struct bio_vec bv; 3232 char *dst, *idaw_dst; 3233 unsigned int cidaw, cplength, datasize; 3234 unsigned int tlf; 3235 sector_t recid; 3236 unsigned char cmd; 3237 struct dasd_device *basedev; 3238 unsigned int trkcount, count, count_to_trk_end; 3239 unsigned int idaw_len, seg_len, part_len, len_to_track_end; 3240 unsigned char new_track, end_idaw; 3241 sector_t trkid; 3242 unsigned int recoffs; 3243 3244 basedev = block->base; 3245 if (rq_data_dir(req) == READ) 3246 cmd = DASD_ECKD_CCW_READ_TRACK_DATA; 3247 else if (rq_data_dir(req) == WRITE) 3248 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA; 3249 else 3250 return ERR_PTR(-EINVAL); 3251 3252 /* Track based I/O needs IDAWs for each page, and not just for 3253 * 64 bit addresses. We need additional idals for pages 3254 * that get filled from two tracks, so we use the number 3255 * of records as upper limit. 3256 */ 3257 cidaw = last_rec - first_rec + 1; 3258 trkcount = last_trk - first_trk + 1; 3259 3260 /* 1x prefix + one read/write ccw per track */ 3261 cplength = 1 + trkcount; 3262 3263 datasize = sizeof(struct PFX_eckd_data) + cidaw * sizeof(unsigned long); 3264 3265 /* Allocate the ccw request. */ 3266 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, 3267 startdev, blk_mq_rq_to_pdu(req)); 3268 if (IS_ERR(cqr)) 3269 return cqr; 3270 ccw = cqr->cpaddr; 3271 /* transfer length factor: how many bytes to read from the last track */ 3272 if (first_trk == last_trk) 3273 tlf = last_offs - first_offs + 1; 3274 else 3275 tlf = last_offs + 1; 3276 tlf *= blksize; 3277 3278 if (prefix_LRE(ccw++, cqr->data, first_trk, 3279 last_trk, cmd, basedev, startdev, 3280 1 /* format */, first_offs + 1, 3281 trkcount, blksize, 3282 tlf) == -EAGAIN) { 3283 /* Clock not in sync and XRC is enabled. 3284 * Try again later. 3285 */ 3286 dasd_sfree_request(cqr, startdev); 3287 return ERR_PTR(-EAGAIN); 3288 } 3289 3290 /* 3291 * The translation of request into ccw programs must meet the 3292 * following conditions: 3293 * - all idaws but the first and the last must address full pages 3294 * (or 2K blocks on 31-bit) 3295 * - the scope of a ccw and it's idal ends with the track boundaries 3296 */ 3297 idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data)); 3298 recid = first_rec; 3299 new_track = 1; 3300 end_idaw = 0; 3301 len_to_track_end = 0; 3302 idaw_dst = NULL; 3303 idaw_len = 0; 3304 rq_for_each_segment(bv, req, iter) { 3305 dst = page_address(bv.bv_page) + bv.bv_offset; 3306 seg_len = bv.bv_len; 3307 while (seg_len) { 3308 if (new_track) { 3309 trkid = recid; 3310 recoffs = sector_div(trkid, blk_per_trk); 3311 count_to_trk_end = blk_per_trk - recoffs; 3312 count = min((last_rec - recid + 1), 3313 (sector_t)count_to_trk_end); 3314 len_to_track_end = count * blksize; 3315 ccw[-1].flags |= CCW_FLAG_CC; 3316 ccw->cmd_code = cmd; 3317 ccw->count = len_to_track_end; 3318 ccw->cda = (__u32)(addr_t)idaws; 3319 ccw->flags = CCW_FLAG_IDA; 3320 ccw++; 3321 recid += count; 3322 new_track = 0; 3323 /* first idaw for a ccw may start anywhere */ 3324 if (!idaw_dst) 3325 idaw_dst = dst; 3326 } 3327 /* If we start a new idaw, we must make sure that it 3328 * starts on an IDA_BLOCK_SIZE boundary. 3329 * If we continue an idaw, we must make sure that the 3330 * current segment begins where the so far accumulated 3331 * idaw ends 3332 */ 3333 if (!idaw_dst) { 3334 if (__pa(dst) & (IDA_BLOCK_SIZE-1)) { 3335 dasd_sfree_request(cqr, startdev); 3336 return ERR_PTR(-ERANGE); 3337 } else 3338 idaw_dst = dst; 3339 } 3340 if ((idaw_dst + idaw_len) != dst) { 3341 dasd_sfree_request(cqr, startdev); 3342 return ERR_PTR(-ERANGE); 3343 } 3344 part_len = min(seg_len, len_to_track_end); 3345 seg_len -= part_len; 3346 dst += part_len; 3347 idaw_len += part_len; 3348 len_to_track_end -= part_len; 3349 /* collected memory area ends on an IDA_BLOCK border, 3350 * -> create an idaw 3351 * idal_create_words will handle cases where idaw_len 3352 * is larger then IDA_BLOCK_SIZE 3353 */ 3354 if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1))) 3355 end_idaw = 1; 3356 /* We also need to end the idaw at track end */ 3357 if (!len_to_track_end) { 3358 new_track = 1; 3359 end_idaw = 1; 3360 } 3361 if (end_idaw) { 3362 idaws = idal_create_words(idaws, idaw_dst, 3363 idaw_len); 3364 idaw_dst = NULL; 3365 idaw_len = 0; 3366 end_idaw = 0; 3367 } 3368 } 3369 } 3370 3371 if (blk_noretry_request(req) || 3372 block->base->features & DASD_FEATURE_FAILFAST) 3373 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 3374 cqr->startdev = startdev; 3375 cqr->memdev = startdev; 3376 cqr->block = block; 3377 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */ 3378 cqr->lpm = dasd_path_get_ppm(startdev); 3379 cqr->retries = startdev->default_retries; 3380 cqr->buildclk = get_tod_clock(); 3381 cqr->status = DASD_CQR_FILLED; 3382 return cqr; 3383 } 3384 3385 static int prepare_itcw(struct itcw *itcw, 3386 unsigned int trk, unsigned int totrk, int cmd, 3387 struct dasd_device *basedev, 3388 struct dasd_device *startdev, 3389 unsigned int rec_on_trk, int count, 3390 unsigned int blksize, 3391 unsigned int total_data_size, 3392 unsigned int tlf, 3393 unsigned int blk_per_trk) 3394 { 3395 struct PFX_eckd_data pfxdata; 3396 struct dasd_eckd_private *basepriv, *startpriv; 3397 struct DE_eckd_data *dedata; 3398 struct LRE_eckd_data *lredata; 3399 struct dcw *dcw; 3400 3401 u32 begcyl, endcyl; 3402 u16 heads, beghead, endhead; 3403 u8 pfx_cmd; 3404 3405 int rc = 0; 3406 int sector = 0; 3407 int dn, d; 3408 3409 3410 /* setup prefix data */ 3411 basepriv = basedev->private; 3412 startpriv = startdev->private; 3413 dedata = &pfxdata.define_extent; 3414 lredata = &pfxdata.locate_record; 3415 3416 memset(&pfxdata, 0, sizeof(pfxdata)); 3417 pfxdata.format = 1; /* PFX with LRE */ 3418 pfxdata.base_address = basepriv->ned->unit_addr; 3419 pfxdata.base_lss = basepriv->ned->ID; 3420 pfxdata.validity.define_extent = 1; 3421 3422 /* private uid is kept up to date, conf_data may be outdated */ 3423 if (startpriv->uid.type == UA_BASE_PAV_ALIAS) 3424 pfxdata.validity.verify_base = 1; 3425 3426 if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) { 3427 pfxdata.validity.verify_base = 1; 3428 pfxdata.validity.hyper_pav = 1; 3429 } 3430 3431 switch (cmd) { 3432 case DASD_ECKD_CCW_READ_TRACK_DATA: 3433 dedata->mask.perm = 0x1; 3434 dedata->attributes.operation = basepriv->attrib.operation; 3435 dedata->blk_size = blksize; 3436 dedata->ga_extended |= 0x42; 3437 lredata->operation.orientation = 0x0; 3438 lredata->operation.operation = 0x0C; 3439 lredata->auxiliary.check_bytes = 0x01; 3440 pfx_cmd = DASD_ECKD_CCW_PFX_READ; 3441 break; 3442 case DASD_ECKD_CCW_WRITE_TRACK_DATA: 3443 dedata->mask.perm = 0x02; 3444 dedata->attributes.operation = basepriv->attrib.operation; 3445 dedata->blk_size = blksize; 3446 rc = set_timestamp(NULL, dedata, basedev); 3447 dedata->ga_extended |= 0x42; 3448 lredata->operation.orientation = 0x0; 3449 lredata->operation.operation = 0x3F; 3450 lredata->extended_operation = 0x23; 3451 lredata->auxiliary.check_bytes = 0x2; 3452 /* 3453 * If XRC is supported the System Time Stamp is set. The 3454 * validity of the time stamp must be reflected in the prefix 3455 * data as well. 3456 */ 3457 if (dedata->ga_extended & 0x08 && dedata->ga_extended & 0x02) 3458 pfxdata.validity.time_stamp = 1; /* 'Time Stamp Valid' */ 3459 pfx_cmd = DASD_ECKD_CCW_PFX; 3460 break; 3461 case DASD_ECKD_CCW_READ_COUNT_MT: 3462 dedata->mask.perm = 0x1; 3463 dedata->attributes.operation = DASD_BYPASS_CACHE; 3464 dedata->ga_extended |= 0x42; 3465 dedata->blk_size = blksize; 3466 lredata->operation.orientation = 0x2; 3467 lredata->operation.operation = 0x16; 3468 lredata->auxiliary.check_bytes = 0x01; 3469 pfx_cmd = DASD_ECKD_CCW_PFX_READ; 3470 break; 3471 default: 3472 DBF_DEV_EVENT(DBF_ERR, basedev, 3473 "prepare itcw, unknown opcode 0x%x", cmd); 3474 BUG(); 3475 break; 3476 } 3477 if (rc) 3478 return rc; 3479 3480 dedata->attributes.mode = 0x3; /* ECKD */ 3481 3482 heads = basepriv->rdc_data.trk_per_cyl; 3483 begcyl = trk / heads; 3484 beghead = trk % heads; 3485 endcyl = totrk / heads; 3486 endhead = totrk % heads; 3487 3488 /* check for sequential prestage - enhance cylinder range */ 3489 if (dedata->attributes.operation == DASD_SEQ_PRESTAGE || 3490 dedata->attributes.operation == DASD_SEQ_ACCESS) { 3491 3492 if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl) 3493 endcyl += basepriv->attrib.nr_cyl; 3494 else 3495 endcyl = (basepriv->real_cyl - 1); 3496 } 3497 3498 set_ch_t(&dedata->beg_ext, begcyl, beghead); 3499 set_ch_t(&dedata->end_ext, endcyl, endhead); 3500 3501 dedata->ep_format = 0x20; /* records per track is valid */ 3502 dedata->ep_rec_per_track = blk_per_trk; 3503 3504 if (rec_on_trk) { 3505 switch (basepriv->rdc_data.dev_type) { 3506 case 0x3390: 3507 dn = ceil_quot(blksize + 6, 232); 3508 d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34); 3509 sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8; 3510 break; 3511 case 0x3380: 3512 d = 7 + ceil_quot(blksize + 12, 32); 3513 sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7; 3514 break; 3515 } 3516 } 3517 3518 if (cmd == DASD_ECKD_CCW_READ_COUNT_MT) { 3519 lredata->auxiliary.length_valid = 0; 3520 lredata->auxiliary.length_scope = 0; 3521 lredata->sector = 0xff; 3522 } else { 3523 lredata->auxiliary.length_valid = 1; 3524 lredata->auxiliary.length_scope = 1; 3525 lredata->sector = sector; 3526 } 3527 lredata->auxiliary.imbedded_ccw_valid = 1; 3528 lredata->length = tlf; 3529 lredata->imbedded_ccw = cmd; 3530 lredata->count = count; 3531 set_ch_t(&lredata->seek_addr, begcyl, beghead); 3532 lredata->search_arg.cyl = lredata->seek_addr.cyl; 3533 lredata->search_arg.head = lredata->seek_addr.head; 3534 lredata->search_arg.record = rec_on_trk; 3535 3536 dcw = itcw_add_dcw(itcw, pfx_cmd, 0, 3537 &pfxdata, sizeof(pfxdata), total_data_size); 3538 return PTR_RET(dcw); 3539 } 3540 3541 static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track( 3542 struct dasd_device *startdev, 3543 struct dasd_block *block, 3544 struct request *req, 3545 sector_t first_rec, 3546 sector_t last_rec, 3547 sector_t first_trk, 3548 sector_t last_trk, 3549 unsigned int first_offs, 3550 unsigned int last_offs, 3551 unsigned int blk_per_trk, 3552 unsigned int blksize) 3553 { 3554 struct dasd_ccw_req *cqr; 3555 struct req_iterator iter; 3556 struct bio_vec bv; 3557 char *dst; 3558 unsigned int trkcount, ctidaw; 3559 unsigned char cmd; 3560 struct dasd_device *basedev; 3561 unsigned int tlf; 3562 struct itcw *itcw; 3563 struct tidaw *last_tidaw = NULL; 3564 int itcw_op; 3565 size_t itcw_size; 3566 u8 tidaw_flags; 3567 unsigned int seg_len, part_len, len_to_track_end; 3568 unsigned char new_track; 3569 sector_t recid, trkid; 3570 unsigned int offs; 3571 unsigned int count, count_to_trk_end; 3572 int ret; 3573 3574 basedev = block->base; 3575 if (rq_data_dir(req) == READ) { 3576 cmd = DASD_ECKD_CCW_READ_TRACK_DATA; 3577 itcw_op = ITCW_OP_READ; 3578 } else if (rq_data_dir(req) == WRITE) { 3579 cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA; 3580 itcw_op = ITCW_OP_WRITE; 3581 } else 3582 return ERR_PTR(-EINVAL); 3583 3584 /* trackbased I/O needs address all memory via TIDAWs, 3585 * not just for 64 bit addresses. This allows us to map 3586 * each segment directly to one tidaw. 3587 * In the case of write requests, additional tidaws may 3588 * be needed when a segment crosses a track boundary. 3589 */ 3590 trkcount = last_trk - first_trk + 1; 3591 ctidaw = 0; 3592 rq_for_each_segment(bv, req, iter) { 3593 ++ctidaw; 3594 } 3595 if (rq_data_dir(req) == WRITE) 3596 ctidaw += (last_trk - first_trk); 3597 3598 /* Allocate the ccw request. */ 3599 itcw_size = itcw_calc_size(0, ctidaw, 0); 3600 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev, 3601 blk_mq_rq_to_pdu(req)); 3602 if (IS_ERR(cqr)) 3603 return cqr; 3604 3605 /* transfer length factor: how many bytes to read from the last track */ 3606 if (first_trk == last_trk) 3607 tlf = last_offs - first_offs + 1; 3608 else 3609 tlf = last_offs + 1; 3610 tlf *= blksize; 3611 3612 itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0); 3613 if (IS_ERR(itcw)) { 3614 ret = -EINVAL; 3615 goto out_error; 3616 } 3617 cqr->cpaddr = itcw_get_tcw(itcw); 3618 if (prepare_itcw(itcw, first_trk, last_trk, 3619 cmd, basedev, startdev, 3620 first_offs + 1, 3621 trkcount, blksize, 3622 (last_rec - first_rec + 1) * blksize, 3623 tlf, blk_per_trk) == -EAGAIN) { 3624 /* Clock not in sync and XRC is enabled. 3625 * Try again later. 3626 */ 3627 ret = -EAGAIN; 3628 goto out_error; 3629 } 3630 len_to_track_end = 0; 3631 /* 3632 * A tidaw can address 4k of memory, but must not cross page boundaries 3633 * We can let the block layer handle this by setting 3634 * blk_queue_segment_boundary to page boundaries and 3635 * blk_max_segment_size to page size when setting up the request queue. 3636 * For write requests, a TIDAW must not cross track boundaries, because 3637 * we have to set the CBC flag on the last tidaw for each track. 3638 */ 3639 if (rq_data_dir(req) == WRITE) { 3640 new_track = 1; 3641 recid = first_rec; 3642 rq_for_each_segment(bv, req, iter) { 3643 dst = page_address(bv.bv_page) + bv.bv_offset; 3644 seg_len = bv.bv_len; 3645 while (seg_len) { 3646 if (new_track) { 3647 trkid = recid; 3648 offs = sector_div(trkid, blk_per_trk); 3649 count_to_trk_end = blk_per_trk - offs; 3650 count = min((last_rec - recid + 1), 3651 (sector_t)count_to_trk_end); 3652 len_to_track_end = count * blksize; 3653 recid += count; 3654 new_track = 0; 3655 } 3656 part_len = min(seg_len, len_to_track_end); 3657 seg_len -= part_len; 3658 len_to_track_end -= part_len; 3659 /* We need to end the tidaw at track end */ 3660 if (!len_to_track_end) { 3661 new_track = 1; 3662 tidaw_flags = TIDAW_FLAGS_INSERT_CBC; 3663 } else 3664 tidaw_flags = 0; 3665 last_tidaw = itcw_add_tidaw(itcw, tidaw_flags, 3666 dst, part_len); 3667 if (IS_ERR(last_tidaw)) { 3668 ret = -EINVAL; 3669 goto out_error; 3670 } 3671 dst += part_len; 3672 } 3673 } 3674 } else { 3675 rq_for_each_segment(bv, req, iter) { 3676 dst = page_address(bv.bv_page) + bv.bv_offset; 3677 last_tidaw = itcw_add_tidaw(itcw, 0x00, 3678 dst, bv.bv_len); 3679 if (IS_ERR(last_tidaw)) { 3680 ret = -EINVAL; 3681 goto out_error; 3682 } 3683 } 3684 } 3685 last_tidaw->flags |= TIDAW_FLAGS_LAST; 3686 last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC; 3687 itcw_finalize(itcw); 3688 3689 if (blk_noretry_request(req) || 3690 block->base->features & DASD_FEATURE_FAILFAST) 3691 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 3692 cqr->cpmode = 1; 3693 cqr->startdev = startdev; 3694 cqr->memdev = startdev; 3695 cqr->block = block; 3696 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */ 3697 cqr->lpm = dasd_path_get_ppm(startdev); 3698 cqr->retries = startdev->default_retries; 3699 cqr->buildclk = get_tod_clock(); 3700 cqr->status = DASD_CQR_FILLED; 3701 return cqr; 3702 out_error: 3703 dasd_sfree_request(cqr, startdev); 3704 return ERR_PTR(ret); 3705 } 3706 3707 static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev, 3708 struct dasd_block *block, 3709 struct request *req) 3710 { 3711 int cmdrtd, cmdwtd; 3712 int use_prefix; 3713 int fcx_multitrack; 3714 struct dasd_eckd_private *private; 3715 struct dasd_device *basedev; 3716 sector_t first_rec, last_rec; 3717 sector_t first_trk, last_trk; 3718 unsigned int first_offs, last_offs; 3719 unsigned int blk_per_trk, blksize; 3720 int cdlspecial; 3721 unsigned int data_size; 3722 struct dasd_ccw_req *cqr; 3723 3724 basedev = block->base; 3725 private = basedev->private; 3726 3727 /* Calculate number of blocks/records per track. */ 3728 blksize = block->bp_block; 3729 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); 3730 if (blk_per_trk == 0) 3731 return ERR_PTR(-EINVAL); 3732 /* Calculate record id of first and last block. */ 3733 first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift; 3734 first_offs = sector_div(first_trk, blk_per_trk); 3735 last_rec = last_trk = 3736 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift; 3737 last_offs = sector_div(last_trk, blk_per_trk); 3738 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk); 3739 3740 fcx_multitrack = private->features.feature[40] & 0x20; 3741 data_size = blk_rq_bytes(req); 3742 if (data_size % blksize) 3743 return ERR_PTR(-EINVAL); 3744 /* tpm write request add CBC data on each track boundary */ 3745 if (rq_data_dir(req) == WRITE) 3746 data_size += (last_trk - first_trk) * 4; 3747 3748 /* is read track data and write track data in command mode supported? */ 3749 cmdrtd = private->features.feature[9] & 0x20; 3750 cmdwtd = private->features.feature[12] & 0x40; 3751 use_prefix = private->features.feature[8] & 0x01; 3752 3753 cqr = NULL; 3754 if (cdlspecial || dasd_page_cache) { 3755 /* do nothing, just fall through to the cmd mode single case */ 3756 } else if ((data_size <= private->fcx_max_data) 3757 && (fcx_multitrack || (first_trk == last_trk))) { 3758 cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req, 3759 first_rec, last_rec, 3760 first_trk, last_trk, 3761 first_offs, last_offs, 3762 blk_per_trk, blksize); 3763 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) && 3764 (PTR_ERR(cqr) != -ENOMEM)) 3765 cqr = NULL; 3766 } else if (use_prefix && 3767 (((rq_data_dir(req) == READ) && cmdrtd) || 3768 ((rq_data_dir(req) == WRITE) && cmdwtd))) { 3769 cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req, 3770 first_rec, last_rec, 3771 first_trk, last_trk, 3772 first_offs, last_offs, 3773 blk_per_trk, blksize); 3774 if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) && 3775 (PTR_ERR(cqr) != -ENOMEM)) 3776 cqr = NULL; 3777 } 3778 if (!cqr) 3779 cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req, 3780 first_rec, last_rec, 3781 first_trk, last_trk, 3782 first_offs, last_offs, 3783 blk_per_trk, blksize); 3784 return cqr; 3785 } 3786 3787 static struct dasd_ccw_req *dasd_eckd_build_cp_raw(struct dasd_device *startdev, 3788 struct dasd_block *block, 3789 struct request *req) 3790 { 3791 sector_t start_padding_sectors, end_sector_offset, end_padding_sectors; 3792 unsigned int seg_len, len_to_track_end; 3793 unsigned int cidaw, cplength, datasize; 3794 sector_t first_trk, last_trk, sectors; 3795 struct dasd_eckd_private *base_priv; 3796 struct dasd_device *basedev; 3797 struct req_iterator iter; 3798 struct dasd_ccw_req *cqr; 3799 unsigned int first_offs; 3800 unsigned int trkcount; 3801 unsigned long *idaws; 3802 unsigned int size; 3803 unsigned char cmd; 3804 struct bio_vec bv; 3805 struct ccw1 *ccw; 3806 int use_prefix; 3807 void *data; 3808 char *dst; 3809 3810 /* 3811 * raw track access needs to be mutiple of 64k and on 64k boundary 3812 * For read requests we can fix an incorrect alignment by padding 3813 * the request with dummy pages. 3814 */ 3815 start_padding_sectors = blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK; 3816 end_sector_offset = (blk_rq_pos(req) + blk_rq_sectors(req)) % 3817 DASD_RAW_SECTORS_PER_TRACK; 3818 end_padding_sectors = (DASD_RAW_SECTORS_PER_TRACK - end_sector_offset) % 3819 DASD_RAW_SECTORS_PER_TRACK; 3820 basedev = block->base; 3821 if ((start_padding_sectors || end_padding_sectors) && 3822 (rq_data_dir(req) == WRITE)) { 3823 DBF_DEV_EVENT(DBF_ERR, basedev, 3824 "raw write not track aligned (%lu,%lu) req %p", 3825 start_padding_sectors, end_padding_sectors, req); 3826 return ERR_PTR(-EINVAL); 3827 } 3828 3829 first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK; 3830 last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) / 3831 DASD_RAW_SECTORS_PER_TRACK; 3832 trkcount = last_trk - first_trk + 1; 3833 first_offs = 0; 3834 3835 if (rq_data_dir(req) == READ) 3836 cmd = DASD_ECKD_CCW_READ_TRACK; 3837 else if (rq_data_dir(req) == WRITE) 3838 cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK; 3839 else 3840 return ERR_PTR(-EINVAL); 3841 3842 /* 3843 * Raw track based I/O needs IDAWs for each page, 3844 * and not just for 64 bit addresses. 3845 */ 3846 cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK; 3847 3848 /* 3849 * struct PFX_eckd_data and struct LRE_eckd_data can have up to 2 bytes 3850 * of extended parameter. This is needed for write full track. 3851 */ 3852 base_priv = basedev->private; 3853 use_prefix = base_priv->features.feature[8] & 0x01; 3854 if (use_prefix) { 3855 cplength = 1 + trkcount; 3856 size = sizeof(struct PFX_eckd_data) + 2; 3857 } else { 3858 cplength = 2 + trkcount; 3859 size = sizeof(struct DE_eckd_data) + 3860 sizeof(struct LRE_eckd_data) + 2; 3861 } 3862 size = ALIGN(size, 8); 3863 3864 datasize = size + cidaw * sizeof(unsigned long); 3865 3866 /* Allocate the ccw request. */ 3867 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, 3868 datasize, startdev, blk_mq_rq_to_pdu(req)); 3869 if (IS_ERR(cqr)) 3870 return cqr; 3871 3872 ccw = cqr->cpaddr; 3873 data = cqr->data; 3874 3875 if (use_prefix) { 3876 prefix_LRE(ccw++, data, first_trk, last_trk, cmd, basedev, 3877 startdev, 1, first_offs + 1, trkcount, 0, 0); 3878 } else { 3879 define_extent(ccw++, data, first_trk, last_trk, cmd, basedev, 0); 3880 ccw[-1].flags |= CCW_FLAG_CC; 3881 3882 data += sizeof(struct DE_eckd_data); 3883 locate_record_ext(ccw++, data, first_trk, first_offs + 1, 3884 trkcount, cmd, basedev, 0, 0); 3885 } 3886 3887 idaws = (unsigned long *)(cqr->data + size); 3888 len_to_track_end = 0; 3889 if (start_padding_sectors) { 3890 ccw[-1].flags |= CCW_FLAG_CC; 3891 ccw->cmd_code = cmd; 3892 /* maximum 3390 track size */ 3893 ccw->count = 57326; 3894 /* 64k map to one track */ 3895 len_to_track_end = 65536 - start_padding_sectors * 512; 3896 ccw->cda = (__u32)(addr_t)idaws; 3897 ccw->flags |= CCW_FLAG_IDA; 3898 ccw->flags |= CCW_FLAG_SLI; 3899 ccw++; 3900 for (sectors = 0; sectors < start_padding_sectors; sectors += 8) 3901 idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE); 3902 } 3903 rq_for_each_segment(bv, req, iter) { 3904 dst = page_address(bv.bv_page) + bv.bv_offset; 3905 seg_len = bv.bv_len; 3906 if (cmd == DASD_ECKD_CCW_READ_TRACK) 3907 memset(dst, 0, seg_len); 3908 if (!len_to_track_end) { 3909 ccw[-1].flags |= CCW_FLAG_CC; 3910 ccw->cmd_code = cmd; 3911 /* maximum 3390 track size */ 3912 ccw->count = 57326; 3913 /* 64k map to one track */ 3914 len_to_track_end = 65536; 3915 ccw->cda = (__u32)(addr_t)idaws; 3916 ccw->flags |= CCW_FLAG_IDA; 3917 ccw->flags |= CCW_FLAG_SLI; 3918 ccw++; 3919 } 3920 len_to_track_end -= seg_len; 3921 idaws = idal_create_words(idaws, dst, seg_len); 3922 } 3923 for (sectors = 0; sectors < end_padding_sectors; sectors += 8) 3924 idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE); 3925 if (blk_noretry_request(req) || 3926 block->base->features & DASD_FEATURE_FAILFAST) 3927 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 3928 cqr->startdev = startdev; 3929 cqr->memdev = startdev; 3930 cqr->block = block; 3931 cqr->expires = startdev->default_expires * HZ; 3932 cqr->lpm = dasd_path_get_ppm(startdev); 3933 cqr->retries = startdev->default_retries; 3934 cqr->buildclk = get_tod_clock(); 3935 cqr->status = DASD_CQR_FILLED; 3936 3937 return cqr; 3938 } 3939 3940 3941 static int 3942 dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req) 3943 { 3944 struct dasd_eckd_private *private; 3945 struct ccw1 *ccw; 3946 struct req_iterator iter; 3947 struct bio_vec bv; 3948 char *dst, *cda; 3949 unsigned int blksize, blk_per_trk, off; 3950 sector_t recid; 3951 int status; 3952 3953 if (!dasd_page_cache) 3954 goto out; 3955 private = cqr->block->base->private; 3956 blksize = cqr->block->bp_block; 3957 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); 3958 recid = blk_rq_pos(req) >> cqr->block->s2b_shift; 3959 ccw = cqr->cpaddr; 3960 /* Skip over define extent & locate record. */ 3961 ccw++; 3962 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) 3963 ccw++; 3964 rq_for_each_segment(bv, req, iter) { 3965 dst = page_address(bv.bv_page) + bv.bv_offset; 3966 for (off = 0; off < bv.bv_len; off += blksize) { 3967 /* Skip locate record. */ 3968 if (private->uses_cdl && recid <= 2*blk_per_trk) 3969 ccw++; 3970 if (dst) { 3971 if (ccw->flags & CCW_FLAG_IDA) 3972 cda = *((char **)((addr_t) ccw->cda)); 3973 else 3974 cda = (char *)((addr_t) ccw->cda); 3975 if (dst != cda) { 3976 if (rq_data_dir(req) == READ) 3977 memcpy(dst, cda, bv.bv_len); 3978 kmem_cache_free(dasd_page_cache, 3979 (void *)((addr_t)cda & PAGE_MASK)); 3980 } 3981 dst = NULL; 3982 } 3983 ccw++; 3984 recid++; 3985 } 3986 } 3987 out: 3988 status = cqr->status == DASD_CQR_DONE; 3989 dasd_sfree_request(cqr, cqr->memdev); 3990 return status; 3991 } 3992 3993 /* 3994 * Modify ccw/tcw in cqr so it can be started on a base device. 3995 * 3996 * Note that this is not enough to restart the cqr! 3997 * Either reset cqr->startdev as well (summary unit check handling) 3998 * or restart via separate cqr (as in ERP handling). 3999 */ 4000 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr) 4001 { 4002 struct ccw1 *ccw; 4003 struct PFX_eckd_data *pfxdata; 4004 struct tcw *tcw; 4005 struct tccb *tccb; 4006 struct dcw *dcw; 4007 4008 if (cqr->cpmode == 1) { 4009 tcw = cqr->cpaddr; 4010 tccb = tcw_get_tccb(tcw); 4011 dcw = (struct dcw *)&tccb->tca[0]; 4012 pfxdata = (struct PFX_eckd_data *)&dcw->cd[0]; 4013 pfxdata->validity.verify_base = 0; 4014 pfxdata->validity.hyper_pav = 0; 4015 } else { 4016 ccw = cqr->cpaddr; 4017 pfxdata = cqr->data; 4018 if (ccw->cmd_code == DASD_ECKD_CCW_PFX) { 4019 pfxdata->validity.verify_base = 0; 4020 pfxdata->validity.hyper_pav = 0; 4021 } 4022 } 4023 } 4024 4025 #define DASD_ECKD_CHANQ_MAX_SIZE 4 4026 4027 static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base, 4028 struct dasd_block *block, 4029 struct request *req) 4030 { 4031 struct dasd_eckd_private *private; 4032 struct dasd_device *startdev; 4033 unsigned long flags; 4034 struct dasd_ccw_req *cqr; 4035 4036 startdev = dasd_alias_get_start_dev(base); 4037 if (!startdev) 4038 startdev = base; 4039 private = startdev->private; 4040 if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE) 4041 return ERR_PTR(-EBUSY); 4042 4043 spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags); 4044 private->count++; 4045 if ((base->features & DASD_FEATURE_USERAW)) 4046 cqr = dasd_eckd_build_cp_raw(startdev, block, req); 4047 else 4048 cqr = dasd_eckd_build_cp(startdev, block, req); 4049 if (IS_ERR(cqr)) 4050 private->count--; 4051 spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags); 4052 return cqr; 4053 } 4054 4055 static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr, 4056 struct request *req) 4057 { 4058 struct dasd_eckd_private *private; 4059 unsigned long flags; 4060 4061 spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags); 4062 private = cqr->memdev->private; 4063 private->count--; 4064 spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags); 4065 return dasd_eckd_free_cp(cqr, req); 4066 } 4067 4068 static int 4069 dasd_eckd_fill_info(struct dasd_device * device, 4070 struct dasd_information2_t * info) 4071 { 4072 struct dasd_eckd_private *private = device->private; 4073 4074 info->label_block = 2; 4075 info->FBA_layout = private->uses_cdl ? 0 : 1; 4076 info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL; 4077 info->characteristics_size = sizeof(private->rdc_data); 4078 memcpy(info->characteristics, &private->rdc_data, 4079 sizeof(private->rdc_data)); 4080 info->confdata_size = min((unsigned long)private->conf_len, 4081 sizeof(info->configuration_data)); 4082 memcpy(info->configuration_data, private->conf_data, 4083 info->confdata_size); 4084 return 0; 4085 } 4086 4087 /* 4088 * SECTION: ioctl functions for eckd devices. 4089 */ 4090 4091 /* 4092 * Release device ioctl. 4093 * Buils a channel programm to releases a prior reserved 4094 * (see dasd_eckd_reserve) device. 4095 */ 4096 static int 4097 dasd_eckd_release(struct dasd_device *device) 4098 { 4099 struct dasd_ccw_req *cqr; 4100 int rc; 4101 struct ccw1 *ccw; 4102 int useglobal; 4103 4104 if (!capable(CAP_SYS_ADMIN)) 4105 return -EACCES; 4106 4107 useglobal = 0; 4108 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device, NULL); 4109 if (IS_ERR(cqr)) { 4110 mutex_lock(&dasd_reserve_mutex); 4111 useglobal = 1; 4112 cqr = &dasd_reserve_req->cqr; 4113 memset(cqr, 0, sizeof(*cqr)); 4114 memset(&dasd_reserve_req->ccw, 0, 4115 sizeof(dasd_reserve_req->ccw)); 4116 cqr->cpaddr = &dasd_reserve_req->ccw; 4117 cqr->data = &dasd_reserve_req->data; 4118 cqr->magic = DASD_ECKD_MAGIC; 4119 } 4120 ccw = cqr->cpaddr; 4121 ccw->cmd_code = DASD_ECKD_CCW_RELEASE; 4122 ccw->flags |= CCW_FLAG_SLI; 4123 ccw->count = 32; 4124 ccw->cda = (__u32)(addr_t) cqr->data; 4125 cqr->startdev = device; 4126 cqr->memdev = device; 4127 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); 4128 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 4129 cqr->retries = 2; /* set retry counter to enable basic ERP */ 4130 cqr->expires = 2 * HZ; 4131 cqr->buildclk = get_tod_clock(); 4132 cqr->status = DASD_CQR_FILLED; 4133 4134 rc = dasd_sleep_on_immediatly(cqr); 4135 if (!rc) 4136 clear_bit(DASD_FLAG_IS_RESERVED, &device->flags); 4137 4138 if (useglobal) 4139 mutex_unlock(&dasd_reserve_mutex); 4140 else 4141 dasd_sfree_request(cqr, cqr->memdev); 4142 return rc; 4143 } 4144 4145 /* 4146 * Reserve device ioctl. 4147 * Options are set to 'synchronous wait for interrupt' and 4148 * 'timeout the request'. This leads to a terminate IO if 4149 * the interrupt is outstanding for a certain time. 4150 */ 4151 static int 4152 dasd_eckd_reserve(struct dasd_device *device) 4153 { 4154 struct dasd_ccw_req *cqr; 4155 int rc; 4156 struct ccw1 *ccw; 4157 int useglobal; 4158 4159 if (!capable(CAP_SYS_ADMIN)) 4160 return -EACCES; 4161 4162 useglobal = 0; 4163 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device, NULL); 4164 if (IS_ERR(cqr)) { 4165 mutex_lock(&dasd_reserve_mutex); 4166 useglobal = 1; 4167 cqr = &dasd_reserve_req->cqr; 4168 memset(cqr, 0, sizeof(*cqr)); 4169 memset(&dasd_reserve_req->ccw, 0, 4170 sizeof(dasd_reserve_req->ccw)); 4171 cqr->cpaddr = &dasd_reserve_req->ccw; 4172 cqr->data = &dasd_reserve_req->data; 4173 cqr->magic = DASD_ECKD_MAGIC; 4174 } 4175 ccw = cqr->cpaddr; 4176 ccw->cmd_code = DASD_ECKD_CCW_RESERVE; 4177 ccw->flags |= CCW_FLAG_SLI; 4178 ccw->count = 32; 4179 ccw->cda = (__u32)(addr_t) cqr->data; 4180 cqr->startdev = device; 4181 cqr->memdev = device; 4182 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); 4183 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 4184 cqr->retries = 2; /* set retry counter to enable basic ERP */ 4185 cqr->expires = 2 * HZ; 4186 cqr->buildclk = get_tod_clock(); 4187 cqr->status = DASD_CQR_FILLED; 4188 4189 rc = dasd_sleep_on_immediatly(cqr); 4190 if (!rc) 4191 set_bit(DASD_FLAG_IS_RESERVED, &device->flags); 4192 4193 if (useglobal) 4194 mutex_unlock(&dasd_reserve_mutex); 4195 else 4196 dasd_sfree_request(cqr, cqr->memdev); 4197 return rc; 4198 } 4199 4200 /* 4201 * Steal lock ioctl - unconditional reserve device. 4202 * Buils a channel programm to break a device's reservation. 4203 * (unconditional reserve) 4204 */ 4205 static int 4206 dasd_eckd_steal_lock(struct dasd_device *device) 4207 { 4208 struct dasd_ccw_req *cqr; 4209 int rc; 4210 struct ccw1 *ccw; 4211 int useglobal; 4212 4213 if (!capable(CAP_SYS_ADMIN)) 4214 return -EACCES; 4215 4216 useglobal = 0; 4217 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device, NULL); 4218 if (IS_ERR(cqr)) { 4219 mutex_lock(&dasd_reserve_mutex); 4220 useglobal = 1; 4221 cqr = &dasd_reserve_req->cqr; 4222 memset(cqr, 0, sizeof(*cqr)); 4223 memset(&dasd_reserve_req->ccw, 0, 4224 sizeof(dasd_reserve_req->ccw)); 4225 cqr->cpaddr = &dasd_reserve_req->ccw; 4226 cqr->data = &dasd_reserve_req->data; 4227 cqr->magic = DASD_ECKD_MAGIC; 4228 } 4229 ccw = cqr->cpaddr; 4230 ccw->cmd_code = DASD_ECKD_CCW_SLCK; 4231 ccw->flags |= CCW_FLAG_SLI; 4232 ccw->count = 32; 4233 ccw->cda = (__u32)(addr_t) cqr->data; 4234 cqr->startdev = device; 4235 cqr->memdev = device; 4236 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); 4237 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 4238 cqr->retries = 2; /* set retry counter to enable basic ERP */ 4239 cqr->expires = 2 * HZ; 4240 cqr->buildclk = get_tod_clock(); 4241 cqr->status = DASD_CQR_FILLED; 4242 4243 rc = dasd_sleep_on_immediatly(cqr); 4244 if (!rc) 4245 set_bit(DASD_FLAG_IS_RESERVED, &device->flags); 4246 4247 if (useglobal) 4248 mutex_unlock(&dasd_reserve_mutex); 4249 else 4250 dasd_sfree_request(cqr, cqr->memdev); 4251 return rc; 4252 } 4253 4254 /* 4255 * SNID - Sense Path Group ID 4256 * This ioctl may be used in situations where I/O is stalled due to 4257 * a reserve, so if the normal dasd_smalloc_request fails, we use the 4258 * preallocated dasd_reserve_req. 4259 */ 4260 static int dasd_eckd_snid(struct dasd_device *device, 4261 void __user *argp) 4262 { 4263 struct dasd_ccw_req *cqr; 4264 int rc; 4265 struct ccw1 *ccw; 4266 int useglobal; 4267 struct dasd_snid_ioctl_data usrparm; 4268 4269 if (!capable(CAP_SYS_ADMIN)) 4270 return -EACCES; 4271 4272 if (copy_from_user(&usrparm, argp, sizeof(usrparm))) 4273 return -EFAULT; 4274 4275 useglobal = 0; 4276 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 4277 sizeof(struct dasd_snid_data), device, 4278 NULL); 4279 if (IS_ERR(cqr)) { 4280 mutex_lock(&dasd_reserve_mutex); 4281 useglobal = 1; 4282 cqr = &dasd_reserve_req->cqr; 4283 memset(cqr, 0, sizeof(*cqr)); 4284 memset(&dasd_reserve_req->ccw, 0, 4285 sizeof(dasd_reserve_req->ccw)); 4286 cqr->cpaddr = &dasd_reserve_req->ccw; 4287 cqr->data = &dasd_reserve_req->data; 4288 cqr->magic = DASD_ECKD_MAGIC; 4289 } 4290 ccw = cqr->cpaddr; 4291 ccw->cmd_code = DASD_ECKD_CCW_SNID; 4292 ccw->flags |= CCW_FLAG_SLI; 4293 ccw->count = 12; 4294 ccw->cda = (__u32)(addr_t) cqr->data; 4295 cqr->startdev = device; 4296 cqr->memdev = device; 4297 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); 4298 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 4299 set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags); 4300 cqr->retries = 5; 4301 cqr->expires = 10 * HZ; 4302 cqr->buildclk = get_tod_clock(); 4303 cqr->status = DASD_CQR_FILLED; 4304 cqr->lpm = usrparm.path_mask; 4305 4306 rc = dasd_sleep_on_immediatly(cqr); 4307 /* verify that I/O processing didn't modify the path mask */ 4308 if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask)) 4309 rc = -EIO; 4310 if (!rc) { 4311 usrparm.data = *((struct dasd_snid_data *)cqr->data); 4312 if (copy_to_user(argp, &usrparm, sizeof(usrparm))) 4313 rc = -EFAULT; 4314 } 4315 4316 if (useglobal) 4317 mutex_unlock(&dasd_reserve_mutex); 4318 else 4319 dasd_sfree_request(cqr, cqr->memdev); 4320 return rc; 4321 } 4322 4323 /* 4324 * Read performance statistics 4325 */ 4326 static int 4327 dasd_eckd_performance(struct dasd_device *device, void __user *argp) 4328 { 4329 struct dasd_psf_prssd_data *prssdp; 4330 struct dasd_rssd_perf_stats_t *stats; 4331 struct dasd_ccw_req *cqr; 4332 struct ccw1 *ccw; 4333 int rc; 4334 4335 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, 4336 (sizeof(struct dasd_psf_prssd_data) + 4337 sizeof(struct dasd_rssd_perf_stats_t)), 4338 device, NULL); 4339 if (IS_ERR(cqr)) { 4340 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 4341 "Could not allocate initialization request"); 4342 return PTR_ERR(cqr); 4343 } 4344 cqr->startdev = device; 4345 cqr->memdev = device; 4346 cqr->retries = 0; 4347 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); 4348 cqr->expires = 10 * HZ; 4349 4350 /* Prepare for Read Subsystem Data */ 4351 prssdp = (struct dasd_psf_prssd_data *) cqr->data; 4352 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); 4353 prssdp->order = PSF_ORDER_PRSSD; 4354 prssdp->suborder = 0x01; /* Performance Statistics */ 4355 prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */ 4356 4357 ccw = cqr->cpaddr; 4358 ccw->cmd_code = DASD_ECKD_CCW_PSF; 4359 ccw->count = sizeof(struct dasd_psf_prssd_data); 4360 ccw->flags |= CCW_FLAG_CC; 4361 ccw->cda = (__u32)(addr_t) prssdp; 4362 4363 /* Read Subsystem Data - Performance Statistics */ 4364 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); 4365 memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t)); 4366 4367 ccw++; 4368 ccw->cmd_code = DASD_ECKD_CCW_RSSD; 4369 ccw->count = sizeof(struct dasd_rssd_perf_stats_t); 4370 ccw->cda = (__u32)(addr_t) stats; 4371 4372 cqr->buildclk = get_tod_clock(); 4373 cqr->status = DASD_CQR_FILLED; 4374 rc = dasd_sleep_on(cqr); 4375 if (rc == 0) { 4376 prssdp = (struct dasd_psf_prssd_data *) cqr->data; 4377 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); 4378 if (copy_to_user(argp, stats, 4379 sizeof(struct dasd_rssd_perf_stats_t))) 4380 rc = -EFAULT; 4381 } 4382 dasd_sfree_request(cqr, cqr->memdev); 4383 return rc; 4384 } 4385 4386 /* 4387 * Get attributes (cache operations) 4388 * Returnes the cache attributes used in Define Extend (DE). 4389 */ 4390 static int 4391 dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp) 4392 { 4393 struct dasd_eckd_private *private = device->private; 4394 struct attrib_data_t attrib = private->attrib; 4395 int rc; 4396 4397 if (!capable(CAP_SYS_ADMIN)) 4398 return -EACCES; 4399 if (!argp) 4400 return -EINVAL; 4401 4402 rc = 0; 4403 if (copy_to_user(argp, (long *) &attrib, 4404 sizeof(struct attrib_data_t))) 4405 rc = -EFAULT; 4406 4407 return rc; 4408 } 4409 4410 /* 4411 * Set attributes (cache operations) 4412 * Stores the attributes for cache operation to be used in Define Extend (DE). 4413 */ 4414 static int 4415 dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp) 4416 { 4417 struct dasd_eckd_private *private = device->private; 4418 struct attrib_data_t attrib; 4419 4420 if (!capable(CAP_SYS_ADMIN)) 4421 return -EACCES; 4422 if (!argp) 4423 return -EINVAL; 4424 4425 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t))) 4426 return -EFAULT; 4427 private->attrib = attrib; 4428 4429 dev_info(&device->cdev->dev, 4430 "The DASD cache mode was set to %x (%i cylinder prestage)\n", 4431 private->attrib.operation, private->attrib.nr_cyl); 4432 return 0; 4433 } 4434 4435 /* 4436 * Issue syscall I/O to EMC Symmetrix array. 4437 * CCWs are PSF and RSSD 4438 */ 4439 static int dasd_symm_io(struct dasd_device *device, void __user *argp) 4440 { 4441 struct dasd_symmio_parms usrparm; 4442 char *psf_data, *rssd_result; 4443 struct dasd_ccw_req *cqr; 4444 struct ccw1 *ccw; 4445 char psf0, psf1; 4446 int rc; 4447 4448 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO)) 4449 return -EACCES; 4450 psf0 = psf1 = 0; 4451 4452 /* Copy parms from caller */ 4453 rc = -EFAULT; 4454 if (copy_from_user(&usrparm, argp, sizeof(usrparm))) 4455 goto out; 4456 if (is_compat_task()) { 4457 /* Make sure pointers are sane even on 31 bit. */ 4458 rc = -EINVAL; 4459 if ((usrparm.psf_data >> 32) != 0) 4460 goto out; 4461 if ((usrparm.rssd_result >> 32) != 0) 4462 goto out; 4463 usrparm.psf_data &= 0x7fffffffULL; 4464 usrparm.rssd_result &= 0x7fffffffULL; 4465 } 4466 /* alloc I/O data area */ 4467 psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA); 4468 rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA); 4469 if (!psf_data || !rssd_result) { 4470 rc = -ENOMEM; 4471 goto out_free; 4472 } 4473 4474 /* get syscall header from user space */ 4475 rc = -EFAULT; 4476 if (copy_from_user(psf_data, 4477 (void __user *)(unsigned long) usrparm.psf_data, 4478 usrparm.psf_data_len)) 4479 goto out_free; 4480 psf0 = psf_data[0]; 4481 psf1 = psf_data[1]; 4482 4483 /* setup CCWs for PSF + RSSD */ 4484 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2, 0, device, NULL); 4485 if (IS_ERR(cqr)) { 4486 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 4487 "Could not allocate initialization request"); 4488 rc = PTR_ERR(cqr); 4489 goto out_free; 4490 } 4491 4492 cqr->startdev = device; 4493 cqr->memdev = device; 4494 cqr->retries = 3; 4495 cqr->expires = 10 * HZ; 4496 cqr->buildclk = get_tod_clock(); 4497 cqr->status = DASD_CQR_FILLED; 4498 4499 /* Build the ccws */ 4500 ccw = cqr->cpaddr; 4501 4502 /* PSF ccw */ 4503 ccw->cmd_code = DASD_ECKD_CCW_PSF; 4504 ccw->count = usrparm.psf_data_len; 4505 ccw->flags |= CCW_FLAG_CC; 4506 ccw->cda = (__u32)(addr_t) psf_data; 4507 4508 ccw++; 4509 4510 /* RSSD ccw */ 4511 ccw->cmd_code = DASD_ECKD_CCW_RSSD; 4512 ccw->count = usrparm.rssd_result_len; 4513 ccw->flags = CCW_FLAG_SLI ; 4514 ccw->cda = (__u32)(addr_t) rssd_result; 4515 4516 rc = dasd_sleep_on(cqr); 4517 if (rc) 4518 goto out_sfree; 4519 4520 rc = -EFAULT; 4521 if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result, 4522 rssd_result, usrparm.rssd_result_len)) 4523 goto out_sfree; 4524 rc = 0; 4525 4526 out_sfree: 4527 dasd_sfree_request(cqr, cqr->memdev); 4528 out_free: 4529 kfree(rssd_result); 4530 kfree(psf_data); 4531 out: 4532 DBF_DEV_EVENT(DBF_WARNING, device, 4533 "Symmetrix ioctl (0x%02x 0x%02x): rc=%d", 4534 (int) psf0, (int) psf1, rc); 4535 return rc; 4536 } 4537 4538 static int 4539 dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp) 4540 { 4541 struct dasd_device *device = block->base; 4542 4543 switch (cmd) { 4544 case BIODASDGATTR: 4545 return dasd_eckd_get_attrib(device, argp); 4546 case BIODASDSATTR: 4547 return dasd_eckd_set_attrib(device, argp); 4548 case BIODASDPSRD: 4549 return dasd_eckd_performance(device, argp); 4550 case BIODASDRLSE: 4551 return dasd_eckd_release(device); 4552 case BIODASDRSRV: 4553 return dasd_eckd_reserve(device); 4554 case BIODASDSLCK: 4555 return dasd_eckd_steal_lock(device); 4556 case BIODASDSNID: 4557 return dasd_eckd_snid(device, argp); 4558 case BIODASDSYMMIO: 4559 return dasd_symm_io(device, argp); 4560 default: 4561 return -ENOTTY; 4562 } 4563 } 4564 4565 /* 4566 * Dump the range of CCWs into 'page' buffer 4567 * and return number of printed chars. 4568 */ 4569 static int 4570 dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page) 4571 { 4572 int len, count; 4573 char *datap; 4574 4575 len = 0; 4576 while (from <= to) { 4577 len += sprintf(page + len, PRINTK_HEADER 4578 " CCW %p: %08X %08X DAT:", 4579 from, ((int *) from)[0], ((int *) from)[1]); 4580 4581 /* get pointer to data (consider IDALs) */ 4582 if (from->flags & CCW_FLAG_IDA) 4583 datap = (char *) *((addr_t *) (addr_t) from->cda); 4584 else 4585 datap = (char *) ((addr_t) from->cda); 4586 4587 /* dump data (max 32 bytes) */ 4588 for (count = 0; count < from->count && count < 32; count++) { 4589 if (count % 8 == 0) len += sprintf(page + len, " "); 4590 if (count % 4 == 0) len += sprintf(page + len, " "); 4591 len += sprintf(page + len, "%02x", datap[count]); 4592 } 4593 len += sprintf(page + len, "\n"); 4594 from++; 4595 } 4596 return len; 4597 } 4598 4599 static void 4600 dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb, 4601 char *reason) 4602 { 4603 u64 *sense; 4604 u64 *stat; 4605 4606 sense = (u64 *) dasd_get_sense(irb); 4607 stat = (u64 *) &irb->scsw; 4608 if (sense) { 4609 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : " 4610 "%016llx %016llx %016llx %016llx", 4611 reason, *stat, *((u32 *) (stat + 1)), 4612 sense[0], sense[1], sense[2], sense[3]); 4613 } else { 4614 DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s", 4615 reason, *stat, *((u32 *) (stat + 1)), 4616 "NO VALID SENSE"); 4617 } 4618 } 4619 4620 /* 4621 * Print sense data and related channel program. 4622 * Parts are printed because printk buffer is only 1024 bytes. 4623 */ 4624 static void dasd_eckd_dump_sense_ccw(struct dasd_device *device, 4625 struct dasd_ccw_req *req, struct irb *irb) 4626 { 4627 char *page; 4628 struct ccw1 *first, *last, *fail, *from, *to; 4629 int len, sl, sct; 4630 4631 page = (char *) get_zeroed_page(GFP_ATOMIC); 4632 if (page == NULL) { 4633 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 4634 "No memory to dump sense data\n"); 4635 return; 4636 } 4637 /* dump the sense data */ 4638 len = sprintf(page, PRINTK_HEADER 4639 " I/O status report for device %s:\n", 4640 dev_name(&device->cdev->dev)); 4641 len += sprintf(page + len, PRINTK_HEADER 4642 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X " 4643 "CS:%02X RC:%d\n", 4644 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw), 4645 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw), 4646 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw), 4647 req ? req->intrc : 0); 4648 len += sprintf(page + len, PRINTK_HEADER 4649 " device %s: Failing CCW: %p\n", 4650 dev_name(&device->cdev->dev), 4651 (void *) (addr_t) irb->scsw.cmd.cpa); 4652 if (irb->esw.esw0.erw.cons) { 4653 for (sl = 0; sl < 4; sl++) { 4654 len += sprintf(page + len, PRINTK_HEADER 4655 " Sense(hex) %2d-%2d:", 4656 (8 * sl), ((8 * sl) + 7)); 4657 4658 for (sct = 0; sct < 8; sct++) { 4659 len += sprintf(page + len, " %02x", 4660 irb->ecw[8 * sl + sct]); 4661 } 4662 len += sprintf(page + len, "\n"); 4663 } 4664 4665 if (irb->ecw[27] & DASD_SENSE_BIT_0) { 4666 /* 24 Byte Sense Data */ 4667 sprintf(page + len, PRINTK_HEADER 4668 " 24 Byte: %x MSG %x, " 4669 "%s MSGb to SYSOP\n", 4670 irb->ecw[7] >> 4, irb->ecw[7] & 0x0f, 4671 irb->ecw[1] & 0x10 ? "" : "no"); 4672 } else { 4673 /* 32 Byte Sense Data */ 4674 sprintf(page + len, PRINTK_HEADER 4675 " 32 Byte: Format: %x " 4676 "Exception class %x\n", 4677 irb->ecw[6] & 0x0f, irb->ecw[22] >> 4); 4678 } 4679 } else { 4680 sprintf(page + len, PRINTK_HEADER 4681 " SORRY - NO VALID SENSE AVAILABLE\n"); 4682 } 4683 printk(KERN_ERR "%s", page); 4684 4685 if (req) { 4686 /* req == NULL for unsolicited interrupts */ 4687 /* dump the Channel Program (max 140 Bytes per line) */ 4688 /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */ 4689 first = req->cpaddr; 4690 for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++); 4691 to = min(first + 6, last); 4692 len = sprintf(page, PRINTK_HEADER 4693 " Related CP in req: %p\n", req); 4694 dasd_eckd_dump_ccw_range(first, to, page + len); 4695 printk(KERN_ERR "%s", page); 4696 4697 /* print failing CCW area (maximum 4) */ 4698 /* scsw->cda is either valid or zero */ 4699 len = 0; 4700 from = ++to; 4701 fail = (struct ccw1 *)(addr_t) 4702 irb->scsw.cmd.cpa; /* failing CCW */ 4703 if (from < fail - 2) { 4704 from = fail - 2; /* there is a gap - print header */ 4705 len += sprintf(page, PRINTK_HEADER "......\n"); 4706 } 4707 to = min(fail + 1, last); 4708 len += dasd_eckd_dump_ccw_range(from, to, page + len); 4709 4710 /* print last CCWs (maximum 2) */ 4711 from = max(from, ++to); 4712 if (from < last - 1) { 4713 from = last - 1; /* there is a gap - print header */ 4714 len += sprintf(page + len, PRINTK_HEADER "......\n"); 4715 } 4716 len += dasd_eckd_dump_ccw_range(from, last, page + len); 4717 if (len > 0) 4718 printk(KERN_ERR "%s", page); 4719 } 4720 free_page((unsigned long) page); 4721 } 4722 4723 4724 /* 4725 * Print sense data from a tcw. 4726 */ 4727 static void dasd_eckd_dump_sense_tcw(struct dasd_device *device, 4728 struct dasd_ccw_req *req, struct irb *irb) 4729 { 4730 char *page; 4731 int len, sl, sct, residual; 4732 struct tsb *tsb; 4733 u8 *sense, *rcq; 4734 4735 page = (char *) get_zeroed_page(GFP_ATOMIC); 4736 if (page == NULL) { 4737 DBF_DEV_EVENT(DBF_WARNING, device, " %s", 4738 "No memory to dump sense data"); 4739 return; 4740 } 4741 /* dump the sense data */ 4742 len = sprintf(page, PRINTK_HEADER 4743 " I/O status report for device %s:\n", 4744 dev_name(&device->cdev->dev)); 4745 len += sprintf(page + len, PRINTK_HEADER 4746 " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X " 4747 "CS:%02X fcxs:%02X schxs:%02X RC:%d\n", 4748 req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw), 4749 scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw), 4750 scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw), 4751 irb->scsw.tm.fcxs, 4752 (irb->scsw.tm.ifob << 7) | irb->scsw.tm.sesq, 4753 req ? req->intrc : 0); 4754 len += sprintf(page + len, PRINTK_HEADER 4755 " device %s: Failing TCW: %p\n", 4756 dev_name(&device->cdev->dev), 4757 (void *) (addr_t) irb->scsw.tm.tcw); 4758 4759 tsb = NULL; 4760 sense = NULL; 4761 if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01)) 4762 tsb = tcw_get_tsb( 4763 (struct tcw *)(unsigned long)irb->scsw.tm.tcw); 4764 4765 if (tsb) { 4766 len += sprintf(page + len, PRINTK_HEADER 4767 " tsb->length %d\n", tsb->length); 4768 len += sprintf(page + len, PRINTK_HEADER 4769 " tsb->flags %x\n", tsb->flags); 4770 len += sprintf(page + len, PRINTK_HEADER 4771 " tsb->dcw_offset %d\n", tsb->dcw_offset); 4772 len += sprintf(page + len, PRINTK_HEADER 4773 " tsb->count %d\n", tsb->count); 4774 residual = tsb->count - 28; 4775 len += sprintf(page + len, PRINTK_HEADER 4776 " residual %d\n", residual); 4777 4778 switch (tsb->flags & 0x07) { 4779 case 1: /* tsa_iostat */ 4780 len += sprintf(page + len, PRINTK_HEADER 4781 " tsb->tsa.iostat.dev_time %d\n", 4782 tsb->tsa.iostat.dev_time); 4783 len += sprintf(page + len, PRINTK_HEADER 4784 " tsb->tsa.iostat.def_time %d\n", 4785 tsb->tsa.iostat.def_time); 4786 len += sprintf(page + len, PRINTK_HEADER 4787 " tsb->tsa.iostat.queue_time %d\n", 4788 tsb->tsa.iostat.queue_time); 4789 len += sprintf(page + len, PRINTK_HEADER 4790 " tsb->tsa.iostat.dev_busy_time %d\n", 4791 tsb->tsa.iostat.dev_busy_time); 4792 len += sprintf(page + len, PRINTK_HEADER 4793 " tsb->tsa.iostat.dev_act_time %d\n", 4794 tsb->tsa.iostat.dev_act_time); 4795 sense = tsb->tsa.iostat.sense; 4796 break; 4797 case 2: /* ts_ddpc */ 4798 len += sprintf(page + len, PRINTK_HEADER 4799 " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc); 4800 for (sl = 0; sl < 2; sl++) { 4801 len += sprintf(page + len, PRINTK_HEADER 4802 " tsb->tsa.ddpc.rcq %2d-%2d: ", 4803 (8 * sl), ((8 * sl) + 7)); 4804 rcq = tsb->tsa.ddpc.rcq; 4805 for (sct = 0; sct < 8; sct++) { 4806 len += sprintf(page + len, " %02x", 4807 rcq[8 * sl + sct]); 4808 } 4809 len += sprintf(page + len, "\n"); 4810 } 4811 sense = tsb->tsa.ddpc.sense; 4812 break; 4813 case 3: /* tsa_intrg */ 4814 len += sprintf(page + len, PRINTK_HEADER 4815 " tsb->tsa.intrg.: not supported yet\n"); 4816 break; 4817 } 4818 4819 if (sense) { 4820 for (sl = 0; sl < 4; sl++) { 4821 len += sprintf(page + len, PRINTK_HEADER 4822 " Sense(hex) %2d-%2d:", 4823 (8 * sl), ((8 * sl) + 7)); 4824 for (sct = 0; sct < 8; sct++) { 4825 len += sprintf(page + len, " %02x", 4826 sense[8 * sl + sct]); 4827 } 4828 len += sprintf(page + len, "\n"); 4829 } 4830 4831 if (sense[27] & DASD_SENSE_BIT_0) { 4832 /* 24 Byte Sense Data */ 4833 sprintf(page + len, PRINTK_HEADER 4834 " 24 Byte: %x MSG %x, " 4835 "%s MSGb to SYSOP\n", 4836 sense[7] >> 4, sense[7] & 0x0f, 4837 sense[1] & 0x10 ? "" : "no"); 4838 } else { 4839 /* 32 Byte Sense Data */ 4840 sprintf(page + len, PRINTK_HEADER 4841 " 32 Byte: Format: %x " 4842 "Exception class %x\n", 4843 sense[6] & 0x0f, sense[22] >> 4); 4844 } 4845 } else { 4846 sprintf(page + len, PRINTK_HEADER 4847 " SORRY - NO VALID SENSE AVAILABLE\n"); 4848 } 4849 } else { 4850 sprintf(page + len, PRINTK_HEADER 4851 " SORRY - NO TSB DATA AVAILABLE\n"); 4852 } 4853 printk(KERN_ERR "%s", page); 4854 free_page((unsigned long) page); 4855 } 4856 4857 static void dasd_eckd_dump_sense(struct dasd_device *device, 4858 struct dasd_ccw_req *req, struct irb *irb) 4859 { 4860 u8 *sense = dasd_get_sense(irb); 4861 4862 if (scsw_is_tm(&irb->scsw)) { 4863 /* 4864 * In some cases the 'File Protected' or 'Incorrect Length' 4865 * error might be expected and log messages shouldn't be written 4866 * then. Check if the according suppress bit is set. 4867 */ 4868 if (sense && (sense[1] & SNS1_FILE_PROTECTED) && 4869 test_bit(DASD_CQR_SUPPRESS_FP, &req->flags)) 4870 return; 4871 if (scsw_cstat(&irb->scsw) == 0x40 && 4872 test_bit(DASD_CQR_SUPPRESS_IL, &req->flags)) 4873 return; 4874 4875 dasd_eckd_dump_sense_tcw(device, req, irb); 4876 } else { 4877 /* 4878 * In some cases the 'Command Reject' or 'No Record Found' 4879 * error might be expected and log messages shouldn't be 4880 * written then. Check if the according suppress bit is set. 4881 */ 4882 if (sense && sense[0] & SNS0_CMD_REJECT && 4883 test_bit(DASD_CQR_SUPPRESS_CR, &req->flags)) 4884 return; 4885 4886 if (sense && sense[1] & SNS1_NO_REC_FOUND && 4887 test_bit(DASD_CQR_SUPPRESS_NRF, &req->flags)) 4888 return; 4889 4890 dasd_eckd_dump_sense_ccw(device, req, irb); 4891 } 4892 } 4893 4894 static int dasd_eckd_pm_freeze(struct dasd_device *device) 4895 { 4896 /* 4897 * the device should be disconnected from our LCU structure 4898 * on restore we will reconnect it and reread LCU specific 4899 * information like PAV support that might have changed 4900 */ 4901 dasd_alias_remove_device(device); 4902 dasd_alias_disconnect_device_from_lcu(device); 4903 4904 return 0; 4905 } 4906 4907 static int dasd_eckd_restore_device(struct dasd_device *device) 4908 { 4909 struct dasd_eckd_private *private = device->private; 4910 struct dasd_eckd_characteristics temp_rdc_data; 4911 int rc; 4912 struct dasd_uid temp_uid; 4913 unsigned long flags; 4914 unsigned long cqr_flags = 0; 4915 4916 /* Read Configuration Data */ 4917 rc = dasd_eckd_read_conf(device); 4918 if (rc) { 4919 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, 4920 "Read configuration data failed, rc=%d", rc); 4921 goto out_err; 4922 } 4923 4924 dasd_eckd_get_uid(device, &temp_uid); 4925 /* Generate device unique id */ 4926 rc = dasd_eckd_generate_uid(device); 4927 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); 4928 if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0) 4929 dev_err(&device->cdev->dev, "The UID of the DASD has " 4930 "changed\n"); 4931 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); 4932 if (rc) 4933 goto out_err; 4934 4935 /* register lcu with alias handling, enable PAV if this is a new lcu */ 4936 rc = dasd_alias_make_device_known_to_lcu(device); 4937 if (rc) 4938 goto out_err; 4939 4940 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr_flags); 4941 dasd_eckd_validate_server(device, cqr_flags); 4942 4943 /* RE-Read Configuration Data */ 4944 rc = dasd_eckd_read_conf(device); 4945 if (rc) { 4946 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, 4947 "Read configuration data failed, rc=%d", rc); 4948 goto out_err2; 4949 } 4950 4951 /* Read Feature Codes */ 4952 dasd_eckd_read_features(device); 4953 4954 /* Read Device Characteristics */ 4955 rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC, 4956 &temp_rdc_data, 64); 4957 if (rc) { 4958 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, 4959 "Read device characteristic failed, rc=%d", rc); 4960 goto out_err2; 4961 } 4962 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); 4963 memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data)); 4964 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); 4965 4966 /* add device to alias management */ 4967 dasd_alias_add_device(device); 4968 4969 return 0; 4970 4971 out_err2: 4972 dasd_alias_disconnect_device_from_lcu(device); 4973 out_err: 4974 return -1; 4975 } 4976 4977 static int dasd_eckd_reload_device(struct dasd_device *device) 4978 { 4979 struct dasd_eckd_private *private = device->private; 4980 int rc, old_base; 4981 char print_uid[60]; 4982 struct dasd_uid uid; 4983 unsigned long flags; 4984 4985 /* 4986 * remove device from alias handling to prevent new requests 4987 * from being scheduled on the wrong alias device 4988 */ 4989 dasd_alias_remove_device(device); 4990 4991 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); 4992 old_base = private->uid.base_unit_addr; 4993 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); 4994 4995 /* Read Configuration Data */ 4996 rc = dasd_eckd_read_conf(device); 4997 if (rc) 4998 goto out_err; 4999 5000 rc = dasd_eckd_generate_uid(device); 5001 if (rc) 5002 goto out_err; 5003 /* 5004 * update unit address configuration and 5005 * add device to alias management 5006 */ 5007 dasd_alias_update_add_device(device); 5008 5009 dasd_eckd_get_uid(device, &uid); 5010 5011 if (old_base != uid.base_unit_addr) { 5012 if (strlen(uid.vduit) > 0) 5013 snprintf(print_uid, sizeof(print_uid), 5014 "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial, 5015 uid.ssid, uid.base_unit_addr, uid.vduit); 5016 else 5017 snprintf(print_uid, sizeof(print_uid), 5018 "%s.%s.%04x.%02x", uid.vendor, uid.serial, 5019 uid.ssid, uid.base_unit_addr); 5020 5021 dev_info(&device->cdev->dev, 5022 "An Alias device was reassigned to a new base device " 5023 "with UID: %s\n", print_uid); 5024 } 5025 return 0; 5026 5027 out_err: 5028 return -1; 5029 } 5030 5031 static int dasd_eckd_read_message_buffer(struct dasd_device *device, 5032 struct dasd_rssd_messages *messages, 5033 __u8 lpum) 5034 { 5035 struct dasd_rssd_messages *message_buf; 5036 struct dasd_psf_prssd_data *prssdp; 5037 struct dasd_ccw_req *cqr; 5038 struct ccw1 *ccw; 5039 int rc; 5040 5041 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, 5042 (sizeof(struct dasd_psf_prssd_data) + 5043 sizeof(struct dasd_rssd_messages)), 5044 device, NULL); 5045 if (IS_ERR(cqr)) { 5046 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", 5047 "Could not allocate read message buffer request"); 5048 return PTR_ERR(cqr); 5049 } 5050 5051 cqr->lpm = lpum; 5052 retry: 5053 cqr->startdev = device; 5054 cqr->memdev = device; 5055 cqr->block = NULL; 5056 cqr->expires = 10 * HZ; 5057 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags); 5058 /* dasd_sleep_on_immediatly does not do complex error 5059 * recovery so clear erp flag and set retry counter to 5060 * do basic erp */ 5061 clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); 5062 cqr->retries = 256; 5063 5064 /* Prepare for Read Subsystem Data */ 5065 prssdp = (struct dasd_psf_prssd_data *) cqr->data; 5066 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); 5067 prssdp->order = PSF_ORDER_PRSSD; 5068 prssdp->suborder = 0x03; /* Message Buffer */ 5069 /* all other bytes of prssdp must be zero */ 5070 5071 ccw = cqr->cpaddr; 5072 ccw->cmd_code = DASD_ECKD_CCW_PSF; 5073 ccw->count = sizeof(struct dasd_psf_prssd_data); 5074 ccw->flags |= CCW_FLAG_CC; 5075 ccw->flags |= CCW_FLAG_SLI; 5076 ccw->cda = (__u32)(addr_t) prssdp; 5077 5078 /* Read Subsystem Data - message buffer */ 5079 message_buf = (struct dasd_rssd_messages *) (prssdp + 1); 5080 memset(message_buf, 0, sizeof(struct dasd_rssd_messages)); 5081 5082 ccw++; 5083 ccw->cmd_code = DASD_ECKD_CCW_RSSD; 5084 ccw->count = sizeof(struct dasd_rssd_messages); 5085 ccw->flags |= CCW_FLAG_SLI; 5086 ccw->cda = (__u32)(addr_t) message_buf; 5087 5088 cqr->buildclk = get_tod_clock(); 5089 cqr->status = DASD_CQR_FILLED; 5090 rc = dasd_sleep_on_immediatly(cqr); 5091 if (rc == 0) { 5092 prssdp = (struct dasd_psf_prssd_data *) cqr->data; 5093 message_buf = (struct dasd_rssd_messages *) 5094 (prssdp + 1); 5095 memcpy(messages, message_buf, 5096 sizeof(struct dasd_rssd_messages)); 5097 } else if (cqr->lpm) { 5098 /* 5099 * on z/VM we might not be able to do I/O on the requested path 5100 * but instead we get the required information on any path 5101 * so retry with open path mask 5102 */ 5103 cqr->lpm = 0; 5104 goto retry; 5105 } else 5106 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, 5107 "Reading messages failed with rc=%d\n" 5108 , rc); 5109 dasd_sfree_request(cqr, cqr->memdev); 5110 return rc; 5111 } 5112 5113 static int dasd_eckd_query_host_access(struct dasd_device *device, 5114 struct dasd_psf_query_host_access *data) 5115 { 5116 struct dasd_eckd_private *private = device->private; 5117 struct dasd_psf_query_host_access *host_access; 5118 struct dasd_psf_prssd_data *prssdp; 5119 struct dasd_ccw_req *cqr; 5120 struct ccw1 *ccw; 5121 int rc; 5122 5123 /* not available for HYPER PAV alias devices */ 5124 if (!device->block && private->lcu->pav == HYPER_PAV) 5125 return -EOPNOTSUPP; 5126 5127 /* may not be supported by the storage server */ 5128 if (!(private->features.feature[14] & 0x80)) 5129 return -EOPNOTSUPP; 5130 5131 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */, 5132 sizeof(struct dasd_psf_prssd_data) + 1, 5133 device, NULL); 5134 if (IS_ERR(cqr)) { 5135 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", 5136 "Could not allocate read message buffer request"); 5137 return PTR_ERR(cqr); 5138 } 5139 host_access = kzalloc(sizeof(*host_access), GFP_KERNEL | GFP_DMA); 5140 if (!host_access) { 5141 dasd_sfree_request(cqr, device); 5142 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", 5143 "Could not allocate host_access buffer"); 5144 return -ENOMEM; 5145 } 5146 cqr->startdev = device; 5147 cqr->memdev = device; 5148 cqr->block = NULL; 5149 cqr->retries = 256; 5150 cqr->expires = 10 * HZ; 5151 5152 /* Prepare for Read Subsystem Data */ 5153 prssdp = (struct dasd_psf_prssd_data *) cqr->data; 5154 memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data)); 5155 prssdp->order = PSF_ORDER_PRSSD; 5156 prssdp->suborder = PSF_SUBORDER_QHA; /* query host access */ 5157 /* LSS and Volume that will be queried */ 5158 prssdp->lss = private->ned->ID; 5159 prssdp->volume = private->ned->unit_addr; 5160 /* all other bytes of prssdp must be zero */ 5161 5162 ccw = cqr->cpaddr; 5163 ccw->cmd_code = DASD_ECKD_CCW_PSF; 5164 ccw->count = sizeof(struct dasd_psf_prssd_data); 5165 ccw->flags |= CCW_FLAG_CC; 5166 ccw->flags |= CCW_FLAG_SLI; 5167 ccw->cda = (__u32)(addr_t) prssdp; 5168 5169 /* Read Subsystem Data - query host access */ 5170 ccw++; 5171 ccw->cmd_code = DASD_ECKD_CCW_RSSD; 5172 ccw->count = sizeof(struct dasd_psf_query_host_access); 5173 ccw->flags |= CCW_FLAG_SLI; 5174 ccw->cda = (__u32)(addr_t) host_access; 5175 5176 cqr->buildclk = get_tod_clock(); 5177 cqr->status = DASD_CQR_FILLED; 5178 /* the command might not be supported, suppress error message */ 5179 __set_bit(DASD_CQR_SUPPRESS_CR, &cqr->flags); 5180 rc = dasd_sleep_on_interruptible(cqr); 5181 if (rc == 0) { 5182 *data = *host_access; 5183 } else { 5184 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, 5185 "Reading host access data failed with rc=%d\n", 5186 rc); 5187 rc = -EOPNOTSUPP; 5188 } 5189 5190 dasd_sfree_request(cqr, cqr->memdev); 5191 kfree(host_access); 5192 return rc; 5193 } 5194 /* 5195 * return number of grouped devices 5196 */ 5197 static int dasd_eckd_host_access_count(struct dasd_device *device) 5198 { 5199 struct dasd_psf_query_host_access *access; 5200 struct dasd_ckd_path_group_entry *entry; 5201 struct dasd_ckd_host_information *info; 5202 int count = 0; 5203 int rc, i; 5204 5205 access = kzalloc(sizeof(*access), GFP_NOIO); 5206 if (!access) { 5207 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", 5208 "Could not allocate access buffer"); 5209 return -ENOMEM; 5210 } 5211 rc = dasd_eckd_query_host_access(device, access); 5212 if (rc) { 5213 kfree(access); 5214 return rc; 5215 } 5216 5217 info = (struct dasd_ckd_host_information *) 5218 access->host_access_information; 5219 for (i = 0; i < info->entry_count; i++) { 5220 entry = (struct dasd_ckd_path_group_entry *) 5221 (info->entry + i * info->entry_size); 5222 if (entry->status_flags & DASD_ECKD_PG_GROUPED) 5223 count++; 5224 } 5225 5226 kfree(access); 5227 return count; 5228 } 5229 5230 /* 5231 * write host access information to a sequential file 5232 */ 5233 static int dasd_hosts_print(struct dasd_device *device, struct seq_file *m) 5234 { 5235 struct dasd_psf_query_host_access *access; 5236 struct dasd_ckd_path_group_entry *entry; 5237 struct dasd_ckd_host_information *info; 5238 char sysplex[9] = ""; 5239 int rc, i; 5240 5241 access = kzalloc(sizeof(*access), GFP_NOIO); 5242 if (!access) { 5243 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", 5244 "Could not allocate access buffer"); 5245 return -ENOMEM; 5246 } 5247 rc = dasd_eckd_query_host_access(device, access); 5248 if (rc) { 5249 kfree(access); 5250 return rc; 5251 } 5252 5253 info = (struct dasd_ckd_host_information *) 5254 access->host_access_information; 5255 for (i = 0; i < info->entry_count; i++) { 5256 entry = (struct dasd_ckd_path_group_entry *) 5257 (info->entry + i * info->entry_size); 5258 /* PGID */ 5259 seq_printf(m, "pgid %*phN\n", 11, entry->pgid); 5260 /* FLAGS */ 5261 seq_printf(m, "status_flags %02x\n", entry->status_flags); 5262 /* SYSPLEX NAME */ 5263 memcpy(&sysplex, &entry->sysplex_name, sizeof(sysplex) - 1); 5264 EBCASC(sysplex, sizeof(sysplex)); 5265 seq_printf(m, "sysplex_name %8s\n", sysplex); 5266 /* SUPPORTED CYLINDER */ 5267 seq_printf(m, "supported_cylinder %d\n", entry->cylinder); 5268 /* TIMESTAMP */ 5269 seq_printf(m, "timestamp %lu\n", (unsigned long) 5270 entry->timestamp); 5271 } 5272 kfree(access); 5273 5274 return 0; 5275 } 5276 5277 /* 5278 * Perform Subsystem Function - CUIR response 5279 */ 5280 static int 5281 dasd_eckd_psf_cuir_response(struct dasd_device *device, int response, 5282 __u32 message_id, __u8 lpum) 5283 { 5284 struct dasd_psf_cuir_response *psf_cuir; 5285 int pos = pathmask_to_pos(lpum); 5286 struct dasd_ccw_req *cqr; 5287 struct ccw1 *ccw; 5288 int rc; 5289 5290 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ , 5291 sizeof(struct dasd_psf_cuir_response), 5292 device, NULL); 5293 5294 if (IS_ERR(cqr)) { 5295 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 5296 "Could not allocate PSF-CUIR request"); 5297 return PTR_ERR(cqr); 5298 } 5299 5300 psf_cuir = (struct dasd_psf_cuir_response *)cqr->data; 5301 psf_cuir->order = PSF_ORDER_CUIR_RESPONSE; 5302 psf_cuir->cc = response; 5303 psf_cuir->chpid = device->path[pos].chpid; 5304 psf_cuir->message_id = message_id; 5305 psf_cuir->cssid = device->path[pos].cssid; 5306 psf_cuir->ssid = device->path[pos].ssid; 5307 ccw = cqr->cpaddr; 5308 ccw->cmd_code = DASD_ECKD_CCW_PSF; 5309 ccw->cda = (__u32)(addr_t)psf_cuir; 5310 ccw->flags = CCW_FLAG_SLI; 5311 ccw->count = sizeof(struct dasd_psf_cuir_response); 5312 5313 cqr->startdev = device; 5314 cqr->memdev = device; 5315 cqr->block = NULL; 5316 cqr->retries = 256; 5317 cqr->expires = 10*HZ; 5318 cqr->buildclk = get_tod_clock(); 5319 cqr->status = DASD_CQR_FILLED; 5320 set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags); 5321 5322 rc = dasd_sleep_on(cqr); 5323 5324 dasd_sfree_request(cqr, cqr->memdev); 5325 return rc; 5326 } 5327 5328 /* 5329 * return configuration data that is referenced by record selector 5330 * if a record selector is specified or per default return the 5331 * conf_data pointer for the path specified by lpum 5332 */ 5333 static struct dasd_conf_data *dasd_eckd_get_ref_conf(struct dasd_device *device, 5334 __u8 lpum, 5335 struct dasd_cuir_message *cuir) 5336 { 5337 struct dasd_conf_data *conf_data; 5338 int path, pos; 5339 5340 if (cuir->record_selector == 0) 5341 goto out; 5342 for (path = 0x80, pos = 0; path; path >>= 1, pos++) { 5343 conf_data = device->path[pos].conf_data; 5344 if (conf_data->gneq.record_selector == 5345 cuir->record_selector) 5346 return conf_data; 5347 } 5348 out: 5349 return device->path[pathmask_to_pos(lpum)].conf_data; 5350 } 5351 5352 /* 5353 * This function determines the scope of a reconfiguration request by 5354 * analysing the path and device selection data provided in the CUIR request. 5355 * Returns a path mask containing CUIR affected paths for the give device. 5356 * 5357 * If the CUIR request does not contain the required information return the 5358 * path mask of the path the attention message for the CUIR request was reveived 5359 * on. 5360 */ 5361 static int dasd_eckd_cuir_scope(struct dasd_device *device, __u8 lpum, 5362 struct dasd_cuir_message *cuir) 5363 { 5364 struct dasd_conf_data *ref_conf_data; 5365 unsigned long bitmask = 0, mask = 0; 5366 struct dasd_conf_data *conf_data; 5367 unsigned int pos, path; 5368 char *ref_gneq, *gneq; 5369 char *ref_ned, *ned; 5370 int tbcpm = 0; 5371 5372 /* if CUIR request does not specify the scope use the path 5373 the attention message was presented on */ 5374 if (!cuir->ned_map || 5375 !(cuir->neq_map[0] | cuir->neq_map[1] | cuir->neq_map[2])) 5376 return lpum; 5377 5378 /* get reference conf data */ 5379 ref_conf_data = dasd_eckd_get_ref_conf(device, lpum, cuir); 5380 /* reference ned is determined by ned_map field */ 5381 pos = 8 - ffs(cuir->ned_map); 5382 ref_ned = (char *)&ref_conf_data->neds[pos]; 5383 ref_gneq = (char *)&ref_conf_data->gneq; 5384 /* transfer 24 bit neq_map to mask */ 5385 mask = cuir->neq_map[2]; 5386 mask |= cuir->neq_map[1] << 8; 5387 mask |= cuir->neq_map[0] << 16; 5388 5389 for (path = 0; path < 8; path++) { 5390 /* initialise data per path */ 5391 bitmask = mask; 5392 conf_data = device->path[path].conf_data; 5393 pos = 8 - ffs(cuir->ned_map); 5394 ned = (char *) &conf_data->neds[pos]; 5395 /* compare reference ned and per path ned */ 5396 if (memcmp(ref_ned, ned, sizeof(*ned)) != 0) 5397 continue; 5398 gneq = (char *)&conf_data->gneq; 5399 /* compare reference gneq and per_path gneq under 5400 24 bit mask where mask bit 0 equals byte 7 of 5401 the gneq and mask bit 24 equals byte 31 */ 5402 while (bitmask) { 5403 pos = ffs(bitmask) - 1; 5404 if (memcmp(&ref_gneq[31 - pos], &gneq[31 - pos], 1) 5405 != 0) 5406 break; 5407 clear_bit(pos, &bitmask); 5408 } 5409 if (bitmask) 5410 continue; 5411 /* device and path match the reference values 5412 add path to CUIR scope */ 5413 tbcpm |= 0x80 >> path; 5414 } 5415 return tbcpm; 5416 } 5417 5418 static void dasd_eckd_cuir_notify_user(struct dasd_device *device, 5419 unsigned long paths, int action) 5420 { 5421 int pos; 5422 5423 while (paths) { 5424 /* get position of bit in mask */ 5425 pos = 8 - ffs(paths); 5426 /* get channel path descriptor from this position */ 5427 if (action == CUIR_QUIESCE) 5428 pr_warn("Service on the storage server caused path %x.%02x to go offline", 5429 device->path[pos].cssid, 5430 device->path[pos].chpid); 5431 else if (action == CUIR_RESUME) 5432 pr_info("Path %x.%02x is back online after service on the storage server", 5433 device->path[pos].cssid, 5434 device->path[pos].chpid); 5435 clear_bit(7 - pos, &paths); 5436 } 5437 } 5438 5439 static int dasd_eckd_cuir_remove_path(struct dasd_device *device, __u8 lpum, 5440 struct dasd_cuir_message *cuir) 5441 { 5442 unsigned long tbcpm; 5443 5444 tbcpm = dasd_eckd_cuir_scope(device, lpum, cuir); 5445 /* nothing to do if path is not in use */ 5446 if (!(dasd_path_get_opm(device) & tbcpm)) 5447 return 0; 5448 if (!(dasd_path_get_opm(device) & ~tbcpm)) { 5449 /* no path would be left if the CUIR action is taken 5450 return error */ 5451 return -EINVAL; 5452 } 5453 /* remove device from operational path mask */ 5454 dasd_path_remove_opm(device, tbcpm); 5455 dasd_path_add_cuirpm(device, tbcpm); 5456 return tbcpm; 5457 } 5458 5459 /* 5460 * walk through all devices and build a path mask to quiesce them 5461 * return an error if the last path to a device would be removed 5462 * 5463 * if only part of the devices are quiesced and an error 5464 * occurs no onlining necessary, the storage server will 5465 * notify the already set offline devices again 5466 */ 5467 static int dasd_eckd_cuir_quiesce(struct dasd_device *device, __u8 lpum, 5468 struct dasd_cuir_message *cuir) 5469 { 5470 struct dasd_eckd_private *private = device->private; 5471 struct alias_pav_group *pavgroup, *tempgroup; 5472 struct dasd_device *dev, *n; 5473 unsigned long paths = 0; 5474 unsigned long flags; 5475 int tbcpm; 5476 5477 /* active devices */ 5478 list_for_each_entry_safe(dev, n, &private->lcu->active_devices, 5479 alias_list) { 5480 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags); 5481 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir); 5482 spin_unlock_irqrestore(get_ccwdev_lock(dev->cdev), flags); 5483 if (tbcpm < 0) 5484 goto out_err; 5485 paths |= tbcpm; 5486 } 5487 /* inactive devices */ 5488 list_for_each_entry_safe(dev, n, &private->lcu->inactive_devices, 5489 alias_list) { 5490 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags); 5491 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir); 5492 spin_unlock_irqrestore(get_ccwdev_lock(dev->cdev), flags); 5493 if (tbcpm < 0) 5494 goto out_err; 5495 paths |= tbcpm; 5496 } 5497 /* devices in PAV groups */ 5498 list_for_each_entry_safe(pavgroup, tempgroup, 5499 &private->lcu->grouplist, group) { 5500 list_for_each_entry_safe(dev, n, &pavgroup->baselist, 5501 alias_list) { 5502 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags); 5503 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir); 5504 spin_unlock_irqrestore( 5505 get_ccwdev_lock(dev->cdev), flags); 5506 if (tbcpm < 0) 5507 goto out_err; 5508 paths |= tbcpm; 5509 } 5510 list_for_each_entry_safe(dev, n, &pavgroup->aliaslist, 5511 alias_list) { 5512 spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags); 5513 tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir); 5514 spin_unlock_irqrestore( 5515 get_ccwdev_lock(dev->cdev), flags); 5516 if (tbcpm < 0) 5517 goto out_err; 5518 paths |= tbcpm; 5519 } 5520 } 5521 /* notify user about all paths affected by CUIR action */ 5522 dasd_eckd_cuir_notify_user(device, paths, CUIR_QUIESCE); 5523 return 0; 5524 out_err: 5525 return tbcpm; 5526 } 5527 5528 static int dasd_eckd_cuir_resume(struct dasd_device *device, __u8 lpum, 5529 struct dasd_cuir_message *cuir) 5530 { 5531 struct dasd_eckd_private *private = device->private; 5532 struct alias_pav_group *pavgroup, *tempgroup; 5533 struct dasd_device *dev, *n; 5534 unsigned long paths = 0; 5535 int tbcpm; 5536 5537 /* 5538 * the path may have been added through a generic path event before 5539 * only trigger path verification if the path is not already in use 5540 */ 5541 list_for_each_entry_safe(dev, n, 5542 &private->lcu->active_devices, 5543 alias_list) { 5544 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir); 5545 paths |= tbcpm; 5546 if (!(dasd_path_get_opm(dev) & tbcpm)) { 5547 dasd_path_add_tbvpm(dev, tbcpm); 5548 dasd_schedule_device_bh(dev); 5549 } 5550 } 5551 list_for_each_entry_safe(dev, n, 5552 &private->lcu->inactive_devices, 5553 alias_list) { 5554 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir); 5555 paths |= tbcpm; 5556 if (!(dasd_path_get_opm(dev) & tbcpm)) { 5557 dasd_path_add_tbvpm(dev, tbcpm); 5558 dasd_schedule_device_bh(dev); 5559 } 5560 } 5561 /* devices in PAV groups */ 5562 list_for_each_entry_safe(pavgroup, tempgroup, 5563 &private->lcu->grouplist, 5564 group) { 5565 list_for_each_entry_safe(dev, n, 5566 &pavgroup->baselist, 5567 alias_list) { 5568 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir); 5569 paths |= tbcpm; 5570 if (!(dasd_path_get_opm(dev) & tbcpm)) { 5571 dasd_path_add_tbvpm(dev, tbcpm); 5572 dasd_schedule_device_bh(dev); 5573 } 5574 } 5575 list_for_each_entry_safe(dev, n, 5576 &pavgroup->aliaslist, 5577 alias_list) { 5578 tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir); 5579 paths |= tbcpm; 5580 if (!(dasd_path_get_opm(dev) & tbcpm)) { 5581 dasd_path_add_tbvpm(dev, tbcpm); 5582 dasd_schedule_device_bh(dev); 5583 } 5584 } 5585 } 5586 /* notify user about all paths affected by CUIR action */ 5587 dasd_eckd_cuir_notify_user(device, paths, CUIR_RESUME); 5588 return 0; 5589 } 5590 5591 static void dasd_eckd_handle_cuir(struct dasd_device *device, void *messages, 5592 __u8 lpum) 5593 { 5594 struct dasd_cuir_message *cuir = messages; 5595 int response; 5596 5597 DBF_DEV_EVENT(DBF_WARNING, device, 5598 "CUIR request: %016llx %016llx %016llx %08x", 5599 ((u64 *)cuir)[0], ((u64 *)cuir)[1], ((u64 *)cuir)[2], 5600 ((u32 *)cuir)[3]); 5601 5602 if (cuir->code == CUIR_QUIESCE) { 5603 /* quiesce */ 5604 if (dasd_eckd_cuir_quiesce(device, lpum, cuir)) 5605 response = PSF_CUIR_LAST_PATH; 5606 else 5607 response = PSF_CUIR_COMPLETED; 5608 } else if (cuir->code == CUIR_RESUME) { 5609 /* resume */ 5610 dasd_eckd_cuir_resume(device, lpum, cuir); 5611 response = PSF_CUIR_COMPLETED; 5612 } else 5613 response = PSF_CUIR_NOT_SUPPORTED; 5614 5615 dasd_eckd_psf_cuir_response(device, response, 5616 cuir->message_id, lpum); 5617 DBF_DEV_EVENT(DBF_WARNING, device, 5618 "CUIR response: %d on message ID %08x", response, 5619 cuir->message_id); 5620 /* to make sure there is no attention left schedule work again */ 5621 device->discipline->check_attention(device, lpum); 5622 } 5623 5624 static void dasd_eckd_check_attention_work(struct work_struct *work) 5625 { 5626 struct check_attention_work_data *data; 5627 struct dasd_rssd_messages *messages; 5628 struct dasd_device *device; 5629 int rc; 5630 5631 data = container_of(work, struct check_attention_work_data, worker); 5632 device = data->device; 5633 messages = kzalloc(sizeof(*messages), GFP_KERNEL); 5634 if (!messages) { 5635 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 5636 "Could not allocate attention message buffer"); 5637 goto out; 5638 } 5639 rc = dasd_eckd_read_message_buffer(device, messages, data->lpum); 5640 if (rc) 5641 goto out; 5642 if (messages->length == ATTENTION_LENGTH_CUIR && 5643 messages->format == ATTENTION_FORMAT_CUIR) 5644 dasd_eckd_handle_cuir(device, messages, data->lpum); 5645 out: 5646 dasd_put_device(device); 5647 kfree(messages); 5648 kfree(data); 5649 } 5650 5651 static int dasd_eckd_check_attention(struct dasd_device *device, __u8 lpum) 5652 { 5653 struct check_attention_work_data *data; 5654 5655 data = kzalloc(sizeof(*data), GFP_ATOMIC); 5656 if (!data) 5657 return -ENOMEM; 5658 INIT_WORK(&data->worker, dasd_eckd_check_attention_work); 5659 dasd_get_device(device); 5660 data->device = device; 5661 data->lpum = lpum; 5662 schedule_work(&data->worker); 5663 return 0; 5664 } 5665 5666 static int dasd_eckd_disable_hpf_path(struct dasd_device *device, __u8 lpum) 5667 { 5668 if (~lpum & dasd_path_get_opm(device)) { 5669 dasd_path_add_nohpfpm(device, lpum); 5670 dasd_path_remove_opm(device, lpum); 5671 dev_err(&device->cdev->dev, 5672 "Channel path %02X lost HPF functionality and is disabled\n", 5673 lpum); 5674 return 1; 5675 } 5676 return 0; 5677 } 5678 5679 static void dasd_eckd_disable_hpf_device(struct dasd_device *device) 5680 { 5681 struct dasd_eckd_private *private = device->private; 5682 5683 dev_err(&device->cdev->dev, 5684 "High Performance FICON disabled\n"); 5685 private->fcx_max_data = 0; 5686 } 5687 5688 static int dasd_eckd_hpf_enabled(struct dasd_device *device) 5689 { 5690 struct dasd_eckd_private *private = device->private; 5691 5692 return private->fcx_max_data ? 1 : 0; 5693 } 5694 5695 static void dasd_eckd_handle_hpf_error(struct dasd_device *device, 5696 struct irb *irb) 5697 { 5698 struct dasd_eckd_private *private = device->private; 5699 5700 if (!private->fcx_max_data) { 5701 /* sanity check for no HPF, the error makes no sense */ 5702 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 5703 "Trying to disable HPF for a non HPF device"); 5704 return; 5705 } 5706 if (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX) { 5707 dasd_eckd_disable_hpf_device(device); 5708 } else if (irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX) { 5709 if (dasd_eckd_disable_hpf_path(device, irb->esw.esw1.lpum)) 5710 return; 5711 dasd_eckd_disable_hpf_device(device); 5712 dasd_path_set_tbvpm(device, 5713 dasd_path_get_hpfpm(device)); 5714 } 5715 /* 5716 * prevent that any new I/O ist started on the device and schedule a 5717 * requeue of existing requests 5718 */ 5719 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC); 5720 dasd_schedule_requeue(device); 5721 } 5722 5723 static struct ccw_driver dasd_eckd_driver = { 5724 .driver = { 5725 .name = "dasd-eckd", 5726 .owner = THIS_MODULE, 5727 }, 5728 .ids = dasd_eckd_ids, 5729 .probe = dasd_eckd_probe, 5730 .remove = dasd_generic_remove, 5731 .set_offline = dasd_generic_set_offline, 5732 .set_online = dasd_eckd_set_online, 5733 .notify = dasd_generic_notify, 5734 .path_event = dasd_generic_path_event, 5735 .shutdown = dasd_generic_shutdown, 5736 .freeze = dasd_generic_pm_freeze, 5737 .thaw = dasd_generic_restore_device, 5738 .restore = dasd_generic_restore_device, 5739 .uc_handler = dasd_generic_uc_handler, 5740 .int_class = IRQIO_DAS, 5741 }; 5742 5743 /* 5744 * max_blocks is dependent on the amount of storage that is available 5745 * in the static io buffer for each device. Currently each device has 5746 * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has 5747 * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use 5748 * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In 5749 * addition we have one define extent ccw + 16 bytes of data and one 5750 * locate record ccw + 16 bytes of data. That makes: 5751 * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum. 5752 * We want to fit two into the available memory so that we can immediately 5753 * start the next request if one finishes off. That makes 249.5 blocks 5754 * for one request. Give a little safety and the result is 240. 5755 */ 5756 static struct dasd_discipline dasd_eckd_discipline = { 5757 .owner = THIS_MODULE, 5758 .name = "ECKD", 5759 .ebcname = "ECKD", 5760 .max_blocks = 190, 5761 .check_device = dasd_eckd_check_characteristics, 5762 .uncheck_device = dasd_eckd_uncheck_device, 5763 .do_analysis = dasd_eckd_do_analysis, 5764 .verify_path = dasd_eckd_verify_path, 5765 .basic_to_ready = dasd_eckd_basic_to_ready, 5766 .online_to_ready = dasd_eckd_online_to_ready, 5767 .basic_to_known = dasd_eckd_basic_to_known, 5768 .fill_geometry = dasd_eckd_fill_geometry, 5769 .start_IO = dasd_start_IO, 5770 .term_IO = dasd_term_IO, 5771 .handle_terminated_request = dasd_eckd_handle_terminated_request, 5772 .format_device = dasd_eckd_format_device, 5773 .check_device_format = dasd_eckd_check_device_format, 5774 .erp_action = dasd_eckd_erp_action, 5775 .erp_postaction = dasd_eckd_erp_postaction, 5776 .check_for_device_change = dasd_eckd_check_for_device_change, 5777 .build_cp = dasd_eckd_build_alias_cp, 5778 .free_cp = dasd_eckd_free_alias_cp, 5779 .dump_sense = dasd_eckd_dump_sense, 5780 .dump_sense_dbf = dasd_eckd_dump_sense_dbf, 5781 .fill_info = dasd_eckd_fill_info, 5782 .ioctl = dasd_eckd_ioctl, 5783 .freeze = dasd_eckd_pm_freeze, 5784 .restore = dasd_eckd_restore_device, 5785 .reload = dasd_eckd_reload_device, 5786 .get_uid = dasd_eckd_get_uid, 5787 .kick_validate = dasd_eckd_kick_validate_server, 5788 .check_attention = dasd_eckd_check_attention, 5789 .host_access_count = dasd_eckd_host_access_count, 5790 .hosts_print = dasd_hosts_print, 5791 .handle_hpf_error = dasd_eckd_handle_hpf_error, 5792 .disable_hpf = dasd_eckd_disable_hpf_device, 5793 .hpf_enabled = dasd_eckd_hpf_enabled, 5794 .reset_path = dasd_eckd_reset_path, 5795 }; 5796 5797 static int __init 5798 dasd_eckd_init(void) 5799 { 5800 int ret; 5801 5802 ASCEBC(dasd_eckd_discipline.ebcname, 4); 5803 dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req), 5804 GFP_KERNEL | GFP_DMA); 5805 if (!dasd_reserve_req) 5806 return -ENOMEM; 5807 path_verification_worker = kmalloc(sizeof(*path_verification_worker), 5808 GFP_KERNEL | GFP_DMA); 5809 if (!path_verification_worker) { 5810 kfree(dasd_reserve_req); 5811 return -ENOMEM; 5812 } 5813 rawpadpage = (void *)__get_free_page(GFP_KERNEL); 5814 if (!rawpadpage) { 5815 kfree(path_verification_worker); 5816 kfree(dasd_reserve_req); 5817 return -ENOMEM; 5818 } 5819 ret = ccw_driver_register(&dasd_eckd_driver); 5820 if (!ret) 5821 wait_for_device_probe(); 5822 else { 5823 kfree(path_verification_worker); 5824 kfree(dasd_reserve_req); 5825 free_page((unsigned long)rawpadpage); 5826 } 5827 return ret; 5828 } 5829 5830 static void __exit 5831 dasd_eckd_cleanup(void) 5832 { 5833 ccw_driver_unregister(&dasd_eckd_driver); 5834 kfree(path_verification_worker); 5835 kfree(dasd_reserve_req); 5836 free_page((unsigned long)rawpadpage); 5837 } 5838 5839 module_init(dasd_eckd_init); 5840 module_exit(dasd_eckd_cleanup); 5841