kbuild: Fix instrumentation removal breakage on avr32
[wrt350n-kernel.git] / drivers / s390 / scsi / zfcp_sysfs_unit.c
blob63f75ee95c338e588e005228d2b2b18aee204862
1 /*
2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "zfcp_ext.h"
24 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
26 /**
27 * zfcp_sysfs_unit_release - gets called when a struct device unit is released
28 * @dev: pointer to belonging device
30 void
31 zfcp_sysfs_unit_release(struct device *dev)
33 kfree(dev);
36 /**
37 * ZFCP_DEFINE_UNIT_ATTR
38 * @_name: name of show attribute
39 * @_format: format string
40 * @_value: value to print
42 * Generates attribute for a unit.
44 #define ZFCP_DEFINE_UNIT_ATTR(_name, _format, _value) \
45 static ssize_t zfcp_sysfs_unit_##_name##_show(struct device *dev, struct device_attribute *attr, \
46 char *buf) \
47 { \
48 struct zfcp_unit *unit; \
50 unit = dev_get_drvdata(dev); \
51 return sprintf(buf, _format, _value); \
52 } \
54 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_unit_##_name##_show, NULL);
56 ZFCP_DEFINE_UNIT_ATTR(status, "0x%08x\n", atomic_read(&unit->status));
57 ZFCP_DEFINE_UNIT_ATTR(in_recovery, "%d\n", atomic_test_mask
58 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status));
59 ZFCP_DEFINE_UNIT_ATTR(access_denied, "%d\n", atomic_test_mask
60 (ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status));
61 ZFCP_DEFINE_UNIT_ATTR(access_shared, "%d\n", atomic_test_mask
62 (ZFCP_STATUS_UNIT_SHARED, &unit->status));
63 ZFCP_DEFINE_UNIT_ATTR(access_readonly, "%d\n", atomic_test_mask
64 (ZFCP_STATUS_UNIT_READONLY, &unit->status));
66 /**
67 * zfcp_sysfs_unit_failed_store - failed state of unit
68 * @dev: pointer to belonging device
69 * @buf: pointer to input buffer
70 * @count: number of bytes in buffer
72 * Store function of the "failed" attribute of a unit.
73 * If a "0" gets written to "failed", error recovery will be
74 * started for the belonging unit.
76 static ssize_t
77 zfcp_sysfs_unit_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
79 struct zfcp_unit *unit;
80 unsigned int val;
81 char *endp;
82 int retval = 0;
84 down(&zfcp_data.config_sema);
85 unit = dev_get_drvdata(dev);
86 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) {
87 retval = -EBUSY;
88 goto out;
91 val = simple_strtoul(buf, &endp, 0);
92 if (((endp + 1) < (buf + count)) || (val != 0)) {
93 retval = -EINVAL;
94 goto out;
97 zfcp_erp_modify_unit_status(unit, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
98 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
99 zfcp_erp_wait(unit->port->adapter);
100 out:
101 up(&zfcp_data.config_sema);
102 return retval ? retval : (ssize_t) count;
106 * zfcp_sysfs_unit_failed_show - failed state of unit
107 * @dev: pointer to belonging device
108 * @buf: pointer to input buffer
110 * Show function of "failed" attribute of unit. Will be
111 * "0" if unit is working, otherwise "1".
113 static ssize_t
114 zfcp_sysfs_unit_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
116 struct zfcp_unit *unit;
118 unit = dev_get_drvdata(dev);
119 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status))
120 return sprintf(buf, "1\n");
121 else
122 return sprintf(buf, "0\n");
125 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show,
126 zfcp_sysfs_unit_failed_store);
128 static struct attribute *zfcp_unit_attrs[] = {
129 &dev_attr_failed.attr,
130 &dev_attr_in_recovery.attr,
131 &dev_attr_status.attr,
132 &dev_attr_access_denied.attr,
133 &dev_attr_access_shared.attr,
134 &dev_attr_access_readonly.attr,
135 NULL
138 static struct attribute_group zfcp_unit_attr_group = {
139 .attrs = zfcp_unit_attrs,
143 * zfcp_sysfs_create_unit_files - create sysfs unit files
144 * @dev: pointer to belonging device
146 * Create all attributes of the sysfs representation of a unit.
149 zfcp_sysfs_unit_create_files(struct device *dev)
151 return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group);
155 * zfcp_sysfs_remove_unit_files - remove sysfs unit files
156 * @dev: pointer to belonging device
158 * Remove all attributes of the sysfs representation of a unit.
160 void
161 zfcp_sysfs_unit_remove_files(struct device *dev)
163 sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group);
166 #undef ZFCP_LOG_AREA