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 #include <linux/ctype.h>
17 #include <linux/init.h>
18 #include <linux/module.h>
19 #include <linux/slab.h>
21 #include <asm/machine.h>
22 #include <asm/debug.h>
23 #include <linux/uaccess.h>
26 #define DASD_MAX_PARAMS 256
30 struct kmem_cache *dasd_page_cache;
31 EXPORT_SYMBOL_GPL(dasd_page_cache);
34 * dasd_devmap_t is used to store the features and the relation
35 * between device number and device index. To find a dasd_devmap_t
36 * that corresponds to a device number of a device index each
37 * dasd_devmap_t is added to two linked lists, one to search by
38 * the device number and one to search by the device index. As
39 * soon as big minor numbers are available the device index list
40 * can be removed since the device number will then be identical
41 * to the device index.
44 struct list_head list;
45 char bus_id[DASD_BUS_ID_SIZE];
46 unsigned int devindex;
47 unsigned short features;
48 struct dasd_device *device;
49 struct dasd_copy_relation *copy;
54 * Parameter parsing functions for dasd= parameter. The syntax is:
55 * <devno> : (0x)?[0-9a-fA-F]+
56 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
58 * <feature_list> : \(<feature>(:<feature>)*\)
59 * <devno-range> : <devno>(-<devno>)?<feature_list>?
60 * <busid-range> : <busid>(-<busid>)?<feature_list>?
61 * <devices> : <devno-range>|<busid-range>
62 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
64 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
67 int dasd_probeonly = 0; /* is true, when probeonly mode is active */
68 int dasd_autodetect = 0; /* is true, when autodetection is active */
69 int dasd_nopav = 0; /* is true, when PAV is disabled */
70 EXPORT_SYMBOL_GPL(dasd_nopav);
71 int dasd_nofcx; /* disable High Performance Ficon */
72 EXPORT_SYMBOL_GPL(dasd_nofcx);
75 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
76 * it is named 'dasd' to directly be filled by insmod with the comma separated
77 * strings when running as a module.
79 static char *dasd[DASD_MAX_PARAMS];
80 module_param_array(dasd, charp, NULL, S_IRUGO);
83 * Single spinlock to protect devmap and servermap structures and lists.
85 static DEFINE_SPINLOCK(dasd_devmap_lock);
88 * Hash lists for devmap structures.
90 static struct list_head dasd_hashlists[256];
91 int dasd_max_devindex;
93 static struct dasd_devmap *dasd_add_busid(const char *, int);
96 dasd_hash_busid(const char *bus_id)
101 for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++)
107 static int __init dasd_call_setup(char *opt)
109 static int i __initdata;
112 while (i < DASD_MAX_PARAMS) {
113 tmp = strsep(&opt, ",");
123 __setup ("dasd=", dasd_call_setup);
124 #endif /* #ifndef MODULE */
126 #define DASD_IPLDEV "ipldev"
129 * Read a device busid/devno from a string.
131 static int dasd_busid(char *str, int *id0, int *id1, int *devno)
136 /* Interpret ipldev busid */
137 if (strncmp(DASD_IPLDEV, str, strlen(DASD_IPLDEV)) == 0) {
138 if (ipl_info.type != IPL_TYPE_CCW) {
139 pr_err("The IPL device is not a CCW device\n");
143 *id1 = ipl_info.data.ccw.dev_id.ssid;
144 *devno = ipl_info.data.ccw.dev_id.devno;
149 /* Old style 0xXXXX or XXXX */
150 if (!kstrtouint(str, 16, &val)) {
158 /* New style x.y.z busid */
159 tok = strsep(&str, ".");
160 if (kstrtouint(tok, 16, &val) || val > 0xff)
164 tok = strsep(&str, ".");
165 if (kstrtouint(tok, 16, &val) || val > 0xff)
169 tok = strsep(&str, ".");
170 if (kstrtouint(tok, 16, &val) || val > 0xffff)
178 * Read colon separated list of dasd features.
180 static int __init dasd_feature_list(char *str)
182 int features, len, rc;
188 return DASD_FEATURE_DEFAULT;
192 str[len] && str[len] != ':' && str[len] != ')'; len++);
193 if (len == 2 && !strncmp(str, "ro", 2))
194 features |= DASD_FEATURE_READONLY;
195 else if (len == 4 && !strncmp(str, "diag", 4))
196 features |= DASD_FEATURE_USEDIAG;
197 else if (len == 3 && !strncmp(str, "raw", 3))
198 features |= DASD_FEATURE_USERAW;
199 else if (len == 6 && !strncmp(str, "erplog", 6))
200 features |= DASD_FEATURE_ERPLOG;
201 else if (len == 8 && !strncmp(str, "failfast", 8))
202 features |= DASD_FEATURE_FAILFAST;
204 pr_warn("%.*s is not a supported device option\n",
214 return rc ? : features;
218 * Try to match the first element on the comma separated parse string
219 * with one of the known keywords. If a keyword is found, take the approprate
220 * action and return a pointer to the residual string. If the first element
221 * could not be matched to any keyword then return an error code.
223 static int __init dasd_parse_keyword(char *keyword)
225 int length = strlen(keyword);
227 if (strncmp("autodetect", keyword, length) == 0) {
229 pr_info("The autodetection mode has been activated\n");
232 if (strncmp("probeonly", keyword, length) == 0) {
234 pr_info("The probeonly mode has been activated\n");
237 if (strncmp("nopav", keyword, length) == 0) {
239 pr_info("'nopav' is not supported on z/VM\n");
242 pr_info("PAV support has be deactivated\n");
246 if (strncmp("nofcx", keyword, length) == 0) {
248 pr_info("High Performance FICON support has been "
252 if (strncmp("fixedbuffers", keyword, length) == 0) {
256 kmem_cache_create("dasd_page_cache", PAGE_SIZE,
257 PAGE_SIZE, SLAB_CACHE_DMA,
259 if (!dasd_page_cache)
260 DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, "
261 "fixed buffer mode disabled.");
263 DBF_EVENT(DBF_INFO, "%s",
264 "turning on fixed buffer mode");
272 * Split a string of a device range into its pieces and return the from, to, and
273 * feature parts separately.
275 * 0.0.1234-0.0.5678(ro:erplog) -> from: 0.0.1234 to: 0.0.5678 features: ro:erplog
276 * 0.0.8765(raw) -> from: 0.0.8765 to: null features: raw
277 * 0x4321 -> from: 0x4321 to: null features: null
279 static int __init dasd_evaluate_range_param(char *range, char **from_str,
280 char **to_str, char **features_str)
284 /* Do we have a range or a single device? */
285 if (strchr(range, '-')) {
286 *from_str = strsep(&range, "-");
287 *to_str = strsep(&range, "(");
288 *features_str = strsep(&range, ")");
290 *from_str = strsep(&range, "(");
291 *features_str = strsep(&range, ")");
294 if (*features_str && !range) {
295 pr_warn("A closing parenthesis ')' is missing in the dasd= parameter\n");
303 * Try to interprete the range string as a device number or a range of devices.
304 * If the interpretation is successful, create the matching dasd_devmap entries.
305 * If interpretation fails or in case of an error, return an error code.
307 static int __init dasd_parse_range(const char *range)
309 struct dasd_devmap *devmap;
310 int from, from_id0, from_id1;
311 int to, to_id0, to_id1;
313 char bus_id[DASD_BUS_ID_SIZE + 1];
314 char *features_str = NULL;
315 char *from_str = NULL;
320 tmp = kstrdup(range, GFP_KERNEL);
324 if (dasd_evaluate_range_param(tmp, &from_str, &to_str, &features_str)) {
329 if (dasd_busid(from_str, &from_id0, &from_id1, &from)) {
338 if (dasd_busid(to_str, &to_id0, &to_id1, &to)) {
342 if (from_id0 != to_id0 || from_id1 != to_id1 || from > to) {
343 pr_err("%s is not a valid device range\n", range);
349 features = dasd_feature_list(features_str);
354 /* each device in dasd= parameter should be set initially online */
355 features |= DASD_FEATURE_INITIAL_ONLINE;
357 sprintf(bus_id, "%01x.%01x.%04x", from_id0, from_id1, from++);
358 devmap = dasd_add_busid(bus_id, features);
359 if (IS_ERR(devmap)) {
360 rc = PTR_ERR(devmap);
372 * Parse parameters stored in dasd[]
373 * The 'dasd=...' parameter allows to specify a comma separated list of
374 * keywords and device ranges. The parameters in that list will be stored as
375 * separate elementes in dasd[].
377 int __init dasd_parse(void)
383 for (i = 0; i < DASD_MAX_PARAMS; i++) {
390 rc = dasd_parse_keyword(cur);
392 rc = dasd_parse_range(cur);
402 * Add a devmap for the device specified by busid. It is possible that
403 * the devmap already exists (dasd= parameter). The order of the devices
404 * added through this function will define the kdevs for the individual
407 static struct dasd_devmap *
408 dasd_add_busid(const char *bus_id, int features)
410 struct dasd_devmap *devmap, *new, *tmp;
413 new = kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
415 return ERR_PTR(-ENOMEM);
416 spin_lock(&dasd_devmap_lock);
418 hash = dasd_hash_busid(bus_id);
419 list_for_each_entry(tmp, &dasd_hashlists[hash], list)
420 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
425 /* This bus_id is new. */
426 new->devindex = dasd_max_devindex++;
427 strscpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
428 new->features = features;
430 list_add(&new->list, &dasd_hashlists[hash]);
434 spin_unlock(&dasd_devmap_lock);
439 static struct dasd_devmap *
440 dasd_find_busid_locked(const char *bus_id)
442 struct dasd_devmap *devmap, *tmp;
445 devmap = ERR_PTR(-ENODEV);
446 hash = dasd_hash_busid(bus_id);
447 list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
448 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
457 * Find devmap for device with given bus_id.
459 static struct dasd_devmap *
460 dasd_find_busid(const char *bus_id)
462 struct dasd_devmap *devmap;
464 spin_lock(&dasd_devmap_lock);
465 devmap = dasd_find_busid_locked(bus_id);
466 spin_unlock(&dasd_devmap_lock);
471 * Check if busid has been added to the list of dasd ranges.
474 dasd_busid_known(const char *bus_id)
476 return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
480 * Forget all about the device numbers added so far.
481 * This may only be called at module unload or system shutdown.
484 dasd_forget_ranges(void)
486 struct dasd_devmap *devmap, *n;
489 spin_lock(&dasd_devmap_lock);
490 for (i = 0; i < 256; i++) {
491 list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
492 BUG_ON(devmap->device != NULL);
493 list_del(&devmap->list);
497 spin_unlock(&dasd_devmap_lock);
501 * Find the device struct by its device index.
504 dasd_device_from_devindex(int devindex)
506 struct dasd_devmap *devmap, *tmp;
507 struct dasd_device *device;
510 spin_lock(&dasd_devmap_lock);
512 for (i = 0; (i < 256) && !devmap; i++)
513 list_for_each_entry(tmp, &dasd_hashlists[i], list)
514 if (tmp->devindex == devindex) {
515 /* Found the devmap for the device. */
519 if (devmap && devmap->device) {
520 device = devmap->device;
521 dasd_get_device(device);
523 device = ERR_PTR(-ENODEV);
524 spin_unlock(&dasd_devmap_lock);
529 * Return devmap for cdev. If no devmap exists yet, create one and
530 * connect it to the cdev.
532 static struct dasd_devmap *
533 dasd_devmap_from_cdev(struct ccw_device *cdev)
535 struct dasd_devmap *devmap;
537 devmap = dasd_find_busid(dev_name(&cdev->dev));
539 devmap = dasd_add_busid(dev_name(&cdev->dev),
540 DASD_FEATURE_DEFAULT);
545 * Create a dasd device structure for cdev.
548 dasd_create_device(struct ccw_device *cdev)
550 struct dasd_devmap *devmap;
551 struct dasd_device *device;
555 devmap = dasd_devmap_from_cdev(cdev);
557 return (void *) devmap;
559 device = dasd_alloc_device();
562 atomic_set(&device->ref_count, 3);
564 spin_lock(&dasd_devmap_lock);
565 if (!devmap->device) {
566 devmap->device = device;
567 device->devindex = devmap->devindex;
568 device->features = devmap->features;
569 get_device(&cdev->dev);
573 /* Someone else was faster. */
575 spin_unlock(&dasd_devmap_lock);
578 dasd_free_device(device);
582 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
583 dev_set_drvdata(&cdev->dev, device);
584 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
586 device->paths_info = kset_create_and_add("paths_info", NULL,
587 &device->cdev->dev.kobj);
588 if (!device->paths_info)
589 dev_warn(&cdev->dev, "Could not create paths_info kset\n");
595 * allocate a PPRC data structure and call the discipline function to fill
597 static int dasd_devmap_get_pprc_status(struct dasd_device *device,
598 struct dasd_pprc_data_sc4 **data)
600 struct dasd_pprc_data_sc4 *temp;
602 if (!device->discipline || !device->discipline->pprc_status) {
603 dev_warn(&device->cdev->dev, "Unable to query copy relation status\n");
606 temp = kzalloc(sizeof(*temp), GFP_KERNEL);
610 /* get PPRC information from storage */
611 if (device->discipline->pprc_status(device, temp)) {
612 dev_warn(&device->cdev->dev, "Error during copy relation status query\n");
622 * find an entry in a PPRC device_info array by a given UID
623 * depending on the primary/secondary state of the device it has to be
624 * matched with the respective fields
626 static int dasd_devmap_entry_from_pprc_data(struct dasd_pprc_data_sc4 *data,
632 for (i = 0; i < DASD_CP_ENTRIES; i++) {
634 if (data->dev_info[i].prim_cu_ssid == uid.ssid &&
635 data->dev_info[i].primary == uid.real_unit_addr)
638 if (data->dev_info[i].sec_cu_ssid == uid.ssid &&
639 data->dev_info[i].secondary == uid.real_unit_addr)
647 * check the consistency of a specified copy relation by checking
648 * the following things:
650 * - is the given device part of a copy pair setup
651 * - does the state of the device match the state in the PPRC status data
652 * - does the device UID match with the UID in the PPRC status data
653 * - to prevent misrouted IO check if the given device is present in all
654 * related PPRC status data
656 static int dasd_devmap_check_copy_relation(struct dasd_device *device,
657 struct dasd_copy_entry *entry,
658 struct dasd_pprc_data_sc4 *data,
659 struct dasd_copy_relation *copy)
661 struct dasd_pprc_data_sc4 *tmp_dat;
662 struct dasd_device *tmp_dev;
666 if (!device->discipline || !device->discipline->get_uid ||
667 device->discipline->get_uid(device, &uid))
670 i = dasd_devmap_entry_from_pprc_data(data, uid, entry->primary);
672 dev_warn(&device->cdev->dev, "Device not part of a copy relation\n");
676 /* double check which role the current device has */
677 if (entry->primary) {
678 if (data->dev_info[i].flags & 0x80) {
679 dev_warn(&device->cdev->dev, "Copy pair secondary is setup as primary\n");
682 if (data->dev_info[i].prim_cu_ssid != uid.ssid ||
683 data->dev_info[i].primary != uid.real_unit_addr) {
684 dev_warn(&device->cdev->dev,
685 "Primary device %s does not match copy pair status primary device %04x\n",
686 dev_name(&device->cdev->dev),
687 data->dev_info[i].prim_cu_ssid |
688 data->dev_info[i].primary);
692 if (!(data->dev_info[i].flags & 0x80)) {
693 dev_warn(&device->cdev->dev, "Copy pair primary is setup as secondary\n");
696 if (data->dev_info[i].sec_cu_ssid != uid.ssid ||
697 data->dev_info[i].secondary != uid.real_unit_addr) {
698 dev_warn(&device->cdev->dev,
699 "Secondary device %s does not match copy pair status secondary device %04x\n",
700 dev_name(&device->cdev->dev),
701 data->dev_info[i].sec_cu_ssid |
702 data->dev_info[i].secondary);
708 * the current device has to be part of the copy relation of all
709 * entries to prevent misrouted IO to another copy pair
711 for (j = 0; j < DASD_CP_ENTRIES; j++) {
712 if (entry == ©->entry[j])
715 tmp_dev = copy->entry[j].device;
720 if (dasd_devmap_get_pprc_status(tmp_dev, &tmp_dat))
723 if (dasd_devmap_entry_from_pprc_data(tmp_dat, uid, entry->primary) < 0) {
724 dev_warn(&tmp_dev->cdev->dev,
725 "Copy pair relation does not contain device: %s\n",
726 dev_name(&device->cdev->dev));
735 /* delete device from copy relation entry */
736 static void dasd_devmap_delete_copy_relation_device(struct dasd_device *device)
738 struct dasd_copy_relation *copy;
745 for (i = 0; i < DASD_CP_ENTRIES; i++) {
746 if (copy->entry[i].device == device)
747 copy->entry[i].device = NULL;
749 dasd_put_device(device);
754 * read all required information for a copy relation setup and setup the device
757 int dasd_devmap_set_device_copy_relation(struct ccw_device *cdev,
760 struct dasd_pprc_data_sc4 *data = NULL;
761 struct dasd_copy_entry *entry = NULL;
762 struct dasd_copy_relation *copy;
763 struct dasd_devmap *devmap;
764 struct dasd_device *device;
767 devmap = dasd_devmap_from_cdev(cdev);
769 return PTR_ERR(devmap);
771 device = devmap->device;
776 /* no copy pair setup for this device */
780 rc = dasd_devmap_get_pprc_status(device, &data);
784 /* print error if PPRC is requested but not enabled on storage server */
786 dev_err(&cdev->dev, "Copy relation not enabled on storage server\n");
791 if (!data->dev_info[0].state) {
792 dev_warn(&device->cdev->dev, "Copy pair setup requested for device not in copy relation\n");
797 for (i = 0; i < DASD_CP_ENTRIES; i++) {
798 if (copy->entry[i].configured &&
799 strncmp(dev_name(&cdev->dev),
800 copy->entry[i].busid, DASD_BUS_ID_SIZE) == 0) {
801 entry = ©->entry[i];
806 dev_warn(&device->cdev->dev, "Copy relation entry not found\n");
810 /* check if the copy relation is valid */
811 if (dasd_devmap_check_copy_relation(device, entry, data, copy)) {
812 dev_warn(&device->cdev->dev, "Copy relation faulty\n");
817 dasd_get_device(device);
818 copy->entry[i].device = device;
824 EXPORT_SYMBOL_GPL(dasd_devmap_set_device_copy_relation);
827 * Wait queue for dasd_delete_device waits.
829 static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
832 * Remove a dasd device structure. The passed referenced
836 dasd_delete_device(struct dasd_device *device)
838 struct ccw_device *cdev;
839 struct dasd_devmap *devmap;
842 /* First remove device pointer from devmap. */
843 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
844 BUG_ON(IS_ERR(devmap));
845 spin_lock(&dasd_devmap_lock);
846 if (devmap->device != device) {
847 spin_unlock(&dasd_devmap_lock);
848 dasd_put_device(device);
851 devmap->device = NULL;
852 spin_unlock(&dasd_devmap_lock);
854 /* Disconnect dasd_device structure from ccw_device structure. */
855 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
856 dev_set_drvdata(&device->cdev->dev, NULL);
857 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
859 /* Remove copy relation */
860 dasd_devmap_delete_copy_relation_device(device);
862 * Drop ref_count by 3, one for the devmap reference, one for
863 * the cdev reference and one for the passed reference.
865 atomic_sub(3, &device->ref_count);
867 /* Wait for reference counter to drop to zero. */
868 wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
870 dasd_generic_free_discipline(device);
872 kset_unregister(device->paths_info);
874 /* Disconnect dasd_device structure from ccw_device structure. */
878 /* Put ccw_device structure. */
879 put_device(&cdev->dev);
881 /* Now the device structure can be freed. */
882 dasd_free_device(device);
886 * Reference counter dropped to zero. Wake up waiter
887 * in dasd_delete_device.
890 dasd_put_device_wake(struct dasd_device *device)
892 wake_up(&dasd_delete_wq);
894 EXPORT_SYMBOL_GPL(dasd_put_device_wake);
897 * Return dasd_device structure associated with cdev.
898 * This function needs to be called with the ccw device
899 * lock held. It can be used from interrupt context.
902 dasd_device_from_cdev_locked(struct ccw_device *cdev)
904 struct dasd_device *device = dev_get_drvdata(&cdev->dev);
907 return ERR_PTR(-ENODEV);
908 dasd_get_device(device);
913 * Return dasd_device structure associated with cdev.
916 dasd_device_from_cdev(struct ccw_device *cdev)
918 struct dasd_device *device;
921 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
922 device = dasd_device_from_cdev_locked(cdev);
923 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
927 void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device)
929 struct dasd_devmap *devmap;
931 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
934 spin_lock(&dasd_devmap_lock);
935 gdp->private_data = devmap;
936 spin_unlock(&dasd_devmap_lock);
938 EXPORT_SYMBOL(dasd_add_link_to_gendisk);
940 struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp)
942 struct dasd_device *device;
943 struct dasd_devmap *devmap;
945 if (!gdp->private_data)
948 spin_lock(&dasd_devmap_lock);
949 devmap = gdp->private_data;
950 if (devmap && devmap->device) {
951 device = devmap->device;
952 dasd_get_device(device);
954 spin_unlock(&dasd_devmap_lock);
959 * SECTION: files in sysfs
963 * failfast controls the behaviour, if no path is available
965 static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
968 struct dasd_devmap *devmap;
971 devmap = dasd_find_busid(dev_name(dev));
973 ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
975 ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
976 return sysfs_emit(buf, ff_flag ? "1\n" : "0\n");
979 static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
980 const char *buf, size_t count)
985 if (kstrtouint(buf, 0, &val) || val > 1)
988 rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_FAILFAST, val);
993 static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
996 * readonly controls the readonly status of a dasd
999 dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
1001 struct dasd_devmap *devmap;
1002 struct dasd_device *device;
1005 devmap = dasd_find_busid(dev_name(dev));
1009 ro_flag = !!(devmap->features & DASD_FEATURE_READONLY);
1011 spin_lock(&dasd_devmap_lock);
1012 device = devmap->device;
1014 ro_flag |= test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1015 spin_unlock(&dasd_devmap_lock);
1018 return sysfs_emit(buf, ro_flag ? "1\n" : "0\n");
1022 dasd_ro_store(struct device *dev, struct device_attribute *attr,
1023 const char *buf, size_t count)
1025 struct ccw_device *cdev = to_ccwdev(dev);
1026 struct dasd_device *device;
1027 unsigned long flags;
1031 if (kstrtouint(buf, 0, &val) || val > 1)
1034 rc = dasd_set_feature(cdev, DASD_FEATURE_READONLY, val);
1038 device = dasd_device_from_cdev(cdev);
1042 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1043 val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
1045 if (!device->block || !device->block->gdp ||
1046 test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1047 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1050 /* Increase open_count to avoid losing the block device */
1051 atomic_inc(&device->block->open_count);
1052 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1054 set_disk_ro(device->block->gdp, val);
1055 atomic_dec(&device->block->open_count);
1058 dasd_put_device(device);
1063 static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
1065 * erplog controls the logging of ERP related data
1066 * (e.g. failing channel programs).
1069 dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
1071 struct dasd_devmap *devmap;
1074 devmap = dasd_find_busid(dev_name(dev));
1075 if (!IS_ERR(devmap))
1076 erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
1078 erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
1079 return sysfs_emit(buf, erplog ? "1\n" : "0\n");
1083 dasd_erplog_store(struct device *dev, struct device_attribute *attr,
1084 const char *buf, size_t count)
1089 if (kstrtouint(buf, 0, &val) || val > 1)
1092 rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_ERPLOG, val);
1094 return rc ? : count;
1097 static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
1100 * use_diag controls whether the driver should use diag rather than ssch
1101 * to talk to the device
1104 dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
1106 struct dasd_devmap *devmap;
1109 devmap = dasd_find_busid(dev_name(dev));
1110 if (!IS_ERR(devmap))
1111 use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
1113 use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
1114 return sysfs_emit(buf, use_diag ? "1\n" : "0\n");
1118 dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
1119 const char *buf, size_t count)
1121 struct dasd_devmap *devmap;
1125 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1127 return PTR_ERR(devmap);
1129 if (kstrtouint(buf, 0, &val) || val > 1)
1132 spin_lock(&dasd_devmap_lock);
1133 /* Changing diag discipline flag is only allowed in offline state. */
1135 if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) {
1137 devmap->features |= DASD_FEATURE_USEDIAG;
1139 devmap->features &= ~DASD_FEATURE_USEDIAG;
1142 spin_unlock(&dasd_devmap_lock);
1146 static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
1149 * use_raw controls whether the driver should give access to raw eckd data or
1150 * operate in standard mode
1153 dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf)
1155 struct dasd_devmap *devmap;
1158 devmap = dasd_find_busid(dev_name(dev));
1159 if (!IS_ERR(devmap))
1160 use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0;
1162 use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0;
1163 return sysfs_emit(buf, use_raw ? "1\n" : "0\n");
1167 dasd_use_raw_store(struct device *dev, struct device_attribute *attr,
1168 const char *buf, size_t count)
1170 struct dasd_devmap *devmap;
1174 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1176 return PTR_ERR(devmap);
1178 if ((kstrtoul(buf, 10, &val) != 0) || val > 1)
1181 spin_lock(&dasd_devmap_lock);
1182 /* Changing diag discipline flag is only allowed in offline state. */
1184 if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) {
1186 devmap->features |= DASD_FEATURE_USERAW;
1188 devmap->features &= ~DASD_FEATURE_USERAW;
1191 spin_unlock(&dasd_devmap_lock);
1195 static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show,
1196 dasd_use_raw_store);
1199 dasd_safe_offline_store(struct device *dev, struct device_attribute *attr,
1200 const char *buf, size_t count)
1202 struct ccw_device *cdev = to_ccwdev(dev);
1203 struct dasd_device *device;
1204 unsigned long flags;
1207 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1208 device = dasd_device_from_cdev_locked(cdev);
1209 if (IS_ERR(device)) {
1210 rc = PTR_ERR(device);
1211 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1215 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1216 test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1217 /* Already doing offline processing */
1218 dasd_put_device(device);
1219 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1224 set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags);
1225 dasd_put_device(device);
1226 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1228 rc = ccw_device_set_offline(cdev);
1231 return rc ? rc : count;
1234 static DEVICE_ATTR(safe_offline, 0200, NULL, dasd_safe_offline_store);
1237 dasd_access_show(struct device *dev, struct device_attribute *attr,
1240 struct ccw_device *cdev = to_ccwdev(dev);
1241 struct dasd_device *device;
1244 device = dasd_device_from_cdev(cdev);
1246 return PTR_ERR(device);
1248 if (!device->discipline)
1250 else if (!device->discipline->host_access_count)
1251 count = -EOPNOTSUPP;
1253 count = device->discipline->host_access_count(device);
1255 dasd_put_device(device);
1259 return sysfs_emit(buf, "%d\n", count);
1262 static DEVICE_ATTR(host_access_count, 0444, dasd_access_show, NULL);
1265 dasd_discipline_show(struct device *dev, struct device_attribute *attr,
1268 struct dasd_device *device;
1271 device = dasd_device_from_cdev(to_ccwdev(dev));
1274 else if (!device->discipline) {
1275 dasd_put_device(device);
1278 len = sysfs_emit(buf, "%s\n",
1279 device->discipline->name);
1280 dasd_put_device(device);
1284 len = sysfs_emit(buf, "none\n");
1288 static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
1291 dasd_device_status_show(struct device *dev, struct device_attribute *attr,
1294 struct dasd_device *device;
1297 device = dasd_device_from_cdev(to_ccwdev(dev));
1298 if (!IS_ERR(device)) {
1299 switch (device->state) {
1300 case DASD_STATE_NEW:
1301 len = sysfs_emit(buf, "new\n");
1303 case DASD_STATE_KNOWN:
1304 len = sysfs_emit(buf, "detected\n");
1306 case DASD_STATE_BASIC:
1307 len = sysfs_emit(buf, "basic\n");
1309 case DASD_STATE_UNFMT:
1310 len = sysfs_emit(buf, "unformatted\n");
1312 case DASD_STATE_READY:
1313 len = sysfs_emit(buf, "ready\n");
1315 case DASD_STATE_ONLINE:
1316 len = sysfs_emit(buf, "online\n");
1319 len = sysfs_emit(buf, "no stat\n");
1322 dasd_put_device(device);
1324 len = sysfs_emit(buf, "unknown\n");
1328 static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL);
1330 static ssize_t dasd_alias_show(struct device *dev,
1331 struct device_attribute *attr, char *buf)
1333 struct dasd_device *device;
1334 struct dasd_uid uid;
1336 device = dasd_device_from_cdev(to_ccwdev(dev));
1338 return sysfs_emit(buf, "0\n");
1340 if (device->discipline && device->discipline->get_uid &&
1341 !device->discipline->get_uid(device, &uid)) {
1342 if (uid.type == UA_BASE_PAV_ALIAS ||
1343 uid.type == UA_HYPER_PAV_ALIAS) {
1344 dasd_put_device(device);
1345 return sysfs_emit(buf, "1\n");
1348 dasd_put_device(device);
1350 return sysfs_emit(buf, "0\n");
1353 static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
1355 static ssize_t dasd_vendor_show(struct device *dev,
1356 struct device_attribute *attr, char *buf)
1358 struct dasd_device *device;
1359 struct dasd_uid uid;
1362 device = dasd_device_from_cdev(to_ccwdev(dev));
1365 return sysfs_emit(buf, "%s\n", vendor);
1367 if (device->discipline && device->discipline->get_uid &&
1368 !device->discipline->get_uid(device, &uid))
1369 vendor = uid.vendor;
1371 dasd_put_device(device);
1373 return sysfs_emit(buf, "%s\n", vendor);
1376 static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
1379 dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
1381 char uid_string[DASD_UID_STRLEN];
1382 struct dasd_device *device;
1383 struct dasd_uid uid;
1386 device = dasd_device_from_cdev(to_ccwdev(dev));
1389 return sysfs_emit(buf, "%s\n", uid_string);
1391 if (device->discipline && device->discipline->get_uid &&
1392 !device->discipline->get_uid(device, &uid)) {
1394 case UA_BASE_DEVICE:
1395 snprintf(ua_string, sizeof(ua_string), "%02x",
1396 uid.real_unit_addr);
1398 case UA_BASE_PAV_ALIAS:
1399 snprintf(ua_string, sizeof(ua_string), "%02x",
1400 uid.base_unit_addr);
1402 case UA_HYPER_PAV_ALIAS:
1403 snprintf(ua_string, sizeof(ua_string), "xx");
1406 /* should not happen, treat like base device */
1407 snprintf(ua_string, sizeof(ua_string), "%02x",
1408 uid.real_unit_addr);
1412 snprintf(uid_string, sizeof(uid_string), "%s.%s.%04x.%s%s%s",
1413 uid.vendor, uid.serial, uid.ssid, ua_string,
1414 uid.vduit[0] ? "." : "", uid.vduit);
1416 dasd_put_device(device);
1418 return sysfs_emit(buf, "%s\n", uid_string);
1420 static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
1423 * extended error-reporting
1426 dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
1428 struct dasd_devmap *devmap;
1431 devmap = dasd_find_busid(dev_name(dev));
1432 if (!IS_ERR(devmap) && devmap->device)
1433 eer_flag = dasd_eer_enabled(devmap->device);
1436 return sysfs_emit(buf, eer_flag ? "1\n" : "0\n");
1440 dasd_eer_store(struct device *dev, struct device_attribute *attr,
1441 const char *buf, size_t count)
1443 struct dasd_device *device;
1447 device = dasd_device_from_cdev(to_ccwdev(dev));
1449 return PTR_ERR(device);
1451 if (kstrtouint(buf, 0, &val) || val > 1)
1455 rc = dasd_eer_enable(device);
1457 dasd_eer_disable(device);
1459 dasd_put_device(device);
1461 return rc ? : count;
1464 static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
1467 * aq_mask controls if the DASD should be quiesced on certain triggers
1468 * The aq_mask attribute is interpreted as bitmap of the DASD_EER_* triggers.
1470 static ssize_t dasd_aq_mask_show(struct device *dev, struct device_attribute *attr,
1473 struct dasd_devmap *devmap;
1474 unsigned int aq_mask = 0;
1476 devmap = dasd_find_busid(dev_name(dev));
1477 if (!IS_ERR(devmap))
1478 aq_mask = devmap->aq_mask;
1480 return sysfs_emit(buf, "%d\n", aq_mask);
1483 static ssize_t dasd_aq_mask_store(struct device *dev, struct device_attribute *attr,
1484 const char *buf, size_t count)
1486 struct dasd_devmap *devmap;
1489 if (kstrtouint(buf, 0, &val) || val > DASD_EER_VALID)
1492 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1494 return PTR_ERR(devmap);
1496 spin_lock(&dasd_devmap_lock);
1497 devmap->aq_mask = val;
1499 devmap->device->aq_mask = devmap->aq_mask;
1500 spin_unlock(&dasd_devmap_lock);
1505 static DEVICE_ATTR(aq_mask, 0644, dasd_aq_mask_show, dasd_aq_mask_store);
1508 * aq_requeue controls if requests are returned to the blocklayer on quiesce
1509 * or if requests are only not started
1511 static ssize_t dasd_aqr_show(struct device *dev, struct device_attribute *attr,
1514 struct dasd_devmap *devmap;
1517 devmap = dasd_find_busid(dev_name(dev));
1518 if (!IS_ERR(devmap))
1519 flag = (devmap->features & DASD_FEATURE_REQUEUEQUIESCE) != 0;
1521 flag = (DASD_FEATURE_DEFAULT &
1522 DASD_FEATURE_REQUEUEQUIESCE) != 0;
1523 return sysfs_emit(buf, "%d\n", flag);
1526 static ssize_t dasd_aqr_store(struct device *dev, struct device_attribute *attr,
1527 const char *buf, size_t count)
1532 if (kstrtobool(buf, &val))
1535 rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_REQUEUEQUIESCE, val);
1537 return rc ? : count;
1540 static DEVICE_ATTR(aq_requeue, 0644, dasd_aqr_show, dasd_aqr_store);
1543 * aq_timeouts controls how much retries have to time out until
1544 * a device gets autoquiesced
1547 dasd_aq_timeouts_show(struct device *dev, struct device_attribute *attr,
1550 struct dasd_device *device;
1553 device = dasd_device_from_cdev(to_ccwdev(dev));
1556 len = sysfs_emit(buf, "%u\n", device->aq_timeouts);
1557 dasd_put_device(device);
1562 dasd_aq_timeouts_store(struct device *dev, struct device_attribute *attr,
1563 const char *buf, size_t count)
1565 struct dasd_device *device;
1568 device = dasd_device_from_cdev(to_ccwdev(dev));
1572 if ((kstrtouint(buf, 10, &val) != 0) ||
1573 val > DASD_RETRIES_MAX || val == 0) {
1574 dasd_put_device(device);
1579 device->aq_timeouts = val;
1581 dasd_put_device(device);
1585 static DEVICE_ATTR(aq_timeouts, 0644, dasd_aq_timeouts_show,
1586 dasd_aq_timeouts_store);
1589 * expiration time for default requests
1592 dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf)
1594 struct dasd_device *device;
1597 device = dasd_device_from_cdev(to_ccwdev(dev));
1600 len = sysfs_emit(buf, "%lu\n", device->default_expires);
1601 dasd_put_device(device);
1606 dasd_expires_store(struct device *dev, struct device_attribute *attr,
1607 const char *buf, size_t count)
1609 struct dasd_device *device;
1612 device = dasd_device_from_cdev(to_ccwdev(dev));
1616 if ((kstrtoul(buf, 10, &val) != 0) ||
1617 (val > DASD_EXPIRES_MAX) || val == 0) {
1618 dasd_put_device(device);
1623 device->default_expires = val;
1625 dasd_put_device(device);
1629 static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store);
1632 dasd_retries_show(struct device *dev, struct device_attribute *attr, char *buf)
1634 struct dasd_device *device;
1637 device = dasd_device_from_cdev(to_ccwdev(dev));
1640 len = sysfs_emit(buf, "%lu\n", device->default_retries);
1641 dasd_put_device(device);
1646 dasd_retries_store(struct device *dev, struct device_attribute *attr,
1647 const char *buf, size_t count)
1649 struct dasd_device *device;
1652 device = dasd_device_from_cdev(to_ccwdev(dev));
1656 if ((kstrtoul(buf, 10, &val) != 0) ||
1657 (val > DASD_RETRIES_MAX)) {
1658 dasd_put_device(device);
1663 device->default_retries = val;
1665 dasd_put_device(device);
1669 static DEVICE_ATTR(retries, 0644, dasd_retries_show, dasd_retries_store);
1672 dasd_timeout_show(struct device *dev, struct device_attribute *attr,
1675 struct dasd_device *device;
1678 device = dasd_device_from_cdev(to_ccwdev(dev));
1681 len = sysfs_emit(buf, "%lu\n", device->blk_timeout);
1682 dasd_put_device(device);
1687 dasd_timeout_store(struct device *dev, struct device_attribute *attr,
1688 const char *buf, size_t count)
1690 struct dasd_device *device;
1693 device = dasd_device_from_cdev(to_ccwdev(dev));
1694 if (IS_ERR(device) || !device->block)
1697 if ((kstrtoul(buf, 10, &val) != 0) ||
1698 val > UINT_MAX / HZ) {
1699 dasd_put_device(device);
1702 if (!device->block->gdp) {
1703 dasd_put_device(device);
1707 device->blk_timeout = val;
1708 blk_queue_rq_timeout(device->block->gdp->queue, val * HZ);
1710 dasd_put_device(device);
1714 static DEVICE_ATTR(timeout, 0644,
1715 dasd_timeout_show, dasd_timeout_store);
1719 dasd_path_reset_store(struct device *dev, struct device_attribute *attr,
1720 const char *buf, size_t count)
1722 struct dasd_device *device;
1725 device = dasd_device_from_cdev(to_ccwdev(dev));
1729 if ((kstrtouint(buf, 16, &val) != 0) || val > 0xff)
1732 if (device->discipline && device->discipline->reset_path)
1733 device->discipline->reset_path(device, (__u8) val);
1735 dasd_put_device(device);
1739 static DEVICE_ATTR(path_reset, 0200, NULL, dasd_path_reset_store);
1741 static ssize_t dasd_hpf_show(struct device *dev, struct device_attribute *attr,
1744 struct dasd_device *device;
1747 device = dasd_device_from_cdev(to_ccwdev(dev));
1750 if (!device->discipline || !device->discipline->hpf_enabled) {
1751 dasd_put_device(device);
1752 return sysfs_emit(buf, "%d\n", dasd_nofcx);
1754 hpf = device->discipline->hpf_enabled(device);
1755 dasd_put_device(device);
1756 return sysfs_emit(buf, "%d\n", hpf);
1759 static DEVICE_ATTR(hpf, 0444, dasd_hpf_show, NULL);
1761 static ssize_t dasd_reservation_policy_show(struct device *dev,
1762 struct device_attribute *attr,
1765 struct dasd_devmap *devmap;
1768 devmap = dasd_find_busid(dev_name(dev));
1769 if (IS_ERR(devmap)) {
1770 rc = sysfs_emit(buf, "ignore\n");
1772 spin_lock(&dasd_devmap_lock);
1773 if (devmap->features & DASD_FEATURE_FAILONSLCK)
1774 rc = sysfs_emit(buf, "fail\n");
1776 rc = sysfs_emit(buf, "ignore\n");
1777 spin_unlock(&dasd_devmap_lock);
1782 static ssize_t dasd_reservation_policy_store(struct device *dev,
1783 struct device_attribute *attr,
1784 const char *buf, size_t count)
1786 struct ccw_device *cdev = to_ccwdev(dev);
1789 if (sysfs_streq("ignore", buf))
1790 rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 0);
1791 else if (sysfs_streq("fail", buf))
1792 rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 1);
1796 return rc ? : count;
1799 static DEVICE_ATTR(reservation_policy, 0644,
1800 dasd_reservation_policy_show, dasd_reservation_policy_store);
1802 static ssize_t dasd_reservation_state_show(struct device *dev,
1803 struct device_attribute *attr,
1806 struct dasd_device *device;
1809 device = dasd_device_from_cdev(to_ccwdev(dev));
1811 return sysfs_emit(buf, "none\n");
1813 if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags))
1814 rc = sysfs_emit(buf, "reserved\n");
1815 else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags))
1816 rc = sysfs_emit(buf, "lost\n");
1818 rc = sysfs_emit(buf, "none\n");
1819 dasd_put_device(device);
1823 static ssize_t dasd_reservation_state_store(struct device *dev,
1824 struct device_attribute *attr,
1825 const char *buf, size_t count)
1827 struct dasd_device *device;
1830 device = dasd_device_from_cdev(to_ccwdev(dev));
1833 if (sysfs_streq("reset", buf))
1834 clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
1837 dasd_put_device(device);
1845 static DEVICE_ATTR(last_known_reservation_state, 0644,
1846 dasd_reservation_state_show, dasd_reservation_state_store);
1848 static ssize_t dasd_pm_show(struct device *dev,
1849 struct device_attribute *attr, char *buf)
1851 struct dasd_device *device;
1852 u8 opm, nppm, cablepm, cuirpm, hpfpm, ifccpm;
1854 device = dasd_device_from_cdev(to_ccwdev(dev));
1856 return sysfs_emit(buf, "0\n");
1858 opm = dasd_path_get_opm(device);
1859 nppm = dasd_path_get_nppm(device);
1860 cablepm = dasd_path_get_cablepm(device);
1861 cuirpm = dasd_path_get_cuirpm(device);
1862 hpfpm = dasd_path_get_hpfpm(device);
1863 ifccpm = dasd_path_get_ifccpm(device);
1864 dasd_put_device(device);
1866 return sysfs_emit(buf, "%02x %02x %02x %02x %02x %02x\n", opm, nppm,
1867 cablepm, cuirpm, hpfpm, ifccpm);
1870 static DEVICE_ATTR(path_masks, 0444, dasd_pm_show, NULL);
1873 * threshold value for IFCC/CCC errors
1876 dasd_path_threshold_show(struct device *dev,
1877 struct device_attribute *attr, char *buf)
1879 struct dasd_device *device;
1882 device = dasd_device_from_cdev(to_ccwdev(dev));
1885 len = sysfs_emit(buf, "%lu\n", device->path_thrhld);
1886 dasd_put_device(device);
1891 dasd_path_threshold_store(struct device *dev, struct device_attribute *attr,
1892 const char *buf, size_t count)
1894 struct dasd_device *device;
1895 unsigned long flags;
1898 device = dasd_device_from_cdev(to_ccwdev(dev));
1902 if (kstrtoul(buf, 10, &val) != 0 || val > DASD_THRHLD_MAX) {
1903 dasd_put_device(device);
1906 spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags);
1907 device->path_thrhld = val;
1908 spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags);
1909 dasd_put_device(device);
1912 static DEVICE_ATTR(path_threshold, 0644, dasd_path_threshold_show,
1913 dasd_path_threshold_store);
1916 * configure if path is disabled after IFCC/CCC error threshold is
1920 dasd_path_autodisable_show(struct device *dev,
1921 struct device_attribute *attr, char *buf)
1923 struct dasd_devmap *devmap;
1926 devmap = dasd_find_busid(dev_name(dev));
1927 if (!IS_ERR(devmap))
1928 flag = (devmap->features & DASD_FEATURE_PATH_AUTODISABLE) != 0;
1930 flag = (DASD_FEATURE_DEFAULT &
1931 DASD_FEATURE_PATH_AUTODISABLE) != 0;
1932 return sysfs_emit(buf, flag ? "1\n" : "0\n");
1936 dasd_path_autodisable_store(struct device *dev,
1937 struct device_attribute *attr,
1938 const char *buf, size_t count)
1943 if (kstrtouint(buf, 0, &val) || val > 1)
1946 rc = dasd_set_feature(to_ccwdev(dev),
1947 DASD_FEATURE_PATH_AUTODISABLE, val);
1949 return rc ? : count;
1952 static DEVICE_ATTR(path_autodisable, 0644,
1953 dasd_path_autodisable_show,
1954 dasd_path_autodisable_store);
1956 * interval for IFCC/CCC checks
1957 * meaning time with no IFCC/CCC error before the error counter
1961 dasd_path_interval_show(struct device *dev,
1962 struct device_attribute *attr, char *buf)
1964 struct dasd_device *device;
1967 device = dasd_device_from_cdev(to_ccwdev(dev));
1970 len = sysfs_emit(buf, "%lu\n", device->path_interval);
1971 dasd_put_device(device);
1976 dasd_path_interval_store(struct device *dev, struct device_attribute *attr,
1977 const char *buf, size_t count)
1979 struct dasd_device *device;
1980 unsigned long flags;
1983 device = dasd_device_from_cdev(to_ccwdev(dev));
1987 if ((kstrtoul(buf, 10, &val) != 0) ||
1988 (val > DASD_INTERVAL_MAX) || val == 0) {
1989 dasd_put_device(device);
1992 spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags);
1994 device->path_interval = val;
1995 spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags);
1996 dasd_put_device(device);
2000 static DEVICE_ATTR(path_interval, 0644, dasd_path_interval_show,
2001 dasd_path_interval_store);
2004 dasd_device_fcs_show(struct device *dev, struct device_attribute *attr,
2007 struct dasd_device *device;
2011 device = dasd_device_from_cdev(to_ccwdev(dev));
2014 fc_sec = dasd_path_get_fcs_device(device);
2015 if (fc_sec == -EINVAL)
2016 rc = sysfs_emit(buf, "Inconsistent\n");
2018 rc = sysfs_emit(buf, "%s\n", dasd_path_get_fcs_str(fc_sec));
2019 dasd_put_device(device);
2023 static DEVICE_ATTR(fc_security, 0444, dasd_device_fcs_show, NULL);
2026 dasd_path_fcs_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
2028 struct dasd_path *path = to_dasd_path(kobj);
2029 unsigned int fc_sec = path->fc_security;
2031 return sysfs_emit(buf, "%s\n", dasd_path_get_fcs_str(fc_sec));
2034 static struct kobj_attribute path_fcs_attribute =
2035 __ATTR(fc_security, 0444, dasd_path_fcs_show, NULL);
2038 * print copy relation in the form
2039 * primary,secondary[1] primary,secondary[2], ...
2042 dasd_copy_pair_show(struct device *dev,
2043 struct device_attribute *attr, char *buf)
2045 char prim_busid[DASD_BUS_ID_SIZE];
2046 struct dasd_copy_relation *copy;
2047 struct dasd_devmap *devmap;
2051 devmap = dasd_find_busid(dev_name(dev));
2058 copy = devmap->copy;
2060 for (i = 0; i < DASD_CP_ENTRIES; i++) {
2061 if (copy->entry[i].configured && copy->entry[i].primary) {
2062 strscpy(prim_busid, copy->entry[i].busid,
2067 if (i == DASD_CP_ENTRIES)
2070 /* print all secondary */
2071 for (i = 0; i < DASD_CP_ENTRIES; i++) {
2072 if (copy->entry[i].configured && !copy->entry[i].primary)
2073 len += sysfs_emit_at(buf, len, "%s,%s ", prim_busid,
2074 copy->entry[i].busid);
2077 len += sysfs_emit_at(buf, len, "\n");
2082 static int dasd_devmap_set_copy_relation(struct dasd_devmap *devmap,
2083 struct dasd_copy_relation *copy,
2084 char *busid, bool primary)
2088 /* find free entry */
2089 for (i = 0; i < DASD_CP_ENTRIES; i++) {
2090 /* current bus_id already included, nothing to do */
2091 if (copy->entry[i].configured &&
2092 strncmp(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE) == 0)
2095 if (!copy->entry[i].configured)
2098 if (i == DASD_CP_ENTRIES)
2101 copy->entry[i].configured = true;
2102 strscpy(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE);
2104 copy->active = ©->entry[i];
2105 copy->entry[i].primary = true;
2108 devmap->copy = copy;
2113 static void dasd_devmap_del_copy_relation(struct dasd_copy_relation *copy,
2118 spin_lock(&dasd_devmap_lock);
2120 for (i = 0; i < DASD_CP_ENTRIES; i++) {
2121 if (copy->entry[i].configured &&
2122 strncmp(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE) == 0)
2125 if (i == DASD_CP_ENTRIES || !copy->entry[i].configured) {
2126 spin_unlock(&dasd_devmap_lock);
2130 copy->entry[i].configured = false;
2131 memset(copy->entry[i].busid, 0, DASD_BUS_ID_SIZE);
2132 if (copy->active == ©->entry[i]) {
2133 copy->active = NULL;
2134 copy->entry[i].primary = false;
2136 spin_unlock(&dasd_devmap_lock);
2139 static int dasd_devmap_clear_copy_relation(struct device *dev)
2141 struct dasd_copy_relation *copy;
2142 struct dasd_devmap *devmap;
2145 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
2149 spin_lock(&dasd_devmap_lock);
2153 copy = devmap->copy;
2154 /* first check if all secondary devices are offline*/
2155 for (i = 0; i < DASD_CP_ENTRIES; i++) {
2156 if (!copy->entry[i].configured)
2159 if (copy->entry[i].device == copy->active->device)
2162 if (copy->entry[i].device)
2165 /* clear all devmap entries */
2166 for (i = 0; i < DASD_CP_ENTRIES; i++) {
2167 if (strlen(copy->entry[i].busid) == 0)
2169 if (copy->entry[i].device) {
2170 dasd_put_device(copy->entry[i].device);
2171 copy->entry[i].device->copy = NULL;
2172 copy->entry[i].device = NULL;
2174 devmap = dasd_find_busid_locked(copy->entry[i].busid);
2175 devmap->copy = NULL;
2176 memset(copy->entry[i].busid, 0, DASD_BUS_ID_SIZE);
2181 spin_unlock(&dasd_devmap_lock);
2186 * parse BUSIDs from a copy pair
2188 static int dasd_devmap_parse_busid(const char *buf, char *prim_busid,
2191 char *primary, *secondary, *tmp, *pt;
2194 pt = kstrdup(buf, GFP_KERNEL);
2199 primary = strsep(&tmp, ",");
2204 secondary = strsep(&tmp, ",");
2209 if (dasd_busid(primary, &id0, &id1, &id2)) {
2213 sprintf(prim_busid, "%01x.%01x.%04x", id0, id1, id2);
2214 if (dasd_busid(secondary, &id0, &id1, &id2)) {
2218 sprintf(sec_busid, "%01x.%01x.%04x", id0, id1, id2);
2224 static ssize_t dasd_copy_pair_store(struct device *dev,
2225 struct device_attribute *attr,
2226 const char *buf, size_t count)
2228 struct dasd_devmap *prim_devmap, *sec_devmap;
2229 char prim_busid[DASD_BUS_ID_SIZE];
2230 char sec_busid[DASD_BUS_ID_SIZE];
2231 struct dasd_copy_relation *copy;
2232 struct dasd_device *device;
2236 if (strncmp(buf, "clear", strlen("clear")) == 0) {
2237 if (dasd_devmap_clear_copy_relation(dev))
2242 rc = dasd_devmap_parse_busid(buf, prim_busid, sec_busid);
2246 if (strncmp(dev_name(dev), prim_busid, DASD_BUS_ID_SIZE) != 0 &&
2247 strncmp(dev_name(dev), sec_busid, DASD_BUS_ID_SIZE) != 0)
2250 /* allocate primary devmap if needed */
2251 prim_devmap = dasd_find_busid(prim_busid);
2252 if (IS_ERR(prim_devmap)) {
2253 prim_devmap = dasd_add_busid(prim_busid, DASD_FEATURE_DEFAULT);
2254 if (IS_ERR(prim_devmap))
2255 return PTR_ERR(prim_devmap);
2258 /* allocate secondary devmap if needed */
2259 sec_devmap = dasd_find_busid(sec_busid);
2260 if (IS_ERR(sec_devmap)) {
2261 sec_devmap = dasd_add_busid(sec_busid, DASD_FEATURE_DEFAULT);
2262 if (IS_ERR(sec_devmap))
2263 return PTR_ERR(sec_devmap);
2266 /* setting copy relation is only allowed for offline secondary */
2267 if (sec_devmap->device)
2270 if (prim_devmap->copy) {
2271 copy = prim_devmap->copy;
2272 } else if (sec_devmap->copy) {
2273 copy = sec_devmap->copy;
2275 copy = kzalloc(sizeof(*copy), GFP_KERNEL);
2279 spin_lock(&dasd_devmap_lock);
2280 rc = dasd_devmap_set_copy_relation(prim_devmap, copy, prim_busid, true);
2282 spin_unlock(&dasd_devmap_lock);
2285 rc = dasd_devmap_set_copy_relation(sec_devmap, copy, sec_busid, false);
2287 spin_unlock(&dasd_devmap_lock);
2290 spin_unlock(&dasd_devmap_lock);
2292 /* if primary device is already online call device setup directly */
2293 if (prim_devmap->device && !prim_devmap->device->copy) {
2294 device = prim_devmap->device;
2295 if (device->discipline->pprc_enabled) {
2296 pprc_enabled = device->discipline->pprc_enabled(device);
2297 rc = dasd_devmap_set_device_copy_relation(device->cdev,
2304 dasd_devmap_del_copy_relation(copy, prim_busid);
2305 dasd_devmap_del_copy_relation(copy, sec_busid);
2311 static DEVICE_ATTR(copy_pair, 0644, dasd_copy_pair_show,
2312 dasd_copy_pair_store);
2315 dasd_copy_role_show(struct device *dev,
2316 struct device_attribute *attr, char *buf)
2318 struct dasd_copy_relation *copy;
2319 struct dasd_device *device;
2322 device = dasd_device_from_cdev(to_ccwdev(dev));
2326 if (!device->copy) {
2327 len = sysfs_emit(buf, "none\n");
2330 copy = device->copy;
2331 /* only the active device is primary */
2332 if (copy->active->device == device) {
2333 len = sysfs_emit(buf, "primary\n");
2336 for (i = 0; i < DASD_CP_ENTRIES; i++) {
2337 if (copy->entry[i].device == device) {
2338 len = sysfs_emit(buf, "secondary\n");
2342 /* not in the list, no COPY role */
2343 len = sysfs_emit(buf, "none\n");
2345 dasd_put_device(device);
2348 static DEVICE_ATTR(copy_role, 0444, dasd_copy_role_show, NULL);
2350 static ssize_t dasd_device_ping(struct device *dev,
2351 struct device_attribute *attr,
2352 const char *buf, size_t count)
2354 struct dasd_device *device;
2357 device = dasd_device_from_cdev(to_ccwdev(dev));
2362 * do not try during offline processing
2364 * the sleep_on function itself checks for offline
2367 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2371 if (!device->discipline || !device->discipline->device_ping) {
2375 rc = device->discipline->device_ping(device);
2379 dasd_put_device(device);
2382 static DEVICE_ATTR(ping, 0200, NULL, dasd_device_ping);
2384 #define DASD_DEFINE_ATTR(_name, _func) \
2385 static ssize_t dasd_##_name##_show(struct device *dev, \
2386 struct device_attribute *attr, \
2389 struct ccw_device *cdev = to_ccwdev(dev); \
2390 struct dasd_device *device = dasd_device_from_cdev(cdev); \
2393 if (IS_ERR(device)) \
2395 if (device->discipline && _func) \
2396 val = _func(device); \
2397 dasd_put_device(device); \
2399 return sysfs_emit(buf, "%d\n", val); \
2401 static DEVICE_ATTR(_name, 0444, dasd_##_name##_show, NULL); \
2403 DASD_DEFINE_ATTR(ese, device->discipline->is_ese);
2404 DASD_DEFINE_ATTR(extent_size, device->discipline->ext_size);
2405 DASD_DEFINE_ATTR(pool_id, device->discipline->ext_pool_id);
2406 DASD_DEFINE_ATTR(space_configured, device->discipline->space_configured);
2407 DASD_DEFINE_ATTR(space_allocated, device->discipline->space_allocated);
2408 DASD_DEFINE_ATTR(logical_capacity, device->discipline->logical_capacity);
2409 DASD_DEFINE_ATTR(warn_threshold, device->discipline->ext_pool_warn_thrshld);
2410 DASD_DEFINE_ATTR(cap_at_warnlevel, device->discipline->ext_pool_cap_at_warnlevel);
2411 DASD_DEFINE_ATTR(pool_oos, device->discipline->ext_pool_oos);
2413 static struct attribute * dasd_attrs[] = {
2414 &dev_attr_readonly.attr,
2415 &dev_attr_discipline.attr,
2416 &dev_attr_status.attr,
2417 &dev_attr_alias.attr,
2418 &dev_attr_vendor.attr,
2420 &dev_attr_use_diag.attr,
2421 &dev_attr_raw_track_access.attr,
2422 &dev_attr_eer_enabled.attr,
2423 &dev_attr_erplog.attr,
2424 &dev_attr_failfast.attr,
2425 &dev_attr_expires.attr,
2426 &dev_attr_retries.attr,
2427 &dev_attr_timeout.attr,
2428 &dev_attr_reservation_policy.attr,
2429 &dev_attr_last_known_reservation_state.attr,
2430 &dev_attr_safe_offline.attr,
2431 &dev_attr_host_access_count.attr,
2432 &dev_attr_path_masks.attr,
2433 &dev_attr_path_threshold.attr,
2434 &dev_attr_path_autodisable.attr,
2435 &dev_attr_path_interval.attr,
2436 &dev_attr_path_reset.attr,
2439 &dev_attr_fc_security.attr,
2440 &dev_attr_copy_pair.attr,
2441 &dev_attr_copy_role.attr,
2442 &dev_attr_ping.attr,
2443 &dev_attr_aq_mask.attr,
2444 &dev_attr_aq_requeue.attr,
2445 &dev_attr_aq_timeouts.attr,
2449 static const struct attribute_group dasd_attr_group = {
2450 .attrs = dasd_attrs,
2453 static struct attribute *capacity_attrs[] = {
2454 &dev_attr_space_configured.attr,
2455 &dev_attr_space_allocated.attr,
2456 &dev_attr_logical_capacity.attr,
2460 static const struct attribute_group capacity_attr_group = {
2462 .attrs = capacity_attrs,
2465 static struct attribute *ext_pool_attrs[] = {
2466 &dev_attr_pool_id.attr,
2467 &dev_attr_extent_size.attr,
2468 &dev_attr_warn_threshold.attr,
2469 &dev_attr_cap_at_warnlevel.attr,
2470 &dev_attr_pool_oos.attr,
2474 static const struct attribute_group ext_pool_attr_group = {
2475 .name = "extent_pool",
2476 .attrs = ext_pool_attrs,
2479 const struct attribute_group *dasd_dev_groups[] = {
2481 &capacity_attr_group,
2482 &ext_pool_attr_group,
2485 EXPORT_SYMBOL_GPL(dasd_dev_groups);
2488 * Return value of the specified feature.
2491 dasd_get_feature(struct ccw_device *cdev, int feature)
2493 struct dasd_devmap *devmap;
2495 devmap = dasd_find_busid(dev_name(&cdev->dev));
2497 return PTR_ERR(devmap);
2499 return ((devmap->features & feature) != 0);
2503 * Set / reset given feature.
2504 * Flag indicates whether to set (!=0) or the reset (=0) the feature.
2507 dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
2509 struct dasd_devmap *devmap;
2511 devmap = dasd_devmap_from_cdev(cdev);
2513 return PTR_ERR(devmap);
2515 spin_lock(&dasd_devmap_lock);
2517 devmap->features |= feature;
2519 devmap->features &= ~feature;
2521 devmap->device->features = devmap->features;
2522 spin_unlock(&dasd_devmap_lock);
2525 EXPORT_SYMBOL(dasd_set_feature);
2527 static struct attribute *paths_info_attrs[] = {
2528 &path_fcs_attribute.attr,
2531 ATTRIBUTE_GROUPS(paths_info);
2533 static struct kobj_type path_attr_type = {
2534 .release = dasd_path_release,
2535 .default_groups = paths_info_groups,
2536 .sysfs_ops = &kobj_sysfs_ops,
2539 static void dasd_path_init_kobj(struct dasd_device *device, int chp)
2541 device->path[chp].kobj.kset = device->paths_info;
2542 kobject_init(&device->path[chp].kobj, &path_attr_type);
2545 void dasd_path_create_kobj(struct dasd_device *device, int chp)
2549 if (test_bit(DASD_FLAG_OFFLINE, &device->flags))
2551 if (!device->paths_info) {
2552 dev_warn(&device->cdev->dev, "Unable to create paths objects\n");
2555 if (device->path[chp].in_sysfs)
2557 if (!device->path[chp].conf_data)
2560 dasd_path_init_kobj(device, chp);
2562 rc = kobject_add(&device->path[chp].kobj, NULL, "%x.%02x",
2563 device->path[chp].cssid, device->path[chp].chpid);
2565 kobject_put(&device->path[chp].kobj);
2566 device->path[chp].in_sysfs = true;
2568 EXPORT_SYMBOL(dasd_path_create_kobj);
2570 void dasd_path_create_kobjects(struct dasd_device *device)
2574 opm = dasd_path_get_opm(device);
2575 for (lpm = 0x80; lpm; lpm >>= 1) {
2578 dasd_path_create_kobj(device, pathmask_to_pos(lpm));
2581 EXPORT_SYMBOL(dasd_path_create_kobjects);
2583 static void dasd_path_remove_kobj(struct dasd_device *device, int chp)
2585 if (device->path[chp].in_sysfs) {
2586 kobject_put(&device->path[chp].kobj);
2587 device->path[chp].in_sysfs = false;
2592 * As we keep kobjects for the lifetime of a device, this function must not be
2593 * called anywhere but in the context of offlining a device.
2595 void dasd_path_remove_kobjects(struct dasd_device *device)
2599 for (i = 0; i < 8; i++)
2600 dasd_path_remove_kobj(device, i);
2602 EXPORT_SYMBOL(dasd_path_remove_kobjects);
2605 dasd_devmap_init(void)
2609 /* Initialize devmap structures. */
2610 dasd_max_devindex = 0;
2611 for (i = 0; i < 256; i++)
2612 INIT_LIST_HEAD(&dasd_hashlists[i]);
2617 dasd_devmap_exit(void)
2619 dasd_forget_ranges();