blob: 0c27ae726475cb253dd3dee10ec73ad91873017d [file] [log] [blame]
Peter Tiedemann293d9842008-02-08 00:03:49 +01001/*
2 * drivers/s390/net/ctcm_sysfs.c
3 *
4 * Copyright IBM Corp. 2007, 2007
5 * Authors: Peter Tiedemann (ptiedem@de.ibm.com)
6 *
7 */
8
9#undef DEBUG
10#undef DEBUGDATA
11#undef DEBUGCCW
12
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +010013#define KMSG_COMPONENT "ctcm"
14#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
15
Sebastian Ott20cdffa2012-05-15 17:54:12 +020016#include <linux/device.h>
Peter Tiedemann293d9842008-02-08 00:03:49 +010017#include <linux/sysfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Peter Tiedemann293d9842008-02-08 00:03:49 +010019#include "ctcm_main.h"
20
21/*
22 * sysfs attributes
23 */
24
25static ssize_t ctcm_buffer_show(struct device *dev,
26 struct device_attribute *attr, char *buf)
27{
28 struct ctcm_priv *priv = dev_get_drvdata(dev);
29
30 if (!priv)
31 return -ENODEV;
32 return sprintf(buf, "%d\n", priv->buffer_size);
33}
34
35static ssize_t ctcm_buffer_write(struct device *dev,
36 struct device_attribute *attr, const char *buf, size_t count)
37{
38 struct net_device *ndev;
39 int bs1;
40 struct ctcm_priv *priv = dev_get_drvdata(dev);
41
Ursula Braun3c09e262010-08-12 01:58:28 +000042 ndev = priv->channel[CTCM_READ]->netdev;
43 if (!(priv && priv->channel[CTCM_READ] && ndev)) {
Peter Tiedemann293d9842008-02-08 00:03:49 +010044 CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev");
45 return -ENODEV;
46 }
47
48 sscanf(buf, "%u", &bs1);
49 if (bs1 > CTCM_BUFSIZE_LIMIT)
50 goto einval;
51 if (bs1 < (576 + LL_HEADER_LENGTH + 2))
52 goto einval;
53 priv->buffer_size = bs1; /* just to overwrite the default */
54
55 if ((ndev->flags & IFF_RUNNING) &&
56 (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2)))
57 goto einval;
58
Ursula Braun3c09e262010-08-12 01:58:28 +000059 priv->channel[CTCM_READ]->max_bufsize = bs1;
60 priv->channel[CTCM_WRITE]->max_bufsize = bs1;
Peter Tiedemann293d9842008-02-08 00:03:49 +010061 if (!(ndev->flags & IFF_RUNNING))
62 ndev->mtu = bs1 - LL_HEADER_LENGTH - 2;
Ursula Braun3c09e262010-08-12 01:58:28 +000063 priv->channel[CTCM_READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
64 priv->channel[CTCM_WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
Peter Tiedemann293d9842008-02-08 00:03:49 +010065
66 CTCM_DBF_DEV(SETUP, ndev, buf);
67 return count;
68
69einval:
70 CTCM_DBF_DEV(SETUP, ndev, "buff_err");
71 return -EINVAL;
72}
73
74static void ctcm_print_statistics(struct ctcm_priv *priv)
75{
76 char *sbuf;
77 char *p;
78
79 if (!priv)
80 return;
81 sbuf = kmalloc(2048, GFP_KERNEL);
82 if (sbuf == NULL)
83 return;
84 p = sbuf;
85
86 p += sprintf(p, " Device FSM state: %s\n",
87 fsm_getstate_str(priv->fsm));
88 p += sprintf(p, " RX channel FSM state: %s\n",
Ursula Braun3c09e262010-08-12 01:58:28 +000089 fsm_getstate_str(priv->channel[CTCM_READ]->fsm));
Peter Tiedemann293d9842008-02-08 00:03:49 +010090 p += sprintf(p, " TX channel FSM state: %s\n",
Ursula Braun3c09e262010-08-12 01:58:28 +000091 fsm_getstate_str(priv->channel[CTCM_WRITE]->fsm));
Peter Tiedemann293d9842008-02-08 00:03:49 +010092 p += sprintf(p, " Max. TX buffer used: %ld\n",
93 priv->channel[WRITE]->prof.maxmulti);
94 p += sprintf(p, " Max. chained SKBs: %ld\n",
95 priv->channel[WRITE]->prof.maxcqueue);
96 p += sprintf(p, " TX single write ops: %ld\n",
97 priv->channel[WRITE]->prof.doios_single);
98 p += sprintf(p, " TX multi write ops: %ld\n",
99 priv->channel[WRITE]->prof.doios_multi);
100 p += sprintf(p, " Netto bytes written: %ld\n",
101 priv->channel[WRITE]->prof.txlen);
102 p += sprintf(p, " Max. TX IO-time: %ld\n",
103 priv->channel[WRITE]->prof.tx_time);
104
105 printk(KERN_INFO "Statistics for %s:\n%s",
Ursula Braun3c09e262010-08-12 01:58:28 +0000106 priv->channel[CTCM_WRITE]->netdev->name, sbuf);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100107 kfree(sbuf);
108 return;
109}
110
111static ssize_t stats_show(struct device *dev,
Sebastian Ott20cdffa2012-05-15 17:54:12 +0200112 struct device_attribute *attr, char *buf)
Peter Tiedemann293d9842008-02-08 00:03:49 +0100113{
Sebastian Ott20cdffa2012-05-15 17:54:12 +0200114 struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100115 struct ctcm_priv *priv = dev_get_drvdata(dev);
Sebastian Ott20cdffa2012-05-15 17:54:12 +0200116
117 if (!priv || gdev->state != CCWGROUP_ONLINE)
Peter Tiedemann293d9842008-02-08 00:03:49 +0100118 return -ENODEV;
119 ctcm_print_statistics(priv);
120 return sprintf(buf, "0\n");
121}
122
123static ssize_t stats_write(struct device *dev, struct device_attribute *attr,
124 const char *buf, size_t count)
125{
126 struct ctcm_priv *priv = dev_get_drvdata(dev);
127 if (!priv)
128 return -ENODEV;
129 /* Reset statistics */
130 memset(&priv->channel[WRITE]->prof, 0,
Ursula Braun3c09e262010-08-12 01:58:28 +0000131 sizeof(priv->channel[CTCM_WRITE]->prof));
Peter Tiedemann293d9842008-02-08 00:03:49 +0100132 return count;
133}
134
135static ssize_t ctcm_proto_show(struct device *dev,
136 struct device_attribute *attr, char *buf)
137{
138 struct ctcm_priv *priv = dev_get_drvdata(dev);
139 if (!priv)
140 return -ENODEV;
141
142 return sprintf(buf, "%d\n", priv->protocol);
143}
144
145static ssize_t ctcm_proto_store(struct device *dev,
146 struct device_attribute *attr, const char *buf, size_t count)
147{
148 int value;
149 struct ctcm_priv *priv = dev_get_drvdata(dev);
150
151 if (!priv)
152 return -ENODEV;
153 sscanf(buf, "%u", &value);
154 if (!((value == CTCM_PROTO_S390) ||
155 (value == CTCM_PROTO_LINUX) ||
156 (value == CTCM_PROTO_MPC) ||
157 (value == CTCM_PROTO_OS390)))
158 return -EINVAL;
159 priv->protocol = value;
160 CTCM_DBF_DEV(SETUP, dev, buf);
161
162 return count;
163}
164
Martin Schwidefskyc4736d92011-10-30 15:17:11 +0100165static const char *ctcm_type[] = {
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000166 "not a channel",
167 "CTC/A",
168 "FICON channel",
169 "ESCON channel",
170 "unknown channel type",
171 "unsupported channel type",
172};
173
Peter Tiedemann293d9842008-02-08 00:03:49 +0100174static ssize_t ctcm_type_show(struct device *dev,
175 struct device_attribute *attr, char *buf)
176{
177 struct ccwgroup_device *cgdev;
178
179 cgdev = to_ccwgroupdev(dev);
180 if (!cgdev)
181 return -ENODEV;
182
183 return sprintf(buf, "%s\n",
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000184 ctcm_type[cgdev->cdev[0]->id.driver_info]);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100185}
186
187static DEVICE_ATTR(buffer, 0644, ctcm_buffer_show, ctcm_buffer_write);
188static DEVICE_ATTR(protocol, 0644, ctcm_proto_show, ctcm_proto_store);
189static DEVICE_ATTR(type, 0444, ctcm_type_show, NULL);
190static DEVICE_ATTR(stats, 0644, stats_show, stats_write);
191
192static struct attribute *ctcm_attr[] = {
193 &dev_attr_protocol.attr,
194 &dev_attr_type.attr,
195 &dev_attr_buffer.attr,
Sebastian Ott20cdffa2012-05-15 17:54:12 +0200196 &dev_attr_stats.attr,
Peter Tiedemann293d9842008-02-08 00:03:49 +0100197 NULL,
198};
199
200static struct attribute_group ctcm_attr_group = {
201 .attrs = ctcm_attr,
202};
Sebastian Ott20cdffa2012-05-15 17:54:12 +0200203const struct attribute_group *ctcm_attr_groups[] = {
204 &ctcm_attr_group,
205 NULL,
206};