Linux Audio

Check our new training course

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