2 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
3 * Horst Hummel <Horst.Hummel@de.ibm.com>
4 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * Copyright IBM Corp. 1999,2001
9 * Device mapping and dasd= parameter parsing functions. All devmap
10 * functions may not be called from interrupt context. In particular
11 * dasd_get_device is a no-no from interrupt context.
15 #define KMSG_COMPONENT "dasd"
17 #include <linux/ctype.h>
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/slab.h>
22 #include <asm/debug.h>
23 #include <asm/uaccess.h>
27 #define PRINTK_HEADER "dasd_devmap:"
28 #define DASD_BUS_ID_SIZE 20
32 struct kmem_cache
*dasd_page_cache
;
33 EXPORT_SYMBOL_GPL(dasd_page_cache
);
36 * dasd_devmap_t is used to store the features and the relation
37 * between device number and device index. To find a dasd_devmap_t
38 * that corresponds to a device number of a device index each
39 * dasd_devmap_t is added to two linked lists, one to search by
40 * the device number and one to search by the device index. As
41 * soon as big minor numbers are available the device index list
42 * can be removed since the device number will then be identical
43 * to the device index.
46 struct list_head list
;
47 char bus_id
[DASD_BUS_ID_SIZE
];
48 unsigned int devindex
;
49 unsigned short features
;
50 struct dasd_device
*device
;
54 * Parameter parsing functions for dasd= parameter. The syntax is:
55 * <devno> : (0x)?[0-9a-fA-F]+
56 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
58 * <feature_list> : \(<feature>(:<feature>)*\)
59 * <devno-range> : <devno>(-<devno>)?<feature_list>?
60 * <busid-range> : <busid>(-<busid>)?<feature_list>?
61 * <devices> : <devno-range>|<busid-range>
62 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
64 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
67 int dasd_probeonly
= 0; /* is true, when probeonly mode is active */
68 int dasd_autodetect
= 0; /* is true, when autodetection is active */
69 int dasd_nopav
= 0; /* is true, when PAV is disabled */
70 EXPORT_SYMBOL_GPL(dasd_nopav
);
71 int dasd_nofcx
; /* disable High Performance Ficon */
72 EXPORT_SYMBOL_GPL(dasd_nofcx
);
75 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
76 * it is named 'dasd' to directly be filled by insmod with the comma separated
77 * strings when running as a module.
79 static char *dasd
[256];
80 module_param_array(dasd
, charp
, NULL
, S_IRUGO
);
83 * Single spinlock to protect devmap and servermap structures and lists.
85 static DEFINE_SPINLOCK(dasd_devmap_lock
);
88 * Hash lists for devmap structures.
90 static struct list_head dasd_hashlists
[256];
91 int dasd_max_devindex
;
93 static struct dasd_devmap
*dasd_add_busid(const char *, int);
96 dasd_hash_busid(const char *bus_id
)
101 for (i
= 0; (i
< DASD_BUS_ID_SIZE
) && *bus_id
; i
++, bus_id
++)
108 * The parameter parsing functions for builtin-drivers are called
109 * before kmalloc works. Store the pointers to the parameters strings
110 * into dasd[] for later processing.
113 dasd_call_setup(char *str
)
115 static int count
= 0;
122 __setup ("dasd=", dasd_call_setup
);
123 #endif /* #ifndef MODULE */
125 #define DASD_IPLDEV "ipldev"
128 * Read a device busid/devno from a string.
132 dasd_busid(char **str
, int *id0
, int *id1
, int *devno
)
136 /* Interpret ipldev busid */
137 if (strncmp(DASD_IPLDEV
, *str
, strlen(DASD_IPLDEV
)) == 0) {
138 if (ipl_info
.type
!= IPL_TYPE_CCW
) {
139 pr_err("The IPL device is not a CCW device\n");
143 *id1
= ipl_info
.data
.ccw
.dev_id
.ssid
;
144 *devno
= ipl_info
.data
.ccw
.dev_id
.devno
;
145 *str
+= strlen(DASD_IPLDEV
);
149 /* check for leading '0x' */
151 if ((*str
)[0] == '0' && (*str
)[1] == 'x') {
155 if (!isxdigit((*str
)[0])) /* We require at least one hex digit */
157 val
= simple_strtoul(*str
, str
, 16);
158 if (old_style
|| (*str
)[0] != '.') {
160 if (val
< 0 || val
> 0xffff)
165 /* New style x.y.z busid */
166 if (val
< 0 || val
> 0xff)
170 if (!isxdigit((*str
)[0])) /* We require at least one hex digit */
172 val
= simple_strtoul(*str
, str
, 16);
173 if (val
< 0 || val
> 0xff || (*str
)++[0] != '.')
176 if (!isxdigit((*str
)[0])) /* We require at least one hex digit */
178 val
= simple_strtoul(*str
, str
, 16);
179 if (val
< 0 || val
> 0xffff)
186 * Read colon separated list of dasd features. Currently there is
187 * only one: "ro" for read-only devices. The default feature set
188 * is empty (value 0).
191 dasd_feature_list(char *str
, char **endp
)
193 int features
, len
, rc
;
198 return DASD_FEATURE_DEFAULT
;
205 str
[len
] && str
[len
] != ':' && str
[len
] != ')'; len
++);
206 if (len
== 2 && !strncmp(str
, "ro", 2))
207 features
|= DASD_FEATURE_READONLY
;
208 else if (len
== 4 && !strncmp(str
, "diag", 4))
209 features
|= DASD_FEATURE_USEDIAG
;
210 else if (len
== 3 && !strncmp(str
, "raw", 3))
211 features
|= DASD_FEATURE_USERAW
;
212 else if (len
== 6 && !strncmp(str
, "erplog", 6))
213 features
|= DASD_FEATURE_ERPLOG
;
214 else if (len
== 8 && !strncmp(str
, "failfast", 8))
215 features
|= DASD_FEATURE_FAILFAST
;
217 pr_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 * successful, 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 = 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
);
642 EXPORT_SYMBOL_GPL(dasd_put_device_wake
);
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
);
675 void dasd_add_link_to_gendisk(struct gendisk
*gdp
, struct dasd_device
*device
)
677 struct dasd_devmap
*devmap
;
679 devmap
= dasd_find_busid(dev_name(&device
->cdev
->dev
));
682 spin_lock(&dasd_devmap_lock
);
683 gdp
->private_data
= devmap
;
684 spin_unlock(&dasd_devmap_lock
);
687 struct dasd_device
*dasd_device_from_gendisk(struct gendisk
*gdp
)
689 struct dasd_device
*device
;
690 struct dasd_devmap
*devmap
;
692 if (!gdp
->private_data
)
695 spin_lock(&dasd_devmap_lock
);
696 devmap
= gdp
->private_data
;
697 if (devmap
&& devmap
->device
) {
698 device
= devmap
->device
;
699 dasd_get_device(device
);
701 spin_unlock(&dasd_devmap_lock
);
706 * SECTION: files in sysfs
710 * failfast controls the behaviour, if no path is available
712 static ssize_t
dasd_ff_show(struct device
*dev
, struct device_attribute
*attr
,
715 struct dasd_devmap
*devmap
;
718 devmap
= dasd_find_busid(dev_name(dev
));
720 ff_flag
= (devmap
->features
& DASD_FEATURE_FAILFAST
) != 0;
722 ff_flag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_FAILFAST
) != 0;
723 return snprintf(buf
, PAGE_SIZE
, ff_flag
? "1\n" : "0\n");
726 static ssize_t
dasd_ff_store(struct device
*dev
, struct device_attribute
*attr
,
727 const char *buf
, size_t count
)
729 struct dasd_devmap
*devmap
;
733 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
735 return PTR_ERR(devmap
);
737 val
= simple_strtoul(buf
, &endp
, 0);
738 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
741 spin_lock(&dasd_devmap_lock
);
743 devmap
->features
|= DASD_FEATURE_FAILFAST
;
745 devmap
->features
&= ~DASD_FEATURE_FAILFAST
;
747 devmap
->device
->features
= devmap
->features
;
748 spin_unlock(&dasd_devmap_lock
);
752 static DEVICE_ATTR(failfast
, 0644, dasd_ff_show
, dasd_ff_store
);
755 * readonly controls the readonly status of a dasd
758 dasd_ro_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
760 struct dasd_devmap
*devmap
;
763 devmap
= dasd_find_busid(dev_name(dev
));
765 ro_flag
= (devmap
->features
& DASD_FEATURE_READONLY
) != 0;
767 ro_flag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_READONLY
) != 0;
768 return snprintf(buf
, PAGE_SIZE
, ro_flag
? "1\n" : "0\n");
772 dasd_ro_store(struct device
*dev
, struct device_attribute
*attr
,
773 const char *buf
, size_t count
)
775 struct dasd_devmap
*devmap
;
776 struct dasd_device
*device
;
780 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
782 return PTR_ERR(devmap
);
784 val
= simple_strtoul(buf
, &endp
, 0);
785 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
788 spin_lock(&dasd_devmap_lock
);
790 devmap
->features
|= DASD_FEATURE_READONLY
;
792 devmap
->features
&= ~DASD_FEATURE_READONLY
;
793 device
= devmap
->device
;
795 device
->features
= devmap
->features
;
796 val
= val
|| test_bit(DASD_FLAG_DEVICE_RO
, &device
->flags
);
798 spin_unlock(&dasd_devmap_lock
);
799 if (device
&& device
->block
&& device
->block
->gdp
)
800 set_disk_ro(device
->block
->gdp
, val
);
804 static DEVICE_ATTR(readonly
, 0644, dasd_ro_show
, dasd_ro_store
);
806 * erplog controls the logging of ERP related data
807 * (e.g. failing channel programs).
810 dasd_erplog_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
812 struct dasd_devmap
*devmap
;
815 devmap
= dasd_find_busid(dev_name(dev
));
817 erplog
= (devmap
->features
& DASD_FEATURE_ERPLOG
) != 0;
819 erplog
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_ERPLOG
) != 0;
820 return snprintf(buf
, PAGE_SIZE
, erplog
? "1\n" : "0\n");
824 dasd_erplog_store(struct device
*dev
, struct device_attribute
*attr
,
825 const char *buf
, size_t count
)
827 struct dasd_devmap
*devmap
;
831 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
833 return PTR_ERR(devmap
);
835 val
= simple_strtoul(buf
, &endp
, 0);
836 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
839 spin_lock(&dasd_devmap_lock
);
841 devmap
->features
|= DASD_FEATURE_ERPLOG
;
843 devmap
->features
&= ~DASD_FEATURE_ERPLOG
;
845 devmap
->device
->features
= devmap
->features
;
846 spin_unlock(&dasd_devmap_lock
);
850 static DEVICE_ATTR(erplog
, 0644, dasd_erplog_show
, dasd_erplog_store
);
853 * use_diag controls whether the driver should use diag rather than ssch
854 * to talk to the device
857 dasd_use_diag_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
859 struct dasd_devmap
*devmap
;
862 devmap
= dasd_find_busid(dev_name(dev
));
864 use_diag
= (devmap
->features
& DASD_FEATURE_USEDIAG
) != 0;
866 use_diag
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_USEDIAG
) != 0;
867 return sprintf(buf
, use_diag
? "1\n" : "0\n");
871 dasd_use_diag_store(struct device
*dev
, struct device_attribute
*attr
,
872 const char *buf
, size_t count
)
874 struct dasd_devmap
*devmap
;
879 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
881 return PTR_ERR(devmap
);
883 val
= simple_strtoul(buf
, &endp
, 0);
884 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
887 spin_lock(&dasd_devmap_lock
);
888 /* Changing diag discipline flag is only allowed in offline state. */
890 if (!devmap
->device
&& !(devmap
->features
& DASD_FEATURE_USERAW
)) {
892 devmap
->features
|= DASD_FEATURE_USEDIAG
;
894 devmap
->features
&= ~DASD_FEATURE_USEDIAG
;
897 spin_unlock(&dasd_devmap_lock
);
901 static DEVICE_ATTR(use_diag
, 0644, dasd_use_diag_show
, dasd_use_diag_store
);
904 * use_raw controls whether the driver should give access to raw eckd data or
905 * operate in standard mode
908 dasd_use_raw_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
910 struct dasd_devmap
*devmap
;
913 devmap
= dasd_find_busid(dev_name(dev
));
915 use_raw
= (devmap
->features
& DASD_FEATURE_USERAW
) != 0;
917 use_raw
= (DASD_FEATURE_DEFAULT
& DASD_FEATURE_USERAW
) != 0;
918 return sprintf(buf
, use_raw
? "1\n" : "0\n");
922 dasd_use_raw_store(struct device
*dev
, struct device_attribute
*attr
,
923 const char *buf
, size_t count
)
925 struct dasd_devmap
*devmap
;
929 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
931 return PTR_ERR(devmap
);
933 if ((kstrtoul(buf
, 10, &val
) != 0) || val
> 1)
936 spin_lock(&dasd_devmap_lock
);
937 /* Changing diag discipline flag is only allowed in offline state. */
939 if (!devmap
->device
&& !(devmap
->features
& DASD_FEATURE_USEDIAG
)) {
941 devmap
->features
|= DASD_FEATURE_USERAW
;
943 devmap
->features
&= ~DASD_FEATURE_USERAW
;
946 spin_unlock(&dasd_devmap_lock
);
950 static DEVICE_ATTR(raw_track_access
, 0644, dasd_use_raw_show
,
954 dasd_safe_offline_store(struct device
*dev
, struct device_attribute
*attr
,
955 const char *buf
, size_t count
)
957 struct ccw_device
*cdev
= to_ccwdev(dev
);
958 struct dasd_device
*device
;
961 device
= dasd_device_from_cdev(cdev
);
962 if (IS_ERR(device
)) {
963 rc
= PTR_ERR(device
);
967 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) ||
968 test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
969 /* Already doing offline processing */
970 dasd_put_device(device
);
975 set_bit(DASD_FLAG_SAFE_OFFLINE
, &device
->flags
);
976 dasd_put_device(device
);
978 rc
= ccw_device_set_offline(cdev
);
981 return rc
? rc
: count
;
984 static DEVICE_ATTR(safe_offline
, 0200, NULL
, dasd_safe_offline_store
);
987 dasd_discipline_show(struct device
*dev
, struct device_attribute
*attr
,
990 struct dasd_device
*device
;
993 device
= dasd_device_from_cdev(to_ccwdev(dev
));
996 else if (!device
->discipline
) {
997 dasd_put_device(device
);
1000 len
= snprintf(buf
, PAGE_SIZE
, "%s\n",
1001 device
->discipline
->name
);
1002 dasd_put_device(device
);
1006 len
= snprintf(buf
, PAGE_SIZE
, "none\n");
1010 static DEVICE_ATTR(discipline
, 0444, dasd_discipline_show
, NULL
);
1013 dasd_device_status_show(struct device
*dev
, struct device_attribute
*attr
,
1016 struct dasd_device
*device
;
1019 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1020 if (!IS_ERR(device
)) {
1021 switch (device
->state
) {
1022 case DASD_STATE_NEW
:
1023 len
= snprintf(buf
, PAGE_SIZE
, "new\n");
1025 case DASD_STATE_KNOWN
:
1026 len
= snprintf(buf
, PAGE_SIZE
, "detected\n");
1028 case DASD_STATE_BASIC
:
1029 len
= snprintf(buf
, PAGE_SIZE
, "basic\n");
1031 case DASD_STATE_UNFMT
:
1032 len
= snprintf(buf
, PAGE_SIZE
, "unformatted\n");
1034 case DASD_STATE_READY
:
1035 len
= snprintf(buf
, PAGE_SIZE
, "ready\n");
1037 case DASD_STATE_ONLINE
:
1038 len
= snprintf(buf
, PAGE_SIZE
, "online\n");
1041 len
= snprintf(buf
, PAGE_SIZE
, "no stat\n");
1044 dasd_put_device(device
);
1046 len
= snprintf(buf
, PAGE_SIZE
, "unknown\n");
1050 static DEVICE_ATTR(status
, 0444, dasd_device_status_show
, NULL
);
1052 static ssize_t
dasd_alias_show(struct device
*dev
,
1053 struct device_attribute
*attr
, char *buf
)
1055 struct dasd_device
*device
;
1056 struct dasd_uid uid
;
1058 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1060 return sprintf(buf
, "0\n");
1062 if (device
->discipline
&& device
->discipline
->get_uid
&&
1063 !device
->discipline
->get_uid(device
, &uid
)) {
1064 if (uid
.type
== UA_BASE_PAV_ALIAS
||
1065 uid
.type
== UA_HYPER_PAV_ALIAS
) {
1066 dasd_put_device(device
);
1067 return sprintf(buf
, "1\n");
1070 dasd_put_device(device
);
1072 return sprintf(buf
, "0\n");
1075 static DEVICE_ATTR(alias
, 0444, dasd_alias_show
, NULL
);
1077 static ssize_t
dasd_vendor_show(struct device
*dev
,
1078 struct device_attribute
*attr
, char *buf
)
1080 struct dasd_device
*device
;
1081 struct dasd_uid uid
;
1084 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1087 return snprintf(buf
, PAGE_SIZE
, "%s\n", vendor
);
1089 if (device
->discipline
&& device
->discipline
->get_uid
&&
1090 !device
->discipline
->get_uid(device
, &uid
))
1091 vendor
= uid
.vendor
;
1093 dasd_put_device(device
);
1095 return snprintf(buf
, PAGE_SIZE
, "%s\n", vendor
);
1098 static DEVICE_ATTR(vendor
, 0444, dasd_vendor_show
, NULL
);
1100 #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
1101 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
1105 dasd_uid_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1107 struct dasd_device
*device
;
1108 struct dasd_uid uid
;
1109 char uid_string
[UID_STRLEN
];
1112 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1115 return snprintf(buf
, PAGE_SIZE
, "%s\n", uid_string
);
1117 if (device
->discipline
&& device
->discipline
->get_uid
&&
1118 !device
->discipline
->get_uid(device
, &uid
)) {
1120 case UA_BASE_DEVICE
:
1121 snprintf(ua_string
, sizeof(ua_string
), "%02x",
1122 uid
.real_unit_addr
);
1124 case UA_BASE_PAV_ALIAS
:
1125 snprintf(ua_string
, sizeof(ua_string
), "%02x",
1126 uid
.base_unit_addr
);
1128 case UA_HYPER_PAV_ALIAS
:
1129 snprintf(ua_string
, sizeof(ua_string
), "xx");
1132 /* should not happen, treat like base device */
1133 snprintf(ua_string
, sizeof(ua_string
), "%02x",
1134 uid
.real_unit_addr
);
1138 if (strlen(uid
.vduit
) > 0)
1139 snprintf(uid_string
, sizeof(uid_string
),
1141 uid
.vendor
, uid
.serial
, uid
.ssid
, ua_string
,
1144 snprintf(uid_string
, sizeof(uid_string
),
1146 uid
.vendor
, uid
.serial
, uid
.ssid
, ua_string
);
1148 dasd_put_device(device
);
1150 return snprintf(buf
, PAGE_SIZE
, "%s\n", uid_string
);
1152 static DEVICE_ATTR(uid
, 0444, dasd_uid_show
, NULL
);
1155 * extended error-reporting
1158 dasd_eer_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1160 struct dasd_devmap
*devmap
;
1163 devmap
= dasd_find_busid(dev_name(dev
));
1164 if (!IS_ERR(devmap
) && devmap
->device
)
1165 eer_flag
= dasd_eer_enabled(devmap
->device
);
1168 return snprintf(buf
, PAGE_SIZE
, eer_flag
? "1\n" : "0\n");
1172 dasd_eer_store(struct device
*dev
, struct device_attribute
*attr
,
1173 const char *buf
, size_t count
)
1175 struct dasd_devmap
*devmap
;
1179 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
1181 return PTR_ERR(devmap
);
1182 if (!devmap
->device
)
1185 val
= simple_strtoul(buf
, &endp
, 0);
1186 if (((endp
+ 1) < (buf
+ count
)) || (val
> 1))
1190 rc
= dasd_eer_enable(devmap
->device
);
1194 dasd_eer_disable(devmap
->device
);
1198 static DEVICE_ATTR(eer_enabled
, 0644, dasd_eer_show
, dasd_eer_store
);
1201 * expiration time for default requests
1204 dasd_expires_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1206 struct dasd_device
*device
;
1209 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1212 len
= snprintf(buf
, PAGE_SIZE
, "%lu\n", device
->default_expires
);
1213 dasd_put_device(device
);
1218 dasd_expires_store(struct device
*dev
, struct device_attribute
*attr
,
1219 const char *buf
, size_t count
)
1221 struct dasd_device
*device
;
1224 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1228 if ((kstrtoul(buf
, 10, &val
) != 0) ||
1229 (val
> DASD_EXPIRES_MAX
) || val
== 0) {
1230 dasd_put_device(device
);
1235 device
->default_expires
= val
;
1237 dasd_put_device(device
);
1241 static DEVICE_ATTR(expires
, 0644, dasd_expires_show
, dasd_expires_store
);
1244 dasd_retries_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1246 struct dasd_device
*device
;
1249 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1252 len
= snprintf(buf
, PAGE_SIZE
, "%lu\n", device
->default_retries
);
1253 dasd_put_device(device
);
1258 dasd_retries_store(struct device
*dev
, struct device_attribute
*attr
,
1259 const char *buf
, size_t count
)
1261 struct dasd_device
*device
;
1264 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1268 if ((kstrtoul(buf
, 10, &val
) != 0) ||
1269 (val
> DASD_RETRIES_MAX
)) {
1270 dasd_put_device(device
);
1275 device
->default_retries
= val
;
1277 dasd_put_device(device
);
1281 static DEVICE_ATTR(retries
, 0644, dasd_retries_show
, dasd_retries_store
);
1284 dasd_timeout_show(struct device
*dev
, struct device_attribute
*attr
,
1287 struct dasd_device
*device
;
1290 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1293 len
= snprintf(buf
, PAGE_SIZE
, "%lu\n", device
->blk_timeout
);
1294 dasd_put_device(device
);
1299 dasd_timeout_store(struct device
*dev
, struct device_attribute
*attr
,
1300 const char *buf
, size_t count
)
1302 struct dasd_device
*device
;
1303 struct request_queue
*q
;
1304 unsigned long val
, flags
;
1306 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1307 if (IS_ERR(device
) || !device
->block
)
1310 if ((kstrtoul(buf
, 10, &val
) != 0) ||
1311 val
> UINT_MAX
/ HZ
) {
1312 dasd_put_device(device
);
1315 q
= device
->block
->request_queue
;
1317 dasd_put_device(device
);
1320 spin_lock_irqsave(&device
->block
->request_queue_lock
, flags
);
1322 blk_queue_rq_timed_out(q
, NULL
);
1324 blk_queue_rq_timed_out(q
, dasd_times_out
);
1326 device
->blk_timeout
= val
;
1328 blk_queue_rq_timeout(q
, device
->blk_timeout
* HZ
);
1329 spin_unlock_irqrestore(&device
->block
->request_queue_lock
, flags
);
1331 dasd_put_device(device
);
1335 static DEVICE_ATTR(timeout
, 0644,
1336 dasd_timeout_show
, dasd_timeout_store
);
1338 static ssize_t
dasd_reservation_policy_show(struct device
*dev
,
1339 struct device_attribute
*attr
,
1342 struct dasd_devmap
*devmap
;
1345 devmap
= dasd_find_busid(dev_name(dev
));
1346 if (IS_ERR(devmap
)) {
1347 rc
= snprintf(buf
, PAGE_SIZE
, "ignore\n");
1349 spin_lock(&dasd_devmap_lock
);
1350 if (devmap
->features
& DASD_FEATURE_FAILONSLCK
)
1351 rc
= snprintf(buf
, PAGE_SIZE
, "fail\n");
1353 rc
= snprintf(buf
, PAGE_SIZE
, "ignore\n");
1354 spin_unlock(&dasd_devmap_lock
);
1359 static ssize_t
dasd_reservation_policy_store(struct device
*dev
,
1360 struct device_attribute
*attr
,
1361 const char *buf
, size_t count
)
1363 struct dasd_devmap
*devmap
;
1366 devmap
= dasd_devmap_from_cdev(to_ccwdev(dev
));
1368 return PTR_ERR(devmap
);
1370 spin_lock(&dasd_devmap_lock
);
1371 if (sysfs_streq("ignore", buf
))
1372 devmap
->features
&= ~DASD_FEATURE_FAILONSLCK
;
1373 else if (sysfs_streq("fail", buf
))
1374 devmap
->features
|= DASD_FEATURE_FAILONSLCK
;
1378 devmap
->device
->features
= devmap
->features
;
1379 spin_unlock(&dasd_devmap_lock
);
1386 static DEVICE_ATTR(reservation_policy
, 0644,
1387 dasd_reservation_policy_show
, dasd_reservation_policy_store
);
1389 static ssize_t
dasd_reservation_state_show(struct device
*dev
,
1390 struct device_attribute
*attr
,
1393 struct dasd_device
*device
;
1396 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1398 return snprintf(buf
, PAGE_SIZE
, "none\n");
1400 if (test_bit(DASD_FLAG_IS_RESERVED
, &device
->flags
))
1401 rc
= snprintf(buf
, PAGE_SIZE
, "reserved\n");
1402 else if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
))
1403 rc
= snprintf(buf
, PAGE_SIZE
, "lost\n");
1405 rc
= snprintf(buf
, PAGE_SIZE
, "none\n");
1406 dasd_put_device(device
);
1410 static ssize_t
dasd_reservation_state_store(struct device
*dev
,
1411 struct device_attribute
*attr
,
1412 const char *buf
, size_t count
)
1414 struct dasd_device
*device
;
1417 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1420 if (sysfs_streq("reset", buf
))
1421 clear_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
);
1424 dasd_put_device(device
);
1432 static DEVICE_ATTR(last_known_reservation_state
, 0644,
1433 dasd_reservation_state_show
, dasd_reservation_state_store
);
1435 static ssize_t
dasd_pm_show(struct device
*dev
,
1436 struct device_attribute
*attr
, char *buf
)
1438 struct dasd_device
*device
;
1439 u8 opm
, nppm
, cablepm
, cuirpm
, hpfpm
;
1441 device
= dasd_device_from_cdev(to_ccwdev(dev
));
1443 return sprintf(buf
, "0\n");
1445 opm
= device
->path_data
.opm
;
1446 nppm
= device
->path_data
.npm
;
1447 cablepm
= device
->path_data
.cablepm
;
1448 cuirpm
= device
->path_data
.cuirpm
;
1449 hpfpm
= device
->path_data
.hpfpm
;
1450 dasd_put_device(device
);
1452 return sprintf(buf
, "%02x %02x %02x %02x %02x\n", opm
, nppm
,
1453 cablepm
, cuirpm
, hpfpm
);
1456 static DEVICE_ATTR(path_masks
, 0444, dasd_pm_show
, NULL
);
1458 static struct attribute
* dasd_attrs
[] = {
1459 &dev_attr_readonly
.attr
,
1460 &dev_attr_discipline
.attr
,
1461 &dev_attr_status
.attr
,
1462 &dev_attr_alias
.attr
,
1463 &dev_attr_vendor
.attr
,
1465 &dev_attr_use_diag
.attr
,
1466 &dev_attr_raw_track_access
.attr
,
1467 &dev_attr_eer_enabled
.attr
,
1468 &dev_attr_erplog
.attr
,
1469 &dev_attr_failfast
.attr
,
1470 &dev_attr_expires
.attr
,
1471 &dev_attr_retries
.attr
,
1472 &dev_attr_timeout
.attr
,
1473 &dev_attr_reservation_policy
.attr
,
1474 &dev_attr_last_known_reservation_state
.attr
,
1475 &dev_attr_safe_offline
.attr
,
1476 &dev_attr_path_masks
.attr
,
1480 static struct attribute_group dasd_attr_group
= {
1481 .attrs
= dasd_attrs
,
1485 * Return value of the specified feature.
1488 dasd_get_feature(struct ccw_device
*cdev
, int feature
)
1490 struct dasd_devmap
*devmap
;
1492 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1494 return PTR_ERR(devmap
);
1496 return ((devmap
->features
& feature
) != 0);
1500 * Set / reset given feature.
1501 * Flag indicates whether to set (!=0) or the reset (=0) the feature.
1504 dasd_set_feature(struct ccw_device
*cdev
, int feature
, int flag
)
1506 struct dasd_devmap
*devmap
;
1508 devmap
= dasd_find_busid(dev_name(&cdev
->dev
));
1510 return PTR_ERR(devmap
);
1512 spin_lock(&dasd_devmap_lock
);
1514 devmap
->features
|= feature
;
1516 devmap
->features
&= ~feature
;
1518 devmap
->device
->features
= devmap
->features
;
1519 spin_unlock(&dasd_devmap_lock
);
1525 dasd_add_sysfs_files(struct ccw_device
*cdev
)
1527 return sysfs_create_group(&cdev
->dev
.kobj
, &dasd_attr_group
);
1531 dasd_remove_sysfs_files(struct ccw_device
*cdev
)
1533 sysfs_remove_group(&cdev
->dev
.kobj
, &dasd_attr_group
);
1538 dasd_devmap_init(void)
1542 /* Initialize devmap structures. */
1543 dasd_max_devindex
= 0;
1544 for (i
= 0; i
< 256; i
++)
1545 INIT_LIST_HEAD(&dasd_hashlists
[i
]);
1550 dasd_devmap_exit(void)
1552 dasd_forget_ranges();