aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/s390/scsi/zfcp_sysfs_adapter.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/s390/scsi/zfcp_sysfs_adapter.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/s390/scsi/zfcp_sysfs_adapter.c')
-rw-r--r--drivers/s390/scsi/zfcp_sysfs_adapter.c298
1 files changed, 298 insertions, 0 deletions
diff --git a/drivers/s390/scsi/zfcp_sysfs_adapter.c b/drivers/s390/scsi/zfcp_sysfs_adapter.c
new file mode 100644
index 000000000000..ff28ade1dfc7
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_sysfs_adapter.c
@@ -0,0 +1,298 @@
1/*
2 * linux/drivers/s390/scsi/zfcp_sysfs_adapter.c
3 *
4 * FCP adapter driver for IBM eServer zSeries
5 *
6 * sysfs adapter related routines
7 *
8 * (C) Copyright IBM Corp. 2003, 2004
9 *
10 * Authors:
11 * Martin Peschke <mpeschke@de.ibm.com>
12 * Heiko Carstens <heiko.carstens@de.ibm.com>
13 * Andreas Herrmann <aherrman@de.ibm.com>
14 *
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)
18 * any later version.
19 *
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.
24 *
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.
28 */
29
30#define ZFCP_SYSFS_ADAPTER_C_REVISION "$Revision: 1.38 $"
31
32#include "zfcp_ext.h"
33
34#define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
35
36static const char fc_topologies[5][25] = {
37 "<error>",
38 "point-to-point",
39 "fabric",
40 "arbitrated loop",
41 "fabric (virt. adapter)"
42};
43
44/**
45 * ZFCP_DEFINE_ADAPTER_ATTR
46 * @_name: name of show attribute
47 * @_format: format string
48 * @_value: value to print
49 *
50 * Generates attributes for an adapter.
51 */
52#define ZFCP_DEFINE_ADAPTER_ATTR(_name, _format, _value) \
53static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
54 char *buf) \
55{ \
56 struct zfcp_adapter *adapter; \
57 \
58 adapter = dev_get_drvdata(dev); \
59 return sprintf(buf, _format, _value); \
60} \
61 \
62static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
63
64ZFCP_DEFINE_ADAPTER_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
65ZFCP_DEFINE_ADAPTER_ATTR(wwnn, "0x%016llx\n", adapter->wwnn);
66ZFCP_DEFINE_ADAPTER_ATTR(wwpn, "0x%016llx\n", adapter->wwpn);
67ZFCP_DEFINE_ADAPTER_ATTR(s_id, "0x%06x\n", adapter->s_id);
68ZFCP_DEFINE_ADAPTER_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
69ZFCP_DEFINE_ADAPTER_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
70ZFCP_DEFINE_ADAPTER_ATTR(fc_link_speed, "%d Gb/s\n", adapter->fc_link_speed);
71ZFCP_DEFINE_ADAPTER_ATTR(fc_service_class, "%d\n", adapter->fc_service_class);
72ZFCP_DEFINE_ADAPTER_ATTR(fc_topology, "%s\n",
73 fc_topologies[adapter->fc_topology]);
74ZFCP_DEFINE_ADAPTER_ATTR(hardware_version, "0x%08x\n",
75 adapter->hardware_version);
76ZFCP_DEFINE_ADAPTER_ATTR(serial_number, "%17s\n", adapter->serial_number);
77ZFCP_DEFINE_ADAPTER_ATTR(scsi_host_no, "0x%x\n", adapter->scsi_host_no);
78ZFCP_DEFINE_ADAPTER_ATTR(in_recovery, "%d\n", atomic_test_mask
79 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status));
80
81/**
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
86 *
87 * Store function of the "port_add" attribute of an adapter.
88 */
89static ssize_t
90zfcp_sysfs_port_add_store(struct device *dev, const char *buf, size_t count)
91{
92 wwn_t wwpn;
93 char *endp;
94 struct zfcp_adapter *adapter;
95 struct zfcp_port *port;
96 int retval = -EINVAL;
97
98 down(&zfcp_data.config_sema);
99
100 adapter = dev_get_drvdata(dev);
101 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
102 retval = -EBUSY;
103 goto out;
104 }
105
106 wwpn = simple_strtoull(buf, &endp, 0);
107 if ((endp + 1) < (buf + count))
108 goto out;
109
110 port = zfcp_port_enqueue(adapter, wwpn, 0, 0);
111 if (!port)
112 goto out;
113
114 retval = 0;
115
116 zfcp_erp_port_reopen(port, 0);
117 zfcp_erp_wait(port->adapter);
118 zfcp_port_put(port);
119 out:
120 up(&zfcp_data.config_sema);
121 return retval ? retval : (ssize_t) count;
122}
123
124static DEVICE_ATTR(port_add, S_IWUSR, NULL, zfcp_sysfs_port_add_store);
125
126/**
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
131 *
132 * Store function of the "port_remove" attribute of an adapter.
133 */
134static ssize_t
135zfcp_sysfs_port_remove_store(struct device *dev, const char *buf, size_t count)
136{
137 struct zfcp_adapter *adapter;
138 struct zfcp_port *port;
139 wwn_t wwpn;
140 char *endp;
141 int retval = 0;
142
143 down(&zfcp_data.config_sema);
144
145 adapter = dev_get_drvdata(dev);
146 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
147 retval = -EBUSY;
148 goto out;
149 }
150
151 wwpn = simple_strtoull(buf, &endp, 0);
152 if ((endp + 1) < (buf + count)) {
153 retval = -EINVAL;
154 goto out;
155 }
156
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)) {
160 zfcp_port_get(port);
161 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
162 list_move(&port->list, &adapter->port_remove_lh);
163 }
164 else {
165 port = NULL;
166 }
167 write_unlock_irq(&zfcp_data.config_lock);
168
169 if (!port) {
170 retval = -ENXIO;
171 goto out;
172 }
173
174 zfcp_erp_port_shutdown(port, 0);
175 zfcp_erp_wait(adapter);
176 zfcp_port_put(port);
177 zfcp_port_dequeue(port);
178 out:
179 up(&zfcp_data.config_sema);
180 return retval ? retval : (ssize_t) count;
181}
182
183static DEVICE_ATTR(port_remove, S_IWUSR, NULL, zfcp_sysfs_port_remove_store);
184
185/**
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
190 *
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.
194 */
195static ssize_t
196zfcp_sysfs_adapter_failed_store(struct device *dev,
197 const char *buf, size_t count)
198{
199 struct zfcp_adapter *adapter;
200 unsigned int val;
201 char *endp;
202 int retval = 0;
203
204 down(&zfcp_data.config_sema);
205
206 adapter = dev_get_drvdata(dev);
207 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
208 retval = -EBUSY;
209 goto out;
210 }
211
212 val = simple_strtoul(buf, &endp, 0);
213 if (((endp + 1) < (buf + count)) || (val != 0)) {
214 retval = -EINVAL;
215 goto out;
216 }
217
218 zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
219 ZFCP_SET);
220 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
221 zfcp_erp_wait(adapter);
222 out:
223 up(&zfcp_data.config_sema);
224 return retval ? retval : (ssize_t) count;
225}
226
227/**
228 * zfcp_sysfs_adapter_failed_show - failed state of adapter
229 * @dev: pointer to belonging device
230 * @buf: pointer to input buffer
231 *
232 * Show function of "failed" attribute of adapter. Will be
233 * "0" if adapter is working, otherwise "1".
234 */
235static ssize_t
236zfcp_sysfs_adapter_failed_show(struct device *dev, char *buf)
237{
238 struct zfcp_adapter *adapter;
239
240 adapter = dev_get_drvdata(dev);
241 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status))
242 return sprintf(buf, "1\n");
243 else
244 return sprintf(buf, "0\n");
245}
246
247static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_adapter_failed_show,
248 zfcp_sysfs_adapter_failed_store);
249
250static 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_wwnn.attr,
256 &dev_attr_wwpn.attr,
257 &dev_attr_s_id.attr,
258 &dev_attr_card_version.attr,
259 &dev_attr_lic_version.attr,
260 &dev_attr_fc_link_speed.attr,
261 &dev_attr_fc_service_class.attr,
262 &dev_attr_fc_topology.attr,
263 &dev_attr_scsi_host_no.attr,
264 &dev_attr_status.attr,
265 &dev_attr_hardware_version.attr,
266 &dev_attr_serial_number.attr,
267 NULL
268};
269
270static struct attribute_group zfcp_adapter_attr_group = {
271 .attrs = zfcp_adapter_attrs,
272};
273
274/**
275 * zfcp_sysfs_create_adapter_files - create sysfs adapter files
276 * @dev: pointer to belonging device
277 *
278 * Create all attributes of the sysfs representation of an adapter.
279 */
280int
281zfcp_sysfs_adapter_create_files(struct device *dev)
282{
283 return sysfs_create_group(&dev->kobj, &zfcp_adapter_attr_group);
284}
285
286/**
287 * zfcp_sysfs_remove_adapter_files - remove sysfs adapter files
288 * @dev: pointer to belonging device
289 *
290 * Remove all attributes of the sysfs representation of an adapter.
291 */
292void
293zfcp_sysfs_adapter_remove_files(struct device *dev)
294{
295 sysfs_remove_group(&dev->kobj, &zfcp_adapter_attr_group);
296}
297
298#undef ZFCP_LOG_AREA