]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/s390/net/ctcm_sysfs.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6-omap-h63xx.git] / drivers / s390 / net / ctcm_sysfs.c
1 /*
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
13 #include <linux/sysfs.h>
14 #include "ctcm_main.h"
15
16 /*
17  * sysfs attributes
18  */
19
20 static ssize_t ctcm_buffer_show(struct device *dev,
21                                 struct device_attribute *attr, char *buf)
22 {
23         struct ctcm_priv *priv = dev_get_drvdata(dev);
24
25         if (!priv)
26                 return -ENODEV;
27         return sprintf(buf, "%d\n", priv->buffer_size);
28 }
29
30 static ssize_t ctcm_buffer_write(struct device *dev,
31                 struct device_attribute *attr, const char *buf, size_t count)
32 {
33         struct net_device *ndev;
34         int bs1;
35         struct ctcm_priv *priv = dev_get_drvdata(dev);
36
37         if (!(priv && priv->channel[READ] &&
38                         (ndev = priv->channel[READ]->netdev))) {
39                 CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev");
40                 return -ENODEV;
41         }
42
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 */
49
50         if ((ndev->flags & IFF_RUNNING) &&
51             (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2)))
52                                         goto einval;
53
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;
60
61         CTCM_DBF_DEV(SETUP, ndev, buf);
62         return count;
63
64 einval:
65         CTCM_DBF_DEV(SETUP, ndev, "buff_err");
66         return -EINVAL;
67 }
68
69 static void ctcm_print_statistics(struct ctcm_priv *priv)
70 {
71         char *sbuf;
72         char *p;
73
74         if (!priv)
75                 return;
76         sbuf = kmalloc(2048, GFP_KERNEL);
77         if (sbuf == NULL)
78                 return;
79         p = sbuf;
80
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);
99
100         printk(KERN_INFO "Statistics for %s:\n%s",
101                                 priv->channel[WRITE]->netdev->name, sbuf);
102         kfree(sbuf);
103         return;
104 }
105
106 static ssize_t stats_show(struct device *dev,
107                                 struct device_attribute *attr, char *buf)
108 {
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");
114 }
115
116 static ssize_t stats_write(struct device *dev, struct device_attribute *attr,
117                                 const char *buf, size_t count)
118 {
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;
126 }
127
128 static ssize_t ctcm_proto_show(struct device *dev,
129                                 struct device_attribute *attr, char *buf)
130 {
131         struct ctcm_priv *priv = dev_get_drvdata(dev);
132         if (!priv)
133                 return -ENODEV;
134
135         return sprintf(buf, "%d\n", priv->protocol);
136 }
137
138 static ssize_t ctcm_proto_store(struct device *dev,
139                 struct device_attribute *attr, const char *buf, size_t count)
140 {
141         int value;
142         struct ctcm_priv *priv = dev_get_drvdata(dev);
143
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);
154
155         return count;
156 }
157
158 static ssize_t ctcm_type_show(struct device *dev,
159                                 struct device_attribute *attr, char *buf)
160 {
161         struct ccwgroup_device *cgdev;
162
163         cgdev = to_ccwgroupdev(dev);
164         if (!cgdev)
165                 return -ENODEV;
166
167         return sprintf(buf, "%s\n",
168                         cu3088_type[cgdev->cdev[0]->id.driver_info]);
169 }
170
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);
175
176 static struct attribute *ctcm_attr[] = {
177         &dev_attr_protocol.attr,
178         &dev_attr_type.attr,
179         &dev_attr_buffer.attr,
180         NULL,
181 };
182
183 static struct attribute_group ctcm_attr_group = {
184         .attrs = ctcm_attr,
185 };
186
187 int ctcm_add_attributes(struct device *dev)
188 {
189         int rc;
190
191         rc = device_create_file(dev, &dev_attr_stats);
192
193         return rc;
194 }
195
196 void ctcm_remove_attributes(struct device *dev)
197 {
198         device_remove_file(dev, &dev_attr_stats);
199 }
200
201 int ctcm_add_files(struct device *dev)
202 {
203         return sysfs_create_group(&dev->kobj, &ctcm_attr_group);
204 }
205
206 void ctcm_remove_files(struct device *dev)
207 {
208         sysfs_remove_group(&dev->kobj, &ctcm_attr_group);
209 }
210