blob: c1c6f138115002d3f7fb0f5606e7ecec691c9be9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
9 *
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.
13 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 */
15
16#include <linux/config.h>
17#include <linux/ctype.h>
18#include <linux/init.h>
Rusty Russell8d3b33f2006-03-25 03:07:05 -080019#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include <asm/debug.h>
22#include <asm/uaccess.h>
23
24/* This is ugly... */
25#define PRINTK_HEADER "dasd_devmap:"
26
27#include "dasd_int.h"
28
29kmem_cache_t *dasd_page_cache;
30EXPORT_SYMBOL(dasd_page_cache);
31
32/*
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.
41 */
42struct 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};
49
50/*
51 * Parameter parsing functions for dasd= parameter. The syntax is:
52 * <devno> : (0x)?[0-9a-fA-F]+
53 * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+
54 * <feature> : ro
55 * <feature_list> : \(<feature>(:<feature>)*\)
56 * <devno-range> : <devno>(-<devno>)?<feature_list>?
57 * <busid-range> : <busid>(-<busid>)?<feature_list>?
58 * <devices> : <devno-range>|<busid-range>
59 * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod
60 *
61 * <dasd> : autodetect|probeonly|<devices>(,<devices>)*
62 */
63
64int dasd_probeonly = 0; /* is true, when probeonly mode is active */
65int dasd_autodetect = 0; /* is true, when autodetection is active */
66
67/*
68 * char *dasd[] is intended to hold the ranges supplied by the dasd= statement
69 * it is named 'dasd' to directly be filled by insmod with the comma separated
70 * strings when running as a module.
71 */
72static char *dasd[256];
Rusty Russell8d3b33f2006-03-25 03:07:05 -080073module_param_array(dasd, charp, NULL, 0);
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/*
76 * Single spinlock to protect devmap structures and lists.
77 */
78static DEFINE_SPINLOCK(dasd_devmap_lock);
79
80/*
81 * Hash lists for devmap structures.
82 */
83static struct list_head dasd_hashlists[256];
84int dasd_max_devindex;
85
86static struct dasd_devmap *dasd_add_busid(char *, int);
87
88static inline int
89dasd_hash_busid(char *bus_id)
90{
91 int hash, i;
92
93 hash = 0;
94 for (i = 0; (i < BUS_ID_SIZE) && *bus_id; i++, bus_id++)
95 hash += *bus_id;
96 return hash & 0xff;
97}
98
99#ifndef MODULE
100/*
101 * The parameter parsing functions for builtin-drivers are called
102 * before kmalloc works. Store the pointers to the parameters strings
103 * into dasd[] for later processing.
104 */
105static int __init
106dasd_call_setup(char *str)
107{
108 static int count = 0;
109
110 if (count < 256)
111 dasd[count++] = str;
112 return 1;
113}
114
115__setup ("dasd=", dasd_call_setup);
116#endif /* #ifndef MODULE */
117
118/*
119 * Read a device busid/devno from a string.
120 */
121static inline int
122dasd_busid(char **str, int *id0, int *id1, int *devno)
123{
124 int val, old_style;
125
126 /* check for leading '0x' */
127 old_style = 0;
128 if ((*str)[0] == '0' && (*str)[1] == 'x') {
129 *str += 2;
130 old_style = 1;
131 }
132 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
133 return -EINVAL;
134 val = simple_strtoul(*str, str, 16);
135 if (old_style || (*str)[0] != '.') {
136 *id0 = *id1 = 0;
137 if (val < 0 || val > 0xffff)
138 return -EINVAL;
139 *devno = val;
140 return 0;
141 }
142 /* New style x.y.z busid */
143 if (val < 0 || val > 0xff)
144 return -EINVAL;
145 *id0 = val;
146 (*str)++;
147 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
148 return -EINVAL;
149 val = simple_strtoul(*str, str, 16);
150 if (val < 0 || val > 0xff || (*str)++[0] != '.')
151 return -EINVAL;
152 *id1 = val;
153 if (!isxdigit((*str)[0])) /* We require at least one hex digit */
154 return -EINVAL;
155 val = simple_strtoul(*str, str, 16);
156 if (val < 0 || val > 0xffff)
157 return -EINVAL;
158 *devno = val;
159 return 0;
160}
161
162/*
163 * Read colon separated list of dasd features. Currently there is
164 * only one: "ro" for read-only devices. The default feature set
165 * is empty (value 0).
166 */
167static inline int
168dasd_feature_list(char *str, char **endp)
169{
170 int features, len, rc;
171
172 rc = 0;
173 if (*str != '(') {
174 *endp = str;
175 return DASD_FEATURE_DEFAULT;
176 }
177 str++;
178 features = 0;
179
180 while (1) {
181 for (len = 0;
182 str[len] && str[len] != ':' && str[len] != ')'; len++);
183 if (len == 2 && !strncmp(str, "ro", 2))
184 features |= DASD_FEATURE_READONLY;
185 else if (len == 4 && !strncmp(str, "diag", 4))
186 features |= DASD_FEATURE_USEDIAG;
187 else {
188 MESSAGE(KERN_WARNING,
189 "unsupported feature: %*s, "
190 "ignoring setting", len, str);
191 rc = -EINVAL;
192 }
193 str += len;
194 if (*str != ':')
195 break;
196 str++;
197 }
198 if (*str != ')') {
199 MESSAGE(KERN_WARNING, "%s",
200 "missing ')' in dasd parameter string\n");
201 rc = -EINVAL;
202 } else
203 str++;
204 *endp = str;
205 if (rc != 0)
206 return rc;
207 return features;
208}
209
210/*
211 * Try to match the first element on the comma separated parse string
212 * with one of the known keywords. If a keyword is found, take the approprate
213 * action and return a pointer to the residual string. If the first element
214 * could not be matched to any keyword then return an error code.
215 */
216static char *
217dasd_parse_keyword( char *parsestring ) {
218
219 char *nextcomma, *residual_str;
220 int length;
221
222 nextcomma = strchr(parsestring,',');
223 if (nextcomma) {
224 length = nextcomma - parsestring;
225 residual_str = nextcomma + 1;
226 } else {
227 length = strlen(parsestring);
228 residual_str = parsestring + length;
229 }
230 if (strncmp ("autodetect", parsestring, length) == 0) {
231 dasd_autodetect = 1;
232 MESSAGE (KERN_INFO, "%s",
233 "turning to autodetection mode");
234 return residual_str;
235 }
236 if (strncmp ("probeonly", parsestring, length) == 0) {
237 dasd_probeonly = 1;
238 MESSAGE(KERN_INFO, "%s",
239 "turning to probeonly mode");
240 return residual_str;
241 }
242 if (strncmp ("fixedbuffers", parsestring, length) == 0) {
243 if (dasd_page_cache)
244 return residual_str;
245 dasd_page_cache =
246 kmem_cache_create("dasd_page_cache", PAGE_SIZE, 0,
247 SLAB_CACHE_DMA, NULL, NULL );
248 if (!dasd_page_cache)
249 MESSAGE(KERN_WARNING, "%s", "Failed to create slab, "
250 "fixed buffer mode disabled.");
251 else
252 MESSAGE (KERN_INFO, "%s",
253 "turning on fixed buffer mode");
254 return residual_str;
255 }
256 return ERR_PTR(-EINVAL);
257}
258
259/*
260 * Try to interprete the first element on the comma separated parse string
261 * as a device number or a range of devices. If the interpretation is
262 * successfull, create the matching dasd_devmap entries and return a pointer
263 * to the residual string.
264 * If interpretation fails or in case of an error, return an error code.
265 */
266static char *
267dasd_parse_range( char *parsestring ) {
268
269 struct dasd_devmap *devmap;
270 int from, from_id0, from_id1;
271 int to, to_id0, to_id1;
272 int features, rc;
273 char bus_id[BUS_ID_SIZE+1], *str;
274
275 str = parsestring;
276 rc = dasd_busid(&str, &from_id0, &from_id1, &from);
277 if (rc == 0) {
278 to = from;
279 to_id0 = from_id0;
280 to_id1 = from_id1;
281 if (*str == '-') {
282 str++;
283 rc = dasd_busid(&str, &to_id0, &to_id1, &to);
284 }
285 }
286 if (rc == 0 &&
287 (from_id0 != to_id0 || from_id1 != to_id1 || from > to))
288 rc = -EINVAL;
289 if (rc) {
290 MESSAGE(KERN_ERR, "Invalid device range %s", parsestring);
291 return ERR_PTR(rc);
292 }
293 features = dasd_feature_list(str, &str);
294 if (features < 0)
295 return ERR_PTR(-EINVAL);
296 while (from <= to) {
297 sprintf(bus_id, "%01x.%01x.%04x",
298 from_id0, from_id1, from++);
299 devmap = dasd_add_busid(bus_id, features);
300 if (IS_ERR(devmap))
301 return (char *)devmap;
302 }
303 if (*str == ',')
304 return str + 1;
305 if (*str == '\0')
306 return str;
307 MESSAGE(KERN_WARNING,
308 "junk at end of dasd parameter string: %s\n", str);
309 return ERR_PTR(-EINVAL);
310}
311
312static inline char *
313dasd_parse_next_element( char *parsestring ) {
314 char * residual_str;
315 residual_str = dasd_parse_keyword(parsestring);
316 if (!IS_ERR(residual_str))
317 return residual_str;
318 residual_str = dasd_parse_range(parsestring);
319 return residual_str;
320}
321
322/*
323 * Parse parameters stored in dasd[]
324 * The 'dasd=...' parameter allows to specify a comma separated list of
325 * keywords and device ranges. When the dasd driver is build into the kernel,
326 * the complete list will be stored as one element of the dasd[] array.
327 * When the dasd driver is build as a module, then the list is broken into
328 * it's elements and each dasd[] entry contains one element.
329 */
330int
331dasd_parse(void)
332{
333 int rc, i;
334 char *parsestring;
335
336 rc = 0;
337 for (i = 0; i < 256; i++) {
338 if (dasd[i] == NULL)
339 break;
340 parsestring = dasd[i];
341 /* loop over the comma separated list in the parsestring */
342 while (*parsestring) {
343 parsestring = dasd_parse_next_element(parsestring);
344 if(IS_ERR(parsestring)) {
345 rc = PTR_ERR(parsestring);
346 break;
347 }
348 }
349 if (rc) {
350 DBF_EVENT(DBF_ALERT, "%s", "invalid range found");
351 break;
352 }
353 }
354 return rc;
355}
356
357/*
358 * Add a devmap for the device specified by busid. It is possible that
359 * the devmap already exists (dasd= parameter). The order of the devices
360 * added through this function will define the kdevs for the individual
361 * devices.
362 */
363static struct dasd_devmap *
364dasd_add_busid(char *bus_id, int features)
365{
366 struct dasd_devmap *devmap, *new, *tmp;
367 int hash;
368
369 new = (struct dasd_devmap *)
370 kmalloc(sizeof(struct dasd_devmap), GFP_KERNEL);
371 if (!new)
372 return ERR_PTR(-ENOMEM);
373 spin_lock(&dasd_devmap_lock);
374 devmap = 0;
375 hash = dasd_hash_busid(bus_id);
376 list_for_each_entry(tmp, &dasd_hashlists[hash], list)
377 if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
378 devmap = tmp;
379 break;
380 }
381 if (!devmap) {
382 /* This bus_id is new. */
383 new->devindex = dasd_max_devindex++;
384 strncpy(new->bus_id, bus_id, BUS_ID_SIZE);
385 new->features = features;
386 new->device = 0;
387 list_add(&new->list, &dasd_hashlists[hash]);
388 devmap = new;
389 new = 0;
390 }
391 spin_unlock(&dasd_devmap_lock);
Jesper Juhl17fd6822005-11-07 01:01:30 -0800392 kfree(new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 return devmap;
394}
395
396/*
397 * Find devmap for device with given bus_id.
398 */
399static struct dasd_devmap *
400dasd_find_busid(char *bus_id)
401{
402 struct dasd_devmap *devmap, *tmp;
403 int hash;
404
405 spin_lock(&dasd_devmap_lock);
406 devmap = ERR_PTR(-ENODEV);
407 hash = dasd_hash_busid(bus_id);
408 list_for_each_entry(tmp, &dasd_hashlists[hash], list) {
409 if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) {
410 devmap = tmp;
411 break;
412 }
413 }
414 spin_unlock(&dasd_devmap_lock);
415 return devmap;
416}
417
418/*
419 * Check if busid has been added to the list of dasd ranges.
420 */
421int
422dasd_busid_known(char *bus_id)
423{
424 return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0;
425}
426
427/*
428 * Forget all about the device numbers added so far.
429 * This may only be called at module unload or system shutdown.
430 */
431static void
432dasd_forget_ranges(void)
433{
434 struct dasd_devmap *devmap, *n;
435 int i;
436
437 spin_lock(&dasd_devmap_lock);
438 for (i = 0; i < 256; i++) {
439 list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) {
Eric Sesterhenn606f4422006-03-26 18:33:07 +0200440 BUG_ON(devmap->device != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 list_del(&devmap->list);
442 kfree(devmap);
443 }
444 }
445 spin_unlock(&dasd_devmap_lock);
446}
447
448/*
449 * Find the device struct by its device index.
450 */
451struct dasd_device *
452dasd_device_from_devindex(int devindex)
453{
454 struct dasd_devmap *devmap, *tmp;
455 struct dasd_device *device;
456 int i;
457
458 spin_lock(&dasd_devmap_lock);
459 devmap = 0;
460 for (i = 0; (i < 256) && !devmap; i++)
461 list_for_each_entry(tmp, &dasd_hashlists[i], list)
462 if (tmp->devindex == devindex) {
463 /* Found the devmap for the device. */
464 devmap = tmp;
465 break;
466 }
467 if (devmap && devmap->device) {
468 device = devmap->device;
469 dasd_get_device(device);
470 } else
471 device = ERR_PTR(-ENODEV);
472 spin_unlock(&dasd_devmap_lock);
473 return device;
474}
475
476/*
477 * Return devmap for cdev. If no devmap exists yet, create one and
478 * connect it to the cdev.
479 */
480static struct dasd_devmap *
481dasd_devmap_from_cdev(struct ccw_device *cdev)
482{
483 struct dasd_devmap *devmap;
484
485 devmap = dasd_find_busid(cdev->dev.bus_id);
486 if (IS_ERR(devmap))
487 devmap = dasd_add_busid(cdev->dev.bus_id,
488 DASD_FEATURE_DEFAULT);
489 return devmap;
490}
491
492/*
493 * Create a dasd device structure for cdev.
494 */
495struct dasd_device *
496dasd_create_device(struct ccw_device *cdev)
497{
498 struct dasd_devmap *devmap;
499 struct dasd_device *device;
500 int rc;
501
502 devmap = dasd_devmap_from_cdev(cdev);
503 if (IS_ERR(devmap))
504 return (void *) devmap;
505 cdev->dev.driver_data = devmap;
506
507 device = dasd_alloc_device();
508 if (IS_ERR(device))
509 return device;
510 atomic_set(&device->ref_count, 2);
511
512 spin_lock(&dasd_devmap_lock);
513 if (!devmap->device) {
514 devmap->device = device;
515 device->devindex = devmap->devindex;
Horst Hummelc6eb7b72005-09-03 15:57:58 -0700516 device->features = devmap->features;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 get_device(&cdev->dev);
518 device->cdev = cdev;
519 rc = 0;
520 } else
521 /* Someone else was faster. */
522 rc = -EBUSY;
523 spin_unlock(&dasd_devmap_lock);
524
525 if (rc) {
526 dasd_free_device(device);
527 return ERR_PTR(rc);
528 }
529 return device;
530}
531
532/*
533 * Wait queue for dasd_delete_device waits.
534 */
535static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq);
536
537/*
538 * Remove a dasd device structure. The passed referenced
539 * is destroyed.
540 */
541void
542dasd_delete_device(struct dasd_device *device)
543{
544 struct ccw_device *cdev;
545 struct dasd_devmap *devmap;
546
547 /* First remove device pointer from devmap. */
548 devmap = dasd_find_busid(device->cdev->dev.bus_id);
Eric Sesterhenn606f4422006-03-26 18:33:07 +0200549 BUG_ON(IS_ERR(devmap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 spin_lock(&dasd_devmap_lock);
551 if (devmap->device != device) {
552 spin_unlock(&dasd_devmap_lock);
553 dasd_put_device(device);
554 return;
555 }
556 devmap->device = NULL;
557 spin_unlock(&dasd_devmap_lock);
558
559 /* Drop ref_count by 2, one for the devmap reference and
560 * one for the passed reference. */
561 atomic_sub(2, &device->ref_count);
562
563 /* Wait for reference counter to drop to zero. */
564 wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0);
565
566 /* Disconnect dasd_device structure from ccw_device structure. */
567 cdev = device->cdev;
568 device->cdev = NULL;
569
570 /* Disconnect dasd_devmap structure from ccw_device structure. */
571 cdev->dev.driver_data = NULL;
572
573 /* Put ccw_device structure. */
574 put_device(&cdev->dev);
575
576 /* Now the device structure can be freed. */
577 dasd_free_device(device);
578}
579
580/*
581 * Reference counter dropped to zero. Wake up waiter
582 * in dasd_delete_device.
583 */
584void
585dasd_put_device_wake(struct dasd_device *device)
586{
587 wake_up(&dasd_delete_wq);
588}
589
590/*
591 * Return dasd_device structure associated with cdev.
592 */
593struct dasd_device *
594dasd_device_from_cdev(struct ccw_device *cdev)
595{
596 struct dasd_devmap *devmap;
597 struct dasd_device *device;
598
599 device = ERR_PTR(-ENODEV);
600 spin_lock(&dasd_devmap_lock);
601 devmap = cdev->dev.driver_data;
602 if (devmap && devmap->device) {
603 device = devmap->device;
604 dasd_get_device(device);
605 }
606 spin_unlock(&dasd_devmap_lock);
607 return device;
608}
609
610/*
611 * SECTION: files in sysfs
612 */
613
614/*
615 * readonly controls the readonly status of a dasd
616 */
617static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400618dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
620 struct dasd_devmap *devmap;
621 int ro_flag;
622
623 devmap = dasd_find_busid(dev->bus_id);
624 if (!IS_ERR(devmap))
625 ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0;
626 else
627 ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0;
628 return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
629}
630
631static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400632dasd_ro_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
634 struct dasd_devmap *devmap;
635 int ro_flag;
636
637 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
638 if (IS_ERR(devmap))
639 return PTR_ERR(devmap);
640 ro_flag = buf[0] == '1';
641 spin_lock(&dasd_devmap_lock);
642 if (ro_flag)
643 devmap->features |= DASD_FEATURE_READONLY;
644 else
645 devmap->features &= ~DASD_FEATURE_READONLY;
Horst Hummelc6eb7b72005-09-03 15:57:58 -0700646 if (devmap->device)
647 devmap->device->features = devmap->features;
Horst Hummelf24acd42005-05-01 08:58:59 -0700648 if (devmap->device && devmap->device->gdp)
649 set_disk_ro(devmap->device->gdp, ro_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 spin_unlock(&dasd_devmap_lock);
651 return count;
652}
653
654static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
655
656/*
657 * use_diag controls whether the driver should use diag rather than ssch
658 * to talk to the device
659 */
660static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400661dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662{
663 struct dasd_devmap *devmap;
664 int use_diag;
665
666 devmap = dasd_find_busid(dev->bus_id);
667 if (!IS_ERR(devmap))
668 use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0;
669 else
670 use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0;
671 return sprintf(buf, use_diag ? "1\n" : "0\n");
672}
673
674static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400675dasd_use_diag_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
677 struct dasd_devmap *devmap;
678 ssize_t rc;
679 int use_diag;
680
681 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
682 if (IS_ERR(devmap))
683 return PTR_ERR(devmap);
684 use_diag = buf[0] == '1';
685 spin_lock(&dasd_devmap_lock);
686 /* Changing diag discipline flag is only allowed in offline state. */
687 rc = count;
688 if (!devmap->device) {
689 if (use_diag)
690 devmap->features |= DASD_FEATURE_USEDIAG;
691 else
692 devmap->features &= ~DASD_FEATURE_USEDIAG;
693 } else
694 rc = -EPERM;
695 spin_unlock(&dasd_devmap_lock);
696 return rc;
697}
698
699static
700DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store);
701
702static ssize_t
Yani Ioannoue404e272005-05-17 06:42:58 -0400703dasd_discipline_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704{
705 struct dasd_devmap *devmap;
706 char *dname;
707
708 spin_lock(&dasd_devmap_lock);
709 dname = "none";
710 devmap = dev->driver_data;
711 if (devmap && devmap->device && devmap->device->discipline)
712 dname = devmap->device->discipline->name;
713 spin_unlock(&dasd_devmap_lock);
714 return snprintf(buf, PAGE_SIZE, "%s\n", dname);
715}
716
717static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
718
Stefan Weinhuber20c64462006-03-24 03:15:25 -0800719/*
720 * extended error-reporting
721 */
722static ssize_t
723dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
724{
725 struct dasd_devmap *devmap;
726 int eer_flag;
727
728 devmap = dasd_find_busid(dev->bus_id);
729 if (!IS_ERR(devmap) && devmap->device)
730 eer_flag = dasd_eer_enabled(devmap->device);
731 else
732 eer_flag = 0;
733 return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
734}
735
736static ssize_t
737dasd_eer_store(struct device *dev, struct device_attribute *attr,
738 const char *buf, size_t count)
739{
740 struct dasd_devmap *devmap;
741 int rc;
742
743 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
744 if (IS_ERR(devmap))
745 return PTR_ERR(devmap);
746 if (!devmap->device)
747 return count;
748 if (buf[0] == '1') {
749 rc = dasd_eer_enable(devmap->device);
750 if (rc)
751 return rc;
752 } else
753 dasd_eer_disable(devmap->device);
754 return count;
755}
756
757static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759static struct attribute * dasd_attrs[] = {
760 &dev_attr_readonly.attr,
761 &dev_attr_discipline.attr,
762 &dev_attr_use_diag.attr,
Stefan Weinhuber20c64462006-03-24 03:15:25 -0800763 &dev_attr_eer_enabled.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 NULL,
765};
766
767static struct attribute_group dasd_attr_group = {
768 .attrs = dasd_attrs,
769};
770
Horst Hummelf24acd42005-05-01 08:58:59 -0700771/*
772 * Return value of the specified feature.
773 */
774int
775dasd_get_feature(struct ccw_device *cdev, int feature)
776{
777 struct dasd_devmap *devmap;
778
779 devmap = dasd_find_busid(cdev->dev.bus_id);
780 if (IS_ERR(devmap))
781 return (int) PTR_ERR(devmap);
782
783 return ((devmap->features & feature) != 0);
784}
785
786/*
787 * Set / reset given feature.
788 * Flag indicates wether to set (!=0) or the reset (=0) the feature.
789 */
790int
791dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
792{
793 struct dasd_devmap *devmap;
794
795 devmap = dasd_find_busid(cdev->dev.bus_id);
796 if (IS_ERR(devmap))
797 return (int) PTR_ERR(devmap);
798
799 spin_lock(&dasd_devmap_lock);
800 if (flag)
801 devmap->features |= feature;
802 else
803 devmap->features &= ~feature;
Horst Hummelc6eb7b72005-09-03 15:57:58 -0700804 if (devmap->device)
805 devmap->device->features = devmap->features;
Horst Hummelf24acd42005-05-01 08:58:59 -0700806 spin_unlock(&dasd_devmap_lock);
807 return 0;
808}
809
810
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811int
812dasd_add_sysfs_files(struct ccw_device *cdev)
813{
814 return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group);
815}
816
817void
818dasd_remove_sysfs_files(struct ccw_device *cdev)
819{
820 sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group);
821}
822
823
824int
825dasd_devmap_init(void)
826{
827 int i;
828
829 /* Initialize devmap structures. */
830 dasd_max_devindex = 0;
831 for (i = 0; i < 256; i++)
832 INIT_LIST_HEAD(&dasd_hashlists[i]);
833 return 0;
834
835}
836
837void
838dasd_devmap_exit(void)
839{
840 dasd_forget_ranges();
841}