[S390] dasd calls kzalloc while holding a spinlock.
[linux-2.6/kvm.git] / drivers / s390 / block / dasd_devmap.c
blob6fcb28d55a9dd7f5529dfe52528281026a19f687
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/ctype.h>
17 #include <linux/init.h>
18 #include <linux/module.h>
20 #include <asm/debug.h>
21 #include <asm/uaccess.h>
23 /* This is ugly... */
24 #define PRINTK_HEADER "dasd_devmap:"
26 #include "dasd_int.h"
28 kmem_cache_t *dasd_page_cache;
29 EXPORT_SYMBOL_GPL(dasd_page_cache);
32 * dasd_devmap_t is used to store the features and the relation
33 * between device number and device index. To find a dasd_devmap_t
34 * that corresponds to a device number of a device index each
35 * dasd_devmap_t is added to two linked lists, one to search by
36 * the device number and one to search by the device index. As
37 * soon as big minor numbers are available the device index list
38 * can be removed since the device number will then be identical
39 * to the device index.
41 struct dasd_devmap {
42 struct list_head list;
43 char bus_id[BUS_ID_SIZE];
44 unsigned int devindex;
45 unsigned short features;
46 struct dasd_device *device;
47 struct dasd_uid uid;
51 * dasd_servermap is used to store the server_id of all storage servers
52 * accessed by DASD device driver.
54 struct dasd_servermap {
55 struct list_head list;
56 struct server_id {
57 char vendor[4];
58 char serial[15];
59 } sid;
62 static struct list_head dasd_serverlist;
65 * Parameter parsing functions for dasd= parameter. The syntax is:
66 * <devno> : (0x)?[0-9a-fA-F]+
67 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
68 * <feature> : ro
69 * <feature_list> : \(<feature>(:<feature>)*\)
70 * <devno-range> : <devno>(-<devno>)?<feature_list>?
71 * <busid-range> : <busid>(-<busid>)?<feature_list>?
72 * <devices> : <devno-range>|<busid-range>
73 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
75 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
78 int dasd_probeonly = 0; /* is true, when probeonly mode is active */
79 int dasd_autodetect = 0; /* is true, when autodetection is active */
80 int dasd_nopav = 0; /* is true, when PAV is disabled */
81 EXPORT_SYMBOL_GPL(dasd_nopav);
84 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
85 * it is named 'dasd' to directly be filled by insmod with the comma separated
86 * strings when running as a module.
88 static char *dasd[256];
89 module_param_array(dasd, charp, NULL, 0);
92 * Single spinlock to protect devmap and servermap structures and lists.
94 static DEFINE_SPINLOCK(dasd_devmap_lock);
97 * Hash lists for devmap structures.
99 static struct list_head dasd_hashlists[256];
100 int dasd_max_devindex;
102 static struct dasd_devmap *dasd_add_busid(char *, int);
104 static inline int
105 dasd_hash_busid(char *bus_id)
107 int hash, i;
109 hash = 0;
110 for (i = 0; (i < BUS_ID_SIZE) && *bus_id; i++, bus_id++)
111 hash += *bus_id;
112 return hash & 0xff;
115 #ifndef MODULE
117 * The parameter parsing functions for builtin-drivers are called
118 * before kmalloc works. Store the pointers to the parameters strings
119 * into dasd[] for later processing.
121 static int __init
122 dasd_call_setup(char *str)
124 static int count = 0;
126 if (count < 256)
127 dasd[count++] = str;
128 return 1;
131 __setup ("dasd=", dasd_call_setup);
132 #endif /* #ifndef MODULE */
135 * Read a device busid/devno from a string.
137 static inline int
138 dasd_busid(char **str, int *id0, int *id1, int *devno)
140 int val, old_style;
142 /* check for leading '0x' */
143 old_style = 0;
144 if ((*str)[0] == '0' && (*str)[1] == 'x') {
145 *str += 2;
146 old_style = 1;
148 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
149 return -EINVAL;
150 val = simple_strtoul(*str, str, 16);
151 if (old_style || (*str)[0] != '.') {
152 *id0 = *id1 = 0;
153 if (val < 0 || val > 0xffff)
154 return -EINVAL;
155 *devno = val;
156 return 0;
158 /* New style x.y.z busid */
159 if (val < 0 || val > 0xff)
160 return -EINVAL;
161 *id0 = val;
162 (*str)++;
163 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
164 return -EINVAL;
165 val = simple_strtoul(*str, str, 16);
166 if (val < 0 || val > 0xff || (*str)++[0] != '.')
167 return -EINVAL;
168 *id1 = val;
169 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
170 return -EINVAL;
171 val = simple_strtoul(*str, str, 16);
172 if (val < 0 || val > 0xffff)
173 return -EINVAL;
174 *devno = val;
175 return 0;
179 * Read colon separated list of dasd features. Currently there is
180 * only one: "ro" for read-only devices. The default feature set
181 * is empty (value 0).
183 static inline int
184 dasd_feature_list(char *str, char **endp)
186 int features, len, rc;
188 rc = 0;
189 if (*str != '(') {
190 *endp = str;
191 return DASD_FEATURE_DEFAULT;
193 str++;
194 features = 0;
196 while (1) {
197 for (len = 0;
198 str[len] && str[len] != ':' && str[len] != ')'; len++);
199 if (len == 2 && !strncmp(str, "ro", 2))
200 features |= DASD_FEATURE_READONLY;
201 else if (len == 4 && !strncmp(str, "diag", 4))
202 features |= DASD_FEATURE_USEDIAG;
203 else {
204 MESSAGE(KERN_WARNING,
205 "unsupported feature: %*s, "
206 "ignoring setting", len, str);
207 rc = -EINVAL;
209 str += len;
210 if (*str != ':')
211 break;
212 str++;
214 if (*str != ')') {
215 MESSAGE(KERN_WARNING, "%s",
216 "missing ')' in dasd parameter string\n");
217 rc = -EINVAL;
218 } else
219 str++;
220 *endp = str;
221 if (rc != 0)
222 return rc;
223 return features;
227 * Try to match the first element on the comma separated parse string
228 * with one of the known keywords. If a keyword is found, take the approprate
229 * action and return a pointer to the residual string. If the first element
230 * could not be matched to any keyword then return an error code.
232 static char *
233 dasd_parse_keyword( char *parsestring ) {
235 char *nextcomma, *residual_str;
236 int length;
238 nextcomma = strchr(parsestring,',');
239 if (nextcomma) {
240 length = nextcomma - parsestring;
241 residual_str = nextcomma + 1;
242 } else {
243 length = strlen(parsestring);
244 residual_str = parsestring + length;
246 if (strncmp("autodetect", parsestring, length) == 0) {
247 dasd_autodetect = 1;
248 MESSAGE (KERN_INFO, "%s",
249 "turning to autodetection mode");
250 return residual_str;
252 if (strncmp("probeonly", parsestring, length) == 0) {
253 dasd_probeonly = 1;
254 MESSAGE(KERN_INFO, "%s",
255 "turning to probeonly mode");
256 return residual_str;
258 if (strncmp("nopav", parsestring, length) == 0) {
259 dasd_nopav = 1;
260 MESSAGE(KERN_INFO, "%s", "disable PAV mode");
261 return residual_str;
263 if (strncmp("fixedbuffers", parsestring, length) == 0) {
264 if (dasd_page_cache)
265 return residual_str;
266 dasd_page_cache =
267 kmem_cache_create("dasd_page_cache", PAGE_SIZE, 0,
268 SLAB_CACHE_DMA, NULL, NULL );
269 if (!dasd_page_cache)
270 MESSAGE(KERN_WARNING, "%s", "Failed to create slab, "
271 "fixed buffer mode disabled.");
272 else
273 MESSAGE (KERN_INFO, "%s",
274 "turning on fixed buffer mode");
275 return residual_str;
277 return ERR_PTR(-EINVAL);
281 * Try to interprete the first element on the comma separated parse string
282 * as a device number or a range of devices. If the interpretation is
283 * successfull, create the matching dasd_devmap entries and return a pointer
284 * to the residual string.
285 * If interpretation fails or in case of an error, return an error code.
287 static char *
288 dasd_parse_range( char *parsestring ) {
290 struct dasd_devmap *devmap;
291 int from, from_id0, from_id1;
292 int to, to_id0, to_id1;
293 int features, rc;
294 char bus_id[BUS_ID_SIZE+1], *str;
296 str = parsestring;
297 rc = dasd_busid(&str, &from_id0, &from_id1, &from);
298 if (rc == 0) {
299 to = from;
300 to_id0 = from_id0;
301 to_id1 = from_id1;
302 if (*str == '-') {
303 str++;
304 rc = dasd_busid(&str, &to_id0, &to_id1, &to);
307 if (rc == 0 &&
308 (from_id0 != to_id0 || from_id1 != to_id1 || from > to))
309 rc = -EINVAL;
310 if (rc) {
311 MESSAGE(KERN_ERR, "Invalid device range %s", parsestring);
312 return ERR_PTR(rc);
314 features = dasd_feature_list(str, &str);
315 if (features < 0)
316 return ERR_PTR(-EINVAL);
317 /* each device in dasd= parameter should be set initially online */
318 features |= DASD_FEATURE_INITIAL_ONLINE;
319 while (from <= to) {
320 sprintf(bus_id, "%01x.%01x.%04x",
321 from_id0, from_id1, from++);
322 devmap = dasd_add_busid(bus_id, features);
323 if (IS_ERR(devmap))
324 return (char *)devmap;
326 if (*str == ',')
327 return str + 1;
328 if (*str == '\0')
329 return str;
330 MESSAGE(KERN_WARNING,
331 "junk at end of dasd parameter string: %s\n", str);
332 return ERR_PTR(-EINVAL);
335 static inline char *
336 dasd_parse_next_element( char *parsestring ) {
337 char * residual_str;
338 residual_str = dasd_parse_keyword(parsestring);
339 if (!IS_ERR(residual_str))
340 return residual_str;
341 residual_str = dasd_parse_range(parsestring);
342 return residual_str;
346 * Parse parameters stored in dasd[]
347 * The 'dasd=...' parameter allows to specify a comma separated list of
348 * keywords and device ranges. When the dasd driver is build into the kernel,
349 * the complete list will be stored as one element of the dasd[] array.
350 * When the dasd driver is build as a module, then the list is broken into
351 * it's elements and each dasd[] entry contains one element.
354 dasd_parse(void)
356 int rc, i;
357 char *parsestring;
359 rc = 0;
360 for (i = 0; i < 256; i++) {
361 if (dasd[i] == NULL)
362 break;
363 parsestring = dasd[i];
364 /* loop over the comma separated list in the parsestring */
365 while (*parsestring) {
366 parsestring = dasd_parse_next_element(parsestring);
367 if(IS_ERR(parsestring)) {
368 rc = PTR_ERR(parsestring);
369 break;
372 if (rc) {
373 DBF_EVENT(DBF_ALERT, "%s", "invalid range found");
374 break;
377 return rc;
381 * Add a devmap for the device specified by busid. It is possible that
382 * the devmap already exists (dasd= parameter). The order of the devices
383 * added through this function will define the kdevs for the individual
384 * devices.
386 static struct dasd_devmap *
387 dasd_add_busid(char *bus_id, int features)
389 struct dasd_devmap *devmap, *new, *tmp;
390 int hash;
392 new = (struct dasd_devmap *)
393 kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
394 if (!new)
395 return ERR_PTR(-ENOMEM);
396 spin_lock(&dasd_devmap_lock);
397 devmap = NULL;
398 hash = dasd_hash_busid(bus_id);
399 list_for_each_entry(tmp, &dasd_hashlists[hash], list)
400 if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
401 devmap = tmp;
402 break;
404 if (!devmap) {
405 /* This bus_id is new. */
406 new->devindex = dasd_max_devindex++;
407 strncpy(new->bus_id, bus_id, BUS_ID_SIZE);
408 new->features = features;
409 new->device = NULL;
410 list_add(&new->list, &dasd_hashlists[hash]);
411 devmap = new;
412 new = NULL;
414 spin_unlock(&dasd_devmap_lock);
415 kfree(new);
416 return devmap;
420 * Find devmap for device with given bus_id.
422 static struct dasd_devmap *
423 dasd_find_busid(char *bus_id)
425 struct dasd_devmap *devmap, *tmp;
426 int hash;
428 spin_lock(&dasd_devmap_lock);
429 devmap = ERR_PTR(-ENODEV);
430 hash = dasd_hash_busid(bus_id);
431 list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
432 if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
433 devmap = tmp;
434 break;
437 spin_unlock(&dasd_devmap_lock);
438 return devmap;
442 * Check if busid has been added to the list of dasd ranges.
445 dasd_busid_known(char *bus_id)
447 return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
451 * Forget all about the device numbers added so far.
452 * This may only be called at module unload or system shutdown.
454 static void
455 dasd_forget_ranges(void)
457 struct dasd_devmap *devmap, *n;
458 int i;
460 spin_lock(&dasd_devmap_lock);
461 for (i = 0; i < 256; i++) {
462 list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
463 BUG_ON(devmap->device != NULL);
464 list_del(&devmap->list);
465 kfree(devmap);
468 spin_unlock(&dasd_devmap_lock);
472 * Find the device struct by its device index.
474 struct dasd_device *
475 dasd_device_from_devindex(int devindex)
477 struct dasd_devmap *devmap, *tmp;
478 struct dasd_device *device;
479 int i;
481 spin_lock(&dasd_devmap_lock);
482 devmap = NULL;
483 for (i = 0; (i < 256) && !devmap; i++)
484 list_for_each_entry(tmp, &dasd_hashlists[i], list)
485 if (tmp->devindex == devindex) {
486 /* Found the devmap for the device. */
487 devmap = tmp;
488 break;
490 if (devmap && devmap->device) {
491 device = devmap->device;
492 dasd_get_device(device);
493 } else
494 device = ERR_PTR(-ENODEV);
495 spin_unlock(&dasd_devmap_lock);
496 return device;
500 * Return devmap for cdev. If no devmap exists yet, create one and
501 * connect it to the cdev.
503 static struct dasd_devmap *
504 dasd_devmap_from_cdev(struct ccw_device *cdev)
506 struct dasd_devmap *devmap;
508 devmap = dasd_find_busid(cdev->dev.bus_id);
509 if (IS_ERR(devmap))
510 devmap = dasd_add_busid(cdev->dev.bus_id,
511 DASD_FEATURE_DEFAULT);
512 return devmap;
516 * Create a dasd device structure for cdev.
518 struct dasd_device *
519 dasd_create_device(struct ccw_device *cdev)
521 struct dasd_devmap *devmap;
522 struct dasd_device *device;
523 int rc;
525 devmap = dasd_devmap_from_cdev(cdev);
526 if (IS_ERR(devmap))
527 return (void *) devmap;
528 cdev->dev.driver_data = devmap;
530 device = dasd_alloc_device();
531 if (IS_ERR(device))
532 return device;
533 atomic_set(&device->ref_count, 2);
535 spin_lock(&dasd_devmap_lock);
536 if (!devmap->device) {
537 devmap->device = device;
538 device->devindex = devmap->devindex;
539 device->features = devmap->features;
540 get_device(&cdev->dev);
541 device->cdev = cdev;
542 rc = 0;
543 } else
544 /* Someone else was faster. */
545 rc = -EBUSY;
546 spin_unlock(&dasd_devmap_lock);
548 if (rc) {
549 dasd_free_device(device);
550 return ERR_PTR(rc);
552 return device;
556 * Wait queue for dasd_delete_device waits.
558 static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
561 * Remove a dasd device structure. The passed referenced
562 * is destroyed.
564 void
565 dasd_delete_device(struct dasd_device *device)
567 struct ccw_device *cdev;
568 struct dasd_devmap *devmap;
570 /* First remove device pointer from devmap. */
571 devmap = dasd_find_busid(device->cdev->dev.bus_id);
572 BUG_ON(IS_ERR(devmap));
573 spin_lock(&dasd_devmap_lock);
574 if (devmap->device != device) {
575 spin_unlock(&dasd_devmap_lock);
576 dasd_put_device(device);
577 return;
579 devmap->device = NULL;
580 spin_unlock(&dasd_devmap_lock);
582 /* Drop ref_count by 2, one for the devmap reference and
583 * one for the passed reference. */
584 atomic_sub(2, &device->ref_count);
586 /* Wait for reference counter to drop to zero. */
587 wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
589 /* Disconnect dasd_device structure from ccw_device structure. */
590 cdev = device->cdev;
591 device->cdev = NULL;
593 /* Disconnect dasd_devmap structure from ccw_device structure. */
594 cdev->dev.driver_data = NULL;
596 /* Put ccw_device structure. */
597 put_device(&cdev->dev);
599 /* Now the device structure can be freed. */
600 dasd_free_device(device);
604 * Reference counter dropped to zero. Wake up waiter
605 * in dasd_delete_device.
607 void
608 dasd_put_device_wake(struct dasd_device *device)
610 wake_up(&dasd_delete_wq);
614 * Return dasd_device structure associated with cdev.
616 struct dasd_device *
617 dasd_device_from_cdev(struct ccw_device *cdev)
619 struct dasd_devmap *devmap;
620 struct dasd_device *device;
622 device = ERR_PTR(-ENODEV);
623 spin_lock(&dasd_devmap_lock);
624 devmap = cdev->dev.driver_data;
625 if (devmap && devmap->device) {
626 device = devmap->device;
627 dasd_get_device(device);
629 spin_unlock(&dasd_devmap_lock);
630 return device;
634 * SECTION: files in sysfs
638 * readonly controls the readonly status of a dasd
640 static ssize_t
641 dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
643 struct dasd_devmap *devmap;
644 int ro_flag;
646 devmap = dasd_find_busid(dev->bus_id);
647 if (!IS_ERR(devmap))
648 ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
649 else
650 ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
651 return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
654 static ssize_t
655 dasd_ro_store(struct device *dev, struct device_attribute *attr,
656 const char *buf, size_t count)
658 struct dasd_devmap *devmap;
659 int ro_flag;
661 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
662 if (IS_ERR(devmap))
663 return PTR_ERR(devmap);
664 ro_flag = buf[0] == '1';
665 spin_lock(&dasd_devmap_lock);
666 if (ro_flag)
667 devmap->features |= DASD_FEATURE_READONLY;
668 else
669 devmap->features &= ~DASD_FEATURE_READONLY;
670 if (devmap->device)
671 devmap->device->features = devmap->features;
672 if (devmap->device && devmap->device->gdp)
673 set_disk_ro(devmap->device->gdp, ro_flag);
674 spin_unlock(&dasd_devmap_lock);
675 return count;
678 static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
681 * use_diag controls whether the driver should use diag rather than ssch
682 * to talk to the device
684 static ssize_t
685 dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
687 struct dasd_devmap *devmap;
688 int use_diag;
690 devmap = dasd_find_busid(dev->bus_id);
691 if (!IS_ERR(devmap))
692 use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
693 else
694 use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
695 return sprintf(buf, use_diag ? "1\n" : "0\n");
698 static ssize_t
699 dasd_use_diag_store(struct device *dev, struct device_attribute *attr,
700 const char *buf, size_t count)
702 struct dasd_devmap *devmap;
703 ssize_t rc;
704 int use_diag;
706 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
707 if (IS_ERR(devmap))
708 return PTR_ERR(devmap);
709 use_diag = buf[0] == '1';
710 spin_lock(&dasd_devmap_lock);
711 /* Changing diag discipline flag is only allowed in offline state. */
712 rc = count;
713 if (!devmap->device) {
714 if (use_diag)
715 devmap->features |= DASD_FEATURE_USEDIAG;
716 else
717 devmap->features &= ~DASD_FEATURE_USEDIAG;
718 } else
719 rc = -EPERM;
720 spin_unlock(&dasd_devmap_lock);
721 return rc;
724 static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
726 static ssize_t
727 dasd_discipline_show(struct device *dev, struct device_attribute *attr,
728 char *buf)
730 struct dasd_devmap *devmap;
731 char *dname;
733 spin_lock(&dasd_devmap_lock);
734 dname = "none";
735 devmap = dev->driver_data;
736 if (devmap && devmap->device && devmap->device->discipline)
737 dname = devmap->device->discipline->name;
738 spin_unlock(&dasd_devmap_lock);
739 return snprintf(buf, PAGE_SIZE, "%s\n", dname);
742 static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
744 static ssize_t
745 dasd_alias_show(struct device *dev, struct device_attribute *attr, char *buf)
747 struct dasd_devmap *devmap;
748 int alias;
750 devmap = dasd_find_busid(dev->bus_id);
751 spin_lock(&dasd_devmap_lock);
752 if (!IS_ERR(devmap))
753 alias = devmap->uid.alias;
754 else
755 alias = 0;
756 spin_unlock(&dasd_devmap_lock);
758 return sprintf(buf, alias ? "1\n" : "0\n");
761 static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
763 static ssize_t
764 dasd_vendor_show(struct device *dev, struct device_attribute *attr, char *buf)
766 struct dasd_devmap *devmap;
767 char *vendor;
769 devmap = dasd_find_busid(dev->bus_id);
770 spin_lock(&dasd_devmap_lock);
771 if (!IS_ERR(devmap) && strlen(devmap->uid.vendor) > 0)
772 vendor = devmap->uid.vendor;
773 else
774 vendor = "";
775 spin_unlock(&dasd_devmap_lock);
777 return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
780 static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
782 #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
783 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1)
785 static ssize_t
786 dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
788 struct dasd_devmap *devmap;
789 char uid[UID_STRLEN];
791 devmap = dasd_find_busid(dev->bus_id);
792 spin_lock(&dasd_devmap_lock);
793 if (!IS_ERR(devmap) && strlen(devmap->uid.vendor) > 0)
794 snprintf(uid, sizeof(uid), "%s.%s.%04x.%02x",
795 devmap->uid.vendor, devmap->uid.serial,
796 devmap->uid.ssid, devmap->uid.unit_addr);
797 else
798 uid[0] = 0;
799 spin_unlock(&dasd_devmap_lock);
801 return snprintf(buf, PAGE_SIZE, "%s\n", uid);
804 static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
807 * extended error-reporting
809 static ssize_t
810 dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
812 struct dasd_devmap *devmap;
813 int eer_flag;
815 devmap = dasd_find_busid(dev->bus_id);
816 if (!IS_ERR(devmap) && devmap->device)
817 eer_flag = dasd_eer_enabled(devmap->device);
818 else
819 eer_flag = 0;
820 return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
823 static ssize_t
824 dasd_eer_store(struct device *dev, struct device_attribute *attr,
825 const char *buf, size_t count)
827 struct dasd_devmap *devmap;
828 int rc;
830 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
831 if (IS_ERR(devmap))
832 return PTR_ERR(devmap);
833 if (!devmap->device)
834 return count;
835 if (buf[0] == '1') {
836 rc = dasd_eer_enable(devmap->device);
837 if (rc)
838 return rc;
839 } else
840 dasd_eer_disable(devmap->device);
841 return count;
844 static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
846 static struct attribute * dasd_attrs[] = {
847 &dev_attr_readonly.attr,
848 &dev_attr_discipline.attr,
849 &dev_attr_alias.attr,
850 &dev_attr_vendor.attr,
851 &dev_attr_uid.attr,
852 &dev_attr_use_diag.attr,
853 &dev_attr_eer_enabled.attr,
854 NULL,
857 static struct attribute_group dasd_attr_group = {
858 .attrs = dasd_attrs,
862 * Return copy of the device unique identifier.
865 dasd_get_uid(struct ccw_device *cdev, struct dasd_uid *uid)
867 struct dasd_devmap *devmap;
869 devmap = dasd_find_busid(cdev->dev.bus_id);
870 if (IS_ERR(devmap))
871 return PTR_ERR(devmap);
872 spin_lock(&dasd_devmap_lock);
873 *uid = devmap->uid;
874 spin_unlock(&dasd_devmap_lock);
875 return 0;
879 * Register the given device unique identifier into devmap struct.
880 * In addition check if the related storage server is already contained in the
881 * dasd_serverlist. If server is not contained, create new entry.
882 * Return 0 if server was already in serverlist,
883 * 1 if the server was added successful
884 * <0 in case of error.
887 dasd_set_uid(struct ccw_device *cdev, struct dasd_uid *uid)
889 struct dasd_devmap *devmap;
890 struct dasd_servermap *srv, *tmp;
892 devmap = dasd_find_busid(cdev->dev.bus_id);
893 if (IS_ERR(devmap))
894 return PTR_ERR(devmap);
896 /* generate entry for servermap */
897 srv = (struct dasd_servermap *)
898 kzalloc(sizeof(struct dasd_servermap), GFP_KERNEL);
899 if (!srv)
900 return -ENOMEM;
901 strncpy(srv->sid.vendor, uid->vendor, sizeof(srv->sid.vendor) - 1);
902 strncpy(srv->sid.serial, uid->serial, sizeof(srv->sid.serial) - 1);
904 /* server is already contained ? */
905 spin_lock(&dasd_devmap_lock);
906 devmap->uid = *uid;
907 list_for_each_entry(tmp, &dasd_serverlist, list) {
908 if (!memcmp(&srv->sid, &tmp->sid,
909 sizeof(struct dasd_servermap))) {
910 kfree(srv);
911 srv = NULL;
912 break;
916 /* add servermap to serverlist */
917 if (srv)
918 list_add(&srv->list, &dasd_serverlist);
919 spin_unlock(&dasd_devmap_lock);
921 return (srv ? 1 : 0);
923 EXPORT_SYMBOL_GPL(dasd_set_uid);
926 * Return value of the specified feature.
929 dasd_get_feature(struct ccw_device *cdev, int feature)
931 struct dasd_devmap *devmap;
933 devmap = dasd_find_busid(cdev->dev.bus_id);
934 if (IS_ERR(devmap))
935 return PTR_ERR(devmap);
937 return ((devmap->features & feature) != 0);
941 * Set / reset given feature.
942 * Flag indicates wether to set (!=0) or the reset (=0) the feature.
945 dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
947 struct dasd_devmap *devmap;
949 devmap = dasd_find_busid(cdev->dev.bus_id);
950 if (IS_ERR(devmap))
951 return PTR_ERR(devmap);
953 spin_lock(&dasd_devmap_lock);
954 if (flag)
955 devmap->features |= feature;
956 else
957 devmap->features &= ~feature;
958 if (devmap->device)
959 devmap->device->features = devmap->features;
960 spin_unlock(&dasd_devmap_lock);
961 return 0;
966 dasd_add_sysfs_files(struct ccw_device *cdev)
968 return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
971 void
972 dasd_remove_sysfs_files(struct ccw_device *cdev)
974 sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
979 dasd_devmap_init(void)
981 int i;
983 /* Initialize devmap structures. */
984 dasd_max_devindex = 0;
985 for (i = 0; i < 256; i++)
986 INIT_LIST_HEAD(&dasd_hashlists[i]);
988 /* Initialize servermap structure. */
989 INIT_LIST_HEAD(&dasd_serverlist);
990 return 0;
993 void
994 dasd_devmap_exit(void)
996 dasd_forget_ranges();