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