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