aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSwen Schillig <swen@vnet.ibm.com>2008-07-02 04:56:38 -0400
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2008-07-12 09:22:35 -0400
commit60221920706a01bef89af2577f9a90a8eeb4e662 (patch)
treef8b38412351e8be78c6f24524d963a08032fb2a1
parent317e6b6519b5a34263a33f150ed57ad468b26a64 (diff)
[SCSI] zfcp: consolidate sysfs things into one file.
zfcp was using three files to deal with sysfs representation for adapters, ports and units. The consolidation into one file prevents code-duplication and eases maintainability. Signed-off-by: Swen Schillig <swen@vnet.ibm.com> Signed-off-by: Christof Schmitt <christof.schmitt@de.ibm.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
-rw-r--r--drivers/s390/scsi/Makefile3
-rw-r--r--drivers/s390/scsi/zfcp_aux.c42
-rw-r--r--drivers/s390/scsi/zfcp_def.h9
-rw-r--r--drivers/s390/scsi/zfcp_ext.h16
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c206
-rw-r--r--drivers/s390/scsi/zfcp_sysfs.c496
-rw-r--r--drivers/s390/scsi/zfcp_sysfs_adapter.c232
-rw-r--r--drivers/s390/scsi/zfcp_sysfs_port.c278
-rw-r--r--drivers/s390/scsi/zfcp_sysfs_unit.c150
9 files changed, 539 insertions, 893 deletions
diff --git a/drivers/s390/scsi/Makefile b/drivers/s390/scsi/Makefile
index 1aa46500f650..cb301cc6178c 100644
--- a/drivers/s390/scsi/Makefile
+++ b/drivers/s390/scsi/Makefile
@@ -3,7 +3,6 @@
3# 3#
4 4
5zfcp-objs := zfcp_aux.o zfcp_ccw.o zfcp_scsi.o zfcp_erp.o zfcp_qdio.o \ 5zfcp-objs := zfcp_aux.o zfcp_ccw.o zfcp_scsi.o zfcp_erp.o zfcp_qdio.o \
6 zfcp_fsf.o zfcp_dbf.o zfcp_sysfs_adapter.o zfcp_sysfs_port.o \ 6 zfcp_fsf.o zfcp_dbf.o zfcp_sysfs.o zfcp_fc.o zfcp_cfdc.o
7 zfcp_sysfs_unit.o zfcp_fc.o zfcp_cfdc.o
8 7
9obj-$(CONFIG_ZFCP) += zfcp.o 8obj-$(CONFIG_ZFCP) += zfcp.o
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index 7777729419eb..5b9ca3cde898 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -262,6 +262,11 @@ struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter,
262 return NULL; 262 return NULL;
263} 263}
264 264
265static void zfcp_sysfs_unit_release(struct device *dev)
266{
267 kfree(container_of(dev, struct zfcp_unit, sysfs_device));
268}
269
265/** 270/**
266 * zfcp_unit_enqueue - enqueue unit to unit list of a port. 271 * zfcp_unit_enqueue - enqueue unit to unit list of a port.
267 * @port: pointer to port where unit is added 272 * @port: pointer to port where unit is added
@@ -311,7 +316,8 @@ struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
311 if (device_register(&unit->sysfs_device)) 316 if (device_register(&unit->sysfs_device))
312 goto err_out_free; 317 goto err_out_free;
313 318
314 if (zfcp_sysfs_unit_create_files(&unit->sysfs_device)) { 319 if (sysfs_create_group(&unit->sysfs_device.kobj,
320 &zfcp_sysfs_unit_attrs)) {
315 device_unregister(&unit->sysfs_device); 321 device_unregister(&unit->sysfs_device);
316 return ERR_PTR(-EIO); 322 return ERR_PTR(-EIO);
317 } 323 }
@@ -351,7 +357,7 @@ void zfcp_unit_dequeue(struct zfcp_unit *unit)
351 write_unlock_irq(&zfcp_data.config_lock); 357 write_unlock_irq(&zfcp_data.config_lock);
352 unit->port->units--; 358 unit->port->units--;
353 zfcp_port_put(unit->port); 359 zfcp_port_put(unit->port);
354 zfcp_sysfs_unit_remove_files(&unit->sysfs_device); 360 sysfs_remove_group(&unit->sysfs_device.kobj, &zfcp_sysfs_unit_attrs);
355 device_unregister(&unit->sysfs_device); 361 device_unregister(&unit->sysfs_device);
356} 362}
357 363
@@ -527,7 +533,8 @@ int zfcp_adapter_enqueue(struct ccw_device *ccw_device)
527 533
528 dev_set_drvdata(&ccw_device->dev, adapter); 534 dev_set_drvdata(&ccw_device->dev, adapter);
529 535
530 if (zfcp_sysfs_adapter_create_files(&ccw_device->dev)) 536 if (sysfs_create_group(&ccw_device->dev.kobj,
537 &zfcp_sysfs_adapter_attrs))
531 goto sysfs_failed; 538 goto sysfs_failed;
532 539
533 adapter->generic_services.parent = &adapter->ccw_device->dev; 540 adapter->generic_services.parent = &adapter->ccw_device->dev;
@@ -550,7 +557,8 @@ int zfcp_adapter_enqueue(struct ccw_device *ccw_device)
550 return 0; 557 return 0;
551 558
552generic_services_failed: 559generic_services_failed:
553 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev); 560 sysfs_remove_group(&ccw_device->dev.kobj,
561 &zfcp_sysfs_adapter_attrs);
554sysfs_failed: 562sysfs_failed:
555 zfcp_adapter_debug_unregister(adapter); 563 zfcp_adapter_debug_unregister(adapter);
556debug_register_failed: 564debug_register_failed:
@@ -578,7 +586,8 @@ void zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
578 cancel_work_sync(&adapter->stat_work); 586 cancel_work_sync(&adapter->stat_work);
579 zfcp_adapter_scsi_unregister(adapter); 587 zfcp_adapter_scsi_unregister(adapter);
580 device_unregister(&adapter->generic_services); 588 device_unregister(&adapter->generic_services);
581 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev); 589 sysfs_remove_group(&adapter->ccw_device->dev.kobj,
590 &zfcp_sysfs_adapter_attrs);
582 dev_set_drvdata(&adapter->ccw_device->dev, NULL); 591 dev_set_drvdata(&adapter->ccw_device->dev, NULL);
583 /* sanity check: no pending FSF requests */ 592 /* sanity check: no pending FSF requests */
584 spin_lock_irqsave(&adapter->req_list_lock, flags); 593 spin_lock_irqsave(&adapter->req_list_lock, flags);
@@ -606,6 +615,11 @@ void zfcp_adapter_dequeue(struct zfcp_adapter *adapter)
606 kfree(adapter); 615 kfree(adapter);
607} 616}
608 617
618static void zfcp_sysfs_port_release(struct device *dev)
619{
620 kfree(container_of(dev, struct zfcp_port, sysfs_device));
621}
622
609/** 623/**
610 * zfcp_port_enqueue - enqueue port to port list of adapter 624 * zfcp_port_enqueue - enqueue port to port list of adapter
611 * @adapter: adapter where remote port is added 625 * @adapter: adapter where remote port is added
@@ -623,6 +637,7 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn,
623 u32 status, u32 d_id) 637 u32 status, u32 d_id)
624{ 638{
625 struct zfcp_port *port; 639 struct zfcp_port *port;
640 int retval;
626 char *bus_id; 641 char *bus_id;
627 642
628 port = kzalloc(sizeof(struct zfcp_port), GFP_KERNEL); 643 port = kzalloc(sizeof(struct zfcp_port), GFP_KERNEL);
@@ -685,7 +700,14 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, wwn_t wwpn,
685 if (device_register(&port->sysfs_device)) 700 if (device_register(&port->sysfs_device))
686 goto err_out_free; 701 goto err_out_free;
687 702
688 if (zfcp_sysfs_port_create_files(&port->sysfs_device, status)) { 703 if (status & ZFCP_STATUS_PORT_WKA)
704 retval = sysfs_create_group(&port->sysfs_device.kobj,
705 &zfcp_sysfs_ns_port_attrs);
706 else
707 retval = sysfs_create_group(&port->sysfs_device.kobj,
708 &zfcp_sysfs_port_attrs);
709
710 if (retval) {
689 device_unregister(&port->sysfs_device); 711 device_unregister(&port->sysfs_device);
690 goto err_out; 712 goto err_out;
691 } 713 }
@@ -727,8 +749,12 @@ void zfcp_port_dequeue(struct zfcp_port *port)
727 fc_remote_port_delete(port->rport); 749 fc_remote_port_delete(port->rport);
728 port->rport = NULL; 750 port->rport = NULL;
729 zfcp_adapter_put(port->adapter); 751 zfcp_adapter_put(port->adapter);
730 zfcp_sysfs_port_remove_files(&port->sysfs_device, 752 if (atomic_read(&port->status) & ZFCP_STATUS_PORT_WKA)
731 atomic_read(&port->status)); 753 sysfs_remove_group(&port->sysfs_device.kobj,
754 &zfcp_sysfs_ns_port_attrs);
755 else
756 sysfs_remove_group(&port->sysfs_device.kobj,
757 &zfcp_sysfs_port_attrs);
732 device_unregister(&port->sysfs_device); 758 device_unregister(&port->sysfs_device);
733} 759}
734 760
diff --git a/drivers/s390/scsi/zfcp_def.h b/drivers/s390/scsi/zfcp_def.h
index d69d280359da..2af043a5c74b 100644
--- a/drivers/s390/scsi/zfcp_def.h
+++ b/drivers/s390/scsi/zfcp_def.h
@@ -627,11 +627,6 @@ struct zfcp_adapter {
627 struct work_struct scan_work; 627 struct work_struct scan_work;
628}; 628};
629 629
630/*
631 * the struct device sysfs_device must be at the beginning of this structure.
632 * pointer to struct device is used to free port structure in release function
633 * of the device. don't change!
634 */
635struct zfcp_port { 630struct zfcp_port {
636 struct device sysfs_device; /* sysfs device */ 631 struct device sysfs_device; /* sysfs device */
637 struct fc_rport *rport; /* rport of fc transport class */ 632 struct fc_rport *rport; /* rport of fc transport class */
@@ -655,10 +650,6 @@ struct zfcp_port {
655 u32 supported_classes; 650 u32 supported_classes;
656}; 651};
657 652
658/* the struct device sysfs_device must be at the beginning of this structure.
659 * pointer to struct device is used to free unit structure in release function
660 * of the device. don't change!
661 */
662struct zfcp_unit { 653struct zfcp_unit {
663 struct device sysfs_device; /* sysfs device */ 654 struct device sysfs_device; /* sysfs device */
664 struct list_head list; /* list of logical units */ 655 struct list_head list; /* list of logical units */
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index 9caa081e52ed..f0d6947ae073 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -13,15 +13,13 @@
13 13
14extern struct zfcp_data zfcp_data; 14extern struct zfcp_data zfcp_data;
15 15
16/******************************** SYSFS *************************************/ 16/* zfcp_sysfs.c */
17extern int zfcp_sysfs_adapter_create_files(struct device *); 17extern struct attribute_group zfcp_sysfs_unit_attrs;
18extern void zfcp_sysfs_adapter_remove_files(struct device *); 18extern struct attribute_group zfcp_sysfs_adapter_attrs;
19extern int zfcp_sysfs_port_create_files(struct device *, u32); 19extern struct attribute_group zfcp_sysfs_ns_port_attrs;
20extern void zfcp_sysfs_port_remove_files(struct device *, u32); 20extern struct attribute_group zfcp_sysfs_port_attrs;
21extern int zfcp_sysfs_unit_create_files(struct device *); 21extern struct device_attribute *zfcp_sysfs_sdev_attrs[];
22extern void zfcp_sysfs_unit_remove_files(struct device *); 22extern struct device_attribute *zfcp_sysfs_shost_attrs[];
23extern void zfcp_sysfs_port_release(struct device *);
24extern void zfcp_sysfs_unit_release(struct device *);
25 23
26/**************************** CONFIGURATION *********************************/ 24/**************************** CONFIGURATION *********************************/
27extern struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *, fcp_lun_t); 25extern struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *, fcp_lun_t);
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index f8594a2e3f5c..e6d8ea8051af 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -520,209 +520,6 @@ struct fc_function_template zfcp_transport_functions = {
520 .disable_target_scan = 1, 520 .disable_target_scan = 1,
521}; 521};
522 522
523#define ZFCP_DEFINE_LATENCY_ATTR(_name) \
524static ssize_t \
525zfcp_sysfs_unit_##_name##_latency_show(struct device *dev, \
526 struct device_attribute *attr, \
527 char *buf) { \
528 struct scsi_device *sdev = to_scsi_device(dev); \
529 struct zfcp_unit *unit = sdev->hostdata; \
530 struct zfcp_latencies *lat = &unit->latencies; \
531 struct zfcp_adapter *adapter = unit->port->adapter; \
532 unsigned long flags; \
533 unsigned long long fsum, fmin, fmax, csum, cmin, cmax, cc; \
534 \
535 spin_lock_irqsave(&lat->lock, flags); \
536 fsum = lat->_name.fabric.sum * adapter->timer_ticks; \
537 fmin = lat->_name.fabric.min * adapter->timer_ticks; \
538 fmax = lat->_name.fabric.max * adapter->timer_ticks; \
539 csum = lat->_name.channel.sum * adapter->timer_ticks; \
540 cmin = lat->_name.channel.min * adapter->timer_ticks; \
541 cmax = lat->_name.channel.max * adapter->timer_ticks; \
542 cc = lat->_name.counter; \
543 spin_unlock_irqrestore(&lat->lock, flags); \
544 \
545 do_div(fsum, 1000); \
546 do_div(fmin, 1000); \
547 do_div(fmax, 1000); \
548 do_div(csum, 1000); \
549 do_div(cmin, 1000); \
550 do_div(cmax, 1000); \
551 \
552 return sprintf(buf, "%llu %llu %llu %llu %llu %llu %llu\n", \
553 fmin, fmax, fsum, cmin, cmax, csum, cc); \
554} \
555static ssize_t \
556zfcp_sysfs_unit_##_name##_latency_store(struct device *dev, \
557 struct device_attribute *attr, \
558 const char *buf, size_t count) \
559{ \
560 struct scsi_device *sdev = to_scsi_device(dev); \
561 struct zfcp_unit *unit = sdev->hostdata; \
562 struct zfcp_latencies *lat = &unit->latencies; \
563 unsigned long flags; \
564 \
565 spin_lock_irqsave(&lat->lock, flags); \
566 lat->_name.fabric.sum = 0; \
567 lat->_name.fabric.min = 0xFFFFFFFF; \
568 lat->_name.fabric.max = 0; \
569 lat->_name.channel.sum = 0; \
570 lat->_name.channel.min = 0xFFFFFFFF; \
571 lat->_name.channel.max = 0; \
572 lat->_name.counter = 0; \
573 spin_unlock_irqrestore(&lat->lock, flags); \
574 \
575 return (ssize_t) count; \
576} \
577static DEVICE_ATTR(_name##_latency, S_IWUSR | S_IRUGO, \
578 zfcp_sysfs_unit_##_name##_latency_show, \
579 zfcp_sysfs_unit_##_name##_latency_store);
580
581ZFCP_DEFINE_LATENCY_ATTR(read);
582ZFCP_DEFINE_LATENCY_ATTR(write);
583ZFCP_DEFINE_LATENCY_ATTR(cmd);
584
585#define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
586static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, struct device_attribute *attr, \
587 char *buf) \
588{ \
589 struct scsi_device *sdev; \
590 struct zfcp_unit *unit; \
591 \
592 sdev = to_scsi_device(dev); \
593 unit = sdev->hostdata; \
594 return sprintf(buf, _format, _value); \
595} \
596 \
597static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
598
599ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n",
600 unit->port->adapter->ccw_device->dev.bus_id);
601ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", unit->port->wwpn);
602ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", unit->fcp_lun);
603
604static struct device_attribute *zfcp_sysfs_sdev_attrs[] = {
605 &dev_attr_fcp_lun,
606 &dev_attr_wwpn,
607 &dev_attr_hba_id,
608 &dev_attr_read_latency,
609 &dev_attr_write_latency,
610 &dev_attr_cmd_latency,
611 NULL
612};
613
614static ssize_t zfcp_sysfs_adapter_util_show(struct device *dev,
615 struct device_attribute *attr,
616 char *buf)
617{
618 struct Scsi_Host *scsi_host = dev_to_shost(dev);
619 struct fsf_qtcb_bottom_port *qtcb_port;
620 struct zfcp_adapter *adapter;
621 int retval;
622
623 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
624 if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA))
625 return -EOPNOTSUPP;
626
627 qtcb_port = kzalloc(sizeof(struct fsf_qtcb_bottom_port), GFP_KERNEL);
628 if (!qtcb_port)
629 return -ENOMEM;
630
631 retval = zfcp_fsf_exchange_port_data_sync(adapter, qtcb_port);
632 if (!retval)
633 retval = sprintf(buf, "%u %u %u\n", qtcb_port->cp_util,
634 qtcb_port->cb_util, qtcb_port->a_util);
635 kfree(qtcb_port);
636 return retval;
637}
638
639static int zfcp_sysfs_adapter_ex_config(struct device *dev,
640 struct fsf_statistics_info *stat_inf)
641{
642 struct Scsi_Host *scsi_host = dev_to_shost(dev);
643 struct fsf_qtcb_bottom_config *qtcb_config;
644 struct zfcp_adapter *adapter;
645 int retval;
646
647 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
648 if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA))
649 return -EOPNOTSUPP;
650
651 qtcb_config = kzalloc(sizeof(struct fsf_qtcb_bottom_config),
652 GFP_KERNEL);
653 if (!qtcb_config)
654 return -ENOMEM;
655
656 retval = zfcp_fsf_exchange_config_data_sync(adapter, qtcb_config);
657 if (!retval)
658 *stat_inf = qtcb_config->stat_info;
659
660 kfree(qtcb_config);
661 return retval;
662}
663
664static ssize_t zfcp_sysfs_adapter_request_show(struct device *dev,
665 struct device_attribute *attr,
666 char *buf)
667{
668 struct fsf_statistics_info stat_info;
669 int retval;
670
671 retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info);
672 if (retval)
673 return retval;
674
675 return sprintf(buf, "%llu %llu %llu\n",
676 (unsigned long long) stat_info.input_req,
677 (unsigned long long) stat_info.output_req,
678 (unsigned long long) stat_info.control_req);
679}
680
681static ssize_t zfcp_sysfs_adapter_mb_show(struct device *dev,
682 struct device_attribute *attr,
683 char *buf)
684{
685 struct fsf_statistics_info stat_info;
686 int retval;
687
688 retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info);
689 if (retval)
690 return retval;
691
692 return sprintf(buf, "%llu %llu\n",
693 (unsigned long long) stat_info.input_mb,
694 (unsigned long long) stat_info.output_mb);
695}
696
697static ssize_t zfcp_sysfs_adapter_sec_active_show(struct device *dev,
698 struct device_attribute *attr,
699 char *buf)
700{
701 struct fsf_statistics_info stat_info;
702 int retval;
703
704 retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info);
705 if (retval)
706 return retval;
707
708 return sprintf(buf, "%llu\n",
709 (unsigned long long) stat_info.seconds_act);
710}
711
712static DEVICE_ATTR(utilization, S_IRUGO, zfcp_sysfs_adapter_util_show, NULL);
713static DEVICE_ATTR(requests, S_IRUGO, zfcp_sysfs_adapter_request_show, NULL);
714static DEVICE_ATTR(megabytes, S_IRUGO, zfcp_sysfs_adapter_mb_show, NULL);
715static DEVICE_ATTR(seconds_active, S_IRUGO,
716 zfcp_sysfs_adapter_sec_active_show, NULL);
717
718static struct device_attribute *zfcp_a_stats_attrs[] = {
719 &dev_attr_utilization,
720 &dev_attr_requests,
721 &dev_attr_megabytes,
722 &dev_attr_seconds_active,
723 NULL
724};
725
726struct zfcp_data zfcp_data = { 523struct zfcp_data zfcp_data = {
727 .scsi_host_template = { 524 .scsi_host_template = {
728 .name = "zfcp", 525 .name = "zfcp",
@@ -743,7 +540,6 @@ struct zfcp_data zfcp_data = {
743 .use_clustering = 1, 540 .use_clustering = 1,
744 .sdev_attrs = zfcp_sysfs_sdev_attrs, 541 .sdev_attrs = zfcp_sysfs_sdev_attrs,
745 .max_sectors = (ZFCP_MAX_SBALES_PER_REQ * 8), 542 .max_sectors = (ZFCP_MAX_SBALES_PER_REQ * 8),
746 .shost_attrs = zfcp_a_stats_attrs, 543 .shost_attrs = zfcp_sysfs_shost_attrs,
747 }, 544 },
748}; 545};
749
diff --git a/drivers/s390/scsi/zfcp_sysfs.c b/drivers/s390/scsi/zfcp_sysfs.c
new file mode 100644
index 000000000000..2e85c6c49e7d
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_sysfs.c
@@ -0,0 +1,496 @@
1/*
2 * zfcp device driver
3 *
4 * sysfs attributes.
5 *
6 * Copyright IBM Corporation 2008
7 */
8
9#include "zfcp_ext.h"
10
11#define ZFCP_DEV_ATTR(_feat, _name, _mode, _show, _store) \
12struct device_attribute dev_attr_##_feat##_##_name = __ATTR(_name, _mode,\
13 _show, _store)
14#define ZFCP_DEFINE_ATTR(_feat_def, _feat, _name, _format, _value) \
15static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev, \
16 struct device_attribute *at,\
17 char *buf) \
18{ \
19 struct _feat_def *_feat = dev_get_drvdata(dev); \
20 \
21 return sprintf(buf, _format, _value); \
22} \
23static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO, \
24 zfcp_sysfs_##_feat##_##_name##_show, NULL);
25
26ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, status, "0x%08x\n",
27 atomic_read(&adapter->status));
28ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, peer_wwnn, "0x%016llx\n",
29 adapter->peer_wwnn);
30ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, peer_wwpn, "0x%016llx\n",
31 adapter->peer_wwpn);
32ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, peer_d_id, "0x%06x\n",
33 adapter->peer_d_id);
34ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, card_version, "0x%04x\n",
35 adapter->hydra_version);
36ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, lic_version, "0x%08x\n",
37 adapter->fsf_lic_version);
38ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, hardware_version, "0x%08x\n",
39 adapter->hardware_version);
40ZFCP_DEFINE_ATTR(zfcp_adapter, adapter, in_recovery, "%d\n",
41 (atomic_read(&adapter->status) &
42 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
43
44ZFCP_DEFINE_ATTR(zfcp_port, port, status, "0x%08x\n",
45 atomic_read(&port->status));
46ZFCP_DEFINE_ATTR(zfcp_port, port, in_recovery, "%d\n",
47 (atomic_read(&port->status) &
48 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
49ZFCP_DEFINE_ATTR(zfcp_port, port, access_denied, "%d\n",
50 (atomic_read(&port->status) &
51 ZFCP_STATUS_COMMON_ACCESS_DENIED) != 0);
52
53ZFCP_DEFINE_ATTR(zfcp_unit, unit, status, "0x%08x\n",
54 atomic_read(&unit->status));
55ZFCP_DEFINE_ATTR(zfcp_unit, unit, in_recovery, "%d\n",
56 (atomic_read(&unit->status) &
57 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
58ZFCP_DEFINE_ATTR(zfcp_unit, unit, access_denied, "%d\n",
59 (atomic_read(&unit->status) &
60 ZFCP_STATUS_COMMON_ACCESS_DENIED) != 0);
61ZFCP_DEFINE_ATTR(zfcp_unit, unit, access_shared, "%d\n",
62 (atomic_read(&unit->status) &
63 ZFCP_STATUS_UNIT_SHARED) != 0);
64ZFCP_DEFINE_ATTR(zfcp_unit, unit, access_readonly, "%d\n",
65 (atomic_read(&unit->status) &
66 ZFCP_STATUS_UNIT_READONLY) != 0);
67
68#define ZFCP_SYSFS_FAILED(_feat_def, _feat, _adapter, _mod_id, _reopen_id) \
69static ssize_t zfcp_sysfs_##_feat##_failed_show(struct device *dev, \
70 struct device_attribute *attr, \
71 char *buf) \
72{ \
73 struct _feat_def *_feat = dev_get_drvdata(dev); \
74 \
75 if (atomic_read(&_feat->status) & ZFCP_STATUS_COMMON_ERP_FAILED) \
76 return sprintf(buf, "1\n"); \
77 else \
78 return sprintf(buf, "0\n"); \
79} \
80static ssize_t zfcp_sysfs_##_feat##_failed_store(struct device *dev, \
81 struct device_attribute *attr,\
82 const char *buf, size_t count)\
83{ \
84 struct _feat_def *_feat = dev_get_drvdata(dev); \
85 unsigned long val; \
86 int retval = 0; \
87 \
88 down(&zfcp_data.config_sema); \
89 if (atomic_read(&_feat->status) & ZFCP_STATUS_COMMON_REMOVE) { \
90 retval = -EBUSY; \
91 goto out; \
92 } \
93 \
94 if (strict_strtoul(buf, 0, &val) || val != 0) { \
95 retval = -EINVAL; \
96 goto out; \
97 } \
98 \
99 zfcp_erp_modify_##_feat##_status(_feat, _mod_id, NULL, \
100 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);\
101 zfcp_erp_##_feat##_reopen(_feat, ZFCP_STATUS_COMMON_ERP_FAILED, \
102 _reopen_id, NULL); \
103 zfcp_erp_wait(_adapter); \
104out: \
105 up(&zfcp_data.config_sema); \
106 return retval ? retval : (ssize_t) count; \
107} \
108static ZFCP_DEV_ATTR(_feat, failed, S_IWUSR | S_IRUGO, \
109 zfcp_sysfs_##_feat##_failed_show, \
110 zfcp_sysfs_##_feat##_failed_store);
111
112ZFCP_SYSFS_FAILED(zfcp_adapter, adapter, adapter, 44, 93);
113ZFCP_SYSFS_FAILED(zfcp_port, port, port->adapter, 45, 96);
114ZFCP_SYSFS_FAILED(zfcp_unit, unit, unit->port->adapter, 46, 97);
115
116static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev,
117 struct device_attribute *attr,
118 const char *buf, size_t count)
119{
120 struct zfcp_adapter *adapter = dev_get_drvdata(dev);
121 int ret;
122
123 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_REMOVE)
124 return -EBUSY;
125
126 ret = zfcp_scan_ports(adapter);
127 return ret ? ret : (ssize_t) count;
128}
129static ZFCP_DEV_ATTR(adapter, port_rescan, S_IWUSR, NULL,
130 zfcp_sysfs_port_rescan_store);
131
132static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,
133 struct device_attribute *attr,
134 const char *buf, size_t count)
135{
136 struct zfcp_adapter *adapter = dev_get_drvdata(dev);
137 struct zfcp_port *port;
138 wwn_t wwpn;
139 int retval = 0;
140
141 down(&zfcp_data.config_sema);
142 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_REMOVE) {
143 retval = -EBUSY;
144 goto out;
145 }
146
147 if (strict_strtoull(buf, 0, &wwpn)) {
148 retval = -EINVAL;
149 goto out;
150 }
151
152 write_lock_irq(&zfcp_data.config_lock);
153 port = zfcp_get_port_by_wwpn(adapter, wwpn);
154 if (port && (atomic_read(&port->refcount) == 0)) {
155 zfcp_port_get(port);
156 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
157 list_move(&port->list, &adapter->port_remove_lh);
158 } else
159 port = NULL;
160 write_unlock_irq(&zfcp_data.config_lock);
161
162 if (!port) {
163 retval = -ENXIO;
164 goto out;
165 }
166
167 zfcp_erp_port_shutdown(port, 0, 92, NULL);
168 zfcp_erp_wait(adapter);
169 zfcp_port_put(port);
170 zfcp_port_dequeue(port);
171 out:
172 up(&zfcp_data.config_sema);
173 return retval ? retval : (ssize_t) count;
174}
175static ZFCP_DEV_ATTR(adapter, port_remove, S_IWUSR, NULL,
176 zfcp_sysfs_port_remove_store);
177
178static struct attribute *zfcp_adapter_attrs[] = {
179 &dev_attr_adapter_failed.attr,
180 &dev_attr_adapter_in_recovery.attr,
181 &dev_attr_adapter_port_remove.attr,
182 &dev_attr_adapter_port_rescan.attr,
183 &dev_attr_adapter_peer_wwnn.attr,
184 &dev_attr_adapter_peer_wwpn.attr,
185 &dev_attr_adapter_peer_d_id.attr,
186 &dev_attr_adapter_card_version.attr,
187 &dev_attr_adapter_lic_version.attr,
188 &dev_attr_adapter_status.attr,
189 &dev_attr_adapter_hardware_version.attr,
190 NULL
191};
192
193struct attribute_group zfcp_sysfs_adapter_attrs = {
194 .attrs = zfcp_adapter_attrs,
195};
196
197static ssize_t zfcp_sysfs_unit_add_store(struct device *dev,
198 struct device_attribute *attr,
199 const char *buf, size_t count)
200{
201 struct zfcp_port *port = dev_get_drvdata(dev);
202 struct zfcp_unit *unit;
203 fcp_lun_t fcp_lun;
204 int retval = -EINVAL;
205
206 down(&zfcp_data.config_sema);
207 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_REMOVE) {
208 retval = -EBUSY;
209 goto out;
210 }
211
212 if (strict_strtoull(buf, 0, &fcp_lun))
213 goto out;
214
215 unit = zfcp_unit_enqueue(port, fcp_lun);
216 if (IS_ERR(unit))
217 goto out;
218
219 retval = 0;
220
221 zfcp_erp_unit_reopen(unit, 0, 94, NULL);
222 zfcp_erp_wait(unit->port->adapter);
223 zfcp_unit_put(unit);
224out:
225 up(&zfcp_data.config_sema);
226 return retval ? retval : (ssize_t) count;
227}
228static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
229
230static ssize_t zfcp_sysfs_unit_remove_store(struct device *dev,
231 struct device_attribute *attr,
232 const char *buf, size_t count)
233{
234 struct zfcp_port *port = dev_get_drvdata(dev);
235 struct zfcp_unit *unit;
236 fcp_lun_t fcp_lun;
237 int retval = 0;
238
239 down(&zfcp_data.config_sema);
240 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_REMOVE) {
241 retval = -EBUSY;
242 goto out;
243 }
244
245 if (strict_strtoull(buf, 0, &fcp_lun)) {
246 retval = -EINVAL;
247 goto out;
248 }
249
250 write_lock_irq(&zfcp_data.config_lock);
251 unit = zfcp_get_unit_by_lun(port, fcp_lun);
252 if (unit && (atomic_read(&unit->refcount) == 0)) {
253 zfcp_unit_get(unit);
254 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
255 list_move(&unit->list, &port->unit_remove_lh);
256 } else
257 unit = NULL;
258
259 write_unlock_irq(&zfcp_data.config_lock);
260
261 if (!unit) {
262 retval = -ENXIO;
263 goto out;
264 }
265
266 zfcp_erp_unit_shutdown(unit, 0, 95, NULL);
267 zfcp_erp_wait(unit->port->adapter);
268 zfcp_unit_put(unit);
269 zfcp_unit_dequeue(unit);
270out:
271 up(&zfcp_data.config_sema);
272 return retval ? retval : (ssize_t) count;
273}
274static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
275
276static struct attribute *zfcp_port_ns_attrs[] = {
277 &dev_attr_port_failed.attr,
278 &dev_attr_port_in_recovery.attr,
279 &dev_attr_port_status.attr,
280 &dev_attr_port_access_denied.attr,
281 NULL
282};
283
284/**
285 * zfcp_sysfs_ns_port_attrs - sysfs attributes for nameserver
286 */
287struct attribute_group zfcp_sysfs_ns_port_attrs = {
288 .attrs = zfcp_port_ns_attrs,
289};
290
291static struct attribute *zfcp_port_no_ns_attrs[] = {
292 &dev_attr_unit_add.attr,
293 &dev_attr_unit_remove.attr,
294 &dev_attr_port_failed.attr,
295 &dev_attr_port_in_recovery.attr,
296 &dev_attr_port_status.attr,
297 &dev_attr_port_access_denied.attr,
298 NULL
299};
300
301/**
302 * zfcp_sysfs_port_attrs - sysfs attributes for all other ports
303 */
304struct attribute_group zfcp_sysfs_port_attrs = {
305 .attrs = zfcp_port_no_ns_attrs,
306};
307
308static struct attribute *zfcp_unit_attrs[] = {
309 &dev_attr_unit_failed.attr,
310 &dev_attr_unit_in_recovery.attr,
311 &dev_attr_unit_status.attr,
312 &dev_attr_unit_access_denied.attr,
313 &dev_attr_unit_access_shared.attr,
314 &dev_attr_unit_access_readonly.attr,
315 NULL
316};
317
318struct attribute_group zfcp_sysfs_unit_attrs = {
319 .attrs = zfcp_unit_attrs,
320};
321
322#define ZFCP_DEFINE_LATENCY_ATTR(_name) \
323static ssize_t \
324zfcp_sysfs_unit_##_name##_latency_show(struct device *dev, \
325 struct device_attribute *attr, \
326 char *buf) { \
327 struct scsi_device *sdev = to_scsi_device(dev); \
328 struct zfcp_unit *unit = sdev->hostdata; \
329 struct zfcp_latencies *lat = &unit->latencies; \
330 struct zfcp_adapter *adapter = unit->port->adapter; \
331 unsigned long flags; \
332 unsigned long long fsum, fmin, fmax, csum, cmin, cmax, cc; \
333 \
334 spin_lock_irqsave(&lat->lock, flags); \
335 fsum = lat->_name.fabric.sum * adapter->timer_ticks; \
336 fmin = lat->_name.fabric.min * adapter->timer_ticks; \
337 fmax = lat->_name.fabric.max * adapter->timer_ticks; \
338 csum = lat->_name.channel.sum * adapter->timer_ticks; \
339 cmin = lat->_name.channel.min * adapter->timer_ticks; \
340 cmax = lat->_name.channel.max * adapter->timer_ticks; \
341 cc = lat->_name.counter; \
342 spin_unlock_irqrestore(&lat->lock, flags); \
343 \
344 do_div(fsum, 1000); \
345 do_div(fmin, 1000); \
346 do_div(fmax, 1000); \
347 do_div(csum, 1000); \
348 do_div(cmin, 1000); \
349 do_div(cmax, 1000); \
350 \
351 return sprintf(buf, "%llu %llu %llu %llu %llu %llu %llu\n", \
352 fmin, fmax, fsum, cmin, cmax, csum, cc); \
353} \
354static ssize_t \
355zfcp_sysfs_unit_##_name##_latency_store(struct device *dev, \
356 struct device_attribute *attr, \
357 const char *buf, size_t count) \
358{ \
359 struct scsi_device *sdev = to_scsi_device(dev); \
360 struct zfcp_unit *unit = sdev->hostdata; \
361 struct zfcp_latencies *lat = &unit->latencies; \
362 unsigned long flags; \
363 \
364 spin_lock_irqsave(&lat->lock, flags); \
365 lat->_name.fabric.sum = 0; \
366 lat->_name.fabric.min = 0xFFFFFFFF; \
367 lat->_name.fabric.max = 0; \
368 lat->_name.channel.sum = 0; \
369 lat->_name.channel.min = 0xFFFFFFFF; \
370 lat->_name.channel.max = 0; \
371 lat->_name.counter = 0; \
372 spin_unlock_irqrestore(&lat->lock, flags); \
373 \
374 return (ssize_t) count; \
375} \
376static DEVICE_ATTR(_name##_latency, S_IWUSR | S_IRUGO, \
377 zfcp_sysfs_unit_##_name##_latency_show, \
378 zfcp_sysfs_unit_##_name##_latency_store);
379
380ZFCP_DEFINE_LATENCY_ATTR(read);
381ZFCP_DEFINE_LATENCY_ATTR(write);
382ZFCP_DEFINE_LATENCY_ATTR(cmd);
383
384#define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
385static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \
386 struct device_attribute *attr,\
387 char *buf) \
388{ \
389 struct scsi_device *sdev = to_scsi_device(dev); \
390 struct zfcp_unit *unit = sdev->hostdata; \
391 \
392 return sprintf(buf, _format, _value); \
393} \
394static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
395
396ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n",
397 unit->port->adapter->ccw_device->dev.bus_id);
398ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", unit->port->wwpn);
399ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", unit->fcp_lun);
400
401struct device_attribute *zfcp_sysfs_sdev_attrs[] = {
402 &dev_attr_fcp_lun,
403 &dev_attr_wwpn,
404 &dev_attr_hba_id,
405 &dev_attr_read_latency,
406 &dev_attr_write_latency,
407 &dev_attr_cmd_latency,
408 NULL
409};
410
411static ssize_t zfcp_sysfs_adapter_util_show(struct device *dev,
412 struct device_attribute *attr,
413 char *buf)
414{
415 struct Scsi_Host *scsi_host = dev_to_shost(dev);
416 struct fsf_qtcb_bottom_port *qtcb_port;
417 struct zfcp_adapter *adapter;
418 int retval;
419
420 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
421 if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA))
422 return -EOPNOTSUPP;
423
424 qtcb_port = kzalloc(sizeof(struct fsf_qtcb_bottom_port), GFP_KERNEL);
425 if (!qtcb_port)
426 return -ENOMEM;
427
428 retval = zfcp_fsf_exchange_port_data_sync(adapter, qtcb_port);
429 if (!retval)
430 retval = sprintf(buf, "%u %u %u\n", qtcb_port->cp_util,
431 qtcb_port->cb_util, qtcb_port->a_util);
432 kfree(qtcb_port);
433 return retval;
434}
435static DEVICE_ATTR(utilization, S_IRUGO, zfcp_sysfs_adapter_util_show, NULL);
436
437static int zfcp_sysfs_adapter_ex_config(struct device *dev,
438 struct fsf_statistics_info *stat_inf)
439{
440 struct Scsi_Host *scsi_host = dev_to_shost(dev);
441 struct fsf_qtcb_bottom_config *qtcb_config;
442 struct zfcp_adapter *adapter;
443 int retval;
444
445 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
446 if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA))
447 return -EOPNOTSUPP;
448
449 qtcb_config = kzalloc(sizeof(struct fsf_qtcb_bottom_config),
450 GFP_KERNEL);
451 if (!qtcb_config)
452 return -ENOMEM;
453
454 retval = zfcp_fsf_exchange_config_data_sync(adapter, qtcb_config);
455 if (!retval)
456 *stat_inf = qtcb_config->stat_info;
457
458 kfree(qtcb_config);
459 return retval;
460}
461
462#define ZFCP_SHOST_ATTR(_name, _format, _arg...) \
463static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
464 struct device_attribute *attr,\
465 char *buf) \
466{ \
467 struct fsf_statistics_info stat_info; \
468 int retval; \
469 \
470 retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info); \
471 if (retval) \
472 return retval; \
473 \
474 return sprintf(buf, _format, ## _arg); \
475} \
476static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
477
478ZFCP_SHOST_ATTR(requests, "%llu %llu %llu\n",
479 (unsigned long long) stat_info.input_req,
480 (unsigned long long) stat_info.output_req,
481 (unsigned long long) stat_info.control_req);
482
483ZFCP_SHOST_ATTR(megabytes, "%llu %llu\n",
484 (unsigned long long) stat_info.input_mb,
485 (unsigned long long) stat_info.output_mb);
486
487ZFCP_SHOST_ATTR(seconds_active, "%llu\n",
488 (unsigned long long) stat_info.seconds_act);
489
490struct device_attribute *zfcp_sysfs_shost_attrs[] = {
491 &dev_attr_utilization,
492 &dev_attr_requests,
493 &dev_attr_megabytes,
494 &dev_attr_seconds_active,
495 NULL
496};
diff --git a/drivers/s390/scsi/zfcp_sysfs_adapter.c b/drivers/s390/scsi/zfcp_sysfs_adapter.c
deleted file mode 100644
index 3985f1f1c291..000000000000
--- a/drivers/s390/scsi/zfcp_sysfs_adapter.c
+++ /dev/null
@@ -1,232 +0,0 @@
1/*
2 * zfcp device driver
3 *
4 * sysfs attributes for CCW device.
5 *
6 * Copyright IBM Corporation 2002, 2008
7 */
8
9#include "zfcp_ext.h"
10
11/**
12 * ZFCP_DEFINE_ADAPTER_ATTR
13 * @_name: name of show attribute
14 * @_format: format string
15 * @_value: value to print
16 *
17 * Generates attributes for an adapter.
18 */
19#define ZFCP_DEFINE_ADAPTER_ATTR(_name, _format, _value) \
20static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, struct device_attribute *attr, \
21 char *buf) \
22{ \
23 struct zfcp_adapter *adapter; \
24 \
25 adapter = dev_get_drvdata(dev); \
26 return sprintf(buf, _format, _value); \
27} \
28 \
29static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
30
31ZFCP_DEFINE_ADAPTER_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
32ZFCP_DEFINE_ADAPTER_ATTR(peer_wwnn, "0x%016llx\n", adapter->peer_wwnn);
33ZFCP_DEFINE_ADAPTER_ATTR(peer_wwpn, "0x%016llx\n", adapter->peer_wwpn);
34ZFCP_DEFINE_ADAPTER_ATTR(peer_d_id, "0x%06x\n", adapter->peer_d_id);
35ZFCP_DEFINE_ADAPTER_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
36ZFCP_DEFINE_ADAPTER_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
37ZFCP_DEFINE_ADAPTER_ATTR(hardware_version, "0x%08x\n",
38 adapter->hardware_version);
39ZFCP_DEFINE_ADAPTER_ATTR(in_recovery, "%d\n", atomic_test_mask
40 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status));
41
42/**
43 * zfcp_sysfs_port_rescan - trigger manual port rescan
44 * @dev: pointer to belonging device
45 * @attr: pointer to struct device_attribute
46 * @buf: pointer to input buffer
47 * @count: number of bytes in buffer
48 */
49static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev,
50 struct device_attribute *attr,
51 const char *buf, size_t count)
52{
53 struct zfcp_adapter *adapter;
54 int ret;
55
56 adapter = dev_get_drvdata(dev);
57 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status))
58 return -EBUSY;
59
60 ret = zfcp_scan_ports(adapter);
61
62 return ret ? ret : (ssize_t) count;
63}
64static DEVICE_ATTR(port_rescan, S_IWUSR, NULL, zfcp_sysfs_port_rescan_store);
65
66/**
67 * zfcp_sysfs_port_remove_store - remove a port from sysfs tree
68 * @dev: pointer to belonging device
69 * @buf: pointer to input buffer
70 * @count: number of bytes in buffer
71 *
72 * Store function of the "port_remove" attribute of an adapter.
73 */
74static ssize_t
75zfcp_sysfs_port_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
76{
77 struct zfcp_adapter *adapter;
78 struct zfcp_port *port;
79 wwn_t wwpn;
80 char *endp;
81 int retval = 0;
82
83 down(&zfcp_data.config_sema);
84
85 adapter = dev_get_drvdata(dev);
86 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
87 retval = -EBUSY;
88 goto out;
89 }
90
91 wwpn = simple_strtoull(buf, &endp, 0);
92 if ((endp + 1) < (buf + count)) {
93 retval = -EINVAL;
94 goto out;
95 }
96
97 write_lock_irq(&zfcp_data.config_lock);
98 port = zfcp_get_port_by_wwpn(adapter, wwpn);
99 if (port && (atomic_read(&port->refcount) == 0)) {
100 zfcp_port_get(port);
101 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
102 list_move(&port->list, &adapter->port_remove_lh);
103 }
104 else {
105 port = NULL;
106 }
107 write_unlock_irq(&zfcp_data.config_lock);
108
109 if (!port) {
110 retval = -ENXIO;
111 goto out;
112 }
113
114 zfcp_erp_port_shutdown(port, 0, 92, NULL);
115 zfcp_erp_wait(adapter);
116 zfcp_port_put(port);
117 zfcp_port_dequeue(port);
118 out:
119 up(&zfcp_data.config_sema);
120 return retval ? retval : (ssize_t) count;
121}
122
123static DEVICE_ATTR(port_remove, S_IWUSR, NULL, zfcp_sysfs_port_remove_store);
124
125/**
126 * zfcp_sysfs_adapter_failed_store - failed state of adapter
127 * @dev: pointer to belonging device
128 * @buf: pointer to input buffer
129 * @count: number of bytes in buffer
130 *
131 * Store function of the "failed" attribute of an adapter.
132 * If a "0" gets written to "failed", error recovery will be
133 * started for the belonging adapter.
134 */
135static ssize_t
136zfcp_sysfs_adapter_failed_store(struct device *dev, struct device_attribute *attr,
137 const char *buf, size_t count)
138{
139 struct zfcp_adapter *adapter;
140 unsigned int val;
141 char *endp;
142 int retval = 0;
143
144 down(&zfcp_data.config_sema);
145
146 adapter = dev_get_drvdata(dev);
147 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
148 retval = -EBUSY;
149 goto out;
150 }
151
152 val = simple_strtoul(buf, &endp, 0);
153 if (((endp + 1) < (buf + count)) || (val != 0)) {
154 retval = -EINVAL;
155 goto out;
156 }
157
158 zfcp_erp_modify_adapter_status(adapter, 44, NULL,
159 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
160 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 93,
161 NULL);
162 zfcp_erp_wait(adapter);
163 out:
164 up(&zfcp_data.config_sema);
165 return retval ? retval : (ssize_t) count;
166}
167
168/**
169 * zfcp_sysfs_adapter_failed_show - failed state of adapter
170 * @dev: pointer to belonging device
171 * @buf: pointer to input buffer
172 *
173 * Show function of "failed" attribute of adapter. Will be
174 * "0" if adapter is working, otherwise "1".
175 */
176static ssize_t
177zfcp_sysfs_adapter_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
178{
179 struct zfcp_adapter *adapter;
180
181 adapter = dev_get_drvdata(dev);
182 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status))
183 return sprintf(buf, "1\n");
184 else
185 return sprintf(buf, "0\n");
186}
187
188static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_adapter_failed_show,
189 zfcp_sysfs_adapter_failed_store);
190
191static struct attribute *zfcp_adapter_attrs[] = {
192 &dev_attr_failed.attr,
193 &dev_attr_in_recovery.attr,
194 &dev_attr_port_remove.attr,
195 &dev_attr_port_rescan.attr,
196 &dev_attr_peer_wwnn.attr,
197 &dev_attr_peer_wwpn.attr,
198 &dev_attr_peer_d_id.attr,
199 &dev_attr_card_version.attr,
200 &dev_attr_lic_version.attr,
201 &dev_attr_status.attr,
202 &dev_attr_hardware_version.attr,
203 NULL
204};
205
206static struct attribute_group zfcp_adapter_attr_group = {
207 .attrs = zfcp_adapter_attrs,
208};
209
210/**
211 * zfcp_sysfs_create_adapter_files - create sysfs adapter files
212 * @dev: pointer to belonging device
213 *
214 * Create all attributes of the sysfs representation of an adapter.
215 */
216int
217zfcp_sysfs_adapter_create_files(struct device *dev)
218{
219 return sysfs_create_group(&dev->kobj, &zfcp_adapter_attr_group);
220}
221
222/**
223 * zfcp_sysfs_remove_adapter_files - remove sysfs adapter files
224 * @dev: pointer to belonging device
225 *
226 * Remove all attributes of the sysfs representation of an adapter.
227 */
228void
229zfcp_sysfs_adapter_remove_files(struct device *dev)
230{
231 sysfs_remove_group(&dev->kobj, &zfcp_adapter_attr_group);
232}
diff --git a/drivers/s390/scsi/zfcp_sysfs_port.c b/drivers/s390/scsi/zfcp_sysfs_port.c
deleted file mode 100644
index e183ff8bdb2a..000000000000
--- a/drivers/s390/scsi/zfcp_sysfs_port.c
+++ /dev/null
@@ -1,278 +0,0 @@
1/*
2 * zfcp device driver
3 *
4 * sysfs attributes for zfcp port.
5 *
6 * Copyright IBM Corporation 2002, 2008
7 */
8
9#include "zfcp_ext.h"
10
11/**
12 * zfcp_sysfs_port_release - gets called when a struct device port is released
13 * @dev: pointer to belonging device
14 */
15void
16zfcp_sysfs_port_release(struct device *dev)
17{
18 kfree(dev);
19}
20
21/**
22 * ZFCP_DEFINE_PORT_ATTR
23 * @_name: name of show attribute
24 * @_format: format string
25 * @_value: value to print
26 *
27 * Generates attributes for a port.
28 */
29#define ZFCP_DEFINE_PORT_ATTR(_name, _format, _value) \
30static ssize_t zfcp_sysfs_port_##_name##_show(struct device *dev, struct device_attribute *attr, \
31 char *buf) \
32{ \
33 struct zfcp_port *port; \
34 \
35 port = dev_get_drvdata(dev); \
36 return sprintf(buf, _format, _value); \
37} \
38 \
39static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_port_##_name##_show, NULL);
40
41ZFCP_DEFINE_PORT_ATTR(status, "0x%08x\n", atomic_read(&port->status));
42ZFCP_DEFINE_PORT_ATTR(in_recovery, "%d\n", atomic_test_mask
43 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status));
44ZFCP_DEFINE_PORT_ATTR(access_denied, "%d\n", atomic_test_mask
45 (ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status));
46
47/**
48 * zfcp_sysfs_unit_add_store - add a unit to sysfs tree
49 * @dev: pointer to belonging device
50 * @buf: pointer to input buffer
51 * @count: number of bytes in buffer
52 *
53 * Store function of the "unit_add" attribute of a port.
54 */
55static ssize_t
56zfcp_sysfs_unit_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
57{
58 fcp_lun_t fcp_lun;
59 char *endp;
60 struct zfcp_port *port;
61 struct zfcp_unit *unit;
62 int retval = -EINVAL;
63
64 down(&zfcp_data.config_sema);
65
66 port = dev_get_drvdata(dev);
67 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
68 retval = -EBUSY;
69 goto out;
70 }
71
72 fcp_lun = simple_strtoull(buf, &endp, 0);
73 if ((endp + 1) < (buf + count))
74 goto out;
75
76 unit = zfcp_unit_enqueue(port, fcp_lun);
77 if (IS_ERR(unit))
78 goto out;
79
80 retval = 0;
81
82 zfcp_erp_unit_reopen(unit, 0, 94, NULL);
83 zfcp_erp_wait(unit->port->adapter);
84 zfcp_unit_put(unit);
85 out:
86 up(&zfcp_data.config_sema);
87 return retval ? retval : (ssize_t) count;
88}
89
90static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
91
92/**
93 * zfcp_sysfs_unit_remove_store - remove a unit from sysfs tree
94 * @dev: pointer to belonging device
95 * @buf: pointer to input buffer
96 * @count: number of bytes in buffer
97 */
98static ssize_t
99zfcp_sysfs_unit_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
100{
101 struct zfcp_port *port;
102 struct zfcp_unit *unit;
103 fcp_lun_t fcp_lun;
104 char *endp;
105 int retval = 0;
106
107 down(&zfcp_data.config_sema);
108
109 port = dev_get_drvdata(dev);
110 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
111 retval = -EBUSY;
112 goto out;
113 }
114
115 fcp_lun = simple_strtoull(buf, &endp, 0);
116 if ((endp + 1) < (buf + count)) {
117 retval = -EINVAL;
118 goto out;
119 }
120
121 write_lock_irq(&zfcp_data.config_lock);
122 unit = zfcp_get_unit_by_lun(port, fcp_lun);
123 if (unit && (atomic_read(&unit->refcount) == 0)) {
124 zfcp_unit_get(unit);
125 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
126 list_move(&unit->list, &port->unit_remove_lh);
127 }
128 else {
129 unit = NULL;
130 }
131 write_unlock_irq(&zfcp_data.config_lock);
132
133 if (!unit) {
134 retval = -ENXIO;
135 goto out;
136 }
137
138 zfcp_erp_unit_shutdown(unit, 0, 95, NULL);
139 zfcp_erp_wait(unit->port->adapter);
140 zfcp_unit_put(unit);
141 zfcp_unit_dequeue(unit);
142 out:
143 up(&zfcp_data.config_sema);
144 return retval ? retval : (ssize_t) count;
145}
146
147static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
148
149/**
150 * zfcp_sysfs_port_failed_store - failed state of port
151 * @dev: pointer to belonging device
152 * @buf: pointer to input buffer
153 * @count: number of bytes in buffer
154 *
155 * Store function of the "failed" attribute of a port.
156 * If a "0" gets written to "failed", error recovery will be
157 * started for the belonging port.
158 */
159static ssize_t
160zfcp_sysfs_port_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
161{
162 struct zfcp_port *port;
163 unsigned int val;
164 char *endp;
165 int retval = 0;
166
167 down(&zfcp_data.config_sema);
168
169 port = dev_get_drvdata(dev);
170 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
171 retval = -EBUSY;
172 goto out;
173 }
174
175 val = simple_strtoul(buf, &endp, 0);
176 if (((endp + 1) < (buf + count)) || (val != 0)) {
177 retval = -EINVAL;
178 goto out;
179 }
180
181 zfcp_erp_modify_port_status(port, 45, NULL,
182 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
183 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, 96, NULL);
184 zfcp_erp_wait(port->adapter);
185 out:
186 up(&zfcp_data.config_sema);
187 return retval ? retval : (ssize_t) count;
188}
189
190/**
191 * zfcp_sysfs_port_failed_show - failed state of port
192 * @dev: pointer to belonging device
193 * @buf: pointer to input buffer
194 *
195 * Show function of "failed" attribute of port. Will be
196 * "0" if port is working, otherwise "1".
197 */
198static ssize_t
199zfcp_sysfs_port_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
200{
201 struct zfcp_port *port;
202
203 port = dev_get_drvdata(dev);
204 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status))
205 return sprintf(buf, "1\n");
206 else
207 return sprintf(buf, "0\n");
208}
209
210static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_port_failed_show,
211 zfcp_sysfs_port_failed_store);
212
213/**
214 * zfcp_port_common_attrs
215 * sysfs attributes that are common for all kind of fc ports.
216 */
217static struct attribute *zfcp_port_common_attrs[] = {
218 &dev_attr_failed.attr,
219 &dev_attr_in_recovery.attr,
220 &dev_attr_status.attr,
221 &dev_attr_access_denied.attr,
222 NULL
223};
224
225static struct attribute_group zfcp_port_common_attr_group = {
226 .attrs = zfcp_port_common_attrs,
227};
228
229/**
230 * zfcp_port_no_ns_attrs
231 * sysfs attributes not to be used for nameserver ports.
232 */
233static struct attribute *zfcp_port_no_ns_attrs[] = {
234 &dev_attr_unit_add.attr,
235 &dev_attr_unit_remove.attr,
236 NULL
237};
238
239static struct attribute_group zfcp_port_no_ns_attr_group = {
240 .attrs = zfcp_port_no_ns_attrs,
241};
242
243/**
244 * zfcp_sysfs_port_create_files - create sysfs port files
245 * @dev: pointer to belonging device
246 *
247 * Create all attributes of the sysfs representation of a port.
248 */
249int
250zfcp_sysfs_port_create_files(struct device *dev, u32 flags)
251{
252 int retval;
253
254 retval = sysfs_create_group(&dev->kobj, &zfcp_port_common_attr_group);
255
256 if ((flags & ZFCP_STATUS_PORT_WKA) || retval)
257 return retval;
258
259 retval = sysfs_create_group(&dev->kobj, &zfcp_port_no_ns_attr_group);
260 if (retval)
261 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
262
263 return retval;
264}
265
266/**
267 * zfcp_sysfs_port_remove_files - remove sysfs port files
268 * @dev: pointer to belonging device
269 *
270 * Remove all attributes of the sysfs representation of a port.
271 */
272void
273zfcp_sysfs_port_remove_files(struct device *dev, u32 flags)
274{
275 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
276 if (!(flags & ZFCP_STATUS_PORT_WKA))
277 sysfs_remove_group(&dev->kobj, &zfcp_port_no_ns_attr_group);
278}
diff --git a/drivers/s390/scsi/zfcp_sysfs_unit.c b/drivers/s390/scsi/zfcp_sysfs_unit.c
deleted file mode 100644
index 587d9e3e12d2..000000000000
--- a/drivers/s390/scsi/zfcp_sysfs_unit.c
+++ /dev/null
@@ -1,150 +0,0 @@
1/*
2 * zfcp device driver
3 *
4 * sysfs interface for zfcp unit.
5 *
6 * Copyright IBM Corporation 2002, 2008
7 */
8
9#include "zfcp_ext.h"
10
11/**
12 * zfcp_sysfs_unit_release - gets called when a struct device unit is released
13 * @dev: pointer to belonging device
14 */
15void
16zfcp_sysfs_unit_release(struct device *dev)
17{
18 kfree(dev);
19}
20
21/**
22 * ZFCP_DEFINE_UNIT_ATTR
23 * @_name: name of show attribute
24 * @_format: format string
25 * @_value: value to print
26 *
27 * Generates attribute for a unit.
28 */
29#define ZFCP_DEFINE_UNIT_ATTR(_name, _format, _value) \
30static ssize_t zfcp_sysfs_unit_##_name##_show(struct device *dev, struct device_attribute *attr, \
31 char *buf) \
32{ \
33 struct zfcp_unit *unit; \
34 \
35 unit = dev_get_drvdata(dev); \
36 return sprintf(buf, _format, _value); \
37} \
38 \
39static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_unit_##_name##_show, NULL);
40
41ZFCP_DEFINE_UNIT_ATTR(status, "0x%08x\n", atomic_read(&unit->status));
42ZFCP_DEFINE_UNIT_ATTR(in_recovery, "%d\n", atomic_test_mask
43 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status));
44ZFCP_DEFINE_UNIT_ATTR(access_denied, "%d\n", atomic_test_mask
45 (ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status));
46ZFCP_DEFINE_UNIT_ATTR(access_shared, "%d\n", atomic_test_mask
47 (ZFCP_STATUS_UNIT_SHARED, &unit->status));
48ZFCP_DEFINE_UNIT_ATTR(access_readonly, "%d\n", atomic_test_mask
49 (ZFCP_STATUS_UNIT_READONLY, &unit->status));
50
51/**
52 * zfcp_sysfs_unit_failed_store - failed state of unit
53 * @dev: pointer to belonging device
54 * @buf: pointer to input buffer
55 * @count: number of bytes in buffer
56 *
57 * Store function of the "failed" attribute of a unit.
58 * If a "0" gets written to "failed", error recovery will be
59 * started for the belonging unit.
60 */
61static ssize_t
62zfcp_sysfs_unit_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
63{
64 struct zfcp_unit *unit;
65 unsigned int val;
66 char *endp;
67 int retval = 0;
68
69 down(&zfcp_data.config_sema);
70 unit = dev_get_drvdata(dev);
71 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) {
72 retval = -EBUSY;
73 goto out;
74 }
75
76 val = simple_strtoul(buf, &endp, 0);
77 if (((endp + 1) < (buf + count)) || (val != 0)) {
78 retval = -EINVAL;
79 goto out;
80 }
81
82 zfcp_erp_modify_unit_status(unit, 46, NULL,
83 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
84 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, 97, NULL);
85 zfcp_erp_wait(unit->port->adapter);
86 out:
87 up(&zfcp_data.config_sema);
88 return retval ? retval : (ssize_t) count;
89}
90
91/**
92 * zfcp_sysfs_unit_failed_show - failed state of unit
93 * @dev: pointer to belonging device
94 * @buf: pointer to input buffer
95 *
96 * Show function of "failed" attribute of unit. Will be
97 * "0" if unit is working, otherwise "1".
98 */
99static ssize_t
100zfcp_sysfs_unit_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
101{
102 struct zfcp_unit *unit;
103
104 unit = dev_get_drvdata(dev);
105 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status))
106 return sprintf(buf, "1\n");
107 else
108 return sprintf(buf, "0\n");
109}
110
111static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show,
112 zfcp_sysfs_unit_failed_store);
113
114static struct attribute *zfcp_unit_attrs[] = {
115 &dev_attr_failed.attr,
116 &dev_attr_in_recovery.attr,
117 &dev_attr_status.attr,
118 &dev_attr_access_denied.attr,
119 &dev_attr_access_shared.attr,
120 &dev_attr_access_readonly.attr,
121 NULL
122};
123
124static struct attribute_group zfcp_unit_attr_group = {
125 .attrs = zfcp_unit_attrs,
126};
127
128/**
129 * zfcp_sysfs_create_unit_files - create sysfs unit files
130 * @dev: pointer to belonging device
131 *
132 * Create all attributes of the sysfs representation of a unit.
133 */
134int
135zfcp_sysfs_unit_create_files(struct device *dev)
136{
137 return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group);
138}
139
140/**
141 * zfcp_sysfs_remove_unit_files - remove sysfs unit files
142 * @dev: pointer to belonging device
143 *
144 * Remove all attributes of the sysfs representation of a unit.
145 */
146void
147zfcp_sysfs_unit_remove_files(struct device *dev)
148{
149 sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group);
150}