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.
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, struct device_attribute *attr, \
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(in_recovery, "%d\n", atomic_test_mask
67 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status));
68 ZFCP_DEFINE_PORT_ATTR(access_denied, "%d\n", atomic_test_mask
69 (ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status));
72 * zfcp_sysfs_unit_add_store - add a unit to sysfs tree
73 * @dev: pointer to belonging device
74 * @buf: pointer to input buffer
75 * @count: number of bytes in buffer
77 * Store function of the "unit_add" attribute of a port.
80 zfcp_sysfs_unit_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
84 struct zfcp_port *port;
85 struct zfcp_unit *unit;
88 down(&zfcp_data.config_sema);
90 port = dev_get_drvdata(dev);
91 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
96 fcp_lun = simple_strtoull(buf, &endp, 0);
97 if ((endp + 1) < (buf + count))
100 unit = zfcp_unit_enqueue(port, fcp_lun);
106 zfcp_erp_unit_reopen(unit, 0);
107 zfcp_erp_wait(unit->port->adapter);
110 up(&zfcp_data.config_sema);
111 return retval ? retval : (ssize_t) count;
114 static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
117 * zfcp_sysfs_unit_remove_store - remove a unit from sysfs tree
118 * @dev: pointer to belonging device
119 * @buf: pointer to input buffer
120 * @count: number of bytes in buffer
123 zfcp_sysfs_unit_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
125 struct zfcp_port *port;
126 struct zfcp_unit *unit;
131 down(&zfcp_data.config_sema);
133 port = dev_get_drvdata(dev);
134 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
139 fcp_lun = simple_strtoull(buf, &endp, 0);
140 if ((endp + 1) < (buf + count)) {
145 write_lock_irq(&zfcp_data.config_lock);
146 unit = zfcp_get_unit_by_lun(port, fcp_lun);
147 if (unit && (atomic_read(&unit->refcount) == 0)) {
149 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
150 list_move(&unit->list, &port->unit_remove_lh);
155 write_unlock_irq(&zfcp_data.config_lock);
162 zfcp_erp_unit_shutdown(unit, 0);
163 zfcp_erp_wait(unit->port->adapter);
165 zfcp_unit_dequeue(unit);
167 up(&zfcp_data.config_sema);
168 return retval ? retval : (ssize_t) count;
171 static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
174 * zfcp_sysfs_port_failed_store - failed state of port
175 * @dev: pointer to belonging device
176 * @buf: pointer to input buffer
177 * @count: number of bytes in buffer
179 * Store function of the "failed" attribute of a port.
180 * If a "0" gets written to "failed", error recovery will be
181 * started for the belonging port.
184 zfcp_sysfs_port_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
186 struct zfcp_port *port;
191 down(&zfcp_data.config_sema);
193 port = dev_get_drvdata(dev);
194 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
199 val = simple_strtoul(buf, &endp, 0);
200 if (((endp + 1) < (buf + count)) || (val != 0)) {
205 zfcp_erp_modify_port_status(port, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
206 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
207 zfcp_erp_wait(port->adapter);
209 up(&zfcp_data.config_sema);
210 return retval ? retval : (ssize_t) count;
214 * zfcp_sysfs_port_failed_show - failed state of port
215 * @dev: pointer to belonging device
216 * @buf: pointer to input buffer
218 * Show function of "failed" attribute of port. Will be
219 * "0" if port is working, otherwise "1".
222 zfcp_sysfs_port_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
224 struct zfcp_port *port;
226 port = dev_get_drvdata(dev);
227 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status))
228 return sprintf(buf, "1\n");
230 return sprintf(buf, "0\n");
233 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_port_failed_show,
234 zfcp_sysfs_port_failed_store);
237 * zfcp_port_common_attrs
238 * sysfs attributes that are common for all kind of fc ports.
240 static struct attribute *zfcp_port_common_attrs[] = {
241 &dev_attr_failed.attr,
242 &dev_attr_in_recovery.attr,
243 &dev_attr_status.attr,
244 &dev_attr_access_denied.attr,
248 static struct attribute_group zfcp_port_common_attr_group = {
249 .attrs = zfcp_port_common_attrs,
253 * zfcp_port_no_ns_attrs
254 * sysfs attributes not to be used for nameserver ports.
256 static struct attribute *zfcp_port_no_ns_attrs[] = {
257 &dev_attr_unit_add.attr,
258 &dev_attr_unit_remove.attr,
262 static struct attribute_group zfcp_port_no_ns_attr_group = {
263 .attrs = zfcp_port_no_ns_attrs,
267 * zfcp_sysfs_port_create_files - create sysfs port files
268 * @dev: pointer to belonging device
270 * Create all attributes of the sysfs representation of a port.
273 zfcp_sysfs_port_create_files(struct device *dev, u32 flags)
277 retval = sysfs_create_group(&dev->kobj, &zfcp_port_common_attr_group);
279 if ((flags & ZFCP_STATUS_PORT_WKA) || retval)
282 retval = sysfs_create_group(&dev->kobj, &zfcp_port_no_ns_attr_group);
284 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
290 * zfcp_sysfs_port_remove_files - remove sysfs port files
291 * @dev: pointer to belonging device
293 * Remove all attributes of the sysfs representation of a port.
296 zfcp_sysfs_port_remove_files(struct device *dev, u32 flags)
298 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
299 if (!(flags & ZFCP_STATUS_PORT_WKA))
300 sysfs_remove_group(&dev->kobj, &zfcp_port_no_ns_attr_group);