Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * zfcp device driver |
| 3 | * |
| 4 | * sysfs attributes. |
| 5 | * |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 6 | * Copyright IBM Corporation 2008, 2009 |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
Christof Schmitt | ecf39d4 | 2008-12-25 13:39:53 +0100 | [diff] [blame] | 9 | #define KMSG_COMPONENT "zfcp" |
| 10 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 11 | |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 12 | #include "zfcp_ext.h" |
| 13 | |
| 14 | #define ZFCP_DEV_ATTR(_feat, _name, _mode, _show, _store) \ |
| 15 | struct device_attribute dev_attr_##_feat##_##_name = __ATTR(_name, _mode,\ |
| 16 | _show, _store) |
| 17 | #define ZFCP_DEFINE_ATTR(_feat_def, _feat, _name, _format, _value) \ |
| 18 | static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev, \ |
| 19 | struct device_attribute *at,\ |
| 20 | char *buf) \ |
| 21 | { \ |
Christof Schmitt | 25458eb | 2009-11-24 16:54:02 +0100 | [diff] [blame] | 22 | struct _feat_def *_feat = container_of(dev, struct _feat_def, \ |
| 23 | sysfs_device); \ |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 24 | \ |
| 25 | return sprintf(buf, _format, _value); \ |
| 26 | } \ |
| 27 | static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO, \ |
| 28 | zfcp_sysfs_##_feat##_##_name##_show, NULL); |
| 29 | |
Swen Schillig | de3dc57 | 2009-11-24 16:54:00 +0100 | [diff] [blame] | 30 | #define ZFCP_DEFINE_A_ATTR(_name, _format, _value) \ |
| 31 | static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \ |
| 32 | struct device_attribute *at,\ |
| 33 | char *buf) \ |
| 34 | { \ |
| 35 | struct ccw_device *cdev = to_ccwdev(dev); \ |
| 36 | struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev); \ |
| 37 | int i; \ |
| 38 | \ |
| 39 | if (!adapter) \ |
| 40 | return -ENODEV; \ |
| 41 | \ |
| 42 | i = sprintf(buf, _format, _value); \ |
| 43 | zfcp_ccw_adapter_put(adapter); \ |
| 44 | return i; \ |
| 45 | } \ |
| 46 | static ZFCP_DEV_ATTR(adapter, _name, S_IRUGO, \ |
| 47 | zfcp_sysfs_adapter_##_name##_show, NULL); |
| 48 | |
| 49 | ZFCP_DEFINE_A_ATTR(status, "0x%08x\n", atomic_read(&adapter->status)); |
| 50 | ZFCP_DEFINE_A_ATTR(peer_wwnn, "0x%016llx\n", |
| 51 | (unsigned long long) adapter->peer_wwnn); |
| 52 | ZFCP_DEFINE_A_ATTR(peer_wwpn, "0x%016llx\n", |
| 53 | (unsigned long long) adapter->peer_wwpn); |
| 54 | ZFCP_DEFINE_A_ATTR(peer_d_id, "0x%06x\n", adapter->peer_d_id); |
| 55 | ZFCP_DEFINE_A_ATTR(card_version, "0x%04x\n", adapter->hydra_version); |
| 56 | ZFCP_DEFINE_A_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version); |
| 57 | ZFCP_DEFINE_A_ATTR(hardware_version, "0x%08x\n", adapter->hardware_version); |
| 58 | ZFCP_DEFINE_A_ATTR(in_recovery, "%d\n", (atomic_read(&adapter->status) & |
| 59 | ZFCP_STATUS_COMMON_ERP_INUSE) != 0); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 60 | |
| 61 | ZFCP_DEFINE_ATTR(zfcp_port, port, status, "0x%08x\n", |
| 62 | atomic_read(&port->status)); |
| 63 | ZFCP_DEFINE_ATTR(zfcp_port, port, in_recovery, "%d\n", |
| 64 | (atomic_read(&port->status) & |
| 65 | ZFCP_STATUS_COMMON_ERP_INUSE) != 0); |
| 66 | ZFCP_DEFINE_ATTR(zfcp_port, port, access_denied, "%d\n", |
| 67 | (atomic_read(&port->status) & |
| 68 | ZFCP_STATUS_COMMON_ACCESS_DENIED) != 0); |
| 69 | |
| 70 | ZFCP_DEFINE_ATTR(zfcp_unit, unit, status, "0x%08x\n", |
| 71 | atomic_read(&unit->status)); |
| 72 | ZFCP_DEFINE_ATTR(zfcp_unit, unit, in_recovery, "%d\n", |
| 73 | (atomic_read(&unit->status) & |
| 74 | ZFCP_STATUS_COMMON_ERP_INUSE) != 0); |
| 75 | ZFCP_DEFINE_ATTR(zfcp_unit, unit, access_denied, "%d\n", |
| 76 | (atomic_read(&unit->status) & |
| 77 | ZFCP_STATUS_COMMON_ACCESS_DENIED) != 0); |
| 78 | ZFCP_DEFINE_ATTR(zfcp_unit, unit, access_shared, "%d\n", |
| 79 | (atomic_read(&unit->status) & |
| 80 | ZFCP_STATUS_UNIT_SHARED) != 0); |
| 81 | ZFCP_DEFINE_ATTR(zfcp_unit, unit, access_readonly, "%d\n", |
| 82 | (atomic_read(&unit->status) & |
| 83 | ZFCP_STATUS_UNIT_READONLY) != 0); |
| 84 | |
| 85 | #define ZFCP_SYSFS_FAILED(_feat_def, _feat, _adapter, _mod_id, _reopen_id) \ |
| 86 | static ssize_t zfcp_sysfs_##_feat##_failed_show(struct device *dev, \ |
| 87 | struct device_attribute *attr, \ |
| 88 | char *buf) \ |
| 89 | { \ |
Christof Schmitt | 25458eb | 2009-11-24 16:54:02 +0100 | [diff] [blame] | 90 | struct _feat_def *_feat = container_of(dev, struct _feat_def, \ |
| 91 | sysfs_device); \ |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 92 | \ |
| 93 | if (atomic_read(&_feat->status) & ZFCP_STATUS_COMMON_ERP_FAILED) \ |
| 94 | return sprintf(buf, "1\n"); \ |
| 95 | else \ |
| 96 | return sprintf(buf, "0\n"); \ |
| 97 | } \ |
| 98 | static ssize_t zfcp_sysfs_##_feat##_failed_store(struct device *dev, \ |
| 99 | struct device_attribute *attr,\ |
| 100 | const char *buf, size_t count)\ |
| 101 | { \ |
Christof Schmitt | 25458eb | 2009-11-24 16:54:02 +0100 | [diff] [blame] | 102 | struct _feat_def *_feat = container_of(dev, struct _feat_def, \ |
| 103 | sysfs_device); \ |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 104 | unsigned long val; \ |
| 105 | int retval = 0; \ |
| 106 | \ |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 107 | if (!(_feat && get_device(&_feat->sysfs_device))) \ |
| 108 | return -EBUSY; \ |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 109 | \ |
| 110 | if (strict_strtoul(buf, 0, &val) || val != 0) { \ |
| 111 | retval = -EINVAL; \ |
| 112 | goto out; \ |
| 113 | } \ |
| 114 | \ |
| 115 | zfcp_erp_modify_##_feat##_status(_feat, _mod_id, NULL, \ |
| 116 | ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);\ |
| 117 | zfcp_erp_##_feat##_reopen(_feat, ZFCP_STATUS_COMMON_ERP_FAILED, \ |
| 118 | _reopen_id, NULL); \ |
| 119 | zfcp_erp_wait(_adapter); \ |
| 120 | out: \ |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 121 | put_device(&_feat->sysfs_device); \ |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 122 | return retval ? retval : (ssize_t) count; \ |
| 123 | } \ |
| 124 | static ZFCP_DEV_ATTR(_feat, failed, S_IWUSR | S_IRUGO, \ |
| 125 | zfcp_sysfs_##_feat##_failed_show, \ |
| 126 | zfcp_sysfs_##_feat##_failed_store); |
| 127 | |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 128 | ZFCP_SYSFS_FAILED(zfcp_port, port, port->adapter, "sypfai1", "sypfai2"); |
| 129 | ZFCP_SYSFS_FAILED(zfcp_unit, unit, unit->port->adapter, "syufai1", "syufai2"); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 130 | |
Swen Schillig | de3dc57 | 2009-11-24 16:54:00 +0100 | [diff] [blame] | 131 | static ssize_t zfcp_sysfs_adapter_failed_show(struct device *dev, |
| 132 | struct device_attribute *attr, |
| 133 | char *buf) |
| 134 | { |
| 135 | struct ccw_device *cdev = to_ccwdev(dev); |
| 136 | struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev); |
| 137 | int i; |
| 138 | |
| 139 | if (!adapter) |
| 140 | return -ENODEV; |
| 141 | |
| 142 | if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) |
| 143 | i = sprintf(buf, "1\n"); |
| 144 | else |
| 145 | i = sprintf(buf, "0\n"); |
| 146 | |
| 147 | zfcp_ccw_adapter_put(adapter); |
| 148 | return i; |
| 149 | } |
| 150 | |
| 151 | static ssize_t zfcp_sysfs_adapter_failed_store(struct device *dev, |
| 152 | struct device_attribute *attr, |
| 153 | const char *buf, size_t count) |
| 154 | { |
| 155 | struct ccw_device *cdev = to_ccwdev(dev); |
| 156 | struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev); |
| 157 | unsigned long val; |
| 158 | int retval = 0; |
| 159 | |
| 160 | if (!adapter) |
| 161 | return -ENODEV; |
| 162 | |
Swen Schillig | de3dc57 | 2009-11-24 16:54:00 +0100 | [diff] [blame] | 163 | if (strict_strtoul(buf, 0, &val) || val != 0) { |
| 164 | retval = -EINVAL; |
| 165 | goto out; |
| 166 | } |
| 167 | |
| 168 | zfcp_erp_modify_adapter_status(adapter, "syafai1", NULL, |
| 169 | ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET); |
| 170 | zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, |
| 171 | "syafai2", NULL); |
| 172 | zfcp_erp_wait(adapter); |
| 173 | out: |
| 174 | zfcp_ccw_adapter_put(adapter); |
| 175 | return retval ? retval : (ssize_t) count; |
| 176 | } |
| 177 | static ZFCP_DEV_ATTR(adapter, failed, S_IWUSR | S_IRUGO, |
| 178 | zfcp_sysfs_adapter_failed_show, |
| 179 | zfcp_sysfs_adapter_failed_store); |
| 180 | |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 181 | static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev, |
| 182 | struct device_attribute *attr, |
| 183 | const char *buf, size_t count) |
| 184 | { |
Swen Schillig | de3dc57 | 2009-11-24 16:54:00 +0100 | [diff] [blame] | 185 | struct ccw_device *cdev = to_ccwdev(dev); |
| 186 | struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 187 | |
Swen Schillig | de3dc57 | 2009-11-24 16:54:00 +0100 | [diff] [blame] | 188 | if (!adapter) |
| 189 | return -ENODEV; |
| 190 | |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame^] | 191 | /* sync the user-space- with the kernel-invocation of scan_work */ |
| 192 | queue_work(adapter->work_queue, &adapter->scan_work); |
| 193 | flush_work(&adapter->scan_work); |
Swen Schillig | de3dc57 | 2009-11-24 16:54:00 +0100 | [diff] [blame] | 194 | zfcp_ccw_adapter_put(adapter); |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 195 | |
Swen Schillig | 9eae07e | 2009-11-24 16:54:06 +0100 | [diff] [blame^] | 196 | return (ssize_t) count; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 197 | } |
| 198 | static ZFCP_DEV_ATTR(adapter, port_rescan, S_IWUSR, NULL, |
| 199 | zfcp_sysfs_port_rescan_store); |
| 200 | |
| 201 | static ssize_t zfcp_sysfs_port_remove_store(struct device *dev, |
| 202 | struct device_attribute *attr, |
| 203 | const char *buf, size_t count) |
| 204 | { |
Swen Schillig | de3dc57 | 2009-11-24 16:54:00 +0100 | [diff] [blame] | 205 | struct ccw_device *cdev = to_ccwdev(dev); |
| 206 | struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 207 | struct zfcp_port *port; |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 208 | u64 wwpn; |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 209 | int retval = -EINVAL; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 210 | |
Swen Schillig | de3dc57 | 2009-11-24 16:54:00 +0100 | [diff] [blame] | 211 | if (!adapter) |
| 212 | return -ENODEV; |
| 213 | |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 214 | if (strict_strtoull(buf, 0, (unsigned long long *) &wwpn)) |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 215 | goto out; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 216 | |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 217 | port = zfcp_get_port_by_wwpn(adapter, wwpn); |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 218 | if (!port) |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 219 | goto out; |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 220 | else |
| 221 | retval = 0; |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 222 | |
| 223 | write_lock_irq(&adapter->port_list_lock); |
| 224 | list_del(&port->list); |
| 225 | write_unlock_irq(&adapter->port_list_lock); |
| 226 | |
| 227 | put_device(&port->sysfs_device); |
| 228 | |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 229 | zfcp_erp_port_shutdown(port, 0, "syprs_1", NULL); |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 230 | zfcp_device_unregister(&port->sysfs_device, &zfcp_sysfs_port_attrs); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 231 | out: |
Swen Schillig | de3dc57 | 2009-11-24 16:54:00 +0100 | [diff] [blame] | 232 | zfcp_ccw_adapter_put(adapter); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 233 | return retval ? retval : (ssize_t) count; |
| 234 | } |
| 235 | static ZFCP_DEV_ATTR(adapter, port_remove, S_IWUSR, NULL, |
| 236 | zfcp_sysfs_port_remove_store); |
| 237 | |
| 238 | static struct attribute *zfcp_adapter_attrs[] = { |
| 239 | &dev_attr_adapter_failed.attr, |
| 240 | &dev_attr_adapter_in_recovery.attr, |
| 241 | &dev_attr_adapter_port_remove.attr, |
| 242 | &dev_attr_adapter_port_rescan.attr, |
| 243 | &dev_attr_adapter_peer_wwnn.attr, |
| 244 | &dev_attr_adapter_peer_wwpn.attr, |
| 245 | &dev_attr_adapter_peer_d_id.attr, |
| 246 | &dev_attr_adapter_card_version.attr, |
| 247 | &dev_attr_adapter_lic_version.attr, |
| 248 | &dev_attr_adapter_status.attr, |
| 249 | &dev_attr_adapter_hardware_version.attr, |
| 250 | NULL |
| 251 | }; |
| 252 | |
| 253 | struct attribute_group zfcp_sysfs_adapter_attrs = { |
| 254 | .attrs = zfcp_adapter_attrs, |
| 255 | }; |
| 256 | |
| 257 | static ssize_t zfcp_sysfs_unit_add_store(struct device *dev, |
| 258 | struct device_attribute *attr, |
| 259 | const char *buf, size_t count) |
| 260 | { |
Christof Schmitt | 25458eb | 2009-11-24 16:54:02 +0100 | [diff] [blame] | 261 | struct zfcp_port *port = container_of(dev, struct zfcp_port, |
| 262 | sysfs_device); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 263 | struct zfcp_unit *unit; |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 264 | u64 fcp_lun; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 265 | int retval = -EINVAL; |
| 266 | |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 267 | if (!(port && get_device(&port->sysfs_device))) |
| 268 | return -EBUSY; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 269 | |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 270 | if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun)) |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 271 | goto out; |
| 272 | |
| 273 | unit = zfcp_unit_enqueue(port, fcp_lun); |
| 274 | if (IS_ERR(unit)) |
| 275 | goto out; |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 276 | else |
| 277 | retval = 0; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 278 | |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 279 | zfcp_erp_unit_reopen(unit, 0, "syuas_1", NULL); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 280 | zfcp_erp_wait(unit->port->adapter); |
Christof Schmitt | 9e820af | 2009-10-13 10:44:11 +0200 | [diff] [blame] | 281 | flush_work(&unit->scsi_work); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 282 | out: |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 283 | put_device(&port->sysfs_device); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 284 | return retval ? retval : (ssize_t) count; |
| 285 | } |
| 286 | static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store); |
| 287 | |
| 288 | static ssize_t zfcp_sysfs_unit_remove_store(struct device *dev, |
| 289 | struct device_attribute *attr, |
| 290 | const char *buf, size_t count) |
| 291 | { |
Christof Schmitt | 25458eb | 2009-11-24 16:54:02 +0100 | [diff] [blame] | 292 | struct zfcp_port *port = container_of(dev, struct zfcp_port, |
| 293 | sysfs_device); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 294 | struct zfcp_unit *unit; |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 295 | u64 fcp_lun; |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 296 | int retval = -EINVAL; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 297 | |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 298 | if (!(port && get_device(&port->sysfs_device))) |
| 299 | return -EBUSY; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 300 | |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 301 | if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun)) |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 302 | goto out; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 303 | |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 304 | unit = zfcp_get_unit_by_lun(port, fcp_lun); |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 305 | if (!unit) |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 306 | goto out; |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 307 | else |
| 308 | retval = 0; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 309 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 310 | /* wait for possible timeout during SCSI probe */ |
| 311 | flush_work(&unit->scsi_work); |
| 312 | |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 313 | write_lock_irq(&port->unit_list_lock); |
| 314 | list_del(&unit->list); |
| 315 | write_unlock_irq(&port->unit_list_lock); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame] | 316 | |
Swen Schillig | f3450c7 | 2009-11-24 16:53:59 +0100 | [diff] [blame] | 317 | put_device(&unit->sysfs_device); |
| 318 | |
| 319 | zfcp_erp_unit_shutdown(unit, 0, "syurs_1", NULL); |
| 320 | zfcp_device_unregister(&unit->sysfs_device, &zfcp_sysfs_unit_attrs); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 321 | out: |
Swen Schillig | 6b18333 | 2009-11-24 16:54:05 +0100 | [diff] [blame] | 322 | put_device(&port->sysfs_device); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 323 | return retval ? retval : (ssize_t) count; |
| 324 | } |
| 325 | static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store); |
| 326 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 327 | static struct attribute *zfcp_port_attrs[] = { |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 328 | &dev_attr_unit_add.attr, |
| 329 | &dev_attr_unit_remove.attr, |
| 330 | &dev_attr_port_failed.attr, |
| 331 | &dev_attr_port_in_recovery.attr, |
| 332 | &dev_attr_port_status.attr, |
| 333 | &dev_attr_port_access_denied.attr, |
| 334 | NULL |
| 335 | }; |
| 336 | |
| 337 | /** |
| 338 | * zfcp_sysfs_port_attrs - sysfs attributes for all other ports |
| 339 | */ |
| 340 | struct attribute_group zfcp_sysfs_port_attrs = { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 341 | .attrs = zfcp_port_attrs, |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 342 | }; |
| 343 | |
| 344 | static struct attribute *zfcp_unit_attrs[] = { |
| 345 | &dev_attr_unit_failed.attr, |
| 346 | &dev_attr_unit_in_recovery.attr, |
| 347 | &dev_attr_unit_status.attr, |
| 348 | &dev_attr_unit_access_denied.attr, |
| 349 | &dev_attr_unit_access_shared.attr, |
| 350 | &dev_attr_unit_access_readonly.attr, |
| 351 | NULL |
| 352 | }; |
| 353 | |
| 354 | struct attribute_group zfcp_sysfs_unit_attrs = { |
| 355 | .attrs = zfcp_unit_attrs, |
| 356 | }; |
| 357 | |
| 358 | #define ZFCP_DEFINE_LATENCY_ATTR(_name) \ |
| 359 | static ssize_t \ |
| 360 | zfcp_sysfs_unit_##_name##_latency_show(struct device *dev, \ |
| 361 | struct device_attribute *attr, \ |
| 362 | char *buf) { \ |
| 363 | struct scsi_device *sdev = to_scsi_device(dev); \ |
| 364 | struct zfcp_unit *unit = sdev->hostdata; \ |
| 365 | struct zfcp_latencies *lat = &unit->latencies; \ |
| 366 | struct zfcp_adapter *adapter = unit->port->adapter; \ |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 367 | unsigned long long fsum, fmin, fmax, csum, cmin, cmax, cc; \ |
| 368 | \ |
Christof Schmitt | 49f0f01 | 2009-03-02 13:08:57 +0100 | [diff] [blame] | 369 | spin_lock_bh(&lat->lock); \ |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 370 | fsum = lat->_name.fabric.sum * adapter->timer_ticks; \ |
| 371 | fmin = lat->_name.fabric.min * adapter->timer_ticks; \ |
| 372 | fmax = lat->_name.fabric.max * adapter->timer_ticks; \ |
| 373 | csum = lat->_name.channel.sum * adapter->timer_ticks; \ |
| 374 | cmin = lat->_name.channel.min * adapter->timer_ticks; \ |
| 375 | cmax = lat->_name.channel.max * adapter->timer_ticks; \ |
| 376 | cc = lat->_name.counter; \ |
Christof Schmitt | 49f0f01 | 2009-03-02 13:08:57 +0100 | [diff] [blame] | 377 | spin_unlock_bh(&lat->lock); \ |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 378 | \ |
| 379 | do_div(fsum, 1000); \ |
| 380 | do_div(fmin, 1000); \ |
| 381 | do_div(fmax, 1000); \ |
| 382 | do_div(csum, 1000); \ |
| 383 | do_div(cmin, 1000); \ |
| 384 | do_div(cmax, 1000); \ |
| 385 | \ |
| 386 | return sprintf(buf, "%llu %llu %llu %llu %llu %llu %llu\n", \ |
| 387 | fmin, fmax, fsum, cmin, cmax, csum, cc); \ |
| 388 | } \ |
| 389 | static ssize_t \ |
| 390 | zfcp_sysfs_unit_##_name##_latency_store(struct device *dev, \ |
| 391 | struct device_attribute *attr, \ |
| 392 | const char *buf, size_t count) \ |
| 393 | { \ |
| 394 | struct scsi_device *sdev = to_scsi_device(dev); \ |
| 395 | struct zfcp_unit *unit = sdev->hostdata; \ |
| 396 | struct zfcp_latencies *lat = &unit->latencies; \ |
| 397 | unsigned long flags; \ |
| 398 | \ |
| 399 | spin_lock_irqsave(&lat->lock, flags); \ |
| 400 | lat->_name.fabric.sum = 0; \ |
| 401 | lat->_name.fabric.min = 0xFFFFFFFF; \ |
| 402 | lat->_name.fabric.max = 0; \ |
| 403 | lat->_name.channel.sum = 0; \ |
| 404 | lat->_name.channel.min = 0xFFFFFFFF; \ |
| 405 | lat->_name.channel.max = 0; \ |
| 406 | lat->_name.counter = 0; \ |
| 407 | spin_unlock_irqrestore(&lat->lock, flags); \ |
| 408 | \ |
| 409 | return (ssize_t) count; \ |
| 410 | } \ |
| 411 | static DEVICE_ATTR(_name##_latency, S_IWUSR | S_IRUGO, \ |
| 412 | zfcp_sysfs_unit_##_name##_latency_show, \ |
| 413 | zfcp_sysfs_unit_##_name##_latency_store); |
| 414 | |
| 415 | ZFCP_DEFINE_LATENCY_ATTR(read); |
| 416 | ZFCP_DEFINE_LATENCY_ATTR(write); |
| 417 | ZFCP_DEFINE_LATENCY_ATTR(cmd); |
| 418 | |
| 419 | #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \ |
| 420 | static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \ |
| 421 | struct device_attribute *attr,\ |
| 422 | char *buf) \ |
| 423 | { \ |
| 424 | struct scsi_device *sdev = to_scsi_device(dev); \ |
| 425 | struct zfcp_unit *unit = sdev->hostdata; \ |
| 426 | \ |
| 427 | return sprintf(buf, _format, _value); \ |
| 428 | } \ |
| 429 | static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL); |
| 430 | |
| 431 | ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", |
Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 432 | dev_name(&unit->port->adapter->ccw_device->dev)); |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 433 | ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", |
| 434 | (unsigned long long) unit->port->wwpn); |
| 435 | ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", |
| 436 | (unsigned long long) unit->fcp_lun); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 437 | |
| 438 | struct device_attribute *zfcp_sysfs_sdev_attrs[] = { |
| 439 | &dev_attr_fcp_lun, |
| 440 | &dev_attr_wwpn, |
| 441 | &dev_attr_hba_id, |
| 442 | &dev_attr_read_latency, |
| 443 | &dev_attr_write_latency, |
| 444 | &dev_attr_cmd_latency, |
| 445 | NULL |
| 446 | }; |
| 447 | |
| 448 | static ssize_t zfcp_sysfs_adapter_util_show(struct device *dev, |
| 449 | struct device_attribute *attr, |
| 450 | char *buf) |
| 451 | { |
| 452 | struct Scsi_Host *scsi_host = dev_to_shost(dev); |
| 453 | struct fsf_qtcb_bottom_port *qtcb_port; |
| 454 | struct zfcp_adapter *adapter; |
| 455 | int retval; |
| 456 | |
| 457 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; |
| 458 | if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)) |
| 459 | return -EOPNOTSUPP; |
| 460 | |
| 461 | qtcb_port = kzalloc(sizeof(struct fsf_qtcb_bottom_port), GFP_KERNEL); |
| 462 | if (!qtcb_port) |
| 463 | return -ENOMEM; |
| 464 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 465 | retval = zfcp_fsf_exchange_port_data_sync(adapter->qdio, qtcb_port); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 466 | if (!retval) |
| 467 | retval = sprintf(buf, "%u %u %u\n", qtcb_port->cp_util, |
| 468 | qtcb_port->cb_util, qtcb_port->a_util); |
| 469 | kfree(qtcb_port); |
| 470 | return retval; |
| 471 | } |
| 472 | static DEVICE_ATTR(utilization, S_IRUGO, zfcp_sysfs_adapter_util_show, NULL); |
| 473 | |
| 474 | static int zfcp_sysfs_adapter_ex_config(struct device *dev, |
| 475 | struct fsf_statistics_info *stat_inf) |
| 476 | { |
| 477 | struct Scsi_Host *scsi_host = dev_to_shost(dev); |
| 478 | struct fsf_qtcb_bottom_config *qtcb_config; |
| 479 | struct zfcp_adapter *adapter; |
| 480 | int retval; |
| 481 | |
| 482 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; |
| 483 | if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)) |
| 484 | return -EOPNOTSUPP; |
| 485 | |
| 486 | qtcb_config = kzalloc(sizeof(struct fsf_qtcb_bottom_config), |
| 487 | GFP_KERNEL); |
| 488 | if (!qtcb_config) |
| 489 | return -ENOMEM; |
| 490 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 491 | retval = zfcp_fsf_exchange_config_data_sync(adapter->qdio, qtcb_config); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 492 | if (!retval) |
| 493 | *stat_inf = qtcb_config->stat_info; |
| 494 | |
| 495 | kfree(qtcb_config); |
| 496 | return retval; |
| 497 | } |
| 498 | |
| 499 | #define ZFCP_SHOST_ATTR(_name, _format, _arg...) \ |
| 500 | static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \ |
| 501 | struct device_attribute *attr,\ |
| 502 | char *buf) \ |
| 503 | { \ |
| 504 | struct fsf_statistics_info stat_info; \ |
| 505 | int retval; \ |
| 506 | \ |
| 507 | retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info); \ |
| 508 | if (retval) \ |
| 509 | return retval; \ |
| 510 | \ |
| 511 | return sprintf(buf, _format, ## _arg); \ |
| 512 | } \ |
| 513 | static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL); |
| 514 | |
| 515 | ZFCP_SHOST_ATTR(requests, "%llu %llu %llu\n", |
| 516 | (unsigned long long) stat_info.input_req, |
| 517 | (unsigned long long) stat_info.output_req, |
| 518 | (unsigned long long) stat_info.control_req); |
| 519 | |
| 520 | ZFCP_SHOST_ATTR(megabytes, "%llu %llu\n", |
| 521 | (unsigned long long) stat_info.input_mb, |
| 522 | (unsigned long long) stat_info.output_mb); |
| 523 | |
| 524 | ZFCP_SHOST_ATTR(seconds_active, "%llu\n", |
| 525 | (unsigned long long) stat_info.seconds_act); |
| 526 | |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 527 | static ssize_t zfcp_sysfs_adapter_q_full_show(struct device *dev, |
| 528 | struct device_attribute *attr, |
| 529 | char *buf) |
| 530 | { |
| 531 | struct Scsi_Host *scsi_host = class_to_shost(dev); |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 532 | struct zfcp_qdio *qdio = |
| 533 | ((struct zfcp_adapter *) scsi_host->hostdata[0])->qdio; |
Christof Schmitt | acf7b86 | 2009-07-13 15:06:03 +0200 | [diff] [blame] | 534 | u64 util; |
| 535 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 536 | spin_lock_bh(&qdio->stat_lock); |
| 537 | util = qdio->req_q_util; |
| 538 | spin_unlock_bh(&qdio->stat_lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 539 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 540 | return sprintf(buf, "%d %llu\n", atomic_read(&qdio->req_q_full), |
Christof Schmitt | acf7b86 | 2009-07-13 15:06:03 +0200 | [diff] [blame] | 541 | (unsigned long long)util); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 542 | } |
| 543 | static DEVICE_ATTR(queue_full, S_IRUGO, zfcp_sysfs_adapter_q_full_show, NULL); |
| 544 | |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 545 | struct device_attribute *zfcp_sysfs_shost_attrs[] = { |
| 546 | &dev_attr_utilization, |
| 547 | &dev_attr_requests, |
| 548 | &dev_attr_megabytes, |
| 549 | &dev_attr_seconds_active, |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 550 | &dev_attr_queue_full, |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 551 | NULL |
| 552 | }; |