[SCSI] zfcp: Cleanup of code in zfcp_aux.c
[linux-2.6.git] / drivers / s390 / scsi / zfcp_sysfs_unit.c
blob587d9e3e12d24a59c94eaac1db64e366e2e06d92
1 /*
2 * zfcp device driver
4 * sysfs interface for zfcp unit.
6 * Copyright IBM Corporation 2002, 2008
7 */
9 #include "zfcp_ext.h"
11 /**
12 * zfcp_sysfs_unit_release - gets called when a struct device unit is released
13 * @dev: pointer to belonging device
15 void
16 zfcp_sysfs_unit_release(struct device *dev)
18 kfree(dev);
21 /**
22 * ZFCP_DEFINE_UNIT_ATTR
23 * @_name: name of show attribute
24 * @_format: format string
25 * @_value: value to print
27 * Generates attribute for a unit.
29 #define ZFCP_DEFINE_UNIT_ATTR(_name, _format, _value) \
30 static ssize_t zfcp_sysfs_unit_##_name##_show(struct device *dev, struct device_attribute *attr, \
31 char *buf) \
32 { \
33 struct zfcp_unit *unit; \
35 unit = dev_get_drvdata(dev); \
36 return sprintf(buf, _format, _value); \
37 } \
39 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_unit_##_name##_show, NULL);
41 ZFCP_DEFINE_UNIT_ATTR(status, "0x%08x\n", atomic_read(&unit->status));
42 ZFCP_DEFINE_UNIT_ATTR(in_recovery, "%d\n", atomic_test_mask
43 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status));
44 ZFCP_DEFINE_UNIT_ATTR(access_denied, "%d\n", atomic_test_mask
45 (ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status));
46 ZFCP_DEFINE_UNIT_ATTR(access_shared, "%d\n", atomic_test_mask
47 (ZFCP_STATUS_UNIT_SHARED, &unit->status));
48 ZFCP_DEFINE_UNIT_ATTR(access_readonly, "%d\n", atomic_test_mask
49 (ZFCP_STATUS_UNIT_READONLY, &unit->status));
51 /**
52 * zfcp_sysfs_unit_failed_store - failed state of unit
53 * @dev: pointer to belonging device
54 * @buf: pointer to input buffer
55 * @count: number of bytes in buffer
57 * Store function of the "failed" attribute of a unit.
58 * If a "0" gets written to "failed", error recovery will be
59 * started for the belonging unit.
61 static ssize_t
62 zfcp_sysfs_unit_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
64 struct zfcp_unit *unit;
65 unsigned int val;
66 char *endp;
67 int retval = 0;
69 down(&zfcp_data.config_sema);
70 unit = dev_get_drvdata(dev);
71 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) {
72 retval = -EBUSY;
73 goto out;
76 val = simple_strtoul(buf, &endp, 0);
77 if (((endp + 1) < (buf + count)) || (val != 0)) {
78 retval = -EINVAL;
79 goto out;
82 zfcp_erp_modify_unit_status(unit, 46, NULL,
83 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
84 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, 97, NULL);
85 zfcp_erp_wait(unit->port->adapter);
86 out:
87 up(&zfcp_data.config_sema);
88 return retval ? retval : (ssize_t) count;
91 /**
92 * zfcp_sysfs_unit_failed_show - failed state of unit
93 * @dev: pointer to belonging device
94 * @buf: pointer to input buffer
96 * Show function of "failed" attribute of unit. Will be
97 * "0" if unit is working, otherwise "1".
99 static ssize_t
100 zfcp_sysfs_unit_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
102 struct zfcp_unit *unit;
104 unit = dev_get_drvdata(dev);
105 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status))
106 return sprintf(buf, "1\n");
107 else
108 return sprintf(buf, "0\n");
111 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show,
112 zfcp_sysfs_unit_failed_store);
114 static struct attribute *zfcp_unit_attrs[] = {
115 &dev_attr_failed.attr,
116 &dev_attr_in_recovery.attr,
117 &dev_attr_status.attr,
118 &dev_attr_access_denied.attr,
119 &dev_attr_access_shared.attr,
120 &dev_attr_access_readonly.attr,
121 NULL
124 static struct attribute_group zfcp_unit_attr_group = {
125 .attrs = zfcp_unit_attrs,
129 * zfcp_sysfs_create_unit_files - create sysfs unit files
130 * @dev: pointer to belonging device
132 * Create all attributes of the sysfs representation of a unit.
135 zfcp_sysfs_unit_create_files(struct device *dev)
137 return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group);
141 * zfcp_sysfs_remove_unit_files - remove sysfs unit files
142 * @dev: pointer to belonging device
144 * Remove all attributes of the sysfs representation of a unit.
146 void
147 zfcp_sysfs_unit_remove_files(struct device *dev)
149 sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group);