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>
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
;
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
[256];
81 module_param_array(dasd
, charp
, NULL
, 0);
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
++)
109 * The parameter parsing functions for builtin-drivers are called
110 * before kmalloc works. Store the pointers to the parameters strings
111 * into dasd[] for later processing.
114 dasd_call_setup(char *str
)
116 static int count
= 0;
123 __setup ("dasd=", dasd_call_setup
);
124 #endif /* #ifndef MODULE */
126 #define DASD_IPLDEV "ipldev"
129 * Read a device busid/devno from a string.
133 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
;
146 *str
+= strlen(DASD_IPLDEV
);
150 /* check for leading '0x' */
152 if ((*str
)[0] == '0' && (*str
)[1] == 'x') {
156 if (!isxdigit((*str
)[0])) /* We require at least one hex digit */
158 val
= simple_strtoul(*str
, str
, 16);
159 if (old_style
|| (*str
)[0] != '.') {
161 if (val
< 0 || val
> 0xffff)
166 /* New style x.y.z busid */
167 if (val
< 0 || val
> 0xff)
171 if (!isxdigit((*str
)[0])) /* We require at least one hex digit */
173 val
= simple_strtoul(*str
, str
, 16);
174 if (val
< 0 || val
> 0xff || (*str
)++[0] != '.')
177 if (!isxdigit((*str
)[0])) /* We require at least one hex digit */
179 val
= simple_strtoul(*str
, str
, 16);
180 if (val
< 0 || val
> 0xffff)
187 * Read colon separated list of dasd features. Currently there is
188 * only one: "ro" for read-only devices. The default feature set
189 * is empty (value 0).
192 dasd_feature_list(char *str
, char **endp
)
194 int features
, len
, rc
;
199 return DASD_FEATURE_DEFAULT
;
206 str
[len
] && str
[len
] != ':' && str
[len
] != ')'; len
++);
207 if (len
== 2 && !strncmp(str
, "ro", 2))
208 features
|= DASD_FEATURE_READONLY
;
209 else if (len
== 4 && !strncmp(str
, "diag", 4))
210 features
|= DASD_FEATURE_USEDIAG
;
211 else if (len
== 6 && !strncmp(str
, "erplog", 6))
212 features
|= DASD_FEATURE_ERPLOG
;
213 else if (len
== 8 && !strncmp(str
, "failfast", 8))
214 features
|= DASD_FEATURE_FAILFAST
;
216 pr_warning("%*s is not a supported device option\n",
226 pr_warning("A closing parenthesis ')' is missing in the "
227 "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 * successfull, 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_warning("The dasd= parameter value %s has an invalid ending\n",
352 return ERR_PTR(-EINVAL
);
356 dasd_parse_next_element( char *parsestring
) {
358 residual_str
= dasd_parse_keyword(parsestring
);
359 if (!IS_ERR(residual_str
))
361 residual_str
= dasd_parse_range(parsestring
);
366 * Parse parameters stored in dasd[]
367 * The 'dasd=...' parameter allows to specify a comma separated list of
368 * keywords and device ranges. When the dasd driver is build into the kernel,
369 * the complete list will be stored as one element of the dasd[] array.
370 * When the dasd driver is build as a module, then the list is broken into
371 * it's elements and each dasd[] entry contains one element.
380 for (i
= 0; i
< 256; i
++) {
383 parsestring
= dasd
[i
];
384 /* loop over the comma separated list in the parsestring */
385 while (*parsestring
) {
386 parsestring
= dasd_parse_next_element(parsestring
);
387 if(IS_ERR(parsestring
)) {
388 rc
= PTR_ERR(parsestring
);
393 DBF_EVENT(DBF_ALERT
, "%s", "invalid range found");
401 * Add a devmap for the device specified by busid. It is possible that
402 * the devmap already exists (dasd= parameter). The order of the devices
403 * added through this function will define the kdevs for the individual
406 static struct dasd_devmap
*
407 dasd_add_busid(const char *bus_id
, int features
)
409 struct dasd_devmap
*devmap
, *new, *tmp
;
412 new = (struct dasd_devmap
*)
413 kzalloc(sizeof(struct dasd_devmap
), GFP_KERNEL
);
415 return ERR_PTR(-ENOMEM
);
416 spin_lock(&dasd_devmap_lock
);
418 hash
= dasd_hash_busid(bus_id
);
419 list_for_each_entry(tmp
, &dasd_hashlists
[hash
], list
)
420 if (strncmp(tmp
->bus_id
, bus_id
, DASD_BUS_ID_SIZE
) == 0) {
425 /* This bus_id is new. */
426 new->devindex
= dasd_max_devindex
++;
427 strncpy(new->bus_id
, bus_id
, DASD_BUS_ID_SIZE
);
428 new->features
= features
;
430 list_add(&new->list
, &dasd_hashlists
[hash
]);
434 spin_unlock(&dasd_devmap_lock
);
440 * Find devmap for device with given bus_id.
442 static struct dasd_devmap
*
443 dasd_find_busid(const char *bus_id
)
445 struct dasd_devmap
*devmap
, *tmp
;
448 spin_lock(&dasd_devmap_lock
);
449 devmap
= ERR_PTR(-ENODEV
);
450 hash
= dasd_hash_busid(bus_id
);
451 list_for_each_entry(tmp
, &dasd_hashlists
[hash
], list
) {
452 if (strncmp(tmp
->bus_id
, bus_id
, DASD_BUS_ID_SIZE
) == 0) {
457 spin_unlock(&dasd_devmap_lock
);
462 * Check if busid has been added to the list of dasd ranges.
465 dasd_busid_known(const char *bus_id
)
467 return IS_ERR(dasd_find_busid(bus_id
)) ? -ENOENT
: 0;
471 * Forget all about the device numbers added so far.
472 * This may only be called at module unload or system shutdown.
475 dasd_forget_ranges(void)
477 struct dasd_devmap
*devmap
, *n
;
480 spin_lock(&dasd_devmap_lock
);
481 for (i
= 0; i
< 256; i
++) {
482 list_for_each_entry_safe(devmap
, n
, &dasd_hashlists
[i
], list
) {
483 BUG_ON(devmap
->device
!= NULL
);
484 list_del(&devmap
->list
);
488 spin_unlock(&dasd_devmap_lock
);
492 * Find the device struct by its device index.
495 dasd_device_from_devindex(int devindex
)
497 struct dasd_devmap
*devmap
, *tmp
;
498 struct dasd_device
*device
;
501 spin_lock(&dasd_devmap_lock
);
503 for (i
= 0; (i
< 256) && !devmap
; i
++)
504 list_for_each_entry(tmp
, &dasd_hashlists
[i
], list
)
505 if (tmp
->devindex
== devindex
) {
506 /* Found the devmap for the device. */
510 if (devmap
&& devmap
->device
) {
511 device
= devmap
->device
;
512 dasd_get_device(device
);
514 device
= ERR_PTR(-ENODEV
);
515 spin_unlock(&dasd_devmap_lock
);
520 * Return devmap for cdev. If no devmap exists yet, create one and
521 * connect it to the cdev.
523 static struct dasd_devmap
*
524 dasd_devmap_from_cdev(struct ccw_device
*cdev
)
526 struct dasd_devmap
*devmap
;
528 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
530 devmap
= dasd_add_busid(dev_name(&cdev
->dev
),
531 DASD_FEATURE_DEFAULT
);
536 * Create a dasd device structure for cdev.
539 dasd_create_device(struct ccw_device
*cdev
)
541 struct dasd_devmap
*devmap
;
542 struct dasd_device
*device
;
546 devmap
= dasd_devmap_from_cdev(cdev
);
548 return (void *) devmap
;
550 device
= dasd_alloc_device();
553 atomic_set(&device
->ref_count
, 3);
555 spin_lock(&dasd_devmap_lock
);
556 if (!devmap
->device
) {
557 devmap
->device
= device
;
558 device
->devindex
= devmap
->devindex
;
559 device
->features
= devmap
->features
;
560 get_device(&cdev
->dev
);
564 /* Someone else was faster. */
566 spin_unlock(&dasd_devmap_lock
);
569 dasd_free_device(device
);
573 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
574 dev_set_drvdata(&cdev
->dev
, device
);
575 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
581 * Wait queue for dasd_delete_device waits.
583 static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq
);
586 * Remove a dasd device structure. The passed referenced
590 dasd_delete_device(struct dasd_device
*device
)
592 struct ccw_device
*cdev
;
593 struct dasd_devmap
*devmap
;
596 /* First remove device pointer from devmap. */
597 devmap
= dasd_find_busid(dev_name(&device
->cdev
->dev
));
598 BUG_ON(IS_ERR(devmap
));
599 spin_lock(&dasd_devmap_lock
);
600 if (devmap
->device
!= device
) {
601 spin_unlock(&dasd_devmap_lock
);
602 dasd_put_device(device
);
605 devmap
->device
= NULL
;
606 spin_unlock(&dasd_devmap_lock
);
608 /* Disconnect dasd_device structure from ccw_device structure. */
609 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
610 dev_set_drvdata(&device
->cdev
->dev
, NULL
);
611 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
614 * Drop ref_count by 3, one for the devmap reference, one for
615 * the cdev reference and one for the passed reference.
617 atomic_sub(3, &device
->ref_count
);
619 /* Wait for reference counter to drop to zero. */
620 wait_event(dasd_delete_wq
, atomic_read(&device
->ref_count
) == 0);
622 /* Disconnect dasd_device structure from ccw_device structure. */
626 /* Put ccw_device structure. */
627 put_device(&cdev
->dev
);
629 /* Now the device structure can be freed. */
630 dasd_free_device(device
);
634 * Reference counter dropped to zero. Wake up waiter
635 * in dasd_delete_device.
638 dasd_put_device_wake(struct dasd_device
*device
)
640 wake_up(&dasd_delete_wq
);
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
);
675 * SECTION: files in sysfs
679 * failfast controls the behaviour, if no path is available
681 static ssize_t
dasd_ff_show(struct device
*dev
, struct device_attribute
*attr
,
684 struct dasd_devmap
*devmap
;
687 devmap
= dasd_find_busid(dev_name(dev
));
689 ff_flag
= (devmap
->features
& DASD_FEATURE_FAILFAST
) != 0;
691 ff_flag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_FAILFAST
) != 0;
692 return snprintf(buf
, PAGE_SIZE
, ff_flag
? "1\n" : "0\n");
695 static ssize_t
dasd_ff_store(struct device
*dev
, struct device_attribute
*attr
,
696 const char *buf
, size_t count
)
698 struct dasd_devmap
*devmap
;
702 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
704 return PTR_ERR(devmap
);
706 val
= simple_strtoul(buf
, &endp
, 0);
707 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
710 spin_lock(&dasd_devmap_lock
);
712 devmap
->features
|= DASD_FEATURE_FAILFAST
;
714 devmap
->features
&= ~DASD_FEATURE_FAILFAST
;
716 devmap
->device
->features
= devmap
->features
;
717 spin_unlock(&dasd_devmap_lock
);
721 static DEVICE_ATTR(failfast
, 0644, dasd_ff_show
, dasd_ff_store
);
724 * readonly controls the readonly status of a dasd
727 dasd_ro_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
729 struct dasd_devmap
*devmap
;
732 devmap
= dasd_find_busid(dev_name(dev
));
734 ro_flag
= (devmap
->features
& DASD_FEATURE_READONLY
) != 0;
736 ro_flag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_READONLY
) != 0;
737 return snprintf(buf
, PAGE_SIZE
, ro_flag
? "1\n" : "0\n");
741 dasd_ro_store(struct device
*dev
, struct device_attribute
*attr
,
742 const char *buf
, size_t count
)
744 struct dasd_devmap
*devmap
;
745 struct dasd_device
*device
;
749 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
751 return PTR_ERR(devmap
);
753 val
= simple_strtoul(buf
, &endp
, 0);
754 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
757 spin_lock(&dasd_devmap_lock
);
759 devmap
->features
|= DASD_FEATURE_READONLY
;
761 devmap
->features
&= ~DASD_FEATURE_READONLY
;
762 device
= devmap
->device
;
764 device
->features
= devmap
->features
;
765 val
= val
|| test_bit(DASD_FLAG_DEVICE_RO
, &device
->flags
);
767 spin_unlock(&dasd_devmap_lock
);
768 if (device
&& device
->block
&& device
->block
->gdp
)
769 set_disk_ro(device
->block
->gdp
, val
);
773 static DEVICE_ATTR(readonly
, 0644, dasd_ro_show
, dasd_ro_store
);
775 * erplog controls the logging of ERP related data
776 * (e.g. failing channel programs).
779 dasd_erplog_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
781 struct dasd_devmap
*devmap
;
784 devmap
= dasd_find_busid(dev_name(dev
));
786 erplog
= (devmap
->features
& DASD_FEATURE_ERPLOG
) != 0;
788 erplog
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_ERPLOG
) != 0;
789 return snprintf(buf
, PAGE_SIZE
, erplog
? "1\n" : "0\n");
793 dasd_erplog_store(struct device
*dev
, struct device_attribute
*attr
,
794 const char *buf
, size_t count
)
796 struct dasd_devmap
*devmap
;
800 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
802 return PTR_ERR(devmap
);
804 val
= simple_strtoul(buf
, &endp
, 0);
805 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
808 spin_lock(&dasd_devmap_lock
);
810 devmap
->features
|= DASD_FEATURE_ERPLOG
;
812 devmap
->features
&= ~DASD_FEATURE_ERPLOG
;
814 devmap
->device
->features
= devmap
->features
;
815 spin_unlock(&dasd_devmap_lock
);
819 static DEVICE_ATTR(erplog
, 0644, dasd_erplog_show
, dasd_erplog_store
);
822 * use_diag controls whether the driver should use diag rather than ssch
823 * to talk to the device
826 dasd_use_diag_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
828 struct dasd_devmap
*devmap
;
831 devmap
= dasd_find_busid(dev_name(dev
));
833 use_diag
= (devmap
->features
& DASD_FEATURE_USEDIAG
) != 0;
835 use_diag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_USEDIAG
) != 0;
836 return sprintf(buf
, use_diag
? "1\n" : "0\n");
840 dasd_use_diag_store(struct device
*dev
, struct device_attribute
*attr
,
841 const char *buf
, size_t count
)
843 struct dasd_devmap
*devmap
;
848 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
850 return PTR_ERR(devmap
);
852 val
= simple_strtoul(buf
, &endp
, 0);
853 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
856 spin_lock(&dasd_devmap_lock
);
857 /* Changing diag discipline flag is only allowed in offline state. */
859 if (!devmap
->device
) {
861 devmap
->features
|= DASD_FEATURE_USEDIAG
;
863 devmap
->features
&= ~DASD_FEATURE_USEDIAG
;
866 spin_unlock(&dasd_devmap_lock
);
870 static DEVICE_ATTR(use_diag
, 0644, dasd_use_diag_show
, dasd_use_diag_store
);
873 dasd_discipline_show(struct device
*dev
, struct device_attribute
*attr
,
876 struct dasd_device
*device
;
879 device
= dasd_device_from_cdev(to_ccwdev(dev
));
882 else if (!device
->discipline
) {
883 dasd_put_device(device
);
886 len
= snprintf(buf
, PAGE_SIZE
, "%s\n",
887 device
->discipline
->name
);
888 dasd_put_device(device
);
892 len
= snprintf(buf
, PAGE_SIZE
, "none\n");
896 static DEVICE_ATTR(discipline
, 0444, dasd_discipline_show
, NULL
);
899 dasd_device_status_show(struct device
*dev
, struct device_attribute
*attr
,
902 struct dasd_device
*device
;
905 device
= dasd_device_from_cdev(to_ccwdev(dev
));
906 if (!IS_ERR(device
)) {
907 switch (device
->state
) {
909 len
= snprintf(buf
, PAGE_SIZE
, "new\n");
911 case DASD_STATE_KNOWN
:
912 len
= snprintf(buf
, PAGE_SIZE
, "detected\n");
914 case DASD_STATE_BASIC
:
915 len
= snprintf(buf
, PAGE_SIZE
, "basic\n");
917 case DASD_STATE_UNFMT
:
918 len
= snprintf(buf
, PAGE_SIZE
, "unformatted\n");
920 case DASD_STATE_READY
:
921 len
= snprintf(buf
, PAGE_SIZE
, "ready\n");
923 case DASD_STATE_ONLINE
:
924 len
= snprintf(buf
, PAGE_SIZE
, "online\n");
927 len
= snprintf(buf
, PAGE_SIZE
, "no stat\n");
930 dasd_put_device(device
);
932 len
= snprintf(buf
, PAGE_SIZE
, "unknown\n");
936 static DEVICE_ATTR(status
, 0444, dasd_device_status_show
, NULL
);
939 dasd_alias_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
941 struct dasd_devmap
*devmap
;
944 devmap
= dasd_find_busid(dev_name(dev
));
945 spin_lock(&dasd_devmap_lock
);
946 if (IS_ERR(devmap
) || strlen(devmap
->uid
.vendor
) == 0) {
947 spin_unlock(&dasd_devmap_lock
);
948 return sprintf(buf
, "0\n");
950 if (devmap
->uid
.type
== UA_BASE_PAV_ALIAS
||
951 devmap
->uid
.type
== UA_HYPER_PAV_ALIAS
)
955 spin_unlock(&dasd_devmap_lock
);
956 return sprintf(buf
, alias
? "1\n" : "0\n");
959 static DEVICE_ATTR(alias
, 0444, dasd_alias_show
, NULL
);
962 dasd_vendor_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
964 struct dasd_devmap
*devmap
;
967 devmap
= dasd_find_busid(dev_name(dev
));
968 spin_lock(&dasd_devmap_lock
);
969 if (!IS_ERR(devmap
) && strlen(devmap
->uid
.vendor
) > 0)
970 vendor
= devmap
->uid
.vendor
;
973 spin_unlock(&dasd_devmap_lock
);
975 return snprintf(buf
, PAGE_SIZE
, "%s\n", vendor
);
978 static DEVICE_ATTR(vendor
, 0444, dasd_vendor_show
, NULL
);
980 #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
981 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
985 dasd_uid_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
987 struct dasd_devmap
*devmap
;
988 char uid_string
[UID_STRLEN
];
990 struct dasd_uid
*uid
;
992 devmap
= dasd_find_busid(dev_name(dev
));
993 spin_lock(&dasd_devmap_lock
);
994 if (IS_ERR(devmap
) || strlen(devmap
->uid
.vendor
) == 0) {
995 spin_unlock(&dasd_devmap_lock
);
996 return sprintf(buf
, "\n");
1000 case UA_BASE_DEVICE
:
1001 sprintf(ua_string
, "%02x", uid
->real_unit_addr
);
1003 case UA_BASE_PAV_ALIAS
:
1004 sprintf(ua_string
, "%02x", uid
->base_unit_addr
);
1006 case UA_HYPER_PAV_ALIAS
:
1007 sprintf(ua_string
, "xx");
1010 /* should not happen, treat like base device */
1011 sprintf(ua_string
, "%02x", uid
->real_unit_addr
);
1014 if (strlen(uid
->vduit
) > 0)
1015 snprintf(uid_string
, sizeof(uid_string
),
1017 uid
->vendor
, uid
->serial
,
1018 uid
->ssid
, ua_string
,
1021 snprintf(uid_string
, sizeof(uid_string
),
1023 uid
->vendor
, uid
->serial
,
1024 uid
->ssid
, ua_string
);
1025 spin_unlock(&dasd_devmap_lock
);
1026 return snprintf(buf
, PAGE_SIZE
, "%s\n", uid_string
);
1029 static DEVICE_ATTR(uid
, 0444, dasd_uid_show
, NULL
);
1032 * extended error-reporting
1035 dasd_eer_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1037 struct dasd_devmap
*devmap
;
1040 devmap
= dasd_find_busid(dev_name(dev
));
1041 if (!IS_ERR(devmap
) && devmap
->device
)
1042 eer_flag
= dasd_eer_enabled(devmap
->device
);
1045 return snprintf(buf
, PAGE_SIZE
, eer_flag
? "1\n" : "0\n");
1049 dasd_eer_store(struct device
*dev
, struct device_attribute
*attr
,
1050 const char *buf
, size_t count
)
1052 struct dasd_devmap
*devmap
;
1056 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
1058 return PTR_ERR(devmap
);
1059 if (!devmap
->device
)
1062 val
= simple_strtoul(buf
, &endp
, 0);
1063 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
1067 rc
= dasd_eer_enable(devmap
->device
);
1071 dasd_eer_disable(devmap
->device
);
1075 static DEVICE_ATTR(eer_enabled
, 0644, dasd_eer_show
, dasd_eer_store
);
1077 static struct attribute
* dasd_attrs
[] = {
1078 &dev_attr_readonly
.attr
,
1079 &dev_attr_discipline
.attr
,
1080 &dev_attr_status
.attr
,
1081 &dev_attr_alias
.attr
,
1082 &dev_attr_vendor
.attr
,
1084 &dev_attr_use_diag
.attr
,
1085 &dev_attr_eer_enabled
.attr
,
1086 &dev_attr_erplog
.attr
,
1087 &dev_attr_failfast
.attr
,
1091 static struct attribute_group dasd_attr_group
= {
1092 .attrs
= dasd_attrs
,
1096 * Return copy of the device unique identifier.
1099 dasd_get_uid(struct ccw_device
*cdev
, struct dasd_uid
*uid
)
1101 struct dasd_devmap
*devmap
;
1103 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1105 return PTR_ERR(devmap
);
1106 spin_lock(&dasd_devmap_lock
);
1108 spin_unlock(&dasd_devmap_lock
);
1111 EXPORT_SYMBOL_GPL(dasd_get_uid
);
1114 * Register the given device unique identifier into devmap struct.
1115 * In addition check if the related storage server subsystem ID is already
1116 * contained in the dasd_server_ssid_list. If subsystem ID is not contained,
1118 * Return 0 if server was already in serverlist,
1119 * 1 if the server was added successful
1120 * <0 in case of error.
1123 dasd_set_uid(struct ccw_device
*cdev
, struct dasd_uid
*uid
)
1125 struct dasd_devmap
*devmap
;
1127 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1129 return PTR_ERR(devmap
);
1131 spin_lock(&dasd_devmap_lock
);
1133 spin_unlock(&dasd_devmap_lock
);
1137 EXPORT_SYMBOL_GPL(dasd_set_uid
);
1140 * Return value of the specified feature.
1143 dasd_get_feature(struct ccw_device
*cdev
, int feature
)
1145 struct dasd_devmap
*devmap
;
1147 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1149 return PTR_ERR(devmap
);
1151 return ((devmap
->features
& feature
) != 0);
1155 * Set / reset given feature.
1156 * Flag indicates wether to set (!=0) or the reset (=0) the feature.
1159 dasd_set_feature(struct ccw_device
*cdev
, int feature
, int flag
)
1161 struct dasd_devmap
*devmap
;
1163 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1165 return PTR_ERR(devmap
);
1167 spin_lock(&dasd_devmap_lock
);
1169 devmap
->features
|= feature
;
1171 devmap
->features
&= ~feature
;
1173 devmap
->device
->features
= devmap
->features
;
1174 spin_unlock(&dasd_devmap_lock
);
1180 dasd_add_sysfs_files(struct ccw_device
*cdev
)
1182 return sysfs_create_group(&cdev
->dev
.kobj
, &dasd_attr_group
);
1186 dasd_remove_sysfs_files(struct ccw_device
*cdev
)
1188 sysfs_remove_group(&cdev
->dev
.kobj
, &dasd_attr_group
);
1193 dasd_devmap_init(void)
1197 /* Initialize devmap structures. */
1198 dasd_max_devindex
= 0;
1199 for (i
= 0; i
< 256; i
++)
1200 INIT_LIST_HEAD(&dasd_hashlists
[i
]);
1205 dasd_devmap_exit(void)
1207 dasd_forget_ranges();