4 * sysfs attributes for CCW device.
6 * Copyright IBM Corporation 2002, 2008
12 * ZFCP_DEFINE_ADAPTER_ATTR
13 * @_name: name of show attribute
14 * @_format: format string
15 * @_value: value to print
17 * Generates attributes for an adapter.
19 #define ZFCP_DEFINE_ADAPTER_ATTR(_name, _format, _value) \
20 static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, struct device_attribute *attr, \
23 struct zfcp_adapter *adapter; \
25 adapter = dev_get_drvdata(dev); \
26 return sprintf(buf, _format, _value); \
29 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
31 ZFCP_DEFINE_ADAPTER_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
32 ZFCP_DEFINE_ADAPTER_ATTR(peer_wwnn, "0x%016llx\n", adapter->peer_wwnn);
33 ZFCP_DEFINE_ADAPTER_ATTR(peer_wwpn, "0x%016llx\n", adapter->peer_wwpn);
34 ZFCP_DEFINE_ADAPTER_ATTR(peer_d_id, "0x%06x\n", adapter->peer_d_id);
35 ZFCP_DEFINE_ADAPTER_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
36 ZFCP_DEFINE_ADAPTER_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
37 ZFCP_DEFINE_ADAPTER_ATTR(hardware_version, "0x%08x\n",
38 adapter->hardware_version);
39 ZFCP_DEFINE_ADAPTER_ATTR(in_recovery, "%d\n", atomic_test_mask
40 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status));
43 * zfcp_sysfs_port_rescan - trigger manual port rescan
44 * @dev: pointer to belonging device
45 * @attr: pointer to struct device_attribute
46 * @buf: pointer to input buffer
47 * @count: number of bytes in buffer
49 static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev,
50 struct device_attribute *attr,
51 const char *buf, size_t count)
53 struct zfcp_adapter *adapter;
56 adapter = dev_get_drvdata(dev);
57 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status))
60 ret = zfcp_scan_ports(adapter);
62 return ret ? ret : (ssize_t) count;
64 static DEVICE_ATTR(port_rescan, S_IWUSR, NULL, zfcp_sysfs_port_rescan_store);
67 * zfcp_sysfs_port_remove_store - remove a port from sysfs tree
68 * @dev: pointer to belonging device
69 * @buf: pointer to input buffer
70 * @count: number of bytes in buffer
72 * Store function of the "port_remove" attribute of an adapter.
75 zfcp_sysfs_port_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
77 struct zfcp_adapter *adapter;
78 struct zfcp_port *port;
83 down(&zfcp_data.config_sema);
85 adapter = dev_get_drvdata(dev);
86 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
91 wwpn = simple_strtoull(buf, &endp, 0);
92 if ((endp + 1) < (buf + count)) {
97 write_lock_irq(&zfcp_data.config_lock);
98 port = zfcp_get_port_by_wwpn(adapter, wwpn);
99 if (port && (atomic_read(&port->refcount) == 0)) {
101 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
102 list_move(&port->list, &adapter->port_remove_lh);
107 write_unlock_irq(&zfcp_data.config_lock);
114 zfcp_erp_port_shutdown(port, 0, 92, NULL);
115 zfcp_erp_wait(adapter);
117 zfcp_port_dequeue(port);
119 up(&zfcp_data.config_sema);
120 return retval ? retval : (ssize_t) count;
123 static DEVICE_ATTR(port_remove, S_IWUSR, NULL, zfcp_sysfs_port_remove_store);
126 * zfcp_sysfs_adapter_failed_store - failed state of adapter
127 * @dev: pointer to belonging device
128 * @buf: pointer to input buffer
129 * @count: number of bytes in buffer
131 * Store function of the "failed" attribute of an adapter.
132 * If a "0" gets written to "failed", error recovery will be
133 * started for the belonging adapter.
136 zfcp_sysfs_adapter_failed_store(struct device *dev, struct device_attribute *attr,
137 const char *buf, size_t count)
139 struct zfcp_adapter *adapter;
144 down(&zfcp_data.config_sema);
146 adapter = dev_get_drvdata(dev);
147 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
152 val = simple_strtoul(buf, &endp, 0);
153 if (((endp + 1) < (buf + count)) || (val != 0)) {
158 zfcp_erp_modify_adapter_status(adapter, 44, NULL,
159 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
160 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 93,
162 zfcp_erp_wait(adapter);
164 up(&zfcp_data.config_sema);
165 return retval ? retval : (ssize_t) count;
169 * zfcp_sysfs_adapter_failed_show - failed state of adapter
170 * @dev: pointer to belonging device
171 * @buf: pointer to input buffer
173 * Show function of "failed" attribute of adapter. Will be
174 * "0" if adapter is working, otherwise "1".
177 zfcp_sysfs_adapter_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
179 struct zfcp_adapter *adapter;
181 adapter = dev_get_drvdata(dev);
182 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status))
183 return sprintf(buf, "1\n");
185 return sprintf(buf, "0\n");
188 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_adapter_failed_show,
189 zfcp_sysfs_adapter_failed_store);
191 static struct attribute *zfcp_adapter_attrs[] = {
192 &dev_attr_failed.attr,
193 &dev_attr_in_recovery.attr,
194 &dev_attr_port_remove.attr,
195 &dev_attr_port_rescan.attr,
196 &dev_attr_peer_wwnn.attr,
197 &dev_attr_peer_wwpn.attr,
198 &dev_attr_peer_d_id.attr,
199 &dev_attr_card_version.attr,
200 &dev_attr_lic_version.attr,
201 &dev_attr_status.attr,
202 &dev_attr_hardware_version.attr,
206 static struct attribute_group zfcp_adapter_attr_group = {
207 .attrs = zfcp_adapter_attrs,
211 * zfcp_sysfs_create_adapter_files - create sysfs adapter files
212 * @dev: pointer to belonging device
214 * Create all attributes of the sysfs representation of an adapter.
217 zfcp_sysfs_adapter_create_files(struct device *dev)
219 return sysfs_create_group(&dev->kobj, &zfcp_adapter_attr_group);
223 * zfcp_sysfs_remove_adapter_files - remove sysfs adapter files
224 * @dev: pointer to belonging device
226 * Remove all attributes of the sysfs representation of an adapter.
229 zfcp_sysfs_adapter_remove_files(struct device *dev)
231 sysfs_remove_group(&dev->kobj, &zfcp_adapter_attr_group);