summaryrefslogtreecommitdiffstats
path: root/drivers/s390/scsi/zfcp_sysfs_driver.c
blob: 005e62f8593b66c021f28d174965f002f27a12a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * This file is part of the zfcp device driver for
 * FCP adapters for IBM System z9 and zSeries.
 *
 * (C) Copyright IBM Corp. 2002, 2006
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "zfcp_ext.h"

#define ZFCP_LOG_AREA                   ZFCP_LOG_AREA_CONFIG

/**
 * ZFCP_DEFINE_DRIVER_ATTR - define for all loglevels sysfs attributes
 * @_name:       name of attribute
 * @_define:     name of ZFCP loglevel define
 *
 * Generates store function for a sysfs loglevel attribute of zfcp driver.
 */
#define ZFCP_DEFINE_DRIVER_ATTR(_name, _define)                               \
static ssize_t zfcp_sysfs_loglevel_##_name##_store(struct device_driver *drv, \
						   const char *buf,           \
						   size_t count)              \
{                                                                             \
	unsigned int loglevel;                                                \
	unsigned int new_loglevel;                                            \
	char *endp;                                                           \
                                                                              \
	new_loglevel = simple_strtoul(buf, &endp, 0);                         \
	if ((endp + 1) < (buf + count))                                       \
		return -EINVAL;                                               \
	if (new_loglevel > 3)                                                 \
		return -EINVAL;                                               \
	down(&zfcp_data.config_sema);                                         \
	loglevel = atomic_read(&zfcp_data.loglevel);                          \
	loglevel &= ~((unsigned int) 0xf << (ZFCP_LOG_AREA_##_define << 2));  \
	loglevel |= new_loglevel << (ZFCP_LOG_AREA_##_define << 2);           \
	atomic_set(&zfcp_data.loglevel, loglevel);                            \
	up(&zfcp_data.config_sema);                                           \
	return count;                                                         \
}                                                                             \
                                                                              \
static ssize_t zfcp_sysfs_loglevel_##_name##_show(struct device_driver *dev,  \
						  char *buf)                  \
{                                                                             \
	return sprintf(buf,"%d\n", (unsigned int)                             \
		       ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA_##_define));          \
}                                                                             \
                                                                              \
static DRIVER_ATTR(loglevel_##_name, S_IWUSR | S_IRUGO,                       \
		   zfcp_sysfs_loglevel_##_name##_show,                        \
		   zfcp_sysfs_loglevel_##_name##_store);

ZFCP_DEFINE_DRIVER_ATTR(other, OTHER);
ZFCP_DEFINE_DRIVER_ATTR(scsi, SCSI);
ZFCP_DEFINE_DRIVER_ATTR(fsf, FSF);
ZFCP_DEFINE_DRIVER_ATTR(config, CONFIG);
ZFCP_DEFINE_DRIVER_ATTR(cio, CIO);
ZFCP_DEFINE_DRIVER_ATTR(qdio, QDIO);
ZFCP_DEFINE_DRIVER_ATTR(erp, ERP);
ZFCP_DEFINE_DRIVER_ATTR(fc, FC);

static ssize_t zfcp_sysfs_version_show(struct device_driver *dev,
					      char *buf)
{
	return sprintf(buf, "%s\n", zfcp_data.driver_version);
}

static DRIVER_ATTR(version, S_IRUGO, zfcp_sysfs_version_show, NULL);

static struct attribute *zfcp_driver_attrs[] = {
	&driver_attr_loglevel_other.attr,
	&driver_attr_loglevel_scsi.attr,
	&driver_attr_loglevel_fsf.attr,
	&driver_attr_loglevel_config.attr,
	&driver_attr_loglevel_cio.attr,
	&driver_attr_loglevel_qdio.attr,
	&driver_attr_loglevel_erp.attr,
	&driver_attr_loglevel_fc.attr,
	&driver_attr_version.attr,
	NULL
};

static struct attribute_group zfcp_driver_attr_group = {
	.attrs = zfcp_driver_attrs,
};

/**
 * zfcp_sysfs_create_driver_files - create sysfs driver files
 * @dev: pointer to belonging device
 *
 * Create all sysfs attributes of the zfcp device driver
 */
int
zfcp_sysfs_driver_create_files(struct device_driver *drv)
{
	return sysfs_create_group(&drv->kobj, &zfcp_driver_attr_group);
}

/**
 * zfcp_sysfs_remove_driver_files - remove sysfs driver files
 * @dev: pointer to belonging device
 *
 * Remove all sysfs attributes of the zfcp device driver
 */
void
zfcp_sysfs_driver_remove_files(struct device_driver *drv)
{
	sysfs_remove_group(&drv->kobj, &zfcp_driver_attr_group);
}

#undef ZFCP_LOG_AREA
OpenPOWER on IntegriCloud