Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / s390 / scsi / zfcp_sysfs_driver.c
1 /*
2  * linux/drivers/s390/scsi/zfcp_sysfs_driver.c
3  *
4  * FCP adapter driver for IBM eServer zSeries
5  *
6  * sysfs driver 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  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2, or (at your option)
18  * any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28  */
29
30 #include "zfcp_ext.h"
31
32 #define ZFCP_LOG_AREA                   ZFCP_LOG_AREA_CONFIG
33
34 /**
35  * ZFCP_DEFINE_DRIVER_ATTR - define for all loglevels sysfs attributes
36  * @_name:       name of attribute
37  * @_define:     name of ZFCP loglevel define
38  *
39  * Generates store function for a sysfs loglevel attribute of zfcp driver.
40  */
41 #define ZFCP_DEFINE_DRIVER_ATTR(_name, _define)                               \
42 static ssize_t zfcp_sysfs_loglevel_##_name##_store(struct device_driver *drv, \
43                                                    const char *buf,           \
44                                                    size_t count)              \
45 {                                                                             \
46         unsigned int loglevel;                                                \
47         unsigned int new_loglevel;                                            \
48         char *endp;                                                           \
49                                                                               \
50         new_loglevel = simple_strtoul(buf, &endp, 0);                         \
51         if ((endp + 1) < (buf + count))                                       \
52                 return -EINVAL;                                               \
53         if (new_loglevel > 3)                                                 \
54                 return -EINVAL;                                               \
55         down(&zfcp_data.config_sema);                                         \
56         loglevel = atomic_read(&zfcp_data.loglevel);                          \
57         loglevel &= ~((unsigned int) 0xf << (ZFCP_LOG_AREA_##_define << 2));  \
58         loglevel |= new_loglevel << (ZFCP_LOG_AREA_##_define << 2);           \
59         atomic_set(&zfcp_data.loglevel, loglevel);                            \
60         up(&zfcp_data.config_sema);                                           \
61         return count;                                                         \
62 }                                                                             \
63                                                                               \
64 static ssize_t zfcp_sysfs_loglevel_##_name##_show(struct device_driver *dev,  \
65                                                   char *buf)                  \
66 {                                                                             \
67         return sprintf(buf,"%d\n", (unsigned int)                             \
68                        ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA_##_define));          \
69 }                                                                             \
70                                                                               \
71 static DRIVER_ATTR(loglevel_##_name, S_IWUSR | S_IRUGO,                       \
72                    zfcp_sysfs_loglevel_##_name##_show,                        \
73                    zfcp_sysfs_loglevel_##_name##_store);
74
75 ZFCP_DEFINE_DRIVER_ATTR(other, OTHER);
76 ZFCP_DEFINE_DRIVER_ATTR(scsi, SCSI);
77 ZFCP_DEFINE_DRIVER_ATTR(fsf, FSF);
78 ZFCP_DEFINE_DRIVER_ATTR(config, CONFIG);
79 ZFCP_DEFINE_DRIVER_ATTR(cio, CIO);
80 ZFCP_DEFINE_DRIVER_ATTR(qdio, QDIO);
81 ZFCP_DEFINE_DRIVER_ATTR(erp, ERP);
82 ZFCP_DEFINE_DRIVER_ATTR(fc, FC);
83
84 static ssize_t zfcp_sysfs_version_show(struct device_driver *dev,
85                                               char *buf)
86 {
87         return sprintf(buf, "%s\n", zfcp_data.driver_version);
88 }
89
90 static DRIVER_ATTR(version, S_IRUGO, zfcp_sysfs_version_show, NULL);
91
92 static struct attribute *zfcp_driver_attrs[] = {
93         &driver_attr_loglevel_other.attr,
94         &driver_attr_loglevel_scsi.attr,
95         &driver_attr_loglevel_fsf.attr,
96         &driver_attr_loglevel_config.attr,
97         &driver_attr_loglevel_cio.attr,
98         &driver_attr_loglevel_qdio.attr,
99         &driver_attr_loglevel_erp.attr,
100         &driver_attr_loglevel_fc.attr,
101         &driver_attr_version.attr,
102         NULL
103 };
104
105 static struct attribute_group zfcp_driver_attr_group = {
106         .attrs = zfcp_driver_attrs,
107 };
108
109 /**
110  * zfcp_sysfs_create_driver_files - create sysfs driver files
111  * @dev: pointer to belonging device
112  *
113  * Create all sysfs attributes of the zfcp device driver
114  */
115 int
116 zfcp_sysfs_driver_create_files(struct device_driver *drv)
117 {
118         return sysfs_create_group(&drv->kobj, &zfcp_driver_attr_group);
119 }
120
121 /**
122  * zfcp_sysfs_remove_driver_files - remove sysfs driver files
123  * @dev: pointer to belonging device
124  *
125  * Remove all sysfs attributes of the zfcp device driver
126  */
127 void
128 zfcp_sysfs_driver_remove_files(struct device_driver *drv)
129 {
130         sysfs_remove_group(&drv->kobj, &zfcp_driver_attr_group);
131 }
132
133 #undef ZFCP_LOG_AREA