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>
13 * Andreas Herrmann <aherrman@de.ibm.com>
14 * Volker Sameske <sameske@de.ibm.com>
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)
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.
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.
31 #define ZFCP_SYSFS_PORT_C_REVISION "$Revision: 1.47 $"
35 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
38 * zfcp_sysfs_port_release - gets called when a struct device port is released
39 * @dev: pointer to belonging device
42 zfcp_sysfs_port_release(struct device *dev)
48 * ZFCP_DEFINE_PORT_ATTR
49 * @_name: name of show attribute
50 * @_format: format string
51 * @_value: value to print
53 * Generates attributes for a port.
55 #define ZFCP_DEFINE_PORT_ATTR(_name, _format, _value) \
56 static ssize_t zfcp_sysfs_port_##_name##_show(struct device *dev, struct device_attribute *attr, \
59 struct zfcp_port *port; \
61 port = dev_get_drvdata(dev); \
62 return sprintf(buf, _format, _value); \
65 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_port_##_name##_show, NULL);
67 ZFCP_DEFINE_PORT_ATTR(status, "0x%08x\n", atomic_read(&port->status));
68 ZFCP_DEFINE_PORT_ATTR(in_recovery, "%d\n", atomic_test_mask
69 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status));
70 ZFCP_DEFINE_PORT_ATTR(access_denied, "%d\n", atomic_test_mask
71 (ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status));
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
79 * Store function of the "unit_add" attribute of a port.
82 zfcp_sysfs_unit_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
86 struct zfcp_port *port;
87 struct zfcp_unit *unit;
90 down(&zfcp_data.config_sema);
92 port = dev_get_drvdata(dev);
93 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
98 fcp_lun = simple_strtoull(buf, &endp, 0);
99 if ((endp + 1) < (buf + count))
102 unit = zfcp_unit_enqueue(port, fcp_lun);
108 zfcp_erp_unit_reopen(unit, 0);
109 zfcp_erp_wait(unit->port->adapter);
112 up(&zfcp_data.config_sema);
113 return retval ? retval : (ssize_t) count;
116 static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
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
125 zfcp_sysfs_unit_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
127 struct zfcp_port *port;
128 struct zfcp_unit *unit;
133 down(&zfcp_data.config_sema);
135 port = dev_get_drvdata(dev);
136 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
141 fcp_lun = simple_strtoull(buf, &endp, 0);
142 if ((endp + 1) < (buf + count)) {
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)) {
151 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
152 list_move(&unit->list, &port->unit_remove_lh);
157 write_unlock_irq(&zfcp_data.config_lock);
164 zfcp_erp_unit_shutdown(unit, 0);
165 zfcp_erp_wait(unit->port->adapter);
167 zfcp_unit_dequeue(unit);
169 up(&zfcp_data.config_sema);
170 return retval ? retval : (ssize_t) count;
173 static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
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
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.
186 zfcp_sysfs_port_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
188 struct zfcp_port *port;
193 down(&zfcp_data.config_sema);
195 port = dev_get_drvdata(dev);
196 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
201 val = simple_strtoul(buf, &endp, 0);
202 if (((endp + 1) < (buf + count)) || (val != 0)) {
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);
211 up(&zfcp_data.config_sema);
212 return retval ? retval : (ssize_t) count;
216 * zfcp_sysfs_port_failed_show - failed state of port
217 * @dev: pointer to belonging device
218 * @buf: pointer to input buffer
220 * Show function of "failed" attribute of port. Will be
221 * "0" if port is working, otherwise "1".
224 zfcp_sysfs_port_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
226 struct zfcp_port *port;
228 port = dev_get_drvdata(dev);
229 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status))
230 return sprintf(buf, "1\n");
232 return sprintf(buf, "0\n");
235 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_port_failed_show,
236 zfcp_sysfs_port_failed_store);
239 * zfcp_port_common_attrs
240 * sysfs attributes that are common for all kind of fc ports.
242 static struct attribute *zfcp_port_common_attrs[] = {
243 &dev_attr_failed.attr,
244 &dev_attr_in_recovery.attr,
245 &dev_attr_status.attr,
246 &dev_attr_access_denied.attr,
250 static struct attribute_group zfcp_port_common_attr_group = {
251 .attrs = zfcp_port_common_attrs,
255 * zfcp_port_no_ns_attrs
256 * sysfs attributes not to be used for nameserver ports.
258 static struct attribute *zfcp_port_no_ns_attrs[] = {
259 &dev_attr_unit_add.attr,
260 &dev_attr_unit_remove.attr,
264 static struct attribute_group zfcp_port_no_ns_attr_group = {
265 .attrs = zfcp_port_no_ns_attrs,
269 * zfcp_sysfs_port_create_files - create sysfs port files
270 * @dev: pointer to belonging device
272 * Create all attributes of the sysfs representation of a port.
275 zfcp_sysfs_port_create_files(struct device *dev, u32 flags)
279 retval = sysfs_create_group(&dev->kobj, &zfcp_port_common_attr_group);
281 if ((flags & ZFCP_STATUS_PORT_WKA) || retval)
284 retval = sysfs_create_group(&dev->kobj, &zfcp_port_no_ns_attr_group);
286 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
292 * zfcp_sysfs_port_remove_files - remove sysfs port files
293 * @dev: pointer to belonging device
295 * Remove all attributes of the sysfs representation of a port.
298 zfcp_sysfs_port_remove_files(struct device *dev, u32 flags)
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);