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