Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1 | /* |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 2 | * 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 Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 11 | #define KMSG_COMPONENT "ctcm" |
| 12 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 13 | |
Sebastian Ott | 20cdffa | 2012-05-15 17:54:12 +0200 | [diff] [blame] | 14 | #include <linux/device.h> |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 15 | #include <linux/sysfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 17 | #include "ctcm_main.h" |
| 18 | |
| 19 | /* |
| 20 | * sysfs attributes |
| 21 | */ |
| 22 | |
| 23 | static 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 | |
| 33 | static 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; |
Ursula Braun | a68be01 | 2014-05-28 10:22:31 +0200 | [diff] [blame] | 37 | unsigned int bs1; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 38 | struct ctcm_priv *priv = dev_get_drvdata(dev); |
Ursula Braun | a68be01 | 2014-05-28 10:22:31 +0200 | [diff] [blame] | 39 | int rc; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 40 | |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 41 | ndev = priv->channel[CTCM_READ]->netdev; |
| 42 | if (!(priv && priv->channel[CTCM_READ] && ndev)) { |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 43 | CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev"); |
| 44 | return -ENODEV; |
| 45 | } |
| 46 | |
Thomas Richter | 652d77b | 2014-10-22 12:18:07 +0200 | [diff] [blame] | 47 | rc = kstrtouint(buf, 0, &bs1); |
| 48 | if (rc) |
Ursula Braun | a68be01 | 2014-05-28 10:22:31 +0200 | [diff] [blame] | 49 | goto einval; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 50 | if (bs1 > CTCM_BUFSIZE_LIMIT) |
| 51 | goto einval; |
| 52 | if (bs1 < (576 + LL_HEADER_LENGTH + 2)) |
| 53 | goto einval; |
| 54 | priv->buffer_size = bs1; /* just to overwrite the default */ |
| 55 | |
| 56 | if ((ndev->flags & IFF_RUNNING) && |
| 57 | (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2))) |
| 58 | goto einval; |
| 59 | |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 60 | priv->channel[CTCM_READ]->max_bufsize = bs1; |
| 61 | priv->channel[CTCM_WRITE]->max_bufsize = bs1; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 62 | if (!(ndev->flags & IFF_RUNNING)) |
| 63 | ndev->mtu = bs1 - LL_HEADER_LENGTH - 2; |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 64 | priv->channel[CTCM_READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED; |
| 65 | priv->channel[CTCM_WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 66 | |
| 67 | CTCM_DBF_DEV(SETUP, ndev, buf); |
| 68 | return count; |
| 69 | |
| 70 | einval: |
| 71 | CTCM_DBF_DEV(SETUP, ndev, "buff_err"); |
| 72 | return -EINVAL; |
| 73 | } |
| 74 | |
| 75 | static void ctcm_print_statistics(struct ctcm_priv *priv) |
| 76 | { |
| 77 | char *sbuf; |
| 78 | char *p; |
| 79 | |
| 80 | if (!priv) |
| 81 | return; |
| 82 | sbuf = kmalloc(2048, GFP_KERNEL); |
| 83 | if (sbuf == NULL) |
| 84 | return; |
| 85 | p = sbuf; |
| 86 | |
| 87 | p += sprintf(p, " Device FSM state: %s\n", |
| 88 | fsm_getstate_str(priv->fsm)); |
| 89 | p += sprintf(p, " RX channel FSM state: %s\n", |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 90 | fsm_getstate_str(priv->channel[CTCM_READ]->fsm)); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 91 | p += sprintf(p, " TX channel FSM state: %s\n", |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 92 | fsm_getstate_str(priv->channel[CTCM_WRITE]->fsm)); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 93 | p += sprintf(p, " Max. TX buffer used: %ld\n", |
| 94 | priv->channel[WRITE]->prof.maxmulti); |
| 95 | p += sprintf(p, " Max. chained SKBs: %ld\n", |
| 96 | priv->channel[WRITE]->prof.maxcqueue); |
| 97 | p += sprintf(p, " TX single write ops: %ld\n", |
| 98 | priv->channel[WRITE]->prof.doios_single); |
| 99 | p += sprintf(p, " TX multi write ops: %ld\n", |
| 100 | priv->channel[WRITE]->prof.doios_multi); |
| 101 | p += sprintf(p, " Netto bytes written: %ld\n", |
| 102 | priv->channel[WRITE]->prof.txlen); |
Aya Mahfouz | ee6edb9 | 2015-01-16 14:05:45 +0100 | [diff] [blame] | 103 | p += sprintf(p, " Max. TX IO-time: %u\n", |
| 104 | jiffies_to_usecs(priv->channel[WRITE]->prof.tx_time)); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 105 | |
| 106 | printk(KERN_INFO "Statistics for %s:\n%s", |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 107 | priv->channel[CTCM_WRITE]->netdev->name, sbuf); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 108 | kfree(sbuf); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | static ssize_t stats_show(struct device *dev, |
Sebastian Ott | 20cdffa | 2012-05-15 17:54:12 +0200 | [diff] [blame] | 113 | struct device_attribute *attr, char *buf) |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 114 | { |
Sebastian Ott | 20cdffa | 2012-05-15 17:54:12 +0200 | [diff] [blame] | 115 | struct ccwgroup_device *gdev = to_ccwgroupdev(dev); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 116 | struct ctcm_priv *priv = dev_get_drvdata(dev); |
Sebastian Ott | 20cdffa | 2012-05-15 17:54:12 +0200 | [diff] [blame] | 117 | |
| 118 | if (!priv || gdev->state != CCWGROUP_ONLINE) |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 119 | return -ENODEV; |
| 120 | ctcm_print_statistics(priv); |
| 121 | return sprintf(buf, "0\n"); |
| 122 | } |
| 123 | |
| 124 | static ssize_t stats_write(struct device *dev, struct device_attribute *attr, |
| 125 | const char *buf, size_t count) |
| 126 | { |
| 127 | struct ctcm_priv *priv = dev_get_drvdata(dev); |
| 128 | if (!priv) |
| 129 | return -ENODEV; |
| 130 | /* Reset statistics */ |
| 131 | memset(&priv->channel[WRITE]->prof, 0, |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 132 | sizeof(priv->channel[CTCM_WRITE]->prof)); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 133 | return count; |
| 134 | } |
| 135 | |
| 136 | static ssize_t ctcm_proto_show(struct device *dev, |
| 137 | struct device_attribute *attr, char *buf) |
| 138 | { |
| 139 | struct ctcm_priv *priv = dev_get_drvdata(dev); |
| 140 | if (!priv) |
| 141 | return -ENODEV; |
| 142 | |
| 143 | return sprintf(buf, "%d\n", priv->protocol); |
| 144 | } |
| 145 | |
| 146 | static ssize_t ctcm_proto_store(struct device *dev, |
| 147 | struct device_attribute *attr, const char *buf, size_t count) |
| 148 | { |
Ursula Braun | a68be01 | 2014-05-28 10:22:31 +0200 | [diff] [blame] | 149 | int value, rc; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 150 | struct ctcm_priv *priv = dev_get_drvdata(dev); |
| 151 | |
| 152 | if (!priv) |
| 153 | return -ENODEV; |
Thomas Richter | 652d77b | 2014-10-22 12:18:07 +0200 | [diff] [blame] | 154 | rc = kstrtoint(buf, 0, &value); |
| 155 | if (rc || |
Ursula Braun | a68be01 | 2014-05-28 10:22:31 +0200 | [diff] [blame] | 156 | !((value == CTCM_PROTO_S390) || |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 157 | (value == CTCM_PROTO_LINUX) || |
| 158 | (value == CTCM_PROTO_MPC) || |
| 159 | (value == CTCM_PROTO_OS390))) |
| 160 | return -EINVAL; |
| 161 | priv->protocol = value; |
| 162 | CTCM_DBF_DEV(SETUP, dev, buf); |
| 163 | |
| 164 | return count; |
| 165 | } |
| 166 | |
Martin Schwidefsky | c4736d9 | 2011-10-30 15:17:11 +0100 | [diff] [blame] | 167 | static const char *ctcm_type[] = { |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 168 | "not a channel", |
| 169 | "CTC/A", |
| 170 | "FICON channel", |
| 171 | "ESCON channel", |
| 172 | "unknown channel type", |
| 173 | "unsupported channel type", |
| 174 | }; |
| 175 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 176 | static ssize_t ctcm_type_show(struct device *dev, |
| 177 | struct device_attribute *attr, char *buf) |
| 178 | { |
| 179 | struct ccwgroup_device *cgdev; |
| 180 | |
| 181 | cgdev = to_ccwgroupdev(dev); |
| 182 | if (!cgdev) |
| 183 | return -ENODEV; |
| 184 | |
| 185 | return sprintf(buf, "%s\n", |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 186 | ctcm_type[cgdev->cdev[0]->id.driver_info]); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static DEVICE_ATTR(buffer, 0644, ctcm_buffer_show, ctcm_buffer_write); |
| 190 | static DEVICE_ATTR(protocol, 0644, ctcm_proto_show, ctcm_proto_store); |
| 191 | static DEVICE_ATTR(type, 0444, ctcm_type_show, NULL); |
| 192 | static DEVICE_ATTR(stats, 0644, stats_show, stats_write); |
| 193 | |
| 194 | static struct attribute *ctcm_attr[] = { |
| 195 | &dev_attr_protocol.attr, |
| 196 | &dev_attr_type.attr, |
| 197 | &dev_attr_buffer.attr, |
Sebastian Ott | 20cdffa | 2012-05-15 17:54:12 +0200 | [diff] [blame] | 198 | &dev_attr_stats.attr, |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 199 | NULL, |
| 200 | }; |
| 201 | |
| 202 | static struct attribute_group ctcm_attr_group = { |
| 203 | .attrs = ctcm_attr, |
| 204 | }; |
Sebastian Ott | 20cdffa | 2012-05-15 17:54:12 +0200 | [diff] [blame] | 205 | const struct attribute_group *ctcm_attr_groups[] = { |
| 206 | &ctcm_attr_group, |
| 207 | NULL, |
| 208 | }; |