2 * linux/drivers/s390/scsi/zfcp_sysfs_port.c
4 * FCP adapter driver for IBM eServer zSeries
6 * sysfs port related routines
8 * (C) Copyright IBM Corp. 2003, 2004
11 * Martin Peschke <mpeschke@de.ibm.com>
12 * Heiko Carstens <heiko.carstens@de.ibm.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define ZFCP_SYSFS_PORT_C_REVISION "$Revision: 1.40 $"
33 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
36 * zfcp_sysfs_port_release - gets called when a struct device port is released
37 * @dev: pointer to belonging device
40 zfcp_sysfs_port_release(struct device *dev)
46 * ZFCP_DEFINE_PORT_ATTR
47 * @_name: name of show attribute
48 * @_format: format string
49 * @_value: value to print
51 * Generates attributes for a port.
53 #define ZFCP_DEFINE_PORT_ATTR(_name, _format, _value) \
54 static ssize_t zfcp_sysfs_port_##_name##_show(struct device *dev, \
57 struct zfcp_port *port; \
59 port = dev_get_drvdata(dev); \
60 return sprintf(buf, _format, _value); \
63 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_port_##_name##_show, NULL);
65 ZFCP_DEFINE_PORT_ATTR(status, "0x%08x\n", atomic_read(&port->status));
66 ZFCP_DEFINE_PORT_ATTR(wwnn, "0x%016llx\n", port->wwnn);
67 ZFCP_DEFINE_PORT_ATTR(d_id, "0x%06x\n", port->d_id);
68 ZFCP_DEFINE_PORT_ATTR(scsi_id, "0x%x\n", port->scsi_id);
71 * zfcp_sysfs_unit_add_store - add a unit to sysfs tree
72 * @dev: pointer to belonging device
73 * @buf: pointer to input buffer
74 * @count: number of bytes in buffer
76 * Store function of the "unit_add" attribute of a port.
79 zfcp_sysfs_unit_add_store(struct device *dev, const char *buf, size_t count)
83 struct zfcp_port *port;
84 struct zfcp_unit *unit;
87 down(&zfcp_data.config_sema);
89 port = dev_get_drvdata(dev);
90 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
95 fcp_lun = simple_strtoull(buf, &endp, 0);
96 if ((endp + 1) < (buf + count))
99 unit = zfcp_unit_enqueue(port, fcp_lun);
105 zfcp_erp_unit_reopen(unit, 0);
106 zfcp_erp_wait(unit->port->adapter);
109 up(&zfcp_data.config_sema);
110 return retval ? retval : count;
113 static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
116 * zfcp_sysfs_unit_remove_store - remove a unit from sysfs tree
117 * @dev: pointer to belonging device
118 * @buf: pointer to input buffer
119 * @count: number of bytes in buffer
122 zfcp_sysfs_unit_remove_store(struct device *dev, const char *buf, size_t count)
124 struct zfcp_port *port;
125 struct zfcp_unit *unit;
128 int retval = -EINVAL;
130 down(&zfcp_data.config_sema);
132 port = dev_get_drvdata(dev);
133 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
138 fcp_lun = simple_strtoull(buf, &endp, 0);
139 if ((endp + 1) < (buf + count))
142 write_lock_irq(&zfcp_data.config_lock);
143 unit = zfcp_get_unit_by_lun(port, fcp_lun);
144 if (unit && (atomic_read(&unit->refcount) == 0)) {
146 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
147 list_move(&unit->list, &port->unit_remove_lh);
152 write_unlock_irq(&zfcp_data.config_lock);
159 zfcp_erp_unit_shutdown(unit, 0);
160 zfcp_erp_wait(unit->port->adapter);
162 zfcp_unit_dequeue(unit);
164 up(&zfcp_data.config_sema);
165 return retval ? retval : count;
168 static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
171 * zfcp_sysfs_port_failed_store - failed state of port
172 * @dev: pointer to belonging device
173 * @buf: pointer to input buffer
174 * @count: number of bytes in buffer
176 * Store function of the "failed" attribute of a port.
177 * If a "0" gets written to "failed", error recovery will be
178 * started for the belonging port.
181 zfcp_sysfs_port_failed_store(struct device *dev, const char *buf, size_t count)
183 struct zfcp_port *port;
188 down(&zfcp_data.config_sema);
190 port = dev_get_drvdata(dev);
191 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
196 val = simple_strtoul(buf, &endp, 0);
197 if (((endp + 1) < (buf + count)) || (val != 0)) {
202 zfcp_erp_modify_port_status(port, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
203 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
204 zfcp_erp_wait(port->adapter);
206 up(&zfcp_data.config_sema);
207 return retval ? retval : count;
211 * zfcp_sysfs_port_failed_show - failed state of port
212 * @dev: pointer to belonging device
213 * @buf: pointer to input buffer
215 * Show function of "failed" attribute of port. Will be
216 * "0" if port is working, otherwise "1".
219 zfcp_sysfs_port_failed_show(struct device *dev, char *buf)
221 struct zfcp_port *port;
223 port = dev_get_drvdata(dev);
224 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status))
225 return sprintf(buf, "1\n");
227 return sprintf(buf, "0\n");
230 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_port_failed_show,
231 zfcp_sysfs_port_failed_store);
234 * zfcp_sysfs_port_in_recovery_show - recovery state of port
235 * @dev: pointer to belonging device
236 * @buf: pointer to input buffer
238 * Show function of "in_recovery" attribute of port. Will be
239 * "0" if no error recovery is pending for port, otherwise "1".
242 zfcp_sysfs_port_in_recovery_show(struct device *dev, char *buf)
244 struct zfcp_port *port;
246 port = dev_get_drvdata(dev);
247 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
248 return sprintf(buf, "1\n");
250 return sprintf(buf, "0\n");
253 static DEVICE_ATTR(in_recovery, S_IRUGO, zfcp_sysfs_port_in_recovery_show,
257 * zfcp_port_common_attrs
258 * sysfs attributes that are common for all kind of fc ports.
260 static struct attribute *zfcp_port_common_attrs[] = {
261 &dev_attr_failed.attr,
262 &dev_attr_in_recovery.attr,
263 &dev_attr_status.attr,
269 static struct attribute_group zfcp_port_common_attr_group = {
270 .attrs = zfcp_port_common_attrs,
274 * zfcp_port_no_ns_attrs
275 * sysfs attributes not to be used for nameserver ports.
277 static struct attribute *zfcp_port_no_ns_attrs[] = {
278 &dev_attr_unit_add.attr,
279 &dev_attr_unit_remove.attr,
280 &dev_attr_scsi_id.attr,
284 static struct attribute_group zfcp_port_no_ns_attr_group = {
285 .attrs = zfcp_port_no_ns_attrs,
289 * zfcp_sysfs_port_create_files - create sysfs port files
290 * @dev: pointer to belonging device
292 * Create all attributes of the sysfs representation of a port.
295 zfcp_sysfs_port_create_files(struct device *dev, u32 flags)
299 retval = sysfs_create_group(&dev->kobj, &zfcp_port_common_attr_group);
301 if ((flags & ZFCP_STATUS_PORT_NAMESERVER) || retval)
304 retval = sysfs_create_group(&dev->kobj, &zfcp_port_no_ns_attr_group);
306 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
312 * zfcp_sysfs_port_remove_files - remove sysfs port files
313 * @dev: pointer to belonging device
315 * Remove all attributes of the sysfs representation of a port.
318 zfcp_sysfs_port_remove_files(struct device *dev, u32 flags)
320 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
321 if (!(flags & ZFCP_STATUS_PORT_NAMESERVER))
322 sysfs_remove_group(&dev->kobj, &zfcp_port_no_ns_attr_group);