Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
3 | * Horst Hummel <Horst.Hummel@de.ibm.com> | |
4 | * Carsten Otte <Cotte@de.ibm.com> | |
5 | * Martin Schwidefsky <schwidefsky@de.ibm.com> | |
6 | * Bugreports.to..: <Linux390@de.ibm.com> | |
a53c8fab | 7 | * Copyright IBM Corp. 1999,2001 |
1da177e4 LT |
8 | * |
9 | * Device mapping and dasd= parameter parsing functions. All devmap | |
10 | * functions may not be called from interrupt context. In particular | |
11 | * dasd_get_device is a no-no from interrupt context. | |
12 | * | |
1da177e4 LT |
13 | */ |
14 | ||
fc19f381 SH |
15 | #define KMSG_COMPONENT "dasd" |
16 | ||
1da177e4 LT |
17 | #include <linux/ctype.h> |
18 | #include <linux/init.h> | |
8d3b33f6 | 19 | #include <linux/module.h> |
5a0e3ad6 | 20 | #include <linux/slab.h> |
1da177e4 LT |
21 | |
22 | #include <asm/debug.h> | |
7c0f6ba6 | 23 | #include <linux/uaccess.h> |
7039d3a1 | 24 | #include <asm/ipl.h> |
1da177e4 LT |
25 | |
26 | /* This is ugly... */ | |
27 | #define PRINTK_HEADER "dasd_devmap:" | |
98df67b3 | 28 | #define DASD_BUS_ID_SIZE 20 |
1da177e4 LT |
29 | |
30 | #include "dasd_int.h" | |
31 | ||
e18b890b | 32 | struct kmem_cache *dasd_page_cache; |
40545573 | 33 | EXPORT_SYMBOL_GPL(dasd_page_cache); |
1da177e4 LT |
34 | |
35 | /* | |
36 | * dasd_devmap_t is used to store the features and the relation | |
37 | * between device number and device index. To find a dasd_devmap_t | |
38 | * that corresponds to a device number of a device index each | |
39 | * dasd_devmap_t is added to two linked lists, one to search by | |
40 | * the device number and one to search by the device index. As | |
41 | * soon as big minor numbers are available the device index list | |
42 | * can be removed since the device number will then be identical | |
43 | * to the device index. | |
44 | */ | |
45 | struct dasd_devmap { | |
46 | struct list_head list; | |
98df67b3 | 47 | char bus_id[DASD_BUS_ID_SIZE]; |
1da177e4 LT |
48 | unsigned int devindex; |
49 | unsigned short features; | |
50 | struct dasd_device *device; | |
51 | }; | |
52 | ||
53 | /* | |
54 | * Parameter parsing functions for dasd= parameter. The syntax is: | |
55 | * <devno> : (0x)?[0-9a-fA-F]+ | |
56 | * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+ | |
57 | * <feature> : ro | |
58 | * <feature_list> : \(<feature>(:<feature>)*\) | |
59 | * <devno-range> : <devno>(-<devno>)?<feature_list>? | |
60 | * <busid-range> : <busid>(-<busid>)?<feature_list>? | |
61 | * <devices> : <devno-range>|<busid-range> | |
62 | * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod | |
63 | * | |
64 | * <dasd> : autodetect|probeonly|<devices>(,<devices>)* | |
65 | */ | |
66 | ||
67 | int dasd_probeonly = 0; /* is true, when probeonly mode is active */ | |
68 | int dasd_autodetect = 0; /* is true, when autodetection is active */ | |
40545573 HH |
69 | int dasd_nopav = 0; /* is true, when PAV is disabled */ |
70 | EXPORT_SYMBOL_GPL(dasd_nopav); | |
f3eb5384 SW |
71 | int dasd_nofcx; /* disable High Performance Ficon */ |
72 | EXPORT_SYMBOL_GPL(dasd_nofcx); | |
1da177e4 LT |
73 | |
74 | /* | |
75 | * char *dasd[] is intended to hold the ranges supplied by the dasd= statement | |
76 | * it is named 'dasd' to directly be filled by insmod with the comma separated | |
77 | * strings when running as a module. | |
78 | */ | |
79 | static char *dasd[256]; | |
3b126935 | 80 | module_param_array(dasd, charp, NULL, S_IRUGO); |
8d3b33f6 | 81 | |
1da177e4 | 82 | /* |
d0710c7c | 83 | * Single spinlock to protect devmap and servermap structures and lists. |
1da177e4 LT |
84 | */ |
85 | static DEFINE_SPINLOCK(dasd_devmap_lock); | |
86 | ||
87 | /* | |
88 | * Hash lists for devmap structures. | |
89 | */ | |
90 | static struct list_head dasd_hashlists[256]; | |
91 | int dasd_max_devindex; | |
92 | ||
69f90f6a | 93 | static struct dasd_devmap *dasd_add_busid(const char *, int); |
1da177e4 LT |
94 | |
95 | static inline int | |
69f90f6a | 96 | dasd_hash_busid(const char *bus_id) |
1da177e4 LT |
97 | { |
98 | int hash, i; | |
99 | ||
100 | hash = 0; | |
98df67b3 | 101 | for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++) |
1da177e4 LT |
102 | hash += *bus_id; |
103 | return hash & 0xff; | |
104 | } | |
105 | ||
106 | #ifndef MODULE | |
107 | /* | |
108 | * The parameter parsing functions for builtin-drivers are called | |
109 | * before kmalloc works. Store the pointers to the parameters strings | |
110 | * into dasd[] for later processing. | |
111 | */ | |
112 | static int __init | |
113 | dasd_call_setup(char *str) | |
114 | { | |
115 | static int count = 0; | |
116 | ||
117 | if (count < 256) | |
118 | dasd[count++] = str; | |
119 | return 1; | |
120 | } | |
121 | ||
122 | __setup ("dasd=", dasd_call_setup); | |
123 | #endif /* #ifndef MODULE */ | |
124 | ||
7039d3a1 PO |
125 | #define DASD_IPLDEV "ipldev" |
126 | ||
1da177e4 LT |
127 | /* |
128 | * Read a device busid/devno from a string. | |
129 | */ | |
4d284cac | 130 | static int |
fc19f381 | 131 | |
1da177e4 LT |
132 | dasd_busid(char **str, int *id0, int *id1, int *devno) |
133 | { | |
134 | int val, old_style; | |
138c014d | 135 | |
7039d3a1 PO |
136 | /* Interpret ipldev busid */ |
137 | if (strncmp(DASD_IPLDEV, *str, strlen(DASD_IPLDEV)) == 0) { | |
138 | if (ipl_info.type != IPL_TYPE_CCW) { | |
fc19f381 | 139 | pr_err("The IPL device is not a CCW device\n"); |
7039d3a1 PO |
140 | return -EINVAL; |
141 | } | |
142 | *id0 = 0; | |
143 | *id1 = ipl_info.data.ccw.dev_id.ssid; | |
144 | *devno = ipl_info.data.ccw.dev_id.devno; | |
145 | *str += strlen(DASD_IPLDEV); | |
146 | ||
147 | return 0; | |
148 | } | |
1da177e4 LT |
149 | /* check for leading '0x' */ |
150 | old_style = 0; | |
151 | if ((*str)[0] == '0' && (*str)[1] == 'x') { | |
152 | *str += 2; | |
153 | old_style = 1; | |
154 | } | |
155 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ | |
156 | return -EINVAL; | |
157 | val = simple_strtoul(*str, str, 16); | |
158 | if (old_style || (*str)[0] != '.') { | |
159 | *id0 = *id1 = 0; | |
160 | if (val < 0 || val > 0xffff) | |
161 | return -EINVAL; | |
162 | *devno = val; | |
163 | return 0; | |
164 | } | |
165 | /* New style x.y.z busid */ | |
166 | if (val < 0 || val > 0xff) | |
167 | return -EINVAL; | |
168 | *id0 = val; | |
169 | (*str)++; | |
170 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ | |
171 | return -EINVAL; | |
172 | val = simple_strtoul(*str, str, 16); | |
173 | if (val < 0 || val > 0xff || (*str)++[0] != '.') | |
174 | return -EINVAL; | |
175 | *id1 = val; | |
176 | if (!isxdigit((*str)[0])) /* We require at least one hex digit */ | |
177 | return -EINVAL; | |
178 | val = simple_strtoul(*str, str, 16); | |
179 | if (val < 0 || val > 0xffff) | |
180 | return -EINVAL; | |
181 | *devno = val; | |
182 | return 0; | |
183 | } | |
184 | ||
185 | /* | |
186 | * Read colon separated list of dasd features. Currently there is | |
187 | * only one: "ro" for read-only devices. The default feature set | |
188 | * is empty (value 0). | |
189 | */ | |
4d284cac | 190 | static int |
1da177e4 LT |
191 | dasd_feature_list(char *str, char **endp) |
192 | { | |
193 | int features, len, rc; | |
194 | ||
195 | rc = 0; | |
196 | if (*str != '(') { | |
197 | *endp = str; | |
198 | return DASD_FEATURE_DEFAULT; | |
199 | } | |
200 | str++; | |
201 | features = 0; | |
202 | ||
203 | while (1) { | |
138c014d | 204 | for (len = 0; |
1da177e4 LT |
205 | str[len] && str[len] != ':' && str[len] != ')'; len++); |
206 | if (len == 2 && !strncmp(str, "ro", 2)) | |
207 | features |= DASD_FEATURE_READONLY; | |
208 | else if (len == 4 && !strncmp(str, "diag", 4)) | |
209 | features |= DASD_FEATURE_USEDIAG; | |
e4dbb0f2 SH |
210 | else if (len == 3 && !strncmp(str, "raw", 3)) |
211 | features |= DASD_FEATURE_USERAW; | |
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 { |
baebc70a JP |
217 | pr_warn("%*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 != ')') { | |
baebc70a | 227 | pr_warn("A closing parenthesis ')' is missing in the dasd= parameter\n"); |
1da177e4 LT |
228 | rc = -EINVAL; |
229 | } else | |
230 | str++; | |
231 | *endp = str; | |
232 | if (rc != 0) | |
233 | return rc; | |
234 | return features; | |
235 | } | |
236 | ||
237 | /* | |
238 | * Try to match the first element on the comma separated parse string | |
239 | * with one of the known keywords. If a keyword is found, take the approprate | |
240 | * action and return a pointer to the residual string. If the first element | |
241 | * could not be matched to any keyword then return an error code. | |
242 | */ | |
243 | static char * | |
244 | dasd_parse_keyword( char *parsestring ) { | |
245 | ||
246 | char *nextcomma, *residual_str; | |
247 | int length; | |
248 | ||
249 | nextcomma = strchr(parsestring,','); | |
250 | if (nextcomma) { | |
251 | length = nextcomma - parsestring; | |
252 | residual_str = nextcomma + 1; | |
253 | } else { | |
254 | length = strlen(parsestring); | |
255 | residual_str = parsestring + length; | |
256 | } | |
40545573 | 257 | if (strncmp("autodetect", parsestring, length) == 0) { |
1da177e4 | 258 | dasd_autodetect = 1; |
fc19f381 | 259 | pr_info("The autodetection mode has been activated\n"); |
1da177e4 LT |
260 | return residual_str; |
261 | } | |
40545573 | 262 | if (strncmp("probeonly", parsestring, length) == 0) { |
1da177e4 | 263 | dasd_probeonly = 1; |
fc19f381 | 264 | pr_info("The probeonly mode has been activated\n"); |
1da177e4 LT |
265 | return residual_str; |
266 | } | |
40545573 | 267 | if (strncmp("nopav", parsestring, length) == 0) { |
dcd707b4 | 268 | if (MACHINE_IS_VM) |
fc19f381 | 269 | pr_info("'nopav' is not supported on z/VM\n"); |
dcd707b4 PO |
270 | else { |
271 | dasd_nopav = 1; | |
fc19f381 | 272 | pr_info("PAV support has be deactivated\n"); |
dcd707b4 | 273 | } |
40545573 HH |
274 | return residual_str; |
275 | } | |
f3eb5384 SW |
276 | if (strncmp("nofcx", parsestring, length) == 0) { |
277 | dasd_nofcx = 1; | |
fc19f381 SH |
278 | pr_info("High Performance FICON support has been " |
279 | "deactivated\n"); | |
f3eb5384 SW |
280 | return residual_str; |
281 | } | |
40545573 | 282 | if (strncmp("fixedbuffers", parsestring, length) == 0) { |
1da177e4 LT |
283 | if (dasd_page_cache) |
284 | return residual_str; | |
285 | dasd_page_cache = | |
2f6c55fc HC |
286 | kmem_cache_create("dasd_page_cache", PAGE_SIZE, |
287 | PAGE_SIZE, SLAB_CACHE_DMA, | |
20c2df83 | 288 | NULL); |
1da177e4 | 289 | if (!dasd_page_cache) |
fc19f381 | 290 | DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, " |
1da177e4 LT |
291 | "fixed buffer mode disabled."); |
292 | else | |
fc19f381 | 293 | DBF_EVENT(DBF_INFO, "%s", |
1da177e4 LT |
294 | "turning on fixed buffer mode"); |
295 | return residual_str; | |
296 | } | |
297 | return ERR_PTR(-EINVAL); | |
298 | } | |
299 | ||
300 | /* | |
301 | * Try to interprete the first element on the comma separated parse string | |
302 | * as a device number or a range of devices. If the interpretation is | |
25985edc | 303 | * successful, create the matching dasd_devmap entries and return a pointer |
1da177e4 LT |
304 | * to the residual string. |
305 | * If interpretation fails or in case of an error, return an error code. | |
306 | */ | |
307 | static char * | |
308 | dasd_parse_range( char *parsestring ) { | |
309 | ||
310 | struct dasd_devmap *devmap; | |
311 | int from, from_id0, from_id1; | |
312 | int to, to_id0, to_id1; | |
313 | int features, rc; | |
98df67b3 | 314 | char bus_id[DASD_BUS_ID_SIZE+1], *str; |
1da177e4 LT |
315 | |
316 | str = parsestring; | |
317 | rc = dasd_busid(&str, &from_id0, &from_id1, &from); | |
318 | if (rc == 0) { | |
319 | to = from; | |
320 | to_id0 = from_id0; | |
321 | to_id1 = from_id1; | |
322 | if (*str == '-') { | |
323 | str++; | |
324 | rc = dasd_busid(&str, &to_id0, &to_id1, &to); | |
325 | } | |
326 | } | |
327 | if (rc == 0 && | |
328 | (from_id0 != to_id0 || from_id1 != to_id1 || from > to)) | |
329 | rc = -EINVAL; | |
330 | if (rc) { | |
fc19f381 | 331 | pr_err("%s is not a valid device range\n", parsestring); |
1da177e4 LT |
332 | return ERR_PTR(rc); |
333 | } | |
334 | features = dasd_feature_list(str, &str); | |
335 | if (features < 0) | |
336 | return ERR_PTR(-EINVAL); | |
40545573 HH |
337 | /* each device in dasd= parameter should be set initially online */ |
338 | features |= DASD_FEATURE_INITIAL_ONLINE; | |
1da177e4 LT |
339 | while (from <= to) { |
340 | sprintf(bus_id, "%01x.%01x.%04x", | |
341 | from_id0, from_id1, from++); | |
342 | devmap = dasd_add_busid(bus_id, features); | |
343 | if (IS_ERR(devmap)) | |
344 | return (char *)devmap; | |
345 | } | |
346 | if (*str == ',') | |
347 | return str + 1; | |
348 | if (*str == '\0') | |
349 | return str; | |
baebc70a | 350 | pr_warn("The dasd= parameter value %s has an invalid ending\n", str); |
1da177e4 LT |
351 | return ERR_PTR(-EINVAL); |
352 | } | |
353 | ||
4d284cac | 354 | static char * |
1da177e4 LT |
355 | dasd_parse_next_element( char *parsestring ) { |
356 | char * residual_str; | |
357 | residual_str = dasd_parse_keyword(parsestring); | |
358 | if (!IS_ERR(residual_str)) | |
359 | return residual_str; | |
360 | residual_str = dasd_parse_range(parsestring); | |
361 | return residual_str; | |
362 | } | |
363 | ||
364 | /* | |
365 | * Parse parameters stored in dasd[] | |
366 | * The 'dasd=...' parameter allows to specify a comma separated list of | |
367 | * keywords and device ranges. When the dasd driver is build into the kernel, | |
368 | * the complete list will be stored as one element of the dasd[] array. | |
369 | * When the dasd driver is build as a module, then the list is broken into | |
370 | * it's elements and each dasd[] entry contains one element. | |
371 | */ | |
372 | int | |
373 | dasd_parse(void) | |
374 | { | |
375 | int rc, i; | |
376 | char *parsestring; | |
377 | ||
378 | rc = 0; | |
379 | for (i = 0; i < 256; i++) { | |
380 | if (dasd[i] == NULL) | |
381 | break; | |
382 | parsestring = dasd[i]; | |
383 | /* loop over the comma separated list in the parsestring */ | |
384 | while (*parsestring) { | |
385 | parsestring = dasd_parse_next_element(parsestring); | |
386 | if(IS_ERR(parsestring)) { | |
387 | rc = PTR_ERR(parsestring); | |
388 | break; | |
389 | } | |
390 | } | |
391 | if (rc) { | |
392 | DBF_EVENT(DBF_ALERT, "%s", "invalid range found"); | |
393 | break; | |
394 | } | |
395 | } | |
396 | return rc; | |
397 | } | |
398 | ||
399 | /* | |
400 | * Add a devmap for the device specified by busid. It is possible that | |
401 | * the devmap already exists (dasd= parameter). The order of the devices | |
402 | * added through this function will define the kdevs for the individual | |
138c014d | 403 | * devices. |
1da177e4 LT |
404 | */ |
405 | static struct dasd_devmap * | |
69f90f6a | 406 | dasd_add_busid(const char *bus_id, int features) |
1da177e4 LT |
407 | { |
408 | struct dasd_devmap *devmap, *new, *tmp; | |
409 | int hash; | |
410 | ||
006485dc | 411 | new = kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL); |
1da177e4 LT |
412 | if (!new) |
413 | return ERR_PTR(-ENOMEM); | |
414 | spin_lock(&dasd_devmap_lock); | |
d2c993d8 | 415 | devmap = NULL; |
1da177e4 LT |
416 | hash = dasd_hash_busid(bus_id); |
417 | list_for_each_entry(tmp, &dasd_hashlists[hash], list) | |
98df67b3 | 418 | if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) { |
1da177e4 LT |
419 | devmap = tmp; |
420 | break; | |
421 | } | |
422 | if (!devmap) { | |
423 | /* This bus_id is new. */ | |
424 | new->devindex = dasd_max_devindex++; | |
98df67b3 | 425 | strncpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE); |
1da177e4 | 426 | new->features = features; |
d2c993d8 | 427 | new->device = NULL; |
1da177e4 LT |
428 | list_add(&new->list, &dasd_hashlists[hash]); |
429 | devmap = new; | |
d2c993d8 | 430 | new = NULL; |
1da177e4 LT |
431 | } |
432 | spin_unlock(&dasd_devmap_lock); | |
17fd682e | 433 | kfree(new); |
1da177e4 LT |
434 | return devmap; |
435 | } | |
436 | ||
437 | /* | |
438 | * Find devmap for device with given bus_id. | |
439 | */ | |
440 | static struct dasd_devmap * | |
69f90f6a | 441 | dasd_find_busid(const char *bus_id) |
1da177e4 LT |
442 | { |
443 | struct dasd_devmap *devmap, *tmp; | |
444 | int hash; | |
445 | ||
446 | spin_lock(&dasd_devmap_lock); | |
447 | devmap = ERR_PTR(-ENODEV); | |
448 | hash = dasd_hash_busid(bus_id); | |
449 | list_for_each_entry(tmp, &dasd_hashlists[hash], list) { | |
98df67b3 | 450 | if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) { |
1da177e4 LT |
451 | devmap = tmp; |
452 | break; | |
453 | } | |
454 | } | |
455 | spin_unlock(&dasd_devmap_lock); | |
456 | return devmap; | |
457 | } | |
458 | ||
459 | /* | |
460 | * Check if busid has been added to the list of dasd ranges. | |
461 | */ | |
462 | int | |
69f90f6a | 463 | dasd_busid_known(const char *bus_id) |
1da177e4 LT |
464 | { |
465 | return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0; | |
466 | } | |
467 | ||
468 | /* | |
469 | * Forget all about the device numbers added so far. | |
470 | * This may only be called at module unload or system shutdown. | |
471 | */ | |
472 | static void | |
473 | dasd_forget_ranges(void) | |
474 | { | |
475 | struct dasd_devmap *devmap, *n; | |
476 | int i; | |
477 | ||
478 | spin_lock(&dasd_devmap_lock); | |
479 | for (i = 0; i < 256; i++) { | |
480 | list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) { | |
606f4422 | 481 | BUG_ON(devmap->device != NULL); |
1da177e4 LT |
482 | list_del(&devmap->list); |
483 | kfree(devmap); | |
484 | } | |
485 | } | |
486 | spin_unlock(&dasd_devmap_lock); | |
487 | } | |
488 | ||
489 | /* | |
490 | * Find the device struct by its device index. | |
491 | */ | |
492 | struct dasd_device * | |
493 | dasd_device_from_devindex(int devindex) | |
494 | { | |
495 | struct dasd_devmap *devmap, *tmp; | |
496 | struct dasd_device *device; | |
497 | int i; | |
498 | ||
499 | spin_lock(&dasd_devmap_lock); | |
d2c993d8 | 500 | devmap = NULL; |
1da177e4 LT |
501 | for (i = 0; (i < 256) && !devmap; i++) |
502 | list_for_each_entry(tmp, &dasd_hashlists[i], list) | |
503 | if (tmp->devindex == devindex) { | |
504 | /* Found the devmap for the device. */ | |
505 | devmap = tmp; | |
506 | break; | |
507 | } | |
508 | if (devmap && devmap->device) { | |
509 | device = devmap->device; | |
510 | dasd_get_device(device); | |
511 | } else | |
512 | device = ERR_PTR(-ENODEV); | |
513 | spin_unlock(&dasd_devmap_lock); | |
514 | return device; | |
515 | } | |
516 | ||
517 | /* | |
518 | * Return devmap for cdev. If no devmap exists yet, create one and | |
519 | * connect it to the cdev. | |
520 | */ | |
521 | static struct dasd_devmap * | |
522 | dasd_devmap_from_cdev(struct ccw_device *cdev) | |
523 | { | |
524 | struct dasd_devmap *devmap; | |
525 | ||
2a0217d5 | 526 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
1da177e4 | 527 | if (IS_ERR(devmap)) |
2a0217d5 | 528 | devmap = dasd_add_busid(dev_name(&cdev->dev), |
1da177e4 LT |
529 | DASD_FEATURE_DEFAULT); |
530 | return devmap; | |
531 | } | |
532 | ||
533 | /* | |
534 | * Create a dasd device structure for cdev. | |
535 | */ | |
536 | struct dasd_device * | |
537 | dasd_create_device(struct ccw_device *cdev) | |
538 | { | |
539 | struct dasd_devmap *devmap; | |
540 | struct dasd_device *device; | |
a00bfd71 | 541 | unsigned long flags; |
1da177e4 LT |
542 | int rc; |
543 | ||
544 | devmap = dasd_devmap_from_cdev(cdev); | |
545 | if (IS_ERR(devmap)) | |
546 | return (void *) devmap; | |
1da177e4 LT |
547 | |
548 | device = dasd_alloc_device(); | |
549 | if (IS_ERR(device)) | |
550 | return device; | |
a00bfd71 | 551 | atomic_set(&device->ref_count, 3); |
1da177e4 LT |
552 | |
553 | spin_lock(&dasd_devmap_lock); | |
554 | if (!devmap->device) { | |
555 | devmap->device = device; | |
556 | device->devindex = devmap->devindex; | |
c6eb7b77 | 557 | device->features = devmap->features; |
1da177e4 LT |
558 | get_device(&cdev->dev); |
559 | device->cdev = cdev; | |
560 | rc = 0; | |
561 | } else | |
562 | /* Someone else was faster. */ | |
563 | rc = -EBUSY; | |
564 | spin_unlock(&dasd_devmap_lock); | |
565 | ||
566 | if (rc) { | |
567 | dasd_free_device(device); | |
568 | return ERR_PTR(rc); | |
569 | } | |
a00bfd71 MS |
570 | |
571 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); | |
faf16aa9 | 572 | dev_set_drvdata(&cdev->dev, device); |
a00bfd71 MS |
573 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
574 | ||
1da177e4 LT |
575 | return device; |
576 | } | |
577 | ||
578 | /* | |
579 | * Wait queue for dasd_delete_device waits. | |
580 | */ | |
581 | static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq); | |
582 | ||
583 | /* | |
584 | * Remove a dasd device structure. The passed referenced | |
585 | * is destroyed. | |
586 | */ | |
587 | void | |
588 | dasd_delete_device(struct dasd_device *device) | |
589 | { | |
590 | struct ccw_device *cdev; | |
591 | struct dasd_devmap *devmap; | |
a00bfd71 | 592 | unsigned long flags; |
1da177e4 LT |
593 | |
594 | /* First remove device pointer from devmap. */ | |
2a0217d5 | 595 | devmap = dasd_find_busid(dev_name(&device->cdev->dev)); |
606f4422 | 596 | BUG_ON(IS_ERR(devmap)); |
1da177e4 LT |
597 | spin_lock(&dasd_devmap_lock); |
598 | if (devmap->device != device) { | |
599 | spin_unlock(&dasd_devmap_lock); | |
600 | dasd_put_device(device); | |
601 | return; | |
602 | } | |
603 | devmap->device = NULL; | |
604 | spin_unlock(&dasd_devmap_lock); | |
605 | ||
a00bfd71 MS |
606 | /* Disconnect dasd_device structure from ccw_device structure. */ |
607 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
faf16aa9 | 608 | dev_set_drvdata(&device->cdev->dev, NULL); |
a00bfd71 MS |
609 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
610 | ||
611 | /* | |
612 | * Drop ref_count by 3, one for the devmap reference, one for | |
613 | * the cdev reference and one for the passed reference. | |
614 | */ | |
615 | atomic_sub(3, &device->ref_count); | |
1da177e4 LT |
616 | |
617 | /* Wait for reference counter to drop to zero. */ | |
618 | wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0); | |
619 | ||
c020d722 | 620 | dasd_generic_free_discipline(device); |
1da177e4 LT |
621 | /* Disconnect dasd_device structure from ccw_device structure. */ |
622 | cdev = device->cdev; | |
623 | device->cdev = NULL; | |
624 | ||
1da177e4 LT |
625 | /* Put ccw_device structure. */ |
626 | put_device(&cdev->dev); | |
627 | ||
628 | /* Now the device structure can be freed. */ | |
629 | dasd_free_device(device); | |
630 | } | |
631 | ||
632 | /* | |
633 | * Reference counter dropped to zero. Wake up waiter | |
634 | * in dasd_delete_device. | |
635 | */ | |
636 | void | |
637 | dasd_put_device_wake(struct dasd_device *device) | |
638 | { | |
639 | wake_up(&dasd_delete_wq); | |
640 | } | |
a4d26c6a | 641 | EXPORT_SYMBOL_GPL(dasd_put_device_wake); |
1da177e4 | 642 | |
a00bfd71 MS |
643 | /* |
644 | * Return dasd_device structure associated with cdev. | |
645 | * This function needs to be called with the ccw device | |
646 | * lock held. It can be used from interrupt context. | |
647 | */ | |
648 | struct dasd_device * | |
649 | dasd_device_from_cdev_locked(struct ccw_device *cdev) | |
650 | { | |
faf16aa9 | 651 | struct dasd_device *device = dev_get_drvdata(&cdev->dev); |
a00bfd71 MS |
652 | |
653 | if (!device) | |
654 | return ERR_PTR(-ENODEV); | |
655 | dasd_get_device(device); | |
656 | return device; | |
657 | } | |
658 | ||
1da177e4 LT |
659 | /* |
660 | * Return dasd_device structure associated with cdev. | |
661 | */ | |
662 | struct dasd_device * | |
663 | dasd_device_from_cdev(struct ccw_device *cdev) | |
664 | { | |
1da177e4 | 665 | struct dasd_device *device; |
a00bfd71 | 666 | unsigned long flags; |
1da177e4 | 667 | |
a00bfd71 MS |
668 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
669 | device = dasd_device_from_cdev_locked(cdev); | |
670 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); | |
1da177e4 LT |
671 | return device; |
672 | } | |
673 | ||
65f8da47 SW |
674 | void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device) |
675 | { | |
676 | struct dasd_devmap *devmap; | |
677 | ||
678 | devmap = dasd_find_busid(dev_name(&device->cdev->dev)); | |
679 | if (IS_ERR(devmap)) | |
680 | return; | |
681 | spin_lock(&dasd_devmap_lock); | |
682 | gdp->private_data = devmap; | |
683 | spin_unlock(&dasd_devmap_lock); | |
684 | } | |
685 | ||
686 | struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp) | |
687 | { | |
688 | struct dasd_device *device; | |
689 | struct dasd_devmap *devmap; | |
690 | ||
691 | if (!gdp->private_data) | |
692 | return NULL; | |
693 | device = NULL; | |
694 | spin_lock(&dasd_devmap_lock); | |
695 | devmap = gdp->private_data; | |
696 | if (devmap && devmap->device) { | |
697 | device = devmap->device; | |
698 | dasd_get_device(device); | |
699 | } | |
700 | spin_unlock(&dasd_devmap_lock); | |
701 | return device; | |
702 | } | |
703 | ||
1da177e4 LT |
704 | /* |
705 | * SECTION: files in sysfs | |
706 | */ | |
707 | ||
13de227b HS |
708 | /* |
709 | * failfast controls the behaviour, if no path is available | |
710 | */ | |
711 | static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr, | |
712 | char *buf) | |
713 | { | |
714 | struct dasd_devmap *devmap; | |
715 | int ff_flag; | |
716 | ||
ca0b4b7d | 717 | devmap = dasd_find_busid(dev_name(dev)); |
13de227b HS |
718 | if (!IS_ERR(devmap)) |
719 | ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0; | |
720 | else | |
721 | ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0; | |
722 | return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n"); | |
723 | } | |
724 | ||
725 | static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr, | |
726 | const char *buf, size_t count) | |
727 | { | |
ce7a788f | 728 | unsigned int val; |
1081f3a7 | 729 | int rc; |
13de227b | 730 | |
ce7a788f | 731 | if (kstrtouint(buf, 0, &val) || val > 1) |
13de227b HS |
732 | return -EINVAL; |
733 | ||
1081f3a7 JH |
734 | rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_FAILFAST, val); |
735 | ||
736 | return rc ? : count; | |
13de227b HS |
737 | } |
738 | ||
739 | static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store); | |
740 | ||
1da177e4 LT |
741 | /* |
742 | * readonly controls the readonly status of a dasd | |
743 | */ | |
744 | static ssize_t | |
e404e274 | 745 | dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf) |
1da177e4 LT |
746 | { |
747 | struct dasd_devmap *devmap; | |
748 | int ro_flag; | |
749 | ||
2a0217d5 | 750 | devmap = dasd_find_busid(dev_name(dev)); |
1da177e4 LT |
751 | if (!IS_ERR(devmap)) |
752 | ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0; | |
753 | else | |
754 | ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0; | |
755 | return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n"); | |
756 | } | |
757 | ||
758 | static ssize_t | |
138c014d HH |
759 | dasd_ro_store(struct device *dev, struct device_attribute *attr, |
760 | const char *buf, size_t count) | |
1da177e4 | 761 | { |
1081f3a7 | 762 | struct ccw_device *cdev = to_ccwdev(dev); |
33b62a30 | 763 | struct dasd_device *device; |
9f9d53e5 | 764 | unsigned long flags; |
ce7a788f | 765 | unsigned int val; |
1081f3a7 | 766 | int rc; |
01376f44 | 767 | |
ce7a788f | 768 | if (kstrtouint(buf, 0, &val) || val > 1) |
01376f44 HH |
769 | return -EINVAL; |
770 | ||
1081f3a7 JH |
771 | rc = dasd_set_feature(cdev, DASD_FEATURE_READONLY, val); |
772 | if (rc) | |
773 | return rc; | |
774 | ||
775 | device = dasd_device_from_cdev(cdev); | |
776 | if (IS_ERR(device)) | |
777 | return PTR_ERR(device); | |
778 | ||
9f9d53e5 | 779 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
1081f3a7 | 780 | val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags); |
1081f3a7 | 781 | |
9f9d53e5 JH |
782 | if (!device->block || !device->block->gdp || |
783 | test_bit(DASD_FLAG_OFFLINE, &device->flags)) { | |
784 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); | |
785 | goto out; | |
786 | } | |
787 | /* Increase open_count to avoid losing the block device */ | |
788 | atomic_inc(&device->block->open_count); | |
789 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); | |
790 | ||
791 | set_disk_ro(device->block->gdp, val); | |
792 | atomic_dec(&device->block->open_count); | |
793 | ||
794 | out: | |
1081f3a7 JH |
795 | dasd_put_device(device); |
796 | ||
1da177e4 LT |
797 | return count; |
798 | } | |
799 | ||
800 | static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store); | |
9575bf26 HH |
801 | /* |
802 | * erplog controls the logging of ERP related data | |
803 | * (e.g. failing channel programs). | |
804 | */ | |
805 | static ssize_t | |
806 | dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf) | |
807 | { | |
808 | struct dasd_devmap *devmap; | |
809 | int erplog; | |
810 | ||
2a0217d5 | 811 | devmap = dasd_find_busid(dev_name(dev)); |
9575bf26 HH |
812 | if (!IS_ERR(devmap)) |
813 | erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0; | |
814 | else | |
815 | erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0; | |
816 | return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n"); | |
817 | } | |
818 | ||
819 | static ssize_t | |
820 | dasd_erplog_store(struct device *dev, struct device_attribute *attr, | |
821 | const char *buf, size_t count) | |
822 | { | |
ce7a788f | 823 | unsigned int val; |
1081f3a7 | 824 | int rc; |
9575bf26 | 825 | |
ce7a788f | 826 | if (kstrtouint(buf, 0, &val) || val > 1) |
9575bf26 HH |
827 | return -EINVAL; |
828 | ||
1081f3a7 JH |
829 | rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_ERPLOG, val); |
830 | ||
831 | return rc ? : count; | |
9575bf26 HH |
832 | } |
833 | ||
834 | static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store); | |
1da177e4 LT |
835 | |
836 | /* | |
837 | * use_diag controls whether the driver should use diag rather than ssch | |
838 | * to talk to the device | |
839 | */ | |
138c014d | 840 | static ssize_t |
e404e274 | 841 | dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf) |
1da177e4 LT |
842 | { |
843 | struct dasd_devmap *devmap; | |
844 | int use_diag; | |
845 | ||
2a0217d5 | 846 | devmap = dasd_find_busid(dev_name(dev)); |
1da177e4 LT |
847 | if (!IS_ERR(devmap)) |
848 | use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0; | |
849 | else | |
850 | use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0; | |
851 | return sprintf(buf, use_diag ? "1\n" : "0\n"); | |
852 | } | |
853 | ||
854 | static ssize_t | |
138c014d HH |
855 | dasd_use_diag_store(struct device *dev, struct device_attribute *attr, |
856 | const char *buf, size_t count) | |
1da177e4 LT |
857 | { |
858 | struct dasd_devmap *devmap; | |
ce7a788f | 859 | unsigned int val; |
1da177e4 | 860 | ssize_t rc; |
1da177e4 LT |
861 | |
862 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | |
863 | if (IS_ERR(devmap)) | |
864 | return PTR_ERR(devmap); | |
01376f44 | 865 | |
ce7a788f | 866 | if (kstrtouint(buf, 0, &val) || val > 1) |
01376f44 HH |
867 | return -EINVAL; |
868 | ||
1da177e4 LT |
869 | spin_lock(&dasd_devmap_lock); |
870 | /* Changing diag discipline flag is only allowed in offline state. */ | |
871 | rc = count; | |
e4dbb0f2 | 872 | if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) { |
01376f44 | 873 | if (val) |
1da177e4 LT |
874 | devmap->features |= DASD_FEATURE_USEDIAG; |
875 | else | |
876 | devmap->features &= ~DASD_FEATURE_USEDIAG; | |
877 | } else | |
878 | rc = -EPERM; | |
879 | spin_unlock(&dasd_devmap_lock); | |
880 | return rc; | |
881 | } | |
882 | ||
138c014d | 883 | static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store); |
1da177e4 | 884 | |
e4dbb0f2 SH |
885 | /* |
886 | * use_raw controls whether the driver should give access to raw eckd data or | |
887 | * operate in standard mode | |
888 | */ | |
889 | static ssize_t | |
890 | dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf) | |
891 | { | |
892 | struct dasd_devmap *devmap; | |
893 | int use_raw; | |
894 | ||
895 | devmap = dasd_find_busid(dev_name(dev)); | |
896 | if (!IS_ERR(devmap)) | |
897 | use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0; | |
898 | else | |
899 | use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0; | |
900 | return sprintf(buf, use_raw ? "1\n" : "0\n"); | |
901 | } | |
902 | ||
903 | static ssize_t | |
904 | dasd_use_raw_store(struct device *dev, struct device_attribute *attr, | |
905 | const char *buf, size_t count) | |
906 | { | |
907 | struct dasd_devmap *devmap; | |
908 | ssize_t rc; | |
909 | unsigned long val; | |
910 | ||
911 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | |
912 | if (IS_ERR(devmap)) | |
913 | return PTR_ERR(devmap); | |
914 | ||
0178722b | 915 | if ((kstrtoul(buf, 10, &val) != 0) || val > 1) |
e4dbb0f2 SH |
916 | return -EINVAL; |
917 | ||
918 | spin_lock(&dasd_devmap_lock); | |
919 | /* Changing diag discipline flag is only allowed in offline state. */ | |
920 | rc = count; | |
921 | if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) { | |
922 | if (val) | |
923 | devmap->features |= DASD_FEATURE_USERAW; | |
924 | else | |
925 | devmap->features &= ~DASD_FEATURE_USERAW; | |
926 | } else | |
927 | rc = -EPERM; | |
928 | spin_unlock(&dasd_devmap_lock); | |
929 | return rc; | |
930 | } | |
931 | ||
932 | static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show, | |
933 | dasd_use_raw_store); | |
934 | ||
d07dc5d8 SH |
935 | static ssize_t |
936 | dasd_safe_offline_store(struct device *dev, struct device_attribute *attr, | |
937 | const char *buf, size_t count) | |
938 | { | |
939 | struct ccw_device *cdev = to_ccwdev(dev); | |
940 | struct dasd_device *device; | |
941 | int rc; | |
942 | ||
943 | device = dasd_device_from_cdev(cdev); | |
944 | if (IS_ERR(device)) { | |
945 | rc = PTR_ERR(device); | |
946 | goto out; | |
947 | } | |
948 | ||
949 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags) || | |
950 | test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { | |
951 | /* Already doing offline processing */ | |
952 | dasd_put_device(device); | |
953 | rc = -EBUSY; | |
954 | goto out; | |
955 | } | |
956 | ||
957 | set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags); | |
958 | dasd_put_device(device); | |
959 | ||
960 | rc = ccw_device_set_offline(cdev); | |
961 | ||
962 | out: | |
963 | return rc ? rc : count; | |
964 | } | |
965 | ||
966 | static DEVICE_ATTR(safe_offline, 0200, NULL, dasd_safe_offline_store); | |
967 | ||
5a3b7b11 SH |
968 | static ssize_t |
969 | dasd_access_show(struct device *dev, struct device_attribute *attr, | |
970 | char *buf) | |
971 | { | |
972 | struct ccw_device *cdev = to_ccwdev(dev); | |
973 | struct dasd_device *device; | |
974 | int count; | |
975 | ||
976 | device = dasd_device_from_cdev(cdev); | |
977 | if (IS_ERR(device)) | |
978 | return PTR_ERR(device); | |
979 | ||
a521b048 SH |
980 | if (!device->discipline) |
981 | count = -ENODEV; | |
982 | else if (!device->discipline->host_access_count) | |
5a3b7b11 | 983 | count = -EOPNOTSUPP; |
a521b048 SH |
984 | else |
985 | count = device->discipline->host_access_count(device); | |
5a3b7b11 SH |
986 | |
987 | dasd_put_device(device); | |
988 | if (count < 0) | |
989 | return count; | |
990 | ||
991 | return sprintf(buf, "%d\n", count); | |
992 | } | |
993 | ||
994 | static DEVICE_ATTR(host_access_count, 0444, dasd_access_show, NULL); | |
995 | ||
1da177e4 | 996 | static ssize_t |
138c014d HH |
997 | dasd_discipline_show(struct device *dev, struct device_attribute *attr, |
998 | char *buf) | |
1da177e4 | 999 | { |
a00bfd71 MS |
1000 | struct dasd_device *device; |
1001 | ssize_t len; | |
1da177e4 | 1002 | |
a00bfd71 | 1003 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
589c74d5 SH |
1004 | if (IS_ERR(device)) |
1005 | goto out; | |
1006 | else if (!device->discipline) { | |
1007 | dasd_put_device(device); | |
1008 | goto out; | |
1009 | } else { | |
a00bfd71 MS |
1010 | len = snprintf(buf, PAGE_SIZE, "%s\n", |
1011 | device->discipline->name); | |
1012 | dasd_put_device(device); | |
589c74d5 SH |
1013 | return len; |
1014 | } | |
1015 | out: | |
1016 | len = snprintf(buf, PAGE_SIZE, "none\n"); | |
a00bfd71 | 1017 | return len; |
1da177e4 LT |
1018 | } |
1019 | ||
1020 | static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL); | |
1021 | ||
4dfd5c45 HH |
1022 | static ssize_t |
1023 | dasd_device_status_show(struct device *dev, struct device_attribute *attr, | |
1024 | char *buf) | |
1025 | { | |
1026 | struct dasd_device *device; | |
1027 | ssize_t len; | |
1028 | ||
1029 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1030 | if (!IS_ERR(device)) { | |
1031 | switch (device->state) { | |
1032 | case DASD_STATE_NEW: | |
1033 | len = snprintf(buf, PAGE_SIZE, "new\n"); | |
1034 | break; | |
1035 | case DASD_STATE_KNOWN: | |
1036 | len = snprintf(buf, PAGE_SIZE, "detected\n"); | |
1037 | break; | |
1038 | case DASD_STATE_BASIC: | |
1039 | len = snprintf(buf, PAGE_SIZE, "basic\n"); | |
1040 | break; | |
1041 | case DASD_STATE_UNFMT: | |
1042 | len = snprintf(buf, PAGE_SIZE, "unformatted\n"); | |
1043 | break; | |
1044 | case DASD_STATE_READY: | |
1045 | len = snprintf(buf, PAGE_SIZE, "ready\n"); | |
1046 | break; | |
1047 | case DASD_STATE_ONLINE: | |
1048 | len = snprintf(buf, PAGE_SIZE, "online\n"); | |
1049 | break; | |
1050 | default: | |
1051 | len = snprintf(buf, PAGE_SIZE, "no stat\n"); | |
1052 | break; | |
1053 | } | |
1054 | dasd_put_device(device); | |
1055 | } else | |
1056 | len = snprintf(buf, PAGE_SIZE, "unknown\n"); | |
1057 | return len; | |
1058 | } | |
1059 | ||
1060 | static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL); | |
1061 | ||
2dedf0d9 SH |
1062 | static ssize_t dasd_alias_show(struct device *dev, |
1063 | struct device_attribute *attr, char *buf) | |
3d052595 | 1064 | { |
2dedf0d9 SH |
1065 | struct dasd_device *device; |
1066 | struct dasd_uid uid; | |
3d052595 | 1067 | |
2dedf0d9 SH |
1068 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
1069 | if (IS_ERR(device)) | |
8e09f215 | 1070 | return sprintf(buf, "0\n"); |
2dedf0d9 SH |
1071 | |
1072 | if (device->discipline && device->discipline->get_uid && | |
1073 | !device->discipline->get_uid(device, &uid)) { | |
1074 | if (uid.type == UA_BASE_PAV_ALIAS || | |
0abccf77 SH |
1075 | uid.type == UA_HYPER_PAV_ALIAS) { |
1076 | dasd_put_device(device); | |
2dedf0d9 | 1077 | return sprintf(buf, "1\n"); |
0abccf77 | 1078 | } |
8e09f215 | 1079 | } |
2dedf0d9 SH |
1080 | dasd_put_device(device); |
1081 | ||
1082 | return sprintf(buf, "0\n"); | |
3d052595 HH |
1083 | } |
1084 | ||
1085 | static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL); | |
1086 | ||
2dedf0d9 SH |
1087 | static ssize_t dasd_vendor_show(struct device *dev, |
1088 | struct device_attribute *attr, char *buf) | |
3d052595 | 1089 | { |
2dedf0d9 SH |
1090 | struct dasd_device *device; |
1091 | struct dasd_uid uid; | |
3d052595 HH |
1092 | char *vendor; |
1093 | ||
2dedf0d9 SH |
1094 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
1095 | vendor = ""; | |
1096 | if (IS_ERR(device)) | |
1097 | return snprintf(buf, PAGE_SIZE, "%s\n", vendor); | |
1098 | ||
1099 | if (device->discipline && device->discipline->get_uid && | |
1100 | !device->discipline->get_uid(device, &uid)) | |
1101 | vendor = uid.vendor; | |
1102 | ||
1103 | dasd_put_device(device); | |
3d052595 HH |
1104 | |
1105 | return snprintf(buf, PAGE_SIZE, "%s\n", vendor); | |
1106 | } | |
1107 | ||
1108 | static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL); | |
1109 | ||
1110 | #define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\ | |
4abb08c2 SW |
1111 | /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\ |
1112 | /* vduit */ 32 + 1) | |
3d052595 HH |
1113 | |
1114 | static ssize_t | |
1115 | dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1116 | { | |
2dedf0d9 SH |
1117 | struct dasd_device *device; |
1118 | struct dasd_uid uid; | |
8e09f215 SW |
1119 | char uid_string[UID_STRLEN]; |
1120 | char ua_string[3]; | |
3d052595 | 1121 | |
2dedf0d9 SH |
1122 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
1123 | uid_string[0] = 0; | |
1124 | if (IS_ERR(device)) | |
1125 | return snprintf(buf, PAGE_SIZE, "%s\n", uid_string); | |
1126 | ||
1127 | if (device->discipline && device->discipline->get_uid && | |
1128 | !device->discipline->get_uid(device, &uid)) { | |
1129 | switch (uid.type) { | |
1130 | case UA_BASE_DEVICE: | |
1131 | snprintf(ua_string, sizeof(ua_string), "%02x", | |
1132 | uid.real_unit_addr); | |
1133 | break; | |
1134 | case UA_BASE_PAV_ALIAS: | |
1135 | snprintf(ua_string, sizeof(ua_string), "%02x", | |
1136 | uid.base_unit_addr); | |
1137 | break; | |
1138 | case UA_HYPER_PAV_ALIAS: | |
1139 | snprintf(ua_string, sizeof(ua_string), "xx"); | |
1140 | break; | |
1141 | default: | |
1142 | /* should not happen, treat like base device */ | |
1143 | snprintf(ua_string, sizeof(ua_string), "%02x", | |
1144 | uid.real_unit_addr); | |
1145 | break; | |
1146 | } | |
1147 | ||
1148 | if (strlen(uid.vduit) > 0) | |
1149 | snprintf(uid_string, sizeof(uid_string), | |
1150 | "%s.%s.%04x.%s.%s", | |
1151 | uid.vendor, uid.serial, uid.ssid, ua_string, | |
1152 | uid.vduit); | |
1153 | else | |
1154 | snprintf(uid_string, sizeof(uid_string), | |
1155 | "%s.%s.%04x.%s", | |
1156 | uid.vendor, uid.serial, uid.ssid, ua_string); | |
8e09f215 | 1157 | } |
2dedf0d9 SH |
1158 | dasd_put_device(device); |
1159 | ||
8e09f215 | 1160 | return snprintf(buf, PAGE_SIZE, "%s\n", uid_string); |
3d052595 | 1161 | } |
3d052595 HH |
1162 | static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL); |
1163 | ||
20c64468 SW |
1164 | /* |
1165 | * extended error-reporting | |
1166 | */ | |
1167 | static ssize_t | |
1168 | dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1169 | { | |
1170 | struct dasd_devmap *devmap; | |
1171 | int eer_flag; | |
1172 | ||
2a0217d5 | 1173 | devmap = dasd_find_busid(dev_name(dev)); |
20c64468 SW |
1174 | if (!IS_ERR(devmap) && devmap->device) |
1175 | eer_flag = dasd_eer_enabled(devmap->device); | |
1176 | else | |
1177 | eer_flag = 0; | |
1178 | return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n"); | |
1179 | } | |
1180 | ||
1181 | static ssize_t | |
1182 | dasd_eer_store(struct device *dev, struct device_attribute *attr, | |
1183 | const char *buf, size_t count) | |
1184 | { | |
9de67725 | 1185 | struct dasd_device *device; |
ce7a788f | 1186 | unsigned int val; |
9de67725 | 1187 | int rc = 0; |
20c64468 | 1188 | |
9de67725 JH |
1189 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
1190 | if (IS_ERR(device)) | |
1191 | return PTR_ERR(device); | |
01376f44 | 1192 | |
ce7a788f | 1193 | if (kstrtouint(buf, 0, &val) || val > 1) |
01376f44 HH |
1194 | return -EINVAL; |
1195 | ||
9de67725 JH |
1196 | if (val) |
1197 | rc = dasd_eer_enable(device); | |
1198 | else | |
1199 | dasd_eer_disable(device); | |
1200 | ||
1201 | dasd_put_device(device); | |
1202 | ||
1203 | return rc ? : count; | |
20c64468 SW |
1204 | } |
1205 | ||
1206 | static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store); | |
1207 | ||
7c8faa86 SH |
1208 | /* |
1209 | * expiration time for default requests | |
1210 | */ | |
1211 | static ssize_t | |
1212 | dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1213 | { | |
1214 | struct dasd_device *device; | |
1215 | int len; | |
1216 | ||
1217 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1218 | if (IS_ERR(device)) | |
1219 | return -ENODEV; | |
1220 | len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_expires); | |
1221 | dasd_put_device(device); | |
1222 | return len; | |
1223 | } | |
1224 | ||
1225 | static ssize_t | |
1226 | dasd_expires_store(struct device *dev, struct device_attribute *attr, | |
1227 | const char *buf, size_t count) | |
1228 | { | |
1229 | struct dasd_device *device; | |
1230 | unsigned long val; | |
1231 | ||
1232 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1233 | if (IS_ERR(device)) | |
1234 | return -ENODEV; | |
1235 | ||
0178722b | 1236 | if ((kstrtoul(buf, 10, &val) != 0) || |
7c8faa86 SH |
1237 | (val > DASD_EXPIRES_MAX) || val == 0) { |
1238 | dasd_put_device(device); | |
1239 | return -EINVAL; | |
1240 | } | |
1241 | ||
1242 | if (val) | |
1243 | device->default_expires = val; | |
1244 | ||
1245 | dasd_put_device(device); | |
1246 | return count; | |
1247 | } | |
1248 | ||
1249 | static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store); | |
1250 | ||
1f1ee9ad HR |
1251 | static ssize_t |
1252 | dasd_retries_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1253 | { | |
1254 | struct dasd_device *device; | |
1255 | int len; | |
1256 | ||
1257 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1258 | if (IS_ERR(device)) | |
1259 | return -ENODEV; | |
1260 | len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_retries); | |
1261 | dasd_put_device(device); | |
1262 | return len; | |
1263 | } | |
1264 | ||
1265 | static ssize_t | |
1266 | dasd_retries_store(struct device *dev, struct device_attribute *attr, | |
1267 | const char *buf, size_t count) | |
1268 | { | |
1269 | struct dasd_device *device; | |
1270 | unsigned long val; | |
1271 | ||
1272 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1273 | if (IS_ERR(device)) | |
1274 | return -ENODEV; | |
1275 | ||
0178722b | 1276 | if ((kstrtoul(buf, 10, &val) != 0) || |
1f1ee9ad HR |
1277 | (val > DASD_RETRIES_MAX)) { |
1278 | dasd_put_device(device); | |
1279 | return -EINVAL; | |
1280 | } | |
1281 | ||
1282 | if (val) | |
1283 | device->default_retries = val; | |
1284 | ||
1285 | dasd_put_device(device); | |
1286 | return count; | |
1287 | } | |
1288 | ||
1289 | static DEVICE_ATTR(retries, 0644, dasd_retries_show, dasd_retries_store); | |
1290 | ||
3d71ad32 HR |
1291 | static ssize_t |
1292 | dasd_timeout_show(struct device *dev, struct device_attribute *attr, | |
1293 | char *buf) | |
1294 | { | |
1295 | struct dasd_device *device; | |
1296 | int len; | |
1297 | ||
1298 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1299 | if (IS_ERR(device)) | |
1300 | return -ENODEV; | |
1301 | len = snprintf(buf, PAGE_SIZE, "%lu\n", device->blk_timeout); | |
1302 | dasd_put_device(device); | |
1303 | return len; | |
1304 | } | |
1305 | ||
1306 | static ssize_t | |
1307 | dasd_timeout_store(struct device *dev, struct device_attribute *attr, | |
1308 | const char *buf, size_t count) | |
1309 | { | |
1310 | struct dasd_device *device; | |
1311 | struct request_queue *q; | |
1312 | unsigned long val, flags; | |
1313 | ||
1314 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1315 | if (IS_ERR(device) || !device->block) | |
1316 | return -ENODEV; | |
1317 | ||
0178722b | 1318 | if ((kstrtoul(buf, 10, &val) != 0) || |
3d71ad32 HR |
1319 | val > UINT_MAX / HZ) { |
1320 | dasd_put_device(device); | |
1321 | return -EINVAL; | |
1322 | } | |
1323 | q = device->block->request_queue; | |
1324 | if (!q) { | |
1325 | dasd_put_device(device); | |
1326 | return -ENODEV; | |
1327 | } | |
1328 | spin_lock_irqsave(&device->block->request_queue_lock, flags); | |
1329 | if (!val) | |
1330 | blk_queue_rq_timed_out(q, NULL); | |
1331 | else | |
1332 | blk_queue_rq_timed_out(q, dasd_times_out); | |
1333 | ||
1334 | device->blk_timeout = val; | |
1335 | ||
1336 | blk_queue_rq_timeout(q, device->blk_timeout * HZ); | |
1337 | spin_unlock_irqrestore(&device->block->request_queue_lock, flags); | |
1338 | ||
1339 | dasd_put_device(device); | |
1340 | return count; | |
1341 | } | |
1342 | ||
1343 | static DEVICE_ATTR(timeout, 0644, | |
1344 | dasd_timeout_show, dasd_timeout_store); | |
1345 | ||
a521b048 SH |
1346 | |
1347 | static ssize_t | |
1348 | dasd_path_reset_store(struct device *dev, struct device_attribute *attr, | |
1349 | const char *buf, size_t count) | |
1350 | { | |
1351 | struct dasd_device *device; | |
1352 | unsigned int val; | |
1353 | ||
1354 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1355 | if (IS_ERR(device)) | |
1356 | return -ENODEV; | |
1357 | ||
1358 | if ((kstrtouint(buf, 16, &val) != 0) || val > 0xff) | |
1359 | val = 0; | |
1360 | ||
1361 | if (device->discipline && device->discipline->reset_path) | |
1362 | device->discipline->reset_path(device, (__u8) val); | |
1363 | ||
1364 | dasd_put_device(device); | |
1365 | return count; | |
1366 | } | |
1367 | ||
1368 | static DEVICE_ATTR(path_reset, 0200, NULL, dasd_path_reset_store); | |
1369 | ||
1370 | static ssize_t dasd_hpf_show(struct device *dev, struct device_attribute *attr, | |
1371 | char *buf) | |
1372 | { | |
1373 | struct dasd_device *device; | |
1374 | int hpf; | |
1375 | ||
1376 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1377 | if (IS_ERR(device)) | |
1378 | return -ENODEV; | |
1379 | if (!device->discipline || !device->discipline->hpf_enabled) { | |
1380 | dasd_put_device(device); | |
1381 | return snprintf(buf, PAGE_SIZE, "%d\n", dasd_nofcx); | |
1382 | } | |
1383 | hpf = device->discipline->hpf_enabled(device); | |
1384 | dasd_put_device(device); | |
1385 | return snprintf(buf, PAGE_SIZE, "%d\n", hpf); | |
1386 | } | |
1387 | ||
1388 | static DEVICE_ATTR(hpf, 0444, dasd_hpf_show, NULL); | |
1389 | ||
5a27e60d SW |
1390 | static ssize_t dasd_reservation_policy_show(struct device *dev, |
1391 | struct device_attribute *attr, | |
1392 | char *buf) | |
1393 | { | |
1394 | struct dasd_devmap *devmap; | |
1395 | int rc = 0; | |
1396 | ||
1397 | devmap = dasd_find_busid(dev_name(dev)); | |
1398 | if (IS_ERR(devmap)) { | |
1399 | rc = snprintf(buf, PAGE_SIZE, "ignore\n"); | |
1400 | } else { | |
1401 | spin_lock(&dasd_devmap_lock); | |
1402 | if (devmap->features & DASD_FEATURE_FAILONSLCK) | |
1403 | rc = snprintf(buf, PAGE_SIZE, "fail\n"); | |
1404 | else | |
1405 | rc = snprintf(buf, PAGE_SIZE, "ignore\n"); | |
1406 | spin_unlock(&dasd_devmap_lock); | |
1407 | } | |
1408 | return rc; | |
1409 | } | |
1410 | ||
1411 | static ssize_t dasd_reservation_policy_store(struct device *dev, | |
1412 | struct device_attribute *attr, | |
1413 | const char *buf, size_t count) | |
1414 | { | |
1081f3a7 | 1415 | struct ccw_device *cdev = to_ccwdev(dev); |
5a27e60d SW |
1416 | int rc; |
1417 | ||
5a27e60d | 1418 | if (sysfs_streq("ignore", buf)) |
1081f3a7 | 1419 | rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 0); |
5a27e60d | 1420 | else if (sysfs_streq("fail", buf)) |
1081f3a7 | 1421 | rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 1); |
5a27e60d SW |
1422 | else |
1423 | rc = -EINVAL; | |
1081f3a7 JH |
1424 | |
1425 | return rc ? : count; | |
5a27e60d SW |
1426 | } |
1427 | ||
1428 | static DEVICE_ATTR(reservation_policy, 0644, | |
1429 | dasd_reservation_policy_show, dasd_reservation_policy_store); | |
1430 | ||
1431 | static ssize_t dasd_reservation_state_show(struct device *dev, | |
1432 | struct device_attribute *attr, | |
1433 | char *buf) | |
1434 | { | |
1435 | struct dasd_device *device; | |
1436 | int rc = 0; | |
1437 | ||
1438 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1439 | if (IS_ERR(device)) | |
1440 | return snprintf(buf, PAGE_SIZE, "none\n"); | |
1441 | ||
1442 | if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) | |
1443 | rc = snprintf(buf, PAGE_SIZE, "reserved\n"); | |
1444 | else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) | |
1445 | rc = snprintf(buf, PAGE_SIZE, "lost\n"); | |
1446 | else | |
1447 | rc = snprintf(buf, PAGE_SIZE, "none\n"); | |
1448 | dasd_put_device(device); | |
1449 | return rc; | |
1450 | } | |
1451 | ||
1452 | static ssize_t dasd_reservation_state_store(struct device *dev, | |
1453 | struct device_attribute *attr, | |
1454 | const char *buf, size_t count) | |
1455 | { | |
1456 | struct dasd_device *device; | |
1457 | int rc = 0; | |
1458 | ||
1459 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1460 | if (IS_ERR(device)) | |
1461 | return -ENODEV; | |
1462 | if (sysfs_streq("reset", buf)) | |
1463 | clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags); | |
1464 | else | |
1465 | rc = -EINVAL; | |
1466 | dasd_put_device(device); | |
1467 | ||
1468 | if (rc) | |
1469 | return rc; | |
1470 | else | |
1471 | return count; | |
1472 | } | |
1473 | ||
1474 | static DEVICE_ATTR(last_known_reservation_state, 0644, | |
1475 | dasd_reservation_state_show, dasd_reservation_state_store); | |
1476 | ||
5db8440c SH |
1477 | static ssize_t dasd_pm_show(struct device *dev, |
1478 | struct device_attribute *attr, char *buf) | |
1479 | { | |
1480 | struct dasd_device *device; | |
a521b048 | 1481 | u8 opm, nppm, cablepm, cuirpm, hpfpm, ifccpm; |
5db8440c SH |
1482 | |
1483 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1484 | if (IS_ERR(device)) | |
1485 | return sprintf(buf, "0\n"); | |
1486 | ||
c9346151 SH |
1487 | opm = dasd_path_get_opm(device); |
1488 | nppm = dasd_path_get_nppm(device); | |
1489 | cablepm = dasd_path_get_cablepm(device); | |
1490 | cuirpm = dasd_path_get_cuirpm(device); | |
1491 | hpfpm = dasd_path_get_hpfpm(device); | |
a521b048 | 1492 | ifccpm = dasd_path_get_ifccpm(device); |
5db8440c SH |
1493 | dasd_put_device(device); |
1494 | ||
a521b048 SH |
1495 | return sprintf(buf, "%02x %02x %02x %02x %02x %02x\n", opm, nppm, |
1496 | cablepm, cuirpm, hpfpm, ifccpm); | |
5db8440c SH |
1497 | } |
1498 | ||
1499 | static DEVICE_ATTR(path_masks, 0444, dasd_pm_show, NULL); | |
1500 | ||
a521b048 SH |
1501 | /* |
1502 | * threshold value for IFCC/CCC errors | |
1503 | */ | |
1504 | static ssize_t | |
1505 | dasd_path_threshold_show(struct device *dev, | |
1506 | struct device_attribute *attr, char *buf) | |
1507 | { | |
1508 | struct dasd_device *device; | |
1509 | int len; | |
1510 | ||
1511 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1512 | if (IS_ERR(device)) | |
1513 | return -ENODEV; | |
1514 | len = snprintf(buf, PAGE_SIZE, "%lu\n", device->path_thrhld); | |
1515 | dasd_put_device(device); | |
1516 | return len; | |
1517 | } | |
1518 | ||
1519 | static ssize_t | |
1520 | dasd_path_threshold_store(struct device *dev, struct device_attribute *attr, | |
1521 | const char *buf, size_t count) | |
1522 | { | |
1523 | struct dasd_device *device; | |
1524 | unsigned long flags; | |
1525 | unsigned long val; | |
1526 | ||
1527 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1528 | if (IS_ERR(device)) | |
1529 | return -ENODEV; | |
1530 | ||
1531 | if ((kstrtoul(buf, 10, &val) != 0) || | |
1532 | (val > DASD_THRHLD_MAX) || val == 0) { | |
1533 | dasd_put_device(device); | |
1534 | return -EINVAL; | |
1535 | } | |
1536 | spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags); | |
1537 | if (val) | |
1538 | device->path_thrhld = val; | |
1539 | spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags); | |
1540 | dasd_put_device(device); | |
1541 | return count; | |
1542 | } | |
1543 | ||
1544 | static DEVICE_ATTR(path_threshold, 0644, dasd_path_threshold_show, | |
1545 | dasd_path_threshold_store); | |
1546 | /* | |
1547 | * interval for IFCC/CCC checks | |
1548 | * meaning time with no IFCC/CCC error before the error counter | |
1549 | * gets reset | |
1550 | */ | |
1551 | static ssize_t | |
1552 | dasd_path_interval_show(struct device *dev, | |
1553 | struct device_attribute *attr, char *buf) | |
1554 | { | |
1555 | struct dasd_device *device; | |
1556 | int len; | |
1557 | ||
1558 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1559 | if (IS_ERR(device)) | |
1560 | return -ENODEV; | |
1561 | len = snprintf(buf, PAGE_SIZE, "%lu\n", device->path_interval); | |
1562 | dasd_put_device(device); | |
1563 | return len; | |
1564 | } | |
1565 | ||
1566 | static ssize_t | |
1567 | dasd_path_interval_store(struct device *dev, struct device_attribute *attr, | |
1568 | const char *buf, size_t count) | |
1569 | { | |
1570 | struct dasd_device *device; | |
1571 | unsigned long flags; | |
1572 | unsigned long val; | |
1573 | ||
1574 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1575 | if (IS_ERR(device)) | |
1576 | return -ENODEV; | |
1577 | ||
1578 | if ((kstrtoul(buf, 10, &val) != 0) || | |
1579 | (val > DASD_INTERVAL_MAX) || val == 0) { | |
1580 | dasd_put_device(device); | |
1581 | return -EINVAL; | |
1582 | } | |
1583 | spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags); | |
1584 | if (val) | |
1585 | device->path_interval = val; | |
1586 | spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags); | |
1587 | dasd_put_device(device); | |
1588 | return count; | |
1589 | } | |
1590 | ||
1591 | static DEVICE_ATTR(path_interval, 0644, dasd_path_interval_show, | |
1592 | dasd_path_interval_store); | |
1593 | ||
1594 | ||
1da177e4 LT |
1595 | static struct attribute * dasd_attrs[] = { |
1596 | &dev_attr_readonly.attr, | |
1597 | &dev_attr_discipline.attr, | |
4dfd5c45 | 1598 | &dev_attr_status.attr, |
3d052595 HH |
1599 | &dev_attr_alias.attr, |
1600 | &dev_attr_vendor.attr, | |
1601 | &dev_attr_uid.attr, | |
1da177e4 | 1602 | &dev_attr_use_diag.attr, |
e4dbb0f2 | 1603 | &dev_attr_raw_track_access.attr, |
20c64468 | 1604 | &dev_attr_eer_enabled.attr, |
9575bf26 | 1605 | &dev_attr_erplog.attr, |
13de227b | 1606 | &dev_attr_failfast.attr, |
7c8faa86 | 1607 | &dev_attr_expires.attr, |
1f1ee9ad | 1608 | &dev_attr_retries.attr, |
3d71ad32 | 1609 | &dev_attr_timeout.attr, |
5a27e60d SW |
1610 | &dev_attr_reservation_policy.attr, |
1611 | &dev_attr_last_known_reservation_state.attr, | |
d07dc5d8 | 1612 | &dev_attr_safe_offline.attr, |
5a3b7b11 | 1613 | &dev_attr_host_access_count.attr, |
5db8440c | 1614 | &dev_attr_path_masks.attr, |
a521b048 SH |
1615 | &dev_attr_path_threshold.attr, |
1616 | &dev_attr_path_interval.attr, | |
1617 | &dev_attr_path_reset.attr, | |
1618 | &dev_attr_hpf.attr, | |
1da177e4 LT |
1619 | NULL, |
1620 | }; | |
1621 | ||
1622 | static struct attribute_group dasd_attr_group = { | |
1623 | .attrs = dasd_attrs, | |
1624 | }; | |
1625 | ||
f24acd45 HH |
1626 | /* |
1627 | * Return value of the specified feature. | |
1628 | */ | |
1629 | int | |
1630 | dasd_get_feature(struct ccw_device *cdev, int feature) | |
1631 | { | |
1632 | struct dasd_devmap *devmap; | |
1633 | ||
2a0217d5 | 1634 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
f24acd45 | 1635 | if (IS_ERR(devmap)) |
40545573 | 1636 | return PTR_ERR(devmap); |
f24acd45 HH |
1637 | |
1638 | return ((devmap->features & feature) != 0); | |
1639 | } | |
1640 | ||
1641 | /* | |
1642 | * Set / reset given feature. | |
48fc7f7e | 1643 | * Flag indicates whether to set (!=0) or the reset (=0) the feature. |
f24acd45 HH |
1644 | */ |
1645 | int | |
1646 | dasd_set_feature(struct ccw_device *cdev, int feature, int flag) | |
1647 | { | |
1648 | struct dasd_devmap *devmap; | |
1649 | ||
1081f3a7 | 1650 | devmap = dasd_devmap_from_cdev(cdev); |
f24acd45 | 1651 | if (IS_ERR(devmap)) |
40545573 | 1652 | return PTR_ERR(devmap); |
f24acd45 HH |
1653 | |
1654 | spin_lock(&dasd_devmap_lock); | |
1655 | if (flag) | |
1656 | devmap->features |= feature; | |
1657 | else | |
1658 | devmap->features &= ~feature; | |
c6eb7b77 HH |
1659 | if (devmap->device) |
1660 | devmap->device->features = devmap->features; | |
f24acd45 HH |
1661 | spin_unlock(&dasd_devmap_lock); |
1662 | return 0; | |
1663 | } | |
1664 | ||
1665 | ||
1da177e4 LT |
1666 | int |
1667 | dasd_add_sysfs_files(struct ccw_device *cdev) | |
1668 | { | |
1669 | return sysfs_create_group(&cdev->dev.kobj, &dasd_attr_group); | |
1670 | } | |
1671 | ||
1672 | void | |
1673 | dasd_remove_sysfs_files(struct ccw_device *cdev) | |
1674 | { | |
1675 | sysfs_remove_group(&cdev->dev.kobj, &dasd_attr_group); | |
1676 | } | |
1677 | ||
1678 | ||
1679 | int | |
1680 | dasd_devmap_init(void) | |
1681 | { | |
1682 | int i; | |
1683 | ||
1684 | /* Initialize devmap structures. */ | |
1685 | dasd_max_devindex = 0; | |
1686 | for (i = 0; i < 256; i++) | |
1687 | INIT_LIST_HEAD(&dasd_hashlists[i]); | |
40545573 | 1688 | return 0; |
1da177e4 LT |
1689 | } |
1690 | ||
1691 | void | |
1692 | dasd_devmap_exit(void) | |
1693 | { | |
1694 | dasd_forget_ranges(); | |
1695 | } |