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