2 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
3 * Horst Hummel <Horst.Hummel@de.ibm.com>
4 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * Copyright IBM Corp. 1999,2001
9 * Device mapping and dasd= parameter parsing functions. All devmap
10 * functions may not be called from interrupt context. In particular
11 * dasd_get_device is a no-no from interrupt context.
15 #define KMSG_COMPONENT "dasd"
17 #include <linux/ctype.h>
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/slab.h>
22 #include <asm/debug.h>
23 #include <linux/uaccess.h>
27 #define PRINTK_HEADER "dasd_devmap:"
28 #define DASD_BUS_ID_SIZE 20
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;
55 * Parameter parsing functions for dasd= parameter. The syntax is:
56 * <devno> : (0x)?[0-9a-fA-F]+
57 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
59 * <feature_list> : \(<feature>(:<feature>)*\)
60 * <devno-range> : <devno>(-<devno>)?<feature_list>?
61 * <busid-range> : <busid>(-<busid>)?<feature_list>?
62 * <devices> : <devno-range>|<busid-range>
63 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
65 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
68 int dasd_probeonly = 0; /* is true, when probeonly mode is active */
69 int dasd_autodetect = 0; /* is true, when autodetection is active */
70 int dasd_nopav = 0; /* is true, when PAV is disabled */
71 EXPORT_SYMBOL_GPL(dasd_nopav);
72 int dasd_nofcx; /* disable High Performance Ficon */
73 EXPORT_SYMBOL_GPL(dasd_nofcx);
76 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
77 * it is named 'dasd' to directly be filled by insmod with the comma separated
78 * strings when running as a module.
80 static char *dasd[DASD_MAX_PARAMS];
81 module_param_array(dasd, charp, NULL, S_IRUGO);
84 * Single spinlock to protect devmap and servermap structures and lists.
86 static DEFINE_SPINLOCK(dasd_devmap_lock);
89 * Hash lists for devmap structures.
91 static struct list_head dasd_hashlists[256];
92 int dasd_max_devindex;
94 static struct dasd_devmap *dasd_add_busid(const char *, int);
97 dasd_hash_busid(const char *bus_id)
102 for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++)
108 static int __init dasd_call_setup(char *opt)
110 static int i __initdata;
113 while (i < DASD_MAX_PARAMS) {
114 tmp = strsep(&opt, ",");
124 __setup ("dasd=", dasd_call_setup);
125 #endif /* #ifndef MODULE */
127 #define DASD_IPLDEV "ipldev"
130 * Read a device busid/devno from a string.
132 static int __init dasd_busid(char *str, int *id0, int *id1, int *devno)
137 /* Interpret ipldev busid */
138 if (strncmp(DASD_IPLDEV, str, strlen(DASD_IPLDEV)) == 0) {
139 if (ipl_info.type != IPL_TYPE_CCW) {
140 pr_err("The IPL device is not a CCW device\n");
144 *id1 = ipl_info.data.ccw.dev_id.ssid;
145 *devno = ipl_info.data.ccw.dev_id.devno;
150 /* Old style 0xXXXX or XXXX */
151 if (!kstrtouint(str, 16, &val)) {
159 /* New style x.y.z busid */
160 tok = strsep(&str, ".");
161 if (kstrtouint(tok, 16, &val) || val > 0xff)
165 tok = strsep(&str, ".");
166 if (kstrtouint(tok, 16, &val) || val > 0xff)
170 tok = strsep(&str, ".");
171 if (kstrtouint(tok, 16, &val) || val > 0xffff)
179 * Read colon separated list of dasd features.
181 static int __init dasd_feature_list(char *str)
183 int features, len, rc;
189 return DASD_FEATURE_DEFAULT;
193 str[len] && str[len] != ':' && str[len] != ')'; len++);
194 if (len == 2 && !strncmp(str, "ro", 2))
195 features |= DASD_FEATURE_READONLY;
196 else if (len == 4 && !strncmp(str, "diag", 4))
197 features |= DASD_FEATURE_USEDIAG;
198 else if (len == 3 && !strncmp(str, "raw", 3))
199 features |= DASD_FEATURE_USERAW;
200 else if (len == 6 && !strncmp(str, "erplog", 6))
201 features |= DASD_FEATURE_ERPLOG;
202 else if (len == 8 && !strncmp(str, "failfast", 8))
203 features |= DASD_FEATURE_FAILFAST;
205 pr_warn("%*s is not a supported device option\n",
215 return rc ? : features;
219 * Try to match the first element on the comma separated parse string
220 * with one of the known keywords. If a keyword is found, take the approprate
221 * action and return a pointer to the residual string. If the first element
222 * could not be matched to any keyword then return an error code.
224 static int __init dasd_parse_keyword(char *keyword)
226 int length = strlen(keyword);
228 if (strncmp("autodetect", keyword, length) == 0) {
230 pr_info("The autodetection mode has been activated\n");
233 if (strncmp("probeonly", keyword, length) == 0) {
235 pr_info("The probeonly mode has been activated\n");
238 if (strncmp("nopav", keyword, length) == 0) {
240 pr_info("'nopav' is not supported on z/VM\n");
243 pr_info("PAV support has be deactivated\n");
247 if (strncmp("nofcx", keyword, length) == 0) {
249 pr_info("High Performance FICON support has been "
253 if (strncmp("fixedbuffers", keyword, length) == 0) {
257 kmem_cache_create("dasd_page_cache", PAGE_SIZE,
258 PAGE_SIZE, SLAB_CACHE_DMA,
260 if (!dasd_page_cache)
261 DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, "
262 "fixed buffer mode disabled.");
264 DBF_EVENT(DBF_INFO, "%s",
265 "turning on fixed buffer mode");
273 * Split a string of a device range into its pieces and return the from, to, and
274 * feature parts separately.
276 * 0.0.1234-0.0.5678(ro:erplog) -> from: 0.0.1234 to: 0.0.5678 features: ro:erplog
277 * 0.0.8765(raw) -> from: 0.0.8765 to: null features: raw
278 * 0x4321 -> from: 0x4321 to: null features: null
280 static int __init dasd_evaluate_range_param(char *range, char **from_str,
281 char **to_str, char **features_str)
285 /* Do we have a range or a single device? */
286 if (strchr(range, '-')) {
287 *from_str = strsep(&range, "-");
288 *to_str = strsep(&range, "(");
289 *features_str = strsep(&range, ")");
291 *from_str = strsep(&range, "(");
292 *features_str = strsep(&range, ")");
295 if (*features_str && !range) {
296 pr_warn("A closing parenthesis ')' is missing in the dasd= parameter\n");
304 * Try to interprete the range string as a device number or a range of devices.
305 * If the interpretation is successful, create the matching dasd_devmap entries.
306 * If interpretation fails or in case of an error, return an error code.
308 static int __init dasd_parse_range(const char *range)
310 struct dasd_devmap *devmap;
311 int from, from_id0, from_id1;
312 int to, to_id0, to_id1;
314 char bus_id[DASD_BUS_ID_SIZE + 1];
315 char *features_str = NULL;
316 char *from_str = NULL;
321 tmp = kstrdup(range, GFP_KERNEL);
325 if (dasd_evaluate_range_param(tmp, &from_str, &to_str, &features_str)) {
330 if (dasd_busid(from_str, &from_id0, &from_id1, &from)) {
339 if (dasd_busid(to_str, &to_id0, &to_id1, &to)) {
343 if (from_id0 != to_id0 || from_id1 != to_id1 || from > to) {
344 pr_err("%s is not a valid device range\n", range);
350 features = dasd_feature_list(features_str);
355 /* each device in dasd= parameter should be set initially online */
356 features |= DASD_FEATURE_INITIAL_ONLINE;
358 sprintf(bus_id, "%01x.%01x.%04x", from_id0, from_id1, from++);
359 devmap = dasd_add_busid(bus_id, features);
360 if (IS_ERR(devmap)) {
361 rc = PTR_ERR(devmap);
373 * Parse parameters stored in dasd[]
374 * The 'dasd=...' parameter allows to specify a comma separated list of
375 * keywords and device ranges. The parameters in that list will be stored as
376 * separate elementes in dasd[].
378 int __init dasd_parse(void)
384 for (i = 0; i < DASD_MAX_PARAMS; i++) {
391 rc = dasd_parse_keyword(cur);
393 rc = dasd_parse_range(cur);
403 * Add a devmap for the device specified by busid. It is possible that
404 * the devmap already exists (dasd= parameter). The order of the devices
405 * added through this function will define the kdevs for the individual
408 static struct dasd_devmap *
409 dasd_add_busid(const char *bus_id, int features)
411 struct dasd_devmap *devmap, *new, *tmp;
414 new = kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
416 return ERR_PTR(-ENOMEM);
417 spin_lock(&dasd_devmap_lock);
419 hash = dasd_hash_busid(bus_id);
420 list_for_each_entry(tmp, &dasd_hashlists[hash], list)
421 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
426 /* This bus_id is new. */
427 new->devindex = dasd_max_devindex++;
428 strncpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
429 new->features = features;
431 list_add(&new->list, &dasd_hashlists[hash]);
435 spin_unlock(&dasd_devmap_lock);
441 * Find devmap for device with given bus_id.
443 static struct dasd_devmap *
444 dasd_find_busid(const char *bus_id)
446 struct dasd_devmap *devmap, *tmp;
449 spin_lock(&dasd_devmap_lock);
450 devmap = ERR_PTR(-ENODEV);
451 hash = dasd_hash_busid(bus_id);
452 list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
453 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
458 spin_unlock(&dasd_devmap_lock);
463 * Check if busid has been added to the list of dasd ranges.
466 dasd_busid_known(const char *bus_id)
468 return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
472 * Forget all about the device numbers added so far.
473 * This may only be called at module unload or system shutdown.
476 dasd_forget_ranges(void)
478 struct dasd_devmap *devmap, *n;
481 spin_lock(&dasd_devmap_lock);
482 for (i = 0; i < 256; i++) {
483 list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
484 BUG_ON(devmap->device != NULL);
485 list_del(&devmap->list);
489 spin_unlock(&dasd_devmap_lock);
493 * Find the device struct by its device index.
496 dasd_device_from_devindex(int devindex)
498 struct dasd_devmap *devmap, *tmp;
499 struct dasd_device *device;
502 spin_lock(&dasd_devmap_lock);
504 for (i = 0; (i < 256) && !devmap; i++)
505 list_for_each_entry(tmp, &dasd_hashlists[i], list)
506 if (tmp->devindex == devindex) {
507 /* Found the devmap for the device. */
511 if (devmap && devmap->device) {
512 device = devmap->device;
513 dasd_get_device(device);
515 device = ERR_PTR(-ENODEV);
516 spin_unlock(&dasd_devmap_lock);
521 * Return devmap for cdev. If no devmap exists yet, create one and
522 * connect it to the cdev.
524 static struct dasd_devmap *
525 dasd_devmap_from_cdev(struct ccw_device *cdev)
527 struct dasd_devmap *devmap;
529 devmap = dasd_find_busid(dev_name(&cdev->dev));
531 devmap = dasd_add_busid(dev_name(&cdev->dev),
532 DASD_FEATURE_DEFAULT);
537 * Create a dasd device structure for cdev.
540 dasd_create_device(struct ccw_device *cdev)
542 struct dasd_devmap *devmap;
543 struct dasd_device *device;
547 devmap = dasd_devmap_from_cdev(cdev);
549 return (void *) devmap;
551 device = dasd_alloc_device();
554 atomic_set(&device->ref_count, 3);
556 spin_lock(&dasd_devmap_lock);
557 if (!devmap->device) {
558 devmap->device = device;
559 device->devindex = devmap->devindex;
560 device->features = devmap->features;
561 get_device(&cdev->dev);
565 /* Someone else was faster. */
567 spin_unlock(&dasd_devmap_lock);
570 dasd_free_device(device);
574 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
575 dev_set_drvdata(&cdev->dev, device);
576 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
582 * Wait queue for dasd_delete_device waits.
584 static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
587 * Remove a dasd device structure. The passed referenced
591 dasd_delete_device(struct dasd_device *device)
593 struct ccw_device *cdev;
594 struct dasd_devmap *devmap;
597 /* First remove device pointer from devmap. */
598 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
599 BUG_ON(IS_ERR(devmap));
600 spin_lock(&dasd_devmap_lock);
601 if (devmap->device != device) {
602 spin_unlock(&dasd_devmap_lock);
603 dasd_put_device(device);
606 devmap->device = NULL;
607 spin_unlock(&dasd_devmap_lock);
609 /* Disconnect dasd_device structure from ccw_device structure. */
610 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
611 dev_set_drvdata(&device->cdev->dev, NULL);
612 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
615 * Drop ref_count by 3, one for the devmap reference, one for
616 * the cdev reference and one for the passed reference.
618 atomic_sub(3, &device->ref_count);
620 /* Wait for reference counter to drop to zero. */
621 wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
623 dasd_generic_free_discipline(device);
624 /* Disconnect dasd_device structure from ccw_device structure. */
628 /* Put ccw_device structure. */
629 put_device(&cdev->dev);
631 /* Now the device structure can be freed. */
632 dasd_free_device(device);
636 * Reference counter dropped to zero. Wake up waiter
637 * in dasd_delete_device.
640 dasd_put_device_wake(struct dasd_device *device)
642 wake_up(&dasd_delete_wq);
644 EXPORT_SYMBOL_GPL(dasd_put_device_wake);
647 * Return dasd_device structure associated with cdev.
648 * This function needs to be called with the ccw device
649 * lock held. It can be used from interrupt context.
652 dasd_device_from_cdev_locked(struct ccw_device *cdev)
654 struct dasd_device *device = dev_get_drvdata(&cdev->dev);
657 return ERR_PTR(-ENODEV);
658 dasd_get_device(device);
663 * Return dasd_device structure associated with cdev.
666 dasd_device_from_cdev(struct ccw_device *cdev)
668 struct dasd_device *device;
671 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
672 device = dasd_device_from_cdev_locked(cdev);
673 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
677 void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device)
679 struct dasd_devmap *devmap;
681 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
684 spin_lock(&dasd_devmap_lock);
685 gdp->private_data = devmap;
686 spin_unlock(&dasd_devmap_lock);
689 struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp)
691 struct dasd_device *device;
692 struct dasd_devmap *devmap;
694 if (!gdp->private_data)
697 spin_lock(&dasd_devmap_lock);
698 devmap = gdp->private_data;
699 if (devmap && devmap->device) {
700 device = devmap->device;
701 dasd_get_device(device);
703 spin_unlock(&dasd_devmap_lock);
708 * SECTION: files in sysfs
712 * failfast controls the behaviour, if no path is available
714 static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
717 struct dasd_devmap *devmap;
720 devmap = dasd_find_busid(dev_name(dev));
722 ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
724 ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
725 return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n");
728 static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
729 const char *buf, size_t count)
734 if (kstrtouint(buf, 0, &val) || val > 1)
737 rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_FAILFAST, val);
742 static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
745 * readonly controls the readonly status of a dasd
748 dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
750 struct dasd_devmap *devmap;
751 struct dasd_device *device;
754 devmap = dasd_find_busid(dev_name(dev));
758 ro_flag = !!(devmap->features & DASD_FEATURE_READONLY);
760 spin_lock(&dasd_devmap_lock);
761 device = devmap->device;
763 ro_flag |= test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
764 spin_unlock(&dasd_devmap_lock);
767 return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
771 dasd_ro_store(struct device *dev, struct device_attribute *attr,
772 const char *buf, size_t count)
774 struct ccw_device *cdev = to_ccwdev(dev);
775 struct dasd_device *device;
780 if (kstrtouint(buf, 0, &val) || val > 1)
783 rc = dasd_set_feature(cdev, DASD_FEATURE_READONLY, val);
787 device = dasd_device_from_cdev(cdev);
791 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
792 val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
794 if (!device->block || !device->block->gdp ||
795 test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
796 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
799 /* Increase open_count to avoid losing the block device */
800 atomic_inc(&device->block->open_count);
801 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
803 set_disk_ro(device->block->gdp, val);
804 atomic_dec(&device->block->open_count);
807 dasd_put_device(device);
812 static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
814 * erplog controls the logging of ERP related data
815 * (e.g. failing channel programs).
818 dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
820 struct dasd_devmap *devmap;
823 devmap = dasd_find_busid(dev_name(dev));
825 erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
827 erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
828 return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n");
832 dasd_erplog_store(struct device *dev, struct device_attribute *attr,
833 const char *buf, size_t count)
838 if (kstrtouint(buf, 0, &val) || val > 1)
841 rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_ERPLOG, val);
846 static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
849 * use_diag controls whether the driver should use diag rather than ssch
850 * to talk to the device
853 dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
855 struct dasd_devmap *devmap;
858 devmap = dasd_find_busid(dev_name(dev));
860 use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
862 use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
863 return sprintf(buf, use_diag ? "1\n" : "0\n");
867 dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
868 const char *buf, size_t count)
870 struct dasd_devmap *devmap;
874 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
876 return PTR_ERR(devmap);
878 if (kstrtouint(buf, 0, &val) || val > 1)
881 spin_lock(&dasd_devmap_lock);
882 /* Changing diag discipline flag is only allowed in offline state. */
884 if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) {
886 devmap->features |= DASD_FEATURE_USEDIAG;
888 devmap->features &= ~DASD_FEATURE_USEDIAG;
891 spin_unlock(&dasd_devmap_lock);
895 static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
898 * use_raw controls whether the driver should give access to raw eckd data or
899 * operate in standard mode
902 dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf)
904 struct dasd_devmap *devmap;
907 devmap = dasd_find_busid(dev_name(dev));
909 use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0;
911 use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0;
912 return sprintf(buf, use_raw ? "1\n" : "0\n");
916 dasd_use_raw_store(struct device *dev, struct device_attribute *attr,
917 const char *buf, size_t count)
919 struct dasd_devmap *devmap;
923 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
925 return PTR_ERR(devmap);
927 if ((kstrtoul(buf, 10, &val) != 0) || val > 1)
930 spin_lock(&dasd_devmap_lock);
931 /* Changing diag discipline flag is only allowed in offline state. */
933 if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) {
935 devmap->features |= DASD_FEATURE_USERAW;
937 devmap->features &= ~DASD_FEATURE_USERAW;
940 spin_unlock(&dasd_devmap_lock);
944 static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show,
948 dasd_safe_offline_store(struct device *dev, struct device_attribute *attr,
949 const char *buf, size_t count)
951 struct ccw_device *cdev = to_ccwdev(dev);
952 struct dasd_device *device;
956 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
957 device = dasd_device_from_cdev_locked(cdev);
958 if (IS_ERR(device)) {
959 rc = PTR_ERR(device);
960 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
964 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
965 test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
966 /* Already doing offline processing */
967 dasd_put_device(device);
968 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
973 set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags);
974 dasd_put_device(device);
975 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
977 rc = ccw_device_set_offline(cdev);
980 return rc ? rc : count;
983 static DEVICE_ATTR(safe_offline, 0200, NULL, dasd_safe_offline_store);
986 dasd_access_show(struct device *dev, struct device_attribute *attr,
989 struct ccw_device *cdev = to_ccwdev(dev);
990 struct dasd_device *device;
993 device = dasd_device_from_cdev(cdev);
995 return PTR_ERR(device);
997 if (!device->discipline)
999 else if (!device->discipline->host_access_count)
1000 count = -EOPNOTSUPP;
1002 count = device->discipline->host_access_count(device);
1004 dasd_put_device(device);
1008 return sprintf(buf, "%d\n", count);
1011 static DEVICE_ATTR(host_access_count, 0444, dasd_access_show, NULL);
1014 dasd_discipline_show(struct device *dev, struct device_attribute *attr,
1017 struct dasd_device *device;
1020 device = dasd_device_from_cdev(to_ccwdev(dev));
1023 else if (!device->discipline) {
1024 dasd_put_device(device);
1027 len = snprintf(buf, PAGE_SIZE, "%s\n",
1028 device->discipline->name);
1029 dasd_put_device(device);
1033 len = snprintf(buf, PAGE_SIZE, "none\n");
1037 static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
1040 dasd_device_status_show(struct device *dev, struct device_attribute *attr,
1043 struct dasd_device *device;
1046 device = dasd_device_from_cdev(to_ccwdev(dev));
1047 if (!IS_ERR(device)) {
1048 switch (device->state) {
1049 case DASD_STATE_NEW:
1050 len = snprintf(buf, PAGE_SIZE, "new\n");
1052 case DASD_STATE_KNOWN:
1053 len = snprintf(buf, PAGE_SIZE, "detected\n");
1055 case DASD_STATE_BASIC:
1056 len = snprintf(buf, PAGE_SIZE, "basic\n");
1058 case DASD_STATE_UNFMT:
1059 len = snprintf(buf, PAGE_SIZE, "unformatted\n");
1061 case DASD_STATE_READY:
1062 len = snprintf(buf, PAGE_SIZE, "ready\n");
1064 case DASD_STATE_ONLINE:
1065 len = snprintf(buf, PAGE_SIZE, "online\n");
1068 len = snprintf(buf, PAGE_SIZE, "no stat\n");
1071 dasd_put_device(device);
1073 len = snprintf(buf, PAGE_SIZE, "unknown\n");
1077 static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL);
1079 static ssize_t dasd_alias_show(struct device *dev,
1080 struct device_attribute *attr, char *buf)
1082 struct dasd_device *device;
1083 struct dasd_uid uid;
1085 device = dasd_device_from_cdev(to_ccwdev(dev));
1087 return sprintf(buf, "0\n");
1089 if (device->discipline && device->discipline->get_uid &&
1090 !device->discipline->get_uid(device, &uid)) {
1091 if (uid.type == UA_BASE_PAV_ALIAS ||
1092 uid.type == UA_HYPER_PAV_ALIAS) {
1093 dasd_put_device(device);
1094 return sprintf(buf, "1\n");
1097 dasd_put_device(device);
1099 return sprintf(buf, "0\n");
1102 static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
1104 static ssize_t dasd_vendor_show(struct device *dev,
1105 struct device_attribute *attr, char *buf)
1107 struct dasd_device *device;
1108 struct dasd_uid uid;
1111 device = dasd_device_from_cdev(to_ccwdev(dev));
1114 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
1116 if (device->discipline && device->discipline->get_uid &&
1117 !device->discipline->get_uid(device, &uid))
1118 vendor = uid.vendor;
1120 dasd_put_device(device);
1122 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
1125 static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
1127 #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
1128 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
1132 dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
1134 struct dasd_device *device;
1135 struct dasd_uid uid;
1136 char uid_string[UID_STRLEN];
1139 device = dasd_device_from_cdev(to_ccwdev(dev));
1142 return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
1144 if (device->discipline && device->discipline->get_uid &&
1145 !device->discipline->get_uid(device, &uid)) {
1147 case UA_BASE_DEVICE:
1148 snprintf(ua_string, sizeof(ua_string), "%02x",
1149 uid.real_unit_addr);
1151 case UA_BASE_PAV_ALIAS:
1152 snprintf(ua_string, sizeof(ua_string), "%02x",
1153 uid.base_unit_addr);
1155 case UA_HYPER_PAV_ALIAS:
1156 snprintf(ua_string, sizeof(ua_string), "xx");
1159 /* should not happen, treat like base device */
1160 snprintf(ua_string, sizeof(ua_string), "%02x",
1161 uid.real_unit_addr);
1165 if (strlen(uid.vduit) > 0)
1166 snprintf(uid_string, sizeof(uid_string),
1168 uid.vendor, uid.serial, uid.ssid, ua_string,
1171 snprintf(uid_string, sizeof(uid_string),
1173 uid.vendor, uid.serial, uid.ssid, ua_string);
1175 dasd_put_device(device);
1177 return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
1179 static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
1182 * extended error-reporting
1185 dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
1187 struct dasd_devmap *devmap;
1190 devmap = dasd_find_busid(dev_name(dev));
1191 if (!IS_ERR(devmap) && devmap->device)
1192 eer_flag = dasd_eer_enabled(devmap->device);
1195 return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
1199 dasd_eer_store(struct device *dev, struct device_attribute *attr,
1200 const char *buf, size_t count)
1202 struct dasd_device *device;
1206 device = dasd_device_from_cdev(to_ccwdev(dev));
1208 return PTR_ERR(device);
1210 if (kstrtouint(buf, 0, &val) || val > 1)
1214 rc = dasd_eer_enable(device);
1216 dasd_eer_disable(device);
1218 dasd_put_device(device);
1220 return rc ? : count;
1223 static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
1226 * expiration time for default requests
1229 dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf)
1231 struct dasd_device *device;
1234 device = dasd_device_from_cdev(to_ccwdev(dev));
1237 len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_expires);
1238 dasd_put_device(device);
1243 dasd_expires_store(struct device *dev, struct device_attribute *attr,
1244 const char *buf, size_t count)
1246 struct dasd_device *device;
1249 device = dasd_device_from_cdev(to_ccwdev(dev));
1253 if ((kstrtoul(buf, 10, &val) != 0) ||
1254 (val > DASD_EXPIRES_MAX) || val == 0) {
1255 dasd_put_device(device);
1260 device->default_expires = val;
1262 dasd_put_device(device);
1266 static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store);
1269 dasd_retries_show(struct device *dev, struct device_attribute *attr, char *buf)
1271 struct dasd_device *device;
1274 device = dasd_device_from_cdev(to_ccwdev(dev));
1277 len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_retries);
1278 dasd_put_device(device);
1283 dasd_retries_store(struct device *dev, struct device_attribute *attr,
1284 const char *buf, size_t count)
1286 struct dasd_device *device;
1289 device = dasd_device_from_cdev(to_ccwdev(dev));
1293 if ((kstrtoul(buf, 10, &val) != 0) ||
1294 (val > DASD_RETRIES_MAX)) {
1295 dasd_put_device(device);
1300 device->default_retries = val;
1302 dasd_put_device(device);
1306 static DEVICE_ATTR(retries, 0644, dasd_retries_show, dasd_retries_store);
1309 dasd_timeout_show(struct device *dev, struct device_attribute *attr,
1312 struct dasd_device *device;
1315 device = dasd_device_from_cdev(to_ccwdev(dev));
1318 len = snprintf(buf, PAGE_SIZE, "%lu\n", device->blk_timeout);
1319 dasd_put_device(device);
1324 dasd_timeout_store(struct device *dev, struct device_attribute *attr,
1325 const char *buf, size_t count)
1327 struct dasd_device *device;
1328 struct request_queue *q;
1331 device = dasd_device_from_cdev(to_ccwdev(dev));
1332 if (IS_ERR(device) || !device->block)
1335 if ((kstrtoul(buf, 10, &val) != 0) ||
1336 val > UINT_MAX / HZ) {
1337 dasd_put_device(device);
1340 q = device->block->request_queue;
1342 dasd_put_device(device);
1346 device->blk_timeout = val;
1348 blk_queue_rq_timeout(q, device->blk_timeout * HZ);
1350 dasd_put_device(device);
1354 static DEVICE_ATTR(timeout, 0644,
1355 dasd_timeout_show, dasd_timeout_store);
1359 dasd_path_reset_store(struct device *dev, struct device_attribute *attr,
1360 const char *buf, size_t count)
1362 struct dasd_device *device;
1365 device = dasd_device_from_cdev(to_ccwdev(dev));
1369 if ((kstrtouint(buf, 16, &val) != 0) || val > 0xff)
1372 if (device->discipline && device->discipline->reset_path)
1373 device->discipline->reset_path(device, (__u8) val);
1375 dasd_put_device(device);
1379 static DEVICE_ATTR(path_reset, 0200, NULL, dasd_path_reset_store);
1381 static ssize_t dasd_hpf_show(struct device *dev, struct device_attribute *attr,
1384 struct dasd_device *device;
1387 device = dasd_device_from_cdev(to_ccwdev(dev));
1390 if (!device->discipline || !device->discipline->hpf_enabled) {
1391 dasd_put_device(device);
1392 return snprintf(buf, PAGE_SIZE, "%d\n", dasd_nofcx);
1394 hpf = device->discipline->hpf_enabled(device);
1395 dasd_put_device(device);
1396 return snprintf(buf, PAGE_SIZE, "%d\n", hpf);
1399 static DEVICE_ATTR(hpf, 0444, dasd_hpf_show, NULL);
1401 static ssize_t dasd_reservation_policy_show(struct device *dev,
1402 struct device_attribute *attr,
1405 struct dasd_devmap *devmap;
1408 devmap = dasd_find_busid(dev_name(dev));
1409 if (IS_ERR(devmap)) {
1410 rc = snprintf(buf, PAGE_SIZE, "ignore\n");
1412 spin_lock(&dasd_devmap_lock);
1413 if (devmap->features & DASD_FEATURE_FAILONSLCK)
1414 rc = snprintf(buf, PAGE_SIZE, "fail\n");
1416 rc = snprintf(buf, PAGE_SIZE, "ignore\n");
1417 spin_unlock(&dasd_devmap_lock);
1422 static ssize_t dasd_reservation_policy_store(struct device *dev,
1423 struct device_attribute *attr,
1424 const char *buf, size_t count)
1426 struct ccw_device *cdev = to_ccwdev(dev);
1429 if (sysfs_streq("ignore", buf))
1430 rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 0);
1431 else if (sysfs_streq("fail", buf))
1432 rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 1);
1436 return rc ? : count;
1439 static DEVICE_ATTR(reservation_policy, 0644,
1440 dasd_reservation_policy_show, dasd_reservation_policy_store);
1442 static ssize_t dasd_reservation_state_show(struct device *dev,
1443 struct device_attribute *attr,
1446 struct dasd_device *device;
1449 device = dasd_device_from_cdev(to_ccwdev(dev));
1451 return snprintf(buf, PAGE_SIZE, "none\n");
1453 if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags))
1454 rc = snprintf(buf, PAGE_SIZE, "reserved\n");
1455 else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags))
1456 rc = snprintf(buf, PAGE_SIZE, "lost\n");
1458 rc = snprintf(buf, PAGE_SIZE, "none\n");
1459 dasd_put_device(device);
1463 static ssize_t dasd_reservation_state_store(struct device *dev,
1464 struct device_attribute *attr,
1465 const char *buf, size_t count)
1467 struct dasd_device *device;
1470 device = dasd_device_from_cdev(to_ccwdev(dev));
1473 if (sysfs_streq("reset", buf))
1474 clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
1477 dasd_put_device(device);
1485 static DEVICE_ATTR(last_known_reservation_state, 0644,
1486 dasd_reservation_state_show, dasd_reservation_state_store);
1488 static ssize_t dasd_pm_show(struct device *dev,
1489 struct device_attribute *attr, char *buf)
1491 struct dasd_device *device;
1492 u8 opm, nppm, cablepm, cuirpm, hpfpm, ifccpm;
1494 device = dasd_device_from_cdev(to_ccwdev(dev));
1496 return sprintf(buf, "0\n");
1498 opm = dasd_path_get_opm(device);
1499 nppm = dasd_path_get_nppm(device);
1500 cablepm = dasd_path_get_cablepm(device);
1501 cuirpm = dasd_path_get_cuirpm(device);
1502 hpfpm = dasd_path_get_hpfpm(device);
1503 ifccpm = dasd_path_get_ifccpm(device);
1504 dasd_put_device(device);
1506 return sprintf(buf, "%02x %02x %02x %02x %02x %02x\n", opm, nppm,
1507 cablepm, cuirpm, hpfpm, ifccpm);
1510 static DEVICE_ATTR(path_masks, 0444, dasd_pm_show, NULL);
1513 * threshold value for IFCC/CCC errors
1516 dasd_path_threshold_show(struct device *dev,
1517 struct device_attribute *attr, char *buf)
1519 struct dasd_device *device;
1522 device = dasd_device_from_cdev(to_ccwdev(dev));
1525 len = snprintf(buf, PAGE_SIZE, "%lu\n", device->path_thrhld);
1526 dasd_put_device(device);
1531 dasd_path_threshold_store(struct device *dev, struct device_attribute *attr,
1532 const char *buf, size_t count)
1534 struct dasd_device *device;
1535 unsigned long flags;
1538 device = dasd_device_from_cdev(to_ccwdev(dev));
1542 if (kstrtoul(buf, 10, &val) != 0 || val > DASD_THRHLD_MAX) {
1543 dasd_put_device(device);
1546 spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags);
1547 device->path_thrhld = val;
1548 spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags);
1549 dasd_put_device(device);
1553 static DEVICE_ATTR(path_threshold, 0644, dasd_path_threshold_show,
1554 dasd_path_threshold_store);
1556 * interval for IFCC/CCC checks
1557 * meaning time with no IFCC/CCC error before the error counter
1561 dasd_path_interval_show(struct device *dev,
1562 struct device_attribute *attr, char *buf)
1564 struct dasd_device *device;
1567 device = dasd_device_from_cdev(to_ccwdev(dev));
1570 len = snprintf(buf, PAGE_SIZE, "%lu\n", device->path_interval);
1571 dasd_put_device(device);
1576 dasd_path_interval_store(struct device *dev, struct device_attribute *attr,
1577 const char *buf, size_t count)
1579 struct dasd_device *device;
1580 unsigned long flags;
1583 device = dasd_device_from_cdev(to_ccwdev(dev));
1587 if ((kstrtoul(buf, 10, &val) != 0) ||
1588 (val > DASD_INTERVAL_MAX) || val == 0) {
1589 dasd_put_device(device);
1592 spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags);
1594 device->path_interval = val;
1595 spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags);
1596 dasd_put_device(device);
1600 static DEVICE_ATTR(path_interval, 0644, dasd_path_interval_show,
1601 dasd_path_interval_store);
1604 static struct attribute * dasd_attrs[] = {
1605 &dev_attr_readonly.attr,
1606 &dev_attr_discipline.attr,
1607 &dev_attr_status.attr,
1608 &dev_attr_alias.attr,
1609 &dev_attr_vendor.attr,
1611 &dev_attr_use_diag.attr,
1612 &dev_attr_raw_track_access.attr,
1613 &dev_attr_eer_enabled.attr,
1614 &dev_attr_erplog.attr,
1615 &dev_attr_failfast.attr,
1616 &dev_attr_expires.attr,
1617 &dev_attr_retries.attr,
1618 &dev_attr_timeout.attr,
1619 &dev_attr_reservation_policy.attr,
1620 &dev_attr_last_known_reservation_state.attr,
1621 &dev_attr_safe_offline.attr,
1622 &dev_attr_host_access_count.attr,
1623 &dev_attr_path_masks.attr,
1624 &dev_attr_path_threshold.attr,
1625 &dev_attr_path_interval.attr,
1626 &dev_attr_path_reset.attr,
1631 static const struct attribute_group dasd_attr_group = {
1632 .attrs = dasd_attrs,
1636 * Return value of the specified feature.
1639 dasd_get_feature(struct ccw_device *cdev, int feature)
1641 struct dasd_devmap *devmap;
1643 devmap = dasd_find_busid(dev_name(&cdev->dev));
1645 return PTR_ERR(devmap);
1647 return ((devmap->features & feature) != 0);
1651 * Set / reset given feature.
1652 * Flag indicates whether to set (!=0) or the reset (=0) the feature.
1655 dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
1657 struct dasd_devmap *devmap;
1659 devmap = dasd_devmap_from_cdev(cdev);
1661 return PTR_ERR(devmap);
1663 spin_lock(&dasd_devmap_lock);
1665 devmap->features |= feature;
1667 devmap->features &= ~feature;
1669 devmap->device->features = devmap->features;
1670 spin_unlock(&dasd_devmap_lock);
1673 EXPORT_SYMBOL(dasd_set_feature);
1677 dasd_add_sysfs_files(struct ccw_device *cdev)
1679 return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
1683 dasd_remove_sysfs_files(struct ccw_device *cdev)
1685 sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
1690 dasd_devmap_init(void)
1694 /* Initialize devmap structures. */
1695 dasd_max_devindex = 0;
1696 for (i = 0; i < 256; i++)
1697 INIT_LIST_HEAD(&dasd_hashlists[i]);
1702 dasd_devmap_exit(void)
1704 dasd_forget_ranges();