[SCSI] zfcp: transport class adaptations
[deliverable/linux.git] / drivers / s390 / scsi / zfcp_sysfs_port.c
CommitLineData
1da177e4
LT
1/*
2 * linux/drivers/s390/scsi/zfcp_sysfs_port.c
3 *
4 * FCP adapter driver for IBM eServer zSeries
5 *
6 * sysfs port 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_PORT_C_REVISION "$Revision: 1.47 $"
32
33#include "zfcp_ext.h"
34
35#define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
36
37/**
38 * zfcp_sysfs_port_release - gets called when a struct device port is released
39 * @dev: pointer to belonging device
40 */
41void
42zfcp_sysfs_port_release(struct device *dev)
43{
44 kfree(dev);
45}
46
47/**
48 * ZFCP_DEFINE_PORT_ATTR
49 * @_name: name of show attribute
50 * @_format: format string
51 * @_value: value to print
52 *
53 * Generates attributes for a port.
54 */
55#define ZFCP_DEFINE_PORT_ATTR(_name, _format, _value) \
10523b3b 56static ssize_t zfcp_sysfs_port_##_name##_show(struct device *dev, struct device_attribute *attr, \
1da177e4
LT
57 char *buf) \
58{ \
59 struct zfcp_port *port; \
60 \
61 port = dev_get_drvdata(dev); \
62 return sprintf(buf, _format, _value); \
63} \
64 \
65static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_port_##_name##_show, NULL);
66
67ZFCP_DEFINE_PORT_ATTR(status, "0x%08x\n", atomic_read(&port->status));
1da177e4
LT
68ZFCP_DEFINE_PORT_ATTR(in_recovery, "%d\n", atomic_test_mask
69 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status));
70ZFCP_DEFINE_PORT_ATTR(access_denied, "%d\n", atomic_test_mask
71 (ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status));
72
73/**
74 * zfcp_sysfs_unit_add_store - add a unit to sysfs tree
75 * @dev: pointer to belonging device
76 * @buf: pointer to input buffer
77 * @count: number of bytes in buffer
78 *
79 * Store function of the "unit_add" attribute of a port.
80 */
81static ssize_t
10523b3b 82zfcp_sysfs_unit_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1da177e4
LT
83{
84 fcp_lun_t fcp_lun;
85 char *endp;
86 struct zfcp_port *port;
87 struct zfcp_unit *unit;
88 int retval = -EINVAL;
89
90 down(&zfcp_data.config_sema);
91
92 port = dev_get_drvdata(dev);
93 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
94 retval = -EBUSY;
95 goto out;
96 }
97
98 fcp_lun = simple_strtoull(buf, &endp, 0);
99 if ((endp + 1) < (buf + count))
100 goto out;
101
102 unit = zfcp_unit_enqueue(port, fcp_lun);
103 if (!unit)
104 goto out;
105
106 retval = 0;
107
108 zfcp_erp_unit_reopen(unit, 0);
109 zfcp_erp_wait(unit->port->adapter);
110 zfcp_unit_put(unit);
111 out:
112 up(&zfcp_data.config_sema);
113 return retval ? retval : (ssize_t) count;
114}
115
116static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
117
118/**
119 * zfcp_sysfs_unit_remove_store - remove a unit from sysfs tree
120 * @dev: pointer to belonging device
121 * @buf: pointer to input buffer
122 * @count: number of bytes in buffer
123 */
124static ssize_t
10523b3b 125zfcp_sysfs_unit_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1da177e4
LT
126{
127 struct zfcp_port *port;
128 struct zfcp_unit *unit;
129 fcp_lun_t fcp_lun;
130 char *endp;
131 int retval = 0;
132
133 down(&zfcp_data.config_sema);
134
135 port = dev_get_drvdata(dev);
136 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
137 retval = -EBUSY;
138 goto out;
139 }
140
141 fcp_lun = simple_strtoull(buf, &endp, 0);
142 if ((endp + 1) < (buf + count)) {
143 retval = -EINVAL;
144 goto out;
145 }
146
147 write_lock_irq(&zfcp_data.config_lock);
148 unit = zfcp_get_unit_by_lun(port, fcp_lun);
149 if (unit && (atomic_read(&unit->refcount) == 0)) {
150 zfcp_unit_get(unit);
151 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
152 list_move(&unit->list, &port->unit_remove_lh);
153 }
154 else {
155 unit = NULL;
156 }
157 write_unlock_irq(&zfcp_data.config_lock);
158
159 if (!unit) {
160 retval = -ENXIO;
161 goto out;
162 }
163
164 zfcp_erp_unit_shutdown(unit, 0);
165 zfcp_erp_wait(unit->port->adapter);
166 zfcp_unit_put(unit);
167 zfcp_unit_dequeue(unit);
168 out:
169 up(&zfcp_data.config_sema);
170 return retval ? retval : (ssize_t) count;
171}
172
173static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
174
175/**
176 * zfcp_sysfs_port_failed_store - failed state of port
177 * @dev: pointer to belonging device
178 * @buf: pointer to input buffer
179 * @count: number of bytes in buffer
180 *
181 * Store function of the "failed" attribute of a port.
182 * If a "0" gets written to "failed", error recovery will be
183 * started for the belonging port.
184 */
185static ssize_t
10523b3b 186zfcp_sysfs_port_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1da177e4
LT
187{
188 struct zfcp_port *port;
189 unsigned int val;
190 char *endp;
191 int retval = 0;
192
193 down(&zfcp_data.config_sema);
194
195 port = dev_get_drvdata(dev);
196 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
197 retval = -EBUSY;
198 goto out;
199 }
200
201 val = simple_strtoul(buf, &endp, 0);
202 if (((endp + 1) < (buf + count)) || (val != 0)) {
203 retval = -EINVAL;
204 goto out;
205 }
206
207 zfcp_erp_modify_port_status(port, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
208 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
209 zfcp_erp_wait(port->adapter);
210 out:
211 up(&zfcp_data.config_sema);
212 return retval ? retval : (ssize_t) count;
213}
214
215/**
216 * zfcp_sysfs_port_failed_show - failed state of port
217 * @dev: pointer to belonging device
218 * @buf: pointer to input buffer
219 *
220 * Show function of "failed" attribute of port. Will be
221 * "0" if port is working, otherwise "1".
222 */
223static ssize_t
10523b3b 224zfcp_sysfs_port_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
225{
226 struct zfcp_port *port;
227
228 port = dev_get_drvdata(dev);
229 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status))
230 return sprintf(buf, "1\n");
231 else
232 return sprintf(buf, "0\n");
233}
234
235static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_port_failed_show,
236 zfcp_sysfs_port_failed_store);
237
238/**
239 * zfcp_port_common_attrs
240 * sysfs attributes that are common for all kind of fc ports.
241 */
242static struct attribute *zfcp_port_common_attrs[] = {
243 &dev_attr_failed.attr,
244 &dev_attr_in_recovery.attr,
245 &dev_attr_status.attr,
1da177e4
LT
246 &dev_attr_access_denied.attr,
247 NULL
248};
249
250static struct attribute_group zfcp_port_common_attr_group = {
251 .attrs = zfcp_port_common_attrs,
252};
253
254/**
255 * zfcp_port_no_ns_attrs
256 * sysfs attributes not to be used for nameserver ports.
257 */
258static struct attribute *zfcp_port_no_ns_attrs[] = {
259 &dev_attr_unit_add.attr,
260 &dev_attr_unit_remove.attr,
1da177e4
LT
261 NULL
262};
263
264static struct attribute_group zfcp_port_no_ns_attr_group = {
265 .attrs = zfcp_port_no_ns_attrs,
266};
267
268/**
269 * zfcp_sysfs_port_create_files - create sysfs port files
270 * @dev: pointer to belonging device
271 *
272 * Create all attributes of the sysfs representation of a port.
273 */
274int
275zfcp_sysfs_port_create_files(struct device *dev, u32 flags)
276{
277 int retval;
278
279 retval = sysfs_create_group(&dev->kobj, &zfcp_port_common_attr_group);
280
281 if ((flags & ZFCP_STATUS_PORT_WKA) || retval)
282 return retval;
283
284 retval = sysfs_create_group(&dev->kobj, &zfcp_port_no_ns_attr_group);
285 if (retval)
286 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
287
288 return retval;
289}
290
291/**
292 * zfcp_sysfs_port_remove_files - remove sysfs port files
293 * @dev: pointer to belonging device
294 *
295 * Remove all attributes of the sysfs representation of a port.
296 */
297void
298zfcp_sysfs_port_remove_files(struct device *dev, u32 flags)
299{
300 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
301 if (!(flags & ZFCP_STATUS_PORT_WKA))
302 sysfs_remove_group(&dev->kobj, &zfcp_port_no_ns_attr_group);
303}
304
305#undef ZFCP_LOG_AREA
This page took 0.16679 seconds and 5 git commands to generate.