blob: 2f50815f65c746d386d051545fe540637676ea9b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/s390/scsi/zfcp_sysfs_unit.c
3 *
4 * FCP adapter driver for IBM eServer zSeries
5 *
6 * sysfs unit related routines
7 *
8 * (C) Copyright IBM Corp. 2003, 2004
9 *
10 * Authors:
11 * Martin Peschke <mpeschke@de.ibm.com>
12 * Heiko Carstens <heiko.carstens@de.ibm.com>
13 * Andreas Herrmann <aherrman@de.ibm.com>
14 * Volker Sameske <sameske@de.ibm.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
19 * any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 */
30
31#define ZFCP_SYSFS_UNIT_C_REVISION "$Revision: 1.30 $"
32
33#include "zfcp_ext.h"
34
35#define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
36
37/**
38 * zfcp_sysfs_unit_release - gets called when a struct device unit is released
39 * @dev: pointer to belonging device
40 */
41void
42zfcp_sysfs_unit_release(struct device *dev)
43{
44 kfree(dev);
45}
46
47/**
48 * ZFCP_DEFINE_UNIT_ATTR
49 * @_name: name of show attribute
50 * @_format: format string
51 * @_value: value to print
52 *
53 * Generates attribute for a unit.
54 */
55#define ZFCP_DEFINE_UNIT_ATTR(_name, _format, _value) \
Yani Ioannou10523b32005-05-17 06:43:37 -040056static ssize_t zfcp_sysfs_unit_##_name##_show(struct device *dev, struct device_attribute *attr, \
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 char *buf) \
58{ \
59 struct zfcp_unit *unit; \
60 \
61 unit = dev_get_drvdata(dev); \
62 return sprintf(buf, _format, _value); \
63} \
64 \
65static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_unit_##_name##_show, NULL);
66
67ZFCP_DEFINE_UNIT_ATTR(status, "0x%08x\n", atomic_read(&unit->status));
Linus Torvalds1da177e2005-04-16 15:20:36 -070068ZFCP_DEFINE_UNIT_ATTR(in_recovery, "%d\n", atomic_test_mask
69 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status));
70ZFCP_DEFINE_UNIT_ATTR(access_denied, "%d\n", atomic_test_mask
71 (ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status));
72ZFCP_DEFINE_UNIT_ATTR(access_shared, "%d\n", atomic_test_mask
73 (ZFCP_STATUS_UNIT_SHARED, &unit->status));
74ZFCP_DEFINE_UNIT_ATTR(access_readonly, "%d\n", atomic_test_mask
75 (ZFCP_STATUS_UNIT_READONLY, &unit->status));
76
77/**
78 * zfcp_sysfs_unit_failed_store - failed state of unit
79 * @dev: pointer to belonging device
80 * @buf: pointer to input buffer
81 * @count: number of bytes in buffer
82 *
83 * Store function of the "failed" attribute of a unit.
84 * If a "0" gets written to "failed", error recovery will be
85 * started for the belonging unit.
86 */
87static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -040088zfcp_sysfs_unit_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 struct zfcp_unit *unit;
91 unsigned int val;
92 char *endp;
93 int retval = 0;
94
95 down(&zfcp_data.config_sema);
96 unit = dev_get_drvdata(dev);
97 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) {
98 retval = -EBUSY;
99 goto out;
100 }
101
102 val = simple_strtoul(buf, &endp, 0);
103 if (((endp + 1) < (buf + count)) || (val != 0)) {
104 retval = -EINVAL;
105 goto out;
106 }
107
108 zfcp_erp_modify_unit_status(unit, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
109 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
110 zfcp_erp_wait(unit->port->adapter);
111 out:
112 up(&zfcp_data.config_sema);
113 return retval ? retval : (ssize_t) count;
114}
115
116/**
117 * zfcp_sysfs_unit_failed_show - failed state of unit
118 * @dev: pointer to belonging device
119 * @buf: pointer to input buffer
120 *
121 * Show function of "failed" attribute of unit. Will be
122 * "0" if unit is working, otherwise "1".
123 */
124static ssize_t
Yani Ioannou10523b32005-05-17 06:43:37 -0400125zfcp_sysfs_unit_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 struct zfcp_unit *unit;
128
129 unit = dev_get_drvdata(dev);
130 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status))
131 return sprintf(buf, "1\n");
132 else
133 return sprintf(buf, "0\n");
134}
135
136static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show,
137 zfcp_sysfs_unit_failed_store);
138
139static struct attribute *zfcp_unit_attrs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 &dev_attr_failed.attr,
141 &dev_attr_in_recovery.attr,
142 &dev_attr_status.attr,
143 &dev_attr_access_denied.attr,
144 &dev_attr_access_shared.attr,
145 &dev_attr_access_readonly.attr,
146 NULL
147};
148
149static struct attribute_group zfcp_unit_attr_group = {
150 .attrs = zfcp_unit_attrs,
151};
152
153/**
154 * zfcp_sysfs_create_unit_files - create sysfs unit files
155 * @dev: pointer to belonging device
156 *
157 * Create all attributes of the sysfs representation of a unit.
158 */
159int
160zfcp_sysfs_unit_create_files(struct device *dev)
161{
162 return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group);
163}
164
165/**
166 * zfcp_sysfs_remove_unit_files - remove sysfs unit files
167 * @dev: pointer to belonging device
168 *
169 * Remove all attributes of the sysfs representation of a unit.
170 */
171void
172zfcp_sysfs_unit_remove_files(struct device *dev)
173{
174 sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group);
175}
176
177#undef ZFCP_LOG_AREA