diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/s390/block/dasd_devmap.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/s390/block/dasd_devmap.c')
-rw-r--r-- | drivers/s390/block/dasd_devmap.c | 772 |
1 files changed, 772 insertions, 0 deletions
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c new file mode 100644 index 000000000000..ad1841a96c87 --- /dev/null +++ b/drivers/s390/block/dasd_devmap.c | |||
@@ -0,0 +1,772 @@ | |||
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 | ||
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 | * | ||
14 | * $Revision: 1.37 $ | ||
15 | */ | ||
16 | |||
17 | #include <linux/config.h> | ||
18 | #include <linux/ctype.h> | ||
19 | #include <linux/init.h> | ||
20 | |||
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 | |||
29 | kmem_cache_t *dasd_page_cache; | ||
30 | EXPORT_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 | */ | ||
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 | }; | ||
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 | |||
64 | int dasd_probeonly = 0; /* is true, when probeonly mode is active */ | ||
65 | int 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 | */ | ||
72 | static char *dasd[256]; | ||
73 | /* | ||
74 | * Single spinlock to protect devmap structures and lists. | ||
75 | */ | ||
76 | static DEFINE_SPINLOCK(dasd_devmap_lock); | ||
77 | |||
78 | /* | ||
79 | * Hash lists for devmap structures. | ||
80 | */ | ||
81 | static struct list_head dasd_hashlists[256]; | ||
82 | int dasd_max_devindex; | ||
83 | |||
84 | static struct dasd_devmap *dasd_add_busid(char *, int); | ||
85 | |||
86 | static inline int | ||
87 | dasd_hash_busid(char *bus_id) | ||
88 | { | ||
89 | int hash, i; | ||
90 | |||
91 | hash = 0; | ||
92 | for (i = 0; (i < BUS_ID_SIZE) && *bus_id; i++, bus_id++) | ||
93 | hash += *bus_id; | ||
94 | return hash & 0xff; | ||
95 | } | ||
96 | |||
97 | #ifndef MODULE | ||
98 | /* | ||
99 | * The parameter parsing functions for builtin-drivers are called | ||
100 | * before kmalloc works. Store the pointers to the parameters strings | ||
101 | * into dasd[] for later processing. | ||
102 | */ | ||
103 | static int __init | ||
104 | dasd_call_setup(char *str) | ||
105 | { | ||
106 | static int count = 0; | ||
107 | |||
108 | if (count < 256) | ||
109 | dasd[count++] = str; | ||
110 | return 1; | ||
111 | } | ||
112 | |||
113 | __setup ("dasd=", dasd_call_setup); | ||
114 | #endif /* #ifndef MODULE */ | ||
115 | |||
116 | /* | ||
117 | * Read a device busid/devno from a string. | ||
118 | */ | ||
119 | static inline int | ||
120 | dasd_busid(char **str, int *id0, int *id1, int *devno) | ||
121 | { | ||
122 | int val, old_style; | ||
123 | |||
124 | /* check for leading '0x' */ | ||
125 | old_style = 0; | ||
126 | if ((*str)[0] == '0' && (*str)[1] == 'x') { | ||
127 | *str += 2; | ||
128 | old_style = 1; | ||
129 | } | ||
130 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ | ||
131 | return -EINVAL; | ||
132 | val = simple_strtoul(*str, str, 16); | ||
133 | if (old_style || (*str)[0] != '.') { | ||
134 | *id0 = *id1 = 0; | ||
135 | if (val < 0 || val > 0xffff) | ||
136 | return -EINVAL; | ||
137 | *devno = val; | ||
138 | return 0; | ||
139 | } | ||
140 | /* New style x.y.z busid */ | ||
141 | if (val < 0 || val > 0xff) | ||
142 | return -EINVAL; | ||
143 | *id0 = val; | ||
144 | (*str)++; | ||
145 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ | ||
146 | return -EINVAL; | ||
147 | val = simple_strtoul(*str, str, 16); | ||
148 | if (val < 0 || val > 0xff || (*str)++[0] != '.') | ||
149 | return -EINVAL; | ||
150 | *id1 = val; | ||
151 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ | ||
152 | return -EINVAL; | ||
153 | val = simple_strtoul(*str, str, 16); | ||
154 | if (val < 0 || val > 0xffff) | ||
155 | return -EINVAL; | ||
156 | *devno = val; | ||
157 | return 0; | ||
158 | } | ||
159 | |||
160 | /* | ||
161 | * Read colon separated list of dasd features. Currently there is | ||
162 | * only one: "ro" for read-only devices. The default feature set | ||
163 | * is empty (value 0). | ||
164 | */ | ||
165 | static inline int | ||
166 | dasd_feature_list(char *str, char **endp) | ||
167 | { | ||
168 | int features, len, rc; | ||
169 | |||
170 | rc = 0; | ||
171 | if (*str != '(') { | ||
172 | *endp = str; | ||
173 | return DASD_FEATURE_DEFAULT; | ||
174 | } | ||
175 | str++; | ||
176 | features = 0; | ||
177 | |||
178 | while (1) { | ||
179 | for (len = 0; | ||
180 | str[len] && str[len] != ':' && str[len] != ')'; len++); | ||
181 | if (len == 2 && !strncmp(str, "ro", 2)) | ||
182 | features |= DASD_FEATURE_READONLY; | ||
183 | else if (len == 4 && !strncmp(str, "diag", 4)) | ||
184 | features |= DASD_FEATURE_USEDIAG; | ||
185 | else { | ||
186 | MESSAGE(KERN_WARNING, | ||
187 | "unsupported feature: %*s, " | ||
188 | "ignoring setting", len, str); | ||
189 | rc = -EINVAL; | ||
190 | } | ||
191 | str += len; | ||
192 | if (*str != ':') | ||
193 | break; | ||
194 | str++; | ||
195 | } | ||
196 | if (*str != ')') { | ||
197 | MESSAGE(KERN_WARNING, "%s", | ||
198 | "missing ')' in dasd parameter string\n"); | ||
199 | rc = -EINVAL; | ||
200 | } else | ||
201 | str++; | ||
202 | *endp = str; | ||
203 | if (rc != 0) | ||
204 | return rc; | ||
205 | return features; | ||
206 | } | ||
207 | |||
208 | /* | ||
209 | * Try to match the first element on the comma separated parse string | ||
210 | * with one of the known keywords. If a keyword is found, take the approprate | ||
211 | * action and return a pointer to the residual string. If the first element | ||
212 | * could not be matched to any keyword then return an error code. | ||
213 | */ | ||
214 | static char * | ||
215 | dasd_parse_keyword( char *parsestring ) { | ||
216 | |||
217 | char *nextcomma, *residual_str; | ||
218 | int length; | ||
219 | |||
220 | nextcomma = strchr(parsestring,','); | ||
221 | if (nextcomma) { | ||
222 | length = nextcomma - parsestring; | ||
223 | residual_str = nextcomma + 1; | ||
224 | } else { | ||
225 | length = strlen(parsestring); | ||
226 | residual_str = parsestring + length; | ||
227 | } | ||
228 | if (strncmp ("autodetect", parsestring, length) == 0) { | ||
229 | dasd_autodetect = 1; | ||
230 | MESSAGE (KERN_INFO, "%s", | ||
231 | "turning to autodetection mode"); | ||
232 | return residual_str; | ||
233 | } | ||
234 | if (strncmp ("probeonly", parsestring, length) == 0) { | ||
235 | dasd_probeonly = 1; | ||
236 | MESSAGE(KERN_INFO, "%s", | ||
237 | "turning to probeonly mode"); | ||
238 | return residual_str; | ||
239 | } | ||
240 | if (strncmp ("fixedbuffers", parsestring, length) == 0) { | ||
241 | if (dasd_page_cache) | ||
242 | return residual_str; | ||
243 | dasd_page_cache = | ||
244 | kmem_cache_create("dasd_page_cache", PAGE_SIZE, 0, | ||
245 | SLAB_CACHE_DMA, NULL, NULL ); | ||
246 | if (!dasd_page_cache) | ||
247 | MESSAGE(KERN_WARNING, "%s", "Failed to create slab, " | ||
248 | "fixed buffer mode disabled."); | ||
249 | else | ||
250 | MESSAGE (KERN_INFO, "%s", | ||
251 | "turning on fixed buffer mode"); | ||
252 | return residual_str; | ||
253 | } | ||
254 | return ERR_PTR(-EINVAL); | ||
255 | } | ||
256 | |||
257 | /* | ||
258 | * Try to interprete the first element on the comma separated parse string | ||
259 | * as a device number or a range of devices. If the interpretation is | ||
260 | * successfull, create the matching dasd_devmap entries and return a pointer | ||
261 | * to the residual string. | ||
262 | * If interpretation fails or in case of an error, return an error code. | ||
263 | */ | ||
264 | static char * | ||
265 | dasd_parse_range( char *parsestring ) { | ||
266 | |||
267 | struct dasd_devmap *devmap; | ||
268 | int from, from_id0, from_id1; | ||
269 | int to, to_id0, to_id1; | ||
270 | int features, rc; | ||
271 | char bus_id[BUS_ID_SIZE+1], *str; | ||
272 | |||
273 | str = parsestring; | ||
274 | rc = dasd_busid(&str, &from_id0, &from_id1, &from); | ||
275 | if (rc == 0) { | ||
276 | to = from; | ||
277 | to_id0 = from_id0; | ||
278 | to_id1 = from_id1; | ||
279 | if (*str == '-') { | ||
280 | str++; | ||
281 | rc = dasd_busid(&str, &to_id0, &to_id1, &to); | ||
282 | } | ||
283 | } | ||
284 | if (rc == 0 && | ||
285 | (from_id0 != to_id0 || from_id1 != to_id1 || from > to)) | ||
286 | rc = -EINVAL; | ||
287 | if (rc) { | ||
288 | MESSAGE(KERN_ERR, "Invalid device range %s", parsestring); | ||
289 | return ERR_PTR(rc); | ||
290 | } | ||
291 | features = dasd_feature_list(str, &str); | ||
292 | if (features < 0) | ||
293 | return ERR_PTR(-EINVAL); | ||
294 | while (from <= to) { | ||
295 | sprintf(bus_id, "%01x.%01x.%04x", | ||
296 | from_id0, from_id1, from++); | ||
297 | devmap = dasd_add_busid(bus_id, features); | ||
298 | if (IS_ERR(devmap)) | ||
299 | return (char *)devmap; | ||
300 | } | ||
301 | if (*str == ',') | ||
302 | return str + 1; | ||
303 | if (*str == '\0') | ||
304 | return str; | ||
305 | MESSAGE(KERN_WARNING, | ||
306 | "junk at end of dasd parameter string: %s\n", str); | ||
307 | return ERR_PTR(-EINVAL); | ||
308 | } | ||
309 | |||
310 | static inline char * | ||
311 | dasd_parse_next_element( char *parsestring ) { | ||
312 | char * residual_str; | ||
313 | residual_str = dasd_parse_keyword(parsestring); | ||
314 | if (!IS_ERR(residual_str)) | ||
315 | return residual_str; | ||
316 | residual_str = dasd_parse_range(parsestring); | ||
317 | return residual_str; | ||
318 | } | ||
319 | |||
320 | /* | ||
321 | * Parse parameters stored in dasd[] | ||
322 | * The 'dasd=...' parameter allows to specify a comma separated list of | ||
323 | * keywords and device ranges. When the dasd driver is build into the kernel, | ||
324 | * the complete list will be stored as one element of the dasd[] array. | ||
325 | * When the dasd driver is build as a module, then the list is broken into | ||
326 | * it's elements and each dasd[] entry contains one element. | ||
327 | */ | ||
328 | int | ||
329 | dasd_parse(void) | ||
330 | { | ||
331 | int rc, i; | ||
332 | char *parsestring; | ||
333 | |||
334 | rc = 0; | ||
335 | for (i = 0; i < 256; i++) { | ||
336 | if (dasd[i] == NULL) | ||
337 | break; | ||
338 | parsestring = dasd[i]; | ||
339 | /* loop over the comma separated list in the parsestring */ | ||
340 | while (*parsestring) { | ||
341 | parsestring = dasd_parse_next_element(parsestring); | ||
342 | if(IS_ERR(parsestring)) { | ||
343 | rc = PTR_ERR(parsestring); | ||
344 | break; | ||
345 | } | ||
346 | } | ||
347 | if (rc) { | ||
348 | DBF_EVENT(DBF_ALERT, "%s", "invalid range found"); | ||
349 | break; | ||
350 | } | ||
351 | } | ||
352 | return rc; | ||
353 | } | ||
354 | |||
355 | /* | ||
356 | * Add a devmap for the device specified by busid. It is possible that | ||
357 | * the devmap already exists (dasd= parameter). The order of the devices | ||
358 | * added through this function will define the kdevs for the individual | ||
359 | * devices. | ||
360 | */ | ||
361 | static struct dasd_devmap * | ||
362 | dasd_add_busid(char *bus_id, int features) | ||
363 | { | ||
364 | struct dasd_devmap *devmap, *new, *tmp; | ||
365 | int hash; | ||
366 | |||
367 | new = (struct dasd_devmap *) | ||
368 | kmalloc(sizeof(struct dasd_devmap), GFP_KERNEL); | ||
369 | if (!new) | ||
370 | return ERR_PTR(-ENOMEM); | ||
371 | spin_lock(&dasd_devmap_lock); | ||
372 | devmap = 0; | ||
373 | hash = dasd_hash_busid(bus_id); | ||
374 | list_for_each_entry(tmp, &dasd_hashlists[hash], list) | ||
375 | if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) { | ||
376 | devmap = tmp; | ||
377 | break; | ||
378 | } | ||
379 | if (!devmap) { | ||
380 | /* This bus_id is new. */ | ||
381 | new->devindex = dasd_max_devindex++; | ||
382 | strncpy(new->bus_id, bus_id, BUS_ID_SIZE); | ||
383 | new->features = features; | ||
384 | new->device = 0; | ||
385 | list_add(&new->list, &dasd_hashlists[hash]); | ||
386 | devmap = new; | ||
387 | new = 0; | ||
388 | } | ||
389 | spin_unlock(&dasd_devmap_lock); | ||
390 | if (new) | ||
391 | kfree(new); | ||
392 | return devmap; | ||
393 | } | ||
394 | |||
395 | /* | ||
396 | * Find devmap for device with given bus_id. | ||
397 | */ | ||
398 | static struct dasd_devmap * | ||
399 | dasd_find_busid(char *bus_id) | ||
400 | { | ||
401 | struct dasd_devmap *devmap, *tmp; | ||
402 | int hash; | ||
403 | |||
404 | spin_lock(&dasd_devmap_lock); | ||
405 | devmap = ERR_PTR(-ENODEV); | ||
406 | hash = dasd_hash_busid(bus_id); | ||
407 | list_for_each_entry(tmp, &dasd_hashlists[hash], list) { | ||
408 | if (strncmp(tmp->bus_id, bus_id, BUS_ID_SIZE) == 0) { | ||
409 | devmap = tmp; | ||
410 | break; | ||
411 | } | ||
412 | } | ||
413 | spin_unlock(&dasd_devmap_lock); | ||
414 | return devmap; | ||
415 | } | ||
416 | |||
417 | /* | ||
418 | * Check if busid has been added to the list of dasd ranges. | ||
419 | */ | ||
420 | int | ||
421 | dasd_busid_known(char *bus_id) | ||
422 | { | ||
423 | return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0; | ||
424 | } | ||
425 | |||
426 | /* | ||
427 | * Forget all about the device numbers added so far. | ||
428 | * This may only be called at module unload or system shutdown. | ||
429 | */ | ||
430 | static void | ||
431 | dasd_forget_ranges(void) | ||
432 | { | ||
433 | struct dasd_devmap *devmap, *n; | ||
434 | int i; | ||
435 | |||
436 | spin_lock(&dasd_devmap_lock); | ||
437 | for (i = 0; i < 256; i++) { | ||
438 | list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) { | ||
439 | if (devmap->device != NULL) | ||
440 | BUG(); | ||
441 | 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 | */ | ||
451 | struct dasd_device * | ||
452 | dasd_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 | */ | ||
480 | static struct dasd_devmap * | ||
481 | dasd_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 | */ | ||
495 | struct dasd_device * | ||
496 | dasd_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; | ||
516 | if (devmap->features & DASD_FEATURE_READONLY) | ||
517 | set_bit(DASD_FLAG_RO, &device->flags); | ||
518 | else | ||
519 | clear_bit(DASD_FLAG_RO, &device->flags); | ||
520 | if (devmap->features & DASD_FEATURE_USEDIAG) | ||
521 | set_bit(DASD_FLAG_USE_DIAG, &device->flags); | ||
522 | else | ||
523 | clear_bit(DASD_FLAG_USE_DIAG, &device->flags); | ||
524 | get_device(&cdev->dev); | ||
525 | device->cdev = cdev; | ||
526 | rc = 0; | ||
527 | } else | ||
528 | /* Someone else was faster. */ | ||
529 | rc = -EBUSY; | ||
530 | spin_unlock(&dasd_devmap_lock); | ||
531 | |||
532 | if (rc) { | ||
533 | dasd_free_device(device); | ||
534 | return ERR_PTR(rc); | ||
535 | } | ||
536 | return device; | ||
537 | } | ||
538 | |||
539 | /* | ||
540 | * Wait queue for dasd_delete_device waits. | ||
541 | */ | ||
542 | static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq); | ||
543 | |||
544 | /* | ||
545 | * Remove a dasd device structure. The passed referenced | ||
546 | * is destroyed. | ||
547 | */ | ||
548 | void | ||
549 | dasd_delete_device(struct dasd_device *device) | ||
550 | { | ||
551 | struct ccw_device *cdev; | ||
552 | struct dasd_devmap *devmap; | ||
553 | |||
554 | /* First remove device pointer from devmap. */ | ||
555 | devmap = dasd_find_busid(device->cdev->dev.bus_id); | ||
556 | if (IS_ERR(devmap)) | ||
557 | BUG(); | ||
558 | spin_lock(&dasd_devmap_lock); | ||
559 | if (devmap->device != device) { | ||
560 | spin_unlock(&dasd_devmap_lock); | ||
561 | dasd_put_device(device); | ||
562 | return; | ||
563 | } | ||
564 | devmap->device = NULL; | ||
565 | spin_unlock(&dasd_devmap_lock); | ||
566 | |||
567 | /* Drop ref_count by 2, one for the devmap reference and | ||
568 | * one for the passed reference. */ | ||
569 | atomic_sub(2, &device->ref_count); | ||
570 | |||
571 | /* Wait for reference counter to drop to zero. */ | ||
572 | wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0); | ||
573 | |||
574 | /* Disconnect dasd_device structure from ccw_device structure. */ | ||
575 | cdev = device->cdev; | ||
576 | device->cdev = NULL; | ||
577 | |||
578 | /* Disconnect dasd_devmap structure from ccw_device structure. */ | ||
579 | cdev->dev.driver_data = NULL; | ||
580 | |||
581 | /* Put ccw_device structure. */ | ||
582 | put_device(&cdev->dev); | ||
583 | |||
584 | /* Now the device structure can be freed. */ | ||
585 | dasd_free_device(device); | ||
586 | } | ||
587 | |||
588 | /* | ||
589 | * Reference counter dropped to zero. Wake up waiter | ||
590 | * in dasd_delete_device. | ||
591 | */ | ||
592 | void | ||
593 | dasd_put_device_wake(struct dasd_device *device) | ||
594 | { | ||
595 | wake_up(&dasd_delete_wq); | ||
596 | } | ||
597 | |||
598 | /* | ||
599 | * Return dasd_device structure associated with cdev. | ||
600 | */ | ||
601 | struct dasd_device * | ||
602 | dasd_device_from_cdev(struct ccw_device *cdev) | ||
603 | { | ||
604 | struct dasd_devmap *devmap; | ||
605 | struct dasd_device *device; | ||
606 | |||
607 | device = ERR_PTR(-ENODEV); | ||
608 | spin_lock(&dasd_devmap_lock); | ||
609 | devmap = cdev->dev.driver_data; | ||
610 | if (devmap && devmap->device) { | ||
611 | device = devmap->device; | ||
612 | dasd_get_device(device); | ||
613 | } | ||
614 | spin_unlock(&dasd_devmap_lock); | ||
615 | return device; | ||
616 | } | ||
617 | |||
618 | /* | ||
619 | * SECTION: files in sysfs | ||
620 | */ | ||
621 | |||
622 | /* | ||
623 | * readonly controls the readonly status of a dasd | ||
624 | */ | ||
625 | static ssize_t | ||
626 | dasd_ro_show(struct device *dev, char *buf) | ||
627 | { | ||
628 | struct dasd_devmap *devmap; | ||
629 | int ro_flag; | ||
630 | |||
631 | devmap = dasd_find_busid(dev->bus_id); | ||
632 | if (!IS_ERR(devmap)) | ||
633 | ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0; | ||
634 | else | ||
635 | ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0; | ||
636 | return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n"); | ||
637 | } | ||
638 | |||
639 | static ssize_t | ||
640 | dasd_ro_store(struct device *dev, const char *buf, size_t count) | ||
641 | { | ||
642 | struct dasd_devmap *devmap; | ||
643 | int ro_flag; | ||
644 | |||
645 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | ||
646 | if (IS_ERR(devmap)) | ||
647 | return PTR_ERR(devmap); | ||
648 | ro_flag = buf[0] == '1'; | ||
649 | spin_lock(&dasd_devmap_lock); | ||
650 | if (ro_flag) | ||
651 | devmap->features |= DASD_FEATURE_READONLY; | ||
652 | else | ||
653 | devmap->features &= ~DASD_FEATURE_READONLY; | ||
654 | if (devmap->device) { | ||
655 | if (devmap->device->gdp) | ||
656 | set_disk_ro(devmap->device->gdp, ro_flag); | ||
657 | if (ro_flag) | ||
658 | set_bit(DASD_FLAG_RO, &devmap->device->flags); | ||
659 | else | ||
660 | clear_bit(DASD_FLAG_RO, &devmap->device->flags); | ||
661 | } | ||
662 | spin_unlock(&dasd_devmap_lock); | ||
663 | return count; | ||
664 | } | ||
665 | |||
666 | static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store); | ||
667 | |||
668 | /* | ||
669 | * use_diag controls whether the driver should use diag rather than ssch | ||
670 | * to talk to the device | ||
671 | */ | ||
672 | static ssize_t | ||
673 | dasd_use_diag_show(struct device *dev, char *buf) | ||
674 | { | ||
675 | struct dasd_devmap *devmap; | ||
676 | int use_diag; | ||
677 | |||
678 | devmap = dasd_find_busid(dev->bus_id); | ||
679 | if (!IS_ERR(devmap)) | ||
680 | use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0; | ||
681 | else | ||
682 | use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0; | ||
683 | return sprintf(buf, use_diag ? "1\n" : "0\n"); | ||
684 | } | ||
685 | |||
686 | static ssize_t | ||
687 | dasd_use_diag_store(struct device *dev, const char *buf, size_t count) | ||
688 | { | ||
689 | struct dasd_devmap *devmap; | ||
690 | ssize_t rc; | ||
691 | int use_diag; | ||
692 | |||
693 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | ||
694 | if (IS_ERR(devmap)) | ||
695 | return PTR_ERR(devmap); | ||
696 | use_diag = buf[0] == '1'; | ||
697 | spin_lock(&dasd_devmap_lock); | ||
698 | /* Changing diag discipline flag is only allowed in offline state. */ | ||
699 | rc = count; | ||
700 | if (!devmap->device) { | ||
701 | if (use_diag) | ||
702 | devmap->features |= DASD_FEATURE_USEDIAG; | ||
703 | else | ||
704 | devmap->features &= ~DASD_FEATURE_USEDIAG; | ||
705 | } else | ||
706 | rc = -EPERM; | ||
707 | spin_unlock(&dasd_devmap_lock); | ||
708 | return rc; | ||
709 | } | ||
710 | |||
711 | static | ||
712 | DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store); | ||
713 | |||
714 | static ssize_t | ||
715 | dasd_discipline_show(struct device *dev, char *buf) | ||
716 | { | ||
717 | struct dasd_devmap *devmap; | ||
718 | char *dname; | ||
719 | |||
720 | spin_lock(&dasd_devmap_lock); | ||
721 | dname = "none"; | ||
722 | devmap = dev->driver_data; | ||
723 | if (devmap && devmap->device && devmap->device->discipline) | ||
724 | dname = devmap->device->discipline->name; | ||
725 | spin_unlock(&dasd_devmap_lock); | ||
726 | return snprintf(buf, PAGE_SIZE, "%s\n", dname); | ||
727 | } | ||
728 | |||
729 | static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL); | ||
730 | |||
731 | static struct attribute * dasd_attrs[] = { | ||
732 | &dev_attr_readonly.attr, | ||
733 | &dev_attr_discipline.attr, | ||
734 | &dev_attr_use_diag.attr, | ||
735 | NULL, | ||
736 | }; | ||
737 | |||
738 | static struct attribute_group dasd_attr_group = { | ||
739 | .attrs = dasd_attrs, | ||
740 | }; | ||
741 | |||
742 | int | ||
743 | dasd_add_sysfs_files(struct ccw_device *cdev) | ||
744 | { | ||
745 | return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group); | ||
746 | } | ||
747 | |||
748 | void | ||
749 | dasd_remove_sysfs_files(struct ccw_device *cdev) | ||
750 | { | ||
751 | sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group); | ||
752 | } | ||
753 | |||
754 | |||
755 | int | ||
756 | dasd_devmap_init(void) | ||
757 | { | ||
758 | int i; | ||
759 | |||
760 | /* Initialize devmap structures. */ | ||
761 | dasd_max_devindex = 0; | ||
762 | for (i = 0; i < 256; i++) | ||
763 | INIT_LIST_HEAD(&dasd_hashlists[i]); | ||
764 | return 0; | ||
765 | |||
766 | } | ||
767 | |||
768 | void | ||
769 | dasd_devmap_exit(void) | ||
770 | { | ||
771 | dasd_forget_ranges(); | ||
772 | } | ||