Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | * | |
1da177e4 LT |
14 | */ |
15 | ||
fc19f381 SH |
16 | #define KMSG_COMPONENT "dasd" |
17 | ||
1da177e4 LT |
18 | #include <linux/ctype.h> |
19 | #include <linux/init.h> | |
8d3b33f6 | 20 | #include <linux/module.h> |
5a0e3ad6 | 21 | #include <linux/slab.h> |
1da177e4 LT |
22 | |
23 | #include <asm/debug.h> | |
24 | #include <asm/uaccess.h> | |
7039d3a1 | 25 | #include <asm/ipl.h> |
1da177e4 LT |
26 | |
27 | /* This is ugly... */ | |
28 | #define PRINTK_HEADER "dasd_devmap:" | |
98df67b3 | 29 | #define DASD_BUS_ID_SIZE 20 |
1da177e4 LT |
30 | |
31 | #include "dasd_int.h" | |
32 | ||
e18b890b | 33 | struct kmem_cache *dasd_page_cache; |
40545573 | 34 | EXPORT_SYMBOL_GPL(dasd_page_cache); |
1da177e4 LT |
35 | |
36 | /* | |
37 | * dasd_devmap_t is used to store the features and the relation | |
38 | * between device number and device index. To find a dasd_devmap_t | |
39 | * that corresponds to a device number of a device index each | |
40 | * dasd_devmap_t is added to two linked lists, one to search by | |
41 | * the device number and one to search by the device index. As | |
42 | * soon as big minor numbers are available the device index list | |
43 | * can be removed since the device number will then be identical | |
44 | * to the device index. | |
45 | */ | |
46 | struct dasd_devmap { | |
47 | struct list_head list; | |
98df67b3 | 48 | char bus_id[DASD_BUS_ID_SIZE]; |
1da177e4 LT |
49 | unsigned int devindex; |
50 | unsigned short features; | |
51 | struct dasd_device *device; | |
3d052595 | 52 | struct dasd_uid uid; |
1da177e4 LT |
53 | }; |
54 | ||
55 | /* | |
56 | * Parameter parsing functions for dasd= parameter. The syntax is: | |
57 | * <devno> : (0x)?[0-9a-fA-F]+ | |
58 | * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+ | |
59 | * <feature> : ro | |
60 | * <feature_list> : \(<feature>(:<feature>)*\) | |
61 | * <devno-range> : <devno>(-<devno>)?<feature_list>? | |
62 | * <busid-range> : <busid>(-<busid>)?<feature_list>? | |
63 | * <devices> : <devno-range>|<busid-range> | |
64 | * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod | |
65 | * | |
66 | * <dasd> : autodetect|probeonly|<devices>(,<devices>)* | |
67 | */ | |
68 | ||
69 | int dasd_probeonly = 0; /* is true, when probeonly mode is active */ | |
70 | int dasd_autodetect = 0; /* is true, when autodetection is active */ | |
40545573 HH |
71 | int dasd_nopav = 0; /* is true, when PAV is disabled */ |
72 | EXPORT_SYMBOL_GPL(dasd_nopav); | |
f3eb5384 SW |
73 | int dasd_nofcx; /* disable High Performance Ficon */ |
74 | EXPORT_SYMBOL_GPL(dasd_nofcx); | |
1da177e4 LT |
75 | |
76 | /* | |
77 | * char *dasd[] is intended to hold the ranges supplied by the dasd= statement | |
78 | * it is named 'dasd' to directly be filled by insmod with the comma separated | |
79 | * strings when running as a module. | |
80 | */ | |
81 | static char *dasd[256]; | |
8d3b33f6 RR |
82 | module_param_array(dasd, charp, NULL, 0); |
83 | ||
1da177e4 | 84 | /* |
d0710c7c | 85 | * Single spinlock to protect devmap and servermap structures and lists. |
1da177e4 LT |
86 | */ |
87 | static DEFINE_SPINLOCK(dasd_devmap_lock); | |
88 | ||
89 | /* | |
90 | * Hash lists for devmap structures. | |
91 | */ | |
92 | static struct list_head dasd_hashlists[256]; | |
93 | int dasd_max_devindex; | |
94 | ||
69f90f6a | 95 | static struct dasd_devmap *dasd_add_busid(const char *, int); |
1da177e4 LT |
96 | |
97 | static inline int | |
69f90f6a | 98 | dasd_hash_busid(const char *bus_id) |
1da177e4 LT |
99 | { |
100 | int hash, i; | |
101 | ||
102 | hash = 0; | |
98df67b3 | 103 | for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++) |
1da177e4 LT |
104 | hash += *bus_id; |
105 | return hash & 0xff; | |
106 | } | |
107 | ||
108 | #ifndef MODULE | |
109 | /* | |
110 | * The parameter parsing functions for builtin-drivers are called | |
111 | * before kmalloc works. Store the pointers to the parameters strings | |
112 | * into dasd[] for later processing. | |
113 | */ | |
114 | static int __init | |
115 | dasd_call_setup(char *str) | |
116 | { | |
117 | static int count = 0; | |
118 | ||
119 | if (count < 256) | |
120 | dasd[count++] = str; | |
121 | return 1; | |
122 | } | |
123 | ||
124 | __setup ("dasd=", dasd_call_setup); | |
125 | #endif /* #ifndef MODULE */ | |
126 | ||
7039d3a1 PO |
127 | #define DASD_IPLDEV "ipldev" |
128 | ||
1da177e4 LT |
129 | /* |
130 | * Read a device busid/devno from a string. | |
131 | */ | |
4d284cac | 132 | static int |
fc19f381 | 133 | |
1da177e4 LT |
134 | dasd_busid(char **str, int *id0, int *id1, int *devno) |
135 | { | |
136 | int val, old_style; | |
138c014d | 137 | |
7039d3a1 PO |
138 | /* Interpret ipldev busid */ |
139 | if (strncmp(DASD_IPLDEV, *str, strlen(DASD_IPLDEV)) == 0) { | |
140 | if (ipl_info.type != IPL_TYPE_CCW) { | |
fc19f381 | 141 | pr_err("The IPL device is not a CCW device\n"); |
7039d3a1 PO |
142 | return -EINVAL; |
143 | } | |
144 | *id0 = 0; | |
145 | *id1 = ipl_info.data.ccw.dev_id.ssid; | |
146 | *devno = ipl_info.data.ccw.dev_id.devno; | |
147 | *str += strlen(DASD_IPLDEV); | |
148 | ||
149 | return 0; | |
150 | } | |
1da177e4 LT |
151 | /* check for leading '0x' */ |
152 | old_style = 0; | |
153 | if ((*str)[0] == '0' && (*str)[1] == 'x') { | |
154 | *str += 2; | |
155 | old_style = 1; | |
156 | } | |
157 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ | |
158 | return -EINVAL; | |
159 | val = simple_strtoul(*str, str, 16); | |
160 | if (old_style || (*str)[0] != '.') { | |
161 | *id0 = *id1 = 0; | |
162 | if (val < 0 || val > 0xffff) | |
163 | return -EINVAL; | |
164 | *devno = val; | |
165 | return 0; | |
166 | } | |
167 | /* New style x.y.z busid */ | |
168 | if (val < 0 || val > 0xff) | |
169 | return -EINVAL; | |
170 | *id0 = val; | |
171 | (*str)++; | |
172 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ | |
173 | return -EINVAL; | |
174 | val = simple_strtoul(*str, str, 16); | |
175 | if (val < 0 || val > 0xff || (*str)++[0] != '.') | |
176 | return -EINVAL; | |
177 | *id1 = val; | |
178 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ | |
179 | return -EINVAL; | |
180 | val = simple_strtoul(*str, str, 16); | |
181 | if (val < 0 || val > 0xffff) | |
182 | return -EINVAL; | |
183 | *devno = val; | |
184 | return 0; | |
185 | } | |
186 | ||
187 | /* | |
188 | * Read colon separated list of dasd features. Currently there is | |
189 | * only one: "ro" for read-only devices. The default feature set | |
190 | * is empty (value 0). | |
191 | */ | |
4d284cac | 192 | static int |
1da177e4 LT |
193 | dasd_feature_list(char *str, char **endp) |
194 | { | |
195 | int features, len, rc; | |
196 | ||
197 | rc = 0; | |
198 | if (*str != '(') { | |
199 | *endp = str; | |
200 | return DASD_FEATURE_DEFAULT; | |
201 | } | |
202 | str++; | |
203 | features = 0; | |
204 | ||
205 | while (1) { | |
138c014d | 206 | for (len = 0; |
1da177e4 LT |
207 | str[len] && str[len] != ':' && str[len] != ')'; len++); |
208 | if (len == 2 && !strncmp(str, "ro", 2)) | |
209 | features |= DASD_FEATURE_READONLY; | |
210 | else if (len == 4 && !strncmp(str, "diag", 4)) | |
211 | features |= DASD_FEATURE_USEDIAG; | |
9575bf26 HH |
212 | else if (len == 6 && !strncmp(str, "erplog", 6)) |
213 | features |= DASD_FEATURE_ERPLOG; | |
13de227b HS |
214 | else if (len == 8 && !strncmp(str, "failfast", 8)) |
215 | features |= DASD_FEATURE_FAILFAST; | |
1da177e4 | 216 | else { |
fc19f381 SH |
217 | pr_warning("%*s is not a supported device option\n", |
218 | len, str); | |
1da177e4 LT |
219 | rc = -EINVAL; |
220 | } | |
221 | str += len; | |
222 | if (*str != ':') | |
223 | break; | |
224 | str++; | |
225 | } | |
226 | if (*str != ')') { | |
fc19f381 SH |
227 | pr_warning("A closing parenthesis ')' is missing in the " |
228 | "dasd= parameter\n"); | |
1da177e4 LT |
229 | rc = -EINVAL; |
230 | } else | |
231 | str++; | |
232 | *endp = str; | |
233 | if (rc != 0) | |
234 | return rc; | |
235 | return features; | |
236 | } | |
237 | ||
238 | /* | |
239 | * Try to match the first element on the comma separated parse string | |
240 | * with one of the known keywords. If a keyword is found, take the approprate | |
241 | * action and return a pointer to the residual string. If the first element | |
242 | * could not be matched to any keyword then return an error code. | |
243 | */ | |
244 | static char * | |
245 | dasd_parse_keyword( char *parsestring ) { | |
246 | ||
247 | char *nextcomma, *residual_str; | |
248 | int length; | |
249 | ||
250 | nextcomma = strchr(parsestring,','); | |
251 | if (nextcomma) { | |
252 | length = nextcomma - parsestring; | |
253 | residual_str = nextcomma + 1; | |
254 | } else { | |
255 | length = strlen(parsestring); | |
256 | residual_str = parsestring + length; | |
257 | } | |
40545573 | 258 | if (strncmp("autodetect", parsestring, length) == 0) { |
1da177e4 | 259 | dasd_autodetect = 1; |
fc19f381 | 260 | pr_info("The autodetection mode has been activated\n"); |
1da177e4 LT |
261 | return residual_str; |
262 | } | |
40545573 | 263 | if (strncmp("probeonly", parsestring, length) == 0) { |
1da177e4 | 264 | dasd_probeonly = 1; |
fc19f381 | 265 | pr_info("The probeonly mode has been activated\n"); |
1da177e4 LT |
266 | return residual_str; |
267 | } | |
40545573 | 268 | if (strncmp("nopav", parsestring, length) == 0) { |
dcd707b4 | 269 | if (MACHINE_IS_VM) |
fc19f381 | 270 | pr_info("'nopav' is not supported on z/VM\n"); |
dcd707b4 PO |
271 | else { |
272 | dasd_nopav = 1; | |
fc19f381 | 273 | pr_info("PAV support has be deactivated\n"); |
dcd707b4 | 274 | } |
40545573 HH |
275 | return residual_str; |
276 | } | |
f3eb5384 SW |
277 | if (strncmp("nofcx", parsestring, length) == 0) { |
278 | dasd_nofcx = 1; | |
fc19f381 SH |
279 | pr_info("High Performance FICON support has been " |
280 | "deactivated\n"); | |
f3eb5384 SW |
281 | return residual_str; |
282 | } | |
40545573 | 283 | if (strncmp("fixedbuffers", parsestring, length) == 0) { |
1da177e4 LT |
284 | if (dasd_page_cache) |
285 | return residual_str; | |
286 | dasd_page_cache = | |
2f6c55fc HC |
287 | kmem_cache_create("dasd_page_cache", PAGE_SIZE, |
288 | PAGE_SIZE, SLAB_CACHE_DMA, | |
20c2df83 | 289 | NULL); |
1da177e4 | 290 | if (!dasd_page_cache) |
fc19f381 | 291 | DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, " |
1da177e4 LT |
292 | "fixed buffer mode disabled."); |
293 | else | |
fc19f381 | 294 | DBF_EVENT(DBF_INFO, "%s", |
1da177e4 LT |
295 | "turning on fixed buffer mode"); |
296 | return residual_str; | |
297 | } | |
298 | return ERR_PTR(-EINVAL); | |
299 | } | |
300 | ||
301 | /* | |
302 | * Try to interprete the first element on the comma separated parse string | |
303 | * as a device number or a range of devices. If the interpretation is | |
304 | * successfull, create the matching dasd_devmap entries and return a pointer | |
305 | * to the residual string. | |
306 | * If interpretation fails or in case of an error, return an error code. | |
307 | */ | |
308 | static char * | |
309 | dasd_parse_range( char *parsestring ) { | |
310 | ||
311 | struct dasd_devmap *devmap; | |
312 | int from, from_id0, from_id1; | |
313 | int to, to_id0, to_id1; | |
314 | int features, rc; | |
98df67b3 | 315 | char bus_id[DASD_BUS_ID_SIZE+1], *str; |
1da177e4 LT |
316 | |
317 | str = parsestring; | |
318 | rc = dasd_busid(&str, &from_id0, &from_id1, &from); | |
319 | if (rc == 0) { | |
320 | to = from; | |
321 | to_id0 = from_id0; | |
322 | to_id1 = from_id1; | |
323 | if (*str == '-') { | |
324 | str++; | |
325 | rc = dasd_busid(&str, &to_id0, &to_id1, &to); | |
326 | } | |
327 | } | |
328 | if (rc == 0 && | |
329 | (from_id0 != to_id0 || from_id1 != to_id1 || from > to)) | |
330 | rc = -EINVAL; | |
331 | if (rc) { | |
fc19f381 | 332 | pr_err("%s is not a valid device range\n", parsestring); |
1da177e4 LT |
333 | return ERR_PTR(rc); |
334 | } | |
335 | features = dasd_feature_list(str, &str); | |
336 | if (features < 0) | |
337 | return ERR_PTR(-EINVAL); | |
40545573 HH |
338 | /* each device in dasd= parameter should be set initially online */ |
339 | features |= DASD_FEATURE_INITIAL_ONLINE; | |
1da177e4 LT |
340 | while (from <= to) { |
341 | sprintf(bus_id, "%01x.%01x.%04x", | |
342 | from_id0, from_id1, from++); | |
343 | devmap = dasd_add_busid(bus_id, features); | |
344 | if (IS_ERR(devmap)) | |
345 | return (char *)devmap; | |
346 | } | |
347 | if (*str == ',') | |
348 | return str + 1; | |
349 | if (*str == '\0') | |
350 | return str; | |
fc19f381 SH |
351 | pr_warning("The dasd= parameter value %s has an invalid ending\n", |
352 | str); | |
1da177e4 LT |
353 | return ERR_PTR(-EINVAL); |
354 | } | |
355 | ||
4d284cac | 356 | static char * |
1da177e4 LT |
357 | dasd_parse_next_element( char *parsestring ) { |
358 | char * residual_str; | |
359 | residual_str = dasd_parse_keyword(parsestring); | |
360 | if (!IS_ERR(residual_str)) | |
361 | return residual_str; | |
362 | residual_str = dasd_parse_range(parsestring); | |
363 | return residual_str; | |
364 | } | |
365 | ||
366 | /* | |
367 | * Parse parameters stored in dasd[] | |
368 | * The 'dasd=...' parameter allows to specify a comma separated list of | |
369 | * keywords and device ranges. When the dasd driver is build into the kernel, | |
370 | * the complete list will be stored as one element of the dasd[] array. | |
371 | * When the dasd driver is build as a module, then the list is broken into | |
372 | * it's elements and each dasd[] entry contains one element. | |
373 | */ | |
374 | int | |
375 | dasd_parse(void) | |
376 | { | |
377 | int rc, i; | |
378 | char *parsestring; | |
379 | ||
380 | rc = 0; | |
381 | for (i = 0; i < 256; i++) { | |
382 | if (dasd[i] == NULL) | |
383 | break; | |
384 | parsestring = dasd[i]; | |
385 | /* loop over the comma separated list in the parsestring */ | |
386 | while (*parsestring) { | |
387 | parsestring = dasd_parse_next_element(parsestring); | |
388 | if(IS_ERR(parsestring)) { | |
389 | rc = PTR_ERR(parsestring); | |
390 | break; | |
391 | } | |
392 | } | |
393 | if (rc) { | |
394 | DBF_EVENT(DBF_ALERT, "%s", "invalid range found"); | |
395 | break; | |
396 | } | |
397 | } | |
398 | return rc; | |
399 | } | |
400 | ||
401 | /* | |
402 | * Add a devmap for the device specified by busid. It is possible that | |
403 | * the devmap already exists (dasd= parameter). The order of the devices | |
404 | * added through this function will define the kdevs for the individual | |
138c014d | 405 | * devices. |
1da177e4 LT |
406 | */ |
407 | static struct dasd_devmap * | |
69f90f6a | 408 | dasd_add_busid(const char *bus_id, int features) |
1da177e4 LT |
409 | { |
410 | struct dasd_devmap *devmap, *new, *tmp; | |
411 | int hash; | |
412 | ||
413 | new = (struct dasd_devmap *) | |
138c014d | 414 | kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL); |
1da177e4 LT |
415 | if (!new) |
416 | return ERR_PTR(-ENOMEM); | |
417 | spin_lock(&dasd_devmap_lock); | |
d2c993d8 | 418 | devmap = NULL; |
1da177e4 LT |
419 | hash = dasd_hash_busid(bus_id); |
420 | list_for_each_entry(tmp, &dasd_hashlists[hash], list) | |
98df67b3 | 421 | if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) { |
1da177e4 LT |
422 | devmap = tmp; |
423 | break; | |
424 | } | |
425 | if (!devmap) { | |
426 | /* This bus_id is new. */ | |
427 | new->devindex = dasd_max_devindex++; | |
98df67b3 | 428 | strncpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE); |
1da177e4 | 429 | new->features = features; |
d2c993d8 | 430 | new->device = NULL; |
1da177e4 LT |
431 | list_add(&new->list, &dasd_hashlists[hash]); |
432 | devmap = new; | |
d2c993d8 | 433 | new = NULL; |
1da177e4 LT |
434 | } |
435 | spin_unlock(&dasd_devmap_lock); | |
17fd682e | 436 | kfree(new); |
1da177e4 LT |
437 | return devmap; |
438 | } | |
439 | ||
440 | /* | |
441 | * Find devmap for device with given bus_id. | |
442 | */ | |
443 | static struct dasd_devmap * | |
69f90f6a | 444 | dasd_find_busid(const char *bus_id) |
1da177e4 LT |
445 | { |
446 | struct dasd_devmap *devmap, *tmp; | |
447 | int hash; | |
448 | ||
449 | spin_lock(&dasd_devmap_lock); | |
450 | devmap = ERR_PTR(-ENODEV); | |
451 | hash = dasd_hash_busid(bus_id); | |
452 | list_for_each_entry(tmp, &dasd_hashlists[hash], list) { | |
98df67b3 | 453 | if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) { |
1da177e4 LT |
454 | devmap = tmp; |
455 | break; | |
456 | } | |
457 | } | |
458 | spin_unlock(&dasd_devmap_lock); | |
459 | return devmap; | |
460 | } | |
461 | ||
462 | /* | |
463 | * Check if busid has been added to the list of dasd ranges. | |
464 | */ | |
465 | int | |
69f90f6a | 466 | dasd_busid_known(const char *bus_id) |
1da177e4 LT |
467 | { |
468 | return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0; | |
469 | } | |
470 | ||
471 | /* | |
472 | * Forget all about the device numbers added so far. | |
473 | * This may only be called at module unload or system shutdown. | |
474 | */ | |
475 | static void | |
476 | dasd_forget_ranges(void) | |
477 | { | |
478 | struct dasd_devmap *devmap, *n; | |
479 | int i; | |
480 | ||
481 | spin_lock(&dasd_devmap_lock); | |
482 | for (i = 0; i < 256; i++) { | |
483 | list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) { | |
606f4422 | 484 | BUG_ON(devmap->device != NULL); |
1da177e4 LT |
485 | list_del(&devmap->list); |
486 | kfree(devmap); | |
487 | } | |
488 | } | |
489 | spin_unlock(&dasd_devmap_lock); | |
490 | } | |
491 | ||
492 | /* | |
493 | * Find the device struct by its device index. | |
494 | */ | |
495 | struct dasd_device * | |
496 | dasd_device_from_devindex(int devindex) | |
497 | { | |
498 | struct dasd_devmap *devmap, *tmp; | |
499 | struct dasd_device *device; | |
500 | int i; | |
501 | ||
502 | spin_lock(&dasd_devmap_lock); | |
d2c993d8 | 503 | devmap = NULL; |
1da177e4 LT |
504 | for (i = 0; (i < 256) && !devmap; i++) |
505 | list_for_each_entry(tmp, &dasd_hashlists[i], list) | |
506 | if (tmp->devindex == devindex) { | |
507 | /* Found the devmap for the device. */ | |
508 | devmap = tmp; | |
509 | break; | |
510 | } | |
511 | if (devmap && devmap->device) { | |
512 | device = devmap->device; | |
513 | dasd_get_device(device); | |
514 | } else | |
515 | device = ERR_PTR(-ENODEV); | |
516 | spin_unlock(&dasd_devmap_lock); | |
517 | return device; | |
518 | } | |
519 | ||
520 | /* | |
521 | * Return devmap for cdev. If no devmap exists yet, create one and | |
522 | * connect it to the cdev. | |
523 | */ | |
524 | static struct dasd_devmap * | |
525 | dasd_devmap_from_cdev(struct ccw_device *cdev) | |
526 | { | |
527 | struct dasd_devmap *devmap; | |
528 | ||
2a0217d5 | 529 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
1da177e4 | 530 | if (IS_ERR(devmap)) |
2a0217d5 | 531 | devmap = dasd_add_busid(dev_name(&cdev->dev), |
1da177e4 LT |
532 | DASD_FEATURE_DEFAULT); |
533 | return devmap; | |
534 | } | |
535 | ||
536 | /* | |
537 | * Create a dasd device structure for cdev. | |
538 | */ | |
539 | struct dasd_device * | |
540 | dasd_create_device(struct ccw_device *cdev) | |
541 | { | |
542 | struct dasd_devmap *devmap; | |
543 | struct dasd_device *device; | |
a00bfd71 | 544 | unsigned long flags; |
1da177e4 LT |
545 | int rc; |
546 | ||
547 | devmap = dasd_devmap_from_cdev(cdev); | |
548 | if (IS_ERR(devmap)) | |
549 | return (void *) devmap; | |
1da177e4 LT |
550 | |
551 | device = dasd_alloc_device(); | |
552 | if (IS_ERR(device)) | |
553 | return device; | |
a00bfd71 | 554 | atomic_set(&device->ref_count, 3); |
1da177e4 LT |
555 | |
556 | spin_lock(&dasd_devmap_lock); | |
557 | if (!devmap->device) { | |
558 | devmap->device = device; | |
559 | device->devindex = devmap->devindex; | |
c6eb7b77 | 560 | device->features = devmap->features; |
1da177e4 LT |
561 | get_device(&cdev->dev); |
562 | device->cdev = cdev; | |
563 | rc = 0; | |
564 | } else | |
565 | /* Someone else was faster. */ | |
566 | rc = -EBUSY; | |
567 | spin_unlock(&dasd_devmap_lock); | |
568 | ||
569 | if (rc) { | |
570 | dasd_free_device(device); | |
571 | return ERR_PTR(rc); | |
572 | } | |
a00bfd71 MS |
573 | |
574 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); | |
faf16aa9 | 575 | dev_set_drvdata(&cdev->dev, device); |
a00bfd71 MS |
576 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
577 | ||
1da177e4 LT |
578 | return device; |
579 | } | |
580 | ||
581 | /* | |
582 | * Wait queue for dasd_delete_device waits. | |
583 | */ | |
584 | static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq); | |
585 | ||
586 | /* | |
587 | * Remove a dasd device structure. The passed referenced | |
588 | * is destroyed. | |
589 | */ | |
590 | void | |
591 | dasd_delete_device(struct dasd_device *device) | |
592 | { | |
593 | struct ccw_device *cdev; | |
594 | struct dasd_devmap *devmap; | |
a00bfd71 | 595 | unsigned long flags; |
1da177e4 LT |
596 | |
597 | /* First remove device pointer from devmap. */ | |
2a0217d5 | 598 | devmap = dasd_find_busid(dev_name(&device->cdev->dev)); |
606f4422 | 599 | BUG_ON(IS_ERR(devmap)); |
1da177e4 LT |
600 | spin_lock(&dasd_devmap_lock); |
601 | if (devmap->device != device) { | |
602 | spin_unlock(&dasd_devmap_lock); | |
603 | dasd_put_device(device); | |
604 | return; | |
605 | } | |
606 | devmap->device = NULL; | |
607 | spin_unlock(&dasd_devmap_lock); | |
608 | ||
a00bfd71 MS |
609 | /* Disconnect dasd_device structure from ccw_device structure. */ |
610 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
faf16aa9 | 611 | dev_set_drvdata(&device->cdev->dev, NULL); |
a00bfd71 MS |
612 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
613 | ||
614 | /* | |
615 | * Drop ref_count by 3, one for the devmap reference, one for | |
616 | * the cdev reference and one for the passed reference. | |
617 | */ | |
618 | atomic_sub(3, &device->ref_count); | |
1da177e4 LT |
619 | |
620 | /* Wait for reference counter to drop to zero. */ | |
621 | wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0); | |
622 | ||
623 | /* Disconnect dasd_device structure from ccw_device structure. */ | |
624 | cdev = device->cdev; | |
625 | device->cdev = NULL; | |
626 | ||
1da177e4 LT |
627 | /* Put ccw_device structure. */ |
628 | put_device(&cdev->dev); | |
629 | ||
630 | /* Now the device structure can be freed. */ | |
631 | dasd_free_device(device); | |
632 | } | |
633 | ||
634 | /* | |
635 | * Reference counter dropped to zero. Wake up waiter | |
636 | * in dasd_delete_device. | |
637 | */ | |
638 | void | |
639 | dasd_put_device_wake(struct dasd_device *device) | |
640 | { | |
641 | wake_up(&dasd_delete_wq); | |
642 | } | |
643 | ||
a00bfd71 MS |
644 | /* |
645 | * Return dasd_device structure associated with cdev. | |
646 | * This function needs to be called with the ccw device | |
647 | * lock held. It can be used from interrupt context. | |
648 | */ | |
649 | struct dasd_device * | |
650 | dasd_device_from_cdev_locked(struct ccw_device *cdev) | |
651 | { | |
faf16aa9 | 652 | struct dasd_device *device = dev_get_drvdata(&cdev->dev); |
a00bfd71 MS |
653 | |
654 | if (!device) | |
655 | return ERR_PTR(-ENODEV); | |
656 | dasd_get_device(device); | |
657 | return device; | |
658 | } | |
659 | ||
1da177e4 LT |
660 | /* |
661 | * Return dasd_device structure associated with cdev. | |
662 | */ | |
663 | struct dasd_device * | |
664 | dasd_device_from_cdev(struct ccw_device *cdev) | |
665 | { | |
1da177e4 | 666 | struct dasd_device *device; |
a00bfd71 | 667 | unsigned long flags; |
1da177e4 | 668 | |
a00bfd71 MS |
669 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
670 | device = dasd_device_from_cdev_locked(cdev); | |
671 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); | |
1da177e4 LT |
672 | return device; |
673 | } | |
674 | ||
675 | /* | |
676 | * SECTION: files in sysfs | |
677 | */ | |
678 | ||
13de227b HS |
679 | /* |
680 | * failfast controls the behaviour, if no path is available | |
681 | */ | |
682 | static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr, | |
683 | char *buf) | |
684 | { | |
685 | struct dasd_devmap *devmap; | |
686 | int ff_flag; | |
687 | ||
ca0b4b7d | 688 | devmap = dasd_find_busid(dev_name(dev)); |
13de227b HS |
689 | if (!IS_ERR(devmap)) |
690 | ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0; | |
691 | else | |
692 | ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0; | |
693 | return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n"); | |
694 | } | |
695 | ||
696 | static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr, | |
697 | const char *buf, size_t count) | |
698 | { | |
699 | struct dasd_devmap *devmap; | |
700 | int val; | |
701 | char *endp; | |
702 | ||
703 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | |
704 | if (IS_ERR(devmap)) | |
705 | return PTR_ERR(devmap); | |
706 | ||
707 | val = simple_strtoul(buf, &endp, 0); | |
708 | if (((endp + 1) < (buf + count)) || (val > 1)) | |
709 | return -EINVAL; | |
710 | ||
711 | spin_lock(&dasd_devmap_lock); | |
712 | if (val) | |
713 | devmap->features |= DASD_FEATURE_FAILFAST; | |
714 | else | |
715 | devmap->features &= ~DASD_FEATURE_FAILFAST; | |
716 | if (devmap->device) | |
717 | devmap->device->features = devmap->features; | |
718 | spin_unlock(&dasd_devmap_lock); | |
719 | return count; | |
720 | } | |
721 | ||
722 | static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store); | |
723 | ||
1da177e4 LT |
724 | /* |
725 | * readonly controls the readonly status of a dasd | |
726 | */ | |
727 | static ssize_t | |
e404e274 | 728 | dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf) |
1da177e4 LT |
729 | { |
730 | struct dasd_devmap *devmap; | |
731 | int ro_flag; | |
732 | ||
2a0217d5 | 733 | devmap = dasd_find_busid(dev_name(dev)); |
1da177e4 LT |
734 | if (!IS_ERR(devmap)) |
735 | ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0; | |
736 | else | |
737 | ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0; | |
738 | return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n"); | |
739 | } | |
740 | ||
741 | static ssize_t | |
138c014d HH |
742 | dasd_ro_store(struct device *dev, struct device_attribute *attr, |
743 | const char *buf, size_t count) | |
1da177e4 LT |
744 | { |
745 | struct dasd_devmap *devmap; | |
33b62a30 | 746 | struct dasd_device *device; |
01376f44 HH |
747 | int val; |
748 | char *endp; | |
1da177e4 LT |
749 | |
750 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | |
751 | if (IS_ERR(devmap)) | |
752 | return PTR_ERR(devmap); | |
01376f44 HH |
753 | |
754 | val = simple_strtoul(buf, &endp, 0); | |
755 | if (((endp + 1) < (buf + count)) || (val > 1)) | |
756 | return -EINVAL; | |
757 | ||
1da177e4 | 758 | spin_lock(&dasd_devmap_lock); |
01376f44 | 759 | if (val) |
1da177e4 LT |
760 | devmap->features |= DASD_FEATURE_READONLY; |
761 | else | |
762 | devmap->features &= ~DASD_FEATURE_READONLY; | |
33b62a30 SW |
763 | device = devmap->device; |
764 | if (device) { | |
765 | device->features = devmap->features; | |
766 | val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags); | |
767 | } | |
1da177e4 | 768 | spin_unlock(&dasd_devmap_lock); |
33b62a30 SW |
769 | if (device && device->block && device->block->gdp) |
770 | set_disk_ro(device->block->gdp, val); | |
1da177e4 LT |
771 | return count; |
772 | } | |
773 | ||
774 | static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store); | |
9575bf26 HH |
775 | /* |
776 | * erplog controls the logging of ERP related data | |
777 | * (e.g. failing channel programs). | |
778 | */ | |
779 | static ssize_t | |
780 | dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf) | |
781 | { | |
782 | struct dasd_devmap *devmap; | |
783 | int erplog; | |
784 | ||
2a0217d5 | 785 | devmap = dasd_find_busid(dev_name(dev)); |
9575bf26 HH |
786 | if (!IS_ERR(devmap)) |
787 | erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0; | |
788 | else | |
789 | erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0; | |
790 | return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n"); | |
791 | } | |
792 | ||
793 | static ssize_t | |
794 | dasd_erplog_store(struct device *dev, struct device_attribute *attr, | |
795 | const char *buf, size_t count) | |
796 | { | |
797 | struct dasd_devmap *devmap; | |
798 | int val; | |
799 | char *endp; | |
800 | ||
801 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | |
802 | if (IS_ERR(devmap)) | |
803 | return PTR_ERR(devmap); | |
804 | ||
805 | val = simple_strtoul(buf, &endp, 0); | |
806 | if (((endp + 1) < (buf + count)) || (val > 1)) | |
807 | return -EINVAL; | |
808 | ||
809 | spin_lock(&dasd_devmap_lock); | |
810 | if (val) | |
811 | devmap->features |= DASD_FEATURE_ERPLOG; | |
812 | else | |
813 | devmap->features &= ~DASD_FEATURE_ERPLOG; | |
814 | if (devmap->device) | |
815 | devmap->device->features = devmap->features; | |
816 | spin_unlock(&dasd_devmap_lock); | |
817 | return count; | |
818 | } | |
819 | ||
820 | static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store); | |
1da177e4 LT |
821 | |
822 | /* | |
823 | * use_diag controls whether the driver should use diag rather than ssch | |
824 | * to talk to the device | |
825 | */ | |
138c014d | 826 | static ssize_t |
e404e274 | 827 | dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf) |
1da177e4 LT |
828 | { |
829 | struct dasd_devmap *devmap; | |
830 | int use_diag; | |
831 | ||
2a0217d5 | 832 | devmap = dasd_find_busid(dev_name(dev)); |
1da177e4 LT |
833 | if (!IS_ERR(devmap)) |
834 | use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0; | |
835 | else | |
836 | use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0; | |
837 | return sprintf(buf, use_diag ? "1\n" : "0\n"); | |
838 | } | |
839 | ||
840 | static ssize_t | |
138c014d HH |
841 | dasd_use_diag_store(struct device *dev, struct device_attribute *attr, |
842 | const char *buf, size_t count) | |
1da177e4 LT |
843 | { |
844 | struct dasd_devmap *devmap; | |
845 | ssize_t rc; | |
01376f44 HH |
846 | int val; |
847 | char *endp; | |
1da177e4 LT |
848 | |
849 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | |
850 | if (IS_ERR(devmap)) | |
851 | return PTR_ERR(devmap); | |
01376f44 HH |
852 | |
853 | val = simple_strtoul(buf, &endp, 0); | |
854 | if (((endp + 1) < (buf + count)) || (val > 1)) | |
855 | return -EINVAL; | |
856 | ||
1da177e4 LT |
857 | spin_lock(&dasd_devmap_lock); |
858 | /* Changing diag discipline flag is only allowed in offline state. */ | |
859 | rc = count; | |
860 | if (!devmap->device) { | |
01376f44 | 861 | if (val) |
1da177e4 LT |
862 | devmap->features |= DASD_FEATURE_USEDIAG; |
863 | else | |
864 | devmap->features &= ~DASD_FEATURE_USEDIAG; | |
865 | } else | |
866 | rc = -EPERM; | |
867 | spin_unlock(&dasd_devmap_lock); | |
868 | return rc; | |
869 | } | |
870 | ||
138c014d | 871 | static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store); |
1da177e4 LT |
872 | |
873 | static ssize_t | |
138c014d HH |
874 | dasd_discipline_show(struct device *dev, struct device_attribute *attr, |
875 | char *buf) | |
1da177e4 | 876 | { |
a00bfd71 MS |
877 | struct dasd_device *device; |
878 | ssize_t len; | |
1da177e4 | 879 | |
a00bfd71 | 880 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
589c74d5 SH |
881 | if (IS_ERR(device)) |
882 | goto out; | |
883 | else if (!device->discipline) { | |
884 | dasd_put_device(device); | |
885 | goto out; | |
886 | } else { | |
a00bfd71 MS |
887 | len = snprintf(buf, PAGE_SIZE, "%s\n", |
888 | device->discipline->name); | |
889 | dasd_put_device(device); | |
589c74d5 SH |
890 | return len; |
891 | } | |
892 | out: | |
893 | len = snprintf(buf, PAGE_SIZE, "none\n"); | |
a00bfd71 | 894 | return len; |
1da177e4 LT |
895 | } |
896 | ||
897 | static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL); | |
898 | ||
4dfd5c45 HH |
899 | static ssize_t |
900 | dasd_device_status_show(struct device *dev, struct device_attribute *attr, | |
901 | char *buf) | |
902 | { | |
903 | struct dasd_device *device; | |
904 | ssize_t len; | |
905 | ||
906 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
907 | if (!IS_ERR(device)) { | |
908 | switch (device->state) { | |
909 | case DASD_STATE_NEW: | |
910 | len = snprintf(buf, PAGE_SIZE, "new\n"); | |
911 | break; | |
912 | case DASD_STATE_KNOWN: | |
913 | len = snprintf(buf, PAGE_SIZE, "detected\n"); | |
914 | break; | |
915 | case DASD_STATE_BASIC: | |
916 | len = snprintf(buf, PAGE_SIZE, "basic\n"); | |
917 | break; | |
918 | case DASD_STATE_UNFMT: | |
919 | len = snprintf(buf, PAGE_SIZE, "unformatted\n"); | |
920 | break; | |
921 | case DASD_STATE_READY: | |
922 | len = snprintf(buf, PAGE_SIZE, "ready\n"); | |
923 | break; | |
924 | case DASD_STATE_ONLINE: | |
925 | len = snprintf(buf, PAGE_SIZE, "online\n"); | |
926 | break; | |
927 | default: | |
928 | len = snprintf(buf, PAGE_SIZE, "no stat\n"); | |
929 | break; | |
930 | } | |
931 | dasd_put_device(device); | |
932 | } else | |
933 | len = snprintf(buf, PAGE_SIZE, "unknown\n"); | |
934 | return len; | |
935 | } | |
936 | ||
937 | static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL); | |
938 | ||
3d052595 HH |
939 | static ssize_t |
940 | dasd_alias_show(struct device *dev, struct device_attribute *attr, char *buf) | |
941 | { | |
942 | struct dasd_devmap *devmap; | |
943 | int alias; | |
944 | ||
2a0217d5 | 945 | devmap = dasd_find_busid(dev_name(dev)); |
3d052595 | 946 | spin_lock(&dasd_devmap_lock); |
8e09f215 SW |
947 | if (IS_ERR(devmap) || strlen(devmap->uid.vendor) == 0) { |
948 | spin_unlock(&dasd_devmap_lock); | |
949 | return sprintf(buf, "0\n"); | |
950 | } | |
951 | if (devmap->uid.type == UA_BASE_PAV_ALIAS || | |
952 | devmap->uid.type == UA_HYPER_PAV_ALIAS) | |
953 | alias = 1; | |
3d052595 HH |
954 | else |
955 | alias = 0; | |
956 | spin_unlock(&dasd_devmap_lock); | |
3d052595 HH |
957 | return sprintf(buf, alias ? "1\n" : "0\n"); |
958 | } | |
959 | ||
960 | static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL); | |
961 | ||
962 | static ssize_t | |
963 | dasd_vendor_show(struct device *dev, struct device_attribute *attr, char *buf) | |
964 | { | |
965 | struct dasd_devmap *devmap; | |
966 | char *vendor; | |
967 | ||
2a0217d5 | 968 | devmap = dasd_find_busid(dev_name(dev)); |
3d052595 HH |
969 | spin_lock(&dasd_devmap_lock); |
970 | if (!IS_ERR(devmap) && strlen(devmap->uid.vendor) > 0) | |
971 | vendor = devmap->uid.vendor; | |
972 | else | |
973 | vendor = ""; | |
974 | spin_unlock(&dasd_devmap_lock); | |
975 | ||
976 | return snprintf(buf, PAGE_SIZE, "%s\n", vendor); | |
977 | } | |
978 | ||
979 | static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL); | |
980 | ||
981 | #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\ | |
4abb08c2 SW |
982 | /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\ |
983 | /* vduit */ 32 + 1) | |
3d052595 HH |
984 | |
985 | static ssize_t | |
986 | dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf) | |
987 | { | |
988 | struct dasd_devmap *devmap; | |
8e09f215 SW |
989 | char uid_string[UID_STRLEN]; |
990 | char ua_string[3]; | |
991 | struct dasd_uid *uid; | |
3d052595 | 992 | |
2a0217d5 | 993 | devmap = dasd_find_busid(dev_name(dev)); |
3d052595 | 994 | spin_lock(&dasd_devmap_lock); |
8e09f215 SW |
995 | if (IS_ERR(devmap) || strlen(devmap->uid.vendor) == 0) { |
996 | spin_unlock(&dasd_devmap_lock); | |
997 | return sprintf(buf, "\n"); | |
998 | } | |
999 | uid = &devmap->uid; | |
1000 | switch (uid->type) { | |
1001 | case UA_BASE_DEVICE: | |
1002 | sprintf(ua_string, "%02x", uid->real_unit_addr); | |
1003 | break; | |
1004 | case UA_BASE_PAV_ALIAS: | |
1005 | sprintf(ua_string, "%02x", uid->base_unit_addr); | |
1006 | break; | |
1007 | case UA_HYPER_PAV_ALIAS: | |
1008 | sprintf(ua_string, "xx"); | |
1009 | break; | |
1010 | default: | |
1011 | /* should not happen, treat like base device */ | |
1012 | sprintf(ua_string, "%02x", uid->real_unit_addr); | |
1013 | break; | |
1014 | } | |
4abb08c2 SW |
1015 | if (strlen(uid->vduit) > 0) |
1016 | snprintf(uid_string, sizeof(uid_string), | |
1017 | "%s.%s.%04x.%s.%s", | |
1018 | uid->vendor, uid->serial, | |
1019 | uid->ssid, ua_string, | |
1020 | uid->vduit); | |
1021 | else | |
1022 | snprintf(uid_string, sizeof(uid_string), | |
1023 | "%s.%s.%04x.%s", | |
1024 | uid->vendor, uid->serial, | |
1025 | uid->ssid, ua_string); | |
3d052595 | 1026 | spin_unlock(&dasd_devmap_lock); |
8e09f215 | 1027 | return snprintf(buf, PAGE_SIZE, "%s\n", uid_string); |
3d052595 HH |
1028 | } |
1029 | ||
1030 | static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL); | |
1031 | ||
20c64468 SW |
1032 | /* |
1033 | * extended error-reporting | |
1034 | */ | |
1035 | static ssize_t | |
1036 | dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1037 | { | |
1038 | struct dasd_devmap *devmap; | |
1039 | int eer_flag; | |
1040 | ||
2a0217d5 | 1041 | devmap = dasd_find_busid(dev_name(dev)); |
20c64468 SW |
1042 | if (!IS_ERR(devmap) && devmap->device) |
1043 | eer_flag = dasd_eer_enabled(devmap->device); | |
1044 | else | |
1045 | eer_flag = 0; | |
1046 | return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n"); | |
1047 | } | |
1048 | ||
1049 | static ssize_t | |
1050 | dasd_eer_store(struct device *dev, struct device_attribute *attr, | |
1051 | const char *buf, size_t count) | |
1052 | { | |
1053 | struct dasd_devmap *devmap; | |
01376f44 HH |
1054 | int val, rc; |
1055 | char *endp; | |
20c64468 SW |
1056 | |
1057 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | |
1058 | if (IS_ERR(devmap)) | |
1059 | return PTR_ERR(devmap); | |
1060 | if (!devmap->device) | |
01376f44 HH |
1061 | return -ENODEV; |
1062 | ||
1063 | val = simple_strtoul(buf, &endp, 0); | |
1064 | if (((endp + 1) < (buf + count)) || (val > 1)) | |
1065 | return -EINVAL; | |
1066 | ||
645c98c8 | 1067 | if (val) { |
20c64468 | 1068 | rc = dasd_eer_enable(devmap->device); |
645c98c8 HH |
1069 | if (rc) |
1070 | return rc; | |
1071 | } else | |
20c64468 | 1072 | dasd_eer_disable(devmap->device); |
645c98c8 | 1073 | return count; |
20c64468 SW |
1074 | } |
1075 | ||
1076 | static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store); | |
1077 | ||
1da177e4 LT |
1078 | static struct attribute * dasd_attrs[] = { |
1079 | &dev_attr_readonly.attr, | |
1080 | &dev_attr_discipline.attr, | |
4dfd5c45 | 1081 | &dev_attr_status.attr, |
3d052595 HH |
1082 | &dev_attr_alias.attr, |
1083 | &dev_attr_vendor.attr, | |
1084 | &dev_attr_uid.attr, | |
1da177e4 | 1085 | &dev_attr_use_diag.attr, |
20c64468 | 1086 | &dev_attr_eer_enabled.attr, |
9575bf26 | 1087 | &dev_attr_erplog.attr, |
13de227b | 1088 | &dev_attr_failfast.attr, |
1da177e4 LT |
1089 | NULL, |
1090 | }; | |
1091 | ||
1092 | static struct attribute_group dasd_attr_group = { | |
1093 | .attrs = dasd_attrs, | |
1094 | }; | |
1095 | ||
3d052595 HH |
1096 | /* |
1097 | * Return copy of the device unique identifier. | |
1098 | */ | |
1099 | int | |
1100 | dasd_get_uid(struct ccw_device *cdev, struct dasd_uid *uid) | |
1101 | { | |
1102 | struct dasd_devmap *devmap; | |
1103 | ||
2a0217d5 | 1104 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
3d052595 HH |
1105 | if (IS_ERR(devmap)) |
1106 | return PTR_ERR(devmap); | |
1107 | spin_lock(&dasd_devmap_lock); | |
1108 | *uid = devmap->uid; | |
1109 | spin_unlock(&dasd_devmap_lock); | |
1110 | return 0; | |
1111 | } | |
d41dd122 | 1112 | EXPORT_SYMBOL_GPL(dasd_get_uid); |
3d052595 HH |
1113 | |
1114 | /* | |
1115 | * Register the given device unique identifier into devmap struct. | |
b18a60e7 PO |
1116 | * In addition check if the related storage server subsystem ID is already |
1117 | * contained in the dasd_server_ssid_list. If subsystem ID is not contained, | |
1118 | * create new entry. | |
40545573 HH |
1119 | * Return 0 if server was already in serverlist, |
1120 | * 1 if the server was added successful | |
1121 | * <0 in case of error. | |
3d052595 HH |
1122 | */ |
1123 | int | |
1124 | dasd_set_uid(struct ccw_device *cdev, struct dasd_uid *uid) | |
1125 | { | |
1126 | struct dasd_devmap *devmap; | |
1127 | ||
2a0217d5 | 1128 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
3d052595 HH |
1129 | if (IS_ERR(devmap)) |
1130 | return PTR_ERR(devmap); | |
d0710c7c | 1131 | |
3d052595 HH |
1132 | spin_lock(&dasd_devmap_lock); |
1133 | devmap->uid = *uid; | |
1134 | spin_unlock(&dasd_devmap_lock); | |
d0710c7c | 1135 | |
8e09f215 | 1136 | return 0; |
3d052595 | 1137 | } |
40545573 | 1138 | EXPORT_SYMBOL_GPL(dasd_set_uid); |
3d052595 | 1139 | |
f24acd45 HH |
1140 | /* |
1141 | * Return value of the specified feature. | |
1142 | */ | |
1143 | int | |
1144 | dasd_get_feature(struct ccw_device *cdev, int feature) | |
1145 | { | |
1146 | struct dasd_devmap *devmap; | |
1147 | ||
2a0217d5 | 1148 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
f24acd45 | 1149 | if (IS_ERR(devmap)) |
40545573 | 1150 | return PTR_ERR(devmap); |
f24acd45 HH |
1151 | |
1152 | return ((devmap->features & feature) != 0); | |
1153 | } | |
1154 | ||
1155 | /* | |
1156 | * Set / reset given feature. | |
1157 | * Flag indicates wether to set (!=0) or the reset (=0) the feature. | |
1158 | */ | |
1159 | int | |
1160 | dasd_set_feature(struct ccw_device *cdev, int feature, int flag) | |
1161 | { | |
1162 | struct dasd_devmap *devmap; | |
1163 | ||
2a0217d5 | 1164 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
f24acd45 | 1165 | if (IS_ERR(devmap)) |
40545573 | 1166 | return PTR_ERR(devmap); |
f24acd45 HH |
1167 | |
1168 | spin_lock(&dasd_devmap_lock); | |
1169 | if (flag) | |
1170 | devmap->features |= feature; | |
1171 | else | |
1172 | devmap->features &= ~feature; | |
c6eb7b77 HH |
1173 | if (devmap->device) |
1174 | devmap->device->features = devmap->features; | |
f24acd45 HH |
1175 | spin_unlock(&dasd_devmap_lock); |
1176 | return 0; | |
1177 | } | |
1178 | ||
1179 | ||
1da177e4 LT |
1180 | int |
1181 | dasd_add_sysfs_files(struct ccw_device *cdev) | |
1182 | { | |
1183 | return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group); | |
1184 | } | |
1185 | ||
1186 | void | |
1187 | dasd_remove_sysfs_files(struct ccw_device *cdev) | |
1188 | { | |
1189 | sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group); | |
1190 | } | |
1191 | ||
1192 | ||
1193 | int | |
1194 | dasd_devmap_init(void) | |
1195 | { | |
1196 | int i; | |
1197 | ||
1198 | /* Initialize devmap structures. */ | |
1199 | dasd_max_devindex = 0; | |
1200 | for (i = 0; i < 256; i++) | |
1201 | INIT_LIST_HEAD(&dasd_hashlists[i]); | |
40545573 | 1202 | return 0; |
1da177e4 LT |
1203 | } |
1204 | ||
1205 | void | |
1206 | dasd_devmap_exit(void) | |
1207 | { | |
1208 | dasd_forget_ranges(); | |
1209 | } |