| 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,2001 |
| 9 | * |
| 10 | * Device mapping and dasd= parameter parsing functions. All devmap |
| 11 | * functions may not be called from interrupt context. In particular |
| 12 | * dasd_get_device is a no-no from interrupt context. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/ctype.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/slab.h> |
| 20 | |
| 21 | #include <asm/machine.h> |
| 22 | #include <asm/debug.h> |
| 23 | #include <linux/uaccess.h> |
| 24 | #include <asm/ipl.h> |
| 25 | |
| 26 | #define DASD_MAX_PARAMS 256 |
| 27 | |
| 28 | #include "dasd_int.h" |
| 29 | |
| 30 | struct kmem_cache *dasd_page_cache; |
| 31 | EXPORT_SYMBOL_GPL(dasd_page_cache); |
| 32 | |
| 33 | /* |
| 34 | * dasd_devmap_t is used to store the features and the relation |
| 35 | * between device number and device index. To find a dasd_devmap_t |
| 36 | * that corresponds to a device number of a device index each |
| 37 | * dasd_devmap_t is added to two linked lists, one to search by |
| 38 | * the device number and one to search by the device index. As |
| 39 | * soon as big minor numbers are available the device index list |
| 40 | * can be removed since the device number will then be identical |
| 41 | * to the device index. |
| 42 | */ |
| 43 | struct dasd_devmap { |
| 44 | struct list_head list; |
| 45 | char bus_id[DASD_BUS_ID_SIZE]; |
| 46 | unsigned int devindex; |
| 47 | unsigned short features; |
| 48 | struct dasd_device *device; |
| 49 | struct dasd_copy_relation *copy; |
| 50 | unsigned int aq_mask; |
| 51 | }; |
| 52 | |
| 53 | /* |
| 54 | * Parameter parsing functions for dasd= parameter. The syntax is: |
| 55 | * <devno> : (0x)?[0-9a-fA-F]+ |
| 56 | * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+ |
| 57 | * <feature> : ro |
| 58 | * <feature_list> : \(<feature>(:<feature>)*\) |
| 59 | * <devno-range> : <devno>(-<devno>)?<feature_list>? |
| 60 | * <busid-range> : <busid>(-<busid>)?<feature_list>? |
| 61 | * <devices> : <devno-range>|<busid-range> |
| 62 | * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod |
| 63 | * |
| 64 | * <dasd> : autodetect|probeonly|<devices>(,<devices>)* |
| 65 | */ |
| 66 | |
| 67 | int dasd_probeonly = 0; /* is true, when probeonly mode is active */ |
| 68 | int dasd_autodetect = 0; /* is true, when autodetection is active */ |
| 69 | int dasd_nopav = 0; /* is true, when PAV is disabled */ |
| 70 | EXPORT_SYMBOL_GPL(dasd_nopav); |
| 71 | int dasd_nofcx; /* disable High Performance Ficon */ |
| 72 | EXPORT_SYMBOL_GPL(dasd_nofcx); |
| 73 | |
| 74 | /* |
| 75 | * char *dasd[] is intended to hold the ranges supplied by the dasd= statement |
| 76 | * it is named 'dasd' to directly be filled by insmod with the comma separated |
| 77 | * strings when running as a module. |
| 78 | */ |
| 79 | static char *dasd[DASD_MAX_PARAMS]; |
| 80 | module_param_array(dasd, charp, NULL, S_IRUGO); |
| 81 | |
| 82 | /* |
| 83 | * Single spinlock to protect devmap and servermap structures and lists. |
| 84 | */ |
| 85 | static DEFINE_SPINLOCK(dasd_devmap_lock); |
| 86 | |
| 87 | /* |
| 88 | * Hash lists for devmap structures. |
| 89 | */ |
| 90 | static struct list_head dasd_hashlists[256]; |
| 91 | int dasd_max_devindex; |
| 92 | |
| 93 | static struct dasd_devmap *dasd_add_busid(const char *, int); |
| 94 | |
| 95 | static inline int |
| 96 | dasd_hash_busid(const char *bus_id) |
| 97 | { |
| 98 | int hash, i; |
| 99 | |
| 100 | hash = 0; |
| 101 | for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++) |
| 102 | hash += *bus_id; |
| 103 | return hash & 0xff; |
| 104 | } |
| 105 | |
| 106 | #ifndef MODULE |
| 107 | static int __init dasd_call_setup(char *opt) |
| 108 | { |
| 109 | static int i __initdata; |
| 110 | char *tmp; |
| 111 | |
| 112 | while (i < DASD_MAX_PARAMS) { |
| 113 | tmp = strsep(&opt, ","); |
| 114 | if (!tmp) |
| 115 | break; |
| 116 | |
| 117 | dasd[i++] = tmp; |
| 118 | } |
| 119 | |
| 120 | return 1; |
| 121 | } |
| 122 | |
| 123 | __setup ("dasd=", dasd_call_setup); |
| 124 | #endif /* #ifndef MODULE */ |
| 125 | |
| 126 | #define DASD_IPLDEV "ipldev" |
| 127 | |
| 128 | /* |
| 129 | * Read a device busid/devno from a string. |
| 130 | */ |
| 131 | static int dasd_busid(char *str, int *id0, int *id1, int *devno) |
| 132 | { |
| 133 | unsigned int val; |
| 134 | char *tok; |
| 135 | |
| 136 | /* Interpret ipldev busid */ |
| 137 | if (strncmp(DASD_IPLDEV, str, strlen(DASD_IPLDEV)) == 0) { |
| 138 | if (ipl_info.type != IPL_TYPE_CCW) { |
| 139 | pr_err("The IPL device is not a CCW device\n"); |
| 140 | return -EINVAL; |
| 141 | } |
| 142 | *id0 = 0; |
| 143 | *id1 = ipl_info.data.ccw.dev_id.ssid; |
| 144 | *devno = ipl_info.data.ccw.dev_id.devno; |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | /* Old style 0xXXXX or XXXX */ |
| 150 | if (!kstrtouint(str, 16, &val)) { |
| 151 | *id0 = *id1 = 0; |
| 152 | if (val > 0xffff) |
| 153 | return -EINVAL; |
| 154 | *devno = val; |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | /* New style x.y.z busid */ |
| 159 | tok = strsep(&str, "."); |
| 160 | if (kstrtouint(tok, 16, &val) || val > 0xff) |
| 161 | return -EINVAL; |
| 162 | *id0 = val; |
| 163 | |
| 164 | tok = strsep(&str, "."); |
| 165 | if (kstrtouint(tok, 16, &val) || val > 0xff) |
| 166 | return -EINVAL; |
| 167 | *id1 = val; |
| 168 | |
| 169 | tok = strsep(&str, "."); |
| 170 | if (kstrtouint(tok, 16, &val) || val > 0xffff) |
| 171 | return -EINVAL; |
| 172 | *devno = val; |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * Read colon separated list of dasd features. |
| 179 | */ |
| 180 | static int __init dasd_feature_list(char *str) |
| 181 | { |
| 182 | int features, len, rc; |
| 183 | |
| 184 | features = 0; |
| 185 | rc = 0; |
| 186 | |
| 187 | if (!str) |
| 188 | return DASD_FEATURE_DEFAULT; |
| 189 | |
| 190 | while (1) { |
| 191 | for (len = 0; |
| 192 | str[len] && str[len] != ':' && str[len] != ')'; len++); |
| 193 | if (len == 2 && !strncmp(str, "ro", 2)) |
| 194 | features |= DASD_FEATURE_READONLY; |
| 195 | else if (len == 4 && !strncmp(str, "diag", 4)) |
| 196 | features |= DASD_FEATURE_USEDIAG; |
| 197 | else if (len == 3 && !strncmp(str, "raw", 3)) |
| 198 | features |= DASD_FEATURE_USERAW; |
| 199 | else if (len == 6 && !strncmp(str, "erplog", 6)) |
| 200 | features |= DASD_FEATURE_ERPLOG; |
| 201 | else if (len == 8 && !strncmp(str, "failfast", 8)) |
| 202 | features |= DASD_FEATURE_FAILFAST; |
| 203 | else { |
| 204 | pr_warn("%.*s is not a supported device option\n", |
| 205 | len, str); |
| 206 | rc = -EINVAL; |
| 207 | } |
| 208 | str += len; |
| 209 | if (*str != ':') |
| 210 | break; |
| 211 | str++; |
| 212 | } |
| 213 | |
| 214 | return rc ? : features; |
| 215 | } |
| 216 | |
| 217 | /* |
| 218 | * Try to match the first element on the comma separated parse string |
| 219 | * with one of the known keywords. If a keyword is found, take the approprate |
| 220 | * action and return a pointer to the residual string. If the first element |
| 221 | * could not be matched to any keyword then return an error code. |
| 222 | */ |
| 223 | static int __init dasd_parse_keyword(char *keyword) |
| 224 | { |
| 225 | int length = strlen(keyword); |
| 226 | |
| 227 | if (strncmp("autodetect", keyword, length) == 0) { |
| 228 | dasd_autodetect = 1; |
| 229 | pr_info("The autodetection mode has been activated\n"); |
| 230 | return 0; |
| 231 | } |
| 232 | if (strncmp("probeonly", keyword, length) == 0) { |
| 233 | dasd_probeonly = 1; |
| 234 | pr_info("The probeonly mode has been activated\n"); |
| 235 | return 0; |
| 236 | } |
| 237 | if (strncmp("nopav", keyword, length) == 0) { |
| 238 | if (machine_is_vm()) |
| 239 | pr_info("'nopav' is not supported on z/VM\n"); |
| 240 | else { |
| 241 | dasd_nopav = 1; |
| 242 | pr_info("PAV support has be deactivated\n"); |
| 243 | } |
| 244 | return 0; |
| 245 | } |
| 246 | if (strncmp("nofcx", keyword, length) == 0) { |
| 247 | dasd_nofcx = 1; |
| 248 | pr_info("High Performance FICON support has been " |
| 249 | "deactivated\n"); |
| 250 | return 0; |
| 251 | } |
| 252 | if (strncmp("fixedbuffers", keyword, length) == 0) { |
| 253 | if (dasd_page_cache) |
| 254 | return 0; |
| 255 | dasd_page_cache = |
| 256 | kmem_cache_create("dasd_page_cache", PAGE_SIZE, |
| 257 | PAGE_SIZE, SLAB_CACHE_DMA, |
| 258 | NULL); |
| 259 | if (!dasd_page_cache) |
| 260 | DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, " |
| 261 | "fixed buffer mode disabled."); |
| 262 | else |
| 263 | DBF_EVENT(DBF_INFO, "%s", |
| 264 | "turning on fixed buffer mode"); |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * Split a string of a device range into its pieces and return the from, to, and |
| 273 | * feature parts separately. |
| 274 | * e.g.: |
| 275 | * 0.0.1234-0.0.5678(ro:erplog) -> from: 0.0.1234 to: 0.0.5678 features: ro:erplog |
| 276 | * 0.0.8765(raw) -> from: 0.0.8765 to: null features: raw |
| 277 | * 0x4321 -> from: 0x4321 to: null features: null |
| 278 | */ |
| 279 | static int __init dasd_evaluate_range_param(char *range, char **from_str, |
| 280 | char **to_str, char **features_str) |
| 281 | { |
| 282 | int rc = 0; |
| 283 | |
| 284 | /* Do we have a range or a single device? */ |
| 285 | if (strchr(range, '-')) { |
| 286 | *from_str = strsep(&range, "-"); |
| 287 | *to_str = strsep(&range, "("); |
| 288 | *features_str = strsep(&range, ")"); |
| 289 | } else { |
| 290 | *from_str = strsep(&range, "("); |
| 291 | *features_str = strsep(&range, ")"); |
| 292 | } |
| 293 | |
| 294 | if (*features_str && !range) { |
| 295 | pr_warn("A closing parenthesis ')' is missing in the dasd= parameter\n"); |
| 296 | rc = -EINVAL; |
| 297 | } |
| 298 | |
| 299 | return rc; |
| 300 | } |
| 301 | |
| 302 | /* |
| 303 | * Try to interprete the range string as a device number or a range of devices. |
| 304 | * If the interpretation is successful, create the matching dasd_devmap entries. |
| 305 | * If interpretation fails or in case of an error, return an error code. |
| 306 | */ |
| 307 | static int __init dasd_parse_range(const char *range) |
| 308 | { |
| 309 | struct dasd_devmap *devmap; |
| 310 | int from, from_id0, from_id1; |
| 311 | int to, to_id0, to_id1; |
| 312 | int features; |
| 313 | char bus_id[DASD_BUS_ID_SIZE + 1]; |
| 314 | char *features_str = NULL; |
| 315 | char *from_str = NULL; |
| 316 | char *to_str = NULL; |
| 317 | int rc = 0; |
| 318 | char *tmp; |
| 319 | |
| 320 | tmp = kstrdup(range, GFP_KERNEL); |
| 321 | if (!tmp) |
| 322 | return -ENOMEM; |
| 323 | |
| 324 | if (dasd_evaluate_range_param(tmp, &from_str, &to_str, &features_str)) { |
| 325 | rc = -EINVAL; |
| 326 | goto out; |
| 327 | } |
| 328 | |
| 329 | if (dasd_busid(from_str, &from_id0, &from_id1, &from)) { |
| 330 | rc = -EINVAL; |
| 331 | goto out; |
| 332 | } |
| 333 | |
| 334 | to = from; |
| 335 | to_id0 = from_id0; |
| 336 | to_id1 = from_id1; |
| 337 | if (to_str) { |
| 338 | if (dasd_busid(to_str, &to_id0, &to_id1, &to)) { |
| 339 | rc = -EINVAL; |
| 340 | goto out; |
| 341 | } |
| 342 | if (from_id0 != to_id0 || from_id1 != to_id1 || from > to) { |
| 343 | pr_err("%s is not a valid device range\n", range); |
| 344 | rc = -EINVAL; |
| 345 | goto out; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | features = dasd_feature_list(features_str); |
| 350 | if (features < 0) { |
| 351 | rc = -EINVAL; |
| 352 | goto out; |
| 353 | } |
| 354 | /* each device in dasd= parameter should be set initially online */ |
| 355 | features |= DASD_FEATURE_INITIAL_ONLINE; |
| 356 | while (from <= to) { |
| 357 | sprintf(bus_id, "%01x.%01x.%04x", from_id0, from_id1, from++); |
| 358 | devmap = dasd_add_busid(bus_id, features); |
| 359 | if (IS_ERR(devmap)) { |
| 360 | rc = PTR_ERR(devmap); |
| 361 | goto out; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | out: |
| 366 | kfree(tmp); |
| 367 | |
| 368 | return rc; |
| 369 | } |
| 370 | |
| 371 | /* |
| 372 | * Parse parameters stored in dasd[] |
| 373 | * The 'dasd=...' parameter allows to specify a comma separated list of |
| 374 | * keywords and device ranges. The parameters in that list will be stored as |
| 375 | * separate elementes in dasd[]. |
| 376 | */ |
| 377 | int __init dasd_parse(void) |
| 378 | { |
| 379 | int rc, i; |
| 380 | char *cur; |
| 381 | |
| 382 | rc = 0; |
| 383 | for (i = 0; i < DASD_MAX_PARAMS; i++) { |
| 384 | cur = dasd[i]; |
| 385 | if (!cur) |
| 386 | break; |
| 387 | if (*cur == '\0') |
| 388 | continue; |
| 389 | |
| 390 | rc = dasd_parse_keyword(cur); |
| 391 | if (rc) |
| 392 | rc = dasd_parse_range(cur); |
| 393 | |
| 394 | if (rc) |
| 395 | break; |
| 396 | } |
| 397 | |
| 398 | return rc; |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * Add a devmap for the device specified by busid. It is possible that |
| 403 | * the devmap already exists (dasd= parameter). The order of the devices |
| 404 | * added through this function will define the kdevs for the individual |
| 405 | * devices. |
| 406 | */ |
| 407 | static struct dasd_devmap * |
| 408 | dasd_add_busid(const char *bus_id, int features) |
| 409 | { |
| 410 | struct dasd_devmap *devmap, *new, *tmp; |
| 411 | int hash; |
| 412 | |
| 413 | new = kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL); |
| 414 | if (!new) |
| 415 | return ERR_PTR(-ENOMEM); |
| 416 | spin_lock(&dasd_devmap_lock); |
| 417 | devmap = NULL; |
| 418 | hash = dasd_hash_busid(bus_id); |
| 419 | list_for_each_entry(tmp, &dasd_hashlists[hash], list) |
| 420 | if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) { |
| 421 | devmap = tmp; |
| 422 | break; |
| 423 | } |
| 424 | if (!devmap) { |
| 425 | /* This bus_id is new. */ |
| 426 | new->devindex = dasd_max_devindex++; |
| 427 | strscpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE); |
| 428 | new->features = features; |
| 429 | new->device = NULL; |
| 430 | list_add(&new->list, &dasd_hashlists[hash]); |
| 431 | devmap = new; |
| 432 | new = NULL; |
| 433 | } |
| 434 | spin_unlock(&dasd_devmap_lock); |
| 435 | kfree(new); |
| 436 | return devmap; |
| 437 | } |
| 438 | |
| 439 | static struct dasd_devmap * |
| 440 | dasd_find_busid_locked(const char *bus_id) |
| 441 | { |
| 442 | struct dasd_devmap *devmap, *tmp; |
| 443 | int hash; |
| 444 | |
| 445 | devmap = ERR_PTR(-ENODEV); |
| 446 | hash = dasd_hash_busid(bus_id); |
| 447 | list_for_each_entry(tmp, &dasd_hashlists[hash], list) { |
| 448 | if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) { |
| 449 | devmap = tmp; |
| 450 | break; |
| 451 | } |
| 452 | } |
| 453 | return devmap; |
| 454 | } |
| 455 | |
| 456 | /* |
| 457 | * Find devmap for device with given bus_id. |
| 458 | */ |
| 459 | static struct dasd_devmap * |
| 460 | dasd_find_busid(const char *bus_id) |
| 461 | { |
| 462 | struct dasd_devmap *devmap; |
| 463 | |
| 464 | spin_lock(&dasd_devmap_lock); |
| 465 | devmap = dasd_find_busid_locked(bus_id); |
| 466 | spin_unlock(&dasd_devmap_lock); |
| 467 | return devmap; |
| 468 | } |
| 469 | |
| 470 | /* |
| 471 | * Check if busid has been added to the list of dasd ranges. |
| 472 | */ |
| 473 | int |
| 474 | dasd_busid_known(const char *bus_id) |
| 475 | { |
| 476 | return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0; |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * Forget all about the device numbers added so far. |
| 481 | * This may only be called at module unload or system shutdown. |
| 482 | */ |
| 483 | static void |
| 484 | dasd_forget_ranges(void) |
| 485 | { |
| 486 | struct dasd_devmap *devmap, *n; |
| 487 | int i; |
| 488 | |
| 489 | spin_lock(&dasd_devmap_lock); |
| 490 | for (i = 0; i < 256; i++) { |
| 491 | list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) { |
| 492 | BUG_ON(devmap->device != NULL); |
| 493 | list_del(&devmap->list); |
| 494 | kfree(devmap); |
| 495 | } |
| 496 | } |
| 497 | spin_unlock(&dasd_devmap_lock); |
| 498 | } |
| 499 | |
| 500 | /* |
| 501 | * Find the device struct by its device index. |
| 502 | */ |
| 503 | struct dasd_device * |
| 504 | dasd_device_from_devindex(int devindex) |
| 505 | { |
| 506 | struct dasd_devmap *devmap, *tmp; |
| 507 | struct dasd_device *device; |
| 508 | int i; |
| 509 | |
| 510 | spin_lock(&dasd_devmap_lock); |
| 511 | devmap = NULL; |
| 512 | for (i = 0; (i < 256) && !devmap; i++) |
| 513 | list_for_each_entry(tmp, &dasd_hashlists[i], list) |
| 514 | if (tmp->devindex == devindex) { |
| 515 | /* Found the devmap for the device. */ |
| 516 | devmap = tmp; |
| 517 | break; |
| 518 | } |
| 519 | if (devmap && devmap->device) { |
| 520 | device = devmap->device; |
| 521 | dasd_get_device(device); |
| 522 | } else |
| 523 | device = ERR_PTR(-ENODEV); |
| 524 | spin_unlock(&dasd_devmap_lock); |
| 525 | return device; |
| 526 | } |
| 527 | |
| 528 | /* |
| 529 | * Return devmap for cdev. If no devmap exists yet, create one and |
| 530 | * connect it to the cdev. |
| 531 | */ |
| 532 | static struct dasd_devmap * |
| 533 | dasd_devmap_from_cdev(struct ccw_device *cdev) |
| 534 | { |
| 535 | struct dasd_devmap *devmap; |
| 536 | |
| 537 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
| 538 | if (IS_ERR(devmap)) |
| 539 | devmap = dasd_add_busid(dev_name(&cdev->dev), |
| 540 | DASD_FEATURE_DEFAULT); |
| 541 | return devmap; |
| 542 | } |
| 543 | |
| 544 | /* |
| 545 | * Create a dasd device structure for cdev. |
| 546 | */ |
| 547 | struct dasd_device * |
| 548 | dasd_create_device(struct ccw_device *cdev) |
| 549 | { |
| 550 | struct dasd_devmap *devmap; |
| 551 | struct dasd_device *device; |
| 552 | unsigned long flags; |
| 553 | int rc; |
| 554 | |
| 555 | devmap = dasd_devmap_from_cdev(cdev); |
| 556 | if (IS_ERR(devmap)) |
| 557 | return (void *) devmap; |
| 558 | |
| 559 | device = dasd_alloc_device(); |
| 560 | if (IS_ERR(device)) |
| 561 | return device; |
| 562 | atomic_set(&device->ref_count, 3); |
| 563 | |
| 564 | spin_lock(&dasd_devmap_lock); |
| 565 | if (!devmap->device) { |
| 566 | devmap->device = device; |
| 567 | device->devindex = devmap->devindex; |
| 568 | device->features = devmap->features; |
| 569 | get_device(&cdev->dev); |
| 570 | device->cdev = cdev; |
| 571 | rc = 0; |
| 572 | } else |
| 573 | /* Someone else was faster. */ |
| 574 | rc = -EBUSY; |
| 575 | spin_unlock(&dasd_devmap_lock); |
| 576 | |
| 577 | if (rc) { |
| 578 | dasd_free_device(device); |
| 579 | return ERR_PTR(rc); |
| 580 | } |
| 581 | |
| 582 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
| 583 | dev_set_drvdata(&cdev->dev, device); |
| 584 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 585 | |
| 586 | device->paths_info = kset_create_and_add("paths_info", NULL, |
| 587 | &device->cdev->dev.kobj); |
| 588 | if (!device->paths_info) |
| 589 | dev_warn(&cdev->dev, "Could not create paths_info kset\n"); |
| 590 | |
| 591 | return device; |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * allocate a PPRC data structure and call the discipline function to fill |
| 596 | */ |
| 597 | static int dasd_devmap_get_pprc_status(struct dasd_device *device, |
| 598 | struct dasd_pprc_data_sc4 **data) |
| 599 | { |
| 600 | struct dasd_pprc_data_sc4 *temp; |
| 601 | |
| 602 | if (!device->discipline || !device->discipline->pprc_status) { |
| 603 | dev_warn(&device->cdev->dev, "Unable to query copy relation status\n"); |
| 604 | return -EOPNOTSUPP; |
| 605 | } |
| 606 | temp = kzalloc(sizeof(*temp), GFP_KERNEL); |
| 607 | if (!temp) |
| 608 | return -ENOMEM; |
| 609 | |
| 610 | /* get PPRC information from storage */ |
| 611 | if (device->discipline->pprc_status(device, temp)) { |
| 612 | dev_warn(&device->cdev->dev, "Error during copy relation status query\n"); |
| 613 | kfree(temp); |
| 614 | return -EINVAL; |
| 615 | } |
| 616 | *data = temp; |
| 617 | |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | /* |
| 622 | * find an entry in a PPRC device_info array by a given UID |
| 623 | * depending on the primary/secondary state of the device it has to be |
| 624 | * matched with the respective fields |
| 625 | */ |
| 626 | static int dasd_devmap_entry_from_pprc_data(struct dasd_pprc_data_sc4 *data, |
| 627 | struct dasd_uid uid, |
| 628 | bool primary) |
| 629 | { |
| 630 | int i; |
| 631 | |
| 632 | for (i = 0; i < DASD_CP_ENTRIES; i++) { |
| 633 | if (primary) { |
| 634 | if (data->dev_info[i].prim_cu_ssid == uid.ssid && |
| 635 | data->dev_info[i].primary == uid.real_unit_addr) |
| 636 | return i; |
| 637 | } else { |
| 638 | if (data->dev_info[i].sec_cu_ssid == uid.ssid && |
| 639 | data->dev_info[i].secondary == uid.real_unit_addr) |
| 640 | return i; |
| 641 | } |
| 642 | } |
| 643 | return -1; |
| 644 | } |
| 645 | |
| 646 | /* |
| 647 | * check the consistency of a specified copy relation by checking |
| 648 | * the following things: |
| 649 | * |
| 650 | * - is the given device part of a copy pair setup |
| 651 | * - does the state of the device match the state in the PPRC status data |
| 652 | * - does the device UID match with the UID in the PPRC status data |
| 653 | * - to prevent misrouted IO check if the given device is present in all |
| 654 | * related PPRC status data |
| 655 | */ |
| 656 | static int dasd_devmap_check_copy_relation(struct dasd_device *device, |
| 657 | struct dasd_copy_entry *entry, |
| 658 | struct dasd_pprc_data_sc4 *data, |
| 659 | struct dasd_copy_relation *copy) |
| 660 | { |
| 661 | struct dasd_pprc_data_sc4 *tmp_dat; |
| 662 | struct dasd_device *tmp_dev; |
| 663 | struct dasd_uid uid; |
| 664 | int i, j; |
| 665 | |
| 666 | if (!device->discipline || !device->discipline->get_uid || |
| 667 | device->discipline->get_uid(device, &uid)) |
| 668 | return 1; |
| 669 | |
| 670 | i = dasd_devmap_entry_from_pprc_data(data, uid, entry->primary); |
| 671 | if (i < 0) { |
| 672 | dev_warn(&device->cdev->dev, "Device not part of a copy relation\n"); |
| 673 | return 1; |
| 674 | } |
| 675 | |
| 676 | /* double check which role the current device has */ |
| 677 | if (entry->primary) { |
| 678 | if (data->dev_info[i].flags & 0x80) { |
| 679 | dev_warn(&device->cdev->dev, "Copy pair secondary is setup as primary\n"); |
| 680 | return 1; |
| 681 | } |
| 682 | if (data->dev_info[i].prim_cu_ssid != uid.ssid || |
| 683 | data->dev_info[i].primary != uid.real_unit_addr) { |
| 684 | dev_warn(&device->cdev->dev, |
| 685 | "Primary device %s does not match copy pair status primary device %04x\n", |
| 686 | dev_name(&device->cdev->dev), |
| 687 | data->dev_info[i].prim_cu_ssid | |
| 688 | data->dev_info[i].primary); |
| 689 | return 1; |
| 690 | } |
| 691 | } else { |
| 692 | if (!(data->dev_info[i].flags & 0x80)) { |
| 693 | dev_warn(&device->cdev->dev, "Copy pair primary is setup as secondary\n"); |
| 694 | return 1; |
| 695 | } |
| 696 | if (data->dev_info[i].sec_cu_ssid != uid.ssid || |
| 697 | data->dev_info[i].secondary != uid.real_unit_addr) { |
| 698 | dev_warn(&device->cdev->dev, |
| 699 | "Secondary device %s does not match copy pair status secondary device %04x\n", |
| 700 | dev_name(&device->cdev->dev), |
| 701 | data->dev_info[i].sec_cu_ssid | |
| 702 | data->dev_info[i].secondary); |
| 703 | return 1; |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | /* |
| 708 | * the current device has to be part of the copy relation of all |
| 709 | * entries to prevent misrouted IO to another copy pair |
| 710 | */ |
| 711 | for (j = 0; j < DASD_CP_ENTRIES; j++) { |
| 712 | if (entry == ©->entry[j]) |
| 713 | tmp_dev = device; |
| 714 | else |
| 715 | tmp_dev = copy->entry[j].device; |
| 716 | |
| 717 | if (!tmp_dev) |
| 718 | continue; |
| 719 | |
| 720 | if (dasd_devmap_get_pprc_status(tmp_dev, &tmp_dat)) |
| 721 | return 1; |
| 722 | |
| 723 | if (dasd_devmap_entry_from_pprc_data(tmp_dat, uid, entry->primary) < 0) { |
| 724 | dev_warn(&tmp_dev->cdev->dev, |
| 725 | "Copy pair relation does not contain device: %s\n", |
| 726 | dev_name(&device->cdev->dev)); |
| 727 | kfree(tmp_dat); |
| 728 | return 1; |
| 729 | } |
| 730 | kfree(tmp_dat); |
| 731 | } |
| 732 | return 0; |
| 733 | } |
| 734 | |
| 735 | /* delete device from copy relation entry */ |
| 736 | static void dasd_devmap_delete_copy_relation_device(struct dasd_device *device) |
| 737 | { |
| 738 | struct dasd_copy_relation *copy; |
| 739 | int i; |
| 740 | |
| 741 | if (!device->copy) |
| 742 | return; |
| 743 | |
| 744 | copy = device->copy; |
| 745 | for (i = 0; i < DASD_CP_ENTRIES; i++) { |
| 746 | if (copy->entry[i].device == device) |
| 747 | copy->entry[i].device = NULL; |
| 748 | } |
| 749 | dasd_put_device(device); |
| 750 | device->copy = NULL; |
| 751 | } |
| 752 | |
| 753 | /* |
| 754 | * read all required information for a copy relation setup and setup the device |
| 755 | * accordingly |
| 756 | */ |
| 757 | int dasd_devmap_set_device_copy_relation(struct ccw_device *cdev, |
| 758 | bool pprc_enabled) |
| 759 | { |
| 760 | struct dasd_pprc_data_sc4 *data = NULL; |
| 761 | struct dasd_copy_entry *entry = NULL; |
| 762 | struct dasd_copy_relation *copy; |
| 763 | struct dasd_devmap *devmap; |
| 764 | struct dasd_device *device; |
| 765 | int i, rc = 0; |
| 766 | |
| 767 | devmap = dasd_devmap_from_cdev(cdev); |
| 768 | if (IS_ERR(devmap)) |
| 769 | return PTR_ERR(devmap); |
| 770 | |
| 771 | device = devmap->device; |
| 772 | if (!device) |
| 773 | return -ENODEV; |
| 774 | |
| 775 | copy = devmap->copy; |
| 776 | /* no copy pair setup for this device */ |
| 777 | if (!copy) |
| 778 | goto out; |
| 779 | |
| 780 | rc = dasd_devmap_get_pprc_status(device, &data); |
| 781 | if (rc) |
| 782 | return rc; |
| 783 | |
| 784 | /* print error if PPRC is requested but not enabled on storage server */ |
| 785 | if (!pprc_enabled) { |
| 786 | dev_err(&cdev->dev, "Copy relation not enabled on storage server\n"); |
| 787 | rc = -EINVAL; |
| 788 | goto out; |
| 789 | } |
| 790 | |
| 791 | if (!data->dev_info[0].state) { |
| 792 | dev_warn(&device->cdev->dev, "Copy pair setup requested for device not in copy relation\n"); |
| 793 | rc = -EINVAL; |
| 794 | goto out; |
| 795 | } |
| 796 | /* find entry */ |
| 797 | for (i = 0; i < DASD_CP_ENTRIES; i++) { |
| 798 | if (copy->entry[i].configured && |
| 799 | strncmp(dev_name(&cdev->dev), |
| 800 | copy->entry[i].busid, DASD_BUS_ID_SIZE) == 0) { |
| 801 | entry = ©->entry[i]; |
| 802 | break; |
| 803 | } |
| 804 | } |
| 805 | if (!entry) { |
| 806 | dev_warn(&device->cdev->dev, "Copy relation entry not found\n"); |
| 807 | rc = -EINVAL; |
| 808 | goto out; |
| 809 | } |
| 810 | /* check if the copy relation is valid */ |
| 811 | if (dasd_devmap_check_copy_relation(device, entry, data, copy)) { |
| 812 | dev_warn(&device->cdev->dev, "Copy relation faulty\n"); |
| 813 | rc = -EINVAL; |
| 814 | goto out; |
| 815 | } |
| 816 | |
| 817 | dasd_get_device(device); |
| 818 | copy->entry[i].device = device; |
| 819 | device->copy = copy; |
| 820 | out: |
| 821 | kfree(data); |
| 822 | return rc; |
| 823 | } |
| 824 | EXPORT_SYMBOL_GPL(dasd_devmap_set_device_copy_relation); |
| 825 | |
| 826 | /* |
| 827 | * Wait queue for dasd_delete_device waits. |
| 828 | */ |
| 829 | static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq); |
| 830 | |
| 831 | /* |
| 832 | * Remove a dasd device structure. The passed referenced |
| 833 | * is destroyed. |
| 834 | */ |
| 835 | void |
| 836 | dasd_delete_device(struct dasd_device *device) |
| 837 | { |
| 838 | struct ccw_device *cdev; |
| 839 | struct dasd_devmap *devmap; |
| 840 | unsigned long flags; |
| 841 | |
| 842 | /* First remove device pointer from devmap. */ |
| 843 | devmap = dasd_find_busid(dev_name(&device->cdev->dev)); |
| 844 | BUG_ON(IS_ERR(devmap)); |
| 845 | spin_lock(&dasd_devmap_lock); |
| 846 | if (devmap->device != device) { |
| 847 | spin_unlock(&dasd_devmap_lock); |
| 848 | dasd_put_device(device); |
| 849 | return; |
| 850 | } |
| 851 | devmap->device = NULL; |
| 852 | spin_unlock(&dasd_devmap_lock); |
| 853 | |
| 854 | /* Disconnect dasd_device structure from ccw_device structure. */ |
| 855 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 856 | dev_set_drvdata(&device->cdev->dev, NULL); |
| 857 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 858 | |
| 859 | /* Remove copy relation */ |
| 860 | dasd_devmap_delete_copy_relation_device(device); |
| 861 | /* |
| 862 | * Drop ref_count by 3, one for the devmap reference, one for |
| 863 | * the cdev reference and one for the passed reference. |
| 864 | */ |
| 865 | atomic_sub(3, &device->ref_count); |
| 866 | |
| 867 | /* Wait for reference counter to drop to zero. */ |
| 868 | wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0); |
| 869 | |
| 870 | dasd_generic_free_discipline(device); |
| 871 | |
| 872 | kset_unregister(device->paths_info); |
| 873 | |
| 874 | /* Disconnect dasd_device structure from ccw_device structure. */ |
| 875 | cdev = device->cdev; |
| 876 | device->cdev = NULL; |
| 877 | |
| 878 | /* Put ccw_device structure. */ |
| 879 | put_device(&cdev->dev); |
| 880 | |
| 881 | /* Now the device structure can be freed. */ |
| 882 | dasd_free_device(device); |
| 883 | } |
| 884 | |
| 885 | /* |
| 886 | * Reference counter dropped to zero. Wake up waiter |
| 887 | * in dasd_delete_device. |
| 888 | */ |
| 889 | void |
| 890 | dasd_put_device_wake(struct dasd_device *device) |
| 891 | { |
| 892 | wake_up(&dasd_delete_wq); |
| 893 | } |
| 894 | EXPORT_SYMBOL_GPL(dasd_put_device_wake); |
| 895 | |
| 896 | /* |
| 897 | * Return dasd_device structure associated with cdev. |
| 898 | * This function needs to be called with the ccw device |
| 899 | * lock held. It can be used from interrupt context. |
| 900 | */ |
| 901 | struct dasd_device * |
| 902 | dasd_device_from_cdev_locked(struct ccw_device *cdev) |
| 903 | { |
| 904 | struct dasd_device *device = dev_get_drvdata(&cdev->dev); |
| 905 | |
| 906 | if (!device) |
| 907 | return ERR_PTR(-ENODEV); |
| 908 | dasd_get_device(device); |
| 909 | return device; |
| 910 | } |
| 911 | |
| 912 | /* |
| 913 | * Return dasd_device structure associated with cdev. |
| 914 | */ |
| 915 | struct dasd_device * |
| 916 | dasd_device_from_cdev(struct ccw_device *cdev) |
| 917 | { |
| 918 | struct dasd_device *device; |
| 919 | unsigned long flags; |
| 920 | |
| 921 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
| 922 | device = dasd_device_from_cdev_locked(cdev); |
| 923 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 924 | return device; |
| 925 | } |
| 926 | |
| 927 | void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device) |
| 928 | { |
| 929 | struct dasd_devmap *devmap; |
| 930 | |
| 931 | devmap = dasd_find_busid(dev_name(&device->cdev->dev)); |
| 932 | if (IS_ERR(devmap)) |
| 933 | return; |
| 934 | spin_lock(&dasd_devmap_lock); |
| 935 | gdp->private_data = devmap; |
| 936 | spin_unlock(&dasd_devmap_lock); |
| 937 | } |
| 938 | EXPORT_SYMBOL(dasd_add_link_to_gendisk); |
| 939 | |
| 940 | struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp) |
| 941 | { |
| 942 | struct dasd_device *device; |
| 943 | struct dasd_devmap *devmap; |
| 944 | |
| 945 | if (!gdp->private_data) |
| 946 | return NULL; |
| 947 | device = NULL; |
| 948 | spin_lock(&dasd_devmap_lock); |
| 949 | devmap = gdp->private_data; |
| 950 | if (devmap && devmap->device) { |
| 951 | device = devmap->device; |
| 952 | dasd_get_device(device); |
| 953 | } |
| 954 | spin_unlock(&dasd_devmap_lock); |
| 955 | return device; |
| 956 | } |
| 957 | |
| 958 | /* |
| 959 | * SECTION: files in sysfs |
| 960 | */ |
| 961 | |
| 962 | /* |
| 963 | * failfast controls the behaviour, if no path is available |
| 964 | */ |
| 965 | static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr, |
| 966 | char *buf) |
| 967 | { |
| 968 | struct dasd_devmap *devmap; |
| 969 | int ff_flag; |
| 970 | |
| 971 | devmap = dasd_find_busid(dev_name(dev)); |
| 972 | if (!IS_ERR(devmap)) |
| 973 | ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0; |
| 974 | else |
| 975 | ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0; |
| 976 | return sysfs_emit(buf, ff_flag ? "1\n" : "0\n"); |
| 977 | } |
| 978 | |
| 979 | static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr, |
| 980 | const char *buf, size_t count) |
| 981 | { |
| 982 | unsigned int val; |
| 983 | int rc; |
| 984 | |
| 985 | if (kstrtouint(buf, 0, &val) || val > 1) |
| 986 | return -EINVAL; |
| 987 | |
| 988 | rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_FAILFAST, val); |
| 989 | |
| 990 | return rc ? : count; |
| 991 | } |
| 992 | |
| 993 | static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store); |
| 994 | |
| 995 | /* |
| 996 | * readonly controls the readonly status of a dasd |
| 997 | */ |
| 998 | static ssize_t |
| 999 | dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1000 | { |
| 1001 | struct dasd_devmap *devmap; |
| 1002 | struct dasd_device *device; |
| 1003 | int ro_flag = 0; |
| 1004 | |
| 1005 | devmap = dasd_find_busid(dev_name(dev)); |
| 1006 | if (IS_ERR(devmap)) |
| 1007 | goto out; |
| 1008 | |
| 1009 | ro_flag = !!(devmap->features & DASD_FEATURE_READONLY); |
| 1010 | |
| 1011 | spin_lock(&dasd_devmap_lock); |
| 1012 | device = devmap->device; |
| 1013 | if (device) |
| 1014 | ro_flag |= test_bit(DASD_FLAG_DEVICE_RO, &device->flags); |
| 1015 | spin_unlock(&dasd_devmap_lock); |
| 1016 | |
| 1017 | out: |
| 1018 | return sysfs_emit(buf, ro_flag ? "1\n" : "0\n"); |
| 1019 | } |
| 1020 | |
| 1021 | static ssize_t |
| 1022 | dasd_ro_store(struct device *dev, struct device_attribute *attr, |
| 1023 | const char *buf, size_t count) |
| 1024 | { |
| 1025 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1026 | struct dasd_device *device; |
| 1027 | unsigned long flags; |
| 1028 | unsigned int val; |
| 1029 | int rc; |
| 1030 | |
| 1031 | if (kstrtouint(buf, 0, &val) || val > 1) |
| 1032 | return -EINVAL; |
| 1033 | |
| 1034 | rc = dasd_set_feature(cdev, DASD_FEATURE_READONLY, val); |
| 1035 | if (rc) |
| 1036 | return rc; |
| 1037 | |
| 1038 | device = dasd_device_from_cdev(cdev); |
| 1039 | if (IS_ERR(device)) |
| 1040 | return count; |
| 1041 | |
| 1042 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
| 1043 | val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags); |
| 1044 | |
| 1045 | if (!device->block || !device->block->gdp || |
| 1046 | test_bit(DASD_FLAG_OFFLINE, &device->flags)) { |
| 1047 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 1048 | goto out; |
| 1049 | } |
| 1050 | /* Increase open_count to avoid losing the block device */ |
| 1051 | atomic_inc(&device->block->open_count); |
| 1052 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 1053 | |
| 1054 | set_disk_ro(device->block->gdp, val); |
| 1055 | atomic_dec(&device->block->open_count); |
| 1056 | |
| 1057 | out: |
| 1058 | dasd_put_device(device); |
| 1059 | |
| 1060 | return count; |
| 1061 | } |
| 1062 | |
| 1063 | static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store); |
| 1064 | /* |
| 1065 | * erplog controls the logging of ERP related data |
| 1066 | * (e.g. failing channel programs). |
| 1067 | */ |
| 1068 | static ssize_t |
| 1069 | dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1070 | { |
| 1071 | struct dasd_devmap *devmap; |
| 1072 | int erplog; |
| 1073 | |
| 1074 | devmap = dasd_find_busid(dev_name(dev)); |
| 1075 | if (!IS_ERR(devmap)) |
| 1076 | erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0; |
| 1077 | else |
| 1078 | erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0; |
| 1079 | return sysfs_emit(buf, erplog ? "1\n" : "0\n"); |
| 1080 | } |
| 1081 | |
| 1082 | static ssize_t |
| 1083 | dasd_erplog_store(struct device *dev, struct device_attribute *attr, |
| 1084 | const char *buf, size_t count) |
| 1085 | { |
| 1086 | unsigned int val; |
| 1087 | int rc; |
| 1088 | |
| 1089 | if (kstrtouint(buf, 0, &val) || val > 1) |
| 1090 | return -EINVAL; |
| 1091 | |
| 1092 | rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_ERPLOG, val); |
| 1093 | |
| 1094 | return rc ? : count; |
| 1095 | } |
| 1096 | |
| 1097 | static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store); |
| 1098 | |
| 1099 | /* |
| 1100 | * use_diag controls whether the driver should use diag rather than ssch |
| 1101 | * to talk to the device |
| 1102 | */ |
| 1103 | static ssize_t |
| 1104 | dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1105 | { |
| 1106 | struct dasd_devmap *devmap; |
| 1107 | int use_diag; |
| 1108 | |
| 1109 | devmap = dasd_find_busid(dev_name(dev)); |
| 1110 | if (!IS_ERR(devmap)) |
| 1111 | use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0; |
| 1112 | else |
| 1113 | use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0; |
| 1114 | return sysfs_emit(buf, use_diag ? "1\n" : "0\n"); |
| 1115 | } |
| 1116 | |
| 1117 | static ssize_t |
| 1118 | dasd_use_diag_store(struct device *dev, struct device_attribute *attr, |
| 1119 | const char *buf, size_t count) |
| 1120 | { |
| 1121 | struct dasd_devmap *devmap; |
| 1122 | unsigned int val; |
| 1123 | ssize_t rc; |
| 1124 | |
| 1125 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 1126 | if (IS_ERR(devmap)) |
| 1127 | return PTR_ERR(devmap); |
| 1128 | |
| 1129 | if (kstrtouint(buf, 0, &val) || val > 1) |
| 1130 | return -EINVAL; |
| 1131 | |
| 1132 | spin_lock(&dasd_devmap_lock); |
| 1133 | /* Changing diag discipline flag is only allowed in offline state. */ |
| 1134 | rc = count; |
| 1135 | if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) { |
| 1136 | if (val) |
| 1137 | devmap->features |= DASD_FEATURE_USEDIAG; |
| 1138 | else |
| 1139 | devmap->features &= ~DASD_FEATURE_USEDIAG; |
| 1140 | } else |
| 1141 | rc = -EPERM; |
| 1142 | spin_unlock(&dasd_devmap_lock); |
| 1143 | return rc; |
| 1144 | } |
| 1145 | |
| 1146 | static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store); |
| 1147 | |
| 1148 | /* |
| 1149 | * use_raw controls whether the driver should give access to raw eckd data or |
| 1150 | * operate in standard mode |
| 1151 | */ |
| 1152 | static ssize_t |
| 1153 | dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1154 | { |
| 1155 | struct dasd_devmap *devmap; |
| 1156 | int use_raw; |
| 1157 | |
| 1158 | devmap = dasd_find_busid(dev_name(dev)); |
| 1159 | if (!IS_ERR(devmap)) |
| 1160 | use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0; |
| 1161 | else |
| 1162 | use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0; |
| 1163 | return sysfs_emit(buf, use_raw ? "1\n" : "0\n"); |
| 1164 | } |
| 1165 | |
| 1166 | static ssize_t |
| 1167 | dasd_use_raw_store(struct device *dev, struct device_attribute *attr, |
| 1168 | const char *buf, size_t count) |
| 1169 | { |
| 1170 | struct dasd_devmap *devmap; |
| 1171 | ssize_t rc; |
| 1172 | unsigned long val; |
| 1173 | |
| 1174 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 1175 | if (IS_ERR(devmap)) |
| 1176 | return PTR_ERR(devmap); |
| 1177 | |
| 1178 | if ((kstrtoul(buf, 10, &val) != 0) || val > 1) |
| 1179 | return -EINVAL; |
| 1180 | |
| 1181 | spin_lock(&dasd_devmap_lock); |
| 1182 | /* Changing diag discipline flag is only allowed in offline state. */ |
| 1183 | rc = count; |
| 1184 | if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) { |
| 1185 | if (val) |
| 1186 | devmap->features |= DASD_FEATURE_USERAW; |
| 1187 | else |
| 1188 | devmap->features &= ~DASD_FEATURE_USERAW; |
| 1189 | } else |
| 1190 | rc = -EPERM; |
| 1191 | spin_unlock(&dasd_devmap_lock); |
| 1192 | return rc; |
| 1193 | } |
| 1194 | |
| 1195 | static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show, |
| 1196 | dasd_use_raw_store); |
| 1197 | |
| 1198 | static ssize_t |
| 1199 | dasd_safe_offline_store(struct device *dev, struct device_attribute *attr, |
| 1200 | const char *buf, size_t count) |
| 1201 | { |
| 1202 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1203 | struct dasd_device *device; |
| 1204 | unsigned long flags; |
| 1205 | int rc; |
| 1206 | |
| 1207 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
| 1208 | device = dasd_device_from_cdev_locked(cdev); |
| 1209 | if (IS_ERR(device)) { |
| 1210 | rc = PTR_ERR(device); |
| 1211 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 1212 | goto out; |
| 1213 | } |
| 1214 | |
| 1215 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags) || |
| 1216 | test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { |
| 1217 | /* Already doing offline processing */ |
| 1218 | dasd_put_device(device); |
| 1219 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 1220 | rc = -EBUSY; |
| 1221 | goto out; |
| 1222 | } |
| 1223 | |
| 1224 | set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags); |
| 1225 | dasd_put_device(device); |
| 1226 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 1227 | |
| 1228 | rc = ccw_device_set_offline(cdev); |
| 1229 | |
| 1230 | out: |
| 1231 | return rc ? rc : count; |
| 1232 | } |
| 1233 | |
| 1234 | static DEVICE_ATTR(safe_offline, 0200, NULL, dasd_safe_offline_store); |
| 1235 | |
| 1236 | static ssize_t |
| 1237 | dasd_access_show(struct device *dev, struct device_attribute *attr, |
| 1238 | char *buf) |
| 1239 | { |
| 1240 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1241 | struct dasd_device *device; |
| 1242 | int count; |
| 1243 | |
| 1244 | device = dasd_device_from_cdev(cdev); |
| 1245 | if (IS_ERR(device)) |
| 1246 | return PTR_ERR(device); |
| 1247 | |
| 1248 | if (!device->discipline) |
| 1249 | count = -ENODEV; |
| 1250 | else if (!device->discipline->host_access_count) |
| 1251 | count = -EOPNOTSUPP; |
| 1252 | else |
| 1253 | count = device->discipline->host_access_count(device); |
| 1254 | |
| 1255 | dasd_put_device(device); |
| 1256 | if (count < 0) |
| 1257 | return count; |
| 1258 | |
| 1259 | return sysfs_emit(buf, "%d\n", count); |
| 1260 | } |
| 1261 | |
| 1262 | static DEVICE_ATTR(host_access_count, 0444, dasd_access_show, NULL); |
| 1263 | |
| 1264 | static ssize_t |
| 1265 | dasd_discipline_show(struct device *dev, struct device_attribute *attr, |
| 1266 | char *buf) |
| 1267 | { |
| 1268 | struct dasd_device *device; |
| 1269 | ssize_t len; |
| 1270 | |
| 1271 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1272 | if (IS_ERR(device)) |
| 1273 | goto out; |
| 1274 | else if (!device->discipline) { |
| 1275 | dasd_put_device(device); |
| 1276 | goto out; |
| 1277 | } else { |
| 1278 | len = sysfs_emit(buf, "%s\n", |
| 1279 | device->discipline->name); |
| 1280 | dasd_put_device(device); |
| 1281 | return len; |
| 1282 | } |
| 1283 | out: |
| 1284 | len = sysfs_emit(buf, "none\n"); |
| 1285 | return len; |
| 1286 | } |
| 1287 | |
| 1288 | static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL); |
| 1289 | |
| 1290 | static ssize_t |
| 1291 | dasd_device_status_show(struct device *dev, struct device_attribute *attr, |
| 1292 | char *buf) |
| 1293 | { |
| 1294 | struct dasd_device *device; |
| 1295 | ssize_t len; |
| 1296 | |
| 1297 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1298 | if (!IS_ERR(device)) { |
| 1299 | switch (device->state) { |
| 1300 | case DASD_STATE_NEW: |
| 1301 | len = sysfs_emit(buf, "new\n"); |
| 1302 | break; |
| 1303 | case DASD_STATE_KNOWN: |
| 1304 | len = sysfs_emit(buf, "detected\n"); |
| 1305 | break; |
| 1306 | case DASD_STATE_BASIC: |
| 1307 | len = sysfs_emit(buf, "basic\n"); |
| 1308 | break; |
| 1309 | case DASD_STATE_UNFMT: |
| 1310 | len = sysfs_emit(buf, "unformatted\n"); |
| 1311 | break; |
| 1312 | case DASD_STATE_READY: |
| 1313 | len = sysfs_emit(buf, "ready\n"); |
| 1314 | break; |
| 1315 | case DASD_STATE_ONLINE: |
| 1316 | len = sysfs_emit(buf, "online\n"); |
| 1317 | break; |
| 1318 | default: |
| 1319 | len = sysfs_emit(buf, "no stat\n"); |
| 1320 | break; |
| 1321 | } |
| 1322 | dasd_put_device(device); |
| 1323 | } else |
| 1324 | len = sysfs_emit(buf, "unknown\n"); |
| 1325 | return len; |
| 1326 | } |
| 1327 | |
| 1328 | static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL); |
| 1329 | |
| 1330 | static ssize_t dasd_alias_show(struct device *dev, |
| 1331 | struct device_attribute *attr, char *buf) |
| 1332 | { |
| 1333 | struct dasd_device *device; |
| 1334 | struct dasd_uid uid; |
| 1335 | |
| 1336 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1337 | if (IS_ERR(device)) |
| 1338 | return sysfs_emit(buf, "0\n"); |
| 1339 | |
| 1340 | if (device->discipline && device->discipline->get_uid && |
| 1341 | !device->discipline->get_uid(device, &uid)) { |
| 1342 | if (uid.type == UA_BASE_PAV_ALIAS || |
| 1343 | uid.type == UA_HYPER_PAV_ALIAS) { |
| 1344 | dasd_put_device(device); |
| 1345 | return sysfs_emit(buf, "1\n"); |
| 1346 | } |
| 1347 | } |
| 1348 | dasd_put_device(device); |
| 1349 | |
| 1350 | return sysfs_emit(buf, "0\n"); |
| 1351 | } |
| 1352 | |
| 1353 | static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL); |
| 1354 | |
| 1355 | static ssize_t dasd_vendor_show(struct device *dev, |
| 1356 | struct device_attribute *attr, char *buf) |
| 1357 | { |
| 1358 | struct dasd_device *device; |
| 1359 | struct dasd_uid uid; |
| 1360 | char *vendor; |
| 1361 | |
| 1362 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1363 | vendor = ""; |
| 1364 | if (IS_ERR(device)) |
| 1365 | return sysfs_emit(buf, "%s\n", vendor); |
| 1366 | |
| 1367 | if (device->discipline && device->discipline->get_uid && |
| 1368 | !device->discipline->get_uid(device, &uid)) |
| 1369 | vendor = uid.vendor; |
| 1370 | |
| 1371 | dasd_put_device(device); |
| 1372 | |
| 1373 | return sysfs_emit(buf, "%s\n", vendor); |
| 1374 | } |
| 1375 | |
| 1376 | static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL); |
| 1377 | |
| 1378 | static ssize_t |
| 1379 | dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1380 | { |
| 1381 | char uid_string[DASD_UID_STRLEN]; |
| 1382 | struct dasd_device *device; |
| 1383 | struct dasd_uid uid; |
| 1384 | char ua_string[3]; |
| 1385 | |
| 1386 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1387 | uid_string[0] = 0; |
| 1388 | if (IS_ERR(device)) |
| 1389 | return sysfs_emit(buf, "%s\n", uid_string); |
| 1390 | |
| 1391 | if (device->discipline && device->discipline->get_uid && |
| 1392 | !device->discipline->get_uid(device, &uid)) { |
| 1393 | switch (uid.type) { |
| 1394 | case UA_BASE_DEVICE: |
| 1395 | snprintf(ua_string, sizeof(ua_string), "%02x", |
| 1396 | uid.real_unit_addr); |
| 1397 | break; |
| 1398 | case UA_BASE_PAV_ALIAS: |
| 1399 | snprintf(ua_string, sizeof(ua_string), "%02x", |
| 1400 | uid.base_unit_addr); |
| 1401 | break; |
| 1402 | case UA_HYPER_PAV_ALIAS: |
| 1403 | snprintf(ua_string, sizeof(ua_string), "xx"); |
| 1404 | break; |
| 1405 | default: |
| 1406 | /* should not happen, treat like base device */ |
| 1407 | snprintf(ua_string, sizeof(ua_string), "%02x", |
| 1408 | uid.real_unit_addr); |
| 1409 | break; |
| 1410 | } |
| 1411 | |
| 1412 | snprintf(uid_string, sizeof(uid_string), "%s.%s.%04x.%s%s%s", |
| 1413 | uid.vendor, uid.serial, uid.ssid, ua_string, |
| 1414 | uid.vduit[0] ? "." : "", uid.vduit); |
| 1415 | } |
| 1416 | dasd_put_device(device); |
| 1417 | |
| 1418 | return sysfs_emit(buf, "%s\n", uid_string); |
| 1419 | } |
| 1420 | static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL); |
| 1421 | |
| 1422 | /* |
| 1423 | * extended error-reporting |
| 1424 | */ |
| 1425 | static ssize_t |
| 1426 | dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1427 | { |
| 1428 | struct dasd_devmap *devmap; |
| 1429 | int eer_flag; |
| 1430 | |
| 1431 | devmap = dasd_find_busid(dev_name(dev)); |
| 1432 | if (!IS_ERR(devmap) && devmap->device) |
| 1433 | eer_flag = dasd_eer_enabled(devmap->device); |
| 1434 | else |
| 1435 | eer_flag = 0; |
| 1436 | return sysfs_emit(buf, eer_flag ? "1\n" : "0\n"); |
| 1437 | } |
| 1438 | |
| 1439 | static ssize_t |
| 1440 | dasd_eer_store(struct device *dev, struct device_attribute *attr, |
| 1441 | const char *buf, size_t count) |
| 1442 | { |
| 1443 | struct dasd_device *device; |
| 1444 | unsigned int val; |
| 1445 | int rc = 0; |
| 1446 | |
| 1447 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1448 | if (IS_ERR(device)) |
| 1449 | return PTR_ERR(device); |
| 1450 | |
| 1451 | if (kstrtouint(buf, 0, &val) || val > 1) |
| 1452 | return -EINVAL; |
| 1453 | |
| 1454 | if (val) |
| 1455 | rc = dasd_eer_enable(device); |
| 1456 | else |
| 1457 | dasd_eer_disable(device); |
| 1458 | |
| 1459 | dasd_put_device(device); |
| 1460 | |
| 1461 | return rc ? : count; |
| 1462 | } |
| 1463 | |
| 1464 | static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store); |
| 1465 | |
| 1466 | /* |
| 1467 | * aq_mask controls if the DASD should be quiesced on certain triggers |
| 1468 | * The aq_mask attribute is interpreted as bitmap of the DASD_EER_* triggers. |
| 1469 | */ |
| 1470 | static ssize_t dasd_aq_mask_show(struct device *dev, struct device_attribute *attr, |
| 1471 | char *buf) |
| 1472 | { |
| 1473 | struct dasd_devmap *devmap; |
| 1474 | unsigned int aq_mask = 0; |
| 1475 | |
| 1476 | devmap = dasd_find_busid(dev_name(dev)); |
| 1477 | if (!IS_ERR(devmap)) |
| 1478 | aq_mask = devmap->aq_mask; |
| 1479 | |
| 1480 | return sysfs_emit(buf, "%d\n", aq_mask); |
| 1481 | } |
| 1482 | |
| 1483 | static ssize_t dasd_aq_mask_store(struct device *dev, struct device_attribute *attr, |
| 1484 | const char *buf, size_t count) |
| 1485 | { |
| 1486 | struct dasd_devmap *devmap; |
| 1487 | unsigned int val; |
| 1488 | |
| 1489 | if (kstrtouint(buf, 0, &val) || val > DASD_EER_VALID) |
| 1490 | return -EINVAL; |
| 1491 | |
| 1492 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 1493 | if (IS_ERR(devmap)) |
| 1494 | return PTR_ERR(devmap); |
| 1495 | |
| 1496 | spin_lock(&dasd_devmap_lock); |
| 1497 | devmap->aq_mask = val; |
| 1498 | if (devmap->device) |
| 1499 | devmap->device->aq_mask = devmap->aq_mask; |
| 1500 | spin_unlock(&dasd_devmap_lock); |
| 1501 | |
| 1502 | return count; |
| 1503 | } |
| 1504 | |
| 1505 | static DEVICE_ATTR(aq_mask, 0644, dasd_aq_mask_show, dasd_aq_mask_store); |
| 1506 | |
| 1507 | /* |
| 1508 | * aq_requeue controls if requests are returned to the blocklayer on quiesce |
| 1509 | * or if requests are only not started |
| 1510 | */ |
| 1511 | static ssize_t dasd_aqr_show(struct device *dev, struct device_attribute *attr, |
| 1512 | char *buf) |
| 1513 | { |
| 1514 | struct dasd_devmap *devmap; |
| 1515 | int flag; |
| 1516 | |
| 1517 | devmap = dasd_find_busid(dev_name(dev)); |
| 1518 | if (!IS_ERR(devmap)) |
| 1519 | flag = (devmap->features & DASD_FEATURE_REQUEUEQUIESCE) != 0; |
| 1520 | else |
| 1521 | flag = (DASD_FEATURE_DEFAULT & |
| 1522 | DASD_FEATURE_REQUEUEQUIESCE) != 0; |
| 1523 | return sysfs_emit(buf, "%d\n", flag); |
| 1524 | } |
| 1525 | |
| 1526 | static ssize_t dasd_aqr_store(struct device *dev, struct device_attribute *attr, |
| 1527 | const char *buf, size_t count) |
| 1528 | { |
| 1529 | bool val; |
| 1530 | int rc; |
| 1531 | |
| 1532 | if (kstrtobool(buf, &val)) |
| 1533 | return -EINVAL; |
| 1534 | |
| 1535 | rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_REQUEUEQUIESCE, val); |
| 1536 | |
| 1537 | return rc ? : count; |
| 1538 | } |
| 1539 | |
| 1540 | static DEVICE_ATTR(aq_requeue, 0644, dasd_aqr_show, dasd_aqr_store); |
| 1541 | |
| 1542 | /* |
| 1543 | * aq_timeouts controls how much retries have to time out until |
| 1544 | * a device gets autoquiesced |
| 1545 | */ |
| 1546 | static ssize_t |
| 1547 | dasd_aq_timeouts_show(struct device *dev, struct device_attribute *attr, |
| 1548 | char *buf) |
| 1549 | { |
| 1550 | struct dasd_device *device; |
| 1551 | int len; |
| 1552 | |
| 1553 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1554 | if (IS_ERR(device)) |
| 1555 | return -ENODEV; |
| 1556 | len = sysfs_emit(buf, "%u\n", device->aq_timeouts); |
| 1557 | dasd_put_device(device); |
| 1558 | return len; |
| 1559 | } |
| 1560 | |
| 1561 | static ssize_t |
| 1562 | dasd_aq_timeouts_store(struct device *dev, struct device_attribute *attr, |
| 1563 | const char *buf, size_t count) |
| 1564 | { |
| 1565 | struct dasd_device *device; |
| 1566 | unsigned int val; |
| 1567 | |
| 1568 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1569 | if (IS_ERR(device)) |
| 1570 | return -ENODEV; |
| 1571 | |
| 1572 | if ((kstrtouint(buf, 10, &val) != 0) || |
| 1573 | val > DASD_RETRIES_MAX || val == 0) { |
| 1574 | dasd_put_device(device); |
| 1575 | return -EINVAL; |
| 1576 | } |
| 1577 | |
| 1578 | if (val) |
| 1579 | device->aq_timeouts = val; |
| 1580 | |
| 1581 | dasd_put_device(device); |
| 1582 | return count; |
| 1583 | } |
| 1584 | |
| 1585 | static DEVICE_ATTR(aq_timeouts, 0644, dasd_aq_timeouts_show, |
| 1586 | dasd_aq_timeouts_store); |
| 1587 | |
| 1588 | /* |
| 1589 | * expiration time for default requests |
| 1590 | */ |
| 1591 | static ssize_t |
| 1592 | dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1593 | { |
| 1594 | struct dasd_device *device; |
| 1595 | int len; |
| 1596 | |
| 1597 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1598 | if (IS_ERR(device)) |
| 1599 | return -ENODEV; |
| 1600 | len = sysfs_emit(buf, "%lu\n", device->default_expires); |
| 1601 | dasd_put_device(device); |
| 1602 | return len; |
| 1603 | } |
| 1604 | |
| 1605 | static ssize_t |
| 1606 | dasd_expires_store(struct device *dev, struct device_attribute *attr, |
| 1607 | const char *buf, size_t count) |
| 1608 | { |
| 1609 | struct dasd_device *device; |
| 1610 | unsigned long val; |
| 1611 | |
| 1612 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1613 | if (IS_ERR(device)) |
| 1614 | return -ENODEV; |
| 1615 | |
| 1616 | if ((kstrtoul(buf, 10, &val) != 0) || |
| 1617 | (val > DASD_EXPIRES_MAX) || val == 0) { |
| 1618 | dasd_put_device(device); |
| 1619 | return -EINVAL; |
| 1620 | } |
| 1621 | |
| 1622 | if (val) |
| 1623 | device->default_expires = val; |
| 1624 | |
| 1625 | dasd_put_device(device); |
| 1626 | return count; |
| 1627 | } |
| 1628 | |
| 1629 | static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store); |
| 1630 | |
| 1631 | static ssize_t |
| 1632 | dasd_retries_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1633 | { |
| 1634 | struct dasd_device *device; |
| 1635 | int len; |
| 1636 | |
| 1637 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1638 | if (IS_ERR(device)) |
| 1639 | return -ENODEV; |
| 1640 | len = sysfs_emit(buf, "%lu\n", device->default_retries); |
| 1641 | dasd_put_device(device); |
| 1642 | return len; |
| 1643 | } |
| 1644 | |
| 1645 | static ssize_t |
| 1646 | dasd_retries_store(struct device *dev, struct device_attribute *attr, |
| 1647 | const char *buf, size_t count) |
| 1648 | { |
| 1649 | struct dasd_device *device; |
| 1650 | unsigned long val; |
| 1651 | |
| 1652 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1653 | if (IS_ERR(device)) |
| 1654 | return -ENODEV; |
| 1655 | |
| 1656 | if ((kstrtoul(buf, 10, &val) != 0) || |
| 1657 | (val > DASD_RETRIES_MAX)) { |
| 1658 | dasd_put_device(device); |
| 1659 | return -EINVAL; |
| 1660 | } |
| 1661 | |
| 1662 | if (val) |
| 1663 | device->default_retries = val; |
| 1664 | |
| 1665 | dasd_put_device(device); |
| 1666 | return count; |
| 1667 | } |
| 1668 | |
| 1669 | static DEVICE_ATTR(retries, 0644, dasd_retries_show, dasd_retries_store); |
| 1670 | |
| 1671 | static ssize_t |
| 1672 | dasd_timeout_show(struct device *dev, struct device_attribute *attr, |
| 1673 | char *buf) |
| 1674 | { |
| 1675 | struct dasd_device *device; |
| 1676 | int len; |
| 1677 | |
| 1678 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1679 | if (IS_ERR(device)) |
| 1680 | return -ENODEV; |
| 1681 | len = sysfs_emit(buf, "%lu\n", device->blk_timeout); |
| 1682 | dasd_put_device(device); |
| 1683 | return len; |
| 1684 | } |
| 1685 | |
| 1686 | static ssize_t |
| 1687 | dasd_timeout_store(struct device *dev, struct device_attribute *attr, |
| 1688 | const char *buf, size_t count) |
| 1689 | { |
| 1690 | struct dasd_device *device; |
| 1691 | unsigned long val; |
| 1692 | |
| 1693 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1694 | if (IS_ERR(device) || !device->block) |
| 1695 | return -ENODEV; |
| 1696 | |
| 1697 | if ((kstrtoul(buf, 10, &val) != 0) || |
| 1698 | val > UINT_MAX / HZ) { |
| 1699 | dasd_put_device(device); |
| 1700 | return -EINVAL; |
| 1701 | } |
| 1702 | if (!device->block->gdp) { |
| 1703 | dasd_put_device(device); |
| 1704 | return -ENODEV; |
| 1705 | } |
| 1706 | |
| 1707 | device->blk_timeout = val; |
| 1708 | blk_queue_rq_timeout(device->block->gdp->queue, val * HZ); |
| 1709 | |
| 1710 | dasd_put_device(device); |
| 1711 | return count; |
| 1712 | } |
| 1713 | |
| 1714 | static DEVICE_ATTR(timeout, 0644, |
| 1715 | dasd_timeout_show, dasd_timeout_store); |
| 1716 | |
| 1717 | |
| 1718 | static ssize_t |
| 1719 | dasd_path_reset_store(struct device *dev, struct device_attribute *attr, |
| 1720 | const char *buf, size_t count) |
| 1721 | { |
| 1722 | struct dasd_device *device; |
| 1723 | unsigned int val; |
| 1724 | |
| 1725 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1726 | if (IS_ERR(device)) |
| 1727 | return -ENODEV; |
| 1728 | |
| 1729 | if ((kstrtouint(buf, 16, &val) != 0) || val > 0xff) |
| 1730 | val = 0; |
| 1731 | |
| 1732 | if (device->discipline && device->discipline->reset_path) |
| 1733 | device->discipline->reset_path(device, (__u8) val); |
| 1734 | |
| 1735 | dasd_put_device(device); |
| 1736 | return count; |
| 1737 | } |
| 1738 | |
| 1739 | static DEVICE_ATTR(path_reset, 0200, NULL, dasd_path_reset_store); |
| 1740 | |
| 1741 | static ssize_t dasd_hpf_show(struct device *dev, struct device_attribute *attr, |
| 1742 | char *buf) |
| 1743 | { |
| 1744 | struct dasd_device *device; |
| 1745 | int hpf; |
| 1746 | |
| 1747 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1748 | if (IS_ERR(device)) |
| 1749 | return -ENODEV; |
| 1750 | if (!device->discipline || !device->discipline->hpf_enabled) { |
| 1751 | dasd_put_device(device); |
| 1752 | return sysfs_emit(buf, "%d\n", dasd_nofcx); |
| 1753 | } |
| 1754 | hpf = device->discipline->hpf_enabled(device); |
| 1755 | dasd_put_device(device); |
| 1756 | return sysfs_emit(buf, "%d\n", hpf); |
| 1757 | } |
| 1758 | |
| 1759 | static DEVICE_ATTR(hpf, 0444, dasd_hpf_show, NULL); |
| 1760 | |
| 1761 | static ssize_t dasd_reservation_policy_show(struct device *dev, |
| 1762 | struct device_attribute *attr, |
| 1763 | char *buf) |
| 1764 | { |
| 1765 | struct dasd_devmap *devmap; |
| 1766 | int rc = 0; |
| 1767 | |
| 1768 | devmap = dasd_find_busid(dev_name(dev)); |
| 1769 | if (IS_ERR(devmap)) { |
| 1770 | rc = sysfs_emit(buf, "ignore\n"); |
| 1771 | } else { |
| 1772 | spin_lock(&dasd_devmap_lock); |
| 1773 | if (devmap->features & DASD_FEATURE_FAILONSLCK) |
| 1774 | rc = sysfs_emit(buf, "fail\n"); |
| 1775 | else |
| 1776 | rc = sysfs_emit(buf, "ignore\n"); |
| 1777 | spin_unlock(&dasd_devmap_lock); |
| 1778 | } |
| 1779 | return rc; |
| 1780 | } |
| 1781 | |
| 1782 | static ssize_t dasd_reservation_policy_store(struct device *dev, |
| 1783 | struct device_attribute *attr, |
| 1784 | const char *buf, size_t count) |
| 1785 | { |
| 1786 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1787 | int rc; |
| 1788 | |
| 1789 | if (sysfs_streq("ignore", buf)) |
| 1790 | rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 0); |
| 1791 | else if (sysfs_streq("fail", buf)) |
| 1792 | rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 1); |
| 1793 | else |
| 1794 | rc = -EINVAL; |
| 1795 | |
| 1796 | return rc ? : count; |
| 1797 | } |
| 1798 | |
| 1799 | static DEVICE_ATTR(reservation_policy, 0644, |
| 1800 | dasd_reservation_policy_show, dasd_reservation_policy_store); |
| 1801 | |
| 1802 | static ssize_t dasd_reservation_state_show(struct device *dev, |
| 1803 | struct device_attribute *attr, |
| 1804 | char *buf) |
| 1805 | { |
| 1806 | struct dasd_device *device; |
| 1807 | int rc = 0; |
| 1808 | |
| 1809 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1810 | if (IS_ERR(device)) |
| 1811 | return sysfs_emit(buf, "none\n"); |
| 1812 | |
| 1813 | if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) |
| 1814 | rc = sysfs_emit(buf, "reserved\n"); |
| 1815 | else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) |
| 1816 | rc = sysfs_emit(buf, "lost\n"); |
| 1817 | else |
| 1818 | rc = sysfs_emit(buf, "none\n"); |
| 1819 | dasd_put_device(device); |
| 1820 | return rc; |
| 1821 | } |
| 1822 | |
| 1823 | static ssize_t dasd_reservation_state_store(struct device *dev, |
| 1824 | struct device_attribute *attr, |
| 1825 | const char *buf, size_t count) |
| 1826 | { |
| 1827 | struct dasd_device *device; |
| 1828 | int rc = 0; |
| 1829 | |
| 1830 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1831 | if (IS_ERR(device)) |
| 1832 | return -ENODEV; |
| 1833 | if (sysfs_streq("reset", buf)) |
| 1834 | clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags); |
| 1835 | else |
| 1836 | rc = -EINVAL; |
| 1837 | dasd_put_device(device); |
| 1838 | |
| 1839 | if (rc) |
| 1840 | return rc; |
| 1841 | else |
| 1842 | return count; |
| 1843 | } |
| 1844 | |
| 1845 | static DEVICE_ATTR(last_known_reservation_state, 0644, |
| 1846 | dasd_reservation_state_show, dasd_reservation_state_store); |
| 1847 | |
| 1848 | static ssize_t dasd_pm_show(struct device *dev, |
| 1849 | struct device_attribute *attr, char *buf) |
| 1850 | { |
| 1851 | struct dasd_device *device; |
| 1852 | u8 opm, nppm, cablepm, cuirpm, hpfpm, ifccpm; |
| 1853 | |
| 1854 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1855 | if (IS_ERR(device)) |
| 1856 | return sysfs_emit(buf, "0\n"); |
| 1857 | |
| 1858 | opm = dasd_path_get_opm(device); |
| 1859 | nppm = dasd_path_get_nppm(device); |
| 1860 | cablepm = dasd_path_get_cablepm(device); |
| 1861 | cuirpm = dasd_path_get_cuirpm(device); |
| 1862 | hpfpm = dasd_path_get_hpfpm(device); |
| 1863 | ifccpm = dasd_path_get_ifccpm(device); |
| 1864 | dasd_put_device(device); |
| 1865 | |
| 1866 | return sysfs_emit(buf, "%02x %02x %02x %02x %02x %02x\n", opm, nppm, |
| 1867 | cablepm, cuirpm, hpfpm, ifccpm); |
| 1868 | } |
| 1869 | |
| 1870 | static DEVICE_ATTR(path_masks, 0444, dasd_pm_show, NULL); |
| 1871 | |
| 1872 | /* |
| 1873 | * threshold value for IFCC/CCC errors |
| 1874 | */ |
| 1875 | static ssize_t |
| 1876 | dasd_path_threshold_show(struct device *dev, |
| 1877 | struct device_attribute *attr, char *buf) |
| 1878 | { |
| 1879 | struct dasd_device *device; |
| 1880 | int len; |
| 1881 | |
| 1882 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1883 | if (IS_ERR(device)) |
| 1884 | return -ENODEV; |
| 1885 | len = sysfs_emit(buf, "%lu\n", device->path_thrhld); |
| 1886 | dasd_put_device(device); |
| 1887 | return len; |
| 1888 | } |
| 1889 | |
| 1890 | static ssize_t |
| 1891 | dasd_path_threshold_store(struct device *dev, struct device_attribute *attr, |
| 1892 | const char *buf, size_t count) |
| 1893 | { |
| 1894 | struct dasd_device *device; |
| 1895 | unsigned long flags; |
| 1896 | unsigned long val; |
| 1897 | |
| 1898 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1899 | if (IS_ERR(device)) |
| 1900 | return -ENODEV; |
| 1901 | |
| 1902 | if (kstrtoul(buf, 10, &val) != 0 || val > DASD_THRHLD_MAX) { |
| 1903 | dasd_put_device(device); |
| 1904 | return -EINVAL; |
| 1905 | } |
| 1906 | spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags); |
| 1907 | device->path_thrhld = val; |
| 1908 | spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags); |
| 1909 | dasd_put_device(device); |
| 1910 | return count; |
| 1911 | } |
| 1912 | static DEVICE_ATTR(path_threshold, 0644, dasd_path_threshold_show, |
| 1913 | dasd_path_threshold_store); |
| 1914 | |
| 1915 | /* |
| 1916 | * configure if path is disabled after IFCC/CCC error threshold is |
| 1917 | * exceeded |
| 1918 | */ |
| 1919 | static ssize_t |
| 1920 | dasd_path_autodisable_show(struct device *dev, |
| 1921 | struct device_attribute *attr, char *buf) |
| 1922 | { |
| 1923 | struct dasd_devmap *devmap; |
| 1924 | int flag; |
| 1925 | |
| 1926 | devmap = dasd_find_busid(dev_name(dev)); |
| 1927 | if (!IS_ERR(devmap)) |
| 1928 | flag = (devmap->features & DASD_FEATURE_PATH_AUTODISABLE) != 0; |
| 1929 | else |
| 1930 | flag = (DASD_FEATURE_DEFAULT & |
| 1931 | DASD_FEATURE_PATH_AUTODISABLE) != 0; |
| 1932 | return sysfs_emit(buf, flag ? "1\n" : "0\n"); |
| 1933 | } |
| 1934 | |
| 1935 | static ssize_t |
| 1936 | dasd_path_autodisable_store(struct device *dev, |
| 1937 | struct device_attribute *attr, |
| 1938 | const char *buf, size_t count) |
| 1939 | { |
| 1940 | unsigned int val; |
| 1941 | int rc; |
| 1942 | |
| 1943 | if (kstrtouint(buf, 0, &val) || val > 1) |
| 1944 | return -EINVAL; |
| 1945 | |
| 1946 | rc = dasd_set_feature(to_ccwdev(dev), |
| 1947 | DASD_FEATURE_PATH_AUTODISABLE, val); |
| 1948 | |
| 1949 | return rc ? : count; |
| 1950 | } |
| 1951 | |
| 1952 | static DEVICE_ATTR(path_autodisable, 0644, |
| 1953 | dasd_path_autodisable_show, |
| 1954 | dasd_path_autodisable_store); |
| 1955 | /* |
| 1956 | * interval for IFCC/CCC checks |
| 1957 | * meaning time with no IFCC/CCC error before the error counter |
| 1958 | * gets reset |
| 1959 | */ |
| 1960 | static ssize_t |
| 1961 | dasd_path_interval_show(struct device *dev, |
| 1962 | struct device_attribute *attr, char *buf) |
| 1963 | { |
| 1964 | struct dasd_device *device; |
| 1965 | int len; |
| 1966 | |
| 1967 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1968 | if (IS_ERR(device)) |
| 1969 | return -ENODEV; |
| 1970 | len = sysfs_emit(buf, "%lu\n", device->path_interval); |
| 1971 | dasd_put_device(device); |
| 1972 | return len; |
| 1973 | } |
| 1974 | |
| 1975 | static ssize_t |
| 1976 | dasd_path_interval_store(struct device *dev, struct device_attribute *attr, |
| 1977 | const char *buf, size_t count) |
| 1978 | { |
| 1979 | struct dasd_device *device; |
| 1980 | unsigned long flags; |
| 1981 | unsigned long val; |
| 1982 | |
| 1983 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 1984 | if (IS_ERR(device)) |
| 1985 | return -ENODEV; |
| 1986 | |
| 1987 | if ((kstrtoul(buf, 10, &val) != 0) || |
| 1988 | (val > DASD_INTERVAL_MAX) || val == 0) { |
| 1989 | dasd_put_device(device); |
| 1990 | return -EINVAL; |
| 1991 | } |
| 1992 | spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags); |
| 1993 | if (val) |
| 1994 | device->path_interval = val; |
| 1995 | spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags); |
| 1996 | dasd_put_device(device); |
| 1997 | return count; |
| 1998 | } |
| 1999 | |
| 2000 | static DEVICE_ATTR(path_interval, 0644, dasd_path_interval_show, |
| 2001 | dasd_path_interval_store); |
| 2002 | |
| 2003 | static ssize_t |
| 2004 | dasd_device_fcs_show(struct device *dev, struct device_attribute *attr, |
| 2005 | char *buf) |
| 2006 | { |
| 2007 | struct dasd_device *device; |
| 2008 | int fc_sec; |
| 2009 | int rc; |
| 2010 | |
| 2011 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 2012 | if (IS_ERR(device)) |
| 2013 | return -ENODEV; |
| 2014 | fc_sec = dasd_path_get_fcs_device(device); |
| 2015 | if (fc_sec == -EINVAL) |
| 2016 | rc = sysfs_emit(buf, "Inconsistent\n"); |
| 2017 | else |
| 2018 | rc = sysfs_emit(buf, "%s\n", dasd_path_get_fcs_str(fc_sec)); |
| 2019 | dasd_put_device(device); |
| 2020 | |
| 2021 | return rc; |
| 2022 | } |
| 2023 | static DEVICE_ATTR(fc_security, 0444, dasd_device_fcs_show, NULL); |
| 2024 | |
| 2025 | static ssize_t |
| 2026 | dasd_path_fcs_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
| 2027 | { |
| 2028 | struct dasd_path *path = to_dasd_path(kobj); |
| 2029 | unsigned int fc_sec = path->fc_security; |
| 2030 | |
| 2031 | return sysfs_emit(buf, "%s\n", dasd_path_get_fcs_str(fc_sec)); |
| 2032 | } |
| 2033 | |
| 2034 | static struct kobj_attribute path_fcs_attribute = |
| 2035 | __ATTR(fc_security, 0444, dasd_path_fcs_show, NULL); |
| 2036 | |
| 2037 | /* |
| 2038 | * print copy relation in the form |
| 2039 | * primary,secondary[1] primary,secondary[2], ... |
| 2040 | */ |
| 2041 | static ssize_t |
| 2042 | dasd_copy_pair_show(struct device *dev, |
| 2043 | struct device_attribute *attr, char *buf) |
| 2044 | { |
| 2045 | char prim_busid[DASD_BUS_ID_SIZE]; |
| 2046 | struct dasd_copy_relation *copy; |
| 2047 | struct dasd_devmap *devmap; |
| 2048 | int len = 0; |
| 2049 | int i; |
| 2050 | |
| 2051 | devmap = dasd_find_busid(dev_name(dev)); |
| 2052 | if (IS_ERR(devmap)) |
| 2053 | return -ENODEV; |
| 2054 | |
| 2055 | if (!devmap->copy) |
| 2056 | return -ENODEV; |
| 2057 | |
| 2058 | copy = devmap->copy; |
| 2059 | /* find primary */ |
| 2060 | for (i = 0; i < DASD_CP_ENTRIES; i++) { |
| 2061 | if (copy->entry[i].configured && copy->entry[i].primary) { |
| 2062 | strscpy(prim_busid, copy->entry[i].busid, |
| 2063 | DASD_BUS_ID_SIZE); |
| 2064 | break; |
| 2065 | } |
| 2066 | } |
| 2067 | if (i == DASD_CP_ENTRIES) |
| 2068 | goto out; |
| 2069 | |
| 2070 | /* print all secondary */ |
| 2071 | for (i = 0; i < DASD_CP_ENTRIES; i++) { |
| 2072 | if (copy->entry[i].configured && !copy->entry[i].primary) |
| 2073 | len += sysfs_emit_at(buf, len, "%s,%s ", prim_busid, |
| 2074 | copy->entry[i].busid); |
| 2075 | } |
| 2076 | |
| 2077 | len += sysfs_emit_at(buf, len, "\n"); |
| 2078 | out: |
| 2079 | return len; |
| 2080 | } |
| 2081 | |
| 2082 | static int dasd_devmap_set_copy_relation(struct dasd_devmap *devmap, |
| 2083 | struct dasd_copy_relation *copy, |
| 2084 | char *busid, bool primary) |
| 2085 | { |
| 2086 | int i; |
| 2087 | |
| 2088 | /* find free entry */ |
| 2089 | for (i = 0; i < DASD_CP_ENTRIES; i++) { |
| 2090 | /* current bus_id already included, nothing to do */ |
| 2091 | if (copy->entry[i].configured && |
| 2092 | strncmp(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE) == 0) |
| 2093 | return 0; |
| 2094 | |
| 2095 | if (!copy->entry[i].configured) |
| 2096 | break; |
| 2097 | } |
| 2098 | if (i == DASD_CP_ENTRIES) |
| 2099 | return -EINVAL; |
| 2100 | |
| 2101 | copy->entry[i].configured = true; |
| 2102 | strscpy(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE); |
| 2103 | if (primary) { |
| 2104 | copy->active = ©->entry[i]; |
| 2105 | copy->entry[i].primary = true; |
| 2106 | } |
| 2107 | if (!devmap->copy) |
| 2108 | devmap->copy = copy; |
| 2109 | |
| 2110 | return 0; |
| 2111 | } |
| 2112 | |
| 2113 | static void dasd_devmap_del_copy_relation(struct dasd_copy_relation *copy, |
| 2114 | char *busid) |
| 2115 | { |
| 2116 | int i; |
| 2117 | |
| 2118 | spin_lock(&dasd_devmap_lock); |
| 2119 | /* find entry */ |
| 2120 | for (i = 0; i < DASD_CP_ENTRIES; i++) { |
| 2121 | if (copy->entry[i].configured && |
| 2122 | strncmp(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE) == 0) |
| 2123 | break; |
| 2124 | } |
| 2125 | if (i == DASD_CP_ENTRIES || !copy->entry[i].configured) { |
| 2126 | spin_unlock(&dasd_devmap_lock); |
| 2127 | return; |
| 2128 | } |
| 2129 | |
| 2130 | copy->entry[i].configured = false; |
| 2131 | memset(copy->entry[i].busid, 0, DASD_BUS_ID_SIZE); |
| 2132 | if (copy->active == ©->entry[i]) { |
| 2133 | copy->active = NULL; |
| 2134 | copy->entry[i].primary = false; |
| 2135 | } |
| 2136 | spin_unlock(&dasd_devmap_lock); |
| 2137 | } |
| 2138 | |
| 2139 | static int dasd_devmap_clear_copy_relation(struct device *dev) |
| 2140 | { |
| 2141 | struct dasd_copy_relation *copy; |
| 2142 | struct dasd_devmap *devmap; |
| 2143 | int i, rc = 1; |
| 2144 | |
| 2145 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); |
| 2146 | if (IS_ERR(devmap)) |
| 2147 | return 1; |
| 2148 | |
| 2149 | spin_lock(&dasd_devmap_lock); |
| 2150 | if (!devmap->copy) |
| 2151 | goto out; |
| 2152 | |
| 2153 | copy = devmap->copy; |
| 2154 | /* first check if all secondary devices are offline*/ |
| 2155 | for (i = 0; i < DASD_CP_ENTRIES; i++) { |
| 2156 | if (!copy->entry[i].configured) |
| 2157 | continue; |
| 2158 | |
| 2159 | if (copy->entry[i].device == copy->active->device) |
| 2160 | continue; |
| 2161 | |
| 2162 | if (copy->entry[i].device) |
| 2163 | goto out; |
| 2164 | } |
| 2165 | /* clear all devmap entries */ |
| 2166 | for (i = 0; i < DASD_CP_ENTRIES; i++) { |
| 2167 | if (strlen(copy->entry[i].busid) == 0) |
| 2168 | continue; |
| 2169 | if (copy->entry[i].device) { |
| 2170 | dasd_put_device(copy->entry[i].device); |
| 2171 | copy->entry[i].device->copy = NULL; |
| 2172 | copy->entry[i].device = NULL; |
| 2173 | } |
| 2174 | devmap = dasd_find_busid_locked(copy->entry[i].busid); |
| 2175 | devmap->copy = NULL; |
| 2176 | memset(copy->entry[i].busid, 0, DASD_BUS_ID_SIZE); |
| 2177 | } |
| 2178 | kfree(copy); |
| 2179 | rc = 0; |
| 2180 | out: |
| 2181 | spin_unlock(&dasd_devmap_lock); |
| 2182 | return rc; |
| 2183 | } |
| 2184 | |
| 2185 | /* |
| 2186 | * parse BUSIDs from a copy pair |
| 2187 | */ |
| 2188 | static int dasd_devmap_parse_busid(const char *buf, char *prim_busid, |
| 2189 | char *sec_busid) |
| 2190 | { |
| 2191 | char *primary, *secondary, *tmp, *pt; |
| 2192 | int id0, id1, id2; |
| 2193 | |
| 2194 | pt = kstrdup(buf, GFP_KERNEL); |
| 2195 | tmp = pt; |
| 2196 | if (!tmp) |
| 2197 | return -ENOMEM; |
| 2198 | |
| 2199 | primary = strsep(&tmp, ","); |
| 2200 | if (!primary) { |
| 2201 | kfree(pt); |
| 2202 | return -EINVAL; |
| 2203 | } |
| 2204 | secondary = strsep(&tmp, ","); |
| 2205 | if (!secondary) { |
| 2206 | kfree(pt); |
| 2207 | return -EINVAL; |
| 2208 | } |
| 2209 | if (dasd_busid(primary, &id0, &id1, &id2)) { |
| 2210 | kfree(pt); |
| 2211 | return -EINVAL; |
| 2212 | } |
| 2213 | sprintf(prim_busid, "%01x.%01x.%04x", id0, id1, id2); |
| 2214 | if (dasd_busid(secondary, &id0, &id1, &id2)) { |
| 2215 | kfree(pt); |
| 2216 | return -EINVAL; |
| 2217 | } |
| 2218 | sprintf(sec_busid, "%01x.%01x.%04x", id0, id1, id2); |
| 2219 | kfree(pt); |
| 2220 | |
| 2221 | return 0; |
| 2222 | } |
| 2223 | |
| 2224 | static ssize_t dasd_copy_pair_store(struct device *dev, |
| 2225 | struct device_attribute *attr, |
| 2226 | const char *buf, size_t count) |
| 2227 | { |
| 2228 | struct dasd_devmap *prim_devmap, *sec_devmap; |
| 2229 | char prim_busid[DASD_BUS_ID_SIZE]; |
| 2230 | char sec_busid[DASD_BUS_ID_SIZE]; |
| 2231 | struct dasd_copy_relation *copy; |
| 2232 | struct dasd_device *device; |
| 2233 | bool pprc_enabled; |
| 2234 | int rc; |
| 2235 | |
| 2236 | if (strncmp(buf, "clear", strlen("clear")) == 0) { |
| 2237 | if (dasd_devmap_clear_copy_relation(dev)) |
| 2238 | return -EINVAL; |
| 2239 | return count; |
| 2240 | } |
| 2241 | |
| 2242 | rc = dasd_devmap_parse_busid(buf, prim_busid, sec_busid); |
| 2243 | if (rc) |
| 2244 | return rc; |
| 2245 | |
| 2246 | if (strncmp(dev_name(dev), prim_busid, DASD_BUS_ID_SIZE) != 0 && |
| 2247 | strncmp(dev_name(dev), sec_busid, DASD_BUS_ID_SIZE) != 0) |
| 2248 | return -EINVAL; |
| 2249 | |
| 2250 | /* allocate primary devmap if needed */ |
| 2251 | prim_devmap = dasd_find_busid(prim_busid); |
| 2252 | if (IS_ERR(prim_devmap)) { |
| 2253 | prim_devmap = dasd_add_busid(prim_busid, DASD_FEATURE_DEFAULT); |
| 2254 | if (IS_ERR(prim_devmap)) |
| 2255 | return PTR_ERR(prim_devmap); |
| 2256 | } |
| 2257 | |
| 2258 | /* allocate secondary devmap if needed */ |
| 2259 | sec_devmap = dasd_find_busid(sec_busid); |
| 2260 | if (IS_ERR(sec_devmap)) { |
| 2261 | sec_devmap = dasd_add_busid(sec_busid, DASD_FEATURE_DEFAULT); |
| 2262 | if (IS_ERR(sec_devmap)) |
| 2263 | return PTR_ERR(sec_devmap); |
| 2264 | } |
| 2265 | |
| 2266 | /* setting copy relation is only allowed for offline secondary */ |
| 2267 | if (sec_devmap->device) |
| 2268 | return -EINVAL; |
| 2269 | |
| 2270 | if (prim_devmap->copy) { |
| 2271 | copy = prim_devmap->copy; |
| 2272 | } else if (sec_devmap->copy) { |
| 2273 | copy = sec_devmap->copy; |
| 2274 | } else { |
| 2275 | copy = kzalloc(sizeof(*copy), GFP_KERNEL); |
| 2276 | if (!copy) |
| 2277 | return -ENOMEM; |
| 2278 | } |
| 2279 | spin_lock(&dasd_devmap_lock); |
| 2280 | rc = dasd_devmap_set_copy_relation(prim_devmap, copy, prim_busid, true); |
| 2281 | if (rc) { |
| 2282 | spin_unlock(&dasd_devmap_lock); |
| 2283 | return rc; |
| 2284 | } |
| 2285 | rc = dasd_devmap_set_copy_relation(sec_devmap, copy, sec_busid, false); |
| 2286 | if (rc) { |
| 2287 | spin_unlock(&dasd_devmap_lock); |
| 2288 | return rc; |
| 2289 | } |
| 2290 | spin_unlock(&dasd_devmap_lock); |
| 2291 | |
| 2292 | /* if primary device is already online call device setup directly */ |
| 2293 | if (prim_devmap->device && !prim_devmap->device->copy) { |
| 2294 | device = prim_devmap->device; |
| 2295 | if (device->discipline->pprc_enabled) { |
| 2296 | pprc_enabled = device->discipline->pprc_enabled(device); |
| 2297 | rc = dasd_devmap_set_device_copy_relation(device->cdev, |
| 2298 | pprc_enabled); |
| 2299 | } else { |
| 2300 | rc = -EOPNOTSUPP; |
| 2301 | } |
| 2302 | } |
| 2303 | if (rc) { |
| 2304 | dasd_devmap_del_copy_relation(copy, prim_busid); |
| 2305 | dasd_devmap_del_copy_relation(copy, sec_busid); |
| 2306 | count = rc; |
| 2307 | } |
| 2308 | |
| 2309 | return count; |
| 2310 | } |
| 2311 | static DEVICE_ATTR(copy_pair, 0644, dasd_copy_pair_show, |
| 2312 | dasd_copy_pair_store); |
| 2313 | |
| 2314 | static ssize_t |
| 2315 | dasd_copy_role_show(struct device *dev, |
| 2316 | struct device_attribute *attr, char *buf) |
| 2317 | { |
| 2318 | struct dasd_copy_relation *copy; |
| 2319 | struct dasd_device *device; |
| 2320 | int len, i; |
| 2321 | |
| 2322 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 2323 | if (IS_ERR(device)) |
| 2324 | return -ENODEV; |
| 2325 | |
| 2326 | if (!device->copy) { |
| 2327 | len = sysfs_emit(buf, "none\n"); |
| 2328 | goto out; |
| 2329 | } |
| 2330 | copy = device->copy; |
| 2331 | /* only the active device is primary */ |
| 2332 | if (copy->active->device == device) { |
| 2333 | len = sysfs_emit(buf, "primary\n"); |
| 2334 | goto out; |
| 2335 | } |
| 2336 | for (i = 0; i < DASD_CP_ENTRIES; i++) { |
| 2337 | if (copy->entry[i].device == device) { |
| 2338 | len = sysfs_emit(buf, "secondary\n"); |
| 2339 | goto out; |
| 2340 | } |
| 2341 | } |
| 2342 | /* not in the list, no COPY role */ |
| 2343 | len = sysfs_emit(buf, "none\n"); |
| 2344 | out: |
| 2345 | dasd_put_device(device); |
| 2346 | return len; |
| 2347 | } |
| 2348 | static DEVICE_ATTR(copy_role, 0444, dasd_copy_role_show, NULL); |
| 2349 | |
| 2350 | static ssize_t dasd_device_ping(struct device *dev, |
| 2351 | struct device_attribute *attr, |
| 2352 | const char *buf, size_t count) |
| 2353 | { |
| 2354 | struct dasd_device *device; |
| 2355 | size_t rc; |
| 2356 | |
| 2357 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
| 2358 | if (IS_ERR(device)) |
| 2359 | return -ENODEV; |
| 2360 | |
| 2361 | /* |
| 2362 | * do not try during offline processing |
| 2363 | * early check only |
| 2364 | * the sleep_on function itself checks for offline |
| 2365 | * processing again |
| 2366 | */ |
| 2367 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) { |
| 2368 | rc = -EBUSY; |
| 2369 | goto out; |
| 2370 | } |
| 2371 | if (!device->discipline || !device->discipline->device_ping) { |
| 2372 | rc = -EOPNOTSUPP; |
| 2373 | goto out; |
| 2374 | } |
| 2375 | rc = device->discipline->device_ping(device); |
| 2376 | if (!rc) |
| 2377 | rc = count; |
| 2378 | out: |
| 2379 | dasd_put_device(device); |
| 2380 | return rc; |
| 2381 | } |
| 2382 | static DEVICE_ATTR(ping, 0200, NULL, dasd_device_ping); |
| 2383 | |
| 2384 | #define DASD_DEFINE_ATTR(_name, _func) \ |
| 2385 | static ssize_t dasd_##_name##_show(struct device *dev, \ |
| 2386 | struct device_attribute *attr, \ |
| 2387 | char *buf) \ |
| 2388 | { \ |
| 2389 | struct ccw_device *cdev = to_ccwdev(dev); \ |
| 2390 | struct dasd_device *device = dasd_device_from_cdev(cdev); \ |
| 2391 | int val = 0; \ |
| 2392 | \ |
| 2393 | if (IS_ERR(device)) \ |
| 2394 | return -ENODEV; \ |
| 2395 | if (device->discipline && _func) \ |
| 2396 | val = _func(device); \ |
| 2397 | dasd_put_device(device); \ |
| 2398 | \ |
| 2399 | return sysfs_emit(buf, "%d\n", val); \ |
| 2400 | } \ |
| 2401 | static DEVICE_ATTR(_name, 0444, dasd_##_name##_show, NULL); \ |
| 2402 | |
| 2403 | DASD_DEFINE_ATTR(ese, device->discipline->is_ese); |
| 2404 | DASD_DEFINE_ATTR(extent_size, device->discipline->ext_size); |
| 2405 | DASD_DEFINE_ATTR(pool_id, device->discipline->ext_pool_id); |
| 2406 | DASD_DEFINE_ATTR(space_configured, device->discipline->space_configured); |
| 2407 | DASD_DEFINE_ATTR(space_allocated, device->discipline->space_allocated); |
| 2408 | DASD_DEFINE_ATTR(logical_capacity, device->discipline->logical_capacity); |
| 2409 | DASD_DEFINE_ATTR(warn_threshold, device->discipline->ext_pool_warn_thrshld); |
| 2410 | DASD_DEFINE_ATTR(cap_at_warnlevel, device->discipline->ext_pool_cap_at_warnlevel); |
| 2411 | DASD_DEFINE_ATTR(pool_oos, device->discipline->ext_pool_oos); |
| 2412 | |
| 2413 | static struct attribute * dasd_attrs[] = { |
| 2414 | &dev_attr_readonly.attr, |
| 2415 | &dev_attr_discipline.attr, |
| 2416 | &dev_attr_status.attr, |
| 2417 | &dev_attr_alias.attr, |
| 2418 | &dev_attr_vendor.attr, |
| 2419 | &dev_attr_uid.attr, |
| 2420 | &dev_attr_use_diag.attr, |
| 2421 | &dev_attr_raw_track_access.attr, |
| 2422 | &dev_attr_eer_enabled.attr, |
| 2423 | &dev_attr_erplog.attr, |
| 2424 | &dev_attr_failfast.attr, |
| 2425 | &dev_attr_expires.attr, |
| 2426 | &dev_attr_retries.attr, |
| 2427 | &dev_attr_timeout.attr, |
| 2428 | &dev_attr_reservation_policy.attr, |
| 2429 | &dev_attr_last_known_reservation_state.attr, |
| 2430 | &dev_attr_safe_offline.attr, |
| 2431 | &dev_attr_host_access_count.attr, |
| 2432 | &dev_attr_path_masks.attr, |
| 2433 | &dev_attr_path_threshold.attr, |
| 2434 | &dev_attr_path_autodisable.attr, |
| 2435 | &dev_attr_path_interval.attr, |
| 2436 | &dev_attr_path_reset.attr, |
| 2437 | &dev_attr_hpf.attr, |
| 2438 | &dev_attr_ese.attr, |
| 2439 | &dev_attr_fc_security.attr, |
| 2440 | &dev_attr_copy_pair.attr, |
| 2441 | &dev_attr_copy_role.attr, |
| 2442 | &dev_attr_ping.attr, |
| 2443 | &dev_attr_aq_mask.attr, |
| 2444 | &dev_attr_aq_requeue.attr, |
| 2445 | &dev_attr_aq_timeouts.attr, |
| 2446 | NULL, |
| 2447 | }; |
| 2448 | |
| 2449 | static const struct attribute_group dasd_attr_group = { |
| 2450 | .attrs = dasd_attrs, |
| 2451 | }; |
| 2452 | |
| 2453 | static struct attribute *capacity_attrs[] = { |
| 2454 | &dev_attr_space_configured.attr, |
| 2455 | &dev_attr_space_allocated.attr, |
| 2456 | &dev_attr_logical_capacity.attr, |
| 2457 | NULL, |
| 2458 | }; |
| 2459 | |
| 2460 | static const struct attribute_group capacity_attr_group = { |
| 2461 | .name = "capacity", |
| 2462 | .attrs = capacity_attrs, |
| 2463 | }; |
| 2464 | |
| 2465 | static struct attribute *ext_pool_attrs[] = { |
| 2466 | &dev_attr_pool_id.attr, |
| 2467 | &dev_attr_extent_size.attr, |
| 2468 | &dev_attr_warn_threshold.attr, |
| 2469 | &dev_attr_cap_at_warnlevel.attr, |
| 2470 | &dev_attr_pool_oos.attr, |
| 2471 | NULL, |
| 2472 | }; |
| 2473 | |
| 2474 | static const struct attribute_group ext_pool_attr_group = { |
| 2475 | .name = "extent_pool", |
| 2476 | .attrs = ext_pool_attrs, |
| 2477 | }; |
| 2478 | |
| 2479 | const struct attribute_group *dasd_dev_groups[] = { |
| 2480 | &dasd_attr_group, |
| 2481 | &capacity_attr_group, |
| 2482 | &ext_pool_attr_group, |
| 2483 | NULL, |
| 2484 | }; |
| 2485 | EXPORT_SYMBOL_GPL(dasd_dev_groups); |
| 2486 | |
| 2487 | /* |
| 2488 | * Return value of the specified feature. |
| 2489 | */ |
| 2490 | int |
| 2491 | dasd_get_feature(struct ccw_device *cdev, int feature) |
| 2492 | { |
| 2493 | struct dasd_devmap *devmap; |
| 2494 | |
| 2495 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
| 2496 | if (IS_ERR(devmap)) |
| 2497 | return PTR_ERR(devmap); |
| 2498 | |
| 2499 | return ((devmap->features & feature) != 0); |
| 2500 | } |
| 2501 | |
| 2502 | /* |
| 2503 | * Set / reset given feature. |
| 2504 | * Flag indicates whether to set (!=0) or the reset (=0) the feature. |
| 2505 | */ |
| 2506 | int |
| 2507 | dasd_set_feature(struct ccw_device *cdev, int feature, int flag) |
| 2508 | { |
| 2509 | struct dasd_devmap *devmap; |
| 2510 | |
| 2511 | devmap = dasd_devmap_from_cdev(cdev); |
| 2512 | if (IS_ERR(devmap)) |
| 2513 | return PTR_ERR(devmap); |
| 2514 | |
| 2515 | spin_lock(&dasd_devmap_lock); |
| 2516 | if (flag) |
| 2517 | devmap->features |= feature; |
| 2518 | else |
| 2519 | devmap->features &= ~feature; |
| 2520 | if (devmap->device) |
| 2521 | devmap->device->features = devmap->features; |
| 2522 | spin_unlock(&dasd_devmap_lock); |
| 2523 | return 0; |
| 2524 | } |
| 2525 | EXPORT_SYMBOL(dasd_set_feature); |
| 2526 | |
| 2527 | static struct attribute *paths_info_attrs[] = { |
| 2528 | &path_fcs_attribute.attr, |
| 2529 | NULL, |
| 2530 | }; |
| 2531 | ATTRIBUTE_GROUPS(paths_info); |
| 2532 | |
| 2533 | static struct kobj_type path_attr_type = { |
| 2534 | .release = dasd_path_release, |
| 2535 | .default_groups = paths_info_groups, |
| 2536 | .sysfs_ops = &kobj_sysfs_ops, |
| 2537 | }; |
| 2538 | |
| 2539 | static void dasd_path_init_kobj(struct dasd_device *device, int chp) |
| 2540 | { |
| 2541 | device->path[chp].kobj.kset = device->paths_info; |
| 2542 | kobject_init(&device->path[chp].kobj, &path_attr_type); |
| 2543 | } |
| 2544 | |
| 2545 | void dasd_path_create_kobj(struct dasd_device *device, int chp) |
| 2546 | { |
| 2547 | int rc; |
| 2548 | |
| 2549 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) |
| 2550 | return; |
| 2551 | if (!device->paths_info) { |
| 2552 | dev_warn(&device->cdev->dev, "Unable to create paths objects\n"); |
| 2553 | return; |
| 2554 | } |
| 2555 | if (device->path[chp].in_sysfs) |
| 2556 | return; |
| 2557 | if (!device->path[chp].conf_data) |
| 2558 | return; |
| 2559 | |
| 2560 | dasd_path_init_kobj(device, chp); |
| 2561 | |
| 2562 | rc = kobject_add(&device->path[chp].kobj, NULL, "%x.%02x", |
| 2563 | device->path[chp].cssid, device->path[chp].chpid); |
| 2564 | if (rc) |
| 2565 | kobject_put(&device->path[chp].kobj); |
| 2566 | device->path[chp].in_sysfs = true; |
| 2567 | } |
| 2568 | EXPORT_SYMBOL(dasd_path_create_kobj); |
| 2569 | |
| 2570 | void dasd_path_create_kobjects(struct dasd_device *device) |
| 2571 | { |
| 2572 | u8 lpm, opm; |
| 2573 | |
| 2574 | opm = dasd_path_get_opm(device); |
| 2575 | for (lpm = 0x80; lpm; lpm >>= 1) { |
| 2576 | if (!(lpm & opm)) |
| 2577 | continue; |
| 2578 | dasd_path_create_kobj(device, pathmask_to_pos(lpm)); |
| 2579 | } |
| 2580 | } |
| 2581 | EXPORT_SYMBOL(dasd_path_create_kobjects); |
| 2582 | |
| 2583 | static void dasd_path_remove_kobj(struct dasd_device *device, int chp) |
| 2584 | { |
| 2585 | if (device->path[chp].in_sysfs) { |
| 2586 | kobject_put(&device->path[chp].kobj); |
| 2587 | device->path[chp].in_sysfs = false; |
| 2588 | } |
| 2589 | } |
| 2590 | |
| 2591 | /* |
| 2592 | * As we keep kobjects for the lifetime of a device, this function must not be |
| 2593 | * called anywhere but in the context of offlining a device. |
| 2594 | */ |
| 2595 | void dasd_path_remove_kobjects(struct dasd_device *device) |
| 2596 | { |
| 2597 | int i; |
| 2598 | |
| 2599 | for (i = 0; i < 8; i++) |
| 2600 | dasd_path_remove_kobj(device, i); |
| 2601 | } |
| 2602 | EXPORT_SYMBOL(dasd_path_remove_kobjects); |
| 2603 | |
| 2604 | int |
| 2605 | dasd_devmap_init(void) |
| 2606 | { |
| 2607 | int i; |
| 2608 | |
| 2609 | /* Initialize devmap structures. */ |
| 2610 | dasd_max_devindex = 0; |
| 2611 | for (i = 0; i < 256; i++) |
| 2612 | INIT_LIST_HEAD(&dasd_hashlists[i]); |
| 2613 | return 0; |
| 2614 | } |
| 2615 | |
| 2616 | void |
| 2617 | dasd_devmap_exit(void) |
| 2618 | { |
| 2619 | dasd_forget_ranges(); |
| 2620 | } |