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 #include <linux/ctype.h>
17 #include <linux/init.h>
18 #include <linux/module.h>
20 #include <asm/debug.h>
21 #include <asm/uaccess.h>
25 #define PRINTK_HEADER "dasd_devmap:"
26 #define DASD_BUS_ID_SIZE 20
30 struct kmem_cache
*dasd_page_cache
;
31 EXPORT_SYMBOL_GPL(dasd_page_cache
);
34 * dasd_devmap_t is used to store the features and the relation
35 * between device number and device index. To find a dasd_devmap_t
36 * that corresponds to a device number of a device index each
37 * dasd_devmap_t is added to two linked lists, one to search by
38 * the device number and one to search by the device index. As
39 * soon as big minor numbers are available the device index list
40 * can be removed since the device number will then be identical
41 * to the device index.
44 struct list_head list
;
45 char bus_id
[DASD_BUS_ID_SIZE
];
46 unsigned int devindex
;
47 unsigned short features
;
48 struct dasd_device
*device
;
53 * Parameter parsing functions for dasd= parameter. The syntax is:
54 * <devno> : (0x)?[0-9a-fA-F]+
55 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
57 * <feature_list> : \(<feature>(:<feature>)*\)
58 * <devno-range> : <devno>(-<devno>)?<feature_list>?
59 * <busid-range> : <busid>(-<busid>)?<feature_list>?
60 * <devices> : <devno-range>|<busid-range>
61 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
63 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
66 int dasd_probeonly
= 0; /* is true, when probeonly mode is active */
67 int dasd_autodetect
= 0; /* is true, when autodetection is active */
68 int dasd_nopav
= 0; /* is true, when PAV is disabled */
69 EXPORT_SYMBOL_GPL(dasd_nopav
);
72 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
73 * it is named 'dasd' to directly be filled by insmod with the comma separated
74 * strings when running as a module.
76 static char *dasd
[256];
77 module_param_array(dasd
, charp
, NULL
, 0);
80 * Single spinlock to protect devmap and servermap structures and lists.
82 static DEFINE_SPINLOCK(dasd_devmap_lock
);
85 * Hash lists for devmap structures.
87 static struct list_head dasd_hashlists
[256];
88 int dasd_max_devindex
;
90 static struct dasd_devmap
*dasd_add_busid(const char *, int);
93 dasd_hash_busid(const char *bus_id
)
98 for (i
= 0; (i
< DASD_BUS_ID_SIZE
) && *bus_id
; i
++, bus_id
++)
105 * The parameter parsing functions for builtin-drivers are called
106 * before kmalloc works. Store the pointers to the parameters strings
107 * into dasd[] for later processing.
110 dasd_call_setup(char *str
)
112 static int count
= 0;
119 __setup ("dasd=", dasd_call_setup
);
120 #endif /* #ifndef MODULE */
122 #define DASD_IPLDEV "ipldev"
125 * Read a device busid/devno from a string.
128 dasd_busid(char **str
, int *id0
, int *id1
, int *devno
)
132 /* Interpret ipldev busid */
133 if (strncmp(DASD_IPLDEV
, *str
, strlen(DASD_IPLDEV
)) == 0) {
134 if (ipl_info
.type
!= IPL_TYPE_CCW
) {
135 MESSAGE(KERN_ERR
, "%s", "ipl device is not a ccw "
140 *id1
= ipl_info
.data
.ccw
.dev_id
.ssid
;
141 *devno
= ipl_info
.data
.ccw
.dev_id
.devno
;
142 *str
+= strlen(DASD_IPLDEV
);
146 /* check for leading '0x' */
148 if ((*str
)[0] == '0' && (*str
)[1] == 'x') {
152 if (!isxdigit((*str
)[0])) /* We require at least one hex digit */
154 val
= simple_strtoul(*str
, str
, 16);
155 if (old_style
|| (*str
)[0] != '.') {
157 if (val
< 0 || val
> 0xffff)
162 /* New style x.y.z busid */
163 if (val
< 0 || val
> 0xff)
167 if (!isxdigit((*str
)[0])) /* We require at least one hex digit */
169 val
= simple_strtoul(*str
, str
, 16);
170 if (val
< 0 || val
> 0xff || (*str
)++[0] != '.')
173 if (!isxdigit((*str
)[0])) /* We require at least one hex digit */
175 val
= simple_strtoul(*str
, str
, 16);
176 if (val
< 0 || val
> 0xffff)
183 * Read colon separated list of dasd features. Currently there is
184 * only one: "ro" for read-only devices. The default feature set
185 * is empty (value 0).
188 dasd_feature_list(char *str
, char **endp
)
190 int features
, len
, rc
;
195 return DASD_FEATURE_DEFAULT
;
202 str
[len
] && str
[len
] != ':' && str
[len
] != ')'; len
++);
203 if (len
== 2 && !strncmp(str
, "ro", 2))
204 features
|= DASD_FEATURE_READONLY
;
205 else if (len
== 4 && !strncmp(str
, "diag", 4))
206 features
|= DASD_FEATURE_USEDIAG
;
207 else if (len
== 6 && !strncmp(str
, "erplog", 6))
208 features
|= DASD_FEATURE_ERPLOG
;
209 else if (len
== 8 && !strncmp(str
, "failfast", 8))
210 features
|= DASD_FEATURE_FAILFAST
;
212 MESSAGE(KERN_WARNING
,
213 "unsupported feature: %*s, "
214 "ignoring setting", len
, str
);
223 MESSAGE(KERN_WARNING
, "%s",
224 "missing ')' in dasd parameter string\n");
235 * Try to match the first element on the comma separated parse string
236 * with one of the known keywords. If a keyword is found, take the approprate
237 * action and return a pointer to the residual string. If the first element
238 * could not be matched to any keyword then return an error code.
241 dasd_parse_keyword( char *parsestring
) {
243 char *nextcomma
, *residual_str
;
246 nextcomma
= strchr(parsestring
,',');
248 length
= nextcomma
- parsestring
;
249 residual_str
= nextcomma
+ 1;
251 length
= strlen(parsestring
);
252 residual_str
= parsestring
+ length
;
254 if (strncmp("autodetect", parsestring
, length
) == 0) {
256 MESSAGE (KERN_INFO
, "%s",
257 "turning to autodetection mode");
260 if (strncmp("probeonly", parsestring
, length
) == 0) {
262 MESSAGE(KERN_INFO
, "%s",
263 "turning to probeonly mode");
266 if (strncmp("nopav", parsestring
, length
) == 0) {
268 MESSAGE(KERN_INFO
, "%s", "'nopav' not supported on VM");
271 MESSAGE(KERN_INFO
, "%s", "disable PAV mode");
275 if (strncmp("fixedbuffers", parsestring
, length
) == 0) {
279 kmem_cache_create("dasd_page_cache", PAGE_SIZE
,
280 PAGE_SIZE
, SLAB_CACHE_DMA
,
282 if (!dasd_page_cache
)
283 MESSAGE(KERN_WARNING
, "%s", "Failed to create slab, "
284 "fixed buffer mode disabled.");
286 MESSAGE (KERN_INFO
, "%s",
287 "turning on fixed buffer mode");
290 return ERR_PTR(-EINVAL
);
294 * Try to interprete the first element on the comma separated parse string
295 * as a device number or a range of devices. If the interpretation is
296 * successfull, create the matching dasd_devmap entries and return a pointer
297 * to the residual string.
298 * If interpretation fails or in case of an error, return an error code.
301 dasd_parse_range( char *parsestring
) {
303 struct dasd_devmap
*devmap
;
304 int from
, from_id0
, from_id1
;
305 int to
, to_id0
, to_id1
;
307 char bus_id
[DASD_BUS_ID_SIZE
+1], *str
;
310 rc
= dasd_busid(&str
, &from_id0
, &from_id1
, &from
);
317 rc
= dasd_busid(&str
, &to_id0
, &to_id1
, &to
);
321 (from_id0
!= to_id0
|| from_id1
!= to_id1
|| from
> to
))
324 MESSAGE(KERN_ERR
, "Invalid device range %s", parsestring
);
327 features
= dasd_feature_list(str
, &str
);
329 return ERR_PTR(-EINVAL
);
330 /* each device in dasd= parameter should be set initially online */
331 features
|= DASD_FEATURE_INITIAL_ONLINE
;
333 sprintf(bus_id
, "%01x.%01x.%04x",
334 from_id0
, from_id1
, from
++);
335 devmap
= dasd_add_busid(bus_id
, features
);
337 return (char *)devmap
;
343 MESSAGE(KERN_WARNING
,
344 "junk at end of dasd parameter string: %s\n", str
);
345 return ERR_PTR(-EINVAL
);
349 dasd_parse_next_element( char *parsestring
) {
351 residual_str
= dasd_parse_keyword(parsestring
);
352 if (!IS_ERR(residual_str
))
354 residual_str
= dasd_parse_range(parsestring
);
359 * Parse parameters stored in dasd[]
360 * The 'dasd=...' parameter allows to specify a comma separated list of
361 * keywords and device ranges. When the dasd driver is build into the kernel,
362 * the complete list will be stored as one element of the dasd[] array.
363 * When the dasd driver is build as a module, then the list is broken into
364 * it's elements and each dasd[] entry contains one element.
373 for (i
= 0; i
< 256; i
++) {
376 parsestring
= dasd
[i
];
377 /* loop over the comma separated list in the parsestring */
378 while (*parsestring
) {
379 parsestring
= dasd_parse_next_element(parsestring
);
380 if(IS_ERR(parsestring
)) {
381 rc
= PTR_ERR(parsestring
);
386 DBF_EVENT(DBF_ALERT
, "%s", "invalid range found");
394 * Add a devmap for the device specified by busid. It is possible that
395 * the devmap already exists (dasd= parameter). The order of the devices
396 * added through this function will define the kdevs for the individual
399 static struct dasd_devmap
*
400 dasd_add_busid(const char *bus_id
, int features
)
402 struct dasd_devmap
*devmap
, *new, *tmp
;
405 new = (struct dasd_devmap
*)
406 kzalloc(sizeof(struct dasd_devmap
), GFP_KERNEL
);
408 return ERR_PTR(-ENOMEM
);
409 spin_lock(&dasd_devmap_lock
);
411 hash
= dasd_hash_busid(bus_id
);
412 list_for_each_entry(tmp
, &dasd_hashlists
[hash
], list
)
413 if (strncmp(tmp
->bus_id
, bus_id
, DASD_BUS_ID_SIZE
) == 0) {
418 /* This bus_id is new. */
419 new->devindex
= dasd_max_devindex
++;
420 strncpy(new->bus_id
, bus_id
, DASD_BUS_ID_SIZE
);
421 new->features
= features
;
423 list_add(&new->list
, &dasd_hashlists
[hash
]);
427 spin_unlock(&dasd_devmap_lock
);
433 * Find devmap for device with given bus_id.
435 static struct dasd_devmap
*
436 dasd_find_busid(const char *bus_id
)
438 struct dasd_devmap
*devmap
, *tmp
;
441 spin_lock(&dasd_devmap_lock
);
442 devmap
= ERR_PTR(-ENODEV
);
443 hash
= dasd_hash_busid(bus_id
);
444 list_for_each_entry(tmp
, &dasd_hashlists
[hash
], list
) {
445 if (strncmp(tmp
->bus_id
, bus_id
, DASD_BUS_ID_SIZE
) == 0) {
450 spin_unlock(&dasd_devmap_lock
);
455 * Check if busid has been added to the list of dasd ranges.
458 dasd_busid_known(const char *bus_id
)
460 return IS_ERR(dasd_find_busid(bus_id
)) ? -ENOENT
: 0;
464 * Forget all about the device numbers added so far.
465 * This may only be called at module unload or system shutdown.
468 dasd_forget_ranges(void)
470 struct dasd_devmap
*devmap
, *n
;
473 spin_lock(&dasd_devmap_lock
);
474 for (i
= 0; i
< 256; i
++) {
475 list_for_each_entry_safe(devmap
, n
, &dasd_hashlists
[i
], list
) {
476 BUG_ON(devmap
->device
!= NULL
);
477 list_del(&devmap
->list
);
481 spin_unlock(&dasd_devmap_lock
);
485 * Find the device struct by its device index.
488 dasd_device_from_devindex(int devindex
)
490 struct dasd_devmap
*devmap
, *tmp
;
491 struct dasd_device
*device
;
494 spin_lock(&dasd_devmap_lock
);
496 for (i
= 0; (i
< 256) && !devmap
; i
++)
497 list_for_each_entry(tmp
, &dasd_hashlists
[i
], list
)
498 if (tmp
->devindex
== devindex
) {
499 /* Found the devmap for the device. */
503 if (devmap
&& devmap
->device
) {
504 device
= devmap
->device
;
505 dasd_get_device(device
);
507 device
= ERR_PTR(-ENODEV
);
508 spin_unlock(&dasd_devmap_lock
);
513 * Return devmap for cdev. If no devmap exists yet, create one and
514 * connect it to the cdev.
516 static struct dasd_devmap
*
517 dasd_devmap_from_cdev(struct ccw_device
*cdev
)
519 struct dasd_devmap
*devmap
;
521 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
523 devmap
= dasd_add_busid(dev_name(&cdev
->dev
),
524 DASD_FEATURE_DEFAULT
);
529 * Create a dasd device structure for cdev.
532 dasd_create_device(struct ccw_device
*cdev
)
534 struct dasd_devmap
*devmap
;
535 struct dasd_device
*device
;
539 devmap
= dasd_devmap_from_cdev(cdev
);
541 return (void *) devmap
;
543 device
= dasd_alloc_device();
546 atomic_set(&device
->ref_count
, 3);
548 spin_lock(&dasd_devmap_lock
);
549 if (!devmap
->device
) {
550 devmap
->device
= device
;
551 device
->devindex
= devmap
->devindex
;
552 device
->features
= devmap
->features
;
553 get_device(&cdev
->dev
);
557 /* Someone else was faster. */
559 spin_unlock(&dasd_devmap_lock
);
562 dasd_free_device(device
);
566 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
567 dev_set_drvdata(&cdev
->dev
, device
);
568 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
574 * Wait queue for dasd_delete_device waits.
576 static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq
);
579 * Remove a dasd device structure. The passed referenced
583 dasd_delete_device(struct dasd_device
*device
)
585 struct ccw_device
*cdev
;
586 struct dasd_devmap
*devmap
;
589 /* First remove device pointer from devmap. */
590 devmap
= dasd_find_busid(dev_name(&device
->cdev
->dev
));
591 BUG_ON(IS_ERR(devmap
));
592 spin_lock(&dasd_devmap_lock
);
593 if (devmap
->device
!= device
) {
594 spin_unlock(&dasd_devmap_lock
);
595 dasd_put_device(device
);
598 devmap
->device
= NULL
;
599 spin_unlock(&dasd_devmap_lock
);
601 /* Disconnect dasd_device structure from ccw_device structure. */
602 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
603 dev_set_drvdata(&device
->cdev
->dev
, NULL
);
604 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
607 * Drop ref_count by 3, one for the devmap reference, one for
608 * the cdev reference and one for the passed reference.
610 atomic_sub(3, &device
->ref_count
);
612 /* Wait for reference counter to drop to zero. */
613 wait_event(dasd_delete_wq
, atomic_read(&device
->ref_count
) == 0);
615 /* Disconnect dasd_device structure from ccw_device structure. */
619 /* Put ccw_device structure. */
620 put_device(&cdev
->dev
);
622 /* Now the device structure can be freed. */
623 dasd_free_device(device
);
627 * Reference counter dropped to zero. Wake up waiter
628 * in dasd_delete_device.
631 dasd_put_device_wake(struct dasd_device
*device
)
633 wake_up(&dasd_delete_wq
);
637 * Return dasd_device structure associated with cdev.
638 * This function needs to be called with the ccw device
639 * lock held. It can be used from interrupt context.
642 dasd_device_from_cdev_locked(struct ccw_device
*cdev
)
644 struct dasd_device
*device
= dev_get_drvdata(&cdev
->dev
);
647 return ERR_PTR(-ENODEV
);
648 dasd_get_device(device
);
653 * Return dasd_device structure associated with cdev.
656 dasd_device_from_cdev(struct ccw_device
*cdev
)
658 struct dasd_device
*device
;
661 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
662 device
= dasd_device_from_cdev_locked(cdev
);
663 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
668 * SECTION: files in sysfs
672 * failfast controls the behaviour, if no path is available
674 static ssize_t
dasd_ff_show(struct device
*dev
, struct device_attribute
*attr
,
677 struct dasd_devmap
*devmap
;
680 devmap
= dasd_find_busid(dev
->bus_id
);
682 ff_flag
= (devmap
->features
& DASD_FEATURE_FAILFAST
) != 0;
684 ff_flag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_FAILFAST
) != 0;
685 return snprintf(buf
, PAGE_SIZE
, ff_flag
? "1\n" : "0\n");
688 static ssize_t
dasd_ff_store(struct device
*dev
, struct device_attribute
*attr
,
689 const char *buf
, size_t count
)
691 struct dasd_devmap
*devmap
;
695 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
697 return PTR_ERR(devmap
);
699 val
= simple_strtoul(buf
, &endp
, 0);
700 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
703 spin_lock(&dasd_devmap_lock
);
705 devmap
->features
|= DASD_FEATURE_FAILFAST
;
707 devmap
->features
&= ~DASD_FEATURE_FAILFAST
;
709 devmap
->device
->features
= devmap
->features
;
710 spin_unlock(&dasd_devmap_lock
);
714 static DEVICE_ATTR(failfast
, 0644, dasd_ff_show
, dasd_ff_store
);
717 * readonly controls the readonly status of a dasd
720 dasd_ro_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
722 struct dasd_devmap
*devmap
;
725 devmap
= dasd_find_busid(dev_name(dev
));
727 ro_flag
= (devmap
->features
& DASD_FEATURE_READONLY
) != 0;
729 ro_flag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_READONLY
) != 0;
730 return snprintf(buf
, PAGE_SIZE
, ro_flag
? "1\n" : "0\n");
734 dasd_ro_store(struct device
*dev
, struct device_attribute
*attr
,
735 const char *buf
, size_t count
)
737 struct dasd_devmap
*devmap
;
741 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
743 return PTR_ERR(devmap
);
745 val
= simple_strtoul(buf
, &endp
, 0);
746 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
749 spin_lock(&dasd_devmap_lock
);
751 devmap
->features
|= DASD_FEATURE_READONLY
;
753 devmap
->features
&= ~DASD_FEATURE_READONLY
;
755 devmap
->device
->features
= devmap
->features
;
756 if (devmap
->device
&& devmap
->device
->block
757 && devmap
->device
->block
->gdp
)
758 set_disk_ro(devmap
->device
->block
->gdp
, val
);
759 spin_unlock(&dasd_devmap_lock
);
763 static DEVICE_ATTR(readonly
, 0644, dasd_ro_show
, dasd_ro_store
);
765 * erplog controls the logging of ERP related data
766 * (e.g. failing channel programs).
769 dasd_erplog_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
771 struct dasd_devmap
*devmap
;
774 devmap
= dasd_find_busid(dev_name(dev
));
776 erplog
= (devmap
->features
& DASD_FEATURE_ERPLOG
) != 0;
778 erplog
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_ERPLOG
) != 0;
779 return snprintf(buf
, PAGE_SIZE
, erplog
? "1\n" : "0\n");
783 dasd_erplog_store(struct device
*dev
, struct device_attribute
*attr
,
784 const char *buf
, size_t count
)
786 struct dasd_devmap
*devmap
;
790 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
792 return PTR_ERR(devmap
);
794 val
= simple_strtoul(buf
, &endp
, 0);
795 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
798 spin_lock(&dasd_devmap_lock
);
800 devmap
->features
|= DASD_FEATURE_ERPLOG
;
802 devmap
->features
&= ~DASD_FEATURE_ERPLOG
;
804 devmap
->device
->features
= devmap
->features
;
805 spin_unlock(&dasd_devmap_lock
);
809 static DEVICE_ATTR(erplog
, 0644, dasd_erplog_show
, dasd_erplog_store
);
812 * use_diag controls whether the driver should use diag rather than ssch
813 * to talk to the device
816 dasd_use_diag_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
818 struct dasd_devmap
*devmap
;
821 devmap
= dasd_find_busid(dev_name(dev
));
823 use_diag
= (devmap
->features
& DASD_FEATURE_USEDIAG
) != 0;
825 use_diag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_USEDIAG
) != 0;
826 return sprintf(buf
, use_diag
? "1\n" : "0\n");
830 dasd_use_diag_store(struct device
*dev
, struct device_attribute
*attr
,
831 const char *buf
, size_t count
)
833 struct dasd_devmap
*devmap
;
838 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
840 return PTR_ERR(devmap
);
842 val
= simple_strtoul(buf
, &endp
, 0);
843 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
846 spin_lock(&dasd_devmap_lock
);
847 /* Changing diag discipline flag is only allowed in offline state. */
849 if (!devmap
->device
) {
851 devmap
->features
|= DASD_FEATURE_USEDIAG
;
853 devmap
->features
&= ~DASD_FEATURE_USEDIAG
;
856 spin_unlock(&dasd_devmap_lock
);
860 static DEVICE_ATTR(use_diag
, 0644, dasd_use_diag_show
, dasd_use_diag_store
);
863 dasd_discipline_show(struct device
*dev
, struct device_attribute
*attr
,
866 struct dasd_device
*device
;
869 device
= dasd_device_from_cdev(to_ccwdev(dev
));
870 if (!IS_ERR(device
) && device
->discipline
) {
871 len
= snprintf(buf
, PAGE_SIZE
, "%s\n",
872 device
->discipline
->name
);
873 dasd_put_device(device
);
875 len
= snprintf(buf
, PAGE_SIZE
, "none\n");
879 static DEVICE_ATTR(discipline
, 0444, dasd_discipline_show
, NULL
);
882 dasd_device_status_show(struct device
*dev
, struct device_attribute
*attr
,
885 struct dasd_device
*device
;
888 device
= dasd_device_from_cdev(to_ccwdev(dev
));
889 if (!IS_ERR(device
)) {
890 switch (device
->state
) {
892 len
= snprintf(buf
, PAGE_SIZE
, "new\n");
894 case DASD_STATE_KNOWN
:
895 len
= snprintf(buf
, PAGE_SIZE
, "detected\n");
897 case DASD_STATE_BASIC
:
898 len
= snprintf(buf
, PAGE_SIZE
, "basic\n");
900 case DASD_STATE_UNFMT
:
901 len
= snprintf(buf
, PAGE_SIZE
, "unformatted\n");
903 case DASD_STATE_READY
:
904 len
= snprintf(buf
, PAGE_SIZE
, "ready\n");
906 case DASD_STATE_ONLINE
:
907 len
= snprintf(buf
, PAGE_SIZE
, "online\n");
910 len
= snprintf(buf
, PAGE_SIZE
, "no stat\n");
913 dasd_put_device(device
);
915 len
= snprintf(buf
, PAGE_SIZE
, "unknown\n");
919 static DEVICE_ATTR(status
, 0444, dasd_device_status_show
, NULL
);
922 dasd_alias_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
924 struct dasd_devmap
*devmap
;
927 devmap
= dasd_find_busid(dev_name(dev
));
928 spin_lock(&dasd_devmap_lock
);
929 if (IS_ERR(devmap
) || strlen(devmap
->uid
.vendor
) == 0) {
930 spin_unlock(&dasd_devmap_lock
);
931 return sprintf(buf
, "0\n");
933 if (devmap
->uid
.type
== UA_BASE_PAV_ALIAS
||
934 devmap
->uid
.type
== UA_HYPER_PAV_ALIAS
)
938 spin_unlock(&dasd_devmap_lock
);
939 return sprintf(buf
, alias
? "1\n" : "0\n");
942 static DEVICE_ATTR(alias
, 0444, dasd_alias_show
, NULL
);
945 dasd_vendor_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
947 struct dasd_devmap
*devmap
;
950 devmap
= dasd_find_busid(dev_name(dev
));
951 spin_lock(&dasd_devmap_lock
);
952 if (!IS_ERR(devmap
) && strlen(devmap
->uid
.vendor
) > 0)
953 vendor
= devmap
->uid
.vendor
;
956 spin_unlock(&dasd_devmap_lock
);
958 return snprintf(buf
, PAGE_SIZE
, "%s\n", vendor
);
961 static DEVICE_ATTR(vendor
, 0444, dasd_vendor_show
, NULL
);
963 #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
964 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
968 dasd_uid_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
970 struct dasd_devmap
*devmap
;
971 char uid_string
[UID_STRLEN
];
973 struct dasd_uid
*uid
;
975 devmap
= dasd_find_busid(dev_name(dev
));
976 spin_lock(&dasd_devmap_lock
);
977 if (IS_ERR(devmap
) || strlen(devmap
->uid
.vendor
) == 0) {
978 spin_unlock(&dasd_devmap_lock
);
979 return sprintf(buf
, "\n");
984 sprintf(ua_string
, "%02x", uid
->real_unit_addr
);
986 case UA_BASE_PAV_ALIAS
:
987 sprintf(ua_string
, "%02x", uid
->base_unit_addr
);
989 case UA_HYPER_PAV_ALIAS
:
990 sprintf(ua_string
, "xx");
993 /* should not happen, treat like base device */
994 sprintf(ua_string
, "%02x", uid
->real_unit_addr
);
997 if (strlen(uid
->vduit
) > 0)
998 snprintf(uid_string
, sizeof(uid_string
),
1000 uid
->vendor
, uid
->serial
,
1001 uid
->ssid
, ua_string
,
1004 snprintf(uid_string
, sizeof(uid_string
),
1006 uid
->vendor
, uid
->serial
,
1007 uid
->ssid
, ua_string
);
1008 spin_unlock(&dasd_devmap_lock
);
1009 return snprintf(buf
, PAGE_SIZE
, "%s\n", uid_string
);
1012 static DEVICE_ATTR(uid
, 0444, dasd_uid_show
, NULL
);
1015 * extended error-reporting
1018 dasd_eer_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1020 struct dasd_devmap
*devmap
;
1023 devmap
= dasd_find_busid(dev_name(dev
));
1024 if (!IS_ERR(devmap
) && devmap
->device
)
1025 eer_flag
= dasd_eer_enabled(devmap
->device
);
1028 return snprintf(buf
, PAGE_SIZE
, eer_flag
? "1\n" : "0\n");
1032 dasd_eer_store(struct device
*dev
, struct device_attribute
*attr
,
1033 const char *buf
, size_t count
)
1035 struct dasd_devmap
*devmap
;
1039 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
1041 return PTR_ERR(devmap
);
1042 if (!devmap
->device
)
1045 val
= simple_strtoul(buf
, &endp
, 0);
1046 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
1050 rc
= dasd_eer_enable(devmap
->device
);
1054 dasd_eer_disable(devmap
->device
);
1058 static DEVICE_ATTR(eer_enabled
, 0644, dasd_eer_show
, dasd_eer_store
);
1060 static struct attribute
* dasd_attrs
[] = {
1061 &dev_attr_readonly
.attr
,
1062 &dev_attr_discipline
.attr
,
1063 &dev_attr_status
.attr
,
1064 &dev_attr_alias
.attr
,
1065 &dev_attr_vendor
.attr
,
1067 &dev_attr_use_diag
.attr
,
1068 &dev_attr_eer_enabled
.attr
,
1069 &dev_attr_erplog
.attr
,
1070 &dev_attr_failfast
.attr
,
1074 static struct attribute_group dasd_attr_group
= {
1075 .attrs
= dasd_attrs
,
1079 * Return copy of the device unique identifier.
1082 dasd_get_uid(struct ccw_device
*cdev
, struct dasd_uid
*uid
)
1084 struct dasd_devmap
*devmap
;
1086 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1088 return PTR_ERR(devmap
);
1089 spin_lock(&dasd_devmap_lock
);
1091 spin_unlock(&dasd_devmap_lock
);
1096 * Register the given device unique identifier into devmap struct.
1097 * In addition check if the related storage server subsystem ID is already
1098 * contained in the dasd_server_ssid_list. If subsystem ID is not contained,
1100 * Return 0 if server was already in serverlist,
1101 * 1 if the server was added successful
1102 * <0 in case of error.
1105 dasd_set_uid(struct ccw_device
*cdev
, struct dasd_uid
*uid
)
1107 struct dasd_devmap
*devmap
;
1109 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1111 return PTR_ERR(devmap
);
1113 spin_lock(&dasd_devmap_lock
);
1115 spin_unlock(&dasd_devmap_lock
);
1119 EXPORT_SYMBOL_GPL(dasd_set_uid
);
1122 * Return value of the specified feature.
1125 dasd_get_feature(struct ccw_device
*cdev
, int feature
)
1127 struct dasd_devmap
*devmap
;
1129 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1131 return PTR_ERR(devmap
);
1133 return ((devmap
->features
& feature
) != 0);
1137 * Set / reset given feature.
1138 * Flag indicates wether to set (!=0) or the reset (=0) the feature.
1141 dasd_set_feature(struct ccw_device
*cdev
, int feature
, int flag
)
1143 struct dasd_devmap
*devmap
;
1145 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1147 return PTR_ERR(devmap
);
1149 spin_lock(&dasd_devmap_lock
);
1151 devmap
->features
|= feature
;
1153 devmap
->features
&= ~feature
;
1155 devmap
->device
->features
= devmap
->features
;
1156 spin_unlock(&dasd_devmap_lock
);
1162 dasd_add_sysfs_files(struct ccw_device
*cdev
)
1164 return sysfs_create_group(&cdev
->dev
.kobj
, &dasd_attr_group
);
1168 dasd_remove_sysfs_files(struct ccw_device
*cdev
)
1170 sysfs_remove_group(&cdev
->dev
.kobj
, &dasd_attr_group
);
1175 dasd_devmap_init(void)
1179 /* Initialize devmap structures. */
1180 dasd_max_devindex
= 0;
1181 for (i
= 0; i
< 256; i
++)
1182 INIT_LIST_HEAD(&dasd_hashlists
[i
]);
1187 dasd_devmap_exit(void)
1189 dasd_forget_ranges();