initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / s390 / scsi / zfcp_sysfs_unit.c
blobbad3b7f2cd1bfd70ac391dff27e1e3bcec9c3170
1 /*
2 * linux/drivers/s390/scsi/zfcp_sysfs_unit.c
4 * FCP adapter driver for IBM eServer zSeries
6 * sysfs unit related routines
8 * (C) Copyright IBM Corp. 2003, 2004
10 * Authors:
11 * Martin Peschke <mpeschke@de.ibm.com>
12 * Heiko Carstens <heiko.carstens@de.ibm.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define ZFCP_SYSFS_UNIT_C_REVISION "$Revision: 1.27 $"
31 #include "zfcp_ext.h"
33 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
35 /**
36 * zfcp_sysfs_unit_release - gets called when a struct device unit is released
37 * @dev: pointer to belonging device
39 void
40 zfcp_sysfs_unit_release(struct device *dev)
42 kfree(dev);
45 /**
46 * ZFCP_DEFINE_UNIT_ATTR
47 * @_name: name of show attribute
48 * @_format: format string
49 * @_value: value to print
51 * Generates attribute for a unit.
53 #define ZFCP_DEFINE_UNIT_ATTR(_name, _format, _value) \
54 static ssize_t zfcp_sysfs_unit_##_name##_show(struct device *dev, \
55 char *buf) \
56 { \
57 struct zfcp_unit *unit; \
59 unit = dev_get_drvdata(dev); \
60 return sprintf(buf, _format, _value); \
61 } \
63 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_unit_##_name##_show, NULL);
65 ZFCP_DEFINE_UNIT_ATTR(status, "0x%08x\n", atomic_read(&unit->status));
66 ZFCP_DEFINE_UNIT_ATTR(scsi_lun, "0x%x\n", unit->scsi_lun);
67 ZFCP_DEFINE_UNIT_ATTR(in_recovery, "%d\n", atomic_test_mask
68 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status));
70 /**
71 * zfcp_sysfs_unit_failed_store - failed state of unit
72 * @dev: pointer to belonging device
73 * @buf: pointer to input buffer
74 * @count: number of bytes in buffer
76 * Store function of the "failed" attribute of a unit.
77 * If a "0" gets written to "failed", error recovery will be
78 * started for the belonging unit.
80 static ssize_t
81 zfcp_sysfs_unit_failed_store(struct device *dev, const char *buf, size_t count)
83 struct zfcp_unit *unit;
84 unsigned int val;
85 char *endp;
86 int retval = 0;
88 down(&zfcp_data.config_sema);
89 unit = dev_get_drvdata(dev);
90 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) {
91 retval = -EBUSY;
92 goto out;
95 val = simple_strtoul(buf, &endp, 0);
96 if (((endp + 1) < (buf + count)) || (val != 0)) {
97 retval = -EINVAL;
98 goto out;
101 zfcp_erp_modify_unit_status(unit, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
102 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
103 zfcp_erp_wait(unit->port->adapter);
104 out:
105 up(&zfcp_data.config_sema);
106 return retval ? retval : (ssize_t) count;
110 * zfcp_sysfs_unit_failed_show - failed state of unit
111 * @dev: pointer to belonging device
112 * @buf: pointer to input buffer
114 * Show function of "failed" attribute of unit. Will be
115 * "0" if unit is working, otherwise "1".
117 static ssize_t
118 zfcp_sysfs_unit_failed_show(struct device *dev, char *buf)
120 struct zfcp_unit *unit;
122 unit = dev_get_drvdata(dev);
123 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status))
124 return sprintf(buf, "1\n");
125 else
126 return sprintf(buf, "0\n");
129 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show,
130 zfcp_sysfs_unit_failed_store);
132 static struct attribute *zfcp_unit_attrs[] = {
133 &dev_attr_scsi_lun.attr,
134 &dev_attr_failed.attr,
135 &dev_attr_in_recovery.attr,
136 &dev_attr_status.attr,
137 NULL
140 static struct attribute_group zfcp_unit_attr_group = {
141 .attrs = zfcp_unit_attrs,
144 /**
145 * zfcp_sysfs_create_unit_files - create sysfs unit files
146 * @dev: pointer to belonging device
148 * Create all attributes of the sysfs representation of a unit.
151 zfcp_sysfs_unit_create_files(struct device *dev)
153 return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group);
156 /**
157 * zfcp_sysfs_remove_unit_files - remove sysfs unit files
158 * @dev: pointer to belonging device
160 * Remove all attributes of the sysfs representation of a unit.
162 void
163 zfcp_sysfs_unit_remove_files(struct device *dev)
165 sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group);
168 #undef ZFCP_LOG_AREA