2 * linux/drivers/s390/scsi/zfcp_sysfs_adapter.c
4 * FCP adapter driver for IBM eServer zSeries
6 * sysfs adapter 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>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #define ZFCP_SYSFS_ADAPTER_C_REVISION "$Revision: 1.38 $"
34 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
36 static const char fc_topologies[5][25] = {
41 "fabric (virt. adapter)"
45 * ZFCP_DEFINE_ADAPTER_ATTR
46 * @_name: name of show attribute
47 * @_format: format string
48 * @_value: value to print
50 * Generates attributes for an adapter.
52 #define ZFCP_DEFINE_ADAPTER_ATTR(_name, _format, _value) \
53 static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, struct device_attribute *attr, \
56 struct zfcp_adapter *adapter; \
58 adapter = dev_get_drvdata(dev); \
59 return sprintf(buf, _format, _value); \
62 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
64 ZFCP_DEFINE_ADAPTER_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
65 ZFCP_DEFINE_ADAPTER_ATTR(peer_wwnn, "0x%016llx\n", adapter->peer_wwnn);
66 ZFCP_DEFINE_ADAPTER_ATTR(peer_wwpn, "0x%016llx\n", adapter->peer_wwpn);
67 ZFCP_DEFINE_ADAPTER_ATTR(peer_d_id, "0x%06x\n", adapter->peer_d_id);
68 ZFCP_DEFINE_ADAPTER_ATTR(physical_wwpn, "0x%016llx\n", adapter->physical_wwpn);
69 ZFCP_DEFINE_ADAPTER_ATTR(physical_s_id, "0x%06x\n", adapter->physical_s_id);
70 ZFCP_DEFINE_ADAPTER_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
71 ZFCP_DEFINE_ADAPTER_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
72 ZFCP_DEFINE_ADAPTER_ATTR(fc_service_class, "%d\n", adapter->fc_service_class);
73 ZFCP_DEFINE_ADAPTER_ATTR(fc_topology, "%s\n",
74 fc_topologies[adapter->fc_topology]);
75 ZFCP_DEFINE_ADAPTER_ATTR(hardware_version, "0x%08x\n",
76 adapter->hardware_version);
77 ZFCP_DEFINE_ADAPTER_ATTR(scsi_host_no, "0x%x\n", adapter->scsi_host_no);
78 ZFCP_DEFINE_ADAPTER_ATTR(in_recovery, "%d\n", atomic_test_mask
79 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status));
82 * zfcp_sysfs_port_add_store - add a port to sysfs tree
83 * @dev: pointer to belonging device
84 * @buf: pointer to input buffer
85 * @count: number of bytes in buffer
87 * Store function of the "port_add" attribute of an adapter.
90 zfcp_sysfs_port_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
94 struct zfcp_adapter *adapter;
95 struct zfcp_port *port;
98 down(&zfcp_data.config_sema);
100 adapter = dev_get_drvdata(dev);
101 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
106 wwpn = simple_strtoull(buf, &endp, 0);
107 if ((endp + 1) < (buf + count))
110 port = zfcp_port_enqueue(adapter, wwpn, 0, 0);
116 zfcp_erp_port_reopen(port, 0);
117 zfcp_erp_wait(port->adapter);
120 up(&zfcp_data.config_sema);
121 return retval ? retval : (ssize_t) count;
124 static DEVICE_ATTR(port_add, S_IWUSR, NULL, zfcp_sysfs_port_add_store);
127 * zfcp_sysfs_port_remove_store - remove a port from sysfs tree
128 * @dev: pointer to belonging device
129 * @buf: pointer to input buffer
130 * @count: number of bytes in buffer
132 * Store function of the "port_remove" attribute of an adapter.
135 zfcp_sysfs_port_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
137 struct zfcp_adapter *adapter;
138 struct zfcp_port *port;
143 down(&zfcp_data.config_sema);
145 adapter = dev_get_drvdata(dev);
146 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
151 wwpn = simple_strtoull(buf, &endp, 0);
152 if ((endp + 1) < (buf + count)) {
157 write_lock_irq(&zfcp_data.config_lock);
158 port = zfcp_get_port_by_wwpn(adapter, wwpn);
159 if (port && (atomic_read(&port->refcount) == 0)) {
161 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
162 list_move(&port->list, &adapter->port_remove_lh);
167 write_unlock_irq(&zfcp_data.config_lock);
174 zfcp_erp_port_shutdown(port, 0);
175 zfcp_erp_wait(adapter);
177 zfcp_port_dequeue(port);
179 up(&zfcp_data.config_sema);
180 return retval ? retval : (ssize_t) count;
183 static DEVICE_ATTR(port_remove, S_IWUSR, NULL, zfcp_sysfs_port_remove_store);
186 * zfcp_sysfs_adapter_failed_store - failed state of adapter
187 * @dev: pointer to belonging device
188 * @buf: pointer to input buffer
189 * @count: number of bytes in buffer
191 * Store function of the "failed" attribute of an adapter.
192 * If a "0" gets written to "failed", error recovery will be
193 * started for the belonging adapter.
196 zfcp_sysfs_adapter_failed_store(struct device *dev, struct device_attribute *attr,
197 const char *buf, size_t count)
199 struct zfcp_adapter *adapter;
204 down(&zfcp_data.config_sema);
206 adapter = dev_get_drvdata(dev);
207 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
212 val = simple_strtoul(buf, &endp, 0);
213 if (((endp + 1) < (buf + count)) || (val != 0)) {
218 zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
220 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
221 zfcp_erp_wait(adapter);
223 up(&zfcp_data.config_sema);
224 return retval ? retval : (ssize_t) count;
228 * zfcp_sysfs_adapter_failed_show - failed state of adapter
229 * @dev: pointer to belonging device
230 * @buf: pointer to input buffer
232 * Show function of "failed" attribute of adapter. Will be
233 * "0" if adapter is working, otherwise "1".
236 zfcp_sysfs_adapter_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
238 struct zfcp_adapter *adapter;
240 adapter = dev_get_drvdata(dev);
241 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status))
242 return sprintf(buf, "1\n");
244 return sprintf(buf, "0\n");
247 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_adapter_failed_show,
248 zfcp_sysfs_adapter_failed_store);
250 static struct attribute *zfcp_adapter_attrs[] = {
251 &dev_attr_failed.attr,
252 &dev_attr_in_recovery.attr,
253 &dev_attr_port_remove.attr,
254 &dev_attr_port_add.attr,
255 &dev_attr_peer_wwnn.attr,
256 &dev_attr_peer_wwpn.attr,
257 &dev_attr_peer_d_id.attr,
258 &dev_attr_physical_wwpn.attr,
259 &dev_attr_physical_s_id.attr,
260 &dev_attr_card_version.attr,
261 &dev_attr_lic_version.attr,
262 &dev_attr_fc_service_class.attr,
263 &dev_attr_fc_topology.attr,
264 &dev_attr_scsi_host_no.attr,
265 &dev_attr_status.attr,
266 &dev_attr_hardware_version.attr,
270 static struct attribute_group zfcp_adapter_attr_group = {
271 .attrs = zfcp_adapter_attrs,
275 * zfcp_sysfs_create_adapter_files - create sysfs adapter files
276 * @dev: pointer to belonging device
278 * Create all attributes of the sysfs representation of an adapter.
281 zfcp_sysfs_adapter_create_files(struct device *dev)
283 return sysfs_create_group(&dev->kobj, &zfcp_adapter_attr_group);
287 * zfcp_sysfs_remove_adapter_files - remove sysfs adapter files
288 * @dev: pointer to belonging device
290 * Remove all attributes of the sysfs representation of an adapter.
293 zfcp_sysfs_adapter_remove_files(struct device *dev)
295 sysfs_remove_group(&dev->kobj, &zfcp_adapter_attr_group);