[SCSI] zfcp: Rename sbal_last.
[safe/jmp/linux-2.6] / drivers / s390 / scsi / zfcp_sysfs_unit.c
1 /*
2  * This file is part of the zfcp device driver for
3  * FCP adapters for IBM System z9 and zSeries.
4  *
5  * (C) Copyright IBM Corp. 2002, 2006
6  *
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.
11  *
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.
16  *
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.
20  */
21
22 #include "zfcp_ext.h"
23
24 #define ZFCP_LOG_AREA                   ZFCP_LOG_AREA_CONFIG
25
26 /**
27  * zfcp_sysfs_unit_release - gets called when a struct device unit is released
28  * @dev: pointer to belonging device
29  */
30 void
31 zfcp_sysfs_unit_release(struct device *dev)
32 {
33         kfree(dev);
34 }
35
36 /**
37  * ZFCP_DEFINE_UNIT_ATTR
38  * @_name:   name of show attribute
39  * @_format: format string
40  * @_value:  value to print
41  *
42  * Generates attribute for a unit.
43  */
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;                                          \
49                                                                          \
50         unit = dev_get_drvdata(dev);                                     \
51         return sprintf(buf, _format, _value);                            \
52 }                                                                        \
53                                                                          \
54 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_unit_##_name##_show, NULL);
55
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));
65
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
71  *
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.
75  */
76 static ssize_t
77 zfcp_sysfs_unit_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
78 {
79         struct zfcp_unit *unit;
80         unsigned int val;
81         char *endp;
82         int retval = 0;
83
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;
89         }
90
91         val = simple_strtoul(buf, &endp, 0);
92         if (((endp + 1) < (buf + count)) || (val != 0)) {
93                 retval = -EINVAL;
94                 goto out;
95         }
96
97         zfcp_erp_modify_unit_status(unit, 46, NULL,
98                                     ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
99         zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, 97, NULL);
100         zfcp_erp_wait(unit->port->adapter);
101  out:
102         up(&zfcp_data.config_sema);
103         return retval ? retval : (ssize_t) count;
104 }
105
106 /**
107  * zfcp_sysfs_unit_failed_show - failed state of unit
108  * @dev: pointer to belonging device
109  * @buf: pointer to input buffer
110  *
111  * Show function of "failed" attribute of unit. Will be
112  * "0" if unit is working, otherwise "1".
113  */
114 static ssize_t
115 zfcp_sysfs_unit_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
116 {
117         struct zfcp_unit *unit;
118
119         unit = dev_get_drvdata(dev);
120         if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status))
121                 return sprintf(buf, "1\n");
122         else
123                 return sprintf(buf, "0\n");
124 }
125
126 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show,
127                    zfcp_sysfs_unit_failed_store);
128
129 static struct attribute *zfcp_unit_attrs[] = {
130         &dev_attr_failed.attr,
131         &dev_attr_in_recovery.attr,
132         &dev_attr_status.attr,
133         &dev_attr_access_denied.attr,
134         &dev_attr_access_shared.attr,
135         &dev_attr_access_readonly.attr,
136         NULL
137 };
138
139 static struct attribute_group zfcp_unit_attr_group = {
140         .attrs = zfcp_unit_attrs,
141 };
142
143 /**
144  * zfcp_sysfs_create_unit_files - create sysfs unit files
145  * @dev: pointer to belonging device
146  *
147  * Create all attributes of the sysfs representation of a unit.
148  */
149 int
150 zfcp_sysfs_unit_create_files(struct device *dev)
151 {
152         return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group);
153 }
154
155 /**
156  * zfcp_sysfs_remove_unit_files - remove sysfs unit files
157  * @dev: pointer to belonging device
158  *
159  * Remove all attributes of the sysfs representation of a unit.
160  */
161 void
162 zfcp_sysfs_unit_remove_files(struct device *dev)
163 {
164         sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group);
165 }
166
167 #undef ZFCP_LOG_AREA