diff options
Diffstat (limited to 'drivers/s390/scsi/zfcp_sysfs_unit.c')
-rw-r--r-- | drivers/s390/scsi/zfcp_sysfs_unit.c | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/drivers/s390/scsi/zfcp_sysfs_unit.c b/drivers/s390/scsi/zfcp_sysfs_unit.c new file mode 100644 index 000000000000..87c0b461831f --- /dev/null +++ b/drivers/s390/scsi/zfcp_sysfs_unit.c | |||
@@ -0,0 +1,179 @@ | |||
1 | /* | ||
2 | * linux/drivers/s390/scsi/zfcp_sysfs_unit.c | ||
3 | * | ||
4 | * FCP adapter driver for IBM eServer zSeries | ||
5 | * | ||
6 | * sysfs unit related routines | ||
7 | * | ||
8 | * (C) Copyright IBM Corp. 2003, 2004 | ||
9 | * | ||
10 | * Authors: | ||
11 | * Martin Peschke <mpeschke@de.ibm.com> | ||
12 | * Heiko Carstens <heiko.carstens@de.ibm.com> | ||
13 | * Andreas Herrmann <aherrman@de.ibm.com> | ||
14 | * Volker Sameske <sameske@de.ibm.com> | ||
15 | * | ||
16 | * This program is free software; you can redistribute it and/or modify | ||
17 | * it under the terms of the GNU General Public License as published by | ||
18 | * the Free Software Foundation; either version 2, or (at your option) | ||
19 | * any later version. | ||
20 | * | ||
21 | * This program is distributed in the hope that it will be useful, | ||
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
24 | * GNU General Public License for more details. | ||
25 | * | ||
26 | * You should have received a copy of the GNU General Public License | ||
27 | * along with this program; if not, write to the Free Software | ||
28 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
29 | */ | ||
30 | |||
31 | #define ZFCP_SYSFS_UNIT_C_REVISION "$Revision: 1.30 $" | ||
32 | |||
33 | #include "zfcp_ext.h" | ||
34 | |||
35 | #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG | ||
36 | |||
37 | /** | ||
38 | * zfcp_sysfs_unit_release - gets called when a struct device unit is released | ||
39 | * @dev: pointer to belonging device | ||
40 | */ | ||
41 | void | ||
42 | zfcp_sysfs_unit_release(struct device *dev) | ||
43 | { | ||
44 | kfree(dev); | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * ZFCP_DEFINE_UNIT_ATTR | ||
49 | * @_name: name of show attribute | ||
50 | * @_format: format string | ||
51 | * @_value: value to print | ||
52 | * | ||
53 | * Generates attribute for a unit. | ||
54 | */ | ||
55 | #define ZFCP_DEFINE_UNIT_ATTR(_name, _format, _value) \ | ||
56 | static ssize_t zfcp_sysfs_unit_##_name##_show(struct device *dev, \ | ||
57 | char *buf) \ | ||
58 | { \ | ||
59 | struct zfcp_unit *unit; \ | ||
60 | \ | ||
61 | unit = dev_get_drvdata(dev); \ | ||
62 | return sprintf(buf, _format, _value); \ | ||
63 | } \ | ||
64 | \ | ||
65 | static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_unit_##_name##_show, NULL); | ||
66 | |||
67 | ZFCP_DEFINE_UNIT_ATTR(status, "0x%08x\n", atomic_read(&unit->status)); | ||
68 | ZFCP_DEFINE_UNIT_ATTR(scsi_lun, "0x%x\n", unit->scsi_lun); | ||
69 | ZFCP_DEFINE_UNIT_ATTR(in_recovery, "%d\n", atomic_test_mask | ||
70 | (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)); | ||
71 | ZFCP_DEFINE_UNIT_ATTR(access_denied, "%d\n", atomic_test_mask | ||
72 | (ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status)); | ||
73 | ZFCP_DEFINE_UNIT_ATTR(access_shared, "%d\n", atomic_test_mask | ||
74 | (ZFCP_STATUS_UNIT_SHARED, &unit->status)); | ||
75 | ZFCP_DEFINE_UNIT_ATTR(access_readonly, "%d\n", atomic_test_mask | ||
76 | (ZFCP_STATUS_UNIT_READONLY, &unit->status)); | ||
77 | |||
78 | /** | ||
79 | * zfcp_sysfs_unit_failed_store - failed state of unit | ||
80 | * @dev: pointer to belonging device | ||
81 | * @buf: pointer to input buffer | ||
82 | * @count: number of bytes in buffer | ||
83 | * | ||
84 | * Store function of the "failed" attribute of a unit. | ||
85 | * If a "0" gets written to "failed", error recovery will be | ||
86 | * started for the belonging unit. | ||
87 | */ | ||
88 | static ssize_t | ||
89 | zfcp_sysfs_unit_failed_store(struct device *dev, const char *buf, size_t count) | ||
90 | { | ||
91 | struct zfcp_unit *unit; | ||
92 | unsigned int val; | ||
93 | char *endp; | ||
94 | int retval = 0; | ||
95 | |||
96 | down(&zfcp_data.config_sema); | ||
97 | unit = dev_get_drvdata(dev); | ||
98 | if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) { | ||
99 | retval = -EBUSY; | ||
100 | goto out; | ||
101 | } | ||
102 | |||
103 | val = simple_strtoul(buf, &endp, 0); | ||
104 | if (((endp + 1) < (buf + count)) || (val != 0)) { | ||
105 | retval = -EINVAL; | ||
106 | goto out; | ||
107 | } | ||
108 | |||
109 | zfcp_erp_modify_unit_status(unit, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET); | ||
110 | zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED); | ||
111 | zfcp_erp_wait(unit->port->adapter); | ||
112 | out: | ||
113 | up(&zfcp_data.config_sema); | ||
114 | return retval ? retval : (ssize_t) count; | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * zfcp_sysfs_unit_failed_show - failed state of unit | ||
119 | * @dev: pointer to belonging device | ||
120 | * @buf: pointer to input buffer | ||
121 | * | ||
122 | * Show function of "failed" attribute of unit. Will be | ||
123 | * "0" if unit is working, otherwise "1". | ||
124 | */ | ||
125 | static ssize_t | ||
126 | zfcp_sysfs_unit_failed_show(struct device *dev, char *buf) | ||
127 | { | ||
128 | struct zfcp_unit *unit; | ||
129 | |||
130 | unit = dev_get_drvdata(dev); | ||
131 | if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) | ||
132 | return sprintf(buf, "1\n"); | ||
133 | else | ||
134 | return sprintf(buf, "0\n"); | ||
135 | } | ||
136 | |||
137 | static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show, | ||
138 | zfcp_sysfs_unit_failed_store); | ||
139 | |||
140 | static struct attribute *zfcp_unit_attrs[] = { | ||
141 | &dev_attr_scsi_lun.attr, | ||
142 | &dev_attr_failed.attr, | ||
143 | &dev_attr_in_recovery.attr, | ||
144 | &dev_attr_status.attr, | ||
145 | &dev_attr_access_denied.attr, | ||
146 | &dev_attr_access_shared.attr, | ||
147 | &dev_attr_access_readonly.attr, | ||
148 | NULL | ||
149 | }; | ||
150 | |||
151 | static struct attribute_group zfcp_unit_attr_group = { | ||
152 | .attrs = zfcp_unit_attrs, | ||
153 | }; | ||
154 | |||
155 | /** | ||
156 | * zfcp_sysfs_create_unit_files - create sysfs unit files | ||
157 | * @dev: pointer to belonging device | ||
158 | * | ||
159 | * Create all attributes of the sysfs representation of a unit. | ||
160 | */ | ||
161 | int | ||
162 | zfcp_sysfs_unit_create_files(struct device *dev) | ||
163 | { | ||
164 | return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group); | ||
165 | } | ||
166 | |||
167 | /** | ||
168 | * zfcp_sysfs_remove_unit_files - remove sysfs unit files | ||
169 | * @dev: pointer to belonging device | ||
170 | * | ||
171 | * Remove all attributes of the sysfs representation of a unit. | ||
172 | */ | ||
173 | void | ||
174 | zfcp_sysfs_unit_remove_files(struct device *dev) | ||
175 | { | ||
176 | sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group); | ||
177 | } | ||
178 | |||
179 | #undef ZFCP_LOG_AREA | ||