2 * File...........: linux/drivers/s390/block/dasd_devmap.c
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 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
10 * Device mapping and dasd= parameter parsing functions. All devmap
11 * functions may not be called from interrupt context. In particular
12 * dasd_get_device is a no-no from interrupt context.
16 #define KMSG_COMPONENT "dasd"
18 #include <linux/ctype.h>
19 #include <linux/init.h>
20 #include <linux/module.h>
21 #include <linux/slab.h>
23 #include <asm/debug.h>
24 #include <asm/uaccess.h>
28 #define PRINTK_HEADER "dasd_devmap:"
29 #define DASD_BUS_ID_SIZE 20
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
;
56 * Parameter parsing functions for dasd= parameter. The syntax is:
57 * <devno> : (0x)?[0-9a-fA-F]+
58 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
60 * <feature_list> : \(<feature>(:<feature>)*\)
61 * <devno-range> : <devno>(-<devno>)?<feature_list>?
62 * <busid-range> : <busid>(-<busid>)?<feature_list>?
63 * <devices> : <devno-range>|<busid-range>
64 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
66 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
69 int dasd_probeonly
= 0; /* is true, when probeonly mode is active */
70 int dasd_autodetect
= 0; /* is true, when autodetection is active */
71 int dasd_nopav
= 0; /* is true, when PAV is disabled */
72 EXPORT_SYMBOL_GPL(dasd_nopav
);
73 int dasd_nofcx
; /* disable High Performance Ficon */
74 EXPORT_SYMBOL_GPL(dasd_nofcx
);
77 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
78 * it is named 'dasd' to directly be filled by insmod with the comma separated
79 * strings when running as a module.
81 static char *dasd
[256];
82 module_param_array(dasd
, charp
, NULL
, 0);
85 * Single spinlock to protect devmap and servermap structures and lists.
87 static DEFINE_SPINLOCK(dasd_devmap_lock
);
90 * Hash lists for devmap structures.
92 static struct list_head dasd_hashlists
[256];
93 int dasd_max_devindex
;
95 static struct dasd_devmap
*dasd_add_busid(const char *, int);
98 dasd_hash_busid(const char *bus_id
)
103 for (i
= 0; (i
< DASD_BUS_ID_SIZE
) && *bus_id
; i
++, bus_id
++)
110 * The parameter parsing functions for builtin-drivers are called
111 * before kmalloc works. Store the pointers to the parameters strings
112 * into dasd[] for later processing.
115 dasd_call_setup(char *str
)
117 static int count
= 0;
124 __setup ("dasd=", dasd_call_setup
);
125 #endif /* #ifndef MODULE */
127 #define DASD_IPLDEV "ipldev"
130 * Read a device busid/devno from a string.
134 dasd_busid(char **str
, int *id0
, int *id1
, int *devno
)
138 /* Interpret ipldev busid */
139 if (strncmp(DASD_IPLDEV
, *str
, strlen(DASD_IPLDEV
)) == 0) {
140 if (ipl_info
.type
!= IPL_TYPE_CCW
) {
141 pr_err("The IPL device is not a CCW device\n");
145 *id1
= ipl_info
.data
.ccw
.dev_id
.ssid
;
146 *devno
= ipl_info
.data
.ccw
.dev_id
.devno
;
147 *str
+= strlen(DASD_IPLDEV
);
151 /* check for leading '0x' */
153 if ((*str
)[0] == '0' && (*str
)[1] == 'x') {
157 if (!isxdigit((*str
)[0])) /* We require at least one hex digit */
159 val
= simple_strtoul(*str
, str
, 16);
160 if (old_style
|| (*str
)[0] != '.') {
162 if (val
< 0 || val
> 0xffff)
167 /* New style x.y.z busid */
168 if (val
< 0 || val
> 0xff)
172 if (!isxdigit((*str
)[0])) /* We require at least one hex digit */
174 val
= simple_strtoul(*str
, str
, 16);
175 if (val
< 0 || val
> 0xff || (*str
)++[0] != '.')
178 if (!isxdigit((*str
)[0])) /* We require at least one hex digit */
180 val
= simple_strtoul(*str
, str
, 16);
181 if (val
< 0 || val
> 0xffff)
188 * Read colon separated list of dasd features. Currently there is
189 * only one: "ro" for read-only devices. The default feature set
190 * is empty (value 0).
193 dasd_feature_list(char *str
, char **endp
)
195 int features
, len
, rc
;
200 return DASD_FEATURE_DEFAULT
;
207 str
[len
] && str
[len
] != ':' && str
[len
] != ')'; len
++);
208 if (len
== 2 && !strncmp(str
, "ro", 2))
209 features
|= DASD_FEATURE_READONLY
;
210 else if (len
== 4 && !strncmp(str
, "diag", 4))
211 features
|= DASD_FEATURE_USEDIAG
;
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_warning("%*s is not a supported device option\n",
227 pr_warning("A closing parenthesis ')' is missing in the "
228 "dasd= parameter\n");
239 * Try to match the first element on the comma separated parse string
240 * with one of the known keywords. If a keyword is found, take the approprate
241 * action and return a pointer to the residual string. If the first element
242 * could not be matched to any keyword then return an error code.
245 dasd_parse_keyword( char *parsestring
) {
247 char *nextcomma
, *residual_str
;
250 nextcomma
= strchr(parsestring
,',');
252 length
= nextcomma
- parsestring
;
253 residual_str
= nextcomma
+ 1;
255 length
= strlen(parsestring
);
256 residual_str
= parsestring
+ length
;
258 if (strncmp("autodetect", parsestring
, length
) == 0) {
260 pr_info("The autodetection mode has been activated\n");
263 if (strncmp("probeonly", parsestring
, length
) == 0) {
265 pr_info("The probeonly mode has been activated\n");
268 if (strncmp("nopav", parsestring
, length
) == 0) {
270 pr_info("'nopav' is not supported on z/VM\n");
273 pr_info("PAV support has be deactivated\n");
277 if (strncmp("nofcx", parsestring
, length
) == 0) {
279 pr_info("High Performance FICON support has been "
283 if (strncmp("fixedbuffers", parsestring
, length
) == 0) {
287 kmem_cache_create("dasd_page_cache", PAGE_SIZE
,
288 PAGE_SIZE
, SLAB_CACHE_DMA
,
290 if (!dasd_page_cache
)
291 DBF_EVENT(DBF_WARNING
, "%s", "Failed to create slab, "
292 "fixed buffer mode disabled.");
294 DBF_EVENT(DBF_INFO
, "%s",
295 "turning on fixed buffer mode");
298 return ERR_PTR(-EINVAL
);
302 * Try to interprete the first element on the comma separated parse string
303 * as a device number or a range of devices. If the interpretation is
304 * successfull, create the matching dasd_devmap entries and return a pointer
305 * to the residual string.
306 * If interpretation fails or in case of an error, return an error code.
309 dasd_parse_range( char *parsestring
) {
311 struct dasd_devmap
*devmap
;
312 int from
, from_id0
, from_id1
;
313 int to
, to_id0
, to_id1
;
315 char bus_id
[DASD_BUS_ID_SIZE
+1], *str
;
318 rc
= dasd_busid(&str
, &from_id0
, &from_id1
, &from
);
325 rc
= dasd_busid(&str
, &to_id0
, &to_id1
, &to
);
329 (from_id0
!= to_id0
|| from_id1
!= to_id1
|| from
> to
))
332 pr_err("%s is not a valid device range\n", parsestring
);
335 features
= dasd_feature_list(str
, &str
);
337 return ERR_PTR(-EINVAL
);
338 /* each device in dasd= parameter should be set initially online */
339 features
|= DASD_FEATURE_INITIAL_ONLINE
;
341 sprintf(bus_id
, "%01x.%01x.%04x",
342 from_id0
, from_id1
, from
++);
343 devmap
= dasd_add_busid(bus_id
, features
);
345 return (char *)devmap
;
351 pr_warning("The dasd= parameter value %s has an invalid ending\n",
353 return ERR_PTR(-EINVAL
);
357 dasd_parse_next_element( char *parsestring
) {
359 residual_str
= dasd_parse_keyword(parsestring
);
360 if (!IS_ERR(residual_str
))
362 residual_str
= dasd_parse_range(parsestring
);
367 * Parse parameters stored in dasd[]
368 * The 'dasd=...' parameter allows to specify a comma separated list of
369 * keywords and device ranges. When the dasd driver is build into the kernel,
370 * the complete list will be stored as one element of the dasd[] array.
371 * When the dasd driver is build as a module, then the list is broken into
372 * it's elements and each dasd[] entry contains one element.
381 for (i
= 0; i
< 256; i
++) {
384 parsestring
= dasd
[i
];
385 /* loop over the comma separated list in the parsestring */
386 while (*parsestring
) {
387 parsestring
= dasd_parse_next_element(parsestring
);
388 if(IS_ERR(parsestring
)) {
389 rc
= PTR_ERR(parsestring
);
394 DBF_EVENT(DBF_ALERT
, "%s", "invalid range found");
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 = (struct dasd_devmap
*)
414 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 /* Disconnect dasd_device structure from ccw_device structure. */
627 /* Put ccw_device structure. */
628 put_device(&cdev
->dev
);
630 /* Now the device structure can be freed. */
631 dasd_free_device(device
);
635 * Reference counter dropped to zero. Wake up waiter
636 * in dasd_delete_device.
639 dasd_put_device_wake(struct dasd_device
*device
)
641 wake_up(&dasd_delete_wq
);
645 * Return dasd_device structure associated with cdev.
646 * This function needs to be called with the ccw device
647 * lock held. It can be used from interrupt context.
650 dasd_device_from_cdev_locked(struct ccw_device
*cdev
)
652 struct dasd_device
*device
= dev_get_drvdata(&cdev
->dev
);
655 return ERR_PTR(-ENODEV
);
656 dasd_get_device(device
);
661 * Return dasd_device structure associated with cdev.
664 dasd_device_from_cdev(struct ccw_device
*cdev
)
666 struct dasd_device
*device
;
669 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
670 device
= dasd_device_from_cdev_locked(cdev
);
671 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
676 * SECTION: files in sysfs
680 * failfast controls the behaviour, if no path is available
682 static ssize_t
dasd_ff_show(struct device
*dev
, struct device_attribute
*attr
,
685 struct dasd_devmap
*devmap
;
688 devmap
= dasd_find_busid(dev_name(dev
));
690 ff_flag
= (devmap
->features
& DASD_FEATURE_FAILFAST
) != 0;
692 ff_flag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_FAILFAST
) != 0;
693 return snprintf(buf
, PAGE_SIZE
, ff_flag
? "1\n" : "0\n");
696 static ssize_t
dasd_ff_store(struct device
*dev
, struct device_attribute
*attr
,
697 const char *buf
, size_t count
)
699 struct dasd_devmap
*devmap
;
703 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
705 return PTR_ERR(devmap
);
707 val
= simple_strtoul(buf
, &endp
, 0);
708 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
711 spin_lock(&dasd_devmap_lock
);
713 devmap
->features
|= DASD_FEATURE_FAILFAST
;
715 devmap
->features
&= ~DASD_FEATURE_FAILFAST
;
717 devmap
->device
->features
= devmap
->features
;
718 spin_unlock(&dasd_devmap_lock
);
722 static DEVICE_ATTR(failfast
, 0644, dasd_ff_show
, dasd_ff_store
);
725 * readonly controls the readonly status of a dasd
728 dasd_ro_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
730 struct dasd_devmap
*devmap
;
733 devmap
= dasd_find_busid(dev_name(dev
));
735 ro_flag
= (devmap
->features
& DASD_FEATURE_READONLY
) != 0;
737 ro_flag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_READONLY
) != 0;
738 return snprintf(buf
, PAGE_SIZE
, ro_flag
? "1\n" : "0\n");
742 dasd_ro_store(struct device
*dev
, struct device_attribute
*attr
,
743 const char *buf
, size_t count
)
745 struct dasd_devmap
*devmap
;
746 struct dasd_device
*device
;
750 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
752 return PTR_ERR(devmap
);
754 val
= simple_strtoul(buf
, &endp
, 0);
755 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
758 spin_lock(&dasd_devmap_lock
);
760 devmap
->features
|= DASD_FEATURE_READONLY
;
762 devmap
->features
&= ~DASD_FEATURE_READONLY
;
763 device
= devmap
->device
;
765 device
->features
= devmap
->features
;
766 val
= val
|| test_bit(DASD_FLAG_DEVICE_RO
, &device
->flags
);
768 spin_unlock(&dasd_devmap_lock
);
769 if (device
&& device
->block
&& device
->block
->gdp
)
770 set_disk_ro(device
->block
->gdp
, val
);
774 static DEVICE_ATTR(readonly
, 0644, dasd_ro_show
, dasd_ro_store
);
776 * erplog controls the logging of ERP related data
777 * (e.g. failing channel programs).
780 dasd_erplog_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
782 struct dasd_devmap
*devmap
;
785 devmap
= dasd_find_busid(dev_name(dev
));
787 erplog
= (devmap
->features
& DASD_FEATURE_ERPLOG
) != 0;
789 erplog
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_ERPLOG
) != 0;
790 return snprintf(buf
, PAGE_SIZE
, erplog
? "1\n" : "0\n");
794 dasd_erplog_store(struct device
*dev
, struct device_attribute
*attr
,
795 const char *buf
, size_t count
)
797 struct dasd_devmap
*devmap
;
801 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
803 return PTR_ERR(devmap
);
805 val
= simple_strtoul(buf
, &endp
, 0);
806 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
809 spin_lock(&dasd_devmap_lock
);
811 devmap
->features
|= DASD_FEATURE_ERPLOG
;
813 devmap
->features
&= ~DASD_FEATURE_ERPLOG
;
815 devmap
->device
->features
= devmap
->features
;
816 spin_unlock(&dasd_devmap_lock
);
820 static DEVICE_ATTR(erplog
, 0644, dasd_erplog_show
, dasd_erplog_store
);
823 * use_diag controls whether the driver should use diag rather than ssch
824 * to talk to the device
827 dasd_use_diag_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
829 struct dasd_devmap
*devmap
;
832 devmap
= dasd_find_busid(dev_name(dev
));
834 use_diag
= (devmap
->features
& DASD_FEATURE_USEDIAG
) != 0;
836 use_diag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_USEDIAG
) != 0;
837 return sprintf(buf
, use_diag
? "1\n" : "0\n");
841 dasd_use_diag_store(struct device
*dev
, struct device_attribute
*attr
,
842 const char *buf
, size_t count
)
844 struct dasd_devmap
*devmap
;
849 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
851 return PTR_ERR(devmap
);
853 val
= simple_strtoul(buf
, &endp
, 0);
854 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
857 spin_lock(&dasd_devmap_lock
);
858 /* Changing diag discipline flag is only allowed in offline state. */
860 if (!devmap
->device
) {
862 devmap
->features
|= DASD_FEATURE_USEDIAG
;
864 devmap
->features
&= ~DASD_FEATURE_USEDIAG
;
867 spin_unlock(&dasd_devmap_lock
);
871 static DEVICE_ATTR(use_diag
, 0644, dasd_use_diag_show
, dasd_use_diag_store
);
874 dasd_discipline_show(struct device
*dev
, struct device_attribute
*attr
,
877 struct dasd_device
*device
;
880 device
= dasd_device_from_cdev(to_ccwdev(dev
));
883 else if (!device
->discipline
) {
884 dasd_put_device(device
);
887 len
= snprintf(buf
, PAGE_SIZE
, "%s\n",
888 device
->discipline
->name
);
889 dasd_put_device(device
);
893 len
= snprintf(buf
, PAGE_SIZE
, "none\n");
897 static DEVICE_ATTR(discipline
, 0444, dasd_discipline_show
, NULL
);
900 dasd_device_status_show(struct device
*dev
, struct device_attribute
*attr
,
903 struct dasd_device
*device
;
906 device
= dasd_device_from_cdev(to_ccwdev(dev
));
907 if (!IS_ERR(device
)) {
908 switch (device
->state
) {
910 len
= snprintf(buf
, PAGE_SIZE
, "new\n");
912 case DASD_STATE_KNOWN
:
913 len
= snprintf(buf
, PAGE_SIZE
, "detected\n");
915 case DASD_STATE_BASIC
:
916 len
= snprintf(buf
, PAGE_SIZE
, "basic\n");
918 case DASD_STATE_UNFMT
:
919 len
= snprintf(buf
, PAGE_SIZE
, "unformatted\n");
921 case DASD_STATE_READY
:
922 len
= snprintf(buf
, PAGE_SIZE
, "ready\n");
924 case DASD_STATE_ONLINE
:
925 len
= snprintf(buf
, PAGE_SIZE
, "online\n");
928 len
= snprintf(buf
, PAGE_SIZE
, "no stat\n");
931 dasd_put_device(device
);
933 len
= snprintf(buf
, PAGE_SIZE
, "unknown\n");
937 static DEVICE_ATTR(status
, 0444, dasd_device_status_show
, NULL
);
940 dasd_alias_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
942 struct dasd_devmap
*devmap
;
945 devmap
= dasd_find_busid(dev_name(dev
));
946 spin_lock(&dasd_devmap_lock
);
947 if (IS_ERR(devmap
) || strlen(devmap
->uid
.vendor
) == 0) {
948 spin_unlock(&dasd_devmap_lock
);
949 return sprintf(buf
, "0\n");
951 if (devmap
->uid
.type
== UA_BASE_PAV_ALIAS
||
952 devmap
->uid
.type
== UA_HYPER_PAV_ALIAS
)
956 spin_unlock(&dasd_devmap_lock
);
957 return sprintf(buf
, alias
? "1\n" : "0\n");
960 static DEVICE_ATTR(alias
, 0444, dasd_alias_show
, NULL
);
963 dasd_vendor_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
965 struct dasd_devmap
*devmap
;
968 devmap
= dasd_find_busid(dev_name(dev
));
969 spin_lock(&dasd_devmap_lock
);
970 if (!IS_ERR(devmap
) && strlen(devmap
->uid
.vendor
) > 0)
971 vendor
= devmap
->uid
.vendor
;
974 spin_unlock(&dasd_devmap_lock
);
976 return snprintf(buf
, PAGE_SIZE
, "%s\n", vendor
);
979 static DEVICE_ATTR(vendor
, 0444, dasd_vendor_show
, NULL
);
981 #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
982 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
986 dasd_uid_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
988 struct dasd_devmap
*devmap
;
989 char uid_string
[UID_STRLEN
];
991 struct dasd_uid
*uid
;
993 devmap
= dasd_find_busid(dev_name(dev
));
994 spin_lock(&dasd_devmap_lock
);
995 if (IS_ERR(devmap
) || strlen(devmap
->uid
.vendor
) == 0) {
996 spin_unlock(&dasd_devmap_lock
);
997 return sprintf(buf
, "\n");
1000 switch (uid
->type
) {
1001 case UA_BASE_DEVICE
:
1002 sprintf(ua_string
, "%02x", uid
->real_unit_addr
);
1004 case UA_BASE_PAV_ALIAS
:
1005 sprintf(ua_string
, "%02x", uid
->base_unit_addr
);
1007 case UA_HYPER_PAV_ALIAS
:
1008 sprintf(ua_string
, "xx");
1011 /* should not happen, treat like base device */
1012 sprintf(ua_string
, "%02x", uid
->real_unit_addr
);
1015 if (strlen(uid
->vduit
) > 0)
1016 snprintf(uid_string
, sizeof(uid_string
),
1018 uid
->vendor
, uid
->serial
,
1019 uid
->ssid
, ua_string
,
1022 snprintf(uid_string
, sizeof(uid_string
),
1024 uid
->vendor
, uid
->serial
,
1025 uid
->ssid
, ua_string
);
1026 spin_unlock(&dasd_devmap_lock
);
1027 return snprintf(buf
, PAGE_SIZE
, "%s\n", uid_string
);
1030 static DEVICE_ATTR(uid
, 0444, dasd_uid_show
, NULL
);
1033 * extended error-reporting
1036 dasd_eer_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1038 struct dasd_devmap
*devmap
;
1041 devmap
= dasd_find_busid(dev_name(dev
));
1042 if (!IS_ERR(devmap
) && devmap
->device
)
1043 eer_flag
= dasd_eer_enabled(devmap
->device
);
1046 return snprintf(buf
, PAGE_SIZE
, eer_flag
? "1\n" : "0\n");
1050 dasd_eer_store(struct device
*dev
, struct device_attribute
*attr
,
1051 const char *buf
, size_t count
)
1053 struct dasd_devmap
*devmap
;
1057 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
1059 return PTR_ERR(devmap
);
1060 if (!devmap
->device
)
1063 val
= simple_strtoul(buf
, &endp
, 0);
1064 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
1068 rc
= dasd_eer_enable(devmap
->device
);
1072 dasd_eer_disable(devmap
->device
);
1076 static DEVICE_ATTR(eer_enabled
, 0644, dasd_eer_show
, dasd_eer_store
);
1078 static struct attribute
* dasd_attrs
[] = {
1079 &dev_attr_readonly
.attr
,
1080 &dev_attr_discipline
.attr
,
1081 &dev_attr_status
.attr
,
1082 &dev_attr_alias
.attr
,
1083 &dev_attr_vendor
.attr
,
1085 &dev_attr_use_diag
.attr
,
1086 &dev_attr_eer_enabled
.attr
,
1087 &dev_attr_erplog
.attr
,
1088 &dev_attr_failfast
.attr
,
1092 static struct attribute_group dasd_attr_group
= {
1093 .attrs
= dasd_attrs
,
1097 * Return copy of the device unique identifier.
1100 dasd_get_uid(struct ccw_device
*cdev
, struct dasd_uid
*uid
)
1102 struct dasd_devmap
*devmap
;
1104 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1106 return PTR_ERR(devmap
);
1107 spin_lock(&dasd_devmap_lock
);
1109 spin_unlock(&dasd_devmap_lock
);
1112 EXPORT_SYMBOL_GPL(dasd_get_uid
);
1115 * Register the given device unique identifier into devmap struct.
1116 * In addition check if the related storage server subsystem ID is already
1117 * contained in the dasd_server_ssid_list. If subsystem ID is not contained,
1119 * Return 0 if server was already in serverlist,
1120 * 1 if the server was added successful
1121 * <0 in case of error.
1124 dasd_set_uid(struct ccw_device
*cdev
, struct dasd_uid
*uid
)
1126 struct dasd_devmap
*devmap
;
1128 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1130 return PTR_ERR(devmap
);
1132 spin_lock(&dasd_devmap_lock
);
1134 spin_unlock(&dasd_devmap_lock
);
1138 EXPORT_SYMBOL_GPL(dasd_set_uid
);
1141 * Return value of the specified feature.
1144 dasd_get_feature(struct ccw_device
*cdev
, int feature
)
1146 struct dasd_devmap
*devmap
;
1148 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1150 return PTR_ERR(devmap
);
1152 return ((devmap
->features
& feature
) != 0);
1156 * Set / reset given feature.
1157 * Flag indicates wether to set (!=0) or the reset (=0) the feature.
1160 dasd_set_feature(struct ccw_device
*cdev
, int feature
, int flag
)
1162 struct dasd_devmap
*devmap
;
1164 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1166 return PTR_ERR(devmap
);
1168 spin_lock(&dasd_devmap_lock
);
1170 devmap
->features
|= feature
;
1172 devmap
->features
&= ~feature
;
1174 devmap
->device
->features
= devmap
->features
;
1175 spin_unlock(&dasd_devmap_lock
);
1181 dasd_add_sysfs_files(struct ccw_device
*cdev
)
1183 return sysfs_create_group(&cdev
->dev
.kobj
, &dasd_attr_group
);
1187 dasd_remove_sysfs_files(struct ccw_device
*cdev
)
1189 sysfs_remove_group(&cdev
->dev
.kobj
, &dasd_attr_group
);
1194 dasd_devmap_init(void)
1198 /* Initialize devmap structures. */
1199 dasd_max_devindex
= 0;
1200 for (i
= 0; i
< 256; i
++)
1201 INIT_LIST_HEAD(&dasd_hashlists
[i
]);
1206 dasd_devmap_exit(void)
1208 dasd_forget_ranges();