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
;
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
== 3 && !strncmp(str
, "raw", 3))
212 features
|= DASD_FEATURE_USERAW
;
213 else if (len
== 6 && !strncmp(str
, "erplog", 6))
214 features
|= DASD_FEATURE_ERPLOG
;
215 else if (len
== 8 && !strncmp(str
, "failfast", 8))
216 features
|= DASD_FEATURE_FAILFAST
;
218 pr_warning("%*s is not a supported device option\n",
228 pr_warning("A closing parenthesis ')' is missing in the "
229 "dasd= parameter\n");
240 * Try to match the first element on the comma separated parse string
241 * with one of the known keywords. If a keyword is found, take the approprate
242 * action and return a pointer to the residual string. If the first element
243 * could not be matched to any keyword then return an error code.
246 dasd_parse_keyword( char *parsestring
) {
248 char *nextcomma
, *residual_str
;
251 nextcomma
= strchr(parsestring
,',');
253 length
= nextcomma
- parsestring
;
254 residual_str
= nextcomma
+ 1;
256 length
= strlen(parsestring
);
257 residual_str
= parsestring
+ length
;
259 if (strncmp("autodetect", parsestring
, length
) == 0) {
261 pr_info("The autodetection mode has been activated\n");
264 if (strncmp("probeonly", parsestring
, length
) == 0) {
266 pr_info("The probeonly mode has been activated\n");
269 if (strncmp("nopav", parsestring
, length
) == 0) {
271 pr_info("'nopav' is not supported on z/VM\n");
274 pr_info("PAV support has be deactivated\n");
278 if (strncmp("nofcx", parsestring
, length
) == 0) {
280 pr_info("High Performance FICON support has been "
284 if (strncmp("fixedbuffers", parsestring
, length
) == 0) {
288 kmem_cache_create("dasd_page_cache", PAGE_SIZE
,
289 PAGE_SIZE
, SLAB_CACHE_DMA
,
291 if (!dasd_page_cache
)
292 DBF_EVENT(DBF_WARNING
, "%s", "Failed to create slab, "
293 "fixed buffer mode disabled.");
295 DBF_EVENT(DBF_INFO
, "%s",
296 "turning on fixed buffer mode");
299 return ERR_PTR(-EINVAL
);
303 * Try to interprete the first element on the comma separated parse string
304 * as a device number or a range of devices. If the interpretation is
305 * successful, create the matching dasd_devmap entries and return a pointer
306 * to the residual string.
307 * If interpretation fails or in case of an error, return an error code.
310 dasd_parse_range( char *parsestring
) {
312 struct dasd_devmap
*devmap
;
313 int from
, from_id0
, from_id1
;
314 int to
, to_id0
, to_id1
;
316 char bus_id
[DASD_BUS_ID_SIZE
+1], *str
;
319 rc
= dasd_busid(&str
, &from_id0
, &from_id1
, &from
);
326 rc
= dasd_busid(&str
, &to_id0
, &to_id1
, &to
);
330 (from_id0
!= to_id0
|| from_id1
!= to_id1
|| from
> to
))
333 pr_err("%s is not a valid device range\n", parsestring
);
336 features
= dasd_feature_list(str
, &str
);
338 return ERR_PTR(-EINVAL
);
339 /* each device in dasd= parameter should be set initially online */
340 features
|= DASD_FEATURE_INITIAL_ONLINE
;
342 sprintf(bus_id
, "%01x.%01x.%04x",
343 from_id0
, from_id1
, from
++);
344 devmap
= dasd_add_busid(bus_id
, features
);
346 return (char *)devmap
;
352 pr_warning("The dasd= parameter value %s has an invalid ending\n",
354 return ERR_PTR(-EINVAL
);
358 dasd_parse_next_element( char *parsestring
) {
360 residual_str
= dasd_parse_keyword(parsestring
);
361 if (!IS_ERR(residual_str
))
363 residual_str
= dasd_parse_range(parsestring
);
368 * Parse parameters stored in dasd[]
369 * The 'dasd=...' parameter allows to specify a comma separated list of
370 * keywords and device ranges. When the dasd driver is build into the kernel,
371 * the complete list will be stored as one element of the dasd[] array.
372 * When the dasd driver is build as a module, then the list is broken into
373 * it's elements and each dasd[] entry contains one element.
382 for (i
= 0; i
< 256; i
++) {
385 parsestring
= dasd
[i
];
386 /* loop over the comma separated list in the parsestring */
387 while (*parsestring
) {
388 parsestring
= dasd_parse_next_element(parsestring
);
389 if(IS_ERR(parsestring
)) {
390 rc
= PTR_ERR(parsestring
);
395 DBF_EVENT(DBF_ALERT
, "%s", "invalid range found");
403 * Add a devmap for the device specified by busid. It is possible that
404 * the devmap already exists (dasd= parameter). The order of the devices
405 * added through this function will define the kdevs for the individual
408 static struct dasd_devmap
*
409 dasd_add_busid(const char *bus_id
, int features
)
411 struct dasd_devmap
*devmap
, *new, *tmp
;
414 new = (struct dasd_devmap
*)
415 kzalloc(sizeof(struct dasd_devmap
), GFP_KERNEL
);
417 return ERR_PTR(-ENOMEM
);
418 spin_lock(&dasd_devmap_lock
);
420 hash
= dasd_hash_busid(bus_id
);
421 list_for_each_entry(tmp
, &dasd_hashlists
[hash
], list
)
422 if (strncmp(tmp
->bus_id
, bus_id
, DASD_BUS_ID_SIZE
) == 0) {
427 /* This bus_id is new. */
428 new->devindex
= dasd_max_devindex
++;
429 strncpy(new->bus_id
, bus_id
, DASD_BUS_ID_SIZE
);
430 new->features
= features
;
432 list_add(&new->list
, &dasd_hashlists
[hash
]);
436 spin_unlock(&dasd_devmap_lock
);
442 * Find devmap for device with given bus_id.
444 static struct dasd_devmap
*
445 dasd_find_busid(const char *bus_id
)
447 struct dasd_devmap
*devmap
, *tmp
;
450 spin_lock(&dasd_devmap_lock
);
451 devmap
= ERR_PTR(-ENODEV
);
452 hash
= dasd_hash_busid(bus_id
);
453 list_for_each_entry(tmp
, &dasd_hashlists
[hash
], list
) {
454 if (strncmp(tmp
->bus_id
, bus_id
, DASD_BUS_ID_SIZE
) == 0) {
459 spin_unlock(&dasd_devmap_lock
);
464 * Check if busid has been added to the list of dasd ranges.
467 dasd_busid_known(const char *bus_id
)
469 return IS_ERR(dasd_find_busid(bus_id
)) ? -ENOENT
: 0;
473 * Forget all about the device numbers added so far.
474 * This may only be called at module unload or system shutdown.
477 dasd_forget_ranges(void)
479 struct dasd_devmap
*devmap
, *n
;
482 spin_lock(&dasd_devmap_lock
);
483 for (i
= 0; i
< 256; i
++) {
484 list_for_each_entry_safe(devmap
, n
, &dasd_hashlists
[i
], list
) {
485 BUG_ON(devmap
->device
!= NULL
);
486 list_del(&devmap
->list
);
490 spin_unlock(&dasd_devmap_lock
);
494 * Find the device struct by its device index.
497 dasd_device_from_devindex(int devindex
)
499 struct dasd_devmap
*devmap
, *tmp
;
500 struct dasd_device
*device
;
503 spin_lock(&dasd_devmap_lock
);
505 for (i
= 0; (i
< 256) && !devmap
; i
++)
506 list_for_each_entry(tmp
, &dasd_hashlists
[i
], list
)
507 if (tmp
->devindex
== devindex
) {
508 /* Found the devmap for the device. */
512 if (devmap
&& devmap
->device
) {
513 device
= devmap
->device
;
514 dasd_get_device(device
);
516 device
= ERR_PTR(-ENODEV
);
517 spin_unlock(&dasd_devmap_lock
);
522 * Return devmap for cdev. If no devmap exists yet, create one and
523 * connect it to the cdev.
525 static struct dasd_devmap
*
526 dasd_devmap_from_cdev(struct ccw_device
*cdev
)
528 struct dasd_devmap
*devmap
;
530 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
532 devmap
= dasd_add_busid(dev_name(&cdev
->dev
),
533 DASD_FEATURE_DEFAULT
);
538 * Create a dasd device structure for cdev.
541 dasd_create_device(struct ccw_device
*cdev
)
543 struct dasd_devmap
*devmap
;
544 struct dasd_device
*device
;
548 devmap
= dasd_devmap_from_cdev(cdev
);
550 return (void *) devmap
;
552 device
= dasd_alloc_device();
555 atomic_set(&device
->ref_count
, 3);
557 spin_lock(&dasd_devmap_lock
);
558 if (!devmap
->device
) {
559 devmap
->device
= device
;
560 device
->devindex
= devmap
->devindex
;
561 device
->features
= devmap
->features
;
562 get_device(&cdev
->dev
);
566 /* Someone else was faster. */
568 spin_unlock(&dasd_devmap_lock
);
571 dasd_free_device(device
);
575 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
576 dev_set_drvdata(&cdev
->dev
, device
);
577 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
583 * Wait queue for dasd_delete_device waits.
585 static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq
);
588 * Remove a dasd device structure. The passed referenced
592 dasd_delete_device(struct dasd_device
*device
)
594 struct ccw_device
*cdev
;
595 struct dasd_devmap
*devmap
;
598 /* First remove device pointer from devmap. */
599 devmap
= dasd_find_busid(dev_name(&device
->cdev
->dev
));
600 BUG_ON(IS_ERR(devmap
));
601 spin_lock(&dasd_devmap_lock
);
602 if (devmap
->device
!= device
) {
603 spin_unlock(&dasd_devmap_lock
);
604 dasd_put_device(device
);
607 devmap
->device
= NULL
;
608 spin_unlock(&dasd_devmap_lock
);
610 /* Disconnect dasd_device structure from ccw_device structure. */
611 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
612 dev_set_drvdata(&device
->cdev
->dev
, NULL
);
613 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
616 * Drop ref_count by 3, one for the devmap reference, one for
617 * the cdev reference and one for the passed reference.
619 atomic_sub(3, &device
->ref_count
);
621 /* Wait for reference counter to drop to zero. */
622 wait_event(dasd_delete_wq
, atomic_read(&device
->ref_count
) == 0);
624 /* Disconnect dasd_device structure from ccw_device structure. */
628 /* Put ccw_device structure. */
629 put_device(&cdev
->dev
);
631 /* Now the device structure can be freed. */
632 dasd_free_device(device
);
636 * Reference counter dropped to zero. Wake up waiter
637 * in dasd_delete_device.
640 dasd_put_device_wake(struct dasd_device
*device
)
642 wake_up(&dasd_delete_wq
);
644 EXPORT_SYMBOL_GPL(dasd_put_device_wake
);
647 * Return dasd_device structure associated with cdev.
648 * This function needs to be called with the ccw device
649 * lock held. It can be used from interrupt context.
652 dasd_device_from_cdev_locked(struct ccw_device
*cdev
)
654 struct dasd_device
*device
= dev_get_drvdata(&cdev
->dev
);
657 return ERR_PTR(-ENODEV
);
658 dasd_get_device(device
);
663 * Return dasd_device structure associated with cdev.
666 dasd_device_from_cdev(struct ccw_device
*cdev
)
668 struct dasd_device
*device
;
671 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
672 device
= dasd_device_from_cdev_locked(cdev
);
673 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
678 * SECTION: files in sysfs
682 * failfast controls the behaviour, if no path is available
684 static ssize_t
dasd_ff_show(struct device
*dev
, struct device_attribute
*attr
,
687 struct dasd_devmap
*devmap
;
690 devmap
= dasd_find_busid(dev_name(dev
));
692 ff_flag
= (devmap
->features
& DASD_FEATURE_FAILFAST
) != 0;
694 ff_flag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_FAILFAST
) != 0;
695 return snprintf(buf
, PAGE_SIZE
, ff_flag
? "1\n" : "0\n");
698 static ssize_t
dasd_ff_store(struct device
*dev
, struct device_attribute
*attr
,
699 const char *buf
, size_t count
)
701 struct dasd_devmap
*devmap
;
705 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
707 return PTR_ERR(devmap
);
709 val
= simple_strtoul(buf
, &endp
, 0);
710 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
713 spin_lock(&dasd_devmap_lock
);
715 devmap
->features
|= DASD_FEATURE_FAILFAST
;
717 devmap
->features
&= ~DASD_FEATURE_FAILFAST
;
719 devmap
->device
->features
= devmap
->features
;
720 spin_unlock(&dasd_devmap_lock
);
724 static DEVICE_ATTR(failfast
, 0644, dasd_ff_show
, dasd_ff_store
);
727 * readonly controls the readonly status of a dasd
730 dasd_ro_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
732 struct dasd_devmap
*devmap
;
735 devmap
= dasd_find_busid(dev_name(dev
));
737 ro_flag
= (devmap
->features
& DASD_FEATURE_READONLY
) != 0;
739 ro_flag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_READONLY
) != 0;
740 return snprintf(buf
, PAGE_SIZE
, ro_flag
? "1\n" : "0\n");
744 dasd_ro_store(struct device
*dev
, struct device_attribute
*attr
,
745 const char *buf
, size_t count
)
747 struct dasd_devmap
*devmap
;
748 struct dasd_device
*device
;
752 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
754 return PTR_ERR(devmap
);
756 val
= simple_strtoul(buf
, &endp
, 0);
757 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
760 spin_lock(&dasd_devmap_lock
);
762 devmap
->features
|= DASD_FEATURE_READONLY
;
764 devmap
->features
&= ~DASD_FEATURE_READONLY
;
765 device
= devmap
->device
;
767 device
->features
= devmap
->features
;
768 val
= val
|| test_bit(DASD_FLAG_DEVICE_RO
, &device
->flags
);
770 spin_unlock(&dasd_devmap_lock
);
771 if (device
&& device
->block
&& device
->block
->gdp
)
772 set_disk_ro(device
->block
->gdp
, val
);
776 static DEVICE_ATTR(readonly
, 0644, dasd_ro_show
, dasd_ro_store
);
778 * erplog controls the logging of ERP related data
779 * (e.g. failing channel programs).
782 dasd_erplog_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
784 struct dasd_devmap
*devmap
;
787 devmap
= dasd_find_busid(dev_name(dev
));
789 erplog
= (devmap
->features
& DASD_FEATURE_ERPLOG
) != 0;
791 erplog
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_ERPLOG
) != 0;
792 return snprintf(buf
, PAGE_SIZE
, erplog
? "1\n" : "0\n");
796 dasd_erplog_store(struct device
*dev
, struct device_attribute
*attr
,
797 const char *buf
, size_t count
)
799 struct dasd_devmap
*devmap
;
803 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
805 return PTR_ERR(devmap
);
807 val
= simple_strtoul(buf
, &endp
, 0);
808 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
811 spin_lock(&dasd_devmap_lock
);
813 devmap
->features
|= DASD_FEATURE_ERPLOG
;
815 devmap
->features
&= ~DASD_FEATURE_ERPLOG
;
817 devmap
->device
->features
= devmap
->features
;
818 spin_unlock(&dasd_devmap_lock
);
822 static DEVICE_ATTR(erplog
, 0644, dasd_erplog_show
, dasd_erplog_store
);
825 * use_diag controls whether the driver should use diag rather than ssch
826 * to talk to the device
829 dasd_use_diag_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
831 struct dasd_devmap
*devmap
;
834 devmap
= dasd_find_busid(dev_name(dev
));
836 use_diag
= (devmap
->features
& DASD_FEATURE_USEDIAG
) != 0;
838 use_diag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_USEDIAG
) != 0;
839 return sprintf(buf
, use_diag
? "1\n" : "0\n");
843 dasd_use_diag_store(struct device
*dev
, struct device_attribute
*attr
,
844 const char *buf
, size_t count
)
846 struct dasd_devmap
*devmap
;
851 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
853 return PTR_ERR(devmap
);
855 val
= simple_strtoul(buf
, &endp
, 0);
856 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
859 spin_lock(&dasd_devmap_lock
);
860 /* Changing diag discipline flag is only allowed in offline state. */
862 if (!devmap
->device
&& !(devmap
->features
& DASD_FEATURE_USERAW
)) {
864 devmap
->features
|= DASD_FEATURE_USEDIAG
;
866 devmap
->features
&= ~DASD_FEATURE_USEDIAG
;
869 spin_unlock(&dasd_devmap_lock
);
873 static DEVICE_ATTR(use_diag
, 0644, dasd_use_diag_show
, dasd_use_diag_store
);
876 * use_raw controls whether the driver should give access to raw eckd data or
877 * operate in standard mode
880 dasd_use_raw_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
882 struct dasd_devmap
*devmap
;
885 devmap
= dasd_find_busid(dev_name(dev
));
887 use_raw
= (devmap
->features
& DASD_FEATURE_USERAW
) != 0;
889 use_raw
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_USERAW
) != 0;
890 return sprintf(buf
, use_raw
? "1\n" : "0\n");
894 dasd_use_raw_store(struct device
*dev
, struct device_attribute
*attr
,
895 const char *buf
, size_t count
)
897 struct dasd_devmap
*devmap
;
901 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
903 return PTR_ERR(devmap
);
905 if ((strict_strtoul(buf
, 10, &val
) != 0) || val
> 1)
908 spin_lock(&dasd_devmap_lock
);
909 /* Changing diag discipline flag is only allowed in offline state. */
911 if (!devmap
->device
&& !(devmap
->features
& DASD_FEATURE_USEDIAG
)) {
913 devmap
->features
|= DASD_FEATURE_USERAW
;
915 devmap
->features
&= ~DASD_FEATURE_USERAW
;
918 spin_unlock(&dasd_devmap_lock
);
922 static DEVICE_ATTR(raw_track_access
, 0644, dasd_use_raw_show
,
926 dasd_discipline_show(struct device
*dev
, struct device_attribute
*attr
,
929 struct dasd_device
*device
;
932 device
= dasd_device_from_cdev(to_ccwdev(dev
));
935 else if (!device
->discipline
) {
936 dasd_put_device(device
);
939 len
= snprintf(buf
, PAGE_SIZE
, "%s\n",
940 device
->discipline
->name
);
941 dasd_put_device(device
);
945 len
= snprintf(buf
, PAGE_SIZE
, "none\n");
949 static DEVICE_ATTR(discipline
, 0444, dasd_discipline_show
, NULL
);
952 dasd_device_status_show(struct device
*dev
, struct device_attribute
*attr
,
955 struct dasd_device
*device
;
958 device
= dasd_device_from_cdev(to_ccwdev(dev
));
959 if (!IS_ERR(device
)) {
960 switch (device
->state
) {
962 len
= snprintf(buf
, PAGE_SIZE
, "new\n");
964 case DASD_STATE_KNOWN
:
965 len
= snprintf(buf
, PAGE_SIZE
, "detected\n");
967 case DASD_STATE_BASIC
:
968 len
= snprintf(buf
, PAGE_SIZE
, "basic\n");
970 case DASD_STATE_UNFMT
:
971 len
= snprintf(buf
, PAGE_SIZE
, "unformatted\n");
973 case DASD_STATE_READY
:
974 len
= snprintf(buf
, PAGE_SIZE
, "ready\n");
976 case DASD_STATE_ONLINE
:
977 len
= snprintf(buf
, PAGE_SIZE
, "online\n");
980 len
= snprintf(buf
, PAGE_SIZE
, "no stat\n");
983 dasd_put_device(device
);
985 len
= snprintf(buf
, PAGE_SIZE
, "unknown\n");
989 static DEVICE_ATTR(status
, 0444, dasd_device_status_show
, NULL
);
991 static ssize_t
dasd_alias_show(struct device
*dev
,
992 struct device_attribute
*attr
, char *buf
)
994 struct dasd_device
*device
;
997 device
= dasd_device_from_cdev(to_ccwdev(dev
));
999 return sprintf(buf
, "0\n");
1001 if (device
->discipline
&& device
->discipline
->get_uid
&&
1002 !device
->discipline
->get_uid(device
, &uid
)) {
1003 if (uid
.type
== UA_BASE_PAV_ALIAS
||
1004 uid
.type
== UA_HYPER_PAV_ALIAS
) {
1005 dasd_put_device(device
);
1006 return sprintf(buf
, "1\n");
1009 dasd_put_device(device
);
1011 return sprintf(buf
, "0\n");
1014 static DEVICE_ATTR(alias
, 0444, dasd_alias_show
, NULL
);
1016 static ssize_t
dasd_vendor_show(struct device
*dev
,
1017 struct device_attribute
*attr
, char *buf
)
1019 struct dasd_device
*device
;
1020 struct dasd_uid uid
;
1023 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1026 return snprintf(buf
, PAGE_SIZE
, "%s\n", vendor
);
1028 if (device
->discipline
&& device
->discipline
->get_uid
&&
1029 !device
->discipline
->get_uid(device
, &uid
))
1030 vendor
= uid
.vendor
;
1032 dasd_put_device(device
);
1034 return snprintf(buf
, PAGE_SIZE
, "%s\n", vendor
);
1037 static DEVICE_ATTR(vendor
, 0444, dasd_vendor_show
, NULL
);
1039 #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
1040 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
1044 dasd_uid_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1046 struct dasd_device
*device
;
1047 struct dasd_uid uid
;
1048 char uid_string
[UID_STRLEN
];
1051 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1054 return snprintf(buf
, PAGE_SIZE
, "%s\n", uid_string
);
1056 if (device
->discipline
&& device
->discipline
->get_uid
&&
1057 !device
->discipline
->get_uid(device
, &uid
)) {
1059 case UA_BASE_DEVICE
:
1060 snprintf(ua_string
, sizeof(ua_string
), "%02x",
1061 uid
.real_unit_addr
);
1063 case UA_BASE_PAV_ALIAS
:
1064 snprintf(ua_string
, sizeof(ua_string
), "%02x",
1065 uid
.base_unit_addr
);
1067 case UA_HYPER_PAV_ALIAS
:
1068 snprintf(ua_string
, sizeof(ua_string
), "xx");
1071 /* should not happen, treat like base device */
1072 snprintf(ua_string
, sizeof(ua_string
), "%02x",
1073 uid
.real_unit_addr
);
1077 if (strlen(uid
.vduit
) > 0)
1078 snprintf(uid_string
, sizeof(uid_string
),
1080 uid
.vendor
, uid
.serial
, uid
.ssid
, ua_string
,
1083 snprintf(uid_string
, sizeof(uid_string
),
1085 uid
.vendor
, uid
.serial
, uid
.ssid
, ua_string
);
1087 dasd_put_device(device
);
1089 return snprintf(buf
, PAGE_SIZE
, "%s\n", uid_string
);
1091 static DEVICE_ATTR(uid
, 0444, dasd_uid_show
, NULL
);
1094 * extended error-reporting
1097 dasd_eer_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1099 struct dasd_devmap
*devmap
;
1102 devmap
= dasd_find_busid(dev_name(dev
));
1103 if (!IS_ERR(devmap
) && devmap
->device
)
1104 eer_flag
= dasd_eer_enabled(devmap
->device
);
1107 return snprintf(buf
, PAGE_SIZE
, eer_flag
? "1\n" : "0\n");
1111 dasd_eer_store(struct device
*dev
, struct device_attribute
*attr
,
1112 const char *buf
, size_t count
)
1114 struct dasd_devmap
*devmap
;
1118 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
1120 return PTR_ERR(devmap
);
1121 if (!devmap
->device
)
1124 val
= simple_strtoul(buf
, &endp
, 0);
1125 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
1129 rc
= dasd_eer_enable(devmap
->device
);
1133 dasd_eer_disable(devmap
->device
);
1137 static DEVICE_ATTR(eer_enabled
, 0644, dasd_eer_show
, dasd_eer_store
);
1140 * expiration time for default requests
1143 dasd_expires_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1145 struct dasd_device
*device
;
1148 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1151 len
= snprintf(buf
, PAGE_SIZE
, "%lu\n", device
->default_expires
);
1152 dasd_put_device(device
);
1157 dasd_expires_store(struct device
*dev
, struct device_attribute
*attr
,
1158 const char *buf
, size_t count
)
1160 struct dasd_device
*device
;
1163 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1167 if ((strict_strtoul(buf
, 10, &val
) != 0) ||
1168 (val
> DASD_EXPIRES_MAX
) || val
== 0) {
1169 dasd_put_device(device
);
1174 device
->default_expires
= val
;
1176 dasd_put_device(device
);
1180 static DEVICE_ATTR(expires
, 0644, dasd_expires_show
, dasd_expires_store
);
1182 static ssize_t
dasd_reservation_policy_show(struct device
*dev
,
1183 struct device_attribute
*attr
,
1186 struct dasd_devmap
*devmap
;
1189 devmap
= dasd_find_busid(dev_name(dev
));
1190 if (IS_ERR(devmap
)) {
1191 rc
= snprintf(buf
, PAGE_SIZE
, "ignore\n");
1193 spin_lock(&dasd_devmap_lock
);
1194 if (devmap
->features
& DASD_FEATURE_FAILONSLCK
)
1195 rc
= snprintf(buf
, PAGE_SIZE
, "fail\n");
1197 rc
= snprintf(buf
, PAGE_SIZE
, "ignore\n");
1198 spin_unlock(&dasd_devmap_lock
);
1203 static ssize_t
dasd_reservation_policy_store(struct device
*dev
,
1204 struct device_attribute
*attr
,
1205 const char *buf
, size_t count
)
1207 struct dasd_devmap
*devmap
;
1210 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
1212 return PTR_ERR(devmap
);
1214 spin_lock(&dasd_devmap_lock
);
1215 if (sysfs_streq("ignore", buf
))
1216 devmap
->features
&= ~DASD_FEATURE_FAILONSLCK
;
1217 else if (sysfs_streq("fail", buf
))
1218 devmap
->features
|= DASD_FEATURE_FAILONSLCK
;
1222 devmap
->device
->features
= devmap
->features
;
1223 spin_unlock(&dasd_devmap_lock
);
1230 static DEVICE_ATTR(reservation_policy
, 0644,
1231 dasd_reservation_policy_show
, dasd_reservation_policy_store
);
1233 static ssize_t
dasd_reservation_state_show(struct device
*dev
,
1234 struct device_attribute
*attr
,
1237 struct dasd_device
*device
;
1240 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1242 return snprintf(buf
, PAGE_SIZE
, "none\n");
1244 if (test_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
))
1245 rc
= snprintf(buf
, PAGE_SIZE
, "reserved\n");
1246 else if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
))
1247 rc
= snprintf(buf
, PAGE_SIZE
, "lost\n");
1249 rc
= snprintf(buf
, PAGE_SIZE
, "none\n");
1250 dasd_put_device(device
);
1254 static ssize_t
dasd_reservation_state_store(struct device
*dev
,
1255 struct device_attribute
*attr
,
1256 const char *buf
, size_t count
)
1258 struct dasd_device
*device
;
1261 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1264 if (sysfs_streq("reset", buf
))
1265 clear_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
);
1268 dasd_put_device(device
);
1276 static DEVICE_ATTR(last_known_reservation_state
, 0644,
1277 dasd_reservation_state_show
, dasd_reservation_state_store
);
1279 static struct attribute
* dasd_attrs
[] = {
1280 &dev_attr_readonly
.attr
,
1281 &dev_attr_discipline
.attr
,
1282 &dev_attr_status
.attr
,
1283 &dev_attr_alias
.attr
,
1284 &dev_attr_vendor
.attr
,
1286 &dev_attr_use_diag
.attr
,
1287 &dev_attr_raw_track_access
.attr
,
1288 &dev_attr_eer_enabled
.attr
,
1289 &dev_attr_erplog
.attr
,
1290 &dev_attr_failfast
.attr
,
1291 &dev_attr_expires
.attr
,
1292 &dev_attr_reservation_policy
.attr
,
1293 &dev_attr_last_known_reservation_state
.attr
,
1297 static struct attribute_group dasd_attr_group
= {
1298 .attrs
= dasd_attrs
,
1302 * Return value of the specified feature.
1305 dasd_get_feature(struct ccw_device
*cdev
, int feature
)
1307 struct dasd_devmap
*devmap
;
1309 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1311 return PTR_ERR(devmap
);
1313 return ((devmap
->features
& feature
) != 0);
1317 * Set / reset given feature.
1318 * Flag indicates wether to set (!=0) or the reset (=0) the feature.
1321 dasd_set_feature(struct ccw_device
*cdev
, int feature
, int flag
)
1323 struct dasd_devmap
*devmap
;
1325 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1327 return PTR_ERR(devmap
);
1329 spin_lock(&dasd_devmap_lock
);
1331 devmap
->features
|= feature
;
1333 devmap
->features
&= ~feature
;
1335 devmap
->device
->features
= devmap
->features
;
1336 spin_unlock(&dasd_devmap_lock
);
1342 dasd_add_sysfs_files(struct ccw_device
*cdev
)
1344 return sysfs_create_group(&cdev
->dev
.kobj
, &dasd_attr_group
);
1348 dasd_remove_sysfs_files(struct ccw_device
*cdev
)
1350 sysfs_remove_group(&cdev
->dev
.kobj
, &dasd_attr_group
);
1355 dasd_devmap_init(void)
1359 /* Initialize devmap structures. */
1360 dasd_max_devindex
= 0;
1361 for (i
= 0; i
< 256; i
++)
1362 INIT_LIST_HEAD(&dasd_hashlists
[i
]);
1367 dasd_devmap_exit(void)
1369 dasd_forget_ranges();