2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
27 * ZFCP_DEFINE_ADAPTER_ATTR
28 * @_name: name of show attribute
29 * @_format: format string
30 * @_value: value to print
32 * Generates attributes for an adapter.
34 #define ZFCP_DEFINE_ADAPTER_ATTR(_name, _format, _value) \
35 static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, struct device_attribute *attr, \
38 struct zfcp_adapter *adapter; \
40 adapter = dev_get_drvdata(dev); \
41 return sprintf(buf, _format, _value); \
44 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
46 ZFCP_DEFINE_ADAPTER_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
47 ZFCP_DEFINE_ADAPTER_ATTR(peer_wwnn, "0x%016llx\n", adapter->peer_wwnn);
48 ZFCP_DEFINE_ADAPTER_ATTR(peer_wwpn, "0x%016llx\n", adapter->peer_wwpn);
49 ZFCP_DEFINE_ADAPTER_ATTR(peer_d_id, "0x%06x\n", adapter->peer_d_id);
50 ZFCP_DEFINE_ADAPTER_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
51 ZFCP_DEFINE_ADAPTER_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
52 ZFCP_DEFINE_ADAPTER_ATTR(hardware_version, "0x%08x\n",
53 adapter->hardware_version);
54 ZFCP_DEFINE_ADAPTER_ATTR(in_recovery, "%d\n", atomic_test_mask
55 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status));
58 * zfcp_sysfs_port_add_store - add a port to sysfs tree
59 * @dev: pointer to belonging device
60 * @buf: pointer to input buffer
61 * @count: number of bytes in buffer
63 * Store function of the "port_add" attribute of an adapter.
66 zfcp_sysfs_port_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
70 struct zfcp_adapter *adapter;
71 struct zfcp_port *port;
74 down(&zfcp_data.config_sema);
76 adapter = dev_get_drvdata(dev);
77 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
82 wwpn = simple_strtoull(buf, &endp, 0);
83 if ((endp + 1) < (buf + count))
86 port = zfcp_port_enqueue(adapter, wwpn, 0, 0);
92 zfcp_erp_port_reopen(port, 0);
93 zfcp_erp_wait(port->adapter);
96 up(&zfcp_data.config_sema);
97 return retval ? retval : (ssize_t) count;
100 static DEVICE_ATTR(port_add, S_IWUSR, NULL, zfcp_sysfs_port_add_store);
103 * zfcp_sysfs_port_remove_store - remove a port from sysfs tree
104 * @dev: pointer to belonging device
105 * @buf: pointer to input buffer
106 * @count: number of bytes in buffer
108 * Store function of the "port_remove" attribute of an adapter.
111 zfcp_sysfs_port_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
113 struct zfcp_adapter *adapter;
114 struct zfcp_port *port;
119 down(&zfcp_data.config_sema);
121 adapter = dev_get_drvdata(dev);
122 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
127 wwpn = simple_strtoull(buf, &endp, 0);
128 if ((endp + 1) < (buf + count)) {
133 write_lock_irq(&zfcp_data.config_lock);
134 port = zfcp_get_port_by_wwpn(adapter, wwpn);
135 if (port && (atomic_read(&port->refcount) == 0)) {
137 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
138 list_move(&port->list, &adapter->port_remove_lh);
143 write_unlock_irq(&zfcp_data.config_lock);
150 zfcp_erp_port_shutdown(port, 0);
151 zfcp_erp_wait(adapter);
153 zfcp_port_dequeue(port);
155 up(&zfcp_data.config_sema);
156 return retval ? retval : (ssize_t) count;
159 static DEVICE_ATTR(port_remove, S_IWUSR, NULL, zfcp_sysfs_port_remove_store);
162 * zfcp_sysfs_adapter_failed_store - failed state of adapter
163 * @dev: pointer to belonging device
164 * @buf: pointer to input buffer
165 * @count: number of bytes in buffer
167 * Store function of the "failed" attribute of an adapter.
168 * If a "0" gets written to "failed", error recovery will be
169 * started for the belonging adapter.
172 zfcp_sysfs_adapter_failed_store(struct device *dev, struct device_attribute *attr,
173 const char *buf, size_t count)
175 struct zfcp_adapter *adapter;
180 down(&zfcp_data.config_sema);
182 adapter = dev_get_drvdata(dev);
183 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
188 val = simple_strtoul(buf, &endp, 0);
189 if (((endp + 1) < (buf + count)) || (val != 0)) {
194 zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
196 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
197 zfcp_erp_wait(adapter);
199 up(&zfcp_data.config_sema);
200 return retval ? retval : (ssize_t) count;
204 * zfcp_sysfs_adapter_failed_show - failed state of adapter
205 * @dev: pointer to belonging device
206 * @buf: pointer to input buffer
208 * Show function of "failed" attribute of adapter. Will be
209 * "0" if adapter is working, otherwise "1".
212 zfcp_sysfs_adapter_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
214 struct zfcp_adapter *adapter;
216 adapter = dev_get_drvdata(dev);
217 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status))
218 return sprintf(buf, "1\n");
220 return sprintf(buf, "0\n");
223 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_adapter_failed_show,
224 zfcp_sysfs_adapter_failed_store);
226 static struct attribute *zfcp_adapter_attrs[] = {
227 &dev_attr_failed.attr,
228 &dev_attr_in_recovery.attr,
229 &dev_attr_port_remove.attr,
230 &dev_attr_port_add.attr,
231 &dev_attr_peer_wwnn.attr,
232 &dev_attr_peer_wwpn.attr,
233 &dev_attr_peer_d_id.attr,
234 &dev_attr_card_version.attr,
235 &dev_attr_lic_version.attr,
236 &dev_attr_status.attr,
237 &dev_attr_hardware_version.attr,
241 static struct attribute_group zfcp_adapter_attr_group = {
242 .attrs = zfcp_adapter_attrs,
246 * zfcp_sysfs_create_adapter_files - create sysfs adapter files
247 * @dev: pointer to belonging device
249 * Create all attributes of the sysfs representation of an adapter.
252 zfcp_sysfs_adapter_create_files(struct device *dev)
254 return sysfs_create_group(&dev->kobj, &zfcp_adapter_attr_group);
258 * zfcp_sysfs_remove_adapter_files - remove sysfs adapter files
259 * @dev: pointer to belonging device
261 * Remove all attributes of the sysfs representation of an adapter.
264 zfcp_sysfs_adapter_remove_files(struct device *dev)
266 sysfs_remove_group(&dev->kobj, &zfcp_adapter_attr_group);