Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * zfcp device driver |
| 3 | * |
| 4 | * sysfs attributes. |
| 5 | * |
| 6 | * Copyright IBM Corporation 2008 |
| 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; |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 143 | LIST_HEAD(port_remove_lh); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 144 | |
Christof Schmitt | 24680de | 2009-08-18 15:43:28 +0200 | [diff] [blame] | 145 | mutex_lock(&zfcp_data.config_mutex); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 146 | if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_REMOVE) { |
| 147 | retval = -EBUSY; |
| 148 | goto out; |
| 149 | } |
| 150 | |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 151 | if (strict_strtoull(buf, 0, (unsigned long long *) &wwpn)) { |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 152 | retval = -EINVAL; |
| 153 | goto out; |
| 154 | } |
| 155 | |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 156 | port = zfcp_get_port_by_wwpn(adapter, wwpn); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 157 | if (port && (atomic_read(&port->refcount) == 1)) { |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 158 | atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 159 | write_lock_irq(&adapter->port_list_lock); |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 160 | list_move(&port->list, &port_remove_lh); |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 161 | write_unlock_irq(&adapter->port_list_lock); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 162 | } else |
| 163 | port = NULL; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 164 | |
| 165 | if (!port) { |
| 166 | retval = -ENXIO; |
| 167 | goto out; |
| 168 | } |
| 169 | |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 170 | zfcp_erp_port_shutdown(port, 0, "syprs_1", NULL); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 171 | zfcp_erp_wait(adapter); |
| 172 | zfcp_port_put(port); |
| 173 | zfcp_port_dequeue(port); |
| 174 | out: |
Christof Schmitt | 24680de | 2009-08-18 15:43:28 +0200 | [diff] [blame] | 175 | mutex_unlock(&zfcp_data.config_mutex); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 176 | return retval ? retval : (ssize_t) count; |
| 177 | } |
| 178 | static ZFCP_DEV_ATTR(adapter, port_remove, S_IWUSR, NULL, |
| 179 | zfcp_sysfs_port_remove_store); |
| 180 | |
| 181 | static struct attribute *zfcp_adapter_attrs[] = { |
| 182 | &dev_attr_adapter_failed.attr, |
| 183 | &dev_attr_adapter_in_recovery.attr, |
| 184 | &dev_attr_adapter_port_remove.attr, |
| 185 | &dev_attr_adapter_port_rescan.attr, |
| 186 | &dev_attr_adapter_peer_wwnn.attr, |
| 187 | &dev_attr_adapter_peer_wwpn.attr, |
| 188 | &dev_attr_adapter_peer_d_id.attr, |
| 189 | &dev_attr_adapter_card_version.attr, |
| 190 | &dev_attr_adapter_lic_version.attr, |
| 191 | &dev_attr_adapter_status.attr, |
| 192 | &dev_attr_adapter_hardware_version.attr, |
| 193 | NULL |
| 194 | }; |
| 195 | |
| 196 | struct attribute_group zfcp_sysfs_adapter_attrs = { |
| 197 | .attrs = zfcp_adapter_attrs, |
| 198 | }; |
| 199 | |
| 200 | static ssize_t zfcp_sysfs_unit_add_store(struct device *dev, |
| 201 | struct device_attribute *attr, |
| 202 | const char *buf, size_t count) |
| 203 | { |
| 204 | struct zfcp_port *port = dev_get_drvdata(dev); |
| 205 | struct zfcp_unit *unit; |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 206 | u64 fcp_lun; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 207 | int retval = -EINVAL; |
| 208 | |
Christof Schmitt | 24680de | 2009-08-18 15:43:28 +0200 | [diff] [blame] | 209 | mutex_lock(&zfcp_data.config_mutex); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 210 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_REMOVE) { |
| 211 | retval = -EBUSY; |
| 212 | goto out; |
| 213 | } |
| 214 | |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 215 | if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun)) |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 216 | goto out; |
| 217 | |
| 218 | unit = zfcp_unit_enqueue(port, fcp_lun); |
| 219 | if (IS_ERR(unit)) |
| 220 | goto out; |
| 221 | |
| 222 | retval = 0; |
| 223 | |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 224 | zfcp_erp_unit_reopen(unit, 0, "syuas_1", NULL); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 225 | zfcp_erp_wait(unit->port->adapter); |
Christof Schmitt | 9e820af | 2009-10-13 10:44:11 +0200 | [diff] [blame] | 226 | flush_work(&unit->scsi_work); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 227 | zfcp_unit_put(unit); |
| 228 | out: |
Christof Schmitt | 24680de | 2009-08-18 15:43:28 +0200 | [diff] [blame] | 229 | mutex_unlock(&zfcp_data.config_mutex); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 230 | return retval ? retval : (ssize_t) count; |
| 231 | } |
| 232 | static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store); |
| 233 | |
| 234 | static ssize_t zfcp_sysfs_unit_remove_store(struct device *dev, |
| 235 | struct device_attribute *attr, |
| 236 | const char *buf, size_t count) |
| 237 | { |
| 238 | struct zfcp_port *port = dev_get_drvdata(dev); |
| 239 | struct zfcp_unit *unit; |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 240 | u64 fcp_lun; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 241 | int retval = 0; |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 242 | LIST_HEAD(unit_remove_lh); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 243 | |
Christof Schmitt | 24680de | 2009-08-18 15:43:28 +0200 | [diff] [blame] | 244 | mutex_lock(&zfcp_data.config_mutex); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 245 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_REMOVE) { |
| 246 | retval = -EBUSY; |
| 247 | goto out; |
| 248 | } |
| 249 | |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 250 | if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun)) { |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 251 | retval = -EINVAL; |
| 252 | goto out; |
| 253 | } |
| 254 | |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 255 | unit = zfcp_get_unit_by_lun(port, fcp_lun); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 256 | if (!unit) { |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 257 | retval = -EINVAL; |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 258 | goto out; |
| 259 | } |
| 260 | |
Swen Schillig | ecf0c77 | 2009-11-24 16:53:58 +0100 | [diff] [blame^] | 261 | /* wait for possible timeout during SCSI probe */ |
| 262 | flush_work(&unit->scsi_work); |
| 263 | |
| 264 | if (atomic_read(&unit->refcount) == 1) { |
| 265 | atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status); |
| 266 | |
| 267 | write_lock_irq(&port->unit_list_lock); |
| 268 | list_move(&unit->list, &unit_remove_lh); |
| 269 | write_unlock_irq(&port->unit_list_lock); |
| 270 | |
| 271 | zfcp_erp_unit_shutdown(unit, 0, "syurs_1", NULL); |
| 272 | zfcp_erp_wait(unit->port->adapter); |
| 273 | zfcp_unit_put(unit); |
| 274 | zfcp_unit_dequeue(unit); |
| 275 | } else |
| 276 | zfcp_unit_put(unit); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 277 | out: |
Christof Schmitt | 24680de | 2009-08-18 15:43:28 +0200 | [diff] [blame] | 278 | mutex_unlock(&zfcp_data.config_mutex); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 279 | return retval ? retval : (ssize_t) count; |
| 280 | } |
| 281 | static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store); |
| 282 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 283 | static struct attribute *zfcp_port_attrs[] = { |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 284 | &dev_attr_unit_add.attr, |
| 285 | &dev_attr_unit_remove.attr, |
| 286 | &dev_attr_port_failed.attr, |
| 287 | &dev_attr_port_in_recovery.attr, |
| 288 | &dev_attr_port_status.attr, |
| 289 | &dev_attr_port_access_denied.attr, |
| 290 | NULL |
| 291 | }; |
| 292 | |
| 293 | /** |
| 294 | * zfcp_sysfs_port_attrs - sysfs attributes for all other ports |
| 295 | */ |
| 296 | struct attribute_group zfcp_sysfs_port_attrs = { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 297 | .attrs = zfcp_port_attrs, |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | static struct attribute *zfcp_unit_attrs[] = { |
| 301 | &dev_attr_unit_failed.attr, |
| 302 | &dev_attr_unit_in_recovery.attr, |
| 303 | &dev_attr_unit_status.attr, |
| 304 | &dev_attr_unit_access_denied.attr, |
| 305 | &dev_attr_unit_access_shared.attr, |
| 306 | &dev_attr_unit_access_readonly.attr, |
| 307 | NULL |
| 308 | }; |
| 309 | |
| 310 | struct attribute_group zfcp_sysfs_unit_attrs = { |
| 311 | .attrs = zfcp_unit_attrs, |
| 312 | }; |
| 313 | |
| 314 | #define ZFCP_DEFINE_LATENCY_ATTR(_name) \ |
| 315 | static ssize_t \ |
| 316 | zfcp_sysfs_unit_##_name##_latency_show(struct device *dev, \ |
| 317 | struct device_attribute *attr, \ |
| 318 | char *buf) { \ |
| 319 | struct scsi_device *sdev = to_scsi_device(dev); \ |
| 320 | struct zfcp_unit *unit = sdev->hostdata; \ |
| 321 | struct zfcp_latencies *lat = &unit->latencies; \ |
| 322 | struct zfcp_adapter *adapter = unit->port->adapter; \ |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 323 | unsigned long long fsum, fmin, fmax, csum, cmin, cmax, cc; \ |
| 324 | \ |
Christof Schmitt | 49f0f01 | 2009-03-02 13:08:57 +0100 | [diff] [blame] | 325 | spin_lock_bh(&lat->lock); \ |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 326 | fsum = lat->_name.fabric.sum * adapter->timer_ticks; \ |
| 327 | fmin = lat->_name.fabric.min * adapter->timer_ticks; \ |
| 328 | fmax = lat->_name.fabric.max * adapter->timer_ticks; \ |
| 329 | csum = lat->_name.channel.sum * adapter->timer_ticks; \ |
| 330 | cmin = lat->_name.channel.min * adapter->timer_ticks; \ |
| 331 | cmax = lat->_name.channel.max * adapter->timer_ticks; \ |
| 332 | cc = lat->_name.counter; \ |
Christof Schmitt | 49f0f01 | 2009-03-02 13:08:57 +0100 | [diff] [blame] | 333 | spin_unlock_bh(&lat->lock); \ |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 334 | \ |
| 335 | do_div(fsum, 1000); \ |
| 336 | do_div(fmin, 1000); \ |
| 337 | do_div(fmax, 1000); \ |
| 338 | do_div(csum, 1000); \ |
| 339 | do_div(cmin, 1000); \ |
| 340 | do_div(cmax, 1000); \ |
| 341 | \ |
| 342 | return sprintf(buf, "%llu %llu %llu %llu %llu %llu %llu\n", \ |
| 343 | fmin, fmax, fsum, cmin, cmax, csum, cc); \ |
| 344 | } \ |
| 345 | static ssize_t \ |
| 346 | zfcp_sysfs_unit_##_name##_latency_store(struct device *dev, \ |
| 347 | struct device_attribute *attr, \ |
| 348 | const char *buf, size_t count) \ |
| 349 | { \ |
| 350 | struct scsi_device *sdev = to_scsi_device(dev); \ |
| 351 | struct zfcp_unit *unit = sdev->hostdata; \ |
| 352 | struct zfcp_latencies *lat = &unit->latencies; \ |
| 353 | unsigned long flags; \ |
| 354 | \ |
| 355 | spin_lock_irqsave(&lat->lock, flags); \ |
| 356 | lat->_name.fabric.sum = 0; \ |
| 357 | lat->_name.fabric.min = 0xFFFFFFFF; \ |
| 358 | lat->_name.fabric.max = 0; \ |
| 359 | lat->_name.channel.sum = 0; \ |
| 360 | lat->_name.channel.min = 0xFFFFFFFF; \ |
| 361 | lat->_name.channel.max = 0; \ |
| 362 | lat->_name.counter = 0; \ |
| 363 | spin_unlock_irqrestore(&lat->lock, flags); \ |
| 364 | \ |
| 365 | return (ssize_t) count; \ |
| 366 | } \ |
| 367 | static DEVICE_ATTR(_name##_latency, S_IWUSR | S_IRUGO, \ |
| 368 | zfcp_sysfs_unit_##_name##_latency_show, \ |
| 369 | zfcp_sysfs_unit_##_name##_latency_store); |
| 370 | |
| 371 | ZFCP_DEFINE_LATENCY_ATTR(read); |
| 372 | ZFCP_DEFINE_LATENCY_ATTR(write); |
| 373 | ZFCP_DEFINE_LATENCY_ATTR(cmd); |
| 374 | |
| 375 | #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \ |
| 376 | static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \ |
| 377 | struct device_attribute *attr,\ |
| 378 | char *buf) \ |
| 379 | { \ |
| 380 | struct scsi_device *sdev = to_scsi_device(dev); \ |
| 381 | struct zfcp_unit *unit = sdev->hostdata; \ |
| 382 | \ |
| 383 | return sprintf(buf, _format, _value); \ |
| 384 | } \ |
| 385 | static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL); |
| 386 | |
| 387 | ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", |
Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 388 | dev_name(&unit->port->adapter->ccw_device->dev)); |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 389 | ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", |
| 390 | (unsigned long long) unit->port->wwpn); |
| 391 | ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", |
| 392 | (unsigned long long) unit->fcp_lun); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 393 | |
| 394 | struct device_attribute *zfcp_sysfs_sdev_attrs[] = { |
| 395 | &dev_attr_fcp_lun, |
| 396 | &dev_attr_wwpn, |
| 397 | &dev_attr_hba_id, |
| 398 | &dev_attr_read_latency, |
| 399 | &dev_attr_write_latency, |
| 400 | &dev_attr_cmd_latency, |
| 401 | NULL |
| 402 | }; |
| 403 | |
| 404 | static ssize_t zfcp_sysfs_adapter_util_show(struct device *dev, |
| 405 | struct device_attribute *attr, |
| 406 | char *buf) |
| 407 | { |
| 408 | struct Scsi_Host *scsi_host = dev_to_shost(dev); |
| 409 | struct fsf_qtcb_bottom_port *qtcb_port; |
| 410 | struct zfcp_adapter *adapter; |
| 411 | int retval; |
| 412 | |
| 413 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; |
| 414 | if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)) |
| 415 | return -EOPNOTSUPP; |
| 416 | |
| 417 | qtcb_port = kzalloc(sizeof(struct fsf_qtcb_bottom_port), GFP_KERNEL); |
| 418 | if (!qtcb_port) |
| 419 | return -ENOMEM; |
| 420 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 421 | retval = zfcp_fsf_exchange_port_data_sync(adapter->qdio, qtcb_port); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 422 | if (!retval) |
| 423 | retval = sprintf(buf, "%u %u %u\n", qtcb_port->cp_util, |
| 424 | qtcb_port->cb_util, qtcb_port->a_util); |
| 425 | kfree(qtcb_port); |
| 426 | return retval; |
| 427 | } |
| 428 | static DEVICE_ATTR(utilization, S_IRUGO, zfcp_sysfs_adapter_util_show, NULL); |
| 429 | |
| 430 | static int zfcp_sysfs_adapter_ex_config(struct device *dev, |
| 431 | struct fsf_statistics_info *stat_inf) |
| 432 | { |
| 433 | struct Scsi_Host *scsi_host = dev_to_shost(dev); |
| 434 | struct fsf_qtcb_bottom_config *qtcb_config; |
| 435 | struct zfcp_adapter *adapter; |
| 436 | int retval; |
| 437 | |
| 438 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; |
| 439 | if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)) |
| 440 | return -EOPNOTSUPP; |
| 441 | |
| 442 | qtcb_config = kzalloc(sizeof(struct fsf_qtcb_bottom_config), |
| 443 | GFP_KERNEL); |
| 444 | if (!qtcb_config) |
| 445 | return -ENOMEM; |
| 446 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 447 | retval = zfcp_fsf_exchange_config_data_sync(adapter->qdio, qtcb_config); |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 448 | if (!retval) |
| 449 | *stat_inf = qtcb_config->stat_info; |
| 450 | |
| 451 | kfree(qtcb_config); |
| 452 | return retval; |
| 453 | } |
| 454 | |
| 455 | #define ZFCP_SHOST_ATTR(_name, _format, _arg...) \ |
| 456 | static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \ |
| 457 | struct device_attribute *attr,\ |
| 458 | char *buf) \ |
| 459 | { \ |
| 460 | struct fsf_statistics_info stat_info; \ |
| 461 | int retval; \ |
| 462 | \ |
| 463 | retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info); \ |
| 464 | if (retval) \ |
| 465 | return retval; \ |
| 466 | \ |
| 467 | return sprintf(buf, _format, ## _arg); \ |
| 468 | } \ |
| 469 | static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL); |
| 470 | |
| 471 | ZFCP_SHOST_ATTR(requests, "%llu %llu %llu\n", |
| 472 | (unsigned long long) stat_info.input_req, |
| 473 | (unsigned long long) stat_info.output_req, |
| 474 | (unsigned long long) stat_info.control_req); |
| 475 | |
| 476 | ZFCP_SHOST_ATTR(megabytes, "%llu %llu\n", |
| 477 | (unsigned long long) stat_info.input_mb, |
| 478 | (unsigned long long) stat_info.output_mb); |
| 479 | |
| 480 | ZFCP_SHOST_ATTR(seconds_active, "%llu\n", |
| 481 | (unsigned long long) stat_info.seconds_act); |
| 482 | |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 483 | static ssize_t zfcp_sysfs_adapter_q_full_show(struct device *dev, |
| 484 | struct device_attribute *attr, |
| 485 | char *buf) |
| 486 | { |
| 487 | struct Scsi_Host *scsi_host = class_to_shost(dev); |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 488 | struct zfcp_qdio *qdio = |
| 489 | ((struct zfcp_adapter *) scsi_host->hostdata[0])->qdio; |
Christof Schmitt | acf7b86 | 2009-07-13 15:06:03 +0200 | [diff] [blame] | 490 | u64 util; |
| 491 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 492 | spin_lock_bh(&qdio->stat_lock); |
| 493 | util = qdio->req_q_util; |
| 494 | spin_unlock_bh(&qdio->stat_lock); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 495 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 496 | return sprintf(buf, "%d %llu\n", atomic_read(&qdio->req_q_full), |
Christof Schmitt | acf7b86 | 2009-07-13 15:06:03 +0200 | [diff] [blame] | 497 | (unsigned long long)util); |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 498 | } |
| 499 | static DEVICE_ATTR(queue_full, S_IRUGO, zfcp_sysfs_adapter_q_full_show, NULL); |
| 500 | |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 501 | struct device_attribute *zfcp_sysfs_shost_attrs[] = { |
| 502 | &dev_attr_utilization, |
| 503 | &dev_attr_requests, |
| 504 | &dev_attr_megabytes, |
| 505 | &dev_attr_seconds_active, |
Stefan Raspl | 2450d3e | 2008-10-01 12:42:14 +0200 | [diff] [blame] | 506 | &dev_attr_queue_full, |
Swen Schillig | 6022192 | 2008-07-02 10:56:38 +0200 | [diff] [blame] | 507 | NULL |
| 508 | }; |