hamradio/scc: add missing block braces to multi-statement if
[linux/fpc-iii.git] / drivers / s390 / net / ctcm_sysfs.c
blobbb2d13721d3472a8ca27036132aa91a793b95ac7
1 /*
2 * drivers/s390/net/ctcm_sysfs.c
4 * Copyright IBM Corp. 2007, 2007
5 * Authors: Peter Tiedemann (ptiedem@de.ibm.com)
7 */
9 #undef DEBUG
10 #undef DEBUGDATA
11 #undef DEBUGCCW
13 #include <linux/sysfs.h>
14 #include "ctcm_main.h"
17 * sysfs attributes
20 static ssize_t ctcm_buffer_show(struct device *dev,
21 struct device_attribute *attr, char *buf)
23 struct ctcm_priv *priv = dev_get_drvdata(dev);
25 if (!priv)
26 return -ENODEV;
27 return sprintf(buf, "%d\n", priv->buffer_size);
30 static ssize_t ctcm_buffer_write(struct device *dev,
31 struct device_attribute *attr, const char *buf, size_t count)
33 struct net_device *ndev;
34 int bs1;
35 struct ctcm_priv *priv = dev_get_drvdata(dev);
37 if (!(priv && priv->channel[READ] &&
38 (ndev = priv->channel[READ]->netdev))) {
39 CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev");
40 return -ENODEV;
43 sscanf(buf, "%u", &bs1);
44 if (bs1 > CTCM_BUFSIZE_LIMIT)
45 goto einval;
46 if (bs1 < (576 + LL_HEADER_LENGTH + 2))
47 goto einval;
48 priv->buffer_size = bs1; /* just to overwrite the default */
50 if ((ndev->flags & IFF_RUNNING) &&
51 (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2)))
52 goto einval;
54 priv->channel[READ]->max_bufsize = bs1;
55 priv->channel[WRITE]->max_bufsize = bs1;
56 if (!(ndev->flags & IFF_RUNNING))
57 ndev->mtu = bs1 - LL_HEADER_LENGTH - 2;
58 priv->channel[READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
59 priv->channel[WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
61 CTCM_DBF_DEV(SETUP, ndev, buf);
62 return count;
64 einval:
65 CTCM_DBF_DEV(SETUP, ndev, "buff_err");
66 return -EINVAL;
69 static void ctcm_print_statistics(struct ctcm_priv *priv)
71 char *sbuf;
72 char *p;
74 if (!priv)
75 return;
76 sbuf = kmalloc(2048, GFP_KERNEL);
77 if (sbuf == NULL)
78 return;
79 p = sbuf;
81 p += sprintf(p, " Device FSM state: %s\n",
82 fsm_getstate_str(priv->fsm));
83 p += sprintf(p, " RX channel FSM state: %s\n",
84 fsm_getstate_str(priv->channel[READ]->fsm));
85 p += sprintf(p, " TX channel FSM state: %s\n",
86 fsm_getstate_str(priv->channel[WRITE]->fsm));
87 p += sprintf(p, " Max. TX buffer used: %ld\n",
88 priv->channel[WRITE]->prof.maxmulti);
89 p += sprintf(p, " Max. chained SKBs: %ld\n",
90 priv->channel[WRITE]->prof.maxcqueue);
91 p += sprintf(p, " TX single write ops: %ld\n",
92 priv->channel[WRITE]->prof.doios_single);
93 p += sprintf(p, " TX multi write ops: %ld\n",
94 priv->channel[WRITE]->prof.doios_multi);
95 p += sprintf(p, " Netto bytes written: %ld\n",
96 priv->channel[WRITE]->prof.txlen);
97 p += sprintf(p, " Max. TX IO-time: %ld\n",
98 priv->channel[WRITE]->prof.tx_time);
100 printk(KERN_INFO "Statistics for %s:\n%s",
101 priv->channel[WRITE]->netdev->name, sbuf);
102 kfree(sbuf);
103 return;
106 static ssize_t stats_show(struct device *dev,
107 struct device_attribute *attr, char *buf)
109 struct ctcm_priv *priv = dev_get_drvdata(dev);
110 if (!priv)
111 return -ENODEV;
112 ctcm_print_statistics(priv);
113 return sprintf(buf, "0\n");
116 static ssize_t stats_write(struct device *dev, struct device_attribute *attr,
117 const char *buf, size_t count)
119 struct ctcm_priv *priv = dev_get_drvdata(dev);
120 if (!priv)
121 return -ENODEV;
122 /* Reset statistics */
123 memset(&priv->channel[WRITE]->prof, 0,
124 sizeof(priv->channel[WRITE]->prof));
125 return count;
128 static ssize_t ctcm_proto_show(struct device *dev,
129 struct device_attribute *attr, char *buf)
131 struct ctcm_priv *priv = dev_get_drvdata(dev);
132 if (!priv)
133 return -ENODEV;
135 return sprintf(buf, "%d\n", priv->protocol);
138 static ssize_t ctcm_proto_store(struct device *dev,
139 struct device_attribute *attr, const char *buf, size_t count)
141 int value;
142 struct ctcm_priv *priv = dev_get_drvdata(dev);
144 if (!priv)
145 return -ENODEV;
146 sscanf(buf, "%u", &value);
147 if (!((value == CTCM_PROTO_S390) ||
148 (value == CTCM_PROTO_LINUX) ||
149 (value == CTCM_PROTO_MPC) ||
150 (value == CTCM_PROTO_OS390)))
151 return -EINVAL;
152 priv->protocol = value;
153 CTCM_DBF_DEV(SETUP, dev, buf);
155 return count;
158 static ssize_t ctcm_type_show(struct device *dev,
159 struct device_attribute *attr, char *buf)
161 struct ccwgroup_device *cgdev;
163 cgdev = to_ccwgroupdev(dev);
164 if (!cgdev)
165 return -ENODEV;
167 return sprintf(buf, "%s\n",
168 cu3088_type[cgdev->cdev[0]->id.driver_info]);
171 static DEVICE_ATTR(buffer, 0644, ctcm_buffer_show, ctcm_buffer_write);
172 static DEVICE_ATTR(protocol, 0644, ctcm_proto_show, ctcm_proto_store);
173 static DEVICE_ATTR(type, 0444, ctcm_type_show, NULL);
174 static DEVICE_ATTR(stats, 0644, stats_show, stats_write);
176 static struct attribute *ctcm_attr[] = {
177 &dev_attr_protocol.attr,
178 &dev_attr_type.attr,
179 &dev_attr_buffer.attr,
180 NULL,
183 static struct attribute_group ctcm_attr_group = {
184 .attrs = ctcm_attr,
187 int ctcm_add_attributes(struct device *dev)
189 int rc;
191 rc = device_create_file(dev, &dev_attr_stats);
193 return rc;
196 void ctcm_remove_attributes(struct device *dev)
198 device_remove_file(dev, &dev_attr_stats);
201 int ctcm_add_files(struct device *dev)
203 return sysfs_create_group(&dev->kobj, &ctcm_attr_group);
206 void ctcm_remove_files(struct device *dev)
208 sysfs_remove_group(&dev->kobj, &ctcm_attr_group);