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 <asm/uaccess.h>
27 #define PRINTK_HEADER "dasd_devmap:"
28 #define DASD_BUS_ID_SIZE 20
32 struct kmem_cache *dasd_page_cache;
33 EXPORT_SYMBOL_GPL(dasd_page_cache);
36 * dasd_devmap_t is used to store the features and the relation
37 * between device number and device index. To find a dasd_devmap_t
38 * that corresponds to a device number of a device index each
39 * dasd_devmap_t is added to two linked lists, one to search by
40 * the device number and one to search by the device index. As
41 * soon as big minor numbers are available the device index list
42 * can be removed since the device number will then be identical
43 * to the device index.
46 struct list_head list;
47 char bus_id[DASD_BUS_ID_SIZE];
48 unsigned int devindex;
49 unsigned short features;
50 struct dasd_device *device;
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[256];
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++)
108 * The parameter parsing functions for builtin-drivers are called
109 * before kmalloc works. Store the pointers to the parameters strings
110 * into dasd[] for later processing.
113 dasd_call_setup(char *str)
115 static int count = 0;
122 __setup ("dasd=", dasd_call_setup);
123 #endif /* #ifndef MODULE */
125 #define DASD_IPLDEV "ipldev"
128 * Read a device busid/devno from a string.
132 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;
145 *str += strlen(DASD_IPLDEV);
149 /* check for leading '0x' */
151 if ((*str)[0] == '0' && (*str)[1] == 'x') {
155 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
157 val = simple_strtoul(*str, str, 16);
158 if (old_style || (*str)[0] != '.') {
160 if (val < 0 || val > 0xffff)
165 /* New style x.y.z busid */
166 if (val < 0 || val > 0xff)
170 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
172 val = simple_strtoul(*str, str, 16);
173 if (val < 0 || val > 0xff || (*str)++[0] != '.')
176 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
178 val = simple_strtoul(*str, str, 16);
179 if (val < 0 || val > 0xffff)
186 * Read colon separated list of dasd features. Currently there is
187 * only one: "ro" for read-only devices. The default feature set
188 * is empty (value 0).
191 dasd_feature_list(char *str, char **endp)
193 int features, len, rc;
198 return DASD_FEATURE_DEFAULT;
205 str[len] && str[len] != ':' && str[len] != ')'; len++);
206 if (len == 2 && !strncmp(str, "ro", 2))
207 features |= DASD_FEATURE_READONLY;
208 else if (len == 4 && !strncmp(str, "diag", 4))
209 features |= DASD_FEATURE_USEDIAG;
210 else if (len == 3 && !strncmp(str, "raw", 3))
211 features |= DASD_FEATURE_USERAW;
212 else if (len == 6 && !strncmp(str, "erplog", 6))
213 features |= DASD_FEATURE_ERPLOG;
214 else if (len == 8 && !strncmp(str, "failfast", 8))
215 features |= DASD_FEATURE_FAILFAST;
217 pr_warn("%*s is not a supported device option\n",
227 pr_warn("A closing parenthesis ')' is missing in the dasd= parameter\n");
238 * Try to match the first element on the comma separated parse string
239 * with one of the known keywords. If a keyword is found, take the approprate
240 * action and return a pointer to the residual string. If the first element
241 * could not be matched to any keyword then return an error code.
244 dasd_parse_keyword( char *parsestring ) {
246 char *nextcomma, *residual_str;
249 nextcomma = strchr(parsestring,',');
251 length = nextcomma - parsestring;
252 residual_str = nextcomma + 1;
254 length = strlen(parsestring);
255 residual_str = parsestring + length;
257 if (strncmp("autodetect", parsestring, length) == 0) {
259 pr_info("The autodetection mode has been activated\n");
262 if (strncmp("probeonly", parsestring, length) == 0) {
264 pr_info("The probeonly mode has been activated\n");
267 if (strncmp("nopav", parsestring, length) == 0) {
269 pr_info("'nopav' is not supported on z/VM\n");
272 pr_info("PAV support has be deactivated\n");
276 if (strncmp("nofcx", parsestring, length) == 0) {
278 pr_info("High Performance FICON support has been "
282 if (strncmp("fixedbuffers", parsestring, length) == 0) {
286 kmem_cache_create("dasd_page_cache", PAGE_SIZE,
287 PAGE_SIZE, SLAB_CACHE_DMA,
289 if (!dasd_page_cache)
290 DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, "
291 "fixed buffer mode disabled.");
293 DBF_EVENT(DBF_INFO, "%s",
294 "turning on fixed buffer mode");
297 return ERR_PTR(-EINVAL);
301 * Try to interprete the first element on the comma separated parse string
302 * as a device number or a range of devices. If the interpretation is
303 * successful, create the matching dasd_devmap entries and return a pointer
304 * to the residual string.
305 * If interpretation fails or in case of an error, return an error code.
308 dasd_parse_range( char *parsestring ) {
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], *str;
317 rc = dasd_busid(&str, &from_id0, &from_id1, &from);
324 rc = dasd_busid(&str, &to_id0, &to_id1, &to);
328 (from_id0 != to_id0 || from_id1 != to_id1 || from > to))
331 pr_err("%s is not a valid device range\n", parsestring);
334 features = dasd_feature_list(str, &str);
336 return ERR_PTR(-EINVAL);
337 /* each device in dasd= parameter should be set initially online */
338 features |= DASD_FEATURE_INITIAL_ONLINE;
340 sprintf(bus_id, "%01x.%01x.%04x",
341 from_id0, from_id1, from++);
342 devmap = dasd_add_busid(bus_id, features);
344 return (char *)devmap;
350 pr_warn("The dasd= parameter value %s has an invalid ending\n", str);
351 return ERR_PTR(-EINVAL);
355 dasd_parse_next_element( char *parsestring ) {
357 residual_str = dasd_parse_keyword(parsestring);
358 if (!IS_ERR(residual_str))
360 residual_str = dasd_parse_range(parsestring);
365 * Parse parameters stored in dasd[]
366 * The 'dasd=...' parameter allows to specify a comma separated list of
367 * keywords and device ranges. When the dasd driver is build into the kernel,
368 * the complete list will be stored as one element of the dasd[] array.
369 * When the dasd driver is build as a module, then the list is broken into
370 * it's elements and each dasd[] entry contains one element.
379 for (i = 0; i < 256; i++) {
382 parsestring = dasd[i];
383 /* loop over the comma separated list in the parsestring */
384 while (*parsestring) {
385 parsestring = dasd_parse_next_element(parsestring);
386 if(IS_ERR(parsestring)) {
387 rc = PTR_ERR(parsestring);
392 DBF_EVENT(DBF_ALERT, "%s", "invalid range found");
400 * Add a devmap for the device specified by busid. It is possible that
401 * the devmap already exists (dasd= parameter). The order of the devices
402 * added through this function will define the kdevs for the individual
405 static struct dasd_devmap *
406 dasd_add_busid(const char *bus_id, int features)
408 struct dasd_devmap *devmap, *new, *tmp;
411 new = kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
413 return ERR_PTR(-ENOMEM);
414 spin_lock(&dasd_devmap_lock);
416 hash = dasd_hash_busid(bus_id);
417 list_for_each_entry(tmp, &dasd_hashlists[hash], list)
418 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
423 /* This bus_id is new. */
424 new->devindex = dasd_max_devindex++;
425 strncpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
426 new->features = features;
428 list_add(&new->list, &dasd_hashlists[hash]);
432 spin_unlock(&dasd_devmap_lock);
438 * Find devmap for device with given bus_id.
440 static struct dasd_devmap *
441 dasd_find_busid(const char *bus_id)
443 struct dasd_devmap *devmap, *tmp;
446 spin_lock(&dasd_devmap_lock);
447 devmap = ERR_PTR(-ENODEV);
448 hash = dasd_hash_busid(bus_id);
449 list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
450 if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) {
455 spin_unlock(&dasd_devmap_lock);
460 * Check if busid has been added to the list of dasd ranges.
463 dasd_busid_known(const char *bus_id)
465 return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
469 * Forget all about the device numbers added so far.
470 * This may only be called at module unload or system shutdown.
473 dasd_forget_ranges(void)
475 struct dasd_devmap *devmap, *n;
478 spin_lock(&dasd_devmap_lock);
479 for (i = 0; i < 256; i++) {
480 list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
481 BUG_ON(devmap->device != NULL);
482 list_del(&devmap->list);
486 spin_unlock(&dasd_devmap_lock);
490 * Find the device struct by its device index.
493 dasd_device_from_devindex(int devindex)
495 struct dasd_devmap *devmap, *tmp;
496 struct dasd_device *device;
499 spin_lock(&dasd_devmap_lock);
501 for (i = 0; (i < 256) && !devmap; i++)
502 list_for_each_entry(tmp, &dasd_hashlists[i], list)
503 if (tmp->devindex == devindex) {
504 /* Found the devmap for the device. */
508 if (devmap && devmap->device) {
509 device = devmap->device;
510 dasd_get_device(device);
512 device = ERR_PTR(-ENODEV);
513 spin_unlock(&dasd_devmap_lock);
518 * Return devmap for cdev. If no devmap exists yet, create one and
519 * connect it to the cdev.
521 static struct dasd_devmap *
522 dasd_devmap_from_cdev(struct ccw_device *cdev)
524 struct dasd_devmap *devmap;
526 devmap = dasd_find_busid(dev_name(&cdev->dev));
528 devmap = dasd_add_busid(dev_name(&cdev->dev),
529 DASD_FEATURE_DEFAULT);
534 * Create a dasd device structure for cdev.
537 dasd_create_device(struct ccw_device *cdev)
539 struct dasd_devmap *devmap;
540 struct dasd_device *device;
544 devmap = dasd_devmap_from_cdev(cdev);
546 return (void *) devmap;
548 device = dasd_alloc_device();
551 atomic_set(&device->ref_count, 3);
553 spin_lock(&dasd_devmap_lock);
554 if (!devmap->device) {
555 devmap->device = device;
556 device->devindex = devmap->devindex;
557 device->features = devmap->features;
558 get_device(&cdev->dev);
562 /* Someone else was faster. */
564 spin_unlock(&dasd_devmap_lock);
567 dasd_free_device(device);
571 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
572 dev_set_drvdata(&cdev->dev, device);
573 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
579 * Wait queue for dasd_delete_device waits.
581 static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
584 * Remove a dasd device structure. The passed referenced
588 dasd_delete_device(struct dasd_device *device)
590 struct ccw_device *cdev;
591 struct dasd_devmap *devmap;
594 /* First remove device pointer from devmap. */
595 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
596 BUG_ON(IS_ERR(devmap));
597 spin_lock(&dasd_devmap_lock);
598 if (devmap->device != device) {
599 spin_unlock(&dasd_devmap_lock);
600 dasd_put_device(device);
603 devmap->device = NULL;
604 spin_unlock(&dasd_devmap_lock);
606 /* Disconnect dasd_device structure from ccw_device structure. */
607 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
608 dev_set_drvdata(&device->cdev->dev, NULL);
609 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
612 * Drop ref_count by 3, one for the devmap reference, one for
613 * the cdev reference and one for the passed reference.
615 atomic_sub(3, &device->ref_count);
617 /* Wait for reference counter to drop to zero. */
618 wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
620 dasd_generic_free_discipline(device);
621 /* Disconnect dasd_device structure from ccw_device structure. */
625 /* Put ccw_device structure. */
626 put_device(&cdev->dev);
628 /* Now the device structure can be freed. */
629 dasd_free_device(device);
633 * Reference counter dropped to zero. Wake up waiter
634 * in dasd_delete_device.
637 dasd_put_device_wake(struct dasd_device *device)
639 wake_up(&dasd_delete_wq);
641 EXPORT_SYMBOL_GPL(dasd_put_device_wake);
644 * Return dasd_device structure associated with cdev.
645 * This function needs to be called with the ccw device
646 * lock held. It can be used from interrupt context.
649 dasd_device_from_cdev_locked(struct ccw_device *cdev)
651 struct dasd_device *device = dev_get_drvdata(&cdev->dev);
654 return ERR_PTR(-ENODEV);
655 dasd_get_device(device);
660 * Return dasd_device structure associated with cdev.
663 dasd_device_from_cdev(struct ccw_device *cdev)
665 struct dasd_device *device;
668 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
669 device = dasd_device_from_cdev_locked(cdev);
670 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
674 void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device)
676 struct dasd_devmap *devmap;
678 devmap = dasd_find_busid(dev_name(&device->cdev->dev));
681 spin_lock(&dasd_devmap_lock);
682 gdp->private_data = devmap;
683 spin_unlock(&dasd_devmap_lock);
686 struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp)
688 struct dasd_device *device;
689 struct dasd_devmap *devmap;
691 if (!gdp->private_data)
694 spin_lock(&dasd_devmap_lock);
695 devmap = gdp->private_data;
696 if (devmap && devmap->device) {
697 device = devmap->device;
698 dasd_get_device(device);
700 spin_unlock(&dasd_devmap_lock);
705 * SECTION: files in sysfs
709 * failfast controls the behaviour, if no path is available
711 static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
714 struct dasd_devmap *devmap;
717 devmap = dasd_find_busid(dev_name(dev));
719 ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
721 ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
722 return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n");
725 static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
726 const char *buf, size_t count)
728 struct dasd_devmap *devmap;
732 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
734 return PTR_ERR(devmap);
736 val = simple_strtoul(buf, &endp, 0);
737 if (((endp + 1) < (buf + count)) || (val > 1))
740 spin_lock(&dasd_devmap_lock);
742 devmap->features |= DASD_FEATURE_FAILFAST;
744 devmap->features &= ~DASD_FEATURE_FAILFAST;
746 devmap->device->features = devmap->features;
747 spin_unlock(&dasd_devmap_lock);
751 static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
754 * readonly controls the readonly status of a dasd
757 dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
759 struct dasd_devmap *devmap;
762 devmap = dasd_find_busid(dev_name(dev));
764 ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
766 ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
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 dasd_devmap *devmap;
775 struct dasd_device *device;
779 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
781 return PTR_ERR(devmap);
783 val = simple_strtoul(buf, &endp, 0);
784 if (((endp + 1) < (buf + count)) || (val > 1))
787 spin_lock(&dasd_devmap_lock);
789 devmap->features |= DASD_FEATURE_READONLY;
791 devmap->features &= ~DASD_FEATURE_READONLY;
792 device = devmap->device;
794 device->features = devmap->features;
795 val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
797 spin_unlock(&dasd_devmap_lock);
798 if (device && device->block && device->block->gdp)
799 set_disk_ro(device->block->gdp, val);
803 static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
805 * erplog controls the logging of ERP related data
806 * (e.g. failing channel programs).
809 dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
811 struct dasd_devmap *devmap;
814 devmap = dasd_find_busid(dev_name(dev));
816 erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
818 erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
819 return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n");
823 dasd_erplog_store(struct device *dev, struct device_attribute *attr,
824 const char *buf, size_t count)
826 struct dasd_devmap *devmap;
830 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
832 return PTR_ERR(devmap);
834 val = simple_strtoul(buf, &endp, 0);
835 if (((endp + 1) < (buf + count)) || (val > 1))
838 spin_lock(&dasd_devmap_lock);
840 devmap->features |= DASD_FEATURE_ERPLOG;
842 devmap->features &= ~DASD_FEATURE_ERPLOG;
844 devmap->device->features = devmap->features;
845 spin_unlock(&dasd_devmap_lock);
849 static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
852 * use_diag controls whether the driver should use diag rather than ssch
853 * to talk to the device
856 dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
858 struct dasd_devmap *devmap;
861 devmap = dasd_find_busid(dev_name(dev));
863 use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
865 use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
866 return sprintf(buf, use_diag ? "1\n" : "0\n");
870 dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
871 const char *buf, size_t count)
873 struct dasd_devmap *devmap;
878 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
880 return PTR_ERR(devmap);
882 val = simple_strtoul(buf, &endp, 0);
883 if (((endp + 1) < (buf + count)) || (val > 1))
886 spin_lock(&dasd_devmap_lock);
887 /* Changing diag discipline flag is only allowed in offline state. */
889 if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) {
891 devmap->features |= DASD_FEATURE_USEDIAG;
893 devmap->features &= ~DASD_FEATURE_USEDIAG;
896 spin_unlock(&dasd_devmap_lock);
900 static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
903 * use_raw controls whether the driver should give access to raw eckd data or
904 * operate in standard mode
907 dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf)
909 struct dasd_devmap *devmap;
912 devmap = dasd_find_busid(dev_name(dev));
914 use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0;
916 use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0;
917 return sprintf(buf, use_raw ? "1\n" : "0\n");
921 dasd_use_raw_store(struct device *dev, struct device_attribute *attr,
922 const char *buf, size_t count)
924 struct dasd_devmap *devmap;
928 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
930 return PTR_ERR(devmap);
932 if ((kstrtoul(buf, 10, &val) != 0) || val > 1)
935 spin_lock(&dasd_devmap_lock);
936 /* Changing diag discipline flag is only allowed in offline state. */
938 if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) {
940 devmap->features |= DASD_FEATURE_USERAW;
942 devmap->features &= ~DASD_FEATURE_USERAW;
945 spin_unlock(&dasd_devmap_lock);
949 static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show,
953 dasd_safe_offline_store(struct device *dev, struct device_attribute *attr,
954 const char *buf, size_t count)
956 struct ccw_device *cdev = to_ccwdev(dev);
957 struct dasd_device *device;
960 device = dasd_device_from_cdev(cdev);
961 if (IS_ERR(device)) {
962 rc = PTR_ERR(device);
966 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
967 test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
968 /* Already doing offline processing */
969 dasd_put_device(device);
974 set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags);
975 dasd_put_device(device);
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->host_access_count)
998 count = device->discipline->host_access_count(device);
1000 count = -EOPNOTSUPP;
1002 dasd_put_device(device);
1006 return sprintf(buf, "%d\n", count);
1009 static DEVICE_ATTR(host_access_count, 0444, dasd_access_show, NULL);
1012 dasd_discipline_show(struct device *dev, struct device_attribute *attr,
1015 struct dasd_device *device;
1018 device = dasd_device_from_cdev(to_ccwdev(dev));
1021 else if (!device->discipline) {
1022 dasd_put_device(device);
1025 len = snprintf(buf, PAGE_SIZE, "%s\n",
1026 device->discipline->name);
1027 dasd_put_device(device);
1031 len = snprintf(buf, PAGE_SIZE, "none\n");
1035 static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
1038 dasd_device_status_show(struct device *dev, struct device_attribute *attr,
1041 struct dasd_device *device;
1044 device = dasd_device_from_cdev(to_ccwdev(dev));
1045 if (!IS_ERR(device)) {
1046 switch (device->state) {
1047 case DASD_STATE_NEW:
1048 len = snprintf(buf, PAGE_SIZE, "new\n");
1050 case DASD_STATE_KNOWN:
1051 len = snprintf(buf, PAGE_SIZE, "detected\n");
1053 case DASD_STATE_BASIC:
1054 len = snprintf(buf, PAGE_SIZE, "basic\n");
1056 case DASD_STATE_UNFMT:
1057 len = snprintf(buf, PAGE_SIZE, "unformatted\n");
1059 case DASD_STATE_READY:
1060 len = snprintf(buf, PAGE_SIZE, "ready\n");
1062 case DASD_STATE_ONLINE:
1063 len = snprintf(buf, PAGE_SIZE, "online\n");
1066 len = snprintf(buf, PAGE_SIZE, "no stat\n");
1069 dasd_put_device(device);
1071 len = snprintf(buf, PAGE_SIZE, "unknown\n");
1075 static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL);
1077 static ssize_t dasd_alias_show(struct device *dev,
1078 struct device_attribute *attr, char *buf)
1080 struct dasd_device *device;
1081 struct dasd_uid uid;
1083 device = dasd_device_from_cdev(to_ccwdev(dev));
1085 return sprintf(buf, "0\n");
1087 if (device->discipline && device->discipline->get_uid &&
1088 !device->discipline->get_uid(device, &uid)) {
1089 if (uid.type == UA_BASE_PAV_ALIAS ||
1090 uid.type == UA_HYPER_PAV_ALIAS) {
1091 dasd_put_device(device);
1092 return sprintf(buf, "1\n");
1095 dasd_put_device(device);
1097 return sprintf(buf, "0\n");
1100 static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
1102 static ssize_t dasd_vendor_show(struct device *dev,
1103 struct device_attribute *attr, char *buf)
1105 struct dasd_device *device;
1106 struct dasd_uid uid;
1109 device = dasd_device_from_cdev(to_ccwdev(dev));
1112 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
1114 if (device->discipline && device->discipline->get_uid &&
1115 !device->discipline->get_uid(device, &uid))
1116 vendor = uid.vendor;
1118 dasd_put_device(device);
1120 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
1123 static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
1125 #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
1126 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
1130 dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
1132 struct dasd_device *device;
1133 struct dasd_uid uid;
1134 char uid_string[UID_STRLEN];
1137 device = dasd_device_from_cdev(to_ccwdev(dev));
1140 return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
1142 if (device->discipline && device->discipline->get_uid &&
1143 !device->discipline->get_uid(device, &uid)) {
1145 case UA_BASE_DEVICE:
1146 snprintf(ua_string, sizeof(ua_string), "%02x",
1147 uid.real_unit_addr);
1149 case UA_BASE_PAV_ALIAS:
1150 snprintf(ua_string, sizeof(ua_string), "%02x",
1151 uid.base_unit_addr);
1153 case UA_HYPER_PAV_ALIAS:
1154 snprintf(ua_string, sizeof(ua_string), "xx");
1157 /* should not happen, treat like base device */
1158 snprintf(ua_string, sizeof(ua_string), "%02x",
1159 uid.real_unit_addr);
1163 if (strlen(uid.vduit) > 0)
1164 snprintf(uid_string, sizeof(uid_string),
1166 uid.vendor, uid.serial, uid.ssid, ua_string,
1169 snprintf(uid_string, sizeof(uid_string),
1171 uid.vendor, uid.serial, uid.ssid, ua_string);
1173 dasd_put_device(device);
1175 return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
1177 static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
1180 * extended error-reporting
1183 dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
1185 struct dasd_devmap *devmap;
1188 devmap = dasd_find_busid(dev_name(dev));
1189 if (!IS_ERR(devmap) && devmap->device)
1190 eer_flag = dasd_eer_enabled(devmap->device);
1193 return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
1197 dasd_eer_store(struct device *dev, struct device_attribute *attr,
1198 const char *buf, size_t count)
1200 struct dasd_devmap *devmap;
1204 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1206 return PTR_ERR(devmap);
1207 if (!devmap->device)
1210 val = simple_strtoul(buf, &endp, 0);
1211 if (((endp + 1) < (buf + count)) || (val > 1))
1215 rc = dasd_eer_enable(devmap->device);
1219 dasd_eer_disable(devmap->device);
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;
1329 unsigned long val, flags;
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);
1345 spin_lock_irqsave(&device->block->request_queue_lock, flags);
1347 blk_queue_rq_timed_out(q, NULL);
1349 blk_queue_rq_timed_out(q, dasd_times_out);
1351 device->blk_timeout = val;
1353 blk_queue_rq_timeout(q, device->blk_timeout * HZ);
1354 spin_unlock_irqrestore(&device->block->request_queue_lock, flags);
1356 dasd_put_device(device);
1360 static DEVICE_ATTR(timeout, 0644,
1361 dasd_timeout_show, dasd_timeout_store);
1363 static ssize_t dasd_reservation_policy_show(struct device *dev,
1364 struct device_attribute *attr,
1367 struct dasd_devmap *devmap;
1370 devmap = dasd_find_busid(dev_name(dev));
1371 if (IS_ERR(devmap)) {
1372 rc = snprintf(buf, PAGE_SIZE, "ignore\n");
1374 spin_lock(&dasd_devmap_lock);
1375 if (devmap->features & DASD_FEATURE_FAILONSLCK)
1376 rc = snprintf(buf, PAGE_SIZE, "fail\n");
1378 rc = snprintf(buf, PAGE_SIZE, "ignore\n");
1379 spin_unlock(&dasd_devmap_lock);
1384 static ssize_t dasd_reservation_policy_store(struct device *dev,
1385 struct device_attribute *attr,
1386 const char *buf, size_t count)
1388 struct dasd_devmap *devmap;
1391 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
1393 return PTR_ERR(devmap);
1395 spin_lock(&dasd_devmap_lock);
1396 if (sysfs_streq("ignore", buf))
1397 devmap->features &= ~DASD_FEATURE_FAILONSLCK;
1398 else if (sysfs_streq("fail", buf))
1399 devmap->features |= DASD_FEATURE_FAILONSLCK;
1403 devmap->device->features = devmap->features;
1404 spin_unlock(&dasd_devmap_lock);
1411 static DEVICE_ATTR(reservation_policy, 0644,
1412 dasd_reservation_policy_show, dasd_reservation_policy_store);
1414 static ssize_t dasd_reservation_state_show(struct device *dev,
1415 struct device_attribute *attr,
1418 struct dasd_device *device;
1421 device = dasd_device_from_cdev(to_ccwdev(dev));
1423 return snprintf(buf, PAGE_SIZE, "none\n");
1425 if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags))
1426 rc = snprintf(buf, PAGE_SIZE, "reserved\n");
1427 else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags))
1428 rc = snprintf(buf, PAGE_SIZE, "lost\n");
1430 rc = snprintf(buf, PAGE_SIZE, "none\n");
1431 dasd_put_device(device);
1435 static ssize_t dasd_reservation_state_store(struct device *dev,
1436 struct device_attribute *attr,
1437 const char *buf, size_t count)
1439 struct dasd_device *device;
1442 device = dasd_device_from_cdev(to_ccwdev(dev));
1445 if (sysfs_streq("reset", buf))
1446 clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
1449 dasd_put_device(device);
1457 static DEVICE_ATTR(last_known_reservation_state, 0644,
1458 dasd_reservation_state_show, dasd_reservation_state_store);
1460 static ssize_t dasd_pm_show(struct device *dev,
1461 struct device_attribute *attr, char *buf)
1463 struct dasd_device *device;
1464 u8 opm, nppm, cablepm, cuirpm, hpfpm;
1466 device = dasd_device_from_cdev(to_ccwdev(dev));
1468 return sprintf(buf, "0\n");
1470 opm = device->path_data.opm;
1471 nppm = device->path_data.npm;
1472 cablepm = device->path_data.cablepm;
1473 cuirpm = device->path_data.cuirpm;
1474 hpfpm = device->path_data.hpfpm;
1475 dasd_put_device(device);
1477 return sprintf(buf, "%02x %02x %02x %02x %02x\n", opm, nppm,
1478 cablepm, cuirpm, hpfpm);
1481 static DEVICE_ATTR(path_masks, 0444, dasd_pm_show, NULL);
1483 static struct attribute * dasd_attrs[] = {
1484 &dev_attr_readonly.attr,
1485 &dev_attr_discipline.attr,
1486 &dev_attr_status.attr,
1487 &dev_attr_alias.attr,
1488 &dev_attr_vendor.attr,
1490 &dev_attr_use_diag.attr,
1491 &dev_attr_raw_track_access.attr,
1492 &dev_attr_eer_enabled.attr,
1493 &dev_attr_erplog.attr,
1494 &dev_attr_failfast.attr,
1495 &dev_attr_expires.attr,
1496 &dev_attr_retries.attr,
1497 &dev_attr_timeout.attr,
1498 &dev_attr_reservation_policy.attr,
1499 &dev_attr_last_known_reservation_state.attr,
1500 &dev_attr_safe_offline.attr,
1501 &dev_attr_host_access_count.attr,
1502 &dev_attr_path_masks.attr,
1506 static struct attribute_group dasd_attr_group = {
1507 .attrs = dasd_attrs,
1511 * Return value of the specified feature.
1514 dasd_get_feature(struct ccw_device *cdev, int feature)
1516 struct dasd_devmap *devmap;
1518 devmap = dasd_find_busid(dev_name(&cdev->dev));
1520 return PTR_ERR(devmap);
1522 return ((devmap->features & feature) != 0);
1526 * Set / reset given feature.
1527 * Flag indicates whether to set (!=0) or the reset (=0) the feature.
1530 dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
1532 struct dasd_devmap *devmap;
1534 devmap = dasd_find_busid(dev_name(&cdev->dev));
1536 return PTR_ERR(devmap);
1538 spin_lock(&dasd_devmap_lock);
1540 devmap->features |= feature;
1542 devmap->features &= ~feature;
1544 devmap->device->features = devmap->features;
1545 spin_unlock(&dasd_devmap_lock);
1551 dasd_add_sysfs_files(struct ccw_device *cdev)
1553 return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
1557 dasd_remove_sysfs_files(struct ccw_device *cdev)
1559 sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
1564 dasd_devmap_init(void)
1568 /* Initialize devmap structures. */
1569 dasd_max_devindex = 0;
1570 for (i = 0; i < 256; i++)
1571 INIT_LIST_HEAD(&dasd_hashlists[i]);
1576 dasd_devmap_exit(void)
1578 dasd_forget_ranges();