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>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define ZFCP_SYSFS_ADAPTER_C_REVISION "$Revision: 1.37 $"
33 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
35 static const char fc_topologies
[5][25] = {
40 "fabric (virt. adapter)"
44 * ZFCP_DEFINE_ADAPTER_ATTR
45 * @_name: name of show attribute
46 * @_format: format string
47 * @_value: value to print
49 * Generates attributes for an adapter.
51 #define ZFCP_DEFINE_ADAPTER_ATTR(_name, _format, _value) \
52 static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
55 struct zfcp_adapter *adapter; \
57 adapter = dev_get_drvdata(dev); \
58 return sprintf(buf, _format, _value); \
61 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
63 ZFCP_DEFINE_ADAPTER_ATTR(status
, "0x%08x\n", atomic_read(&adapter
->status
));
64 ZFCP_DEFINE_ADAPTER_ATTR(wwnn
, "0x%016llx\n", adapter
->wwnn
);
65 ZFCP_DEFINE_ADAPTER_ATTR(wwpn
, "0x%016llx\n", adapter
->wwpn
);
66 ZFCP_DEFINE_ADAPTER_ATTR(s_id
, "0x%06x\n", adapter
->s_id
);
67 ZFCP_DEFINE_ADAPTER_ATTR(card_version
, "0x%04x\n", adapter
->hydra_version
);
68 ZFCP_DEFINE_ADAPTER_ATTR(lic_version
, "0x%08x\n", adapter
->fsf_lic_version
);
69 ZFCP_DEFINE_ADAPTER_ATTR(fc_link_speed
, "%d Gb/s\n", adapter
->fc_link_speed
);
70 ZFCP_DEFINE_ADAPTER_ATTR(fc_service_class
, "%d\n", adapter
->fc_service_class
);
71 ZFCP_DEFINE_ADAPTER_ATTR(fc_topology
, "%s\n",
72 fc_topologies
[adapter
->fc_topology
]);
73 ZFCP_DEFINE_ADAPTER_ATTR(hardware_version
, "0x%08x\n",
74 adapter
->hardware_version
);
75 ZFCP_DEFINE_ADAPTER_ATTR(serial_number
, "%17s\n", adapter
->serial_number
);
76 ZFCP_DEFINE_ADAPTER_ATTR(scsi_host_no
, "0x%x\n", adapter
->scsi_host_no
);
77 ZFCP_DEFINE_ADAPTER_ATTR(in_recovery
, "%d\n", atomic_test_mask
78 (ZFCP_STATUS_COMMON_ERP_INUSE
, &adapter
->status
));
81 * zfcp_sysfs_port_add_store - add a port to sysfs tree
82 * @dev: pointer to belonging device
83 * @buf: pointer to input buffer
84 * @count: number of bytes in buffer
86 * Store function of the "port_add" attribute of an adapter.
89 zfcp_sysfs_port_add_store(struct device
*dev
, const char *buf
, size_t count
)
93 struct zfcp_adapter
*adapter
;
94 struct zfcp_port
*port
;
97 down(&zfcp_data
.config_sema
);
99 adapter
= dev_get_drvdata(dev
);
100 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
)) {
105 wwpn
= simple_strtoull(buf
, &endp
, 0);
106 if ((endp
+ 1) < (buf
+ count
))
109 port
= zfcp_port_enqueue(adapter
, wwpn
, 0, 0);
115 zfcp_erp_port_reopen(port
, 0);
116 zfcp_erp_wait(port
->adapter
);
119 up(&zfcp_data
.config_sema
);
120 return retval
? retval
: (ssize_t
) count
;
123 static DEVICE_ATTR(port_add
, S_IWUSR
, NULL
, zfcp_sysfs_port_add_store
);
126 * zfcp_sysfs_port_remove_store - remove a port from sysfs tree
127 * @dev: pointer to belonging device
128 * @buf: pointer to input buffer
129 * @count: number of bytes in buffer
131 * Store function of the "port_remove" attribute of an adapter.
134 zfcp_sysfs_port_remove_store(struct device
*dev
, const char *buf
, size_t count
)
136 struct zfcp_adapter
*adapter
;
137 struct zfcp_port
*port
;
142 down(&zfcp_data
.config_sema
);
144 adapter
= dev_get_drvdata(dev
);
145 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
)) {
150 wwpn
= simple_strtoull(buf
, &endp
, 0);
151 if ((endp
+ 1) < (buf
+ count
)) {
156 write_lock_irq(&zfcp_data
.config_lock
);
157 port
= zfcp_get_port_by_wwpn(adapter
, wwpn
);
158 if (port
&& (atomic_read(&port
->refcount
) == 0)) {
160 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
161 list_move(&port
->list
, &adapter
->port_remove_lh
);
166 write_unlock_irq(&zfcp_data
.config_lock
);
173 zfcp_erp_port_shutdown(port
, 0);
174 zfcp_erp_wait(adapter
);
176 zfcp_port_dequeue(port
);
178 up(&zfcp_data
.config_sema
);
179 return retval
? retval
: (ssize_t
) count
;
182 static DEVICE_ATTR(port_remove
, S_IWUSR
, NULL
, zfcp_sysfs_port_remove_store
);
185 * zfcp_sysfs_adapter_failed_store - failed state of adapter
186 * @dev: pointer to belonging device
187 * @buf: pointer to input buffer
188 * @count: number of bytes in buffer
190 * Store function of the "failed" attribute of an adapter.
191 * If a "0" gets written to "failed", error recovery will be
192 * started for the belonging adapter.
195 zfcp_sysfs_adapter_failed_store(struct device
*dev
,
196 const char *buf
, size_t count
)
198 struct zfcp_adapter
*adapter
;
203 down(&zfcp_data
.config_sema
);
205 adapter
= dev_get_drvdata(dev
);
206 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE
, &adapter
->status
)) {
211 val
= simple_strtoul(buf
, &endp
, 0);
212 if (((endp
+ 1) < (buf
+ count
)) || (val
!= 0)) {
217 zfcp_erp_modify_adapter_status(adapter
, ZFCP_STATUS_COMMON_RUNNING
,
219 zfcp_erp_adapter_reopen(adapter
, ZFCP_STATUS_COMMON_ERP_FAILED
);
220 zfcp_erp_wait(adapter
);
222 up(&zfcp_data
.config_sema
);
223 return retval
? retval
: (ssize_t
) count
;
227 * zfcp_sysfs_adapter_failed_show - failed state of adapter
228 * @dev: pointer to belonging device
229 * @buf: pointer to input buffer
231 * Show function of "failed" attribute of adapter. Will be
232 * "0" if adapter is working, otherwise "1".
235 zfcp_sysfs_adapter_failed_show(struct device
*dev
, char *buf
)
237 struct zfcp_adapter
*adapter
;
239 adapter
= dev_get_drvdata(dev
);
240 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED
, &adapter
->status
))
241 return sprintf(buf
, "1\n");
243 return sprintf(buf
, "0\n");
246 static DEVICE_ATTR(failed
, S_IWUSR
| S_IRUGO
, zfcp_sysfs_adapter_failed_show
,
247 zfcp_sysfs_adapter_failed_store
);
249 static struct attribute
*zfcp_adapter_attrs
[] = {
250 &dev_attr_failed
.attr
,
251 &dev_attr_in_recovery
.attr
,
252 &dev_attr_port_remove
.attr
,
253 &dev_attr_port_add
.attr
,
257 &dev_attr_card_version
.attr
,
258 &dev_attr_lic_version
.attr
,
259 &dev_attr_fc_link_speed
.attr
,
260 &dev_attr_fc_service_class
.attr
,
261 &dev_attr_fc_topology
.attr
,
262 &dev_attr_scsi_host_no
.attr
,
263 &dev_attr_status
.attr
,
264 &dev_attr_hardware_version
.attr
,
265 &dev_attr_serial_number
.attr
,
269 static struct attribute_group zfcp_adapter_attr_group
= {
270 .attrs
= zfcp_adapter_attrs
,
274 * zfcp_sysfs_create_adapter_files - create sysfs adapter files
275 * @dev: pointer to belonging device
277 * Create all attributes of the sysfs representation of an adapter.
280 zfcp_sysfs_adapter_create_files(struct device
*dev
)
282 return sysfs_create_group(&dev
->kobj
, &zfcp_adapter_attr_group
);
286 * zfcp_sysfs_remove_adapter_files - remove sysfs adapter files
287 * @dev: pointer to belonging device
289 * Remove all attributes of the sysfs representation of an adapter.
292 zfcp_sysfs_adapter_remove_files(struct device
*dev
)
294 sysfs_remove_group(&dev
->kobj
, &zfcp_adapter_attr_group
);