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