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