1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2007, 2007
4 * Authors: Peter Tiedemann (ptiedem@de.ibm.com)
12 #define KMSG_COMPONENT "ctcm"
13 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
15 #include <linux/device.h>
16 #include <linux/sysfs.h>
17 #include <linux/slab.h>
18 #include "ctcm_main.h"
24 static ssize_t ctcm_buffer_show(struct device *dev,
25 struct device_attribute *attr, char *buf)
27 struct ctcm_priv *priv = dev_get_drvdata(dev);
31 return sprintf(buf, "%d\n", priv->buffer_size);
34 static ssize_t ctcm_buffer_write(struct device *dev,
35 struct device_attribute *attr, const char *buf, size_t count)
37 struct net_device *ndev;
39 struct ctcm_priv *priv = dev_get_drvdata(dev);
42 if (!(priv && priv->channel[CTCM_READ] &&
43 priv->channel[CTCM_READ]->netdev)) {
44 CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev");
47 ndev = priv->channel[CTCM_READ]->netdev;
49 rc = kstrtouint(buf, 0, &bs1);
52 if (bs1 > CTCM_BUFSIZE_LIMIT)
54 if (bs1 < (576 + LL_HEADER_LENGTH + 2))
56 priv->buffer_size = bs1; /* just to overwrite the default */
58 if ((ndev->flags & IFF_RUNNING) &&
59 (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2)))
62 priv->channel[CTCM_READ]->max_bufsize = bs1;
63 priv->channel[CTCM_WRITE]->max_bufsize = bs1;
64 if (!(ndev->flags & IFF_RUNNING))
65 ndev->mtu = bs1 - LL_HEADER_LENGTH - 2;
66 priv->channel[CTCM_READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
67 priv->channel[CTCM_WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
69 CTCM_DBF_DEV(SETUP, ndev, buf);
73 CTCM_DBF_DEV(SETUP, ndev, "buff_err");
77 static void ctcm_print_statistics(struct ctcm_priv *priv)
84 sbuf = kmalloc(2048, GFP_KERNEL);
89 p += sprintf(p, " Device FSM state: %s\n",
90 fsm_getstate_str(priv->fsm));
91 p += sprintf(p, " RX channel FSM state: %s\n",
92 fsm_getstate_str(priv->channel[CTCM_READ]->fsm));
93 p += sprintf(p, " TX channel FSM state: %s\n",
94 fsm_getstate_str(priv->channel[CTCM_WRITE]->fsm));
95 p += sprintf(p, " Max. TX buffer used: %ld\n",
96 priv->channel[WRITE]->prof.maxmulti);
97 p += sprintf(p, " Max. chained SKBs: %ld\n",
98 priv->channel[WRITE]->prof.maxcqueue);
99 p += sprintf(p, " TX single write ops: %ld\n",
100 priv->channel[WRITE]->prof.doios_single);
101 p += sprintf(p, " TX multi write ops: %ld\n",
102 priv->channel[WRITE]->prof.doios_multi);
103 p += sprintf(p, " Netto bytes written: %ld\n",
104 priv->channel[WRITE]->prof.txlen);
105 p += sprintf(p, " Max. TX IO-time: %u\n",
106 jiffies_to_usecs(priv->channel[WRITE]->prof.tx_time));
108 printk(KERN_INFO "Statistics for %s:\n%s",
109 priv->channel[CTCM_WRITE]->netdev->name, sbuf);
114 static ssize_t stats_show(struct device *dev,
115 struct device_attribute *attr, char *buf)
117 struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
118 struct ctcm_priv *priv = dev_get_drvdata(dev);
120 if (!priv || gdev->state != CCWGROUP_ONLINE)
122 ctcm_print_statistics(priv);
123 return sprintf(buf, "0\n");
126 static ssize_t stats_write(struct device *dev, struct device_attribute *attr,
127 const char *buf, size_t count)
129 struct ctcm_priv *priv = dev_get_drvdata(dev);
132 /* Reset statistics */
133 memset(&priv->channel[WRITE]->prof, 0,
134 sizeof(priv->channel[CTCM_WRITE]->prof));
138 static ssize_t ctcm_proto_show(struct device *dev,
139 struct device_attribute *attr, char *buf)
141 struct ctcm_priv *priv = dev_get_drvdata(dev);
145 return sprintf(buf, "%d\n", priv->protocol);
148 static ssize_t ctcm_proto_store(struct device *dev,
149 struct device_attribute *attr, const char *buf, size_t count)
152 struct ctcm_priv *priv = dev_get_drvdata(dev);
156 rc = kstrtoint(buf, 0, &value);
158 !((value == CTCM_PROTO_S390) ||
159 (value == CTCM_PROTO_LINUX) ||
160 (value == CTCM_PROTO_MPC) ||
161 (value == CTCM_PROTO_OS390)))
163 priv->protocol = value;
164 CTCM_DBF_DEV(SETUP, dev, buf);
169 static const char *ctcm_type[] = {
174 "unknown channel type",
175 "unsupported channel type",
178 static ssize_t ctcm_type_show(struct device *dev,
179 struct device_attribute *attr, char *buf)
181 struct ccwgroup_device *cgdev;
183 cgdev = to_ccwgroupdev(dev);
187 return sprintf(buf, "%s\n",
188 ctcm_type[cgdev->cdev[0]->id.driver_info]);
191 static DEVICE_ATTR(buffer, 0644, ctcm_buffer_show, ctcm_buffer_write);
192 static DEVICE_ATTR(protocol, 0644, ctcm_proto_show, ctcm_proto_store);
193 static DEVICE_ATTR(type, 0444, ctcm_type_show, NULL);
194 static DEVICE_ATTR(stats, 0644, stats_show, stats_write);
196 static struct attribute *ctcm_attr[] = {
197 &dev_attr_protocol.attr,
199 &dev_attr_buffer.attr,
200 &dev_attr_stats.attr,
204 static struct attribute_group ctcm_attr_group = {
207 const struct attribute_group *ctcm_attr_groups[] = {