linux/drivers/s390/scsi/zfcp_sysfs.c
<<
>>
Prefs
   1/*
   2 * zfcp device driver
   3 *
   4 * sysfs attributes.
   5 *
   6 * Copyright IBM Corp. 2008, 2010
   7 */
   8
   9#define KMSG_COMPONENT "zfcp"
  10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  11
  12#include <linux/slab.h>
  13#include "zfcp_ext.h"
  14
  15#define ZFCP_DEV_ATTR(_feat, _name, _mode, _show, _store) \
  16struct device_attribute dev_attr_##_feat##_##_name = __ATTR(_name, _mode,\
  17                                                            _show, _store)
  18#define ZFCP_DEFINE_ATTR(_feat_def, _feat, _name, _format, _value)             \
  19static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev,         \
  20                                                   struct device_attribute *at,\
  21                                                   char *buf)                  \
  22{                                                                              \
  23        struct _feat_def *_feat = container_of(dev, struct _feat_def, dev);    \
  24                                                                               \
  25        return sprintf(buf, _format, _value);                                  \
  26}                                                                              \
  27static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO,                                    \
  28                     zfcp_sysfs_##_feat##_##_name##_show, NULL);
  29
  30#define ZFCP_DEFINE_ATTR_CONST(_feat, _name, _format, _value)                  \
  31static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev,         \
  32                                                   struct device_attribute *at,\
  33                                                   char *buf)                  \
  34{                                                                              \
  35        return sprintf(buf, _format, _value);                                  \
  36}                                                                              \
  37static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO,                                    \
  38                     zfcp_sysfs_##_feat##_##_name##_show, NULL);
  39
  40#define ZFCP_DEFINE_A_ATTR(_name, _format, _value)                           \
  41static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev,         \
  42                                                 struct device_attribute *at,\
  43                                                 char *buf)                  \
  44{                                                                            \
  45        struct ccw_device *cdev = to_ccwdev(dev);                            \
  46        struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);       \
  47        int i;                                                               \
  48                                                                             \
  49        if (!adapter)                                                        \
  50                return -ENODEV;                                              \
  51                                                                             \
  52        i = sprintf(buf, _format, _value);                                   \
  53        zfcp_ccw_adapter_put(adapter);                                       \
  54        return i;                                                            \
  55}                                                                            \
  56static ZFCP_DEV_ATTR(adapter, _name, S_IRUGO,                                \
  57                     zfcp_sysfs_adapter_##_name##_show, NULL);
  58
  59ZFCP_DEFINE_A_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
  60ZFCP_DEFINE_A_ATTR(peer_wwnn, "0x%016llx\n",
  61                   (unsigned long long) adapter->peer_wwnn);
  62ZFCP_DEFINE_A_ATTR(peer_wwpn, "0x%016llx\n",
  63                   (unsigned long long) adapter->peer_wwpn);
  64ZFCP_DEFINE_A_ATTR(peer_d_id, "0x%06x\n", adapter->peer_d_id);
  65ZFCP_DEFINE_A_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
  66ZFCP_DEFINE_A_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
  67ZFCP_DEFINE_A_ATTR(hardware_version, "0x%08x\n", adapter->hardware_version);
  68ZFCP_DEFINE_A_ATTR(in_recovery, "%d\n", (atomic_read(&adapter->status) &
  69                                         ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
  70
  71ZFCP_DEFINE_ATTR(zfcp_port, port, status, "0x%08x\n",
  72                 atomic_read(&port->status));
  73ZFCP_DEFINE_ATTR(zfcp_port, port, in_recovery, "%d\n",
  74                 (atomic_read(&port->status) &
  75                  ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
  76ZFCP_DEFINE_ATTR_CONST(port, access_denied, "%d\n", 0);
  77
  78ZFCP_DEFINE_ATTR(zfcp_unit, unit, status, "0x%08x\n",
  79                 zfcp_unit_sdev_status(unit));
  80ZFCP_DEFINE_ATTR(zfcp_unit, unit, in_recovery, "%d\n",
  81                 (zfcp_unit_sdev_status(unit) &
  82                  ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
  83ZFCP_DEFINE_ATTR(zfcp_unit, unit, access_denied, "%d\n",
  84                 (zfcp_unit_sdev_status(unit) &
  85                  ZFCP_STATUS_COMMON_ACCESS_DENIED) != 0);
  86ZFCP_DEFINE_ATTR_CONST(unit, access_shared, "%d\n", 0);
  87ZFCP_DEFINE_ATTR_CONST(unit, access_readonly, "%d\n", 0);
  88
  89static ssize_t zfcp_sysfs_port_failed_show(struct device *dev,
  90                                           struct device_attribute *attr,
  91                                           char *buf)
  92{
  93        struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
  94
  95        if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
  96                return sprintf(buf, "1\n");
  97
  98        return sprintf(buf, "0\n");
  99}
 100
 101static ssize_t zfcp_sysfs_port_failed_store(struct device *dev,
 102                                            struct device_attribute *attr,
 103                                            const char *buf, size_t count)
 104{
 105        struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
 106        unsigned long val;
 107
 108        if (strict_strtoul(buf, 0, &val) || val != 0)
 109                return -EINVAL;
 110
 111        zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_RUNNING);
 112        zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, "sypfai2");
 113        zfcp_erp_wait(port->adapter);
 114
 115        return count;
 116}
 117static ZFCP_DEV_ATTR(port, failed, S_IWUSR | S_IRUGO,
 118                     zfcp_sysfs_port_failed_show,
 119                     zfcp_sysfs_port_failed_store);
 120
 121static ssize_t zfcp_sysfs_unit_failed_show(struct device *dev,
 122                                           struct device_attribute *attr,
 123                                           char *buf)
 124{
 125        struct zfcp_unit *unit = container_of(dev, struct zfcp_unit, dev);
 126        struct scsi_device *sdev;
 127        unsigned int status, failed = 1;
 128
 129        sdev = zfcp_unit_sdev(unit);
 130        if (sdev) {
 131                status = atomic_read(&sdev_to_zfcp(sdev)->status);
 132                failed = status & ZFCP_STATUS_COMMON_ERP_FAILED ? 1 : 0;
 133                scsi_device_put(sdev);
 134        }
 135
 136        return sprintf(buf, "%d\n", failed);
 137}
 138
 139static ssize_t zfcp_sysfs_unit_failed_store(struct device *dev,
 140                                            struct device_attribute *attr,
 141                                            const char *buf, size_t count)
 142{
 143        struct zfcp_unit *unit = container_of(dev, struct zfcp_unit, dev);
 144        unsigned long val;
 145        struct scsi_device *sdev;
 146
 147        if (strict_strtoul(buf, 0, &val) || val != 0)
 148                return -EINVAL;
 149
 150        sdev = zfcp_unit_sdev(unit);
 151        if (sdev) {
 152                zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_RUNNING);
 153                zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
 154                                    "syufai2");
 155                zfcp_erp_wait(unit->port->adapter);
 156        } else
 157                zfcp_unit_scsi_scan(unit);
 158
 159        return count;
 160}
 161static ZFCP_DEV_ATTR(unit, failed, S_IWUSR | S_IRUGO,
 162                     zfcp_sysfs_unit_failed_show,
 163                     zfcp_sysfs_unit_failed_store);
 164
 165static ssize_t zfcp_sysfs_adapter_failed_show(struct device *dev,
 166                                              struct device_attribute *attr,
 167                                              char *buf)
 168{
 169        struct ccw_device *cdev = to_ccwdev(dev);
 170        struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
 171        int i;
 172
 173        if (!adapter)
 174                return -ENODEV;
 175
 176        if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
 177                i = sprintf(buf, "1\n");
 178        else
 179                i = sprintf(buf, "0\n");
 180
 181        zfcp_ccw_adapter_put(adapter);
 182        return i;
 183}
 184
 185static ssize_t zfcp_sysfs_adapter_failed_store(struct device *dev,
 186                                               struct device_attribute *attr,
 187                                               const char *buf, size_t count)
 188{
 189        struct ccw_device *cdev = to_ccwdev(dev);
 190        struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
 191        unsigned long val;
 192        int retval = 0;
 193
 194        if (!adapter)
 195                return -ENODEV;
 196
 197        if (strict_strtoul(buf, 0, &val) || val != 0) {
 198                retval = -EINVAL;
 199                goto out;
 200        }
 201
 202        zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING);
 203        zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
 204                                "syafai2");
 205        zfcp_erp_wait(adapter);
 206out:
 207        zfcp_ccw_adapter_put(adapter);
 208        return retval ? retval : (ssize_t) count;
 209}
 210static ZFCP_DEV_ATTR(adapter, failed, S_IWUSR | S_IRUGO,
 211                     zfcp_sysfs_adapter_failed_show,
 212                     zfcp_sysfs_adapter_failed_store);
 213
 214static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev,
 215                                            struct device_attribute *attr,
 216                                            const char *buf, size_t count)
 217{
 218        struct ccw_device *cdev = to_ccwdev(dev);
 219        struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
 220
 221        if (!adapter)
 222                return -ENODEV;
 223
 224        /*
 225         * Users wish is our command: immediately schedule and flush a
 226         * worker to conduct a synchronous port scan, that is, neither
 227         * a random delay nor a rate limit is applied here.
 228         */
 229        queue_delayed_work(adapter->work_queue, &adapter->scan_work, 0);
 230        flush_delayed_work(&adapter->scan_work);
 231        zfcp_ccw_adapter_put(adapter);
 232
 233        return (ssize_t) count;
 234}
 235static ZFCP_DEV_ATTR(adapter, port_rescan, S_IWUSR, NULL,
 236                     zfcp_sysfs_port_rescan_store);
 237
 238DEFINE_MUTEX(zfcp_sysfs_port_units_mutex);
 239
 240static void zfcp_sysfs_port_set_removing(struct zfcp_port *const port)
 241{
 242        lockdep_assert_held(&zfcp_sysfs_port_units_mutex);
 243        atomic_set(&port->units, -1);
 244}
 245
 246bool zfcp_sysfs_port_is_removing(const struct zfcp_port *const port)
 247{
 248        lockdep_assert_held(&zfcp_sysfs_port_units_mutex);
 249        return atomic_read(&port->units) == -1;
 250}
 251
 252static bool zfcp_sysfs_port_in_use(struct zfcp_port *const port)
 253{
 254        struct zfcp_adapter *const adapter = port->adapter;
 255        unsigned long flags;
 256        struct scsi_device *sdev;
 257        bool in_use = true;
 258
 259        mutex_lock(&zfcp_sysfs_port_units_mutex);
 260        if (atomic_read(&port->units) > 0)
 261                goto unlock_port_units_mutex; /* zfcp_unit(s) under port */
 262
 263        spin_lock_irqsave(adapter->scsi_host->host_lock, flags);
 264        __shost_for_each_device(sdev, adapter->scsi_host) {
 265                const struct zfcp_scsi_dev *zsdev = sdev_to_zfcp(sdev);
 266
 267                if (sdev->sdev_state == SDEV_DEL ||
 268                    sdev->sdev_state == SDEV_CANCEL)
 269                        continue;
 270                if (zsdev->port != port)
 271                        continue;
 272                /* alive scsi_device under port of interest */
 273                goto unlock_host_lock;
 274        }
 275
 276        /* port is about to be removed, so no more unit_add or slave_alloc */
 277        zfcp_sysfs_port_set_removing(port);
 278        in_use = false;
 279
 280unlock_host_lock:
 281        spin_unlock_irqrestore(adapter->scsi_host->host_lock, flags);
 282unlock_port_units_mutex:
 283        mutex_unlock(&zfcp_sysfs_port_units_mutex);
 284        return in_use;
 285}
 286
 287static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,
 288                                            struct device_attribute *attr,
 289                                            const char *buf, size_t count)
 290{
 291        struct ccw_device *cdev = to_ccwdev(dev);
 292        struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
 293        struct zfcp_port *port;
 294        u64 wwpn;
 295        int retval = -EINVAL;
 296
 297        if (!adapter)
 298                return -ENODEV;
 299
 300        if (strict_strtoull(buf, 0, (unsigned long long *) &wwpn))
 301                goto out;
 302
 303        port = zfcp_get_port_by_wwpn(adapter, wwpn);
 304        if (!port)
 305                goto out;
 306        else
 307                retval = 0;
 308
 309        if (zfcp_sysfs_port_in_use(port)) {
 310                retval = -EBUSY;
 311                put_device(&port->dev); /* undo zfcp_get_port_by_wwpn() */
 312                goto out;
 313        }
 314
 315        write_lock_irq(&adapter->port_list_lock);
 316        list_del(&port->list);
 317        write_unlock_irq(&adapter->port_list_lock);
 318
 319        put_device(&port->dev);
 320
 321        zfcp_erp_port_shutdown(port, 0, "syprs_1");
 322        zfcp_device_unregister(&port->dev, &zfcp_sysfs_port_attrs);
 323 out:
 324        zfcp_ccw_adapter_put(adapter);
 325        return retval ? retval : (ssize_t) count;
 326}
 327static ZFCP_DEV_ATTR(adapter, port_remove, S_IWUSR, NULL,
 328                     zfcp_sysfs_port_remove_store);
 329
 330static struct attribute *zfcp_adapter_attrs[] = {
 331        &dev_attr_adapter_failed.attr,
 332        &dev_attr_adapter_in_recovery.attr,
 333        &dev_attr_adapter_port_remove.attr,
 334        &dev_attr_adapter_port_rescan.attr,
 335        &dev_attr_adapter_peer_wwnn.attr,
 336        &dev_attr_adapter_peer_wwpn.attr,
 337        &dev_attr_adapter_peer_d_id.attr,
 338        &dev_attr_adapter_card_version.attr,
 339        &dev_attr_adapter_lic_version.attr,
 340        &dev_attr_adapter_status.attr,
 341        &dev_attr_adapter_hardware_version.attr,
 342        NULL
 343};
 344
 345struct attribute_group zfcp_sysfs_adapter_attrs = {
 346        .attrs = zfcp_adapter_attrs,
 347};
 348
 349static ssize_t zfcp_sysfs_unit_add_store(struct device *dev,
 350                                         struct device_attribute *attr,
 351                                         const char *buf, size_t count)
 352{
 353        struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
 354        u64 fcp_lun;
 355        int retval;
 356
 357        if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun))
 358                return -EINVAL;
 359
 360        retval = zfcp_unit_add(port, fcp_lun);
 361        if (retval)
 362                return retval;
 363
 364        return count;
 365}
 366static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
 367
 368static ssize_t zfcp_sysfs_unit_remove_store(struct device *dev,
 369                                            struct device_attribute *attr,
 370                                            const char *buf, size_t count)
 371{
 372        struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
 373        u64 fcp_lun;
 374
 375        if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun))
 376                return -EINVAL;
 377
 378        if (zfcp_unit_remove(port, fcp_lun))
 379                return -EINVAL;
 380
 381        return count;
 382}
 383static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
 384
 385static struct attribute *zfcp_port_attrs[] = {
 386        &dev_attr_unit_add.attr,
 387        &dev_attr_unit_remove.attr,
 388        &dev_attr_port_failed.attr,
 389        &dev_attr_port_in_recovery.attr,
 390        &dev_attr_port_status.attr,
 391        &dev_attr_port_access_denied.attr,
 392        NULL
 393};
 394
 395/**
 396 * zfcp_sysfs_port_attrs - sysfs attributes for all other ports
 397 */
 398struct attribute_group zfcp_sysfs_port_attrs = {
 399        .attrs = zfcp_port_attrs,
 400};
 401
 402static struct attribute *zfcp_unit_attrs[] = {
 403        &dev_attr_unit_failed.attr,
 404        &dev_attr_unit_in_recovery.attr,
 405        &dev_attr_unit_status.attr,
 406        &dev_attr_unit_access_denied.attr,
 407        &dev_attr_unit_access_shared.attr,
 408        &dev_attr_unit_access_readonly.attr,
 409        NULL
 410};
 411
 412struct attribute_group zfcp_sysfs_unit_attrs = {
 413        .attrs = zfcp_unit_attrs,
 414};
 415
 416#define ZFCP_DEFINE_LATENCY_ATTR(_name)                                 \
 417static ssize_t                                                          \
 418zfcp_sysfs_unit_##_name##_latency_show(struct device *dev,              \
 419                                       struct device_attribute *attr,   \
 420                                       char *buf) {                     \
 421        struct scsi_device *sdev = to_scsi_device(dev);                 \
 422        struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);           \
 423        struct zfcp_latencies *lat = &zfcp_sdev->latencies;             \
 424        struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;        \
 425        unsigned long long fsum, fmin, fmax, csum, cmin, cmax, cc;      \
 426                                                                        \
 427        spin_lock_bh(&lat->lock);                                       \
 428        fsum = lat->_name.fabric.sum * adapter->timer_ticks;            \
 429        fmin = lat->_name.fabric.min * adapter->timer_ticks;            \
 430        fmax = lat->_name.fabric.max * adapter->timer_ticks;            \
 431        csum = lat->_name.channel.sum * adapter->timer_ticks;           \
 432        cmin = lat->_name.channel.min * adapter->timer_ticks;           \
 433        cmax = lat->_name.channel.max * adapter->timer_ticks;           \
 434        cc  = lat->_name.counter;                                       \
 435        spin_unlock_bh(&lat->lock);                                     \
 436                                                                        \
 437        do_div(fsum, 1000);                                             \
 438        do_div(fmin, 1000);                                             \
 439        do_div(fmax, 1000);                                             \
 440        do_div(csum, 1000);                                             \
 441        do_div(cmin, 1000);                                             \
 442        do_div(cmax, 1000);                                             \
 443                                                                        \
 444        return sprintf(buf, "%llu %llu %llu %llu %llu %llu %llu\n",     \
 445                       fmin, fmax, fsum, cmin, cmax, csum, cc);         \
 446}                                                                       \
 447static ssize_t                                                          \
 448zfcp_sysfs_unit_##_name##_latency_store(struct device *dev,             \
 449                                        struct device_attribute *attr,  \
 450                                        const char *buf, size_t count)  \
 451{                                                                       \
 452        struct scsi_device *sdev = to_scsi_device(dev);                 \
 453        struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);           \
 454        struct zfcp_latencies *lat = &zfcp_sdev->latencies;             \
 455        unsigned long flags;                                            \
 456                                                                        \
 457        spin_lock_irqsave(&lat->lock, flags);                           \
 458        lat->_name.fabric.sum = 0;                                      \
 459        lat->_name.fabric.min = 0xFFFFFFFF;                             \
 460        lat->_name.fabric.max = 0;                                      \
 461        lat->_name.channel.sum = 0;                                     \
 462        lat->_name.channel.min = 0xFFFFFFFF;                            \
 463        lat->_name.channel.max = 0;                                     \
 464        lat->_name.counter = 0;                                         \
 465        spin_unlock_irqrestore(&lat->lock, flags);                      \
 466                                                                        \
 467        return (ssize_t) count;                                         \
 468}                                                                       \
 469static DEVICE_ATTR(_name##_latency, S_IWUSR | S_IRUGO,                  \
 470                   zfcp_sysfs_unit_##_name##_latency_show,              \
 471                   zfcp_sysfs_unit_##_name##_latency_store);
 472
 473ZFCP_DEFINE_LATENCY_ATTR(read);
 474ZFCP_DEFINE_LATENCY_ATTR(write);
 475ZFCP_DEFINE_LATENCY_ATTR(cmd);
 476
 477#define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value)                   \
 478static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev,       \
 479                                              struct device_attribute *attr,\
 480                                              char *buf)                 \
 481{                                                                        \
 482        struct scsi_device *sdev = to_scsi_device(dev);                  \
 483        struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);            \
 484                                                                         \
 485        return sprintf(buf, _format, _value);                            \
 486}                                                                        \
 487static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
 488
 489ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n",
 490                      dev_name(&zfcp_sdev->port->adapter->ccw_device->dev));
 491ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n",
 492                      (unsigned long long) zfcp_sdev->port->wwpn);
 493
 494static ssize_t zfcp_sysfs_scsi_fcp_lun_show(struct device *dev,
 495                                            struct device_attribute *attr,
 496                                            char *buf)
 497{
 498        struct scsi_device *sdev = to_scsi_device(dev);
 499
 500        return sprintf(buf, "0x%016llx\n", zfcp_scsi_dev_lun(sdev));
 501}
 502static DEVICE_ATTR(fcp_lun, S_IRUGO, zfcp_sysfs_scsi_fcp_lun_show, NULL);
 503
 504ZFCP_DEFINE_SCSI_ATTR(zfcp_access_denied, "%d\n",
 505                      (atomic_read(&zfcp_sdev->status) &
 506                       ZFCP_STATUS_COMMON_ACCESS_DENIED) != 0);
 507
 508static ssize_t zfcp_sysfs_scsi_zfcp_failed_show(struct device *dev,
 509                                           struct device_attribute *attr,
 510                                           char *buf)
 511{
 512        struct scsi_device *sdev = to_scsi_device(dev);
 513        unsigned int status = atomic_read(&sdev_to_zfcp(sdev)->status);
 514        unsigned int failed = status & ZFCP_STATUS_COMMON_ERP_FAILED ? 1 : 0;
 515
 516        return sprintf(buf, "%d\n", failed);
 517}
 518
 519static ssize_t zfcp_sysfs_scsi_zfcp_failed_store(struct device *dev,
 520                                            struct device_attribute *attr,
 521                                            const char *buf, size_t count)
 522{
 523        struct scsi_device *sdev = to_scsi_device(dev);
 524        unsigned long val;
 525
 526        if (kstrtoul(buf, 0, &val) || val != 0)
 527                return -EINVAL;
 528
 529        zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_RUNNING);
 530        zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
 531                            "syufai3");
 532        zfcp_erp_wait(sdev_to_zfcp(sdev)->port->adapter);
 533
 534        return count;
 535}
 536static DEVICE_ATTR(zfcp_failed, S_IWUSR | S_IRUGO,
 537                   zfcp_sysfs_scsi_zfcp_failed_show,
 538                   zfcp_sysfs_scsi_zfcp_failed_store);
 539
 540ZFCP_DEFINE_SCSI_ATTR(zfcp_in_recovery, "%d\n",
 541                      (atomic_read(&zfcp_sdev->status) &
 542                       ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
 543
 544ZFCP_DEFINE_SCSI_ATTR(zfcp_status, "0x%08x\n",
 545                      atomic_read(&zfcp_sdev->status));
 546
 547struct device_attribute *zfcp_sysfs_sdev_attrs[] = {
 548        &dev_attr_fcp_lun,
 549        &dev_attr_wwpn,
 550        &dev_attr_hba_id,
 551        &dev_attr_read_latency,
 552        &dev_attr_write_latency,
 553        &dev_attr_cmd_latency,
 554        &dev_attr_zfcp_access_denied,
 555        &dev_attr_zfcp_failed,
 556        &dev_attr_zfcp_in_recovery,
 557        &dev_attr_zfcp_status,
 558        NULL
 559};
 560
 561static ssize_t zfcp_sysfs_adapter_util_show(struct device *dev,
 562                                            struct device_attribute *attr,
 563                                            char *buf)
 564{
 565        struct Scsi_Host *scsi_host = dev_to_shost(dev);
 566        struct fsf_qtcb_bottom_port *qtcb_port;
 567        struct zfcp_adapter *adapter;
 568        int retval;
 569
 570        adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
 571        if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA))
 572                return -EOPNOTSUPP;
 573
 574        qtcb_port = kzalloc(sizeof(struct fsf_qtcb_bottom_port), GFP_KERNEL);
 575        if (!qtcb_port)
 576                return -ENOMEM;
 577
 578        retval = zfcp_fsf_exchange_port_data_sync(adapter->qdio, qtcb_port);
 579        if (!retval)
 580                retval = sprintf(buf, "%u %u %u\n", qtcb_port->cp_util,
 581                                 qtcb_port->cb_util, qtcb_port->a_util);
 582        kfree(qtcb_port);
 583        return retval;
 584}
 585static DEVICE_ATTR(utilization, S_IRUGO, zfcp_sysfs_adapter_util_show, NULL);
 586
 587static int zfcp_sysfs_adapter_ex_config(struct device *dev,
 588                                        struct fsf_statistics_info *stat_inf)
 589{
 590        struct Scsi_Host *scsi_host = dev_to_shost(dev);
 591        struct fsf_qtcb_bottom_config *qtcb_config;
 592        struct zfcp_adapter *adapter;
 593        int retval;
 594
 595        adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
 596        if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA))
 597                return -EOPNOTSUPP;
 598
 599        qtcb_config = kzalloc(sizeof(struct fsf_qtcb_bottom_config),
 600                              GFP_KERNEL);
 601        if (!qtcb_config)
 602                return -ENOMEM;
 603
 604        retval = zfcp_fsf_exchange_config_data_sync(adapter->qdio, qtcb_config);
 605        if (!retval)
 606                *stat_inf = qtcb_config->stat_info;
 607
 608        kfree(qtcb_config);
 609        return retval;
 610}
 611
 612#define ZFCP_SHOST_ATTR(_name, _format, _arg...)                        \
 613static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev,    \
 614                                                 struct device_attribute *attr,\
 615                                                 char *buf)             \
 616{                                                                       \
 617        struct fsf_statistics_info stat_info;                           \
 618        int retval;                                                     \
 619                                                                        \
 620        retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info);         \
 621        if (retval)                                                     \
 622                return retval;                                          \
 623                                                                        \
 624        return sprintf(buf, _format, ## _arg);                          \
 625}                                                                       \
 626static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
 627
 628ZFCP_SHOST_ATTR(requests, "%llu %llu %llu\n",
 629                (unsigned long long) stat_info.input_req,
 630                (unsigned long long) stat_info.output_req,
 631                (unsigned long long) stat_info.control_req);
 632
 633ZFCP_SHOST_ATTR(megabytes, "%llu %llu\n",
 634                (unsigned long long) stat_info.input_mb,
 635                (unsigned long long) stat_info.output_mb);
 636
 637ZFCP_SHOST_ATTR(seconds_active, "%llu\n",
 638                (unsigned long long) stat_info.seconds_act);
 639
 640static ssize_t zfcp_sysfs_adapter_q_full_show(struct device *dev,
 641                                              struct device_attribute *attr,
 642                                              char *buf)
 643{
 644        struct Scsi_Host *scsi_host = class_to_shost(dev);
 645        struct zfcp_qdio *qdio =
 646                ((struct zfcp_adapter *) scsi_host->hostdata[0])->qdio;
 647        u64 util;
 648
 649        spin_lock_bh(&qdio->stat_lock);
 650        util = qdio->req_q_util;
 651        spin_unlock_bh(&qdio->stat_lock);
 652
 653        return sprintf(buf, "%d %llu\n", atomic_read(&qdio->req_q_full),
 654                       (unsigned long long)util);
 655}
 656static DEVICE_ATTR(queue_full, S_IRUGO, zfcp_sysfs_adapter_q_full_show, NULL);
 657
 658struct device_attribute *zfcp_sysfs_shost_attrs[] = {
 659        &dev_attr_utilization,
 660        &dev_attr_requests,
 661        &dev_attr_megabytes,
 662        &dev_attr_seconds_active,
 663        &dev_attr_queue_full,
 664        NULL
 665};
 666