ia64/kvm: compilation fix. export account_system_vtime.
[pv_ops_mirror.git] / drivers / s390 / scsi / zfcp_sysfs_adapter.c
blobccbba4dd3a77aabfcb7a3c5ee8d89c98289501e6
1 /*
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)
10 * any later version.
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.
22 #include "zfcp_ext.h"
24 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
26 /**
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, \
36 char *buf) \
37 { \
38 struct zfcp_adapter *adapter; \
40 adapter = dev_get_drvdata(dev); \
41 return sprintf(buf, _format, _value); \
42 } \
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));
57 /**
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.
65 static ssize_t
66 zfcp_sysfs_port_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
68 wwn_t wwpn;
69 char *endp;
70 struct zfcp_adapter *adapter;
71 struct zfcp_port *port;
72 int retval = -EINVAL;
74 down(&zfcp_data.config_sema);
76 adapter = dev_get_drvdata(dev);
77 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
78 retval = -EBUSY;
79 goto out;
82 wwpn = simple_strtoull(buf, &endp, 0);
83 if ((endp + 1) < (buf + count))
84 goto out;
86 port = zfcp_port_enqueue(adapter, wwpn, 0, 0);
87 if (!port)
88 goto out;
90 retval = 0;
92 zfcp_erp_port_reopen(port, 0, 91, NULL);
93 zfcp_erp_wait(port->adapter);
94 zfcp_port_put(port);
95 out:
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.
110 static ssize_t
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;
115 wwn_t wwpn;
116 char *endp;
117 int retval = 0;
119 down(&zfcp_data.config_sema);
121 adapter = dev_get_drvdata(dev);
122 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
123 retval = -EBUSY;
124 goto out;
127 wwpn = simple_strtoull(buf, &endp, 0);
128 if ((endp + 1) < (buf + count)) {
129 retval = -EINVAL;
130 goto out;
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)) {
136 zfcp_port_get(port);
137 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
138 list_move(&port->list, &adapter->port_remove_lh);
140 else {
141 port = NULL;
143 write_unlock_irq(&zfcp_data.config_lock);
145 if (!port) {
146 retval = -ENXIO;
147 goto out;
150 zfcp_erp_port_shutdown(port, 0, 92, NULL);
151 zfcp_erp_wait(adapter);
152 zfcp_port_put(port);
153 zfcp_port_dequeue(port);
154 out:
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.
171 static ssize_t
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;
176 unsigned int val;
177 char *endp;
178 int retval = 0;
180 down(&zfcp_data.config_sema);
182 adapter = dev_get_drvdata(dev);
183 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
184 retval = -EBUSY;
185 goto out;
188 val = simple_strtoul(buf, &endp, 0);
189 if (((endp + 1) < (buf + count)) || (val != 0)) {
190 retval = -EINVAL;
191 goto out;
194 zfcp_erp_modify_adapter_status(adapter, 44, NULL,
195 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
196 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 93,
197 NULL);
198 zfcp_erp_wait(adapter);
199 out:
200 up(&zfcp_data.config_sema);
201 return retval ? retval : (ssize_t) count;
205 * zfcp_sysfs_adapter_failed_show - failed state of adapter
206 * @dev: pointer to belonging device
207 * @buf: pointer to input buffer
209 * Show function of "failed" attribute of adapter. Will be
210 * "0" if adapter is working, otherwise "1".
212 static ssize_t
213 zfcp_sysfs_adapter_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
215 struct zfcp_adapter *adapter;
217 adapter = dev_get_drvdata(dev);
218 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status))
219 return sprintf(buf, "1\n");
220 else
221 return sprintf(buf, "0\n");
224 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_adapter_failed_show,
225 zfcp_sysfs_adapter_failed_store);
227 static struct attribute *zfcp_adapter_attrs[] = {
228 &dev_attr_failed.attr,
229 &dev_attr_in_recovery.attr,
230 &dev_attr_port_remove.attr,
231 &dev_attr_port_add.attr,
232 &dev_attr_peer_wwnn.attr,
233 &dev_attr_peer_wwpn.attr,
234 &dev_attr_peer_d_id.attr,
235 &dev_attr_card_version.attr,
236 &dev_attr_lic_version.attr,
237 &dev_attr_status.attr,
238 &dev_attr_hardware_version.attr,
239 NULL
242 static struct attribute_group zfcp_adapter_attr_group = {
243 .attrs = zfcp_adapter_attrs,
247 * zfcp_sysfs_create_adapter_files - create sysfs adapter files
248 * @dev: pointer to belonging device
250 * Create all attributes of the sysfs representation of an adapter.
253 zfcp_sysfs_adapter_create_files(struct device *dev)
255 return sysfs_create_group(&dev->kobj, &zfcp_adapter_attr_group);
259 * zfcp_sysfs_remove_adapter_files - remove sysfs adapter files
260 * @dev: pointer to belonging device
262 * Remove all attributes of the sysfs representation of an adapter.
264 void
265 zfcp_sysfs_adapter_remove_files(struct device *dev)
267 sysfs_remove_group(&dev->kobj, &zfcp_adapter_attr_group);
270 #undef ZFCP_LOG_AREA