1 // SPDX-License-Identifier: GPL-2.0
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
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.
16 #define KMSG_COMPONENT "dasd"
18 #include <linux/ctype.h>
19 #include <linux/init.h>
20 #include <linux/module.h>
21 #include <linux/slab.h>
23 #include <asm/debug.h>
24 #include <linux/uaccess.h>
28 #define PRINTK_HEADER "dasd_devmap:"
29 #define DASD_MAX_PARAMS 256
33 struct kmem_cache *dasd_page_cache;
34 EXPORT_SYMBOL_GPL(dasd_page_cache);
37 * dasd_devmap_t is used to store the features and the relation
38 * between device number and device index. To find a dasd_devmap_t
39 * that corresponds to a device number of a device index each
40 * dasd_devmap_t is added to two linked lists, one to search by
41 * the device number and one to search by the device index. As
42 * soon as big minor numbers are available the device index list
43 * can be removed since the device number will then be identical
44 * to the device index.
47 struct list_head list;
48 char bus_id[DASD_BUS_ID_SIZE];
49 unsigned int devindex;
50 unsigned short features;
51 struct dasd_device *device;
52 struct dasd_copy_relation *copy;
56 * Parameter parsing functions for dasd= parameter. The syntax is:
57 * <devno> : (0x)?[0-9a-fA-F]+
58 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
60 * <feature_list> : \(<feature>(:<feature>)*\)
61 * <devno-range> : <devno>(-<devno>)?<feature_list>?
62 * <busid-range> : <busid>(-<busid>)?<feature_list>?
63 * <devices> : <devno-range>|<busid-range>
64 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
66 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
69 int dasd_probeonly = 0; /* is true, when probeonly mode is active */
70 int dasd_autodetect = 0; /* is true, when autodetection is active */
71 int dasd_nopav = 0; /* is true, when PAV is disabled */
72 EXPORT_SYMBOL_GPL(dasd_nopav);
73 int dasd_nofcx; /* disable High Performance Ficon */
74 EXPORT_SYMBOL_GPL(dasd_nofcx);
77 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
78 * it is named 'dasd' to directly be filled by insmod with the comma separated
79 * strings when running as a module.
81 static char *dasd[DASD_MAX_PARAMS];
82 module_param_array(dasd, charp, NULL, S_IRUGO);
85 * Single spinlock to protect devmap and servermap structures and lists.
87 static DEFINE_SPINLOCK(dasd_devmap_lock);
90 * Hash lists for devmap structures.
92 static struct list_head dasd_hashlists[256];
93 int dasd_max_devindex;
95 static struct dasd_devmap *dasd_add_busid(const char *, int);
98 dasd_hash_busid(const char *bus_id)
103 for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++)
109 static int __init dasd_call_setup(char *opt)
111 static int i __initdata;
114 while (i < DASD_MAX_PARAMS) {
115 tmp = strsep(&opt, ",");
125 __setup ("dasd=", dasd_call_setup);
126 #endif /* #ifndef MODULE */
128 #define DASD_IPLDEV "ipldev"
131 * Read a device busid/devno from a string.
133 static int dasd_busid(char *str, int *id0, int *id1, int *devno)
138 /* Interpret ipldev busid */
139 if (strncmp(DASD_IPLDEV, str, strlen(DASD_IPLDEV)) == 0) {
140 if (ipl_info.type != IPL_TYPE_CCW) {
141 pr_err("The IPL device is not a CCW device\n");
145 *id1 = ipl_info.data.ccw.dev_id.ssid;
146 *devno = ipl_info.data.ccw.dev_id.devno;
151 /* Old style 0xXXXX or XXXX */
152 if (!kstrtouint(str, 16, &val)) {
160 /* New style x.y.z busid */
161 tok = strsep(&str, ".");
162 if (kstrtouint(tok, 16, &val) || val > 0xff)
166 tok = strsep(&str, ".");
167 if (kstrtouint(tok, 16, &val) || val > 0xff)
171 tok = strsep(&str, ".");
172 if (kstrtouint(tok, 16, &val) || val > 0xffff)
180 * Read colon separated list of dasd features.
182 static int __init dasd_feature_list(char *str)
184 int features, len, rc;
190 return DASD_FEATURE_DEFAULT;
194 str[len] && str[len] != ':' && str[len] != ')'; len++);
195 if (len == 2 && !strncmp(str, "ro", 2))
196 features |= DASD_FEATURE_READONLY;
197 else if (len == 4 && !strncmp(str, "diag", 4))
198 features |= DASD_FEATURE_USEDIAG;
199 else if (len == 3 && !strncmp(str, "raw", 3))
200 features |= DASD_FEATURE_USERAW;
201 else if (len == 6 && !strncmp(str, "erplog", 6))
202 features |= DASD_FEATURE_ERPLOG;
203 else if (len == 8 && !strncmp(str, "failfast", 8))
204 features |= DASD_FEATURE_FAILFAST;
206 pr_warn("%.*s is not a supported device option\n",
216 return rc ? : features;
220 * Try to match the first element on the comma separated parse string
221 * with one of the known keywords. If a keyword is found, take the approprate
222 * action and return a pointer to the residual string. If the first element
223 * could not be matched to any keyword then return an error code.
225 static int __init dasd_parse_keyword(char *keyword)
227 int length = strlen(keyword);
229 if (strncmp("autodetect", keyword, length) == 0) {
231 pr_info("The autodetection mode has been activated\n");
234 if (strncmp("probeonly", keyword, length) == 0) {
236 pr_info("The probeonly mode has been activated\n");
239 if (strncmp("nopav", keyword, length) == 0) {
241 pr_info("'nopav' is not supported on z/VM\n");
244 pr_info("PAV support has be deactivated\n");
248 if (strncmp("nofcx", keyword, length) == 0) {
250 pr_info("High Performance FICON support has been "
254 if (strncmp("fixedbuffers", keyword, length) == 0) {
258 kmem_cache_create("dasd_page_cache", PAGE_SIZE,
259 PAGE_SIZE, SLAB_CACHE_DMA,
261 if (!dasd_page_cache)
262 DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, "
263 "fixed buffer mode disabled.");
265 DBF_EVENT(DBF_INFO, "%s",
266 "turning on fixed buffer mode");
274 * Split a string of a device range into its pieces and return the from, to, and
275 * feature parts separately.
277 * 0.0.1234-0.0.5678(ro:erplog) -> from: 0.0.1234 to: 0.0.5678 features: ro:erplog
278 * 0.0.8765(raw) -> from: 0.0.8765 to: null features: raw
279 * 0x4321 -> from: 0x4321 to: null features: null
281 static int __init dasd_evaluate_range_param(char *range, char **from_str,
282 char **to_str, char **features_str)
286 /* Do we have a range or a single device? */
287 if (strchr(range, '-')) {
288 *from_str = strsep(&range, "-");
289 *to_str = strsep(&range, "(");
290 *features_str = strsep(&range, ")");
292 *from_str = strsep(&range, "(");
293 *features_str = strsep(&range, ")");
296 if (*features_str && !range) {
297 pr_warn("A closing parenthesis ')' is missing in the dasd= parameter\n");
305 * Try to interprete the range string as a device number or a range of devices.
306 * If the interpretation is successful, create the matching dasd_devmap entries.
307 * If interpretation fails or in case of an error, return an error code.
309 static int __init dasd_parse_range(const char *range)
311 struct dasd_devmap *devmap;
312 int from, from_id0, from_id1;
313 int to, to_id0, to_id1;
315 char bus_id[DASD_BUS_ID_SIZE + 1];
316 char *features_str = NULL;
317 char *from_str = NULL;
322 tmp = kstrdup(range, GFP_KERNEL);
326 if (dasd_evaluate_range_param(tmp, &from_str, &to_str, &features_str)) {
331 if (dasd_busid(from_str, &from_id0, &from_id1, &from)) {
340 if (dasd_busid(to_str, &to_id0, &to_id1, &to)) {
344 if (from_id0 != to_id0 || from_id1 != to_id1 || from > to) {
345 pr_err("%s is not a valid device range\n", range);
351 features = dasd_feature_list(features_str);
356 /* each device in dasd= parameter should be set initially online */
357 features |= DASD_FEATURE_INITIAL_ONLINE;
359 sprintf(bus_id, "%01x.%01x.%04x", from_id0, from_id1, from++);
360 devmap = dasd_add_busid(bus_id, features);
361 if (IS_ERR(devmap)) {
362 rc = PTR_ERR(devmap);
374 * Parse parameters stored in dasd[]
375 * The 'dasd=...' parameter allows to specify a comma separated list of
376 * keywords and device ranges. The parameters in that list will be stored as
377 * separate elementes in dasd[].
379 int __init dasd_parse(void)
385 for (i = 0; i < DASD_MAX_PARAMS; i++) {
392 rc = dasd_parse_keyword(cur);
394 rc = dasd_parse_range(cur);
404 * Add a devmap for the device specified by busid. It is possible that
405 * the devmap already exists (dasd= parameter). The order of the devices
406 * added through this function will define the kdevs for the individual
409 static struct dasd_devmap *
410 dasd_add_busid(const char *bus_id, int features)
412 struct dasd_devmap *devmap, *new, *tmp;
415 new = kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
417 return ERR_PTR(-ENOMEM);
418 spin_lock(&dasd_devmap_lock);
420 hash = dasd_hash_busid(bus_id);
421 list_for_each_entry(tmp, &dasd_hashlists[hash], list)
422 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
427 /* This bus_id is new. */
428 new->devindex = dasd_max_devindex++;
429 strscpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
430 new->features = features;
432 list_add(&new->list, &dasd_hashlists[hash]);
436 spin_unlock(&dasd_devmap_lock);
441 static struct dasd_devmap *
442 dasd_find_busid_locked(const char *bus_id)
444 struct dasd_devmap *devmap, *tmp;
447 devmap = ERR_PTR(-ENODEV);
448 hash = dasd_hash_busid(bus_id);
449 list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
450 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
459 * Find devmap for device with given bus_id.
461 static struct dasd_devmap *
462 dasd_find_busid(const char *bus_id)
464 struct dasd_devmap *devmap;
466 spin_lock(&dasd_devmap_lock);
467 devmap = dasd_find_busid_locked(bus_id);
468 spin_unlock(&dasd_devmap_lock);
473 * Check if busid has been added to the list of dasd ranges.
476 dasd_busid_known(const char *bus_id)
478 return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
482 * Forget all about the device numbers added so far.
483 * This may only be called at module unload or system shutdown.
486 dasd_forget_ranges(void)
488 struct dasd_devmap *devmap, *n;
491 spin_lock(&dasd_devmap_lock);
492 for (i = 0; i < 256; i++) {
493 list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
494 BUG_ON(devmap->device != NULL);
495 list_del(&devmap->list);
499 spin_unlock(&dasd_devmap_lock);
503 * Find the device struct by its device index.
506 dasd_device_from_devindex(int devindex)
508 struct dasd_devmap *devmap, *tmp;
509 struct dasd_device *device;
512 spin_lock(&dasd_devmap_lock);
514 for (i = 0; (i < 256) && !devmap; i++)
515 list_for_each_entry(tmp, &dasd_hashlists[i], list)
516 if (tmp->devindex == devindex) {
517 /* Found the devmap for the device. */
521 if (devmap && devmap->device) {
522 device = devmap->device;
523 dasd_get_device(device);
525 device = ERR_PTR(-ENODEV);
526 spin_unlock(&dasd_devmap_lock);
531 * Return devmap for cdev. If no devmap exists yet, create one and
532 * connect it to the cdev.
534 static struct dasd_devmap *
535 dasd_devmap_from_cdev(struct ccw_device *cdev)
537 struct dasd_devmap *devmap;
539 devmap = dasd_find_busid(dev_name(&cdev->dev));
541 devmap = dasd_add_busid(dev_name(&cdev->dev),
542 DASD_FEATURE_DEFAULT);
547 * Create a dasd device structure for cdev.
550 dasd_create_device(struct ccw_device *cdev)
552 struct dasd_devmap *devmap;
553 struct dasd_device *device;
557 devmap = dasd_devmap_from_cdev(cdev);
559 return (void *) devmap;
561 device = dasd_alloc_device();
564 atomic_set(&device->ref_count, 3);
566 spin_lock(&dasd_devmap_lock);
567 if (!devmap->device) {
568 devmap->device = device;
569 device->devindex = devmap->devindex;
570 device->features = devmap->features;
571 get_device(&cdev->dev);
575 /* Someone else was faster. */
577 spin_unlock(&dasd_devmap_lock);
580 dasd_free_device(device);
584 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
585 dev_set_drvdata(&cdev->dev, device);
586 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
588 device->paths_info = kset_create_and_add("paths_info", NULL,
589 &device->cdev->dev.kobj);
590 if (!device->paths_info)
591 dev_warn(&cdev->dev, "Could not create paths_info kset\n");
597 * allocate a PPRC data structure and call the discipline function to fill
599 static int dasd_devmap_get_pprc_status(struct dasd_device *device,
600 struct dasd_pprc_data_sc4 **data)
602 struct dasd_pprc_data_sc4 *temp;
604 if (!device->discipline || !device->discipline->pprc_status) {
605 dev_warn(&device->cdev->dev, "Unable to query copy relation status\n");
608 temp = kzalloc(sizeof(*temp), GFP_KERNEL);
612 /* get PPRC information from storage */
613 if (device->discipline->pprc_status(device, temp)) {
614 dev_warn(&device->cdev->dev, "Error during copy relation status query\n");
624 * find an entry in a PPRC device_info array by a given UID
625 * depending on the primary/secondary state of the device it has to be
626 * matched with the respective fields
628 static int dasd_devmap_entry_from_pprc_data(struct dasd_pprc_data_sc4 *data,
634 for (i = 0; i < DASD_CP_ENTRIES; i++) {
636 if (data->dev_info[i].prim_cu_ssid == uid.ssid &&
637 data->dev_info[i].primary == uid.real_unit_addr)
640 if (data->dev_info[i].sec_cu_ssid == uid.ssid &&
641 data->dev_info[i].secondary == uid.real_unit_addr)
649 * check the consistency of a specified copy relation by checking
650 * the following things:
652 * - is the given device part of a copy pair setup
653 * - does the state of the device match the state in the PPRC status data
654 * - does the device UID match with the UID in the PPRC status data
655 * - to prevent misrouted IO check if the given device is present in all
656 * related PPRC status data
658 static int dasd_devmap_check_copy_relation(struct dasd_device *device,
659 struct dasd_copy_entry *entry,
660 struct dasd_pprc_data_sc4 *data,
661 struct dasd_copy_relation *copy)
663 struct dasd_pprc_data_sc4 *tmp_dat;
664 struct dasd_device *tmp_dev;
668 if (!device->discipline || !device->discipline->get_uid ||
669 device->discipline->get_uid(device, &uid))
672 i = dasd_devmap_entry_from_pprc_data(data, uid, entry->primary);
674 dev_warn(&device->cdev->dev, "Device not part of a copy relation\n");
678 /* double check which role the current device has */
679 if (entry->primary) {
680 if (data->dev_info[i].flags & 0x80) {
681 dev_warn(&device->cdev->dev, "Copy pair secondary is setup as primary\n");
684 if (data->dev_info[i].prim_cu_ssid != uid.ssid ||
685 data->dev_info[i].primary != uid.real_unit_addr) {
686 dev_warn(&device->cdev->dev,
687 "Primary device %s does not match copy pair status primary device %04x\n",
688 dev_name(&device->cdev->dev),
689 data->dev_info[i].prim_cu_ssid |
690 data->dev_info[i].primary);
694 if (!(data->dev_info[i].flags & 0x80)) {
695 dev_warn(&device->cdev->dev, "Copy pair primary is setup as secondary\n");
698 if (data->dev_info[i].sec_cu_ssid != uid.ssid ||
699 data->dev_info[i].secondary != uid.real_unit_addr) {
700 dev_warn(&device->cdev->dev,
701 "Secondary device %s does not match copy pair status secondary device %04x\n",
702 dev_name(&device->cdev->dev),
703 data->dev_info[i].sec_cu_ssid |
704 data->dev_info[i].secondary);
710 * the current device has to be part of the copy relation of all
711 * entries to prevent misrouted IO to another copy pair
713 for (j = 0; j < DASD_CP_ENTRIES; j++) {
714 if (entry == ©->entry[j])
717 tmp_dev = copy->entry[j].device;
722 if (dasd_devmap_get_pprc_status(tmp_dev, &tmp_dat))
725 if (dasd_devmap_entry_from_pprc_data(tmp_dat, uid, entry->primary) < 0) {
726 dev_warn(&tmp_dev->cdev->dev,
727 "Copy pair relation does not contain device: %s\n",
728 dev_name(&device->cdev->dev));
737 /* delete device from copy relation entry */
738 static void dasd_devmap_delete_copy_relation_device(struct dasd_device *device)
740 struct dasd_copy_relation *copy;
747 for (i = 0; i < DASD_CP_ENTRIES; i++) {
748 if (copy->entry[i].device == device)
749 copy->entry[i].device = NULL;
751 dasd_put_device(device);
756 * read all required information for a copy relation setup and setup the device
759 int dasd_devmap_set_device_copy_relation(struct ccw_device *cdev,
762 struct dasd_pprc_data_sc4 *data = NULL;
763 struct dasd_copy_entry *entry = NULL;
764 struct dasd_copy_relation *copy;
765 struct dasd_devmap *devmap;
766 struct dasd_device *device;
769 devmap = dasd_devmap_from_cdev(cdev);
771 return PTR_ERR(devmap);
773 device = devmap->device;
778 /* no copy pair setup for this device */
782 rc = dasd_devmap_get_pprc_status(device, &data);
786 /* print error if PPRC is requested but not enabled on storage server */
788 dev_err(&cdev->dev, "Copy relation not enabled on storage server\n");
793 if (!data->dev_info[0].state) {
794 dev_warn(&device->cdev->dev, "Copy pair setup requested for device not in copy relation\n");
799 for (i = 0; i < DASD_CP_ENTRIES; i++) {
800 if (copy->entry[i].configured &&
801 strncmp(dev_name(&cdev->dev),
802 copy->entry[i].busid, DASD_BUS_ID_SIZE) == 0) {
803 entry = ©->entry[i];
808 dev_warn(&device->cdev->dev, "Copy relation entry not found\n");
812 /* check if the copy relation is valid */
813 if (dasd_devmap_check_copy_relation(device, entry, data, copy)) {
814 dev_warn(&device->cdev->dev, "Copy relation faulty\n");
819 dasd_get_device(device);
820 copy->entry[i].device = device;
826 EXPORT_SYMBOL_GPL(dasd_devmap_set_device_copy_relation);
829 * Wait queue for dasd_delete_device waits.
831 static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
834 * Remove a dasd device structure. The passed referenced
838 dasd_delete_device(struct dasd_device *device)
840 struct ccw_device *cdev;
841 struct dasd_devmap *devmap;
844 /* First remove device pointer from devmap. */
845 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
846 BUG_ON(IS_ERR(devmap));
847 spin_lock(&dasd_devmap_lock);
848 if (devmap->device != device) {
849 spin_unlock(&dasd_devmap_lock);
850 dasd_put_device(device);
853 devmap->device = NULL;
854 spin_unlock(&dasd_devmap_lock);
856 /* Disconnect dasd_device structure from ccw_device structure. */
857 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
858 dev_set_drvdata(&device->cdev->dev, NULL);
859 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
861 /* Removve copy relation */
862 dasd_devmap_delete_copy_relation_device(device);
864 * Drop ref_count by 3, one for the devmap reference, one for
865 * the cdev reference and one for the passed reference.
867 atomic_sub(3, &device->ref_count);
869 /* Wait for reference counter to drop to zero. */
870 wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
872 dasd_generic_free_discipline(device);
874 kset_unregister(device->paths_info);
876 /* Disconnect dasd_device structure from ccw_device structure. */
880 /* Put ccw_device structure. */
881 put_device(&cdev->dev);
883 /* Now the device structure can be freed. */
884 dasd_free_device(device);
888 * Reference counter dropped to zero. Wake up waiter
889 * in dasd_delete_device.
892 dasd_put_device_wake(struct dasd_device *device)
894 wake_up(&dasd_delete_wq);
896 EXPORT_SYMBOL_GPL(dasd_put_device_wake);
899 * Return dasd_device structure associated with cdev.
900 * This function needs to be called with the ccw device
901 * lock held. It can be used from interrupt context.
904 dasd_device_from_cdev_locked(struct ccw_device *cdev)
906 struct dasd_device *device = dev_get_drvdata(&cdev->dev);
909 return ERR_PTR(-ENODEV);
910 dasd_get_device(device);
915 * Return dasd_device structure associated with cdev.
918 dasd_device_from_cdev(struct ccw_device *cdev)
920 struct dasd_device *device;
923 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
924 device = dasd_device_from_cdev_locked(cdev);
925 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
929 void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device)
931 struct dasd_devmap *devmap;
933 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
936 spin_lock(&dasd_devmap_lock);
937 gdp->private_data = devmap;
938 spin_unlock(&dasd_devmap_lock);
940 EXPORT_SYMBOL(dasd_add_link_to_gendisk);
942 struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp)
944 struct dasd_device *device;
945 struct dasd_devmap *devmap;
947 if (!gdp->private_data)
950 spin_lock(&dasd_devmap_lock);
951 devmap = gdp->private_data;
952 if (devmap && devmap->device) {
953 device = devmap->device;
954 dasd_get_device(device);
956 spin_unlock(&dasd_devmap_lock);
961 * SECTION: files in sysfs
965 * failfast controls the behaviour, if no path is available
967 static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
970 struct dasd_devmap *devmap;
973 devmap = dasd_find_busid(dev_name(dev));
975 ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
977 ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
978 return sysfs_emit(buf, ff_flag ? "1\n" : "0\n");
981 static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
982 const char *buf, size_t count)
987 if (kstrtouint(buf, 0, &val) || val > 1)
990 rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_FAILFAST, val);
995 static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
998 * readonly controls the readonly status of a dasd
1001 dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
1003 struct dasd_devmap *devmap;
1004 struct dasd_device *device;
1007 devmap = dasd_find_busid(dev_name(dev));
1011 ro_flag = !!(devmap->features & DASD_FEATURE_READONLY);
1013 spin_lock(&dasd_devmap_lock);
1014 device = devmap->device;
1016 ro_flag |= test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1017 spin_unlock(&dasd_devmap_lock);
1020 return sysfs_emit(buf, ro_flag ? "1\n" : "0\n");
1024 dasd_ro_store(struct device *dev, struct device_attribute *attr,
1025 const char *buf, size_t count)
1027 struct ccw_device *cdev = to_ccwdev(dev);
1028 struct dasd_device *device;
1029 unsigned long flags;
1033 if (kstrtouint(buf, 0, &val) || val > 1)
1036 rc = dasd_set_feature(cdev, DASD_FEATURE_READONLY, val);
1040 device = dasd_device_from_cdev(cdev);
1044 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1045 val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1047 if (!device->block || !device->block->gdp ||
1048 test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1049 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1052 /* Increase open_count to avoid losing the block device */
1053 atomic_inc(&device->block->open_count);
1054 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1056 set_disk_ro(device->block->gdp, val);
1057 atomic_dec(&device->block->open_count);
1060 dasd_put_device(device);
1065 static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
1067 * erplog controls the logging of ERP related data
1068 * (e.g. failing channel programs).
1071 dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
1073 struct dasd_devmap *devmap;
1076 devmap = dasd_find_busid(dev_name(dev));
1077 if (!IS_ERR(devmap))
1078 erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
1080 erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
1081 return sysfs_emit(buf, erplog ? "1\n" : "0\n");
1085 dasd_erplog_store(struct device *dev, struct device_attribute *attr,
1086 const char *buf, size_t count)
1091 if (kstrtouint(buf, 0, &val) || val > 1)
1094 rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_ERPLOG, val);
1096 return rc ? : count;
1099 static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
1102 * use_diag controls whether the driver should use diag rather than ssch
1103 * to talk to the device
1106 dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
1108 struct dasd_devmap *devmap;
1111 devmap = dasd_find_busid(dev_name(dev));
1112 if (!IS_ERR(devmap))
1113 use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
1115 use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
1116 return sprintf(buf, use_diag ? "1\n" : "0\n");
1120 dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
1121 const char *buf, size_t count)
1123 struct dasd_devmap *devmap;
1127 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1129 return PTR_ERR(devmap);
1131 if (kstrtouint(buf, 0, &val) || val > 1)
1134 spin_lock(&dasd_devmap_lock);
1135 /* Changing diag discipline flag is only allowed in offline state. */
1137 if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) {
1139 devmap->features |= DASD_FEATURE_USEDIAG;
1141 devmap->features &= ~DASD_FEATURE_USEDIAG;
1144 spin_unlock(&dasd_devmap_lock);
1148 static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
1151 * use_raw controls whether the driver should give access to raw eckd data or
1152 * operate in standard mode
1155 dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf)
1157 struct dasd_devmap *devmap;
1160 devmap = dasd_find_busid(dev_name(dev));
1161 if (!IS_ERR(devmap))
1162 use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0;
1164 use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0;
1165 return sprintf(buf, use_raw ? "1\n" : "0\n");
1169 dasd_use_raw_store(struct device *dev, struct device_attribute *attr,
1170 const char *buf, size_t count)
1172 struct dasd_devmap *devmap;
1176 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1178 return PTR_ERR(devmap);
1180 if ((kstrtoul(buf, 10, &val) != 0) || val > 1)
1183 spin_lock(&dasd_devmap_lock);
1184 /* Changing diag discipline flag is only allowed in offline state. */
1186 if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) {
1188 devmap->features |= DASD_FEATURE_USERAW;
1190 devmap->features &= ~DASD_FEATURE_USERAW;
1193 spin_unlock(&dasd_devmap_lock);
1197 static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show,
1198 dasd_use_raw_store);
1201 dasd_safe_offline_store(struct device *dev, struct device_attribute *attr,
1202 const char *buf, size_t count)
1204 struct ccw_device *cdev = to_ccwdev(dev);
1205 struct dasd_device *device;
1206 unsigned long flags;
1209 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1210 device = dasd_device_from_cdev_locked(cdev);
1211 if (IS_ERR(device)) {
1212 rc = PTR_ERR(device);
1213 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1217 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1218 test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1219 /* Already doing offline processing */
1220 dasd_put_device(device);
1221 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1226 set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags);
1227 dasd_put_device(device);
1228 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1230 rc = ccw_device_set_offline(cdev);
1233 return rc ? rc : count;
1236 static DEVICE_ATTR(safe_offline, 0200, NULL, dasd_safe_offline_store);
1239 dasd_access_show(struct device *dev, struct device_attribute *attr,
1242 struct ccw_device *cdev = to_ccwdev(dev);
1243 struct dasd_device *device;
1246 device = dasd_device_from_cdev(cdev);
1248 return PTR_ERR(device);
1250 if (!device->discipline)
1252 else if (!device->discipline->host_access_count)
1253 count = -EOPNOTSUPP;
1255 count = device->discipline->host_access_count(device);
1257 dasd_put_device(device);
1261 return sprintf(buf, "%d\n", count);
1264 static DEVICE_ATTR(host_access_count, 0444, dasd_access_show, NULL);
1267 dasd_discipline_show(struct device *dev, struct device_attribute *attr,
1270 struct dasd_device *device;
1273 device = dasd_device_from_cdev(to_ccwdev(dev));
1276 else if (!device->discipline) {
1277 dasd_put_device(device);
1280 len = sysfs_emit(buf, "%s\n",
1281 device->discipline->name);
1282 dasd_put_device(device);
1286 len = sysfs_emit(buf, "none\n");
1290 static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
1293 dasd_device_status_show(struct device *dev, struct device_attribute *attr,
1296 struct dasd_device *device;
1299 device = dasd_device_from_cdev(to_ccwdev(dev));
1300 if (!IS_ERR(device)) {
1301 switch (device->state) {
1302 case DASD_STATE_NEW:
1303 len = sysfs_emit(buf, "new\n");
1305 case DASD_STATE_KNOWN:
1306 len = sysfs_emit(buf, "detected\n");
1308 case DASD_STATE_BASIC:
1309 len = sysfs_emit(buf, "basic\n");
1311 case DASD_STATE_UNFMT:
1312 len = sysfs_emit(buf, "unformatted\n");
1314 case DASD_STATE_READY:
1315 len = sysfs_emit(buf, "ready\n");
1317 case DASD_STATE_ONLINE:
1318 len = sysfs_emit(buf, "online\n");
1321 len = sysfs_emit(buf, "no stat\n");
1324 dasd_put_device(device);
1326 len = sysfs_emit(buf, "unknown\n");
1330 static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL);
1332 static ssize_t dasd_alias_show(struct device *dev,
1333 struct device_attribute *attr, char *buf)
1335 struct dasd_device *device;
1336 struct dasd_uid uid;
1338 device = dasd_device_from_cdev(to_ccwdev(dev));
1340 return sprintf(buf, "0\n");
1342 if (device->discipline && device->discipline->get_uid &&
1343 !device->discipline->get_uid(device, &uid)) {
1344 if (uid.type == UA_BASE_PAV_ALIAS ||
1345 uid.type == UA_HYPER_PAV_ALIAS) {
1346 dasd_put_device(device);
1347 return sprintf(buf, "1\n");
1350 dasd_put_device(device);
1352 return sprintf(buf, "0\n");
1355 static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
1357 static ssize_t dasd_vendor_show(struct device *dev,
1358 struct device_attribute *attr, char *buf)
1360 struct dasd_device *device;
1361 struct dasd_uid uid;
1364 device = dasd_device_from_cdev(to_ccwdev(dev));
1367 return sysfs_emit(buf, "%s\n", vendor);
1369 if (device->discipline && device->discipline->get_uid &&
1370 !device->discipline->get_uid(device, &uid))
1371 vendor = uid.vendor;
1373 dasd_put_device(device);
1375 return sysfs_emit(buf, "%s\n", vendor);
1378 static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
1380 #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
1381 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
1385 dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
1387 struct dasd_device *device;
1388 struct dasd_uid uid;
1389 char uid_string[UID_STRLEN];
1392 device = dasd_device_from_cdev(to_ccwdev(dev));
1395 return sysfs_emit(buf, "%s\n", uid_string);
1397 if (device->discipline && device->discipline->get_uid &&
1398 !device->discipline->get_uid(device, &uid)) {
1400 case UA_BASE_DEVICE:
1401 snprintf(ua_string, sizeof(ua_string), "%02x",
1402 uid.real_unit_addr);
1404 case UA_BASE_PAV_ALIAS:
1405 snprintf(ua_string, sizeof(ua_string), "%02x",
1406 uid.base_unit_addr);
1408 case UA_HYPER_PAV_ALIAS:
1409 snprintf(ua_string, sizeof(ua_string), "xx");
1412 /* should not happen, treat like base device */
1413 snprintf(ua_string, sizeof(ua_string), "%02x",
1414 uid.real_unit_addr);
1418 if (strlen(uid.vduit) > 0)
1419 snprintf(uid_string, sizeof(uid_string),
1421 uid.vendor, uid.serial, uid.ssid, ua_string,
1424 snprintf(uid_string, sizeof(uid_string),
1426 uid.vendor, uid.serial, uid.ssid, ua_string);
1428 dasd_put_device(device);
1430 return sysfs_emit(buf, "%s\n", uid_string);
1432 static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
1435 * extended error-reporting
1438 dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
1440 struct dasd_devmap *devmap;
1443 devmap = dasd_find_busid(dev_name(dev));
1444 if (!IS_ERR(devmap) && devmap->device)
1445 eer_flag = dasd_eer_enabled(devmap->device);
1448 return sysfs_emit(buf, eer_flag ? "1\n" : "0\n");
1452 dasd_eer_store(struct device *dev, struct device_attribute *attr,
1453 const char *buf, size_t count)
1455 struct dasd_device *device;
1459 device = dasd_device_from_cdev(to_ccwdev(dev));
1461 return PTR_ERR(device);
1463 if (kstrtouint(buf, 0, &val) || val > 1)
1467 rc = dasd_eer_enable(device);
1469 dasd_eer_disable(device);
1471 dasd_put_device(device);
1473 return rc ? : count;
1476 static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
1479 * expiration time for default requests
1482 dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf)
1484 struct dasd_device *device;
1487 device = dasd_device_from_cdev(to_ccwdev(dev));
1490 len = sysfs_emit(buf, "%lu\n", device->default_expires);
1491 dasd_put_device(device);
1496 dasd_expires_store(struct device *dev, struct device_attribute *attr,
1497 const char *buf, size_t count)
1499 struct dasd_device *device;
1502 device = dasd_device_from_cdev(to_ccwdev(dev));
1506 if ((kstrtoul(buf, 10, &val) != 0) ||
1507 (val > DASD_EXPIRES_MAX) || val == 0) {
1508 dasd_put_device(device);
1513 device->default_expires = val;
1515 dasd_put_device(device);
1519 static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store);
1522 dasd_retries_show(struct device *dev, struct device_attribute *attr, char *buf)
1524 struct dasd_device *device;
1527 device = dasd_device_from_cdev(to_ccwdev(dev));
1530 len = sysfs_emit(buf, "%lu\n", device->default_retries);
1531 dasd_put_device(device);
1536 dasd_retries_store(struct device *dev, struct device_attribute *attr,
1537 const char *buf, size_t count)
1539 struct dasd_device *device;
1542 device = dasd_device_from_cdev(to_ccwdev(dev));
1546 if ((kstrtoul(buf, 10, &val) != 0) ||
1547 (val > DASD_RETRIES_MAX)) {
1548 dasd_put_device(device);
1553 device->default_retries = val;
1555 dasd_put_device(device);
1559 static DEVICE_ATTR(retries, 0644, dasd_retries_show, dasd_retries_store);
1562 dasd_timeout_show(struct device *dev, struct device_attribute *attr,
1565 struct dasd_device *device;
1568 device = dasd_device_from_cdev(to_ccwdev(dev));
1571 len = sysfs_emit(buf, "%lu\n", device->blk_timeout);
1572 dasd_put_device(device);
1577 dasd_timeout_store(struct device *dev, struct device_attribute *attr,
1578 const char *buf, size_t count)
1580 struct dasd_device *device;
1583 device = dasd_device_from_cdev(to_ccwdev(dev));
1584 if (IS_ERR(device) || !device->block)
1587 if ((kstrtoul(buf, 10, &val) != 0) ||
1588 val > UINT_MAX / HZ) {
1589 dasd_put_device(device);
1592 if (!device->block->gdp) {
1593 dasd_put_device(device);
1597 device->blk_timeout = val;
1598 blk_queue_rq_timeout(device->block->gdp->queue, val * HZ);
1600 dasd_put_device(device);
1604 static DEVICE_ATTR(timeout, 0644,
1605 dasd_timeout_show, dasd_timeout_store);
1609 dasd_path_reset_store(struct device *dev, struct device_attribute *attr,
1610 const char *buf, size_t count)
1612 struct dasd_device *device;
1615 device = dasd_device_from_cdev(to_ccwdev(dev));
1619 if ((kstrtouint(buf, 16, &val) != 0) || val > 0xff)
1622 if (device->discipline && device->discipline->reset_path)
1623 device->discipline->reset_path(device, (__u8) val);
1625 dasd_put_device(device);
1629 static DEVICE_ATTR(path_reset, 0200, NULL, dasd_path_reset_store);
1631 static ssize_t dasd_hpf_show(struct device *dev, struct device_attribute *attr,
1634 struct dasd_device *device;
1637 device = dasd_device_from_cdev(to_ccwdev(dev));
1640 if (!device->discipline || !device->discipline->hpf_enabled) {
1641 dasd_put_device(device);
1642 return sysfs_emit(buf, "%d\n", dasd_nofcx);
1644 hpf = device->discipline->hpf_enabled(device);
1645 dasd_put_device(device);
1646 return sysfs_emit(buf, "%d\n", hpf);
1649 static DEVICE_ATTR(hpf, 0444, dasd_hpf_show, NULL);
1651 static ssize_t dasd_reservation_policy_show(struct device *dev,
1652 struct device_attribute *attr,
1655 struct dasd_devmap *devmap;
1658 devmap = dasd_find_busid(dev_name(dev));
1659 if (IS_ERR(devmap)) {
1660 rc = sysfs_emit(buf, "ignore\n");
1662 spin_lock(&dasd_devmap_lock);
1663 if (devmap->features & DASD_FEATURE_FAILONSLCK)
1664 rc = sysfs_emit(buf, "fail\n");
1666 rc = sysfs_emit(buf, "ignore\n");
1667 spin_unlock(&dasd_devmap_lock);
1672 static ssize_t dasd_reservation_policy_store(struct device *dev,
1673 struct device_attribute *attr,
1674 const char *buf, size_t count)
1676 struct ccw_device *cdev = to_ccwdev(dev);
1679 if (sysfs_streq("ignore", buf))
1680 rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 0);
1681 else if (sysfs_streq("fail", buf))
1682 rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 1);
1686 return rc ? : count;
1689 static DEVICE_ATTR(reservation_policy, 0644,
1690 dasd_reservation_policy_show, dasd_reservation_policy_store);
1692 static ssize_t dasd_reservation_state_show(struct device *dev,
1693 struct device_attribute *attr,
1696 struct dasd_device *device;
1699 device = dasd_device_from_cdev(to_ccwdev(dev));
1701 return sysfs_emit(buf, "none\n");
1703 if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags))
1704 rc = sysfs_emit(buf, "reserved\n");
1705 else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags))
1706 rc = sysfs_emit(buf, "lost\n");
1708 rc = sysfs_emit(buf, "none\n");
1709 dasd_put_device(device);
1713 static ssize_t dasd_reservation_state_store(struct device *dev,
1714 struct device_attribute *attr,
1715 const char *buf, size_t count)
1717 struct dasd_device *device;
1720 device = dasd_device_from_cdev(to_ccwdev(dev));
1723 if (sysfs_streq("reset", buf))
1724 clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
1727 dasd_put_device(device);
1735 static DEVICE_ATTR(last_known_reservation_state, 0644,
1736 dasd_reservation_state_show, dasd_reservation_state_store);
1738 static ssize_t dasd_pm_show(struct device *dev,
1739 struct device_attribute *attr, char *buf)
1741 struct dasd_device *device;
1742 u8 opm, nppm, cablepm, cuirpm, hpfpm, ifccpm;
1744 device = dasd_device_from_cdev(to_ccwdev(dev));
1746 return sprintf(buf, "0\n");
1748 opm = dasd_path_get_opm(device);
1749 nppm = dasd_path_get_nppm(device);
1750 cablepm = dasd_path_get_cablepm(device);
1751 cuirpm = dasd_path_get_cuirpm(device);
1752 hpfpm = dasd_path_get_hpfpm(device);
1753 ifccpm = dasd_path_get_ifccpm(device);
1754 dasd_put_device(device);
1756 return sprintf(buf, "%02x %02x %02x %02x %02x %02x\n", opm, nppm,
1757 cablepm, cuirpm, hpfpm, ifccpm);
1760 static DEVICE_ATTR(path_masks, 0444, dasd_pm_show, NULL);
1763 * threshold value for IFCC/CCC errors
1766 dasd_path_threshold_show(struct device *dev,
1767 struct device_attribute *attr, char *buf)
1769 struct dasd_device *device;
1772 device = dasd_device_from_cdev(to_ccwdev(dev));
1775 len = sysfs_emit(buf, "%lu\n", device->path_thrhld);
1776 dasd_put_device(device);
1781 dasd_path_threshold_store(struct device *dev, struct device_attribute *attr,
1782 const char *buf, size_t count)
1784 struct dasd_device *device;
1785 unsigned long flags;
1788 device = dasd_device_from_cdev(to_ccwdev(dev));
1792 if (kstrtoul(buf, 10, &val) != 0 || val > DASD_THRHLD_MAX) {
1793 dasd_put_device(device);
1796 spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags);
1797 device->path_thrhld = val;
1798 spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags);
1799 dasd_put_device(device);
1802 static DEVICE_ATTR(path_threshold, 0644, dasd_path_threshold_show,
1803 dasd_path_threshold_store);
1806 * configure if path is disabled after IFCC/CCC error threshold is
1810 dasd_path_autodisable_show(struct device *dev,
1811 struct device_attribute *attr, char *buf)
1813 struct dasd_devmap *devmap;
1816 devmap = dasd_find_busid(dev_name(dev));
1817 if (!IS_ERR(devmap))
1818 flag = (devmap->features & DASD_FEATURE_PATH_AUTODISABLE) != 0;
1820 flag = (DASD_FEATURE_DEFAULT &
1821 DASD_FEATURE_PATH_AUTODISABLE) != 0;
1822 return sysfs_emit(buf, flag ? "1\n" : "0\n");
1826 dasd_path_autodisable_store(struct device *dev,
1827 struct device_attribute *attr,
1828 const char *buf, size_t count)
1833 if (kstrtouint(buf, 0, &val) || val > 1)
1836 rc = dasd_set_feature(to_ccwdev(dev),
1837 DASD_FEATURE_PATH_AUTODISABLE, val);
1839 return rc ? : count;
1842 static DEVICE_ATTR(path_autodisable, 0644,
1843 dasd_path_autodisable_show,
1844 dasd_path_autodisable_store);
1846 * interval for IFCC/CCC checks
1847 * meaning time with no IFCC/CCC error before the error counter
1851 dasd_path_interval_show(struct device *dev,
1852 struct device_attribute *attr, char *buf)
1854 struct dasd_device *device;
1857 device = dasd_device_from_cdev(to_ccwdev(dev));
1860 len = sysfs_emit(buf, "%lu\n", device->path_interval);
1861 dasd_put_device(device);
1866 dasd_path_interval_store(struct device *dev, struct device_attribute *attr,
1867 const char *buf, size_t count)
1869 struct dasd_device *device;
1870 unsigned long flags;
1873 device = dasd_device_from_cdev(to_ccwdev(dev));
1877 if ((kstrtoul(buf, 10, &val) != 0) ||
1878 (val > DASD_INTERVAL_MAX) || val == 0) {
1879 dasd_put_device(device);
1882 spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags);
1884 device->path_interval = val;
1885 spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags);
1886 dasd_put_device(device);
1890 static DEVICE_ATTR(path_interval, 0644, dasd_path_interval_show,
1891 dasd_path_interval_store);
1894 dasd_device_fcs_show(struct device *dev, struct device_attribute *attr,
1897 struct dasd_device *device;
1901 device = dasd_device_from_cdev(to_ccwdev(dev));
1904 fc_sec = dasd_path_get_fcs_device(device);
1905 if (fc_sec == -EINVAL)
1906 rc = sysfs_emit(buf, "Inconsistent\n");
1908 rc = sysfs_emit(buf, "%s\n", dasd_path_get_fcs_str(fc_sec));
1909 dasd_put_device(device);
1913 static DEVICE_ATTR(fc_security, 0444, dasd_device_fcs_show, NULL);
1916 dasd_path_fcs_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
1918 struct dasd_path *path = to_dasd_path(kobj);
1919 unsigned int fc_sec = path->fc_security;
1921 return sysfs_emit(buf, "%s\n", dasd_path_get_fcs_str(fc_sec));
1924 static struct kobj_attribute path_fcs_attribute =
1925 __ATTR(fc_security, 0444, dasd_path_fcs_show, NULL);
1928 * print copy relation in the form
1929 * primary,secondary[1] primary,secondary[2], ...
1932 dasd_copy_pair_show(struct device *dev,
1933 struct device_attribute *attr, char *buf)
1935 char prim_busid[DASD_BUS_ID_SIZE];
1936 struct dasd_copy_relation *copy;
1937 struct dasd_devmap *devmap;
1941 devmap = dasd_find_busid(dev_name(dev));
1948 copy = devmap->copy;
1950 for (i = 0; i < DASD_CP_ENTRIES; i++) {
1951 if (copy->entry[i].configured && copy->entry[i].primary) {
1952 strscpy(prim_busid, copy->entry[i].busid,
1957 if (!copy->entry[i].primary)
1960 /* print all secondary */
1961 for (i = 0; i < DASD_CP_ENTRIES; i++) {
1962 if (copy->entry[i].configured && !copy->entry[i].primary)
1963 len += sysfs_emit_at(buf, len, "%s,%s ", prim_busid,
1964 copy->entry[i].busid);
1967 len += sysfs_emit_at(buf, len, "\n");
1972 static int dasd_devmap_set_copy_relation(struct dasd_devmap *devmap,
1973 struct dasd_copy_relation *copy,
1974 char *busid, bool primary)
1978 /* find free entry */
1979 for (i = 0; i < DASD_CP_ENTRIES; i++) {
1980 /* current bus_id already included, nothing to do */
1981 if (copy->entry[i].configured &&
1982 strncmp(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE) == 0)
1985 if (!copy->entry[i].configured)
1988 if (i == DASD_CP_ENTRIES)
1991 copy->entry[i].configured = true;
1992 strscpy(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE);
1994 copy->active = ©->entry[i];
1995 copy->entry[i].primary = true;
1998 devmap->copy = copy;
2003 static void dasd_devmap_del_copy_relation(struct dasd_copy_relation *copy,
2008 spin_lock(&dasd_devmap_lock);
2010 for (i = 0; i < DASD_CP_ENTRIES; i++) {
2011 if (copy->entry[i].configured &&
2012 strncmp(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE) == 0)
2015 if (i == DASD_CP_ENTRIES || !copy->entry[i].configured) {
2016 spin_unlock(&dasd_devmap_lock);
2020 copy->entry[i].configured = false;
2021 memset(copy->entry[i].busid, 0, DASD_BUS_ID_SIZE);
2022 if (copy->active == ©->entry[i]) {
2023 copy->active = NULL;
2024 copy->entry[i].primary = false;
2026 spin_unlock(&dasd_devmap_lock);
2029 static int dasd_devmap_clear_copy_relation(struct device *dev)
2031 struct dasd_copy_relation *copy;
2032 struct dasd_devmap *devmap;
2035 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
2039 spin_lock(&dasd_devmap_lock);
2043 copy = devmap->copy;
2044 /* first check if all secondary devices are offline*/
2045 for (i = 0; i < DASD_CP_ENTRIES; i++) {
2046 if (!copy->entry[i].configured)
2049 if (copy->entry[i].device == copy->active->device)
2052 if (copy->entry[i].device)
2055 /* clear all devmap entries */
2056 for (i = 0; i < DASD_CP_ENTRIES; i++) {
2057 if (strlen(copy->entry[i].busid) == 0)
2059 if (copy->entry[i].device) {
2060 dasd_put_device(copy->entry[i].device);
2061 copy->entry[i].device->copy = NULL;
2062 copy->entry[i].device = NULL;
2064 devmap = dasd_find_busid_locked(copy->entry[i].busid);
2065 devmap->copy = NULL;
2066 memset(copy->entry[i].busid, 0, DASD_BUS_ID_SIZE);
2071 spin_unlock(&dasd_devmap_lock);
2076 * parse BUSIDs from a copy pair
2078 static int dasd_devmap_parse_busid(const char *buf, char *prim_busid,
2081 char *primary, *secondary, *tmp, *pt;
2084 pt = kstrdup(buf, GFP_KERNEL);
2089 primary = strsep(&tmp, ",");
2094 secondary = strsep(&tmp, ",");
2099 if (dasd_busid(primary, &id0, &id1, &id2)) {
2103 sprintf(prim_busid, "%01x.%01x.%04x", id0, id1, id2);
2104 if (dasd_busid(secondary, &id0, &id1, &id2)) {
2108 sprintf(sec_busid, "%01x.%01x.%04x", id0, id1, id2);
2114 static ssize_t dasd_copy_pair_store(struct device *dev,
2115 struct device_attribute *attr,
2116 const char *buf, size_t count)
2118 struct dasd_devmap *prim_devmap, *sec_devmap;
2119 char prim_busid[DASD_BUS_ID_SIZE];
2120 char sec_busid[DASD_BUS_ID_SIZE];
2121 struct dasd_copy_relation *copy;
2122 struct dasd_device *device;
2126 if (strncmp(buf, "clear", strlen("clear")) == 0) {
2127 if (dasd_devmap_clear_copy_relation(dev))
2132 rc = dasd_devmap_parse_busid(buf, prim_busid, sec_busid);
2136 if (strncmp(dev_name(dev), prim_busid, DASD_BUS_ID_SIZE) != 0 &&
2137 strncmp(dev_name(dev), sec_busid, DASD_BUS_ID_SIZE) != 0)
2140 /* allocate primary devmap if needed */
2141 prim_devmap = dasd_find_busid(prim_busid);
2142 if (IS_ERR(prim_devmap))
2143 prim_devmap = dasd_add_busid(prim_busid, DASD_FEATURE_DEFAULT);
2145 /* allocate secondary devmap if needed */
2146 sec_devmap = dasd_find_busid(sec_busid);
2147 if (IS_ERR(sec_devmap))
2148 sec_devmap = dasd_add_busid(sec_busid, DASD_FEATURE_DEFAULT);
2150 /* setting copy relation is only allowed for offline secondary */
2151 if (sec_devmap->device)
2154 if (prim_devmap->copy) {
2155 copy = prim_devmap->copy;
2156 } else if (sec_devmap->copy) {
2157 copy = sec_devmap->copy;
2159 copy = kzalloc(sizeof(*copy), GFP_KERNEL);
2163 spin_lock(&dasd_devmap_lock);
2164 rc = dasd_devmap_set_copy_relation(prim_devmap, copy, prim_busid, true);
2166 spin_unlock(&dasd_devmap_lock);
2169 rc = dasd_devmap_set_copy_relation(sec_devmap, copy, sec_busid, false);
2171 spin_unlock(&dasd_devmap_lock);
2174 spin_unlock(&dasd_devmap_lock);
2176 /* if primary device is already online call device setup directly */
2177 if (prim_devmap->device && !prim_devmap->device->copy) {
2178 device = prim_devmap->device;
2179 if (device->discipline->pprc_enabled) {
2180 pprc_enabled = device->discipline->pprc_enabled(device);
2181 rc = dasd_devmap_set_device_copy_relation(device->cdev,
2188 dasd_devmap_del_copy_relation(copy, prim_busid);
2189 dasd_devmap_del_copy_relation(copy, sec_busid);
2195 static DEVICE_ATTR(copy_pair, 0644, dasd_copy_pair_show,
2196 dasd_copy_pair_store);
2199 dasd_copy_role_show(struct device *dev,
2200 struct device_attribute *attr, char *buf)
2202 struct dasd_copy_relation *copy;
2203 struct dasd_device *device;
2206 device = dasd_device_from_cdev(to_ccwdev(dev));
2210 if (!device->copy) {
2211 len = sysfs_emit(buf, "none\n");
2214 copy = device->copy;
2215 /* only the active device is primary */
2216 if (copy->active->device == device) {
2217 len = sysfs_emit(buf, "primary\n");
2220 for (i = 0; i < DASD_CP_ENTRIES; i++) {
2221 if (copy->entry[i].device == device) {
2222 len = sysfs_emit(buf, "secondary\n");
2226 /* not in the list, no COPY role */
2227 len = sysfs_emit(buf, "none\n");
2229 dasd_put_device(device);
2232 static DEVICE_ATTR(copy_role, 0444, dasd_copy_role_show, NULL);
2234 static ssize_t dasd_device_ping(struct device *dev,
2235 struct device_attribute *attr,
2236 const char *buf, size_t count)
2238 struct dasd_device *device;
2241 device = dasd_device_from_cdev(to_ccwdev(dev));
2246 * do not try during offline processing
2248 * the sleep_on function itself checks for offline
2251 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2255 if (!device->discipline || !device->discipline->device_ping) {
2259 rc = device->discipline->device_ping(device);
2263 dasd_put_device(device);
2266 static DEVICE_ATTR(ping, 0200, NULL, dasd_device_ping);
2268 #define DASD_DEFINE_ATTR(_name, _func) \
2269 static ssize_t dasd_##_name##_show(struct device *dev, \
2270 struct device_attribute *attr, \
2273 struct ccw_device *cdev = to_ccwdev(dev); \
2274 struct dasd_device *device = dasd_device_from_cdev(cdev); \
2277 if (IS_ERR(device)) \
2279 if (device->discipline && _func) \
2280 val = _func(device); \
2281 dasd_put_device(device); \
2283 return sysfs_emit(buf, "%d\n", val); \
2285 static DEVICE_ATTR(_name, 0444, dasd_##_name##_show, NULL); \
2287 DASD_DEFINE_ATTR(ese, device->discipline->is_ese);
2288 DASD_DEFINE_ATTR(extent_size, device->discipline->ext_size);
2289 DASD_DEFINE_ATTR(pool_id, device->discipline->ext_pool_id);
2290 DASD_DEFINE_ATTR(space_configured, device->discipline->space_configured);
2291 DASD_DEFINE_ATTR(space_allocated, device->discipline->space_allocated);
2292 DASD_DEFINE_ATTR(logical_capacity, device->discipline->logical_capacity);
2293 DASD_DEFINE_ATTR(warn_threshold, device->discipline->ext_pool_warn_thrshld);
2294 DASD_DEFINE_ATTR(cap_at_warnlevel, device->discipline->ext_pool_cap_at_warnlevel);
2295 DASD_DEFINE_ATTR(pool_oos, device->discipline->ext_pool_oos);
2297 static struct attribute * dasd_attrs[] = {
2298 &dev_attr_readonly.attr,
2299 &dev_attr_discipline.attr,
2300 &dev_attr_status.attr,
2301 &dev_attr_alias.attr,
2302 &dev_attr_vendor.attr,
2304 &dev_attr_use_diag.attr,
2305 &dev_attr_raw_track_access.attr,
2306 &dev_attr_eer_enabled.attr,
2307 &dev_attr_erplog.attr,
2308 &dev_attr_failfast.attr,
2309 &dev_attr_expires.attr,
2310 &dev_attr_retries.attr,
2311 &dev_attr_timeout.attr,
2312 &dev_attr_reservation_policy.attr,
2313 &dev_attr_last_known_reservation_state.attr,
2314 &dev_attr_safe_offline.attr,
2315 &dev_attr_host_access_count.attr,
2316 &dev_attr_path_masks.attr,
2317 &dev_attr_path_threshold.attr,
2318 &dev_attr_path_autodisable.attr,
2319 &dev_attr_path_interval.attr,
2320 &dev_attr_path_reset.attr,
2323 &dev_attr_fc_security.attr,
2324 &dev_attr_copy_pair.attr,
2325 &dev_attr_copy_role.attr,
2326 &dev_attr_ping.attr,
2330 static const struct attribute_group dasd_attr_group = {
2331 .attrs = dasd_attrs,
2334 static struct attribute *capacity_attrs[] = {
2335 &dev_attr_space_configured.attr,
2336 &dev_attr_space_allocated.attr,
2337 &dev_attr_logical_capacity.attr,
2341 static const struct attribute_group capacity_attr_group = {
2343 .attrs = capacity_attrs,
2346 static struct attribute *ext_pool_attrs[] = {
2347 &dev_attr_pool_id.attr,
2348 &dev_attr_extent_size.attr,
2349 &dev_attr_warn_threshold.attr,
2350 &dev_attr_cap_at_warnlevel.attr,
2351 &dev_attr_pool_oos.attr,
2355 static const struct attribute_group ext_pool_attr_group = {
2356 .name = "extent_pool",
2357 .attrs = ext_pool_attrs,
2360 const struct attribute_group *dasd_dev_groups[] = {
2362 &capacity_attr_group,
2363 &ext_pool_attr_group,
2366 EXPORT_SYMBOL_GPL(dasd_dev_groups);
2369 * Return value of the specified feature.
2372 dasd_get_feature(struct ccw_device *cdev, int feature)
2374 struct dasd_devmap *devmap;
2376 devmap = dasd_find_busid(dev_name(&cdev->dev));
2378 return PTR_ERR(devmap);
2380 return ((devmap->features & feature) != 0);
2384 * Set / reset given feature.
2385 * Flag indicates whether to set (!=0) or the reset (=0) the feature.
2388 dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
2390 struct dasd_devmap *devmap;
2392 devmap = dasd_devmap_from_cdev(cdev);
2394 return PTR_ERR(devmap);
2396 spin_lock(&dasd_devmap_lock);
2398 devmap->features |= feature;
2400 devmap->features &= ~feature;
2402 devmap->device->features = devmap->features;
2403 spin_unlock(&dasd_devmap_lock);
2406 EXPORT_SYMBOL(dasd_set_feature);
2408 static struct attribute *paths_info_attrs[] = {
2409 &path_fcs_attribute.attr,
2412 ATTRIBUTE_GROUPS(paths_info);
2414 static struct kobj_type path_attr_type = {
2415 .release = dasd_path_release,
2416 .default_groups = paths_info_groups,
2417 .sysfs_ops = &kobj_sysfs_ops,
2420 static void dasd_path_init_kobj(struct dasd_device *device, int chp)
2422 device->path[chp].kobj.kset = device->paths_info;
2423 kobject_init(&device->path[chp].kobj, &path_attr_type);
2426 void dasd_path_create_kobj(struct dasd_device *device, int chp)
2430 if (test_bit(DASD_FLAG_OFFLINE, &device->flags))
2432 if (!device->paths_info) {
2433 dev_warn(&device->cdev->dev, "Unable to create paths objects\n");
2436 if (device->path[chp].in_sysfs)
2438 if (!device->path[chp].conf_data)
2441 dasd_path_init_kobj(device, chp);
2443 rc = kobject_add(&device->path[chp].kobj, NULL, "%x.%02x",
2444 device->path[chp].cssid, device->path[chp].chpid);
2446 kobject_put(&device->path[chp].kobj);
2447 device->path[chp].in_sysfs = true;
2449 EXPORT_SYMBOL(dasd_path_create_kobj);
2451 void dasd_path_create_kobjects(struct dasd_device *device)
2455 opm = dasd_path_get_opm(device);
2456 for (lpm = 0x80; lpm; lpm >>= 1) {
2459 dasd_path_create_kobj(device, pathmask_to_pos(lpm));
2462 EXPORT_SYMBOL(dasd_path_create_kobjects);
2464 static void dasd_path_remove_kobj(struct dasd_device *device, int chp)
2466 if (device->path[chp].in_sysfs) {
2467 kobject_put(&device->path[chp].kobj);
2468 device->path[chp].in_sysfs = false;
2473 * As we keep kobjects for the lifetime of a device, this function must not be
2474 * called anywhere but in the context of offlining a device.
2476 void dasd_path_remove_kobjects(struct dasd_device *device)
2480 for (i = 0; i < 8; i++)
2481 dasd_path_remove_kobj(device, i);
2483 EXPORT_SYMBOL(dasd_path_remove_kobjects);
2486 dasd_devmap_init(void)
2490 /* Initialize devmap structures. */
2491 dasd_max_devindex = 0;
2492 for (i = 0; i < 256; i++)
2493 INIT_LIST_HEAD(&dasd_hashlists[i]);
2498 dasd_devmap_exit(void)
2500 dasd_forget_ranges();