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