blob: 985b5dcbdac8b348dc6394898ad55bcddf9b8aa9 [file] [log] [blame]
Peter Tiedemann293d9842008-02-08 00:03:49 +01001/*
Peter Tiedemann293d9842008-02-08 00:03:49 +01002 * Copyright IBM Corp. 2007, 2007
3 * Authors: Peter Tiedemann (ptiedem@de.ibm.com)
4 *
5 */
6
7#undef DEBUG
8#undef DEBUGDATA
9#undef DEBUGCCW
10
Peter Tiedemann2a7c6f22008-12-25 13:39:54 +010011#define KMSG_COMPONENT "ctcm"
12#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
Sebastian Ott20cdffa2012-05-15 17:54:12 +020014#include <linux/device.h>
Peter Tiedemann293d9842008-02-08 00:03:49 +010015#include <linux/sysfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Peter Tiedemann293d9842008-02-08 00:03:49 +010017#include "ctcm_main.h"
18
19/*
20 * sysfs attributes
21 */
22
23static ssize_t ctcm_buffer_show(struct device *dev,
24 struct device_attribute *attr, char *buf)
25{
26 struct ctcm_priv *priv = dev_get_drvdata(dev);
27
28 if (!priv)
29 return -ENODEV;
30 return sprintf(buf, "%d\n", priv->buffer_size);
31}
32
33static ssize_t ctcm_buffer_write(struct device *dev,
34 struct device_attribute *attr, const char *buf, size_t count)
35{
36 struct net_device *ndev;
37 int bs1;
38 struct ctcm_priv *priv = dev_get_drvdata(dev);
39
Ursula Braun3c09e262010-08-12 01:58:28 +000040 ndev = priv->channel[CTCM_READ]->netdev;
41 if (!(priv && priv->channel[CTCM_READ] && ndev)) {
Peter Tiedemann293d9842008-02-08 00:03:49 +010042 CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev");
43 return -ENODEV;
44 }
45
46 sscanf(buf, "%u", &bs1);
47 if (bs1 > CTCM_BUFSIZE_LIMIT)
48 goto einval;
49 if (bs1 < (576 + LL_HEADER_LENGTH + 2))
50 goto einval;
51 priv->buffer_size = bs1; /* just to overwrite the default */
52
53 if ((ndev->flags & IFF_RUNNING) &&
54 (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2)))
55 goto einval;
56
Ursula Braun3c09e262010-08-12 01:58:28 +000057 priv->channel[CTCM_READ]->max_bufsize = bs1;
58 priv->channel[CTCM_WRITE]->max_bufsize = bs1;
Peter Tiedemann293d9842008-02-08 00:03:49 +010059 if (!(ndev->flags & IFF_RUNNING))
60 ndev->mtu = bs1 - LL_HEADER_LENGTH - 2;
Ursula Braun3c09e262010-08-12 01:58:28 +000061 priv->channel[CTCM_READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
62 priv->channel[CTCM_WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
Peter Tiedemann293d9842008-02-08 00:03:49 +010063
64 CTCM_DBF_DEV(SETUP, ndev, buf);
65 return count;
66
67einval:
68 CTCM_DBF_DEV(SETUP, ndev, "buff_err");
69 return -EINVAL;
70}
71
72static void ctcm_print_statistics(struct ctcm_priv *priv)
73{
74 char *sbuf;
75 char *p;
76
77 if (!priv)
78 return;
79 sbuf = kmalloc(2048, GFP_KERNEL);
80 if (sbuf == NULL)
81 return;
82 p = sbuf;
83
84 p += sprintf(p, " Device FSM state: %s\n",
85 fsm_getstate_str(priv->fsm));
86 p += sprintf(p, " RX channel FSM state: %s\n",
Ursula Braun3c09e262010-08-12 01:58:28 +000087 fsm_getstate_str(priv->channel[CTCM_READ]->fsm));
Peter Tiedemann293d9842008-02-08 00:03:49 +010088 p += sprintf(p, " TX channel FSM state: %s\n",
Ursula Braun3c09e262010-08-12 01:58:28 +000089 fsm_getstate_str(priv->channel[CTCM_WRITE]->fsm));
Peter Tiedemann293d9842008-02-08 00:03:49 +010090 p += sprintf(p, " Max. TX buffer used: %ld\n",
91 priv->channel[WRITE]->prof.maxmulti);
92 p += sprintf(p, " Max. chained SKBs: %ld\n",
93 priv->channel[WRITE]->prof.maxcqueue);
94 p += sprintf(p, " TX single write ops: %ld\n",
95 priv->channel[WRITE]->prof.doios_single);
96 p += sprintf(p, " TX multi write ops: %ld\n",
97 priv->channel[WRITE]->prof.doios_multi);
98 p += sprintf(p, " Netto bytes written: %ld\n",
99 priv->channel[WRITE]->prof.txlen);
100 p += sprintf(p, " Max. TX IO-time: %ld\n",
101 priv->channel[WRITE]->prof.tx_time);
102
103 printk(KERN_INFO "Statistics for %s:\n%s",
Ursula Braun3c09e262010-08-12 01:58:28 +0000104 priv->channel[CTCM_WRITE]->netdev->name, sbuf);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100105 kfree(sbuf);
106 return;
107}
108
109static ssize_t stats_show(struct device *dev,
Sebastian Ott20cdffa2012-05-15 17:54:12 +0200110 struct device_attribute *attr, char *buf)
Peter Tiedemann293d9842008-02-08 00:03:49 +0100111{
Sebastian Ott20cdffa2012-05-15 17:54:12 +0200112 struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100113 struct ctcm_priv *priv = dev_get_drvdata(dev);
Sebastian Ott20cdffa2012-05-15 17:54:12 +0200114
115 if (!priv || gdev->state != CCWGROUP_ONLINE)
Peter Tiedemann293d9842008-02-08 00:03:49 +0100116 return -ENODEV;
117 ctcm_print_statistics(priv);
118 return sprintf(buf, "0\n");
119}
120
121static ssize_t stats_write(struct device *dev, struct device_attribute *attr,
122 const char *buf, size_t count)
123{
124 struct ctcm_priv *priv = dev_get_drvdata(dev);
125 if (!priv)
126 return -ENODEV;
127 /* Reset statistics */
128 memset(&priv->channel[WRITE]->prof, 0,
Ursula Braun3c09e262010-08-12 01:58:28 +0000129 sizeof(priv->channel[CTCM_WRITE]->prof));
Peter Tiedemann293d9842008-02-08 00:03:49 +0100130 return count;
131}
132
133static ssize_t ctcm_proto_show(struct device *dev,
134 struct device_attribute *attr, char *buf)
135{
136 struct ctcm_priv *priv = dev_get_drvdata(dev);
137 if (!priv)
138 return -ENODEV;
139
140 return sprintf(buf, "%d\n", priv->protocol);
141}
142
143static ssize_t ctcm_proto_store(struct device *dev,
144 struct device_attribute *attr, const char *buf, size_t count)
145{
146 int value;
147 struct ctcm_priv *priv = dev_get_drvdata(dev);
148
149 if (!priv)
150 return -ENODEV;
151 sscanf(buf, "%u", &value);
152 if (!((value == CTCM_PROTO_S390) ||
153 (value == CTCM_PROTO_LINUX) ||
154 (value == CTCM_PROTO_MPC) ||
155 (value == CTCM_PROTO_OS390)))
156 return -EINVAL;
157 priv->protocol = value;
158 CTCM_DBF_DEV(SETUP, dev, buf);
159
160 return count;
161}
162
Martin Schwidefskyc4736d92011-10-30 15:17:11 +0100163static const char *ctcm_type[] = {
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000164 "not a channel",
165 "CTC/A",
166 "FICON channel",
167 "ESCON channel",
168 "unknown channel type",
169 "unsupported channel type",
170};
171
Peter Tiedemann293d9842008-02-08 00:03:49 +0100172static ssize_t ctcm_type_show(struct device *dev,
173 struct device_attribute *attr, char *buf)
174{
175 struct ccwgroup_device *cgdev;
176
177 cgdev = to_ccwgroupdev(dev);
178 if (!cgdev)
179 return -ENODEV;
180
181 return sprintf(buf, "%s\n",
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000182 ctcm_type[cgdev->cdev[0]->id.driver_info]);
Peter Tiedemann293d9842008-02-08 00:03:49 +0100183}
184
185static DEVICE_ATTR(buffer, 0644, ctcm_buffer_show, ctcm_buffer_write);
186static DEVICE_ATTR(protocol, 0644, ctcm_proto_show, ctcm_proto_store);
187static DEVICE_ATTR(type, 0444, ctcm_type_show, NULL);
188static DEVICE_ATTR(stats, 0644, stats_show, stats_write);
189
190static struct attribute *ctcm_attr[] = {
191 &dev_attr_protocol.attr,
192 &dev_attr_type.attr,
193 &dev_attr_buffer.attr,
Sebastian Ott20cdffa2012-05-15 17:54:12 +0200194 &dev_attr_stats.attr,
Peter Tiedemann293d9842008-02-08 00:03:49 +0100195 NULL,
196};
197
198static struct attribute_group ctcm_attr_group = {
199 .attrs = ctcm_attr,
200};
Sebastian Ott20cdffa2012-05-15 17:54:12 +0200201const struct attribute_group *ctcm_attr_groups[] = {
202 &ctcm_attr_group,
203 NULL,
204};