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:" | |
09762dcb | 29 | #define DASD_MAX_PARAMS 256 |
1da177e4 LT |
30 | |
31 | #include "dasd_int.h" | |
32 | ||
e18b890b | 33 | struct kmem_cache *dasd_page_cache; |
40545573 | 34 | EXPORT_SYMBOL_GPL(dasd_page_cache); |
1da177e4 LT |
35 | |
36 | /* | |
37 | * dasd_devmap_t is used to store the features and the relation | |
38 | * between device number and device index. To find a dasd_devmap_t | |
39 | * that corresponds to a device number of a device index each | |
40 | * dasd_devmap_t is added to two linked lists, one to search by | |
41 | * the device number and one to search by the device index. As | |
42 | * soon as big minor numbers are available the device index list | |
43 | * can be removed since the device number will then be identical | |
44 | * to the device index. | |
45 | */ | |
46 | struct dasd_devmap { | |
47 | struct list_head list; | |
98df67b3 | 48 | char bus_id[DASD_BUS_ID_SIZE]; |
1da177e4 LT |
49 | unsigned int devindex; |
50 | unsigned short features; | |
51 | struct dasd_device *device; | |
a91ff09d | 52 | struct dasd_copy_relation *copy; |
9558a8e9 | 53 | unsigned int aq_mask; |
1da177e4 LT |
54 | }; |
55 | ||
56 | /* | |
57 | * Parameter parsing functions for dasd= parameter. The syntax is: | |
58 | * <devno> : (0x)?[0-9a-fA-F]+ | |
59 | * <busid> : [0-0a-f]\.[0-9a-f]\.(0x)?[0-9a-fA-F]+ | |
60 | * <feature> : ro | |
61 | * <feature_list> : \(<feature>(:<feature>)*\) | |
62 | * <devno-range> : <devno>(-<devno>)?<feature_list>? | |
63 | * <busid-range> : <busid>(-<busid>)?<feature_list>? | |
64 | * <devices> : <devno-range>|<busid-range> | |
65 | * <dasd_module> : dasd_diag_mod|dasd_eckd_mod|dasd_fba_mod | |
66 | * | |
67 | * <dasd> : autodetect|probeonly|<devices>(,<devices>)* | |
68 | */ | |
69 | ||
70 | int dasd_probeonly = 0; /* is true, when probeonly mode is active */ | |
71 | int dasd_autodetect = 0; /* is true, when autodetection is active */ | |
40545573 HH |
72 | int dasd_nopav = 0; /* is true, when PAV is disabled */ |
73 | EXPORT_SYMBOL_GPL(dasd_nopav); | |
f3eb5384 SW |
74 | int dasd_nofcx; /* disable High Performance Ficon */ |
75 | EXPORT_SYMBOL_GPL(dasd_nofcx); | |
1da177e4 LT |
76 | |
77 | /* | |
78 | * char *dasd[] is intended to hold the ranges supplied by the dasd= statement | |
79 | * it is named 'dasd' to directly be filled by insmod with the comma separated | |
80 | * strings when running as a module. | |
81 | */ | |
09762dcb | 82 | static char *dasd[DASD_MAX_PARAMS]; |
3b126935 | 83 | module_param_array(dasd, charp, NULL, S_IRUGO); |
8d3b33f6 | 84 | |
1da177e4 | 85 | /* |
d0710c7c | 86 | * Single spinlock to protect devmap and servermap structures and lists. |
1da177e4 LT |
87 | */ |
88 | static DEFINE_SPINLOCK(dasd_devmap_lock); | |
89 | ||
90 | /* | |
91 | * Hash lists for devmap structures. | |
92 | */ | |
93 | static struct list_head dasd_hashlists[256]; | |
94 | int dasd_max_devindex; | |
95 | ||
69f90f6a | 96 | static struct dasd_devmap *dasd_add_busid(const char *, int); |
1da177e4 LT |
97 | |
98 | static inline int | |
69f90f6a | 99 | dasd_hash_busid(const char *bus_id) |
1da177e4 LT |
100 | { |
101 | int hash, i; | |
102 | ||
103 | hash = 0; | |
98df67b3 | 104 | for (i = 0; (i < DASD_BUS_ID_SIZE) && *bus_id; i++, bus_id++) |
1da177e4 LT |
105 | hash += *bus_id; |
106 | return hash & 0xff; | |
107 | } | |
108 | ||
109 | #ifndef MODULE | |
09762dcb | 110 | static int __init dasd_call_setup(char *opt) |
1da177e4 | 111 | { |
3b1bea01 | 112 | static int i __initdata; |
09762dcb JH |
113 | char *tmp; |
114 | ||
115 | while (i < DASD_MAX_PARAMS) { | |
116 | tmp = strsep(&opt, ","); | |
117 | if (!tmp) | |
118 | break; | |
119 | ||
120 | dasd[i++] = tmp; | |
121 | } | |
1da177e4 | 122 | |
1da177e4 LT |
123 | return 1; |
124 | } | |
125 | ||
126 | __setup ("dasd=", dasd_call_setup); | |
127 | #endif /* #ifndef MODULE */ | |
128 | ||
7039d3a1 PO |
129 | #define DASD_IPLDEV "ipldev" |
130 | ||
1da177e4 LT |
131 | /* |
132 | * Read a device busid/devno from a string. | |
133 | */ | |
a91ff09d | 134 | static int dasd_busid(char *str, int *id0, int *id1, int *devno) |
1da177e4 | 135 | { |
3b1bea01 JH |
136 | unsigned int val; |
137 | char *tok; | |
138c014d | 138 | |
7039d3a1 | 139 | /* Interpret ipldev busid */ |
3b1bea01 | 140 | if (strncmp(DASD_IPLDEV, str, strlen(DASD_IPLDEV)) == 0) { |
7039d3a1 | 141 | if (ipl_info.type != IPL_TYPE_CCW) { |
fc19f381 | 142 | pr_err("The IPL device is not a CCW device\n"); |
7039d3a1 PO |
143 | return -EINVAL; |
144 | } | |
145 | *id0 = 0; | |
146 | *id1 = ipl_info.data.ccw.dev_id.ssid; | |
147 | *devno = ipl_info.data.ccw.dev_id.devno; | |
7039d3a1 PO |
148 | |
149 | return 0; | |
150 | } | |
3b1bea01 JH |
151 | |
152 | /* Old style 0xXXXX or XXXX */ | |
153 | if (!kstrtouint(str, 16, &val)) { | |
1da177e4 | 154 | *id0 = *id1 = 0; |
4bca698f | 155 | if (val > 0xffff) |
1da177e4 LT |
156 | return -EINVAL; |
157 | *devno = val; | |
158 | return 0; | |
159 | } | |
3b1bea01 | 160 | |
1da177e4 | 161 | /* New style x.y.z busid */ |
3b1bea01 JH |
162 | tok = strsep(&str, "."); |
163 | if (kstrtouint(tok, 16, &val) || val > 0xff) | |
1da177e4 LT |
164 | return -EINVAL; |
165 | *id0 = val; | |
3b1bea01 JH |
166 | |
167 | tok = strsep(&str, "."); | |
168 | if (kstrtouint(tok, 16, &val) || val > 0xff) | |
1da177e4 LT |
169 | return -EINVAL; |
170 | *id1 = val; | |
3b1bea01 JH |
171 | |
172 | tok = strsep(&str, "."); | |
173 | if (kstrtouint(tok, 16, &val) || val > 0xffff) | |
1da177e4 LT |
174 | return -EINVAL; |
175 | *devno = val; | |
3b1bea01 | 176 | |
1da177e4 LT |
177 | return 0; |
178 | } | |
179 | ||
180 | /* | |
3b1bea01 | 181 | * Read colon separated list of dasd features. |
1da177e4 | 182 | */ |
3b1bea01 | 183 | static int __init dasd_feature_list(char *str) |
1da177e4 LT |
184 | { |
185 | int features, len, rc; | |
186 | ||
3b1bea01 | 187 | features = 0; |
1da177e4 | 188 | rc = 0; |
3b1bea01 JH |
189 | |
190 | if (!str) | |
1da177e4 | 191 | return DASD_FEATURE_DEFAULT; |
1da177e4 LT |
192 | |
193 | while (1) { | |
138c014d | 194 | for (len = 0; |
1da177e4 LT |
195 | str[len] && str[len] != ':' && str[len] != ')'; len++); |
196 | if (len == 2 && !strncmp(str, "ro", 2)) | |
197 | features |= DASD_FEATURE_READONLY; | |
198 | else if (len == 4 && !strncmp(str, "diag", 4)) | |
199 | features |= DASD_FEATURE_USEDIAG; | |
e4dbb0f2 SH |
200 | else if (len == 3 && !strncmp(str, "raw", 3)) |
201 | features |= DASD_FEATURE_USERAW; | |
9575bf26 HH |
202 | else if (len == 6 && !strncmp(str, "erplog", 6)) |
203 | features |= DASD_FEATURE_ERPLOG; | |
13de227b HS |
204 | else if (len == 8 && !strncmp(str, "failfast", 8)) |
205 | features |= DASD_FEATURE_FAILFAST; | |
1da177e4 | 206 | else { |
83eb1a41 | 207 | pr_warn("%.*s is not a supported device option\n", |
baebc70a | 208 | len, str); |
1da177e4 LT |
209 | rc = -EINVAL; |
210 | } | |
211 | str += len; | |
212 | if (*str != ':') | |
213 | break; | |
214 | str++; | |
215 | } | |
3b1bea01 JH |
216 | |
217 | return rc ? : features; | |
1da177e4 LT |
218 | } |
219 | ||
220 | /* | |
221 | * Try to match the first element on the comma separated parse string | |
222 | * with one of the known keywords. If a keyword is found, take the approprate | |
223 | * action and return a pointer to the residual string. If the first element | |
224 | * could not be matched to any keyword then return an error code. | |
225 | */ | |
3b1bea01 JH |
226 | static int __init dasd_parse_keyword(char *keyword) |
227 | { | |
228 | int length = strlen(keyword); | |
1da177e4 | 229 | |
3b1bea01 | 230 | if (strncmp("autodetect", keyword, length) == 0) { |
1da177e4 | 231 | dasd_autodetect = 1; |
fc19f381 | 232 | pr_info("The autodetection mode has been activated\n"); |
3b1bea01 | 233 | return 0; |
1da177e4 | 234 | } |
3b1bea01 | 235 | if (strncmp("probeonly", keyword, length) == 0) { |
1da177e4 | 236 | dasd_probeonly = 1; |
fc19f381 | 237 | pr_info("The probeonly mode has been activated\n"); |
3b1bea01 | 238 | return 0; |
1da177e4 | 239 | } |
3b1bea01 | 240 | if (strncmp("nopav", keyword, length) == 0) { |
dcd707b4 | 241 | if (MACHINE_IS_VM) |
fc19f381 | 242 | pr_info("'nopav' is not supported on z/VM\n"); |
dcd707b4 PO |
243 | else { |
244 | dasd_nopav = 1; | |
fc19f381 | 245 | pr_info("PAV support has be deactivated\n"); |
dcd707b4 | 246 | } |
3b1bea01 | 247 | return 0; |
40545573 | 248 | } |
3b1bea01 | 249 | if (strncmp("nofcx", keyword, length) == 0) { |
f3eb5384 | 250 | dasd_nofcx = 1; |
fc19f381 SH |
251 | pr_info("High Performance FICON support has been " |
252 | "deactivated\n"); | |
3b1bea01 | 253 | return 0; |
f3eb5384 | 254 | } |
3b1bea01 | 255 | if (strncmp("fixedbuffers", keyword, length) == 0) { |
1da177e4 | 256 | if (dasd_page_cache) |
3b1bea01 | 257 | return 0; |
1da177e4 | 258 | dasd_page_cache = |
2f6c55fc HC |
259 | kmem_cache_create("dasd_page_cache", PAGE_SIZE, |
260 | PAGE_SIZE, SLAB_CACHE_DMA, | |
20c2df83 | 261 | NULL); |
1da177e4 | 262 | if (!dasd_page_cache) |
fc19f381 | 263 | DBF_EVENT(DBF_WARNING, "%s", "Failed to create slab, " |
1da177e4 LT |
264 | "fixed buffer mode disabled."); |
265 | else | |
fc19f381 | 266 | DBF_EVENT(DBF_INFO, "%s", |
1da177e4 | 267 | "turning on fixed buffer mode"); |
3b1bea01 JH |
268 | return 0; |
269 | } | |
270 | ||
271 | return -EINVAL; | |
1da177e4 LT |
272 | } |
273 | ||
274 | /* | |
3b1bea01 JH |
275 | * Split a string of a device range into its pieces and return the from, to, and |
276 | * feature parts separately. | |
277 | * e.g.: | |
278 | * 0.0.1234-0.0.5678(ro:erplog) -> from: 0.0.1234 to: 0.0.5678 features: ro:erplog | |
279 | * 0.0.8765(raw) -> from: 0.0.8765 to: null features: raw | |
280 | * 0x4321 -> from: 0x4321 to: null features: null | |
1da177e4 | 281 | */ |
3b1bea01 JH |
282 | static int __init dasd_evaluate_range_param(char *range, char **from_str, |
283 | char **to_str, char **features_str) | |
284 | { | |
285 | int rc = 0; | |
286 | ||
287 | /* Do we have a range or a single device? */ | |
288 | if (strchr(range, '-')) { | |
289 | *from_str = strsep(&range, "-"); | |
290 | *to_str = strsep(&range, "("); | |
291 | *features_str = strsep(&range, ")"); | |
292 | } else { | |
293 | *from_str = strsep(&range, "("); | |
294 | *features_str = strsep(&range, ")"); | |
295 | } | |
296 | ||
297 | if (*features_str && !range) { | |
298 | pr_warn("A closing parenthesis ')' is missing in the dasd= parameter\n"); | |
299 | rc = -EINVAL; | |
300 | } | |
1da177e4 | 301 | |
3b1bea01 JH |
302 | return rc; |
303 | } | |
304 | ||
305 | /* | |
306 | * Try to interprete the range string as a device number or a range of devices. | |
307 | * If the interpretation is successful, create the matching dasd_devmap entries. | |
308 | * If interpretation fails or in case of an error, return an error code. | |
309 | */ | |
310 | static int __init dasd_parse_range(const char *range) | |
311 | { | |
1da177e4 LT |
312 | struct dasd_devmap *devmap; |
313 | int from, from_id0, from_id1; | |
314 | int to, to_id0, to_id1; | |
3b1bea01 JH |
315 | int features; |
316 | char bus_id[DASD_BUS_ID_SIZE + 1]; | |
317 | char *features_str = NULL; | |
318 | char *from_str = NULL; | |
319 | char *to_str = NULL; | |
3050c208 JH |
320 | int rc = 0; |
321 | char *tmp; | |
3b1bea01 | 322 | |
3050c208 JH |
323 | tmp = kstrdup(range, GFP_KERNEL); |
324 | if (!tmp) | |
325 | return -ENOMEM; | |
3b1bea01 | 326 | |
3050c208 JH |
327 | if (dasd_evaluate_range_param(tmp, &from_str, &to_str, &features_str)) { |
328 | rc = -EINVAL; | |
329 | goto out; | |
330 | } | |
3b1bea01 | 331 | |
3050c208 JH |
332 | if (dasd_busid(from_str, &from_id0, &from_id1, &from)) { |
333 | rc = -EINVAL; | |
334 | goto out; | |
335 | } | |
3b1bea01 JH |
336 | |
337 | to = from; | |
338 | to_id0 = from_id0; | |
339 | to_id1 = from_id1; | |
340 | if (to_str) { | |
3050c208 JH |
341 | if (dasd_busid(to_str, &to_id0, &to_id1, &to)) { |
342 | rc = -EINVAL; | |
343 | goto out; | |
344 | } | |
3b1bea01 JH |
345 | if (from_id0 != to_id0 || from_id1 != to_id1 || from > to) { |
346 | pr_err("%s is not a valid device range\n", range); | |
3050c208 JH |
347 | rc = -EINVAL; |
348 | goto out; | |
1da177e4 LT |
349 | } |
350 | } | |
3b1bea01 JH |
351 | |
352 | features = dasd_feature_list(features_str); | |
3050c208 JH |
353 | if (features < 0) { |
354 | rc = -EINVAL; | |
355 | goto out; | |
356 | } | |
40545573 HH |
357 | /* each device in dasd= parameter should be set initially online */ |
358 | features |= DASD_FEATURE_INITIAL_ONLINE; | |
1da177e4 | 359 | while (from <= to) { |
3b1bea01 | 360 | sprintf(bus_id, "%01x.%01x.%04x", from_id0, from_id1, from++); |
1da177e4 | 361 | devmap = dasd_add_busid(bus_id, features); |
3050c208 JH |
362 | if (IS_ERR(devmap)) { |
363 | rc = PTR_ERR(devmap); | |
364 | goto out; | |
365 | } | |
1da177e4 | 366 | } |
1da177e4 | 367 | |
3050c208 JH |
368 | out: |
369 | kfree(tmp); | |
3b1bea01 | 370 | |
3050c208 | 371 | return rc; |
1da177e4 LT |
372 | } |
373 | ||
374 | /* | |
375 | * Parse parameters stored in dasd[] | |
376 | * The 'dasd=...' parameter allows to specify a comma separated list of | |
09762dcb JH |
377 | * keywords and device ranges. The parameters in that list will be stored as |
378 | * separate elementes in dasd[]. | |
1da177e4 | 379 | */ |
3b1bea01 | 380 | int __init dasd_parse(void) |
1da177e4 LT |
381 | { |
382 | int rc, i; | |
3b1bea01 | 383 | char *cur; |
1da177e4 LT |
384 | |
385 | rc = 0; | |
09762dcb | 386 | for (i = 0; i < DASD_MAX_PARAMS; i++) { |
3b1bea01 JH |
387 | cur = dasd[i]; |
388 | if (!cur) | |
1da177e4 | 389 | break; |
3b1bea01 JH |
390 | if (*cur == '\0') |
391 | continue; | |
392 | ||
393 | rc = dasd_parse_keyword(cur); | |
394 | if (rc) | |
395 | rc = dasd_parse_range(cur); | |
396 | ||
397 | if (rc) | |
1da177e4 | 398 | break; |
1da177e4 | 399 | } |
3b1bea01 | 400 | |
1da177e4 LT |
401 | return rc; |
402 | } | |
403 | ||
404 | /* | |
405 | * Add a devmap for the device specified by busid. It is possible that | |
406 | * the devmap already exists (dasd= parameter). The order of the devices | |
407 | * added through this function will define the kdevs for the individual | |
138c014d | 408 | * devices. |
1da177e4 LT |
409 | */ |
410 | static struct dasd_devmap * | |
69f90f6a | 411 | dasd_add_busid(const char *bus_id, int features) |
1da177e4 LT |
412 | { |
413 | struct dasd_devmap *devmap, *new, *tmp; | |
414 | int hash; | |
415 | ||
006485dc | 416 | new = kzalloc(sizeof(struct dasd_devmap), GFP_KERNEL); |
1da177e4 LT |
417 | if (!new) |
418 | return ERR_PTR(-ENOMEM); | |
419 | spin_lock(&dasd_devmap_lock); | |
d2c993d8 | 420 | devmap = NULL; |
1da177e4 LT |
421 | hash = dasd_hash_busid(bus_id); |
422 | list_for_each_entry(tmp, &dasd_hashlists[hash], list) | |
98df67b3 | 423 | if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) { |
1da177e4 LT |
424 | devmap = tmp; |
425 | break; | |
426 | } | |
427 | if (!devmap) { | |
428 | /* This bus_id is new. */ | |
429 | new->devindex = dasd_max_devindex++; | |
820109fb | 430 | strscpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE); |
1da177e4 | 431 | new->features = features; |
d2c993d8 | 432 | new->device = NULL; |
1da177e4 LT |
433 | list_add(&new->list, &dasd_hashlists[hash]); |
434 | devmap = new; | |
d2c993d8 | 435 | new = NULL; |
1da177e4 LT |
436 | } |
437 | spin_unlock(&dasd_devmap_lock); | |
17fd682e | 438 | kfree(new); |
1da177e4 LT |
439 | return devmap; |
440 | } | |
441 | ||
1da177e4 | 442 | static struct dasd_devmap * |
a91ff09d | 443 | dasd_find_busid_locked(const char *bus_id) |
1da177e4 LT |
444 | { |
445 | struct dasd_devmap *devmap, *tmp; | |
446 | int hash; | |
447 | ||
1da177e4 LT |
448 | devmap = ERR_PTR(-ENODEV); |
449 | hash = dasd_hash_busid(bus_id); | |
450 | list_for_each_entry(tmp, &dasd_hashlists[hash], list) { | |
98df67b3 | 451 | if (strncmp(tmp->bus_id, bus_id, DASD_BUS_ID_SIZE) == 0) { |
1da177e4 LT |
452 | devmap = tmp; |
453 | break; | |
454 | } | |
455 | } | |
a91ff09d SH |
456 | return devmap; |
457 | } | |
458 | ||
459 | /* | |
460 | * Find devmap for device with given bus_id. | |
461 | */ | |
462 | static struct dasd_devmap * | |
463 | dasd_find_busid(const char *bus_id) | |
464 | { | |
465 | struct dasd_devmap *devmap; | |
466 | ||
467 | spin_lock(&dasd_devmap_lock); | |
468 | devmap = dasd_find_busid_locked(bus_id); | |
1da177e4 LT |
469 | spin_unlock(&dasd_devmap_lock); |
470 | return devmap; | |
471 | } | |
472 | ||
473 | /* | |
474 | * Check if busid has been added to the list of dasd ranges. | |
475 | */ | |
476 | int | |
69f90f6a | 477 | dasd_busid_known(const char *bus_id) |
1da177e4 LT |
478 | { |
479 | return IS_ERR(dasd_find_busid(bus_id)) ? -ENOENT : 0; | |
480 | } | |
481 | ||
482 | /* | |
483 | * Forget all about the device numbers added so far. | |
484 | * This may only be called at module unload or system shutdown. | |
485 | */ | |
486 | static void | |
487 | dasd_forget_ranges(void) | |
488 | { | |
489 | struct dasd_devmap *devmap, *n; | |
490 | int i; | |
491 | ||
492 | spin_lock(&dasd_devmap_lock); | |
493 | for (i = 0; i < 256; i++) { | |
494 | list_for_each_entry_safe(devmap, n, &dasd_hashlists[i], list) { | |
606f4422 | 495 | BUG_ON(devmap->device != NULL); |
1da177e4 LT |
496 | list_del(&devmap->list); |
497 | kfree(devmap); | |
498 | } | |
499 | } | |
500 | spin_unlock(&dasd_devmap_lock); | |
501 | } | |
502 | ||
503 | /* | |
504 | * Find the device struct by its device index. | |
505 | */ | |
506 | struct dasd_device * | |
507 | dasd_device_from_devindex(int devindex) | |
508 | { | |
509 | struct dasd_devmap *devmap, *tmp; | |
510 | struct dasd_device *device; | |
511 | int i; | |
512 | ||
513 | spin_lock(&dasd_devmap_lock); | |
d2c993d8 | 514 | devmap = NULL; |
1da177e4 LT |
515 | for (i = 0; (i < 256) && !devmap; i++) |
516 | list_for_each_entry(tmp, &dasd_hashlists[i], list) | |
517 | if (tmp->devindex == devindex) { | |
518 | /* Found the devmap for the device. */ | |
519 | devmap = tmp; | |
520 | break; | |
521 | } | |
522 | if (devmap && devmap->device) { | |
523 | device = devmap->device; | |
524 | dasd_get_device(device); | |
525 | } else | |
526 | device = ERR_PTR(-ENODEV); | |
527 | spin_unlock(&dasd_devmap_lock); | |
528 | return device; | |
529 | } | |
530 | ||
531 | /* | |
532 | * Return devmap for cdev. If no devmap exists yet, create one and | |
533 | * connect it to the cdev. | |
534 | */ | |
535 | static struct dasd_devmap * | |
536 | dasd_devmap_from_cdev(struct ccw_device *cdev) | |
537 | { | |
538 | struct dasd_devmap *devmap; | |
539 | ||
2a0217d5 | 540 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
1da177e4 | 541 | if (IS_ERR(devmap)) |
2a0217d5 | 542 | devmap = dasd_add_busid(dev_name(&cdev->dev), |
1da177e4 LT |
543 | DASD_FEATURE_DEFAULT); |
544 | return devmap; | |
545 | } | |
546 | ||
547 | /* | |
548 | * Create a dasd device structure for cdev. | |
549 | */ | |
550 | struct dasd_device * | |
551 | dasd_create_device(struct ccw_device *cdev) | |
552 | { | |
553 | struct dasd_devmap *devmap; | |
554 | struct dasd_device *device; | |
a00bfd71 | 555 | unsigned long flags; |
1da177e4 LT |
556 | int rc; |
557 | ||
558 | devmap = dasd_devmap_from_cdev(cdev); | |
559 | if (IS_ERR(devmap)) | |
560 | return (void *) devmap; | |
1da177e4 LT |
561 | |
562 | device = dasd_alloc_device(); | |
563 | if (IS_ERR(device)) | |
564 | return device; | |
a00bfd71 | 565 | atomic_set(&device->ref_count, 3); |
1da177e4 LT |
566 | |
567 | spin_lock(&dasd_devmap_lock); | |
568 | if (!devmap->device) { | |
569 | devmap->device = device; | |
570 | device->devindex = devmap->devindex; | |
c6eb7b77 | 571 | device->features = devmap->features; |
1da177e4 LT |
572 | get_device(&cdev->dev); |
573 | device->cdev = cdev; | |
574 | rc = 0; | |
575 | } else | |
576 | /* Someone else was faster. */ | |
577 | rc = -EBUSY; | |
578 | spin_unlock(&dasd_devmap_lock); | |
579 | ||
580 | if (rc) { | |
581 | dasd_free_device(device); | |
582 | return ERR_PTR(rc); | |
583 | } | |
a00bfd71 MS |
584 | |
585 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); | |
faf16aa9 | 586 | dev_set_drvdata(&cdev->dev, device); |
a00bfd71 MS |
587 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
588 | ||
19508b20 JH |
589 | device->paths_info = kset_create_and_add("paths_info", NULL, |
590 | &device->cdev->dev.kobj); | |
591 | if (!device->paths_info) | |
592 | dev_warn(&cdev->dev, "Could not create paths_info kset\n"); | |
593 | ||
1da177e4 LT |
594 | return device; |
595 | } | |
596 | ||
a91ff09d SH |
597 | /* |
598 | * allocate a PPRC data structure and call the discipline function to fill | |
599 | */ | |
600 | static int dasd_devmap_get_pprc_status(struct dasd_device *device, | |
601 | struct dasd_pprc_data_sc4 **data) | |
602 | { | |
603 | struct dasd_pprc_data_sc4 *temp; | |
604 | ||
605 | if (!device->discipline || !device->discipline->pprc_status) { | |
606 | dev_warn(&device->cdev->dev, "Unable to query copy relation status\n"); | |
607 | return -EOPNOTSUPP; | |
608 | } | |
609 | temp = kzalloc(sizeof(*temp), GFP_KERNEL); | |
610 | if (!temp) | |
611 | return -ENOMEM; | |
612 | ||
613 | /* get PPRC information from storage */ | |
614 | if (device->discipline->pprc_status(device, temp)) { | |
615 | dev_warn(&device->cdev->dev, "Error during copy relation status query\n"); | |
616 | kfree(temp); | |
617 | return -EINVAL; | |
618 | } | |
619 | *data = temp; | |
620 | ||
621 | return 0; | |
622 | } | |
623 | ||
624 | /* | |
625 | * find an entry in a PPRC device_info array by a given UID | |
626 | * depending on the primary/secondary state of the device it has to be | |
627 | * matched with the respective fields | |
628 | */ | |
629 | static int dasd_devmap_entry_from_pprc_data(struct dasd_pprc_data_sc4 *data, | |
630 | struct dasd_uid uid, | |
631 | bool primary) | |
632 | { | |
633 | int i; | |
634 | ||
635 | for (i = 0; i < DASD_CP_ENTRIES; i++) { | |
636 | if (primary) { | |
637 | if (data->dev_info[i].prim_cu_ssid == uid.ssid && | |
638 | data->dev_info[i].primary == uid.real_unit_addr) | |
639 | return i; | |
640 | } else { | |
641 | if (data->dev_info[i].sec_cu_ssid == uid.ssid && | |
642 | data->dev_info[i].secondary == uid.real_unit_addr) | |
643 | return i; | |
644 | } | |
645 | } | |
646 | return -1; | |
647 | } | |
648 | ||
649 | /* | |
650 | * check the consistency of a specified copy relation by checking | |
651 | * the following things: | |
652 | * | |
653 | * - is the given device part of a copy pair setup | |
654 | * - does the state of the device match the state in the PPRC status data | |
655 | * - does the device UID match with the UID in the PPRC status data | |
656 | * - to prevent misrouted IO check if the given device is present in all | |
657 | * related PPRC status data | |
658 | */ | |
659 | static int dasd_devmap_check_copy_relation(struct dasd_device *device, | |
660 | struct dasd_copy_entry *entry, | |
661 | struct dasd_pprc_data_sc4 *data, | |
662 | struct dasd_copy_relation *copy) | |
663 | { | |
664 | struct dasd_pprc_data_sc4 *tmp_dat; | |
665 | struct dasd_device *tmp_dev; | |
666 | struct dasd_uid uid; | |
667 | int i, j; | |
668 | ||
669 | if (!device->discipline || !device->discipline->get_uid || | |
670 | device->discipline->get_uid(device, &uid)) | |
671 | return 1; | |
672 | ||
673 | i = dasd_devmap_entry_from_pprc_data(data, uid, entry->primary); | |
674 | if (i < 0) { | |
675 | dev_warn(&device->cdev->dev, "Device not part of a copy relation\n"); | |
676 | return 1; | |
677 | } | |
678 | ||
679 | /* double check which role the current device has */ | |
680 | if (entry->primary) { | |
681 | if (data->dev_info[i].flags & 0x80) { | |
682 | dev_warn(&device->cdev->dev, "Copy pair secondary is setup as primary\n"); | |
683 | return 1; | |
684 | } | |
685 | if (data->dev_info[i].prim_cu_ssid != uid.ssid || | |
686 | data->dev_info[i].primary != uid.real_unit_addr) { | |
687 | dev_warn(&device->cdev->dev, | |
688 | "Primary device %s does not match copy pair status primary device %04x\n", | |
689 | dev_name(&device->cdev->dev), | |
690 | data->dev_info[i].prim_cu_ssid | | |
691 | data->dev_info[i].primary); | |
692 | return 1; | |
693 | } | |
694 | } else { | |
695 | if (!(data->dev_info[i].flags & 0x80)) { | |
696 | dev_warn(&device->cdev->dev, "Copy pair primary is setup as secondary\n"); | |
697 | return 1; | |
698 | } | |
699 | if (data->dev_info[i].sec_cu_ssid != uid.ssid || | |
700 | data->dev_info[i].secondary != uid.real_unit_addr) { | |
701 | dev_warn(&device->cdev->dev, | |
702 | "Secondary device %s does not match copy pair status secondary device %04x\n", | |
703 | dev_name(&device->cdev->dev), | |
704 | data->dev_info[i].sec_cu_ssid | | |
705 | data->dev_info[i].secondary); | |
706 | return 1; | |
707 | } | |
708 | } | |
709 | ||
710 | /* | |
711 | * the current device has to be part of the copy relation of all | |
712 | * entries to prevent misrouted IO to another copy pair | |
713 | */ | |
714 | for (j = 0; j < DASD_CP_ENTRIES; j++) { | |
715 | if (entry == ©->entry[j]) | |
716 | tmp_dev = device; | |
717 | else | |
718 | tmp_dev = copy->entry[j].device; | |
719 | ||
720 | if (!tmp_dev) | |
721 | continue; | |
722 | ||
723 | if (dasd_devmap_get_pprc_status(tmp_dev, &tmp_dat)) | |
724 | return 1; | |
725 | ||
726 | if (dasd_devmap_entry_from_pprc_data(tmp_dat, uid, entry->primary) < 0) { | |
727 | dev_warn(&tmp_dev->cdev->dev, | |
728 | "Copy pair relation does not contain device: %s\n", | |
729 | dev_name(&device->cdev->dev)); | |
730 | kfree(tmp_dat); | |
731 | return 1; | |
732 | } | |
733 | kfree(tmp_dat); | |
734 | } | |
735 | return 0; | |
736 | } | |
737 | ||
738 | /* delete device from copy relation entry */ | |
739 | static void dasd_devmap_delete_copy_relation_device(struct dasd_device *device) | |
740 | { | |
741 | struct dasd_copy_relation *copy; | |
742 | int i; | |
743 | ||
744 | if (!device->copy) | |
745 | return; | |
746 | ||
747 | copy = device->copy; | |
748 | for (i = 0; i < DASD_CP_ENTRIES; i++) { | |
749 | if (copy->entry[i].device == device) | |
750 | copy->entry[i].device = NULL; | |
751 | } | |
752 | dasd_put_device(device); | |
753 | device->copy = NULL; | |
754 | } | |
755 | ||
756 | /* | |
757 | * read all required information for a copy relation setup and setup the device | |
758 | * accordingly | |
759 | */ | |
760 | int dasd_devmap_set_device_copy_relation(struct ccw_device *cdev, | |
761 | bool pprc_enabled) | |
762 | { | |
763 | struct dasd_pprc_data_sc4 *data = NULL; | |
764 | struct dasd_copy_entry *entry = NULL; | |
765 | struct dasd_copy_relation *copy; | |
766 | struct dasd_devmap *devmap; | |
767 | struct dasd_device *device; | |
768 | int i, rc = 0; | |
769 | ||
770 | devmap = dasd_devmap_from_cdev(cdev); | |
771 | if (IS_ERR(devmap)) | |
772 | return PTR_ERR(devmap); | |
773 | ||
774 | device = devmap->device; | |
775 | if (!device) | |
776 | return -ENODEV; | |
777 | ||
778 | copy = devmap->copy; | |
779 | /* no copy pair setup for this device */ | |
780 | if (!copy) | |
781 | goto out; | |
782 | ||
783 | rc = dasd_devmap_get_pprc_status(device, &data); | |
784 | if (rc) | |
785 | return rc; | |
786 | ||
787 | /* print error if PPRC is requested but not enabled on storage server */ | |
788 | if (!pprc_enabled) { | |
789 | dev_err(&cdev->dev, "Copy relation not enabled on storage server\n"); | |
790 | rc = -EINVAL; | |
791 | goto out; | |
792 | } | |
793 | ||
794 | if (!data->dev_info[0].state) { | |
795 | dev_warn(&device->cdev->dev, "Copy pair setup requested for device not in copy relation\n"); | |
796 | rc = -EINVAL; | |
797 | goto out; | |
798 | } | |
799 | /* find entry */ | |
800 | for (i = 0; i < DASD_CP_ENTRIES; i++) { | |
801 | if (copy->entry[i].configured && | |
802 | strncmp(dev_name(&cdev->dev), | |
803 | copy->entry[i].busid, DASD_BUS_ID_SIZE) == 0) { | |
804 | entry = ©->entry[i]; | |
805 | break; | |
806 | } | |
807 | } | |
808 | if (!entry) { | |
809 | dev_warn(&device->cdev->dev, "Copy relation entry not found\n"); | |
810 | rc = -EINVAL; | |
811 | goto out; | |
812 | } | |
813 | /* check if the copy relation is valid */ | |
814 | if (dasd_devmap_check_copy_relation(device, entry, data, copy)) { | |
815 | dev_warn(&device->cdev->dev, "Copy relation faulty\n"); | |
816 | rc = -EINVAL; | |
817 | goto out; | |
818 | } | |
819 | ||
820 | dasd_get_device(device); | |
821 | copy->entry[i].device = device; | |
822 | device->copy = copy; | |
823 | out: | |
824 | kfree(data); | |
825 | return rc; | |
826 | } | |
827 | EXPORT_SYMBOL_GPL(dasd_devmap_set_device_copy_relation); | |
828 | ||
1da177e4 LT |
829 | /* |
830 | * Wait queue for dasd_delete_device waits. | |
831 | */ | |
832 | static DECLARE_WAIT_QUEUE_HEAD(dasd_delete_wq); | |
833 | ||
834 | /* | |
835 | * Remove a dasd device structure. The passed referenced | |
836 | * is destroyed. | |
837 | */ | |
838 | void | |
839 | dasd_delete_device(struct dasd_device *device) | |
840 | { | |
841 | struct ccw_device *cdev; | |
842 | struct dasd_devmap *devmap; | |
a00bfd71 | 843 | unsigned long flags; |
1da177e4 LT |
844 | |
845 | /* First remove device pointer from devmap. */ | |
2a0217d5 | 846 | devmap = dasd_find_busid(dev_name(&device->cdev->dev)); |
606f4422 | 847 | BUG_ON(IS_ERR(devmap)); |
1da177e4 LT |
848 | spin_lock(&dasd_devmap_lock); |
849 | if (devmap->device != device) { | |
850 | spin_unlock(&dasd_devmap_lock); | |
851 | dasd_put_device(device); | |
852 | return; | |
853 | } | |
854 | devmap->device = NULL; | |
855 | spin_unlock(&dasd_devmap_lock); | |
856 | ||
a00bfd71 MS |
857 | /* Disconnect dasd_device structure from ccw_device structure. */ |
858 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
faf16aa9 | 859 | dev_set_drvdata(&device->cdev->dev, NULL); |
a00bfd71 MS |
860 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
861 | ||
a91ff09d SH |
862 | /* Removve copy relation */ |
863 | dasd_devmap_delete_copy_relation_device(device); | |
a00bfd71 MS |
864 | /* |
865 | * Drop ref_count by 3, one for the devmap reference, one for | |
866 | * the cdev reference and one for the passed reference. | |
867 | */ | |
868 | atomic_sub(3, &device->ref_count); | |
1da177e4 LT |
869 | |
870 | /* Wait for reference counter to drop to zero. */ | |
871 | wait_event(dasd_delete_wq, atomic_read(&device->ref_count) == 0); | |
872 | ||
c020d722 | 873 | dasd_generic_free_discipline(device); |
19508b20 JH |
874 | |
875 | kset_unregister(device->paths_info); | |
876 | ||
1da177e4 LT |
877 | /* Disconnect dasd_device structure from ccw_device structure. */ |
878 | cdev = device->cdev; | |
879 | device->cdev = NULL; | |
880 | ||
1da177e4 LT |
881 | /* Put ccw_device structure. */ |
882 | put_device(&cdev->dev); | |
883 | ||
884 | /* Now the device structure can be freed. */ | |
885 | dasd_free_device(device); | |
886 | } | |
887 | ||
888 | /* | |
889 | * Reference counter dropped to zero. Wake up waiter | |
890 | * in dasd_delete_device. | |
891 | */ | |
892 | void | |
893 | dasd_put_device_wake(struct dasd_device *device) | |
894 | { | |
895 | wake_up(&dasd_delete_wq); | |
896 | } | |
a4d26c6a | 897 | EXPORT_SYMBOL_GPL(dasd_put_device_wake); |
1da177e4 | 898 | |
a00bfd71 MS |
899 | /* |
900 | * Return dasd_device structure associated with cdev. | |
901 | * This function needs to be called with the ccw device | |
902 | * lock held. It can be used from interrupt context. | |
903 | */ | |
904 | struct dasd_device * | |
905 | dasd_device_from_cdev_locked(struct ccw_device *cdev) | |
906 | { | |
faf16aa9 | 907 | struct dasd_device *device = dev_get_drvdata(&cdev->dev); |
a00bfd71 MS |
908 | |
909 | if (!device) | |
910 | return ERR_PTR(-ENODEV); | |
911 | dasd_get_device(device); | |
912 | return device; | |
913 | } | |
914 | ||
1da177e4 LT |
915 | /* |
916 | * Return dasd_device structure associated with cdev. | |
917 | */ | |
918 | struct dasd_device * | |
919 | dasd_device_from_cdev(struct ccw_device *cdev) | |
920 | { | |
1da177e4 | 921 | struct dasd_device *device; |
a00bfd71 | 922 | unsigned long flags; |
1da177e4 | 923 | |
a00bfd71 MS |
924 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
925 | device = dasd_device_from_cdev_locked(cdev); | |
926 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); | |
1da177e4 LT |
927 | return device; |
928 | } | |
929 | ||
65f8da47 SW |
930 | void dasd_add_link_to_gendisk(struct gendisk *gdp, struct dasd_device *device) |
931 | { | |
932 | struct dasd_devmap *devmap; | |
933 | ||
934 | devmap = dasd_find_busid(dev_name(&device->cdev->dev)); | |
935 | if (IS_ERR(devmap)) | |
936 | return; | |
937 | spin_lock(&dasd_devmap_lock); | |
938 | gdp->private_data = devmap; | |
939 | spin_unlock(&dasd_devmap_lock); | |
940 | } | |
413862ca | 941 | EXPORT_SYMBOL(dasd_add_link_to_gendisk); |
65f8da47 SW |
942 | |
943 | struct dasd_device *dasd_device_from_gendisk(struct gendisk *gdp) | |
944 | { | |
945 | struct dasd_device *device; | |
946 | struct dasd_devmap *devmap; | |
947 | ||
948 | if (!gdp->private_data) | |
949 | return NULL; | |
950 | device = NULL; | |
951 | spin_lock(&dasd_devmap_lock); | |
952 | devmap = gdp->private_data; | |
953 | if (devmap && devmap->device) { | |
954 | device = devmap->device; | |
955 | dasd_get_device(device); | |
956 | } | |
957 | spin_unlock(&dasd_devmap_lock); | |
958 | return device; | |
959 | } | |
960 | ||
1da177e4 LT |
961 | /* |
962 | * SECTION: files in sysfs | |
963 | */ | |
964 | ||
13de227b HS |
965 | /* |
966 | * failfast controls the behaviour, if no path is available | |
967 | */ | |
968 | static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr, | |
969 | char *buf) | |
970 | { | |
971 | struct dasd_devmap *devmap; | |
972 | int ff_flag; | |
973 | ||
ca0b4b7d | 974 | devmap = dasd_find_busid(dev_name(dev)); |
13de227b HS |
975 | if (!IS_ERR(devmap)) |
976 | ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0; | |
977 | else | |
978 | ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0; | |
4b9e0436 | 979 | return sysfs_emit(buf, ff_flag ? "1\n" : "0\n"); |
13de227b HS |
980 | } |
981 | ||
982 | static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr, | |
983 | const char *buf, size_t count) | |
984 | { | |
ce7a788f | 985 | unsigned int val; |
1081f3a7 | 986 | int rc; |
13de227b | 987 | |
ce7a788f | 988 | if (kstrtouint(buf, 0, &val) || val > 1) |
13de227b HS |
989 | return -EINVAL; |
990 | ||
1081f3a7 JH |
991 | rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_FAILFAST, val); |
992 | ||
993 | return rc ? : count; | |
13de227b HS |
994 | } |
995 | ||
996 | static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store); | |
997 | ||
1da177e4 LT |
998 | /* |
999 | * readonly controls the readonly status of a dasd | |
1000 | */ | |
1001 | static ssize_t | |
e404e274 | 1002 | dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf) |
1da177e4 LT |
1003 | { |
1004 | struct dasd_devmap *devmap; | |
b487a914 JH |
1005 | struct dasd_device *device; |
1006 | int ro_flag = 0; | |
1da177e4 | 1007 | |
2a0217d5 | 1008 | devmap = dasd_find_busid(dev_name(dev)); |
b487a914 JH |
1009 | if (IS_ERR(devmap)) |
1010 | goto out; | |
1011 | ||
1012 | ro_flag = !!(devmap->features & DASD_FEATURE_READONLY); | |
1013 | ||
1014 | spin_lock(&dasd_devmap_lock); | |
1015 | device = devmap->device; | |
1016 | if (device) | |
1017 | ro_flag |= test_bit(DASD_FLAG_DEVICE_RO, &device->flags); | |
1018 | spin_unlock(&dasd_devmap_lock); | |
1019 | ||
1020 | out: | |
4b9e0436 | 1021 | return sysfs_emit(buf, ro_flag ? "1\n" : "0\n"); |
1da177e4 LT |
1022 | } |
1023 | ||
1024 | static ssize_t | |
138c014d HH |
1025 | dasd_ro_store(struct device *dev, struct device_attribute *attr, |
1026 | const char *buf, size_t count) | |
1da177e4 | 1027 | { |
1081f3a7 | 1028 | struct ccw_device *cdev = to_ccwdev(dev); |
33b62a30 | 1029 | struct dasd_device *device; |
9f9d53e5 | 1030 | unsigned long flags; |
ce7a788f | 1031 | unsigned int val; |
1081f3a7 | 1032 | int rc; |
01376f44 | 1033 | |
ce7a788f | 1034 | if (kstrtouint(buf, 0, &val) || val > 1) |
01376f44 HH |
1035 | return -EINVAL; |
1036 | ||
1081f3a7 JH |
1037 | rc = dasd_set_feature(cdev, DASD_FEATURE_READONLY, val); |
1038 | if (rc) | |
1039 | return rc; | |
1040 | ||
1041 | device = dasd_device_from_cdev(cdev); | |
1042 | if (IS_ERR(device)) | |
795c9a51 | 1043 | return count; |
1081f3a7 | 1044 | |
9f9d53e5 | 1045 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
1081f3a7 | 1046 | val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags); |
1081f3a7 | 1047 | |
9f9d53e5 JH |
1048 | if (!device->block || !device->block->gdp || |
1049 | test_bit(DASD_FLAG_OFFLINE, &device->flags)) { | |
1050 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); | |
1051 | goto out; | |
1052 | } | |
1053 | /* Increase open_count to avoid losing the block device */ | |
1054 | atomic_inc(&device->block->open_count); | |
1055 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); | |
1056 | ||
1057 | set_disk_ro(device->block->gdp, val); | |
1058 | atomic_dec(&device->block->open_count); | |
1059 | ||
1060 | out: | |
1081f3a7 JH |
1061 | dasd_put_device(device); |
1062 | ||
1da177e4 LT |
1063 | return count; |
1064 | } | |
1065 | ||
1066 | static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store); | |
9575bf26 HH |
1067 | /* |
1068 | * erplog controls the logging of ERP related data | |
1069 | * (e.g. failing channel programs). | |
1070 | */ | |
1071 | static ssize_t | |
1072 | dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1073 | { | |
1074 | struct dasd_devmap *devmap; | |
1075 | int erplog; | |
1076 | ||
2a0217d5 | 1077 | devmap = dasd_find_busid(dev_name(dev)); |
9575bf26 HH |
1078 | if (!IS_ERR(devmap)) |
1079 | erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0; | |
1080 | else | |
1081 | erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0; | |
4b9e0436 | 1082 | return sysfs_emit(buf, erplog ? "1\n" : "0\n"); |
9575bf26 HH |
1083 | } |
1084 | ||
1085 | static ssize_t | |
1086 | dasd_erplog_store(struct device *dev, struct device_attribute *attr, | |
1087 | const char *buf, size_t count) | |
1088 | { | |
ce7a788f | 1089 | unsigned int val; |
1081f3a7 | 1090 | int rc; |
9575bf26 | 1091 | |
ce7a788f | 1092 | if (kstrtouint(buf, 0, &val) || val > 1) |
9575bf26 HH |
1093 | return -EINVAL; |
1094 | ||
1081f3a7 JH |
1095 | rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_ERPLOG, val); |
1096 | ||
1097 | return rc ? : count; | |
9575bf26 HH |
1098 | } |
1099 | ||
1100 | static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store); | |
1da177e4 LT |
1101 | |
1102 | /* | |
1103 | * use_diag controls whether the driver should use diag rather than ssch | |
1104 | * to talk to the device | |
1105 | */ | |
138c014d | 1106 | static ssize_t |
e404e274 | 1107 | dasd_use_diag_show(struct device *dev, struct device_attribute *attr, char *buf) |
1da177e4 LT |
1108 | { |
1109 | struct dasd_devmap *devmap; | |
1110 | int use_diag; | |
1111 | ||
2a0217d5 | 1112 | devmap = dasd_find_busid(dev_name(dev)); |
1da177e4 LT |
1113 | if (!IS_ERR(devmap)) |
1114 | use_diag = (devmap->features & DASD_FEATURE_USEDIAG) != 0; | |
1115 | else | |
1116 | use_diag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USEDIAG) != 0; | |
9c386d0f | 1117 | return sysfs_emit(buf, use_diag ? "1\n" : "0\n"); |
1da177e4 LT |
1118 | } |
1119 | ||
1120 | static ssize_t | |
138c014d HH |
1121 | dasd_use_diag_store(struct device *dev, struct device_attribute *attr, |
1122 | const char *buf, size_t count) | |
1da177e4 LT |
1123 | { |
1124 | struct dasd_devmap *devmap; | |
ce7a788f | 1125 | unsigned int val; |
1da177e4 | 1126 | ssize_t rc; |
1da177e4 LT |
1127 | |
1128 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | |
1129 | if (IS_ERR(devmap)) | |
1130 | return PTR_ERR(devmap); | |
01376f44 | 1131 | |
ce7a788f | 1132 | if (kstrtouint(buf, 0, &val) || val > 1) |
01376f44 HH |
1133 | return -EINVAL; |
1134 | ||
1da177e4 LT |
1135 | spin_lock(&dasd_devmap_lock); |
1136 | /* Changing diag discipline flag is only allowed in offline state. */ | |
1137 | rc = count; | |
e4dbb0f2 | 1138 | if (!devmap->device && !(devmap->features & DASD_FEATURE_USERAW)) { |
01376f44 | 1139 | if (val) |
1da177e4 LT |
1140 | devmap->features |= DASD_FEATURE_USEDIAG; |
1141 | else | |
1142 | devmap->features &= ~DASD_FEATURE_USEDIAG; | |
1143 | } else | |
1144 | rc = -EPERM; | |
1145 | spin_unlock(&dasd_devmap_lock); | |
1146 | return rc; | |
1147 | } | |
1148 | ||
138c014d | 1149 | static DEVICE_ATTR(use_diag, 0644, dasd_use_diag_show, dasd_use_diag_store); |
1da177e4 | 1150 | |
e4dbb0f2 SH |
1151 | /* |
1152 | * use_raw controls whether the driver should give access to raw eckd data or | |
1153 | * operate in standard mode | |
1154 | */ | |
1155 | static ssize_t | |
1156 | dasd_use_raw_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1157 | { | |
1158 | struct dasd_devmap *devmap; | |
1159 | int use_raw; | |
1160 | ||
1161 | devmap = dasd_find_busid(dev_name(dev)); | |
1162 | if (!IS_ERR(devmap)) | |
1163 | use_raw = (devmap->features & DASD_FEATURE_USERAW) != 0; | |
1164 | else | |
1165 | use_raw = (DASD_FEATURE_DEFAULT & DASD_FEATURE_USERAW) != 0; | |
9c386d0f | 1166 | return sysfs_emit(buf, use_raw ? "1\n" : "0\n"); |
e4dbb0f2 SH |
1167 | } |
1168 | ||
1169 | static ssize_t | |
1170 | dasd_use_raw_store(struct device *dev, struct device_attribute *attr, | |
1171 | const char *buf, size_t count) | |
1172 | { | |
1173 | struct dasd_devmap *devmap; | |
1174 | ssize_t rc; | |
1175 | unsigned long val; | |
1176 | ||
1177 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | |
1178 | if (IS_ERR(devmap)) | |
1179 | return PTR_ERR(devmap); | |
1180 | ||
0178722b | 1181 | if ((kstrtoul(buf, 10, &val) != 0) || val > 1) |
e4dbb0f2 SH |
1182 | return -EINVAL; |
1183 | ||
1184 | spin_lock(&dasd_devmap_lock); | |
1185 | /* Changing diag discipline flag is only allowed in offline state. */ | |
1186 | rc = count; | |
1187 | if (!devmap->device && !(devmap->features & DASD_FEATURE_USEDIAG)) { | |
1188 | if (val) | |
1189 | devmap->features |= DASD_FEATURE_USERAW; | |
1190 | else | |
1191 | devmap->features &= ~DASD_FEATURE_USERAW; | |
1192 | } else | |
1193 | rc = -EPERM; | |
1194 | spin_unlock(&dasd_devmap_lock); | |
1195 | return rc; | |
1196 | } | |
1197 | ||
1198 | static DEVICE_ATTR(raw_track_access, 0644, dasd_use_raw_show, | |
1199 | dasd_use_raw_store); | |
1200 | ||
d07dc5d8 SH |
1201 | static ssize_t |
1202 | dasd_safe_offline_store(struct device *dev, struct device_attribute *attr, | |
1203 | const char *buf, size_t count) | |
1204 | { | |
1205 | struct ccw_device *cdev = to_ccwdev(dev); | |
1206 | struct dasd_device *device; | |
2757fe1d | 1207 | unsigned long flags; |
d07dc5d8 SH |
1208 | int rc; |
1209 | ||
2757fe1d SH |
1210 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
1211 | device = dasd_device_from_cdev_locked(cdev); | |
d07dc5d8 SH |
1212 | if (IS_ERR(device)) { |
1213 | rc = PTR_ERR(device); | |
2757fe1d | 1214 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
d07dc5d8 SH |
1215 | goto out; |
1216 | } | |
1217 | ||
1218 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags) || | |
1219 | test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { | |
1220 | /* Already doing offline processing */ | |
1221 | dasd_put_device(device); | |
2757fe1d | 1222 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
d07dc5d8 SH |
1223 | rc = -EBUSY; |
1224 | goto out; | |
1225 | } | |
1226 | ||
1227 | set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags); | |
1228 | dasd_put_device(device); | |
2757fe1d | 1229 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
d07dc5d8 SH |
1230 | |
1231 | rc = ccw_device_set_offline(cdev); | |
1232 | ||
1233 | out: | |
1234 | return rc ? rc : count; | |
1235 | } | |
1236 | ||
1237 | static DEVICE_ATTR(safe_offline, 0200, NULL, dasd_safe_offline_store); | |
1238 | ||
5a3b7b11 SH |
1239 | static ssize_t |
1240 | dasd_access_show(struct device *dev, struct device_attribute *attr, | |
1241 | char *buf) | |
1242 | { | |
1243 | struct ccw_device *cdev = to_ccwdev(dev); | |
1244 | struct dasd_device *device; | |
1245 | int count; | |
1246 | ||
1247 | device = dasd_device_from_cdev(cdev); | |
1248 | if (IS_ERR(device)) | |
1249 | return PTR_ERR(device); | |
1250 | ||
a521b048 SH |
1251 | if (!device->discipline) |
1252 | count = -ENODEV; | |
1253 | else if (!device->discipline->host_access_count) | |
5a3b7b11 | 1254 | count = -EOPNOTSUPP; |
a521b048 SH |
1255 | else |
1256 | count = device->discipline->host_access_count(device); | |
5a3b7b11 SH |
1257 | |
1258 | dasd_put_device(device); | |
1259 | if (count < 0) | |
1260 | return count; | |
1261 | ||
9c386d0f | 1262 | return sysfs_emit(buf, "%d\n", count); |
5a3b7b11 SH |
1263 | } |
1264 | ||
1265 | static DEVICE_ATTR(host_access_count, 0444, dasd_access_show, NULL); | |
1266 | ||
1da177e4 | 1267 | static ssize_t |
138c014d HH |
1268 | dasd_discipline_show(struct device *dev, struct device_attribute *attr, |
1269 | char *buf) | |
1da177e4 | 1270 | { |
a00bfd71 MS |
1271 | struct dasd_device *device; |
1272 | ssize_t len; | |
1da177e4 | 1273 | |
a00bfd71 | 1274 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
589c74d5 SH |
1275 | if (IS_ERR(device)) |
1276 | goto out; | |
1277 | else if (!device->discipline) { | |
1278 | dasd_put_device(device); | |
1279 | goto out; | |
1280 | } else { | |
4b9e0436 QW |
1281 | len = sysfs_emit(buf, "%s\n", |
1282 | device->discipline->name); | |
a00bfd71 | 1283 | dasd_put_device(device); |
589c74d5 SH |
1284 | return len; |
1285 | } | |
1286 | out: | |
4b9e0436 | 1287 | len = sysfs_emit(buf, "none\n"); |
a00bfd71 | 1288 | return len; |
1da177e4 LT |
1289 | } |
1290 | ||
1291 | static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL); | |
1292 | ||
4dfd5c45 HH |
1293 | static ssize_t |
1294 | dasd_device_status_show(struct device *dev, struct device_attribute *attr, | |
1295 | char *buf) | |
1296 | { | |
1297 | struct dasd_device *device; | |
1298 | ssize_t len; | |
1299 | ||
1300 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1301 | if (!IS_ERR(device)) { | |
1302 | switch (device->state) { | |
1303 | case DASD_STATE_NEW: | |
4b9e0436 | 1304 | len = sysfs_emit(buf, "new\n"); |
4dfd5c45 HH |
1305 | break; |
1306 | case DASD_STATE_KNOWN: | |
4b9e0436 | 1307 | len = sysfs_emit(buf, "detected\n"); |
4dfd5c45 HH |
1308 | break; |
1309 | case DASD_STATE_BASIC: | |
4b9e0436 | 1310 | len = sysfs_emit(buf, "basic\n"); |
4dfd5c45 HH |
1311 | break; |
1312 | case DASD_STATE_UNFMT: | |
4b9e0436 | 1313 | len = sysfs_emit(buf, "unformatted\n"); |
4dfd5c45 HH |
1314 | break; |
1315 | case DASD_STATE_READY: | |
4b9e0436 | 1316 | len = sysfs_emit(buf, "ready\n"); |
4dfd5c45 HH |
1317 | break; |
1318 | case DASD_STATE_ONLINE: | |
4b9e0436 | 1319 | len = sysfs_emit(buf, "online\n"); |
4dfd5c45 HH |
1320 | break; |
1321 | default: | |
4b9e0436 | 1322 | len = sysfs_emit(buf, "no stat\n"); |
4dfd5c45 HH |
1323 | break; |
1324 | } | |
1325 | dasd_put_device(device); | |
1326 | } else | |
4b9e0436 | 1327 | len = sysfs_emit(buf, "unknown\n"); |
4dfd5c45 HH |
1328 | return len; |
1329 | } | |
1330 | ||
1331 | static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL); | |
1332 | ||
2dedf0d9 SH |
1333 | static ssize_t dasd_alias_show(struct device *dev, |
1334 | struct device_attribute *attr, char *buf) | |
3d052595 | 1335 | { |
2dedf0d9 SH |
1336 | struct dasd_device *device; |
1337 | struct dasd_uid uid; | |
3d052595 | 1338 | |
2dedf0d9 SH |
1339 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
1340 | if (IS_ERR(device)) | |
9c386d0f | 1341 | return sysfs_emit(buf, "0\n"); |
2dedf0d9 SH |
1342 | |
1343 | if (device->discipline && device->discipline->get_uid && | |
1344 | !device->discipline->get_uid(device, &uid)) { | |
1345 | if (uid.type == UA_BASE_PAV_ALIAS || | |
0abccf77 SH |
1346 | uid.type == UA_HYPER_PAV_ALIAS) { |
1347 | dasd_put_device(device); | |
9c386d0f | 1348 | return sysfs_emit(buf, "1\n"); |
0abccf77 | 1349 | } |
8e09f215 | 1350 | } |
2dedf0d9 SH |
1351 | dasd_put_device(device); |
1352 | ||
9c386d0f | 1353 | return sysfs_emit(buf, "0\n"); |
3d052595 HH |
1354 | } |
1355 | ||
1356 | static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL); | |
1357 | ||
2dedf0d9 SH |
1358 | static ssize_t dasd_vendor_show(struct device *dev, |
1359 | struct device_attribute *attr, char *buf) | |
3d052595 | 1360 | { |
2dedf0d9 SH |
1361 | struct dasd_device *device; |
1362 | struct dasd_uid uid; | |
3d052595 HH |
1363 | char *vendor; |
1364 | ||
2dedf0d9 SH |
1365 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
1366 | vendor = ""; | |
1367 | if (IS_ERR(device)) | |
4b9e0436 | 1368 | return sysfs_emit(buf, "%s\n", vendor); |
2dedf0d9 SH |
1369 | |
1370 | if (device->discipline && device->discipline->get_uid && | |
1371 | !device->discipline->get_uid(device, &uid)) | |
1372 | vendor = uid.vendor; | |
1373 | ||
1374 | dasd_put_device(device); | |
3d052595 | 1375 | |
4b9e0436 | 1376 | return sysfs_emit(buf, "%s\n", vendor); |
3d052595 HH |
1377 | } |
1378 | ||
1379 | static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL); | |
1380 | ||
3d052595 HH |
1381 | static ssize_t |
1382 | dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1383 | { | |
f7cf2242 | 1384 | char uid_string[DASD_UID_STRLEN]; |
2dedf0d9 SH |
1385 | struct dasd_device *device; |
1386 | struct dasd_uid uid; | |
8e09f215 | 1387 | char ua_string[3]; |
3d052595 | 1388 | |
2dedf0d9 SH |
1389 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
1390 | uid_string[0] = 0; | |
1391 | if (IS_ERR(device)) | |
4b9e0436 | 1392 | return sysfs_emit(buf, "%s\n", uid_string); |
2dedf0d9 SH |
1393 | |
1394 | if (device->discipline && device->discipline->get_uid && | |
1395 | !device->discipline->get_uid(device, &uid)) { | |
1396 | switch (uid.type) { | |
1397 | case UA_BASE_DEVICE: | |
1398 | snprintf(ua_string, sizeof(ua_string), "%02x", | |
1399 | uid.real_unit_addr); | |
1400 | break; | |
1401 | case UA_BASE_PAV_ALIAS: | |
1402 | snprintf(ua_string, sizeof(ua_string), "%02x", | |
1403 | uid.base_unit_addr); | |
1404 | break; | |
1405 | case UA_HYPER_PAV_ALIAS: | |
1406 | snprintf(ua_string, sizeof(ua_string), "xx"); | |
1407 | break; | |
1408 | default: | |
1409 | /* should not happen, treat like base device */ | |
1410 | snprintf(ua_string, sizeof(ua_string), "%02x", | |
1411 | uid.real_unit_addr); | |
1412 | break; | |
1413 | } | |
1414 | ||
e5de34db JH |
1415 | snprintf(uid_string, sizeof(uid_string), "%s.%s.%04x.%s%s%s", |
1416 | uid.vendor, uid.serial, uid.ssid, ua_string, | |
1417 | uid.vduit[0] ? "." : "", uid.vduit); | |
8e09f215 | 1418 | } |
2dedf0d9 SH |
1419 | dasd_put_device(device); |
1420 | ||
4b9e0436 | 1421 | return sysfs_emit(buf, "%s\n", uid_string); |
3d052595 | 1422 | } |
3d052595 HH |
1423 | static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL); |
1424 | ||
20c64468 SW |
1425 | /* |
1426 | * extended error-reporting | |
1427 | */ | |
1428 | static ssize_t | |
1429 | dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1430 | { | |
1431 | struct dasd_devmap *devmap; | |
1432 | int eer_flag; | |
1433 | ||
2a0217d5 | 1434 | devmap = dasd_find_busid(dev_name(dev)); |
20c64468 SW |
1435 | if (!IS_ERR(devmap) && devmap->device) |
1436 | eer_flag = dasd_eer_enabled(devmap->device); | |
1437 | else | |
1438 | eer_flag = 0; | |
4b9e0436 | 1439 | return sysfs_emit(buf, eer_flag ? "1\n" : "0\n"); |
20c64468 SW |
1440 | } |
1441 | ||
1442 | static ssize_t | |
1443 | dasd_eer_store(struct device *dev, struct device_attribute *attr, | |
1444 | const char *buf, size_t count) | |
1445 | { | |
9de67725 | 1446 | struct dasd_device *device; |
ce7a788f | 1447 | unsigned int val; |
9de67725 | 1448 | int rc = 0; |
20c64468 | 1449 | |
9de67725 JH |
1450 | device = dasd_device_from_cdev(to_ccwdev(dev)); |
1451 | if (IS_ERR(device)) | |
1452 | return PTR_ERR(device); | |
01376f44 | 1453 | |
ce7a788f | 1454 | if (kstrtouint(buf, 0, &val) || val > 1) |
01376f44 HH |
1455 | return -EINVAL; |
1456 | ||
9de67725 JH |
1457 | if (val) |
1458 | rc = dasd_eer_enable(device); | |
1459 | else | |
1460 | dasd_eer_disable(device); | |
1461 | ||
1462 | dasd_put_device(device); | |
1463 | ||
1464 | return rc ? : count; | |
20c64468 SW |
1465 | } |
1466 | ||
1467 | static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store); | |
1468 | ||
9558a8e9 SH |
1469 | /* |
1470 | * aq_mask controls if the DASD should be quiesced on certain triggers | |
1471 | * The aq_mask attribute is interpreted as bitmap of the DASD_EER_* triggers. | |
1472 | */ | |
1473 | static ssize_t dasd_aq_mask_show(struct device *dev, struct device_attribute *attr, | |
1474 | char *buf) | |
1475 | { | |
1476 | struct dasd_devmap *devmap; | |
1477 | unsigned int aq_mask = 0; | |
1478 | ||
1479 | devmap = dasd_find_busid(dev_name(dev)); | |
1480 | if (!IS_ERR(devmap)) | |
1481 | aq_mask = devmap->aq_mask; | |
1482 | ||
1483 | return sysfs_emit(buf, "%d\n", aq_mask); | |
1484 | } | |
1485 | ||
1486 | static ssize_t dasd_aq_mask_store(struct device *dev, struct device_attribute *attr, | |
1487 | const char *buf, size_t count) | |
1488 | { | |
1489 | struct dasd_devmap *devmap; | |
1490 | unsigned int val; | |
1491 | ||
1492 | if (kstrtouint(buf, 0, &val) || val > DASD_EER_VALID) | |
1493 | return -EINVAL; | |
1494 | ||
1495 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | |
1496 | if (IS_ERR(devmap)) | |
1497 | return PTR_ERR(devmap); | |
1498 | ||
1499 | spin_lock(&dasd_devmap_lock); | |
1500 | devmap->aq_mask = val; | |
1501 | if (devmap->device) | |
1502 | devmap->device->aq_mask = devmap->aq_mask; | |
1503 | spin_unlock(&dasd_devmap_lock); | |
1504 | ||
1505 | return count; | |
1506 | } | |
1507 | ||
1508 | static DEVICE_ATTR(aq_mask, 0644, dasd_aq_mask_show, dasd_aq_mask_store); | |
1509 | ||
bdac94e2 SH |
1510 | /* |
1511 | * aq_requeue controls if requests are returned to the blocklayer on quiesce | |
1512 | * or if requests are only not started | |
1513 | */ | |
1514 | static ssize_t dasd_aqr_show(struct device *dev, struct device_attribute *attr, | |
1515 | char *buf) | |
1516 | { | |
1517 | struct dasd_devmap *devmap; | |
1518 | int flag; | |
1519 | ||
1520 | devmap = dasd_find_busid(dev_name(dev)); | |
1521 | if (!IS_ERR(devmap)) | |
1522 | flag = (devmap->features & DASD_FEATURE_REQUEUEQUIESCE) != 0; | |
1523 | else | |
1524 | flag = (DASD_FEATURE_DEFAULT & | |
1525 | DASD_FEATURE_REQUEUEQUIESCE) != 0; | |
1526 | return sysfs_emit(buf, "%d\n", flag); | |
1527 | } | |
1528 | ||
1529 | static ssize_t dasd_aqr_store(struct device *dev, struct device_attribute *attr, | |
1530 | const char *buf, size_t count) | |
1531 | { | |
1532 | bool val; | |
1533 | int rc; | |
1534 | ||
1535 | if (kstrtobool(buf, &val)) | |
1536 | return -EINVAL; | |
1537 | ||
1538 | rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_REQUEUEQUIESCE, val); | |
1539 | ||
1540 | return rc ? : count; | |
1541 | } | |
1542 | ||
1543 | static DEVICE_ATTR(aq_requeue, 0644, dasd_aqr_show, dasd_aqr_store); | |
1544 | ||
0c1a1474 SH |
1545 | /* |
1546 | * aq_timeouts controls how much retries have to time out until | |
1547 | * a device gets autoquiesced | |
1548 | */ | |
1549 | static ssize_t | |
1550 | dasd_aq_timeouts_show(struct device *dev, struct device_attribute *attr, | |
1551 | char *buf) | |
1552 | { | |
1553 | struct dasd_device *device; | |
1554 | int len; | |
1555 | ||
1556 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1557 | if (IS_ERR(device)) | |
1558 | return -ENODEV; | |
1559 | len = sysfs_emit(buf, "%u\n", device->aq_timeouts); | |
1560 | dasd_put_device(device); | |
1561 | return len; | |
1562 | } | |
1563 | ||
1564 | static ssize_t | |
1565 | dasd_aq_timeouts_store(struct device *dev, struct device_attribute *attr, | |
1566 | const char *buf, size_t count) | |
1567 | { | |
1568 | struct dasd_device *device; | |
1569 | unsigned int val; | |
1570 | ||
1571 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1572 | if (IS_ERR(device)) | |
1573 | return -ENODEV; | |
1574 | ||
1575 | if ((kstrtouint(buf, 10, &val) != 0) || | |
1576 | val > DASD_RETRIES_MAX || val == 0) { | |
1577 | dasd_put_device(device); | |
1578 | return -EINVAL; | |
1579 | } | |
1580 | ||
1581 | if (val) | |
1582 | device->aq_timeouts = val; | |
1583 | ||
1584 | dasd_put_device(device); | |
1585 | return count; | |
1586 | } | |
1587 | ||
1588 | static DEVICE_ATTR(aq_timeouts, 0644, dasd_aq_timeouts_show, | |
1589 | dasd_aq_timeouts_store); | |
1590 | ||
7c8faa86 SH |
1591 | /* |
1592 | * expiration time for default requests | |
1593 | */ | |
1594 | static ssize_t | |
1595 | dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1596 | { | |
1597 | struct dasd_device *device; | |
1598 | int len; | |
1599 | ||
1600 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1601 | if (IS_ERR(device)) | |
1602 | return -ENODEV; | |
4b9e0436 | 1603 | len = sysfs_emit(buf, "%lu\n", device->default_expires); |
7c8faa86 SH |
1604 | dasd_put_device(device); |
1605 | return len; | |
1606 | } | |
1607 | ||
1608 | static ssize_t | |
1609 | dasd_expires_store(struct device *dev, struct device_attribute *attr, | |
1610 | const char *buf, size_t count) | |
1611 | { | |
1612 | struct dasd_device *device; | |
1613 | unsigned long val; | |
1614 | ||
1615 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1616 | if (IS_ERR(device)) | |
1617 | return -ENODEV; | |
1618 | ||
0178722b | 1619 | if ((kstrtoul(buf, 10, &val) != 0) || |
7c8faa86 SH |
1620 | (val > DASD_EXPIRES_MAX) || val == 0) { |
1621 | dasd_put_device(device); | |
1622 | return -EINVAL; | |
1623 | } | |
1624 | ||
1625 | if (val) | |
1626 | device->default_expires = val; | |
1627 | ||
1628 | dasd_put_device(device); | |
1629 | return count; | |
1630 | } | |
1631 | ||
1632 | static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store); | |
1633 | ||
1f1ee9ad HR |
1634 | static ssize_t |
1635 | dasd_retries_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1636 | { | |
1637 | struct dasd_device *device; | |
1638 | int len; | |
1639 | ||
1640 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1641 | if (IS_ERR(device)) | |
1642 | return -ENODEV; | |
4b9e0436 | 1643 | len = sysfs_emit(buf, "%lu\n", device->default_retries); |
1f1ee9ad HR |
1644 | dasd_put_device(device); |
1645 | return len; | |
1646 | } | |
1647 | ||
1648 | static ssize_t | |
1649 | dasd_retries_store(struct device *dev, struct device_attribute *attr, | |
1650 | const char *buf, size_t count) | |
1651 | { | |
1652 | struct dasd_device *device; | |
1653 | unsigned long val; | |
1654 | ||
1655 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1656 | if (IS_ERR(device)) | |
1657 | return -ENODEV; | |
1658 | ||
0178722b | 1659 | if ((kstrtoul(buf, 10, &val) != 0) || |
1f1ee9ad HR |
1660 | (val > DASD_RETRIES_MAX)) { |
1661 | dasd_put_device(device); | |
1662 | return -EINVAL; | |
1663 | } | |
1664 | ||
1665 | if (val) | |
1666 | device->default_retries = val; | |
1667 | ||
1668 | dasd_put_device(device); | |
1669 | return count; | |
1670 | } | |
1671 | ||
1672 | static DEVICE_ATTR(retries, 0644, dasd_retries_show, dasd_retries_store); | |
1673 | ||
3d71ad32 HR |
1674 | static ssize_t |
1675 | dasd_timeout_show(struct device *dev, struct device_attribute *attr, | |
1676 | char *buf) | |
1677 | { | |
1678 | struct dasd_device *device; | |
1679 | int len; | |
1680 | ||
1681 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1682 | if (IS_ERR(device)) | |
1683 | return -ENODEV; | |
4b9e0436 | 1684 | len = sysfs_emit(buf, "%lu\n", device->blk_timeout); |
3d71ad32 HR |
1685 | dasd_put_device(device); |
1686 | return len; | |
1687 | } | |
1688 | ||
1689 | static ssize_t | |
1690 | dasd_timeout_store(struct device *dev, struct device_attribute *attr, | |
1691 | const char *buf, size_t count) | |
1692 | { | |
1693 | struct dasd_device *device; | |
e443343e | 1694 | unsigned long val; |
3d71ad32 HR |
1695 | |
1696 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1697 | if (IS_ERR(device) || !device->block) | |
1698 | return -ENODEV; | |
1699 | ||
0178722b | 1700 | if ((kstrtoul(buf, 10, &val) != 0) || |
3d71ad32 HR |
1701 | val > UINT_MAX / HZ) { |
1702 | dasd_put_device(device); | |
1703 | return -EINVAL; | |
1704 | } | |
c68f4f4e | 1705 | if (!device->block->gdp) { |
3d71ad32 HR |
1706 | dasd_put_device(device); |
1707 | return -ENODEV; | |
1708 | } | |
3d71ad32 HR |
1709 | |
1710 | device->blk_timeout = val; | |
c68f4f4e | 1711 | blk_queue_rq_timeout(device->block->gdp->queue, val * HZ); |
3d71ad32 HR |
1712 | |
1713 | dasd_put_device(device); | |
1714 | return count; | |
1715 | } | |
1716 | ||
1717 | static DEVICE_ATTR(timeout, 0644, | |
1718 | dasd_timeout_show, dasd_timeout_store); | |
1719 | ||
a521b048 SH |
1720 | |
1721 | static ssize_t | |
1722 | dasd_path_reset_store(struct device *dev, struct device_attribute *attr, | |
1723 | const char *buf, size_t count) | |
1724 | { | |
1725 | struct dasd_device *device; | |
1726 | unsigned int val; | |
1727 | ||
1728 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1729 | if (IS_ERR(device)) | |
1730 | return -ENODEV; | |
1731 | ||
1732 | if ((kstrtouint(buf, 16, &val) != 0) || val > 0xff) | |
1733 | val = 0; | |
1734 | ||
1735 | if (device->discipline && device->discipline->reset_path) | |
1736 | device->discipline->reset_path(device, (__u8) val); | |
1737 | ||
1738 | dasd_put_device(device); | |
1739 | return count; | |
1740 | } | |
1741 | ||
1742 | static DEVICE_ATTR(path_reset, 0200, NULL, dasd_path_reset_store); | |
1743 | ||
1744 | static ssize_t dasd_hpf_show(struct device *dev, struct device_attribute *attr, | |
1745 | char *buf) | |
1746 | { | |
1747 | struct dasd_device *device; | |
1748 | int hpf; | |
1749 | ||
1750 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1751 | if (IS_ERR(device)) | |
1752 | return -ENODEV; | |
1753 | if (!device->discipline || !device->discipline->hpf_enabled) { | |
1754 | dasd_put_device(device); | |
4b9e0436 | 1755 | return sysfs_emit(buf, "%d\n", dasd_nofcx); |
a521b048 SH |
1756 | } |
1757 | hpf = device->discipline->hpf_enabled(device); | |
1758 | dasd_put_device(device); | |
4b9e0436 | 1759 | return sysfs_emit(buf, "%d\n", hpf); |
a521b048 SH |
1760 | } |
1761 | ||
1762 | static DEVICE_ATTR(hpf, 0444, dasd_hpf_show, NULL); | |
1763 | ||
5a27e60d SW |
1764 | static ssize_t dasd_reservation_policy_show(struct device *dev, |
1765 | struct device_attribute *attr, | |
1766 | char *buf) | |
1767 | { | |
1768 | struct dasd_devmap *devmap; | |
1769 | int rc = 0; | |
1770 | ||
1771 | devmap = dasd_find_busid(dev_name(dev)); | |
1772 | if (IS_ERR(devmap)) { | |
4b9e0436 | 1773 | rc = sysfs_emit(buf, "ignore\n"); |
5a27e60d SW |
1774 | } else { |
1775 | spin_lock(&dasd_devmap_lock); | |
1776 | if (devmap->features & DASD_FEATURE_FAILONSLCK) | |
4b9e0436 | 1777 | rc = sysfs_emit(buf, "fail\n"); |
5a27e60d | 1778 | else |
4b9e0436 | 1779 | rc = sysfs_emit(buf, "ignore\n"); |
5a27e60d SW |
1780 | spin_unlock(&dasd_devmap_lock); |
1781 | } | |
1782 | return rc; | |
1783 | } | |
1784 | ||
1785 | static ssize_t dasd_reservation_policy_store(struct device *dev, | |
1786 | struct device_attribute *attr, | |
1787 | const char *buf, size_t count) | |
1788 | { | |
1081f3a7 | 1789 | struct ccw_device *cdev = to_ccwdev(dev); |
5a27e60d SW |
1790 | int rc; |
1791 | ||
5a27e60d | 1792 | if (sysfs_streq("ignore", buf)) |
1081f3a7 | 1793 | rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 0); |
5a27e60d | 1794 | else if (sysfs_streq("fail", buf)) |
1081f3a7 | 1795 | rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 1); |
5a27e60d SW |
1796 | else |
1797 | rc = -EINVAL; | |
1081f3a7 JH |
1798 | |
1799 | return rc ? : count; | |
5a27e60d SW |
1800 | } |
1801 | ||
1802 | static DEVICE_ATTR(reservation_policy, 0644, | |
1803 | dasd_reservation_policy_show, dasd_reservation_policy_store); | |
1804 | ||
1805 | static ssize_t dasd_reservation_state_show(struct device *dev, | |
1806 | struct device_attribute *attr, | |
1807 | char *buf) | |
1808 | { | |
1809 | struct dasd_device *device; | |
1810 | int rc = 0; | |
1811 | ||
1812 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1813 | if (IS_ERR(device)) | |
4b9e0436 | 1814 | return sysfs_emit(buf, "none\n"); |
5a27e60d SW |
1815 | |
1816 | if (test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) | |
4b9e0436 | 1817 | rc = sysfs_emit(buf, "reserved\n"); |
5a27e60d | 1818 | else if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) |
4b9e0436 | 1819 | rc = sysfs_emit(buf, "lost\n"); |
5a27e60d | 1820 | else |
4b9e0436 | 1821 | rc = sysfs_emit(buf, "none\n"); |
5a27e60d SW |
1822 | dasd_put_device(device); |
1823 | return rc; | |
1824 | } | |
1825 | ||
1826 | static ssize_t dasd_reservation_state_store(struct device *dev, | |
1827 | struct device_attribute *attr, | |
1828 | const char *buf, size_t count) | |
1829 | { | |
1830 | struct dasd_device *device; | |
1831 | int rc = 0; | |
1832 | ||
1833 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1834 | if (IS_ERR(device)) | |
1835 | return -ENODEV; | |
1836 | if (sysfs_streq("reset", buf)) | |
1837 | clear_bit(DASD_FLAG_LOCK_STOLEN, &device->flags); | |
1838 | else | |
1839 | rc = -EINVAL; | |
1840 | dasd_put_device(device); | |
1841 | ||
1842 | if (rc) | |
1843 | return rc; | |
1844 | else | |
1845 | return count; | |
1846 | } | |
1847 | ||
1848 | static DEVICE_ATTR(last_known_reservation_state, 0644, | |
1849 | dasd_reservation_state_show, dasd_reservation_state_store); | |
1850 | ||
5db8440c SH |
1851 | static ssize_t dasd_pm_show(struct device *dev, |
1852 | struct device_attribute *attr, char *buf) | |
1853 | { | |
1854 | struct dasd_device *device; | |
a521b048 | 1855 | u8 opm, nppm, cablepm, cuirpm, hpfpm, ifccpm; |
5db8440c SH |
1856 | |
1857 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1858 | if (IS_ERR(device)) | |
9c386d0f | 1859 | return sysfs_emit(buf, "0\n"); |
5db8440c | 1860 | |
c9346151 SH |
1861 | opm = dasd_path_get_opm(device); |
1862 | nppm = dasd_path_get_nppm(device); | |
1863 | cablepm = dasd_path_get_cablepm(device); | |
1864 | cuirpm = dasd_path_get_cuirpm(device); | |
1865 | hpfpm = dasd_path_get_hpfpm(device); | |
a521b048 | 1866 | ifccpm = dasd_path_get_ifccpm(device); |
5db8440c SH |
1867 | dasd_put_device(device); |
1868 | ||
9c386d0f JH |
1869 | return sysfs_emit(buf, "%02x %02x %02x %02x %02x %02x\n", opm, nppm, |
1870 | cablepm, cuirpm, hpfpm, ifccpm); | |
5db8440c SH |
1871 | } |
1872 | ||
1873 | static DEVICE_ATTR(path_masks, 0444, dasd_pm_show, NULL); | |
1874 | ||
a521b048 SH |
1875 | /* |
1876 | * threshold value for IFCC/CCC errors | |
1877 | */ | |
1878 | static ssize_t | |
1879 | dasd_path_threshold_show(struct device *dev, | |
1880 | struct device_attribute *attr, char *buf) | |
1881 | { | |
1882 | struct dasd_device *device; | |
1883 | int len; | |
1884 | ||
1885 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1886 | if (IS_ERR(device)) | |
1887 | return -ENODEV; | |
4b9e0436 | 1888 | len = sysfs_emit(buf, "%lu\n", device->path_thrhld); |
a521b048 SH |
1889 | dasd_put_device(device); |
1890 | return len; | |
1891 | } | |
1892 | ||
1893 | static ssize_t | |
1894 | dasd_path_threshold_store(struct device *dev, struct device_attribute *attr, | |
1895 | const char *buf, size_t count) | |
1896 | { | |
1897 | struct dasd_device *device; | |
1898 | unsigned long flags; | |
1899 | unsigned long val; | |
1900 | ||
1901 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1902 | if (IS_ERR(device)) | |
1903 | return -ENODEV; | |
1904 | ||
defc2a9b | 1905 | if (kstrtoul(buf, 10, &val) != 0 || val > DASD_THRHLD_MAX) { |
a521b048 SH |
1906 | dasd_put_device(device); |
1907 | return -EINVAL; | |
1908 | } | |
1909 | spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags); | |
defc2a9b | 1910 | device->path_thrhld = val; |
a521b048 SH |
1911 | spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags); |
1912 | dasd_put_device(device); | |
1913 | return count; | |
1914 | } | |
a521b048 SH |
1915 | static DEVICE_ATTR(path_threshold, 0644, dasd_path_threshold_show, |
1916 | dasd_path_threshold_store); | |
ddc1c945 SH |
1917 | |
1918 | /* | |
1919 | * configure if path is disabled after IFCC/CCC error threshold is | |
1920 | * exceeded | |
1921 | */ | |
1922 | static ssize_t | |
1923 | dasd_path_autodisable_show(struct device *dev, | |
1924 | struct device_attribute *attr, char *buf) | |
1925 | { | |
1926 | struct dasd_devmap *devmap; | |
1927 | int flag; | |
1928 | ||
1929 | devmap = dasd_find_busid(dev_name(dev)); | |
1930 | if (!IS_ERR(devmap)) | |
1931 | flag = (devmap->features & DASD_FEATURE_PATH_AUTODISABLE) != 0; | |
1932 | else | |
1933 | flag = (DASD_FEATURE_DEFAULT & | |
1934 | DASD_FEATURE_PATH_AUTODISABLE) != 0; | |
4b9e0436 | 1935 | return sysfs_emit(buf, flag ? "1\n" : "0\n"); |
ddc1c945 SH |
1936 | } |
1937 | ||
1938 | static ssize_t | |
1939 | dasd_path_autodisable_store(struct device *dev, | |
1940 | struct device_attribute *attr, | |
1941 | const char *buf, size_t count) | |
1942 | { | |
1943 | unsigned int val; | |
1944 | int rc; | |
1945 | ||
1946 | if (kstrtouint(buf, 0, &val) || val > 1) | |
1947 | return -EINVAL; | |
1948 | ||
1949 | rc = dasd_set_feature(to_ccwdev(dev), | |
1950 | DASD_FEATURE_PATH_AUTODISABLE, val); | |
1951 | ||
1952 | return rc ? : count; | |
1953 | } | |
1954 | ||
1955 | static DEVICE_ATTR(path_autodisable, 0644, | |
1956 | dasd_path_autodisable_show, | |
1957 | dasd_path_autodisable_store); | |
a521b048 SH |
1958 | /* |
1959 | * interval for IFCC/CCC checks | |
1960 | * meaning time with no IFCC/CCC error before the error counter | |
1961 | * gets reset | |
1962 | */ | |
1963 | static ssize_t | |
1964 | dasd_path_interval_show(struct device *dev, | |
1965 | struct device_attribute *attr, char *buf) | |
1966 | { | |
1967 | struct dasd_device *device; | |
1968 | int len; | |
1969 | ||
1970 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1971 | if (IS_ERR(device)) | |
1972 | return -ENODEV; | |
4b9e0436 | 1973 | len = sysfs_emit(buf, "%lu\n", device->path_interval); |
a521b048 SH |
1974 | dasd_put_device(device); |
1975 | return len; | |
1976 | } | |
1977 | ||
1978 | static ssize_t | |
1979 | dasd_path_interval_store(struct device *dev, struct device_attribute *attr, | |
1980 | const char *buf, size_t count) | |
1981 | { | |
1982 | struct dasd_device *device; | |
1983 | unsigned long flags; | |
1984 | unsigned long val; | |
1985 | ||
1986 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
1987 | if (IS_ERR(device)) | |
1988 | return -ENODEV; | |
1989 | ||
1990 | if ((kstrtoul(buf, 10, &val) != 0) || | |
1991 | (val > DASD_INTERVAL_MAX) || val == 0) { | |
1992 | dasd_put_device(device); | |
1993 | return -EINVAL; | |
1994 | } | |
1995 | spin_lock_irqsave(get_ccwdev_lock(to_ccwdev(dev)), flags); | |
1996 | if (val) | |
1997 | device->path_interval = val; | |
1998 | spin_unlock_irqrestore(get_ccwdev_lock(to_ccwdev(dev)), flags); | |
1999 | dasd_put_device(device); | |
2000 | return count; | |
2001 | } | |
2002 | ||
2003 | static DEVICE_ATTR(path_interval, 0644, dasd_path_interval_show, | |
2004 | dasd_path_interval_store); | |
2005 | ||
19508b20 JH |
2006 | static ssize_t |
2007 | dasd_device_fcs_show(struct device *dev, struct device_attribute *attr, | |
2008 | char *buf) | |
2009 | { | |
2010 | struct dasd_device *device; | |
2011 | int fc_sec; | |
2012 | int rc; | |
2013 | ||
2014 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
2015 | if (IS_ERR(device)) | |
2016 | return -ENODEV; | |
2017 | fc_sec = dasd_path_get_fcs_device(device); | |
2018 | if (fc_sec == -EINVAL) | |
4b9e0436 | 2019 | rc = sysfs_emit(buf, "Inconsistent\n"); |
19508b20 | 2020 | else |
4b9e0436 | 2021 | rc = sysfs_emit(buf, "%s\n", dasd_path_get_fcs_str(fc_sec)); |
19508b20 JH |
2022 | dasd_put_device(device); |
2023 | ||
2024 | return rc; | |
2025 | } | |
2026 | static DEVICE_ATTR(fc_security, 0444, dasd_device_fcs_show, NULL); | |
2027 | ||
2028 | static ssize_t | |
2029 | dasd_path_fcs_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) | |
2030 | { | |
2031 | struct dasd_path *path = to_dasd_path(kobj); | |
2032 | unsigned int fc_sec = path->fc_security; | |
2033 | ||
4b9e0436 | 2034 | return sysfs_emit(buf, "%s\n", dasd_path_get_fcs_str(fc_sec)); |
19508b20 JH |
2035 | } |
2036 | ||
2037 | static struct kobj_attribute path_fcs_attribute = | |
2038 | __ATTR(fc_security, 0444, dasd_path_fcs_show, NULL); | |
a521b048 | 2039 | |
a91ff09d SH |
2040 | /* |
2041 | * print copy relation in the form | |
2042 | * primary,secondary[1] primary,secondary[2], ... | |
2043 | */ | |
2044 | static ssize_t | |
2045 | dasd_copy_pair_show(struct device *dev, | |
2046 | struct device_attribute *attr, char *buf) | |
2047 | { | |
2048 | char prim_busid[DASD_BUS_ID_SIZE]; | |
2049 | struct dasd_copy_relation *copy; | |
2050 | struct dasd_devmap *devmap; | |
2051 | int len = 0; | |
2052 | int i; | |
2053 | ||
2054 | devmap = dasd_find_busid(dev_name(dev)); | |
2055 | if (IS_ERR(devmap)) | |
2056 | return -ENODEV; | |
2057 | ||
2058 | if (!devmap->copy) | |
2059 | return -ENODEV; | |
2060 | ||
2061 | copy = devmap->copy; | |
2062 | /* find primary */ | |
2063 | for (i = 0; i < DASD_CP_ENTRIES; i++) { | |
2064 | if (copy->entry[i].configured && copy->entry[i].primary) { | |
2065 | strscpy(prim_busid, copy->entry[i].busid, | |
2066 | DASD_BUS_ID_SIZE); | |
2067 | break; | |
2068 | } | |
2069 | } | |
7e8a05b4 | 2070 | if (i == DASD_CP_ENTRIES) |
a91ff09d SH |
2071 | goto out; |
2072 | ||
2073 | /* print all secondary */ | |
2074 | for (i = 0; i < DASD_CP_ENTRIES; i++) { | |
2075 | if (copy->entry[i].configured && !copy->entry[i].primary) | |
2076 | len += sysfs_emit_at(buf, len, "%s,%s ", prim_busid, | |
2077 | copy->entry[i].busid); | |
2078 | } | |
2079 | ||
2080 | len += sysfs_emit_at(buf, len, "\n"); | |
2081 | out: | |
2082 | return len; | |
2083 | } | |
2084 | ||
2085 | static int dasd_devmap_set_copy_relation(struct dasd_devmap *devmap, | |
2086 | struct dasd_copy_relation *copy, | |
2087 | char *busid, bool primary) | |
2088 | { | |
2089 | int i; | |
2090 | ||
2091 | /* find free entry */ | |
2092 | for (i = 0; i < DASD_CP_ENTRIES; i++) { | |
2093 | /* current bus_id already included, nothing to do */ | |
2094 | if (copy->entry[i].configured && | |
2095 | strncmp(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE) == 0) | |
2096 | return 0; | |
2097 | ||
2098 | if (!copy->entry[i].configured) | |
2099 | break; | |
2100 | } | |
2101 | if (i == DASD_CP_ENTRIES) | |
2102 | return -EINVAL; | |
2103 | ||
2104 | copy->entry[i].configured = true; | |
2105 | strscpy(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE); | |
2106 | if (primary) { | |
2107 | copy->active = ©->entry[i]; | |
2108 | copy->entry[i].primary = true; | |
2109 | } | |
2110 | if (!devmap->copy) | |
2111 | devmap->copy = copy; | |
2112 | ||
2113 | return 0; | |
2114 | } | |
2115 | ||
2116 | static void dasd_devmap_del_copy_relation(struct dasd_copy_relation *copy, | |
2117 | char *busid) | |
2118 | { | |
2119 | int i; | |
2120 | ||
2121 | spin_lock(&dasd_devmap_lock); | |
2122 | /* find entry */ | |
2123 | for (i = 0; i < DASD_CP_ENTRIES; i++) { | |
2124 | if (copy->entry[i].configured && | |
2125 | strncmp(copy->entry[i].busid, busid, DASD_BUS_ID_SIZE) == 0) | |
2126 | break; | |
2127 | } | |
2128 | if (i == DASD_CP_ENTRIES || !copy->entry[i].configured) { | |
2129 | spin_unlock(&dasd_devmap_lock); | |
2130 | return; | |
2131 | } | |
2132 | ||
2133 | copy->entry[i].configured = false; | |
2134 | memset(copy->entry[i].busid, 0, DASD_BUS_ID_SIZE); | |
2135 | if (copy->active == ©->entry[i]) { | |
2136 | copy->active = NULL; | |
2137 | copy->entry[i].primary = false; | |
2138 | } | |
2139 | spin_unlock(&dasd_devmap_lock); | |
2140 | } | |
2141 | ||
2142 | static int dasd_devmap_clear_copy_relation(struct device *dev) | |
2143 | { | |
2144 | struct dasd_copy_relation *copy; | |
2145 | struct dasd_devmap *devmap; | |
2146 | int i, rc = 1; | |
2147 | ||
2148 | devmap = dasd_devmap_from_cdev(to_ccwdev(dev)); | |
2149 | if (IS_ERR(devmap)) | |
2150 | return 1; | |
2151 | ||
2152 | spin_lock(&dasd_devmap_lock); | |
2153 | if (!devmap->copy) | |
2154 | goto out; | |
2155 | ||
2156 | copy = devmap->copy; | |
2157 | /* first check if all secondary devices are offline*/ | |
2158 | for (i = 0; i < DASD_CP_ENTRIES; i++) { | |
2159 | if (!copy->entry[i].configured) | |
2160 | continue; | |
2161 | ||
2162 | if (copy->entry[i].device == copy->active->device) | |
2163 | continue; | |
2164 | ||
2165 | if (copy->entry[i].device) | |
2166 | goto out; | |
2167 | } | |
2168 | /* clear all devmap entries */ | |
2169 | for (i = 0; i < DASD_CP_ENTRIES; i++) { | |
2170 | if (strlen(copy->entry[i].busid) == 0) | |
2171 | continue; | |
2172 | if (copy->entry[i].device) { | |
2173 | dasd_put_device(copy->entry[i].device); | |
2174 | copy->entry[i].device->copy = NULL; | |
2175 | copy->entry[i].device = NULL; | |
2176 | } | |
2177 | devmap = dasd_find_busid_locked(copy->entry[i].busid); | |
2178 | devmap->copy = NULL; | |
2179 | memset(copy->entry[i].busid, 0, DASD_BUS_ID_SIZE); | |
2180 | } | |
2181 | kfree(copy); | |
2182 | rc = 0; | |
2183 | out: | |
2184 | spin_unlock(&dasd_devmap_lock); | |
2185 | return rc; | |
2186 | } | |
2187 | ||
2188 | /* | |
2189 | * parse BUSIDs from a copy pair | |
2190 | */ | |
2191 | static int dasd_devmap_parse_busid(const char *buf, char *prim_busid, | |
2192 | char *sec_busid) | |
2193 | { | |
2194 | char *primary, *secondary, *tmp, *pt; | |
2195 | int id0, id1, id2; | |
2196 | ||
2197 | pt = kstrdup(buf, GFP_KERNEL); | |
2198 | tmp = pt; | |
2199 | if (!tmp) | |
2200 | return -ENOMEM; | |
2201 | ||
2202 | primary = strsep(&tmp, ","); | |
2203 | if (!primary) { | |
2204 | kfree(pt); | |
2205 | return -EINVAL; | |
2206 | } | |
2207 | secondary = strsep(&tmp, ","); | |
2208 | if (!secondary) { | |
2209 | kfree(pt); | |
2210 | return -EINVAL; | |
2211 | } | |
2212 | if (dasd_busid(primary, &id0, &id1, &id2)) { | |
2213 | kfree(pt); | |
2214 | return -EINVAL; | |
2215 | } | |
2216 | sprintf(prim_busid, "%01x.%01x.%04x", id0, id1, id2); | |
2217 | if (dasd_busid(secondary, &id0, &id1, &id2)) { | |
2218 | kfree(pt); | |
2219 | return -EINVAL; | |
2220 | } | |
2221 | sprintf(sec_busid, "%01x.%01x.%04x", id0, id1, id2); | |
2222 | kfree(pt); | |
2223 | ||
2224 | return 0; | |
2225 | } | |
2226 | ||
2227 | static ssize_t dasd_copy_pair_store(struct device *dev, | |
2228 | struct device_attribute *attr, | |
2229 | const char *buf, size_t count) | |
2230 | { | |
2231 | struct dasd_devmap *prim_devmap, *sec_devmap; | |
2232 | char prim_busid[DASD_BUS_ID_SIZE]; | |
2233 | char sec_busid[DASD_BUS_ID_SIZE]; | |
2234 | struct dasd_copy_relation *copy; | |
2235 | struct dasd_device *device; | |
2236 | bool pprc_enabled; | |
2237 | int rc; | |
2238 | ||
2239 | if (strncmp(buf, "clear", strlen("clear")) == 0) { | |
2240 | if (dasd_devmap_clear_copy_relation(dev)) | |
2241 | return -EINVAL; | |
2242 | return count; | |
2243 | } | |
2244 | ||
2245 | rc = dasd_devmap_parse_busid(buf, prim_busid, sec_busid); | |
2246 | if (rc) | |
2247 | return rc; | |
2248 | ||
2249 | if (strncmp(dev_name(dev), prim_busid, DASD_BUS_ID_SIZE) != 0 && | |
2250 | strncmp(dev_name(dev), sec_busid, DASD_BUS_ID_SIZE) != 0) | |
2251 | return -EINVAL; | |
2252 | ||
2253 | /* allocate primary devmap if needed */ | |
2254 | prim_devmap = dasd_find_busid(prim_busid); | |
2255 | if (IS_ERR(prim_devmap)) | |
2256 | prim_devmap = dasd_add_busid(prim_busid, DASD_FEATURE_DEFAULT); | |
2257 | ||
2258 | /* allocate secondary devmap if needed */ | |
2259 | sec_devmap = dasd_find_busid(sec_busid); | |
2260 | if (IS_ERR(sec_devmap)) | |
2261 | sec_devmap = dasd_add_busid(sec_busid, DASD_FEATURE_DEFAULT); | |
2262 | ||
2263 | /* setting copy relation is only allowed for offline secondary */ | |
2264 | if (sec_devmap->device) | |
2265 | return -EINVAL; | |
2266 | ||
2267 | if (prim_devmap->copy) { | |
2268 | copy = prim_devmap->copy; | |
2269 | } else if (sec_devmap->copy) { | |
2270 | copy = sec_devmap->copy; | |
2271 | } else { | |
2272 | copy = kzalloc(sizeof(*copy), GFP_KERNEL); | |
2273 | if (!copy) | |
2274 | return -ENOMEM; | |
2275 | } | |
2276 | spin_lock(&dasd_devmap_lock); | |
2277 | rc = dasd_devmap_set_copy_relation(prim_devmap, copy, prim_busid, true); | |
2278 | if (rc) { | |
2279 | spin_unlock(&dasd_devmap_lock); | |
2280 | return rc; | |
2281 | } | |
2282 | rc = dasd_devmap_set_copy_relation(sec_devmap, copy, sec_busid, false); | |
2283 | if (rc) { | |
2284 | spin_unlock(&dasd_devmap_lock); | |
2285 | return rc; | |
2286 | } | |
2287 | spin_unlock(&dasd_devmap_lock); | |
2288 | ||
2289 | /* if primary device is already online call device setup directly */ | |
2290 | if (prim_devmap->device && !prim_devmap->device->copy) { | |
2291 | device = prim_devmap->device; | |
2292 | if (device->discipline->pprc_enabled) { | |
2293 | pprc_enabled = device->discipline->pprc_enabled(device); | |
2294 | rc = dasd_devmap_set_device_copy_relation(device->cdev, | |
2295 | pprc_enabled); | |
2296 | } else { | |
2297 | rc = -EOPNOTSUPP; | |
2298 | } | |
2299 | } | |
2300 | if (rc) { | |
2301 | dasd_devmap_del_copy_relation(copy, prim_busid); | |
2302 | dasd_devmap_del_copy_relation(copy, sec_busid); | |
2303 | count = rc; | |
2304 | } | |
2305 | ||
2306 | return count; | |
2307 | } | |
2308 | static DEVICE_ATTR(copy_pair, 0644, dasd_copy_pair_show, | |
2309 | dasd_copy_pair_store); | |
2310 | ||
2311 | static ssize_t | |
2312 | dasd_copy_role_show(struct device *dev, | |
2313 | struct device_attribute *attr, char *buf) | |
2314 | { | |
2315 | struct dasd_copy_relation *copy; | |
2316 | struct dasd_device *device; | |
2317 | int len, i; | |
2318 | ||
2319 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
2320 | if (IS_ERR(device)) | |
2321 | return -ENODEV; | |
2322 | ||
2323 | if (!device->copy) { | |
2324 | len = sysfs_emit(buf, "none\n"); | |
2325 | goto out; | |
2326 | } | |
2327 | copy = device->copy; | |
2328 | /* only the active device is primary */ | |
2329 | if (copy->active->device == device) { | |
2330 | len = sysfs_emit(buf, "primary\n"); | |
2331 | goto out; | |
2332 | } | |
2333 | for (i = 0; i < DASD_CP_ENTRIES; i++) { | |
2334 | if (copy->entry[i].device == device) { | |
2335 | len = sysfs_emit(buf, "secondary\n"); | |
2336 | goto out; | |
2337 | } | |
2338 | } | |
2339 | /* not in the list, no COPY role */ | |
2340 | len = sysfs_emit(buf, "none\n"); | |
2341 | out: | |
2342 | dasd_put_device(device); | |
2343 | return len; | |
2344 | } | |
2345 | static DEVICE_ATTR(copy_role, 0444, dasd_copy_role_show, NULL); | |
2346 | ||
32ff8ce0 SH |
2347 | static ssize_t dasd_device_ping(struct device *dev, |
2348 | struct device_attribute *attr, | |
2349 | const char *buf, size_t count) | |
2350 | { | |
2351 | struct dasd_device *device; | |
2352 | size_t rc; | |
2353 | ||
2354 | device = dasd_device_from_cdev(to_ccwdev(dev)); | |
2355 | if (IS_ERR(device)) | |
2356 | return -ENODEV; | |
2357 | ||
2358 | /* | |
2359 | * do not try during offline processing | |
2360 | * early check only | |
2361 | * the sleep_on function itself checks for offline | |
2362 | * processing again | |
2363 | */ | |
2364 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) { | |
2365 | rc = -EBUSY; | |
2366 | goto out; | |
2367 | } | |
2368 | if (!device->discipline || !device->discipline->device_ping) { | |
2369 | rc = -EOPNOTSUPP; | |
2370 | goto out; | |
2371 | } | |
2372 | rc = device->discipline->device_ping(device); | |
2373 | if (!rc) | |
2374 | rc = count; | |
2375 | out: | |
2376 | dasd_put_device(device); | |
2377 | return rc; | |
2378 | } | |
2379 | static DEVICE_ATTR(ping, 0200, NULL, dasd_device_ping); | |
2380 | ||
c729696b JH |
2381 | #define DASD_DEFINE_ATTR(_name, _func) \ |
2382 | static ssize_t dasd_##_name##_show(struct device *dev, \ | |
2383 | struct device_attribute *attr, \ | |
2384 | char *buf) \ | |
2385 | { \ | |
2386 | struct ccw_device *cdev = to_ccwdev(dev); \ | |
2387 | struct dasd_device *device = dasd_device_from_cdev(cdev); \ | |
2388 | int val = 0; \ | |
2389 | \ | |
2390 | if (IS_ERR(device)) \ | |
2391 | return -ENODEV; \ | |
2392 | if (device->discipline && _func) \ | |
2393 | val = _func(device); \ | |
2394 | dasd_put_device(device); \ | |
2395 | \ | |
4b9e0436 | 2396 | return sysfs_emit(buf, "%d\n", val); \ |
c729696b JH |
2397 | } \ |
2398 | static DEVICE_ATTR(_name, 0444, dasd_##_name##_show, NULL); \ | |
2399 | ||
2400 | DASD_DEFINE_ATTR(ese, device->discipline->is_ese); | |
2401 | DASD_DEFINE_ATTR(extent_size, device->discipline->ext_size); | |
2402 | DASD_DEFINE_ATTR(pool_id, device->discipline->ext_pool_id); | |
2403 | DASD_DEFINE_ATTR(space_configured, device->discipline->space_configured); | |
2404 | DASD_DEFINE_ATTR(space_allocated, device->discipline->space_allocated); | |
2405 | DASD_DEFINE_ATTR(logical_capacity, device->discipline->logical_capacity); | |
2406 | DASD_DEFINE_ATTR(warn_threshold, device->discipline->ext_pool_warn_thrshld); | |
2407 | DASD_DEFINE_ATTR(cap_at_warnlevel, device->discipline->ext_pool_cap_at_warnlevel); | |
2408 | DASD_DEFINE_ATTR(pool_oos, device->discipline->ext_pool_oos); | |
2409 | ||
1da177e4 LT |
2410 | static struct attribute * dasd_attrs[] = { |
2411 | &dev_attr_readonly.attr, | |
2412 | &dev_attr_discipline.attr, | |
4dfd5c45 | 2413 | &dev_attr_status.attr, |
3d052595 HH |
2414 | &dev_attr_alias.attr, |
2415 | &dev_attr_vendor.attr, | |
2416 | &dev_attr_uid.attr, | |
1da177e4 | 2417 | &dev_attr_use_diag.attr, |
e4dbb0f2 | 2418 | &dev_attr_raw_track_access.attr, |
20c64468 | 2419 | &dev_attr_eer_enabled.attr, |
9575bf26 | 2420 | &dev_attr_erplog.attr, |
13de227b | 2421 | &dev_attr_failfast.attr, |
7c8faa86 | 2422 | &dev_attr_expires.attr, |
1f1ee9ad | 2423 | &dev_attr_retries.attr, |
3d71ad32 | 2424 | &dev_attr_timeout.attr, |
5a27e60d SW |
2425 | &dev_attr_reservation_policy.attr, |
2426 | &dev_attr_last_known_reservation_state.attr, | |
d07dc5d8 | 2427 | &dev_attr_safe_offline.attr, |
5a3b7b11 | 2428 | &dev_attr_host_access_count.attr, |
5db8440c | 2429 | &dev_attr_path_masks.attr, |
a521b048 | 2430 | &dev_attr_path_threshold.attr, |
ddc1c945 | 2431 | &dev_attr_path_autodisable.attr, |
a521b048 SH |
2432 | &dev_attr_path_interval.attr, |
2433 | &dev_attr_path_reset.attr, | |
2434 | &dev_attr_hpf.attr, | |
c729696b | 2435 | &dev_attr_ese.attr, |
19508b20 | 2436 | &dev_attr_fc_security.attr, |
a91ff09d SH |
2437 | &dev_attr_copy_pair.attr, |
2438 | &dev_attr_copy_role.attr, | |
32ff8ce0 | 2439 | &dev_attr_ping.attr, |
9558a8e9 | 2440 | &dev_attr_aq_mask.attr, |
bdac94e2 | 2441 | &dev_attr_aq_requeue.attr, |
0c1a1474 | 2442 | &dev_attr_aq_timeouts.attr, |
1da177e4 LT |
2443 | NULL, |
2444 | }; | |
2445 | ||
13171677 | 2446 | static const struct attribute_group dasd_attr_group = { |
1da177e4 LT |
2447 | .attrs = dasd_attrs, |
2448 | }; | |
2449 | ||
c729696b JH |
2450 | static struct attribute *capacity_attrs[] = { |
2451 | &dev_attr_space_configured.attr, | |
2452 | &dev_attr_space_allocated.attr, | |
2453 | &dev_attr_logical_capacity.attr, | |
2454 | NULL, | |
2455 | }; | |
2456 | ||
2457 | static const struct attribute_group capacity_attr_group = { | |
2458 | .name = "capacity", | |
2459 | .attrs = capacity_attrs, | |
2460 | }; | |
2461 | ||
2462 | static struct attribute *ext_pool_attrs[] = { | |
2463 | &dev_attr_pool_id.attr, | |
2464 | &dev_attr_extent_size.attr, | |
2465 | &dev_attr_warn_threshold.attr, | |
2466 | &dev_attr_cap_at_warnlevel.attr, | |
2467 | &dev_attr_pool_oos.attr, | |
2468 | NULL, | |
2469 | }; | |
2470 | ||
2471 | static const struct attribute_group ext_pool_attr_group = { | |
2472 | .name = "extent_pool", | |
2473 | .attrs = ext_pool_attrs, | |
2474 | }; | |
2475 | ||
1987c551 | 2476 | const struct attribute_group *dasd_dev_groups[] = { |
c729696b JH |
2477 | &dasd_attr_group, |
2478 | &capacity_attr_group, | |
2479 | &ext_pool_attr_group, | |
2480 | NULL, | |
2481 | }; | |
1987c551 | 2482 | EXPORT_SYMBOL_GPL(dasd_dev_groups); |
c729696b | 2483 | |
f24acd45 HH |
2484 | /* |
2485 | * Return value of the specified feature. | |
2486 | */ | |
2487 | int | |
2488 | dasd_get_feature(struct ccw_device *cdev, int feature) | |
2489 | { | |
2490 | struct dasd_devmap *devmap; | |
2491 | ||
2a0217d5 | 2492 | devmap = dasd_find_busid(dev_name(&cdev->dev)); |
f24acd45 | 2493 | if (IS_ERR(devmap)) |
40545573 | 2494 | return PTR_ERR(devmap); |
f24acd45 HH |
2495 | |
2496 | return ((devmap->features & feature) != 0); | |
2497 | } | |
2498 | ||
2499 | /* | |
2500 | * Set / reset given feature. | |
48fc7f7e | 2501 | * Flag indicates whether to set (!=0) or the reset (=0) the feature. |
f24acd45 HH |
2502 | */ |
2503 | int | |
2504 | dasd_set_feature(struct ccw_device *cdev, int feature, int flag) | |
2505 | { | |
2506 | struct dasd_devmap *devmap; | |
2507 | ||
1081f3a7 | 2508 | devmap = dasd_devmap_from_cdev(cdev); |
f24acd45 | 2509 | if (IS_ERR(devmap)) |
40545573 | 2510 | return PTR_ERR(devmap); |
f24acd45 HH |
2511 | |
2512 | spin_lock(&dasd_devmap_lock); | |
2513 | if (flag) | |
2514 | devmap->features |= feature; | |
2515 | else | |
2516 | devmap->features &= ~feature; | |
c6eb7b77 HH |
2517 | if (devmap->device) |
2518 | devmap->device->features = devmap->features; | |
f24acd45 HH |
2519 | spin_unlock(&dasd_devmap_lock); |
2520 | return 0; | |
2521 | } | |
28b841b3 | 2522 | EXPORT_SYMBOL(dasd_set_feature); |
f24acd45 | 2523 | |
19508b20 JH |
2524 | static struct attribute *paths_info_attrs[] = { |
2525 | &path_fcs_attribute.attr, | |
2526 | NULL, | |
2527 | }; | |
0704a858 | 2528 | ATTRIBUTE_GROUPS(paths_info); |
19508b20 JH |
2529 | |
2530 | static struct kobj_type path_attr_type = { | |
2531 | .release = dasd_path_release, | |
0704a858 | 2532 | .default_groups = paths_info_groups, |
19508b20 JH |
2533 | .sysfs_ops = &kobj_sysfs_ops, |
2534 | }; | |
2535 | ||
2536 | static void dasd_path_init_kobj(struct dasd_device *device, int chp) | |
2537 | { | |
2538 | device->path[chp].kobj.kset = device->paths_info; | |
2539 | kobject_init(&device->path[chp].kobj, &path_attr_type); | |
2540 | } | |
2541 | ||
2542 | void dasd_path_create_kobj(struct dasd_device *device, int chp) | |
2543 | { | |
2544 | int rc; | |
2545 | ||
2546 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) | |
2547 | return; | |
2548 | if (!device->paths_info) { | |
2549 | dev_warn(&device->cdev->dev, "Unable to create paths objects\n"); | |
2550 | return; | |
2551 | } | |
2552 | if (device->path[chp].in_sysfs) | |
2553 | return; | |
2554 | if (!device->path[chp].conf_data) | |
2555 | return; | |
2556 | ||
2557 | dasd_path_init_kobj(device, chp); | |
2558 | ||
2559 | rc = kobject_add(&device->path[chp].kobj, NULL, "%x.%02x", | |
2560 | device->path[chp].cssid, device->path[chp].chpid); | |
2561 | if (rc) | |
2562 | kobject_put(&device->path[chp].kobj); | |
2563 | device->path[chp].in_sysfs = true; | |
2564 | } | |
2565 | EXPORT_SYMBOL(dasd_path_create_kobj); | |
2566 | ||
2567 | void dasd_path_create_kobjects(struct dasd_device *device) | |
2568 | { | |
2569 | u8 lpm, opm; | |
2570 | ||
2571 | opm = dasd_path_get_opm(device); | |
2572 | for (lpm = 0x80; lpm; lpm >>= 1) { | |
2573 | if (!(lpm & opm)) | |
2574 | continue; | |
2575 | dasd_path_create_kobj(device, pathmask_to_pos(lpm)); | |
2576 | } | |
2577 | } | |
2578 | EXPORT_SYMBOL(dasd_path_create_kobjects); | |
2579 | ||
ac55ad2b | 2580 | static void dasd_path_remove_kobj(struct dasd_device *device, int chp) |
19508b20 JH |
2581 | { |
2582 | if (device->path[chp].in_sysfs) { | |
2583 | kobject_put(&device->path[chp].kobj); | |
2584 | device->path[chp].in_sysfs = false; | |
2585 | } | |
2586 | } | |
ac55ad2b JH |
2587 | |
2588 | /* | |
2589 | * As we keep kobjects for the lifetime of a device, this function must not be | |
2590 | * called anywhere but in the context of offlining a device. | |
2591 | */ | |
2592 | void dasd_path_remove_kobjects(struct dasd_device *device) | |
2593 | { | |
2594 | int i; | |
2595 | ||
2596 | for (i = 0; i < 8; i++) | |
2597 | dasd_path_remove_kobj(device, i); | |
2598 | } | |
2599 | EXPORT_SYMBOL(dasd_path_remove_kobjects); | |
f24acd45 | 2600 | |
1da177e4 LT |
2601 | int |
2602 | dasd_devmap_init(void) | |
2603 | { | |
2604 | int i; | |
2605 | ||
2606 | /* Initialize devmap structures. */ | |
2607 | dasd_max_devindex = 0; | |
2608 | for (i = 0; i < 256; i++) | |
2609 | INIT_LIST_HEAD(&dasd_hashlists[i]); | |
40545573 | 2610 | return 0; |
1da177e4 LT |
2611 | } |
2612 | ||
2613 | void | |
2614 | dasd_devmap_exit(void) | |
2615 | { | |
2616 | dasd_forget_ranges(); | |
2617 | } |