0001
0002
0003
0004
0005
0006
0007
0008 #undef DEBUG
0009 #undef DEBUGDATA
0010 #undef DEBUGCCW
0011
0012 #define KMSG_COMPONENT "ctcm"
0013 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
0014
0015 #include <linux/device.h>
0016 #include <linux/sysfs.h>
0017 #include <linux/slab.h>
0018 #include "ctcm_main.h"
0019
0020
0021
0022
0023
0024 static ssize_t ctcm_buffer_show(struct device *dev,
0025 struct device_attribute *attr, char *buf)
0026 {
0027 struct ctcm_priv *priv = dev_get_drvdata(dev);
0028
0029 if (!priv)
0030 return -ENODEV;
0031 return sprintf(buf, "%d\n", priv->buffer_size);
0032 }
0033
0034 static ssize_t ctcm_buffer_write(struct device *dev,
0035 struct device_attribute *attr, const char *buf, size_t count)
0036 {
0037 struct net_device *ndev;
0038 unsigned int bs1;
0039 struct ctcm_priv *priv = dev_get_drvdata(dev);
0040 int rc;
0041
0042 if (!(priv && priv->channel[CTCM_READ] &&
0043 priv->channel[CTCM_READ]->netdev)) {
0044 CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev");
0045 return -ENODEV;
0046 }
0047 ndev = priv->channel[CTCM_READ]->netdev;
0048
0049 rc = kstrtouint(buf, 0, &bs1);
0050 if (rc)
0051 goto einval;
0052 if (bs1 > CTCM_BUFSIZE_LIMIT)
0053 goto einval;
0054 if (bs1 < (576 + LL_HEADER_LENGTH + 2))
0055 goto einval;
0056 priv->buffer_size = bs1;
0057
0058 if ((ndev->flags & IFF_RUNNING) &&
0059 (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2)))
0060 goto einval;
0061
0062 priv->channel[CTCM_READ]->max_bufsize = bs1;
0063 priv->channel[CTCM_WRITE]->max_bufsize = bs1;
0064 if (!(ndev->flags & IFF_RUNNING))
0065 ndev->mtu = bs1 - LL_HEADER_LENGTH - 2;
0066 priv->channel[CTCM_READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
0067 priv->channel[CTCM_WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
0068
0069 CTCM_DBF_DEV(SETUP, ndev, buf);
0070 return count;
0071
0072 einval:
0073 CTCM_DBF_DEV(SETUP, ndev, "buff_err");
0074 return -EINVAL;
0075 }
0076
0077 static void ctcm_print_statistics(struct ctcm_priv *priv)
0078 {
0079 char *sbuf;
0080 char *p;
0081
0082 if (!priv)
0083 return;
0084 sbuf = kmalloc(2048, GFP_KERNEL);
0085 if (sbuf == NULL)
0086 return;
0087 p = sbuf;
0088
0089 p += sprintf(p, " Device FSM state: %s\n",
0090 fsm_getstate_str(priv->fsm));
0091 p += sprintf(p, " RX channel FSM state: %s\n",
0092 fsm_getstate_str(priv->channel[CTCM_READ]->fsm));
0093 p += sprintf(p, " TX channel FSM state: %s\n",
0094 fsm_getstate_str(priv->channel[CTCM_WRITE]->fsm));
0095 p += sprintf(p, " Max. TX buffer used: %ld\n",
0096 priv->channel[WRITE]->prof.maxmulti);
0097 p += sprintf(p, " Max. chained SKBs: %ld\n",
0098 priv->channel[WRITE]->prof.maxcqueue);
0099 p += sprintf(p, " TX single write ops: %ld\n",
0100 priv->channel[WRITE]->prof.doios_single);
0101 p += sprintf(p, " TX multi write ops: %ld\n",
0102 priv->channel[WRITE]->prof.doios_multi);
0103 p += sprintf(p, " Netto bytes written: %ld\n",
0104 priv->channel[WRITE]->prof.txlen);
0105 p += sprintf(p, " Max. TX IO-time: %u\n",
0106 jiffies_to_usecs(priv->channel[WRITE]->prof.tx_time));
0107
0108 printk(KERN_INFO "Statistics for %s:\n%s",
0109 priv->channel[CTCM_WRITE]->netdev->name, sbuf);
0110 kfree(sbuf);
0111 return;
0112 }
0113
0114 static ssize_t stats_show(struct device *dev,
0115 struct device_attribute *attr, char *buf)
0116 {
0117 struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
0118 struct ctcm_priv *priv = dev_get_drvdata(dev);
0119
0120 if (!priv || gdev->state != CCWGROUP_ONLINE)
0121 return -ENODEV;
0122 ctcm_print_statistics(priv);
0123 return sprintf(buf, "0\n");
0124 }
0125
0126 static ssize_t stats_write(struct device *dev, struct device_attribute *attr,
0127 const char *buf, size_t count)
0128 {
0129 struct ctcm_priv *priv = dev_get_drvdata(dev);
0130 if (!priv)
0131 return -ENODEV;
0132
0133 memset(&priv->channel[WRITE]->prof, 0,
0134 sizeof(priv->channel[CTCM_WRITE]->prof));
0135 return count;
0136 }
0137
0138 static ssize_t ctcm_proto_show(struct device *dev,
0139 struct device_attribute *attr, char *buf)
0140 {
0141 struct ctcm_priv *priv = dev_get_drvdata(dev);
0142 if (!priv)
0143 return -ENODEV;
0144
0145 return sprintf(buf, "%d\n", priv->protocol);
0146 }
0147
0148 static ssize_t ctcm_proto_store(struct device *dev,
0149 struct device_attribute *attr, const char *buf, size_t count)
0150 {
0151 int value, rc;
0152 struct ctcm_priv *priv = dev_get_drvdata(dev);
0153
0154 if (!priv)
0155 return -ENODEV;
0156 rc = kstrtoint(buf, 0, &value);
0157 if (rc ||
0158 !((value == CTCM_PROTO_S390) ||
0159 (value == CTCM_PROTO_LINUX) ||
0160 (value == CTCM_PROTO_MPC) ||
0161 (value == CTCM_PROTO_OS390)))
0162 return -EINVAL;
0163 priv->protocol = value;
0164 CTCM_DBF_DEV(SETUP, dev, buf);
0165
0166 return count;
0167 }
0168
0169 static const char *ctcm_type[] = {
0170 "not a channel",
0171 "CTC/A",
0172 "FICON channel",
0173 "ESCON channel",
0174 "unknown channel type",
0175 "unsupported channel type",
0176 };
0177
0178 static ssize_t ctcm_type_show(struct device *dev,
0179 struct device_attribute *attr, char *buf)
0180 {
0181 struct ccwgroup_device *cgdev;
0182
0183 cgdev = to_ccwgroupdev(dev);
0184 if (!cgdev)
0185 return -ENODEV;
0186
0187 return sprintf(buf, "%s\n",
0188 ctcm_type[cgdev->cdev[0]->id.driver_info]);
0189 }
0190
0191 static DEVICE_ATTR(buffer, 0644, ctcm_buffer_show, ctcm_buffer_write);
0192 static DEVICE_ATTR(protocol, 0644, ctcm_proto_show, ctcm_proto_store);
0193 static DEVICE_ATTR(type, 0444, ctcm_type_show, NULL);
0194 static DEVICE_ATTR(stats, 0644, stats_show, stats_write);
0195
0196 static struct attribute *ctcm_attr[] = {
0197 &dev_attr_protocol.attr,
0198 &dev_attr_type.attr,
0199 &dev_attr_buffer.attr,
0200 &dev_attr_stats.attr,
0201 NULL,
0202 };
0203
0204 static struct attribute_group ctcm_attr_group = {
0205 .attrs = ctcm_attr,
0206 };
0207 const struct attribute_group *ctcm_attr_groups[] = {
0208 &ctcm_attr_group,
0209 NULL,
0210 };