patch-2_6_7-vs1_9_1_12
[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  *
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.
18  *
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.
23  *
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.
27  */
28
29 #define ZFCP_SYSFS_DRIVER_C_REVISION "$Revision: 1.14 $"
30
31 #include "zfcp_ext.h"
32
33 #define ZFCP_LOG_AREA                   ZFCP_LOG_AREA_CONFIG
34
35 /**
36  * ZFCP_DEFINE_DRIVER_ATTR - define for all loglevels sysfs attributes
37  * @_name:       name of attribute
38  * @_define:     name of ZFCP loglevel define
39  *
40  * Generates store function for a sysfs loglevel attribute of zfcp driver.
41  */
42 #define ZFCP_DEFINE_DRIVER_ATTR(_name, _define)                               \
43 static ssize_t zfcp_sysfs_loglevel_##_name##_store(struct device_driver *drv, \
44                                                    const char *buf,           \
45                                                    size_t count)              \
46 {                                                                             \
47         unsigned int loglevel;                                                \
48         unsigned int new_loglevel;                                            \
49         char *endp;                                                           \
50                                                                               \
51         new_loglevel = simple_strtoul(buf, &endp, 0);                         \
52         if ((endp + 1) < (buf + count))                                       \
53                 return -EINVAL;                                               \
54         if (new_loglevel > 3)                                                 \
55                 return -EINVAL;                                               \
56         down(&zfcp_data.config_sema);                                         \
57         loglevel = atomic_read(&zfcp_data.loglevel);                          \
58         loglevel &= ~((unsigned int) 0xf << (ZFCP_LOG_AREA_##_define << 2));  \
59         loglevel |= new_loglevel << (ZFCP_LOG_AREA_##_define << 2);           \
60         atomic_set(&zfcp_data.loglevel, loglevel);                            \
61         up(&zfcp_data.config_sema);                                           \
62         return count;                                                         \
63 }                                                                             \
64                                                                               \
65 static ssize_t zfcp_sysfs_loglevel_##_name##_show(struct device_driver *dev,  \
66                                                   char *buf)                  \
67 {                                                                             \
68         return sprintf(buf,"%d\n",                                            \
69                        ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA_##_define));          \
70 }                                                                             \
71                                                                               \
72 static DRIVER_ATTR(loglevel_##_name, S_IWUSR | S_IRUGO,                       \
73                    zfcp_sysfs_loglevel_##_name##_show,                        \
74                    zfcp_sysfs_loglevel_##_name##_store);
75
76 ZFCP_DEFINE_DRIVER_ATTR(other, OTHER);
77 ZFCP_DEFINE_DRIVER_ATTR(scsi, SCSI);
78 ZFCP_DEFINE_DRIVER_ATTR(fsf, FSF);
79 ZFCP_DEFINE_DRIVER_ATTR(config, CONFIG);
80 ZFCP_DEFINE_DRIVER_ATTR(cio, CIO);
81 ZFCP_DEFINE_DRIVER_ATTR(qdio, QDIO);
82 ZFCP_DEFINE_DRIVER_ATTR(erp, ERP);
83 ZFCP_DEFINE_DRIVER_ATTR(fc, FC);
84
85 static ssize_t zfcp_sysfs_version_show(struct device_driver *dev,
86                                               char *buf)
87 {
88         return sprintf(buf, "%s\n", ZFCP_VERSION);
89 }
90
91 static DRIVER_ATTR(version, S_IRUGO, zfcp_sysfs_version_show, NULL);
92
93 static struct attribute *zfcp_driver_attrs[] = {
94         &driver_attr_loglevel_other.attr,
95         &driver_attr_loglevel_scsi.attr,
96         &driver_attr_loglevel_fsf.attr,
97         &driver_attr_loglevel_config.attr,
98         &driver_attr_loglevel_cio.attr,
99         &driver_attr_loglevel_qdio.attr,
100         &driver_attr_loglevel_erp.attr,
101         &driver_attr_loglevel_fc.attr,
102         &driver_attr_version.attr,
103         NULL
104 };
105
106 static struct attribute_group zfcp_driver_attr_group = {
107         .attrs = zfcp_driver_attrs,
108 };
109
110 /**
111  * zfcp_sysfs_create_driver_files - create sysfs driver files
112  * @dev: pointer to belonging device
113  *
114  * Create all sysfs attributes of the zfcp device driver
115  */
116 int
117 zfcp_sysfs_driver_create_files(struct device_driver *drv)
118 {
119         return sysfs_create_group(&drv->kobj, &zfcp_driver_attr_group);
120 }
121
122 /**
123  * zfcp_sysfs_remove_driver_files - remove sysfs driver files
124  * @dev: pointer to belonging device
125  *
126  * Remove all sysfs attributes of the zfcp device driver
127  */
128 void
129 zfcp_sysfs_driver_remove_files(struct device_driver *drv)
130 {
131         sysfs_remove_group(&drv->kobj, &zfcp_driver_attr_group);
132 }
133
134 #undef ZFCP_LOG_AREA