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