[PATCH] W1: possible cleanups
[linux-2.6/verdex.git] / drivers / s390 / block / dasd_devmap.c
blob216bc4fba19998c2c5a92a8455d92f32d0dce4ab
1 /*
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/config.h>
17 #include <linux/ctype.h>
18 #include <linux/init.h>
19 #include <linux/module.h>
21 #include <asm/debug.h>
22 #include <asm/uaccess.h>
24 /* This is ugly... */
25 #define PRINTK_HEADER "dasd_devmap:"
27 #include "dasd_int.h"
29 kmem_cache_t *dasd_page_cache;
30 EXPORT_SYMBOL(dasd_page_cache);
33 * dasd_devmap_t is used to store the features and the relation
34 * between device number and device index. To find a dasd_devmap_t
35 * that corresponds to a device number of a device index each
36 * dasd_devmap_t is added to two linked lists, one to search by
37 * the device number and one to search by the device index. As
38 * soon as big minor numbers are available the device index list
39 * can be removed since the device number will then be identical
40 * to the device index.
42 struct dasd_devmap {
43 struct list_head list;
44 char bus_id[BUS_ID_SIZE];
45 unsigned int devindex;
46 unsigned short features;
47 struct dasd_device *device;
48 struct dasd_uid uid;
52 * Parameter parsing functions for dasd= parameter. The syntax is:
53 * <devno> : (0x)?[0-9a-fA-F]+
54 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
55 * <feature> : ro
56 * <feature_list> : \(<feature>(:<feature>)*\)
57 * <devno-range> : <devno>(-<devno>)?<feature_list>?
58 * <busid-range> : <busid>(-<busid>)?<feature_list>?
59 * <devices> : <devno-range>|<busid-range>
60 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
62 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
65 int dasd_probeonly = 0; /* is true, when probeonly mode is active */
66 int dasd_autodetect = 0; /* is true, when autodetection is active */
69 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
70 * it is named 'dasd' to directly be filled by insmod with the comma separated
71 * strings when running as a module.
73 static char *dasd[256];
74 module_param_array(dasd, charp, NULL, 0);
77 * Single spinlock to protect devmap structures and lists.
79 static DEFINE_SPINLOCK(dasd_devmap_lock);
82 * Hash lists for devmap structures.
84 static struct list_head dasd_hashlists[256];
85 int dasd_max_devindex;
87 static struct dasd_devmap *dasd_add_busid(char *, int);
89 static inline int
90 dasd_hash_busid(char *bus_id)
92 int hash, i;
94 hash = 0;
95 for (i = 0; (i < BUS_ID_SIZE) && *bus_id; i++, bus_id++)
96 hash += *bus_id;
97 return hash & 0xff;
100 #ifndef MODULE
102 * The parameter parsing functions for builtin-drivers are called
103 * before kmalloc works. Store the pointers to the parameters strings
104 * into dasd[] for later processing.
106 static int __init
107 dasd_call_setup(char *str)
109 static int count = 0;
111 if (count < 256)
112 dasd[count++] = str;
113 return 1;
116 __setup ("dasd=", dasd_call_setup);
117 #endif /* #ifndef MODULE */
120 * Read a device busid/devno from a string.
122 static inline int
123 dasd_busid(char **str, int *id0, int *id1, int *devno)
125 int val, old_style;
127 /* check for leading '0x' */
128 old_style = 0;
129 if ((*str)[0] == '0' && (*str)[1] == 'x') {
130 *str += 2;
131 old_style = 1;
133 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
134 return -EINVAL;
135 val = simple_strtoul(*str, str, 16);
136 if (old_style || (*str)[0] != '.') {
137 *id0 = *id1 = 0;
138 if (val < 0 || val > 0xffff)
139 return -EINVAL;
140 *devno = val;
141 return 0;
143 /* New style x.y.z busid */
144 if (val < 0 || val > 0xff)
145 return -EINVAL;
146 *id0 = val;
147 (*str)++;
148 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
149 return -EINVAL;
150 val = simple_strtoul(*str, str, 16);
151 if (val < 0 || val > 0xff || (*str)++[0] != '.')
152 return -EINVAL;
153 *id1 = val;
154 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
155 return -EINVAL;
156 val = simple_strtoul(*str, str, 16);
157 if (val < 0 || val > 0xffff)
158 return -EINVAL;
159 *devno = val;
160 return 0;
164 * Read colon separated list of dasd features. Currently there is
165 * only one: "ro" for read-only devices. The default feature set
166 * is empty (value 0).
168 static inline int
169 dasd_feature_list(char *str, char **endp)
171 int features, len, rc;
173 rc = 0;
174 if (*str != '(') {
175 *endp = str;
176 return DASD_FEATURE_DEFAULT;
178 str++;
179 features = 0;
181 while (1) {
182 for (len = 0;
183 str[len] && str[len] != ':' && str[len] != ')'; len++);
184 if (len == 2 && !strncmp(str, "ro", 2))
185 features |= DASD_FEATURE_READONLY;
186 else if (len == 4 && !strncmp(str, "diag", 4))
187 features |= DASD_FEATURE_USEDIAG;
188 else {
189 MESSAGE(KERN_WARNING,
190 "unsupported feature: %*s, "
191 "ignoring setting", len, str);
192 rc = -EINVAL;
194 str += len;
195 if (*str != ':')
196 break;
197 str++;
199 if (*str != ')') {
200 MESSAGE(KERN_WARNING, "%s",
201 "missing ')' in dasd parameter string\n");
202 rc = -EINVAL;
203 } else
204 str++;
205 *endp = str;
206 if (rc != 0)
207 return rc;
208 return features;
212 * Try to match the first element on the comma separated parse string
213 * with one of the known keywords. If a keyword is found, take the approprate
214 * action and return a pointer to the residual string. If the first element
215 * could not be matched to any keyword then return an error code.
217 static char *
218 dasd_parse_keyword( char *parsestring ) {
220 char *nextcomma, *residual_str;
221 int length;
223 nextcomma = strchr(parsestring,',');
224 if (nextcomma) {
225 length = nextcomma - parsestring;
226 residual_str = nextcomma + 1;
227 } else {
228 length = strlen(parsestring);
229 residual_str = parsestring + length;
231 if (strncmp ("autodetect", parsestring, length) == 0) {
232 dasd_autodetect = 1;
233 MESSAGE (KERN_INFO, "%s",
234 "turning to autodetection mode");
235 return residual_str;
237 if (strncmp ("probeonly", parsestring, length) == 0) {
238 dasd_probeonly = 1;
239 MESSAGE(KERN_INFO, "%s",
240 "turning to probeonly mode");
241 return residual_str;
243 if (strncmp ("fixedbuffers", parsestring, length) == 0) {
244 if (dasd_page_cache)
245 return residual_str;
246 dasd_page_cache =
247 kmem_cache_create("dasd_page_cache", PAGE_SIZE, 0,
248 SLAB_CACHE_DMA, NULL, NULL );
249 if (!dasd_page_cache)
250 MESSAGE(KERN_WARNING, "%s", "Failed to create slab, "
251 "fixed buffer mode disabled.");
252 else
253 MESSAGE (KERN_INFO, "%s",
254 "turning on fixed buffer mode");
255 return residual_str;
257 return ERR_PTR(-EINVAL);
261 * Try to interprete the first element on the comma separated parse string
262 * as a device number or a range of devices. If the interpretation is
263 * successfull, create the matching dasd_devmap entries and return a pointer
264 * to the residual string.
265 * If interpretation fails or in case of an error, return an error code.
267 static char *
268 dasd_parse_range( char *parsestring ) {
270 struct dasd_devmap *devmap;
271 int from, from_id0, from_id1;
272 int to, to_id0, to_id1;
273 int features, rc;
274 char bus_id[BUS_ID_SIZE+1], *str;
276 str = parsestring;
277 rc = dasd_busid(&str, &from_id0, &from_id1, &from);
278 if (rc == 0) {
279 to = from;
280 to_id0 = from_id0;
281 to_id1 = from_id1;
282 if (*str == '-') {
283 str++;
284 rc = dasd_busid(&str, &to_id0, &to_id1, &to);
287 if (rc == 0 &&
288 (from_id0 != to_id0 || from_id1 != to_id1 || from > to))
289 rc = -EINVAL;
290 if (rc) {
291 MESSAGE(KERN_ERR, "Invalid device range %s", parsestring);
292 return ERR_PTR(rc);
294 features = dasd_feature_list(str, &str);
295 if (features < 0)
296 return ERR_PTR(-EINVAL);
297 while (from <= to) {
298 sprintf(bus_id, "%01x.%01x.%04x",
299 from_id0, from_id1, from++);
300 devmap = dasd_add_busid(bus_id, features);
301 if (IS_ERR(devmap))
302 return (char *)devmap;
304 if (*str == ',')
305 return str + 1;
306 if (*str == '\0')
307 return str;
308 MESSAGE(KERN_WARNING,
309 "junk at end of dasd parameter string: %s\n", str);
310 return ERR_PTR(-EINVAL);
313 static inline char *
314 dasd_parse_next_element( char *parsestring ) {
315 char * residual_str;
316 residual_str = dasd_parse_keyword(parsestring);
317 if (!IS_ERR(residual_str))
318 return residual_str;
319 residual_str = dasd_parse_range(parsestring);
320 return residual_str;
324 * Parse parameters stored in dasd[]
325 * The 'dasd=...' parameter allows to specify a comma separated list of
326 * keywords and device ranges. When the dasd driver is build into the kernel,
327 * the complete list will be stored as one element of the dasd[] array.
328 * When the dasd driver is build as a module, then the list is broken into
329 * it's elements and each dasd[] entry contains one element.
332 dasd_parse(void)
334 int rc, i;
335 char *parsestring;
337 rc = 0;
338 for (i = 0; i < 256; i++) {
339 if (dasd[i] == NULL)
340 break;
341 parsestring = dasd[i];
342 /* loop over the comma separated list in the parsestring */
343 while (*parsestring) {
344 parsestring = dasd_parse_next_element(parsestring);
345 if(IS_ERR(parsestring)) {
346 rc = PTR_ERR(parsestring);
347 break;
350 if (rc) {
351 DBF_EVENT(DBF_ALERT, "%s", "invalid range found");
352 break;
355 return rc;
359 * Add a devmap for the device specified by busid. It is possible that
360 * the devmap already exists (dasd= parameter). The order of the devices
361 * added through this function will define the kdevs for the individual
362 * devices.
364 static struct dasd_devmap *
365 dasd_add_busid(char *bus_id, int features)
367 struct dasd_devmap *devmap, *new, *tmp;
368 int hash;
370 new = (struct dasd_devmap *)
371 kmalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
372 if (!new)
373 return ERR_PTR(-ENOMEM);
374 spin_lock(&dasd_devmap_lock);
375 devmap = 0;
376 hash = dasd_hash_busid(bus_id);
377 list_for_each_entry(tmp, &dasd_hashlists[hash], list)
378 if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
379 devmap = tmp;
380 break;
382 if (!devmap) {
383 /* This bus_id is new. */
384 new->devindex = dasd_max_devindex++;
385 strncpy(new->bus_id, bus_id, BUS_ID_SIZE);
386 new->features = features;
387 new->device = 0;
388 list_add(&new->list, &dasd_hashlists[hash]);
389 devmap = new;
390 new = 0;
392 spin_unlock(&dasd_devmap_lock);
393 kfree(new);
394 return devmap;
398 * Find devmap for device with given bus_id.
400 static struct dasd_devmap *
401 dasd_find_busid(char *bus_id)
403 struct dasd_devmap *devmap, *tmp;
404 int hash;
406 spin_lock(&dasd_devmap_lock);
407 devmap = ERR_PTR(-ENODEV);
408 hash = dasd_hash_busid(bus_id);
409 list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
410 if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
411 devmap = tmp;
412 break;
415 spin_unlock(&dasd_devmap_lock);
416 return devmap;
420 * Check if busid has been added to the list of dasd ranges.
423 dasd_busid_known(char *bus_id)
425 return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
429 * Forget all about the device numbers added so far.
430 * This may only be called at module unload or system shutdown.
432 static void
433 dasd_forget_ranges(void)
435 struct dasd_devmap *devmap, *n;
436 int i;
438 spin_lock(&dasd_devmap_lock);
439 for (i = 0; i < 256; i++) {
440 list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
441 BUG_ON(devmap->device != NULL);
442 list_del(&devmap->list);
443 kfree(devmap);
446 spin_unlock(&dasd_devmap_lock);
450 * Find the device struct by its device index.
452 struct dasd_device *
453 dasd_device_from_devindex(int devindex)
455 struct dasd_devmap *devmap, *tmp;
456 struct dasd_device *device;
457 int i;
459 spin_lock(&dasd_devmap_lock);
460 devmap = 0;
461 for (i = 0; (i < 256) && !devmap; i++)
462 list_for_each_entry(tmp, &dasd_hashlists[i], list)
463 if (tmp->devindex == devindex) {
464 /* Found the devmap for the device. */
465 devmap = tmp;
466 break;
468 if (devmap && devmap->device) {
469 device = devmap->device;
470 dasd_get_device(device);
471 } else
472 device = ERR_PTR(-ENODEV);
473 spin_unlock(&dasd_devmap_lock);
474 return device;
478 * Return devmap for cdev. If no devmap exists yet, create one and
479 * connect it to the cdev.
481 static struct dasd_devmap *
482 dasd_devmap_from_cdev(struct ccw_device *cdev)
484 struct dasd_devmap *devmap;
486 devmap = dasd_find_busid(cdev->dev.bus_id);
487 if (IS_ERR(devmap))
488 devmap = dasd_add_busid(cdev->dev.bus_id,
489 DASD_FEATURE_DEFAULT);
490 return devmap;
494 * Create a dasd device structure for cdev.
496 struct dasd_device *
497 dasd_create_device(struct ccw_device *cdev)
499 struct dasd_devmap *devmap;
500 struct dasd_device *device;
501 int rc;
503 devmap = dasd_devmap_from_cdev(cdev);
504 if (IS_ERR(devmap))
505 return (void *) devmap;
506 cdev->dev.driver_data = devmap;
508 device = dasd_alloc_device();
509 if (IS_ERR(device))
510 return device;
511 atomic_set(&device->ref_count, 2);
513 spin_lock(&dasd_devmap_lock);
514 if (!devmap->device) {
515 devmap->device = device;
516 device->devindex = devmap->devindex;
517 device->features = devmap->features;
518 get_device(&cdev->dev);
519 device->cdev = cdev;
520 rc = 0;
521 } else
522 /* Someone else was faster. */
523 rc = -EBUSY;
524 spin_unlock(&dasd_devmap_lock);
526 if (rc) {
527 dasd_free_device(device);
528 return ERR_PTR(rc);
530 return device;
534 * Wait queue for dasd_delete_device waits.
536 static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
539 * Remove a dasd device structure. The passed referenced
540 * is destroyed.
542 void
543 dasd_delete_device(struct dasd_device *device)
545 struct ccw_device *cdev;
546 struct dasd_devmap *devmap;
548 /* First remove device pointer from devmap. */
549 devmap = dasd_find_busid(device->cdev->dev.bus_id);
550 BUG_ON(IS_ERR(devmap));
551 spin_lock(&dasd_devmap_lock);
552 if (devmap->device != device) {
553 spin_unlock(&dasd_devmap_lock);
554 dasd_put_device(device);
555 return;
557 devmap->device = NULL;
558 spin_unlock(&dasd_devmap_lock);
560 /* Drop ref_count by 2, one for the devmap reference and
561 * one for the passed reference. */
562 atomic_sub(2, &device->ref_count);
564 /* Wait for reference counter to drop to zero. */
565 wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
567 /* Disconnect dasd_device structure from ccw_device structure. */
568 cdev = device->cdev;
569 device->cdev = NULL;
571 /* Disconnect dasd_devmap structure from ccw_device structure. */
572 cdev->dev.driver_data = NULL;
574 /* Put ccw_device structure. */
575 put_device(&cdev->dev);
577 /* Now the device structure can be freed. */
578 dasd_free_device(device);
582 * Reference counter dropped to zero. Wake up waiter
583 * in dasd_delete_device.
585 void
586 dasd_put_device_wake(struct dasd_device *device)
588 wake_up(&dasd_delete_wq);
592 * Return dasd_device structure associated with cdev.
594 struct dasd_device *
595 dasd_device_from_cdev(struct ccw_device *cdev)
597 struct dasd_devmap *devmap;
598 struct dasd_device *device;
600 device = ERR_PTR(-ENODEV);
601 spin_lock(&dasd_devmap_lock);
602 devmap = cdev->dev.driver_data;
603 if (devmap && devmap->device) {
604 device = devmap->device;
605 dasd_get_device(device);
607 spin_unlock(&dasd_devmap_lock);
608 return device;
612 * SECTION: files in sysfs
616 * readonly controls the readonly status of a dasd
618 static ssize_t
619 dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
621 struct dasd_devmap *devmap;
622 int ro_flag;
624 devmap = dasd_find_busid(dev->bus_id);
625 if (!IS_ERR(devmap))
626 ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
627 else
628 ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
629 return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
632 static ssize_t
633 dasd_ro_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
635 struct dasd_devmap *devmap;
636 int ro_flag;
638 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
639 if (IS_ERR(devmap))
640 return PTR_ERR(devmap);
641 ro_flag = buf[0] == '1';
642 spin_lock(&dasd_devmap_lock);
643 if (ro_flag)
644 devmap->features |= DASD_FEATURE_READONLY;
645 else
646 devmap->features &= ~DASD_FEATURE_READONLY;
647 if (devmap->device)
648 devmap->device->features = devmap->features;
649 if (devmap->device && devmap->device->gdp)
650 set_disk_ro(devmap->device->gdp, ro_flag);
651 spin_unlock(&dasd_devmap_lock);
652 return count;
655 static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
658 * use_diag controls whether the driver should use diag rather than ssch
659 * to talk to the device
661 static ssize_t
662 dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
664 struct dasd_devmap *devmap;
665 int use_diag;
667 devmap = dasd_find_busid(dev->bus_id);
668 if (!IS_ERR(devmap))
669 use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
670 else
671 use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
672 return sprintf(buf, use_diag ? "1\n" : "0\n");
675 static ssize_t
676 dasd_use_diag_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
678 struct dasd_devmap *devmap;
679 ssize_t rc;
680 int use_diag;
682 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
683 if (IS_ERR(devmap))
684 return PTR_ERR(devmap);
685 use_diag = buf[0] == '1';
686 spin_lock(&dasd_devmap_lock);
687 /* Changing diag discipline flag is only allowed in offline state. */
688 rc = count;
689 if (!devmap->device) {
690 if (use_diag)
691 devmap->features |= DASD_FEATURE_USEDIAG;
692 else
693 devmap->features &= ~DASD_FEATURE_USEDIAG;
694 } else
695 rc = -EPERM;
696 spin_unlock(&dasd_devmap_lock);
697 return rc;
700 static
701 DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
703 static ssize_t
704 dasd_discipline_show(struct device *dev, struct device_attribute *attr, char *buf)
706 struct dasd_devmap *devmap;
707 char *dname;
709 spin_lock(&dasd_devmap_lock);
710 dname = "none";
711 devmap = dev->driver_data;
712 if (devmap && devmap->device && devmap->device->discipline)
713 dname = devmap->device->discipline->name;
714 spin_unlock(&dasd_devmap_lock);
715 return snprintf(buf, PAGE_SIZE, "%s\n", dname);
718 static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
720 static ssize_t
721 dasd_alias_show(struct device *dev, struct device_attribute *attr, char *buf)
723 struct dasd_devmap *devmap;
724 int alias;
726 devmap = dasd_find_busid(dev->bus_id);
727 spin_lock(&dasd_devmap_lock);
728 if (!IS_ERR(devmap))
729 alias = devmap->uid.alias;
730 else
731 alias = 0;
732 spin_unlock(&dasd_devmap_lock);
734 return sprintf(buf, alias ? "1\n" : "0\n");
737 static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
739 static ssize_t
740 dasd_vendor_show(struct device *dev, struct device_attribute *attr, char *buf)
742 struct dasd_devmap *devmap;
743 char *vendor;
745 devmap = dasd_find_busid(dev->bus_id);
746 spin_lock(&dasd_devmap_lock);
747 if (!IS_ERR(devmap) && strlen(devmap->uid.vendor) > 0)
748 vendor = devmap->uid.vendor;
749 else
750 vendor = "";
751 spin_unlock(&dasd_devmap_lock);
753 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
756 static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
758 #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
759 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1)
761 static ssize_t
762 dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
764 struct dasd_devmap *devmap;
765 char uid[UID_STRLEN];
767 devmap = dasd_find_busid(dev->bus_id);
768 spin_lock(&dasd_devmap_lock);
769 if (!IS_ERR(devmap) && strlen(devmap->uid.vendor) > 0)
770 snprintf(uid, sizeof(uid), "%s.%s.%04x.%02x",
771 devmap->uid.vendor, devmap->uid.serial,
772 devmap->uid.ssid, devmap->uid.unit_addr);
773 else
774 uid[0] = 0;
775 spin_unlock(&dasd_devmap_lock);
777 return snprintf(buf, PAGE_SIZE, "%s\n", uid);
780 static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
783 * extended error-reporting
785 static ssize_t
786 dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
788 struct dasd_devmap *devmap;
789 int eer_flag;
791 devmap = dasd_find_busid(dev->bus_id);
792 if (!IS_ERR(devmap) && devmap->device)
793 eer_flag = dasd_eer_enabled(devmap->device);
794 else
795 eer_flag = 0;
796 return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
799 static ssize_t
800 dasd_eer_store(struct device *dev, struct device_attribute *attr,
801 const char *buf, size_t count)
803 struct dasd_devmap *devmap;
804 int rc;
806 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
807 if (IS_ERR(devmap))
808 return PTR_ERR(devmap);
809 if (!devmap->device)
810 return count;
811 if (buf[0] == '1') {
812 rc = dasd_eer_enable(devmap->device);
813 if (rc)
814 return rc;
815 } else
816 dasd_eer_disable(devmap->device);
817 return count;
820 static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
822 static struct attribute * dasd_attrs[] = {
823 &dev_attr_readonly.attr,
824 &dev_attr_discipline.attr,
825 &dev_attr_alias.attr,
826 &dev_attr_vendor.attr,
827 &dev_attr_uid.attr,
828 &dev_attr_use_diag.attr,
829 &dev_attr_eer_enabled.attr,
830 NULL,
833 static struct attribute_group dasd_attr_group = {
834 .attrs = dasd_attrs,
839 * Return copy of the device unique identifier.
842 dasd_get_uid(struct ccw_device *cdev, struct dasd_uid *uid)
844 struct dasd_devmap *devmap;
846 devmap = dasd_find_busid(cdev->dev.bus_id);
847 if (IS_ERR(devmap))
848 return PTR_ERR(devmap);
849 spin_lock(&dasd_devmap_lock);
850 *uid = devmap->uid;
851 spin_unlock(&dasd_devmap_lock);
852 return 0;
856 * Register the given device unique identifier into devmap struct.
859 dasd_set_uid(struct ccw_device *cdev, struct dasd_uid *uid)
861 struct dasd_devmap *devmap;
863 devmap = dasd_find_busid(cdev->dev.bus_id);
864 if (IS_ERR(devmap))
865 return PTR_ERR(devmap);
866 spin_lock(&dasd_devmap_lock);
867 devmap->uid = *uid;
868 spin_unlock(&dasd_devmap_lock);
869 return 0;
871 EXPORT_SYMBOL(dasd_set_uid);
874 * Return value of the specified feature.
877 dasd_get_feature(struct ccw_device *cdev, int feature)
879 struct dasd_devmap *devmap;
881 devmap = dasd_find_busid(cdev->dev.bus_id);
882 if (IS_ERR(devmap))
883 return (int) PTR_ERR(devmap);
885 return ((devmap->features & feature) != 0);
889 * Set / reset given feature.
890 * Flag indicates wether to set (!=0) or the reset (=0) the feature.
893 dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
895 struct dasd_devmap *devmap;
897 devmap = dasd_find_busid(cdev->dev.bus_id);
898 if (IS_ERR(devmap))
899 return (int) PTR_ERR(devmap);
901 spin_lock(&dasd_devmap_lock);
902 if (flag)
903 devmap->features |= feature;
904 else
905 devmap->features &= ~feature;
906 if (devmap->device)
907 devmap->device->features = devmap->features;
908 spin_unlock(&dasd_devmap_lock);
909 return 0;
914 dasd_add_sysfs_files(struct ccw_device *cdev)
916 return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
919 void
920 dasd_remove_sysfs_files(struct ccw_device *cdev)
922 sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
927 dasd_devmap_init(void)
929 int i;
931 /* Initialize devmap structures. */
932 dasd_max_devindex = 0;
933 for (i = 0; i < 256; i++)
934 INIT_LIST_HEAD(&dasd_hashlists[i]);
935 return 0;
939 void
940 dasd_devmap_exit(void)
942 dasd_forget_ranges();