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