2 * Copyright IBM Corp. 2007, 2007
3 * Authors: Peter Tiedemann (ptiedem@de.ibm.com)
11 #define KMSG_COMPONENT "ctcm"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/device.h>
15 #include <linux/sysfs.h>
16 #include <linux/slab.h>
17 #include "ctcm_main.h"
23 static ssize_t
ctcm_buffer_show(struct device
*dev
,
24 struct device_attribute
*attr
, char *buf
)
26 struct ctcm_priv
*priv
= dev_get_drvdata(dev
);
30 return sprintf(buf
, "%d\n", priv
->buffer_size
);
33 static ssize_t
ctcm_buffer_write(struct device
*dev
,
34 struct device_attribute
*attr
, const char *buf
, size_t count
)
36 struct net_device
*ndev
;
38 struct ctcm_priv
*priv
= dev_get_drvdata(dev
);
40 ndev
= priv
->channel
[CTCM_READ
]->netdev
;
41 if (!(priv
&& priv
->channel
[CTCM_READ
] && ndev
)) {
42 CTCM_DBF_TEXT(SETUP
, CTC_DBF_ERROR
, "bfnondev");
46 sscanf(buf
, "%u", &bs1
);
47 if (bs1
> CTCM_BUFSIZE_LIMIT
)
49 if (bs1
< (576 + LL_HEADER_LENGTH
+ 2))
51 priv
->buffer_size
= bs1
; /* just to overwrite the default */
53 if ((ndev
->flags
& IFF_RUNNING
) &&
54 (bs1
< (ndev
->mtu
+ LL_HEADER_LENGTH
+ 2)))
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
;
64 CTCM_DBF_DEV(SETUP
, ndev
, buf
);
68 CTCM_DBF_DEV(SETUP
, ndev
, "buff_err");
72 static void ctcm_print_statistics(struct ctcm_priv
*priv
)
79 sbuf
= kmalloc(2048, GFP_KERNEL
);
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
);
103 printk(KERN_INFO
"Statistics for %s:\n%s",
104 priv
->channel
[CTCM_WRITE
]->netdev
->name
, sbuf
);
109 static ssize_t
stats_show(struct device
*dev
,
110 struct device_attribute
*attr
, char *buf
)
112 struct ccwgroup_device
*gdev
= to_ccwgroupdev(dev
);
113 struct ctcm_priv
*priv
= dev_get_drvdata(dev
);
115 if (!priv
|| gdev
->state
!= CCWGROUP_ONLINE
)
117 ctcm_print_statistics(priv
);
118 return sprintf(buf
, "0\n");
121 static ssize_t
stats_write(struct device
*dev
, struct device_attribute
*attr
,
122 const char *buf
, size_t count
)
124 struct ctcm_priv
*priv
= dev_get_drvdata(dev
);
127 /* Reset statistics */
128 memset(&priv
->channel
[WRITE
]->prof
, 0,
129 sizeof(priv
->channel
[CTCM_WRITE
]->prof
));
133 static ssize_t
ctcm_proto_show(struct device
*dev
,
134 struct device_attribute
*attr
, char *buf
)
136 struct ctcm_priv
*priv
= dev_get_drvdata(dev
);
140 return sprintf(buf
, "%d\n", priv
->protocol
);
143 static ssize_t
ctcm_proto_store(struct device
*dev
,
144 struct device_attribute
*attr
, const char *buf
, size_t count
)
147 struct ctcm_priv
*priv
= dev_get_drvdata(dev
);
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
)))
157 priv
->protocol
= value
;
158 CTCM_DBF_DEV(SETUP
, dev
, buf
);
163 static const char *ctcm_type
[] = {
168 "unknown channel type",
169 "unsupported channel type",
172 static ssize_t
ctcm_type_show(struct device
*dev
,
173 struct device_attribute
*attr
, char *buf
)
175 struct ccwgroup_device
*cgdev
;
177 cgdev
= to_ccwgroupdev(dev
);
181 return sprintf(buf
, "%s\n",
182 ctcm_type
[cgdev
->cdev
[0]->id
.driver_info
]);
185 static DEVICE_ATTR(buffer
, 0644, ctcm_buffer_show
, ctcm_buffer_write
);
186 static DEVICE_ATTR(protocol
, 0644, ctcm_proto_show
, ctcm_proto_store
);
187 static DEVICE_ATTR(type
, 0444, ctcm_type_show
, NULL
);
188 static DEVICE_ATTR(stats
, 0644, stats_show
, stats_write
);
190 static struct attribute
*ctcm_attr
[] = {
191 &dev_attr_protocol
.attr
,
193 &dev_attr_buffer
.attr
,
194 &dev_attr_stats
.attr
,
198 static struct attribute_group ctcm_attr_group
= {
201 const struct attribute_group
*ctcm_attr_groups
[] = {